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 <trace/syscall.h>
24 #include <asm/compat.h>
25 #include <asm/segment.h>
27 #include <asm/pgtable.h>
28 #include <asm/pgalloc.h>
29 #include <asm/system.h>
30 #include <asm/uaccess.h>
31 #include <asm/unistd.h>
35 #include "compat_ptrace.h"
38 #define CREATE_TRACE_POINTS
39 #include <trace/events/syscalls.h>
46 REGSET_GENERAL_EXTENDED,
49 void update_per_regs(struct task_struct *task)
51 struct pt_regs *regs = task_pt_regs(task);
52 struct thread_struct *thread = &task->thread;
53 struct per_regs old, new;
55 /* Copy user specified PER registers */
56 new.control = thread->per_user.control;
57 new.start = thread->per_user.start;
58 new.end = thread->per_user.end;
60 /* merge TIF_SINGLE_STEP into user specified PER registers. */
61 if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) {
62 new.control |= PER_EVENT_IFETCH;
64 new.end = PSW_ADDR_INSN;
67 /* Take care of the PER enablement bit in the PSW. */
68 if (!(new.control & PER_EVENT_MASK)) {
69 regs->psw.mask &= ~PSW_MASK_PER;
72 regs->psw.mask |= PSW_MASK_PER;
73 __ctl_store(old, 9, 11);
74 if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
75 __ctl_load(new, 9, 11);
78 void user_enable_single_step(struct task_struct *task)
80 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
82 update_per_regs(task);
85 void user_disable_single_step(struct task_struct *task)
87 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
89 update_per_regs(task);
93 * Called by kernel/ptrace.c when detaching..
95 * Clear all debugging related fields.
97 void ptrace_disable(struct task_struct *task)
99 memset(&task->thread.per_user, 0, sizeof(task->thread.per_user));
100 memset(&task->thread.per_event, 0, sizeof(task->thread.per_event));
101 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
102 clear_tsk_thread_flag(task, TIF_PER_TRAP);
106 # define __ADDR_MASK 3
108 # define __ADDR_MASK 7
111 static inline unsigned long __peek_user_per(struct task_struct *child,
114 struct per_struct_kernel *dummy = NULL;
116 if (addr == (addr_t) &dummy->cr9)
117 /* Control bits of the active per set. */
118 return test_thread_flag(TIF_SINGLE_STEP) ?
119 PER_EVENT_IFETCH : child->thread.per_user.control;
120 else if (addr == (addr_t) &dummy->cr10)
121 /* Start address of the active per set. */
122 return test_thread_flag(TIF_SINGLE_STEP) ?
123 0 : child->thread.per_user.start;
124 else if (addr == (addr_t) &dummy->cr11)
125 /* End address of the active per set. */
126 return test_thread_flag(TIF_SINGLE_STEP) ?
127 PSW_ADDR_INSN : child->thread.per_user.end;
128 else if (addr == (addr_t) &dummy->bits)
129 /* Single-step bit. */
130 return test_thread_flag(TIF_SINGLE_STEP) ?
131 (1UL << (BITS_PER_LONG - 1)) : 0;
132 else if (addr == (addr_t) &dummy->starting_addr)
133 /* Start address of the user specified per set. */
134 return child->thread.per_user.start;
135 else if (addr == (addr_t) &dummy->ending_addr)
136 /* End address of the user specified per set. */
137 return child->thread.per_user.end;
138 else if (addr == (addr_t) &dummy->perc_atmid)
139 /* PER code, ATMID and AI of the last PER trap */
140 return (unsigned long)
141 child->thread.per_event.cause << (BITS_PER_LONG - 16);
142 else if (addr == (addr_t) &dummy->address)
143 /* Address of the last PER trap */
144 return child->thread.per_event.address;
145 else if (addr == (addr_t) &dummy->access_id)
146 /* Access id of the last PER trap */
147 return (unsigned long)
148 child->thread.per_event.paid << (BITS_PER_LONG - 8);
153 * Read the word at offset addr from the user area of a process. The
154 * trouble here is that the information is littered over different
155 * locations. The process registers are found on the kernel stack,
156 * the floating point stuff and the trace settings are stored in
157 * the task structure. In addition the different structures in
158 * struct user contain pad bytes that should be read as zeroes.
161 static unsigned long __peek_user(struct task_struct *child, addr_t addr)
163 struct user *dummy = NULL;
166 if (addr < (addr_t) &dummy->regs.acrs) {
168 * psw and gprs are stored on the stack
170 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
171 if (addr == (addr_t) &dummy->regs.psw.mask)
172 /* Return a clean psw mask. */
173 tmp = psw_user_bits | (tmp & PSW_MASK_USER) |
174 PSW_MASK_EA | PSW_MASK_BA;
176 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
178 * access registers are stored in the thread structure
180 offset = addr - (addr_t) &dummy->regs.acrs;
183 * Very special case: old & broken 64 bit gdb reading
184 * from acrs[15]. Result is a 64 bit value. Read the
185 * 32 bit acrs[15] value and shift it by 32. Sick...
187 if (addr == (addr_t) &dummy->regs.acrs[15])
188 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
191 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
193 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
195 * orig_gpr2 is stored on the kernel stack
197 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
199 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
201 * prevent reads of padding hole between
202 * orig_gpr2 and fp_regs on s390.
206 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
208 * floating point regs. are stored in the thread structure
210 offset = addr - (addr_t) &dummy->regs.fp_regs;
211 tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
212 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
213 tmp &= (unsigned long) FPC_VALID_MASK
214 << (BITS_PER_LONG - 32);
216 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
218 * Handle access to the per_info structure.
220 addr -= (addr_t) &dummy->regs.per_info;
221 tmp = __peek_user_per(child, addr);
230 peek_user(struct task_struct *child, addr_t addr, addr_t data)
235 * Stupid gdb peeks/pokes the access registers in 64 bit with
236 * an alignment of 4. Programmers from hell...
240 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
241 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
244 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
247 tmp = __peek_user(child, addr);
248 return put_user(tmp, (addr_t __user *) data);
251 static inline void __poke_user_per(struct task_struct *child,
252 addr_t addr, addr_t data)
254 struct per_struct_kernel *dummy = NULL;
257 * There are only three fields in the per_info struct that the
258 * debugger user can write to.
259 * 1) cr9: the debugger wants to set a new PER event mask
260 * 2) starting_addr: the debugger wants to set a new starting
261 * address to use with the PER event mask.
262 * 3) ending_addr: the debugger wants to set a new ending
263 * address to use with the PER event mask.
264 * The user specified PER event mask and the start and end
265 * addresses are used only if single stepping is not in effect.
266 * Writes to any other field in per_info are ignored.
268 if (addr == (addr_t) &dummy->cr9)
269 /* PER event mask of the user specified per set. */
270 child->thread.per_user.control =
271 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
272 else if (addr == (addr_t) &dummy->starting_addr)
273 /* Starting address of the user specified per set. */
274 child->thread.per_user.start = data;
275 else if (addr == (addr_t) &dummy->ending_addr)
276 /* Ending address of the user specified per set. */
277 child->thread.per_user.end = data;
281 * Write a word to the user area of a process at location addr. This
282 * operation does have an additional problem compared to peek_user.
283 * Stores to the program status word and on the floating point
284 * control register needs to get checked for validity.
286 static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
288 struct user *dummy = NULL;
291 if (addr < (addr_t) &dummy->regs.acrs) {
293 * psw and gprs are stored on the stack
295 tmp = (data & ~PSW_MASK_USER) ^ psw_user_bits;
296 if (addr == (addr_t) &dummy->regs.psw.mask &&
298 tmp != PSW_MASK_BA &&
300 tmp != (PSW_MASK_EA | PSW_MASK_BA))
301 /* Invalid psw mask. */
304 if (addr == (addr_t) &dummy->regs.psw.addr)
305 /* I'd like to reject addresses without the
306 high order bit but older gdb's rely on it */
307 data |= PSW_ADDR_AMODE;
309 if (addr == (addr_t) &dummy->regs.psw.addr)
311 * The debugger changed the instruction address,
312 * reset system call restart, see signal.c:do_signal
314 task_thread_info(child)->system_call = 0;
316 *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
318 } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
320 * access registers are stored in the thread structure
322 offset = addr - (addr_t) &dummy->regs.acrs;
325 * Very special case: old & broken 64 bit gdb writing
326 * to acrs[15] with a 64 bit value. Ignore the lower
327 * half of the value and write the upper 32 bit to
330 if (addr == (addr_t) &dummy->regs.acrs[15])
331 child->thread.acrs[15] = (unsigned int) (data >> 32);
334 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
336 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
338 * orig_gpr2 is stored on the kernel stack
340 task_pt_regs(child)->orig_gpr2 = data;
342 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
344 * prevent writes of padding hole between
345 * orig_gpr2 and fp_regs on s390.
349 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
351 * floating point regs. are stored in the thread structure
353 if (addr == (addr_t) &dummy->regs.fp_regs.fpc &&
354 (data & ~((unsigned long) FPC_VALID_MASK
355 << (BITS_PER_LONG - 32))) != 0)
357 offset = addr - (addr_t) &dummy->regs.fp_regs;
358 *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
360 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
362 * Handle access to the per_info structure.
364 addr -= (addr_t) &dummy->regs.per_info;
365 __poke_user_per(child, addr, data);
372 static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
377 * Stupid gdb peeks/pokes the access registers in 64 bit with
378 * an alignment of 4. Programmers from hell indeed...
382 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
383 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
386 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
389 return __poke_user(child, addr, data);
392 long arch_ptrace(struct task_struct *child, long request,
393 unsigned long addr, unsigned long data)
400 /* read the word at location addr in the USER area. */
401 return peek_user(child, addr, data);
404 /* write the word at location addr in the USER area */
405 return poke_user(child, addr, data);
407 case PTRACE_PEEKUSR_AREA:
408 case PTRACE_POKEUSR_AREA:
409 if (copy_from_user(&parea, (void __force __user *) addr,
412 addr = parea.kernel_addr;
413 data = parea.process_addr;
415 while (copied < parea.len) {
416 if (request == PTRACE_PEEKUSR_AREA)
417 ret = peek_user(child, addr, data);
421 (addr_t __force __user *) data))
423 ret = poke_user(child, addr, utmp);
427 addr += sizeof(unsigned long);
428 data += sizeof(unsigned long);
429 copied += sizeof(unsigned long);
432 case PTRACE_GET_LAST_BREAK:
433 put_user(task_thread_info(child)->last_break,
434 (unsigned long __user *) data);
437 /* Removing high order bit from addr (only for 31 bit). */
438 addr &= PSW_ADDR_INSN;
439 return ptrace_request(child, request, addr, data);
445 * Now the fun part starts... a 31 bit program running in the
446 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
447 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
448 * to handle, the difference to the 64 bit versions of the requests
449 * is that the access is done in multiples of 4 byte instead of
450 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
451 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
452 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
453 * is a 31 bit program too, the content of struct user can be
454 * emulated. A 31 bit program peeking into the struct user of
455 * a 64 bit program is a no-no.
459 * Same as peek_user_per but for a 31 bit program.
461 static inline __u32 __peek_user_per_compat(struct task_struct *child,
464 struct compat_per_struct_kernel *dummy32 = NULL;
466 if (addr == (addr_t) &dummy32->cr9)
467 /* Control bits of the active per set. */
468 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
469 PER_EVENT_IFETCH : child->thread.per_user.control;
470 else if (addr == (addr_t) &dummy32->cr10)
471 /* Start address of the active per set. */
472 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
473 0 : child->thread.per_user.start;
474 else if (addr == (addr_t) &dummy32->cr11)
475 /* End address of the active per set. */
476 return test_thread_flag(TIF_SINGLE_STEP) ?
477 PSW32_ADDR_INSN : child->thread.per_user.end;
478 else if (addr == (addr_t) &dummy32->bits)
479 /* Single-step bit. */
480 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
482 else if (addr == (addr_t) &dummy32->starting_addr)
483 /* Start address of the user specified per set. */
484 return (__u32) child->thread.per_user.start;
485 else if (addr == (addr_t) &dummy32->ending_addr)
486 /* End address of the user specified per set. */
487 return (__u32) child->thread.per_user.end;
488 else if (addr == (addr_t) &dummy32->perc_atmid)
489 /* PER code, ATMID and AI of the last PER trap */
490 return (__u32) child->thread.per_event.cause << 16;
491 else if (addr == (addr_t) &dummy32->address)
492 /* Address of the last PER trap */
493 return (__u32) child->thread.per_event.address;
494 else if (addr == (addr_t) &dummy32->access_id)
495 /* Access id of the last PER trap */
496 return (__u32) child->thread.per_event.paid << 24;
501 * Same as peek_user but for a 31 bit program.
503 static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
505 struct compat_user *dummy32 = NULL;
509 if (addr < (addr_t) &dummy32->regs.acrs) {
510 struct pt_regs *regs = task_pt_regs(child);
512 * psw and gprs are stored on the stack
514 if (addr == (addr_t) &dummy32->regs.psw.mask) {
515 /* Fake a 31 bit psw mask. */
516 tmp = (__u32)(regs->psw.mask >> 32);
517 tmp = psw32_user_bits | (tmp & PSW32_MASK_USER);
518 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
519 /* Fake a 31 bit psw address. */
520 tmp = (__u32) regs->psw.addr | PSW32_ADDR_AMODE;
523 tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4);
525 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
527 * access registers are stored in the thread structure
529 offset = addr - (addr_t) &dummy32->regs.acrs;
530 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
532 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
534 * orig_gpr2 is stored on the kernel stack
536 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
538 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
540 * prevent reads of padding hole between
541 * orig_gpr2 and fp_regs on s390.
545 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
547 * floating point regs. are stored in the thread structure
549 offset = addr - (addr_t) &dummy32->regs.fp_regs;
550 tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
552 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
554 * Handle access to the per_info structure.
556 addr -= (addr_t) &dummy32->regs.per_info;
557 tmp = __peek_user_per_compat(child, addr);
565 static int peek_user_compat(struct task_struct *child,
566 addr_t addr, addr_t data)
570 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
573 tmp = __peek_user_compat(child, addr);
574 return put_user(tmp, (__u32 __user *) data);
578 * Same as poke_user_per but for a 31 bit program.
580 static inline void __poke_user_per_compat(struct task_struct *child,
581 addr_t addr, __u32 data)
583 struct compat_per_struct_kernel *dummy32 = NULL;
585 if (addr == (addr_t) &dummy32->cr9)
586 /* PER event mask of the user specified per set. */
587 child->thread.per_user.control =
588 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
589 else if (addr == (addr_t) &dummy32->starting_addr)
590 /* Starting address of the user specified per set. */
591 child->thread.per_user.start = data;
592 else if (addr == (addr_t) &dummy32->ending_addr)
593 /* Ending address of the user specified per set. */
594 child->thread.per_user.end = data;
598 * Same as poke_user but for a 31 bit program.
600 static int __poke_user_compat(struct task_struct *child,
601 addr_t addr, addr_t data)
603 struct compat_user *dummy32 = NULL;
604 __u32 tmp = (__u32) data;
607 if (addr < (addr_t) &dummy32->regs.acrs) {
608 struct pt_regs *regs = task_pt_regs(child);
610 * psw, gprs, acrs and orig_gpr2 are stored on the stack
612 if (addr == (addr_t) &dummy32->regs.psw.mask) {
613 /* Build a 64 bit psw mask from 31 bit mask. */
614 if ((tmp & ~PSW32_MASK_USER) != psw32_user_bits)
615 /* Invalid psw mask. */
617 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
618 (__u64)(tmp & PSW32_MASK_USER) << 32;
619 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
620 /* Build a 64 bit psw address from 31 bit address. */
621 regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
623 * The debugger changed the instruction address,
624 * reset system call restart, see signal.c:do_signal
626 task_thread_info(child)->system_call = 0;
629 *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp;
631 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
633 * access registers are stored in the thread structure
635 offset = addr - (addr_t) &dummy32->regs.acrs;
636 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
638 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
640 * orig_gpr2 is stored on the kernel stack
642 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
644 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
646 * prevent writess of padding hole between
647 * orig_gpr2 and fp_regs on s390.
651 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
653 * floating point regs. are stored in the thread structure
655 if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
656 (tmp & ~FPC_VALID_MASK) != 0)
657 /* Invalid floating point control. */
659 offset = addr - (addr_t) &dummy32->regs.fp_regs;
660 *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
662 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
664 * Handle access to the per_info structure.
666 addr -= (addr_t) &dummy32->regs.per_info;
667 __poke_user_per_compat(child, addr, data);
673 static int poke_user_compat(struct task_struct *child,
674 addr_t addr, addr_t data)
676 if (!is_compat_task() || (addr & 3) ||
677 addr > sizeof(struct compat_user) - 3)
680 return __poke_user_compat(child, addr, data);
683 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
684 compat_ulong_t caddr, compat_ulong_t cdata)
686 unsigned long addr = caddr;
687 unsigned long data = cdata;
688 compat_ptrace_area parea;
693 /* read the word at location addr in the USER area. */
694 return peek_user_compat(child, addr, data);
697 /* write the word at location addr in the USER area */
698 return poke_user_compat(child, addr, data);
700 case PTRACE_PEEKUSR_AREA:
701 case PTRACE_POKEUSR_AREA:
702 if (copy_from_user(&parea, (void __force __user *) addr,
705 addr = parea.kernel_addr;
706 data = parea.process_addr;
708 while (copied < parea.len) {
709 if (request == PTRACE_PEEKUSR_AREA)
710 ret = peek_user_compat(child, addr, data);
714 (__u32 __force __user *) data))
716 ret = poke_user_compat(child, addr, utmp);
720 addr += sizeof(unsigned int);
721 data += sizeof(unsigned int);
722 copied += sizeof(unsigned int);
725 case PTRACE_GET_LAST_BREAK:
726 put_user(task_thread_info(child)->last_break,
727 (unsigned int __user *) data);
730 return compat_ptrace_request(child, request, addr, data);
734 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
738 /* Do the secure computing check first. */
739 secure_computing(regs->gprs[2]);
742 * The sysc_tracesys code in entry.S stored the system
743 * call number to gprs[2].
745 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
746 (tracehook_report_syscall_entry(regs) ||
747 regs->gprs[2] >= NR_syscalls)) {
749 * Tracing decided this syscall should not happen or the
750 * debugger stored an invalid system call number. Skip
751 * the system call and the system call restart handling.
753 clear_thread_flag(TIF_SYSCALL);
757 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
758 trace_sys_enter(regs, regs->gprs[2]);
760 if (unlikely(current->audit_context))
761 audit_syscall_entry(is_compat_task() ?
762 AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
763 regs->gprs[2], regs->orig_gpr2,
764 regs->gprs[3], regs->gprs[4],
766 return ret ?: regs->gprs[2];
769 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
771 if (unlikely(current->audit_context))
772 audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
775 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
776 trace_sys_exit(regs, regs->gprs[2]);
778 if (test_thread_flag(TIF_SYSCALL_TRACE))
779 tracehook_report_syscall_exit(regs, 0);
783 * user_regset definitions.
786 static int s390_regs_get(struct task_struct *target,
787 const struct user_regset *regset,
788 unsigned int pos, unsigned int count,
789 void *kbuf, void __user *ubuf)
791 if (target == current)
792 save_access_regs(target->thread.acrs);
795 unsigned long *k = kbuf;
797 *k++ = __peek_user(target, pos);
802 unsigned long __user *u = ubuf;
804 if (__put_user(__peek_user(target, pos), u++))
813 static int s390_regs_set(struct task_struct *target,
814 const struct user_regset *regset,
815 unsigned int pos, unsigned int count,
816 const void *kbuf, const void __user *ubuf)
820 if (target == current)
821 save_access_regs(target->thread.acrs);
824 const unsigned long *k = kbuf;
825 while (count > 0 && !rc) {
826 rc = __poke_user(target, pos, *k++);
831 const unsigned long __user *u = ubuf;
832 while (count > 0 && !rc) {
834 rc = __get_user(word, u++);
837 rc = __poke_user(target, pos, word);
843 if (rc == 0 && target == current)
844 restore_access_regs(target->thread.acrs);
849 static int s390_fpregs_get(struct task_struct *target,
850 const struct user_regset *regset, unsigned int pos,
851 unsigned int count, void *kbuf, void __user *ubuf)
853 if (target == current)
854 save_fp_regs(&target->thread.fp_regs);
856 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
857 &target->thread.fp_regs, 0, -1);
860 static int s390_fpregs_set(struct task_struct *target,
861 const struct user_regset *regset, unsigned int pos,
862 unsigned int count, const void *kbuf,
863 const void __user *ubuf)
867 if (target == current)
868 save_fp_regs(&target->thread.fp_regs);
870 /* If setting FPC, must validate it first. */
871 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
872 u32 fpc[2] = { target->thread.fp_regs.fpc, 0 };
873 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc,
874 0, offsetof(s390_fp_regs, fprs));
877 if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0)
879 target->thread.fp_regs.fpc = fpc[0];
882 if (rc == 0 && count > 0)
883 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
884 target->thread.fp_regs.fprs,
885 offsetof(s390_fp_regs, fprs), -1);
887 if (rc == 0 && target == current)
888 restore_fp_regs(&target->thread.fp_regs);
895 static int s390_last_break_get(struct task_struct *target,
896 const struct user_regset *regset,
897 unsigned int pos, unsigned int count,
898 void *kbuf, void __user *ubuf)
902 unsigned long *k = kbuf;
903 *k = task_thread_info(target)->last_break;
905 unsigned long __user *u = ubuf;
906 if (__put_user(task_thread_info(target)->last_break, u))
915 static int s390_system_call_get(struct task_struct *target,
916 const struct user_regset *regset,
917 unsigned int pos, unsigned int count,
918 void *kbuf, void __user *ubuf)
920 unsigned int *data = &task_thread_info(target)->system_call;
921 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
922 data, 0, sizeof(unsigned int));
925 static int s390_system_call_set(struct task_struct *target,
926 const struct user_regset *regset,
927 unsigned int pos, unsigned int count,
928 const void *kbuf, const void __user *ubuf)
930 unsigned int *data = &task_thread_info(target)->system_call;
931 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
932 data, 0, sizeof(unsigned int));
935 static const struct user_regset s390_regsets[] = {
937 .core_note_type = NT_PRSTATUS,
938 .n = sizeof(s390_regs) / sizeof(long),
939 .size = sizeof(long),
940 .align = sizeof(long),
941 .get = s390_regs_get,
942 .set = s390_regs_set,
945 .core_note_type = NT_PRFPREG,
946 .n = sizeof(s390_fp_regs) / sizeof(long),
947 .size = sizeof(long),
948 .align = sizeof(long),
949 .get = s390_fpregs_get,
950 .set = s390_fpregs_set,
953 [REGSET_LAST_BREAK] = {
954 .core_note_type = NT_S390_LAST_BREAK,
956 .size = sizeof(long),
957 .align = sizeof(long),
958 .get = s390_last_break_get,
961 [REGSET_SYSTEM_CALL] = {
962 .core_note_type = NT_S390_SYSTEM_CALL,
964 .size = sizeof(unsigned int),
965 .align = sizeof(unsigned int),
966 .get = s390_system_call_get,
967 .set = s390_system_call_set,
971 static const struct user_regset_view user_s390_view = {
973 .e_machine = EM_S390,
974 .regsets = s390_regsets,
975 .n = ARRAY_SIZE(s390_regsets)
979 static int s390_compat_regs_get(struct task_struct *target,
980 const struct user_regset *regset,
981 unsigned int pos, unsigned int count,
982 void *kbuf, void __user *ubuf)
984 if (target == current)
985 save_access_regs(target->thread.acrs);
988 compat_ulong_t *k = kbuf;
990 *k++ = __peek_user_compat(target, pos);
995 compat_ulong_t __user *u = ubuf;
997 if (__put_user(__peek_user_compat(target, pos), u++))
1006 static int s390_compat_regs_set(struct task_struct *target,
1007 const struct user_regset *regset,
1008 unsigned int pos, unsigned int count,
1009 const void *kbuf, const void __user *ubuf)
1013 if (target == current)
1014 save_access_regs(target->thread.acrs);
1017 const compat_ulong_t *k = kbuf;
1018 while (count > 0 && !rc) {
1019 rc = __poke_user_compat(target, pos, *k++);
1020 count -= sizeof(*k);
1024 const compat_ulong_t __user *u = ubuf;
1025 while (count > 0 && !rc) {
1026 compat_ulong_t word;
1027 rc = __get_user(word, u++);
1030 rc = __poke_user_compat(target, pos, word);
1031 count -= sizeof(*u);
1036 if (rc == 0 && target == current)
1037 restore_access_regs(target->thread.acrs);
1042 static int s390_compat_regs_high_get(struct task_struct *target,
1043 const struct user_regset *regset,
1044 unsigned int pos, unsigned int count,
1045 void *kbuf, void __user *ubuf)
1047 compat_ulong_t *gprs_high;
1049 gprs_high = (compat_ulong_t *)
1050 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1052 compat_ulong_t *k = kbuf;
1056 count -= sizeof(*k);
1059 compat_ulong_t __user *u = ubuf;
1061 if (__put_user(*gprs_high, u++))
1064 count -= sizeof(*u);
1070 static int s390_compat_regs_high_set(struct task_struct *target,
1071 const struct user_regset *regset,
1072 unsigned int pos, unsigned int count,
1073 const void *kbuf, const void __user *ubuf)
1075 compat_ulong_t *gprs_high;
1078 gprs_high = (compat_ulong_t *)
1079 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1081 const compat_ulong_t *k = kbuf;
1085 count -= sizeof(*k);
1088 const compat_ulong_t __user *u = ubuf;
1089 while (count > 0 && !rc) {
1091 rc = __get_user(word, u++);
1096 count -= sizeof(*u);
1103 static int s390_compat_last_break_get(struct task_struct *target,
1104 const struct user_regset *regset,
1105 unsigned int pos, unsigned int count,
1106 void *kbuf, void __user *ubuf)
1108 compat_ulong_t last_break;
1111 last_break = task_thread_info(target)->last_break;
1113 unsigned long *k = kbuf;
1116 unsigned long __user *u = ubuf;
1117 if (__put_user(last_break, u))
1124 static const struct user_regset s390_compat_regsets[] = {
1125 [REGSET_GENERAL] = {
1126 .core_note_type = NT_PRSTATUS,
1127 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1128 .size = sizeof(compat_long_t),
1129 .align = sizeof(compat_long_t),
1130 .get = s390_compat_regs_get,
1131 .set = s390_compat_regs_set,
1134 .core_note_type = NT_PRFPREG,
1135 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1136 .size = sizeof(compat_long_t),
1137 .align = sizeof(compat_long_t),
1138 .get = s390_fpregs_get,
1139 .set = s390_fpregs_set,
1141 [REGSET_LAST_BREAK] = {
1142 .core_note_type = NT_S390_LAST_BREAK,
1144 .size = sizeof(long),
1145 .align = sizeof(long),
1146 .get = s390_compat_last_break_get,
1148 [REGSET_SYSTEM_CALL] = {
1149 .core_note_type = NT_S390_SYSTEM_CALL,
1151 .size = sizeof(compat_uint_t),
1152 .align = sizeof(compat_uint_t),
1153 .get = s390_system_call_get,
1154 .set = s390_system_call_set,
1156 [REGSET_GENERAL_EXTENDED] = {
1157 .core_note_type = NT_S390_HIGH_GPRS,
1158 .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
1159 .size = sizeof(compat_long_t),
1160 .align = sizeof(compat_long_t),
1161 .get = s390_compat_regs_high_get,
1162 .set = s390_compat_regs_high_set,
1166 static const struct user_regset_view user_s390_compat_view = {
1168 .e_machine = EM_S390,
1169 .regsets = s390_compat_regsets,
1170 .n = ARRAY_SIZE(s390_compat_regsets)
1174 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1176 #ifdef CONFIG_COMPAT
1177 if (test_tsk_thread_flag(task, TIF_31BIT))
1178 return &user_s390_compat_view;
1180 return &user_s390_view;
1183 static const char *gpr_names[NUM_GPRS] = {
1184 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1185 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1188 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1190 if (offset >= NUM_GPRS)
1192 return regs->gprs[offset];
1195 int regs_query_register_offset(const char *name)
1197 unsigned long offset;
1199 if (!name || *name != 'r')
1201 if (strict_strtoul(name + 1, 10, &offset))
1203 if (offset >= NUM_GPRS)
1208 const char *regs_query_register_name(unsigned int offset)
1210 if (offset >= NUM_GPRS)
1212 return gpr_names[offset];
1215 static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1217 unsigned long ksp = kernel_stack_pointer(regs);
1219 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1223 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1224 * @regs:pt_regs which contains kernel stack pointer.
1225 * @n:stack entry number.
1227 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1228 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1231 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1235 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1236 if (!regs_within_kernel_stack(regs, addr))
1238 return *(unsigned long *)addr;