2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
14 * Copied from i386: Ross Biro 1/23/92
17 #include <linux/kernel.h>
18 #include <linux/ptrace.h>
19 #include <linux/kprobes.h>
20 #include <linux/compat.h>
21 #include <linux/uaccess.h>
22 #include <asm/traps.h>
24 void user_enable_single_step(struct task_struct
*child
)
26 set_tsk_thread_flag(child
, TIF_SINGLESTEP
);
29 void user_disable_single_step(struct task_struct
*child
)
31 clear_tsk_thread_flag(child
, TIF_SINGLESTEP
);
35 * Called by kernel/ptrace.c when detaching..
37 void ptrace_disable(struct task_struct
*child
)
39 clear_tsk_thread_flag(child
, TIF_SINGLESTEP
);
42 * These two are currently unused, but will be set by arch_ptrace()
43 * and used in the syscall assembly when we do support them.
45 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
48 long arch_ptrace(struct task_struct
*child
, long request
,
49 unsigned long addr
, unsigned long data
)
51 unsigned long __user
*datap
= (long __user __force
*)data
;
55 struct pt_regs copyregs
;
60 case PTRACE_PEEKUSR
: /* Read register from pt_regs. */
61 if (addr
>= PTREGS_SIZE
)
63 childreg
= (char *)task_pt_regs(child
) + addr
;
65 if (is_compat_task()) {
66 if (addr
& (sizeof(compat_long_t
)-1))
68 ret
= put_user(*(compat_long_t
*)childreg
,
69 (compat_long_t __user
*)datap
);
73 if (addr
& (sizeof(long)-1))
75 ret
= put_user(*(long *)childreg
, datap
);
79 case PTRACE_POKEUSR
: /* Write register in pt_regs. */
80 if (addr
>= PTREGS_SIZE
)
82 childreg
= (char *)task_pt_regs(child
) + addr
;
84 /* Guard against overwrites of the privilege level. */
85 ex1_offset
= PTREGS_OFFSET_EX1
;
86 #if defined(CONFIG_COMPAT) && defined(__BIG_ENDIAN)
87 if (is_compat_task()) /* point at low word */
88 ex1_offset
+= sizeof(compat_long_t
);
90 if (addr
== ex1_offset
)
91 data
= PL_ICS_EX1(USER_PL
, EX1_ICS(data
));
94 if (is_compat_task()) {
95 if (addr
& (sizeof(compat_long_t
)-1))
97 *(compat_long_t
*)childreg
= data
;
101 if (addr
& (sizeof(long)-1))
103 *(long *)childreg
= data
;
108 case PTRACE_GETREGS
: /* Get all registers from the child. */
109 if (copy_to_user(datap
, task_pt_regs(child
),
110 sizeof(struct pt_regs
)) == 0) {
115 case PTRACE_SETREGS
: /* Set all registers in the child. */
116 if (copy_from_user(©regs
, datap
,
117 sizeof(struct pt_regs
)) == 0) {
119 PL_ICS_EX1(USER_PL
, EX1_ICS(copyregs
.ex1
));
120 *task_pt_regs(child
) = copyregs
;
125 case PTRACE_GETFPREGS
: /* Get the child FPU state. */
126 case PTRACE_SETFPREGS
: /* Set the child FPU state. */
129 case PTRACE_SETOPTIONS
:
130 /* Support TILE-specific ptrace options. */
131 child
->ptrace
&= ~PT_TRACE_MASK_TILE
;
132 tmp
= data
& PTRACE_O_MASK_TILE
;
133 data
&= ~PTRACE_O_MASK_TILE
;
134 ret
= ptrace_request(child
, request
, addr
, data
);
135 if (tmp
& PTRACE_O_TRACEMIGRATE
)
136 child
->ptrace
|= PT_TRACE_MIGRATE
;
141 if (task_thread_info(current
)->status
& TS_COMPAT
) {
142 ret
= compat_ptrace_request(child
, request
,
147 ret
= ptrace_request(child
, request
, addr
, data
);
155 /* Not used; we handle compat issues in arch_ptrace() directly. */
156 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
157 compat_ulong_t addr
, compat_ulong_t data
)
163 void do_syscall_trace(void)
165 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
168 if (!(current
->ptrace
& PT_PTRACED
))
172 * The 0x80 provides a way for the tracing parent to distinguish
173 * between a syscall stop and SIGTRAP delivery
175 ptrace_notify(SIGTRAP
|((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80 : 0));
178 * this isn't the same as continuing with a signal, but it will do
179 * for normal use. strace only continues with a signal if the
180 * stopping signal is not SIGTRAP. -brl
182 if (current
->exit_code
) {
183 send_sig(current
->exit_code
, current
, 1);
184 current
->exit_code
= 0;
188 void send_sigtrap(struct task_struct
*tsk
, struct pt_regs
*regs
, int error_code
)
192 memset(&info
, 0, sizeof(info
));
193 info
.si_signo
= SIGTRAP
;
194 info
.si_code
= TRAP_BRKPT
;
195 info
.si_addr
= (void __user
*) regs
->pc
;
197 /* Send us the fakey SIGTRAP */
198 force_sig_info(SIGTRAP
, &info
, tsk
);
201 /* Handle synthetic interrupt delivered only by the simulator. */
202 void __kprobes
do_breakpoint(struct pt_regs
* regs
, int fault_num
)
204 send_sigtrap(current
, regs
, fault_num
);