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