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