]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/sh64/kernel/ptrace.c
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * arch/sh64/kernel/ptrace.c
8 * Copyright (C) 2000, 2001 Paolo Alberelli
9 * Copyright (C) 2003 Paul Mundt
11 * Started from SH3/4 version:
12 * SuperH version: Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
14 * Original x86 implementation:
15 * By Ross Biro 1/23/92
16 * edited by Linus Torvalds
20 #include <linux/kernel.h>
21 #include <linux/rwsem.h>
22 #include <linux/sched.h>
24 #include <linux/smp.h>
25 #include <linux/smp_lock.h>
26 #include <linux/errno.h>
27 #include <linux/ptrace.h>
28 #include <linux/user.h>
29 #include <linux/signal.h>
30 #include <linux/syscalls.h>
33 #include <asm/uaccess.h>
34 #include <asm/pgtable.h>
35 #include <asm/system.h>
36 #include <asm/processor.h>
37 #include <asm/mmu_context.h>
39 /* This mask defines the bits of the SR which the user is not allowed to
40 change, which are everything except S, Q, M, PR, SZ, FR. */
41 #define SR_MASK (0xffff8cfd)
44 * does not yet catch signals sent when the child dies.
45 * in exit.c or in signal.c.
49 * This routine will get a word from the user area in the process kernel stack.
51 static inline int get_stack_long(struct task_struct
*task
, int offset
)
55 stack
= (unsigned char *)(task
->thread
.uregs
);
57 return (*((int *)stack
));
60 static inline unsigned long
61 get_fpu_long(struct task_struct
*task
, unsigned long addr
)
65 regs
= (struct pt_regs
*)((unsigned char *)task
+ THREAD_SIZE
) - 1;
67 if (!tsk_used_math(task
)) {
68 if (addr
== offsetof(struct user_fpu_struct
, fpscr
)) {
71 tmp
= 0xffffffffUL
; /* matches initial value in fpu.c */
76 if (last_task_used_math
== task
) {
78 fpsave(&task
->thread
.fpu
.hard
);
80 last_task_used_math
= 0;
84 tmp
= ((long *)&task
->thread
.fpu
)[addr
/ sizeof(unsigned long)];
89 * This routine will put a word into the user area in the process kernel stack.
91 static inline int put_stack_long(struct task_struct
*task
, int offset
,
96 stack
= (unsigned char *)(task
->thread
.uregs
);
98 *(unsigned long *) stack
= data
;
103 put_fpu_long(struct task_struct
*task
, unsigned long addr
, unsigned long data
)
105 struct pt_regs
*regs
;
107 regs
= (struct pt_regs
*)((unsigned char *)task
+ THREAD_SIZE
) - 1;
109 if (!tsk_used_math(task
)) {
110 fpinit(&task
->thread
.fpu
.hard
);
111 set_stopped_child_used_math(task
);
112 } else if (last_task_used_math
== task
) {
114 fpsave(&task
->thread
.fpu
.hard
);
116 last_task_used_math
= 0;
120 ((long *)&task
->thread
.fpu
)[addr
/ sizeof(unsigned long)] = data
;
125 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
130 /* when I and D space are separate, these will need to be fixed. */
131 case PTRACE_PEEKTEXT
: /* read word at location addr. */
132 case PTRACE_PEEKDATA
: {
136 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
138 if (copied
!= sizeof(tmp
))
140 ret
= put_user(tmp
,(unsigned long *) data
);
144 /* read the word at location addr in the USER area. */
145 case PTRACE_PEEKUSR
: {
149 if ((addr
& 3) || addr
< 0)
152 if (addr
< sizeof(struct pt_regs
))
153 tmp
= get_stack_long(child
, addr
);
154 else if ((addr
>= offsetof(struct user
, fpu
)) &&
155 (addr
< offsetof(struct user
, u_fpvalid
))) {
156 tmp
= get_fpu_long(child
, addr
- offsetof(struct user
, fpu
));
157 } else if (addr
== offsetof(struct user
, u_fpvalid
)) {
158 tmp
= !!tsk_used_math(child
);
162 ret
= put_user(tmp
, (unsigned long *)data
);
166 /* when I and D space are separate, this will have to be fixed. */
167 case PTRACE_POKETEXT
: /* write the word at location addr. */
168 case PTRACE_POKEDATA
:
170 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1) == sizeof(data
))
176 /* write the word at location addr in the USER area. We must
177 disallow any changes to certain SR bits or u_fpvalid, since
178 this could crash the kernel or result in a security
181 if ((addr
& 3) || addr
< 0)
184 if (addr
< sizeof(struct pt_regs
)) {
185 /* Ignore change of top 32 bits of SR */
186 if (addr
== offsetof (struct pt_regs
, sr
)+4)
191 /* If lower 32 bits of SR, ignore non-user bits */
192 if (addr
== offsetof (struct pt_regs
, sr
))
194 long cursr
= get_stack_long(child
, addr
);
196 data
|= (cursr
& SR_MASK
);
198 ret
= put_stack_long(child
, addr
, data
);
200 else if ((addr
>= offsetof(struct user
, fpu
)) &&
201 (addr
< offsetof(struct user
, u_fpvalid
))) {
202 ret
= put_fpu_long(child
, addr
- offsetof(struct user
, fpu
), data
);
206 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
207 case PTRACE_CONT
: { /* restart after signal. */
209 if (!valid_signal(data
))
211 if (request
== PTRACE_SYSCALL
)
212 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
214 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
215 child
->exit_code
= data
;
216 wake_up_process(child
);
222 * make the child exit. Best I can do is send it a sigkill.
223 * perhaps it should be put in the status that it wants to
228 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
230 child
->exit_code
= SIGKILL
;
231 wake_up_process(child
);
235 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
236 struct pt_regs
*regs
;
239 if (!valid_signal(data
))
241 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
242 if ((child
->ptrace
& PT_DTRACE
) == 0) {
243 /* Spurious delayed TF traps may occur */
244 child
->ptrace
|= PT_DTRACE
;
247 regs
= child
->thread
.uregs
;
249 regs
->sr
|= SR_SSTEP
; /* auto-resetting upon exception */
251 child
->exit_code
= data
;
252 /* give it a chance to run. */
253 wake_up_process(child
);
258 case PTRACE_DETACH
: /* detach a process that was attached. */
259 ret
= ptrace_detach(child
, data
);
263 ret
= ptrace_request(child
, request
, addr
, data
);
269 asmlinkage
int sh64_ptrace(long request
, long pid
, long addr
, long data
)
271 extern void poke_real_address_q(unsigned long long addr
, unsigned long long data
);
272 #define WPC_DBRMODE 0x0d104008
273 static int first_call
= 1;
277 /* Set WPC.DBRMODE to 0. This makes all debug events get
278 * delivered through RESVEC, i.e. into the handlers in entry.S.
279 * (If the kernel was downloaded using a remote gdb, WPC.DBRMODE
280 * would normally be left set to 1, which makes debug events get
281 * delivered through DBRVEC, i.e. into the remote gdb's
282 * handlers. This prevents ptrace getting them, and confuses
283 * the remote gdb.) */
284 printk("DBRMODE set to 0 to permit native debugging\n");
285 poke_real_address_q(WPC_DBRMODE
, 0);
290 return sys_ptrace(request
, pid
, addr
, data
);
293 asmlinkage
void syscall_trace(void)
295 struct task_struct
*tsk
= current
;
297 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
299 if (!(tsk
->ptrace
& PT_PTRACED
))
302 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
305 * this isn't the same as continuing with a signal, but it will do
306 * for normal use. strace only continues with a signal if the
307 * stopping signal is not SIGTRAP. -brl
309 if (tsk
->exit_code
) {
310 send_sig(tsk
->exit_code
, tsk
, 1);
315 /* Called with interrupts disabled */
316 asmlinkage
void do_single_step(unsigned long long vec
, struct pt_regs
*regs
)
318 /* This is called after a single step exception (DEBUGSS).
319 There is no need to change the PC, as it is a post-execution
320 exception, as entry.S does not do anything to the PC for DEBUGSS.
321 We need to clear the Single Step setting in SR to avoid
322 continually stepping. */
324 regs
->sr
&= ~SR_SSTEP
;
325 force_sig(SIGTRAP
, current
);
328 /* Called with interrupts disabled */
329 asmlinkage
void do_software_break_point(unsigned long long vec
,
330 struct pt_regs
*regs
)
332 /* We need to forward step the PC, to counteract the backstep done
335 force_sig(SIGTRAP
, current
);
340 * Called by kernel/ptrace.c when detaching..
342 * Make sure single step bits etc are not set.
344 void ptrace_disable(struct task_struct
*child
)
346 /* nothing to do.. */