2 * linux/arch/sh/kernel/ptrace.c
4 * Original x86 implementation:
6 * edited by Linus Torvalds
8 * SuperH version: Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
15 #include <linux/smp.h>
16 #include <linux/smp_lock.h>
17 #include <linux/errno.h>
18 #include <linux/ptrace.h>
19 #include <linux/user.h>
20 #include <linux/slab.h>
21 #include <linux/security.h>
22 #include <linux/signal.h>
25 #include <asm/uaccess.h>
26 #include <asm/pgtable.h>
27 #include <asm/system.h>
28 #include <asm/processor.h>
29 #include <asm/mmu_context.h>
32 * does not yet catch signals sent when the child dies.
33 * in exit.c or in signal.c.
37 * This routine will get a word off of the process kernel stack.
39 static inline int get_stack_long(struct task_struct *task, int offset)
43 stack = (unsigned char *)task_pt_regs(task);
45 return (*((int *)stack));
49 * This routine will put a word on the process kernel stack.
51 static inline int put_stack_long(struct task_struct *task, int offset,
56 stack = (unsigned char *)task_pt_regs(task);
58 *(unsigned long *) stack = data;
63 * Called by kernel/ptrace.c when detaching..
65 * Make sure single step bits etc are not set.
67 void ptrace_disable(struct task_struct *child)
72 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
74 struct user * dummy = NULL;
78 /* when I and D space are separate, these will need to be fixed. */
79 case PTRACE_PEEKTEXT: /* read word at location addr. */
80 case PTRACE_PEEKDATA: {
84 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
86 if (copied != sizeof(tmp))
88 ret = put_user(tmp,(unsigned long *) data);
92 /* read the word at location addr in the USER area. */
93 case PTRACE_PEEKUSR: {
97 if ((addr & 3) || addr < 0 ||
98 addr > sizeof(struct user) - 3)
101 if (addr < sizeof(struct pt_regs))
102 tmp = get_stack_long(child, addr);
103 else if (addr >= (long) &dummy->fpu &&
104 addr < (long) &dummy->u_fpvalid) {
105 if (!tsk_used_math(child)) {
106 if (addr == (long)&dummy->fpu.fpscr)
111 tmp = ((long *)&child->thread.fpu)
112 [(addr - (long)&dummy->fpu) >> 2];
113 } else if (addr == (long) &dummy->u_fpvalid)
114 tmp = !!tsk_used_math(child);
117 ret = put_user(tmp, (unsigned long *)data);
121 /* when I and D space are separate, this will have to be fixed. */
122 case PTRACE_POKETEXT: /* write the word at location addr. */
123 case PTRACE_POKEDATA:
125 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
130 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
132 if ((addr & 3) || addr < 0 ||
133 addr > sizeof(struct user) - 3)
136 if (addr < sizeof(struct pt_regs))
137 ret = put_stack_long(child, addr, data);
138 else if (addr >= (long) &dummy->fpu &&
139 addr < (long) &dummy->u_fpvalid) {
140 set_stopped_child_used_math(child);
141 ((long *)&child->thread.fpu)
142 [(addr - (long)&dummy->fpu) >> 2] = data;
144 } else if (addr == (long) &dummy->u_fpvalid) {
145 conditional_stopped_child_used_math(data, child);
150 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
151 case PTRACE_CONT: { /* restart after signal. */
153 if (!valid_signal(data))
155 if (request == PTRACE_SYSCALL)
156 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
158 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
159 child->exit_code = data;
160 wake_up_process(child);
166 * make the child exit. Best I can do is send it a sigkill.
167 * perhaps it should be put in the status that it wants to
172 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
174 child->exit_code = SIGKILL;
175 wake_up_process(child);
179 case PTRACE_SINGLESTEP: { /* set the trap flag. */
181 struct pt_regs *dummy = NULL;
184 if (!valid_signal(data))
186 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
187 if ((child->ptrace & PT_DTRACE) == 0) {
188 /* Spurious delayed TF traps may occur */
189 child->ptrace |= PT_DTRACE;
192 pc = get_stack_long(child, (long)&dummy->pc);
194 /* Next scheduling will set up UBC */
195 if (child->thread.ubc_pc == 0)
197 child->thread.ubc_pc = pc;
199 child->exit_code = data;
200 /* give it a chance to run. */
201 wake_up_process(child);
206 case PTRACE_DETACH: /* detach a process that was attached. */
207 ret = ptrace_detach(child, data);
211 case PTRACE_GETDSPREGS: {
215 dp = ((unsigned long) child) + THREAD_SIZE -
216 sizeof(struct pt_dspregs);
217 if (*((int *) (dp - 4)) == SR_FD) {
218 copy_to_user(addr, (void *) dp,
219 sizeof(struct pt_dspregs));
225 case PTRACE_SETDSPREGS: {
229 dp = ((unsigned long) child) + THREAD_SIZE -
230 sizeof(struct pt_dspregs);
231 if (*((int *) (dp - 4)) == SR_FD) {
232 copy_from_user((void *) dp, addr,
233 sizeof(struct pt_dspregs));
240 ret = ptrace_request(child, request, addr, data);
247 asmlinkage void do_syscall_trace(void)
249 struct task_struct *tsk = current;
251 if (!test_thread_flag(TIF_SYSCALL_TRACE))
253 if (!(tsk->ptrace & PT_PTRACED))
255 /* the 0x80 provides a way for the tracing parent to distinguish
256 between a syscall stop and SIGTRAP delivery */
257 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
261 * this isn't the same as continuing with a signal, but it will do
262 * for normal use. strace only continues with a signal if the
263 * stopping signal is not SIGTRAP. -brl
265 if (tsk->exit_code) {
266 send_sig(tsk->exit_code, tsk, 1);