Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / arch / powerpc / kernel / ptrace.c
1 /*
2  *  PowerPC version
3  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4  *
5  *  Derived from "arch/m68k/kernel/ptrace.c"
6  *  Copyright (C) 1994 by Hamish Macdonald
7  *  Taken from linux/kernel/ptrace.c and modified for M680x0.
8  *  linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
9  *
10  * Modified by Cort Dougan (cort@hq.fsmlabs.com)
11  * and Paul Mackerras (paulus@samba.org).
12  *
13  * This file is subject to the terms and conditions of the GNU General
14  * Public License.  See the file README.legal in the main directory of
15  * this archive for more details.
16  */
17
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/mm.h>
21 #include <linux/smp.h>
22 #include <linux/smp_lock.h>
23 #include <linux/errno.h>
24 #include <linux/ptrace.h>
25 #include <linux/tracehook.h>
26 #include <linux/user.h>
27 #include <linux/security.h>
28 #include <linux/signal.h>
29 #include <linux/seccomp.h>
30 #include <linux/audit.h>
31 #include <linux/elf.h>
32 #include <linux/module.h>
33
34 #include <asm/uaccess.h>
35 #include <asm/page.h>
36 #include <asm/pgtable.h>
37 #include <asm/system.h>
38 #include <asm/tracehook.h>
39
40 /*
41  * Set of msr bits that gdb can change on behalf of a process.
42  */
43 #ifdef CONFIG_PPC64
44 #define MSR_DEBUGCHANGE (MSR_FE0 | MSR_SE | MSR_BE | MSR_FE1)
45 #elif defined(CONFIG_40x) || defined(CONFIG_BOOKE)
46 #define MSR_DEBUGCHANGE 0
47 #else  /* CONFIG_PPC32 */
48 #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
49 #endif /* CONFIG_PPC64 */
50
51 /*
52  * Last register that can be changed via ptrace.
53  */
54 #ifdef CONFIG_PPC64
55 #define PT_LAST PT_SOFTE
56 #else
57 #define PT_LAST PT_MQ
58 #endif
59
60 static int
61 genregs_get(struct task_struct *target,
62             const struct utrace_regset *regset,
63             unsigned int pos, unsigned int count,
64             void *kbuf, void __user *ubuf)
65 {
66         if (target->thread.regs == NULL)
67                 return -EIO;
68
69 #ifdef CONFIG_PPC32
70         CHECK_FULL_REGS(target->thread.regs);
71 #endif
72
73         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
74                                      target->thread.regs, 0, -1);
75 }
76
77 static int
78 genregs_set(struct task_struct *target,
79             const struct utrace_regset *regset,
80             unsigned int pos, unsigned int count,
81             const void *kbuf, const void __user *ubuf)
82 {
83         unsigned long msr_save;
84         int ret = 0;
85
86         if (target->thread.regs == NULL)
87                 return -EIO;
88
89 #ifdef CONFIG_PPC32
90         CHECK_FULL_REGS(target->thread.regs);
91 #endif
92
93         /*
94          * Just ignore attempts to set the registers beyond PT_LAST.
95          * They are read-only.
96          */
97
98         msr_save = target->thread.regs->msr &~ MSR_DEBUGCHANGE;
99
100         ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
101                                    target->thread.regs, 0,
102                                    (PT_LAST + 1) * sizeof(long));
103
104         target->thread.regs->msr &= MSR_DEBUGCHANGE;
105         target->thread.regs->msr |= msr_save;
106
107         return ret;
108 }
109
110 static int
111 fpregs_get(struct task_struct *target,
112            const struct utrace_regset *regset,
113            unsigned int pos, unsigned int count,
114            void *kbuf, void __user *ubuf)
115 {
116         BUILD_BUG_ON(offsetof(struct thread_struct, fpscr)
117                      != offsetof(struct thread_struct, fpr[32]));
118
119         flush_fp_to_thread(target);
120
121         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
122                                      &target->thread.fpr, 0, -1);
123 }
124
125 static int
126 fpregs_set(struct task_struct *target,
127             const struct utrace_regset *regset,
128             unsigned int pos, unsigned int count,
129             const void *kbuf, const void __user *ubuf)
130 {
131         return utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
132                                     &target->thread.fpr, 0, -1);
133 }
134
135 #ifdef CONFIG_ALTIVEC
136 /*
137  * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
138  * The transfer totals 34 quadword.  Quadwords 0-31 contain the
139  * corresponding vector registers.  Quadword 32 contains the vscr as the
140  * last word (offset 12) within that quadword.  Quadword 33 contains the
141  * vrsave as the first word (offset 0) within the quadword.
142  *
143  * This definition of the VMX state is compatible with the current PPC32
144  * ptrace interface.  This allows signal handling and ptrace to use the
145  * same structures.  This also simplifies the implementation of a bi-arch
146  * (combined (32- and 64-bit) gdb.
147  */
148
149 static int
150 vrregs_active(struct task_struct *target, const struct utrace_regset *regset)
151 {
152         flush_altivec_to_thread(target);
153         return target->thread.used_vr ? regset->n : 0;
154 }
155
156 static int
157 vrregs_get(struct task_struct *target,
158            const struct utrace_regset *regset,
159            unsigned int pos, unsigned int count,
160            void *kbuf, void __user *ubuf)
161 {
162         BUILD_BUG_ON(offsetof(struct thread_struct, vscr)
163                      != offsetof(struct thread_struct, vr[32]));
164         BUILD_BUG_ON(offsetof(struct thread_struct, vscr) + sizeof(vector128)
165                      != offsetof(struct thread_struct, vrsave));
166
167         flush_altivec_to_thread(target);
168
169         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
170                                      &target->thread.vr, 0, -1);
171 }
172
173 static int
174 vrregs_set(struct task_struct *target,
175             const struct utrace_regset *regset,
176             unsigned int pos, unsigned int count,
177             const void *kbuf, const void __user *ubuf)
178 {
179         flush_altivec_to_thread(target);
180
181         return utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
182                                     &target->thread.vr, 0, -1);
183 }
184 #endif  /* CONFIG_ALTIVEC */
185
186 #ifdef CONFIG_PPC64
187 /* We only support one DABR and no IABRS at the moment */
188
189 static int
190 set_thread_dabr(struct task_struct *tsk, unsigned long dabr)
191 {
192         /* The bottom 3 bits are flags */
193         if ((dabr & ~0x7UL) >= TASK_SIZE)
194                 return -EIO;
195
196         /* Ensure translation is on */
197         if (dabr && !(dabr & DABR_TRANSLATION))
198                 return -EIO;
199
200         tsk->thread.dabr = dabr;
201         return 0;
202 }
203
204 static int
205 debugreg_get(struct task_struct *target,
206              const struct utrace_regset *regset,
207              unsigned int pos, unsigned int count,
208              void *kbuf, void __user *ubuf)
209 {
210         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
211                                      &target->thread.dabr, 0, -1);
212 }
213
214 static int
215 debugreg_set(struct task_struct *target,
216              const struct utrace_regset *regset,
217              unsigned int pos, unsigned int count,
218              const void *kbuf, const void __user *ubuf)
219 {
220         unsigned long dabr;
221         int ret;
222
223         ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf, &dabr, 0, -1);
224         if (ret == 0)
225                 ret = set_thread_dabr(target, dabr);
226
227         return ret;
228 }
229
230 static int
231 ppc32_dabr_get(struct task_struct *target,
232                const struct utrace_regset *regset,
233                unsigned int pos, unsigned int count,
234                void *kbuf, void __user *ubuf)
235 {
236         u32 dabr = target->thread.dabr;
237         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf, &dabr, 0, -1);
238 }
239
240 static int
241 ppc32_dabr_set(struct task_struct *target,
242                const struct utrace_regset *regset,
243                unsigned int pos, unsigned int count,
244                const void *kbuf, const void __user *ubuf)
245 {
246         u32 dabr;
247         int ret;
248
249         ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf, &dabr, 0, -1);
250         if (ret == 0)
251                 ret = set_thread_dabr(target, dabr);
252
253         return ret;
254 }
255 #endif  /* CONFIG_PPC64 */
256
257 #ifdef CONFIG_SPE
258 /*
259  * For get_evrregs/set_evrregs functions 'data' has the following layout:
260  *
261  * struct {
262  *   u32 evr[32];
263  *   u64 acc;
264  *   u32 spefscr;
265  * }
266  */
267
268 static int
269 evrregs_active(struct task_struct *target, const struct utrace_regset *regset)
270 {
271         if (target->thread.regs->msr & MSR_SPE)
272                 giveup_spe(target);
273         return target->thread.used_spe ? regset->n : 0;
274 }
275
276 static int
277 evrregs_get(struct task_struct *target,
278             const struct utrace_regset *regset,
279             unsigned int pos, unsigned int count,
280             void *kbuf, void __user *ubuf)
281 {
282         BUILD_BUG_ON(offsetof(struct thread_struct, acc)
283                      != offsetof(struct thread_struct, evr[32]));
284         BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64)
285                      != offsetof(struct thread_struct, spefscr));
286
287         if (target->thread.regs->msr & MSR_SPE)
288                 giveup_spe(target);
289
290         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
291                                      &target->thread.evr, 0, -1);
292 }
293
294 static int
295 evrregs_set(struct task_struct *target,
296             const struct utrace_regset *regset,
297             unsigned int pos, unsigned int count,
298             const void *kbuf, const void __user *ubuf)
299 {
300         /* this is to clear the MSR_SPE bit to force a reload
301          * of register state from memory */
302         if (target->thread.regs->msr & MSR_SPE)
303                 giveup_spe(target);
304
305         return utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
306                                     &target->thread.evr, 0, -1);
307 }
308 #endif /* CONFIG_SPE */
309
310
311 /*
312  * These are our native regset flavors.
313  */
314 static const struct utrace_regset native_regsets[] = {
315         {
316                 .n = ELF_NGREG, .size = sizeof(long), .align = sizeof(long),
317                 .get = genregs_get, .set = genregs_set
318         },
319         {
320                 .n = ELF_NFPREG,
321                 .size = sizeof(double), .align = sizeof(double),
322                 .get = fpregs_get, .set = fpregs_set
323         },
324 #ifdef CONFIG_ALTIVEC
325         {
326                 .n = 33*4+1, .size = sizeof(u32), .align = sizeof(u32),
327                 .active = vrregs_active, .get = vrregs_get, .set = vrregs_set
328         },
329 #endif
330 #ifdef CONFIG_SPE
331         {
332                 .n = 35, .size = sizeof(long), .align = sizeof(long),
333                 .active = evrregs_active,
334                 .get = evrregs_get, .set = evrregs_set
335         },
336 #endif
337 #ifdef CONFIG_PPC64
338         {
339                 .n = 1, .size = sizeof(long), .align = sizeof(long),
340                 .get = debugreg_get, .set = debugreg_set
341         },
342 #endif
343 };
344
345 const struct utrace_regset_view utrace_ppc_native_view = {
346         .name = UTS_MACHINE, .e_machine = ELF_ARCH,
347         .regsets = native_regsets,
348         .n = sizeof native_regsets / sizeof native_regsets[0],
349 };
350 EXPORT_SYMBOL_GPL(utrace_ppc_native_view);
351
352
353 #ifdef CONFIG_PPC64
354 #include <linux/compat.h>
355
356 static int
357 ppc32_gpr_get(struct task_struct *target,
358               const struct utrace_regset *regset,
359               unsigned int pos, unsigned int count,
360               void *kbuf, void __user *ubuf)
361 {
362         unsigned long *regs = (unsigned long *) target->thread.regs;
363
364         if (regs == NULL)
365                 return -EIO;
366
367         regs += pos / sizeof(u32);
368
369         if (kbuf) {
370                 u32 *out = kbuf;
371                 for (; count > 0; count -= sizeof(u32))
372                         *out++ = *regs++;
373         }
374         else {
375                 u32 __user *out = ubuf;
376                 for (; count > 0; count -= sizeof(u32))
377                         if (put_user((u32) *regs++, out++))
378                                 return -EFAULT;
379         }
380
381         return 0;
382 }
383
384 static int
385 ppc32_gpr_set(struct task_struct *target,
386               const struct utrace_regset *regset,
387               unsigned int pos, unsigned int count,
388               const void *kbuf, const void __user *ubuf)
389 {
390         unsigned long *regs = (unsigned long *) target->thread.regs;
391
392         if (regs == NULL)
393                 return -EIO;
394
395         /*
396          * Just ignore attempts to set the registers beyond PT_LAST.
397          * They are read-only.
398          */
399         if (count > (PT_LAST + 1) * sizeof(u32) - pos)
400                 count = (PT_LAST + 1) * sizeof(u32) - pos;
401
402         pos /= sizeof(u32);
403
404         if (kbuf) {
405                 const u32 *in = kbuf;
406                 for (; count > 0; count -= sizeof(u32), ++pos, ++in) {
407                         if (pos == PT_MSR)
408                                 regs[pos] = ((regs[pos] &~ MSR_DEBUGCHANGE)
409                                              | (*in & MSR_DEBUGCHANGE));
410                         else
411                                 regs[pos] = *in;
412                 }
413         }
414         else {
415                 const u32 __user *in = kbuf;
416                 for (; count > 0; count -= sizeof(u32), ++pos) {
417                         u32 val;
418                         if (get_user(val, in++))
419                                 return -EFAULT;
420                         else if (pos == PT_MSR)
421                                 regs[pos] = ((regs[pos] &~ MSR_DEBUGCHANGE)
422                                              | (val & MSR_DEBUGCHANGE));
423                         else
424                                 regs[pos] = val;
425                 }
426         }
427
428         return 0;
429 }
430
431 /*
432  * These are the regset flavors matching the CONFIG_PPC32 native set.
433  */
434 static const struct utrace_regset ppc32_regsets[] = {
435         {
436                 .n = ELF_NGREG,
437                 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
438                 .get = ppc32_gpr_get, .set = ppc32_gpr_set
439         },
440         {
441                 .n = ELF_NFPREG,
442                 .size = sizeof(double), .align = sizeof(double),
443                 .get = fpregs_get, .set = fpregs_set
444         },
445 #ifdef CONFIG_ALTIVEC
446         {
447                 .n = 33*4+1, .size = sizeof(u32), .align = sizeof(u32),
448                 .active = vrregs_active, .get = vrregs_get, .set = vrregs_set
449         },
450 #endif
451         {
452                 .n = 1,
453                 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
454                 .get = ppc32_dabr_get, .set = ppc32_dabr_set
455         },
456 };
457
458 const struct utrace_regset_view utrace_ppc32_view = {
459         .name = "ppc", .e_machine = EM_PPC,
460         .regsets = ppc32_regsets,
461         .n = sizeof ppc32_regsets / sizeof ppc32_regsets[0],
462 };
463 EXPORT_SYMBOL_GPL(utrace_ppc32_view);
464 #endif
465
466
467 #ifdef CONFIG_PTRACE
468 static const struct ptrace_layout_segment ppc_uarea[] = {
469         {0, PT_FPR0 * sizeof(long), 0, 0},
470         {PT_FPR0 * sizeof(long), (PT_FPSCR + 1) * sizeof(long), 1, 0},
471         {0, 0, -1, 0}
472 };
473
474 fastcall int arch_ptrace(long *request, struct task_struct *child,
475                          struct utrace_attached_engine *engine,
476                          unsigned long addr, unsigned long data, long *val)
477 {
478         switch (*request) {
479         case PTRACE_PEEKUSR:
480                 return ptrace_peekusr(child, engine, ppc_uarea, addr, data);
481         case PTRACE_POKEUSR:
482                 return ptrace_pokeusr(child, engine, ppc_uarea, addr, data);
483         case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
484         case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
485                 return ptrace_regset_access(child, engine,
486                                             utrace_native_view(current), 0,
487                                             0, 32 * sizeof(long),
488                                             (void __user *)addr,
489                                             *request == PPC_PTRACE_SETREGS);
490         case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
491         case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
492                 return ptrace_regset_access(child, engine,
493                                             utrace_native_view(current), 1,
494                                             0, 32 * sizeof(double),
495                                             (void __user *)addr,
496                                             *request == PPC_PTRACE_SETFPREGS);
497 #ifdef CONFIG_PPC64
498         case PTRACE_GET_DEBUGREG:
499         case PTRACE_SET_DEBUGREG:
500                 return ptrace_onereg_access(child, engine,
501                                             utrace_native_view(current), 3,
502                                             addr, (unsigned long __user *)data,
503                                             *request == PTRACE_SET_DEBUGREG);
504 #endif /* CONFIG_PPC64 */
505 #ifdef CONFIG_ALTIVEC
506         case PTRACE_GETVRREGS:
507                 return ptrace_whole_regset(child, engine, data, 2, 0);
508         case PTRACE_SETVRREGS:
509                 return ptrace_whole_regset(child, engine, data, 2, 1);
510 #endif
511 #ifdef CONFIG_SPE
512 #ifdef CONFIG_ALTIVEC
513 #define REGSET_EVR 3
514 #else
515 #define REGSET_EVR 2
516 #endif
517         case PTRACE_GETEVRREGS:
518                 return ptrace_whole_regset(child, engine, data, REGSET_EVR, 0);
519         case PTRACE_SETEVRREGS:
520                 return ptrace_whole_regset(child, engine, data, REGSET_EVR, 1);
521 #endif
522         }
523         return -ENOSYS;
524 }
525
526 #ifdef CONFIG_COMPAT
527 #include <linux/mm.h>
528 #include <asm/uaccess.h>
529
530 static const struct ptrace_layout_segment ppc32_uarea[] = {
531         {0, PT_FPR0 * sizeof(u32), 0, 0},
532         {PT_FPR0 * sizeof(u32), (PT_FPSCR32 + 1) * sizeof(u32), 1, 0},
533         {0, 0, -1, 0}
534 };
535
536 fastcall int arch_compat_ptrace(compat_long_t *request,
537                                 struct task_struct *child,
538                                 struct utrace_attached_engine *engine,
539                                 compat_ulong_t addr, compat_ulong_t data,
540                                 compat_long_t *val)
541 {
542         void __user *uaddr = (void __user *) (unsigned long) addr;
543         int ret = -ENOSYS;
544
545         switch (*request) {
546         case PTRACE_PEEKUSR:
547                 return ptrace_compat_peekusr(child, engine, ppc32_uarea,
548                                              addr, data);
549         case PTRACE_POKEUSR:
550                 return ptrace_compat_pokeusr(child, engine, ppc32_uarea,
551                                              addr, data);
552
553         case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
554         case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
555                 return ptrace_regset_access(child, engine,
556                                             utrace_native_view(current), 0,
557                                             0, 32 * sizeof(compat_long_t),
558                                             uaddr,
559                                             *request == PPC_PTRACE_SETREGS);
560         case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
561         case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
562                 return ptrace_regset_access(child, engine,
563                                             utrace_native_view(current), 1,
564                                             0, 32 * sizeof(double),
565                                             uaddr,
566                                             *request == PPC_PTRACE_SETFPREGS);
567 #ifdef CONFIG_ALTIVEC
568         case PTRACE_GETVRREGS:
569                 return ptrace_whole_regset(child, engine, data, 2, 0);
570         case PTRACE_SETVRREGS:
571                 return ptrace_whole_regset(child, engine, data, 2, 1);
572 #endif
573         case PTRACE_GET_DEBUGREG:
574         case PTRACE_SET_DEBUGREG:
575                 return ptrace_onereg_access(child, engine,
576                                             utrace_native_view(current), 3,
577                                             addr,
578                                             (unsigned long __user *)
579                                             (unsigned long) data,
580                                             *request == PTRACE_SET_DEBUGREG);
581
582         /*
583          * Read 4 bytes of the other process' storage
584          *  data is a pointer specifying where the user wants the
585          *      4 bytes copied into
586          *  addr is a pointer in the user's storage that contains an 8 byte
587          *      address in the other process of the 4 bytes that is to be read
588          * (this is run in a 32-bit process looking at a 64-bit process)
589          * when I and D space are separate, these will need to be fixed.
590          */
591         case PPC_PTRACE_PEEKTEXT_3264:
592         case PPC_PTRACE_PEEKDATA_3264: {
593                 u32 tmp;
594                 int copied;
595                 u32 __user * addrOthers;
596
597                 ret = -EIO;
598
599                 /* Get the addr in the other process that we want to read */
600                 if (get_user(addrOthers, ((u32 __user * __user *)
601                                           (unsigned long) addr)) != 0)
602                         break;
603
604                 copied = access_process_vm(child, (u64)addrOthers, &tmp,
605                                 sizeof(tmp), 0);
606                 if (copied != sizeof(tmp))
607                         break;
608                 ret = put_user(tmp, (u32 __user *)(unsigned long)data);
609                 break;
610         }
611
612         /*
613          * Write 4 bytes into the other process' storage
614          *  data is the 4 bytes that the user wants written
615          *  addr is a pointer in the user's storage that contains an
616          *      8 byte address in the other process where the 4 bytes
617          *      that is to be written
618          * (this is run in a 32-bit process looking at a 64-bit process)
619          * when I and D space are separate, these will need to be fixed.
620          */
621         case PPC_PTRACE_POKETEXT_3264:
622         case PPC_PTRACE_POKEDATA_3264: {
623                 u32 tmp = data;
624                 u32 __user * addrOthers;
625
626                 /* Get the addr in the other process that we want to write into */
627                 ret = -EIO;
628                 if (get_user(addrOthers, ((u32 __user * __user *)
629                                           (unsigned long) addr)) != 0)
630                         break;
631                 ret = 0;
632                 if (access_process_vm(child, (u64)addrOthers, &tmp,
633                                         sizeof(tmp), 1) == sizeof(tmp))
634                         break;
635                 ret = -EIO;
636                 break;
637         }
638
639         /*
640          * This is like PTRACE_PEEKUSR on a 64-bit process,
641          * but here we access only 4 bytes at a time.
642          */
643         case PPC_PTRACE_PEEKUSR_3264: {
644                 union
645                 {
646                         u64 whole;
647                         u32 half[2];
648                 } reg;
649                 int setno;
650                 const struct utrace_regset *regset;
651
652                 ret = -EIO;
653                 if ((addr & 3) || addr > PT_FPSCR*8)
654                         break;
655
656                 setno = 0;
657                 if (addr >= PT_FPR0*8) {
658                         setno = 1;
659                         addr -= PT_FPR0*8;
660                 }
661                 regset = utrace_regset(child, NULL,
662                                        &utrace_ppc_native_view, setno);
663                 ret = (*regset->get)(child, regset, addr &~ 7,
664                                      sizeof(reg.whole), &reg.whole, NULL);
665                 if (ret == 0)
666                         ret = put_user(reg.half[(addr >> 2) & 1],
667                                        (u32 __user *)(unsigned long)data);
668                 break;
669         }
670
671         /*
672          * This is like PTRACE_POKEUSR on a 64-bit process,
673          * but here we access only 4 bytes at a time.
674          */
675         case PPC_PTRACE_POKEUSR_3264: {
676                 union
677                 {
678                         u64 whole;
679                         u32 half[2];
680                 } reg;
681                 int setno;
682                 const struct utrace_regset *regset;
683
684                 ret = -EIO;
685                 if ((addr & 3) || addr > PT_FPSCR*8)
686                         break;
687
688                 setno = 0;
689                 if (addr >= PT_FPR0*8) {
690                         setno = 1;
691                         addr -= PT_FPR0*8;
692                 }
693                 regset = utrace_regset(child, NULL,
694                                        &utrace_ppc_native_view, setno);
695                 ret = (*regset->get)(child, regset, addr &~ 7,
696                                      sizeof(reg.whole), &reg.whole, NULL);
697                 BUG_ON(ret);
698                 reg.half[(addr >> 2) & 1] = data;
699                 ret = (*regset->set)(child, regset, addr &~ 7,
700                                      sizeof(reg.whole), &reg.whole, NULL);
701                 break;
702         }
703         }
704         return ret;
705 }
706 #endif  /* CONFIG_COMPAT */
707 #endif  /* CONFIG_PTRACE */
708
709
710 void do_syscall_trace_enter(struct pt_regs *regs)
711 {
712 #ifdef CONFIG_PPC64
713         secure_computing(regs->gpr[0]);
714 #endif
715
716         if (test_thread_flag(TIF_SYSCALL_TRACE))
717                 tracehook_report_syscall(regs, 0);
718
719         if (unlikely(current->audit_context))
720                 audit_syscall_entry(
721 #ifdef CONFIG_PPC32
722                                     AUDIT_ARCH_PPC,
723 #else
724                                     test_thread_flag(TIF_32BIT)?AUDIT_ARCH_PPC:AUDIT_ARCH_PPC64,
725 #endif
726                                     regs->gpr[0],
727                                     regs->gpr[3], regs->gpr[4],
728                                     regs->gpr[5], regs->gpr[6]);
729 }
730
731 void do_syscall_trace_leave(struct pt_regs *regs)
732 {
733 #ifdef CONFIG_PPC32
734         secure_computing(regs->gpr[0]);
735 #endif
736
737         if (unlikely(current->audit_context))
738                 audit_syscall_exit((regs->ccr&0x1000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
739                                    regs->result);
740
741         if (test_thread_flag(TIF_SYSCALL_TRACE))
742                 tracehook_report_syscall(regs, 1);
743
744         if (test_thread_flag(TIF_SINGLESTEP)) {
745                 force_sig(SIGTRAP, current); /* XXX */
746                 tracehook_report_syscall_step(regs);
747         }
748 }
749
750 #ifdef CONFIG_PPC32
751 EXPORT_SYMBOL(do_syscall_trace_enter);
752 EXPORT_SYMBOL(do_syscall_trace_leave);
753 #endif