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 / s390 / kernel / ptrace.c
1 /*
2  *  arch/s390/kernel/ptrace.c
3  *
4  *  S390 version
5  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
7  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
8  *
9  *  Based on PowerPC version 
10  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
11  *
12  *  Derived from "arch/m68k/kernel/ptrace.c"
13  *  Copyright (C) 1994 by Hamish Macdonald
14  *  Taken from linux/kernel/ptrace.c and modified for M680x0.
15  *  linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
16  *
17  * Modified by Cort Dougan (cort@cs.nmt.edu) 
18  *
19  *
20  * This file is subject to the terms and conditions of the GNU General
21  * Public License.  See the file README.legal in the main directory of
22  * this archive for more details.
23  */
24
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/mm.h>
28 #include <linux/smp.h>
29 #include <linux/smp_lock.h>
30 #include <linux/errno.h>
31 #include <linux/ptrace.h>
32 #include <linux/tracehook.h>
33 #include <linux/module.h>
34 #include <linux/user.h>
35 #include <linux/security.h>
36 #include <linux/audit.h>
37 #include <linux/signal.h>
38
39 #include <asm/segment.h>
40 #include <asm/page.h>
41 #include <asm/pgtable.h>
42 #include <asm/pgalloc.h>
43 #include <asm/system.h>
44 #include <asm/uaccess.h>
45 #include <asm/unistd.h>
46 #include <asm/elf.h>
47
48 #ifdef CONFIG_COMPAT
49 #include "compat_ptrace.h"
50 #endif
51
52 static void
53 FixPerRegisters(struct task_struct *task)
54 {
55         struct pt_regs *regs;
56         per_struct *per_info;
57
58         regs = task_pt_regs(task);
59         per_info = (per_struct *) &task->thread.per_info;
60         per_info->control_regs.bits.em_instruction_fetch =
61                 per_info->single_step | per_info->instruction_fetch;
62         
63         if (per_info->single_step) {
64                 per_info->control_regs.bits.starting_addr = 0;
65 #ifdef CONFIG_COMPAT
66                 if (test_thread_flag(TIF_31BIT))
67                         per_info->control_regs.bits.ending_addr = 0x7fffffffUL;
68                 else
69 #endif
70                         per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN;
71         } else {
72                 per_info->control_regs.bits.starting_addr =
73                         per_info->starting_addr;
74                 per_info->control_regs.bits.ending_addr =
75                         per_info->ending_addr;
76         }
77         /*
78          * if any of the control reg tracing bits are on 
79          * we switch on per in the psw
80          */
81         if (per_info->control_regs.words.cr[0] & PER_EM_MASK)
82                 regs->psw.mask |= PSW_MASK_PER;
83         else
84                 regs->psw.mask &= ~PSW_MASK_PER;
85
86         if (per_info->control_regs.bits.em_storage_alteration)
87                 per_info->control_regs.bits.storage_alt_space_ctl = 1;
88         else
89                 per_info->control_regs.bits.storage_alt_space_ctl = 0;
90
91         if (task == current)
92                 /*
93                  * These registers are loaded in __switch_to on
94                  * context switch.  We must load them now if
95                  * touching the current thread.
96                  */
97                 __ctl_load(per_info->control_regs.words.cr, 9, 11);
98 }
99
100 void
101 tracehook_enable_single_step(struct task_struct *task)
102 {
103         task->thread.per_info.single_step = 1;
104         FixPerRegisters(task);
105 }
106
107 void
108 tracehook_disable_single_step(struct task_struct *task)
109 {
110         task->thread.per_info.single_step = 0;
111         FixPerRegisters(task);
112         clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
113 }
114
115 int
116 tracehook_single_step_enabled(struct task_struct *task)
117 {
118         return task->thread.per_info.single_step;
119 }
120
121
122 static int
123 genregs_get(struct task_struct *target,
124             const struct utrace_regset *regset,
125             unsigned int pos, unsigned int count,
126             void *kbuf, void __user *ubuf)
127 {
128         struct pt_regs *regs = task_pt_regs(target);
129         unsigned long pswmask;
130         int ret;
131
132         /* Remove per bit from user psw. */
133         pswmask = regs->psw.mask & ~PSW_MASK_PER;
134         ret = utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
135                                     &pswmask, PT_PSWMASK, PT_PSWADDR);
136
137         /* The rest of the PSW and the GPRs are directly on the stack. */
138         if (ret == 0)
139                 ret = utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
140                                             &regs->psw.addr, PT_PSWADDR,
141                                             PT_ACR0);
142
143         /* The ACRs are kept in the thread_struct.  */
144         if (ret == 0 && count > 0 && pos < PT_ORIGGPR2) {
145                 if (target == current)
146                         save_access_regs(target->thread.acrs);
147
148                 ret = utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
149                                             target->thread.acrs,
150                                             PT_ACR0, PT_ORIGGPR2);
151         }
152
153         /* Finally, the ORIG_GPR2 value.  */
154         if (ret == 0)
155                 ret = utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
156                                             &regs->orig_gpr2, PT_ORIGGPR2, -1);
157
158         return ret;
159 }
160
161 static int
162 genregs_set(struct task_struct *target,
163             const struct utrace_regset *regset,
164             unsigned int pos, unsigned int count,
165             const void *kbuf, const void __user *ubuf)
166 {
167         struct pt_regs *regs = task_pt_regs(target);
168         int ret = 0;
169
170         /* Check for an invalid PSW mask.  */
171         if (count > 0 && pos == PT_PSWMASK) {
172                 unsigned long pswmask = regs->psw.mask;
173                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
174                                            &pswmask, PT_PSWMASK, PT_PSWADDR);
175                 if (pswmask != PSW_MASK_MERGE(PSW_USER_BITS, pswmask)
176 #ifdef CONFIG_COMPAT
177                     && pswmask != PSW_MASK_MERGE(PSW_USER32_BITS, pswmask)
178 #endif
179                         )
180                         /* Invalid psw mask. */
181                         return -EINVAL;
182                 regs->psw.mask = pswmask;
183                 FixPerRegisters(target);
184         }
185
186         /* The rest of the PSW and the GPRs are directly on the stack. */
187         if (ret == 0) {
188                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
189                                            &regs->psw.addr, PT_PSWADDR,
190                                            PT_ACR0);
191 #ifndef CONFIG_64BIT
192                 /* I'd like to reject addresses without the
193                    high order bit but older gdb's rely on it */
194                 regs->psw.addr |= PSW_ADDR_AMODE;
195 #endif
196         }
197
198         /* The ACRs are kept in the thread_struct.  */
199         if (ret == 0 && count > 0 && pos < PT_ORIGGPR2) {
200                 if (target == current
201                     && (pos != PT_ACR0 || count < sizeof(target->thread.acrs)))
202                         save_access_regs(target->thread.acrs);
203
204                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
205                                            target->thread.acrs,
206                                            PT_ACR0, PT_ORIGGPR2);
207                 if (ret == 0 && target == current)
208                         restore_access_regs(target->thread.acrs);
209         }
210
211         /* Finally, the ORIG_GPR2 value.  */
212         if (ret == 0)
213                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
214                                            &regs->orig_gpr2, PT_ORIGGPR2, -1);
215
216         return ret;
217 }
218
219 static int
220 fpregs_get(struct task_struct *target,
221            const struct utrace_regset *regset,
222            unsigned int pos, unsigned int count,
223            void *kbuf, void __user *ubuf)
224 {
225         if (target == current)
226                 save_fp_regs(&target->thread.fp_regs);
227
228         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
229                                      &target->thread.fp_regs, 0, -1);
230 }
231
232 static int
233 fpregs_set(struct task_struct *target,
234             const struct utrace_regset *regset,
235             unsigned int pos, unsigned int count,
236             const void *kbuf, const void __user *ubuf)
237 {
238         int ret = 0;
239
240         if (target == current && (pos != 0 || count != sizeof(s390_fp_regs)))
241                 save_fp_regs(&target->thread.fp_regs);
242
243         /* If setting FPC, must validate it first. */
244         if (count > 0 && pos == 0) {
245                 unsigned long fpc;
246                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
247                                            &fpc, 0, sizeof(fpc));
248                 if (ret)
249                         return ret;
250
251                 if ((fpc & ~((unsigned long) FPC_VALID_MASK
252                              << (BITS_PER_LONG - 32))) != 0)
253                         return -EINVAL;
254
255                 memcpy(&target->thread.fp_regs, &fpc, sizeof(fpc));
256         }
257
258         if (ret == 0)
259                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
260                                            &target->thread.fp_regs, 0, -1);
261
262         if (ret == 0 && target == current)
263                 restore_fp_regs(&target->thread.fp_regs);
264
265         return ret;
266 }
267
268 static int
269 per_info_get(struct task_struct *target,
270              const struct utrace_regset *regset,
271              unsigned int pos, unsigned int count,
272              void *kbuf, void __user *ubuf)
273 {
274         return utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
275                                      &target->thread.per_info, 0, -1);
276 }
277
278 static int
279 per_info_set(struct task_struct *target,
280              const struct utrace_regset *regset,
281              unsigned int pos, unsigned int count,
282              const void *kbuf, const void __user *ubuf)
283 {
284         int ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
285                                        &target->thread.per_info, 0, -1);
286
287         FixPerRegisters(target);
288
289         return ret;
290 }
291
292
293 /*
294  * These are our native regset flavors.
295  */
296 static const struct utrace_regset native_regsets[] = {
297         {
298                 .size = sizeof(long), .align = sizeof(long),
299                 .n = sizeof(s390_regs) / sizeof(long),
300                 .get = genregs_get, .set = genregs_set
301         },
302         {
303                 .size = sizeof(long), .align = sizeof(long),
304                 .n = sizeof(s390_fp_regs) / sizeof(long),
305                 .get = fpregs_get, .set = fpregs_set
306         },
307         {
308                 .size = sizeof(long), .align = sizeof(long),
309                 .n = sizeof(per_struct) / sizeof(long),
310                 .get = per_info_get, .set = per_info_set
311         },
312 };
313
314 const struct utrace_regset_view utrace_s390_native_view = {
315         .name = UTS_MACHINE, .e_machine = ELF_ARCH,
316         .regsets = native_regsets,
317         .n = sizeof native_regsets / sizeof native_regsets[0],
318 };
319 EXPORT_SYMBOL_GPL(utrace_s390_native_view);
320
321
322 #ifdef CONFIG_COMPAT
323 static int
324 s390_genregs_get(struct task_struct *target,
325                  const struct utrace_regset *regset,
326                  unsigned int pos, unsigned int count,
327                  void *kbuf, void __user *ubuf)
328 {
329         struct pt_regs *regs = task_pt_regs(target);
330         int ret = 0;
331
332         /* Fake a 31 bit psw mask. */
333         if (count > 0 && pos == PT_PSWMASK / 2) {
334                 u32 pswmask = PSW32_MASK_MERGE(PSW32_USER_BITS,
335                                                (u32) (regs->psw.mask >> 32));
336                 ret = utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
337                                             &pswmask, PT_PSWMASK / 2,
338                                             PT_PSWADDR / 2);
339         }
340
341         /* Fake a 31 bit psw address. */
342         if (ret == 0 && count > 0 && pos == PT_PSWADDR / 2) {
343                 u32 pswaddr = (u32) regs->psw.addr | PSW32_ADDR_AMODE31;
344                 ret = utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
345                                             &pswaddr, PT_PSWADDR / 2,
346                                             PT_GPR0 / 2);
347         }
348
349         /* The GPRs are directly on the stack.  Just truncate them.  */
350         while (ret == 0 && count > 0 && pos < PT_ACR0 / 2) {
351                 u32 value = regs->gprs[(pos - PT_GPR0 / 2) / sizeof(u32)];
352                 if (kbuf) {
353                         *(u32 *) kbuf = value;
354                         kbuf += sizeof(u32);
355                 }
356                 else if (put_user(value, (u32 __user *) ubuf))
357                         ret = -EFAULT;
358                 else
359                         ubuf += sizeof(u32);
360                 pos += sizeof(u32);
361                 count -= sizeof(u32);
362         }
363
364         /* The ACRs are kept in the thread_struct.  */
365         if (ret == 0 && count > 0 && pos < PT_ACR0 / 2 + NUM_ACRS * ACR_SIZE) {
366                 if (target == current)
367                         save_access_regs(target->thread.acrs);
368
369                 ret = utrace_regset_copyout(&pos, &count, &kbuf, &ubuf,
370                                             target->thread.acrs,
371                                             PT_ACR0 / 2,
372                                             PT_ACR0 / 2 + NUM_ACRS * ACR_SIZE);
373         }
374
375         /* Finally, the ORIG_GPR2 value.  */
376         if (count > 0) {
377                 if (kbuf)
378                         *(u32 *) kbuf = regs->orig_gpr2;
379                 else if (put_user((u32) regs->orig_gpr2,
380                                   (u32 __user *) ubuf))
381                         return -EFAULT;
382         }
383
384         return 0;
385 }
386
387 static int
388 s390_genregs_set(struct task_struct *target,
389                  const struct utrace_regset *regset,
390                  unsigned int pos, unsigned int count,
391                  const void *kbuf, const void __user *ubuf)
392 {
393         struct pt_regs *regs = task_pt_regs(target);
394         int ret = 0;
395
396         /* Check for an invalid PSW mask.  */
397         if (count > 0 && pos == PT_PSWMASK / 2) {
398                 u32 pswmask;
399                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
400                                            &pswmask, PT_PSWMASK / 2,
401                                            PT_PSWADDR / 2);
402                 if (ret)
403                         return ret;
404
405                 if (pswmask != PSW_MASK_MERGE(PSW_USER32_BITS, pswmask))
406                         /* Invalid psw mask. */
407                         return -EINVAL;
408
409                 /* Build a 64 bit psw mask from 31 bit mask. */
410                 regs->psw.mask = PSW_MASK_MERGE(PSW_USER32_BITS,
411                                                 (u64) pswmask << 32);
412                 FixPerRegisters(target);
413         }
414
415         /* Build a 64 bit psw address from 31 bit address. */
416         if (count > 0 && pos == PT_PSWADDR / 2) {
417                 u32 pswaddr;
418                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
419                                            &pswaddr, PT_PSWADDR / 2,
420                                            PT_GPR0 / 2);
421                 if (ret == 0)
422                         /* Build a 64 bit psw mask from 31 bit mask. */
423                         regs->psw.addr = pswaddr & PSW32_ADDR_INSN;
424         }
425
426         /* The GPRs are directly onto the stack. */
427         while (ret == 0 && count > 0 && pos < PT_ACR0 / 2) {
428                 u32 value;
429
430                 if (kbuf) {
431                         value = *(const u32 *) kbuf;
432                         kbuf += sizeof(u32);
433                 }
434                 else if (get_user(value, (const u32 __user *) ubuf))
435                         return -EFAULT;
436                 else
437                         ubuf += sizeof(u32);
438                 pos += sizeof(u32);
439                 count -= sizeof(u32);
440
441                 regs->gprs[(pos - PT_GPR0 / 2) / sizeof(u32)] = value;
442         }
443
444         /* The ACRs are kept in the thread_struct.  */
445         if (count > 0 && pos < PT_ORIGGPR2 / 2) {
446                 if (target == current
447                     && (pos != PT_ACR0 / 2
448                         || count < sizeof(target->thread.acrs)))
449                         save_access_regs(target->thread.acrs);
450
451                 ret = utrace_regset_copyin(&pos, &count, &kbuf, &ubuf,
452                                            target->thread.acrs,
453                                            PT_ACR0 / 2,
454                                            PT_ACR0 / 2 + NUM_ACRS * ACR_SIZE);
455
456                 if (ret == 0 && target == current)
457                         restore_access_regs(target->thread.acrs);
458         }
459
460         /* Finally, the ORIG_GPR2 value.  */
461         if (ret == 0 && count > 0) {
462                 u32 value;
463                 if (kbuf)
464                         value = *(const u32 *) kbuf;
465                 else if (get_user(value, (const u32 __user *) ubuf))
466                         return -EFAULT;
467                 regs->orig_gpr2 = value;
468         }
469
470         return ret;
471 }
472
473
474 /*
475  * This is magic. See per_struct and per_struct32.
476  * By incident the offsets in per_struct are exactly
477  * twice the offsets in per_struct32 for all fields.
478  * The 8 byte fields need special handling though,
479  * because the second half (bytes 4-7) is needed and
480  * not the first half.
481  */
482 static unsigned int
483 offset_from_per32(unsigned int offset)
484 {
485         BUILD_BUG_ON(offsetof(per_struct32, control_regs) != 0);
486         if (offset - offsetof(per_struct32, control_regs) < 3*sizeof(u32)
487             || (offset >= offsetof(per_struct32, starting_addr) &&
488                 offset <= offsetof(per_struct32, ending_addr))
489             || offset == offsetof(per_struct32, lowcore.words.address))
490                 offset = offset*2 + 4;
491         else
492                 offset = offset*2;
493         return offset;
494 }
495
496 static int
497 s390_per_info_get(struct task_struct *target,
498                   const struct utrace_regset *regset,
499                   unsigned int pos, unsigned int count,
500                   void *kbuf, void __user *ubuf)
501 {
502         while (count > 0) {
503                 u32 val = *(u32 *) ((char *) &target->thread.per_info
504                                     + offset_from_per32 (pos));
505                 if (kbuf) {
506                         *(u32 *) kbuf = val;
507                         kbuf += sizeof(u32);
508                 }
509                 else if (put_user(val, (u32 __user *) ubuf))
510                         return -EFAULT;
511                 else
512                         ubuf += sizeof(u32);
513                 pos += sizeof(u32);
514                 count -= sizeof(u32);
515         }
516         return 0;
517 }
518
519 static int
520 s390_per_info_set(struct task_struct *target,
521                   const struct utrace_regset *regset,
522                   unsigned int pos, unsigned int count,
523                   const void *kbuf, const void __user *ubuf)
524 {
525         while (count > 0) {
526                 u32 val;
527
528                 if (kbuf) {
529                         val = *(const u32 *) kbuf;
530                         kbuf += sizeof(u32);
531                 }
532                 else if (get_user(val, (const u32 __user *) ubuf))
533                         return -EFAULT;
534                 else
535                         ubuf += sizeof(u32);
536                 pos += sizeof(u32);
537                 count -= sizeof(u32);
538
539                 *(u32 *) ((char *) &target->thread.per_info
540                           + offset_from_per32 (pos)) = val;
541         }
542         return 0;
543 }
544
545
546 static const struct utrace_regset s390_compat_regsets[] = {
547         {
548                 .size = sizeof(u32), .align = sizeof(u32),
549                 .n = sizeof(s390_regs) / sizeof(long),
550                 .get = s390_genregs_get, .set = s390_genregs_set
551         },
552         {
553                 .size = sizeof(u32), .align = sizeof(u32),
554                 .n = sizeof(s390_fp_regs) / sizeof(u32),
555                 .get = fpregs_get, .set = fpregs_set
556         },
557         {
558                 .size = sizeof(u32), .align = sizeof(u32),
559                 .n = sizeof(per_struct) / sizeof(u32),
560                 .get = s390_per_info_get, .set = s390_per_info_set
561         },
562 };
563
564 const struct utrace_regset_view utrace_s390_compat_view = {
565         .name = "s390", .e_machine = EM_S390,
566         .regsets = s390_compat_regsets,
567         .n = sizeof s390_compat_regsets / sizeof s390_compat_regsets[0],
568 };
569 EXPORT_SYMBOL_GPL(utrace_s390_compat_view);
570 #endif  /* CONFIG_COMPAT */
571
572
573 #ifdef CONFIG_PTRACE
574 static const struct ptrace_layout_segment s390_uarea[] = {
575         {PT_PSWMASK, PT_FPC, 0, 0},
576         {PT_FPC, PT_CR_9, 1, 0},
577         {PT_CR_9, PT_IEEE_IP, 2, 0},
578         {PT_IEEE_IP, sizeof(struct user), -1, -1},
579         {0, 0, -1, 0}
580 };
581
582 fastcall int arch_ptrace(long *request, struct task_struct *child,
583                          struct utrace_attached_engine *engine,
584                          unsigned long addr, unsigned long data, long *val)
585 {
586         ptrace_area parea;
587         unsigned long tmp;
588         int copied;
589
590         switch (*request) {
591         case PTRACE_PEEKUSR:
592                 return ptrace_peekusr(child, engine, s390_uarea, addr, data);
593         case PTRACE_POKEUSR:
594                 return ptrace_pokeusr(child, engine, s390_uarea, addr, data);
595
596         case PTRACE_PEEKUSR_AREA:
597         case PTRACE_POKEUSR_AREA:
598                 if (copy_from_user(&parea, (ptrace_area __user *) addr,
599                                    sizeof(parea)))
600                         return -EFAULT;
601                 if ((parea.kernel_addr | parea.len) & (sizeof(data) - 1))
602                         return -EIO;
603                 return ptrace_layout_access(child, engine,
604                                             utrace_native_view(current),
605                                             s390_uarea,
606                                             parea.kernel_addr, parea.len,
607                                             (void __user *) parea.process_addr,
608                                             NULL,
609                                             *request == PTRACE_POKEUSR_AREA);
610
611         case PTRACE_PEEKTEXT:
612         case PTRACE_PEEKDATA:
613                 /* Remove high order bit from address (only for 31 bit). */
614                 addr &= PSW_ADDR_INSN;
615                 /* read word at location addr. */
616                 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
617                 if (copied != sizeof(tmp))
618                         return -EIO;
619                 return put_user(tmp, (unsigned long __user *) data);
620
621         case PTRACE_POKETEXT:
622         case PTRACE_POKEDATA:
623                 /* Remove high order bit from address (only for 31 bit). */
624                 addr &= PSW_ADDR_INSN;
625                 /* write the word at location addr. */
626                 copied = access_process_vm(child, addr, &data, sizeof(data),1);
627                 if (copied != sizeof(data))
628                         return -EIO;
629                 return 0;
630         }
631
632         return -ENOSYS;
633 }
634
635 #ifdef CONFIG_COMPAT
636 static const struct ptrace_layout_segment s390_compat_uarea[] = {
637         {PT_PSWMASK / 2, PT_FPC / 2, 0, 0},
638         {PT_FPC / 2, PT_CR_9 / 2, 1, 0},
639         {PT_CR_9 / 2, PT_IEEE_IP / 2, 2, 0},
640         {PT_IEEE_IP / 2, sizeof(struct user32), -1, -1},
641         {0, 0, -1, 0}
642 };
643
644 fastcall int arch_compat_ptrace(compat_long_t *request,
645                                 struct task_struct *child,
646                                 struct utrace_attached_engine *engine,
647                                 compat_ulong_t addr, compat_ulong_t data,
648                                 compat_long_t *val)
649 {
650         ptrace_area_emu31 parea;
651
652         switch (*request) {
653         case PTRACE_PEEKUSR:
654                 return ptrace_compat_peekusr(child, engine, s390_compat_uarea,
655                                              addr, data);
656         case PTRACE_POKEUSR:
657                 return ptrace_compat_pokeusr(child, engine, s390_compat_uarea,
658                                              addr, data);
659         case PTRACE_PEEKUSR_AREA:
660         case PTRACE_POKEUSR_AREA:
661                 if (copy_from_user(&parea, ((ptrace_area_emu31 __user *)
662                                             (unsigned long) addr),
663                                    sizeof(parea)))
664                         return -EFAULT;
665                 if ((parea.kernel_addr | parea.len) & (sizeof(data) - 1))
666                         return -EIO;
667                 return ptrace_layout_access(child, engine,
668                                             utrace_native_view(current),
669                                             s390_compat_uarea,
670                                             parea.kernel_addr, parea.len,
671                                             (void __user *)
672                                             (unsigned long) parea.process_addr,
673                                             NULL,
674                                             *request == PTRACE_POKEUSR_AREA);
675         }
676
677         return -ENOSYS;
678 }
679 #endif  /* CONFIG_COMPAT */
680 #endif  /* CONFIG_PTRACE */
681
682
683 #if 0                           /* XXX */
684
685 #ifndef CONFIG_64BIT
686 # define __ADDR_MASK 3
687 #else
688 # define __ADDR_MASK 7
689 #endif
690
691 /*
692  * Read the word at offset addr from the user area of a process. The
693  * trouble here is that the information is littered over different
694  * locations. The process registers are found on the kernel stack,
695  * the floating point stuff and the trace settings are stored in
696  * the task structure. In addition the different structures in
697  * struct user contain pad bytes that should be read as zeroes.
698  * Lovely...
699  */
700 static int
701 peek_user(struct task_struct *child, addr_t addr, addr_t data)
702 {
703         struct user *dummy = NULL;
704         addr_t offset, tmp, mask;
705
706         /*
707          * Stupid gdb peeks/pokes the access registers in 64 bit with
708          * an alignment of 4. Programmers from hell...
709          */
710         mask = __ADDR_MASK;
711 #ifdef CONFIG_64BIT
712         if (addr >= (addr_t) &dummy->regs.acrs &&
713             addr < (addr_t) &dummy->regs.orig_gpr2)
714                 mask = 3;
715 #endif
716         if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
717                 return -EIO;
718
719         if (addr < (addr_t) &dummy->regs.acrs) {
720                 /*
721                  * psw and gprs are stored on the stack
722                  */
723                 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
724                 if (addr == (addr_t) &dummy->regs.psw.mask)
725                         /* Remove per bit from user psw. */
726                         tmp &= ~PSW_MASK_PER;
727
728         } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
729                 /*
730                  * access registers are stored in the thread structure
731                  */
732                 offset = addr - (addr_t) &dummy->regs.acrs;
733 #ifdef CONFIG_64BIT
734                 /*
735                  * Very special case: old & broken 64 bit gdb reading
736                  * from acrs[15]. Result is a 64 bit value. Read the
737                  * 32 bit acrs[15] value and shift it by 32. Sick...
738                  */
739                 if (addr == (addr_t) &dummy->regs.acrs[15])
740                         tmp = ((unsigned long) child->thread.acrs[15]) << 32;
741                 else
742 #endif
743                 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
744
745         } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
746                 /*
747                  * orig_gpr2 is stored on the kernel stack
748                  */
749                 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
750
751         } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
752                 /* 
753                  * floating point regs. are stored in the thread structure
754                  */
755                 offset = addr - (addr_t) &dummy->regs.fp_regs;
756                 tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
757                 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
758                         tmp &= (unsigned long) FPC_VALID_MASK
759                                 << (BITS_PER_LONG - 32);
760
761         } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
762                 /*
763                  * per_info is found in the thread structure
764                  */
765                 offset = addr - (addr_t) &dummy->regs.per_info;
766                 tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset);
767
768         } else
769                 tmp = 0;
770
771         return put_user(tmp, (addr_t __user *) data);
772 }
773
774 /*
775  * Write a word to the user area of a process at location addr. This
776  * operation does have an additional problem compared to peek_user.
777  * Stores to the program status word and on the floating point
778  * control register needs to get checked for validity.
779  */
780 static int
781 poke_user(struct task_struct *child, addr_t addr, addr_t data)
782 {
783         struct user *dummy = NULL;
784         addr_t offset, mask;
785
786         /*
787          * Stupid gdb peeks/pokes the access registers in 64 bit with
788          * an alignment of 4. Programmers from hell indeed...
789          */
790         mask = __ADDR_MASK;
791 #ifdef CONFIG_64BIT
792         if (addr >= (addr_t) &dummy->regs.acrs &&
793             addr < (addr_t) &dummy->regs.orig_gpr2)
794                 mask = 3;
795 #endif
796         if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
797                 return -EIO;
798
799         if (addr < (addr_t) &dummy->regs.acrs) {
800                 /*
801                  * psw and gprs are stored on the stack
802                  */
803                 if (addr == (addr_t) &dummy->regs.psw.mask &&
804 #ifdef CONFIG_COMPAT
805                     data != PSW_MASK_MERGE(PSW_USER32_BITS, data) &&
806 #endif
807                     data != PSW_MASK_MERGE(PSW_USER_BITS, data))
808                         /* Invalid psw mask. */
809                         return -EINVAL;
810 #ifndef CONFIG_64BIT
811                 if (addr == (addr_t) &dummy->regs.psw.addr)
812                         /* I'd like to reject addresses without the
813                            high order bit but older gdb's rely on it */
814                         data |= PSW_ADDR_AMODE;
815 #endif
816                 *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
817
818         } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
819                 /*
820                  * access registers are stored in the thread structure
821                  */
822                 offset = addr - (addr_t) &dummy->regs.acrs;
823 #ifdef CONFIG_64BIT
824                 /*
825                  * Very special case: old & broken 64 bit gdb writing
826                  * to acrs[15] with a 64 bit value. Ignore the lower
827                  * half of the value and write the upper 32 bit to
828                  * acrs[15]. Sick...
829                  */
830                 if (addr == (addr_t) &dummy->regs.acrs[15])
831                         child->thread.acrs[15] = (unsigned int) (data >> 32);
832                 else
833 #endif
834                 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
835
836         } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
837                 /*
838                  * orig_gpr2 is stored on the kernel stack
839                  */
840                 task_pt_regs(child)->orig_gpr2 = data;
841
842         } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
843                 /*
844                  * floating point regs. are stored in the thread structure
845                  */
846                 if (addr == (addr_t) &dummy->regs.fp_regs.fpc &&
847                     (data & ~((unsigned long) FPC_VALID_MASK
848                               << (BITS_PER_LONG - 32))) != 0)
849                         return -EINVAL;
850                 offset = addr - (addr_t) &dummy->regs.fp_regs;
851                 *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
852
853         } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
854                 /*
855                  * per_info is found in the thread structure 
856                  */
857                 offset = addr - (addr_t) &dummy->regs.per_info;
858                 *(addr_t *)((addr_t) &child->thread.per_info + offset) = data;
859
860         }
861
862         FixPerRegisters(child);
863         return 0;
864 }
865
866 static int
867 do_ptrace_normal(struct task_struct *child, long request, long addr, long data)
868 {
869         unsigned long tmp;
870         ptrace_area parea; 
871         int copied, ret;
872
873         switch (request) {
874         case PTRACE_PEEKTEXT:
875         case PTRACE_PEEKDATA:
876                 /* Remove high order bit from address (only for 31 bit). */
877                 addr &= PSW_ADDR_INSN;
878                 /* read word at location addr. */
879                 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
880                 if (copied != sizeof(tmp))
881                         return -EIO;
882                 return put_user(tmp, (unsigned long __user *) data);
883
884         case PTRACE_PEEKUSR:
885                 /* read the word at location addr in the USER area. */
886                 return peek_user(child, addr, data);
887
888         case PTRACE_POKETEXT:
889         case PTRACE_POKEDATA:
890                 /* Remove high order bit from address (only for 31 bit). */
891                 addr &= PSW_ADDR_INSN;
892                 /* write the word at location addr. */
893                 copied = access_process_vm(child, addr, &data, sizeof(data),1);
894                 if (copied != sizeof(data))
895                         return -EIO;
896                 return 0;
897
898         case PTRACE_POKEUSR:
899                 /* write the word at location addr in the USER area */
900                 return poke_user(child, addr, data);
901
902         case PTRACE_PEEKUSR_AREA:
903         case PTRACE_POKEUSR_AREA:
904                 if (copy_from_user(&parea, (void __user *) addr,
905                                                         sizeof(parea)))
906                         return -EFAULT;
907                 addr = parea.kernel_addr;
908                 data = parea.process_addr;
909                 copied = 0;
910                 while (copied < parea.len) {
911                         if (request == PTRACE_PEEKUSR_AREA)
912                                 ret = peek_user(child, addr, data);
913                         else {
914                                 addr_t tmp;
915                                 if (get_user (tmp, (addr_t __user *) data))
916                                         return -EFAULT;
917                                 ret = poke_user(child, addr, tmp);
918                         }
919                         if (ret)
920                                 return ret;
921                         addr += sizeof(unsigned long);
922                         data += sizeof(unsigned long);
923                         copied += sizeof(unsigned long);
924                 }
925                 return 0;
926         }
927         return ptrace_request(child, request, addr, data);
928 }
929
930 #ifdef CONFIG_COMPAT
931 /*
932  * Now the fun part starts... a 31 bit program running in the
933  * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
934  * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
935  * to handle, the difference to the 64 bit versions of the requests
936  * is that the access is done in multiples of 4 byte instead of
937  * 8 bytes (sizeof(unsigned long) on 31/64 bit).
938  * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
939  * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
940  * is a 31 bit program too, the content of struct user can be
941  * emulated. A 31 bit program peeking into the struct user of
942  * a 64 bit program is a no-no.
943  */
944
945 /*
946  * Same as peek_user but for a 31 bit program.
947  */
948 static int
949 peek_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
950 {
951         struct user32 *dummy32 = NULL;
952         per_struct32 *dummy_per32 = NULL;
953         addr_t offset;
954         __u32 tmp;
955
956         if (!test_thread_flag(TIF_31BIT) ||
957             (addr & 3) || addr > sizeof(struct user) - 3)
958                 return -EIO;
959
960         if (addr < (addr_t) &dummy32->regs.acrs) {
961                 /*
962                  * psw and gprs are stored on the stack
963                  */
964                 if (addr == (addr_t) &dummy32->regs.psw.mask) {
965                         /* Fake a 31 bit psw mask. */
966                         tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32);
967                         tmp = PSW32_MASK_MERGE(PSW32_USER_BITS, tmp);
968                 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
969                         /* Fake a 31 bit psw address. */
970                         tmp = (__u32) task_pt_regs(child)->psw.addr |
971                                 PSW32_ADDR_AMODE31;
972                 } else {
973                         /* gpr 0-15 */
974                         tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw +
975                                          addr*2 + 4);
976                 }
977         } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
978                 /*
979                  * access registers are stored in the thread structure
980                  */
981                 offset = addr - (addr_t) &dummy32->regs.acrs;
982                 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
983
984         } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
985                 /*
986                  * orig_gpr2 is stored on the kernel stack
987                  */
988                 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
989
990         } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
991                 /*
992                  * floating point regs. are stored in the thread structure 
993                  */
994                 offset = addr - (addr_t) &dummy32->regs.fp_regs;
995                 tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
996
997         } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
998                 /*
999                  * per_info is found in the thread structure
1000                  */
1001                 offset = addr - (addr_t) &dummy32->regs.per_info;
1002                 /* This is magic. See per_struct and per_struct32. */
1003                 if ((offset >= (addr_t) &dummy_per32->control_regs &&
1004                      offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
1005                     (offset >= (addr_t) &dummy_per32->starting_addr &&
1006                      offset <= (addr_t) &dummy_per32->ending_addr) ||
1007                     offset == (addr_t) &dummy_per32->lowcore.words.address)
1008                         offset = offset*2 + 4;
1009                 else
1010                         offset = offset*2;
1011                 tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset);
1012
1013         } else
1014                 tmp = 0;
1015
1016         return put_user(tmp, (__u32 __user *) data);
1017 }
1018
1019 /*
1020  * Same as poke_user but for a 31 bit program.
1021  */
1022 static int
1023 poke_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
1024 {
1025         struct user32 *dummy32 = NULL;
1026         per_struct32 *dummy_per32 = NULL;
1027         addr_t offset;
1028         __u32 tmp;
1029
1030         if (!test_thread_flag(TIF_31BIT) ||
1031             (addr & 3) || addr > sizeof(struct user32) - 3)
1032                 return -EIO;
1033
1034         tmp = (__u32) data;
1035
1036         if (addr < (addr_t) &dummy32->regs.acrs) {
1037                 /*
1038                  * psw, gprs, acrs and orig_gpr2 are stored on the stack
1039                  */
1040                 if (addr == (addr_t) &dummy32->regs.psw.mask) {
1041                         /* Build a 64 bit psw mask from 31 bit mask. */
1042                         if (tmp != PSW32_MASK_MERGE(PSW32_USER_BITS, tmp))
1043                                 /* Invalid psw mask. */
1044                                 return -EINVAL;
1045                         task_pt_regs(child)->psw.mask =
1046                                 PSW_MASK_MERGE(PSW_USER32_BITS, (__u64) tmp << 32);
1047                 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
1048                         /* Build a 64 bit psw address from 31 bit address. */
1049                         task_pt_regs(child)->psw.addr =
1050                                 (__u64) tmp & PSW32_ADDR_INSN;
1051                 } else {
1052                         /* gpr 0-15 */
1053                         *(__u32*)((addr_t) &task_pt_regs(child)->psw
1054                                   + addr*2 + 4) = tmp;
1055                 }
1056         } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
1057                 /*
1058                  * access registers are stored in the thread structure
1059                  */
1060                 offset = addr - (addr_t) &dummy32->regs.acrs;
1061                 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
1062
1063         } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
1064                 /*
1065                  * orig_gpr2 is stored on the kernel stack
1066                  */
1067                 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
1068
1069         } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
1070                 /*
1071                  * floating point regs. are stored in the thread structure 
1072                  */
1073                 if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
1074                     (tmp & ~FPC_VALID_MASK) != 0)
1075                         /* Invalid floating point control. */
1076                         return -EINVAL;
1077                 offset = addr - (addr_t) &dummy32->regs.fp_regs;
1078                 *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
1079
1080         } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
1081                 /*
1082                  * per_info is found in the thread structure.
1083                  */
1084                 offset = addr - (addr_t) &dummy32->regs.per_info;
1085                 /*
1086                  * This is magic. See per_struct and per_struct32.
1087                  * By incident the offsets in per_struct are exactly
1088                  * twice the offsets in per_struct32 for all fields.
1089                  * The 8 byte fields need special handling though,
1090                  * because the second half (bytes 4-7) is needed and
1091                  * not the first half.
1092                  */
1093                 if ((offset >= (addr_t) &dummy_per32->control_regs &&
1094                      offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
1095                     (offset >= (addr_t) &dummy_per32->starting_addr &&
1096                      offset <= (addr_t) &dummy_per32->ending_addr) ||
1097                     offset == (addr_t) &dummy_per32->lowcore.words.address)
1098                         offset = offset*2 + 4;
1099                 else
1100                         offset = offset*2;
1101                 *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp;
1102
1103         }
1104
1105         FixPerRegisters(child);
1106         return 0;
1107 }
1108
1109 static int
1110 do_ptrace_emu31(struct task_struct *child, long request, long addr, long data)
1111 {
1112         unsigned int tmp;  /* 4 bytes !! */
1113         ptrace_area_emu31 parea; 
1114         int copied, ret;
1115
1116         switch (request) {
1117         case PTRACE_PEEKTEXT:
1118         case PTRACE_PEEKDATA:
1119                 /* read word at location addr. */
1120                 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
1121                 if (copied != sizeof(tmp))
1122                         return -EIO;
1123                 return put_user(tmp, (unsigned int __user *) data);
1124
1125         case PTRACE_PEEKUSR:
1126                 /* read the word at location addr in the USER area. */
1127                 return peek_user_emu31(child, addr, data);
1128
1129         case PTRACE_POKETEXT:
1130         case PTRACE_POKEDATA:
1131                 /* write the word at location addr. */
1132                 tmp = data;
1133                 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 1);
1134                 if (copied != sizeof(tmp))
1135                         return -EIO;
1136                 return 0;
1137
1138         case PTRACE_POKEUSR:
1139                 /* write the word at location addr in the USER area */
1140                 return poke_user_emu31(child, addr, data);
1141
1142         case PTRACE_PEEKUSR_AREA:
1143         case PTRACE_POKEUSR_AREA:
1144                 if (copy_from_user(&parea, (void __user *) addr,
1145                                                         sizeof(parea)))
1146                         return -EFAULT;
1147                 addr = parea.kernel_addr;
1148                 data = parea.process_addr;
1149                 copied = 0;
1150                 while (copied < parea.len) {
1151                         if (request == PTRACE_PEEKUSR_AREA)
1152                                 ret = peek_user_emu31(child, addr, data);
1153                         else {
1154                                 __u32 tmp;
1155                                 if (get_user (tmp, (__u32 __user *) data))
1156                                         return -EFAULT;
1157                                 ret = poke_user_emu31(child, addr, tmp);
1158                         }
1159                         if (ret)
1160                                 return ret;
1161                         addr += sizeof(unsigned int);
1162                         data += sizeof(unsigned int);
1163                         copied += sizeof(unsigned int);
1164                 }
1165                 return 0;
1166 #if 0                           /* XXX */
1167         case PTRACE_GETEVENTMSG:
1168                 return put_user((__u32) child->ptrace_message,
1169                                 (unsigned int __user *) data);
1170         case PTRACE_GETSIGINFO:
1171                 if (child->last_siginfo == NULL)
1172                         return -EINVAL;
1173                 return copy_siginfo_to_user32((compat_siginfo_t __user *) data,
1174                                               child->last_siginfo);
1175         case PTRACE_SETSIGINFO:
1176                 if (child->last_siginfo == NULL)
1177                         return -EINVAL;
1178                 return copy_siginfo_from_user32(child->last_siginfo,
1179                                                 (compat_siginfo_t __user *) data);
1180 #endif
1181         }
1182         return ptrace_request(child, request, addr, data);
1183 }
1184 #endif
1185
1186 #define PT32_IEEE_IP 0x13c
1187
1188 static int
1189 do_ptrace(struct task_struct *child, long request, long addr, long data)
1190 {
1191         int ret;
1192
1193         if (request == PTRACE_ATTACH)
1194                 return ptrace_attach(child);
1195
1196         /*
1197          * Special cases to get/store the ieee instructions pointer.
1198          */
1199         if (child == current) {
1200                 if (request == PTRACE_PEEKUSR && addr == PT_IEEE_IP)
1201                         return peek_user(child, addr, data);
1202                 if (request == PTRACE_POKEUSR && addr == PT_IEEE_IP)
1203                         return poke_user(child, addr, data);
1204 #ifdef CONFIG_COMPAT
1205                 if (request == PTRACE_PEEKUSR &&
1206                     addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT))
1207                         return peek_user_emu31(child, addr, data);
1208                 if (request == PTRACE_POKEUSR &&
1209                     addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT))
1210                         return poke_user_emu31(child, addr, data);
1211 #endif
1212         }
1213
1214         ret = ptrace_check_attach(child, request == PTRACE_KILL);
1215         if (ret < 0)
1216                 return ret;
1217
1218         switch (request) {
1219         case PTRACE_SYSCALL:
1220                 /* continue and stop at next (return from) syscall */
1221         case PTRACE_CONT:
1222                 /* restart after signal. */
1223                 if (!valid_signal(data))
1224                         return -EIO;
1225                 if (request == PTRACE_SYSCALL)
1226                         set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
1227                 else
1228                         clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
1229                 child->exit_code = data;
1230                 /* make sure the single step bit is not set. */
1231                 tracehook_disable_single_step(child);
1232                 wake_up_process(child);
1233                 return 0;
1234
1235         case PTRACE_KILL:
1236                 /*
1237                  * make the child exit.  Best I can do is send it a sigkill. 
1238                  * perhaps it should be put in the status that it wants to 
1239                  * exit.
1240                  */
1241                 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
1242                         return 0;
1243                 child->exit_code = SIGKILL;
1244                 /* make sure the single step bit is not set. */
1245                 tracehook_disable_single_step(child);
1246                 wake_up_process(child);
1247                 return 0;
1248
1249         case PTRACE_SINGLESTEP:
1250                 /* set the trap flag. */
1251                 if (!valid_signal(data))
1252                         return -EIO;
1253                 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
1254                 child->exit_code = data;
1255                 if (data)
1256                         set_tsk_thread_flag(child, TIF_SINGLE_STEP);
1257                 else
1258                         tracehook_enable_single_step(child);
1259                 /* give it a chance to run. */
1260                 wake_up_process(child);
1261                 return 0;
1262
1263         case PTRACE_DETACH:
1264                 /* detach a process that was attached. */
1265                 return ptrace_detach(child, data);
1266
1267
1268         /* Do requests that differ for 31/64 bit */
1269         default:
1270 #ifdef CONFIG_COMPAT
1271                 if (test_thread_flag(TIF_31BIT))
1272                         return do_ptrace_emu31(child, request, addr, data);
1273 #endif
1274                 return do_ptrace_normal(child, request, addr, data);
1275         }
1276         /* Not reached.  */
1277         return -EIO;
1278 }
1279 #endif
1280
1281
1282
1283 asmlinkage void
1284 syscall_trace(struct pt_regs *regs, int entryexit)
1285 {
1286         if (unlikely(current->audit_context) && entryexit)
1287                 audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]);
1288
1289         if (test_thread_flag(TIF_SYSCALL_TRACE)) {
1290                 tracehook_report_syscall(regs, entryexit);
1291
1292                 /*
1293                  * If the debugger has set an invalid system call number,
1294                  * we prepare to skip the system call restart handling.
1295                  */
1296                 if (!entryexit && regs->gprs[2] >= NR_syscalls)
1297                         regs->trap = -1;
1298         }
1299
1300         if (unlikely(current->audit_context) && !entryexit)
1301                 audit_syscall_entry(test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X,
1302                                     regs->gprs[2], regs->orig_gpr2, regs->gprs[3],
1303                                     regs->gprs[4], regs->gprs[5]);
1304 }