]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/sh/kernel/ptrace.c
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 *)
45 task
->thread_info
+ THREAD_SIZE
- sizeof(struct pt_regs
)
47 - sizeof(struct pt_dspregs
)
49 - sizeof(unsigned long);
51 return (*((int *)stack
));
55 * This routine will put a word on the process kernel stack.
57 static inline int put_stack_long(struct task_struct
*task
, int offset
,
62 stack
= (unsigned char *)
63 task
->thread_info
+ THREAD_SIZE
- sizeof(struct pt_regs
)
65 - sizeof(struct pt_dspregs
)
67 - sizeof(unsigned long);
69 *(unsigned long *) stack
= data
;
74 * Called by kernel/ptrace.c when detaching..
76 * Make sure single step bits etc are not set.
78 void ptrace_disable(struct task_struct
*child
)
83 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
85 struct user
* dummy
= NULL
;
89 /* when I and D space are separate, these will need to be fixed. */
90 case PTRACE_PEEKTEXT
: /* read word at location addr. */
91 case PTRACE_PEEKDATA
: {
95 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
97 if (copied
!= sizeof(tmp
))
99 ret
= put_user(tmp
,(unsigned long *) data
);
103 /* read the word at location addr in the USER area. */
104 case PTRACE_PEEKUSR
: {
108 if ((addr
& 3) || addr
< 0 ||
109 addr
> sizeof(struct user
) - 3)
112 if (addr
< sizeof(struct pt_regs
))
113 tmp
= get_stack_long(child
, addr
);
114 else if (addr
>= (long) &dummy
->fpu
&&
115 addr
< (long) &dummy
->u_fpvalid
) {
116 if (!tsk_used_math(child
)) {
117 if (addr
== (long)&dummy
->fpu
.fpscr
)
122 tmp
= ((long *)&child
->thread
.fpu
)
123 [(addr
- (long)&dummy
->fpu
) >> 2];
124 } else if (addr
== (long) &dummy
->u_fpvalid
)
125 tmp
= !!tsk_used_math(child
);
128 ret
= put_user(tmp
, (unsigned long *)data
);
132 /* when I and D space are separate, this will have to be fixed. */
133 case PTRACE_POKETEXT
: /* write the word at location addr. */
134 case PTRACE_POKEDATA
:
136 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1) == sizeof(data
))
141 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
143 if ((addr
& 3) || addr
< 0 ||
144 addr
> sizeof(struct user
) - 3)
147 if (addr
< sizeof(struct pt_regs
))
148 ret
= put_stack_long(child
, addr
, data
);
149 else if (addr
>= (long) &dummy
->fpu
&&
150 addr
< (long) &dummy
->u_fpvalid
) {
151 set_stopped_child_used_math(child
);
152 ((long *)&child
->thread
.fpu
)
153 [(addr
- (long)&dummy
->fpu
) >> 2] = data
;
155 } else if (addr
== (long) &dummy
->u_fpvalid
) {
156 conditional_stopped_child_used_math(data
, child
);
161 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
162 case PTRACE_CONT
: { /* restart after signal. */
164 if (!valid_signal(data
))
166 if (request
== PTRACE_SYSCALL
)
167 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
169 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
170 child
->exit_code
= data
;
171 wake_up_process(child
);
177 * make the child exit. Best I can do is send it a sigkill.
178 * perhaps it should be put in the status that it wants to
183 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
185 child
->exit_code
= SIGKILL
;
186 wake_up_process(child
);
190 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
192 struct pt_regs
*dummy
= NULL
;
195 if (!valid_signal(data
))
197 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
198 if ((child
->ptrace
& PT_DTRACE
) == 0) {
199 /* Spurious delayed TF traps may occur */
200 child
->ptrace
|= PT_DTRACE
;
203 pc
= get_stack_long(child
, (long)&dummy
->pc
);
205 /* Next scheduling will set up UBC */
206 if (child
->thread
.ubc_pc
== 0)
208 child
->thread
.ubc_pc
= pc
;
210 child
->exit_code
= data
;
211 /* give it a chance to run. */
212 wake_up_process(child
);
217 case PTRACE_DETACH
: /* detach a process that was attached. */
218 ret
= ptrace_detach(child
, data
);
222 case PTRACE_GETDSPREGS
: {
226 dp
= ((unsigned long) child
) + THREAD_SIZE
-
227 sizeof(struct pt_dspregs
);
228 if (*((int *) (dp
- 4)) == SR_FD
) {
229 copy_to_user(addr
, (void *) dp
,
230 sizeof(struct pt_dspregs
));
236 case PTRACE_SETDSPREGS
: {
241 dp
= ((unsigned long) child
) + THREAD_SIZE
-
242 sizeof(struct pt_dspregs
);
243 if (*((int *) (dp
- 4)) == SR_FD
) {
244 copy_from_user((void *) dp
, addr
,
245 sizeof(struct pt_dspregs
));
252 ret
= ptrace_request(child
, request
, addr
, data
);
259 asmlinkage
void do_syscall_trace(void)
261 struct task_struct
*tsk
= current
;
263 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
265 if (!(tsk
->ptrace
& PT_PTRACED
))
267 /* the 0x80 provides a way for the tracing parent to distinguish
268 between a syscall stop and SIGTRAP delivery */
269 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
273 * this isn't the same as continuing with a signal, but it will do
274 * for normal use. strace only continues with a signal if the
275 * stopping signal is not SIGTRAP. -brl
277 if (tsk
->exit_code
) {
278 send_sig(tsk
->exit_code
, tsk
, 1);