3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Derived from "arch/m68k/kernel/ptrace.c"
6 * Copyright (C) 1994 by Hamish Macdonald
7 * Taken from linux/kernel/ptrace.c and modified for M680x0.
8 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
10 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
11 * and Paul Mackerras (paulus@samba.org).
13 * This file is subject to the terms and conditions of the GNU General
14 * Public License. See the file README.legal in the main directory of
15 * this archive for more details.
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
21 #include <linux/smp.h>
22 #include <linux/errno.h>
23 #include <linux/ptrace.h>
24 #include <linux/user.h>
25 #include <linux/security.h>
26 #include <linux/signal.h>
27 #include <linux/seccomp.h>
28 #include <linux/audit.h>
30 #include <linux/module.h>
33 #include <asm/uaccess.h>
35 #include <asm/pgtable.h>
36 #include <asm/system.h>
39 #include "ptrace-ppc64.h"
41 #include "ptrace-ppc32.h"
44 #include "ptrace-common.h"
47 * does not yet catch signals sent when the child dies.
48 * in exit.c or in signal.c.
52 * Called by kernel/ptrace.c when detaching..
54 * Make sure single step bits etc are not set.
56 void ptrace_disable(struct task_struct *child)
58 /* make sure the single step bit is not set. */
59 clear_single_step(child);
63 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
64 * we mark them as obsolete now, they will be removed in a future version
66 static long arch_ptrace_old(struct task_struct *child, long request, long addr,
72 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
74 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
75 unsigned long __user *tmp = (unsigned long __user *)addr;
77 for (i = 0; i < 32; i++) {
78 ret = put_user(*reg, tmp);
87 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
89 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
90 unsigned long __user *tmp = (unsigned long __user *)addr;
92 for (i = 0; i < 32; i++) {
93 ret = get_user(*reg, tmp);
102 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
103 flush_fp_to_thread(child);
104 ret = get_fpregs((void __user *)addr, child, 0);
108 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
109 flush_fp_to_thread(child);
110 ret = set_fpregs((void __user *)addr, child, 0);
118 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
123 /* when I and D space are separate, these will need to be fixed. */
124 case PTRACE_PEEKTEXT: /* read word at location addr. */
125 case PTRACE_PEEKDATA: {
129 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
131 if (copied != sizeof(tmp))
133 ret = put_user(tmp,(unsigned long __user *) data);
137 /* read the word at location addr in the USER area. */
138 case PTRACE_PEEKUSR: {
139 unsigned long index, tmp;
142 /* convert to index and check */
144 index = (unsigned long) addr >> 2;
145 if ((addr & 3) || (index > PT_FPSCR)
146 || (child->thread.regs == NULL))
148 index = (unsigned long) addr >> 3;
149 if ((addr & 7) || (index > PT_FPSCR))
154 CHECK_FULL_REGS(child->thread.regs);
156 if (index < PT_FPR0) {
157 tmp = get_reg(child, (int) index);
159 flush_fp_to_thread(child);
160 tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
162 ret = put_user(tmp,(unsigned long __user *) data);
166 /* If I and D space are separate, this will have to be fixed. */
167 case PTRACE_POKETEXT: /* write the word at location addr. */
168 case PTRACE_POKEDATA:
170 if (access_process_vm(child, addr, &data, sizeof(data), 1)
176 /* write the word at location addr in the USER area */
177 case PTRACE_POKEUSR: {
181 /* convert to index and check */
183 index = (unsigned long) addr >> 2;
184 if ((addr & 3) || (index > PT_FPSCR)
185 || (child->thread.regs == NULL))
187 index = (unsigned long) addr >> 3;
188 if ((addr & 7) || (index > PT_FPSCR))
193 CHECK_FULL_REGS(child->thread.regs);
195 if (index == PT_ORIG_R3)
197 if (index < PT_FPR0) {
198 ret = put_reg(child, index, data);
200 flush_fp_to_thread(child);
201 ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
207 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
208 case PTRACE_CONT: { /* restart after signal. */
210 if (!valid_signal(data))
212 if (request == PTRACE_SYSCALL)
213 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
215 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
216 child->exit_code = data;
217 /* make sure the single step bit is not set. */
218 clear_single_step(child);
219 wake_up_process(child);
225 * make the child exit. Best I can do is send it a sigkill.
226 * perhaps it should be put in the status that it wants to
231 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
233 child->exit_code = SIGKILL;
234 /* make sure the single step bit is not set. */
235 clear_single_step(child);
236 wake_up_process(child);
240 case PTRACE_SINGLESTEP: { /* set the trap flag. */
242 if (!valid_signal(data))
244 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
245 set_single_step(child);
246 child->exit_code = data;
247 /* give it a chance to run. */
248 wake_up_process(child);
254 case PTRACE_GET_DEBUGREG: {
256 /* We only support one DABR and no IABRS at the moment */
259 ret = put_user(child->thread.dabr,
260 (unsigned long __user *)data);
264 case PTRACE_SET_DEBUGREG:
265 ret = ptrace_set_debugreg(child, addr, data);
270 ret = ptrace_detach(child, data);
274 case PTRACE_GETREGS64:
276 case PTRACE_GETREGS: { /* Get all pt_regs from the child. */
278 if (!access_ok(VERIFY_WRITE, (void __user *)data,
279 sizeof(struct pt_regs))) {
284 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
285 ret |= __put_user(get_reg(child, ui),
286 (unsigned long __user *) data);
287 data += sizeof(long);
293 case PTRACE_SETREGS64:
295 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
298 if (!access_ok(VERIFY_READ, (void __user *)data,
299 sizeof(struct pt_regs))) {
304 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
305 ret = __get_user(tmp, (unsigned long __user *) data);
308 put_reg(child, ui, tmp);
309 data += sizeof(long);
314 case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */
315 flush_fp_to_thread(child);
316 ret = get_fpregs((void __user *)data, child, 1);
320 case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */
321 flush_fp_to_thread(child);
322 ret = set_fpregs((void __user *)data, child, 1);
326 #ifdef CONFIG_ALTIVEC
327 case PTRACE_GETVRREGS:
328 /* Get the child altivec register state. */
329 flush_altivec_to_thread(child);
330 ret = get_vrregs((unsigned long __user *)data, child);
333 case PTRACE_SETVRREGS:
334 /* Set the child altivec register state. */
335 flush_altivec_to_thread(child);
336 ret = set_vrregs(child, (unsigned long __user *)data);
340 case PTRACE_GETEVRREGS:
341 /* Get the child spe register state. */
342 if (child->thread.regs->msr & MSR_SPE)
344 ret = get_evrregs((unsigned long __user *)data, child);
347 case PTRACE_SETEVRREGS:
348 /* Set the child spe register state. */
349 /* this is to clear the MSR_SPE bit to force a reload
350 * of register state from memory */
351 if (child->thread.regs->msr & MSR_SPE)
353 ret = set_evrregs(child, (unsigned long __user *)data);
357 /* Old reverse args ptrace callss */
358 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
359 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
360 case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
361 case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
362 ret = arch_ptrace_old(child, request, addr, data);
366 ret = ptrace_request(child, request, addr, data);
372 static void do_syscall_trace(void)
374 /* the 0x80 provides a way for the tracing parent to distinguish
375 between a syscall stop and SIGTRAP delivery */
376 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
380 * this isn't the same as continuing with a signal, but it will do
381 * for normal use. strace only continues with a signal if the
382 * stopping signal is not SIGTRAP. -brl
384 if (current->exit_code) {
385 send_sig(current->exit_code, current, 1);
386 current->exit_code = 0;
390 void do_syscall_trace_enter(struct pt_regs *regs)
392 secure_computing(regs->gpr[0]);
394 if (test_thread_flag(TIF_SYSCALL_TRACE)
395 && (current->ptrace & PT_PTRACED))
398 if (unlikely(current->audit_context)) {
400 if (!test_thread_flag(TIF_32BIT))
401 audit_syscall_entry(AUDIT_ARCH_PPC64,
403 regs->gpr[3], regs->gpr[4],
404 regs->gpr[5], regs->gpr[6]);
407 audit_syscall_entry(AUDIT_ARCH_PPC,
409 regs->gpr[3] & 0xffffffff,
410 regs->gpr[4] & 0xffffffff,
411 regs->gpr[5] & 0xffffffff,
412 regs->gpr[6] & 0xffffffff);
416 void do_syscall_trace_leave(struct pt_regs *regs)
418 if (unlikely(current->audit_context))
419 audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
422 if ((test_thread_flag(TIF_SYSCALL_TRACE)
423 || test_thread_flag(TIF_SINGLESTEP))
424 && (current->ptrace & PT_PTRACED))