Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
7ed20e1a | 35 | #include <linux/signal.h> |
1da177e4 LT |
36 | |
37 | #include <asm/segment.h> | |
38 | #include <asm/page.h> | |
39 | #include <asm/pgtable.h> | |
40 | #include <asm/pgalloc.h> | |
41 | #include <asm/system.h> | |
42 | #include <asm/uaccess.h> | |
778959db | 43 | #include <asm/unistd.h> |
1da177e4 | 44 | |
347a8dc3 | 45 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
46 | #include "compat_ptrace.h" |
47 | #endif | |
48 | ||
49 | static void | |
50 | FixPerRegisters(struct task_struct *task) | |
51 | { | |
52 | struct pt_regs *regs; | |
53 | per_struct *per_info; | |
54 | ||
c7584fb6 | 55 | regs = task_pt_regs(task); |
1da177e4 LT |
56 | per_info = (per_struct *) &task->thread.per_info; |
57 | per_info->control_regs.bits.em_instruction_fetch = | |
58 | per_info->single_step | per_info->instruction_fetch; | |
59 | ||
60 | if (per_info->single_step) { | |
61 | per_info->control_regs.bits.starting_addr = 0; | |
347a8dc3 | 62 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
63 | if (test_thread_flag(TIF_31BIT)) |
64 | per_info->control_regs.bits.ending_addr = 0x7fffffffUL; | |
65 | else | |
66 | #endif | |
67 | per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN; | |
68 | } else { | |
69 | per_info->control_regs.bits.starting_addr = | |
70 | per_info->starting_addr; | |
71 | per_info->control_regs.bits.ending_addr = | |
72 | per_info->ending_addr; | |
73 | } | |
74 | /* | |
75 | * if any of the control reg tracing bits are on | |
76 | * we switch on per in the psw | |
77 | */ | |
78 | if (per_info->control_regs.words.cr[0] & PER_EM_MASK) | |
79 | regs->psw.mask |= PSW_MASK_PER; | |
80 | else | |
81 | regs->psw.mask &= ~PSW_MASK_PER; | |
82 | ||
83 | if (per_info->control_regs.bits.em_storage_alteration) | |
84 | per_info->control_regs.bits.storage_alt_space_ctl = 1; | |
85 | else | |
86 | per_info->control_regs.bits.storage_alt_space_ctl = 0; | |
87 | } | |
88 | ||
2b67fc46 | 89 | static void set_single_step(struct task_struct *task) |
1da177e4 LT |
90 | { |
91 | task->thread.per_info.single_step = 1; | |
92 | FixPerRegisters(task); | |
93 | } | |
94 | ||
2b67fc46 | 95 | static void clear_single_step(struct task_struct *task) |
1da177e4 LT |
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 | ||
347a8dc3 | 113 | #ifndef CONFIG_64BIT |
1da177e4 LT |
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; | |
778959db | 132 | addr_t offset, tmp, mask; |
1da177e4 LT |
133 | |
134 | /* | |
135 | * Stupid gdb peeks/pokes the access registers in 64 bit with | |
136 | * an alignment of 4. Programmers from hell... | |
137 | */ | |
778959db | 138 | mask = __ADDR_MASK; |
347a8dc3 | 139 | #ifdef CONFIG_64BIT |
778959db MS |
140 | if (addr >= (addr_t) &dummy->regs.acrs && |
141 | addr < (addr_t) &dummy->regs.orig_gpr2) | |
142 | mask = 3; | |
143 | #endif | |
144 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) | |
1da177e4 LT |
145 | return -EIO; |
146 | ||
147 | if (addr < (addr_t) &dummy->regs.acrs) { | |
148 | /* | |
149 | * psw and gprs are stored on the stack | |
150 | */ | |
c7584fb6 | 151 | tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr); |
1da177e4 LT |
152 | if (addr == (addr_t) &dummy->regs.psw.mask) |
153 | /* Remove per bit from user psw. */ | |
154 | tmp &= ~PSW_MASK_PER; | |
155 | ||
156 | } else if (addr < (addr_t) &dummy->regs.orig_gpr2) { | |
157 | /* | |
158 | * access registers are stored in the thread structure | |
159 | */ | |
160 | offset = addr - (addr_t) &dummy->regs.acrs; | |
347a8dc3 | 161 | #ifdef CONFIG_64BIT |
778959db MS |
162 | /* |
163 | * Very special case: old & broken 64 bit gdb reading | |
164 | * from acrs[15]. Result is a 64 bit value. Read the | |
165 | * 32 bit acrs[15] value and shift it by 32. Sick... | |
166 | */ | |
167 | if (addr == (addr_t) &dummy->regs.acrs[15]) | |
168 | tmp = ((unsigned long) child->thread.acrs[15]) << 32; | |
169 | else | |
170 | #endif | |
1da177e4 LT |
171 | tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset); |
172 | ||
173 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | |
174 | /* | |
175 | * orig_gpr2 is stored on the kernel stack | |
176 | */ | |
c7584fb6 | 177 | tmp = (addr_t) task_pt_regs(child)->orig_gpr2; |
1da177e4 LT |
178 | |
179 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { | |
180 | /* | |
181 | * floating point regs. are stored in the thread structure | |
182 | */ | |
183 | offset = addr - (addr_t) &dummy->regs.fp_regs; | |
184 | tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset); | |
778959db MS |
185 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
186 | tmp &= (unsigned long) FPC_VALID_MASK | |
187 | << (BITS_PER_LONG - 32); | |
1da177e4 LT |
188 | |
189 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | |
190 | /* | |
191 | * per_info is found in the thread structure | |
192 | */ | |
193 | offset = addr - (addr_t) &dummy->regs.per_info; | |
194 | tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset); | |
195 | ||
196 | } else | |
197 | tmp = 0; | |
198 | ||
199 | return put_user(tmp, (addr_t __user *) data); | |
200 | } | |
201 | ||
202 | /* | |
203 | * Write a word to the user area of a process at location addr. This | |
204 | * operation does have an additional problem compared to peek_user. | |
205 | * Stores to the program status word and on the floating point | |
206 | * control register needs to get checked for validity. | |
207 | */ | |
208 | static int | |
209 | poke_user(struct task_struct *child, addr_t addr, addr_t data) | |
210 | { | |
211 | struct user *dummy = NULL; | |
778959db | 212 | addr_t offset, mask; |
1da177e4 LT |
213 | |
214 | /* | |
215 | * Stupid gdb peeks/pokes the access registers in 64 bit with | |
216 | * an alignment of 4. Programmers from hell indeed... | |
217 | */ | |
778959db | 218 | mask = __ADDR_MASK; |
347a8dc3 | 219 | #ifdef CONFIG_64BIT |
778959db MS |
220 | if (addr >= (addr_t) &dummy->regs.acrs && |
221 | addr < (addr_t) &dummy->regs.orig_gpr2) | |
222 | mask = 3; | |
223 | #endif | |
224 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) | |
1da177e4 LT |
225 | return -EIO; |
226 | ||
227 | if (addr < (addr_t) &dummy->regs.acrs) { | |
228 | /* | |
229 | * psw and gprs are stored on the stack | |
230 | */ | |
231 | if (addr == (addr_t) &dummy->regs.psw.mask && | |
347a8dc3 | 232 | #ifdef CONFIG_COMPAT |
c1821c2e | 233 | data != PSW_MASK_MERGE(psw_user32_bits, data) && |
1da177e4 | 234 | #endif |
c1821c2e | 235 | data != PSW_MASK_MERGE(psw_user_bits, data)) |
1da177e4 LT |
236 | /* Invalid psw mask. */ |
237 | return -EINVAL; | |
347a8dc3 | 238 | #ifndef CONFIG_64BIT |
1da177e4 LT |
239 | if (addr == (addr_t) &dummy->regs.psw.addr) |
240 | /* I'd like to reject addresses without the | |
241 | high order bit but older gdb's rely on it */ | |
242 | data |= PSW_ADDR_AMODE; | |
243 | #endif | |
c7584fb6 | 244 | *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; |
1da177e4 LT |
245 | |
246 | } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { | |
247 | /* | |
248 | * access registers are stored in the thread structure | |
249 | */ | |
250 | offset = addr - (addr_t) &dummy->regs.acrs; | |
347a8dc3 | 251 | #ifdef CONFIG_64BIT |
778959db MS |
252 | /* |
253 | * Very special case: old & broken 64 bit gdb writing | |
254 | * to acrs[15] with a 64 bit value. Ignore the lower | |
255 | * half of the value and write the upper 32 bit to | |
256 | * acrs[15]. Sick... | |
257 | */ | |
258 | if (addr == (addr_t) &dummy->regs.acrs[15]) | |
259 | child->thread.acrs[15] = (unsigned int) (data >> 32); | |
260 | else | |
261 | #endif | |
1da177e4 LT |
262 | *(addr_t *)((addr_t) &child->thread.acrs + offset) = data; |
263 | ||
264 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | |
265 | /* | |
266 | * orig_gpr2 is stored on the kernel stack | |
267 | */ | |
c7584fb6 | 268 | task_pt_regs(child)->orig_gpr2 = data; |
1da177e4 LT |
269 | |
270 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { | |
271 | /* | |
272 | * floating point regs. are stored in the thread structure | |
273 | */ | |
274 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc && | |
778959db MS |
275 | (data & ~((unsigned long) FPC_VALID_MASK |
276 | << (BITS_PER_LONG - 32))) != 0) | |
1da177e4 LT |
277 | return -EINVAL; |
278 | offset = addr - (addr_t) &dummy->regs.fp_regs; | |
279 | *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data; | |
280 | ||
281 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | |
282 | /* | |
283 | * per_info is found in the thread structure | |
284 | */ | |
285 | offset = addr - (addr_t) &dummy->regs.per_info; | |
286 | *(addr_t *)((addr_t) &child->thread.per_info + offset) = data; | |
287 | ||
288 | } | |
289 | ||
290 | FixPerRegisters(child); | |
291 | return 0; | |
292 | } | |
293 | ||
294 | static int | |
295 | do_ptrace_normal(struct task_struct *child, long request, long addr, long data) | |
296 | { | |
1da177e4 LT |
297 | ptrace_area parea; |
298 | int copied, ret; | |
299 | ||
300 | switch (request) { | |
301 | case PTRACE_PEEKTEXT: | |
302 | case PTRACE_PEEKDATA: | |
303 | /* Remove high order bit from address (only for 31 bit). */ | |
304 | addr &= PSW_ADDR_INSN; | |
305 | /* read word at location addr. */ | |
76647323 | 306 | return generic_ptrace_peekdata(child, addr, data); |
1da177e4 LT |
307 | |
308 | case PTRACE_PEEKUSR: | |
309 | /* read the word at location addr in the USER area. */ | |
310 | return peek_user(child, addr, data); | |
311 | ||
312 | case PTRACE_POKETEXT: | |
313 | case PTRACE_POKEDATA: | |
314 | /* Remove high order bit from address (only for 31 bit). */ | |
315 | addr &= PSW_ADDR_INSN; | |
316 | /* write the word at location addr. */ | |
317 | copied = access_process_vm(child, addr, &data, sizeof(data),1); | |
318 | if (copied != sizeof(data)) | |
319 | return -EIO; | |
320 | return 0; | |
321 | ||
322 | case PTRACE_POKEUSR: | |
323 | /* write the word at location addr in the USER area */ | |
324 | return poke_user(child, addr, data); | |
325 | ||
326 | case PTRACE_PEEKUSR_AREA: | |
327 | case PTRACE_POKEUSR_AREA: | |
2b67fc46 | 328 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
329 | sizeof(parea))) |
330 | return -EFAULT; | |
331 | addr = parea.kernel_addr; | |
332 | data = parea.process_addr; | |
333 | copied = 0; | |
334 | while (copied < parea.len) { | |
335 | if (request == PTRACE_PEEKUSR_AREA) | |
336 | ret = peek_user(child, addr, data); | |
337 | else { | |
2b67fc46 HC |
338 | addr_t utmp; |
339 | if (get_user(utmp, | |
340 | (addr_t __force __user *) data)) | |
1da177e4 | 341 | return -EFAULT; |
2b67fc46 | 342 | ret = poke_user(child, addr, utmp); |
1da177e4 LT |
343 | } |
344 | if (ret) | |
345 | return ret; | |
346 | addr += sizeof(unsigned long); | |
347 | data += sizeof(unsigned long); | |
348 | copied += sizeof(unsigned long); | |
349 | } | |
350 | return 0; | |
351 | } | |
352 | return ptrace_request(child, request, addr, data); | |
353 | } | |
354 | ||
347a8dc3 | 355 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
356 | /* |
357 | * Now the fun part starts... a 31 bit program running in the | |
358 | * 31 bit emulation tracing another program. PTRACE_PEEKTEXT, | |
359 | * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy | |
360 | * to handle, the difference to the 64 bit versions of the requests | |
361 | * is that the access is done in multiples of 4 byte instead of | |
362 | * 8 bytes (sizeof(unsigned long) on 31/64 bit). | |
363 | * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA, | |
364 | * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program | |
365 | * is a 31 bit program too, the content of struct user can be | |
366 | * emulated. A 31 bit program peeking into the struct user of | |
367 | * a 64 bit program is a no-no. | |
368 | */ | |
369 | ||
370 | /* | |
371 | * Same as peek_user but for a 31 bit program. | |
372 | */ | |
373 | static int | |
374 | peek_user_emu31(struct task_struct *child, addr_t addr, addr_t data) | |
375 | { | |
376 | struct user32 *dummy32 = NULL; | |
377 | per_struct32 *dummy_per32 = NULL; | |
378 | addr_t offset; | |
379 | __u32 tmp; | |
380 | ||
381 | if (!test_thread_flag(TIF_31BIT) || | |
382 | (addr & 3) || addr > sizeof(struct user) - 3) | |
383 | return -EIO; | |
384 | ||
385 | if (addr < (addr_t) &dummy32->regs.acrs) { | |
386 | /* | |
387 | * psw and gprs are stored on the stack | |
388 | */ | |
389 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | |
390 | /* Fake a 31 bit psw mask. */ | |
c7584fb6 | 391 | tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32); |
c1821c2e | 392 | tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp); |
1da177e4 LT |
393 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
394 | /* Fake a 31 bit psw address. */ | |
c7584fb6 | 395 | tmp = (__u32) task_pt_regs(child)->psw.addr | |
1da177e4 LT |
396 | PSW32_ADDR_AMODE31; |
397 | } else { | |
398 | /* gpr 0-15 */ | |
c7584fb6 | 399 | tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw + |
1da177e4 LT |
400 | addr*2 + 4); |
401 | } | |
402 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | |
403 | /* | |
404 | * access registers are stored in the thread structure | |
405 | */ | |
406 | offset = addr - (addr_t) &dummy32->regs.acrs; | |
407 | tmp = *(__u32*)((addr_t) &child->thread.acrs + offset); | |
408 | ||
409 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | |
410 | /* | |
411 | * orig_gpr2 is stored on the kernel stack | |
412 | */ | |
c7584fb6 | 413 | tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4); |
1da177e4 LT |
414 | |
415 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { | |
416 | /* | |
417 | * floating point regs. are stored in the thread structure | |
418 | */ | |
419 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | |
420 | tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset); | |
421 | ||
422 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | |
423 | /* | |
424 | * per_info is found in the thread structure | |
425 | */ | |
426 | offset = addr - (addr_t) &dummy32->regs.per_info; | |
427 | /* This is magic. See per_struct and per_struct32. */ | |
428 | if ((offset >= (addr_t) &dummy_per32->control_regs && | |
429 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || | |
430 | (offset >= (addr_t) &dummy_per32->starting_addr && | |
431 | offset <= (addr_t) &dummy_per32->ending_addr) || | |
432 | offset == (addr_t) &dummy_per32->lowcore.words.address) | |
433 | offset = offset*2 + 4; | |
434 | else | |
435 | offset = offset*2; | |
436 | tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset); | |
437 | ||
438 | } else | |
439 | tmp = 0; | |
440 | ||
441 | return put_user(tmp, (__u32 __user *) data); | |
442 | } | |
443 | ||
444 | /* | |
445 | * Same as poke_user but for a 31 bit program. | |
446 | */ | |
447 | static int | |
448 | poke_user_emu31(struct task_struct *child, addr_t addr, addr_t data) | |
449 | { | |
450 | struct user32 *dummy32 = NULL; | |
451 | per_struct32 *dummy_per32 = NULL; | |
452 | addr_t offset; | |
453 | __u32 tmp; | |
454 | ||
455 | if (!test_thread_flag(TIF_31BIT) || | |
456 | (addr & 3) || addr > sizeof(struct user32) - 3) | |
457 | return -EIO; | |
458 | ||
459 | tmp = (__u32) data; | |
460 | ||
461 | if (addr < (addr_t) &dummy32->regs.acrs) { | |
462 | /* | |
463 | * psw, gprs, acrs and orig_gpr2 are stored on the stack | |
464 | */ | |
465 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | |
466 | /* Build a 64 bit psw mask from 31 bit mask. */ | |
c1821c2e | 467 | if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp)) |
1da177e4 LT |
468 | /* Invalid psw mask. */ |
469 | return -EINVAL; | |
c7584fb6 | 470 | task_pt_regs(child)->psw.mask = |
c1821c2e | 471 | PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32); |
1da177e4 LT |
472 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
473 | /* Build a 64 bit psw address from 31 bit address. */ | |
c7584fb6 | 474 | task_pt_regs(child)->psw.addr = |
1da177e4 LT |
475 | (__u64) tmp & PSW32_ADDR_INSN; |
476 | } else { | |
477 | /* gpr 0-15 */ | |
c7584fb6 | 478 | *(__u32*)((addr_t) &task_pt_regs(child)->psw |
1da177e4 LT |
479 | + addr*2 + 4) = tmp; |
480 | } | |
481 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | |
482 | /* | |
483 | * access registers are stored in the thread structure | |
484 | */ | |
485 | offset = addr - (addr_t) &dummy32->regs.acrs; | |
486 | *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp; | |
487 | ||
488 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | |
489 | /* | |
490 | * orig_gpr2 is stored on the kernel stack | |
491 | */ | |
c7584fb6 | 492 | *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp; |
1da177e4 LT |
493 | |
494 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { | |
495 | /* | |
496 | * floating point regs. are stored in the thread structure | |
497 | */ | |
498 | if (addr == (addr_t) &dummy32->regs.fp_regs.fpc && | |
499 | (tmp & ~FPC_VALID_MASK) != 0) | |
500 | /* Invalid floating point control. */ | |
501 | return -EINVAL; | |
502 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | |
503 | *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp; | |
504 | ||
505 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | |
506 | /* | |
507 | * per_info is found in the thread structure. | |
508 | */ | |
509 | offset = addr - (addr_t) &dummy32->regs.per_info; | |
510 | /* | |
511 | * This is magic. See per_struct and per_struct32. | |
512 | * By incident the offsets in per_struct are exactly | |
513 | * twice the offsets in per_struct32 for all fields. | |
514 | * The 8 byte fields need special handling though, | |
515 | * because the second half (bytes 4-7) is needed and | |
516 | * not the first half. | |
517 | */ | |
518 | if ((offset >= (addr_t) &dummy_per32->control_regs && | |
519 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || | |
520 | (offset >= (addr_t) &dummy_per32->starting_addr && | |
521 | offset <= (addr_t) &dummy_per32->ending_addr) || | |
522 | offset == (addr_t) &dummy_per32->lowcore.words.address) | |
523 | offset = offset*2 + 4; | |
524 | else | |
525 | offset = offset*2; | |
526 | *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp; | |
527 | ||
528 | } | |
529 | ||
530 | FixPerRegisters(child); | |
531 | return 0; | |
532 | } | |
533 | ||
534 | static int | |
535 | do_ptrace_emu31(struct task_struct *child, long request, long addr, long data) | |
536 | { | |
537 | unsigned int tmp; /* 4 bytes !! */ | |
538 | ptrace_area_emu31 parea; | |
539 | int copied, ret; | |
540 | ||
541 | switch (request) { | |
542 | case PTRACE_PEEKTEXT: | |
543 | case PTRACE_PEEKDATA: | |
544 | /* read word at location addr. */ | |
545 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); | |
546 | if (copied != sizeof(tmp)) | |
547 | return -EIO; | |
2b67fc46 | 548 | return put_user(tmp, (unsigned int __force __user *) data); |
1da177e4 LT |
549 | |
550 | case PTRACE_PEEKUSR: | |
551 | /* read the word at location addr in the USER area. */ | |
552 | return peek_user_emu31(child, addr, data); | |
553 | ||
554 | case PTRACE_POKETEXT: | |
555 | case PTRACE_POKEDATA: | |
556 | /* write the word at location addr. */ | |
557 | tmp = data; | |
558 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 1); | |
559 | if (copied != sizeof(tmp)) | |
560 | return -EIO; | |
561 | return 0; | |
562 | ||
563 | case PTRACE_POKEUSR: | |
564 | /* write the word at location addr in the USER area */ | |
565 | return poke_user_emu31(child, addr, data); | |
566 | ||
567 | case PTRACE_PEEKUSR_AREA: | |
568 | case PTRACE_POKEUSR_AREA: | |
2b67fc46 | 569 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
570 | sizeof(parea))) |
571 | return -EFAULT; | |
572 | addr = parea.kernel_addr; | |
573 | data = parea.process_addr; | |
574 | copied = 0; | |
575 | while (copied < parea.len) { | |
576 | if (request == PTRACE_PEEKUSR_AREA) | |
577 | ret = peek_user_emu31(child, addr, data); | |
578 | else { | |
2b67fc46 HC |
579 | __u32 utmp; |
580 | if (get_user(utmp, | |
581 | (__u32 __force __user *) data)) | |
1da177e4 | 582 | return -EFAULT; |
2b67fc46 | 583 | ret = poke_user_emu31(child, addr, utmp); |
1da177e4 LT |
584 | } |
585 | if (ret) | |
586 | return ret; | |
587 | addr += sizeof(unsigned int); | |
588 | data += sizeof(unsigned int); | |
589 | copied += sizeof(unsigned int); | |
590 | } | |
591 | return 0; | |
592 | case PTRACE_GETEVENTMSG: | |
593 | return put_user((__u32) child->ptrace_message, | |
2b67fc46 | 594 | (unsigned int __force __user *) data); |
1da177e4 LT |
595 | case PTRACE_GETSIGINFO: |
596 | if (child->last_siginfo == NULL) | |
597 | return -EINVAL; | |
2b67fc46 HC |
598 | return copy_siginfo_to_user32((compat_siginfo_t |
599 | __force __user *) data, | |
1da177e4 LT |
600 | child->last_siginfo); |
601 | case PTRACE_SETSIGINFO: | |
602 | if (child->last_siginfo == NULL) | |
603 | return -EINVAL; | |
604 | return copy_siginfo_from_user32(child->last_siginfo, | |
2b67fc46 HC |
605 | (compat_siginfo_t |
606 | __force __user *) data); | |
1da177e4 LT |
607 | } |
608 | return ptrace_request(child, request, addr, data); | |
609 | } | |
610 | #endif | |
611 | ||
612 | #define PT32_IEEE_IP 0x13c | |
613 | ||
614 | static int | |
615 | do_ptrace(struct task_struct *child, long request, long addr, long data) | |
616 | { | |
617 | int ret; | |
618 | ||
619 | if (request == PTRACE_ATTACH) | |
620 | return ptrace_attach(child); | |
621 | ||
622 | /* | |
623 | * Special cases to get/store the ieee instructions pointer. | |
624 | */ | |
625 | if (child == current) { | |
626 | if (request == PTRACE_PEEKUSR && addr == PT_IEEE_IP) | |
627 | return peek_user(child, addr, data); | |
628 | if (request == PTRACE_POKEUSR && addr == PT_IEEE_IP) | |
629 | return poke_user(child, addr, data); | |
347a8dc3 | 630 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
631 | if (request == PTRACE_PEEKUSR && |
632 | addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT)) | |
633 | return peek_user_emu31(child, addr, data); | |
634 | if (request == PTRACE_POKEUSR && | |
635 | addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT)) | |
636 | return poke_user_emu31(child, addr, data); | |
637 | #endif | |
638 | } | |
639 | ||
640 | ret = ptrace_check_attach(child, request == PTRACE_KILL); | |
641 | if (ret < 0) | |
642 | return ret; | |
643 | ||
644 | switch (request) { | |
645 | case PTRACE_SYSCALL: | |
646 | /* continue and stop at next (return from) syscall */ | |
647 | case PTRACE_CONT: | |
648 | /* restart after signal. */ | |
7ed20e1a | 649 | if (!valid_signal(data)) |
1da177e4 LT |
650 | return -EIO; |
651 | if (request == PTRACE_SYSCALL) | |
652 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
653 | else | |
654 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
655 | child->exit_code = data; | |
656 | /* make sure the single step bit is not set. */ | |
657 | clear_single_step(child); | |
658 | wake_up_process(child); | |
659 | return 0; | |
660 | ||
661 | case PTRACE_KILL: | |
662 | /* | |
663 | * make the child exit. Best I can do is send it a sigkill. | |
664 | * perhaps it should be put in the status that it wants to | |
665 | * exit. | |
666 | */ | |
667 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ | |
668 | return 0; | |
669 | child->exit_code = SIGKILL; | |
670 | /* make sure the single step bit is not set. */ | |
671 | clear_single_step(child); | |
672 | wake_up_process(child); | |
673 | return 0; | |
674 | ||
675 | case PTRACE_SINGLESTEP: | |
676 | /* set the trap flag. */ | |
7ed20e1a | 677 | if (!valid_signal(data)) |
1da177e4 LT |
678 | return -EIO; |
679 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
680 | child->exit_code = data; | |
681 | if (data) | |
682 | set_tsk_thread_flag(child, TIF_SINGLE_STEP); | |
683 | else | |
684 | set_single_step(child); | |
685 | /* give it a chance to run. */ | |
686 | wake_up_process(child); | |
687 | return 0; | |
688 | ||
689 | case PTRACE_DETACH: | |
690 | /* detach a process that was attached. */ | |
691 | return ptrace_detach(child, data); | |
692 | ||
693 | ||
694 | /* Do requests that differ for 31/64 bit */ | |
695 | default: | |
347a8dc3 | 696 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
697 | if (test_thread_flag(TIF_31BIT)) |
698 | return do_ptrace_emu31(child, request, addr, data); | |
699 | #endif | |
700 | return do_ptrace_normal(child, request, addr, data); | |
701 | } | |
702 | /* Not reached. */ | |
703 | return -EIO; | |
704 | } | |
705 | ||
706 | asmlinkage long | |
707 | sys_ptrace(long request, long pid, long addr, long data) | |
708 | { | |
709 | struct task_struct *child; | |
710 | int ret; | |
711 | ||
712 | lock_kernel(); | |
1da177e4 | 713 | if (request == PTRACE_TRACEME) { |
6b9c7ed8 CH |
714 | ret = ptrace_traceme(); |
715 | goto out; | |
1da177e4 LT |
716 | } |
717 | ||
6b9c7ed8 CH |
718 | child = ptrace_get_task_struct(pid); |
719 | if (IS_ERR(child)) { | |
720 | ret = PTR_ERR(child); | |
1da177e4 | 721 | goto out; |
6b9c7ed8 | 722 | } |
1da177e4 LT |
723 | |
724 | ret = do_ptrace(child, request, addr, data); | |
1da177e4 LT |
725 | put_task_struct(child); |
726 | out: | |
727 | unlock_kernel(); | |
728 | return ret; | |
729 | } | |
730 | ||
731 | asmlinkage void | |
732 | syscall_trace(struct pt_regs *regs, int entryexit) | |
733 | { | |
2fd6f58b | 734 | if (unlikely(current->audit_context) && entryexit) |
5411be59 | 735 | audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]); |
2fd6f58b | 736 | |
1da177e4 | 737 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) |
2fd6f58b | 738 | goto out; |
1da177e4 | 739 | if (!(current->ptrace & PT_PTRACED)) |
2fd6f58b | 740 | goto out; |
1da177e4 LT |
741 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) |
742 | ? 0x80 : 0)); | |
743 | ||
c5c3a6d8 BS |
744 | /* |
745 | * If the debuffer has set an invalid system call number, | |
746 | * we prepare to skip the system call restart handling. | |
747 | */ | |
748 | if (!entryexit && regs->gprs[2] >= NR_syscalls) | |
749 | regs->trap = -1; | |
750 | ||
1da177e4 LT |
751 | /* |
752 | * this isn't the same as continuing with a signal, but it will do | |
753 | * for normal use. strace only continues with a signal if the | |
754 | * stopping signal is not SIGTRAP. -brl | |
755 | */ | |
756 | if (current->exit_code) { | |
757 | send_sig(current->exit_code, current, 1); | |
758 | current->exit_code = 0; | |
759 | } | |
2fd6f58b | 760 | out: |
761 | if (unlikely(current->audit_context) && !entryexit) | |
5411be59 | 762 | audit_syscall_entry(test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X, |
2fd6f58b | 763 | regs->gprs[2], regs->orig_gpr2, regs->gprs[3], |
764 | regs->gprs[4], regs->gprs[5]); | |
1da177e4 | 765 | } |