Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
5e9a2692 | 2 | * Ptrace user space interface. |
1da177e4 | 3 | * |
a53c8fab | 4 | * Copyright IBM Corp. 1999, 2010 |
5e9a2692 | 5 | * Author(s): Denis Joseph Barrow |
1da177e4 | 6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
1da177e4 LT |
7 | */ |
8 | ||
9 | #include <linux/kernel.h> | |
10 | #include <linux/sched.h> | |
11 | #include <linux/mm.h> | |
12 | #include <linux/smp.h> | |
1da177e4 LT |
13 | #include <linux/errno.h> |
14 | #include <linux/ptrace.h> | |
15 | #include <linux/user.h> | |
16 | #include <linux/security.h> | |
17 | #include <linux/audit.h> | |
7ed20e1a | 18 | #include <linux/signal.h> |
63506c41 MS |
19 | #include <linux/elf.h> |
20 | #include <linux/regset.h> | |
753c4dd6 | 21 | #include <linux/tracehook.h> |
bcf5cef7 | 22 | #include <linux/seccomp.h> |
048cd4e5 | 23 | #include <linux/compat.h> |
9bf1226b | 24 | #include <trace/syscall.h> |
1da177e4 LT |
25 | #include <asm/segment.h> |
26 | #include <asm/page.h> | |
27 | #include <asm/pgtable.h> | |
28 | #include <asm/pgalloc.h> | |
1da177e4 | 29 | #include <asm/uaccess.h> |
778959db | 30 | #include <asm/unistd.h> |
a0616cde | 31 | #include <asm/switch_to.h> |
a806170e | 32 | #include "entry.h" |
1da177e4 | 33 | |
347a8dc3 | 34 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
35 | #include "compat_ptrace.h" |
36 | #endif | |
37 | ||
1c569f02 JS |
38 | #define CREATE_TRACE_POINTS |
39 | #include <trace/events/syscalls.h> | |
5e9ad7df | 40 | |
63506c41 MS |
41 | enum s390_regset { |
42 | REGSET_GENERAL, | |
43 | REGSET_FP, | |
86f2552b | 44 | REGSET_LAST_BREAK, |
d35339a4 | 45 | REGSET_TDB, |
20b40a79 | 46 | REGSET_SYSTEM_CALL, |
ea2a4d3a | 47 | REGSET_GENERAL_EXTENDED, |
63506c41 MS |
48 | }; |
49 | ||
5e9a2692 | 50 | void update_per_regs(struct task_struct *task) |
1da177e4 | 51 | { |
5e9a2692 MS |
52 | struct pt_regs *regs = task_pt_regs(task); |
53 | struct thread_struct *thread = &task->thread; | |
a45aff52 | 54 | struct per_regs old, new; |
5e9a2692 | 55 | |
d35339a4 MS |
56 | /* Take care of the enable/disable of transactional execution. */ |
57 | if (MACHINE_HAS_TE) { | |
58 | unsigned long cr0, cr0_new; | |
59 | ||
60 | __ctl_store(cr0, 0, 0); | |
61 | /* set or clear transaction execution bits 8 and 9. */ | |
62 | if (task->thread.per_flags & PER_FLAG_NO_TE) | |
63 | cr0_new = cr0 & ~(3UL << 54); | |
64 | else | |
65 | cr0_new = cr0 | (3UL << 54); | |
66 | /* Only load control register 0 if necessary. */ | |
67 | if (cr0 != cr0_new) | |
68 | __ctl_load(cr0_new, 0, 0); | |
69 | } | |
70 | ||
a45aff52 MS |
71 | /* Copy user specified PER registers */ |
72 | new.control = thread->per_user.control; | |
73 | new.start = thread->per_user.start; | |
74 | new.end = thread->per_user.end; | |
75 | ||
76 | /* merge TIF_SINGLE_STEP into user specified PER registers. */ | |
77 | if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) { | |
78 | new.control |= PER_EVENT_IFETCH; | |
d35339a4 MS |
79 | #ifdef CONFIG_64BIT |
80 | new.control |= PER_CONTROL_SUSPENSION; | |
81 | new.control |= PER_EVENT_TRANSACTION_END; | |
82 | #endif | |
a45aff52 MS |
83 | new.start = 0; |
84 | new.end = PSW_ADDR_INSN; | |
85 | } | |
5e9a2692 MS |
86 | |
87 | /* Take care of the PER enablement bit in the PSW. */ | |
a45aff52 | 88 | if (!(new.control & PER_EVENT_MASK)) { |
1da177e4 | 89 | regs->psw.mask &= ~PSW_MASK_PER; |
5e9a2692 | 90 | return; |
c3311c13 | 91 | } |
5e9a2692 MS |
92 | regs->psw.mask |= PSW_MASK_PER; |
93 | __ctl_store(old, 9, 11); | |
a45aff52 MS |
94 | if (memcmp(&new, &old, sizeof(struct per_regs)) != 0) |
95 | __ctl_load(new, 9, 11); | |
1da177e4 LT |
96 | } |
97 | ||
0ac30be4 | 98 | void user_enable_single_step(struct task_struct *task) |
1da177e4 | 99 | { |
5e9a2692 MS |
100 | set_tsk_thread_flag(task, TIF_SINGLE_STEP); |
101 | if (task == current) | |
102 | update_per_regs(task); | |
1da177e4 LT |
103 | } |
104 | ||
0ac30be4 | 105 | void user_disable_single_step(struct task_struct *task) |
1da177e4 | 106 | { |
5e9a2692 MS |
107 | clear_tsk_thread_flag(task, TIF_SINGLE_STEP); |
108 | if (task == current) | |
109 | update_per_regs(task); | |
1da177e4 LT |
110 | } |
111 | ||
112 | /* | |
113 | * Called by kernel/ptrace.c when detaching.. | |
114 | * | |
5e9a2692 | 115 | * Clear all debugging related fields. |
1da177e4 | 116 | */ |
5e9a2692 | 117 | void ptrace_disable(struct task_struct *task) |
1da177e4 | 118 | { |
5e9a2692 MS |
119 | memset(&task->thread.per_user, 0, sizeof(task->thread.per_user)); |
120 | memset(&task->thread.per_event, 0, sizeof(task->thread.per_event)); | |
121 | clear_tsk_thread_flag(task, TIF_SINGLE_STEP); | |
122 | clear_tsk_thread_flag(task, TIF_PER_TRAP); | |
d35339a4 | 123 | task->thread.per_flags = 0; |
1da177e4 LT |
124 | } |
125 | ||
347a8dc3 | 126 | #ifndef CONFIG_64BIT |
1da177e4 LT |
127 | # define __ADDR_MASK 3 |
128 | #else | |
129 | # define __ADDR_MASK 7 | |
130 | #endif | |
131 | ||
5e9a2692 MS |
132 | static inline unsigned long __peek_user_per(struct task_struct *child, |
133 | addr_t addr) | |
134 | { | |
135 | struct per_struct_kernel *dummy = NULL; | |
136 | ||
137 | if (addr == (addr_t) &dummy->cr9) | |
138 | /* Control bits of the active per set. */ | |
139 | return test_thread_flag(TIF_SINGLE_STEP) ? | |
140 | PER_EVENT_IFETCH : child->thread.per_user.control; | |
141 | else if (addr == (addr_t) &dummy->cr10) | |
142 | /* Start address of the active per set. */ | |
143 | return test_thread_flag(TIF_SINGLE_STEP) ? | |
144 | 0 : child->thread.per_user.start; | |
145 | else if (addr == (addr_t) &dummy->cr11) | |
146 | /* End address of the active per set. */ | |
147 | return test_thread_flag(TIF_SINGLE_STEP) ? | |
148 | PSW_ADDR_INSN : child->thread.per_user.end; | |
149 | else if (addr == (addr_t) &dummy->bits) | |
150 | /* Single-step bit. */ | |
151 | return test_thread_flag(TIF_SINGLE_STEP) ? | |
152 | (1UL << (BITS_PER_LONG - 1)) : 0; | |
153 | else if (addr == (addr_t) &dummy->starting_addr) | |
154 | /* Start address of the user specified per set. */ | |
155 | return child->thread.per_user.start; | |
156 | else if (addr == (addr_t) &dummy->ending_addr) | |
157 | /* End address of the user specified per set. */ | |
158 | return child->thread.per_user.end; | |
159 | else if (addr == (addr_t) &dummy->perc_atmid) | |
160 | /* PER code, ATMID and AI of the last PER trap */ | |
161 | return (unsigned long) | |
162 | child->thread.per_event.cause << (BITS_PER_LONG - 16); | |
163 | else if (addr == (addr_t) &dummy->address) | |
164 | /* Address of the last PER trap */ | |
165 | return child->thread.per_event.address; | |
166 | else if (addr == (addr_t) &dummy->access_id) | |
167 | /* Access id of the last PER trap */ | |
168 | return (unsigned long) | |
169 | child->thread.per_event.paid << (BITS_PER_LONG - 8); | |
170 | return 0; | |
171 | } | |
172 | ||
1da177e4 LT |
173 | /* |
174 | * Read the word at offset addr from the user area of a process. The | |
175 | * trouble here is that the information is littered over different | |
176 | * locations. The process registers are found on the kernel stack, | |
177 | * the floating point stuff and the trace settings are stored in | |
178 | * the task structure. In addition the different structures in | |
179 | * struct user contain pad bytes that should be read as zeroes. | |
180 | * Lovely... | |
181 | */ | |
63506c41 | 182 | static unsigned long __peek_user(struct task_struct *child, addr_t addr) |
1da177e4 LT |
183 | { |
184 | struct user *dummy = NULL; | |
63506c41 | 185 | addr_t offset, tmp; |
1da177e4 LT |
186 | |
187 | if (addr < (addr_t) &dummy->regs.acrs) { | |
188 | /* | |
189 | * psw and gprs are stored on the stack | |
190 | */ | |
c7584fb6 | 191 | tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr); |
1da177e4 | 192 | if (addr == (addr_t) &dummy->regs.psw.mask) |
b50511e4 | 193 | /* Return a clean psw mask. */ |
d4e81b35 | 194 | tmp = psw_user_bits | (tmp & PSW_MASK_USER); |
1da177e4 LT |
195 | |
196 | } else if (addr < (addr_t) &dummy->regs.orig_gpr2) { | |
197 | /* | |
198 | * access registers are stored in the thread structure | |
199 | */ | |
200 | offset = addr - (addr_t) &dummy->regs.acrs; | |
347a8dc3 | 201 | #ifdef CONFIG_64BIT |
778959db MS |
202 | /* |
203 | * Very special case: old & broken 64 bit gdb reading | |
204 | * from acrs[15]. Result is a 64 bit value. Read the | |
205 | * 32 bit acrs[15] value and shift it by 32. Sick... | |
206 | */ | |
207 | if (addr == (addr_t) &dummy->regs.acrs[15]) | |
208 | tmp = ((unsigned long) child->thread.acrs[15]) << 32; | |
209 | else | |
210 | #endif | |
1da177e4 LT |
211 | tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset); |
212 | ||
213 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | |
214 | /* | |
215 | * orig_gpr2 is stored on the kernel stack | |
216 | */ | |
c7584fb6 | 217 | tmp = (addr_t) task_pt_regs(child)->orig_gpr2; |
1da177e4 | 218 | |
3d6e48f4 JW |
219 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
220 | /* | |
221 | * prevent reads of padding hole between | |
222 | * orig_gpr2 and fp_regs on s390. | |
223 | */ | |
224 | tmp = 0; | |
225 | ||
1da177e4 LT |
226 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
227 | /* | |
228 | * floating point regs. are stored in the thread structure | |
229 | */ | |
230 | offset = addr - (addr_t) &dummy->regs.fp_regs; | |
231 | tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset); | |
778959db MS |
232 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
233 | tmp &= (unsigned long) FPC_VALID_MASK | |
234 | << (BITS_PER_LONG - 32); | |
1da177e4 LT |
235 | |
236 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | |
237 | /* | |
5e9a2692 | 238 | * Handle access to the per_info structure. |
1da177e4 | 239 | */ |
5e9a2692 MS |
240 | addr -= (addr_t) &dummy->regs.per_info; |
241 | tmp = __peek_user_per(child, addr); | |
1da177e4 LT |
242 | |
243 | } else | |
244 | tmp = 0; | |
245 | ||
63506c41 | 246 | return tmp; |
1da177e4 LT |
247 | } |
248 | ||
1da177e4 | 249 | static int |
63506c41 | 250 | peek_user(struct task_struct *child, addr_t addr, addr_t data) |
1da177e4 | 251 | { |
63506c41 | 252 | addr_t tmp, mask; |
1da177e4 LT |
253 | |
254 | /* | |
255 | * Stupid gdb peeks/pokes the access registers in 64 bit with | |
63506c41 | 256 | * an alignment of 4. Programmers from hell... |
1da177e4 | 257 | */ |
778959db | 258 | mask = __ADDR_MASK; |
347a8dc3 | 259 | #ifdef CONFIG_64BIT |
547e3cec MS |
260 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
261 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) | |
778959db MS |
262 | mask = 3; |
263 | #endif | |
264 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) | |
1da177e4 LT |
265 | return -EIO; |
266 | ||
63506c41 MS |
267 | tmp = __peek_user(child, addr); |
268 | return put_user(tmp, (addr_t __user *) data); | |
269 | } | |
270 | ||
5e9a2692 MS |
271 | static inline void __poke_user_per(struct task_struct *child, |
272 | addr_t addr, addr_t data) | |
273 | { | |
274 | struct per_struct_kernel *dummy = NULL; | |
275 | ||
276 | /* | |
277 | * There are only three fields in the per_info struct that the | |
278 | * debugger user can write to. | |
279 | * 1) cr9: the debugger wants to set a new PER event mask | |
280 | * 2) starting_addr: the debugger wants to set a new starting | |
281 | * address to use with the PER event mask. | |
282 | * 3) ending_addr: the debugger wants to set a new ending | |
283 | * address to use with the PER event mask. | |
284 | * The user specified PER event mask and the start and end | |
285 | * addresses are used only if single stepping is not in effect. | |
286 | * Writes to any other field in per_info are ignored. | |
287 | */ | |
288 | if (addr == (addr_t) &dummy->cr9) | |
289 | /* PER event mask of the user specified per set. */ | |
290 | child->thread.per_user.control = | |
291 | data & (PER_EVENT_MASK | PER_CONTROL_MASK); | |
292 | else if (addr == (addr_t) &dummy->starting_addr) | |
293 | /* Starting address of the user specified per set. */ | |
294 | child->thread.per_user.start = data; | |
295 | else if (addr == (addr_t) &dummy->ending_addr) | |
296 | /* Ending address of the user specified per set. */ | |
297 | child->thread.per_user.end = data; | |
298 | } | |
299 | ||
63506c41 MS |
300 | /* |
301 | * Write a word to the user area of a process at location addr. This | |
302 | * operation does have an additional problem compared to peek_user. | |
303 | * Stores to the program status word and on the floating point | |
304 | * control register needs to get checked for validity. | |
305 | */ | |
306 | static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) | |
307 | { | |
308 | struct user *dummy = NULL; | |
d4e81b35 | 309 | addr_t offset; |
63506c41 | 310 | |
1da177e4 LT |
311 | if (addr < (addr_t) &dummy->regs.acrs) { |
312 | /* | |
313 | * psw and gprs are stored on the stack | |
314 | */ | |
315 | if (addr == (addr_t) &dummy->regs.psw.mask && | |
d4e81b35 MS |
316 | ((data & ~PSW_MASK_USER) != psw_user_bits || |
317 | ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA)))) | |
1da177e4 LT |
318 | /* Invalid psw mask. */ |
319 | return -EINVAL; | |
c7584fb6 | 320 | *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; |
1da177e4 LT |
321 | |
322 | } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { | |
323 | /* | |
324 | * access registers are stored in the thread structure | |
325 | */ | |
326 | offset = addr - (addr_t) &dummy->regs.acrs; | |
347a8dc3 | 327 | #ifdef CONFIG_64BIT |
778959db MS |
328 | /* |
329 | * Very special case: old & broken 64 bit gdb writing | |
330 | * to acrs[15] with a 64 bit value. Ignore the lower | |
331 | * half of the value and write the upper 32 bit to | |
332 | * acrs[15]. Sick... | |
333 | */ | |
334 | if (addr == (addr_t) &dummy->regs.acrs[15]) | |
335 | child->thread.acrs[15] = (unsigned int) (data >> 32); | |
336 | else | |
337 | #endif | |
1da177e4 LT |
338 | *(addr_t *)((addr_t) &child->thread.acrs + offset) = data; |
339 | ||
340 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { | |
341 | /* | |
342 | * orig_gpr2 is stored on the kernel stack | |
343 | */ | |
c7584fb6 | 344 | task_pt_regs(child)->orig_gpr2 = data; |
1da177e4 | 345 | |
3d6e48f4 JW |
346 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
347 | /* | |
348 | * prevent writes of padding hole between | |
349 | * orig_gpr2 and fp_regs on s390. | |
350 | */ | |
351 | return 0; | |
352 | ||
1da177e4 LT |
353 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
354 | /* | |
355 | * floating point regs. are stored in the thread structure | |
356 | */ | |
357 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc && | |
778959db MS |
358 | (data & ~((unsigned long) FPC_VALID_MASK |
359 | << (BITS_PER_LONG - 32))) != 0) | |
1da177e4 LT |
360 | return -EINVAL; |
361 | offset = addr - (addr_t) &dummy->regs.fp_regs; | |
362 | *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data; | |
363 | ||
364 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | |
365 | /* | |
5e9a2692 | 366 | * Handle access to the per_info structure. |
1da177e4 | 367 | */ |
5e9a2692 MS |
368 | addr -= (addr_t) &dummy->regs.per_info; |
369 | __poke_user_per(child, addr, data); | |
1da177e4 LT |
370 | |
371 | } | |
372 | ||
1da177e4 LT |
373 | return 0; |
374 | } | |
375 | ||
5e9a2692 | 376 | static int poke_user(struct task_struct *child, addr_t addr, addr_t data) |
63506c41 | 377 | { |
63506c41 MS |
378 | addr_t mask; |
379 | ||
380 | /* | |
381 | * Stupid gdb peeks/pokes the access registers in 64 bit with | |
382 | * an alignment of 4. Programmers from hell indeed... | |
383 | */ | |
384 | mask = __ADDR_MASK; | |
385 | #ifdef CONFIG_64BIT | |
547e3cec MS |
386 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
387 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) | |
63506c41 MS |
388 | mask = 3; |
389 | #endif | |
390 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) | |
391 | return -EIO; | |
392 | ||
393 | return __poke_user(child, addr, data); | |
394 | } | |
395 | ||
9b05a69e NK |
396 | long arch_ptrace(struct task_struct *child, long request, |
397 | unsigned long addr, unsigned long data) | |
1da177e4 | 398 | { |
1da177e4 LT |
399 | ptrace_area parea; |
400 | int copied, ret; | |
401 | ||
402 | switch (request) { | |
1da177e4 LT |
403 | case PTRACE_PEEKUSR: |
404 | /* read the word at location addr in the USER area. */ | |
405 | return peek_user(child, addr, data); | |
406 | ||
1da177e4 LT |
407 | case PTRACE_POKEUSR: |
408 | /* write the word at location addr in the USER area */ | |
409 | return poke_user(child, addr, data); | |
410 | ||
411 | case PTRACE_PEEKUSR_AREA: | |
412 | case PTRACE_POKEUSR_AREA: | |
2b67fc46 | 413 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
414 | sizeof(parea))) |
415 | return -EFAULT; | |
416 | addr = parea.kernel_addr; | |
417 | data = parea.process_addr; | |
418 | copied = 0; | |
419 | while (copied < parea.len) { | |
420 | if (request == PTRACE_PEEKUSR_AREA) | |
421 | ret = peek_user(child, addr, data); | |
422 | else { | |
2b67fc46 HC |
423 | addr_t utmp; |
424 | if (get_user(utmp, | |
425 | (addr_t __force __user *) data)) | |
1da177e4 | 426 | return -EFAULT; |
2b67fc46 | 427 | ret = poke_user(child, addr, utmp); |
1da177e4 LT |
428 | } |
429 | if (ret) | |
430 | return ret; | |
431 | addr += sizeof(unsigned long); | |
432 | data += sizeof(unsigned long); | |
433 | copied += sizeof(unsigned long); | |
434 | } | |
435 | return 0; | |
86f2552b MS |
436 | case PTRACE_GET_LAST_BREAK: |
437 | put_user(task_thread_info(child)->last_break, | |
438 | (unsigned long __user *) data); | |
439 | return 0; | |
d35339a4 MS |
440 | case PTRACE_ENABLE_TE: |
441 | if (!MACHINE_HAS_TE) | |
442 | return -EIO; | |
443 | child->thread.per_flags &= ~PER_FLAG_NO_TE; | |
444 | return 0; | |
445 | case PTRACE_DISABLE_TE: | |
446 | if (!MACHINE_HAS_TE) | |
447 | return -EIO; | |
448 | child->thread.per_flags |= PER_FLAG_NO_TE; | |
449 | return 0; | |
07805ac8 CB |
450 | default: |
451 | /* Removing high order bit from addr (only for 31 bit). */ | |
452 | addr &= PSW_ADDR_INSN; | |
453 | return ptrace_request(child, request, addr, data); | |
1da177e4 | 454 | } |
1da177e4 LT |
455 | } |
456 | ||
347a8dc3 | 457 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
458 | /* |
459 | * Now the fun part starts... a 31 bit program running in the | |
460 | * 31 bit emulation tracing another program. PTRACE_PEEKTEXT, | |
461 | * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy | |
462 | * to handle, the difference to the 64 bit versions of the requests | |
463 | * is that the access is done in multiples of 4 byte instead of | |
464 | * 8 bytes (sizeof(unsigned long) on 31/64 bit). | |
465 | * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA, | |
466 | * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program | |
467 | * is a 31 bit program too, the content of struct user can be | |
468 | * emulated. A 31 bit program peeking into the struct user of | |
469 | * a 64 bit program is a no-no. | |
470 | */ | |
471 | ||
5e9a2692 MS |
472 | /* |
473 | * Same as peek_user_per but for a 31 bit program. | |
474 | */ | |
475 | static inline __u32 __peek_user_per_compat(struct task_struct *child, | |
476 | addr_t addr) | |
477 | { | |
478 | struct compat_per_struct_kernel *dummy32 = NULL; | |
479 | ||
480 | if (addr == (addr_t) &dummy32->cr9) | |
481 | /* Control bits of the active per set. */ | |
482 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? | |
483 | PER_EVENT_IFETCH : child->thread.per_user.control; | |
484 | else if (addr == (addr_t) &dummy32->cr10) | |
485 | /* Start address of the active per set. */ | |
486 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? | |
487 | 0 : child->thread.per_user.start; | |
488 | else if (addr == (addr_t) &dummy32->cr11) | |
489 | /* End address of the active per set. */ | |
490 | return test_thread_flag(TIF_SINGLE_STEP) ? | |
491 | PSW32_ADDR_INSN : child->thread.per_user.end; | |
492 | else if (addr == (addr_t) &dummy32->bits) | |
493 | /* Single-step bit. */ | |
494 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? | |
495 | 0x80000000 : 0; | |
496 | else if (addr == (addr_t) &dummy32->starting_addr) | |
497 | /* Start address of the user specified per set. */ | |
498 | return (__u32) child->thread.per_user.start; | |
499 | else if (addr == (addr_t) &dummy32->ending_addr) | |
500 | /* End address of the user specified per set. */ | |
501 | return (__u32) child->thread.per_user.end; | |
502 | else if (addr == (addr_t) &dummy32->perc_atmid) | |
503 | /* PER code, ATMID and AI of the last PER trap */ | |
504 | return (__u32) child->thread.per_event.cause << 16; | |
505 | else if (addr == (addr_t) &dummy32->address) | |
506 | /* Address of the last PER trap */ | |
507 | return (__u32) child->thread.per_event.address; | |
508 | else if (addr == (addr_t) &dummy32->access_id) | |
509 | /* Access id of the last PER trap */ | |
510 | return (__u32) child->thread.per_event.paid << 24; | |
511 | return 0; | |
512 | } | |
513 | ||
1da177e4 LT |
514 | /* |
515 | * Same as peek_user but for a 31 bit program. | |
516 | */ | |
63506c41 | 517 | static u32 __peek_user_compat(struct task_struct *child, addr_t addr) |
1da177e4 | 518 | { |
5e9a2692 | 519 | struct compat_user *dummy32 = NULL; |
1da177e4 LT |
520 | addr_t offset; |
521 | __u32 tmp; | |
522 | ||
1da177e4 | 523 | if (addr < (addr_t) &dummy32->regs.acrs) { |
b50511e4 | 524 | struct pt_regs *regs = task_pt_regs(child); |
1da177e4 LT |
525 | /* |
526 | * psw and gprs are stored on the stack | |
527 | */ | |
528 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | |
529 | /* Fake a 31 bit psw mask. */ | |
b50511e4 MS |
530 | tmp = (__u32)(regs->psw.mask >> 32); |
531 | tmp = psw32_user_bits | (tmp & PSW32_MASK_USER); | |
1da177e4 LT |
532 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
533 | /* Fake a 31 bit psw address. */ | |
d4e81b35 MS |
534 | tmp = (__u32) regs->psw.addr | |
535 | (__u32)(regs->psw.mask & PSW_MASK_BA); | |
1da177e4 LT |
536 | } else { |
537 | /* gpr 0-15 */ | |
b50511e4 | 538 | tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4); |
1da177e4 LT |
539 | } |
540 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | |
541 | /* | |
542 | * access registers are stored in the thread structure | |
543 | */ | |
544 | offset = addr - (addr_t) &dummy32->regs.acrs; | |
545 | tmp = *(__u32*)((addr_t) &child->thread.acrs + offset); | |
546 | ||
547 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | |
548 | /* | |
549 | * orig_gpr2 is stored on the kernel stack | |
550 | */ | |
c7584fb6 | 551 | tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4); |
1da177e4 | 552 | |
3d6e48f4 JW |
553 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
554 | /* | |
555 | * prevent reads of padding hole between | |
556 | * orig_gpr2 and fp_regs on s390. | |
557 | */ | |
558 | tmp = 0; | |
559 | ||
1da177e4 LT |
560 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
561 | /* | |
562 | * floating point regs. are stored in the thread structure | |
563 | */ | |
564 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | |
565 | tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset); | |
566 | ||
567 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | |
568 | /* | |
5e9a2692 | 569 | * Handle access to the per_info structure. |
1da177e4 | 570 | */ |
5e9a2692 MS |
571 | addr -= (addr_t) &dummy32->regs.per_info; |
572 | tmp = __peek_user_per_compat(child, addr); | |
1da177e4 LT |
573 | |
574 | } else | |
575 | tmp = 0; | |
576 | ||
63506c41 MS |
577 | return tmp; |
578 | } | |
579 | ||
580 | static int peek_user_compat(struct task_struct *child, | |
581 | addr_t addr, addr_t data) | |
582 | { | |
583 | __u32 tmp; | |
584 | ||
7757591a | 585 | if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3) |
63506c41 MS |
586 | return -EIO; |
587 | ||
588 | tmp = __peek_user_compat(child, addr); | |
1da177e4 LT |
589 | return put_user(tmp, (__u32 __user *) data); |
590 | } | |
591 | ||
5e9a2692 MS |
592 | /* |
593 | * Same as poke_user_per but for a 31 bit program. | |
594 | */ | |
595 | static inline void __poke_user_per_compat(struct task_struct *child, | |
596 | addr_t addr, __u32 data) | |
597 | { | |
598 | struct compat_per_struct_kernel *dummy32 = NULL; | |
599 | ||
600 | if (addr == (addr_t) &dummy32->cr9) | |
601 | /* PER event mask of the user specified per set. */ | |
602 | child->thread.per_user.control = | |
603 | data & (PER_EVENT_MASK | PER_CONTROL_MASK); | |
604 | else if (addr == (addr_t) &dummy32->starting_addr) | |
605 | /* Starting address of the user specified per set. */ | |
606 | child->thread.per_user.start = data; | |
607 | else if (addr == (addr_t) &dummy32->ending_addr) | |
608 | /* Ending address of the user specified per set. */ | |
609 | child->thread.per_user.end = data; | |
610 | } | |
611 | ||
1da177e4 LT |
612 | /* |
613 | * Same as poke_user but for a 31 bit program. | |
614 | */ | |
63506c41 MS |
615 | static int __poke_user_compat(struct task_struct *child, |
616 | addr_t addr, addr_t data) | |
1da177e4 | 617 | { |
5e9a2692 | 618 | struct compat_user *dummy32 = NULL; |
63506c41 | 619 | __u32 tmp = (__u32) data; |
1da177e4 | 620 | addr_t offset; |
1da177e4 LT |
621 | |
622 | if (addr < (addr_t) &dummy32->regs.acrs) { | |
b50511e4 | 623 | struct pt_regs *regs = task_pt_regs(child); |
1da177e4 LT |
624 | /* |
625 | * psw, gprs, acrs and orig_gpr2 are stored on the stack | |
626 | */ | |
627 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | |
628 | /* Build a 64 bit psw mask from 31 bit mask. */ | |
b50511e4 | 629 | if ((tmp & ~PSW32_MASK_USER) != psw32_user_bits) |
1da177e4 LT |
630 | /* Invalid psw mask. */ |
631 | return -EINVAL; | |
b50511e4 | 632 | regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) | |
d4e81b35 | 633 | (regs->psw.mask & PSW_MASK_BA) | |
b50511e4 | 634 | (__u64)(tmp & PSW32_MASK_USER) << 32; |
1da177e4 LT |
635 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
636 | /* Build a 64 bit psw address from 31 bit address. */ | |
b50511e4 | 637 | regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN; |
d4e81b35 MS |
638 | /* Transfer 31 bit amode bit to psw mask. */ |
639 | regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) | | |
640 | (__u64)(tmp & PSW32_ADDR_AMODE); | |
1da177e4 LT |
641 | } else { |
642 | /* gpr 0-15 */ | |
b50511e4 | 643 | *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp; |
1da177e4 LT |
644 | } |
645 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { | |
646 | /* | |
647 | * access registers are stored in the thread structure | |
648 | */ | |
649 | offset = addr - (addr_t) &dummy32->regs.acrs; | |
650 | *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp; | |
651 | ||
652 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { | |
653 | /* | |
654 | * orig_gpr2 is stored on the kernel stack | |
655 | */ | |
c7584fb6 | 656 | *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp; |
1da177e4 | 657 | |
3d6e48f4 JW |
658 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
659 | /* | |
660 | * prevent writess of padding hole between | |
661 | * orig_gpr2 and fp_regs on s390. | |
662 | */ | |
663 | return 0; | |
664 | ||
1da177e4 LT |
665 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
666 | /* | |
667 | * floating point regs. are stored in the thread structure | |
668 | */ | |
669 | if (addr == (addr_t) &dummy32->regs.fp_regs.fpc && | |
670 | (tmp & ~FPC_VALID_MASK) != 0) | |
671 | /* Invalid floating point control. */ | |
672 | return -EINVAL; | |
673 | offset = addr - (addr_t) &dummy32->regs.fp_regs; | |
674 | *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp; | |
675 | ||
676 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { | |
677 | /* | |
5e9a2692 | 678 | * Handle access to the per_info structure. |
1da177e4 | 679 | */ |
5e9a2692 MS |
680 | addr -= (addr_t) &dummy32->regs.per_info; |
681 | __poke_user_per_compat(child, addr, data); | |
1da177e4 LT |
682 | } |
683 | ||
1da177e4 LT |
684 | return 0; |
685 | } | |
686 | ||
63506c41 MS |
687 | static int poke_user_compat(struct task_struct *child, |
688 | addr_t addr, addr_t data) | |
689 | { | |
5e9a2692 MS |
690 | if (!is_compat_task() || (addr & 3) || |
691 | addr > sizeof(struct compat_user) - 3) | |
63506c41 MS |
692 | return -EIO; |
693 | ||
694 | return __poke_user_compat(child, addr, data); | |
695 | } | |
696 | ||
b499d76b RM |
697 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
698 | compat_ulong_t caddr, compat_ulong_t cdata) | |
1da177e4 | 699 | { |
b499d76b RM |
700 | unsigned long addr = caddr; |
701 | unsigned long data = cdata; | |
5e9a2692 | 702 | compat_ptrace_area parea; |
1da177e4 LT |
703 | int copied, ret; |
704 | ||
705 | switch (request) { | |
1da177e4 LT |
706 | case PTRACE_PEEKUSR: |
707 | /* read the word at location addr in the USER area. */ | |
63506c41 | 708 | return peek_user_compat(child, addr, data); |
1da177e4 | 709 | |
1da177e4 LT |
710 | case PTRACE_POKEUSR: |
711 | /* write the word at location addr in the USER area */ | |
63506c41 | 712 | return poke_user_compat(child, addr, data); |
1da177e4 LT |
713 | |
714 | case PTRACE_PEEKUSR_AREA: | |
715 | case PTRACE_POKEUSR_AREA: | |
2b67fc46 | 716 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
717 | sizeof(parea))) |
718 | return -EFAULT; | |
719 | addr = parea.kernel_addr; | |
720 | data = parea.process_addr; | |
721 | copied = 0; | |
722 | while (copied < parea.len) { | |
723 | if (request == PTRACE_PEEKUSR_AREA) | |
63506c41 | 724 | ret = peek_user_compat(child, addr, data); |
1da177e4 | 725 | else { |
2b67fc46 HC |
726 | __u32 utmp; |
727 | if (get_user(utmp, | |
728 | (__u32 __force __user *) data)) | |
1da177e4 | 729 | return -EFAULT; |
63506c41 | 730 | ret = poke_user_compat(child, addr, utmp); |
1da177e4 LT |
731 | } |
732 | if (ret) | |
733 | return ret; | |
734 | addr += sizeof(unsigned int); | |
735 | data += sizeof(unsigned int); | |
736 | copied += sizeof(unsigned int); | |
737 | } | |
738 | return 0; | |
86f2552b MS |
739 | case PTRACE_GET_LAST_BREAK: |
740 | put_user(task_thread_info(child)->last_break, | |
741 | (unsigned int __user *) data); | |
742 | return 0; | |
1da177e4 | 743 | } |
b499d76b | 744 | return compat_ptrace_request(child, request, addr, data); |
1da177e4 LT |
745 | } |
746 | #endif | |
747 | ||
753c4dd6 | 748 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) |
1da177e4 | 749 | { |
545c174d | 750 | long ret = 0; |
1da177e4 | 751 | |
bcf5cef7 | 752 | /* Do the secure computing check first. */ |
c63cb468 HC |
753 | if (secure_computing(regs->gprs[2])) { |
754 | /* seccomp failures shouldn't expose any additional code. */ | |
755 | ret = -1; | |
756 | goto out; | |
757 | } | |
bcf5cef7 | 758 | |
c5c3a6d8 | 759 | /* |
753c4dd6 MS |
760 | * The sysc_tracesys code in entry.S stored the system |
761 | * call number to gprs[2]. | |
c5c3a6d8 | 762 | */ |
753c4dd6 MS |
763 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
764 | (tracehook_report_syscall_entry(regs) || | |
765 | regs->gprs[2] >= NR_syscalls)) { | |
766 | /* | |
767 | * Tracing decided this syscall should not happen or the | |
768 | * debugger stored an invalid system call number. Skip | |
769 | * the system call and the system call restart handling. | |
770 | */ | |
b6ef5bb3 | 771 | clear_thread_flag(TIF_SYSCALL); |
753c4dd6 | 772 | ret = -1; |
1da177e4 | 773 | } |
753c4dd6 | 774 | |
66700001 | 775 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
1c569f02 | 776 | trace_sys_enter(regs, regs->gprs[2]); |
9bf1226b | 777 | |
b05d8447 EP |
778 | audit_syscall_entry(is_compat_task() ? |
779 | AUDIT_ARCH_S390 : AUDIT_ARCH_S390X, | |
780 | regs->gprs[2], regs->orig_gpr2, | |
781 | regs->gprs[3], regs->gprs[4], | |
782 | regs->gprs[5]); | |
c63cb468 | 783 | out: |
545c174d | 784 | return ret ?: regs->gprs[2]; |
753c4dd6 MS |
785 | } |
786 | ||
787 | asmlinkage void do_syscall_trace_exit(struct pt_regs *regs) | |
788 | { | |
d7e7528b | 789 | audit_syscall_exit(regs); |
753c4dd6 | 790 | |
66700001 | 791 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
1c569f02 | 792 | trace_sys_exit(regs, regs->gprs[2]); |
9bf1226b | 793 | |
753c4dd6 MS |
794 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
795 | tracehook_report_syscall_exit(regs, 0); | |
1da177e4 | 796 | } |
63506c41 MS |
797 | |
798 | /* | |
799 | * user_regset definitions. | |
800 | */ | |
801 | ||
802 | static int s390_regs_get(struct task_struct *target, | |
803 | const struct user_regset *regset, | |
804 | unsigned int pos, unsigned int count, | |
805 | void *kbuf, void __user *ubuf) | |
806 | { | |
807 | if (target == current) | |
808 | save_access_regs(target->thread.acrs); | |
809 | ||
810 | if (kbuf) { | |
811 | unsigned long *k = kbuf; | |
812 | while (count > 0) { | |
813 | *k++ = __peek_user(target, pos); | |
814 | count -= sizeof(*k); | |
815 | pos += sizeof(*k); | |
816 | } | |
817 | } else { | |
818 | unsigned long __user *u = ubuf; | |
819 | while (count > 0) { | |
820 | if (__put_user(__peek_user(target, pos), u++)) | |
821 | return -EFAULT; | |
822 | count -= sizeof(*u); | |
823 | pos += sizeof(*u); | |
824 | } | |
825 | } | |
826 | return 0; | |
827 | } | |
828 | ||
829 | static int s390_regs_set(struct task_struct *target, | |
830 | const struct user_regset *regset, | |
831 | unsigned int pos, unsigned int count, | |
832 | const void *kbuf, const void __user *ubuf) | |
833 | { | |
834 | int rc = 0; | |
835 | ||
836 | if (target == current) | |
837 | save_access_regs(target->thread.acrs); | |
838 | ||
839 | if (kbuf) { | |
840 | const unsigned long *k = kbuf; | |
841 | while (count > 0 && !rc) { | |
842 | rc = __poke_user(target, pos, *k++); | |
843 | count -= sizeof(*k); | |
844 | pos += sizeof(*k); | |
845 | } | |
846 | } else { | |
847 | const unsigned long __user *u = ubuf; | |
848 | while (count > 0 && !rc) { | |
849 | unsigned long word; | |
850 | rc = __get_user(word, u++); | |
851 | if (rc) | |
852 | break; | |
853 | rc = __poke_user(target, pos, word); | |
854 | count -= sizeof(*u); | |
855 | pos += sizeof(*u); | |
856 | } | |
857 | } | |
858 | ||
859 | if (rc == 0 && target == current) | |
860 | restore_access_regs(target->thread.acrs); | |
861 | ||
862 | return rc; | |
863 | } | |
864 | ||
865 | static int s390_fpregs_get(struct task_struct *target, | |
866 | const struct user_regset *regset, unsigned int pos, | |
867 | unsigned int count, void *kbuf, void __user *ubuf) | |
868 | { | |
869 | if (target == current) | |
870 | save_fp_regs(&target->thread.fp_regs); | |
871 | ||
872 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
873 | &target->thread.fp_regs, 0, -1); | |
874 | } | |
875 | ||
876 | static int s390_fpregs_set(struct task_struct *target, | |
877 | const struct user_regset *regset, unsigned int pos, | |
878 | unsigned int count, const void *kbuf, | |
879 | const void __user *ubuf) | |
880 | { | |
881 | int rc = 0; | |
882 | ||
883 | if (target == current) | |
884 | save_fp_regs(&target->thread.fp_regs); | |
885 | ||
886 | /* If setting FPC, must validate it first. */ | |
887 | if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) { | |
888 | u32 fpc[2] = { target->thread.fp_regs.fpc, 0 }; | |
889 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc, | |
890 | 0, offsetof(s390_fp_regs, fprs)); | |
891 | if (rc) | |
892 | return rc; | |
893 | if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0) | |
894 | return -EINVAL; | |
895 | target->thread.fp_regs.fpc = fpc[0]; | |
896 | } | |
897 | ||
898 | if (rc == 0 && count > 0) | |
899 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
900 | target->thread.fp_regs.fprs, | |
901 | offsetof(s390_fp_regs, fprs), -1); | |
902 | ||
903 | if (rc == 0 && target == current) | |
904 | restore_fp_regs(&target->thread.fp_regs); | |
905 | ||
906 | return rc; | |
907 | } | |
908 | ||
86f2552b MS |
909 | #ifdef CONFIG_64BIT |
910 | ||
911 | static int s390_last_break_get(struct task_struct *target, | |
912 | const struct user_regset *regset, | |
913 | unsigned int pos, unsigned int count, | |
914 | void *kbuf, void __user *ubuf) | |
915 | { | |
916 | if (count > 0) { | |
917 | if (kbuf) { | |
918 | unsigned long *k = kbuf; | |
919 | *k = task_thread_info(target)->last_break; | |
920 | } else { | |
921 | unsigned long __user *u = ubuf; | |
922 | if (__put_user(task_thread_info(target)->last_break, u)) | |
923 | return -EFAULT; | |
924 | } | |
925 | } | |
926 | return 0; | |
927 | } | |
928 | ||
b934069c MS |
929 | static int s390_last_break_set(struct task_struct *target, |
930 | const struct user_regset *regset, | |
931 | unsigned int pos, unsigned int count, | |
932 | const void *kbuf, const void __user *ubuf) | |
933 | { | |
934 | return 0; | |
935 | } | |
936 | ||
d35339a4 MS |
937 | static int s390_tdb_get(struct task_struct *target, |
938 | const struct user_regset *regset, | |
939 | unsigned int pos, unsigned int count, | |
940 | void *kbuf, void __user *ubuf) | |
941 | { | |
942 | struct pt_regs *regs = task_pt_regs(target); | |
943 | unsigned char *data; | |
944 | ||
945 | if (!(regs->int_code & 0x200)) | |
946 | return -ENODATA; | |
947 | data = target->thread.trap_tdb; | |
948 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256); | |
949 | } | |
950 | ||
951 | static int s390_tdb_set(struct task_struct *target, | |
952 | const struct user_regset *regset, | |
953 | unsigned int pos, unsigned int count, | |
954 | const void *kbuf, const void __user *ubuf) | |
955 | { | |
956 | return 0; | |
957 | } | |
958 | ||
86f2552b MS |
959 | #endif |
960 | ||
20b40a79 MS |
961 | static int s390_system_call_get(struct task_struct *target, |
962 | const struct user_regset *regset, | |
963 | unsigned int pos, unsigned int count, | |
964 | void *kbuf, void __user *ubuf) | |
965 | { | |
966 | unsigned int *data = &task_thread_info(target)->system_call; | |
967 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | |
968 | data, 0, sizeof(unsigned int)); | |
969 | } | |
970 | ||
971 | static int s390_system_call_set(struct task_struct *target, | |
972 | const struct user_regset *regset, | |
973 | unsigned int pos, unsigned int count, | |
974 | const void *kbuf, const void __user *ubuf) | |
975 | { | |
976 | unsigned int *data = &task_thread_info(target)->system_call; | |
977 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, | |
978 | data, 0, sizeof(unsigned int)); | |
979 | } | |
980 | ||
63506c41 MS |
981 | static const struct user_regset s390_regsets[] = { |
982 | [REGSET_GENERAL] = { | |
983 | .core_note_type = NT_PRSTATUS, | |
984 | .n = sizeof(s390_regs) / sizeof(long), | |
985 | .size = sizeof(long), | |
986 | .align = sizeof(long), | |
987 | .get = s390_regs_get, | |
988 | .set = s390_regs_set, | |
989 | }, | |
990 | [REGSET_FP] = { | |
991 | .core_note_type = NT_PRFPREG, | |
992 | .n = sizeof(s390_fp_regs) / sizeof(long), | |
993 | .size = sizeof(long), | |
994 | .align = sizeof(long), | |
995 | .get = s390_fpregs_get, | |
996 | .set = s390_fpregs_set, | |
997 | }, | |
86f2552b MS |
998 | #ifdef CONFIG_64BIT |
999 | [REGSET_LAST_BREAK] = { | |
1000 | .core_note_type = NT_S390_LAST_BREAK, | |
1001 | .n = 1, | |
1002 | .size = sizeof(long), | |
1003 | .align = sizeof(long), | |
1004 | .get = s390_last_break_get, | |
b934069c | 1005 | .set = s390_last_break_set, |
86f2552b | 1006 | }, |
d35339a4 MS |
1007 | [REGSET_TDB] = { |
1008 | .core_note_type = NT_S390_TDB, | |
1009 | .n = 1, | |
1010 | .size = 256, | |
1011 | .align = 1, | |
1012 | .get = s390_tdb_get, | |
1013 | .set = s390_tdb_set, | |
1014 | }, | |
86f2552b | 1015 | #endif |
20b40a79 MS |
1016 | [REGSET_SYSTEM_CALL] = { |
1017 | .core_note_type = NT_S390_SYSTEM_CALL, | |
1018 | .n = 1, | |
1019 | .size = sizeof(unsigned int), | |
1020 | .align = sizeof(unsigned int), | |
1021 | .get = s390_system_call_get, | |
1022 | .set = s390_system_call_set, | |
1023 | }, | |
63506c41 MS |
1024 | }; |
1025 | ||
1026 | static const struct user_regset_view user_s390_view = { | |
1027 | .name = UTS_MACHINE, | |
1028 | .e_machine = EM_S390, | |
1029 | .regsets = s390_regsets, | |
1030 | .n = ARRAY_SIZE(s390_regsets) | |
1031 | }; | |
1032 | ||
1033 | #ifdef CONFIG_COMPAT | |
1034 | static int s390_compat_regs_get(struct task_struct *target, | |
1035 | const struct user_regset *regset, | |
1036 | unsigned int pos, unsigned int count, | |
1037 | void *kbuf, void __user *ubuf) | |
1038 | { | |
1039 | if (target == current) | |
1040 | save_access_regs(target->thread.acrs); | |
1041 | ||
1042 | if (kbuf) { | |
1043 | compat_ulong_t *k = kbuf; | |
1044 | while (count > 0) { | |
1045 | *k++ = __peek_user_compat(target, pos); | |
1046 | count -= sizeof(*k); | |
1047 | pos += sizeof(*k); | |
1048 | } | |
1049 | } else { | |
1050 | compat_ulong_t __user *u = ubuf; | |
1051 | while (count > 0) { | |
1052 | if (__put_user(__peek_user_compat(target, pos), u++)) | |
1053 | return -EFAULT; | |
1054 | count -= sizeof(*u); | |
1055 | pos += sizeof(*u); | |
1056 | } | |
1057 | } | |
1058 | return 0; | |
1059 | } | |
1060 | ||
1061 | static int s390_compat_regs_set(struct task_struct *target, | |
1062 | const struct user_regset *regset, | |
1063 | unsigned int pos, unsigned int count, | |
1064 | const void *kbuf, const void __user *ubuf) | |
1065 | { | |
1066 | int rc = 0; | |
1067 | ||
1068 | if (target == current) | |
1069 | save_access_regs(target->thread.acrs); | |
1070 | ||
1071 | if (kbuf) { | |
1072 | const compat_ulong_t *k = kbuf; | |
1073 | while (count > 0 && !rc) { | |
1074 | rc = __poke_user_compat(target, pos, *k++); | |
1075 | count -= sizeof(*k); | |
1076 | pos += sizeof(*k); | |
1077 | } | |
1078 | } else { | |
1079 | const compat_ulong_t __user *u = ubuf; | |
1080 | while (count > 0 && !rc) { | |
1081 | compat_ulong_t word; | |
1082 | rc = __get_user(word, u++); | |
1083 | if (rc) | |
1084 | break; | |
1085 | rc = __poke_user_compat(target, pos, word); | |
1086 | count -= sizeof(*u); | |
1087 | pos += sizeof(*u); | |
1088 | } | |
1089 | } | |
1090 | ||
1091 | if (rc == 0 && target == current) | |
1092 | restore_access_regs(target->thread.acrs); | |
1093 | ||
1094 | return rc; | |
1095 | } | |
1096 | ||
ea2a4d3a HC |
1097 | static int s390_compat_regs_high_get(struct task_struct *target, |
1098 | const struct user_regset *regset, | |
1099 | unsigned int pos, unsigned int count, | |
1100 | void *kbuf, void __user *ubuf) | |
1101 | { | |
1102 | compat_ulong_t *gprs_high; | |
1103 | ||
1104 | gprs_high = (compat_ulong_t *) | |
1105 | &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)]; | |
1106 | if (kbuf) { | |
1107 | compat_ulong_t *k = kbuf; | |
1108 | while (count > 0) { | |
1109 | *k++ = *gprs_high; | |
1110 | gprs_high += 2; | |
1111 | count -= sizeof(*k); | |
1112 | } | |
1113 | } else { | |
1114 | compat_ulong_t __user *u = ubuf; | |
1115 | while (count > 0) { | |
1116 | if (__put_user(*gprs_high, u++)) | |
1117 | return -EFAULT; | |
1118 | gprs_high += 2; | |
1119 | count -= sizeof(*u); | |
1120 | } | |
1121 | } | |
1122 | return 0; | |
1123 | } | |
1124 | ||
1125 | static int s390_compat_regs_high_set(struct task_struct *target, | |
1126 | const struct user_regset *regset, | |
1127 | unsigned int pos, unsigned int count, | |
1128 | const void *kbuf, const void __user *ubuf) | |
1129 | { | |
1130 | compat_ulong_t *gprs_high; | |
1131 | int rc = 0; | |
1132 | ||
1133 | gprs_high = (compat_ulong_t *) | |
1134 | &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)]; | |
1135 | if (kbuf) { | |
1136 | const compat_ulong_t *k = kbuf; | |
1137 | while (count > 0) { | |
1138 | *gprs_high = *k++; | |
1139 | *gprs_high += 2; | |
1140 | count -= sizeof(*k); | |
1141 | } | |
1142 | } else { | |
1143 | const compat_ulong_t __user *u = ubuf; | |
1144 | while (count > 0 && !rc) { | |
1145 | unsigned long word; | |
1146 | rc = __get_user(word, u++); | |
1147 | if (rc) | |
1148 | break; | |
1149 | *gprs_high = word; | |
1150 | *gprs_high += 2; | |
1151 | count -= sizeof(*u); | |
1152 | } | |
1153 | } | |
1154 | ||
1155 | return rc; | |
1156 | } | |
1157 | ||
86f2552b MS |
1158 | static int s390_compat_last_break_get(struct task_struct *target, |
1159 | const struct user_regset *regset, | |
1160 | unsigned int pos, unsigned int count, | |
1161 | void *kbuf, void __user *ubuf) | |
1162 | { | |
1163 | compat_ulong_t last_break; | |
1164 | ||
1165 | if (count > 0) { | |
1166 | last_break = task_thread_info(target)->last_break; | |
1167 | if (kbuf) { | |
1168 | unsigned long *k = kbuf; | |
1169 | *k = last_break; | |
1170 | } else { | |
1171 | unsigned long __user *u = ubuf; | |
1172 | if (__put_user(last_break, u)) | |
1173 | return -EFAULT; | |
1174 | } | |
1175 | } | |
1176 | return 0; | |
1177 | } | |
1178 | ||
b934069c MS |
1179 | static int s390_compat_last_break_set(struct task_struct *target, |
1180 | const struct user_regset *regset, | |
1181 | unsigned int pos, unsigned int count, | |
1182 | const void *kbuf, const void __user *ubuf) | |
1183 | { | |
1184 | return 0; | |
1185 | } | |
1186 | ||
63506c41 MS |
1187 | static const struct user_regset s390_compat_regsets[] = { |
1188 | [REGSET_GENERAL] = { | |
1189 | .core_note_type = NT_PRSTATUS, | |
1190 | .n = sizeof(s390_compat_regs) / sizeof(compat_long_t), | |
1191 | .size = sizeof(compat_long_t), | |
1192 | .align = sizeof(compat_long_t), | |
1193 | .get = s390_compat_regs_get, | |
1194 | .set = s390_compat_regs_set, | |
1195 | }, | |
1196 | [REGSET_FP] = { | |
1197 | .core_note_type = NT_PRFPREG, | |
1198 | .n = sizeof(s390_fp_regs) / sizeof(compat_long_t), | |
1199 | .size = sizeof(compat_long_t), | |
1200 | .align = sizeof(compat_long_t), | |
1201 | .get = s390_fpregs_get, | |
1202 | .set = s390_fpregs_set, | |
1203 | }, | |
86f2552b MS |
1204 | [REGSET_LAST_BREAK] = { |
1205 | .core_note_type = NT_S390_LAST_BREAK, | |
1206 | .n = 1, | |
1207 | .size = sizeof(long), | |
1208 | .align = sizeof(long), | |
1209 | .get = s390_compat_last_break_get, | |
b934069c | 1210 | .set = s390_compat_last_break_set, |
86f2552b | 1211 | }, |
d35339a4 MS |
1212 | [REGSET_TDB] = { |
1213 | .core_note_type = NT_S390_TDB, | |
1214 | .n = 1, | |
1215 | .size = 256, | |
1216 | .align = 1, | |
1217 | .get = s390_tdb_get, | |
1218 | .set = s390_tdb_set, | |
1219 | }, | |
20b40a79 MS |
1220 | [REGSET_SYSTEM_CALL] = { |
1221 | .core_note_type = NT_S390_SYSTEM_CALL, | |
1222 | .n = 1, | |
1223 | .size = sizeof(compat_uint_t), | |
1224 | .align = sizeof(compat_uint_t), | |
1225 | .get = s390_system_call_get, | |
1226 | .set = s390_system_call_set, | |
1227 | }, | |
ea2a4d3a | 1228 | [REGSET_GENERAL_EXTENDED] = { |
622e99bf | 1229 | .core_note_type = NT_S390_HIGH_GPRS, |
ea2a4d3a HC |
1230 | .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t), |
1231 | .size = sizeof(compat_long_t), | |
1232 | .align = sizeof(compat_long_t), | |
1233 | .get = s390_compat_regs_high_get, | |
1234 | .set = s390_compat_regs_high_set, | |
1235 | }, | |
63506c41 MS |
1236 | }; |
1237 | ||
1238 | static const struct user_regset_view user_s390_compat_view = { | |
1239 | .name = "s390", | |
1240 | .e_machine = EM_S390, | |
1241 | .regsets = s390_compat_regsets, | |
1242 | .n = ARRAY_SIZE(s390_compat_regsets) | |
1243 | }; | |
1244 | #endif | |
1245 | ||
1246 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) | |
1247 | { | |
1248 | #ifdef CONFIG_COMPAT | |
1249 | if (test_tsk_thread_flag(task, TIF_31BIT)) | |
1250 | return &user_s390_compat_view; | |
1251 | #endif | |
1252 | return &user_s390_view; | |
1253 | } | |
952974ac HC |
1254 | |
1255 | static const char *gpr_names[NUM_GPRS] = { | |
1256 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
1257 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
1258 | }; | |
1259 | ||
1260 | unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset) | |
1261 | { | |
1262 | if (offset >= NUM_GPRS) | |
1263 | return 0; | |
1264 | return regs->gprs[offset]; | |
1265 | } | |
1266 | ||
1267 | int regs_query_register_offset(const char *name) | |
1268 | { | |
1269 | unsigned long offset; | |
1270 | ||
1271 | if (!name || *name != 'r') | |
1272 | return -EINVAL; | |
1273 | if (strict_strtoul(name + 1, 10, &offset)) | |
1274 | return -EINVAL; | |
1275 | if (offset >= NUM_GPRS) | |
1276 | return -EINVAL; | |
1277 | return offset; | |
1278 | } | |
1279 | ||
1280 | const char *regs_query_register_name(unsigned int offset) | |
1281 | { | |
1282 | if (offset >= NUM_GPRS) | |
1283 | return NULL; | |
1284 | return gpr_names[offset]; | |
1285 | } | |
1286 | ||
1287 | static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr) | |
1288 | { | |
1289 | unsigned long ksp = kernel_stack_pointer(regs); | |
1290 | ||
1291 | return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1)); | |
1292 | } | |
1293 | ||
1294 | /** | |
1295 | * regs_get_kernel_stack_nth() - get Nth entry of the stack | |
1296 | * @regs:pt_regs which contains kernel stack pointer. | |
1297 | * @n:stack entry number. | |
1298 | * | |
1299 | * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which | |
1300 | * is specifined by @regs. If the @n th entry is NOT in the kernel stack, | |
1301 | * this returns 0. | |
1302 | */ | |
1303 | unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n) | |
1304 | { | |
1305 | unsigned long addr; | |
1306 | ||
1307 | addr = kernel_stack_pointer(regs) + n * sizeof(long); | |
1308 | if (!regs_within_kernel_stack(regs, addr)) | |
1309 | return 0; | |
1310 | return *(unsigned long *)addr; | |
1311 | } |