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_USER_BITS | (tmp & PSW_MASK_USER);
205 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
207 * access registers are stored in the thread structure
209 offset = addr - (addr_t) &dummy->regs.acrs;
212 * Very special case: old & broken 64 bit gdb reading
213 * from acrs[15]. Result is a 64 bit value. Read the
214 * 32 bit acrs[15] value and shift it by 32. Sick...
216 if (addr == (addr_t) &dummy->regs.acrs[15])
217 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
220 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
222 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
224 * orig_gpr2 is stored on the kernel stack
226 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
228 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
230 * prevent reads of padding hole between
231 * orig_gpr2 and fp_regs on s390.
235 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
237 * floating point regs. are stored in the thread structure
239 offset = addr - (addr_t) &dummy->regs.fp_regs;
240 tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
241 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
242 tmp <<= BITS_PER_LONG - 32;
244 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
246 * Handle access to the per_info structure.
248 addr -= (addr_t) &dummy->regs.per_info;
249 tmp = __peek_user_per(child, addr);
258 peek_user(struct task_struct *child, addr_t addr, addr_t data)
263 * Stupid gdb peeks/pokes the access registers in 64 bit with
264 * an alignment of 4. Programmers from hell...
268 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
269 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
272 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
275 tmp = __peek_user(child, addr);
276 return put_user(tmp, (addr_t __user *) data);
279 static inline void __poke_user_per(struct task_struct *child,
280 addr_t addr, addr_t data)
282 struct per_struct_kernel *dummy = NULL;
285 * There are only three fields in the per_info struct that the
286 * debugger user can write to.
287 * 1) cr9: the debugger wants to set a new PER event mask
288 * 2) starting_addr: the debugger wants to set a new starting
289 * address to use with the PER event mask.
290 * 3) ending_addr: the debugger wants to set a new ending
291 * address to use with the PER event mask.
292 * The user specified PER event mask and the start and end
293 * addresses are used only if single stepping is not in effect.
294 * Writes to any other field in per_info are ignored.
296 if (addr == (addr_t) &dummy->cr9)
297 /* PER event mask of the user specified per set. */
298 child->thread.per_user.control =
299 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
300 else if (addr == (addr_t) &dummy->starting_addr)
301 /* Starting address of the user specified per set. */
302 child->thread.per_user.start = data;
303 else if (addr == (addr_t) &dummy->ending_addr)
304 /* Ending address of the user specified per set. */
305 child->thread.per_user.end = data;
309 * Write a word to the user area of a process at location addr. This
310 * operation does have an additional problem compared to peek_user.
311 * Stores to the program status word and on the floating point
312 * control register needs to get checked for validity.
314 static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
316 struct user *dummy = NULL;
319 if (addr < (addr_t) &dummy->regs.acrs) {
321 * psw and gprs are stored on the stack
323 if (addr == (addr_t) &dummy->regs.psw.mask &&
324 ((data & ~PSW_MASK_USER) != PSW_USER_BITS ||
325 ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))))
326 /* Invalid psw mask. */
328 *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
330 } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
332 * access registers are stored in the thread structure
334 offset = addr - (addr_t) &dummy->regs.acrs;
337 * Very special case: old & broken 64 bit gdb writing
338 * to acrs[15] with a 64 bit value. Ignore the lower
339 * half of the value and write the upper 32 bit to
342 if (addr == (addr_t) &dummy->regs.acrs[15])
343 child->thread.acrs[15] = (unsigned int) (data >> 32);
346 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
348 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
350 * orig_gpr2 is stored on the kernel stack
352 task_pt_regs(child)->orig_gpr2 = data;
354 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
356 * prevent writes of padding hole between
357 * orig_gpr2 and fp_regs on s390.
361 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
363 * floating point regs. are stored in the thread structure
365 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
366 if ((unsigned int) data != 0 ||
367 test_fp_ctl(data >> (BITS_PER_LONG - 32)))
369 offset = addr - (addr_t) &dummy->regs.fp_regs;
370 *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
372 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
374 * Handle access to the per_info structure.
376 addr -= (addr_t) &dummy->regs.per_info;
377 __poke_user_per(child, addr, data);
384 static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
389 * Stupid gdb peeks/pokes the access registers in 64 bit with
390 * an alignment of 4. Programmers from hell indeed...
394 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
395 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
398 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
401 return __poke_user(child, addr, data);
404 long arch_ptrace(struct task_struct *child, long request,
405 unsigned long addr, unsigned long data)
412 /* read the word at location addr in the USER area. */
413 return peek_user(child, addr, data);
416 /* write the word at location addr in the USER area */
417 return poke_user(child, addr, data);
419 case PTRACE_PEEKUSR_AREA:
420 case PTRACE_POKEUSR_AREA:
421 if (copy_from_user(&parea, (void __force __user *) addr,
424 addr = parea.kernel_addr;
425 data = parea.process_addr;
427 while (copied < parea.len) {
428 if (request == PTRACE_PEEKUSR_AREA)
429 ret = peek_user(child, addr, data);
433 (addr_t __force __user *) data))
435 ret = poke_user(child, addr, utmp);
439 addr += sizeof(unsigned long);
440 data += sizeof(unsigned long);
441 copied += sizeof(unsigned long);
444 case PTRACE_GET_LAST_BREAK:
445 put_user(task_thread_info(child)->last_break,
446 (unsigned long __user *) data);
448 case PTRACE_ENABLE_TE:
451 child->thread.per_flags &= ~PER_FLAG_NO_TE;
453 case PTRACE_DISABLE_TE:
456 child->thread.per_flags |= PER_FLAG_NO_TE;
457 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
459 case PTRACE_TE_ABORT_RAND:
460 if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
464 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
467 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
468 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
471 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
472 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
479 /* Removing high order bit from addr (only for 31 bit). */
480 addr &= PSW_ADDR_INSN;
481 return ptrace_request(child, request, addr, data);
487 * Now the fun part starts... a 31 bit program running in the
488 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
489 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
490 * to handle, the difference to the 64 bit versions of the requests
491 * is that the access is done in multiples of 4 byte instead of
492 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
493 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
494 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
495 * is a 31 bit program too, the content of struct user can be
496 * emulated. A 31 bit program peeking into the struct user of
497 * a 64 bit program is a no-no.
501 * Same as peek_user_per but for a 31 bit program.
503 static inline __u32 __peek_user_per_compat(struct task_struct *child,
506 struct compat_per_struct_kernel *dummy32 = NULL;
508 if (addr == (addr_t) &dummy32->cr9)
509 /* Control bits of the active per set. */
510 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
511 PER_EVENT_IFETCH : child->thread.per_user.control;
512 else if (addr == (addr_t) &dummy32->cr10)
513 /* Start address of the active per set. */
514 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
515 0 : child->thread.per_user.start;
516 else if (addr == (addr_t) &dummy32->cr11)
517 /* End address of the active per set. */
518 return test_thread_flag(TIF_SINGLE_STEP) ?
519 PSW32_ADDR_INSN : child->thread.per_user.end;
520 else if (addr == (addr_t) &dummy32->bits)
521 /* Single-step bit. */
522 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
524 else if (addr == (addr_t) &dummy32->starting_addr)
525 /* Start address of the user specified per set. */
526 return (__u32) child->thread.per_user.start;
527 else if (addr == (addr_t) &dummy32->ending_addr)
528 /* End address of the user specified per set. */
529 return (__u32) child->thread.per_user.end;
530 else if (addr == (addr_t) &dummy32->perc_atmid)
531 /* PER code, ATMID and AI of the last PER trap */
532 return (__u32) child->thread.per_event.cause << 16;
533 else if (addr == (addr_t) &dummy32->address)
534 /* Address of the last PER trap */
535 return (__u32) child->thread.per_event.address;
536 else if (addr == (addr_t) &dummy32->access_id)
537 /* Access id of the last PER trap */
538 return (__u32) child->thread.per_event.paid << 24;
543 * Same as peek_user but for a 31 bit program.
545 static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
547 struct compat_user *dummy32 = NULL;
551 if (addr < (addr_t) &dummy32->regs.acrs) {
552 struct pt_regs *regs = task_pt_regs(child);
554 * psw and gprs are stored on the stack
556 if (addr == (addr_t) &dummy32->regs.psw.mask) {
557 /* Fake a 31 bit psw mask. */
558 tmp = (__u32)(regs->psw.mask >> 32);
559 tmp = psw32_user_bits | (tmp & PSW32_MASK_USER);
560 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
561 /* Fake a 31 bit psw address. */
562 tmp = (__u32) regs->psw.addr |
563 (__u32)(regs->psw.mask & PSW_MASK_BA);
566 tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4);
568 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
570 * access registers are stored in the thread structure
572 offset = addr - (addr_t) &dummy32->regs.acrs;
573 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
575 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
577 * orig_gpr2 is stored on the kernel stack
579 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
581 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
583 * prevent reads of padding hole between
584 * orig_gpr2 and fp_regs on s390.
588 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
590 * floating point regs. are stored in the thread structure
592 offset = addr - (addr_t) &dummy32->regs.fp_regs;
593 tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
595 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
597 * Handle access to the per_info structure.
599 addr -= (addr_t) &dummy32->regs.per_info;
600 tmp = __peek_user_per_compat(child, addr);
608 static int peek_user_compat(struct task_struct *child,
609 addr_t addr, addr_t data)
613 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
616 tmp = __peek_user_compat(child, addr);
617 return put_user(tmp, (__u32 __user *) data);
621 * Same as poke_user_per but for a 31 bit program.
623 static inline void __poke_user_per_compat(struct task_struct *child,
624 addr_t addr, __u32 data)
626 struct compat_per_struct_kernel *dummy32 = NULL;
628 if (addr == (addr_t) &dummy32->cr9)
629 /* PER event mask of the user specified per set. */
630 child->thread.per_user.control =
631 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
632 else if (addr == (addr_t) &dummy32->starting_addr)
633 /* Starting address of the user specified per set. */
634 child->thread.per_user.start = data;
635 else if (addr == (addr_t) &dummy32->ending_addr)
636 /* Ending address of the user specified per set. */
637 child->thread.per_user.end = data;
641 * Same as poke_user but for a 31 bit program.
643 static int __poke_user_compat(struct task_struct *child,
644 addr_t addr, addr_t data)
646 struct compat_user *dummy32 = NULL;
647 __u32 tmp = (__u32) data;
650 if (addr < (addr_t) &dummy32->regs.acrs) {
651 struct pt_regs *regs = task_pt_regs(child);
653 * psw, gprs, acrs and orig_gpr2 are stored on the stack
655 if (addr == (addr_t) &dummy32->regs.psw.mask) {
656 /* Build a 64 bit psw mask from 31 bit mask. */
657 if ((tmp & ~PSW32_MASK_USER) != psw32_user_bits)
658 /* Invalid psw mask. */
660 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
661 (regs->psw.mask & PSW_MASK_BA) |
662 (__u64)(tmp & PSW32_MASK_USER) << 32;
663 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
664 /* Build a 64 bit psw address from 31 bit address. */
665 regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
666 /* Transfer 31 bit amode bit to psw mask. */
667 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
668 (__u64)(tmp & PSW32_ADDR_AMODE);
671 *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp;
673 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
675 * access registers are stored in the thread structure
677 offset = addr - (addr_t) &dummy32->regs.acrs;
678 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
680 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
682 * orig_gpr2 is stored on the kernel stack
684 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
686 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
688 * prevent writess of padding hole between
689 * orig_gpr2 and fp_regs on s390.
693 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
695 * floating point regs. are stored in the thread structure
697 if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
700 offset = addr - (addr_t) &dummy32->regs.fp_regs;
701 *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
703 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
705 * Handle access to the per_info structure.
707 addr -= (addr_t) &dummy32->regs.per_info;
708 __poke_user_per_compat(child, addr, data);
714 static int poke_user_compat(struct task_struct *child,
715 addr_t addr, addr_t data)
717 if (!is_compat_task() || (addr & 3) ||
718 addr > sizeof(struct compat_user) - 3)
721 return __poke_user_compat(child, addr, data);
724 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
725 compat_ulong_t caddr, compat_ulong_t cdata)
727 unsigned long addr = caddr;
728 unsigned long data = cdata;
729 compat_ptrace_area parea;
734 /* read the word at location addr in the USER area. */
735 return peek_user_compat(child, addr, data);
738 /* write the word at location addr in the USER area */
739 return poke_user_compat(child, addr, data);
741 case PTRACE_PEEKUSR_AREA:
742 case PTRACE_POKEUSR_AREA:
743 if (copy_from_user(&parea, (void __force __user *) addr,
746 addr = parea.kernel_addr;
747 data = parea.process_addr;
749 while (copied < parea.len) {
750 if (request == PTRACE_PEEKUSR_AREA)
751 ret = peek_user_compat(child, addr, data);
755 (__u32 __force __user *) data))
757 ret = poke_user_compat(child, addr, utmp);
761 addr += sizeof(unsigned int);
762 data += sizeof(unsigned int);
763 copied += sizeof(unsigned int);
766 case PTRACE_GET_LAST_BREAK:
767 put_user(task_thread_info(child)->last_break,
768 (unsigned int __user *) data);
771 return compat_ptrace_request(child, request, addr, data);
775 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
779 /* Do the secure computing check first. */
780 if (secure_computing(regs->gprs[2])) {
781 /* seccomp failures shouldn't expose any additional code. */
787 * The sysc_tracesys code in entry.S stored the system
788 * call number to gprs[2].
790 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
791 (tracehook_report_syscall_entry(regs) ||
792 regs->gprs[2] >= NR_syscalls)) {
794 * Tracing decided this syscall should not happen or the
795 * debugger stored an invalid system call number. Skip
796 * the system call and the system call restart handling.
798 clear_thread_flag(TIF_SYSCALL);
802 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
803 trace_sys_enter(regs, regs->gprs[2]);
805 audit_syscall_entry(is_compat_task() ?
806 AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
807 regs->gprs[2], regs->orig_gpr2,
808 regs->gprs[3], regs->gprs[4],
811 return ret ?: regs->gprs[2];
814 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
816 audit_syscall_exit(regs);
818 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
819 trace_sys_exit(regs, regs->gprs[2]);
821 if (test_thread_flag(TIF_SYSCALL_TRACE))
822 tracehook_report_syscall_exit(regs, 0);
826 * user_regset definitions.
829 static int s390_regs_get(struct task_struct *target,
830 const struct user_regset *regset,
831 unsigned int pos, unsigned int count,
832 void *kbuf, void __user *ubuf)
834 if (target == current)
835 save_access_regs(target->thread.acrs);
838 unsigned long *k = kbuf;
840 *k++ = __peek_user(target, pos);
845 unsigned long __user *u = ubuf;
847 if (__put_user(__peek_user(target, pos), u++))
856 static int s390_regs_set(struct task_struct *target,
857 const struct user_regset *regset,
858 unsigned int pos, unsigned int count,
859 const void *kbuf, const void __user *ubuf)
863 if (target == current)
864 save_access_regs(target->thread.acrs);
867 const unsigned long *k = kbuf;
868 while (count > 0 && !rc) {
869 rc = __poke_user(target, pos, *k++);
874 const unsigned long __user *u = ubuf;
875 while (count > 0 && !rc) {
877 rc = __get_user(word, u++);
880 rc = __poke_user(target, pos, word);
886 if (rc == 0 && target == current)
887 restore_access_regs(target->thread.acrs);
892 static int s390_fpregs_get(struct task_struct *target,
893 const struct user_regset *regset, unsigned int pos,
894 unsigned int count, void *kbuf, void __user *ubuf)
896 if (target == current) {
897 save_fp_ctl(&target->thread.fp_regs.fpc);
898 save_fp_regs(target->thread.fp_regs.fprs);
901 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
902 &target->thread.fp_regs, 0, -1);
905 static int s390_fpregs_set(struct task_struct *target,
906 const struct user_regset *regset, unsigned int pos,
907 unsigned int count, const void *kbuf,
908 const void __user *ubuf)
912 if (target == current) {
913 save_fp_ctl(&target->thread.fp_regs.fpc);
914 save_fp_regs(target->thread.fp_regs.fprs);
917 /* If setting FPC, must validate it first. */
918 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
919 u32 ufpc[2] = { target->thread.fp_regs.fpc, 0 };
920 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
921 0, offsetof(s390_fp_regs, fprs));
924 if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
926 target->thread.fp_regs.fpc = ufpc[0];
929 if (rc == 0 && count > 0)
930 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
931 target->thread.fp_regs.fprs,
932 offsetof(s390_fp_regs, fprs), -1);
934 if (rc == 0 && target == current) {
935 restore_fp_ctl(&target->thread.fp_regs.fpc);
936 restore_fp_regs(target->thread.fp_regs.fprs);
944 static int s390_last_break_get(struct task_struct *target,
945 const struct user_regset *regset,
946 unsigned int pos, unsigned int count,
947 void *kbuf, void __user *ubuf)
951 unsigned long *k = kbuf;
952 *k = task_thread_info(target)->last_break;
954 unsigned long __user *u = ubuf;
955 if (__put_user(task_thread_info(target)->last_break, u))
962 static int s390_last_break_set(struct task_struct *target,
963 const struct user_regset *regset,
964 unsigned int pos, unsigned int count,
965 const void *kbuf, const void __user *ubuf)
970 static int s390_tdb_get(struct task_struct *target,
971 const struct user_regset *regset,
972 unsigned int pos, unsigned int count,
973 void *kbuf, void __user *ubuf)
975 struct pt_regs *regs = task_pt_regs(target);
978 if (!(regs->int_code & 0x200))
980 data = target->thread.trap_tdb;
981 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
984 static int s390_tdb_set(struct task_struct *target,
985 const struct user_regset *regset,
986 unsigned int pos, unsigned int count,
987 const void *kbuf, const void __user *ubuf)
994 static int s390_system_call_get(struct task_struct *target,
995 const struct user_regset *regset,
996 unsigned int pos, unsigned int count,
997 void *kbuf, void __user *ubuf)
999 unsigned int *data = &task_thread_info(target)->system_call;
1000 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1001 data, 0, sizeof(unsigned int));
1004 static int s390_system_call_set(struct task_struct *target,
1005 const struct user_regset *regset,
1006 unsigned int pos, unsigned int count,
1007 const void *kbuf, const void __user *ubuf)
1009 unsigned int *data = &task_thread_info(target)->system_call;
1010 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1011 data, 0, sizeof(unsigned int));
1014 static const struct user_regset s390_regsets[] = {
1015 [REGSET_GENERAL] = {
1016 .core_note_type = NT_PRSTATUS,
1017 .n = sizeof(s390_regs) / sizeof(long),
1018 .size = sizeof(long),
1019 .align = sizeof(long),
1020 .get = s390_regs_get,
1021 .set = s390_regs_set,
1024 .core_note_type = NT_PRFPREG,
1025 .n = sizeof(s390_fp_regs) / sizeof(long),
1026 .size = sizeof(long),
1027 .align = sizeof(long),
1028 .get = s390_fpregs_get,
1029 .set = s390_fpregs_set,
1032 [REGSET_LAST_BREAK] = {
1033 .core_note_type = NT_S390_LAST_BREAK,
1035 .size = sizeof(long),
1036 .align = sizeof(long),
1037 .get = s390_last_break_get,
1038 .set = s390_last_break_set,
1041 .core_note_type = NT_S390_TDB,
1045 .get = s390_tdb_get,
1046 .set = s390_tdb_set,
1049 [REGSET_SYSTEM_CALL] = {
1050 .core_note_type = NT_S390_SYSTEM_CALL,
1052 .size = sizeof(unsigned int),
1053 .align = sizeof(unsigned int),
1054 .get = s390_system_call_get,
1055 .set = s390_system_call_set,
1059 static const struct user_regset_view user_s390_view = {
1060 .name = UTS_MACHINE,
1061 .e_machine = EM_S390,
1062 .regsets = s390_regsets,
1063 .n = ARRAY_SIZE(s390_regsets)
1066 #ifdef CONFIG_COMPAT
1067 static int s390_compat_regs_get(struct task_struct *target,
1068 const struct user_regset *regset,
1069 unsigned int pos, unsigned int count,
1070 void *kbuf, void __user *ubuf)
1072 if (target == current)
1073 save_access_regs(target->thread.acrs);
1076 compat_ulong_t *k = kbuf;
1078 *k++ = __peek_user_compat(target, pos);
1079 count -= sizeof(*k);
1083 compat_ulong_t __user *u = ubuf;
1085 if (__put_user(__peek_user_compat(target, pos), u++))
1087 count -= sizeof(*u);
1094 static int s390_compat_regs_set(struct task_struct *target,
1095 const struct user_regset *regset,
1096 unsigned int pos, unsigned int count,
1097 const void *kbuf, const void __user *ubuf)
1101 if (target == current)
1102 save_access_regs(target->thread.acrs);
1105 const compat_ulong_t *k = kbuf;
1106 while (count > 0 && !rc) {
1107 rc = __poke_user_compat(target, pos, *k++);
1108 count -= sizeof(*k);
1112 const compat_ulong_t __user *u = ubuf;
1113 while (count > 0 && !rc) {
1114 compat_ulong_t word;
1115 rc = __get_user(word, u++);
1118 rc = __poke_user_compat(target, pos, word);
1119 count -= sizeof(*u);
1124 if (rc == 0 && target == current)
1125 restore_access_regs(target->thread.acrs);
1130 static int s390_compat_regs_high_get(struct task_struct *target,
1131 const struct user_regset *regset,
1132 unsigned int pos, unsigned int count,
1133 void *kbuf, void __user *ubuf)
1135 compat_ulong_t *gprs_high;
1137 gprs_high = (compat_ulong_t *)
1138 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1140 compat_ulong_t *k = kbuf;
1144 count -= sizeof(*k);
1147 compat_ulong_t __user *u = ubuf;
1149 if (__put_user(*gprs_high, u++))
1152 count -= sizeof(*u);
1158 static int s390_compat_regs_high_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 compat_ulong_t *gprs_high;
1166 gprs_high = (compat_ulong_t *)
1167 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1169 const compat_ulong_t *k = kbuf;
1173 count -= sizeof(*k);
1176 const compat_ulong_t __user *u = ubuf;
1177 while (count > 0 && !rc) {
1179 rc = __get_user(word, u++);
1184 count -= sizeof(*u);
1191 static int s390_compat_last_break_get(struct task_struct *target,
1192 const struct user_regset *regset,
1193 unsigned int pos, unsigned int count,
1194 void *kbuf, void __user *ubuf)
1196 compat_ulong_t last_break;
1199 last_break = task_thread_info(target)->last_break;
1201 unsigned long *k = kbuf;
1204 unsigned long __user *u = ubuf;
1205 if (__put_user(last_break, u))
1212 static int s390_compat_last_break_set(struct task_struct *target,
1213 const struct user_regset *regset,
1214 unsigned int pos, unsigned int count,
1215 const void *kbuf, const void __user *ubuf)
1220 static const struct user_regset s390_compat_regsets[] = {
1221 [REGSET_GENERAL] = {
1222 .core_note_type = NT_PRSTATUS,
1223 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1224 .size = sizeof(compat_long_t),
1225 .align = sizeof(compat_long_t),
1226 .get = s390_compat_regs_get,
1227 .set = s390_compat_regs_set,
1230 .core_note_type = NT_PRFPREG,
1231 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1232 .size = sizeof(compat_long_t),
1233 .align = sizeof(compat_long_t),
1234 .get = s390_fpregs_get,
1235 .set = s390_fpregs_set,
1237 [REGSET_LAST_BREAK] = {
1238 .core_note_type = NT_S390_LAST_BREAK,
1240 .size = sizeof(long),
1241 .align = sizeof(long),
1242 .get = s390_compat_last_break_get,
1243 .set = s390_compat_last_break_set,
1246 .core_note_type = NT_S390_TDB,
1250 .get = s390_tdb_get,
1251 .set = s390_tdb_set,
1253 [REGSET_SYSTEM_CALL] = {
1254 .core_note_type = NT_S390_SYSTEM_CALL,
1256 .size = sizeof(compat_uint_t),
1257 .align = sizeof(compat_uint_t),
1258 .get = s390_system_call_get,
1259 .set = s390_system_call_set,
1261 [REGSET_GENERAL_EXTENDED] = {
1262 .core_note_type = NT_S390_HIGH_GPRS,
1263 .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
1264 .size = sizeof(compat_long_t),
1265 .align = sizeof(compat_long_t),
1266 .get = s390_compat_regs_high_get,
1267 .set = s390_compat_regs_high_set,
1271 static const struct user_regset_view user_s390_compat_view = {
1273 .e_machine = EM_S390,
1274 .regsets = s390_compat_regsets,
1275 .n = ARRAY_SIZE(s390_compat_regsets)
1279 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1281 #ifdef CONFIG_COMPAT
1282 if (test_tsk_thread_flag(task, TIF_31BIT))
1283 return &user_s390_compat_view;
1285 return &user_s390_view;
1288 static const char *gpr_names[NUM_GPRS] = {
1289 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1290 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1293 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1295 if (offset >= NUM_GPRS)
1297 return regs->gprs[offset];
1300 int regs_query_register_offset(const char *name)
1302 unsigned long offset;
1304 if (!name || *name != 'r')
1306 if (kstrtoul(name + 1, 10, &offset))
1308 if (offset >= NUM_GPRS)
1313 const char *regs_query_register_name(unsigned int offset)
1315 if (offset >= NUM_GPRS)
1317 return gpr_names[offset];
1320 static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1322 unsigned long ksp = kernel_stack_pointer(regs);
1324 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1328 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1329 * @regs:pt_regs which contains kernel stack pointer.
1330 * @n:stack entry number.
1332 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1333 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1336 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1340 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1341 if (!regs_within_kernel_stack(regs, addr))
1343 return *(unsigned long *)addr;