1 // SPDX-License-Identifier: GPL-2.0
3 * Ptrace user space interface.
5 * Copyright IBM Corp. 1999, 2010
6 * Author(s): Denis Joseph Barrow
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/sched/task_stack.h>
14 #include <linux/smp.h>
15 #include <linux/errno.h>
16 #include <linux/ptrace.h>
17 #include <linux/user.h>
18 #include <linux/security.h>
19 #include <linux/audit.h>
20 #include <linux/signal.h>
21 #include <linux/elf.h>
22 #include <linux/regset.h>
23 #include <linux/tracehook.h>
24 #include <linux/seccomp.h>
25 #include <linux/compat.h>
26 #include <trace/syscall.h>
28 #include <asm/pgalloc.h>
29 #include <linux/uaccess.h>
30 #include <asm/unistd.h>
31 #include <asm/switch_to.h>
32 #include <asm/runtime_instr.h>
33 #include <asm/facility.h>
38 #include "compat_ptrace.h"
41 #define CREATE_TRACE_POINTS
42 #include <trace/events/syscalls.h>
44 void update_cr_regs(struct task_struct *task)
46 struct pt_regs *regs = task_pt_regs(task);
47 struct thread_struct *thread = &task->thread;
48 struct per_regs old, new;
49 union ctlreg0 cr0_old, cr0_new;
50 union ctlreg2 cr2_old, cr2_new;
51 int cr0_changed, cr2_changed;
53 __ctl_store(cr0_old.val, 0, 0);
54 __ctl_store(cr2_old.val, 2, 2);
57 /* Take care of the enable/disable of transactional execution. */
59 /* Set or clear transaction execution TXC bit 8. */
61 if (task->thread.per_flags & PER_FLAG_NO_TE)
63 /* Set or clear transaction execution TDC bits 62 and 63. */
65 if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) {
66 if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND_TEND)
72 /* Take care of enable/disable of guarded storage. */
75 if (task->thread.gs_cb)
78 /* Load control register 0/2 iff changed */
79 cr0_changed = cr0_new.val != cr0_old.val;
80 cr2_changed = cr2_new.val != cr2_old.val;
82 __ctl_load(cr0_new.val, 0, 0);
84 __ctl_load(cr2_new.val, 2, 2);
85 /* Copy user specified PER registers */
86 new.control = thread->per_user.control;
87 new.start = thread->per_user.start;
88 new.end = thread->per_user.end;
90 /* merge TIF_SINGLE_STEP into user specified PER registers. */
91 if (test_tsk_thread_flag(task, TIF_SINGLE_STEP) ||
92 test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP)) {
93 if (test_tsk_thread_flag(task, TIF_BLOCK_STEP))
94 new.control |= PER_EVENT_BRANCH;
96 new.control |= PER_EVENT_IFETCH;
97 new.control |= PER_CONTROL_SUSPENSION;
98 new.control |= PER_EVENT_TRANSACTION_END;
99 if (test_tsk_thread_flag(task, TIF_UPROBE_SINGLESTEP))
100 new.control |= PER_EVENT_IFETCH;
105 /* Take care of the PER enablement bit in the PSW. */
106 if (!(new.control & PER_EVENT_MASK)) {
107 regs->psw.mask &= ~PSW_MASK_PER;
110 regs->psw.mask |= PSW_MASK_PER;
111 __ctl_store(old, 9, 11);
112 if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
113 __ctl_load(new, 9, 11);
116 void user_enable_single_step(struct task_struct *task)
118 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
119 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
122 void user_disable_single_step(struct task_struct *task)
124 clear_tsk_thread_flag(task, TIF_BLOCK_STEP);
125 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
128 void user_enable_block_step(struct task_struct *task)
130 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
131 set_tsk_thread_flag(task, TIF_BLOCK_STEP);
135 * Called by kernel/ptrace.c when detaching..
137 * Clear all debugging related fields.
139 void ptrace_disable(struct task_struct *task)
141 memset(&task->thread.per_user, 0, sizeof(task->thread.per_user));
142 memset(&task->thread.per_event, 0, sizeof(task->thread.per_event));
143 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
144 clear_pt_regs_flag(task_pt_regs(task), PIF_PER_TRAP);
145 task->thread.per_flags = 0;
148 #define __ADDR_MASK 7
150 static inline unsigned long __peek_user_per(struct task_struct *child,
153 struct per_struct_kernel *dummy = NULL;
155 if (addr == (addr_t) &dummy->cr9)
156 /* Control bits of the active per set. */
157 return test_thread_flag(TIF_SINGLE_STEP) ?
158 PER_EVENT_IFETCH : child->thread.per_user.control;
159 else if (addr == (addr_t) &dummy->cr10)
160 /* Start address of the active per set. */
161 return test_thread_flag(TIF_SINGLE_STEP) ?
162 0 : child->thread.per_user.start;
163 else if (addr == (addr_t) &dummy->cr11)
164 /* End address of the active per set. */
165 return test_thread_flag(TIF_SINGLE_STEP) ?
166 -1UL : child->thread.per_user.end;
167 else if (addr == (addr_t) &dummy->bits)
168 /* Single-step bit. */
169 return test_thread_flag(TIF_SINGLE_STEP) ?
170 (1UL << (BITS_PER_LONG - 1)) : 0;
171 else if (addr == (addr_t) &dummy->starting_addr)
172 /* Start address of the user specified per set. */
173 return child->thread.per_user.start;
174 else if (addr == (addr_t) &dummy->ending_addr)
175 /* End address of the user specified per set. */
176 return child->thread.per_user.end;
177 else if (addr == (addr_t) &dummy->perc_atmid)
178 /* PER code, ATMID and AI of the last PER trap */
179 return (unsigned long)
180 child->thread.per_event.cause << (BITS_PER_LONG - 16);
181 else if (addr == (addr_t) &dummy->address)
182 /* Address of the last PER trap */
183 return child->thread.per_event.address;
184 else if (addr == (addr_t) &dummy->access_id)
185 /* Access id of the last PER trap */
186 return (unsigned long)
187 child->thread.per_event.paid << (BITS_PER_LONG - 8);
192 * Read the word at offset addr from the user area of a process. The
193 * trouble here is that the information is littered over different
194 * locations. The process registers are found on the kernel stack,
195 * the floating point stuff and the trace settings are stored in
196 * the task structure. In addition the different structures in
197 * struct user contain pad bytes that should be read as zeroes.
200 static unsigned long __peek_user(struct task_struct *child, addr_t addr)
202 struct user *dummy = NULL;
205 if (addr < (addr_t) &dummy->regs.acrs) {
207 * psw and gprs are stored on the stack
209 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
210 if (addr == (addr_t) &dummy->regs.psw.mask) {
211 /* Return a clean psw mask. */
212 tmp &= PSW_MASK_USER | PSW_MASK_RI;
213 tmp |= PSW_USER_BITS;
216 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
218 * access registers are stored in the thread structure
220 offset = addr - (addr_t) &dummy->regs.acrs;
222 * Very special case: old & broken 64 bit gdb reading
223 * from acrs[15]. Result is a 64 bit value. Read the
224 * 32 bit acrs[15] value and shift it by 32. Sick...
226 if (addr == (addr_t) &dummy->regs.acrs[15])
227 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
229 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
231 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
233 * orig_gpr2 is stored on the kernel stack
235 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
237 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
239 * prevent reads of padding hole between
240 * orig_gpr2 and fp_regs on s390.
244 } else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
246 * floating point control reg. is in the thread structure
248 tmp = child->thread.fpu.fpc;
249 tmp <<= BITS_PER_LONG - 32;
251 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
253 * floating point regs. are either in child->thread.fpu
254 * or the child->thread.fpu.vxrs array
256 offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
259 ((addr_t) child->thread.fpu.vxrs + 2*offset);
262 ((addr_t) child->thread.fpu.fprs + offset);
264 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
266 * Handle access to the per_info structure.
268 addr -= (addr_t) &dummy->regs.per_info;
269 tmp = __peek_user_per(child, addr);
278 peek_user(struct task_struct *child, addr_t addr, addr_t data)
283 * Stupid gdb peeks/pokes the access registers in 64 bit with
284 * an alignment of 4. Programmers from hell...
287 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
288 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
290 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
293 tmp = __peek_user(child, addr);
294 return put_user(tmp, (addr_t __user *) data);
297 static inline void __poke_user_per(struct task_struct *child,
298 addr_t addr, addr_t data)
300 struct per_struct_kernel *dummy = NULL;
303 * There are only three fields in the per_info struct that the
304 * debugger user can write to.
305 * 1) cr9: the debugger wants to set a new PER event mask
306 * 2) starting_addr: the debugger wants to set a new starting
307 * address to use with the PER event mask.
308 * 3) ending_addr: the debugger wants to set a new ending
309 * address to use with the PER event mask.
310 * The user specified PER event mask and the start and end
311 * addresses are used only if single stepping is not in effect.
312 * Writes to any other field in per_info are ignored.
314 if (addr == (addr_t) &dummy->cr9)
315 /* PER event mask of the user specified per set. */
316 child->thread.per_user.control =
317 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
318 else if (addr == (addr_t) &dummy->starting_addr)
319 /* Starting address of the user specified per set. */
320 child->thread.per_user.start = data;
321 else if (addr == (addr_t) &dummy->ending_addr)
322 /* Ending address of the user specified per set. */
323 child->thread.per_user.end = data;
326 static void fixup_int_code(struct task_struct *child, addr_t data)
328 struct pt_regs *regs = task_pt_regs(child);
329 int ilc = regs->int_code >> 16;
335 if (ptrace_access_vm(child, regs->psw.addr - (regs->int_code >> 16),
336 &insn, sizeof(insn), FOLL_FORCE) != sizeof(insn))
339 /* double check that tracee stopped on svc instruction */
340 if ((insn >> 8) != 0xa)
343 regs->int_code = 0x20000 | (data & 0xffff);
346 * Write a word to the user area of a process at location addr. This
347 * operation does have an additional problem compared to peek_user.
348 * Stores to the program status word and on the floating point
349 * control register needs to get checked for validity.
351 static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
353 struct user *dummy = NULL;
357 if (addr < (addr_t) &dummy->regs.acrs) {
358 struct pt_regs *regs = task_pt_regs(child);
360 * psw and gprs are stored on the stack
362 if (addr == (addr_t) &dummy->regs.psw.mask) {
363 unsigned long mask = PSW_MASK_USER;
365 mask |= is_ri_task(child) ? PSW_MASK_RI : 0;
366 if ((data ^ PSW_USER_BITS) & ~mask)
367 /* Invalid psw mask. */
369 if ((data & PSW_MASK_ASC) == PSW_ASC_HOME)
370 /* Invalid address-space-control bits */
372 if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))
373 /* Invalid addressing mode bits */
377 if (test_pt_regs_flag(regs, PIF_SYSCALL) &&
378 addr == offsetof(struct user, regs.gprs[2]))
379 fixup_int_code(child, data);
380 *(addr_t *)((addr_t) ®s->psw + addr) = data;
382 } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
384 * access registers are stored in the thread structure
386 offset = addr - (addr_t) &dummy->regs.acrs;
388 * Very special case: old & broken 64 bit gdb writing
389 * to acrs[15] with a 64 bit value. Ignore the lower
390 * half of the value and write the upper 32 bit to
393 if (addr == (addr_t) &dummy->regs.acrs[15])
394 child->thread.acrs[15] = (unsigned int) (data >> 32);
396 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
398 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
400 * orig_gpr2 is stored on the kernel stack
402 task_pt_regs(child)->orig_gpr2 = data;
404 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
406 * prevent writes of padding hole between
407 * orig_gpr2 and fp_regs on s390.
411 } else if (addr == (addr_t) &dummy->regs.fp_regs.fpc) {
413 * floating point control reg. is in the thread structure
415 if ((unsigned int) data != 0 ||
416 test_fp_ctl(data >> (BITS_PER_LONG - 32)))
418 child->thread.fpu.fpc = data >> (BITS_PER_LONG - 32);
420 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
422 * floating point regs. are either in child->thread.fpu
423 * or the child->thread.fpu.vxrs array
425 offset = addr - (addr_t) &dummy->regs.fp_regs.fprs;
428 child->thread.fpu.vxrs + 2*offset) = data;
431 child->thread.fpu.fprs + offset) = data;
433 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
435 * Handle access to the per_info structure.
437 addr -= (addr_t) &dummy->regs.per_info;
438 __poke_user_per(child, addr, data);
445 static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
450 * Stupid gdb peeks/pokes the access registers in 64 bit with
451 * an alignment of 4. Programmers from hell indeed...
454 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
455 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
457 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
460 return __poke_user(child, addr, data);
463 long arch_ptrace(struct task_struct *child, long request,
464 unsigned long addr, unsigned long data)
471 /* read the word at location addr in the USER area. */
472 return peek_user(child, addr, data);
475 /* write the word at location addr in the USER area */
476 return poke_user(child, addr, data);
478 case PTRACE_PEEKUSR_AREA:
479 case PTRACE_POKEUSR_AREA:
480 if (copy_from_user(&parea, (void __force __user *) addr,
483 addr = parea.kernel_addr;
484 data = parea.process_addr;
486 while (copied < parea.len) {
487 if (request == PTRACE_PEEKUSR_AREA)
488 ret = peek_user(child, addr, data);
492 (addr_t __force __user *) data))
494 ret = poke_user(child, addr, utmp);
498 addr += sizeof(unsigned long);
499 data += sizeof(unsigned long);
500 copied += sizeof(unsigned long);
503 case PTRACE_GET_LAST_BREAK:
504 put_user(child->thread.last_break,
505 (unsigned long __user *) data);
507 case PTRACE_ENABLE_TE:
510 child->thread.per_flags &= ~PER_FLAG_NO_TE;
512 case PTRACE_DISABLE_TE:
515 child->thread.per_flags |= PER_FLAG_NO_TE;
516 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
518 case PTRACE_TE_ABORT_RAND:
519 if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
523 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
526 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
527 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
530 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
531 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
538 return ptrace_request(child, request, addr, data);
544 * Now the fun part starts... a 31 bit program running in the
545 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
546 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
547 * to handle, the difference to the 64 bit versions of the requests
548 * is that the access is done in multiples of 4 byte instead of
549 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
550 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
551 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
552 * is a 31 bit program too, the content of struct user can be
553 * emulated. A 31 bit program peeking into the struct user of
554 * a 64 bit program is a no-no.
558 * Same as peek_user_per but for a 31 bit program.
560 static inline __u32 __peek_user_per_compat(struct task_struct *child,
563 struct compat_per_struct_kernel *dummy32 = NULL;
565 if (addr == (addr_t) &dummy32->cr9)
566 /* Control bits of the active per set. */
567 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
568 PER_EVENT_IFETCH : child->thread.per_user.control;
569 else if (addr == (addr_t) &dummy32->cr10)
570 /* Start address of the active per set. */
571 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
572 0 : child->thread.per_user.start;
573 else if (addr == (addr_t) &dummy32->cr11)
574 /* End address of the active per set. */
575 return test_thread_flag(TIF_SINGLE_STEP) ?
576 PSW32_ADDR_INSN : child->thread.per_user.end;
577 else if (addr == (addr_t) &dummy32->bits)
578 /* Single-step bit. */
579 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
581 else if (addr == (addr_t) &dummy32->starting_addr)
582 /* Start address of the user specified per set. */
583 return (__u32) child->thread.per_user.start;
584 else if (addr == (addr_t) &dummy32->ending_addr)
585 /* End address of the user specified per set. */
586 return (__u32) child->thread.per_user.end;
587 else if (addr == (addr_t) &dummy32->perc_atmid)
588 /* PER code, ATMID and AI of the last PER trap */
589 return (__u32) child->thread.per_event.cause << 16;
590 else if (addr == (addr_t) &dummy32->address)
591 /* Address of the last PER trap */
592 return (__u32) child->thread.per_event.address;
593 else if (addr == (addr_t) &dummy32->access_id)
594 /* Access id of the last PER trap */
595 return (__u32) child->thread.per_event.paid << 24;
600 * Same as peek_user but for a 31 bit program.
602 static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
604 struct compat_user *dummy32 = NULL;
608 if (addr < (addr_t) &dummy32->regs.acrs) {
609 struct pt_regs *regs = task_pt_regs(child);
611 * psw and gprs are stored on the stack
613 if (addr == (addr_t) &dummy32->regs.psw.mask) {
614 /* Fake a 31 bit psw mask. */
615 tmp = (__u32)(regs->psw.mask >> 32);
616 tmp &= PSW32_MASK_USER | PSW32_MASK_RI;
617 tmp |= PSW32_USER_BITS;
618 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
619 /* Fake a 31 bit psw address. */
620 tmp = (__u32) regs->psw.addr |
621 (__u32)(regs->psw.mask & PSW_MASK_BA);
624 tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4);
626 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
628 * access registers are stored in the thread structure
630 offset = addr - (addr_t) &dummy32->regs.acrs;
631 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
633 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
635 * orig_gpr2 is stored on the kernel stack
637 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
639 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
641 * prevent reads of padding hole between
642 * orig_gpr2 and fp_regs on s390.
646 } else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
648 * floating point control reg. is in the thread structure
650 tmp = child->thread.fpu.fpc;
652 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
654 * floating point regs. are either in child->thread.fpu
655 * or the child->thread.fpu.vxrs array
657 offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
660 ((addr_t) child->thread.fpu.vxrs + 2*offset);
663 ((addr_t) child->thread.fpu.fprs + offset);
665 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
667 * Handle access to the per_info structure.
669 addr -= (addr_t) &dummy32->regs.per_info;
670 tmp = __peek_user_per_compat(child, addr);
678 static int peek_user_compat(struct task_struct *child,
679 addr_t addr, addr_t data)
683 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
686 tmp = __peek_user_compat(child, addr);
687 return put_user(tmp, (__u32 __user *) data);
691 * Same as poke_user_per but for a 31 bit program.
693 static inline void __poke_user_per_compat(struct task_struct *child,
694 addr_t addr, __u32 data)
696 struct compat_per_struct_kernel *dummy32 = NULL;
698 if (addr == (addr_t) &dummy32->cr9)
699 /* PER event mask of the user specified per set. */
700 child->thread.per_user.control =
701 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
702 else if (addr == (addr_t) &dummy32->starting_addr)
703 /* Starting address of the user specified per set. */
704 child->thread.per_user.start = data;
705 else if (addr == (addr_t) &dummy32->ending_addr)
706 /* Ending address of the user specified per set. */
707 child->thread.per_user.end = data;
711 * Same as poke_user but for a 31 bit program.
713 static int __poke_user_compat(struct task_struct *child,
714 addr_t addr, addr_t data)
716 struct compat_user *dummy32 = NULL;
717 __u32 tmp = (__u32) data;
720 if (addr < (addr_t) &dummy32->regs.acrs) {
721 struct pt_regs *regs = task_pt_regs(child);
723 * psw, gprs, acrs and orig_gpr2 are stored on the stack
725 if (addr == (addr_t) &dummy32->regs.psw.mask) {
726 __u32 mask = PSW32_MASK_USER;
728 mask |= is_ri_task(child) ? PSW32_MASK_RI : 0;
729 /* Build a 64 bit psw mask from 31 bit mask. */
730 if ((tmp ^ PSW32_USER_BITS) & ~mask)
731 /* Invalid psw mask. */
733 if ((data & PSW32_MASK_ASC) == PSW32_ASC_HOME)
734 /* Invalid address-space-control bits */
736 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
737 (regs->psw.mask & PSW_MASK_BA) |
738 (__u64)(tmp & mask) << 32;
739 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
740 /* Build a 64 bit psw address from 31 bit address. */
741 regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
742 /* Transfer 31 bit amode bit to psw mask. */
743 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
744 (__u64)(tmp & PSW32_ADDR_AMODE);
747 if (test_pt_regs_flag(regs, PIF_SYSCALL) &&
748 addr == offsetof(struct compat_user, regs.gprs[2]))
749 fixup_int_code(child, data);
751 *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp;
753 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
755 * access registers are stored in the thread structure
757 offset = addr - (addr_t) &dummy32->regs.acrs;
758 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
760 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
762 * orig_gpr2 is stored on the kernel stack
764 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
766 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
768 * prevent writess of padding hole between
769 * orig_gpr2 and fp_regs on s390.
773 } else if (addr == (addr_t) &dummy32->regs.fp_regs.fpc) {
775 * floating point control reg. is in the thread structure
777 if (test_fp_ctl(tmp))
779 child->thread.fpu.fpc = data;
781 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
783 * floating point regs. are either in child->thread.fpu
784 * or the child->thread.fpu.vxrs array
786 offset = addr - (addr_t) &dummy32->regs.fp_regs.fprs;
789 child->thread.fpu.vxrs + 2*offset) = tmp;
792 child->thread.fpu.fprs + offset) = tmp;
794 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
796 * Handle access to the per_info structure.
798 addr -= (addr_t) &dummy32->regs.per_info;
799 __poke_user_per_compat(child, addr, data);
805 static int poke_user_compat(struct task_struct *child,
806 addr_t addr, addr_t data)
808 if (!is_compat_task() || (addr & 3) ||
809 addr > sizeof(struct compat_user) - 3)
812 return __poke_user_compat(child, addr, data);
815 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
816 compat_ulong_t caddr, compat_ulong_t cdata)
818 unsigned long addr = caddr;
819 unsigned long data = cdata;
820 compat_ptrace_area parea;
825 /* read the word at location addr in the USER area. */
826 return peek_user_compat(child, addr, data);
829 /* write the word at location addr in the USER area */
830 return poke_user_compat(child, addr, data);
832 case PTRACE_PEEKUSR_AREA:
833 case PTRACE_POKEUSR_AREA:
834 if (copy_from_user(&parea, (void __force __user *) addr,
837 addr = parea.kernel_addr;
838 data = parea.process_addr;
840 while (copied < parea.len) {
841 if (request == PTRACE_PEEKUSR_AREA)
842 ret = peek_user_compat(child, addr, data);
846 (__u32 __force __user *) data))
848 ret = poke_user_compat(child, addr, utmp);
852 addr += sizeof(unsigned int);
853 data += sizeof(unsigned int);
854 copied += sizeof(unsigned int);
857 case PTRACE_GET_LAST_BREAK:
858 put_user(child->thread.last_break,
859 (unsigned int __user *) data);
862 return compat_ptrace_request(child, request, addr, data);
866 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
868 unsigned long mask = -1UL;
871 if (is_compat_task())
875 * The sysc_tracesys code in entry.S stored the system
876 * call number to gprs[2].
878 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
879 tracehook_report_syscall_entry(regs)) {
881 * Tracing decided this syscall should not happen. Skip
882 * the system call and the system call restart handling.
887 #ifdef CONFIG_SECCOMP
888 /* Do the secure computing check after ptrace. */
889 if (unlikely(test_thread_flag(TIF_SECCOMP))) {
890 struct seccomp_data sd;
892 if (is_compat_task()) {
893 sd.instruction_pointer = regs->psw.addr & 0x7fffffff;
894 sd.arch = AUDIT_ARCH_S390;
896 sd.instruction_pointer = regs->psw.addr;
897 sd.arch = AUDIT_ARCH_S390X;
900 sd.nr = regs->int_code & 0xffff;
901 sd.args[0] = regs->orig_gpr2 & mask;
902 sd.args[1] = regs->gprs[3] & mask;
903 sd.args[2] = regs->gprs[4] & mask;
904 sd.args[3] = regs->gprs[5] & mask;
905 sd.args[4] = regs->gprs[6] & mask;
906 sd.args[5] = regs->gprs[7] & mask;
908 if (__secure_computing(&sd) == -1)
911 #endif /* CONFIG_SECCOMP */
913 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
914 trace_sys_enter(regs, regs->int_code & 0xffff);
917 audit_syscall_entry(regs->int_code & 0xffff, regs->orig_gpr2 & mask,
918 regs->gprs[3] &mask, regs->gprs[4] &mask,
919 regs->gprs[5] &mask);
921 if ((signed long)regs->gprs[2] >= NR_syscalls) {
922 regs->gprs[2] = -ENOSYS;
925 return regs->gprs[2];
927 clear_pt_regs_flag(regs, PIF_SYSCALL);
931 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
933 audit_syscall_exit(regs);
935 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
936 trace_sys_exit(regs, regs->gprs[2]);
938 if (test_thread_flag(TIF_SYSCALL_TRACE))
939 tracehook_report_syscall_exit(regs, 0);
943 * user_regset definitions.
946 static int s390_regs_get(struct task_struct *target,
947 const struct user_regset *regset,
948 unsigned int pos, unsigned int count,
949 void *kbuf, void __user *ubuf)
951 if (target == current)
952 save_access_regs(target->thread.acrs);
955 unsigned long *k = kbuf;
957 *k++ = __peek_user(target, pos);
962 unsigned long __user *u = ubuf;
964 if (__put_user(__peek_user(target, pos), u++))
973 static int s390_regs_set(struct task_struct *target,
974 const struct user_regset *regset,
975 unsigned int pos, unsigned int count,
976 const void *kbuf, const void __user *ubuf)
980 if (target == current)
981 save_access_regs(target->thread.acrs);
984 const unsigned long *k = kbuf;
985 while (count > 0 && !rc) {
986 rc = __poke_user(target, pos, *k++);
991 const unsigned long __user *u = ubuf;
992 while (count > 0 && !rc) {
994 rc = __get_user(word, u++);
997 rc = __poke_user(target, pos, word);
1003 if (rc == 0 && target == current)
1004 restore_access_regs(target->thread.acrs);
1009 static int s390_fpregs_get(struct task_struct *target,
1010 const struct user_regset *regset, unsigned int pos,
1011 unsigned int count, void *kbuf, void __user *ubuf)
1013 _s390_fp_regs fp_regs;
1015 if (target == current)
1018 fp_regs.fpc = target->thread.fpu.fpc;
1019 fpregs_store(&fp_regs, &target->thread.fpu);
1021 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1025 static int s390_fpregs_set(struct task_struct *target,
1026 const struct user_regset *regset, unsigned int pos,
1027 unsigned int count, const void *kbuf,
1028 const void __user *ubuf)
1031 freg_t fprs[__NUM_FPRS];
1033 if (target == current)
1037 convert_vx_to_fp(fprs, target->thread.fpu.vxrs);
1039 memcpy(&fprs, target->thread.fpu.fprs, sizeof(fprs));
1041 /* If setting FPC, must validate it first. */
1042 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
1043 u32 ufpc[2] = { target->thread.fpu.fpc, 0 };
1044 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc,
1045 0, offsetof(s390_fp_regs, fprs));
1048 if (ufpc[1] != 0 || test_fp_ctl(ufpc[0]))
1050 target->thread.fpu.fpc = ufpc[0];
1053 if (rc == 0 && count > 0)
1054 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1055 fprs, offsetof(s390_fp_regs, fprs), -1);
1060 convert_fp_to_vx(target->thread.fpu.vxrs, fprs);
1062 memcpy(target->thread.fpu.fprs, &fprs, sizeof(fprs));
1067 static int s390_last_break_get(struct task_struct *target,
1068 const struct user_regset *regset,
1069 unsigned int pos, unsigned int count,
1070 void *kbuf, void __user *ubuf)
1074 unsigned long *k = kbuf;
1075 *k = target->thread.last_break;
1077 unsigned long __user *u = ubuf;
1078 if (__put_user(target->thread.last_break, u))
1085 static int s390_last_break_set(struct task_struct *target,
1086 const struct user_regset *regset,
1087 unsigned int pos, unsigned int count,
1088 const void *kbuf, const void __user *ubuf)
1093 static int s390_tdb_get(struct task_struct *target,
1094 const struct user_regset *regset,
1095 unsigned int pos, unsigned int count,
1096 void *kbuf, void __user *ubuf)
1098 struct pt_regs *regs = task_pt_regs(target);
1099 unsigned char *data;
1101 if (!(regs->int_code & 0x200))
1103 data = target->thread.trap_tdb;
1104 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
1107 static int s390_tdb_set(struct task_struct *target,
1108 const struct user_regset *regset,
1109 unsigned int pos, unsigned int count,
1110 const void *kbuf, const void __user *ubuf)
1115 static int s390_vxrs_low_get(struct task_struct *target,
1116 const struct user_regset *regset,
1117 unsigned int pos, unsigned int count,
1118 void *kbuf, void __user *ubuf)
1120 __u64 vxrs[__NUM_VXRS_LOW];
1123 if (!MACHINE_HAS_VX)
1125 if (target == current)
1127 for (i = 0; i < __NUM_VXRS_LOW; i++)
1128 vxrs[i] = *((__u64 *)(target->thread.fpu.vxrs + i) + 1);
1129 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1132 static int s390_vxrs_low_set(struct task_struct *target,
1133 const struct user_regset *regset,
1134 unsigned int pos, unsigned int count,
1135 const void *kbuf, const void __user *ubuf)
1137 __u64 vxrs[__NUM_VXRS_LOW];
1140 if (!MACHINE_HAS_VX)
1142 if (target == current)
1145 for (i = 0; i < __NUM_VXRS_LOW; i++)
1146 vxrs[i] = *((__u64 *)(target->thread.fpu.vxrs + i) + 1);
1148 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1150 for (i = 0; i < __NUM_VXRS_LOW; i++)
1151 *((__u64 *)(target->thread.fpu.vxrs + i) + 1) = vxrs[i];
1156 static int s390_vxrs_high_get(struct task_struct *target,
1157 const struct user_regset *regset,
1158 unsigned int pos, unsigned int count,
1159 void *kbuf, void __user *ubuf)
1161 __vector128 vxrs[__NUM_VXRS_HIGH];
1163 if (!MACHINE_HAS_VX)
1165 if (target == current)
1167 memcpy(vxrs, target->thread.fpu.vxrs + __NUM_VXRS_LOW, sizeof(vxrs));
1169 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, vxrs, 0, -1);
1172 static int s390_vxrs_high_set(struct task_struct *target,
1173 const struct user_regset *regset,
1174 unsigned int pos, unsigned int count,
1175 const void *kbuf, const void __user *ubuf)
1179 if (!MACHINE_HAS_VX)
1181 if (target == current)
1184 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1185 target->thread.fpu.vxrs + __NUM_VXRS_LOW, 0, -1);
1189 static int s390_system_call_get(struct task_struct *target,
1190 const struct user_regset *regset,
1191 unsigned int pos, unsigned int count,
1192 void *kbuf, void __user *ubuf)
1194 unsigned int *data = &target->thread.system_call;
1195 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1196 data, 0, sizeof(unsigned int));
1199 static int s390_system_call_set(struct task_struct *target,
1200 const struct user_regset *regset,
1201 unsigned int pos, unsigned int count,
1202 const void *kbuf, const void __user *ubuf)
1204 unsigned int *data = &target->thread.system_call;
1205 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1206 data, 0, sizeof(unsigned int));
1209 static int s390_gs_cb_get(struct task_struct *target,
1210 const struct user_regset *regset,
1211 unsigned int pos, unsigned int count,
1212 void *kbuf, void __user *ubuf)
1214 struct gs_cb *data = target->thread.gs_cb;
1216 if (!MACHINE_HAS_GS)
1220 if (target == current)
1222 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1223 data, 0, sizeof(struct gs_cb));
1226 static int s390_gs_cb_set(struct task_struct *target,
1227 const struct user_regset *regset,
1228 unsigned int pos, unsigned int count,
1229 const void *kbuf, const void __user *ubuf)
1231 struct gs_cb gs_cb = { }, *data = NULL;
1234 if (!MACHINE_HAS_GS)
1236 if (!target->thread.gs_cb) {
1237 data = kzalloc(sizeof(*data), GFP_KERNEL);
1241 if (!target->thread.gs_cb)
1243 else if (target == current)
1246 gs_cb = *target->thread.gs_cb;
1247 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1248 &gs_cb, 0, sizeof(gs_cb));
1254 if (!target->thread.gs_cb)
1255 target->thread.gs_cb = data;
1256 *target->thread.gs_cb = gs_cb;
1257 if (target == current) {
1258 __ctl_set_bit(2, 4);
1259 restore_gs_cb(target->thread.gs_cb);
1265 static int s390_gs_bc_get(struct task_struct *target,
1266 const struct user_regset *regset,
1267 unsigned int pos, unsigned int count,
1268 void *kbuf, void __user *ubuf)
1270 struct gs_cb *data = target->thread.gs_bc_cb;
1272 if (!MACHINE_HAS_GS)
1276 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1277 data, 0, sizeof(struct gs_cb));
1280 static int s390_gs_bc_set(struct task_struct *target,
1281 const struct user_regset *regset,
1282 unsigned int pos, unsigned int count,
1283 const void *kbuf, const void __user *ubuf)
1285 struct gs_cb *data = target->thread.gs_bc_cb;
1287 if (!MACHINE_HAS_GS)
1290 data = kzalloc(sizeof(*data), GFP_KERNEL);
1293 target->thread.gs_bc_cb = data;
1295 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1296 data, 0, sizeof(struct gs_cb));
1299 static bool is_ri_cb_valid(struct runtime_instr_cb *cb)
1301 return (cb->rca & 0x1f) == 0 &&
1302 (cb->roa & 0xfff) == 0 &&
1303 (cb->rla & 0xfff) == 0xfff &&
1307 cb->reserved1 == 0 &&
1312 cb->reserved2 == 0 &&
1313 cb->key == PAGE_DEFAULT_KEY &&
1314 cb->reserved3 == 0 &&
1315 cb->reserved4 == 0 &&
1316 cb->reserved5 == 0 &&
1317 cb->reserved6 == 0 &&
1318 cb->reserved7 == 0 &&
1319 cb->reserved8 == 0 &&
1320 cb->rla >= cb->roa &&
1321 cb->rca >= cb->roa &&
1322 cb->rca <= cb->rla+1 &&
1326 static int s390_runtime_instr_get(struct task_struct *target,
1327 const struct user_regset *regset,
1328 unsigned int pos, unsigned int count,
1329 void *kbuf, void __user *ubuf)
1331 struct runtime_instr_cb *data = target->thread.ri_cb;
1333 if (!test_facility(64))
1338 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1339 data, 0, sizeof(struct runtime_instr_cb));
1342 static int s390_runtime_instr_set(struct task_struct *target,
1343 const struct user_regset *regset,
1344 unsigned int pos, unsigned int count,
1345 const void *kbuf, const void __user *ubuf)
1347 struct runtime_instr_cb ri_cb = { }, *data = NULL;
1350 if (!test_facility(64))
1353 if (!target->thread.ri_cb) {
1354 data = kzalloc(sizeof(*data), GFP_KERNEL);
1359 if (target->thread.ri_cb) {
1360 if (target == current)
1361 store_runtime_instr_cb(&ri_cb);
1363 ri_cb = *target->thread.ri_cb;
1366 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1367 &ri_cb, 0, sizeof(struct runtime_instr_cb));
1373 if (!is_ri_cb_valid(&ri_cb)) {
1379 if (!target->thread.ri_cb)
1380 target->thread.ri_cb = data;
1381 *target->thread.ri_cb = ri_cb;
1382 if (target == current)
1383 load_runtime_instr_cb(target->thread.ri_cb);
1389 static const struct user_regset s390_regsets[] = {
1391 .core_note_type = NT_PRSTATUS,
1392 .n = sizeof(s390_regs) / sizeof(long),
1393 .size = sizeof(long),
1394 .align = sizeof(long),
1395 .get = s390_regs_get,
1396 .set = s390_regs_set,
1399 .core_note_type = NT_PRFPREG,
1400 .n = sizeof(s390_fp_regs) / sizeof(long),
1401 .size = sizeof(long),
1402 .align = sizeof(long),
1403 .get = s390_fpregs_get,
1404 .set = s390_fpregs_set,
1407 .core_note_type = NT_S390_SYSTEM_CALL,
1409 .size = sizeof(unsigned int),
1410 .align = sizeof(unsigned int),
1411 .get = s390_system_call_get,
1412 .set = s390_system_call_set,
1415 .core_note_type = NT_S390_LAST_BREAK,
1417 .size = sizeof(long),
1418 .align = sizeof(long),
1419 .get = s390_last_break_get,
1420 .set = s390_last_break_set,
1423 .core_note_type = NT_S390_TDB,
1427 .get = s390_tdb_get,
1428 .set = s390_tdb_set,
1431 .core_note_type = NT_S390_VXRS_LOW,
1432 .n = __NUM_VXRS_LOW,
1433 .size = sizeof(__u64),
1434 .align = sizeof(__u64),
1435 .get = s390_vxrs_low_get,
1436 .set = s390_vxrs_low_set,
1439 .core_note_type = NT_S390_VXRS_HIGH,
1440 .n = __NUM_VXRS_HIGH,
1441 .size = sizeof(__vector128),
1442 .align = sizeof(__vector128),
1443 .get = s390_vxrs_high_get,
1444 .set = s390_vxrs_high_set,
1447 .core_note_type = NT_S390_GS_CB,
1448 .n = sizeof(struct gs_cb) / sizeof(__u64),
1449 .size = sizeof(__u64),
1450 .align = sizeof(__u64),
1451 .get = s390_gs_cb_get,
1452 .set = s390_gs_cb_set,
1455 .core_note_type = NT_S390_GS_BC,
1456 .n = sizeof(struct gs_cb) / sizeof(__u64),
1457 .size = sizeof(__u64),
1458 .align = sizeof(__u64),
1459 .get = s390_gs_bc_get,
1460 .set = s390_gs_bc_set,
1463 .core_note_type = NT_S390_RI_CB,
1464 .n = sizeof(struct runtime_instr_cb) / sizeof(__u64),
1465 .size = sizeof(__u64),
1466 .align = sizeof(__u64),
1467 .get = s390_runtime_instr_get,
1468 .set = s390_runtime_instr_set,
1472 static const struct user_regset_view user_s390_view = {
1474 .e_machine = EM_S390,
1475 .regsets = s390_regsets,
1476 .n = ARRAY_SIZE(s390_regsets)
1479 #ifdef CONFIG_COMPAT
1480 static int s390_compat_regs_get(struct task_struct *target,
1481 const struct user_regset *regset,
1482 unsigned int pos, unsigned int count,
1483 void *kbuf, void __user *ubuf)
1485 if (target == current)
1486 save_access_regs(target->thread.acrs);
1489 compat_ulong_t *k = kbuf;
1491 *k++ = __peek_user_compat(target, pos);
1492 count -= sizeof(*k);
1496 compat_ulong_t __user *u = ubuf;
1498 if (__put_user(__peek_user_compat(target, pos), u++))
1500 count -= sizeof(*u);
1507 static int s390_compat_regs_set(struct task_struct *target,
1508 const struct user_regset *regset,
1509 unsigned int pos, unsigned int count,
1510 const void *kbuf, const void __user *ubuf)
1514 if (target == current)
1515 save_access_regs(target->thread.acrs);
1518 const compat_ulong_t *k = kbuf;
1519 while (count > 0 && !rc) {
1520 rc = __poke_user_compat(target, pos, *k++);
1521 count -= sizeof(*k);
1525 const compat_ulong_t __user *u = ubuf;
1526 while (count > 0 && !rc) {
1527 compat_ulong_t word;
1528 rc = __get_user(word, u++);
1531 rc = __poke_user_compat(target, pos, word);
1532 count -= sizeof(*u);
1537 if (rc == 0 && target == current)
1538 restore_access_regs(target->thread.acrs);
1543 static int s390_compat_regs_high_get(struct task_struct *target,
1544 const struct user_regset *regset,
1545 unsigned int pos, unsigned int count,
1546 void *kbuf, void __user *ubuf)
1548 compat_ulong_t *gprs_high;
1550 gprs_high = (compat_ulong_t *)
1551 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1553 compat_ulong_t *k = kbuf;
1557 count -= sizeof(*k);
1560 compat_ulong_t __user *u = ubuf;
1562 if (__put_user(*gprs_high, u++))
1565 count -= sizeof(*u);
1571 static int s390_compat_regs_high_set(struct task_struct *target,
1572 const struct user_regset *regset,
1573 unsigned int pos, unsigned int count,
1574 const void *kbuf, const void __user *ubuf)
1576 compat_ulong_t *gprs_high;
1579 gprs_high = (compat_ulong_t *)
1580 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1582 const compat_ulong_t *k = kbuf;
1586 count -= sizeof(*k);
1589 const compat_ulong_t __user *u = ubuf;
1590 while (count > 0 && !rc) {
1592 rc = __get_user(word, u++);
1597 count -= sizeof(*u);
1604 static int s390_compat_last_break_get(struct task_struct *target,
1605 const struct user_regset *regset,
1606 unsigned int pos, unsigned int count,
1607 void *kbuf, void __user *ubuf)
1609 compat_ulong_t last_break;
1612 last_break = target->thread.last_break;
1614 unsigned long *k = kbuf;
1617 unsigned long __user *u = ubuf;
1618 if (__put_user(last_break, u))
1625 static int s390_compat_last_break_set(struct task_struct *target,
1626 const struct user_regset *regset,
1627 unsigned int pos, unsigned int count,
1628 const void *kbuf, const void __user *ubuf)
1633 static const struct user_regset s390_compat_regsets[] = {
1635 .core_note_type = NT_PRSTATUS,
1636 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1637 .size = sizeof(compat_long_t),
1638 .align = sizeof(compat_long_t),
1639 .get = s390_compat_regs_get,
1640 .set = s390_compat_regs_set,
1643 .core_note_type = NT_PRFPREG,
1644 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1645 .size = sizeof(compat_long_t),
1646 .align = sizeof(compat_long_t),
1647 .get = s390_fpregs_get,
1648 .set = s390_fpregs_set,
1651 .core_note_type = NT_S390_SYSTEM_CALL,
1653 .size = sizeof(compat_uint_t),
1654 .align = sizeof(compat_uint_t),
1655 .get = s390_system_call_get,
1656 .set = s390_system_call_set,
1659 .core_note_type = NT_S390_LAST_BREAK,
1661 .size = sizeof(long),
1662 .align = sizeof(long),
1663 .get = s390_compat_last_break_get,
1664 .set = s390_compat_last_break_set,
1667 .core_note_type = NT_S390_TDB,
1671 .get = s390_tdb_get,
1672 .set = s390_tdb_set,
1675 .core_note_type = NT_S390_VXRS_LOW,
1676 .n = __NUM_VXRS_LOW,
1677 .size = sizeof(__u64),
1678 .align = sizeof(__u64),
1679 .get = s390_vxrs_low_get,
1680 .set = s390_vxrs_low_set,
1683 .core_note_type = NT_S390_VXRS_HIGH,
1684 .n = __NUM_VXRS_HIGH,
1685 .size = sizeof(__vector128),
1686 .align = sizeof(__vector128),
1687 .get = s390_vxrs_high_get,
1688 .set = s390_vxrs_high_set,
1691 .core_note_type = NT_S390_HIGH_GPRS,
1692 .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
1693 .size = sizeof(compat_long_t),
1694 .align = sizeof(compat_long_t),
1695 .get = s390_compat_regs_high_get,
1696 .set = s390_compat_regs_high_set,
1699 .core_note_type = NT_S390_GS_CB,
1700 .n = sizeof(struct gs_cb) / sizeof(__u64),
1701 .size = sizeof(__u64),
1702 .align = sizeof(__u64),
1703 .get = s390_gs_cb_get,
1704 .set = s390_gs_cb_set,
1707 .core_note_type = NT_S390_GS_BC,
1708 .n = sizeof(struct gs_cb) / sizeof(__u64),
1709 .size = sizeof(__u64),
1710 .align = sizeof(__u64),
1711 .get = s390_gs_bc_get,
1712 .set = s390_gs_bc_set,
1715 .core_note_type = NT_S390_RI_CB,
1716 .n = sizeof(struct runtime_instr_cb) / sizeof(__u64),
1717 .size = sizeof(__u64),
1718 .align = sizeof(__u64),
1719 .get = s390_runtime_instr_get,
1720 .set = s390_runtime_instr_set,
1724 static const struct user_regset_view user_s390_compat_view = {
1726 .e_machine = EM_S390,
1727 .regsets = s390_compat_regsets,
1728 .n = ARRAY_SIZE(s390_compat_regsets)
1732 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1734 #ifdef CONFIG_COMPAT
1735 if (test_tsk_thread_flag(task, TIF_31BIT))
1736 return &user_s390_compat_view;
1738 return &user_s390_view;
1741 static const char *gpr_names[NUM_GPRS] = {
1742 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1743 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1746 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1748 if (offset >= NUM_GPRS)
1750 return regs->gprs[offset];
1753 int regs_query_register_offset(const char *name)
1755 unsigned long offset;
1757 if (!name || *name != 'r')
1759 if (kstrtoul(name + 1, 10, &offset))
1761 if (offset >= NUM_GPRS)
1766 const char *regs_query_register_name(unsigned int offset)
1768 if (offset >= NUM_GPRS)
1770 return gpr_names[offset];
1773 static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1775 unsigned long ksp = kernel_stack_pointer(regs);
1777 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1781 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1782 * @regs:pt_regs which contains kernel stack pointer.
1783 * @n:stack entry number.
1785 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1786 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1789 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1793 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1794 if (!regs_within_kernel_stack(regs, addr))
1796 return *(unsigned long *)addr;