Commit | Line | Data |
---|---|---|
867e359b CM |
1 | /* |
2 | * Copyright 2010 Tilera Corporation. All Rights Reserved. | |
3 | * | |
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. | |
7 | * | |
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 | |
12 | * more details. | |
13 | * | |
14 | * Copied from i386: Ross Biro 1/23/92 | |
15 | */ | |
16 | ||
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> | |
0707ad30 | 22 | #include <asm/traps.h> |
867e359b CM |
23 | |
24 | void user_enable_single_step(struct task_struct *child) | |
25 | { | |
26 | set_tsk_thread_flag(child, TIF_SINGLESTEP); | |
27 | } | |
28 | ||
29 | void user_disable_single_step(struct task_struct *child) | |
30 | { | |
31 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | |
32 | } | |
33 | ||
867e359b CM |
34 | /* |
35 | * Called by kernel/ptrace.c when detaching.. | |
36 | */ | |
37 | void ptrace_disable(struct task_struct *child) | |
38 | { | |
39 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | |
40 | ||
41 | /* | |
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. | |
44 | */ | |
45 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
46 | } | |
47 | ||
48 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |
49 | { | |
ce7f2a39 | 50 | unsigned long __user *datap = (long __user __force *)data; |
867e359b CM |
51 | unsigned long tmp; |
52 | int i; | |
53 | long ret = -EIO; | |
ce7f2a39 CM |
54 | unsigned long *childregs; |
55 | char *childreg; | |
867e359b CM |
56 | |
57 | switch (request) { | |
58 | ||
59 | case PTRACE_PEEKUSR: /* Read register from pt_regs. */ | |
867e359b CM |
60 | if (addr < 0 || addr >= PTREGS_SIZE) |
61 | break; | |
ce7f2a39 CM |
62 | childreg = (char *)task_pt_regs(child) + addr; |
63 | #ifdef CONFIG_COMPAT | |
64 | if (is_compat_task()) { | |
65 | if (addr & (sizeof(compat_long_t)-1)) | |
66 | break; | |
67 | ret = put_user(*(compat_long_t *)childreg, | |
68 | (compat_long_t __user *)datap); | |
69 | } else | |
70 | #endif | |
71 | { | |
72 | if (addr & (sizeof(long)-1)) | |
73 | break; | |
74 | ret = put_user(*(long *)childreg, datap); | |
75 | } | |
867e359b CM |
76 | break; |
77 | ||
78 | case PTRACE_POKEUSR: /* Write register in pt_regs. */ | |
867e359b CM |
79 | if (addr < 0 || addr >= PTREGS_SIZE) |
80 | break; | |
ce7f2a39 CM |
81 | childreg = (char *)task_pt_regs(child) + addr; |
82 | #ifdef CONFIG_COMPAT | |
83 | if (is_compat_task()) { | |
84 | if (addr & (sizeof(compat_long_t)-1)) | |
85 | break; | |
86 | *(compat_long_t *)childreg = data; | |
87 | } else | |
88 | #endif | |
89 | { | |
90 | if (addr & (sizeof(long)-1)) | |
91 | break; | |
92 | *(long *)childreg = data; | |
93 | } | |
bcd97c3f | 94 | ret = 0; |
867e359b CM |
95 | break; |
96 | ||
97 | case PTRACE_GETREGS: /* Get all registers from the child. */ | |
98 | if (!access_ok(VERIFY_WRITE, datap, PTREGS_SIZE)) | |
99 | break; | |
ce7f2a39 CM |
100 | childregs = (long *)task_pt_regs(child); |
101 | for (i = 0; i < sizeof(struct pt_regs)/sizeof(long); ++i) { | |
102 | ret = __put_user(childregs[i], &datap[i]); | |
867e359b CM |
103 | if (ret != 0) |
104 | break; | |
867e359b CM |
105 | } |
106 | break; | |
107 | ||
108 | case PTRACE_SETREGS: /* Set all registers in the child. */ | |
109 | if (!access_ok(VERIFY_READ, datap, PTREGS_SIZE)) | |
110 | break; | |
ce7f2a39 CM |
111 | childregs = (long *)task_pt_regs(child); |
112 | for (i = 0; i < sizeof(struct pt_regs)/sizeof(long); ++i) { | |
113 | ret = __get_user(childregs[i], &datap[i]); | |
867e359b CM |
114 | if (ret != 0) |
115 | break; | |
867e359b CM |
116 | } |
117 | break; | |
118 | ||
119 | case PTRACE_GETFPREGS: /* Get the child FPU state. */ | |
120 | case PTRACE_SETFPREGS: /* Set the child FPU state. */ | |
121 | break; | |
122 | ||
123 | case PTRACE_SETOPTIONS: | |
124 | /* Support TILE-specific ptrace options. */ | |
125 | child->ptrace &= ~PT_TRACE_MASK_TILE; | |
126 | tmp = data & PTRACE_O_MASK_TILE; | |
127 | data &= ~PTRACE_O_MASK_TILE; | |
128 | ret = ptrace_request(child, request, addr, data); | |
129 | if (tmp & PTRACE_O_TRACEMIGRATE) | |
130 | child->ptrace |= PT_TRACE_MIGRATE; | |
131 | break; | |
132 | ||
133 | default: | |
134 | #ifdef CONFIG_COMPAT | |
135 | if (task_thread_info(current)->status & TS_COMPAT) { | |
136 | ret = compat_ptrace_request(child, request, | |
137 | addr, data); | |
138 | break; | |
139 | } | |
140 | #endif | |
141 | ret = ptrace_request(child, request, addr, data); | |
142 | break; | |
143 | } | |
144 | ||
145 | return ret; | |
146 | } | |
147 | ||
148 | #ifdef CONFIG_COMPAT | |
149 | /* Not used; we handle compat issues in arch_ptrace() directly. */ | |
150 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | |
151 | compat_ulong_t addr, compat_ulong_t data) | |
152 | { | |
153 | BUG(); | |
154 | } | |
155 | #endif | |
156 | ||
157 | void do_syscall_trace(void) | |
158 | { | |
159 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) | |
160 | return; | |
161 | ||
162 | if (!(current->ptrace & PT_PTRACED)) | |
163 | return; | |
164 | ||
165 | /* | |
166 | * The 0x80 provides a way for the tracing parent to distinguish | |
167 | * between a syscall stop and SIGTRAP delivery | |
168 | */ | |
169 | ptrace_notify(SIGTRAP|((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0)); | |
170 | ||
171 | /* | |
172 | * this isn't the same as continuing with a signal, but it will do | |
173 | * for normal use. strace only continues with a signal if the | |
174 | * stopping signal is not SIGTRAP. -brl | |
175 | */ | |
176 | if (current->exit_code) { | |
177 | send_sig(current->exit_code, current, 1); | |
178 | current->exit_code = 0; | |
179 | } | |
180 | } | |
181 | ||
182 | void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) | |
183 | { | |
184 | struct siginfo info; | |
185 | ||
186 | memset(&info, 0, sizeof(info)); | |
187 | info.si_signo = SIGTRAP; | |
188 | info.si_code = TRAP_BRKPT; | |
189 | info.si_addr = (void __user *) regs->pc; | |
190 | ||
191 | /* Send us the fakey SIGTRAP */ | |
192 | force_sig_info(SIGTRAP, &info, tsk); | |
193 | } | |
194 | ||
195 | /* Handle synthetic interrupt delivered only by the simulator. */ | |
196 | void __kprobes do_breakpoint(struct pt_regs* regs, int fault_num) | |
197 | { | |
198 | send_sigtrap(current, regs, fault_num); | |
199 | } |