Linux Audio

Check our new training course

Loading...
v3.1
 
   1/* ptrace.c: Sparc process tracing support.
   2 *
   3 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
   4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
   5 *
   6 * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
   7 * and David Mosberger.
   8 *
   9 * Added Linux support -miguel (weird, eh?, the original code was meant
  10 * to emulate SunOS).
  11 */
  12
  13#include <linux/kernel.h>
  14#include <linux/sched.h>
 
  15#include <linux/mm.h>
  16#include <linux/errno.h>
 
  17#include <linux/ptrace.h>
  18#include <linux/user.h>
  19#include <linux/smp.h>
  20#include <linux/security.h>
  21#include <linux/seccomp.h>
  22#include <linux/audit.h>
  23#include <linux/signal.h>
  24#include <linux/regset.h>
  25#include <linux/tracehook.h>
  26#include <trace/syscall.h>
  27#include <linux/compat.h>
  28#include <linux/elf.h>
 
  29
  30#include <asm/asi.h>
  31#include <asm/pgtable.h>
  32#include <asm/system.h>
  33#include <asm/uaccess.h>
  34#include <asm/psrcompat.h>
  35#include <asm/visasm.h>
  36#include <asm/spitfire.h>
  37#include <asm/page.h>
  38#include <asm/cpudata.h>
  39#include <asm/cacheflush.h>
  40
  41#define CREATE_TRACE_POINTS
  42#include <trace/events/syscalls.h>
  43
  44#include "entry.h"
  45
  46/* #define ALLOW_INIT_TRACING */
  47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  48/*
  49 * Called by kernel/ptrace.c when detaching..
  50 *
  51 * Make sure single step bits etc are not set.
  52 */
  53void ptrace_disable(struct task_struct *child)
  54{
  55	/* nothing to do */
  56}
  57
  58/* To get the necessary page struct, access_process_vm() first calls
  59 * get_user_pages().  This has done a flush_dcache_page() on the
  60 * accessed page.  Then our caller (copy_{to,from}_user_page()) did
  61 * to memcpy to read/write the data from that page.
  62 *
  63 * Now, the only thing we have to do is:
  64 * 1) flush the D-cache if it's possible than an illegal alias
  65 *    has been created
  66 * 2) flush the I-cache if this is pre-cheetah and we did a write
  67 */
  68void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  69			 unsigned long uaddr, void *kaddr,
  70			 unsigned long len, int write)
  71{
  72	BUG_ON(len > PAGE_SIZE);
  73
  74	if (tlb_type == hypervisor)
  75		return;
  76
  77	preempt_disable();
  78
  79#ifdef DCACHE_ALIASING_POSSIBLE
  80	/* If bit 13 of the kernel address we used to access the
  81	 * user page is the same as the virtual address that page
  82	 * is mapped to in the user's address space, we can skip the
  83	 * D-cache flush.
  84	 */
  85	if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
  86		unsigned long start = __pa(kaddr);
  87		unsigned long end = start + len;
  88		unsigned long dcache_line_size;
  89
  90		dcache_line_size = local_cpu_data().dcache_line_size;
  91
  92		if (tlb_type == spitfire) {
  93			for (; start < end; start += dcache_line_size)
  94				spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
  95		} else {
  96			start &= ~(dcache_line_size - 1);
  97			for (; start < end; start += dcache_line_size)
  98				__asm__ __volatile__(
  99					"stxa %%g0, [%0] %1\n\t"
 100					"membar #Sync"
 101					: /* no outputs */
 102					: "r" (start),
 103					"i" (ASI_DCACHE_INVALIDATE));
 104		}
 105	}
 106#endif
 107	if (write && tlb_type == spitfire) {
 108		unsigned long start = (unsigned long) kaddr;
 109		unsigned long end = start + len;
 110		unsigned long icache_line_size;
 111
 112		icache_line_size = local_cpu_data().icache_line_size;
 113
 114		for (; start < end; start += icache_line_size)
 115			flushi(start);
 116	}
 117
 118	preempt_enable();
 119}
 
 120
 121static int get_from_target(struct task_struct *target, unsigned long uaddr,
 122			   void *kbuf, int len)
 123{
 124	if (target == current) {
 125		if (copy_from_user(kbuf, (void __user *) uaddr, len))
 126			return -EFAULT;
 127	} else {
 128		int len2 = access_process_vm(target, uaddr, kbuf, len, 0);
 
 129		if (len2 != len)
 130			return -EFAULT;
 131	}
 132	return 0;
 133}
 134
 135static int set_to_target(struct task_struct *target, unsigned long uaddr,
 136			 void *kbuf, int len)
 137{
 138	if (target == current) {
 139		if (copy_to_user((void __user *) uaddr, kbuf, len))
 140			return -EFAULT;
 141	} else {
 142		int len2 = access_process_vm(target, uaddr, kbuf, len, 1);
 
 143		if (len2 != len)
 144			return -EFAULT;
 145	}
 146	return 0;
 147}
 148
 149static int regwindow64_get(struct task_struct *target,
 150			   const struct pt_regs *regs,
 151			   struct reg_window *wbuf)
 152{
 153	unsigned long rw_addr = regs->u_regs[UREG_I6];
 154
 155	if (test_tsk_thread_flag(current, TIF_32BIT)) {
 156		struct reg_window32 win32;
 157		int i;
 158
 159		if (get_from_target(target, rw_addr, &win32, sizeof(win32)))
 160			return -EFAULT;
 161		for (i = 0; i < 8; i++)
 162			wbuf->locals[i] = win32.locals[i];
 163		for (i = 0; i < 8; i++)
 164			wbuf->ins[i] = win32.ins[i];
 165	} else {
 166		rw_addr += STACK_BIAS;
 167		if (get_from_target(target, rw_addr, wbuf, sizeof(*wbuf)))
 168			return -EFAULT;
 169	}
 170
 171	return 0;
 172}
 173
 174static int regwindow64_set(struct task_struct *target,
 175			   const struct pt_regs *regs,
 176			   struct reg_window *wbuf)
 177{
 178	unsigned long rw_addr = regs->u_regs[UREG_I6];
 179
 180	if (test_tsk_thread_flag(current, TIF_32BIT)) {
 181		struct reg_window32 win32;
 182		int i;
 183
 184		for (i = 0; i < 8; i++)
 185			win32.locals[i] = wbuf->locals[i];
 186		for (i = 0; i < 8; i++)
 187			win32.ins[i] = wbuf->ins[i];
 188
 189		if (set_to_target(target, rw_addr, &win32, sizeof(win32)))
 190			return -EFAULT;
 191	} else {
 192		rw_addr += STACK_BIAS;
 193		if (set_to_target(target, rw_addr, wbuf, sizeof(*wbuf)))
 194			return -EFAULT;
 195	}
 196
 197	return 0;
 198}
 199
 200enum sparc_regset {
 201	REGSET_GENERAL,
 202	REGSET_FP,
 203};
 204
 205static int genregs64_get(struct task_struct *target,
 206			 const struct user_regset *regset,
 207			 unsigned int pos, unsigned int count,
 208			 void *kbuf, void __user *ubuf)
 209{
 210	const struct pt_regs *regs = task_pt_regs(target);
 211	int ret;
 212
 213	if (target == current)
 214		flushw_user();
 215
 216	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 217				  regs->u_regs,
 218				  0, 16 * sizeof(u64));
 219	if (!ret && count && pos < (32 * sizeof(u64))) {
 220		struct reg_window window;
 221
 222		if (regwindow64_get(target, regs, &window))
 223			return -EFAULT;
 224		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 225					  &window,
 226					  16 * sizeof(u64),
 227					  32 * sizeof(u64));
 228	}
 229
 230	if (!ret) {
 231		/* TSTATE, TPC, TNPC */
 232		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 233					  &regs->tstate,
 234					  32 * sizeof(u64),
 235					  35 * sizeof(u64));
 236	}
 237
 238	if (!ret) {
 239		unsigned long y = regs->y;
 240
 241		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 242					  &y,
 243					  35 * sizeof(u64),
 244					  36 * sizeof(u64));
 245	}
 246
 247	if (!ret) {
 248		ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
 249					       36 * sizeof(u64), -1);
 250
 251	}
 252	return ret;
 253}
 254
 255static int genregs64_set(struct task_struct *target,
 256			 const struct user_regset *regset,
 257			 unsigned int pos, unsigned int count,
 258			 const void *kbuf, const void __user *ubuf)
 259{
 260	struct pt_regs *regs = task_pt_regs(target);
 261	int ret;
 262
 263	if (target == current)
 264		flushw_user();
 265
 266	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 267				 regs->u_regs,
 268				 0, 16 * sizeof(u64));
 269	if (!ret && count && pos < (32 * sizeof(u64))) {
 270		struct reg_window window;
 271
 272		if (regwindow64_get(target, regs, &window))
 273			return -EFAULT;
 274
 275		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 276					 &window,
 277					 16 * sizeof(u64),
 278					 32 * sizeof(u64));
 279
 280		if (!ret &&
 281		    regwindow64_set(target, regs, &window))
 282			return -EFAULT;
 283	}
 284
 285	if (!ret && count > 0) {
 286		unsigned long tstate;
 287
 288		/* TSTATE */
 289		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 290					 &tstate,
 291					 32 * sizeof(u64),
 292					 33 * sizeof(u64));
 293		if (!ret) {
 294			/* Only the condition codes and the "in syscall"
 295			 * state can be modified in the %tstate register.
 296			 */
 297			tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 298			regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 299			regs->tstate |= tstate;
 300		}
 301	}
 302
 303	if (!ret) {
 304		/* TPC, TNPC */
 305		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 306					 &regs->tpc,
 307					 33 * sizeof(u64),
 308					 35 * sizeof(u64));
 309	}
 310
 311	if (!ret) {
 312		unsigned long y;
 313
 314		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 315					 &y,
 316					 35 * sizeof(u64),
 317					 36 * sizeof(u64));
 318		if (!ret)
 319			regs->y = y;
 320	}
 321
 322	if (!ret)
 323		ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 324						36 * sizeof(u64), -1);
 325
 326	return ret;
 327}
 328
 329static int fpregs64_get(struct task_struct *target,
 330			const struct user_regset *regset,
 331			unsigned int pos, unsigned int count,
 332			void *kbuf, void __user *ubuf)
 333{
 334	const unsigned long *fpregs = task_thread_info(target)->fpregs;
 335	unsigned long fprs, fsr, gsr;
 336	int ret;
 337
 338	if (target == current)
 339		save_and_clear_fpu();
 340
 341	fprs = task_thread_info(target)->fpsaved[0];
 342
 343	if (fprs & FPRS_DL)
 344		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 345					  fpregs,
 346					  0, 16 * sizeof(u64));
 347	else
 348		ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
 349					       0,
 350					       16 * sizeof(u64));
 351
 352	if (!ret) {
 353		if (fprs & FPRS_DU)
 354			ret = user_regset_copyout(&pos, &count,
 355						  &kbuf, &ubuf,
 356						  fpregs + 16,
 357						  16 * sizeof(u64),
 358						  32 * sizeof(u64));
 359		else
 360			ret = user_regset_copyout_zero(&pos, &count,
 361						       &kbuf, &ubuf,
 362						       16 * sizeof(u64),
 363						       32 * sizeof(u64));
 364	}
 365
 
 
 
 
 366	if (fprs & FPRS_FEF) {
 367		fsr = task_thread_info(target)->xfsr[0];
 368		gsr = task_thread_info(target)->gsr[0];
 369	} else {
 370		fsr = gsr = 0;
 371	}
 372
 373	if (!ret)
 374		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 375					  &fsr,
 376					  32 * sizeof(u64),
 377					  33 * sizeof(u64));
 378	if (!ret)
 379		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 380					  &gsr,
 381					  33 * sizeof(u64),
 382					  34 * sizeof(u64));
 383	if (!ret)
 384		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 385					  &fprs,
 386					  34 * sizeof(u64),
 387					  35 * sizeof(u64));
 388
 389	if (!ret)
 390		ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
 391					       35 * sizeof(u64), -1);
 392
 393	return ret;
 394}
 395
 396static int fpregs64_set(struct task_struct *target,
 397			const struct user_regset *regset,
 398			unsigned int pos, unsigned int count,
 399			const void *kbuf, const void __user *ubuf)
 400{
 401	unsigned long *fpregs = task_thread_info(target)->fpregs;
 402	unsigned long fprs;
 403	int ret;
 404
 405	if (target == current)
 406		save_and_clear_fpu();
 407
 408	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 409				 fpregs,
 410				 0, 32 * sizeof(u64));
 411	if (!ret)
 412		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 413					 task_thread_info(target)->xfsr,
 414					 32 * sizeof(u64),
 415					 33 * sizeof(u64));
 416	if (!ret)
 417		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 418					 task_thread_info(target)->gsr,
 419					 33 * sizeof(u64),
 420					 34 * sizeof(u64));
 421
 422	fprs = task_thread_info(target)->fpsaved[0];
 423	if (!ret && count > 0) {
 424		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 425					 &fprs,
 426					 34 * sizeof(u64),
 427					 35 * sizeof(u64));
 428	}
 429
 430	fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
 431	task_thread_info(target)->fpsaved[0] = fprs;
 432
 433	if (!ret)
 434		ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 435						35 * sizeof(u64), -1);
 436	return ret;
 437}
 438
 439static const struct user_regset sparc64_regsets[] = {
 440	/* Format is:
 441	 * 	G0 --> G7
 442	 *	O0 --> O7
 443	 *	L0 --> L7
 444	 *	I0 --> I7
 445	 *	TSTATE, TPC, TNPC, Y
 446	 */
 447	[REGSET_GENERAL] = {
 448		.core_note_type = NT_PRSTATUS,
 449		.n = 36,
 450		.size = sizeof(u64), .align = sizeof(u64),
 451		.get = genregs64_get, .set = genregs64_set
 452	},
 453	/* Format is:
 454	 *	F0 --> F63
 455	 *	FSR
 456	 *	GSR
 457	 *	FPRS
 458	 */
 459	[REGSET_FP] = {
 460		.core_note_type = NT_PRFPREG,
 461		.n = 35,
 462		.size = sizeof(u64), .align = sizeof(u64),
 463		.get = fpregs64_get, .set = fpregs64_set
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 464	},
 465};
 466
 
 
 
 
 467static const struct user_regset_view user_sparc64_view = {
 468	.name = "sparc64", .e_machine = EM_SPARCV9,
 469	.regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
 470};
 471
 472#ifdef CONFIG_COMPAT
 473static int genregs32_get(struct task_struct *target,
 474			 const struct user_regset *regset,
 475			 unsigned int pos, unsigned int count,
 476			 void *kbuf, void __user *ubuf)
 477{
 478	const struct pt_regs *regs = task_pt_regs(target);
 479	compat_ulong_t __user *reg_window;
 480	compat_ulong_t *k = kbuf;
 481	compat_ulong_t __user *u = ubuf;
 482	compat_ulong_t reg;
 483
 484	if (target == current)
 485		flushw_user();
 486
 487	pos /= sizeof(reg);
 488	count /= sizeof(reg);
 489
 490	if (kbuf) {
 491		for (; count > 0 && pos < 16; count--)
 492			*k++ = regs->u_regs[pos++];
 493
 494		reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
 495		reg_window -= 16;
 496		if (target == current) {
 497			for (; count > 0 && pos < 32; count--) {
 498				if (get_user(*k++, &reg_window[pos++]))
 499					return -EFAULT;
 500			}
 501		} else {
 502			for (; count > 0 && pos < 32; count--) {
 503				if (access_process_vm(target,
 504						      (unsigned long)
 505						      &reg_window[pos],
 506						      k, sizeof(*k), 0)
 507				    != sizeof(*k))
 508					return -EFAULT;
 509				k++;
 510				pos++;
 511			}
 512		}
 513	} else {
 514		for (; count > 0 && pos < 16; count--) {
 515			if (put_user((compat_ulong_t) regs->u_regs[pos++], u++))
 516				return -EFAULT;
 517		}
 518
 519		reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
 520		reg_window -= 16;
 521		if (target == current) {
 522			for (; count > 0 && pos < 32; count--) {
 523				if (get_user(reg, &reg_window[pos++]) ||
 524				    put_user(reg, u++))
 525					return -EFAULT;
 526			}
 527		} else {
 528			for (; count > 0 && pos < 32; count--) {
 529				if (access_process_vm(target,
 530						      (unsigned long)
 531						      &reg_window[pos],
 532						      &reg, sizeof(reg), 0)
 533				    != sizeof(reg))
 534					return -EFAULT;
 535				if (access_process_vm(target,
 536						      (unsigned long) u,
 537						      &reg, sizeof(reg), 1)
 538				    != sizeof(reg))
 539					return -EFAULT;
 540				pos++;
 541				u++;
 542			}
 543		}
 544	}
 545	while (count > 0) {
 546		switch (pos) {
 547		case 32: /* PSR */
 548			reg = tstate_to_psr(regs->tstate);
 549			break;
 550		case 33: /* PC */
 551			reg = regs->tpc;
 552			break;
 553		case 34: /* NPC */
 554			reg = regs->tnpc;
 555			break;
 556		case 35: /* Y */
 557			reg = regs->y;
 558			break;
 559		case 36: /* WIM */
 560		case 37: /* TBR */
 561			reg = 0;
 562			break;
 563		default:
 564			goto finish;
 565		}
 566
 567		if (kbuf)
 568			*k++ = reg;
 569		else if (put_user(reg, u++))
 570			return -EFAULT;
 571		pos++;
 572		count--;
 573	}
 574finish:
 575	pos *= sizeof(reg);
 576	count *= sizeof(reg);
 577
 578	return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
 579					38 * sizeof(reg), -1);
 580}
 581
 582static int genregs32_set(struct task_struct *target,
 583			 const struct user_regset *regset,
 584			 unsigned int pos, unsigned int count,
 585			 const void *kbuf, const void __user *ubuf)
 586{
 587	struct pt_regs *regs = task_pt_regs(target);
 588	compat_ulong_t __user *reg_window;
 589	const compat_ulong_t *k = kbuf;
 590	const compat_ulong_t __user *u = ubuf;
 591	compat_ulong_t reg;
 592
 593	if (target == current)
 594		flushw_user();
 595
 596	pos /= sizeof(reg);
 597	count /= sizeof(reg);
 598
 599	if (kbuf) {
 600		for (; count > 0 && pos < 16; count--)
 601			regs->u_regs[pos++] = *k++;
 602
 603		reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
 604		reg_window -= 16;
 605		if (target == current) {
 606			for (; count > 0 && pos < 32; count--) {
 607				if (put_user(*k++, &reg_window[pos++]))
 608					return -EFAULT;
 609			}
 610		} else {
 611			for (; count > 0 && pos < 32; count--) {
 612				if (access_process_vm(target,
 613						      (unsigned long)
 614						      &reg_window[pos],
 615						      (void *) k,
 616						      sizeof(*k), 1)
 
 617				    != sizeof(*k))
 618					return -EFAULT;
 619				k++;
 620				pos++;
 621			}
 622		}
 623	} else {
 624		for (; count > 0 && pos < 16; count--) {
 625			if (get_user(reg, u++))
 626				return -EFAULT;
 627			regs->u_regs[pos++] = reg;
 628		}
 629
 630		reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
 631		reg_window -= 16;
 632		if (target == current) {
 633			for (; count > 0 && pos < 32; count--) {
 634				if (get_user(reg, u++) ||
 635				    put_user(reg, &reg_window[pos++]))
 636					return -EFAULT;
 637			}
 638		} else {
 639			for (; count > 0 && pos < 32; count--) {
 640				if (access_process_vm(target,
 641						      (unsigned long)
 642						      u,
 643						      &reg, sizeof(reg), 0)
 644				    != sizeof(reg))
 645					return -EFAULT;
 646				if (access_process_vm(target,
 647						      (unsigned long)
 648						      &reg_window[pos],
 649						      &reg, sizeof(reg), 1)
 
 650				    != sizeof(reg))
 651					return -EFAULT;
 652				pos++;
 653				u++;
 654			}
 655		}
 656	}
 657	while (count > 0) {
 658		unsigned long tstate;
 659
 660		if (kbuf)
 661			reg = *k++;
 662		else if (get_user(reg, u++))
 663			return -EFAULT;
 664
 665		switch (pos) {
 666		case 32: /* PSR */
 667			tstate = regs->tstate;
 668			tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 669			tstate |= psr_to_tstate_icc(reg);
 670			if (reg & PSR_SYSCALL)
 671				tstate |= TSTATE_SYSCALL;
 672			regs->tstate = tstate;
 673			break;
 674		case 33: /* PC */
 675			regs->tpc = reg;
 676			break;
 677		case 34: /* NPC */
 678			regs->tnpc = reg;
 679			break;
 680		case 35: /* Y */
 681			regs->y = reg;
 682			break;
 683		case 36: /* WIM */
 684		case 37: /* TBR */
 685			break;
 686		default:
 687			goto finish;
 688		}
 689
 690		pos++;
 691		count--;
 692	}
 693finish:
 694	pos *= sizeof(reg);
 695	count *= sizeof(reg);
 696
 697	return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 698					 38 * sizeof(reg), -1);
 699}
 700
 701static int fpregs32_get(struct task_struct *target,
 702			const struct user_regset *regset,
 703			unsigned int pos, unsigned int count,
 704			void *kbuf, void __user *ubuf)
 705{
 706	const unsigned long *fpregs = task_thread_info(target)->fpregs;
 707	compat_ulong_t enabled;
 708	unsigned long fprs;
 709	compat_ulong_t fsr;
 710	int ret = 0;
 711
 712	if (target == current)
 713		save_and_clear_fpu();
 714
 715	fprs = task_thread_info(target)->fpsaved[0];
 716	if (fprs & FPRS_FEF) {
 717		fsr = task_thread_info(target)->xfsr[0];
 718		enabled = 1;
 719	} else {
 720		fsr = 0;
 721		enabled = 0;
 722	}
 723
 724	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 725				  fpregs,
 726				  0, 32 * sizeof(u32));
 727
 728	if (!ret)
 729		ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
 730					       32 * sizeof(u32),
 731					       33 * sizeof(u32));
 732	if (!ret)
 733		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 734					  &fsr,
 735					  33 * sizeof(u32),
 736					  34 * sizeof(u32));
 737
 738	if (!ret) {
 739		compat_ulong_t val;
 740
 741		val = (enabled << 8) | (8 << 16);
 742		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
 743					  &val,
 744					  34 * sizeof(u32),
 745					  35 * sizeof(u32));
 746	}
 747
 748	if (!ret)
 749		ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
 750					       35 * sizeof(u32), -1);
 751
 752	return ret;
 753}
 754
 755static int fpregs32_set(struct task_struct *target,
 756			const struct user_regset *regset,
 757			unsigned int pos, unsigned int count,
 758			const void *kbuf, const void __user *ubuf)
 759{
 760	unsigned long *fpregs = task_thread_info(target)->fpregs;
 761	unsigned long fprs;
 762	int ret;
 763
 764	if (target == current)
 765		save_and_clear_fpu();
 766
 767	fprs = task_thread_info(target)->fpsaved[0];
 768
 769	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 770				 fpregs,
 771				 0, 32 * sizeof(u32));
 772	if (!ret)
 773		user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 774					  32 * sizeof(u32),
 775					  33 * sizeof(u32));
 776	if (!ret && count > 0) {
 777		compat_ulong_t fsr;
 778		unsigned long val;
 779
 780		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 781					 &fsr,
 782					 33 * sizeof(u32),
 783					 34 * sizeof(u32));
 784		if (!ret) {
 785			val = task_thread_info(target)->xfsr[0];
 786			val &= 0xffffffff00000000UL;
 787			val |= fsr;
 788			task_thread_info(target)->xfsr[0] = val;
 789		}
 790	}
 791
 792	fprs |= (FPRS_FEF | FPRS_DL);
 793	task_thread_info(target)->fpsaved[0] = fprs;
 794
 795	if (!ret)
 796		ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 797						34 * sizeof(u32), -1);
 798	return ret;
 799}
 800
 801static const struct user_regset sparc32_regsets[] = {
 802	/* Format is:
 803	 * 	G0 --> G7
 804	 *	O0 --> O7
 805	 *	L0 --> L7
 806	 *	I0 --> I7
 807	 *	PSR, PC, nPC, Y, WIM, TBR
 808	 */
 809	[REGSET_GENERAL] = {
 810		.core_note_type = NT_PRSTATUS,
 811		.n = 38,
 812		.size = sizeof(u32), .align = sizeof(u32),
 813		.get = genregs32_get, .set = genregs32_set
 814	},
 815	/* Format is:
 816	 *	F0 --> F31
 817	 *	empty 32-bit word
 818	 *	FSR (32--bit word)
 819	 *	FPU QUEUE COUNT (8-bit char)
 820	 *	FPU QUEUE ENTRYSIZE (8-bit char)
 821	 *	FPU ENABLED (8-bit char)
 822	 *	empty 8-bit char
 823	 *	FPU QUEUE (64 32-bit ints)
 824	 */
 825	[REGSET_FP] = {
 826		.core_note_type = NT_PRFPREG,
 827		.n = 99,
 828		.size = sizeof(u32), .align = sizeof(u32),
 829		.get = fpregs32_get, .set = fpregs32_set
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 830	},
 831};
 832
 
 
 
 
 833static const struct user_regset_view user_sparc32_view = {
 834	.name = "sparc", .e_machine = EM_SPARC,
 835	.regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
 836};
 837#endif /* CONFIG_COMPAT */
 838
 839const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 840{
 841#ifdef CONFIG_COMPAT
 842	if (test_tsk_thread_flag(task, TIF_32BIT))
 843		return &user_sparc32_view;
 844#endif
 845	return &user_sparc64_view;
 846}
 847
 848#ifdef CONFIG_COMPAT
 849struct compat_fps {
 850	unsigned int regs[32];
 851	unsigned int fsr;
 852	unsigned int flags;
 853	unsigned int extra;
 854	unsigned int fpqd;
 855	struct compat_fq {
 856		unsigned int insnaddr;
 857		unsigned int insn;
 858	} fpq[16];
 859};
 860
 861long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
 862			compat_ulong_t caddr, compat_ulong_t cdata)
 863{
 864	const struct user_regset_view *view = task_user_regset_view(current);
 865	compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
 866	struct pt_regs32 __user *pregs;
 867	struct compat_fps __user *fps;
 868	unsigned long addr2 = caddr2;
 869	unsigned long addr = caddr;
 870	unsigned long data = cdata;
 871	int ret;
 872
 873	pregs = (struct pt_regs32 __user *) addr;
 874	fps = (struct compat_fps __user *) addr;
 875
 876	switch (request) {
 877	case PTRACE_PEEKUSR:
 878		ret = (addr != 0) ? -EIO : 0;
 879		break;
 880
 881	case PTRACE_GETREGS:
 882		ret = copy_regset_to_user(child, view, REGSET_GENERAL,
 883					  32 * sizeof(u32),
 884					  4 * sizeof(u32),
 885					  &pregs->psr);
 886		if (!ret)
 887			ret = copy_regset_to_user(child, view, REGSET_GENERAL,
 888						  1 * sizeof(u32),
 889						  15 * sizeof(u32),
 890						  &pregs->u_regs[0]);
 891		break;
 892
 893	case PTRACE_SETREGS:
 894		ret = copy_regset_from_user(child, view, REGSET_GENERAL,
 895					    32 * sizeof(u32),
 896					    4 * sizeof(u32),
 897					    &pregs->psr);
 898		if (!ret)
 899			ret = copy_regset_from_user(child, view, REGSET_GENERAL,
 900						    1 * sizeof(u32),
 901						    15 * sizeof(u32),
 902						    &pregs->u_regs[0]);
 903		break;
 904
 905	case PTRACE_GETFPREGS:
 906		ret = copy_regset_to_user(child, view, REGSET_FP,
 907					  0 * sizeof(u32),
 908					  32 * sizeof(u32),
 909					  &fps->regs[0]);
 910		if (!ret)
 911			ret = copy_regset_to_user(child, view, REGSET_FP,
 912						  33 * sizeof(u32),
 913						  1 * sizeof(u32),
 914						  &fps->fsr);
 915		if (!ret) {
 916			if (__put_user(0, &fps->flags) ||
 917			    __put_user(0, &fps->extra) ||
 918			    __put_user(0, &fps->fpqd) ||
 919			    clear_user(&fps->fpq[0], 32 * sizeof(unsigned int)))
 920				ret = -EFAULT;
 921		}
 922		break;
 923
 924	case PTRACE_SETFPREGS:
 925		ret = copy_regset_from_user(child, view, REGSET_FP,
 926					    0 * sizeof(u32),
 927					    32 * sizeof(u32),
 928					    &fps->regs[0]);
 929		if (!ret)
 930			ret = copy_regset_from_user(child, view, REGSET_FP,
 931						    33 * sizeof(u32),
 932						    1 * sizeof(u32),
 933						    &fps->fsr);
 934		break;
 935
 936	case PTRACE_READTEXT:
 937	case PTRACE_READDATA:
 938		ret = ptrace_readdata(child, addr,
 939				      (char __user *)addr2, data);
 940		if (ret == data)
 941			ret = 0;
 942		else if (ret >= 0)
 943			ret = -EIO;
 944		break;
 945
 946	case PTRACE_WRITETEXT:
 947	case PTRACE_WRITEDATA:
 948		ret = ptrace_writedata(child, (char __user *) addr2,
 949				       addr, data);
 950		if (ret == data)
 951			ret = 0;
 952		else if (ret >= 0)
 953			ret = -EIO;
 954		break;
 955
 956	default:
 957		if (request == PTRACE_SPARC_DETACH)
 958			request = PTRACE_DETACH;
 959		ret = compat_ptrace_request(child, request, addr, data);
 960		break;
 961	}
 962
 963	return ret;
 964}
 965#endif /* CONFIG_COMPAT */
 966
 967struct fps {
 968	unsigned int regs[64];
 969	unsigned long fsr;
 970};
 971
 972long arch_ptrace(struct task_struct *child, long request,
 973		 unsigned long addr, unsigned long data)
 974{
 975	const struct user_regset_view *view = task_user_regset_view(current);
 976	unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
 977	struct pt_regs __user *pregs;
 978	struct fps __user *fps;
 979	void __user *addr2p;
 980	int ret;
 981
 982	pregs = (struct pt_regs __user *) addr;
 983	fps = (struct fps __user *) addr;
 984	addr2p = (void __user *) addr2;
 985
 986	switch (request) {
 987	case PTRACE_PEEKUSR:
 988		ret = (addr != 0) ? -EIO : 0;
 989		break;
 990
 991	case PTRACE_GETREGS64:
 992		ret = copy_regset_to_user(child, view, REGSET_GENERAL,
 993					  1 * sizeof(u64),
 994					  15 * sizeof(u64),
 995					  &pregs->u_regs[0]);
 996		if (!ret) {
 997			/* XXX doesn't handle 'y' register correctly XXX */
 998			ret = copy_regset_to_user(child, view, REGSET_GENERAL,
 999						  32 * sizeof(u64),
1000						  4 * sizeof(u64),
1001						  &pregs->tstate);
1002		}
1003		break;
1004
1005	case PTRACE_SETREGS64:
1006		ret = copy_regset_from_user(child, view, REGSET_GENERAL,
1007					    1 * sizeof(u64),
1008					    15 * sizeof(u64),
1009					    &pregs->u_regs[0]);
1010		if (!ret) {
1011			/* XXX doesn't handle 'y' register correctly XXX */
1012			ret = copy_regset_from_user(child, view, REGSET_GENERAL,
1013						    32 * sizeof(u64),
1014						    4 * sizeof(u64),
1015						    &pregs->tstate);
1016		}
1017		break;
1018
1019	case PTRACE_GETFPREGS64:
1020		ret = copy_regset_to_user(child, view, REGSET_FP,
1021					  0 * sizeof(u64),
1022					  33 * sizeof(u64),
1023					  fps);
1024		break;
1025
1026	case PTRACE_SETFPREGS64:
1027		ret = copy_regset_from_user(child, view, REGSET_FP,
1028					  0 * sizeof(u64),
1029					  33 * sizeof(u64),
1030					  fps);
1031		break;
1032
1033	case PTRACE_READTEXT:
1034	case PTRACE_READDATA:
1035		ret = ptrace_readdata(child, addr, addr2p, data);
1036		if (ret == data)
1037			ret = 0;
1038		else if (ret >= 0)
1039			ret = -EIO;
1040		break;
1041
1042	case PTRACE_WRITETEXT:
1043	case PTRACE_WRITEDATA:
1044		ret = ptrace_writedata(child, addr2p, addr, data);
1045		if (ret == data)
1046			ret = 0;
1047		else if (ret >= 0)
1048			ret = -EIO;
1049		break;
1050
1051	default:
1052		if (request == PTRACE_SPARC_DETACH)
1053			request = PTRACE_DETACH;
1054		ret = ptrace_request(child, request, addr, data);
1055		break;
1056	}
1057
1058	return ret;
1059}
1060
1061asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1062{
1063	int ret = 0;
1064
1065	/* do the secure computing check first */
1066	secure_computing(regs->u_regs[UREG_G1]);
 
 
 
1067
1068	if (test_thread_flag(TIF_SYSCALL_TRACE))
1069		ret = tracehook_report_syscall_entry(regs);
1070
1071	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1072		trace_sys_enter(regs, regs->u_regs[UREG_G1]);
1073
1074	if (unlikely(current->audit_context) && !ret)
1075		audit_syscall_entry((test_thread_flag(TIF_32BIT) ?
1076				     AUDIT_ARCH_SPARC :
1077				     AUDIT_ARCH_SPARC64),
1078				    regs->u_regs[UREG_G1],
1079				    regs->u_regs[UREG_I0],
1080				    regs->u_regs[UREG_I1],
1081				    regs->u_regs[UREG_I2],
1082				    regs->u_regs[UREG_I3]);
1083
1084	return ret;
1085}
1086
1087asmlinkage void syscall_trace_leave(struct pt_regs *regs)
1088{
1089#ifdef CONFIG_AUDITSYSCALL
1090	if (unlikely(current->audit_context)) {
1091		unsigned long tstate = regs->tstate;
1092		int result = AUDITSC_SUCCESS;
1093
1094		if (unlikely(tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
1095			result = AUDITSC_FAILURE;
1096
1097		audit_syscall_exit(result, regs->u_regs[UREG_I0]);
1098	}
1099#endif
1100	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1101		trace_sys_exit(regs, regs->u_regs[UREG_G1]);
1102
1103	if (test_thread_flag(TIF_SYSCALL_TRACE))
1104		tracehook_report_syscall_exit(regs, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1105}
v5.9
   1// SPDX-License-Identifier: GPL-2.0-only
   2/* ptrace.c: Sparc process tracing support.
   3 *
   4 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
   5 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
   6 *
   7 * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
   8 * and David Mosberger.
   9 *
  10 * Added Linux support -miguel (weird, eh?, the original code was meant
  11 * to emulate SunOS).
  12 */
  13
  14#include <linux/kernel.h>
  15#include <linux/sched.h>
  16#include <linux/sched/task_stack.h>
  17#include <linux/mm.h>
  18#include <linux/errno.h>
  19#include <linux/export.h>
  20#include <linux/ptrace.h>
  21#include <linux/user.h>
  22#include <linux/smp.h>
  23#include <linux/security.h>
  24#include <linux/seccomp.h>
  25#include <linux/audit.h>
  26#include <linux/signal.h>
  27#include <linux/regset.h>
  28#include <linux/tracehook.h>
  29#include <trace/syscall.h>
  30#include <linux/compat.h>
  31#include <linux/elf.h>
  32#include <linux/context_tracking.h>
  33
  34#include <asm/asi.h>
  35#include <linux/uaccess.h>
 
 
  36#include <asm/psrcompat.h>
  37#include <asm/visasm.h>
  38#include <asm/spitfire.h>
  39#include <asm/page.h>
  40#include <asm/cpudata.h>
  41#include <asm/cacheflush.h>
  42
  43#define CREATE_TRACE_POINTS
  44#include <trace/events/syscalls.h>
  45
  46#include "entry.h"
  47
  48/* #define ALLOW_INIT_TRACING */
  49
  50struct pt_regs_offset {
  51	const char *name;
  52	int offset;
  53};
  54
  55#define REG_OFFSET_NAME(n, r) \
  56	{.name = n, .offset = (PT_V9_##r)}
  57#define REG_OFFSET_END {.name = NULL, .offset = 0}
  58
  59static const struct pt_regs_offset regoffset_table[] = {
  60	REG_OFFSET_NAME("g0", G0),
  61	REG_OFFSET_NAME("g1", G1),
  62	REG_OFFSET_NAME("g2", G2),
  63	REG_OFFSET_NAME("g3", G3),
  64	REG_OFFSET_NAME("g4", G4),
  65	REG_OFFSET_NAME("g5", G5),
  66	REG_OFFSET_NAME("g6", G6),
  67	REG_OFFSET_NAME("g7", G7),
  68
  69	REG_OFFSET_NAME("i0", I0),
  70	REG_OFFSET_NAME("i1", I1),
  71	REG_OFFSET_NAME("i2", I2),
  72	REG_OFFSET_NAME("i3", I3),
  73	REG_OFFSET_NAME("i4", I4),
  74	REG_OFFSET_NAME("i5", I5),
  75	REG_OFFSET_NAME("i6", I6),
  76	REG_OFFSET_NAME("i7", I7),
  77
  78	REG_OFFSET_NAME("tstate", TSTATE),
  79	REG_OFFSET_NAME("pc", TPC),
  80	REG_OFFSET_NAME("npc", TNPC),
  81	REG_OFFSET_NAME("y", Y),
  82	REG_OFFSET_NAME("lr", I7),
  83
  84	REG_OFFSET_END,
  85};
  86
  87/*
  88 * Called by kernel/ptrace.c when detaching..
  89 *
  90 * Make sure single step bits etc are not set.
  91 */
  92void ptrace_disable(struct task_struct *child)
  93{
  94	/* nothing to do */
  95}
  96
  97/* To get the necessary page struct, access_process_vm() first calls
  98 * get_user_pages().  This has done a flush_dcache_page() on the
  99 * accessed page.  Then our caller (copy_{to,from}_user_page()) did
 100 * to memcpy to read/write the data from that page.
 101 *
 102 * Now, the only thing we have to do is:
 103 * 1) flush the D-cache if it's possible than an illegal alias
 104 *    has been created
 105 * 2) flush the I-cache if this is pre-cheetah and we did a write
 106 */
 107void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
 108			 unsigned long uaddr, void *kaddr,
 109			 unsigned long len, int write)
 110{
 111	BUG_ON(len > PAGE_SIZE);
 112
 113	if (tlb_type == hypervisor)
 114		return;
 115
 116	preempt_disable();
 117
 118#ifdef DCACHE_ALIASING_POSSIBLE
 119	/* If bit 13 of the kernel address we used to access the
 120	 * user page is the same as the virtual address that page
 121	 * is mapped to in the user's address space, we can skip the
 122	 * D-cache flush.
 123	 */
 124	if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
 125		unsigned long start = __pa(kaddr);
 126		unsigned long end = start + len;
 127		unsigned long dcache_line_size;
 128
 129		dcache_line_size = local_cpu_data().dcache_line_size;
 130
 131		if (tlb_type == spitfire) {
 132			for (; start < end; start += dcache_line_size)
 133				spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
 134		} else {
 135			start &= ~(dcache_line_size - 1);
 136			for (; start < end; start += dcache_line_size)
 137				__asm__ __volatile__(
 138					"stxa %%g0, [%0] %1\n\t"
 139					"membar #Sync"
 140					: /* no outputs */
 141					: "r" (start),
 142					"i" (ASI_DCACHE_INVALIDATE));
 143		}
 144	}
 145#endif
 146	if (write && tlb_type == spitfire) {
 147		unsigned long start = (unsigned long) kaddr;
 148		unsigned long end = start + len;
 149		unsigned long icache_line_size;
 150
 151		icache_line_size = local_cpu_data().icache_line_size;
 152
 153		for (; start < end; start += icache_line_size)
 154			flushi(start);
 155	}
 156
 157	preempt_enable();
 158}
 159EXPORT_SYMBOL_GPL(flush_ptrace_access);
 160
 161static int get_from_target(struct task_struct *target, unsigned long uaddr,
 162			   void *kbuf, int len)
 163{
 164	if (target == current) {
 165		if (copy_from_user(kbuf, (void __user *) uaddr, len))
 166			return -EFAULT;
 167	} else {
 168		int len2 = access_process_vm(target, uaddr, kbuf, len,
 169				FOLL_FORCE);
 170		if (len2 != len)
 171			return -EFAULT;
 172	}
 173	return 0;
 174}
 175
 176static int set_to_target(struct task_struct *target, unsigned long uaddr,
 177			 void *kbuf, int len)
 178{
 179	if (target == current) {
 180		if (copy_to_user((void __user *) uaddr, kbuf, len))
 181			return -EFAULT;
 182	} else {
 183		int len2 = access_process_vm(target, uaddr, kbuf, len,
 184				FOLL_FORCE | FOLL_WRITE);
 185		if (len2 != len)
 186			return -EFAULT;
 187	}
 188	return 0;
 189}
 190
 191static int regwindow64_get(struct task_struct *target,
 192			   const struct pt_regs *regs,
 193			   struct reg_window *wbuf)
 194{
 195	unsigned long rw_addr = regs->u_regs[UREG_I6];
 196
 197	if (!test_thread_64bit_stack(rw_addr)) {
 198		struct reg_window32 win32;
 199		int i;
 200
 201		if (get_from_target(target, rw_addr, &win32, sizeof(win32)))
 202			return -EFAULT;
 203		for (i = 0; i < 8; i++)
 204			wbuf->locals[i] = win32.locals[i];
 205		for (i = 0; i < 8; i++)
 206			wbuf->ins[i] = win32.ins[i];
 207	} else {
 208		rw_addr += STACK_BIAS;
 209		if (get_from_target(target, rw_addr, wbuf, sizeof(*wbuf)))
 210			return -EFAULT;
 211	}
 212
 213	return 0;
 214}
 215
 216static int regwindow64_set(struct task_struct *target,
 217			   const struct pt_regs *regs,
 218			   struct reg_window *wbuf)
 219{
 220	unsigned long rw_addr = regs->u_regs[UREG_I6];
 221
 222	if (!test_thread_64bit_stack(rw_addr)) {
 223		struct reg_window32 win32;
 224		int i;
 225
 226		for (i = 0; i < 8; i++)
 227			win32.locals[i] = wbuf->locals[i];
 228		for (i = 0; i < 8; i++)
 229			win32.ins[i] = wbuf->ins[i];
 230
 231		if (set_to_target(target, rw_addr, &win32, sizeof(win32)))
 232			return -EFAULT;
 233	} else {
 234		rw_addr += STACK_BIAS;
 235		if (set_to_target(target, rw_addr, wbuf, sizeof(*wbuf)))
 236			return -EFAULT;
 237	}
 238
 239	return 0;
 240}
 241
 242enum sparc_regset {
 243	REGSET_GENERAL,
 244	REGSET_FP,
 245};
 246
 247static int genregs64_get(struct task_struct *target,
 248			 const struct user_regset *regset,
 249			 struct membuf to)
 
 250{
 251	const struct pt_regs *regs = task_pt_regs(target);
 252	struct reg_window window;
 253
 254	if (target == current)
 255		flushw_user();
 256
 257	membuf_write(&to, regs->u_regs, 16 * sizeof(u64));
 258	if (!to.left)
 259		return 0;
 260	if (regwindow64_get(target, regs, &window))
 261		return -EFAULT;
 262	membuf_write(&to, &window, 16 * sizeof(u64));
 263	/* TSTATE, TPC, TNPC */
 264	membuf_write(&to, &regs->tstate, 3 * sizeof(u64));
 265	return membuf_store(&to, (u64)regs->y);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 266}
 267
 268static int genregs64_set(struct task_struct *target,
 269			 const struct user_regset *regset,
 270			 unsigned int pos, unsigned int count,
 271			 const void *kbuf, const void __user *ubuf)
 272{
 273	struct pt_regs *regs = task_pt_regs(target);
 274	int ret;
 275
 276	if (target == current)
 277		flushw_user();
 278
 279	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 280				 regs->u_regs,
 281				 0, 16 * sizeof(u64));
 282	if (!ret && count && pos < (32 * sizeof(u64))) {
 283		struct reg_window window;
 284
 285		if (regwindow64_get(target, regs, &window))
 286			return -EFAULT;
 287
 288		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 289					 &window,
 290					 16 * sizeof(u64),
 291					 32 * sizeof(u64));
 292
 293		if (!ret &&
 294		    regwindow64_set(target, regs, &window))
 295			return -EFAULT;
 296	}
 297
 298	if (!ret && count > 0) {
 299		unsigned long tstate;
 300
 301		/* TSTATE */
 302		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 303					 &tstate,
 304					 32 * sizeof(u64),
 305					 33 * sizeof(u64));
 306		if (!ret) {
 307			/* Only the condition codes and the "in syscall"
 308			 * state can be modified in the %tstate register.
 309			 */
 310			tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 311			regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 312			regs->tstate |= tstate;
 313		}
 314	}
 315
 316	if (!ret) {
 317		/* TPC, TNPC */
 318		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 319					 &regs->tpc,
 320					 33 * sizeof(u64),
 321					 35 * sizeof(u64));
 322	}
 323
 324	if (!ret) {
 325		unsigned long y = regs->y;
 326
 327		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 328					 &y,
 329					 35 * sizeof(u64),
 330					 36 * sizeof(u64));
 331		if (!ret)
 332			regs->y = y;
 333	}
 334
 335	if (!ret)
 336		ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 337						36 * sizeof(u64), -1);
 338
 339	return ret;
 340}
 341
 342static int fpregs64_get(struct task_struct *target,
 343			const struct user_regset *regset,
 344			struct membuf to)
 
 345{
 346	struct thread_info *t = task_thread_info(target);
 347	unsigned long fprs;
 
 348
 349	if (target == current)
 350		save_and_clear_fpu();
 351
 352	fprs = t->fpsaved[0];
 353
 354	if (fprs & FPRS_DL)
 355		membuf_write(&to, t->fpregs, 16 * sizeof(u64));
 
 
 356	else
 357		membuf_zero(&to, 16 * sizeof(u64));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 358
 359	if (fprs & FPRS_DU)
 360		membuf_write(&to, t->fpregs + 16, 16 * sizeof(u64));
 361	else
 362		membuf_zero(&to, 16 * sizeof(u64));
 363	if (fprs & FPRS_FEF) {
 364		membuf_store(&to, t->xfsr[0]);
 365		membuf_store(&to, t->gsr[0]);
 366	} else {
 367		membuf_zero(&to, 2 * sizeof(u64));
 368	}
 369	return membuf_store(&to, fprs);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 370}
 371
 372static int fpregs64_set(struct task_struct *target,
 373			const struct user_regset *regset,
 374			unsigned int pos, unsigned int count,
 375			const void *kbuf, const void __user *ubuf)
 376{
 377	unsigned long *fpregs = task_thread_info(target)->fpregs;
 378	unsigned long fprs;
 379	int ret;
 380
 381	if (target == current)
 382		save_and_clear_fpu();
 383
 384	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 385				 fpregs,
 386				 0, 32 * sizeof(u64));
 387	if (!ret)
 388		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 389					 task_thread_info(target)->xfsr,
 390					 32 * sizeof(u64),
 391					 33 * sizeof(u64));
 392	if (!ret)
 393		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 394					 task_thread_info(target)->gsr,
 395					 33 * sizeof(u64),
 396					 34 * sizeof(u64));
 397
 398	fprs = task_thread_info(target)->fpsaved[0];
 399	if (!ret && count > 0) {
 400		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 401					 &fprs,
 402					 34 * sizeof(u64),
 403					 35 * sizeof(u64));
 404	}
 405
 406	fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
 407	task_thread_info(target)->fpsaved[0] = fprs;
 408
 409	if (!ret)
 410		ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 411						35 * sizeof(u64), -1);
 412	return ret;
 413}
 414
 415static const struct user_regset sparc64_regsets[] = {
 416	/* Format is:
 417	 * 	G0 --> G7
 418	 *	O0 --> O7
 419	 *	L0 --> L7
 420	 *	I0 --> I7
 421	 *	TSTATE, TPC, TNPC, Y
 422	 */
 423	[REGSET_GENERAL] = {
 424		.core_note_type = NT_PRSTATUS,
 425		.n = 36,
 426		.size = sizeof(u64), .align = sizeof(u64),
 427		.regset_get = genregs64_get, .set = genregs64_set
 428	},
 429	/* Format is:
 430	 *	F0 --> F63
 431	 *	FSR
 432	 *	GSR
 433	 *	FPRS
 434	 */
 435	[REGSET_FP] = {
 436		.core_note_type = NT_PRFPREG,
 437		.n = 35,
 438		.size = sizeof(u64), .align = sizeof(u64),
 439		.regset_get = fpregs64_get, .set = fpregs64_set
 440	},
 441};
 442
 443static int getregs64_get(struct task_struct *target,
 444			 const struct user_regset *regset,
 445			 struct membuf to)
 446{
 447	const struct pt_regs *regs = task_pt_regs(target);
 448
 449	if (target == current)
 450		flushw_user();
 451
 452	membuf_write(&to, regs->u_regs + 1, 15 * sizeof(u64));
 453	membuf_store(&to, (u64)0);
 454	membuf_write(&to, &regs->tstate, 3 * sizeof(u64));
 455	return membuf_store(&to, (u64)regs->y);
 456}
 457
 458static int setregs64_set(struct task_struct *target,
 459			 const struct user_regset *regset,
 460			 unsigned int pos, unsigned int count,
 461			 const void *kbuf, const void __user *ubuf)
 462{
 463	struct pt_regs *regs = task_pt_regs(target);
 464	unsigned long y = regs->y;
 465	unsigned long tstate;
 466	int ret;
 467
 468	if (target == current)
 469		flushw_user();
 470
 471	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 472				 regs->u_regs + 1,
 473				 0 * sizeof(u64),
 474				 15 * sizeof(u64));
 475	if (ret)
 476		return ret;
 477	ret =user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 478				 15 * sizeof(u64), 16 * sizeof(u64));
 479	if (ret)
 480		return ret;
 481	/* TSTATE */
 482	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 483				 &tstate,
 484				 16 * sizeof(u64),
 485				 17 * sizeof(u64));
 486	if (ret)
 487		return ret;
 488	/* Only the condition codes and the "in syscall"
 489	 * state can be modified in the %tstate register.
 490	 */
 491	tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 492	regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 493	regs->tstate |= tstate;
 494
 495	/* TPC, TNPC */
 496	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 497				 &regs->tpc,
 498				 17 * sizeof(u64),
 499				 19 * sizeof(u64));
 500	if (ret)
 501		return ret;
 502	/* Y */
 503	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 504				 &y,
 505				 19 * sizeof(u64),
 506				 20 * sizeof(u64));
 507	if (!ret)
 508		regs->y = y;
 509	return ret;
 510}
 511
 512static const struct user_regset ptrace64_regsets[] = {
 513	/* Format is:
 514	 *      G1 --> G7
 515	 *      O0 --> O7
 516	 *	0
 517	 *      TSTATE, TPC, TNPC, Y
 518	 */
 519	[REGSET_GENERAL] = {
 520		.n = 20, .size = sizeof(u64),
 521		.regset_get = getregs64_get, .set = setregs64_set,
 522	},
 523};
 524
 525static const struct user_regset_view ptrace64_view = {
 526	.regsets = ptrace64_regsets, .n = ARRAY_SIZE(ptrace64_regsets)
 527};
 528
 529static const struct user_regset_view user_sparc64_view = {
 530	.name = "sparc64", .e_machine = EM_SPARCV9,
 531	.regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
 532};
 533
 534#ifdef CONFIG_COMPAT
 535static int genregs32_get(struct task_struct *target,
 536			 const struct user_regset *regset,
 537			 struct membuf to)
 
 538{
 539	const struct pt_regs *regs = task_pt_regs(target);
 540	u32 uregs[16];
 541	int i;
 
 
 542
 543	if (target == current)
 544		flushw_user();
 545
 546	for (i = 0; i < 16; i++)
 547		membuf_store(&to, (u32)regs->u_regs[i]);
 548	if (!to.left)
 549		return 0;
 550	if (get_from_target(target, regs->u_regs[UREG_I6],
 551			    uregs, sizeof(uregs)))
 552		return -EFAULT;
 553	membuf_write(&to, uregs, 16 * sizeof(u32));
 554	membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
 555	membuf_store(&to, (u32)(regs->tpc));
 556	membuf_store(&to, (u32)(regs->tnpc));
 557	membuf_store(&to, (u32)(regs->y));
 558	return membuf_zero(&to, 2 * sizeof(u32));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 559}
 560
 561static int genregs32_set(struct task_struct *target,
 562			 const struct user_regset *regset,
 563			 unsigned int pos, unsigned int count,
 564			 const void *kbuf, const void __user *ubuf)
 565{
 566	struct pt_regs *regs = task_pt_regs(target);
 567	compat_ulong_t __user *reg_window;
 568	const compat_ulong_t *k = kbuf;
 569	const compat_ulong_t __user *u = ubuf;
 570	compat_ulong_t reg;
 571
 572	if (target == current)
 573		flushw_user();
 574
 575	pos /= sizeof(reg);
 576	count /= sizeof(reg);
 577
 578	if (kbuf) {
 579		for (; count > 0 && pos < 16; count--)
 580			regs->u_regs[pos++] = *k++;
 581
 582		reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
 583		reg_window -= 16;
 584		if (target == current) {
 585			for (; count > 0 && pos < 32; count--) {
 586				if (put_user(*k++, &reg_window[pos++]))
 587					return -EFAULT;
 588			}
 589		} else {
 590			for (; count > 0 && pos < 32; count--) {
 591				if (access_process_vm(target,
 592						      (unsigned long)
 593						      &reg_window[pos],
 594						      (void *) k,
 595						      sizeof(*k),
 596						      FOLL_FORCE | FOLL_WRITE)
 597				    != sizeof(*k))
 598					return -EFAULT;
 599				k++;
 600				pos++;
 601			}
 602		}
 603	} else {
 604		for (; count > 0 && pos < 16; count--) {
 605			if (get_user(reg, u++))
 606				return -EFAULT;
 607			regs->u_regs[pos++] = reg;
 608		}
 609
 610		reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
 611		reg_window -= 16;
 612		if (target == current) {
 613			for (; count > 0 && pos < 32; count--) {
 614				if (get_user(reg, u++) ||
 615				    put_user(reg, &reg_window[pos++]))
 616					return -EFAULT;
 617			}
 618		} else {
 619			for (; count > 0 && pos < 32; count--) {
 620				if (get_user(reg, u++))
 
 
 
 
 621					return -EFAULT;
 622				if (access_process_vm(target,
 623						      (unsigned long)
 624						      &reg_window[pos],
 625						      &reg, sizeof(reg),
 626						      FOLL_FORCE | FOLL_WRITE)
 627				    != sizeof(reg))
 628					return -EFAULT;
 629				pos++;
 630				u++;
 631			}
 632		}
 633	}
 634	while (count > 0) {
 635		unsigned long tstate;
 636
 637		if (kbuf)
 638			reg = *k++;
 639		else if (get_user(reg, u++))
 640			return -EFAULT;
 641
 642		switch (pos) {
 643		case 32: /* PSR */
 644			tstate = regs->tstate;
 645			tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 646			tstate |= psr_to_tstate_icc(reg);
 647			if (reg & PSR_SYSCALL)
 648				tstate |= TSTATE_SYSCALL;
 649			regs->tstate = tstate;
 650			break;
 651		case 33: /* PC */
 652			regs->tpc = reg;
 653			break;
 654		case 34: /* NPC */
 655			regs->tnpc = reg;
 656			break;
 657		case 35: /* Y */
 658			regs->y = reg;
 659			break;
 660		case 36: /* WIM */
 661		case 37: /* TBR */
 662			break;
 663		default:
 664			goto finish;
 665		}
 666
 667		pos++;
 668		count--;
 669	}
 670finish:
 671	pos *= sizeof(reg);
 672	count *= sizeof(reg);
 673
 674	return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 675					 38 * sizeof(reg), -1);
 676}
 677
 678static int fpregs32_get(struct task_struct *target,
 679			const struct user_regset *regset,
 680			struct membuf to)
 
 681{
 682	struct thread_info *t = task_thread_info(target);
 683	bool enabled;
 
 
 
 684
 685	if (target == current)
 686		save_and_clear_fpu();
 687
 688	enabled = t->fpsaved[0] & FPRS_FEF;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 689
 690	membuf_write(&to, t->fpregs, 32 * sizeof(u32));
 691	membuf_zero(&to, sizeof(u32));
 692	if (enabled)
 693		membuf_store(&to, (u32)t->xfsr[0]);
 694	else
 695		membuf_zero(&to, sizeof(u32));
 696	membuf_store(&to, (u32)((enabled << 8) | (8 << 16)));
 697	return membuf_zero(&to, 64 * sizeof(u32));
 
 
 
 
 698}
 699
 700static int fpregs32_set(struct task_struct *target,
 701			const struct user_regset *regset,
 702			unsigned int pos, unsigned int count,
 703			const void *kbuf, const void __user *ubuf)
 704{
 705	unsigned long *fpregs = task_thread_info(target)->fpregs;
 706	unsigned long fprs;
 707	int ret;
 708
 709	if (target == current)
 710		save_and_clear_fpu();
 711
 712	fprs = task_thread_info(target)->fpsaved[0];
 713
 714	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 715				 fpregs,
 716				 0, 32 * sizeof(u32));
 717	if (!ret)
 718		user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 719					  32 * sizeof(u32),
 720					  33 * sizeof(u32));
 721	if (!ret && count > 0) {
 722		compat_ulong_t fsr;
 723		unsigned long val;
 724
 725		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 726					 &fsr,
 727					 33 * sizeof(u32),
 728					 34 * sizeof(u32));
 729		if (!ret) {
 730			val = task_thread_info(target)->xfsr[0];
 731			val &= 0xffffffff00000000UL;
 732			val |= fsr;
 733			task_thread_info(target)->xfsr[0] = val;
 734		}
 735	}
 736
 737	fprs |= (FPRS_FEF | FPRS_DL);
 738	task_thread_info(target)->fpsaved[0] = fprs;
 739
 740	if (!ret)
 741		ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
 742						34 * sizeof(u32), -1);
 743	return ret;
 744}
 745
 746static const struct user_regset sparc32_regsets[] = {
 747	/* Format is:
 748	 * 	G0 --> G7
 749	 *	O0 --> O7
 750	 *	L0 --> L7
 751	 *	I0 --> I7
 752	 *	PSR, PC, nPC, Y, WIM, TBR
 753	 */
 754	[REGSET_GENERAL] = {
 755		.core_note_type = NT_PRSTATUS,
 756		.n = 38,
 757		.size = sizeof(u32), .align = sizeof(u32),
 758		.regset_get = genregs32_get, .set = genregs32_set
 759	},
 760	/* Format is:
 761	 *	F0 --> F31
 762	 *	empty 32-bit word
 763	 *	FSR (32--bit word)
 764	 *	FPU QUEUE COUNT (8-bit char)
 765	 *	FPU QUEUE ENTRYSIZE (8-bit char)
 766	 *	FPU ENABLED (8-bit char)
 767	 *	empty 8-bit char
 768	 *	FPU QUEUE (64 32-bit ints)
 769	 */
 770	[REGSET_FP] = {
 771		.core_note_type = NT_PRFPREG,
 772		.n = 99,
 773		.size = sizeof(u32), .align = sizeof(u32),
 774		.regset_get = fpregs32_get, .set = fpregs32_set
 775	},
 776};
 777
 778static int getregs_get(struct task_struct *target,
 779			 const struct user_regset *regset,
 780			 struct membuf to)
 781{
 782	const struct pt_regs *regs = task_pt_regs(target);
 783	int i;
 784
 785	if (target == current)
 786		flushw_user();
 787
 788	membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
 789	membuf_store(&to, (u32)(regs->tpc));
 790	membuf_store(&to, (u32)(regs->tnpc));
 791	membuf_store(&to, (u32)(regs->y));
 792	for (i = 1; i < 16; i++)
 793		membuf_store(&to, (u32)regs->u_regs[i]);
 794	return to.left;
 795}
 796
 797static int setregs_set(struct task_struct *target,
 798			 const struct user_regset *regset,
 799			 unsigned int pos, unsigned int count,
 800			 const void *kbuf, const void __user *ubuf)
 801{
 802	struct pt_regs *regs = task_pt_regs(target);
 803	unsigned long tstate;
 804	u32 uregs[19];
 805	int i, ret;
 806
 807	if (target == current)
 808		flushw_user();
 809
 810	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 811				 uregs,
 812				 0, 19 * sizeof(u32));
 813	if (ret)
 814		return ret;
 815
 816	tstate = regs->tstate;
 817	tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
 818	tstate |= psr_to_tstate_icc(uregs[0]);
 819	if (uregs[0] & PSR_SYSCALL)
 820		tstate |= TSTATE_SYSCALL;
 821	regs->tstate = tstate;
 822	regs->tpc = uregs[1];
 823	regs->tnpc = uregs[2];
 824	regs->y = uregs[3];
 825
 826	for (i = 1; i < 15; i++)
 827		regs->u_regs[i] = uregs[3 + i];
 828	return 0;
 829}
 830
 831static int getfpregs_get(struct task_struct *target,
 832			const struct user_regset *regset,
 833			struct membuf to)
 834{
 835	struct thread_info *t = task_thread_info(target);
 836
 837	if (target == current)
 838		save_and_clear_fpu();
 839
 840	membuf_write(&to, t->fpregs, 32 * sizeof(u32));
 841	if (t->fpsaved[0] & FPRS_FEF)
 842		membuf_store(&to, (u32)t->xfsr[0]);
 843	else
 844		membuf_zero(&to, sizeof(u32));
 845	return membuf_zero(&to, 35 * sizeof(u32));
 846}
 847
 848static int setfpregs_set(struct task_struct *target,
 849			const struct user_regset *regset,
 850			unsigned int pos, unsigned int count,
 851			const void *kbuf, const void __user *ubuf)
 852{
 853	unsigned long *fpregs = task_thread_info(target)->fpregs;
 854	unsigned long fprs;
 855	int ret;
 856
 857	if (target == current)
 858		save_and_clear_fpu();
 859
 860	fprs = task_thread_info(target)->fpsaved[0];
 861
 862	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 863				 fpregs,
 864				 0, 32 * sizeof(u32));
 865	if (!ret) {
 866		compat_ulong_t fsr;
 867		unsigned long val;
 868
 869		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
 870					 &fsr,
 871					 32 * sizeof(u32),
 872					 33 * sizeof(u32));
 873		if (!ret) {
 874			val = task_thread_info(target)->xfsr[0];
 875			val &= 0xffffffff00000000UL;
 876			val |= fsr;
 877			task_thread_info(target)->xfsr[0] = val;
 878		}
 879	}
 880
 881	fprs |= (FPRS_FEF | FPRS_DL);
 882	task_thread_info(target)->fpsaved[0] = fprs;
 883	return ret;
 884}
 885
 886static const struct user_regset ptrace32_regsets[] = {
 887	[REGSET_GENERAL] = {
 888		.n = 19, .size = sizeof(u32),
 889		.regset_get = getregs_get, .set = setregs_set,
 890	},
 891	[REGSET_FP] = {
 892		.n = 68, .size = sizeof(u32),
 893		.regset_get = getfpregs_get, .set = setfpregs_set,
 894	},
 895};
 896
 897static const struct user_regset_view ptrace32_view = {
 898	.regsets = ptrace32_regsets, .n = ARRAY_SIZE(ptrace32_regsets)
 899};
 900
 901static const struct user_regset_view user_sparc32_view = {
 902	.name = "sparc", .e_machine = EM_SPARC,
 903	.regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
 904};
 905#endif /* CONFIG_COMPAT */
 906
 907const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 908{
 909#ifdef CONFIG_COMPAT
 910	if (test_tsk_thread_flag(task, TIF_32BIT))
 911		return &user_sparc32_view;
 912#endif
 913	return &user_sparc64_view;
 914}
 915
 916#ifdef CONFIG_COMPAT
 917struct compat_fps {
 918	unsigned int regs[32];
 919	unsigned int fsr;
 920	unsigned int flags;
 921	unsigned int extra;
 922	unsigned int fpqd;
 923	struct compat_fq {
 924		unsigned int insnaddr;
 925		unsigned int insn;
 926	} fpq[16];
 927};
 928
 929long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
 930			compat_ulong_t caddr, compat_ulong_t cdata)
 931{
 
 932	compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
 933	struct pt_regs32 __user *pregs;
 934	struct compat_fps __user *fps;
 935	unsigned long addr2 = caddr2;
 936	unsigned long addr = caddr;
 937	unsigned long data = cdata;
 938	int ret;
 939
 940	pregs = (struct pt_regs32 __user *) addr;
 941	fps = (struct compat_fps __user *) addr;
 942
 943	switch (request) {
 944	case PTRACE_PEEKUSR:
 945		ret = (addr != 0) ? -EIO : 0;
 946		break;
 947
 948	case PTRACE_GETREGS:
 949		ret = copy_regset_to_user(child, &ptrace32_view,
 950					  REGSET_GENERAL, 0,
 951					  19 * sizeof(u32),
 952					  pregs);
 
 
 
 
 
 953		break;
 954
 955	case PTRACE_SETREGS:
 956		ret = copy_regset_from_user(child, &ptrace32_view,
 957					  REGSET_GENERAL, 0,
 958					  19 * sizeof(u32),
 959					  pregs);
 
 
 
 
 
 960		break;
 961
 962	case PTRACE_GETFPREGS:
 963		ret = copy_regset_to_user(child, &ptrace32_view,
 964					  REGSET_FP, 0,
 965					  68 * sizeof(u32),
 966					  fps);
 
 
 
 
 
 
 
 
 
 
 
 
 967		break;
 968
 969	case PTRACE_SETFPREGS:
 970		ret = copy_regset_from_user(child, &ptrace32_view,
 971					  REGSET_FP, 0,
 972					  33 * sizeof(u32),
 973					  fps);
 
 
 
 
 
 974		break;
 975
 976	case PTRACE_READTEXT:
 977	case PTRACE_READDATA:
 978		ret = ptrace_readdata(child, addr,
 979				      (char __user *)addr2, data);
 980		if (ret == data)
 981			ret = 0;
 982		else if (ret >= 0)
 983			ret = -EIO;
 984		break;
 985
 986	case PTRACE_WRITETEXT:
 987	case PTRACE_WRITEDATA:
 988		ret = ptrace_writedata(child, (char __user *) addr2,
 989				       addr, data);
 990		if (ret == data)
 991			ret = 0;
 992		else if (ret >= 0)
 993			ret = -EIO;
 994		break;
 995
 996	default:
 997		if (request == PTRACE_SPARC_DETACH)
 998			request = PTRACE_DETACH;
 999		ret = compat_ptrace_request(child, request, addr, data);
1000		break;
1001	}
1002
1003	return ret;
1004}
1005#endif /* CONFIG_COMPAT */
1006
1007struct fps {
1008	unsigned int regs[64];
1009	unsigned long fsr;
1010};
1011
1012long arch_ptrace(struct task_struct *child, long request,
1013		 unsigned long addr, unsigned long data)
1014{
1015	const struct user_regset_view *view = task_user_regset_view(current);
1016	unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
1017	struct pt_regs __user *pregs;
1018	struct fps __user *fps;
1019	void __user *addr2p;
1020	int ret;
1021
1022	pregs = (struct pt_regs __user *) addr;
1023	fps = (struct fps __user *) addr;
1024	addr2p = (void __user *) addr2;
1025
1026	switch (request) {
1027	case PTRACE_PEEKUSR:
1028		ret = (addr != 0) ? -EIO : 0;
1029		break;
1030
1031	case PTRACE_GETREGS64:
1032		ret = copy_regset_to_user(child, &ptrace64_view,
1033					  REGSET_GENERAL, 0,
1034					  19 * sizeof(u64),
1035					  pregs);
 
 
 
 
 
 
 
1036		break;
1037
1038	case PTRACE_SETREGS64:
1039		ret = copy_regset_from_user(child, &ptrace64_view,
1040					  REGSET_GENERAL, 0,
1041					  19 * sizeof(u64),
1042					  pregs);
 
 
 
 
 
 
 
1043		break;
1044
1045	case PTRACE_GETFPREGS64:
1046		ret = copy_regset_to_user(child, view, REGSET_FP,
1047					  0 * sizeof(u64),
1048					  33 * sizeof(u64),
1049					  fps);
1050		break;
1051
1052	case PTRACE_SETFPREGS64:
1053		ret = copy_regset_from_user(child, view, REGSET_FP,
1054					  0 * sizeof(u64),
1055					  33 * sizeof(u64),
1056					  fps);
1057		break;
1058
1059	case PTRACE_READTEXT:
1060	case PTRACE_READDATA:
1061		ret = ptrace_readdata(child, addr, addr2p, data);
1062		if (ret == data)
1063			ret = 0;
1064		else if (ret >= 0)
1065			ret = -EIO;
1066		break;
1067
1068	case PTRACE_WRITETEXT:
1069	case PTRACE_WRITEDATA:
1070		ret = ptrace_writedata(child, addr2p, addr, data);
1071		if (ret == data)
1072			ret = 0;
1073		else if (ret >= 0)
1074			ret = -EIO;
1075		break;
1076
1077	default:
1078		if (request == PTRACE_SPARC_DETACH)
1079			request = PTRACE_DETACH;
1080		ret = ptrace_request(child, request, addr, data);
1081		break;
1082	}
1083
1084	return ret;
1085}
1086
1087asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1088{
1089	int ret = 0;
1090
1091	/* do the secure computing check first */
1092	secure_computing_strict(regs->u_regs[UREG_G1]);
1093
1094	if (test_thread_flag(TIF_NOHZ))
1095		user_exit();
1096
1097	if (test_thread_flag(TIF_SYSCALL_TRACE))
1098		ret = tracehook_report_syscall_entry(regs);
1099
1100	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1101		trace_sys_enter(regs, regs->u_regs[UREG_G1]);
1102
1103	audit_syscall_entry(regs->u_regs[UREG_G1], regs->u_regs[UREG_I0],
1104			    regs->u_regs[UREG_I1], regs->u_regs[UREG_I2],
1105			    regs->u_regs[UREG_I3]);
 
 
 
 
 
 
1106
1107	return ret;
1108}
1109
1110asmlinkage void syscall_trace_leave(struct pt_regs *regs)
1111{
1112	if (test_thread_flag(TIF_NOHZ))
1113		user_exit();
 
 
1114
1115	audit_syscall_exit(regs);
 
1116
 
 
 
1117	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1118		trace_sys_exit(regs, regs->u_regs[UREG_I0]);
1119
1120	if (test_thread_flag(TIF_SYSCALL_TRACE))
1121		tracehook_report_syscall_exit(regs, 0);
1122
1123	if (test_thread_flag(TIF_NOHZ))
1124		user_enter();
1125}
1126
1127/**
1128 * regs_query_register_offset() - query register offset from its name
1129 * @name:	the name of a register
1130 *
1131 * regs_query_register_offset() returns the offset of a register in struct
1132 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
1133 */
1134int regs_query_register_offset(const char *name)
1135{
1136	const struct pt_regs_offset *roff;
1137
1138	for (roff = regoffset_table; roff->name != NULL; roff++)
1139		if (!strcmp(roff->name, name))
1140			return roff->offset;
1141	return -EINVAL;
1142}
1143
1144/**
1145 * regs_within_kernel_stack() - check the address in the stack
1146 * @regs:	pt_regs which contains kernel stack pointer.
1147 * @addr:	address which is checked.
1148 *
1149 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
1150 * If @addr is within the kernel stack, it returns true. If not, returns false.
1151 */
1152static inline int regs_within_kernel_stack(struct pt_regs *regs,
1153					   unsigned long addr)
1154{
1155	unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1156	return ((addr & ~(THREAD_SIZE - 1))  ==
1157		(ksp & ~(THREAD_SIZE - 1)));
1158}
1159
1160/**
1161 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1162 * @regs:	pt_regs which contains kernel stack pointer.
1163 * @n:		stack entry number.
1164 *
1165 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1166 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
1167 * this returns 0.
1168 */
1169unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1170{
1171	unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1172	unsigned long *addr = (unsigned long *)ksp;
1173	addr += n;
1174	if (regs_within_kernel_stack(regs, (unsigned long)addr))
1175		return *addr;
1176	else
1177		return 0;
1178}