2 * Ptrace user space interface.
4 * Copyright IBM Corp. 1999, 2010
5 * Author(s): Denis Joseph Barrow
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
12 #include <linux/smp.h>
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>
18 #include <linux/signal.h>
19 #include <linux/elf.h>
20 #include <linux/regset.h>
21 #include <linux/tracehook.h>
22 #include <linux/seccomp.h>
23 #include <linux/compat.h>
24 #include <trace/syscall.h>
25 #include <asm/segment.h>
27 #include <asm/pgtable.h>
28 #include <asm/pgalloc.h>
29 #include <asm/uaccess.h>
30 #include <asm/unistd.h>
31 #include <asm/switch_to.h>
35 #include "compat_ptrace.h"
38 #define CREATE_TRACE_POINTS
39 #include <trace/events/syscalls.h>
41 void update_cr_regs(struct task_struct *task)
43 struct pt_regs *regs = task_pt_regs(task);
44 struct thread_struct *thread = &task->thread;
45 struct per_regs old, new;
48 /* Take care of the enable/disable of transactional execution. */
49 if (MACHINE_HAS_TE || MACHINE_HAS_VX) {
50 unsigned long cr, cr_new;
52 __ctl_store(cr, 0, 0);
55 /* Set or clear transaction execution TXC bit 8. */
56 cr_new |= (1UL << 55);
57 if (task->thread.per_flags & PER_FLAG_NO_TE)
58 cr_new &= ~(1UL << 55);
61 /* Enable/disable of vector extension */
62 cr_new &= ~(1UL << 17);
63 if (task->thread.vxrs)
64 cr_new |= (1UL << 17);
67 __ctl_load(cr_new, 0, 0);
69 /* Set/clear transaction execution TDC bits 62/63. */
70 __ctl_store(cr, 2, 2);
72 if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) {
73 if (task->thread.per_flags &
74 PER_FLAG_TE_ABORT_RAND_TEND)
80 __ctl_load(cr_new, 2, 2);
84 /* Copy user specified PER registers */
85 new.control = thread->per_user.control;
86 new.start = thread->per_user.start;
87 new.end = thread->per_user.end;
89 /* merge TIF_SINGLE_STEP into user specified PER registers. */
90 if (test_tsk_thread_flag(task, TIF_SINGLE_STEP) ||
91 test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP)) {
92 if (test_tsk_thread_flag(task, TIF_BLOCK_STEP))
93 new.control |= PER_EVENT_BRANCH;
95 new.control |= PER_EVENT_IFETCH;
97 new.control |= PER_CONTROL_SUSPENSION;
98 new.control |= PER_EVENT_TRANSACTION_END;
100 if (test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP))
101 new.control |= PER_EVENT_IFETCH;
103 new.end = PSW_ADDR_INSN;
106 /* Take care of the PER enablement bit in the PSW. */
107 if (!(new.control & PER_EVENT_MASK)) {
108 regs->psw.mask &= ~PSW_MASK_PER;
111 regs->psw.mask |= PSW_MASK_PER;
112 __ctl_store(old, 9, 11);
113 if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
114 __ctl_load(new, 9, 11);
117 void user_enable_single_step(struct task_struct *task)
119 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
120 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
123 void user_disable_single_step(struct task_struct *task)
125 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
126 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
129 void user_enable_block_step(struct task_struct *task)
131 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
132 set_tsk_thread_flag(task, TIF_BLOCK_STEP);
136 * Called by kernel/ptrace.c when detaching..
138 * Clear all debugging related fields.
140 void ptrace_disable(struct task_struct *task)
142 memset(&task->thread.per_user, 0, sizeof(task->thread.per_user));
143 memset(&task->thread.per_event, 0, sizeof(task->thread.per_event));
144 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
145 clear_pt_regs_flag(task_pt_regs(task), PIF_PER_TRAP);
146 task->thread.per_flags = 0;
150 # define __ADDR_MASK 3
152 # define __ADDR_MASK 7
155 static inline unsigned long __peek_user_per(struct task_struct *child,
158 struct per_struct_kernel *dummy = NULL;
160 if (addr == (addr_t) &dummy->cr9)
161 /* Control bits of the active per set. */
162 return test_thread_flag(TIF_SINGLE_STEP) ?
163 PER_EVENT_IFETCH : child->thread.per_user.control;
164 else if (addr == (addr_t) &dummy->cr10)
165 /* Start address of the active per set. */
166 return test_thread_flag(TIF_SINGLE_STEP) ?
167 0 : child->thread.per_user.start;
168 else if (addr == (addr_t) &dummy->cr11)
169 /* End address of the active per set. */
170 return test_thread_flag(TIF_SINGLE_STEP) ?
171 PSW_ADDR_INSN : child->thread.per_user.end;
172 else if (addr == (addr_t) &dummy->bits)
173 /* Single-step bit. */
174 return test_thread_flag(TIF_SINGLE_STEP) ?
175 (1UL << (BITS_PER_LONG - 1)) : 0;
176 else if (addr == (addr_t) &dummy->starting_addr)
177 /* Start address of the user specified per set. */
178 return child->thread.per_user.start;
179 else if (addr == (addr_t) &dummy->ending_addr)
180 /* End address of the user specified per set. */
181 return child->thread.per_user.end;
182 else if (addr == (addr_t) &dummy->perc_atmid)
183 /* PER code, ATMID and AI of the last PER trap */
184 return (unsigned long)
185 child->thread.per_event.cause << (BITS_PER_LONG - 16);
186 else if (addr == (addr_t) &dummy->address)
187 /* Address of the last PER trap */
188 return child->thread.per_event.address;
189 else if (addr == (addr_t) &dummy->access_id)
190 /* Access id of the last PER trap */
191 return (unsigned long)
192 child->thread.per_event.paid << (BITS_PER_LONG - 8);
197 * Read the word at offset addr from the user area of a process. The
198 * trouble here is that the information is littered over different
199 * locations. The process registers are found on the kernel stack,
200 * the floating point stuff and the trace settings are stored in
201 * the task structure. In addition the different structures in
202 * struct user contain pad bytes that should be read as zeroes.
205 static unsigned long __peek_user(struct task_struct *child, addr_t addr)
207 struct user *dummy = NULL;
210 if (addr < (addr_t) &dummy->regs.acrs) {
212 * psw and gprs are stored on the stack
214 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
215 if (addr == (addr_t) &dummy->regs.psw.mask) {
216 /* Return a clean psw mask. */
217 tmp &= PSW_MASK_USER | PSW_MASK_RI;
218 tmp |= PSW_USER_BITS;
221 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
223 * access registers are stored in the thread structure
225 offset = addr - (addr_t) &dummy->regs.acrs;
228 * Very special case: old & broken 64 bit gdb reading
229 * from acrs[15]. Result is a 64 bit value. Read the
230 * 32 bit acrs[15] value and shift it by 32. Sick...
232 if (addr == (addr_t) &dummy->regs.acrs[15])
233 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
236 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
238 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
240 * orig_gpr2 is stored on the kernel stack
242 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
244 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
246 * prevent reads of padding hole between
247 * orig_gpr2 and fp_regs on s390.
251 } else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
253 * floating point control reg. is in the thread structure
255 tmp = child->thread.fp_regs.fpc;
256 tmp <<= BITS_PER_LONG - 32;
258 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
260 * floating point regs. are either in child->thread.fp_regs
261 * or the child->thread.vxrs array
263 offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
265 if (child->thread.vxrs)
267 ((addr_t) child->thread.vxrs + 2*offset);
271 ((addr_t) &child->thread.fp_regs.fprs + offset);
273 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
275 * Handle access to the per_info structure.
277 addr -= (addr_t) &dummy->regs.per_info;
278 tmp = __peek_user_per(child, addr);
287 peek_user(struct task_struct *child, addr_t addr, addr_t data)
292 * Stupid gdb peeks/pokes the access registers in 64 bit with
293 * an alignment of 4. Programmers from hell...
297 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
298 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
301 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
304 tmp = __peek_user(child, addr);
305 return put_user(tmp, (addr_t __user *) data);
308 static inline void __poke_user_per(struct task_struct *child,
309 addr_t addr, addr_t data)
311 struct per_struct_kernel *dummy = NULL;
314 * There are only three fields in the per_info struct that the
315 * debugger user can write to.
316 * 1) cr9: the debugger wants to set a new PER event mask
317 * 2) starting_addr: the debugger wants to set a new starting
318 * address to use with the PER event mask.
319 * 3) ending_addr: the debugger wants to set a new ending
320 * address to use with the PER event mask.
321 * The user specified PER event mask and the start and end
322 * addresses are used only if single stepping is not in effect.
323 * Writes to any other field in per_info are ignored.
325 if (addr == (addr_t) &dummy->cr9)
326 /* PER event mask of the user specified per set. */
327 child->thread.per_user.control =
328 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
329 else if (addr == (addr_t) &dummy->starting_addr)
330 /* Starting address of the user specified per set. */
331 child->thread.per_user.start = data;
332 else if (addr == (addr_t) &dummy->ending_addr)
333 /* Ending address of the user specified per set. */
334 child->thread.per_user.end = data;
338 * Write a word to the user area of a process at location addr. This
339 * operation does have an additional problem compared to peek_user.
340 * Stores to the program status word and on the floating point
341 * control register needs to get checked for validity.
343 static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
345 struct user *dummy = NULL;
348 if (addr < (addr_t) &dummy->regs.acrs) {
350 * psw and gprs are stored on the stack
352 if (addr == (addr_t) &dummy->regs.psw.mask) {
353 unsigned long mask = PSW_MASK_USER;
355 mask |= is_ri_task(child) ? PSW_MASK_RI : 0;
356 if ((data ^ PSW_USER_BITS) & ~mask)
357 /* Invalid psw mask. */
359 if ((data & PSW_MASK_ASC) == PSW_ASC_HOME)
360 /* Invalid address-space-control bits */
362 if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))
363 /* Invalid addressing mode bits */
366 *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
368 } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
370 * access registers are stored in the thread structure
372 offset = addr - (addr_t) &dummy->regs.acrs;
375 * Very special case: old & broken 64 bit gdb writing
376 * to acrs[15] with a 64 bit value. Ignore the lower
377 * half of the value and write the upper 32 bit to
380 if (addr == (addr_t) &dummy->regs.acrs[15])
381 child->thread.acrs[15] = (unsigned int) (data >> 32);
384 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
386 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
388 * orig_gpr2 is stored on the kernel stack
390 task_pt_regs(child)->orig_gpr2 = data;
392 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
394 * prevent writes of padding hole between
395 * orig_gpr2 and fp_regs on s390.
399 } else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
401 * floating point control reg. is in the thread structure
403 if ((unsigned int) data != 0 ||
404 test_fp_ctl(data >> (BITS_PER_LONG - 32)))
406 child->thread.fp_regs.fpc = data >> (BITS_PER_LONG - 32);
408 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
410 * floating point regs. are either in child->thread.fp_regs
411 * or the child->thread.vxrs array
413 offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
415 if (child->thread.vxrs)
417 child->thread.vxrs + 2*offset) = data;
421 &child->thread.fp_regs.fprs + offset) = data;
423 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
425 * Handle access to the per_info structure.
427 addr -= (addr_t) &dummy->regs.per_info;
428 __poke_user_per(child, addr, data);
435 static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
440 * Stupid gdb peeks/pokes the access registers in 64 bit with
441 * an alignment of 4. Programmers from hell indeed...
445 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
446 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
449 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
452 return __poke_user(child, addr, data);
455 long arch_ptrace(struct task_struct *child, long request,
456 unsigned long addr, unsigned long data)
463 /* read the word at location addr in the USER area. */
464 return peek_user(child, addr, data);
467 /* write the word at location addr in the USER area */
468 return poke_user(child, addr, data);
470 case PTRACE_PEEKUSR_AREA:
471 case PTRACE_POKEUSR_AREA:
472 if (copy_from_user(&parea, (void __force __user *) addr,
475 addr = parea.kernel_addr;
476 data = parea.process_addr;
478 while (copied < parea.len) {
479 if (request == PTRACE_PEEKUSR_AREA)
480 ret = peek_user(child, addr, data);
484 (addr_t __force __user *) data))
486 ret = poke_user(child, addr, utmp);
490 addr += sizeof(unsigned long);
491 data += sizeof(unsigned long);
492 copied += sizeof(unsigned long);
495 case PTRACE_GET_LAST_BREAK:
496 put_user(task_thread_info(child)->last_break,
497 (unsigned long __user *) data);
499 case PTRACE_ENABLE_TE:
502 child->thread.per_flags &= ~PER_FLAG_NO_TE;
504 case PTRACE_DISABLE_TE:
507 child->thread.per_flags |= PER_FLAG_NO_TE;
508 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
510 case PTRACE_TE_ABORT_RAND:
511 if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
515 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
518 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
519 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
522 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
523 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
530 /* Removing high order bit from addr (only for 31 bit). */
531 addr &= PSW_ADDR_INSN;
532 return ptrace_request(child, request, addr, data);
538 * Now the fun part starts... a 31 bit program running in the
539 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
540 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
541 * to handle, the difference to the 64 bit versions of the requests
542 * is that the access is done in multiples of 4 byte instead of
543 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
544 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
545 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
546 * is a 31 bit program too, the content of struct user can be
547 * emulated. A 31 bit program peeking into the struct user of
548 * a 64 bit program is a no-no.
552 * Same as peek_user_per but for a 31 bit program.
554 static inline __u32 __peek_user_per_compat(struct task_struct *child,
557 struct compat_per_struct_kernel *dummy32 = NULL;
559 if (addr == (addr_t) &dummy32->cr9)
560 /* Control bits of the active per set. */
561 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
562 PER_EVENT_IFETCH : child->thread.per_user.control;
563 else if (addr == (addr_t) &dummy32->cr10)
564 /* Start address of the active per set. */
565 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
566 0 : child->thread.per_user.start;
567 else if (addr == (addr_t) &dummy32->cr11)
568 /* End address of the active per set. */
569 return test_thread_flag(TIF_SINGLE_STEP) ?
570 PSW32_ADDR_INSN : child->thread.per_user.end;
571 else if (addr == (addr_t) &dummy32->bits)
572 /* Single-step bit. */
573 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
575 else if (addr == (addr_t) &dummy32->starting_addr)
576 /* Start address of the user specified per set. */
577 return (__u32) child->thread.per_user.start;
578 else if (addr == (addr_t) &dummy32->ending_addr)
579 /* End address of the user specified per set. */
580 return (__u32) child->thread.per_user.end;
581 else if (addr == (addr_t) &dummy32->perc_atmid)
582 /* PER code, ATMID and AI of the last PER trap */
583 return (__u32) child->thread.per_event.cause << 16;
584 else if (addr == (addr_t) &dummy32->address)
585 /* Address of the last PER trap */
586 return (__u32) child->thread.per_event.address;
587 else if (addr == (addr_t) &dummy32->access_id)
588 /* Access id of the last PER trap */
589 return (__u32) child->thread.per_event.paid << 24;
594 * Same as peek_user but for a 31 bit program.
596 static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
598 struct compat_user *dummy32 = NULL;
602 if (addr < (addr_t) &dummy32->regs.acrs) {
603 struct pt_regs *regs = task_pt_regs(child);
605 * psw and gprs are stored on the stack
607 if (addr == (addr_t) &dummy32->regs.psw.mask) {
608 /* Fake a 31 bit psw mask. */
609 tmp = (__u32)(regs->psw.mask >> 32);
610 tmp &= PSW32_MASK_USER | PSW32_MASK_RI;
611 tmp |= PSW32_USER_BITS;
612 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
613 /* Fake a 31 bit psw address. */
614 tmp = (__u32) regs->psw.addr |
615 (__u32)(regs->psw.mask & PSW_MASK_BA);
618 tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4);
620 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
622 * access registers are stored in the thread structure
624 offset = addr - (addr_t) &dummy32->regs.acrs;
625 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
627 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
629 * orig_gpr2 is stored on the kernel stack
631 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
633 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
635 * prevent reads of padding hole between
636 * orig_gpr2 and fp_regs on s390.
640 } else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
642 * floating point control reg. is in the thread structure
644 tmp = child->thread.fp_regs.fpc;
646 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
648 * floating point regs. are either in child->thread.fp_regs
649 * or the child->thread.vxrs array
651 offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
653 if (child->thread.vxrs)
655 ((addr_t) child->thread.vxrs + 2*offset);
659 ((addr_t) &child->thread.fp_regs.fprs + offset);
661 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
663 * Handle access to the per_info structure.
665 addr -= (addr_t) &dummy32->regs.per_info;
666 tmp = __peek_user_per_compat(child, addr);
674 static int peek_user_compat(struct task_struct *child,
675 addr_t addr, addr_t data)
679 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
682 tmp = __peek_user_compat(child, addr);
683 return put_user(tmp, (__u32 __user *) data);
687 * Same as poke_user_per but for a 31 bit program.
689 static inline void __poke_user_per_compat(struct task_struct *child,
690 addr_t addr, __u32 data)
692 struct compat_per_struct_kernel *dummy32 = NULL;
694 if (addr == (addr_t) &dummy32->cr9)
695 /* PER event mask of the user specified per set. */
696 child->thread.per_user.control =
697 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
698 else if (addr == (addr_t) &dummy32->starting_addr)
699 /* Starting address of the user specified per set. */
700 child->thread.per_user.start = data;
701 else if (addr == (addr_t) &dummy32->ending_addr)
702 /* Ending address of the user specified per set. */
703 child->thread.per_user.end = data;
707 * Same as poke_user but for a 31 bit program.
709 static int __poke_user_compat(struct task_struct *child,
710 addr_t addr, addr_t data)
712 struct compat_user *dummy32 = NULL;
713 __u32 tmp = (__u32) data;
716 if (addr < (addr_t) &dummy32->regs.acrs) {
717 struct pt_regs *regs = task_pt_regs(child);
719 * psw, gprs, acrs and orig_gpr2 are stored on the stack
721 if (addr == (addr_t) &dummy32->regs.psw.mask) {
722 __u32 mask = PSW32_MASK_USER;
724 mask |= is_ri_task(child) ? PSW32_MASK_RI : 0;
725 /* Build a 64 bit psw mask from 31 bit mask. */
726 if ((tmp ^ PSW32_USER_BITS) & ~mask)
727 /* Invalid psw mask. */
729 if ((data & PSW32_MASK_ASC) == PSW32_ASC_HOME)
730 /* Invalid address-space-control bits */
732 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
733 (regs->psw.mask & PSW_MASK_BA) |
734 (__u64)(tmp & mask) << 32;
735 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
736 /* Build a 64 bit psw address from 31 bit address. */
737 regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
738 /* Transfer 31 bit amode bit to psw mask. */
739 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
740 (__u64)(tmp & PSW32_ADDR_AMODE);
743 *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp;
745 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
747 * access registers are stored in the thread structure
749 offset = addr - (addr_t) &dummy32->regs.acrs;
750 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
752 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
754 * orig_gpr2 is stored on the kernel stack
756 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
758 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
760 * prevent writess of padding hole between
761 * orig_gpr2 and fp_regs on s390.
765 } else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
767 * floating point control reg. is in the thread structure
769 if (test_fp_ctl(tmp))
771 child->thread.fp_regs.fpc = data;
773 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
775 * floating point regs. are either in child->thread.fp_regs
776 * or the child->thread.vxrs array
778 offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
780 if (child->thread.vxrs)
782 child->thread.vxrs + 2*offset) = tmp;
786 &child->thread.fp_regs.fprs + offset) = tmp;
788 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
790 * Handle access to the per_info structure.
792 addr -= (addr_t) &dummy32->regs.per_info;
793 __poke_user_per_compat(child, addr, data);
799 static int poke_user_compat(struct task_struct *child,
800 addr_t addr, addr_t data)
802 if (!is_compat_task() || (addr & 3) ||
803 addr > sizeof(struct compat_user) - 3)
806 return __poke_user_compat(child, addr, data);
809 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
810 compat_ulong_t caddr, compat_ulong_t cdata)
812 unsigned long addr = caddr;
813 unsigned long data = cdata;
814 compat_ptrace_area parea;
819 /* read the word at location addr in the USER area. */
820 return peek_user_compat(child, addr, data);
823 /* write the word at location addr in the USER area */
824 return poke_user_compat(child, addr, data);
826 case PTRACE_PEEKUSR_AREA:
827 case PTRACE_POKEUSR_AREA:
828 if (copy_from_user(&parea, (void __force __user *) addr,
831 addr = parea.kernel_addr;
832 data = parea.process_addr;
834 while (copied < parea.len) {
835 if (request == PTRACE_PEEKUSR_AREA)
836 ret = peek_user_compat(child, addr, data);
840 (__u32 __force __user *) data))
842 ret = poke_user_compat(child, addr, utmp);
846 addr += sizeof(unsigned int);
847 data += sizeof(unsigned int);
848 copied += sizeof(unsigned int);
851 case PTRACE_GET_LAST_BREAK:
852 put_user(task_thread_info(child)->last_break,
853 (unsigned int __user *) data);
856 return compat_ptrace_request(child, request, addr, data);
860 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
864 /* Do the secure computing check first. */
865 if (secure_computing()) {
866 /* seccomp failures shouldn't expose any additional code. */
872 * The sysc_tracesys code in entry.S stored the system
873 * call number to gprs[2].
875 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
876 (tracehook_report_syscall_entry(regs) ||
877 regs->gprs[2] >= NR_syscalls)) {
879 * Tracing decided this syscall should not happen or the
880 * debugger stored an invalid system call number. Skip
881 * the system call and the system call restart handling.
883 clear_pt_regs_flag(regs, PIF_SYSCALL);
887 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
888 trace_sys_enter(regs, regs->gprs[2]);
890 audit_syscall_entry(regs->gprs[2], regs->orig_gpr2,
891 regs->gprs[3], regs->gprs[4],
894 return ret ?: regs->gprs[2];
897 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
899 audit_syscall_exit(regs);
901 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
902 trace_sys_exit(regs, regs->gprs[2]);
904 if (test_thread_flag(TIF_SYSCALL_TRACE))
905 tracehook_report_syscall_exit(regs, 0);
909 * user_regset definitions.
912 static int s390_regs_get(struct task_struct *target,
913 const struct user_regset *regset,
914 unsigned int pos, unsigned int count,
915 void *kbuf, void __user *ubuf)
917 if (target == current)
918 save_access_regs(target->thread.acrs);
921 unsigned long *k = kbuf;
923 *k++ = __peek_user(target, pos);
928 unsigned long __user *u = ubuf;
930 if (__put_user(__peek_user(target, pos), u++))
939 static int s390_regs_set(struct task_struct *target,
940 const struct user_regset *regset,
941 unsigned int pos, unsigned int count,
942 const void *kbuf, const void __user *ubuf)
946 if (target == current)
947 save_access_regs(target->thread.acrs);
950 const unsigned long *k = kbuf;
951 while (count > 0 && !rc) {
952 rc = __poke_user(target, pos, *k++);
957 const unsigned long __user *u = ubuf;
958 while (count > 0 && !rc) {
960 rc = __get_user(word, u++);
963 rc = __poke_user(target, pos, word);
969 if (rc == 0 && target == current)
970 restore_access_regs(target->thread.acrs);
975 static int s390_fpregs_get(struct task_struct *target,
976 const struct user_regset *regset, unsigned int pos,
977 unsigned int count, void *kbuf, void __user *ubuf)
979 if (target == current) {
980 save_fp_ctl(&target->thread.fp_regs.fpc);
981 save_fp_regs(target->thread.fp_regs.fprs);
984 else if (target->thread.vxrs) {
987 for (i = 0; i < __NUM_VXRS_LOW; i++)
988 target->thread.fp_regs.fprs[i] =
989 *(freg_t *)(target->thread.vxrs + i);
992 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
993 &target->thread.fp_regs, 0, -1);
996 static int s390_fpregs_set(struct task_struct *target,
997 const struct user_regset *regset, unsigned int pos,
998 unsigned int count, const void *kbuf,
999 const void __user *ubuf)
1003 if (target == current) {
1004 save_fp_ctl(&target->thread.fp_regs.fpc);
1005 save_fp_regs(target->thread.fp_regs.fprs);
1008 /* If setting FPC, must validate it first. */
1009 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
1010 u32 ufpc[2] = { target->thread.fp_regs.fpc, 0 };
1011 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
1012 0, offsetof(s390_fp_regs, fprs));
1015 if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
1017 target->thread.fp_regs.fpc = ufpc[0];
1020 if (rc == 0 && count > 0)
1021 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1022 target->thread.fp_regs.fprs,
1023 offsetof(s390_fp_regs, fprs), -1);
1026 if (target == current) {
1027 restore_fp_ctl(&target->thread.fp_regs.fpc);
1028 restore_fp_regs(target->thread.fp_regs.fprs);
1031 else if (target->thread.vxrs) {
1034 for (i = 0; i < __NUM_VXRS_LOW; i++)
1035 *(freg_t *)(target->thread.vxrs + i) =
1036 target->thread.fp_regs.fprs[i];
1046 static int s390_last_break_get(struct task_struct *target,
1047 const struct user_regset *regset,
1048 unsigned int pos, unsigned int count,
1049 void *kbuf, void __user *ubuf)
1053 unsigned long *k = kbuf;
1054 *k = task_thread_info(target)->last_break;
1056 unsigned long __user *u = ubuf;
1057 if (__put_user(task_thread_info(target)->last_break, u))
1064 static int s390_last_break_set(struct task_struct *target,
1065 const struct user_regset *regset,
1066 unsigned int pos, unsigned int count,
1067 const void *kbuf, const void __user *ubuf)
1072 static int s390_tdb_get(struct task_struct *target,
1073 const struct user_regset *regset,
1074 unsigned int pos, unsigned int count,
1075 void *kbuf, void __user *ubuf)
1077 struct pt_regs *regs = task_pt_regs(target);
1078 unsigned char *data;
1080 if (!(regs->int_code & 0x200))
1082 data = target->thread.trap_tdb;
1083 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
1086 static int s390_tdb_set(struct task_struct *target,
1087 const struct user_regset *regset,
1088 unsigned int pos, unsigned int count,
1089 const void *kbuf, const void __user *ubuf)
1094 static int s390_vxrs_low_get(struct task_struct *target,
1095 const struct user_regset *regset,
1096 unsigned int pos, unsigned int count,
1097 void *kbuf, void __user *ubuf)
1099 __u64 vxrs[__NUM_VXRS_LOW];
1102 if (!MACHINE_HAS_VX)
1104 if (target->thread.vxrs) {
1105 if (target == current)
1106 save_vx_regs(target->thread.vxrs);
1107 for (i = 0; i < __NUM_VXRS_LOW; i++)
1108 vxrs[i] = *((__u64 *)(target->thread.vxrs + i) + 1);
1110 memset(vxrs, 0, sizeof(vxrs));
1111 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1114 static int s390_vxrs_low_set(struct task_struct *target,
1115 const struct user_regset *regset,
1116 unsigned int pos, unsigned int count,
1117 const void *kbuf, const void __user *ubuf)
1119 __u64 vxrs[__NUM_VXRS_LOW];
1122 if (!MACHINE_HAS_VX)
1124 if (!target->thread.vxrs) {
1125 rc = alloc_vector_registers(target);
1128 } else if (target == current)
1129 save_vx_regs(target->thread.vxrs);
1131 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1133 for (i = 0; i < __NUM_VXRS_LOW; i++)
1134 *((__u64 *)(target->thread.vxrs + i) + 1) = vxrs[i];
1135 if (target == current)
1136 restore_vx_regs(target->thread.vxrs);
1142 static int s390_vxrs_high_get(struct task_struct *target,
1143 const struct user_regset *regset,
1144 unsigned int pos, unsigned int count,
1145 void *kbuf, void __user *ubuf)
1147 __vector128 vxrs[__NUM_VXRS_HIGH];
1149 if (!MACHINE_HAS_VX)
1151 if (target->thread.vxrs) {
1152 if (target == current)
1153 save_vx_regs(target->thread.vxrs);
1154 memcpy(vxrs, target->thread.vxrs + __NUM_VXRS_LOW,
1157 memset(vxrs, 0, sizeof(vxrs));
1158 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1161 static int s390_vxrs_high_set(struct task_struct *target,
1162 const struct user_regset *regset,
1163 unsigned int pos, unsigned int count,
1164 const void *kbuf, const void __user *ubuf)
1168 if (!MACHINE_HAS_VX)
1170 if (!target->thread.vxrs) {
1171 rc = alloc_vector_registers(target);
1174 } else if (target == current)
1175 save_vx_regs(target->thread.vxrs);
1177 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1178 target->thread.vxrs + __NUM_VXRS_LOW, 0, -1);
1179 if (rc == 0 && target == current)
1180 restore_vx_regs(target->thread.vxrs);
1187 static int s390_system_call_get(struct task_struct *target,
1188 const struct user_regset *regset,
1189 unsigned int pos, unsigned int count,
1190 void *kbuf, void __user *ubuf)
1192 unsigned int *data = &task_thread_info(target)->system_call;
1193 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1194 data, 0, sizeof(unsigned int));
1197 static int s390_system_call_set(struct task_struct *target,
1198 const struct user_regset *regset,
1199 unsigned int pos, unsigned int count,
1200 const void *kbuf, const void __user *ubuf)
1202 unsigned int *data = &task_thread_info(target)->system_call;
1203 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1204 data, 0, sizeof(unsigned int));
1207 static const struct user_regset s390_regsets[] = {
1209 .core_note_type = NT_PRSTATUS,
1210 .n = sizeof(s390_regs) / sizeof(long),
1211 .size = sizeof(long),
1212 .align = sizeof(long),
1213 .get = s390_regs_get,
1214 .set = s390_regs_set,
1217 .core_note_type = NT_PRFPREG,
1218 .n = sizeof(s390_fp_regs) / sizeof(long),
1219 .size = sizeof(long),
1220 .align = sizeof(long),
1221 .get = s390_fpregs_get,
1222 .set = s390_fpregs_set,
1225 .core_note_type = NT_S390_SYSTEM_CALL,
1227 .size = sizeof(unsigned int),
1228 .align = sizeof(unsigned int),
1229 .get = s390_system_call_get,
1230 .set = s390_system_call_set,
1234 .core_note_type = NT_S390_LAST_BREAK,
1236 .size = sizeof(long),
1237 .align = sizeof(long),
1238 .get = s390_last_break_get,
1239 .set = s390_last_break_set,
1242 .core_note_type = NT_S390_TDB,
1246 .get = s390_tdb_get,
1247 .set = s390_tdb_set,
1250 .core_note_type = NT_S390_VXRS_LOW,
1251 .n = __NUM_VXRS_LOW,
1252 .size = sizeof(__u64),
1253 .align = sizeof(__u64),
1254 .get = s390_vxrs_low_get,
1255 .set = s390_vxrs_low_set,
1258 .core_note_type = NT_S390_VXRS_HIGH,
1259 .n = __NUM_VXRS_HIGH,
1260 .size = sizeof(__vector128),
1261 .align = sizeof(__vector128),
1262 .get = s390_vxrs_high_get,
1263 .set = s390_vxrs_high_set,
1268 static const struct user_regset_view user_s390_view = {
1269 .name = UTS_MACHINE,
1270 .e_machine = EM_S390,
1271 .regsets = s390_regsets,
1272 .n = ARRAY_SIZE(s390_regsets)
1275 #ifdef CONFIG_COMPAT
1276 static int s390_compat_regs_get(struct task_struct *target,
1277 const struct user_regset *regset,
1278 unsigned int pos, unsigned int count,
1279 void *kbuf, void __user *ubuf)
1281 if (target == current)
1282 save_access_regs(target->thread.acrs);
1285 compat_ulong_t *k = kbuf;
1287 *k++ = __peek_user_compat(target, pos);
1288 count -= sizeof(*k);
1292 compat_ulong_t __user *u = ubuf;
1294 if (__put_user(__peek_user_compat(target, pos), u++))
1296 count -= sizeof(*u);
1303 static int s390_compat_regs_set(struct task_struct *target,
1304 const struct user_regset *regset,
1305 unsigned int pos, unsigned int count,
1306 const void *kbuf, const void __user *ubuf)
1310 if (target == current)
1311 save_access_regs(target->thread.acrs);
1314 const compat_ulong_t *k = kbuf;
1315 while (count > 0 && !rc) {
1316 rc = __poke_user_compat(target, pos, *k++);
1317 count -= sizeof(*k);
1321 const compat_ulong_t __user *u = ubuf;
1322 while (count > 0 && !rc) {
1323 compat_ulong_t word;
1324 rc = __get_user(word, u++);
1327 rc = __poke_user_compat(target, pos, word);
1328 count -= sizeof(*u);
1333 if (rc == 0 && target == current)
1334 restore_access_regs(target->thread.acrs);
1339 static int s390_compat_regs_high_get(struct task_struct *target,
1340 const struct user_regset *regset,
1341 unsigned int pos, unsigned int count,
1342 void *kbuf, void __user *ubuf)
1344 compat_ulong_t *gprs_high;
1346 gprs_high = (compat_ulong_t *)
1347 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1349 compat_ulong_t *k = kbuf;
1353 count -= sizeof(*k);
1356 compat_ulong_t __user *u = ubuf;
1358 if (__put_user(*gprs_high, u++))
1361 count -= sizeof(*u);
1367 static int s390_compat_regs_high_set(struct task_struct *target,
1368 const struct user_regset *regset,
1369 unsigned int pos, unsigned int count,
1370 const void *kbuf, const void __user *ubuf)
1372 compat_ulong_t *gprs_high;
1375 gprs_high = (compat_ulong_t *)
1376 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1378 const compat_ulong_t *k = kbuf;
1382 count -= sizeof(*k);
1385 const compat_ulong_t __user *u = ubuf;
1386 while (count > 0 && !rc) {
1388 rc = __get_user(word, u++);
1393 count -= sizeof(*u);
1400 static int s390_compat_last_break_get(struct task_struct *target,
1401 const struct user_regset *regset,
1402 unsigned int pos, unsigned int count,
1403 void *kbuf, void __user *ubuf)
1405 compat_ulong_t last_break;
1408 last_break = task_thread_info(target)->last_break;
1410 unsigned long *k = kbuf;
1413 unsigned long __user *u = ubuf;
1414 if (__put_user(last_break, u))
1421 static int s390_compat_last_break_set(struct task_struct *target,
1422 const struct user_regset *regset,
1423 unsigned int pos, unsigned int count,
1424 const void *kbuf, const void __user *ubuf)
1429 static const struct user_regset s390_compat_regsets[] = {
1431 .core_note_type = NT_PRSTATUS,
1432 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1433 .size = sizeof(compat_long_t),
1434 .align = sizeof(compat_long_t),
1435 .get = s390_compat_regs_get,
1436 .set = s390_compat_regs_set,
1439 .core_note_type = NT_PRFPREG,
1440 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1441 .size = sizeof(compat_long_t),
1442 .align = sizeof(compat_long_t),
1443 .get = s390_fpregs_get,
1444 .set = s390_fpregs_set,
1447 .core_note_type = NT_S390_SYSTEM_CALL,
1449 .size = sizeof(compat_uint_t),
1450 .align = sizeof(compat_uint_t),
1451 .get = s390_system_call_get,
1452 .set = s390_system_call_set,
1455 .core_note_type = NT_S390_LAST_BREAK,
1457 .size = sizeof(long),
1458 .align = sizeof(long),
1459 .get = s390_compat_last_break_get,
1460 .set = s390_compat_last_break_set,
1463 .core_note_type = NT_S390_TDB,
1467 .get = s390_tdb_get,
1468 .set = s390_tdb_set,
1471 .core_note_type = NT_S390_VXRS_LOW,
1472 .n = __NUM_VXRS_LOW,
1473 .size = sizeof(__u64),
1474 .align = sizeof(__u64),
1475 .get = s390_vxrs_low_get,
1476 .set = s390_vxrs_low_set,
1479 .core_note_type = NT_S390_VXRS_HIGH,
1480 .n = __NUM_VXRS_HIGH,
1481 .size = sizeof(__vector128),
1482 .align = sizeof(__vector128),
1483 .get = s390_vxrs_high_get,
1484 .set = s390_vxrs_high_set,
1487 .core_note_type = NT_S390_HIGH_GPRS,
1488 .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
1489 .size = sizeof(compat_long_t),
1490 .align = sizeof(compat_long_t),
1491 .get = s390_compat_regs_high_get,
1492 .set = s390_compat_regs_high_set,
1496 static const struct user_regset_view user_s390_compat_view = {
1498 .e_machine = EM_S390,
1499 .regsets = s390_compat_regsets,
1500 .n = ARRAY_SIZE(s390_compat_regsets)
1504 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1506 #ifdef CONFIG_COMPAT
1507 if (test_tsk_thread_flag(task, TIF_31BIT))
1508 return &user_s390_compat_view;
1510 return &user_s390_view;
1513 static const char *gpr_names[NUM_GPRS] = {
1514 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1515 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1518 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1520 if (offset >= NUM_GPRS)
1522 return regs->gprs[offset];
1525 int regs_query_register_offset(const char *name)
1527 unsigned long offset;
1529 if (!name || *name != 'r')
1531 if (kstrtoul(name + 1, 10, &offset))
1533 if (offset >= NUM_GPRS)
1538 const char *regs_query_register_name(unsigned int offset)
1540 if (offset >= NUM_GPRS)
1542 return gpr_names[offset];
1545 static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1547 unsigned long ksp = kernel_stack_pointer(regs);
1549 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1553 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1554 * @regs:pt_regs which contains kernel stack pointer.
1555 * @n:stack entry number.
1557 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1558 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1561 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1565 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1566 if (!regs_within_kernel_stack(regs, addr))
1568 return *(unsigned long *)addr;