• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Kernel support for the ptrace() and syscall tracing interfaces.
4  *
5  * Copyright (C) 2000 Hewlett-Packard Co, Linuxcare Inc.
6  * Copyright (C) 2000 Matthew Wilcox <matthew@wil.cx>
7  * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
8  * Copyright (C) 2008-2016 Helge Deller <deller@gmx.de>
9  */
10 
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/smp.h>
15 #include <linux/elf.h>
16 #include <linux/errno.h>
17 #include <linux/ptrace.h>
18 #include <linux/tracehook.h>
19 #include <linux/user.h>
20 #include <linux/personality.h>
21 #include <linux/regset.h>
22 #include <linux/security.h>
23 #include <linux/seccomp.h>
24 #include <linux/compat.h>
25 #include <linux/signal.h>
26 #include <linux/audit.h>
27 
28 #include <linux/uaccess.h>
29 #include <asm/pgtable.h>
30 #include <asm/processor.h>
31 #include <asm/asm-offsets.h>
32 
33 /* PSW bits we allow the debugger to modify */
34 #define USER_PSW_BITS	(PSW_N | PSW_B | PSW_V | PSW_CB)
35 
36 #define CREATE_TRACE_POINTS
37 #include <trace/events/syscalls.h>
38 
39 /*
40  * These are our native regset flavors.
41  */
42 enum parisc_regset {
43 	REGSET_GENERAL,
44 	REGSET_FP
45 };
46 
47 /*
48  * Called by kernel/ptrace.c when detaching..
49  *
50  * Make sure single step bits etc are not set.
51  */
ptrace_disable(struct task_struct * task)52 void ptrace_disable(struct task_struct *task)
53 {
54 	clear_tsk_thread_flag(task, TIF_SINGLESTEP);
55 	clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
56 
57 	/* make sure the trap bits are not set */
58 	pa_psw(task)->r = 0;
59 	pa_psw(task)->t = 0;
60 	pa_psw(task)->h = 0;
61 	pa_psw(task)->l = 0;
62 }
63 
64 /*
65  * The following functions are called by ptrace_resume() when
66  * enabling or disabling single/block tracing.
67  */
user_disable_single_step(struct task_struct * task)68 void user_disable_single_step(struct task_struct *task)
69 {
70 	ptrace_disable(task);
71 }
72 
user_enable_single_step(struct task_struct * task)73 void user_enable_single_step(struct task_struct *task)
74 {
75 	clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
76 	set_tsk_thread_flag(task, TIF_SINGLESTEP);
77 
78 	if (pa_psw(task)->n) {
79 		struct siginfo si;
80 
81 		/* Nullified, just crank over the queue. */
82 		task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1];
83 		task_regs(task)->iasq[0] = task_regs(task)->iasq[1];
84 		task_regs(task)->iaoq[1] = task_regs(task)->iaoq[0] + 4;
85 		pa_psw(task)->n = 0;
86 		pa_psw(task)->x = 0;
87 		pa_psw(task)->y = 0;
88 		pa_psw(task)->z = 0;
89 		pa_psw(task)->b = 0;
90 		ptrace_disable(task);
91 		/* Don't wake up the task, but let the
92 		   parent know something happened. */
93 		si.si_code = TRAP_TRACE;
94 		si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3);
95 		si.si_signo = SIGTRAP;
96 		si.si_errno = 0;
97 		force_sig_info(SIGTRAP, &si, task);
98 		/* notify_parent(task, SIGCHLD); */
99 		return;
100 	}
101 
102 	/* Enable recovery counter traps.  The recovery counter
103 	 * itself will be set to zero on a task switch.  If the
104 	 * task is suspended on a syscall then the syscall return
105 	 * path will overwrite the recovery counter with a suitable
106 	 * value such that it traps once back in user space.  We
107 	 * disable interrupts in the tasks PSW here also, to avoid
108 	 * interrupts while the recovery counter is decrementing.
109 	 */
110 	pa_psw(task)->r = 1;
111 	pa_psw(task)->t = 0;
112 	pa_psw(task)->h = 0;
113 	pa_psw(task)->l = 0;
114 }
115 
user_enable_block_step(struct task_struct * task)116 void user_enable_block_step(struct task_struct *task)
117 {
118 	clear_tsk_thread_flag(task, TIF_SINGLESTEP);
119 	set_tsk_thread_flag(task, TIF_BLOCKSTEP);
120 
121 	/* Enable taken branch trap. */
122 	pa_psw(task)->r = 0;
123 	pa_psw(task)->t = 1;
124 	pa_psw(task)->h = 0;
125 	pa_psw(task)->l = 0;
126 }
127 
arch_ptrace(struct task_struct * child,long request,unsigned long addr,unsigned long data)128 long arch_ptrace(struct task_struct *child, long request,
129 		 unsigned long addr, unsigned long data)
130 {
131 	unsigned long __user *datap = (unsigned long __user *)data;
132 	unsigned long tmp;
133 	long ret = -EIO;
134 
135 	switch (request) {
136 
137 	/* Read the word at location addr in the USER area.  For ptraced
138 	   processes, the kernel saves all regs on a syscall. */
139 	case PTRACE_PEEKUSR:
140 		if ((addr & (sizeof(unsigned long)-1)) ||
141 		     addr >= sizeof(struct pt_regs))
142 			break;
143 		tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
144 		ret = put_user(tmp, datap);
145 		break;
146 
147 	/* Write the word at location addr in the USER area.  This will need
148 	   to change when the kernel no longer saves all regs on a syscall.
149 	   FIXME.  There is a problem at the moment in that r3-r18 are only
150 	   saved if the process is ptraced on syscall entry, and even then
151 	   those values are overwritten by actual register values on syscall
152 	   exit. */
153 	case PTRACE_POKEUSR:
154 		/* Some register values written here may be ignored in
155 		 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
156 		 * r31/r31+4, and not with the values in pt_regs.
157 		 */
158 		if (addr == PT_PSW) {
159 			/* Allow writing to Nullify, Divide-step-correction,
160 			 * and carry/borrow bits.
161 			 * BEWARE, if you set N, and then single step, it won't
162 			 * stop on the nullified instruction.
163 			 */
164 			data &= USER_PSW_BITS;
165 			task_regs(child)->gr[0] &= ~USER_PSW_BITS;
166 			task_regs(child)->gr[0] |= data;
167 			ret = 0;
168 			break;
169 		}
170 
171 		if ((addr & (sizeof(unsigned long)-1)) ||
172 		     addr >= sizeof(struct pt_regs))
173 			break;
174 		if (addr == PT_IAOQ0 || addr == PT_IAOQ1) {
175 			data |= 3; /* ensure userspace privilege */
176 		}
177 		if ((addr >= PT_GR1 && addr <= PT_GR31) ||
178 				addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
179 				(addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
180 				addr == PT_SAR) {
181 			*(unsigned long *) ((char *) task_regs(child) + addr) = data;
182 			ret = 0;
183 		}
184 		break;
185 
186 	case PTRACE_GETREGS:	/* Get all gp regs from the child. */
187 		return copy_regset_to_user(child,
188 					   task_user_regset_view(current),
189 					   REGSET_GENERAL,
190 					   0, sizeof(struct user_regs_struct),
191 					   datap);
192 
193 	case PTRACE_SETREGS:	/* Set all gp regs in the child. */
194 		return copy_regset_from_user(child,
195 					     task_user_regset_view(current),
196 					     REGSET_GENERAL,
197 					     0, sizeof(struct user_regs_struct),
198 					     datap);
199 
200 	case PTRACE_GETFPREGS:	/* Get the child FPU state. */
201 		return copy_regset_to_user(child,
202 					   task_user_regset_view(current),
203 					   REGSET_FP,
204 					   0, sizeof(struct user_fp_struct),
205 					   datap);
206 
207 	case PTRACE_SETFPREGS:	/* Set the child FPU state. */
208 		return copy_regset_from_user(child,
209 					     task_user_regset_view(current),
210 					     REGSET_FP,
211 					     0, sizeof(struct user_fp_struct),
212 					     datap);
213 
214 	default:
215 		ret = ptrace_request(child, request, addr, data);
216 		break;
217 	}
218 
219 	return ret;
220 }
221 
222 
223 #ifdef CONFIG_COMPAT
224 
225 /* This function is needed to translate 32 bit pt_regs offsets in to
226  * 64 bit pt_regs offsets.  For example, a 32 bit gdb under a 64 bit kernel
227  * will request offset 12 if it wants gr3, but the lower 32 bits of
228  * the 64 bit kernels view of gr3 will be at offset 28 (3*8 + 4).
229  * This code relies on a 32 bit pt_regs being comprised of 32 bit values
230  * except for the fp registers which (a) are 64 bits, and (b) follow
231  * the gr registers at the start of pt_regs.  The 32 bit pt_regs should
232  * be half the size of the 64 bit pt_regs, plus 32*4 to allow for fr[]
233  * being 64 bit in both cases.
234  */
235 
translate_usr_offset(compat_ulong_t offset)236 static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
237 {
238 	compat_ulong_t pos;
239 
240 	if (offset < 32*4)	/* gr[0..31] */
241 		pos = offset * 2 + 4;
242 	else if (offset < 32*4+32*8)	/* fr[0] ... fr[31] */
243 		pos = (offset - 32*4) + PT_FR0;
244 	else if (offset < sizeof(struct pt_regs)/2 + 32*4) /* sr[0] ... ipsw */
245 		pos = (offset - 32*4 - 32*8) * 2 + PT_SR0 + 4;
246 	else
247 		pos = sizeof(struct pt_regs);
248 
249 	return pos;
250 }
251 
compat_arch_ptrace(struct task_struct * child,compat_long_t request,compat_ulong_t addr,compat_ulong_t data)252 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
253 			compat_ulong_t addr, compat_ulong_t data)
254 {
255 	compat_uint_t tmp;
256 	long ret = -EIO;
257 
258 	switch (request) {
259 
260 	case PTRACE_PEEKUSR:
261 		if (addr & (sizeof(compat_uint_t)-1))
262 			break;
263 		addr = translate_usr_offset(addr);
264 		if (addr >= sizeof(struct pt_regs))
265 			break;
266 
267 		tmp = *(compat_uint_t *) ((char *) task_regs(child) + addr);
268 		ret = put_user(tmp, (compat_uint_t *) (unsigned long) data);
269 		break;
270 
271 	/* Write the word at location addr in the USER area.  This will need
272 	   to change when the kernel no longer saves all regs on a syscall.
273 	   FIXME.  There is a problem at the moment in that r3-r18 are only
274 	   saved if the process is ptraced on syscall entry, and even then
275 	   those values are overwritten by actual register values on syscall
276 	   exit. */
277 	case PTRACE_POKEUSR:
278 		/* Some register values written here may be ignored in
279 		 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
280 		 * r31/r31+4, and not with the values in pt_regs.
281 		 */
282 		if (addr == PT_PSW) {
283 			/* Since PT_PSW==0, it is valid for 32 bit processes
284 			 * under 64 bit kernels as well.
285 			 */
286 			ret = arch_ptrace(child, request, addr, data);
287 		} else {
288 			if (addr & (sizeof(compat_uint_t)-1))
289 				break;
290 			addr = translate_usr_offset(addr);
291 			if (addr >= sizeof(struct pt_regs))
292 				break;
293 			if (addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4) {
294 				data |= 3; /* ensure userspace privilege */
295 			}
296 			if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
297 				/* Special case, fp regs are 64 bits anyway */
298 				*(__u32 *) ((char *) task_regs(child) + addr) = data;
299 				ret = 0;
300 			}
301 			else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||
302 					addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4 ||
303 					addr == PT_SAR+4) {
304 				/* Zero the top 32 bits */
305 				*(__u32 *) ((char *) task_regs(child) + addr - 4) = 0;
306 				*(__u32 *) ((char *) task_regs(child) + addr) = data;
307 				ret = 0;
308 			}
309 		}
310 		break;
311 
312 	default:
313 		ret = compat_ptrace_request(child, request, addr, data);
314 		break;
315 	}
316 
317 	return ret;
318 }
319 #endif
320 
do_syscall_trace_enter(struct pt_regs * regs)321 long do_syscall_trace_enter(struct pt_regs *regs)
322 {
323 	if (test_thread_flag(TIF_SYSCALL_TRACE)) {
324 		int rc = tracehook_report_syscall_entry(regs);
325 
326 		/*
327 		 * As tracesys_next does not set %r28 to -ENOSYS
328 		 * when %r20 is set to -1, initialize it here.
329 		 */
330 		regs->gr[28] = -ENOSYS;
331 
332 		if (rc) {
333 			/*
334 			 * A nonzero return code from
335 			 * tracehook_report_syscall_entry() tells us
336 			 * to prevent the syscall execution.  Skip
337 			 * the syscall call and the syscall restart handling.
338 			 *
339 			 * Note that the tracer may also just change
340 			 * regs->gr[20] to an invalid syscall number,
341 			 * that is handled by tracesys_next.
342 			 */
343 			regs->gr[20] = -1UL;
344 			return -1;
345 		}
346 	}
347 
348 	/* Do the secure computing check after ptrace. */
349 	if (secure_computing(NULL) == -1)
350 		return -1;
351 
352 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
353 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
354 		trace_sys_enter(regs, regs->gr[20]);
355 #endif
356 
357 #ifdef CONFIG_64BIT
358 	if (!is_compat_task())
359 		audit_syscall_entry(regs->gr[20], regs->gr[26], regs->gr[25],
360 				    regs->gr[24], regs->gr[23]);
361 	else
362 #endif
363 		audit_syscall_entry(regs->gr[20] & 0xffffffff,
364 			regs->gr[26] & 0xffffffff,
365 			regs->gr[25] & 0xffffffff,
366 			regs->gr[24] & 0xffffffff,
367 			regs->gr[23] & 0xffffffff);
368 
369 	/*
370 	 * Sign extend the syscall number to 64bit since it may have been
371 	 * modified by a compat ptrace call
372 	 */
373 	return (int) ((u32) regs->gr[20]);
374 }
375 
do_syscall_trace_exit(struct pt_regs * regs)376 void do_syscall_trace_exit(struct pt_regs *regs)
377 {
378 	int stepping = test_thread_flag(TIF_SINGLESTEP) ||
379 		test_thread_flag(TIF_BLOCKSTEP);
380 
381 	audit_syscall_exit(regs);
382 
383 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
384 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
385 		trace_sys_exit(regs, regs->gr[20]);
386 #endif
387 
388 	if (stepping || test_thread_flag(TIF_SYSCALL_TRACE))
389 		tracehook_report_syscall_exit(regs, stepping);
390 }
391 
392 
393 /*
394  * regset functions.
395  */
396 
fpr_get(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,void * kbuf,void __user * ubuf)397 static int fpr_get(struct task_struct *target,
398 		     const struct user_regset *regset,
399 		     unsigned int pos, unsigned int count,
400 		     void *kbuf, void __user *ubuf)
401 {
402 	struct pt_regs *regs = task_regs(target);
403 	__u64 *k = kbuf;
404 	__u64 __user *u = ubuf;
405 	__u64 reg;
406 
407 	pos /= sizeof(reg);
408 	count /= sizeof(reg);
409 
410 	if (kbuf)
411 		for (; count > 0 && pos < ELF_NFPREG; --count)
412 			*k++ = regs->fr[pos++];
413 	else
414 		for (; count > 0 && pos < ELF_NFPREG; --count)
415 			if (__put_user(regs->fr[pos++], u++))
416 				return -EFAULT;
417 
418 	kbuf = k;
419 	ubuf = u;
420 	pos *= sizeof(reg);
421 	count *= sizeof(reg);
422 	return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
423 					ELF_NFPREG * sizeof(reg), -1);
424 }
425 
fpr_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)426 static int fpr_set(struct task_struct *target,
427 		     const struct user_regset *regset,
428 		     unsigned int pos, unsigned int count,
429 		     const void *kbuf, const void __user *ubuf)
430 {
431 	struct pt_regs *regs = task_regs(target);
432 	const __u64 *k = kbuf;
433 	const __u64 __user *u = ubuf;
434 	__u64 reg;
435 
436 	pos /= sizeof(reg);
437 	count /= sizeof(reg);
438 
439 	if (kbuf)
440 		for (; count > 0 && pos < ELF_NFPREG; --count)
441 			regs->fr[pos++] = *k++;
442 	else
443 		for (; count > 0 && pos < ELF_NFPREG; --count) {
444 			if (__get_user(reg, u++))
445 				return -EFAULT;
446 			regs->fr[pos++] = reg;
447 		}
448 
449 	kbuf = k;
450 	ubuf = u;
451 	pos *= sizeof(reg);
452 	count *= sizeof(reg);
453 	return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
454 					 ELF_NFPREG * sizeof(reg), -1);
455 }
456 
457 #define RI(reg) (offsetof(struct user_regs_struct,reg) / sizeof(long))
458 
get_reg(struct pt_regs * regs,int num)459 static unsigned long get_reg(struct pt_regs *regs, int num)
460 {
461 	switch (num) {
462 	case RI(gr[0]) ... RI(gr[31]):	return regs->gr[num - RI(gr[0])];
463 	case RI(sr[0]) ... RI(sr[7]):	return regs->sr[num - RI(sr[0])];
464 	case RI(iasq[0]):		return regs->iasq[0];
465 	case RI(iasq[1]):		return regs->iasq[1];
466 	case RI(iaoq[0]):		return regs->iaoq[0];
467 	case RI(iaoq[1]):		return regs->iaoq[1];
468 	case RI(sar):			return regs->sar;
469 	case RI(iir):			return regs->iir;
470 	case RI(isr):			return regs->isr;
471 	case RI(ior):			return regs->ior;
472 	case RI(ipsw):			return regs->ipsw;
473 	case RI(cr27):			return regs->cr27;
474 	case RI(cr0):			return mfctl(0);
475 	case RI(cr24):			return mfctl(24);
476 	case RI(cr25):			return mfctl(25);
477 	case RI(cr26):			return mfctl(26);
478 	case RI(cr28):			return mfctl(28);
479 	case RI(cr29):			return mfctl(29);
480 	case RI(cr30):			return mfctl(30);
481 	case RI(cr31):			return mfctl(31);
482 	case RI(cr8):			return mfctl(8);
483 	case RI(cr9):			return mfctl(9);
484 	case RI(cr12):			return mfctl(12);
485 	case RI(cr13):			return mfctl(13);
486 	case RI(cr10):			return mfctl(10);
487 	case RI(cr15):			return mfctl(15);
488 	default:			return 0;
489 	}
490 }
491 
set_reg(struct pt_regs * regs,int num,unsigned long val)492 static void set_reg(struct pt_regs *regs, int num, unsigned long val)
493 {
494 	switch (num) {
495 	case RI(gr[0]): /*
496 			 * PSW is in gr[0].
497 			 * Allow writing to Nullify, Divide-step-correction,
498 			 * and carry/borrow bits.
499 			 * BEWARE, if you set N, and then single step, it won't
500 			 * stop on the nullified instruction.
501 			 */
502 			val &= USER_PSW_BITS;
503 			regs->gr[0] &= ~USER_PSW_BITS;
504 			regs->gr[0] |= val;
505 			return;
506 	case RI(gr[1]) ... RI(gr[31]):
507 			regs->gr[num - RI(gr[0])] = val;
508 			return;
509 	case RI(iaoq[0]):
510 	case RI(iaoq[1]):
511 			/* set 2 lowest bits to ensure userspace privilege: */
512 			regs->iaoq[num - RI(iaoq[0])] = val | 3;
513 			return;
514 	case RI(sar):	regs->sar = val;
515 			return;
516 	default:	return;
517 #if 0
518 	/* do not allow to change any of the following registers (yet) */
519 	case RI(sr[0]) ... RI(sr[7]):	return regs->sr[num - RI(sr[0])];
520 	case RI(iasq[0]):		return regs->iasq[0];
521 	case RI(iasq[1]):		return regs->iasq[1];
522 	case RI(iir):			return regs->iir;
523 	case RI(isr):			return regs->isr;
524 	case RI(ior):			return regs->ior;
525 	case RI(ipsw):			return regs->ipsw;
526 	case RI(cr27):			return regs->cr27;
527         case cr0, cr24, cr25, cr26, cr27, cr28, cr29, cr30, cr31;
528         case cr8, cr9, cr12, cr13, cr10, cr15;
529 #endif
530 	}
531 }
532 
gpr_get(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,void * kbuf,void __user * ubuf)533 static int gpr_get(struct task_struct *target,
534 		     const struct user_regset *regset,
535 		     unsigned int pos, unsigned int count,
536 		     void *kbuf, void __user *ubuf)
537 {
538 	struct pt_regs *regs = task_regs(target);
539 	unsigned long *k = kbuf;
540 	unsigned long __user *u = ubuf;
541 	unsigned long reg;
542 
543 	pos /= sizeof(reg);
544 	count /= sizeof(reg);
545 
546 	if (kbuf)
547 		for (; count > 0 && pos < ELF_NGREG; --count)
548 			*k++ = get_reg(regs, pos++);
549 	else
550 		for (; count > 0 && pos < ELF_NGREG; --count)
551 			if (__put_user(get_reg(regs, pos++), u++))
552 				return -EFAULT;
553 	kbuf = k;
554 	ubuf = u;
555 	pos *= sizeof(reg);
556 	count *= sizeof(reg);
557 	return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
558 					ELF_NGREG * sizeof(reg), -1);
559 }
560 
gpr_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)561 static int gpr_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_regs(target);
567 	const unsigned long *k = kbuf;
568 	const unsigned long __user *u = ubuf;
569 	unsigned long reg;
570 
571 	pos /= sizeof(reg);
572 	count /= sizeof(reg);
573 
574 	if (kbuf)
575 		for (; count > 0 && pos < ELF_NGREG; --count)
576 			set_reg(regs, pos++, *k++);
577 	else
578 		for (; count > 0 && pos < ELF_NGREG; --count) {
579 			if (__get_user(reg, u++))
580 				return -EFAULT;
581 			set_reg(regs, pos++, reg);
582 		}
583 
584 	kbuf = k;
585 	ubuf = u;
586 	pos *= sizeof(reg);
587 	count *= sizeof(reg);
588 	return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
589 					 ELF_NGREG * sizeof(reg), -1);
590 }
591 
592 static const struct user_regset native_regsets[] = {
593 	[REGSET_GENERAL] = {
594 		.core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
595 		.size = sizeof(long), .align = sizeof(long),
596 		.get = gpr_get, .set = gpr_set
597 	},
598 	[REGSET_FP] = {
599 		.core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
600 		.size = sizeof(__u64), .align = sizeof(__u64),
601 		.get = fpr_get, .set = fpr_set
602 	}
603 };
604 
605 static const struct user_regset_view user_parisc_native_view = {
606 	.name = "parisc", .e_machine = ELF_ARCH, .ei_osabi = ELFOSABI_LINUX,
607 	.regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
608 };
609 
610 #ifdef CONFIG_64BIT
611 #include <linux/compat.h>
612 
gpr32_get(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,void * kbuf,void __user * ubuf)613 static int gpr32_get(struct task_struct *target,
614 		     const struct user_regset *regset,
615 		     unsigned int pos, unsigned int count,
616 		     void *kbuf, void __user *ubuf)
617 {
618 	struct pt_regs *regs = task_regs(target);
619 	compat_ulong_t *k = kbuf;
620 	compat_ulong_t __user *u = ubuf;
621 	compat_ulong_t reg;
622 
623 	pos /= sizeof(reg);
624 	count /= sizeof(reg);
625 
626 	if (kbuf)
627 		for (; count > 0 && pos < ELF_NGREG; --count)
628 			*k++ = get_reg(regs, pos++);
629 	else
630 		for (; count > 0 && pos < ELF_NGREG; --count)
631 			if (__put_user((compat_ulong_t) get_reg(regs, pos++), u++))
632 				return -EFAULT;
633 
634 	kbuf = k;
635 	ubuf = u;
636 	pos *= sizeof(reg);
637 	count *= sizeof(reg);
638 	return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
639 					ELF_NGREG * sizeof(reg), -1);
640 }
641 
gpr32_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)642 static int gpr32_set(struct task_struct *target,
643 		     const struct user_regset *regset,
644 		     unsigned int pos, unsigned int count,
645 		     const void *kbuf, const void __user *ubuf)
646 {
647 	struct pt_regs *regs = task_regs(target);
648 	const compat_ulong_t *k = kbuf;
649 	const compat_ulong_t __user *u = ubuf;
650 	compat_ulong_t reg;
651 
652 	pos /= sizeof(reg);
653 	count /= sizeof(reg);
654 
655 	if (kbuf)
656 		for (; count > 0 && pos < ELF_NGREG; --count)
657 			set_reg(regs, pos++, *k++);
658 	else
659 		for (; count > 0 && pos < ELF_NGREG; --count) {
660 			if (__get_user(reg, u++))
661 				return -EFAULT;
662 			set_reg(regs, pos++, reg);
663 		}
664 
665 	kbuf = k;
666 	ubuf = u;
667 	pos *= sizeof(reg);
668 	count *= sizeof(reg);
669 	return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
670 					 ELF_NGREG * sizeof(reg), -1);
671 }
672 
673 /*
674  * These are the regset flavors matching the 32bit native set.
675  */
676 static const struct user_regset compat_regsets[] = {
677 	[REGSET_GENERAL] = {
678 		.core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
679 		.size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
680 		.get = gpr32_get, .set = gpr32_set
681 	},
682 	[REGSET_FP] = {
683 		.core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
684 		.size = sizeof(__u64), .align = sizeof(__u64),
685 		.get = fpr_get, .set = fpr_set
686 	}
687 };
688 
689 static const struct user_regset_view user_parisc_compat_view = {
690 	.name = "parisc", .e_machine = EM_PARISC, .ei_osabi = ELFOSABI_LINUX,
691 	.regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
692 };
693 #endif	/* CONFIG_64BIT */
694 
task_user_regset_view(struct task_struct * task)695 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
696 {
697 	BUILD_BUG_ON(sizeof(struct user_regs_struct)/sizeof(long) != ELF_NGREG);
698 	BUILD_BUG_ON(sizeof(struct user_fp_struct)/sizeof(__u64) != ELF_NFPREG);
699 #ifdef CONFIG_64BIT
700 	if (is_compat_task())
701 		return &user_parisc_compat_view;
702 #endif
703 	return &user_parisc_native_view;
704 }
705