2 * linux/arch/ppc64/kernel/ptrace.c
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Derived from "arch/m68k/kernel/ptrace.c"
8 * Copyright (C) 1994 by Hamish Macdonald
9 * Taken from linux/kernel/ptrace.c and modified for M680x0.
10 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
12 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
13 * and Paul Mackerras (paulus@linuxcare.com.au).
15 * This file is subject to the terms and conditions of the GNU General
16 * Public License. See the file README.legal in the main directory of
17 * this archive for more details.
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/errno.h>
26 #include <linux/ptrace.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/audit.h>
31 #include <asm/uaccess.h>
33 #include <asm/pgtable.h>
34 #include <asm/system.h>
35 #include <asm/ptrace-common.h>
38 * does not yet catch signals sent when the child dies.
39 * in exit.c or in signal.c.
43 * Called by kernel/ptrace.c when detaching..
45 * Make sure single step bits etc are not set.
47 void ptrace_disable(struct task_struct *child)
49 /* make sure the single step bit is not set. */
50 clear_single_step(child);
53 int sys_ptrace(long request, long pid, long addr, long data)
55 struct task_struct *child;
59 if (request == PTRACE_TRACEME) {
60 /* are we already being traced? */
61 if (current->ptrace & PT_PTRACED)
63 ret = security_ptrace(current->parent, current);
66 /* set the ptrace bit in the process flags. */
67 current->ptrace |= PT_PTRACED;
72 read_lock(&tasklist_lock);
73 child = find_task_by_pid(pid);
75 get_task_struct(child);
76 read_unlock(&tasklist_lock);
81 if (pid == 1) /* you may not mess with init */
84 if (request == PTRACE_ATTACH) {
85 ret = ptrace_attach(child);
89 ret = ptrace_check_attach(child, request == PTRACE_KILL);
94 /* when I and D space are separate, these will need to be fixed. */
95 case PTRACE_PEEKTEXT: /* read word at location addr. */
96 case PTRACE_PEEKDATA: {
100 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
102 if (copied != sizeof(tmp))
104 ret = put_user(tmp,(unsigned long __user *) data);
108 /* read the word at location addr in the USER area. */
109 case PTRACE_PEEKUSR: {
114 /* convert to index and check */
115 index = (unsigned long) addr >> 3;
116 if ((addr & 7) || (index > PT_FPSCR))
119 if (index < PT_FPR0) {
120 tmp = get_reg(child, (int)index);
122 flush_fp_to_thread(child);
123 tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
125 ret = put_user(tmp,(unsigned long __user *) data);
129 /* If I and D space are separate, this will have to be fixed. */
130 case PTRACE_POKETEXT: /* write the word at location addr. */
131 case PTRACE_POKEDATA:
133 if (access_process_vm(child, addr, &data, sizeof(data), 1)
139 /* write the word at location addr in the USER area */
140 case PTRACE_POKEUSR: {
144 /* convert to index and check */
145 index = (unsigned long) addr >> 3;
146 if ((addr & 7) || (index > PT_FPSCR))
149 if (index == PT_ORIG_R3)
151 if (index < PT_FPR0) {
152 ret = put_reg(child, index, data);
154 flush_fp_to_thread(child);
155 ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
161 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
162 case PTRACE_CONT: { /* restart after signal. */
164 if ((unsigned long) data > _NSIG)
166 if (request == PTRACE_SYSCALL)
167 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
169 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
170 child->exit_code = data;
171 /* make sure the single step bit is not set. */
172 clear_single_step(child);
173 wake_up_process(child);
179 * make the child exit. Best I can do is send it a sigkill.
180 * perhaps it should be put in the status that it wants to
185 if (child->state == TASK_ZOMBIE) /* already dead */
187 child->exit_code = SIGKILL;
188 /* make sure the single step bit is not set. */
189 clear_single_step(child);
190 wake_up_process(child);
194 case PTRACE_SINGLESTEP: { /* set the trap flag. */
196 if ((unsigned long) data > _NSIG)
198 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
199 set_single_step(child);
200 child->exit_code = data;
201 /* give it a chance to run. */
202 wake_up_process(child);
208 ret = ptrace_detach(child, data);
211 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
213 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
214 unsigned long __user *tmp = (unsigned long __user *)addr;
216 for (i = 0; i < 32; i++) {
217 ret = put_user(*reg, tmp);
226 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
228 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
229 unsigned long __user *tmp = (unsigned long __user *)addr;
231 for (i = 0; i < 32; i++) {
232 ret = get_user(*reg, tmp);
241 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
243 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
244 unsigned long __user *tmp = (unsigned long __user *)addr;
246 flush_fp_to_thread(child);
248 for (i = 0; i < 32; i++) {
249 ret = put_user(*reg, tmp);
258 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
260 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
261 unsigned long __user *tmp = (unsigned long __user *)addr;
263 flush_fp_to_thread(child);
265 for (i = 0; i < 32; i++) {
266 ret = get_user(*reg, tmp);
276 ret = ptrace_request(child, request, addr, data);
280 put_task_struct(child);
286 static void do_syscall_trace(void)
288 /* the 0x80 provides a way for the tracing parent to distinguish
289 between a syscall stop and SIGTRAP delivery */
290 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
294 * this isn't the same as continuing with a signal, but it will do
295 * for normal use. strace only continues with a signal if the
296 * stopping signal is not SIGTRAP. -brl
298 if (current->exit_code) {
299 send_sig(current->exit_code, current, 1);
300 current->exit_code = 0;
304 void do_syscall_trace_enter(struct pt_regs *regs)
306 if (unlikely(current->audit_context))
307 audit_syscall_entry(current, regs->gpr[0],
308 regs->gpr[3], regs->gpr[4],
309 regs->gpr[5], regs->gpr[6]);
311 if (test_thread_flag(TIF_SYSCALL_TRACE)
312 && (current->ptrace & PT_PTRACED))
316 void do_syscall_trace_leave(void)
318 if (unlikely(current->audit_context))
319 audit_syscall_exit(current, 0); /* FIXME: pass pt_regs */
321 if (test_thread_flag(TIF_SYSCALL_TRACE)
322 && (current->ptrace & PT_PTRACED))