4 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2007-2009 PetaLogix
6 * Copyright (C) 2004-2007 John Williams <john.williams@petalogix.com>
8 * derived from arch/v850/kernel/ptrace.c
10 * Copyright (C) 2002,03 NEC Electronics Corporation
11 * Copyright (C) 2002,03 Miles Bader <miles@gnu.org>
13 * Derived from arch/mips/kernel/ptrace.c:
15 * Copyright (C) 1992 Ross Biro
16 * Copyright (C) Linus Torvalds
17 * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
18 * Copyright (C) 1996 David S. Miller
19 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
20 * Copyright (C) 1999 MIPS Technologies, Inc.
22 * This file is subject to the terms and conditions of the GNU General
23 * Public License. See the file COPYING in the main directory of this
24 * archive for more details.
27 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/ptrace.h>
31 #include <linux/signal.h>
32 #include <linux/elf.h>
33 #include <linux/audit.h>
34 #include <linux/seccomp.h>
35 #include <linux/tracehook.h>
37 #include <linux/errno.h>
38 #include <asm/processor.h>
39 #include <linux/uaccess.h>
40 #include <asm/asm-offsets.h>
42 /* Returns the address where the register at REG_OFFS in P is stashed away. */
43 static microblaze_reg_t *reg_save_addr(unsigned reg_offs,
44 struct task_struct *t)
51 * (1) A register normally saved before calling the scheduler, is
52 * available in the kernel entry pt_regs structure at the top
53 * of the kernel stack. The kernel trap/irq exit path takes
54 * care to save/restore almost all registers for ptrace'd
57 * (2) A call-clobbered register, where the process P entered the
58 * kernel via [syscall] trap, is not stored anywhere; that's
59 * OK, because such registers are not expected to be preserved
60 * when the trap returns anyway (so we don't actually bother to
61 * test for this case).
63 * (3) A few registers not used at all by the kernel, and so
64 * normally never saved except by context-switches, are in the
65 * context switch state.
68 /* Register saved during kernel entry (or not available). */
69 regs = task_pt_regs(t);
71 return (microblaze_reg_t *)((char *)regs + reg_offs);
74 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
77 unsigned long val = 0;
81 /* Read/write the word at location ADDR in the registers. */
84 pr_debug("PEEKUSR/POKEUSR : 0x%08lx\n", addr);
86 if (addr >= PT_SIZE && request == PTRACE_PEEKUSR) {
88 * Special requests that don't actually correspond
89 * to offsets in struct pt_regs.
91 if (addr == PT_TEXT_ADDR) {
92 val = child->mm->start_code;
93 } else if (addr == PT_DATA_ADDR) {
94 val = child->mm->start_data;
95 } else if (addr == PT_TEXT_LEN) {
96 val = child->mm->end_code
97 - child->mm->start_code;
101 } else if (addr >= 0 && addr < PT_SIZE && (addr & 0x3) == 0) {
102 microblaze_reg_t *reg_addr = reg_save_addr(addr, child);
103 if (request == PTRACE_PEEKUSR)
110 if (rval == 0 && request == PTRACE_PEEKUSR)
111 rval = put_user(val, (unsigned long *)data);
113 /* Continue and stop at next (return from) syscall */
115 pr_debug("PTRACE_SYSCALL\n");
116 case PTRACE_SINGLESTEP:
117 pr_debug("PTRACE_SINGLESTEP\n");
118 /* Restart after a signal. */
120 pr_debug("PTRACE_CONT\n");
122 if (!valid_signal(data))
125 if (request == PTRACE_SYSCALL)
126 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
128 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
130 child->exit_code = data;
131 pr_debug("wakeup_process\n");
132 wake_up_process(child);
137 * make the child exit. Best I can do is send it a sigkill.
138 * perhaps it should be put in the status that it wants to
142 pr_debug("PTRACE_KILL\n");
144 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
146 child->exit_code = SIGKILL;
147 wake_up_process(child);
151 rval = ptrace_request(child, request, addr, data);
156 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
160 secure_computing(regs->r12);
162 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
163 tracehook_report_syscall_entry(regs))
165 * Tracing decided this syscall should not happen.
166 * We'll return a bogus call number to get an ENOSYS
167 * error, but leave the original number in regs->regs[0].
171 if (unlikely(current->audit_context))
172 audit_syscall_entry(EM_XILINX_MICROBLAZE, regs->r12,
176 return ret ?: regs->r12;
179 asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
183 if (unlikely(current->audit_context))
184 audit_syscall_exit(AUDITSC_RESULT(regs->r3), regs->r3);
186 step = test_thread_flag(TIF_SINGLESTEP);
187 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
188 tracehook_report_syscall_exit(regs, step);
192 static asmlinkage void syscall_trace(void)
194 if (!test_thread_flag(TIF_SYSCALL_TRACE))
196 if (!(current->ptrace & PT_PTRACED))
198 /* The 0x80 provides a way for the tracing parent to distinguish
199 between a syscall stop and SIGTRAP delivery */
200 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
203 * this isn't the same as continuing with a signal, but it will do
204 * for normal use. strace only continues with a signal if the
205 * stopping signal is not SIGTRAP. -brl
207 if (current->exit_code) {
208 send_sig(current->exit_code, current, 1);
209 current->exit_code = 0;
214 void ptrace_disable(struct task_struct *child)