]>
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> |
63506c41 MS |
36 | #include <linux/elf.h> |
37 | #include <linux/regset.h> | |
1da177e4 LT |
38 | |
39 | #include <asm/segment.h> | |
40 | #include <asm/page.h> | |
41 | #include <asm/pgtable.h> | |
42 | #include <asm/pgalloc.h> | |
43 | #include <asm/system.h> | |
44 | #include <asm/uaccess.h> | |
778959db | 45 | #include <asm/unistd.h> |
a806170e | 46 | #include "entry.h" |
1da177e4 | 47 | |
347a8dc3 | 48 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
49 | #include "compat_ptrace.h" |
50 | #endif | |
51 | ||
63506c41 MS |
52 | enum s390_regset { |
53 | REGSET_GENERAL, | |
54 | REGSET_FP, | |
55 | }; | |
56 | ||
1da177e4 LT |
57 | static void |
58 | FixPerRegisters(struct task_struct *task) | |
59 | { | |
60 | struct pt_regs *regs; | |
61 | per_struct *per_info; | |
62 | ||
c7584fb6 | 63 | regs = task_pt_regs(task); |
1da177e4 LT |
64 | per_info = (per_struct *) &task->thread.per_info; |
65 | per_info->control_regs.bits.em_instruction_fetch = | |
66 | per_info->single_step | per_info->instruction_fetch; | |
67 | ||
68 | if (per_info->single_step) { | |
69 | per_info->control_regs.bits.starting_addr = 0; | |
347a8dc3 | 70 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
71 | if (test_thread_flag(TIF_31BIT)) |
72 | per_info->control_regs.bits.ending_addr = 0x7fffffffUL; | |
73 | else | |
74 | #endif | |
75 | per_info->control_regs.bits.ending_addr = PSW_ADDR_INSN; | |
76 | } else { | |
77 | per_info->control_regs.bits.starting_addr = | |
78 | per_info->starting_addr; | |
79 | per_info->control_regs.bits.ending_addr = | |
80 | per_info->ending_addr; | |
81 | } | |
82 | /* | |
83 | * if any of the control reg tracing bits are on | |
84 | * we switch on per in the psw | |
85 | */ | |
86 | if (per_info->control_regs.words.cr[0] & PER_EM_MASK) | |
87 | regs->psw.mask |= PSW_MASK_PER; | |
88 | else | |
89 | regs->psw.mask &= ~PSW_MASK_PER; | |
90 | ||
91 | if (per_info->control_regs.bits.em_storage_alteration) | |
92 | per_info->control_regs.bits.storage_alt_space_ctl = 1; | |
93 | else | |
94 | per_info->control_regs.bits.storage_alt_space_ctl = 0; | |
95 | } | |
96 | ||
0ac30be4 | 97 | void user_enable_single_step(struct task_struct *task) |
1da177e4 LT |
98 | { |
99 | task->thread.per_info.single_step = 1; | |
100 | FixPerRegisters(task); | |
101 | } | |
102 | ||
0ac30be4 | 103 | void user_disable_single_step(struct task_struct *task) |
1da177e4 LT |
104 | { |
105 | task->thread.per_info.single_step = 0; | |
106 | FixPerRegisters(task); | |
107 | } | |
108 | ||
109 | /* | |
110 | * Called by kernel/ptrace.c when detaching.. | |
111 | * | |
112 | * Make sure single step bits etc are not set. | |
113 | */ | |
114 | void | |
115 | ptrace_disable(struct task_struct *child) | |
116 | { | |
117 | /* make sure the single step bit is not set. */ | |
0ac30be4 | 118 | user_disable_single_step(child); |
1da177e4 LT |
119 | } |
120 | ||
347a8dc3 | 121 | #ifndef CONFIG_64BIT |
1da177e4 LT |
122 | # define __ADDR_MASK 3 |
123 | #else | |
124 | # define __ADDR_MASK 7 | |
125 | #endif | |
126 | ||
127 | /* | |
128 | * Read the word at offset addr from the user area of a process. The | |
129 | * trouble here is that the information is littered over different | |
130 | * locations. The process registers are found on the kernel stack, | |
131 | * the floating point stuff and the trace settings are stored in | |
132 | * the task structure. In addition the different structures in | |
133 | * struct user contain pad bytes that should be read as zeroes. | |
134 | * Lovely... | |
135 | */ | |
63506c41 | 136 | static unsigned long __peek_user(struct task_struct *child, addr_t addr) |
1da177e4 LT |
137 | { |
138 | struct user *dummy = NULL; | |
63506c41 | 139 | addr_t offset, tmp; |
1da177e4 LT |
140 | |
141 | if (addr < (addr_t) &dummy->regs.acrs) { | |
142 | /* | |
143 | * psw and gprs are stored on the stack | |
144 | */ | |
c7584fb6 | 145 | tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr); |
1da177e4 LT |
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; | |
347a8dc3 | 155 | #ifdef CONFIG_64BIT |
778959db MS |
156 | /* |
157 | * Very special case: old & broken 64 bit gdb reading | |
158 | * from acrs[15]. Result is a 64 bit value. Read the | |
159 | * 32 bit acrs[15] value and shift it by 32. Sick... | |
160 | */ | |
161 | if (addr == (addr_t) &dummy->regs.acrs[15]) | |
162 | tmp = ((unsigned long) child->thread.acrs[15]) << 32; | |
163 | else | |
164 | #endif | |
1da177e4 LT |
165 | tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset); |
166 | ||
167 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | |
168 | /* | |
169 | * orig_gpr2 is stored on the kernel stack | |
170 | */ | |
c7584fb6 | 171 | tmp = (addr_t) task_pt_regs(child)->orig_gpr2; |
1da177e4 | 172 | |
3d6e48f4 JW |
173 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
174 | /* | |
175 | * prevent reads of padding hole between | |
176 | * orig_gpr2 and fp_regs on s390. | |
177 | */ | |
178 | tmp = 0; | |
179 | ||
1da177e4 LT |
180 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
181 | /* | |
182 | * floating point regs. are stored in the thread structure | |
183 | */ | |
184 | offset = addr - (addr_t) &dummy->regs.fp_regs; | |
185 | tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset); | |
778959db MS |
186 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
187 | tmp &= (unsigned long) FPC_VALID_MASK | |
188 | << (BITS_PER_LONG - 32); | |
1da177e4 LT |
189 | |
190 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | |
191 | /* | |
192 | * per_info is found in the thread structure | |
193 | */ | |
194 | offset = addr - (addr_t) &dummy->regs.per_info; | |
195 | tmp = *(addr_t *)((addr_t) &child->thread.per_info + offset); | |
196 | ||
197 | } else | |
198 | tmp = 0; | |
199 | ||
63506c41 | 200 | return tmp; |
1da177e4 LT |
201 | } |
202 | ||
1da177e4 | 203 | static int |
63506c41 | 204 | peek_user(struct task_struct *child, addr_t addr, addr_t data) |
1da177e4 LT |
205 | { |
206 | struct user *dummy = NULL; | |
63506c41 | 207 | addr_t tmp, mask; |
1da177e4 LT |
208 | |
209 | /* | |
210 | * Stupid gdb peeks/pokes the access registers in 64 bit with | |
63506c41 | 211 | * an alignment of 4. Programmers from hell... |
1da177e4 | 212 | */ |
778959db | 213 | mask = __ADDR_MASK; |
347a8dc3 | 214 | #ifdef CONFIG_64BIT |
778959db MS |
215 | if (addr >= (addr_t) &dummy->regs.acrs && |
216 | addr < (addr_t) &dummy->regs.orig_gpr2) | |
217 | mask = 3; | |
218 | #endif | |
219 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) | |
1da177e4 LT |
220 | return -EIO; |
221 | ||
63506c41 MS |
222 | tmp = __peek_user(child, addr); |
223 | return put_user(tmp, (addr_t __user *) data); | |
224 | } | |
225 | ||
226 | /* | |
227 | * Write a word to the user area of a process at location addr. This | |
228 | * operation does have an additional problem compared to peek_user. | |
229 | * Stores to the program status word and on the floating point | |
230 | * control register needs to get checked for validity. | |
231 | */ | |
232 | static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) | |
233 | { | |
234 | struct user *dummy = NULL; | |
235 | addr_t offset; | |
236 | ||
1da177e4 LT |
237 | if (addr < (addr_t) &dummy->regs.acrs) { |
238 | /* | |
239 | * psw and gprs are stored on the stack | |
240 | */ | |
241 | if (addr == (addr_t) &dummy->regs.psw.mask && | |
347a8dc3 | 242 | #ifdef CONFIG_COMPAT |
c1821c2e | 243 | data != PSW_MASK_MERGE(psw_user32_bits, data) && |
1da177e4 | 244 | #endif |
c1821c2e | 245 | data != PSW_MASK_MERGE(psw_user_bits, data)) |
1da177e4 LT |
246 | /* Invalid psw mask. */ |
247 | return -EINVAL; | |
347a8dc3 | 248 | #ifndef CONFIG_64BIT |
1da177e4 LT |
249 | if (addr == (addr_t) &dummy->regs.psw.addr) |
250 | /* I'd like to reject addresses without the | |
251 | high order bit but older gdb's rely on it */ | |
252 | data |= PSW_ADDR_AMODE; | |
253 | #endif | |
c7584fb6 | 254 | *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; |
1da177e4 LT |
255 | |
256 | } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { | |
257 | /* | |
258 | * access registers are stored in the thread structure | |
259 | */ | |
260 | offset = addr - (addr_t) &dummy->regs.acrs; | |
347a8dc3 | 261 | #ifdef CONFIG_64BIT |
778959db MS |
262 | /* |
263 | * Very special case: old & broken 64 bit gdb writing | |
264 | * to acrs[15] with a 64 bit value. Ignore the lower | |
265 | * half of the value and write the upper 32 bit to | |
266 | * acrs[15]. Sick... | |
267 | */ | |
268 | if (addr == (addr_t) &dummy->regs.acrs[15]) | |
269 | child->thread.acrs[15] = (unsigned int) (data >> 32); | |
270 | else | |
271 | #endif | |
1da177e4 LT |
272 | *(addr_t *)((addr_t) &child->thread.acrs + offset) = data; |
273 | ||
274 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | |
275 | /* | |
276 | * orig_gpr2 is stored on the kernel stack | |
277 | */ | |
c7584fb6 | 278 | task_pt_regs(child)->orig_gpr2 = data; |
1da177e4 | 279 | |
3d6e48f4 JW |
280 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
281 | /* | |
282 | * prevent writes of padding hole between | |
283 | * orig_gpr2 and fp_regs on s390. | |
284 | */ | |
285 | return 0; | |
286 | ||
1da177e4 LT |
287 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
288 | /* | |
289 | * floating point regs. are stored in the thread structure | |
290 | */ | |
291 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc && | |
778959db MS |
292 | (data & ~((unsigned long) FPC_VALID_MASK |
293 | << (BITS_PER_LONG - 32))) != 0) | |
1da177e4 LT |
294 | return -EINVAL; |
295 | offset = addr - (addr_t) &dummy->regs.fp_regs; | |
296 | *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data; | |
297 | ||
298 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | |
299 | /* | |
300 | * per_info is found in the thread structure | |
301 | */ | |
302 | offset = addr - (addr_t) &dummy->regs.per_info; | |
303 | *(addr_t *)((addr_t) &child->thread.per_info + offset) = data; | |
304 | ||
305 | } | |
306 | ||
307 | FixPerRegisters(child); | |
308 | return 0; | |
309 | } | |
310 | ||
63506c41 MS |
311 | static int |
312 | poke_user(struct task_struct *child, addr_t addr, addr_t data) | |
313 | { | |
314 | struct user *dummy = NULL; | |
315 | addr_t mask; | |
316 | ||
317 | /* | |
318 | * Stupid gdb peeks/pokes the access registers in 64 bit with | |
319 | * an alignment of 4. Programmers from hell indeed... | |
320 | */ | |
321 | mask = __ADDR_MASK; | |
322 | #ifdef CONFIG_64BIT | |
323 | if (addr >= (addr_t) &dummy->regs.acrs && | |
324 | addr < (addr_t) &dummy->regs.orig_gpr2) | |
325 | mask = 3; | |
326 | #endif | |
327 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) | |
328 | return -EIO; | |
329 | ||
330 | return __poke_user(child, addr, data); | |
331 | } | |
332 | ||
b499d76b | 333 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) |
1da177e4 | 334 | { |
1da177e4 LT |
335 | ptrace_area parea; |
336 | int copied, ret; | |
337 | ||
338 | switch (request) { | |
339 | case PTRACE_PEEKTEXT: | |
340 | case PTRACE_PEEKDATA: | |
341 | /* Remove high order bit from address (only for 31 bit). */ | |
342 | addr &= PSW_ADDR_INSN; | |
343 | /* read word at location addr. */ | |
76647323 | 344 | return generic_ptrace_peekdata(child, addr, data); |
1da177e4 LT |
345 | |
346 | case PTRACE_PEEKUSR: | |
347 | /* read the word at location addr in the USER area. */ | |
348 | return peek_user(child, addr, data); | |
349 | ||
350 | case PTRACE_POKETEXT: | |
351 | case PTRACE_POKEDATA: | |
352 | /* Remove high order bit from address (only for 31 bit). */ | |
353 | addr &= PSW_ADDR_INSN; | |
354 | /* write the word at location addr. */ | |
f284ce72 | 355 | return generic_ptrace_pokedata(child, addr, data); |
1da177e4 LT |
356 | |
357 | case PTRACE_POKEUSR: | |
358 | /* write the word at location addr in the USER area */ | |
359 | return poke_user(child, addr, data); | |
360 | ||
361 | case PTRACE_PEEKUSR_AREA: | |
362 | case PTRACE_POKEUSR_AREA: | |
2b67fc46 | 363 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
364 | sizeof(parea))) |
365 | return -EFAULT; | |
366 | addr = parea.kernel_addr; | |
367 | data = parea.process_addr; | |
368 | copied = 0; | |
369 | while (copied < parea.len) { | |
370 | if (request == PTRACE_PEEKUSR_AREA) | |
371 | ret = peek_user(child, addr, data); | |
372 | else { | |
2b67fc46 HC |
373 | addr_t utmp; |
374 | if (get_user(utmp, | |
375 | (addr_t __force __user *) data)) | |
1da177e4 | 376 | return -EFAULT; |
2b67fc46 | 377 | ret = poke_user(child, addr, utmp); |
1da177e4 LT |
378 | } |
379 | if (ret) | |
380 | return ret; | |
381 | addr += sizeof(unsigned long); | |
382 | data += sizeof(unsigned long); | |
383 | copied += sizeof(unsigned long); | |
384 | } | |
385 | return 0; | |
386 | } | |
387 | return ptrace_request(child, request, addr, data); | |
388 | } | |
389 | ||
347a8dc3 | 390 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
391 | /* |
392 | * Now the fun part starts... a 31 bit program running in the | |
393 | * 31 bit emulation tracing another program. PTRACE_PEEKTEXT, | |
394 | * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy | |
395 | * to handle, the difference to the 64 bit versions of the requests | |
396 | * is that the access is done in multiples of 4 byte instead of | |
397 | * 8 bytes (sizeof(unsigned long) on 31/64 bit). | |
398 | * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA, | |
399 | * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program | |
400 | * is a 31 bit program too, the content of struct user can be | |
401 | * emulated. A 31 bit program peeking into the struct user of | |
402 | * a 64 bit program is a no-no. | |
403 | */ | |
404 | ||
405 | /* | |
406 | * Same as peek_user but for a 31 bit program. | |
407 | */ | |
63506c41 | 408 | static u32 __peek_user_compat(struct task_struct *child, addr_t addr) |
1da177e4 LT |
409 | { |
410 | struct user32 *dummy32 = NULL; | |
411 | per_struct32 *dummy_per32 = NULL; | |
412 | addr_t offset; | |
413 | __u32 tmp; | |
414 | ||
1da177e4 LT |
415 | if (addr < (addr_t) &dummy32->regs.acrs) { |
416 | /* | |
417 | * psw and gprs are stored on the stack | |
418 | */ | |
419 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | |
420 | /* Fake a 31 bit psw mask. */ | |
c7584fb6 | 421 | tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32); |
c1821c2e | 422 | tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp); |
1da177e4 LT |
423 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
424 | /* Fake a 31 bit psw address. */ | |
c7584fb6 | 425 | tmp = (__u32) task_pt_regs(child)->psw.addr | |
1da177e4 LT |
426 | PSW32_ADDR_AMODE31; |
427 | } else { | |
428 | /* gpr 0-15 */ | |
c7584fb6 | 429 | tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw + |
1da177e4 LT |
430 | addr*2 + 4); |
431 | } | |
432 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | |
433 | /* | |
434 | * access registers are stored in the thread structure | |
435 | */ | |
436 | offset = addr - (addr_t) &dummy32->regs.acrs; | |
437 | tmp = *(__u32*)((addr_t) &child->thread.acrs + offset); | |
438 | ||
439 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | |
440 | /* | |
441 | * orig_gpr2 is stored on the kernel stack | |
442 | */ | |
c7584fb6 | 443 | tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4); |
1da177e4 | 444 | |
3d6e48f4 JW |
445 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
446 | /* | |
447 | * prevent reads of padding hole between | |
448 | * orig_gpr2 and fp_regs on s390. | |
449 | */ | |
450 | tmp = 0; | |
451 | ||
1da177e4 LT |
452 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
453 | /* | |
454 | * floating point regs. are stored in the thread structure | |
455 | */ | |
456 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | |
457 | tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset); | |
458 | ||
459 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | |
460 | /* | |
461 | * per_info is found in the thread structure | |
462 | */ | |
463 | offset = addr - (addr_t) &dummy32->regs.per_info; | |
464 | /* This is magic. See per_struct and per_struct32. */ | |
465 | if ((offset >= (addr_t) &dummy_per32->control_regs && | |
466 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || | |
467 | (offset >= (addr_t) &dummy_per32->starting_addr && | |
468 | offset <= (addr_t) &dummy_per32->ending_addr) || | |
469 | offset == (addr_t) &dummy_per32->lowcore.words.address) | |
470 | offset = offset*2 + 4; | |
471 | else | |
472 | offset = offset*2; | |
473 | tmp = *(__u32 *)((addr_t) &child->thread.per_info + offset); | |
474 | ||
475 | } else | |
476 | tmp = 0; | |
477 | ||
63506c41 MS |
478 | return tmp; |
479 | } | |
480 | ||
481 | static int peek_user_compat(struct task_struct *child, | |
482 | addr_t addr, addr_t data) | |
483 | { | |
484 | __u32 tmp; | |
485 | ||
486 | if (!test_thread_flag(TIF_31BIT) || | |
487 | (addr & 3) || addr > sizeof(struct user) - 3) | |
488 | return -EIO; | |
489 | ||
490 | tmp = __peek_user_compat(child, addr); | |
1da177e4 LT |
491 | return put_user(tmp, (__u32 __user *) data); |
492 | } | |
493 | ||
494 | /* | |
495 | * Same as poke_user but for a 31 bit program. | |
496 | */ | |
63506c41 MS |
497 | static int __poke_user_compat(struct task_struct *child, |
498 | addr_t addr, addr_t data) | |
1da177e4 LT |
499 | { |
500 | struct user32 *dummy32 = NULL; | |
501 | per_struct32 *dummy_per32 = NULL; | |
63506c41 | 502 | __u32 tmp = (__u32) data; |
1da177e4 | 503 | addr_t offset; |
1da177e4 LT |
504 | |
505 | if (addr < (addr_t) &dummy32->regs.acrs) { | |
506 | /* | |
507 | * psw, gprs, acrs and orig_gpr2 are stored on the stack | |
508 | */ | |
509 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | |
510 | /* Build a 64 bit psw mask from 31 bit mask. */ | |
c1821c2e | 511 | if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp)) |
1da177e4 LT |
512 | /* Invalid psw mask. */ |
513 | return -EINVAL; | |
c7584fb6 | 514 | task_pt_regs(child)->psw.mask = |
c1821c2e | 515 | PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32); |
1da177e4 LT |
516 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
517 | /* Build a 64 bit psw address from 31 bit address. */ | |
c7584fb6 | 518 | task_pt_regs(child)->psw.addr = |
1da177e4 LT |
519 | (__u64) tmp & PSW32_ADDR_INSN; |
520 | } else { | |
521 | /* gpr 0-15 */ | |
c7584fb6 | 522 | *(__u32*)((addr_t) &task_pt_regs(child)->psw |
1da177e4 LT |
523 | + addr*2 + 4) = tmp; |
524 | } | |
525 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | |
526 | /* | |
527 | * access registers are stored in the thread structure | |
528 | */ | |
529 | offset = addr - (addr_t) &dummy32->regs.acrs; | |
530 | *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp; | |
531 | ||
532 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | |
533 | /* | |
534 | * orig_gpr2 is stored on the kernel stack | |
535 | */ | |
c7584fb6 | 536 | *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp; |
1da177e4 | 537 | |
3d6e48f4 JW |
538 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
539 | /* | |
540 | * prevent writess of padding hole between | |
541 | * orig_gpr2 and fp_regs on s390. | |
542 | */ | |
543 | return 0; | |
544 | ||
1da177e4 LT |
545 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
546 | /* | |
547 | * floating point regs. are stored in the thread structure | |
548 | */ | |
549 | if (addr == (addr_t) &dummy32->regs.fp_regs.fpc && | |
550 | (tmp & ~FPC_VALID_MASK) != 0) | |
551 | /* Invalid floating point control. */ | |
552 | return -EINVAL; | |
553 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | |
554 | *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp; | |
555 | ||
556 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | |
557 | /* | |
558 | * per_info is found in the thread structure. | |
559 | */ | |
560 | offset = addr - (addr_t) &dummy32->regs.per_info; | |
561 | /* | |
562 | * This is magic. See per_struct and per_struct32. | |
563 | * By incident the offsets in per_struct are exactly | |
564 | * twice the offsets in per_struct32 for all fields. | |
565 | * The 8 byte fields need special handling though, | |
566 | * because the second half (bytes 4-7) is needed and | |
567 | * not the first half. | |
568 | */ | |
569 | if ((offset >= (addr_t) &dummy_per32->control_regs && | |
570 | offset < (addr_t) (&dummy_per32->control_regs + 1)) || | |
571 | (offset >= (addr_t) &dummy_per32->starting_addr && | |
572 | offset <= (addr_t) &dummy_per32->ending_addr) || | |
573 | offset == (addr_t) &dummy_per32->lowcore.words.address) | |
574 | offset = offset*2 + 4; | |
575 | else | |
576 | offset = offset*2; | |
577 | *(__u32 *)((addr_t) &child->thread.per_info + offset) = tmp; | |
578 | ||
579 | } | |
580 | ||
581 | FixPerRegisters(child); | |
582 | return 0; | |
583 | } | |
584 | ||
63506c41 MS |
585 | static int poke_user_compat(struct task_struct *child, |
586 | addr_t addr, addr_t data) | |
587 | { | |
588 | if (!test_thread_flag(TIF_31BIT) || | |
589 | (addr & 3) || addr > sizeof(struct user32) - 3) | |
590 | return -EIO; | |
591 | ||
592 | return __poke_user_compat(child, addr, data); | |
593 | } | |
594 | ||
b499d76b RM |
595 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
596 | compat_ulong_t caddr, compat_ulong_t cdata) | |
1da177e4 | 597 | { |
b499d76b RM |
598 | unsigned long addr = caddr; |
599 | unsigned long data = cdata; | |
1da177e4 LT |
600 | ptrace_area_emu31 parea; |
601 | int copied, ret; | |
602 | ||
603 | switch (request) { | |
1da177e4 LT |
604 | case PTRACE_PEEKUSR: |
605 | /* read the word at location addr in the USER area. */ | |
63506c41 | 606 | return peek_user_compat(child, addr, data); |
1da177e4 | 607 | |
1da177e4 LT |
608 | case PTRACE_POKEUSR: |
609 | /* write the word at location addr in the USER area */ | |
63506c41 | 610 | return poke_user_compat(child, addr, data); |
1da177e4 LT |
611 | |
612 | case PTRACE_PEEKUSR_AREA: | |
613 | case PTRACE_POKEUSR_AREA: | |
2b67fc46 | 614 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
615 | sizeof(parea))) |
616 | return -EFAULT; | |
617 | addr = parea.kernel_addr; | |
618 | data = parea.process_addr; | |
619 | copied = 0; | |
620 | while (copied < parea.len) { | |
621 | if (request == PTRACE_PEEKUSR_AREA) | |
63506c41 | 622 | ret = peek_user_compat(child, addr, data); |
1da177e4 | 623 | else { |
2b67fc46 HC |
624 | __u32 utmp; |
625 | if (get_user(utmp, | |
626 | (__u32 __force __user *) data)) | |
1da177e4 | 627 | return -EFAULT; |
63506c41 | 628 | ret = poke_user_compat(child, addr, utmp); |
1da177e4 LT |
629 | } |
630 | if (ret) | |
631 | return ret; | |
632 | addr += sizeof(unsigned int); | |
633 | data += sizeof(unsigned int); | |
634 | copied += sizeof(unsigned int); | |
635 | } | |
636 | return 0; | |
1da177e4 | 637 | } |
b499d76b | 638 | return compat_ptrace_request(child, request, addr, data); |
1da177e4 LT |
639 | } |
640 | #endif | |
641 | ||
1da177e4 LT |
642 | asmlinkage void |
643 | syscall_trace(struct pt_regs *regs, int entryexit) | |
644 | { | |
2fd6f58b | 645 | if (unlikely(current->audit_context) && entryexit) |
5411be59 | 646 | audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]); |
2fd6f58b | 647 | |
1da177e4 | 648 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) |
2fd6f58b | 649 | goto out; |
1da177e4 | 650 | if (!(current->ptrace & PT_PTRACED)) |
2fd6f58b | 651 | goto out; |
1da177e4 LT |
652 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) |
653 | ? 0x80 : 0)); | |
654 | ||
c5c3a6d8 BS |
655 | /* |
656 | * If the debuffer has set an invalid system call number, | |
657 | * we prepare to skip the system call restart handling. | |
658 | */ | |
659 | if (!entryexit && regs->gprs[2] >= NR_syscalls) | |
660 | regs->trap = -1; | |
661 | ||
1da177e4 LT |
662 | /* |
663 | * this isn't the same as continuing with a signal, but it will do | |
664 | * for normal use. strace only continues with a signal if the | |
665 | * stopping signal is not SIGTRAP. -brl | |
666 | */ | |
667 | if (current->exit_code) { | |
668 | send_sig(current->exit_code, current, 1); | |
669 | current->exit_code = 0; | |
670 | } | |
2fd6f58b DW |
671 | out: |
672 | if (unlikely(current->audit_context) && !entryexit) | |
5411be59 | 673 | audit_syscall_entry(test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X, |
2fd6f58b DW |
674 | regs->gprs[2], regs->orig_gpr2, regs->gprs[3], |
675 | regs->gprs[4], regs->gprs[5]); | |
1da177e4 | 676 | } |
63506c41 MS |
677 | |
678 | /* | |
679 | * user_regset definitions. | |
680 | */ | |
681 | ||
682 | static int s390_regs_get(struct task_struct *target, | |
683 | const struct user_regset *regset, | |
684 | unsigned int pos, unsigned int count, | |
685 | void *kbuf, void __user *ubuf) | |
686 | { | |
687 | if (target == current) | |
688 | save_access_regs(target->thread.acrs); | |
689 | ||
690 | if (kbuf) { | |
691 | unsigned long *k = kbuf; | |
692 | while (count > 0) { | |
693 | *k++ = __peek_user(target, pos); | |
694 | count -= sizeof(*k); | |
695 | pos += sizeof(*k); | |
696 | } | |
697 | } else { | |
698 | unsigned long __user *u = ubuf; | |
699 | while (count > 0) { | |
700 | if (__put_user(__peek_user(target, pos), u++)) | |
701 | return -EFAULT; | |
702 | count -= sizeof(*u); | |
703 | pos += sizeof(*u); | |
704 | } | |
705 | } | |
706 | return 0; | |
707 | } | |
708 | ||
709 | static int s390_regs_set(struct task_struct *target, | |
710 | const struct user_regset *regset, | |
711 | unsigned int pos, unsigned int count, | |
712 | const void *kbuf, const void __user *ubuf) | |
713 | { | |
714 | int rc = 0; | |
715 | ||
716 | if (target == current) | |
717 | save_access_regs(target->thread.acrs); | |
718 | ||
719 | if (kbuf) { | |
720 | const unsigned long *k = kbuf; | |
721 | while (count > 0 && !rc) { | |
722 | rc = __poke_user(target, pos, *k++); | |
723 | count -= sizeof(*k); | |
724 | pos += sizeof(*k); | |
725 | } | |
726 | } else { | |
727 | const unsigned long __user *u = ubuf; | |
728 | while (count > 0 && !rc) { | |
729 | unsigned long word; | |
730 | rc = __get_user(word, u++); | |
731 | if (rc) | |
732 | break; | |
733 | rc = __poke_user(target, pos, word); | |
734 | count -= sizeof(*u); | |
735 | pos += sizeof(*u); | |
736 | } | |
737 | } | |
738 | ||
739 | if (rc == 0 && target == current) | |
740 | restore_access_regs(target->thread.acrs); | |
741 | ||
742 | return rc; | |
743 | } | |
744 | ||
745 | static int s390_fpregs_get(struct task_struct *target, | |
746 | const struct user_regset *regset, unsigned int pos, | |
747 | unsigned int count, void *kbuf, void __user *ubuf) | |
748 | { | |
749 | if (target == current) | |
750 | save_fp_regs(&target->thread.fp_regs); | |
751 | ||
752 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
753 | &target->thread.fp_regs, 0, -1); | |
754 | } | |
755 | ||
756 | static int s390_fpregs_set(struct task_struct *target, | |
757 | const struct user_regset *regset, unsigned int pos, | |
758 | unsigned int count, const void *kbuf, | |
759 | const void __user *ubuf) | |
760 | { | |
761 | int rc = 0; | |
762 | ||
763 | if (target == current) | |
764 | save_fp_regs(&target->thread.fp_regs); | |
765 | ||
766 | /* If setting FPC, must validate it first. */ | |
767 | if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) { | |
768 | u32 fpc[2] = { target->thread.fp_regs.fpc, 0 }; | |
769 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc, | |
770 | 0, offsetof(s390_fp_regs, fprs)); | |
771 | if (rc) | |
772 | return rc; | |
773 | if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0) | |
774 | return -EINVAL; | |
775 | target->thread.fp_regs.fpc = fpc[0]; | |
776 | } | |
777 | ||
778 | if (rc == 0 && count > 0) | |
779 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
780 | target->thread.fp_regs.fprs, | |
781 | offsetof(s390_fp_regs, fprs), -1); | |
782 | ||
783 | if (rc == 0 && target == current) | |
784 | restore_fp_regs(&target->thread.fp_regs); | |
785 | ||
786 | return rc; | |
787 | } | |
788 | ||
789 | static const struct user_regset s390_regsets[] = { | |
790 | [REGSET_GENERAL] = { | |
791 | .core_note_type = NT_PRSTATUS, | |
792 | .n = sizeof(s390_regs) / sizeof(long), | |
793 | .size = sizeof(long), | |
794 | .align = sizeof(long), | |
795 | .get = s390_regs_get, | |
796 | .set = s390_regs_set, | |
797 | }, | |
798 | [REGSET_FP] = { | |
799 | .core_note_type = NT_PRFPREG, | |
800 | .n = sizeof(s390_fp_regs) / sizeof(long), | |
801 | .size = sizeof(long), | |
802 | .align = sizeof(long), | |
803 | .get = s390_fpregs_get, | |
804 | .set = s390_fpregs_set, | |
805 | }, | |
806 | }; | |
807 | ||
808 | static const struct user_regset_view user_s390_view = { | |
809 | .name = UTS_MACHINE, | |
810 | .e_machine = EM_S390, | |
811 | .regsets = s390_regsets, | |
812 | .n = ARRAY_SIZE(s390_regsets) | |
813 | }; | |
814 | ||
815 | #ifdef CONFIG_COMPAT | |
816 | static int s390_compat_regs_get(struct task_struct *target, | |
817 | const struct user_regset *regset, | |
818 | unsigned int pos, unsigned int count, | |
819 | void *kbuf, void __user *ubuf) | |
820 | { | |
821 | if (target == current) | |
822 | save_access_regs(target->thread.acrs); | |
823 | ||
824 | if (kbuf) { | |
825 | compat_ulong_t *k = kbuf; | |
826 | while (count > 0) { | |
827 | *k++ = __peek_user_compat(target, pos); | |
828 | count -= sizeof(*k); | |
829 | pos += sizeof(*k); | |
830 | } | |
831 | } else { | |
832 | compat_ulong_t __user *u = ubuf; | |
833 | while (count > 0) { | |
834 | if (__put_user(__peek_user_compat(target, pos), u++)) | |
835 | return -EFAULT; | |
836 | count -= sizeof(*u); | |
837 | pos += sizeof(*u); | |
838 | } | |
839 | } | |
840 | return 0; | |
841 | } | |
842 | ||
843 | static int s390_compat_regs_set(struct task_struct *target, | |
844 | const struct user_regset *regset, | |
845 | unsigned int pos, unsigned int count, | |
846 | const void *kbuf, const void __user *ubuf) | |
847 | { | |
848 | int rc = 0; | |
849 | ||
850 | if (target == current) | |
851 | save_access_regs(target->thread.acrs); | |
852 | ||
853 | if (kbuf) { | |
854 | const compat_ulong_t *k = kbuf; | |
855 | while (count > 0 && !rc) { | |
856 | rc = __poke_user_compat(target, pos, *k++); | |
857 | count -= sizeof(*k); | |
858 | pos += sizeof(*k); | |
859 | } | |
860 | } else { | |
861 | const compat_ulong_t __user *u = ubuf; | |
862 | while (count > 0 && !rc) { | |
863 | compat_ulong_t word; | |
864 | rc = __get_user(word, u++); | |
865 | if (rc) | |
866 | break; | |
867 | rc = __poke_user_compat(target, pos, word); | |
868 | count -= sizeof(*u); | |
869 | pos += sizeof(*u); | |
870 | } | |
871 | } | |
872 | ||
873 | if (rc == 0 && target == current) | |
874 | restore_access_regs(target->thread.acrs); | |
875 | ||
876 | return rc; | |
877 | } | |
878 | ||
879 | static const struct user_regset s390_compat_regsets[] = { | |
880 | [REGSET_GENERAL] = { | |
881 | .core_note_type = NT_PRSTATUS, | |
882 | .n = sizeof(s390_compat_regs) / sizeof(compat_long_t), | |
883 | .size = sizeof(compat_long_t), | |
884 | .align = sizeof(compat_long_t), | |
885 | .get = s390_compat_regs_get, | |
886 | .set = s390_compat_regs_set, | |
887 | }, | |
888 | [REGSET_FP] = { | |
889 | .core_note_type = NT_PRFPREG, | |
890 | .n = sizeof(s390_fp_regs) / sizeof(compat_long_t), | |
891 | .size = sizeof(compat_long_t), | |
892 | .align = sizeof(compat_long_t), | |
893 | .get = s390_fpregs_get, | |
894 | .set = s390_fpregs_set, | |
895 | }, | |
896 | }; | |
897 | ||
898 | static const struct user_regset_view user_s390_compat_view = { | |
899 | .name = "s390", | |
900 | .e_machine = EM_S390, | |
901 | .regsets = s390_compat_regsets, | |
902 | .n = ARRAY_SIZE(s390_compat_regsets) | |
903 | }; | |
904 | #endif | |
905 | ||
906 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) | |
907 | { | |
908 | #ifdef CONFIG_COMPAT | |
909 | if (test_tsk_thread_flag(task, TIF_31BIT)) | |
910 | return &user_s390_compat_view; | |
911 | #endif | |
912 | return &user_s390_view; | |
913 | } |