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;
47 /* Take care of the enable/disable of transactional execution. */
49 unsigned long cr, cr_new;
51 __ctl_store(cr, 0, 0);
52 /* Set or clear transaction execution TXC bit 8. */
53 cr_new = cr | (1UL << 55);
54 if (task->thread.per_flags & PER_FLAG_NO_TE)
55 cr_new &= ~(1UL << 55);
57 __ctl_load(cr_new, 0, 0);
58 /* Set or clear transaction execution TDC bits 62 and 63. */
59 __ctl_store(cr, 2, 2);
61 if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) {
62 if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND_TEND)
68 __ctl_load(cr_new, 2, 2);
70 /* Copy user specified PER registers */
71 new.control = thread->per_user.control;
72 new.start = thread->per_user.start;
73 new.end = thread->per_user.end;
75 /* merge TIF_SINGLE_STEP into user specified PER registers. */
76 if (test_tsk_thread_flag(task, TIF_SINGLE_STEP) ||
77 test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP)) {
78 if (test_tsk_thread_flag(task, TIF_BLOCK_STEP))
79 new.control |= PER_EVENT_BRANCH;
81 new.control |= PER_EVENT_IFETCH;
82 new.control |= PER_CONTROL_SUSPENSION;
83 new.control |= PER_EVENT_TRANSACTION_END;
84 if (test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP))
85 new.control |= PER_EVENT_IFETCH;
90 /* Take care of the PER enablement bit in the PSW. */
91 if (!(new.control & PER_EVENT_MASK)) {
92 regs->psw.mask &= ~PSW_MASK_PER;
95 regs->psw.mask |= PSW_MASK_PER;
96 __ctl_store(old, 9, 11);
97 if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
98 __ctl_load(new, 9, 11);
101 void user_enable_single_step(struct task_struct *task)
103 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
104 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
107 void user_disable_single_step(struct task_struct *task)
109 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
110 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
113 void user_enable_block_step(struct task_struct *task)
115 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
116 set_tsk_thread_flag(task, TIF_BLOCK_STEP);
120 * Called by kernel/ptrace.c when detaching..
122 * Clear all debugging related fields.
124 void ptrace_disable(struct task_struct *task)
126 memset(&task->thread.per_user, 0, sizeof(task->thread.per_user));
127 memset(&task->thread.per_event, 0, sizeof(task->thread.per_event));
128 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
129 clear_pt_regs_flag(task_pt_regs(task), PIF_PER_TRAP);
130 task->thread.per_flags = 0;
133 #define __ADDR_MASK 7
135 static inline unsigned long __peek_user_per(struct task_struct *child,
138 struct per_struct_kernel *dummy = NULL;
140 if (addr == (addr_t) &dummy->cr9)
141 /* Control bits of the active per set. */
142 return test_thread_flag(TIF_SINGLE_STEP) ?
143 PER_EVENT_IFETCH : child->thread.per_user.control;
144 else if (addr == (addr_t) &dummy->cr10)
145 /* Start address of the active per set. */
146 return test_thread_flag(TIF_SINGLE_STEP) ?
147 0 : child->thread.per_user.start;
148 else if (addr == (addr_t) &dummy->cr11)
149 /* End address of the active per set. */
150 return test_thread_flag(TIF_SINGLE_STEP) ?
151 -1UL : child->thread.per_user.end;
152 else if (addr == (addr_t) &dummy->bits)
153 /* Single-step bit. */
154 return test_thread_flag(TIF_SINGLE_STEP) ?
155 (1UL << (BITS_PER_LONG - 1)) : 0;
156 else if (addr == (addr_t) &dummy->starting_addr)
157 /* Start address of the user specified per set. */
158 return child->thread.per_user.start;
159 else if (addr == (addr_t) &dummy->ending_addr)
160 /* End address of the user specified per set. */
161 return child->thread.per_user.end;
162 else if (addr == (addr_t) &dummy->perc_atmid)
163 /* PER code, ATMID and AI of the last PER trap */
164 return (unsigned long)
165 child->thread.per_event.cause << (BITS_PER_LONG - 16);
166 else if (addr == (addr_t) &dummy->address)
167 /* Address of the last PER trap */
168 return child->thread.per_event.address;
169 else if (addr == (addr_t) &dummy->access_id)
170 /* Access id of the last PER trap */
171 return (unsigned long)
172 child->thread.per_event.paid << (BITS_PER_LONG - 8);
177 * Read the word at offset addr from the user area of a process. The
178 * trouble here is that the information is littered over different
179 * locations. The process registers are found on the kernel stack,
180 * the floating point stuff and the trace settings are stored in
181 * the task structure. In addition the different structures in
182 * struct user contain pad bytes that should be read as zeroes.
185 static unsigned long __peek_user(struct task_struct *child, addr_t addr)
187 struct user *dummy = NULL;
190 if (addr < (addr_t) &dummy->regs.acrs) {
192 * psw and gprs are stored on the stack
194 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
195 if (addr == (addr_t) &dummy->regs.psw.mask) {
196 /* Return a clean psw mask. */
197 tmp &= PSW_MASK_USER | PSW_MASK_RI;
198 tmp |= PSW_USER_BITS;
201 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
203 * access registers are stored in the thread structure
205 offset = addr - (addr_t) &dummy->regs.acrs;
207 * Very special case: old & broken 64 bit gdb reading
208 * from acrs[15]. Result is a 64 bit value. Read the
209 * 32 bit acrs[15] value and shift it by 32. Sick...
211 if (addr == (addr_t) &dummy->regs.acrs[15])
212 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
214 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
216 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
218 * orig_gpr2 is stored on the kernel stack
220 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
222 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
224 * prevent reads of padding hole between
225 * orig_gpr2 and fp_regs on s390.
229 } else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
231 * floating point control reg. is in the thread structure
233 tmp = child->thread.fpu.fpc;
234 tmp <<= BITS_PER_LONG - 32;
236 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
238 * floating point regs. are either in child->thread.fpu
239 * or the child->thread.fpu.vxrs array
241 offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
244 ((addr_t) child->thread.fpu.vxrs + 2*offset);
247 ((addr_t) child->thread.fpu.fprs + offset);
249 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
251 * Handle access to the per_info structure.
253 addr -= (addr_t) &dummy->regs.per_info;
254 tmp = __peek_user_per(child, addr);
263 peek_user(struct task_struct *child, addr_t addr, addr_t data)
268 * Stupid gdb peeks/pokes the access registers in 64 bit with
269 * an alignment of 4. Programmers from hell...
272 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
273 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
275 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
278 tmp = __peek_user(child, addr);
279 return put_user(tmp, (addr_t __user *) data);
282 static inline void __poke_user_per(struct task_struct *child,
283 addr_t addr, addr_t data)
285 struct per_struct_kernel *dummy = NULL;
288 * There are only three fields in the per_info struct that the
289 * debugger user can write to.
290 * 1) cr9: the debugger wants to set a new PER event mask
291 * 2) starting_addr: the debugger wants to set a new starting
292 * address to use with the PER event mask.
293 * 3) ending_addr: the debugger wants to set a new ending
294 * address to use with the PER event mask.
295 * The user specified PER event mask and the start and end
296 * addresses are used only if single stepping is not in effect.
297 * Writes to any other field in per_info are ignored.
299 if (addr == (addr_t) &dummy->cr9)
300 /* PER event mask of the user specified per set. */
301 child->thread.per_user.control =
302 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
303 else if (addr == (addr_t) &dummy->starting_addr)
304 /* Starting address of the user specified per set. */
305 child->thread.per_user.start = data;
306 else if (addr == (addr_t) &dummy->ending_addr)
307 /* Ending address of the user specified per set. */
308 child->thread.per_user.end = data;
311 static void fixup_int_code(struct task_struct *child, addr_t data)
313 struct pt_regs *regs = task_pt_regs(child);
314 int ilc = regs->int_code >> 16;
320 if (ptrace_access_vm(child, regs->psw.addr - (regs->int_code >> 16),
321 &insn, sizeof(insn), FOLL_FORCE) != sizeof(insn))
324 /* double check that tracee stopped on svc instruction */
325 if ((insn >> 8) != 0xa)
328 regs->int_code = 0x20000 | (data & 0xffff);
331 * Write a word to the user area of a process at location addr. This
332 * operation does have an additional problem compared to peek_user.
333 * Stores to the program status word and on the floating point
334 * control register needs to get checked for validity.
336 static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
338 struct user *dummy = NULL;
342 if (addr < (addr_t) &dummy->regs.acrs) {
343 struct pt_regs *regs = task_pt_regs(child);
345 * psw and gprs are stored on the stack
347 if (addr == (addr_t) &dummy->regs.psw.mask) {
348 unsigned long mask = PSW_MASK_USER;
350 mask |= is_ri_task(child) ? PSW_MASK_RI : 0;
351 if ((data ^ PSW_USER_BITS) & ~mask)
352 /* Invalid psw mask. */
354 if ((data & PSW_MASK_ASC) == PSW_ASC_HOME)
355 /* Invalid address-space-control bits */
357 if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))
358 /* Invalid addressing mode bits */
362 if (test_pt_regs_flag(regs, PIF_SYSCALL) &&
363 addr == offsetof(struct user, regs.gprs[2]))
364 fixup_int_code(child, data);
365 *(addr_t *)((addr_t) ®s->psw + addr) = data;
367 } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
369 * access registers are stored in the thread structure
371 offset = addr - (addr_t) &dummy->regs.acrs;
373 * Very special case: old & broken 64 bit gdb writing
374 * to acrs[15] with a 64 bit value. Ignore the lower
375 * half of the value and write the upper 32 bit to
378 if (addr == (addr_t) &dummy->regs.acrs[15])
379 child->thread.acrs[15] = (unsigned int) (data >> 32);
381 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
383 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
385 * orig_gpr2 is stored on the kernel stack
387 task_pt_regs(child)->orig_gpr2 = data;
389 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
391 * prevent writes of padding hole between
392 * orig_gpr2 and fp_regs on s390.
396 } else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
398 * floating point control reg. is in the thread structure
400 if ((unsigned int) data != 0 ||
401 test_fp_ctl(data >> (BITS_PER_LONG - 32)))
403 child->thread.fpu.fpc = data >> (BITS_PER_LONG - 32);
405 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
407 * floating point regs. are either in child->thread.fpu
408 * or the child->thread.fpu.vxrs array
410 offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
413 child->thread.fpu.vxrs + 2*offset) = data;
416 child->thread.fpu.fprs + offset) = data;
418 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
420 * Handle access to the per_info structure.
422 addr -= (addr_t) &dummy->regs.per_info;
423 __poke_user_per(child, addr, data);
430 static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
435 * Stupid gdb peeks/pokes the access registers in 64 bit with
436 * an alignment of 4. Programmers from hell indeed...
439 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
440 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
442 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
445 return __poke_user(child, addr, data);
448 long arch_ptrace(struct task_struct *child, long request,
449 unsigned long addr, unsigned long data)
456 /* read the word at location addr in the USER area. */
457 return peek_user(child, addr, data);
460 /* write the word at location addr in the USER area */
461 return poke_user(child, addr, data);
463 case PTRACE_PEEKUSR_AREA:
464 case PTRACE_POKEUSR_AREA:
465 if (copy_from_user(&parea, (void __force __user *) addr,
468 addr = parea.kernel_addr;
469 data = parea.process_addr;
471 while (copied < parea.len) {
472 if (request == PTRACE_PEEKUSR_AREA)
473 ret = peek_user(child, addr, data);
477 (addr_t __force __user *) data))
479 ret = poke_user(child, addr, utmp);
483 addr += sizeof(unsigned long);
484 data += sizeof(unsigned long);
485 copied += sizeof(unsigned long);
488 case PTRACE_GET_LAST_BREAK:
489 put_user(task_thread_info(child)->last_break,
490 (unsigned long __user *) data);
492 case PTRACE_ENABLE_TE:
495 child->thread.per_flags &= ~PER_FLAG_NO_TE;
497 case PTRACE_DISABLE_TE:
500 child->thread.per_flags |= PER_FLAG_NO_TE;
501 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
503 case PTRACE_TE_ABORT_RAND:
504 if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
508 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
511 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
512 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
515 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
516 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
523 return ptrace_request(child, request, addr, data);
529 * Now the fun part starts... a 31 bit program running in the
530 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
531 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
532 * to handle, the difference to the 64 bit versions of the requests
533 * is that the access is done in multiples of 4 byte instead of
534 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
535 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
536 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
537 * is a 31 bit program too, the content of struct user can be
538 * emulated. A 31 bit program peeking into the struct user of
539 * a 64 bit program is a no-no.
543 * Same as peek_user_per but for a 31 bit program.
545 static inline __u32 __peek_user_per_compat(struct task_struct *child,
548 struct compat_per_struct_kernel *dummy32 = NULL;
550 if (addr == (addr_t) &dummy32->cr9)
551 /* Control bits of the active per set. */
552 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
553 PER_EVENT_IFETCH : child->thread.per_user.control;
554 else if (addr == (addr_t) &dummy32->cr10)
555 /* Start address of the active per set. */
556 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
557 0 : child->thread.per_user.start;
558 else if (addr == (addr_t) &dummy32->cr11)
559 /* End address of the active per set. */
560 return test_thread_flag(TIF_SINGLE_STEP) ?
561 PSW32_ADDR_INSN : child->thread.per_user.end;
562 else if (addr == (addr_t) &dummy32->bits)
563 /* Single-step bit. */
564 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
566 else if (addr == (addr_t) &dummy32->starting_addr)
567 /* Start address of the user specified per set. */
568 return (__u32) child->thread.per_user.start;
569 else if (addr == (addr_t) &dummy32->ending_addr)
570 /* End address of the user specified per set. */
571 return (__u32) child->thread.per_user.end;
572 else if (addr == (addr_t) &dummy32->perc_atmid)
573 /* PER code, ATMID and AI of the last PER trap */
574 return (__u32) child->thread.per_event.cause << 16;
575 else if (addr == (addr_t) &dummy32->address)
576 /* Address of the last PER trap */
577 return (__u32) child->thread.per_event.address;
578 else if (addr == (addr_t) &dummy32->access_id)
579 /* Access id of the last PER trap */
580 return (__u32) child->thread.per_event.paid << 24;
585 * Same as peek_user but for a 31 bit program.
587 static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
589 struct compat_user *dummy32 = NULL;
593 if (addr < (addr_t) &dummy32->regs.acrs) {
594 struct pt_regs *regs = task_pt_regs(child);
596 * psw and gprs are stored on the stack
598 if (addr == (addr_t) &dummy32->regs.psw.mask) {
599 /* Fake a 31 bit psw mask. */
600 tmp = (__u32)(regs->psw.mask >> 32);
601 tmp &= PSW32_MASK_USER | PSW32_MASK_RI;
602 tmp |= PSW32_USER_BITS;
603 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
604 /* Fake a 31 bit psw address. */
605 tmp = (__u32) regs->psw.addr |
606 (__u32)(regs->psw.mask & PSW_MASK_BA);
609 tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4);
611 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
613 * access registers are stored in the thread structure
615 offset = addr - (addr_t) &dummy32->regs.acrs;
616 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
618 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
620 * orig_gpr2 is stored on the kernel stack
622 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
624 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
626 * prevent reads of padding hole between
627 * orig_gpr2 and fp_regs on s390.
631 } else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
633 * floating point control reg. is in the thread structure
635 tmp = child->thread.fpu.fpc;
637 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
639 * floating point regs. are either in child->thread.fpu
640 * or the child->thread.fpu.vxrs array
642 offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
645 ((addr_t) child->thread.fpu.vxrs + 2*offset);
648 ((addr_t) child->thread.fpu.fprs + offset);
650 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
652 * Handle access to the per_info structure.
654 addr -= (addr_t) &dummy32->regs.per_info;
655 tmp = __peek_user_per_compat(child, addr);
663 static int peek_user_compat(struct task_struct *child,
664 addr_t addr, addr_t data)
668 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
671 tmp = __peek_user_compat(child, addr);
672 return put_user(tmp, (__u32 __user *) data);
676 * Same as poke_user_per but for a 31 bit program.
678 static inline void __poke_user_per_compat(struct task_struct *child,
679 addr_t addr, __u32 data)
681 struct compat_per_struct_kernel *dummy32 = NULL;
683 if (addr == (addr_t) &dummy32->cr9)
684 /* PER event mask of the user specified per set. */
685 child->thread.per_user.control =
686 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
687 else if (addr == (addr_t) &dummy32->starting_addr)
688 /* Starting address of the user specified per set. */
689 child->thread.per_user.start = data;
690 else if (addr == (addr_t) &dummy32->ending_addr)
691 /* Ending address of the user specified per set. */
692 child->thread.per_user.end = data;
696 * Same as poke_user but for a 31 bit program.
698 static int __poke_user_compat(struct task_struct *child,
699 addr_t addr, addr_t data)
701 struct compat_user *dummy32 = NULL;
702 __u32 tmp = (__u32) data;
705 if (addr < (addr_t) &dummy32->regs.acrs) {
706 struct pt_regs *regs = task_pt_regs(child);
708 * psw, gprs, acrs and orig_gpr2 are stored on the stack
710 if (addr == (addr_t) &dummy32->regs.psw.mask) {
711 __u32 mask = PSW32_MASK_USER;
713 mask |= is_ri_task(child) ? PSW32_MASK_RI : 0;
714 /* Build a 64 bit psw mask from 31 bit mask. */
715 if ((tmp ^ PSW32_USER_BITS) & ~mask)
716 /* Invalid psw mask. */
718 if ((data & PSW32_MASK_ASC) == PSW32_ASC_HOME)
719 /* Invalid address-space-control bits */
721 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
722 (regs->psw.mask & PSW_MASK_BA) |
723 (__u64)(tmp & mask) << 32;
724 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
725 /* Build a 64 bit psw address from 31 bit address. */
726 regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
727 /* Transfer 31 bit amode bit to psw mask. */
728 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
729 (__u64)(tmp & PSW32_ADDR_AMODE);
732 if (test_pt_regs_flag(regs, PIF_SYSCALL) &&
733 addr == offsetof(struct compat_user, regs.gprs[2]))
734 fixup_int_code(child, data);
736 *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp;
738 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
740 * access registers are stored in the thread structure
742 offset = addr - (addr_t) &dummy32->regs.acrs;
743 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
745 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
747 * orig_gpr2 is stored on the kernel stack
749 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
751 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
753 * prevent writess of padding hole between
754 * orig_gpr2 and fp_regs on s390.
758 } else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
760 * floating point control reg. is in the thread structure
762 if (test_fp_ctl(tmp))
764 child->thread.fpu.fpc = data;
766 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
768 * floating point regs. are either in child->thread.fpu
769 * or the child->thread.fpu.vxrs array
771 offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
774 child->thread.fpu.vxrs + 2*offset) = tmp;
777 child->thread.fpu.fprs + offset) = tmp;
779 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
781 * Handle access to the per_info structure.
783 addr -= (addr_t) &dummy32->regs.per_info;
784 __poke_user_per_compat(child, addr, data);
790 static int poke_user_compat(struct task_struct *child,
791 addr_t addr, addr_t data)
793 if (!is_compat_task() || (addr & 3) ||
794 addr > sizeof(struct compat_user) - 3)
797 return __poke_user_compat(child, addr, data);
800 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
801 compat_ulong_t caddr, compat_ulong_t cdata)
803 unsigned long addr = caddr;
804 unsigned long data = cdata;
805 compat_ptrace_area parea;
810 /* read the word at location addr in the USER area. */
811 return peek_user_compat(child, addr, data);
814 /* write the word at location addr in the USER area */
815 return poke_user_compat(child, addr, data);
817 case PTRACE_PEEKUSR_AREA:
818 case PTRACE_POKEUSR_AREA:
819 if (copy_from_user(&parea, (void __force __user *) addr,
822 addr = parea.kernel_addr;
823 data = parea.process_addr;
825 while (copied < parea.len) {
826 if (request == PTRACE_PEEKUSR_AREA)
827 ret = peek_user_compat(child, addr, data);
831 (__u32 __force __user *) data))
833 ret = poke_user_compat(child, addr, utmp);
837 addr += sizeof(unsigned int);
838 data += sizeof(unsigned int);
839 copied += sizeof(unsigned int);
842 case PTRACE_GET_LAST_BREAK:
843 put_user(task_thread_info(child)->last_break,
844 (unsigned int __user *) data);
847 return compat_ptrace_request(child, request, addr, data);
851 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
853 unsigned long mask = -1UL;
856 * The sysc_tracesys code in entry.S stored the system
857 * call number to gprs[2].
859 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
860 (tracehook_report_syscall_entry(regs) ||
861 regs->gprs[2] >= NR_syscalls)) {
863 * Tracing decided this syscall should not happen or the
864 * debugger stored an invalid system call number. Skip
865 * the system call and the system call restart handling.
867 clear_pt_regs_flag(regs, PIF_SYSCALL);
871 /* Do the secure computing check after ptrace. */
872 if (secure_computing(NULL)) {
873 /* seccomp failures shouldn't expose any additional code. */
877 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
878 trace_sys_enter(regs, regs->gprs[2]);
880 if (is_compat_task())
883 audit_syscall_entry(regs->gprs[2], regs->orig_gpr2 & mask,
884 regs->gprs[3] &mask, regs->gprs[4] &mask,
885 regs->gprs[5] &mask);
887 return regs->gprs[2];
890 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
892 audit_syscall_exit(regs);
894 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
895 trace_sys_exit(regs, regs->gprs[2]);
897 if (test_thread_flag(TIF_SYSCALL_TRACE))
898 tracehook_report_syscall_exit(regs, 0);
902 * user_regset definitions.
905 static int s390_regs_get(struct task_struct *target,
906 const struct user_regset *regset,
907 unsigned int pos, unsigned int count,
908 void *kbuf, void __user *ubuf)
910 if (target == current)
911 save_access_regs(target->thread.acrs);
914 unsigned long *k = kbuf;
916 *k++ = __peek_user(target, pos);
921 unsigned long __user *u = ubuf;
923 if (__put_user(__peek_user(target, pos), u++))
932 static int s390_regs_set(struct task_struct *target,
933 const struct user_regset *regset,
934 unsigned int pos, unsigned int count,
935 const void *kbuf, const void __user *ubuf)
939 if (target == current)
940 save_access_regs(target->thread.acrs);
943 const unsigned long *k = kbuf;
944 while (count > 0 && !rc) {
945 rc = __poke_user(target, pos, *k++);
950 const unsigned long __user *u = ubuf;
951 while (count > 0 && !rc) {
953 rc = __get_user(word, u++);
956 rc = __poke_user(target, pos, word);
962 if (rc == 0 && target == current)
963 restore_access_regs(target->thread.acrs);
968 static int s390_fpregs_get(struct task_struct *target,
969 const struct user_regset *regset, unsigned int pos,
970 unsigned int count, void *kbuf, void __user *ubuf)
972 _s390_fp_regs fp_regs;
974 if (target == current)
977 fp_regs.fpc = target->thread.fpu.fpc;
978 fpregs_store(&fp_regs, &target->thread.fpu);
980 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
984 static int s390_fpregs_set(struct task_struct *target,
985 const struct user_regset *regset, unsigned int pos,
986 unsigned int count, const void *kbuf,
987 const void __user *ubuf)
990 freg_t fprs[__NUM_FPRS];
992 if (target == current)
996 convert_vx_to_fp(fprs, target->thread.fpu.vxrs);
998 memcpy(&fprs, target->thread.fpu.fprs, sizeof(fprs));
1000 /* If setting FPC, must validate it first. */
1001 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
1002 u32 ufpc[2] = { target->thread.fpu.fpc, 0 };
1003 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
1004 0, offsetof(s390_fp_regs, fprs));
1007 if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
1009 target->thread.fpu.fpc = ufpc[0];
1012 if (rc == 0 && count > 0)
1013 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1014 fprs, offsetof(s390_fp_regs, fprs), -1);
1019 convert_fp_to_vx(target->thread.fpu.vxrs, fprs);
1021 memcpy(target->thread.fpu.fprs, &fprs, sizeof(fprs));
1026 static int s390_last_break_get(struct task_struct *target,
1027 const struct user_regset *regset,
1028 unsigned int pos, unsigned int count,
1029 void *kbuf, void __user *ubuf)
1033 unsigned long *k = kbuf;
1034 *k = task_thread_info(target)->last_break;
1036 unsigned long __user *u = ubuf;
1037 if (__put_user(task_thread_info(target)->last_break, u))
1044 static int s390_last_break_set(struct task_struct *target,
1045 const struct user_regset *regset,
1046 unsigned int pos, unsigned int count,
1047 const void *kbuf, const void __user *ubuf)
1052 static int s390_tdb_get(struct task_struct *target,
1053 const struct user_regset *regset,
1054 unsigned int pos, unsigned int count,
1055 void *kbuf, void __user *ubuf)
1057 struct pt_regs *regs = task_pt_regs(target);
1058 unsigned char *data;
1060 if (!(regs->int_code & 0x200))
1062 data = target->thread.trap_tdb;
1063 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
1066 static int s390_tdb_set(struct task_struct *target,
1067 const struct user_regset *regset,
1068 unsigned int pos, unsigned int count,
1069 const void *kbuf, const void __user *ubuf)
1074 static int s390_vxrs_low_get(struct task_struct *target,
1075 const struct user_regset *regset,
1076 unsigned int pos, unsigned int count,
1077 void *kbuf, void __user *ubuf)
1079 __u64 vxrs[__NUM_VXRS_LOW];
1082 if (!MACHINE_HAS_VX)
1084 if (target == current)
1086 for (i = 0; i < __NUM_VXRS_LOW; i++)
1087 vxrs[i] = *((__u64 *)(target->thread.fpu.vxrs + i) + 1);
1088 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1091 static int s390_vxrs_low_set(struct task_struct *target,
1092 const struct user_regset *regset,
1093 unsigned int pos, unsigned int count,
1094 const void *kbuf, const void __user *ubuf)
1096 __u64 vxrs[__NUM_VXRS_LOW];
1099 if (!MACHINE_HAS_VX)
1101 if (target == current)
1104 for (i = 0; i < __NUM_VXRS_LOW; i++)
1105 vxrs[i] = *((__u64 *)(target->thread.fpu.vxrs + i) + 1);
1107 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1109 for (i = 0; i < __NUM_VXRS_LOW; i++)
1110 *((__u64 *)(target->thread.fpu.vxrs + i) + 1) = vxrs[i];
1115 static int s390_vxrs_high_get(struct task_struct *target,
1116 const struct user_regset *regset,
1117 unsigned int pos, unsigned int count,
1118 void *kbuf, void __user *ubuf)
1120 __vector128 vxrs[__NUM_VXRS_HIGH];
1122 if (!MACHINE_HAS_VX)
1124 if (target == current)
1126 memcpy(vxrs, target->thread.fpu.vxrs + __NUM_VXRS_LOW, sizeof(vxrs));
1128 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1131 static int s390_vxrs_high_set(struct task_struct *target,
1132 const struct user_regset *regset,
1133 unsigned int pos, unsigned int count,
1134 const void *kbuf, const void __user *ubuf)
1138 if (!MACHINE_HAS_VX)
1140 if (target == current)
1143 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1144 target->thread.fpu.vxrs + __NUM_VXRS_LOW, 0, -1);
1148 static int s390_system_call_get(struct task_struct *target,
1149 const struct user_regset *regset,
1150 unsigned int pos, unsigned int count,
1151 void *kbuf, void __user *ubuf)
1153 unsigned int *data = &task_thread_info(target)->system_call;
1154 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1155 data, 0, sizeof(unsigned int));
1158 static int s390_system_call_set(struct task_struct *target,
1159 const struct user_regset *regset,
1160 unsigned int pos, unsigned int count,
1161 const void *kbuf, const void __user *ubuf)
1163 unsigned int *data = &task_thread_info(target)->system_call;
1164 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1165 data, 0, sizeof(unsigned int));
1168 static const struct user_regset s390_regsets[] = {
1170 .core_note_type = NT_PRSTATUS,
1171 .n = sizeof(s390_regs) / sizeof(long),
1172 .size = sizeof(long),
1173 .align = sizeof(long),
1174 .get = s390_regs_get,
1175 .set = s390_regs_set,
1178 .core_note_type = NT_PRFPREG,
1179 .n = sizeof(s390_fp_regs) / sizeof(long),
1180 .size = sizeof(long),
1181 .align = sizeof(long),
1182 .get = s390_fpregs_get,
1183 .set = s390_fpregs_set,
1186 .core_note_type = NT_S390_SYSTEM_CALL,
1188 .size = sizeof(unsigned int),
1189 .align = sizeof(unsigned int),
1190 .get = s390_system_call_get,
1191 .set = s390_system_call_set,
1194 .core_note_type = NT_S390_LAST_BREAK,
1196 .size = sizeof(long),
1197 .align = sizeof(long),
1198 .get = s390_last_break_get,
1199 .set = s390_last_break_set,
1202 .core_note_type = NT_S390_TDB,
1206 .get = s390_tdb_get,
1207 .set = s390_tdb_set,
1210 .core_note_type = NT_S390_VXRS_LOW,
1211 .n = __NUM_VXRS_LOW,
1212 .size = sizeof(__u64),
1213 .align = sizeof(__u64),
1214 .get = s390_vxrs_low_get,
1215 .set = s390_vxrs_low_set,
1218 .core_note_type = NT_S390_VXRS_HIGH,
1219 .n = __NUM_VXRS_HIGH,
1220 .size = sizeof(__vector128),
1221 .align = sizeof(__vector128),
1222 .get = s390_vxrs_high_get,
1223 .set = s390_vxrs_high_set,
1227 static const struct user_regset_view user_s390_view = {
1228 .name = UTS_MACHINE,
1229 .e_machine = EM_S390,
1230 .regsets = s390_regsets,
1231 .n = ARRAY_SIZE(s390_regsets)
1234 #ifdef CONFIG_COMPAT
1235 static int s390_compat_regs_get(struct task_struct *target,
1236 const struct user_regset *regset,
1237 unsigned int pos, unsigned int count,
1238 void *kbuf, void __user *ubuf)
1240 if (target == current)
1241 save_access_regs(target->thread.acrs);
1244 compat_ulong_t *k = kbuf;
1246 *k++ = __peek_user_compat(target, pos);
1247 count -= sizeof(*k);
1251 compat_ulong_t __user *u = ubuf;
1253 if (__put_user(__peek_user_compat(target, pos), u++))
1255 count -= sizeof(*u);
1262 static int s390_compat_regs_set(struct task_struct *target,
1263 const struct user_regset *regset,
1264 unsigned int pos, unsigned int count,
1265 const void *kbuf, const void __user *ubuf)
1269 if (target == current)
1270 save_access_regs(target->thread.acrs);
1273 const compat_ulong_t *k = kbuf;
1274 while (count > 0 && !rc) {
1275 rc = __poke_user_compat(target, pos, *k++);
1276 count -= sizeof(*k);
1280 const compat_ulong_t __user *u = ubuf;
1281 while (count > 0 && !rc) {
1282 compat_ulong_t word;
1283 rc = __get_user(word, u++);
1286 rc = __poke_user_compat(target, pos, word);
1287 count -= sizeof(*u);
1292 if (rc == 0 && target == current)
1293 restore_access_regs(target->thread.acrs);
1298 static int s390_compat_regs_high_get(struct task_struct *target,
1299 const struct user_regset *regset,
1300 unsigned int pos, unsigned int count,
1301 void *kbuf, void __user *ubuf)
1303 compat_ulong_t *gprs_high;
1305 gprs_high = (compat_ulong_t *)
1306 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1308 compat_ulong_t *k = kbuf;
1312 count -= sizeof(*k);
1315 compat_ulong_t __user *u = ubuf;
1317 if (__put_user(*gprs_high, u++))
1320 count -= sizeof(*u);
1326 static int s390_compat_regs_high_set(struct task_struct *target,
1327 const struct user_regset *regset,
1328 unsigned int pos, unsigned int count,
1329 const void *kbuf, const void __user *ubuf)
1331 compat_ulong_t *gprs_high;
1334 gprs_high = (compat_ulong_t *)
1335 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1337 const compat_ulong_t *k = kbuf;
1341 count -= sizeof(*k);
1344 const compat_ulong_t __user *u = ubuf;
1345 while (count > 0 && !rc) {
1347 rc = __get_user(word, u++);
1352 count -= sizeof(*u);
1359 static int s390_compat_last_break_get(struct task_struct *target,
1360 const struct user_regset *regset,
1361 unsigned int pos, unsigned int count,
1362 void *kbuf, void __user *ubuf)
1364 compat_ulong_t last_break;
1367 last_break = task_thread_info(target)->last_break;
1369 unsigned long *k = kbuf;
1372 unsigned long __user *u = ubuf;
1373 if (__put_user(last_break, u))
1380 static int s390_compat_last_break_set(struct task_struct *target,
1381 const struct user_regset *regset,
1382 unsigned int pos, unsigned int count,
1383 const void *kbuf, const void __user *ubuf)
1388 static const struct user_regset s390_compat_regsets[] = {
1390 .core_note_type = NT_PRSTATUS,
1391 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1392 .size = sizeof(compat_long_t),
1393 .align = sizeof(compat_long_t),
1394 .get = s390_compat_regs_get,
1395 .set = s390_compat_regs_set,
1398 .core_note_type = NT_PRFPREG,
1399 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1400 .size = sizeof(compat_long_t),
1401 .align = sizeof(compat_long_t),
1402 .get = s390_fpregs_get,
1403 .set = s390_fpregs_set,
1406 .core_note_type = NT_S390_SYSTEM_CALL,
1408 .size = sizeof(compat_uint_t),
1409 .align = sizeof(compat_uint_t),
1410 .get = s390_system_call_get,
1411 .set = s390_system_call_set,
1414 .core_note_type = NT_S390_LAST_BREAK,
1416 .size = sizeof(long),
1417 .align = sizeof(long),
1418 .get = s390_compat_last_break_get,
1419 .set = s390_compat_last_break_set,
1422 .core_note_type = NT_S390_TDB,
1426 .get = s390_tdb_get,
1427 .set = s390_tdb_set,
1430 .core_note_type = NT_S390_VXRS_LOW,
1431 .n = __NUM_VXRS_LOW,
1432 .size = sizeof(__u64),
1433 .align = sizeof(__u64),
1434 .get = s390_vxrs_low_get,
1435 .set = s390_vxrs_low_set,
1438 .core_note_type = NT_S390_VXRS_HIGH,
1439 .n = __NUM_VXRS_HIGH,
1440 .size = sizeof(__vector128),
1441 .align = sizeof(__vector128),
1442 .get = s390_vxrs_high_get,
1443 .set = s390_vxrs_high_set,
1446 .core_note_type = NT_S390_HIGH_GPRS,
1447 .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
1448 .size = sizeof(compat_long_t),
1449 .align = sizeof(compat_long_t),
1450 .get = s390_compat_regs_high_get,
1451 .set = s390_compat_regs_high_set,
1455 static const struct user_regset_view user_s390_compat_view = {
1457 .e_machine = EM_S390,
1458 .regsets = s390_compat_regsets,
1459 .n = ARRAY_SIZE(s390_compat_regsets)
1463 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1465 #ifdef CONFIG_COMPAT
1466 if (test_tsk_thread_flag(task, TIF_31BIT))
1467 return &user_s390_compat_view;
1469 return &user_s390_view;
1472 static const char *gpr_names[NUM_GPRS] = {
1473 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1474 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1477 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1479 if (offset >= NUM_GPRS)
1481 return regs->gprs[offset];
1484 int regs_query_register_offset(const char *name)
1486 unsigned long offset;
1488 if (!name || *name != 'r')
1490 if (kstrtoul(name + 1, 10, &offset))
1492 if (offset >= NUM_GPRS)
1497 const char *regs_query_register_name(unsigned int offset)
1499 if (offset >= NUM_GPRS)
1501 return gpr_names[offset];
1504 static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1506 unsigned long ksp = kernel_stack_pointer(regs);
1508 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1512 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1513 * @regs:pt_regs which contains kernel stack pointer.
1514 * @n:stack entry number.
1516 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1517 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1520 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1524 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1525 if (!regs_within_kernel_stack(regs, addr))
1527 return *(unsigned long *)addr;