fedora core 6 1.2949 + vserver 2.2.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, .n = ARRAY_SIZE(native_regsets)
348 };
349 EXPORT_SYMBOL_GPL(utrace_ppc_native_view);
350
351
352 #ifdef CONFIG_PPC64
353 #include <linux/compat.h>
354
355 static int
356 ppc32_gpr_get(struct task_struct *target,
357               const struct utrace_regset *regset,
358               unsigned int pos, unsigned int count,
359               void *kbuf, void __user *ubuf)
360 {
361         unsigned long *regs = (unsigned long *) target->thread.regs;
362
363         if (regs == NULL)
364                 return -EIO;
365
366         regs += pos / sizeof(u32);
367
368         if (kbuf) {
369                 u32 *out = kbuf;
370                 for (; count > 0; count -= sizeof(u32))
371                         *out++ = *regs++;
372         }
373         else {
374                 u32 __user *out = ubuf;
375                 for (; count > 0; count -= sizeof(u32))
376                         if (put_user((u32) *regs++, out++))
377                                 return -EFAULT;
378         }
379
380         return 0;
381 }
382
383 static int
384 ppc32_gpr_set(struct task_struct *target,
385               const struct utrace_regset *regset,
386               unsigned int pos, unsigned int count,
387               const void *kbuf, const void __user *ubuf)
388 {
389         unsigned long *regs = (unsigned long *) target->thread.regs;
390
391         if (regs == NULL)
392                 return -EIO;
393
394         /*
395          * Just ignore attempts to set the registers beyond PT_LAST.
396          * They are read-only.
397          */
398         if (count > (PT_LAST + 1) * sizeof(u32) - pos)
399                 count = (PT_LAST + 1) * sizeof(u32) - pos;
400
401         pos /= sizeof(u32);
402
403         if (kbuf) {
404                 const u32 *in = kbuf;
405                 for (; count > 0; count -= sizeof(u32), ++pos, ++in) {
406                         if (pos == PT_MSR)
407                                 regs[pos] = ((regs[pos] &~ MSR_DEBUGCHANGE)
408                                              | (*in & MSR_DEBUGCHANGE));
409                         else
410                                 regs[pos] = *in;
411                 }
412         }
413         else {
414                 const u32 __user *in = kbuf;
415                 for (; count > 0; count -= sizeof(u32), ++pos) {
416                         u32 val;
417                         if (get_user(val, in++))
418                                 return -EFAULT;
419                         else if (pos == PT_MSR)
420                                 regs[pos] = ((regs[pos] &~ MSR_DEBUGCHANGE)
421                                              | (val & MSR_DEBUGCHANGE));
422                         else
423                                 regs[pos] = val;
424                 }
425         }
426
427         return 0;
428 }
429
430 /*
431  * These are the regset flavors matching the CONFIG_PPC32 native set.
432  */
433 static const struct utrace_regset ppc32_regsets[] = {
434         {
435                 .n = ELF_NGREG,
436                 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
437                 .get = ppc32_gpr_get, .set = ppc32_gpr_set
438         },
439         {
440                 .n = ELF_NFPREG,
441                 .size = sizeof(double), .align = sizeof(double),
442                 .get = fpregs_get, .set = fpregs_set
443         },
444 #ifdef CONFIG_ALTIVEC
445         {
446                 .n = 33*4+1, .size = sizeof(u32), .align = sizeof(u32),
447                 .active = vrregs_active, .get = vrregs_get, .set = vrregs_set
448         },
449 #endif
450         {
451                 .n = 1,
452                 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
453                 .get = ppc32_dabr_get, .set = ppc32_dabr_set
454         },
455 };
456
457 const struct utrace_regset_view utrace_ppc32_view = {
458         .name = "ppc", .e_machine = EM_PPC,
459         .regsets = ppc32_regsets, .n = ARRAY_SIZE(ppc32_regsets)
460 };
461 EXPORT_SYMBOL_GPL(utrace_ppc32_view);
462 #endif
463
464
465 #ifdef CONFIG_PTRACE
466 static const struct ptrace_layout_segment ppc_uarea[] = {
467         {0, PT_FPR0 * sizeof(long), 0, 0},
468         {PT_FPR0 * sizeof(long), (PT_FPSCR + 1) * sizeof(long), 1, 0},
469         {0, 0, -1, 0}
470 };
471
472 int arch_ptrace(long *request, struct task_struct *child,
473                 struct utrace_attached_engine *engine,
474                 unsigned long addr, unsigned long data, long *val)
475 {
476         switch (*request) {
477         case PTRACE_PEEKUSR:
478                 return ptrace_peekusr(child, engine, ppc_uarea, addr, data);
479         case PTRACE_POKEUSR:
480                 return ptrace_pokeusr(child, engine, ppc_uarea, addr, data);
481         case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
482         case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
483                 return ptrace_regset_access(child, engine,
484                                             utrace_native_view(current), 0,
485                                             0, 32 * sizeof(long),
486                                             (void __user *)addr,
487                                             *request == PPC_PTRACE_SETREGS);
488         case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
489         case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
490                 return ptrace_regset_access(child, engine,
491                                             utrace_native_view(current), 1,
492                                             0, 32 * sizeof(double),
493                                             (void __user *)addr,
494                                             *request == PPC_PTRACE_SETFPREGS);
495 #ifdef CONFIG_PPC64
496         case PTRACE_GET_DEBUGREG:
497         case PTRACE_SET_DEBUGREG:
498                 return ptrace_onereg_access(child, engine,
499                                             utrace_native_view(current), 3,
500                                             addr, (unsigned long __user *)data,
501                                             *request == PTRACE_SET_DEBUGREG);
502 #endif /* CONFIG_PPC64 */
503 #ifdef CONFIG_ALTIVEC
504         case PTRACE_GETVRREGS:
505                 return ptrace_whole_regset(child, engine, data, 2, 0);
506         case PTRACE_SETVRREGS:
507                 return ptrace_whole_regset(child, engine, data, 2, 1);
508 #endif
509 #ifdef CONFIG_SPE
510 #ifdef CONFIG_ALTIVEC
511 #define REGSET_EVR 3
512 #else
513 #define REGSET_EVR 2
514 #endif
515         case PTRACE_GETEVRREGS:
516                 return ptrace_whole_regset(child, engine, data, REGSET_EVR, 0);
517         case PTRACE_SETEVRREGS:
518                 return ptrace_whole_regset(child, engine, data, REGSET_EVR, 1);
519 #endif
520         }
521         return -ENOSYS;
522 }
523
524 #ifdef CONFIG_COMPAT
525 #include <linux/mm.h>
526 #include <asm/uaccess.h>
527
528 static const struct ptrace_layout_segment ppc32_uarea[] = {
529         {0, PT_FPR0 * sizeof(u32), 0, 0},
530         {PT_FPR0 * sizeof(u32), (PT_FPSCR32 + 1) * sizeof(u32), 1, 0},
531         {0, 0, -1, 0}
532 };
533
534 int arch_compat_ptrace(compat_long_t *request,
535                        struct task_struct *child,
536                        struct utrace_attached_engine *engine,
537                        compat_ulong_t addr, compat_ulong_t data,
538                        compat_long_t *val)
539 {
540         void __user *uaddr = (void __user *) (unsigned long) addr;
541         int ret = -ENOSYS;
542
543         switch (*request) {
544         case PTRACE_PEEKUSR:
545                 return ptrace_compat_peekusr(child, engine, ppc32_uarea,
546                                              addr, data);
547         case PTRACE_POKEUSR:
548                 return ptrace_compat_pokeusr(child, engine, ppc32_uarea,
549                                              addr, data);
550
551         case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
552         case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
553                 return ptrace_regset_access(child, engine,
554                                             utrace_native_view(current), 0,
555                                             0, 32 * sizeof(compat_long_t),
556                                             uaddr,
557                                             *request == PPC_PTRACE_SETREGS);
558         case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
559         case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
560                 return ptrace_regset_access(child, engine,
561                                             utrace_native_view(current), 1,
562                                             0, 32 * sizeof(double),
563                                             uaddr,
564                                             *request == PPC_PTRACE_SETFPREGS);
565 #ifdef CONFIG_ALTIVEC
566         case PTRACE_GETVRREGS:
567                 return ptrace_whole_regset(child, engine, data, 2, 0);
568         case PTRACE_SETVRREGS:
569                 return ptrace_whole_regset(child, engine, data, 2, 1);
570 #endif
571         case PTRACE_GET_DEBUGREG:
572         case PTRACE_SET_DEBUGREG:
573                 return ptrace_onereg_access(child, engine,
574                                             utrace_native_view(current), 3,
575                                             addr,
576                                             (unsigned long __user *)
577                                             (unsigned long) data,
578                                             *request == PTRACE_SET_DEBUGREG);
579
580         /*
581          * Read 4 bytes of the other process' storage
582          *  data is a pointer specifying where the user wants the
583          *      4 bytes copied into
584          *  addr is a pointer in the user's storage that contains an 8 byte
585          *      address in the other process of the 4 bytes that is to be read
586          * (this is run in a 32-bit process looking at a 64-bit process)
587          * when I and D space are separate, these will need to be fixed.
588          */
589         case PPC_PTRACE_PEEKTEXT_3264:
590         case PPC_PTRACE_PEEKDATA_3264: {
591                 u32 tmp;
592                 int copied;
593                 u32 __user * addrOthers;
594
595                 ret = -EIO;
596
597                 /* Get the addr in the other process that we want to read */
598                 if (get_user(addrOthers, ((u32 __user * __user *)
599                                           (unsigned long) addr)) != 0)
600                         break;
601
602                 copied = access_process_vm(child, (u64)addrOthers, &tmp,
603                                 sizeof(tmp), 0);
604                 if (copied != sizeof(tmp))
605                         break;
606                 ret = put_user(tmp, (u32 __user *)(unsigned long)data);
607                 break;
608         }
609
610         /*
611          * Write 4 bytes into the other process' storage
612          *  data is the 4 bytes that the user wants written
613          *  addr is a pointer in the user's storage that contains an
614          *      8 byte address in the other process where the 4 bytes
615          *      that is to be written
616          * (this is run in a 32-bit process looking at a 64-bit process)
617          * when I and D space are separate, these will need to be fixed.
618          */
619         case PPC_PTRACE_POKETEXT_3264:
620         case PPC_PTRACE_POKEDATA_3264: {
621                 u32 tmp = data;
622                 u32 __user * addrOthers;
623
624                 /* Get the addr in the other process that we want to write into */
625                 ret = -EIO;
626                 if (get_user(addrOthers, ((u32 __user * __user *)
627                                           (unsigned long) addr)) != 0)
628                         break;
629                 ret = 0;
630                 if (access_process_vm(child, (u64)addrOthers, &tmp,
631                                         sizeof(tmp), 1) == sizeof(tmp))
632                         break;
633                 ret = -EIO;
634                 break;
635         }
636
637         /*
638          * This is like PTRACE_PEEKUSR on a 64-bit process,
639          * but here we access only 4 bytes at a time.
640          */
641         case PPC_PTRACE_PEEKUSR_3264: {
642                 union
643                 {
644                         u64 whole;
645                         u32 half[2];
646                 } reg;
647                 int setno;
648                 const struct utrace_regset *regset;
649
650                 ret = -EIO;
651                 if ((addr & 3) || addr > PT_FPSCR*8)
652                         break;
653
654                 setno = 0;
655                 if (addr >= PT_FPR0*8) {
656                         setno = 1;
657                         addr -= PT_FPR0*8;
658                 }
659                 regset = utrace_regset(child, NULL,
660                                        &utrace_ppc_native_view, setno);
661                 ret = (*regset->get)(child, regset, addr &~ 7,
662                                      sizeof(reg.whole), &reg.whole, NULL);
663                 if (ret == 0)
664                         ret = put_user(reg.half[(addr >> 2) & 1],
665                                        (u32 __user *)(unsigned long)data);
666                 break;
667         }
668
669         /*
670          * This is like PTRACE_POKEUSR on a 64-bit process,
671          * but here we access only 4 bytes at a time.
672          */
673         case PPC_PTRACE_POKEUSR_3264: {
674                 union
675                 {
676                         u64 whole;
677                         u32 half[2];
678                 } reg;
679                 int setno;
680                 const struct utrace_regset *regset;
681
682                 ret = -EIO;
683                 if ((addr & 3) || addr > PT_FPSCR*8)
684                         break;
685
686                 setno = 0;
687                 if (addr >= PT_FPR0*8) {
688                         setno = 1;
689                         addr -= PT_FPR0*8;
690                 }
691                 regset = utrace_regset(child, NULL,
692                                        &utrace_ppc_native_view, setno);
693                 ret = (*regset->get)(child, regset, addr &~ 7,
694                                      sizeof(reg.whole), &reg.whole, NULL);
695                 BUG_ON(ret);
696                 reg.half[(addr >> 2) & 1] = data;
697                 ret = (*regset->set)(child, regset, addr &~ 7,
698                                      sizeof(reg.whole), &reg.whole, NULL);
699                 break;
700         }
701         }
702         return ret;
703 }
704 #endif  /* CONFIG_COMPAT */
705 #endif  /* CONFIG_PTRACE */
706
707
708 void do_syscall_trace_enter(struct pt_regs *regs)
709 {
710         secure_computing(regs->gpr[0]);
711
712         if (test_thread_flag(TIF_SYSCALL_TRACE))
713                 tracehook_report_syscall(regs, 0);
714
715         if (unlikely(current->audit_context))
716                 audit_syscall_entry(
717 #ifdef CONFIG_PPC32
718                                     AUDIT_ARCH_PPC,
719 #else
720                                     test_thread_flag(TIF_32BIT)?AUDIT_ARCH_PPC:AUDIT_ARCH_PPC64,
721 #endif
722                                     regs->gpr[0],
723                                     regs->gpr[3], regs->gpr[4],
724                                     regs->gpr[5], regs->gpr[6]);
725 }
726
727 void do_syscall_trace_leave(struct pt_regs *regs)
728 {
729         if (unlikely(current->audit_context))
730                 audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
731                                    regs->result);
732
733         if (test_thread_flag(TIF_SYSCALL_TRACE))
734                 tracehook_report_syscall(regs, 1);
735
736         if (test_thread_flag(TIF_SINGLESTEP)) {
737                 force_sig(SIGTRAP, current); /* XXX */
738                 tracehook_report_syscall_step(regs);
739         }
740 }