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
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
14 #include <linux/smp.h>
15 #include <linux/errno.h>
16 #include <linux/ptrace.h>
17 #include <linux/user.h>
18 #include <linux/slab.h>
19 #include <linux/security.h>
20 #include <linux/signal.h>
22 #include <asm/uaccess.h>
23 #include <asm/pgtable.h>
24 #include <asm/system.h>
25 #include <asm/processor.h>
26 #include <asm/mmu_context.h>
29 * does not yet catch signals sent when the child dies.
30 * in exit.c or in signal.c.
34 * This routine will get a word off of the process kernel stack.
36 static inline int get_stack_long(struct task_struct
*task
, int offset
)
40 stack
= (unsigned char *)task_pt_regs(task
);
42 return (*((int *)stack
));
46 * This routine will put a word on the process kernel stack.
48 static inline int put_stack_long(struct task_struct
*task
, int offset
,
53 stack
= (unsigned char *)task_pt_regs(task
);
55 *(unsigned long *) stack
= data
;
59 static void ptrace_disable_singlestep(struct task_struct
*child
)
61 clear_tsk_thread_flag(child
, TIF_SINGLESTEP
);
64 * Ensure the UBC is not programmed at the next context switch.
66 * Normally this is not needed but there are sequences such as
67 * singlestep, signal delivery, and continue that leave the
68 * ubc_pc non-zero leading to spurious SIGTRAPs.
70 if (child
->thread
.ubc_pc
!= 0) {
72 child
->thread
.ubc_pc
= 0;
77 * Called by kernel/ptrace.c when detaching..
79 * Make sure single step bits etc are not set.
81 void ptrace_disable(struct task_struct
*child
)
83 ptrace_disable_singlestep(child
);
86 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
88 struct user
* dummy
= NULL
;
92 /* when I and D space are separate, these will need to be fixed. */
93 case PTRACE_PEEKTEXT
: /* read word at location addr. */
95 ret
= generic_ptrace_peekdata(child
, addr
, data
);
98 /* read the word at location addr in the USER area. */
99 case PTRACE_PEEKUSR
: {
103 if ((addr
& 3) || addr
< 0 ||
104 addr
> sizeof(struct user
) - 3)
107 if (addr
< sizeof(struct pt_regs
))
108 tmp
= get_stack_long(child
, addr
);
109 else if (addr
>= (long) &dummy
->fpu
&&
110 addr
< (long) &dummy
->u_fpvalid
) {
111 if (!tsk_used_math(child
)) {
112 if (addr
== (long)&dummy
->fpu
.fpscr
)
117 tmp
= ((long *)&child
->thread
.fpu
)
118 [(addr
- (long)&dummy
->fpu
) >> 2];
119 } else if (addr
== (long) &dummy
->u_fpvalid
)
120 tmp
= !!tsk_used_math(child
);
123 ret
= put_user(tmp
, (unsigned long __user
*)data
);
127 /* when I and D space are separate, this will have to be fixed. */
128 case PTRACE_POKETEXT
: /* write the word at location addr. */
129 case PTRACE_POKEDATA
:
130 ret
= generic_ptrace_pokedata(child
, addr
, data
);
133 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
135 if ((addr
& 3) || addr
< 0 ||
136 addr
> sizeof(struct user
) - 3)
139 if (addr
< sizeof(struct pt_regs
))
140 ret
= put_stack_long(child
, addr
, data
);
141 else if (addr
>= (long) &dummy
->fpu
&&
142 addr
< (long) &dummy
->u_fpvalid
) {
143 set_stopped_child_used_math(child
);
144 ((long *)&child
->thread
.fpu
)
145 [(addr
- (long)&dummy
->fpu
) >> 2] = data
;
147 } else if (addr
== (long) &dummy
->u_fpvalid
) {
148 conditional_stopped_child_used_math(data
, child
);
153 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
154 case PTRACE_CONT
: { /* restart after signal. */
156 if (!valid_signal(data
))
158 if (request
== PTRACE_SYSCALL
)
159 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
161 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
163 ptrace_disable_singlestep(child
);
165 child
->exit_code
= data
;
166 wake_up_process(child
);
172 * make the child exit. Best I can do is send it a sigkill.
173 * perhaps it should be put in the status that it wants to
178 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
180 ptrace_disable_singlestep(child
);
181 child
->exit_code
= SIGKILL
;
182 wake_up_process(child
);
186 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
188 struct pt_regs
*regs
= NULL
;
191 if (!valid_signal(data
))
193 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
194 if ((child
->ptrace
& PT_DTRACE
) == 0) {
195 /* Spurious delayed TF traps may occur */
196 child
->ptrace
|= PT_DTRACE
;
199 pc
= get_stack_long(child
, (long)®s
->pc
);
201 /* Next scheduling will set up UBC */
202 if (child
->thread
.ubc_pc
== 0)
204 child
->thread
.ubc_pc
= pc
;
206 set_tsk_thread_flag(child
, TIF_SINGLESTEP
);
207 child
->exit_code
= data
;
208 /* give it a chance to run. */
209 wake_up_process(child
);
215 case PTRACE_GETDSPREGS
: {
219 dp
= ((unsigned long) child
) + THREAD_SIZE
-
220 sizeof(struct pt_dspregs
);
221 if (*((int *) (dp
- 4)) == SR_FD
) {
222 copy_to_user(addr
, (void *) dp
,
223 sizeof(struct pt_dspregs
));
229 case PTRACE_SETDSPREGS
: {
233 dp
= ((unsigned long) child
) + THREAD_SIZE
-
234 sizeof(struct pt_dspregs
);
235 if (*((int *) (dp
- 4)) == SR_FD
) {
236 copy_from_user((void *) dp
, addr
,
237 sizeof(struct pt_dspregs
));
244 ret
= ptrace_request(child
, request
, addr
, data
);
251 asmlinkage
void do_syscall_trace(void)
253 struct task_struct
*tsk
= current
;
255 if (!test_thread_flag(TIF_SYSCALL_TRACE
) &&
256 !test_thread_flag(TIF_SINGLESTEP
))
258 if (!(tsk
->ptrace
& PT_PTRACED
))
260 /* the 0x80 provides a way for the tracing parent to distinguish
261 between a syscall stop and SIGTRAP delivery */
262 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
) &&
263 !test_thread_flag(TIF_SINGLESTEP
) ? 0x80 : 0));
266 * this isn't the same as continuing with a signal, but it will do
267 * for normal use. strace only continues with a signal if the
268 * stopping signal is not SIGTRAP. -brl
270 if (tsk
->exit_code
) {
271 send_sig(tsk
->exit_code
, tsk
, 1);