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>
47 REGSET_GENERAL_EXTENDED,
50 void update_cr_regs(struct task_struct *task)
52 struct pt_regs *regs = task_pt_regs(task);
53 struct thread_struct *thread = &task->thread;
54 struct per_regs old, new;
57 /* Take care of the enable/disable of transactional execution. */
59 unsigned long cr[3], cr_new[3];
61 __ctl_store(cr, 0, 2);
63 /* Set or clear transaction execution TXC bit 8. */
64 if (task->thread.per_flags & PER_FLAG_NO_TE)
65 cr_new[0] = cr[0] & ~(1UL << 55);
67 cr_new[0] = cr[0] | (1UL << 55);
68 /* Set or clear transaction execution TDC bits 62 and 63. */
69 cr_new[2] = cr[2] & ~3UL;
70 if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) {
71 if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND_TEND)
76 if (memcmp(&cr_new, &cr, sizeof(cr)))
77 __ctl_load(cr_new, 0, 2);
80 /* Copy user specified PER registers */
81 new.control = thread->per_user.control;
82 new.start = thread->per_user.start;
83 new.end = thread->per_user.end;
85 /* merge TIF_SINGLE_STEP into user specified PER registers. */
86 if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) {
87 new.control |= PER_EVENT_IFETCH;
89 new.control |= PER_CONTROL_SUSPENSION;
90 new.control |= PER_EVENT_TRANSACTION_END;
93 new.end = PSW_ADDR_INSN;
96 /* Take care of the PER enablement bit in the PSW. */
97 if (!(new.control & PER_EVENT_MASK)) {
98 regs->psw.mask &= ~PSW_MASK_PER;
101 regs->psw.mask |= PSW_MASK_PER;
102 __ctl_store(old, 9, 11);
103 if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
104 __ctl_load(new, 9, 11);
107 void user_enable_single_step(struct task_struct *task)
109 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
111 update_cr_regs(task);
114 void user_disable_single_step(struct task_struct *task)
116 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
118 update_cr_regs(task);
122 * Called by kernel/ptrace.c when detaching..
124 * Clear all debugging related fields.
126 void ptrace_disable(struct task_struct *task)
128 memset(&task->thread.per_user, 0, sizeof(task->thread.per_user));
129 memset(&task->thread.per_event, 0, sizeof(task->thread.per_event));
130 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
131 clear_tsk_thread_flag(task, TIF_PER_TRAP);
132 task->thread.per_flags = 0;
136 # define __ADDR_MASK 3
138 # define __ADDR_MASK 7
141 static inline unsigned long __peek_user_per(struct task_struct *child,
144 struct per_struct_kernel *dummy = NULL;
146 if (addr == (addr_t) &dummy->cr9)
147 /* Control bits of the active per set. */
148 return test_thread_flag(TIF_SINGLE_STEP) ?
149 PER_EVENT_IFETCH : child->thread.per_user.control;
150 else if (addr == (addr_t) &dummy->cr10)
151 /* Start address of the active per set. */
152 return test_thread_flag(TIF_SINGLE_STEP) ?
153 0 : child->thread.per_user.start;
154 else if (addr == (addr_t) &dummy->cr11)
155 /* End address of the active per set. */
156 return test_thread_flag(TIF_SINGLE_STEP) ?
157 PSW_ADDR_INSN : child->thread.per_user.end;
158 else if (addr == (addr_t) &dummy->bits)
159 /* Single-step bit. */
160 return test_thread_flag(TIF_SINGLE_STEP) ?
161 (1UL << (BITS_PER_LONG - 1)) : 0;
162 else if (addr == (addr_t) &dummy->starting_addr)
163 /* Start address of the user specified per set. */
164 return child->thread.per_user.start;
165 else if (addr == (addr_t) &dummy->ending_addr)
166 /* End address of the user specified per set. */
167 return child->thread.per_user.end;
168 else if (addr == (addr_t) &dummy->perc_atmid)
169 /* PER code, ATMID and AI of the last PER trap */
170 return (unsigned long)
171 child->thread.per_event.cause << (BITS_PER_LONG - 16);
172 else if (addr == (addr_t) &dummy->address)
173 /* Address of the last PER trap */
174 return child->thread.per_event.address;
175 else if (addr == (addr_t) &dummy->access_id)
176 /* Access id of the last PER trap */
177 return (unsigned long)
178 child->thread.per_event.paid << (BITS_PER_LONG - 8);
183 * Read the word at offset addr from the user area of a process. The
184 * trouble here is that the information is littered over different
185 * locations. The process registers are found on the kernel stack,
186 * the floating point stuff and the trace settings are stored in
187 * the task structure. In addition the different structures in
188 * struct user contain pad bytes that should be read as zeroes.
191 static unsigned long __peek_user(struct task_struct *child, addr_t addr)
193 struct user *dummy = NULL;
196 if (addr < (addr_t) &dummy->regs.acrs) {
198 * psw and gprs are stored on the stack
200 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
201 if (addr == (addr_t) &dummy->regs.psw.mask) {
202 /* Return a clean psw mask. */
203 tmp &= PSW_MASK_USER | PSW_MASK_RI;
204 tmp |= PSW_USER_BITS;
207 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
209 * access registers are stored in the thread structure
211 offset = addr - (addr_t) &dummy->regs.acrs;
214 * Very special case: old & broken 64 bit gdb reading
215 * from acrs[15]. Result is a 64 bit value. Read the
216 * 32 bit acrs[15] value and shift it by 32. Sick...
218 if (addr == (addr_t) &dummy->regs.acrs[15])
219 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
222 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
224 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
226 * orig_gpr2 is stored on the kernel stack
228 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
230 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
232 * prevent reads of padding hole between
233 * orig_gpr2 and fp_regs on s390.
237 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
239 * floating point regs. are stored in the thread structure
241 offset = addr - (addr_t) &dummy->regs.fp_regs;
242 tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
243 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
244 tmp <<= BITS_PER_LONG - 32;
246 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
248 * Handle access to the per_info structure.
250 addr -= (addr_t) &dummy->regs.per_info;
251 tmp = __peek_user_per(child, addr);
260 peek_user(struct task_struct *child, addr_t addr, addr_t data)
265 * Stupid gdb peeks/pokes the access registers in 64 bit with
266 * an alignment of 4. Programmers from hell...
270 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
271 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
274 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
277 tmp = __peek_user(child, addr);
278 return put_user(tmp, (addr_t __user *) data);
281 static inline void __poke_user_per(struct task_struct *child,
282 addr_t addr, addr_t data)
284 struct per_struct_kernel *dummy = NULL;
287 * There are only three fields in the per_info struct that the
288 * debugger user can write to.
289 * 1) cr9: the debugger wants to set a new PER event mask
290 * 2) starting_addr: the debugger wants to set a new starting
291 * address to use with the PER event mask.
292 * 3) ending_addr: the debugger wants to set a new ending
293 * address to use with the PER event mask.
294 * The user specified PER event mask and the start and end
295 * addresses are used only if single stepping is not in effect.
296 * Writes to any other field in per_info are ignored.
298 if (addr == (addr_t) &dummy->cr9)
299 /* PER event mask of the user specified per set. */
300 child->thread.per_user.control =
301 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
302 else if (addr == (addr_t) &dummy->starting_addr)
303 /* Starting address of the user specified per set. */
304 child->thread.per_user.start = data;
305 else if (addr == (addr_t) &dummy->ending_addr)
306 /* Ending address of the user specified per set. */
307 child->thread.per_user.end = data;
311 * Write a word to the user area of a process at location addr. This
312 * operation does have an additional problem compared to peek_user.
313 * Stores to the program status word and on the floating point
314 * control register needs to get checked for validity.
316 static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
318 struct user *dummy = NULL;
321 if (addr < (addr_t) &dummy->regs.acrs) {
323 * psw and gprs are stored on the stack
325 if (addr == (addr_t) &dummy->regs.psw.mask) {
326 unsigned long mask = PSW_MASK_USER;
328 mask |= is_ri_task(child) ? PSW_MASK_RI : 0;
329 if ((data & ~mask) != PSW_USER_BITS)
331 if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))
334 *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
336 } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
338 * access registers are stored in the thread structure
340 offset = addr - (addr_t) &dummy->regs.acrs;
343 * Very special case: old & broken 64 bit gdb writing
344 * to acrs[15] with a 64 bit value. Ignore the lower
345 * half of the value and write the upper 32 bit to
348 if (addr == (addr_t) &dummy->regs.acrs[15])
349 child->thread.acrs[15] = (unsigned int) (data >> 32);
352 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
354 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
356 * orig_gpr2 is stored on the kernel stack
358 task_pt_regs(child)->orig_gpr2 = data;
360 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
362 * prevent writes of padding hole between
363 * orig_gpr2 and fp_regs on s390.
367 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
369 * floating point regs. are stored in the thread structure
371 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
372 if ((unsigned int) data != 0 ||
373 test_fp_ctl(data >> (BITS_PER_LONG - 32)))
375 offset = addr - (addr_t) &dummy->regs.fp_regs;
376 *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
378 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
380 * Handle access to the per_info structure.
382 addr -= (addr_t) &dummy->regs.per_info;
383 __poke_user_per(child, addr, data);
390 static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
395 * Stupid gdb peeks/pokes the access registers in 64 bit with
396 * an alignment of 4. Programmers from hell indeed...
400 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
401 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
404 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
407 return __poke_user(child, addr, data);
410 long arch_ptrace(struct task_struct *child, long request,
411 unsigned long addr, unsigned long data)
418 /* read the word at location addr in the USER area. */
419 return peek_user(child, addr, data);
422 /* write the word at location addr in the USER area */
423 return poke_user(child, addr, data);
425 case PTRACE_PEEKUSR_AREA:
426 case PTRACE_POKEUSR_AREA:
427 if (copy_from_user(&parea, (void __force __user *) addr,
430 addr = parea.kernel_addr;
431 data = parea.process_addr;
433 while (copied < parea.len) {
434 if (request == PTRACE_PEEKUSR_AREA)
435 ret = peek_user(child, addr, data);
439 (addr_t __force __user *) data))
441 ret = poke_user(child, addr, utmp);
445 addr += sizeof(unsigned long);
446 data += sizeof(unsigned long);
447 copied += sizeof(unsigned long);
450 case PTRACE_GET_LAST_BREAK:
451 put_user(task_thread_info(child)->last_break,
452 (unsigned long __user *) data);
454 case PTRACE_ENABLE_TE:
457 child->thread.per_flags &= ~PER_FLAG_NO_TE;
459 case PTRACE_DISABLE_TE:
462 child->thread.per_flags |= PER_FLAG_NO_TE;
463 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
465 case PTRACE_TE_ABORT_RAND:
466 if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
470 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
473 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
474 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
477 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
478 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
485 /* Removing high order bit from addr (only for 31 bit). */
486 addr &= PSW_ADDR_INSN;
487 return ptrace_request(child, request, addr, data);
493 * Now the fun part starts... a 31 bit program running in the
494 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
495 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
496 * to handle, the difference to the 64 bit versions of the requests
497 * is that the access is done in multiples of 4 byte instead of
498 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
499 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
500 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
501 * is a 31 bit program too, the content of struct user can be
502 * emulated. A 31 bit program peeking into the struct user of
503 * a 64 bit program is a no-no.
507 * Same as peek_user_per but for a 31 bit program.
509 static inline __u32 __peek_user_per_compat(struct task_struct *child,
512 struct compat_per_struct_kernel *dummy32 = NULL;
514 if (addr == (addr_t) &dummy32->cr9)
515 /* Control bits of the active per set. */
516 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
517 PER_EVENT_IFETCH : child->thread.per_user.control;
518 else if (addr == (addr_t) &dummy32->cr10)
519 /* Start address of the active per set. */
520 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
521 0 : child->thread.per_user.start;
522 else if (addr == (addr_t) &dummy32->cr11)
523 /* End address of the active per set. */
524 return test_thread_flag(TIF_SINGLE_STEP) ?
525 PSW32_ADDR_INSN : child->thread.per_user.end;
526 else if (addr == (addr_t) &dummy32->bits)
527 /* Single-step bit. */
528 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
530 else if (addr == (addr_t) &dummy32->starting_addr)
531 /* Start address of the user specified per set. */
532 return (__u32) child->thread.per_user.start;
533 else if (addr == (addr_t) &dummy32->ending_addr)
534 /* End address of the user specified per set. */
535 return (__u32) child->thread.per_user.end;
536 else if (addr == (addr_t) &dummy32->perc_atmid)
537 /* PER code, ATMID and AI of the last PER trap */
538 return (__u32) child->thread.per_event.cause << 16;
539 else if (addr == (addr_t) &dummy32->address)
540 /* Address of the last PER trap */
541 return (__u32) child->thread.per_event.address;
542 else if (addr == (addr_t) &dummy32->access_id)
543 /* Access id of the last PER trap */
544 return (__u32) child->thread.per_event.paid << 24;
549 * Same as peek_user but for a 31 bit program.
551 static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
553 struct compat_user *dummy32 = NULL;
557 if (addr < (addr_t) &dummy32->regs.acrs) {
558 struct pt_regs *regs = task_pt_regs(child);
560 * psw and gprs are stored on the stack
562 if (addr == (addr_t) &dummy32->regs.psw.mask) {
563 /* Fake a 31 bit psw mask. */
564 tmp = (__u32)(regs->psw.mask >> 32);
565 tmp &= PSW32_MASK_USER | PSW32_MASK_RI;
566 tmp |= PSW32_USER_BITS;
567 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
568 /* Fake a 31 bit psw address. */
569 tmp = (__u32) regs->psw.addr |
570 (__u32)(regs->psw.mask & PSW_MASK_BA);
573 tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4);
575 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
577 * access registers are stored in the thread structure
579 offset = addr - (addr_t) &dummy32->regs.acrs;
580 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
582 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
584 * orig_gpr2 is stored on the kernel stack
586 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
588 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
590 * prevent reads of padding hole between
591 * orig_gpr2 and fp_regs on s390.
595 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
597 * floating point regs. are stored in the thread structure
599 offset = addr - (addr_t) &dummy32->regs.fp_regs;
600 tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
602 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
604 * Handle access to the per_info structure.
606 addr -= (addr_t) &dummy32->regs.per_info;
607 tmp = __peek_user_per_compat(child, addr);
615 static int peek_user_compat(struct task_struct *child,
616 addr_t addr, addr_t data)
620 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
623 tmp = __peek_user_compat(child, addr);
624 return put_user(tmp, (__u32 __user *) data);
628 * Same as poke_user_per but for a 31 bit program.
630 static inline void __poke_user_per_compat(struct task_struct *child,
631 addr_t addr, __u32 data)
633 struct compat_per_struct_kernel *dummy32 = NULL;
635 if (addr == (addr_t) &dummy32->cr9)
636 /* PER event mask of the user specified per set. */
637 child->thread.per_user.control =
638 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
639 else if (addr == (addr_t) &dummy32->starting_addr)
640 /* Starting address of the user specified per set. */
641 child->thread.per_user.start = data;
642 else if (addr == (addr_t) &dummy32->ending_addr)
643 /* Ending address of the user specified per set. */
644 child->thread.per_user.end = data;
648 * Same as poke_user but for a 31 bit program.
650 static int __poke_user_compat(struct task_struct *child,
651 addr_t addr, addr_t data)
653 struct compat_user *dummy32 = NULL;
654 __u32 tmp = (__u32) data;
657 if (addr < (addr_t) &dummy32->regs.acrs) {
658 struct pt_regs *regs = task_pt_regs(child);
660 * psw, gprs, acrs and orig_gpr2 are stored on the stack
662 if (addr == (addr_t) &dummy32->regs.psw.mask) {
663 __u32 mask = PSW32_MASK_USER;
665 mask |= is_ri_task(child) ? PSW32_MASK_RI : 0;
666 /* Build a 64 bit psw mask from 31 bit mask. */
667 if ((tmp & ~mask) != PSW32_USER_BITS)
668 /* Invalid psw mask. */
670 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
671 (regs->psw.mask & PSW_MASK_BA) |
672 (__u64)(tmp & mask) << 32;
673 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
674 /* Build a 64 bit psw address from 31 bit address. */
675 regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
676 /* Transfer 31 bit amode bit to psw mask. */
677 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
678 (__u64)(tmp & PSW32_ADDR_AMODE);
681 *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp;
683 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
685 * access registers are stored in the thread structure
687 offset = addr - (addr_t) &dummy32->regs.acrs;
688 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
690 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
692 * orig_gpr2 is stored on the kernel stack
694 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
696 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
698 * prevent writess of padding hole between
699 * orig_gpr2 and fp_regs on s390.
703 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
705 * floating point regs. are stored in the thread structure
707 if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
710 offset = addr - (addr_t) &dummy32->regs.fp_regs;
711 *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
713 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
715 * Handle access to the per_info structure.
717 addr -= (addr_t) &dummy32->regs.per_info;
718 __poke_user_per_compat(child, addr, data);
724 static int poke_user_compat(struct task_struct *child,
725 addr_t addr, addr_t data)
727 if (!is_compat_task() || (addr & 3) ||
728 addr > sizeof(struct compat_user) - 3)
731 return __poke_user_compat(child, addr, data);
734 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
735 compat_ulong_t caddr, compat_ulong_t cdata)
737 unsigned long addr = caddr;
738 unsigned long data = cdata;
739 compat_ptrace_area parea;
744 /* read the word at location addr in the USER area. */
745 return peek_user_compat(child, addr, data);
748 /* write the word at location addr in the USER area */
749 return poke_user_compat(child, addr, data);
751 case PTRACE_PEEKUSR_AREA:
752 case PTRACE_POKEUSR_AREA:
753 if (copy_from_user(&parea, (void __force __user *) addr,
756 addr = parea.kernel_addr;
757 data = parea.process_addr;
759 while (copied < parea.len) {
760 if (request == PTRACE_PEEKUSR_AREA)
761 ret = peek_user_compat(child, addr, data);
765 (__u32 __force __user *) data))
767 ret = poke_user_compat(child, addr, utmp);
771 addr += sizeof(unsigned int);
772 data += sizeof(unsigned int);
773 copied += sizeof(unsigned int);
776 case PTRACE_GET_LAST_BREAK:
777 put_user(task_thread_info(child)->last_break,
778 (unsigned int __user *) data);
781 return compat_ptrace_request(child, request, addr, data);
785 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
789 /* Do the secure computing check first. */
790 if (secure_computing(regs->gprs[2])) {
791 /* seccomp failures shouldn't expose any additional code. */
797 * The sysc_tracesys code in entry.S stored the system
798 * call number to gprs[2].
800 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
801 (tracehook_report_syscall_entry(regs) ||
802 regs->gprs[2] >= NR_syscalls)) {
804 * Tracing decided this syscall should not happen or the
805 * debugger stored an invalid system call number. Skip
806 * the system call and the system call restart handling.
808 clear_thread_flag(TIF_SYSCALL);
812 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
813 trace_sys_enter(regs, regs->gprs[2]);
815 audit_syscall_entry(is_compat_task() ?
816 AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
817 regs->gprs[2], regs->orig_gpr2,
818 regs->gprs[3], regs->gprs[4],
821 return ret ?: regs->gprs[2];
824 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
826 audit_syscall_exit(regs);
828 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
829 trace_sys_exit(regs, regs->gprs[2]);
831 if (test_thread_flag(TIF_SYSCALL_TRACE))
832 tracehook_report_syscall_exit(regs, 0);
836 * user_regset definitions.
839 static int s390_regs_get(struct task_struct *target,
840 const struct user_regset *regset,
841 unsigned int pos, unsigned int count,
842 void *kbuf, void __user *ubuf)
844 if (target == current)
845 save_access_regs(target->thread.acrs);
848 unsigned long *k = kbuf;
850 *k++ = __peek_user(target, pos);
855 unsigned long __user *u = ubuf;
857 if (__put_user(__peek_user(target, pos), u++))
866 static int s390_regs_set(struct task_struct *target,
867 const struct user_regset *regset,
868 unsigned int pos, unsigned int count,
869 const void *kbuf, const void __user *ubuf)
873 if (target == current)
874 save_access_regs(target->thread.acrs);
877 const unsigned long *k = kbuf;
878 while (count > 0 && !rc) {
879 rc = __poke_user(target, pos, *k++);
884 const unsigned long __user *u = ubuf;
885 while (count > 0 && !rc) {
887 rc = __get_user(word, u++);
890 rc = __poke_user(target, pos, word);
896 if (rc == 0 && target == current)
897 restore_access_regs(target->thread.acrs);
902 static int s390_fpregs_get(struct task_struct *target,
903 const struct user_regset *regset, unsigned int pos,
904 unsigned int count, void *kbuf, void __user *ubuf)
906 if (target == current) {
907 save_fp_ctl(&target->thread.fp_regs.fpc);
908 save_fp_regs(target->thread.fp_regs.fprs);
911 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
912 &target->thread.fp_regs, 0, -1);
915 static int s390_fpregs_set(struct task_struct *target,
916 const struct user_regset *regset, unsigned int pos,
917 unsigned int count, const void *kbuf,
918 const void __user *ubuf)
922 if (target == current) {
923 save_fp_ctl(&target->thread.fp_regs.fpc);
924 save_fp_regs(target->thread.fp_regs.fprs);
927 /* If setting FPC, must validate it first. */
928 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
929 u32 ufpc[2] = { target->thread.fp_regs.fpc, 0 };
930 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
931 0, offsetof(s390_fp_regs, fprs));
934 if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
936 target->thread.fp_regs.fpc = ufpc[0];
939 if (rc == 0 && count > 0)
940 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
941 target->thread.fp_regs.fprs,
942 offsetof(s390_fp_regs, fprs), -1);
944 if (rc == 0 && target == current) {
945 restore_fp_ctl(&target->thread.fp_regs.fpc);
946 restore_fp_regs(target->thread.fp_regs.fprs);
954 static int s390_last_break_get(struct task_struct *target,
955 const struct user_regset *regset,
956 unsigned int pos, unsigned int count,
957 void *kbuf, void __user *ubuf)
961 unsigned long *k = kbuf;
962 *k = task_thread_info(target)->last_break;
964 unsigned long __user *u = ubuf;
965 if (__put_user(task_thread_info(target)->last_break, u))
972 static int s390_last_break_set(struct task_struct *target,
973 const struct user_regset *regset,
974 unsigned int pos, unsigned int count,
975 const void *kbuf, const void __user *ubuf)
980 static int s390_tdb_get(struct task_struct *target,
981 const struct user_regset *regset,
982 unsigned int pos, unsigned int count,
983 void *kbuf, void __user *ubuf)
985 struct pt_regs *regs = task_pt_regs(target);
988 if (!(regs->int_code & 0x200))
990 data = target->thread.trap_tdb;
991 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
994 static int s390_tdb_set(struct task_struct *target,
995 const struct user_regset *regset,
996 unsigned int pos, unsigned int count,
997 const void *kbuf, const void __user *ubuf)
1004 static int s390_system_call_get(struct task_struct *target,
1005 const struct user_regset *regset,
1006 unsigned int pos, unsigned int count,
1007 void *kbuf, void __user *ubuf)
1009 unsigned int *data = &task_thread_info(target)->system_call;
1010 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1011 data, 0, sizeof(unsigned int));
1014 static int s390_system_call_set(struct task_struct *target,
1015 const struct user_regset *regset,
1016 unsigned int pos, unsigned int count,
1017 const void *kbuf, const void __user *ubuf)
1019 unsigned int *data = &task_thread_info(target)->system_call;
1020 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1021 data, 0, sizeof(unsigned int));
1024 static const struct user_regset s390_regsets[] = {
1025 [REGSET_GENERAL] = {
1026 .core_note_type = NT_PRSTATUS,
1027 .n = sizeof(s390_regs) / sizeof(long),
1028 .size = sizeof(long),
1029 .align = sizeof(long),
1030 .get = s390_regs_get,
1031 .set = s390_regs_set,
1034 .core_note_type = NT_PRFPREG,
1035 .n = sizeof(s390_fp_regs) / sizeof(long),
1036 .size = sizeof(long),
1037 .align = sizeof(long),
1038 .get = s390_fpregs_get,
1039 .set = s390_fpregs_set,
1042 [REGSET_LAST_BREAK] = {
1043 .core_note_type = NT_S390_LAST_BREAK,
1045 .size = sizeof(long),
1046 .align = sizeof(long),
1047 .get = s390_last_break_get,
1048 .set = s390_last_break_set,
1051 .core_note_type = NT_S390_TDB,
1055 .get = s390_tdb_get,
1056 .set = s390_tdb_set,
1059 [REGSET_SYSTEM_CALL] = {
1060 .core_note_type = NT_S390_SYSTEM_CALL,
1062 .size = sizeof(unsigned int),
1063 .align = sizeof(unsigned int),
1064 .get = s390_system_call_get,
1065 .set = s390_system_call_set,
1069 static const struct user_regset_view user_s390_view = {
1070 .name = UTS_MACHINE,
1071 .e_machine = EM_S390,
1072 .regsets = s390_regsets,
1073 .n = ARRAY_SIZE(s390_regsets)
1076 #ifdef CONFIG_COMPAT
1077 static int s390_compat_regs_get(struct task_struct *target,
1078 const struct user_regset *regset,
1079 unsigned int pos, unsigned int count,
1080 void *kbuf, void __user *ubuf)
1082 if (target == current)
1083 save_access_regs(target->thread.acrs);
1086 compat_ulong_t *k = kbuf;
1088 *k++ = __peek_user_compat(target, pos);
1089 count -= sizeof(*k);
1093 compat_ulong_t __user *u = ubuf;
1095 if (__put_user(__peek_user_compat(target, pos), u++))
1097 count -= sizeof(*u);
1104 static int s390_compat_regs_set(struct task_struct *target,
1105 const struct user_regset *regset,
1106 unsigned int pos, unsigned int count,
1107 const void *kbuf, const void __user *ubuf)
1111 if (target == current)
1112 save_access_regs(target->thread.acrs);
1115 const compat_ulong_t *k = kbuf;
1116 while (count > 0 && !rc) {
1117 rc = __poke_user_compat(target, pos, *k++);
1118 count -= sizeof(*k);
1122 const compat_ulong_t __user *u = ubuf;
1123 while (count > 0 && !rc) {
1124 compat_ulong_t word;
1125 rc = __get_user(word, u++);
1128 rc = __poke_user_compat(target, pos, word);
1129 count -= sizeof(*u);
1134 if (rc == 0 && target == current)
1135 restore_access_regs(target->thread.acrs);
1140 static int s390_compat_regs_high_get(struct task_struct *target,
1141 const struct user_regset *regset,
1142 unsigned int pos, unsigned int count,
1143 void *kbuf, void __user *ubuf)
1145 compat_ulong_t *gprs_high;
1147 gprs_high = (compat_ulong_t *)
1148 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1150 compat_ulong_t *k = kbuf;
1154 count -= sizeof(*k);
1157 compat_ulong_t __user *u = ubuf;
1159 if (__put_user(*gprs_high, u++))
1162 count -= sizeof(*u);
1168 static int s390_compat_regs_high_set(struct task_struct *target,
1169 const struct user_regset *regset,
1170 unsigned int pos, unsigned int count,
1171 const void *kbuf, const void __user *ubuf)
1173 compat_ulong_t *gprs_high;
1176 gprs_high = (compat_ulong_t *)
1177 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1179 const compat_ulong_t *k = kbuf;
1183 count -= sizeof(*k);
1186 const compat_ulong_t __user *u = ubuf;
1187 while (count > 0 && !rc) {
1189 rc = __get_user(word, u++);
1194 count -= sizeof(*u);
1201 static int s390_compat_last_break_get(struct task_struct *target,
1202 const struct user_regset *regset,
1203 unsigned int pos, unsigned int count,
1204 void *kbuf, void __user *ubuf)
1206 compat_ulong_t last_break;
1209 last_break = task_thread_info(target)->last_break;
1211 unsigned long *k = kbuf;
1214 unsigned long __user *u = ubuf;
1215 if (__put_user(last_break, u))
1222 static int s390_compat_last_break_set(struct task_struct *target,
1223 const struct user_regset *regset,
1224 unsigned int pos, unsigned int count,
1225 const void *kbuf, const void __user *ubuf)
1230 static const struct user_regset s390_compat_regsets[] = {
1231 [REGSET_GENERAL] = {
1232 .core_note_type = NT_PRSTATUS,
1233 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1234 .size = sizeof(compat_long_t),
1235 .align = sizeof(compat_long_t),
1236 .get = s390_compat_regs_get,
1237 .set = s390_compat_regs_set,
1240 .core_note_type = NT_PRFPREG,
1241 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1242 .size = sizeof(compat_long_t),
1243 .align = sizeof(compat_long_t),
1244 .get = s390_fpregs_get,
1245 .set = s390_fpregs_set,
1247 [REGSET_LAST_BREAK] = {
1248 .core_note_type = NT_S390_LAST_BREAK,
1250 .size = sizeof(long),
1251 .align = sizeof(long),
1252 .get = s390_compat_last_break_get,
1253 .set = s390_compat_last_break_set,
1256 .core_note_type = NT_S390_TDB,
1260 .get = s390_tdb_get,
1261 .set = s390_tdb_set,
1263 [REGSET_SYSTEM_CALL] = {
1264 .core_note_type = NT_S390_SYSTEM_CALL,
1266 .size = sizeof(compat_uint_t),
1267 .align = sizeof(compat_uint_t),
1268 .get = s390_system_call_get,
1269 .set = s390_system_call_set,
1271 [REGSET_GENERAL_EXTENDED] = {
1272 .core_note_type = NT_S390_HIGH_GPRS,
1273 .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
1274 .size = sizeof(compat_long_t),
1275 .align = sizeof(compat_long_t),
1276 .get = s390_compat_regs_high_get,
1277 .set = s390_compat_regs_high_set,
1281 static const struct user_regset_view user_s390_compat_view = {
1283 .e_machine = EM_S390,
1284 .regsets = s390_compat_regsets,
1285 .n = ARRAY_SIZE(s390_compat_regsets)
1289 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1291 #ifdef CONFIG_COMPAT
1292 if (test_tsk_thread_flag(task, TIF_31BIT))
1293 return &user_s390_compat_view;
1295 return &user_s390_view;
1298 static const char *gpr_names[NUM_GPRS] = {
1299 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1300 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1303 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1305 if (offset >= NUM_GPRS)
1307 return regs->gprs[offset];
1310 int regs_query_register_offset(const char *name)
1312 unsigned long offset;
1314 if (!name || *name != 'r')
1316 if (kstrtoul(name + 1, 10, &offset))
1318 if (offset >= NUM_GPRS)
1323 const char *regs_query_register_name(unsigned int offset)
1325 if (offset >= NUM_GPRS)
1327 return gpr_names[offset];
1330 static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1332 unsigned long ksp = kernel_stack_pointer(regs);
1334 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1338 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1339 * @regs:pt_regs which contains kernel stack pointer.
1340 * @n:stack entry number.
1342 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1343 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1346 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1350 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1351 if (!regs_within_kernel_stack(regs, addr))
1353 return *(unsigned long *)addr;