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/config.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
24 #include <linux/smp.h>
25 #include <linux/smp_lock.h>
26 #include <linux/errno.h>
27 #include <linux/ptrace.h>
28 #include <linux/user.h>
29 #include <linux/security.h>
30 #include <linux/audit.h>
31 #include <linux/seccomp.h>
32 #include <linux/signal.h>
34 #include <asm/uaccess.h>
36 #include <asm/pgtable.h>
37 #include <asm/system.h>
38 #include <asm/ptrace-common.h>
41 * does not yet catch signals sent when the child dies.
42 * in exit.c or in signal.c.
46 * Called by kernel/ptrace.c when detaching..
48 * Make sure single step bits etc are not set.
50 void ptrace_disable(struct task_struct *child)
52 /* make sure the single step bit is not set. */
53 clear_single_step(child);
56 int sys_ptrace(long request, long pid, long addr, long data)
58 struct task_struct *child;
62 if (request == PTRACE_TRACEME) {
63 /* are we already being traced? */
64 if (current->ptrace & PT_PTRACED)
66 ret = security_ptrace(current->parent, current);
69 /* set the ptrace bit in the process flags. */
70 current->ptrace |= PT_PTRACED;
75 read_lock(&tasklist_lock);
76 child = find_task_by_pid(pid);
78 get_task_struct(child);
79 read_unlock(&tasklist_lock);
84 if (pid == 1) /* you may not mess with init */
87 if (request == PTRACE_ATTACH) {
88 ret = ptrace_attach(child);
92 ret = ptrace_check_attach(child, request == PTRACE_KILL);
97 /* when I and D space are separate, these will need to be fixed. */
98 case PTRACE_PEEKTEXT: /* read word at location addr. */
99 case PTRACE_PEEKDATA: {
103 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
105 if (copied != sizeof(tmp))
107 ret = put_user(tmp,(unsigned long __user *) data);
111 /* read the word at location addr in the USER area. */
112 case PTRACE_PEEKUSR: {
117 /* convert to index and check */
118 index = (unsigned long) addr >> 3;
119 if ((addr & 7) || (index > PT_FPSCR))
122 if (index < PT_FPR0) {
123 tmp = get_reg(child, (int)index);
125 flush_fp_to_thread(child);
126 tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
128 ret = put_user(tmp,(unsigned long __user *) data);
132 /* If I and D space are separate, this will have to be fixed. */
133 case PTRACE_POKETEXT: /* write the word at location addr. */
134 case PTRACE_POKEDATA:
136 if (access_process_vm(child, addr, &data, sizeof(data), 1)
142 /* write the word at location addr in the USER area */
143 case PTRACE_POKEUSR: {
147 /* convert to index and check */
148 index = (unsigned long) addr >> 3;
149 if ((addr & 7) || (index > PT_FPSCR))
152 if (index == PT_ORIG_R3)
154 if (index < PT_FPR0) {
155 ret = put_reg(child, index, data);
157 flush_fp_to_thread(child);
158 ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
164 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
165 case PTRACE_CONT: { /* restart after signal. */
167 if (!valid_signal(data))
169 if (request == PTRACE_SYSCALL)
170 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
172 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
173 child->exit_code = data;
174 /* make sure the single step bit is not set. */
175 clear_single_step(child);
176 wake_up_process(child);
182 * make the child exit. Best I can do is send it a sigkill.
183 * perhaps it should be put in the status that it wants to
188 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
190 child->exit_code = SIGKILL;
191 /* make sure the single step bit is not set. */
192 clear_single_step(child);
193 wake_up_process(child);
197 case PTRACE_SINGLESTEP: { /* set the trap flag. */
199 if (!valid_signal(data))
201 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
202 set_single_step(child);
203 child->exit_code = data;
204 /* give it a chance to run. */
205 wake_up_process(child);
211 ret = ptrace_detach(child, data);
214 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
216 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
217 unsigned long __user *tmp = (unsigned long __user *)addr;
219 for (i = 0; i < 32; i++) {
220 ret = put_user(*reg, tmp);
229 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
231 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
232 unsigned long __user *tmp = (unsigned long __user *)addr;
234 for (i = 0; i < 32; i++) {
235 ret = get_user(*reg, tmp);
244 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
246 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
247 unsigned long __user *tmp = (unsigned long __user *)addr;
249 flush_fp_to_thread(child);
251 for (i = 0; i < 32; i++) {
252 ret = put_user(*reg, tmp);
261 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
263 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
264 unsigned long __user *tmp = (unsigned long __user *)addr;
266 flush_fp_to_thread(child);
268 for (i = 0; i < 32; i++) {
269 ret = get_user(*reg, tmp);
278 #ifdef CONFIG_ALTIVEC
279 case PTRACE_GETVRREGS:
280 /* Get the child altivec register state. */
281 flush_altivec_to_thread(child);
282 ret = get_vrregs((unsigned long __user *)data, child);
285 case PTRACE_SETVRREGS:
286 /* Set the child altivec register state. */
287 flush_altivec_to_thread(child);
288 ret = set_vrregs(child, (unsigned long __user *)data);
293 ret = ptrace_request(child, request, addr, data);
297 put_task_struct(child);
303 static void do_syscall_trace(void)
305 /* the 0x80 provides a way for the tracing parent to distinguish
306 between a syscall stop and SIGTRAP delivery */
307 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
311 * this isn't the same as continuing with a signal, but it will do
312 * for normal use. strace only continues with a signal if the
313 * stopping signal is not SIGTRAP. -brl
315 if (current->exit_code) {
316 send_sig(current->exit_code, current, 1);
317 current->exit_code = 0;
321 void do_syscall_trace_enter(struct pt_regs *regs)
323 secure_computing(regs->gpr[0]);
325 if (test_thread_flag(TIF_SYSCALL_TRACE)
326 && (current->ptrace & PT_PTRACED))
329 if (unlikely(current->audit_context))
330 audit_syscall_entry(current,
331 test_thread_flag(TIF_32BIT)?AUDIT_ARCH_PPC:AUDIT_ARCH_PPC64,
333 regs->gpr[3], regs->gpr[4],
334 regs->gpr[5], regs->gpr[6]);
338 void do_syscall_trace_leave(struct pt_regs *regs)
340 if (unlikely(current->audit_context))
341 audit_syscall_exit(current,
342 (regs->ccr&0x1000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
345 if ((test_thread_flag(TIF_SYSCALL_TRACE)
346 || test_thread_flag(TIF_SINGLESTEP))
347 && (current->ptrace & PT_PTRACED))