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/config.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
16 #include <linux/smp.h>
17 #include <linux/smp_lock.h>
18 #include <linux/errno.h>
19 #include <linux/ptrace.h>
20 #include <linux/user.h>
21 #include <linux/slab.h>
22 #include <linux/security.h>
23 #include <linux/signal.h>
26 #include <asm/uaccess.h>
27 #include <asm/pgtable.h>
28 #include <asm/system.h>
29 #include <asm/processor.h>
30 #include <asm/mmu_context.h>
33 * does not yet catch signals sent when the child dies.
34 * in exit.c or in signal.c.
38 * This routine will get a word off of the process kernel stack.
40 static inline int get_stack_long(struct task_struct
*task
, int offset
)
44 stack
= (unsigned char *)task_pt_regs(task
);
46 return (*((int *)stack
));
50 * This routine will put a word on the process kernel stack.
52 static inline int put_stack_long(struct task_struct
*task
, int offset
,
57 stack
= (unsigned char *)task_pt_regs(task
);
59 *(unsigned long *) stack
= data
;
64 * Called by kernel/ptrace.c when detaching..
66 * Make sure single step bits etc are not set.
68 void ptrace_disable(struct task_struct
*child
)
73 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
75 struct user
* dummy
= NULL
;
79 /* when I and D space are separate, these will need to be fixed. */
80 case PTRACE_PEEKTEXT
: /* read word at location addr. */
81 case PTRACE_PEEKDATA
: {
85 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
87 if (copied
!= sizeof(tmp
))
89 ret
= put_user(tmp
,(unsigned long *) data
);
93 /* read the word at location addr in the USER area. */
94 case PTRACE_PEEKUSR
: {
98 if ((addr
& 3) || addr
< 0 ||
99 addr
> sizeof(struct user
) - 3)
102 if (addr
< sizeof(struct pt_regs
))
103 tmp
= get_stack_long(child
, addr
);
104 else if (addr
>= (long) &dummy
->fpu
&&
105 addr
< (long) &dummy
->u_fpvalid
) {
106 if (!tsk_used_math(child
)) {
107 if (addr
== (long)&dummy
->fpu
.fpscr
)
112 tmp
= ((long *)&child
->thread
.fpu
)
113 [(addr
- (long)&dummy
->fpu
) >> 2];
114 } else if (addr
== (long) &dummy
->u_fpvalid
)
115 tmp
= !!tsk_used_math(child
);
118 ret
= put_user(tmp
, (unsigned long *)data
);
122 /* when I and D space are separate, this will have to be fixed. */
123 case PTRACE_POKETEXT
: /* write the word at location addr. */
124 case PTRACE_POKEDATA
:
126 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1) == sizeof(data
))
131 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
133 if ((addr
& 3) || addr
< 0 ||
134 addr
> sizeof(struct user
) - 3)
137 if (addr
< sizeof(struct pt_regs
))
138 ret
= put_stack_long(child
, addr
, data
);
139 else if (addr
>= (long) &dummy
->fpu
&&
140 addr
< (long) &dummy
->u_fpvalid
) {
141 set_stopped_child_used_math(child
);
142 ((long *)&child
->thread
.fpu
)
143 [(addr
- (long)&dummy
->fpu
) >> 2] = data
;
145 } else if (addr
== (long) &dummy
->u_fpvalid
) {
146 conditional_stopped_child_used_math(data
, child
);
151 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
152 case PTRACE_CONT
: { /* restart after signal. */
154 if (!valid_signal(data
))
156 if (request
== PTRACE_SYSCALL
)
157 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
159 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
160 child
->exit_code
= data
;
161 wake_up_process(child
);
167 * make the child exit. Best I can do is send it a sigkill.
168 * perhaps it should be put in the status that it wants to
173 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
175 child
->exit_code
= SIGKILL
;
176 wake_up_process(child
);
180 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
182 struct pt_regs
*dummy
= NULL
;
185 if (!valid_signal(data
))
187 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
188 if ((child
->ptrace
& PT_DTRACE
) == 0) {
189 /* Spurious delayed TF traps may occur */
190 child
->ptrace
|= PT_DTRACE
;
193 pc
= get_stack_long(child
, (long)&dummy
->pc
);
195 /* Next scheduling will set up UBC */
196 if (child
->thread
.ubc_pc
== 0)
198 child
->thread
.ubc_pc
= pc
;
200 child
->exit_code
= data
;
201 /* give it a chance to run. */
202 wake_up_process(child
);
207 case PTRACE_DETACH
: /* detach a process that was attached. */
208 ret
= ptrace_detach(child
, data
);
212 case PTRACE_GETDSPREGS
: {
216 dp
= ((unsigned long) child
) + THREAD_SIZE
-
217 sizeof(struct pt_dspregs
);
218 if (*((int *) (dp
- 4)) == SR_FD
) {
219 copy_to_user(addr
, (void *) dp
,
220 sizeof(struct pt_dspregs
));
226 case PTRACE_SETDSPREGS
: {
231 dp
= ((unsigned long) child
) + THREAD_SIZE
-
232 sizeof(struct pt_dspregs
);
233 if (*((int *) (dp
- 4)) == SR_FD
) {
234 copy_from_user((void *) dp
, addr
,
235 sizeof(struct pt_dspregs
));
242 ret
= ptrace_request(child
, request
, addr
, data
);
249 asmlinkage
void do_syscall_trace(void)
251 struct task_struct
*tsk
= current
;
253 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
255 if (!(tsk
->ptrace
& PT_PTRACED
))
257 /* the 0x80 provides a way for the tracing parent to distinguish
258 between a syscall stop and SIGTRAP delivery */
259 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
263 * this isn't the same as continuing with a signal, but it will do
264 * for normal use. strace only continues with a signal if the
265 * stopping signal is not SIGTRAP. -brl
267 if (tsk
->exit_code
) {
268 send_sig(tsk
->exit_code
, tsk
, 1);