aboutsummaryrefslogtreecommitdiffstats
path: root/arch/parisc/kernel/ptrace.c
diff options
context:
space:
mode:
authorHelge Deller <deller@gmx.de>2008-10-17 14:48:36 -0400
committerKyle McMartin <kyle@hera.kernel.org>2008-10-17 15:03:23 -0400
commit81e192d6ce303b6792aa38ff35f41a1a7357f23a (patch)
treef4410647fc30739593ecd5d1a159092cdb6bde9c /arch/parisc/kernel/ptrace.c
parent9eb1686423756f4dfb0ad8bfb02bb8bf1b89e50a (diff)
parisc: convert to generic compat_sys_ptrace
This patch does the compat_sys_ptrace conversion for parisc. In addition it does convert the parisc ptrace code to use the architecture-independent ptrace infrastructure instead of own coding. Signed-off-by: Helge Deller <deller@gmx.de> Signed-off-by: Kyle McMartin <kyle@mcmartin.ca>
Diffstat (limited to 'arch/parisc/kernel/ptrace.c')
-rw-r--r--arch/parisc/kernel/ptrace.c429
1 files changed, 172 insertions, 257 deletions
diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c
index 49c637970789..90904f9dfc50 100644
--- a/arch/parisc/kernel/ptrace.c
+++ b/arch/parisc/kernel/ptrace.c
@@ -4,6 +4,7 @@
4 * Copyright (C) 2000 Hewlett-Packard Co, Linuxcare Inc. 4 * Copyright (C) 2000 Hewlett-Packard Co, Linuxcare Inc.
5 * Copyright (C) 2000 Matthew Wilcox <matthew@wil.cx> 5 * Copyright (C) 2000 Matthew Wilcox <matthew@wil.cx>
6 * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org> 6 * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
7 * Copyright (C) 2008 Helge Deller <deller@gmx.de>
7 */ 8 */
8 9
9#include <linux/kernel.h> 10#include <linux/kernel.h>
@@ -27,15 +28,149 @@
27/* PSW bits we allow the debugger to modify */ 28/* PSW bits we allow the debugger to modify */
28#define USER_PSW_BITS (PSW_N | PSW_V | PSW_CB) 29#define USER_PSW_BITS (PSW_N | PSW_V | PSW_CB)
29 30
30#undef DEBUG_PTRACE 31/*
32 * Called by kernel/ptrace.c when detaching..
33 *
34 * Make sure single step bits etc are not set.
35 */
36void ptrace_disable(struct task_struct *task)
37{
38 task->ptrace &= ~(PT_SINGLESTEP|PT_BLOCKSTEP);
31 39
32#ifdef DEBUG_PTRACE 40 /* make sure the trap bits are not set */
33#define DBG(x...) printk(x) 41 pa_psw(task)->r = 0;
34#else 42 pa_psw(task)->t = 0;
35#define DBG(x...) 43 pa_psw(task)->h = 0;
36#endif 44 pa_psw(task)->l = 0;
45}
46
47/*
48 * The following functions are called by ptrace_resume() when
49 * enabling or disabling single/block tracing.
50 */
51void user_disable_single_step(struct task_struct *task)
52{
53 ptrace_disable(task);
54}
55
56void user_enable_single_step(struct task_struct *task)
57{
58 task->ptrace &= ~PT_BLOCKSTEP;
59 task->ptrace |= PT_SINGLESTEP;
60
61 if (pa_psw(task)->n) {
62 struct siginfo si;
63
64 /* Nullified, just crank over the queue. */
65 task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1];
66 task_regs(task)->iasq[0] = task_regs(task)->iasq[1];
67 task_regs(task)->iaoq[1] = task_regs(task)->iaoq[0] + 4;
68 pa_psw(task)->n = 0;
69 pa_psw(task)->x = 0;
70 pa_psw(task)->y = 0;
71 pa_psw(task)->z = 0;
72 pa_psw(task)->b = 0;
73 ptrace_disable(task);
74 /* Don't wake up the task, but let the
75 parent know something happened. */
76 si.si_code = TRAP_TRACE;
77 si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3);
78 si.si_signo = SIGTRAP;
79 si.si_errno = 0;
80 force_sig_info(SIGTRAP, &si, task);
81 /* notify_parent(task, SIGCHLD); */
82 return;
83 }
84
85 /* Enable recovery counter traps. The recovery counter
86 * itself will be set to zero on a task switch. If the
87 * task is suspended on a syscall then the syscall return
88 * path will overwrite the recovery counter with a suitable
89 * value such that it traps once back in user space. We
90 * disable interrupts in the tasks PSW here also, to avoid
91 * interrupts while the recovery counter is decrementing.
92 */
93 pa_psw(task)->r = 1;
94 pa_psw(task)->t = 0;
95 pa_psw(task)->h = 0;
96 pa_psw(task)->l = 0;
97}
98
99void user_enable_block_step(struct task_struct *task)
100{
101 task->ptrace &= ~PT_SINGLESTEP;
102 task->ptrace |= PT_BLOCKSTEP;
103
104 /* Enable taken branch trap. */
105 pa_psw(task)->r = 0;
106 pa_psw(task)->t = 1;
107 pa_psw(task)->h = 0;
108 pa_psw(task)->l = 0;
109}
110
111long arch_ptrace(struct task_struct *child, long request, long addr, long data)
112{
113 unsigned long tmp;
114 long ret = -EIO;
37 115
38#ifdef CONFIG_64BIT 116 switch (request) {
117
118 /* Read the word at location addr in the USER area. For ptraced
119 processes, the kernel saves all regs on a syscall. */
120 case PTRACE_PEEKUSR:
121 if ((addr & (sizeof(long)-1)) ||
122 (unsigned long) addr >= sizeof(struct pt_regs))
123 break;
124 tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
125 ret = put_user(tmp, (unsigned long *) data);
126 break;
127
128 /* Write the word at location addr in the USER area. This will need
129 to change when the kernel no longer saves all regs on a syscall.
130 FIXME. There is a problem at the moment in that r3-r18 are only
131 saved if the process is ptraced on syscall entry, and even then
132 those values are overwritten by actual register values on syscall
133 exit. */
134 case PTRACE_POKEUSR:
135 /* Some register values written here may be ignored in
136 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
137 * r31/r31+4, and not with the values in pt_regs.
138 */
139 if (addr == PT_PSW) {
140 /* Allow writing to Nullify, Divide-step-correction,
141 * and carry/borrow bits.
142 * BEWARE, if you set N, and then single step, it won't
143 * stop on the nullified instruction.
144 */
145 data &= USER_PSW_BITS;
146 task_regs(child)->gr[0] &= ~USER_PSW_BITS;
147 task_regs(child)->gr[0] |= data;
148 ret = 0;
149 break;
150 }
151
152 if ((addr & (sizeof(long)-1)) ||
153 (unsigned long) addr >= sizeof(struct pt_regs))
154 break;
155 if ((addr >= PT_GR1 && addr <= PT_GR31) ||
156 addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
157 (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
158 addr == PT_SAR) {
159 *(unsigned long *) ((char *) task_regs(child) + addr) = data;
160 ret = 0;
161 }
162 break;
163
164 default:
165 ret = ptrace_request(child, request, addr, data);
166 break;
167 }
168
169 return ret;
170}
171
172
173#ifdef CONFIG_COMPAT
39 174
40/* This function is needed to translate 32 bit pt_regs offsets in to 175/* This function is needed to translate 32 bit pt_regs offsets in to
41 * 64 bit pt_regs offsets. For example, a 32 bit gdb under a 64 bit kernel 176 * 64 bit pt_regs offsets. For example, a 32 bit gdb under a 64 bit kernel
@@ -61,106 +196,25 @@ static long translate_usr_offset(long offset)
61 else 196 else
62 return -1; 197 return -1;
63} 198}
64#endif
65 199
66/* 200long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67 * Called by kernel/ptrace.c when detaching.. 201 compat_ulong_t addr, compat_ulong_t data)
68 *
69 * Make sure single step bits etc are not set.
70 */
71void ptrace_disable(struct task_struct *child)
72{ 202{
73 /* make sure the trap bits are not set */ 203 compat_uint_t tmp;
74 pa_psw(child)->r = 0; 204 long ret = -EIO;
75 pa_psw(child)->t = 0;
76 pa_psw(child)->h = 0;
77 pa_psw(child)->l = 0;
78}
79
80long arch_ptrace(struct task_struct *child, long request, long addr, long data)
81{
82 long ret;
83#ifdef DEBUG_PTRACE
84 long oaddr=addr, odata=data;
85#endif
86 205
87 switch (request) { 206 switch (request) {
88 case PTRACE_PEEKTEXT: /* read word at location addr. */
89 case PTRACE_PEEKDATA: {
90#ifdef CONFIG_64BIT
91 if (__is_compat_task(child)) {
92 int copied;
93 unsigned int tmp;
94
95 addr &= 0xffffffffL;
96 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
97 ret = -EIO;
98 if (copied != sizeof(tmp))
99 goto out_tsk;
100 ret = put_user(tmp,(unsigned int *) data);
101 DBG("sys_ptrace(PEEK%s, %d, %lx, %lx) returning %ld, data %x\n",
102 request == PTRACE_PEEKTEXT ? "TEXT" : "DATA",
103 pid, oaddr, odata, ret, tmp);
104 }
105 else
106#endif
107 ret = generic_ptrace_peekdata(child, addr, data);
108 goto out_tsk;
109 }
110 207
111 /* when I and D space are separate, this will have to be fixed. */ 208 case PTRACE_PEEKUSR:
112 case PTRACE_POKETEXT: /* write the word at location addr. */ 209 if (addr & (sizeof(compat_uint_t)-1))
113 case PTRACE_POKEDATA: 210 break;
114 ret = 0; 211 addr = translate_usr_offset(addr);
115#ifdef CONFIG_64BIT 212 if (addr < 0)
116 if (__is_compat_task(child)) { 213 break;
117 unsigned int tmp = (unsigned int)data;
118 DBG("sys_ptrace(POKE%s, %d, %lx, %lx)\n",
119 request == PTRACE_POKETEXT ? "TEXT" : "DATA",
120 pid, oaddr, odata);
121 addr &= 0xffffffffL;
122 if (access_process_vm(child, addr, &tmp, sizeof(tmp), 1) == sizeof(tmp))
123 goto out_tsk;
124 }
125 else
126#endif
127 {
128 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
129 goto out_tsk;
130 }
131 ret = -EIO;
132 goto out_tsk;
133
134 /* Read the word at location addr in the USER area. For ptraced
135 processes, the kernel saves all regs on a syscall. */
136 case PTRACE_PEEKUSR: {
137 ret = -EIO;
138#ifdef CONFIG_64BIT
139 if (__is_compat_task(child)) {
140 unsigned int tmp;
141
142 if (addr & (sizeof(int)-1))
143 goto out_tsk;
144 if ((addr = translate_usr_offset(addr)) < 0)
145 goto out_tsk;
146
147 tmp = *(unsigned int *) ((char *) task_regs(child) + addr);
148 ret = put_user(tmp, (unsigned int *) data);
149 DBG("sys_ptrace(PEEKUSR, %d, %lx, %lx) returning %ld, addr %lx, data %x\n",
150 pid, oaddr, odata, ret, addr, tmp);
151 }
152 else
153#endif
154 {
155 unsigned long tmp;
156 214
157 if ((addr & (sizeof(long)-1)) || (unsigned long) addr >= sizeof(struct pt_regs)) 215 tmp = *(compat_uint_t *) ((char *) task_regs(child) + addr);
158 goto out_tsk; 216 ret = put_user(tmp, (compat_uint_t *) (unsigned long) data);
159 tmp = *(unsigned long *) ((char *) task_regs(child) + addr); 217 break;
160 ret = put_user(tmp, (unsigned long *) data);
161 }
162 goto out_tsk;
163 }
164 218
165 /* Write the word at location addr in the USER area. This will need 219 /* Write the word at location addr in the USER area. This will need
166 to change when the kernel no longer saves all regs on a syscall. 220 to change when the kernel no longer saves all regs on a syscall.
@@ -169,185 +223,46 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
169 those values are overwritten by actual register values on syscall 223 those values are overwritten by actual register values on syscall
170 exit. */ 224 exit. */
171 case PTRACE_POKEUSR: 225 case PTRACE_POKEUSR:
172 ret = -EIO;
173 /* Some register values written here may be ignored in 226 /* Some register values written here may be ignored in
174 * entry.S:syscall_restore_rfi; e.g. iaoq is written with 227 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
175 * r31/r31+4, and not with the values in pt_regs. 228 * r31/r31+4, and not with the values in pt_regs.
176 */ 229 */
177 /* PT_PSW=0, so this is valid for 32 bit processes under 64
178 * bit kernels.
179 */
180 if (addr == PT_PSW) { 230 if (addr == PT_PSW) {
181 /* PT_PSW=0, so this is valid for 32 bit processes 231 /* Since PT_PSW==0, it is valid for 32 bit processes
182 * under 64 bit kernels. 232 * under 64 bit kernels as well.
183 *
184 * Allow writing to Nullify, Divide-step-correction,
185 * and carry/borrow bits.
186 * BEWARE, if you set N, and then single step, it won't
187 * stop on the nullified instruction.
188 */ 233 */
189 DBG("sys_ptrace(POKEUSR, %d, %lx, %lx)\n", 234 ret = arch_ptrace(child, request, addr, data);
190 pid, oaddr, odata); 235 } else {
191 data &= USER_PSW_BITS; 236 if (addr & (sizeof(compat_uint_t)-1))
192 task_regs(child)->gr[0] &= ~USER_PSW_BITS; 237 break;
193 task_regs(child)->gr[0] |= data; 238 addr = translate_usr_offset(addr);
194 ret = 0; 239 if (addr < 0)
195 goto out_tsk; 240 break;
196 }
197#ifdef CONFIG_64BIT
198 if (__is_compat_task(child)) {
199 if (addr & (sizeof(int)-1))
200 goto out_tsk;
201 if ((addr = translate_usr_offset(addr)) < 0)
202 goto out_tsk;
203 DBG("sys_ptrace(POKEUSR, %d, %lx, %lx) addr %lx\n",
204 pid, oaddr, odata, addr);
205 if (addr >= PT_FR0 && addr <= PT_FR31 + 4) { 241 if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
206 /* Special case, fp regs are 64 bits anyway */ 242 /* Special case, fp regs are 64 bits anyway */
207 *(unsigned int *) ((char *) task_regs(child) + addr) = data; 243 *(__u64 *) ((char *) task_regs(child) + addr) = data;
208 ret = 0; 244 ret = 0;
209 } 245 }
210 else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) || 246 else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||
211 addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4 || 247 addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4 ||
212 addr == PT_SAR+4) { 248 addr == PT_SAR+4) {
213 /* Zero the top 32 bits */ 249 /* Zero the top 32 bits */
214 *(unsigned int *) ((char *) task_regs(child) + addr - 4) = 0; 250 *(__u32 *) ((char *) task_regs(child) + addr - 4) = 0;
215 *(unsigned int *) ((char *) task_regs(child) + addr) = data; 251 *(__u32 *) ((char *) task_regs(child) + addr) = data;
216 ret = 0; 252 ret = 0;
217 } 253 }
218 goto out_tsk;
219 } 254 }
220 else 255 break;
221#endif
222 {
223 if ((addr & (sizeof(long)-1)) || (unsigned long) addr >= sizeof(struct pt_regs))
224 goto out_tsk;
225 if ((addr >= PT_GR1 && addr <= PT_GR31) ||
226 addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
227 (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
228 addr == PT_SAR) {
229 *(unsigned long *) ((char *) task_regs(child) + addr) = data;
230 ret = 0;
231 }
232 goto out_tsk;
233 }
234
235 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
236 case PTRACE_CONT:
237 ret = -EIO;
238 DBG("sys_ptrace(%s)\n",
239 request == PTRACE_SYSCALL ? "SYSCALL" : "CONT");
240 if (!valid_signal(data))
241 goto out_tsk;
242 child->ptrace &= ~(PT_SINGLESTEP|PT_BLOCKSTEP);
243 if (request == PTRACE_SYSCALL) {
244 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
245 } else {
246 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
247 }
248 child->exit_code = data;
249 goto out_wake_notrap;
250
251 case PTRACE_KILL:
252 /*
253 * make the child exit. Best I can do is send it a
254 * sigkill. perhaps it should be put in the status
255 * that it wants to exit.
256 */
257 ret = 0;
258 DBG("sys_ptrace(KILL)\n");
259 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
260 goto out_tsk;
261 child->exit_code = SIGKILL;
262 goto out_wake_notrap;
263
264 case PTRACE_SINGLEBLOCK:
265 DBG("sys_ptrace(SINGLEBLOCK)\n");
266 ret = -EIO;
267 if (!valid_signal(data))
268 goto out_tsk;
269 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
270 child->ptrace &= ~PT_SINGLESTEP;
271 child->ptrace |= PT_BLOCKSTEP;
272 child->exit_code = data;
273
274 /* Enable taken branch trap. */
275 pa_psw(child)->r = 0;
276 pa_psw(child)->t = 1;
277 pa_psw(child)->h = 0;
278 pa_psw(child)->l = 0;
279 goto out_wake;
280
281 case PTRACE_SINGLESTEP:
282 DBG("sys_ptrace(SINGLESTEP)\n");
283 ret = -EIO;
284 if (!valid_signal(data))
285 goto out_tsk;
286
287 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
288 child->ptrace &= ~PT_BLOCKSTEP;
289 child->ptrace |= PT_SINGLESTEP;
290 child->exit_code = data;
291
292 if (pa_psw(child)->n) {
293 struct siginfo si;
294
295 /* Nullified, just crank over the queue. */
296 task_regs(child)->iaoq[0] = task_regs(child)->iaoq[1];
297 task_regs(child)->iasq[0] = task_regs(child)->iasq[1];
298 task_regs(child)->iaoq[1] = task_regs(child)->iaoq[0] + 4;
299 pa_psw(child)->n = 0;
300 pa_psw(child)->x = 0;
301 pa_psw(child)->y = 0;
302 pa_psw(child)->z = 0;
303 pa_psw(child)->b = 0;
304 ptrace_disable(child);
305 /* Don't wake up the child, but let the
306 parent know something happened. */
307 si.si_code = TRAP_TRACE;
308 si.si_addr = (void __user *) (task_regs(child)->iaoq[0] & ~3);
309 si.si_signo = SIGTRAP;
310 si.si_errno = 0;
311 force_sig_info(SIGTRAP, &si, child);
312 //notify_parent(child, SIGCHLD);
313 //ret = 0;
314 goto out_wake;
315 }
316
317 /* Enable recovery counter traps. The recovery counter
318 * itself will be set to zero on a task switch. If the
319 * task is suspended on a syscall then the syscall return
320 * path will overwrite the recovery counter with a suitable
321 * value such that it traps once back in user space. We
322 * disable interrupts in the childs PSW here also, to avoid
323 * interrupts while the recovery counter is decrementing.
324 */
325 pa_psw(child)->r = 1;
326 pa_psw(child)->t = 0;
327 pa_psw(child)->h = 0;
328 pa_psw(child)->l = 0;
329 /* give it a chance to run. */
330 goto out_wake;
331
332 case PTRACE_GETEVENTMSG:
333 ret = put_user(child->ptrace_message, (unsigned int __user *) data);
334 goto out_tsk;
335 256
336 default: 257 default:
337 ret = ptrace_request(child, request, addr, data); 258 ret = compat_ptrace_request(child, request, addr, data);
338 goto out_tsk; 259 break;
339 } 260 }
340 261
341out_wake_notrap:
342 ptrace_disable(child);
343out_wake:
344 wake_up_process(child);
345 ret = 0;
346out_tsk:
347 DBG("arch_ptrace(%ld, %d, %lx, %lx) returning %ld\n",
348 request, pid, oaddr, odata, ret);
349 return ret; 262 return ret;
350} 263}
264#endif
265
351 266
352void syscall_trace(void) 267void syscall_trace(void)
353{ 268{