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>
30 #include <linux/seccomp.h>
31 #include <linux/signal.h>
33 #include <asm/uaccess.h>
35 #include <asm/pgtable.h>
36 #include <asm/system.h>
37 #include <asm/ptrace-common.h>
40 * does not yet catch signals sent when the child dies.
41 * in exit.c or in signal.c.
45 * Called by kernel/ptrace.c when detaching..
47 * Make sure single step bits etc are not set.
49 void ptrace_disable(struct task_struct *child)
51 /* make sure the single step bit is not set. */
52 clear_single_step(child);
55 int sys_ptrace(long request, long pid, long addr, long data)
57 struct task_struct *child;
61 if (request == PTRACE_TRACEME) {
62 /* are we already being traced? */
63 if (current->ptrace & PT_PTRACED)
65 ret = security_ptrace(current->parent, current);
68 /* set the ptrace bit in the process flags. */
69 current->ptrace |= PT_PTRACED;
74 read_lock(&tasklist_lock);
75 child = find_task_by_pid(pid);
77 get_task_struct(child);
78 read_unlock(&tasklist_lock);
81 if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
85 if (pid == 1) /* you may not mess with init */
88 if (request == PTRACE_ATTACH) {
89 ret = ptrace_attach(child);
93 ret = ptrace_check_attach(child, request == PTRACE_KILL);
98 /* when I and D space are separate, these will need to be fixed. */
99 case PTRACE_PEEKTEXT: /* read word at location addr. */
100 case PTRACE_PEEKDATA: {
104 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
106 if (copied != sizeof(tmp))
108 ret = put_user(tmp,(unsigned long __user *) data);
112 /* read the word at location addr in the USER area. */
113 case PTRACE_PEEKUSR: {
118 /* convert to index and check */
119 index = (unsigned long) addr >> 3;
120 if ((addr & 7) || (index > PT_FPSCR))
123 if (index < PT_FPR0) {
124 tmp = get_reg(child, (int)index);
126 flush_fp_to_thread(child);
127 tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
129 ret = put_user(tmp,(unsigned long __user *) data);
133 /* If I and D space are separate, this will have to be fixed. */
134 case PTRACE_POKETEXT: /* write the word at location addr. */
135 case PTRACE_POKEDATA:
137 if (access_process_vm(child, addr, &data, sizeof(data), 1)
143 /* write the word at location addr in the USER area */
144 case PTRACE_POKEUSR: {
148 /* convert to index and check */
149 index = (unsigned long) addr >> 3;
150 if ((addr & 7) || (index > PT_FPSCR))
153 if (index == PT_ORIG_R3)
155 if (index < PT_FPR0) {
156 ret = put_reg(child, index, data);
158 flush_fp_to_thread(child);
159 ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
165 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
166 case PTRACE_CONT: { /* restart after signal. */
168 if (!valid_signal(data))
170 if (request == PTRACE_SYSCALL)
171 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
173 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
174 child->exit_code = data;
175 /* make sure the single step bit is not set. */
176 clear_single_step(child);
177 wake_up_process(child);
183 * make the child exit. Best I can do is send it a sigkill.
184 * perhaps it should be put in the status that it wants to
189 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
191 child->exit_code = SIGKILL;
192 /* make sure the single step bit is not set. */
193 clear_single_step(child);
194 wake_up_process(child);
198 case PTRACE_SINGLESTEP: { /* set the trap flag. */
200 if (!valid_signal(data))
202 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
203 set_single_step(child);
204 child->exit_code = data;
205 /* give it a chance to run. */
206 wake_up_process(child);
212 ret = ptrace_detach(child, data);
215 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
217 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
218 unsigned long __user *tmp = (unsigned long __user *)addr;
220 for (i = 0; i < 32; i++) {
221 ret = put_user(*reg, tmp);
230 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
232 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
233 unsigned long __user *tmp = (unsigned long __user *)addr;
235 for (i = 0; i < 32; i++) {
236 ret = get_user(*reg, tmp);
245 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
247 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
248 unsigned long __user *tmp = (unsigned long __user *)addr;
250 flush_fp_to_thread(child);
252 for (i = 0; i < 32; i++) {
253 ret = put_user(*reg, tmp);
262 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
264 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
265 unsigned long __user *tmp = (unsigned long __user *)addr;
267 flush_fp_to_thread(child);
269 for (i = 0; i < 32; i++) {
270 ret = get_user(*reg, tmp);
280 ret = ptrace_request(child, request, addr, data);
284 put_task_struct(child);
290 static void do_syscall_trace(void)
292 /* the 0x80 provides a way for the tracing parent to distinguish
293 between a syscall stop and SIGTRAP delivery */
294 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
298 * this isn't the same as continuing with a signal, but it will do
299 * for normal use. strace only continues with a signal if the
300 * stopping signal is not SIGTRAP. -brl
302 if (current->exit_code) {
303 send_sig(current->exit_code, current, 1);
304 current->exit_code = 0;
308 void do_syscall_trace_enter(struct pt_regs *regs)
310 if (test_thread_flag(TIF_SYSCALL_TRACE)
311 && (current->ptrace & PT_PTRACED))
314 if (unlikely(current->audit_context))
315 audit_syscall_entry(current,
316 test_thread_flag(TIF_32BIT)?AUDIT_ARCH_PPC:AUDIT_ARCH_PPC64,
318 regs->gpr[3], regs->gpr[4],
319 regs->gpr[5], regs->gpr[6]);
323 void do_syscall_trace_leave(struct pt_regs *regs)
325 secure_computing(regs->gpr[0]);
327 if (unlikely(current->audit_context))
328 audit_syscall_exit(current,
329 (regs->ccr&0x1000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
332 if ((test_thread_flag(TIF_SYSCALL_TRACE)
333 || test_thread_flag(TIF_SINGLESTEP))
334 && (current->ptrace & PT_PTRACED))