diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/s390/kernel/ptrace.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/s390/kernel/ptrace.c')
-rw-r--r-- | arch/s390/kernel/ptrace.c | 738 |
1 files changed, 738 insertions, 0 deletions
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c new file mode 100644 index 000000000000..647233c02fc8 --- /dev/null +++ b/arch/s390/kernel/ptrace.c | |||
@@ -0,0 +1,738 @@ | |||
1 | /* | ||
2 | * arch/s390/kernel/ptrace.c | ||
3 | * | ||
4 | * S390 version | ||
5 | * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation | ||
6 | * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com), | ||
7 | * Martin Schwidefsky (schwidefsky@de.ibm.com) | ||
8 | * | ||
9 | * Based on PowerPC version | ||
10 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | ||
11 | * | ||
12 | * Derived from "arch/m68k/kernel/ptrace.c" | ||
13 | * Copyright (C) 1994 by Hamish Macdonald | ||
14 | * Taken from linux/kernel/ptrace.c and modified for M680x0. | ||
15 | * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds | ||
16 | * | ||
17 | * Modified by Cort Dougan (cort@cs.nmt.edu) | ||
18 | * | ||
19 | * | ||
20 | * This file is subject to the terms and conditions of the GNU General | ||
21 | * Public License. See the file README.legal in the main directory of | ||
22 | * this archive for more details. | ||
23 | */ | ||
24 | |||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <linux/mm.h> | ||
28 | #include <linux/smp.h> | ||
29 | #include <linux/smp_lock.h> | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/ptrace.h> | ||
32 | #include <linux/user.h> | ||
33 | #include <linux/security.h> | ||
34 | #include <linux/audit.h> | ||
35 | |||
36 | #include <asm/segment.h> | ||
37 | #include <asm/page.h> | ||
38 | #include <asm/pgtable.h> | ||
39 | #include <asm/pgalloc.h> | ||
40 | #include <asm/system.h> | ||
41 | #include <asm/uaccess.h> | ||
42 | |||
43 | #ifdef CONFIG_S390_SUPPORT | ||
44 | #include "compat_ptrace.h" | ||
45 | #endif | ||
46 | |||
47 | static void | ||
48 | FixPerRegisters(struct task_struct *task) | ||
49 | { | ||
50 | struct pt_regs *regs; | ||
51 | per_struct *per_info; | ||
52 | |||
53 | regs = __KSTK_PTREGS(task); | ||
54 | per_info = (per_struct *) &task->thread.per_info; | ||
55 | per_info->control_regs.bits.em_instruction_fetch = | ||
56 | per_info->single_step | per_info->instruction_fetch; | ||
57 | |||
58 | if (per_info->single_step) { | ||
59 | per_info->control_regs.bits.starting_addr = 0; | ||
60 | #ifdef CONFIG_S390_SUPPORT | ||
61 | if (test_thread_flag(TIF_31BIT)) | ||
62 | per_info->control_regs.bits.ending_addr = 0x7fffffffUL; | ||
63 | else | ||
64 | #endif | ||
65 | per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN; | ||
66 | } else { | ||
67 | per_info->control_regs.bits.starting_addr = | ||
68 | per_info->starting_addr; | ||
69 | per_info->control_regs.bits.ending_addr = | ||
70 | per_info->ending_addr; | ||
71 | } | ||
72 | /* | ||
73 | * if any of the control reg tracing bits are on | ||
74 | * we switch on per in the psw | ||
75 | */ | ||
76 | if (per_info->control_regs.words.cr[0] & PER_EM_MASK) | ||
77 | regs->psw.mask |= PSW_MASK_PER; | ||
78 | else | ||
79 | regs->psw.mask &= ~PSW_MASK_PER; | ||
80 | |||
81 | if (per_info->control_regs.bits.em_storage_alteration) | ||
82 | per_info->control_regs.bits.storage_alt_space_ctl = 1; | ||
83 | else | ||
84 | per_info->control_regs.bits.storage_alt_space_ctl = 0; | ||
85 | } | ||
86 | |||
87 | void | ||
88 | set_single_step(struct task_struct *task) | ||
89 | { | ||
90 | task->thread.per_info.single_step = 1; | ||
91 | FixPerRegisters(task); | ||
92 | } | ||
93 | |||
94 | void | ||
95 | clear_single_step(struct task_struct *task) | ||
96 | { | ||
97 | task->thread.per_info.single_step = 0; | ||
98 | FixPerRegisters(task); | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * Called by kernel/ptrace.c when detaching.. | ||
103 | * | ||
104 | * Make sure single step bits etc are not set. | ||
105 | */ | ||
106 | void | ||
107 | ptrace_disable(struct task_struct *child) | ||
108 | { | ||
109 | /* make sure the single step bit is not set. */ | ||
110 | clear_single_step(child); | ||
111 | } | ||
112 | |||
113 | #ifndef CONFIG_ARCH_S390X | ||
114 | # define __ADDR_MASK 3 | ||
115 | #else | ||
116 | # define __ADDR_MASK 7 | ||
117 | #endif | ||
118 | |||
119 | /* | ||
120 | * Read the word at offset addr from the user area of a process. The | ||
121 | * trouble here is that the information is littered over different | ||
122 | * locations. The process registers are found on the kernel stack, | ||
123 | * the floating point stuff and the trace settings are stored in | ||
124 | * the task structure. In addition the different structures in | ||
125 | * struct user contain pad bytes that should be read as zeroes. | ||
126 | * Lovely... | ||
127 | */ | ||
128 | static int | ||
129 | peek_user(struct task_struct *child, addr_t addr, addr_t data) | ||
130 | { | ||
131 | struct user *dummy = NULL; | ||
132 | addr_t offset, tmp; | ||
133 | |||
134 | /* | ||
135 | * Stupid gdb peeks/pokes the access registers in 64 bit with | ||
136 | * an alignment of 4. Programmers from hell... | ||
137 | */ | ||
138 | if ((addr & 3) || addr > sizeof(struct user) - __ADDR_MASK) | ||
139 | return -EIO; | ||
140 | |||
141 | if (addr < (addr_t) &dummy->regs.acrs) { | ||
142 | /* | ||
143 | * psw and gprs are stored on the stack | ||
144 | */ | ||
145 | tmp = *(addr_t *)((addr_t) &__KSTK_PTREGS(child)->psw + addr); | ||
146 | if (addr == (addr_t) &dummy->regs.psw.mask) | ||
147 | /* Remove per bit from user psw. */ | ||
148 | tmp &= ~PSW_MASK_PER; | ||
149 | |||
150 | } else if (addr < (addr_t) &dummy->regs.orig_gpr2) { | ||
151 | /* | ||
152 | * access registers are stored in the thread structure | ||
153 | */ | ||
154 | offset = addr - (addr_t) &dummy->regs.acrs; | ||
155 | tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset); | ||
156 | |||
157 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | ||
158 | /* | ||
159 | * orig_gpr2 is stored on the kernel stack | ||
160 | */ | ||
161 | tmp = (addr_t) __KSTK_PTREGS(child)->orig_gpr2; | ||
162 | |||
163 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { | ||
164 | /* | ||
165 | * floating point regs. are stored in the thread structure | ||
166 | */ | ||
167 | offset = addr - (addr_t) &dummy->regs.fp_regs; | ||
168 | tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset); | ||
169 | |||
170 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | ||
171 | /* | ||
172 | * per_info is found in the thread structure | ||
173 | */ | ||
174 | offset = addr - (addr_t) &dummy->regs.per_info; | ||
175 | tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset); | ||
176 | |||
177 | } else | ||
178 | tmp = 0; | ||
179 | |||
180 | return put_user(tmp, (addr_t __user *) data); | ||
181 | } | ||
182 | |||
183 | /* | ||
184 | * Write a word to the user area of a process at location addr. This | ||
185 | * operation does have an additional problem compared to peek_user. | ||
186 | * Stores to the program status word and on the floating point | ||
187 | * control register needs to get checked for validity. | ||
188 | */ | ||
189 | static int | ||
190 | poke_user(struct task_struct *child, addr_t addr, addr_t data) | ||
191 | { | ||
192 | struct user *dummy = NULL; | ||
193 | addr_t offset; | ||
194 | |||
195 | /* | ||
196 | * Stupid gdb peeks/pokes the access registers in 64 bit with | ||
197 | * an alignment of 4. Programmers from hell indeed... | ||
198 | */ | ||
199 | if ((addr & 3) || addr > sizeof(struct user) - __ADDR_MASK) | ||
200 | return -EIO; | ||
201 | |||
202 | if (addr < (addr_t) &dummy->regs.acrs) { | ||
203 | /* | ||
204 | * psw and gprs are stored on the stack | ||
205 | */ | ||
206 | if (addr == (addr_t) &dummy->regs.psw.mask && | ||
207 | #ifdef CONFIG_S390_SUPPORT | ||
208 | data != PSW_MASK_MERGE(PSW_USER32_BITS, data) && | ||
209 | #endif | ||
210 | data != PSW_MASK_MERGE(PSW_USER_BITS, data)) | ||
211 | /* Invalid psw mask. */ | ||
212 | return -EINVAL; | ||
213 | #ifndef CONFIG_ARCH_S390X | ||
214 | if (addr == (addr_t) &dummy->regs.psw.addr) | ||
215 | /* I'd like to reject addresses without the | ||
216 | high order bit but older gdb's rely on it */ | ||
217 | data |= PSW_ADDR_AMODE; | ||
218 | #endif | ||
219 | *(addr_t *)((addr_t) &__KSTK_PTREGS(child)->psw + addr) = data; | ||
220 | |||
221 | } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { | ||
222 | /* | ||
223 | * access registers are stored in the thread structure | ||
224 | */ | ||
225 | offset = addr - (addr_t) &dummy->regs.acrs; | ||
226 | *(addr_t *)((addr_t) &child->thread.acrs + offset) = data; | ||
227 | |||
228 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | ||
229 | /* | ||
230 | * orig_gpr2 is stored on the kernel stack | ||
231 | */ | ||
232 | __KSTK_PTREGS(child)->orig_gpr2 = data; | ||
233 | |||
234 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { | ||
235 | /* | ||
236 | * floating point regs. are stored in the thread structure | ||
237 | */ | ||
238 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc && | ||
239 | (data & ~FPC_VALID_MASK) != 0) | ||
240 | return -EINVAL; | ||
241 | offset = addr - (addr_t) &dummy->regs.fp_regs; | ||
242 | *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data; | ||
243 | |||
244 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | ||
245 | /* | ||
246 | * per_info is found in the thread structure | ||
247 | */ | ||
248 | offset = addr - (addr_t) &dummy->regs.per_info; | ||
249 | *(addr_t *)((addr_t) &child->thread.per_info + offset) = data; | ||
250 | |||
251 | } | ||
252 | |||
253 | FixPerRegisters(child); | ||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static int | ||
258 | do_ptrace_normal(struct task_struct *child, long request, long addr, long data) | ||
259 | { | ||
260 | unsigned long tmp; | ||
261 | ptrace_area parea; | ||
262 | int copied, ret; | ||
263 | |||
264 | switch (request) { | ||
265 | case PTRACE_PEEKTEXT: | ||
266 | case PTRACE_PEEKDATA: | ||
267 | /* Remove high order bit from address (only for 31 bit). */ | ||
268 | addr &= PSW_ADDR_INSN; | ||
269 | /* read word at location addr. */ | ||
270 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); | ||
271 | if (copied != sizeof(tmp)) | ||
272 | return -EIO; | ||
273 | return put_user(tmp, (unsigned long __user *) data); | ||
274 | |||
275 | case PTRACE_PEEKUSR: | ||
276 | /* read the word at location addr in the USER area. */ | ||
277 | return peek_user(child, addr, data); | ||
278 | |||
279 | case PTRACE_POKETEXT: | ||
280 | case PTRACE_POKEDATA: | ||
281 | /* Remove high order bit from address (only for 31 bit). */ | ||
282 | addr &= PSW_ADDR_INSN; | ||
283 | /* write the word at location addr. */ | ||
284 | copied = access_process_vm(child, addr, &data, sizeof(data),1); | ||
285 | if (copied != sizeof(data)) | ||
286 | return -EIO; | ||
287 | return 0; | ||
288 | |||
289 | case PTRACE_POKEUSR: | ||
290 | /* write the word at location addr in the USER area */ | ||
291 | return poke_user(child, addr, data); | ||
292 | |||
293 | case PTRACE_PEEKUSR_AREA: | ||
294 | case PTRACE_POKEUSR_AREA: | ||
295 | if (copy_from_user(&parea, (void __user *) addr, | ||
296 | sizeof(parea))) | ||
297 | return -EFAULT; | ||
298 | addr = parea.kernel_addr; | ||
299 | data = parea.process_addr; | ||
300 | copied = 0; | ||
301 | while (copied < parea.len) { | ||
302 | if (request == PTRACE_PEEKUSR_AREA) | ||
303 | ret = peek_user(child, addr, data); | ||
304 | else { | ||
305 | addr_t tmp; | ||
306 | if (get_user (tmp, (addr_t __user *) data)) | ||
307 | return -EFAULT; | ||
308 | ret = poke_user(child, addr, tmp); | ||
309 | } | ||
310 | if (ret) | ||
311 | return ret; | ||
312 | addr += sizeof(unsigned long); | ||
313 | data += sizeof(unsigned long); | ||
314 | copied += sizeof(unsigned long); | ||
315 | } | ||
316 | return 0; | ||
317 | } | ||
318 | return ptrace_request(child, request, addr, data); | ||
319 | } | ||
320 | |||
321 | #ifdef CONFIG_S390_SUPPORT | ||
322 | /* | ||
323 | * Now the fun part starts... a 31 bit program running in the | ||
324 | * 31 bit emulation tracing another program. PTRACE_PEEKTEXT, | ||
325 | * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy | ||
326 | * to handle, the difference to the 64 bit versions of the requests | ||
327 | * is that the access is done in multiples of 4 byte instead of | ||
328 | * 8 bytes (sizeof(unsigned long) on 31/64 bit). | ||
329 | * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA, | ||
330 | * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program | ||
331 | * is a 31 bit program too, the content of struct user can be | ||
332 | * emulated. A 31 bit program peeking into the struct user of | ||
333 | * a 64 bit program is a no-no. | ||
334 | */ | ||
335 | |||
336 | /* | ||
337 | * Same as peek_user but for a 31 bit program. | ||
338 | */ | ||
339 | static int | ||
340 | peek_user_emu31(struct task_struct *child, addr_t addr, addr_t data) | ||
341 | { | ||
342 | struct user32 *dummy32 = NULL; | ||
343 | per_struct32 *dummy_per32 = NULL; | ||
344 | addr_t offset; | ||
345 | __u32 tmp; | ||
346 | |||
347 | if (!test_thread_flag(TIF_31BIT) || | ||
348 | (addr & 3) || addr > sizeof(struct user) - 3) | ||
349 | return -EIO; | ||
350 | |||
351 | if (addr < (addr_t) &dummy32->regs.acrs) { | ||
352 | /* | ||
353 | * psw and gprs are stored on the stack | ||
354 | */ | ||
355 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | ||
356 | /* Fake a 31 bit psw mask. */ | ||
357 | tmp = (__u32)(__KSTK_PTREGS(child)->psw.mask >> 32); | ||
358 | tmp = PSW32_MASK_MERGE(PSW32_USER_BITS, tmp); | ||
359 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { | ||
360 | /* Fake a 31 bit psw address. */ | ||
361 | tmp = (__u32) __KSTK_PTREGS(child)->psw.addr | | ||
362 | PSW32_ADDR_AMODE31; | ||
363 | } else { | ||
364 | /* gpr 0-15 */ | ||
365 | tmp = *(__u32 *)((addr_t) &__KSTK_PTREGS(child)->psw + | ||
366 | addr*2 + 4); | ||
367 | } | ||
368 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | ||
369 | /* | ||
370 | * access registers are stored in the thread structure | ||
371 | */ | ||
372 | offset = addr - (addr_t) &dummy32->regs.acrs; | ||
373 | tmp = *(__u32*)((addr_t) &child->thread.acrs + offset); | ||
374 | |||
375 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | ||
376 | /* | ||
377 | * orig_gpr2 is stored on the kernel stack | ||
378 | */ | ||
379 | tmp = *(__u32*)((addr_t) &__KSTK_PTREGS(child)->orig_gpr2 + 4); | ||
380 | |||
381 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { | ||
382 | /* | ||
383 | * floating point regs. are stored in the thread structure | ||
384 | */ | ||
385 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | ||
386 | tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset); | ||
387 | |||
388 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | ||
389 | /* | ||
390 | * per_info is found in the thread structure | ||
391 | */ | ||
392 | offset = addr - (addr_t) &dummy32->regs.per_info; | ||
393 | /* This is magic. See per_struct and per_struct32. */ | ||
394 | if ((offset >= (addr_t) &dummy_per32->control_regs && | ||
395 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || | ||
396 | (offset >= (addr_t) &dummy_per32->starting_addr && | ||
397 | offset <= (addr_t) &dummy_per32->ending_addr) || | ||
398 | offset == (addr_t) &dummy_per32->lowcore.words.address) | ||
399 | offset = offset*2 + 4; | ||
400 | else | ||
401 | offset = offset*2; | ||
402 | tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset); | ||
403 | |||
404 | } else | ||
405 | tmp = 0; | ||
406 | |||
407 | return put_user(tmp, (__u32 __user *) data); | ||
408 | } | ||
409 | |||
410 | /* | ||
411 | * Same as poke_user but for a 31 bit program. | ||
412 | */ | ||
413 | static int | ||
414 | poke_user_emu31(struct task_struct *child, addr_t addr, addr_t data) | ||
415 | { | ||
416 | struct user32 *dummy32 = NULL; | ||
417 | per_struct32 *dummy_per32 = NULL; | ||
418 | addr_t offset; | ||
419 | __u32 tmp; | ||
420 | |||
421 | if (!test_thread_flag(TIF_31BIT) || | ||
422 | (addr & 3) || addr > sizeof(struct user32) - 3) | ||
423 | return -EIO; | ||
424 | |||
425 | tmp = (__u32) data; | ||
426 | |||
427 | if (addr < (addr_t) &dummy32->regs.acrs) { | ||
428 | /* | ||
429 | * psw, gprs, acrs and orig_gpr2 are stored on the stack | ||
430 | */ | ||
431 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | ||
432 | /* Build a 64 bit psw mask from 31 bit mask. */ | ||
433 | if (tmp != PSW32_MASK_MERGE(PSW32_USER_BITS, tmp)) | ||
434 | /* Invalid psw mask. */ | ||
435 | return -EINVAL; | ||
436 | __KSTK_PTREGS(child)->psw.mask = | ||
437 | PSW_MASK_MERGE(PSW_USER32_BITS, (__u64) tmp << 32); | ||
438 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { | ||
439 | /* Build a 64 bit psw address from 31 bit address. */ | ||
440 | __KSTK_PTREGS(child)->psw.addr = | ||
441 | (__u64) tmp & PSW32_ADDR_INSN; | ||
442 | } else { | ||
443 | /* gpr 0-15 */ | ||
444 | *(__u32*)((addr_t) &__KSTK_PTREGS(child)->psw | ||
445 | + addr*2 + 4) = tmp; | ||
446 | } | ||
447 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | ||
448 | /* | ||
449 | * access registers are stored in the thread structure | ||
450 | */ | ||
451 | offset = addr - (addr_t) &dummy32->regs.acrs; | ||
452 | *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp; | ||
453 | |||
454 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | ||
455 | /* | ||
456 | * orig_gpr2 is stored on the kernel stack | ||
457 | */ | ||
458 | *(__u32*)((addr_t) &__KSTK_PTREGS(child)->orig_gpr2 + 4) = tmp; | ||
459 | |||
460 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { | ||
461 | /* | ||
462 | * floating point regs. are stored in the thread structure | ||
463 | */ | ||
464 | if (addr == (addr_t) &dummy32->regs.fp_regs.fpc && | ||
465 | (tmp & ~FPC_VALID_MASK) != 0) | ||
466 | /* Invalid floating point control. */ | ||
467 | return -EINVAL; | ||
468 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | ||
469 | *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp; | ||
470 | |||
471 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | ||
472 | /* | ||
473 | * per_info is found in the thread structure. | ||
474 | */ | ||
475 | offset = addr - (addr_t) &dummy32->regs.per_info; | ||
476 | /* | ||
477 | * This is magic. See per_struct and per_struct32. | ||
478 | * By incident the offsets in per_struct are exactly | ||
479 | * twice the offsets in per_struct32 for all fields. | ||
480 | * The 8 byte fields need special handling though, | ||
481 | * because the second half (bytes 4-7) is needed and | ||
482 | * not the first half. | ||
483 | */ | ||
484 | if ((offset >= (addr_t) &dummy_per32->control_regs && | ||
485 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || | ||
486 | (offset >= (addr_t) &dummy_per32->starting_addr && | ||
487 | offset <= (addr_t) &dummy_per32->ending_addr) || | ||
488 | offset == (addr_t) &dummy_per32->lowcore.words.address) | ||
489 | offset = offset*2 + 4; | ||
490 | else | ||
491 | offset = offset*2; | ||
492 | *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp; | ||
493 | |||
494 | } | ||
495 | |||
496 | FixPerRegisters(child); | ||
497 | return 0; | ||
498 | } | ||
499 | |||
500 | static int | ||
501 | do_ptrace_emu31(struct task_struct *child, long request, long addr, long data) | ||
502 | { | ||
503 | unsigned int tmp; /* 4 bytes !! */ | ||
504 | ptrace_area_emu31 parea; | ||
505 | int copied, ret; | ||
506 | |||
507 | switch (request) { | ||
508 | case PTRACE_PEEKTEXT: | ||
509 | case PTRACE_PEEKDATA: | ||
510 | /* read word at location addr. */ | ||
511 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); | ||
512 | if (copied != sizeof(tmp)) | ||
513 | return -EIO; | ||
514 | return put_user(tmp, (unsigned int __user *) data); | ||
515 | |||
516 | case PTRACE_PEEKUSR: | ||
517 | /* read the word at location addr in the USER area. */ | ||
518 | return peek_user_emu31(child, addr, data); | ||
519 | |||
520 | case PTRACE_POKETEXT: | ||
521 | case PTRACE_POKEDATA: | ||
522 | /* write the word at location addr. */ | ||
523 | tmp = data; | ||
524 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 1); | ||
525 | if (copied != sizeof(tmp)) | ||
526 | return -EIO; | ||
527 | return 0; | ||
528 | |||
529 | case PTRACE_POKEUSR: | ||
530 | /* write the word at location addr in the USER area */ | ||
531 | return poke_user_emu31(child, addr, data); | ||
532 | |||
533 | case PTRACE_PEEKUSR_AREA: | ||
534 | case PTRACE_POKEUSR_AREA: | ||
535 | if (copy_from_user(&parea, (void __user *) addr, | ||
536 | sizeof(parea))) | ||
537 | return -EFAULT; | ||
538 | addr = parea.kernel_addr; | ||
539 | data = parea.process_addr; | ||
540 | copied = 0; | ||
541 | while (copied < parea.len) { | ||
542 | if (request == PTRACE_PEEKUSR_AREA) | ||
543 | ret = peek_user_emu31(child, addr, data); | ||
544 | else { | ||
545 | __u32 tmp; | ||
546 | if (get_user (tmp, (__u32 __user *) data)) | ||
547 | return -EFAULT; | ||
548 | ret = poke_user_emu31(child, addr, tmp); | ||
549 | } | ||
550 | if (ret) | ||
551 | return ret; | ||
552 | addr += sizeof(unsigned int); | ||
553 | data += sizeof(unsigned int); | ||
554 | copied += sizeof(unsigned int); | ||
555 | } | ||
556 | return 0; | ||
557 | case PTRACE_GETEVENTMSG: | ||
558 | return put_user((__u32) child->ptrace_message, | ||
559 | (unsigned int __user *) data); | ||
560 | case PTRACE_GETSIGINFO: | ||
561 | if (child->last_siginfo == NULL) | ||
562 | return -EINVAL; | ||
563 | return copy_siginfo_to_user32((compat_siginfo_t __user *) data, | ||
564 | child->last_siginfo); | ||
565 | case PTRACE_SETSIGINFO: | ||
566 | if (child->last_siginfo == NULL) | ||
567 | return -EINVAL; | ||
568 | return copy_siginfo_from_user32(child->last_siginfo, | ||
569 | (compat_siginfo_t __user *) data); | ||
570 | } | ||
571 | return ptrace_request(child, request, addr, data); | ||
572 | } | ||
573 | #endif | ||
574 | |||
575 | #define PT32_IEEE_IP 0x13c | ||
576 | |||
577 | static int | ||
578 | do_ptrace(struct task_struct *child, long request, long addr, long data) | ||
579 | { | ||
580 | int ret; | ||
581 | |||
582 | if (request == PTRACE_ATTACH) | ||
583 | return ptrace_attach(child); | ||
584 | |||
585 | /* | ||
586 | * Special cases to get/store the ieee instructions pointer. | ||
587 | */ | ||
588 | if (child == current) { | ||
589 | if (request == PTRACE_PEEKUSR && addr == PT_IEEE_IP) | ||
590 | return peek_user(child, addr, data); | ||
591 | if (request == PTRACE_POKEUSR && addr == PT_IEEE_IP) | ||
592 | return poke_user(child, addr, data); | ||
593 | #ifdef CONFIG_S390_SUPPORT | ||
594 | if (request == PTRACE_PEEKUSR && | ||
595 | addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT)) | ||
596 | return peek_user_emu31(child, addr, data); | ||
597 | if (request == PTRACE_POKEUSR && | ||
598 | addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT)) | ||
599 | return poke_user_emu31(child, addr, data); | ||
600 | #endif | ||
601 | } | ||
602 | |||
603 | ret = ptrace_check_attach(child, request == PTRACE_KILL); | ||
604 | if (ret < 0) | ||
605 | return ret; | ||
606 | |||
607 | switch (request) { | ||
608 | case PTRACE_SYSCALL: | ||
609 | /* continue and stop at next (return from) syscall */ | ||
610 | case PTRACE_CONT: | ||
611 | /* restart after signal. */ | ||
612 | if ((unsigned long) data >= _NSIG) | ||
613 | return -EIO; | ||
614 | if (request == PTRACE_SYSCALL) | ||
615 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
616 | else | ||
617 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
618 | child->exit_code = data; | ||
619 | /* make sure the single step bit is not set. */ | ||
620 | clear_single_step(child); | ||
621 | wake_up_process(child); | ||
622 | return 0; | ||
623 | |||
624 | case PTRACE_KILL: | ||
625 | /* | ||
626 | * make the child exit. Best I can do is send it a sigkill. | ||
627 | * perhaps it should be put in the status that it wants to | ||
628 | * exit. | ||
629 | */ | ||
630 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ | ||
631 | return 0; | ||
632 | child->exit_code = SIGKILL; | ||
633 | /* make sure the single step bit is not set. */ | ||
634 | clear_single_step(child); | ||
635 | wake_up_process(child); | ||
636 | return 0; | ||
637 | |||
638 | case PTRACE_SINGLESTEP: | ||
639 | /* set the trap flag. */ | ||
640 | if ((unsigned long) data >= _NSIG) | ||
641 | return -EIO; | ||
642 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | ||
643 | child->exit_code = data; | ||
644 | if (data) | ||
645 | set_tsk_thread_flag(child, TIF_SINGLE_STEP); | ||
646 | else | ||
647 | set_single_step(child); | ||
648 | /* give it a chance to run. */ | ||
649 | wake_up_process(child); | ||
650 | return 0; | ||
651 | |||
652 | case PTRACE_DETACH: | ||
653 | /* detach a process that was attached. */ | ||
654 | return ptrace_detach(child, data); | ||
655 | |||
656 | |||
657 | /* Do requests that differ for 31/64 bit */ | ||
658 | default: | ||
659 | #ifdef CONFIG_S390_SUPPORT | ||
660 | if (test_thread_flag(TIF_31BIT)) | ||
661 | return do_ptrace_emu31(child, request, addr, data); | ||
662 | #endif | ||
663 | return do_ptrace_normal(child, request, addr, data); | ||
664 | } | ||
665 | /* Not reached. */ | ||
666 | return -EIO; | ||
667 | } | ||
668 | |||
669 | asmlinkage long | ||
670 | sys_ptrace(long request, long pid, long addr, long data) | ||
671 | { | ||
672 | struct task_struct *child; | ||
673 | int ret; | ||
674 | |||
675 | lock_kernel(); | ||
676 | |||
677 | if (request == PTRACE_TRACEME) { | ||
678 | /* are we already being traced? */ | ||
679 | ret = -EPERM; | ||
680 | if (current->ptrace & PT_PTRACED) | ||
681 | goto out; | ||
682 | ret = security_ptrace(current->parent, current); | ||
683 | if (ret) | ||
684 | goto out; | ||
685 | /* set the ptrace bit in the process flags. */ | ||
686 | current->ptrace |= PT_PTRACED; | ||
687 | goto out; | ||
688 | } | ||
689 | |||
690 | ret = -EPERM; | ||
691 | if (pid == 1) /* you may not mess with init */ | ||
692 | goto out; | ||
693 | |||
694 | ret = -ESRCH; | ||
695 | read_lock(&tasklist_lock); | ||
696 | child = find_task_by_pid(pid); | ||
697 | if (child) | ||
698 | get_task_struct(child); | ||
699 | read_unlock(&tasklist_lock); | ||
700 | if (!child) | ||
701 | goto out; | ||
702 | |||
703 | ret = do_ptrace(child, request, addr, data); | ||
704 | |||
705 | put_task_struct(child); | ||
706 | out: | ||
707 | unlock_kernel(); | ||
708 | return ret; | ||
709 | } | ||
710 | |||
711 | asmlinkage void | ||
712 | syscall_trace(struct pt_regs *regs, int entryexit) | ||
713 | { | ||
714 | if (unlikely(current->audit_context)) { | ||
715 | if (!entryexit) | ||
716 | audit_syscall_entry(current, regs->gprs[2], | ||
717 | regs->orig_gpr2, regs->gprs[3], | ||
718 | regs->gprs[4], regs->gprs[5]); | ||
719 | else | ||
720 | audit_syscall_exit(current, regs->gprs[2]); | ||
721 | } | ||
722 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) | ||
723 | return; | ||
724 | if (!(current->ptrace & PT_PTRACED)) | ||
725 | return; | ||
726 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) | ||
727 | ? 0x80 : 0)); | ||
728 | |||
729 | /* | ||
730 | * this isn't the same as continuing with a signal, but it will do | ||
731 | * for normal use. strace only continues with a signal if the | ||
732 | * stopping signal is not SIGTRAP. -brl | ||
733 | */ | ||
734 | if (current->exit_code) { | ||
735 | send_sig(current->exit_code, current, 1); | ||
736 | current->exit_code = 0; | ||
737 | } | ||
738 | } | ||