Automatic merge with /usr/src/ntfs-2.6.git.
[sfrench/cifs-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/user.h>
33 #include <linux/security.h>
34 #include <linux/audit.h>
35 #include <linux/signal.h>
36
37 #include <asm/segment.h>
38 #include <asm/page.h>
39 #include <asm/pgtable.h>
40 #include <asm/pgalloc.h>
41 #include <asm/system.h>
42 #include <asm/uaccess.h>
43
44 #ifdef CONFIG_S390_SUPPORT
45 #include "compat_ptrace.h"
46 #endif
47
48 static void
49 FixPerRegisters(struct task_struct *task)
50 {
51         struct pt_regs *regs;
52         per_struct *per_info;
53
54         regs = __KSTK_PTREGS(task);
55         per_info = (per_struct *) &task->thread.per_info;
56         per_info->control_regs.bits.em_instruction_fetch =
57                 per_info->single_step | per_info->instruction_fetch;
58         
59         if (per_info->single_step) {
60                 per_info->control_regs.bits.starting_addr = 0;
61 #ifdef CONFIG_S390_SUPPORT
62                 if (test_thread_flag(TIF_31BIT))
63                         per_info->control_regs.bits.ending_addr = 0x7fffffffUL;
64                 else
65 #endif
66                         per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN;
67         } else {
68                 per_info->control_regs.bits.starting_addr =
69                         per_info->starting_addr;
70                 per_info->control_regs.bits.ending_addr =
71                         per_info->ending_addr;
72         }
73         /*
74          * if any of the control reg tracing bits are on 
75          * we switch on per in the psw
76          */
77         if (per_info->control_regs.words.cr[0] & PER_EM_MASK)
78                 regs->psw.mask |= PSW_MASK_PER;
79         else
80                 regs->psw.mask &= ~PSW_MASK_PER;
81
82         if (per_info->control_regs.bits.em_storage_alteration)
83                 per_info->control_regs.bits.storage_alt_space_ctl = 1;
84         else
85                 per_info->control_regs.bits.storage_alt_space_ctl = 0;
86 }
87
88 void
89 set_single_step(struct task_struct *task)
90 {
91         task->thread.per_info.single_step = 1;
92         FixPerRegisters(task);
93 }
94
95 void
96 clear_single_step(struct task_struct *task)
97 {
98         task->thread.per_info.single_step = 0;
99         FixPerRegisters(task);
100 }
101
102 /*
103  * Called by kernel/ptrace.c when detaching..
104  *
105  * Make sure single step bits etc are not set.
106  */
107 void
108 ptrace_disable(struct task_struct *child)
109 {
110         /* make sure the single step bit is not set. */
111         clear_single_step(child);
112 }
113
114 #ifndef CONFIG_ARCH_S390X
115 # define __ADDR_MASK 3
116 #else
117 # define __ADDR_MASK 7
118 #endif
119
120 /*
121  * Read the word at offset addr from the user area of a process. The
122  * trouble here is that the information is littered over different
123  * locations. The process registers are found on the kernel stack,
124  * the floating point stuff and the trace settings are stored in
125  * the task structure. In addition the different structures in
126  * struct user contain pad bytes that should be read as zeroes.
127  * Lovely...
128  */
129 static int
130 peek_user(struct task_struct *child, addr_t addr, addr_t data)
131 {
132         struct user *dummy = NULL;
133         addr_t offset, tmp;
134
135         /*
136          * Stupid gdb peeks/pokes the access registers in 64 bit with
137          * an alignment of 4. Programmers from hell...
138          */
139         if ((addr & 3) || addr > sizeof(struct user) - __ADDR_MASK)
140                 return -EIO;
141
142         if (addr < (addr_t) &dummy->regs.acrs) {
143                 /*
144                  * psw and gprs are stored on the stack
145                  */
146                 tmp = *(addr_t *)((addr_t) &__KSTK_PTREGS(child)->psw + addr);
147                 if (addr == (addr_t) &dummy->regs.psw.mask)
148                         /* Remove per bit from user psw. */
149                         tmp &= ~PSW_MASK_PER;
150
151         } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
152                 /*
153                  * access registers are stored in the thread structure
154                  */
155                 offset = addr - (addr_t) &dummy->regs.acrs;
156                 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
157
158         } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
159                 /*
160                  * orig_gpr2 is stored on the kernel stack
161                  */
162                 tmp = (addr_t) __KSTK_PTREGS(child)->orig_gpr2;
163
164         } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
165                 /* 
166                  * floating point regs. are stored in the thread structure
167                  */
168                 offset = addr - (addr_t) &dummy->regs.fp_regs;
169                 tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
170
171         } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
172                 /*
173                  * per_info is found in the thread structure
174                  */
175                 offset = addr - (addr_t) &dummy->regs.per_info;
176                 tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset);
177
178         } else
179                 tmp = 0;
180
181         return put_user(tmp, (addr_t __user *) data);
182 }
183
184 /*
185  * Write a word to the user area of a process at location addr. This
186  * operation does have an additional problem compared to peek_user.
187  * Stores to the program status word and on the floating point
188  * control register needs to get checked for validity.
189  */
190 static int
191 poke_user(struct task_struct *child, addr_t addr, addr_t data)
192 {
193         struct user *dummy = NULL;
194         addr_t offset;
195
196         /*
197          * Stupid gdb peeks/pokes the access registers in 64 bit with
198          * an alignment of 4. Programmers from hell indeed...
199          */
200         if ((addr & 3) || addr > sizeof(struct user) - __ADDR_MASK)
201                 return -EIO;
202
203         if (addr < (addr_t) &dummy->regs.acrs) {
204                 /*
205                  * psw and gprs are stored on the stack
206                  */
207                 if (addr == (addr_t) &dummy->regs.psw.mask &&
208 #ifdef CONFIG_S390_SUPPORT
209                     data != PSW_MASK_MERGE(PSW_USER32_BITS, data) &&
210 #endif
211                     data != PSW_MASK_MERGE(PSW_USER_BITS, data))
212                         /* Invalid psw mask. */
213                         return -EINVAL;
214 #ifndef CONFIG_ARCH_S390X
215                 if (addr == (addr_t) &dummy->regs.psw.addr)
216                         /* I'd like to reject addresses without the
217                            high order bit but older gdb's rely on it */
218                         data |= PSW_ADDR_AMODE;
219 #endif
220                 *(addr_t *)((addr_t) &__KSTK_PTREGS(child)->psw + addr) = data;
221
222         } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
223                 /*
224                  * access registers are stored in the thread structure
225                  */
226                 offset = addr - (addr_t) &dummy->regs.acrs;
227                 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
228
229         } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
230                 /*
231                  * orig_gpr2 is stored on the kernel stack
232                  */
233                 __KSTK_PTREGS(child)->orig_gpr2 = data;
234
235         } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
236                 /*
237                  * floating point regs. are stored in the thread structure
238                  */
239                 if (addr == (addr_t) &dummy->regs.fp_regs.fpc &&
240                     (data & ~FPC_VALID_MASK) != 0)
241                         return -EINVAL;
242                 offset = addr - (addr_t) &dummy->regs.fp_regs;
243                 *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
244
245         } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
246                 /*
247                  * per_info is found in the thread structure 
248                  */
249                 offset = addr - (addr_t) &dummy->regs.per_info;
250                 *(addr_t *)((addr_t) &child->thread.per_info + offset) = data;
251
252         }
253
254         FixPerRegisters(child);
255         return 0;
256 }
257
258 static int
259 do_ptrace_normal(struct task_struct *child, long request, long addr, long data)
260 {
261         unsigned long tmp;
262         ptrace_area parea; 
263         int copied, ret;
264
265         switch (request) {
266         case PTRACE_PEEKTEXT:
267         case PTRACE_PEEKDATA:
268                 /* Remove high order bit from address (only for 31 bit). */
269                 addr &= PSW_ADDR_INSN;
270                 /* read word at location addr. */
271                 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
272                 if (copied != sizeof(tmp))
273                         return -EIO;
274                 return put_user(tmp, (unsigned long __user *) data);
275
276         case PTRACE_PEEKUSR:
277                 /* read the word at location addr in the USER area. */
278                 return peek_user(child, addr, data);
279
280         case PTRACE_POKETEXT:
281         case PTRACE_POKEDATA:
282                 /* Remove high order bit from address (only for 31 bit). */
283                 addr &= PSW_ADDR_INSN;
284                 /* write the word at location addr. */
285                 copied = access_process_vm(child, addr, &data, sizeof(data),1);
286                 if (copied != sizeof(data))
287                         return -EIO;
288                 return 0;
289
290         case PTRACE_POKEUSR:
291                 /* write the word at location addr in the USER area */
292                 return poke_user(child, addr, data);
293
294         case PTRACE_PEEKUSR_AREA:
295         case PTRACE_POKEUSR_AREA:
296                 if (copy_from_user(&parea, (void __user *) addr,
297                                                         sizeof(parea)))
298                         return -EFAULT;
299                 addr = parea.kernel_addr;
300                 data = parea.process_addr;
301                 copied = 0;
302                 while (copied < parea.len) {
303                         if (request == PTRACE_PEEKUSR_AREA)
304                                 ret = peek_user(child, addr, data);
305                         else {
306                                 addr_t tmp;
307                                 if (get_user (tmp, (addr_t __user *) data))
308                                         return -EFAULT;
309                                 ret = poke_user(child, addr, tmp);
310                         }
311                         if (ret)
312                                 return ret;
313                         addr += sizeof(unsigned long);
314                         data += sizeof(unsigned long);
315                         copied += sizeof(unsigned long);
316                 }
317                 return 0;
318         }
319         return ptrace_request(child, request, addr, data);
320 }
321
322 #ifdef CONFIG_S390_SUPPORT
323 /*
324  * Now the fun part starts... a 31 bit program running in the
325  * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
326  * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
327  * to handle, the difference to the 64 bit versions of the requests
328  * is that the access is done in multiples of 4 byte instead of
329  * 8 bytes (sizeof(unsigned long) on 31/64 bit).
330  * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
331  * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
332  * is a 31 bit program too, the content of struct user can be
333  * emulated. A 31 bit program peeking into the struct user of
334  * a 64 bit program is a no-no.
335  */
336
337 /*
338  * Same as peek_user but for a 31 bit program.
339  */
340 static int
341 peek_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
342 {
343         struct user32 *dummy32 = NULL;
344         per_struct32 *dummy_per32 = NULL;
345         addr_t offset;
346         __u32 tmp;
347
348         if (!test_thread_flag(TIF_31BIT) ||
349             (addr & 3) || addr > sizeof(struct user) - 3)
350                 return -EIO;
351
352         if (addr < (addr_t) &dummy32->regs.acrs) {
353                 /*
354                  * psw and gprs are stored on the stack
355                  */
356                 if (addr == (addr_t) &dummy32->regs.psw.mask) {
357                         /* Fake a 31 bit psw mask. */
358                         tmp = (__u32)(__KSTK_PTREGS(child)->psw.mask >> 32);
359                         tmp = PSW32_MASK_MERGE(PSW32_USER_BITS, tmp);
360                 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
361                         /* Fake a 31 bit psw address. */
362                         tmp = (__u32) __KSTK_PTREGS(child)->psw.addr |
363                                 PSW32_ADDR_AMODE31;
364                 } else {
365                         /* gpr 0-15 */
366                         tmp = *(__u32 *)((addr_t) &__KSTK_PTREGS(child)->psw +
367                                          addr*2 + 4);
368                 }
369         } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
370                 /*
371                  * access registers are stored in the thread structure
372                  */
373                 offset = addr - (addr_t) &dummy32->regs.acrs;
374                 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
375
376         } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
377                 /*
378                  * orig_gpr2 is stored on the kernel stack
379                  */
380                 tmp = *(__u32*)((addr_t) &__KSTK_PTREGS(child)->orig_gpr2 + 4);
381
382         } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
383                 /*
384                  * floating point regs. are stored in the thread structure 
385                  */
386                 offset = addr - (addr_t) &dummy32->regs.fp_regs;
387                 tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
388
389         } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
390                 /*
391                  * per_info is found in the thread structure
392                  */
393                 offset = addr - (addr_t) &dummy32->regs.per_info;
394                 /* This is magic. See per_struct and per_struct32. */
395                 if ((offset >= (addr_t) &dummy_per32->control_regs &&
396                      offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
397                     (offset >= (addr_t) &dummy_per32->starting_addr &&
398                      offset <= (addr_t) &dummy_per32->ending_addr) ||
399                     offset == (addr_t) &dummy_per32->lowcore.words.address)
400                         offset = offset*2 + 4;
401                 else
402                         offset = offset*2;
403                 tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset);
404
405         } else
406                 tmp = 0;
407
408         return put_user(tmp, (__u32 __user *) data);
409 }
410
411 /*
412  * Same as poke_user but for a 31 bit program.
413  */
414 static int
415 poke_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
416 {
417         struct user32 *dummy32 = NULL;
418         per_struct32 *dummy_per32 = NULL;
419         addr_t offset;
420         __u32 tmp;
421
422         if (!test_thread_flag(TIF_31BIT) ||
423             (addr & 3) || addr > sizeof(struct user32) - 3)
424                 return -EIO;
425
426         tmp = (__u32) data;
427
428         if (addr < (addr_t) &dummy32->regs.acrs) {
429                 /*
430                  * psw, gprs, acrs and orig_gpr2 are stored on the stack
431                  */
432                 if (addr == (addr_t) &dummy32->regs.psw.mask) {
433                         /* Build a 64 bit psw mask from 31 bit mask. */
434                         if (tmp != PSW32_MASK_MERGE(PSW32_USER_BITS, tmp))
435                                 /* Invalid psw mask. */
436                                 return -EINVAL;
437                         __KSTK_PTREGS(child)->psw.mask =
438                                 PSW_MASK_MERGE(PSW_USER32_BITS, (__u64) tmp << 32);
439                 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
440                         /* Build a 64 bit psw address from 31 bit address. */
441                         __KSTK_PTREGS(child)->psw.addr = 
442                                 (__u64) tmp & PSW32_ADDR_INSN;
443                 } else {
444                         /* gpr 0-15 */
445                         *(__u32*)((addr_t) &__KSTK_PTREGS(child)->psw
446                                   + addr*2 + 4) = tmp;
447                 }
448         } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
449                 /*
450                  * access registers are stored in the thread structure
451                  */
452                 offset = addr - (addr_t) &dummy32->regs.acrs;
453                 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
454
455         } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
456                 /*
457                  * orig_gpr2 is stored on the kernel stack
458                  */
459                 *(__u32*)((addr_t) &__KSTK_PTREGS(child)->orig_gpr2 + 4) = tmp;
460
461         } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
462                 /*
463                  * floating point regs. are stored in the thread structure 
464                  */
465                 if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
466                     (tmp & ~FPC_VALID_MASK) != 0)
467                         /* Invalid floating point control. */
468                         return -EINVAL;
469                 offset = addr - (addr_t) &dummy32->regs.fp_regs;
470                 *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
471
472         } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
473                 /*
474                  * per_info is found in the thread structure.
475                  */
476                 offset = addr - (addr_t) &dummy32->regs.per_info;
477                 /*
478                  * This is magic. See per_struct and per_struct32.
479                  * By incident the offsets in per_struct are exactly
480                  * twice the offsets in per_struct32 for all fields.
481                  * The 8 byte fields need special handling though,
482                  * because the second half (bytes 4-7) is needed and
483                  * not the first half.
484                  */
485                 if ((offset >= (addr_t) &dummy_per32->control_regs &&
486                      offset < (addr_t) (&dummy_per32->control_regs + 1)) ||
487                     (offset >= (addr_t) &dummy_per32->starting_addr &&
488                      offset <= (addr_t) &dummy_per32->ending_addr) ||
489                     offset == (addr_t) &dummy_per32->lowcore.words.address)
490                         offset = offset*2 + 4;
491                 else
492                         offset = offset*2;
493                 *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp;
494
495         }
496
497         FixPerRegisters(child);
498         return 0;
499 }
500
501 static int
502 do_ptrace_emu31(struct task_struct *child, long request, long addr, long data)
503 {
504         unsigned int tmp;  /* 4 bytes !! */
505         ptrace_area_emu31 parea; 
506         int copied, ret;
507
508         switch (request) {
509         case PTRACE_PEEKTEXT:
510         case PTRACE_PEEKDATA:
511                 /* read word at location addr. */
512                 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
513                 if (copied != sizeof(tmp))
514                         return -EIO;
515                 return put_user(tmp, (unsigned int __user *) data);
516
517         case PTRACE_PEEKUSR:
518                 /* read the word at location addr in the USER area. */
519                 return peek_user_emu31(child, addr, data);
520
521         case PTRACE_POKETEXT:
522         case PTRACE_POKEDATA:
523                 /* write the word at location addr. */
524                 tmp = data;
525                 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 1);
526                 if (copied != sizeof(tmp))
527                         return -EIO;
528                 return 0;
529
530         case PTRACE_POKEUSR:
531                 /* write the word at location addr in the USER area */
532                 return poke_user_emu31(child, addr, data);
533
534         case PTRACE_PEEKUSR_AREA:
535         case PTRACE_POKEUSR_AREA:
536                 if (copy_from_user(&parea, (void __user *) addr,
537                                                         sizeof(parea)))
538                         return -EFAULT;
539                 addr = parea.kernel_addr;
540                 data = parea.process_addr;
541                 copied = 0;
542                 while (copied < parea.len) {
543                         if (request == PTRACE_PEEKUSR_AREA)
544                                 ret = peek_user_emu31(child, addr, data);
545                         else {
546                                 __u32 tmp;
547                                 if (get_user (tmp, (__u32 __user *) data))
548                                         return -EFAULT;
549                                 ret = poke_user_emu31(child, addr, tmp);
550                         }
551                         if (ret)
552                                 return ret;
553                         addr += sizeof(unsigned int);
554                         data += sizeof(unsigned int);
555                         copied += sizeof(unsigned int);
556                 }
557                 return 0;
558         case PTRACE_GETEVENTMSG:
559                 return put_user((__u32) child->ptrace_message,
560                                 (unsigned int __user *) data);
561         case PTRACE_GETSIGINFO:
562                 if (child->last_siginfo == NULL)
563                         return -EINVAL;
564                 return copy_siginfo_to_user32((compat_siginfo_t __user *) data,
565                                               child->last_siginfo);
566         case PTRACE_SETSIGINFO:
567                 if (child->last_siginfo == NULL)
568                         return -EINVAL;
569                 return copy_siginfo_from_user32(child->last_siginfo,
570                                                 (compat_siginfo_t __user *) data);
571         }
572         return ptrace_request(child, request, addr, data);
573 }
574 #endif
575
576 #define PT32_IEEE_IP 0x13c
577
578 static int
579 do_ptrace(struct task_struct *child, long request, long addr, long data)
580 {
581         int ret;
582
583         if (request == PTRACE_ATTACH)
584                 return ptrace_attach(child);
585
586         /*
587          * Special cases to get/store the ieee instructions pointer.
588          */
589         if (child == current) {
590                 if (request == PTRACE_PEEKUSR && addr == PT_IEEE_IP)
591                         return peek_user(child, addr, data);
592                 if (request == PTRACE_POKEUSR && addr == PT_IEEE_IP)
593                         return poke_user(child, addr, data);
594 #ifdef CONFIG_S390_SUPPORT
595                 if (request == PTRACE_PEEKUSR &&
596                     addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT))
597                         return peek_user_emu31(child, addr, data);
598                 if (request == PTRACE_POKEUSR &&
599                     addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT))
600                         return poke_user_emu31(child, addr, data);
601 #endif
602         }
603
604         ret = ptrace_check_attach(child, request == PTRACE_KILL);
605         if (ret < 0)
606                 return ret;
607
608         switch (request) {
609         case PTRACE_SYSCALL:
610                 /* continue and stop at next (return from) syscall */
611         case PTRACE_CONT:
612                 /* restart after signal. */
613                 if (!valid_signal(data))
614                         return -EIO;
615                 if (request == PTRACE_SYSCALL)
616                         set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
617                 else
618                         clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
619                 child->exit_code = data;
620                 /* make sure the single step bit is not set. */
621                 clear_single_step(child);
622                 wake_up_process(child);
623                 return 0;
624
625         case PTRACE_KILL:
626                 /*
627                  * make the child exit.  Best I can do is send it a sigkill. 
628                  * perhaps it should be put in the status that it wants to 
629                  * exit.
630                  */
631                 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
632                         return 0;
633                 child->exit_code = SIGKILL;
634                 /* make sure the single step bit is not set. */
635                 clear_single_step(child);
636                 wake_up_process(child);
637                 return 0;
638
639         case PTRACE_SINGLESTEP:
640                 /* set the trap flag. */
641                 if (!valid_signal(data))
642                         return -EIO;
643                 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
644                 child->exit_code = data;
645                 if (data)
646                         set_tsk_thread_flag(child, TIF_SINGLE_STEP);
647                 else
648                         set_single_step(child);
649                 /* give it a chance to run. */
650                 wake_up_process(child);
651                 return 0;
652
653         case PTRACE_DETACH:
654                 /* detach a process that was attached. */
655                 return ptrace_detach(child, data);
656
657
658         /* Do requests that differ for 31/64 bit */
659         default:
660 #ifdef CONFIG_S390_SUPPORT
661                 if (test_thread_flag(TIF_31BIT))
662                         return do_ptrace_emu31(child, request, addr, data);
663 #endif
664                 return do_ptrace_normal(child, request, addr, data);
665         }
666         /* Not reached.  */
667         return -EIO;
668 }
669
670 asmlinkage long
671 sys_ptrace(long request, long pid, long addr, long data)
672 {
673         struct task_struct *child;
674         int ret;
675
676         lock_kernel();
677
678         if (request == PTRACE_TRACEME) {
679                 /* are we already being traced? */
680                 ret = -EPERM;
681                 if (current->ptrace & PT_PTRACED)
682                         goto out;
683                 ret = security_ptrace(current->parent, current);
684                 if (ret)
685                         goto out;
686                 /* set the ptrace bit in the process flags. */
687                 current->ptrace |= PT_PTRACED;
688                 goto out;
689         }
690
691         ret = -EPERM;
692         if (pid == 1)           /* you may not mess with init */
693                 goto out;
694
695         ret = -ESRCH;
696         read_lock(&tasklist_lock);
697         child = find_task_by_pid(pid);
698         if (child)
699                 get_task_struct(child);
700         read_unlock(&tasklist_lock);
701         if (!child)
702                 goto out;
703
704         ret = do_ptrace(child, request, addr, data);
705
706         put_task_struct(child);
707 out:
708         unlock_kernel();
709         return ret;
710 }
711
712 asmlinkage void
713 syscall_trace(struct pt_regs *regs, int entryexit)
714 {
715         if (unlikely(current->audit_context) && entryexit)
716                 audit_syscall_exit(current, AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]);
717
718         if (!test_thread_flag(TIF_SYSCALL_TRACE))
719                 goto out;
720         if (!(current->ptrace & PT_PTRACED))
721                 goto out;
722         ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
723                                  ? 0x80 : 0));
724
725         /*
726          * this isn't the same as continuing with a signal, but it will do
727          * for normal use.  strace only continues with a signal if the
728          * stopping signal is not SIGTRAP.  -brl
729          */
730         if (current->exit_code) {
731                 send_sig(current->exit_code, current, 1);
732                 current->exit_code = 0;
733         }
734  out:
735         if (unlikely(current->audit_context) && !entryexit)
736                 audit_syscall_entry(current, 
737                                     test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X,
738                                     regs->gprs[2], regs->orig_gpr2, regs->gprs[3],
739                                     regs->gprs[4], regs->gprs[5]);
740 }