1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ptrace.c: Sparc process tracing support.
4 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
5 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
10 * Added Linux support -miguel (weird, eh?, the original code was meant
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/sched/task_stack.h>
18 #include <linux/errno.h>
19 #include <linux/export.h>
20 #include <linux/ptrace.h>
21 #include <linux/user.h>
22 #include <linux/smp.h>
23 #include <linux/security.h>
24 #include <linux/seccomp.h>
25 #include <linux/audit.h>
26 #include <linux/signal.h>
27 #include <linux/regset.h>
28 #include <linux/tracehook.h>
29 #include <trace/syscall.h>
30 #include <linux/compat.h>
31 #include <linux/elf.h>
32 #include <linux/context_tracking.h>
35 #include <asm/pgtable.h>
36 #include <linux/uaccess.h>
37 #include <asm/psrcompat.h>
38 #include <asm/visasm.h>
39 #include <asm/spitfire.h>
41 #include <asm/cpudata.h>
42 #include <asm/cacheflush.h>
44 #define CREATE_TRACE_POINTS
45 #include <trace/events/syscalls.h>
49 /* #define ALLOW_INIT_TRACING */
51 struct pt_regs_offset {
56 #define REG_OFFSET_NAME(n, r) \
57 {.name = n, .offset = (PT_V9_##r)}
58 #define REG_OFFSET_END {.name = NULL, .offset = 0}
60 static const struct pt_regs_offset regoffset_table[] = {
61 REG_OFFSET_NAME("g0", G0),
62 REG_OFFSET_NAME("g1", G1),
63 REG_OFFSET_NAME("g2", G2),
64 REG_OFFSET_NAME("g3", G3),
65 REG_OFFSET_NAME("g4", G4),
66 REG_OFFSET_NAME("g5", G5),
67 REG_OFFSET_NAME("g6", G6),
68 REG_OFFSET_NAME("g7", G7),
70 REG_OFFSET_NAME("i0", I0),
71 REG_OFFSET_NAME("i1", I1),
72 REG_OFFSET_NAME("i2", I2),
73 REG_OFFSET_NAME("i3", I3),
74 REG_OFFSET_NAME("i4", I4),
75 REG_OFFSET_NAME("i5", I5),
76 REG_OFFSET_NAME("i6", I6),
77 REG_OFFSET_NAME("i7", I7),
79 REG_OFFSET_NAME("tstate", TSTATE),
80 REG_OFFSET_NAME("pc", TPC),
81 REG_OFFSET_NAME("npc", TNPC),
82 REG_OFFSET_NAME("y", Y),
83 REG_OFFSET_NAME("lr", I7),
89 * Called by kernel/ptrace.c when detaching..
91 * Make sure single step bits etc are not set.
93 void ptrace_disable(struct task_struct *child)
98 /* To get the necessary page struct, access_process_vm() first calls
99 * get_user_pages(). This has done a flush_dcache_page() on the
100 * accessed page. Then our caller (copy_{to,from}_user_page()) did
101 * to memcpy to read/write the data from that page.
103 * Now, the only thing we have to do is:
104 * 1) flush the D-cache if it's possible than an illegal alias
106 * 2) flush the I-cache if this is pre-cheetah and we did a write
108 void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
109 unsigned long uaddr, void *kaddr,
110 unsigned long len, int write)
112 BUG_ON(len > PAGE_SIZE);
114 if (tlb_type == hypervisor)
119 #ifdef DCACHE_ALIASING_POSSIBLE
120 /* If bit 13 of the kernel address we used to access the
121 * user page is the same as the virtual address that page
122 * is mapped to in the user's address space, we can skip the
125 if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
126 unsigned long start = __pa(kaddr);
127 unsigned long end = start + len;
128 unsigned long dcache_line_size;
130 dcache_line_size = local_cpu_data().dcache_line_size;
132 if (tlb_type == spitfire) {
133 for (; start < end; start += dcache_line_size)
134 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
136 start &= ~(dcache_line_size - 1);
137 for (; start < end; start += dcache_line_size)
138 __asm__ __volatile__(
139 "stxa %%g0, [%0] %1\n\t"
143 "i" (ASI_DCACHE_INVALIDATE));
147 if (write && tlb_type == spitfire) {
148 unsigned long start = (unsigned long) kaddr;
149 unsigned long end = start + len;
150 unsigned long icache_line_size;
152 icache_line_size = local_cpu_data().icache_line_size;
154 for (; start < end; start += icache_line_size)
160 EXPORT_SYMBOL_GPL(flush_ptrace_access);
162 static int get_from_target(struct task_struct *target, unsigned long uaddr,
165 if (target == current) {
166 if (copy_from_user(kbuf, (void __user *) uaddr, len))
169 int len2 = access_process_vm(target, uaddr, kbuf, len,
177 static int set_to_target(struct task_struct *target, unsigned long uaddr,
180 if (target == current) {
181 if (copy_to_user((void __user *) uaddr, kbuf, len))
184 int len2 = access_process_vm(target, uaddr, kbuf, len,
185 FOLL_FORCE | FOLL_WRITE);
192 static int regwindow64_get(struct task_struct *target,
193 const struct pt_regs *regs,
194 struct reg_window *wbuf)
196 unsigned long rw_addr = regs->u_regs[UREG_I6];
198 if (!test_thread_64bit_stack(rw_addr)) {
199 struct reg_window32 win32;
202 if (get_from_target(target, rw_addr, &win32, sizeof(win32)))
204 for (i = 0; i < 8; i++)
205 wbuf->locals[i] = win32.locals[i];
206 for (i = 0; i < 8; i++)
207 wbuf->ins[i] = win32.ins[i];
209 rw_addr += STACK_BIAS;
210 if (get_from_target(target, rw_addr, wbuf, sizeof(*wbuf)))
217 static int regwindow64_set(struct task_struct *target,
218 const struct pt_regs *regs,
219 struct reg_window *wbuf)
221 unsigned long rw_addr = regs->u_regs[UREG_I6];
223 if (!test_thread_64bit_stack(rw_addr)) {
224 struct reg_window32 win32;
227 for (i = 0; i < 8; i++)
228 win32.locals[i] = wbuf->locals[i];
229 for (i = 0; i < 8; i++)
230 win32.ins[i] = wbuf->ins[i];
232 if (set_to_target(target, rw_addr, &win32, sizeof(win32)))
235 rw_addr += STACK_BIAS;
236 if (set_to_target(target, rw_addr, wbuf, sizeof(*wbuf)))
248 static int genregs64_get(struct task_struct *target,
249 const struct user_regset *regset,
250 unsigned int pos, unsigned int count,
251 void *kbuf, void __user *ubuf)
253 const struct pt_regs *regs = task_pt_regs(target);
256 if (target == current)
259 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
261 0, 16 * sizeof(u64));
262 if (!ret && count && pos < (32 * sizeof(u64))) {
263 struct reg_window window;
265 if (regwindow64_get(target, regs, &window))
267 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
274 /* TSTATE, TPC, TNPC */
275 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
282 unsigned long y = regs->y;
284 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
291 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
292 36 * sizeof(u64), -1);
298 static int genregs64_set(struct task_struct *target,
299 const struct user_regset *regset,
300 unsigned int pos, unsigned int count,
301 const void *kbuf, const void __user *ubuf)
303 struct pt_regs *regs = task_pt_regs(target);
306 if (target == current)
309 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
311 0, 16 * sizeof(u64));
312 if (!ret && count && pos < (32 * sizeof(u64))) {
313 struct reg_window window;
315 if (regwindow64_get(target, regs, &window))
318 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
324 regwindow64_set(target, regs, &window))
328 if (!ret && count > 0) {
329 unsigned long tstate;
332 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
337 /* Only the condition codes and the "in syscall"
338 * state can be modified in the %tstate register.
340 tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
341 regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
342 regs->tstate |= tstate;
348 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
355 unsigned long y = regs->y;
357 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
366 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
367 36 * sizeof(u64), -1);
372 static int fpregs64_get(struct task_struct *target,
373 const struct user_regset *regset,
374 unsigned int pos, unsigned int count,
375 void *kbuf, void __user *ubuf)
377 const unsigned long *fpregs = task_thread_info(target)->fpregs;
378 unsigned long fprs, fsr, gsr;
381 if (target == current)
382 save_and_clear_fpu();
384 fprs = task_thread_info(target)->fpsaved[0];
387 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
389 0, 16 * sizeof(u64));
391 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
397 ret = user_regset_copyout(&pos, &count,
403 ret = user_regset_copyout_zero(&pos, &count,
409 if (fprs & FPRS_FEF) {
410 fsr = task_thread_info(target)->xfsr[0];
411 gsr = task_thread_info(target)->gsr[0];
417 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
422 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
427 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
433 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
434 35 * sizeof(u64), -1);
439 static int fpregs64_set(struct task_struct *target,
440 const struct user_regset *regset,
441 unsigned int pos, unsigned int count,
442 const void *kbuf, const void __user *ubuf)
444 unsigned long *fpregs = task_thread_info(target)->fpregs;
448 if (target == current)
449 save_and_clear_fpu();
451 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
453 0, 32 * sizeof(u64));
455 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
456 task_thread_info(target)->xfsr,
460 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
461 task_thread_info(target)->gsr,
465 fprs = task_thread_info(target)->fpsaved[0];
466 if (!ret && count > 0) {
467 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
473 fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
474 task_thread_info(target)->fpsaved[0] = fprs;
477 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
478 35 * sizeof(u64), -1);
482 static const struct user_regset sparc64_regsets[] = {
488 * TSTATE, TPC, TNPC, Y
491 .core_note_type = NT_PRSTATUS,
493 .size = sizeof(u64), .align = sizeof(u64),
494 .get = genregs64_get, .set = genregs64_set
503 .core_note_type = NT_PRFPREG,
505 .size = sizeof(u64), .align = sizeof(u64),
506 .get = fpregs64_get, .set = fpregs64_set
510 static const struct user_regset_view user_sparc64_view = {
511 .name = "sparc64", .e_machine = EM_SPARCV9,
512 .regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
516 static int genregs32_get(struct task_struct *target,
517 const struct user_regset *regset,
518 unsigned int pos, unsigned int count,
519 void *kbuf, void __user *ubuf)
521 const struct pt_regs *regs = task_pt_regs(target);
522 compat_ulong_t __user *reg_window;
523 compat_ulong_t *k = kbuf;
524 compat_ulong_t __user *u = ubuf;
527 if (target == current)
531 count /= sizeof(reg);
534 for (; count > 0 && pos < 16; count--)
535 *k++ = regs->u_regs[pos++];
537 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
539 if (target == current) {
540 for (; count > 0 && pos < 32; count--) {
541 if (get_user(*k++, ®_window[pos++]))
545 for (; count > 0 && pos < 32; count--) {
546 if (access_process_vm(target,
558 for (; count > 0 && pos < 16; count--) {
559 if (put_user((compat_ulong_t) regs->u_regs[pos++], u++))
563 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
565 if (target == current) {
566 for (; count > 0 && pos < 32; count--) {
567 if (get_user(reg, ®_window[pos++]) ||
572 for (; count > 0 && pos < 32; count--) {
573 if (access_process_vm(target,
580 if (access_process_vm(target,
583 FOLL_FORCE | FOLL_WRITE)
594 reg = tstate_to_psr(regs->tstate);
615 else if (put_user(reg, u++))
622 count *= sizeof(reg);
624 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
625 38 * sizeof(reg), -1);
628 static int genregs32_set(struct task_struct *target,
629 const struct user_regset *regset,
630 unsigned int pos, unsigned int count,
631 const void *kbuf, const void __user *ubuf)
633 struct pt_regs *regs = task_pt_regs(target);
634 compat_ulong_t __user *reg_window;
635 const compat_ulong_t *k = kbuf;
636 const compat_ulong_t __user *u = ubuf;
639 if (target == current)
643 count /= sizeof(reg);
646 for (; count > 0 && pos < 16; count--)
647 regs->u_regs[pos++] = *k++;
649 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
651 if (target == current) {
652 for (; count > 0 && pos < 32; count--) {
653 if (put_user(*k++, ®_window[pos++]))
657 for (; count > 0 && pos < 32; count--) {
658 if (access_process_vm(target,
663 FOLL_FORCE | FOLL_WRITE)
671 for (; count > 0 && pos < 16; count--) {
672 if (get_user(reg, u++))
674 regs->u_regs[pos++] = reg;
677 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
679 if (target == current) {
680 for (; count > 0 && pos < 32; count--) {
681 if (get_user(reg, u++) ||
682 put_user(reg, ®_window[pos++]))
686 for (; count > 0 && pos < 32; count--) {
687 if (access_process_vm(target,
694 if (access_process_vm(target,
698 FOLL_FORCE | FOLL_WRITE)
707 unsigned long tstate;
711 else if (get_user(reg, u++))
716 tstate = regs->tstate;
717 tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
718 tstate |= psr_to_tstate_icc(reg);
719 if (reg & PSR_SYSCALL)
720 tstate |= TSTATE_SYSCALL;
721 regs->tstate = tstate;
744 count *= sizeof(reg);
746 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
747 38 * sizeof(reg), -1);
750 static int fpregs32_get(struct task_struct *target,
751 const struct user_regset *regset,
752 unsigned int pos, unsigned int count,
753 void *kbuf, void __user *ubuf)
755 const unsigned long *fpregs = task_thread_info(target)->fpregs;
756 compat_ulong_t enabled;
761 if (target == current)
762 save_and_clear_fpu();
764 fprs = task_thread_info(target)->fpsaved[0];
765 if (fprs & FPRS_FEF) {
766 fsr = task_thread_info(target)->xfsr[0];
773 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
775 0, 32 * sizeof(u32));
778 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
782 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
790 val = (enabled << 8) | (8 << 16);
791 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
798 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
799 35 * sizeof(u32), -1);
804 static int fpregs32_set(struct task_struct *target,
805 const struct user_regset *regset,
806 unsigned int pos, unsigned int count,
807 const void *kbuf, const void __user *ubuf)
809 unsigned long *fpregs = task_thread_info(target)->fpregs;
813 if (target == current)
814 save_and_clear_fpu();
816 fprs = task_thread_info(target)->fpsaved[0];
818 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
820 0, 32 * sizeof(u32));
822 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
825 if (!ret && count > 0) {
829 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
834 val = task_thread_info(target)->xfsr[0];
835 val &= 0xffffffff00000000UL;
837 task_thread_info(target)->xfsr[0] = val;
841 fprs |= (FPRS_FEF | FPRS_DL);
842 task_thread_info(target)->fpsaved[0] = fprs;
845 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
846 34 * sizeof(u32), -1);
850 static const struct user_regset sparc32_regsets[] = {
856 * PSR, PC, nPC, Y, WIM, TBR
859 .core_note_type = NT_PRSTATUS,
861 .size = sizeof(u32), .align = sizeof(u32),
862 .get = genregs32_get, .set = genregs32_set
868 * FPU QUEUE COUNT (8-bit char)
869 * FPU QUEUE ENTRYSIZE (8-bit char)
870 * FPU ENABLED (8-bit char)
872 * FPU QUEUE (64 32-bit ints)
875 .core_note_type = NT_PRFPREG,
877 .size = sizeof(u32), .align = sizeof(u32),
878 .get = fpregs32_get, .set = fpregs32_set
882 static const struct user_regset_view user_sparc32_view = {
883 .name = "sparc", .e_machine = EM_SPARC,
884 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
886 #endif /* CONFIG_COMPAT */
888 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
891 if (test_tsk_thread_flag(task, TIF_32BIT))
892 return &user_sparc32_view;
894 return &user_sparc64_view;
899 unsigned int regs[32];
905 unsigned int insnaddr;
910 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
911 compat_ulong_t caddr, compat_ulong_t cdata)
913 const struct user_regset_view *view = task_user_regset_view(current);
914 compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
915 struct pt_regs32 __user *pregs;
916 struct compat_fps __user *fps;
917 unsigned long addr2 = caddr2;
918 unsigned long addr = caddr;
919 unsigned long data = cdata;
922 pregs = (struct pt_regs32 __user *) addr;
923 fps = (struct compat_fps __user *) addr;
927 ret = (addr != 0) ? -EIO : 0;
931 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
936 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
943 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
948 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
954 case PTRACE_GETFPREGS:
955 ret = copy_regset_to_user(child, view, REGSET_FP,
960 ret = copy_regset_to_user(child, view, REGSET_FP,
965 if (__put_user(0, &fps->flags) ||
966 __put_user(0, &fps->extra) ||
967 __put_user(0, &fps->fpqd) ||
968 clear_user(&fps->fpq[0], 32 * sizeof(unsigned int)))
973 case PTRACE_SETFPREGS:
974 ret = copy_regset_from_user(child, view, REGSET_FP,
979 ret = copy_regset_from_user(child, view, REGSET_FP,
985 case PTRACE_READTEXT:
986 case PTRACE_READDATA:
987 ret = ptrace_readdata(child, addr,
988 (char __user *)addr2, data);
995 case PTRACE_WRITETEXT:
996 case PTRACE_WRITEDATA:
997 ret = ptrace_writedata(child, (char __user *) addr2,
1006 if (request == PTRACE_SPARC_DETACH)
1007 request = PTRACE_DETACH;
1008 ret = compat_ptrace_request(child, request, addr, data);
1014 #endif /* CONFIG_COMPAT */
1017 unsigned int regs[64];
1021 long arch_ptrace(struct task_struct *child, long request,
1022 unsigned long addr, unsigned long data)
1024 const struct user_regset_view *view = task_user_regset_view(current);
1025 unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
1026 struct pt_regs __user *pregs;
1027 struct fps __user *fps;
1028 void __user *addr2p;
1031 pregs = (struct pt_regs __user *) addr;
1032 fps = (struct fps __user *) addr;
1033 addr2p = (void __user *) addr2;
1036 case PTRACE_PEEKUSR:
1037 ret = (addr != 0) ? -EIO : 0;
1040 case PTRACE_GETREGS64:
1041 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
1046 /* XXX doesn't handle 'y' register correctly XXX */
1047 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
1054 case PTRACE_SETREGS64:
1055 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
1060 /* XXX doesn't handle 'y' register correctly XXX */
1061 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
1068 case PTRACE_GETFPREGS64:
1069 ret = copy_regset_to_user(child, view, REGSET_FP,
1075 case PTRACE_SETFPREGS64:
1076 ret = copy_regset_from_user(child, view, REGSET_FP,
1082 case PTRACE_READTEXT:
1083 case PTRACE_READDATA:
1084 ret = ptrace_readdata(child, addr, addr2p, data);
1091 case PTRACE_WRITETEXT:
1092 case PTRACE_WRITEDATA:
1093 ret = ptrace_writedata(child, addr2p, addr, data);
1101 if (request == PTRACE_SPARC_DETACH)
1102 request = PTRACE_DETACH;
1103 ret = ptrace_request(child, request, addr, data);
1110 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1114 /* do the secure computing check first */
1115 secure_computing_strict(regs->u_regs[UREG_G1]);
1117 if (test_thread_flag(TIF_NOHZ))
1120 if (test_thread_flag(TIF_SYSCALL_TRACE))
1121 ret = tracehook_report_syscall_entry(regs);
1123 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1124 trace_sys_enter(regs, regs->u_regs[UREG_G1]);
1126 audit_syscall_entry(regs->u_regs[UREG_G1], regs->u_regs[UREG_I0],
1127 regs->u_regs[UREG_I1], regs->u_regs[UREG_I2],
1128 regs->u_regs[UREG_I3]);
1133 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
1135 if (test_thread_flag(TIF_NOHZ))
1138 audit_syscall_exit(regs);
1140 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1141 trace_sys_exit(regs, regs->u_regs[UREG_I0]);
1143 if (test_thread_flag(TIF_SYSCALL_TRACE))
1144 tracehook_report_syscall_exit(regs, 0);
1146 if (test_thread_flag(TIF_NOHZ))
1151 * regs_query_register_offset() - query register offset from its name
1152 * @name: the name of a register
1154 * regs_query_register_offset() returns the offset of a register in struct
1155 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
1157 int regs_query_register_offset(const char *name)
1159 const struct pt_regs_offset *roff;
1161 for (roff = regoffset_table; roff->name != NULL; roff++)
1162 if (!strcmp(roff->name, name))
1163 return roff->offset;
1168 * regs_within_kernel_stack() - check the address in the stack
1169 * @regs: pt_regs which contains kernel stack pointer.
1170 * @addr: address which is checked.
1172 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
1173 * If @addr is within the kernel stack, it returns true. If not, returns false.
1175 static inline int regs_within_kernel_stack(struct pt_regs *regs,
1178 unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1179 return ((addr & ~(THREAD_SIZE - 1)) ==
1180 (ksp & ~(THREAD_SIZE - 1)));
1184 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1185 * @regs: pt_regs which contains kernel stack pointer.
1186 * @n: stack entry number.
1188 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1189 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
1192 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1194 unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1195 unsigned long *addr = (unsigned long *)ksp;
1197 if (regs_within_kernel_stack(regs, (unsigned long)addr))