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 <linux/uaccess.h>
36 #include <asm/psrcompat.h>
37 #include <asm/visasm.h>
38 #include <asm/spitfire.h>
40 #include <asm/cpudata.h>
41 #include <asm/cacheflush.h>
43 #define CREATE_TRACE_POINTS
44 #include <trace/events/syscalls.h>
48 /* #define ALLOW_INIT_TRACING */
50 struct pt_regs_offset {
55 #define REG_OFFSET_NAME(n, r) \
56 {.name = n, .offset = (PT_V9_##r)}
57 #define REG_OFFSET_END {.name = NULL, .offset = 0}
59 static const struct pt_regs_offset regoffset_table[] = {
60 REG_OFFSET_NAME("g0", G0),
61 REG_OFFSET_NAME("g1", G1),
62 REG_OFFSET_NAME("g2", G2),
63 REG_OFFSET_NAME("g3", G3),
64 REG_OFFSET_NAME("g4", G4),
65 REG_OFFSET_NAME("g5", G5),
66 REG_OFFSET_NAME("g6", G6),
67 REG_OFFSET_NAME("g7", G7),
69 REG_OFFSET_NAME("i0", I0),
70 REG_OFFSET_NAME("i1", I1),
71 REG_OFFSET_NAME("i2", I2),
72 REG_OFFSET_NAME("i3", I3),
73 REG_OFFSET_NAME("i4", I4),
74 REG_OFFSET_NAME("i5", I5),
75 REG_OFFSET_NAME("i6", I6),
76 REG_OFFSET_NAME("i7", I7),
78 REG_OFFSET_NAME("tstate", TSTATE),
79 REG_OFFSET_NAME("pc", TPC),
80 REG_OFFSET_NAME("npc", TNPC),
81 REG_OFFSET_NAME("y", Y),
82 REG_OFFSET_NAME("lr", I7),
88 * Called by kernel/ptrace.c when detaching..
90 * Make sure single step bits etc are not set.
92 void ptrace_disable(struct task_struct *child)
97 /* To get the necessary page struct, access_process_vm() first calls
98 * get_user_pages(). This has done a flush_dcache_page() on the
99 * accessed page. Then our caller (copy_{to,from}_user_page()) did
100 * to memcpy to read/write the data from that page.
102 * Now, the only thing we have to do is:
103 * 1) flush the D-cache if it's possible than an illegal alias
105 * 2) flush the I-cache if this is pre-cheetah and we did a write
107 void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
108 unsigned long uaddr, void *kaddr,
109 unsigned long len, int write)
111 BUG_ON(len > PAGE_SIZE);
113 if (tlb_type == hypervisor)
118 #ifdef DCACHE_ALIASING_POSSIBLE
119 /* If bit 13 of the kernel address we used to access the
120 * user page is the same as the virtual address that page
121 * is mapped to in the user's address space, we can skip the
124 if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
125 unsigned long start = __pa(kaddr);
126 unsigned long end = start + len;
127 unsigned long dcache_line_size;
129 dcache_line_size = local_cpu_data().dcache_line_size;
131 if (tlb_type == spitfire) {
132 for (; start < end; start += dcache_line_size)
133 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
135 start &= ~(dcache_line_size - 1);
136 for (; start < end; start += dcache_line_size)
137 __asm__ __volatile__(
138 "stxa %%g0, [%0] %1\n\t"
142 "i" (ASI_DCACHE_INVALIDATE));
146 if (write && tlb_type == spitfire) {
147 unsigned long start = (unsigned long) kaddr;
148 unsigned long end = start + len;
149 unsigned long icache_line_size;
151 icache_line_size = local_cpu_data().icache_line_size;
153 for (; start < end; start += icache_line_size)
159 EXPORT_SYMBOL_GPL(flush_ptrace_access);
161 static int get_from_target(struct task_struct *target, unsigned long uaddr,
164 if (target == current) {
165 if (copy_from_user(kbuf, (void __user *) uaddr, len))
168 int len2 = access_process_vm(target, uaddr, kbuf, len,
176 static int set_to_target(struct task_struct *target, unsigned long uaddr,
179 if (target == current) {
180 if (copy_to_user((void __user *) uaddr, kbuf, len))
183 int len2 = access_process_vm(target, uaddr, kbuf, len,
184 FOLL_FORCE | FOLL_WRITE);
191 static int regwindow64_get(struct task_struct *target,
192 const struct pt_regs *regs,
193 struct reg_window *wbuf)
195 unsigned long rw_addr = regs->u_regs[UREG_I6];
197 if (!test_thread_64bit_stack(rw_addr)) {
198 struct reg_window32 win32;
201 if (get_from_target(target, rw_addr, &win32, sizeof(win32)))
203 for (i = 0; i < 8; i++)
204 wbuf->locals[i] = win32.locals[i];
205 for (i = 0; i < 8; i++)
206 wbuf->ins[i] = win32.ins[i];
208 rw_addr += STACK_BIAS;
209 if (get_from_target(target, rw_addr, wbuf, sizeof(*wbuf)))
216 static int regwindow64_set(struct task_struct *target,
217 const struct pt_regs *regs,
218 struct reg_window *wbuf)
220 unsigned long rw_addr = regs->u_regs[UREG_I6];
222 if (!test_thread_64bit_stack(rw_addr)) {
223 struct reg_window32 win32;
226 for (i = 0; i < 8; i++)
227 win32.locals[i] = wbuf->locals[i];
228 for (i = 0; i < 8; i++)
229 win32.ins[i] = wbuf->ins[i];
231 if (set_to_target(target, rw_addr, &win32, sizeof(win32)))
234 rw_addr += STACK_BIAS;
235 if (set_to_target(target, rw_addr, wbuf, sizeof(*wbuf)))
247 static int genregs64_get(struct task_struct *target,
248 const struct user_regset *regset,
251 const struct pt_regs *regs = task_pt_regs(target);
252 struct reg_window window;
254 if (target == current)
257 membuf_write(&to, regs->u_regs, 16 * sizeof(u64));
260 if (regwindow64_get(target, regs, &window))
262 membuf_write(&to, &window, 16 * sizeof(u64));
263 /* TSTATE, TPC, TNPC */
264 membuf_write(&to, ®s->tstate, 3 * sizeof(u64));
265 return membuf_store(&to, (u64)regs->y);
268 static int genregs64_set(struct task_struct *target,
269 const struct user_regset *regset,
270 unsigned int pos, unsigned int count,
271 const void *kbuf, const void __user *ubuf)
273 struct pt_regs *regs = task_pt_regs(target);
276 if (target == current)
279 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
281 0, 16 * sizeof(u64));
282 if (!ret && count && pos < (32 * sizeof(u64))) {
283 struct reg_window window;
285 if (regwindow64_get(target, regs, &window))
288 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
294 regwindow64_set(target, regs, &window))
298 if (!ret && count > 0) {
299 unsigned long tstate;
302 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
307 /* Only the condition codes and the "in syscall"
308 * state can be modified in the %tstate register.
310 tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
311 regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
312 regs->tstate |= tstate;
318 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
325 unsigned long y = regs->y;
327 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
336 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
337 36 * sizeof(u64), -1);
342 static int fpregs64_get(struct task_struct *target,
343 const struct user_regset *regset,
346 struct thread_info *t = task_thread_info(target);
349 if (target == current)
350 save_and_clear_fpu();
352 fprs = t->fpsaved[0];
355 membuf_write(&to, t->fpregs, 16 * sizeof(u64));
357 membuf_zero(&to, 16 * sizeof(u64));
360 membuf_write(&to, t->fpregs + 16, 16 * sizeof(u64));
362 membuf_zero(&to, 16 * sizeof(u64));
363 if (fprs & FPRS_FEF) {
364 membuf_store(&to, t->xfsr[0]);
365 membuf_store(&to, t->gsr[0]);
367 membuf_zero(&to, 2 * sizeof(u64));
369 return membuf_store(&to, fprs);
372 static int fpregs64_set(struct task_struct *target,
373 const struct user_regset *regset,
374 unsigned int pos, unsigned int count,
375 const void *kbuf, const void __user *ubuf)
377 unsigned long *fpregs = task_thread_info(target)->fpregs;
381 if (target == current)
382 save_and_clear_fpu();
384 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
386 0, 32 * sizeof(u64));
388 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
389 task_thread_info(target)->xfsr,
393 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
394 task_thread_info(target)->gsr,
398 fprs = task_thread_info(target)->fpsaved[0];
399 if (!ret && count > 0) {
400 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
406 fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
407 task_thread_info(target)->fpsaved[0] = fprs;
410 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
411 35 * sizeof(u64), -1);
415 static const struct user_regset sparc64_regsets[] = {
421 * TSTATE, TPC, TNPC, Y
424 .core_note_type = NT_PRSTATUS,
426 .size = sizeof(u64), .align = sizeof(u64),
427 .regset_get = genregs64_get, .set = genregs64_set
436 .core_note_type = NT_PRFPREG,
438 .size = sizeof(u64), .align = sizeof(u64),
439 .regset_get = fpregs64_get, .set = fpregs64_set
443 static int getregs64_get(struct task_struct *target,
444 const struct user_regset *regset,
447 const struct pt_regs *regs = task_pt_regs(target);
449 if (target == current)
452 membuf_write(&to, regs->u_regs + 1, 15 * sizeof(u64));
453 membuf_store(&to, (u64)0);
454 membuf_write(&to, ®s->tstate, 3 * sizeof(u64));
455 return membuf_store(&to, (u64)regs->y);
458 static int setregs64_set(struct task_struct *target,
459 const struct user_regset *regset,
460 unsigned int pos, unsigned int count,
461 const void *kbuf, const void __user *ubuf)
463 struct pt_regs *regs = task_pt_regs(target);
464 unsigned long y = regs->y;
465 unsigned long tstate;
468 if (target == current)
471 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
477 ret =user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
478 15 * sizeof(u64), 16 * sizeof(u64));
482 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
488 /* Only the condition codes and the "in syscall"
489 * state can be modified in the %tstate register.
491 tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
492 regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
493 regs->tstate |= tstate;
496 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
503 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
512 static const struct user_regset ptrace64_regsets[] = {
517 * TSTATE, TPC, TNPC, Y
520 .n = 20, .size = sizeof(u64),
521 .regset_get = getregs64_get, .set = setregs64_set,
525 static const struct user_regset_view ptrace64_view = {
526 .regsets = ptrace64_regsets, .n = ARRAY_SIZE(ptrace64_regsets)
529 static const struct user_regset_view user_sparc64_view = {
530 .name = "sparc64", .e_machine = EM_SPARCV9,
531 .regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
535 static int genregs32_get(struct task_struct *target,
536 const struct user_regset *regset,
539 const struct pt_regs *regs = task_pt_regs(target);
543 if (target == current)
546 for (i = 0; i < 16; i++)
547 membuf_store(&to, (u32)regs->u_regs[i]);
550 if (get_from_target(target, regs->u_regs[UREG_I6],
551 uregs, sizeof(uregs)))
553 membuf_write(&to, uregs, 16 * sizeof(u32));
554 membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
555 membuf_store(&to, (u32)(regs->tpc));
556 membuf_store(&to, (u32)(regs->tnpc));
557 membuf_store(&to, (u32)(regs->y));
558 return membuf_zero(&to, 2 * sizeof(u32));
561 static int genregs32_set(struct task_struct *target,
562 const struct user_regset *regset,
563 unsigned int pos, unsigned int count,
564 const void *kbuf, const void __user *ubuf)
566 struct pt_regs *regs = task_pt_regs(target);
567 compat_ulong_t __user *reg_window;
568 const compat_ulong_t *k = kbuf;
569 const compat_ulong_t __user *u = ubuf;
572 if (target == current)
576 count /= sizeof(reg);
579 for (; count > 0 && pos < 16; count--)
580 regs->u_regs[pos++] = *k++;
582 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
584 if (target == current) {
585 for (; count > 0 && pos < 32; count--) {
586 if (put_user(*k++, ®_window[pos++]))
590 for (; count > 0 && pos < 32; count--) {
591 if (access_process_vm(target,
596 FOLL_FORCE | FOLL_WRITE)
604 for (; count > 0 && pos < 16; count--) {
605 if (get_user(reg, u++))
607 regs->u_regs[pos++] = reg;
610 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
612 if (target == current) {
613 for (; count > 0 && pos < 32; count--) {
614 if (get_user(reg, u++) ||
615 put_user(reg, ®_window[pos++]))
619 for (; count > 0 && pos < 32; count--) {
620 if (get_user(reg, u++))
622 if (access_process_vm(target,
626 FOLL_FORCE | FOLL_WRITE)
635 unsigned long tstate;
639 else if (get_user(reg, u++))
644 tstate = regs->tstate;
645 tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
646 tstate |= psr_to_tstate_icc(reg);
647 if (reg & PSR_SYSCALL)
648 tstate |= TSTATE_SYSCALL;
649 regs->tstate = tstate;
672 count *= sizeof(reg);
674 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
675 38 * sizeof(reg), -1);
678 static int fpregs32_get(struct task_struct *target,
679 const struct user_regset *regset,
682 struct thread_info *t = task_thread_info(target);
685 if (target == current)
686 save_and_clear_fpu();
688 enabled = t->fpsaved[0] & FPRS_FEF;
690 membuf_write(&to, t->fpregs, 32 * sizeof(u32));
691 membuf_zero(&to, sizeof(u32));
693 membuf_store(&to, (u32)t->xfsr[0]);
695 membuf_zero(&to, sizeof(u32));
696 membuf_store(&to, (u32)((enabled << 8) | (8 << 16)));
697 return membuf_zero(&to, 64 * sizeof(u32));
700 static int fpregs32_set(struct task_struct *target,
701 const struct user_regset *regset,
702 unsigned int pos, unsigned int count,
703 const void *kbuf, const void __user *ubuf)
705 unsigned long *fpregs = task_thread_info(target)->fpregs;
709 if (target == current)
710 save_and_clear_fpu();
712 fprs = task_thread_info(target)->fpsaved[0];
714 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
716 0, 32 * sizeof(u32));
718 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
721 if (!ret && count > 0) {
725 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
730 val = task_thread_info(target)->xfsr[0];
731 val &= 0xffffffff00000000UL;
733 task_thread_info(target)->xfsr[0] = val;
737 fprs |= (FPRS_FEF | FPRS_DL);
738 task_thread_info(target)->fpsaved[0] = fprs;
741 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
742 34 * sizeof(u32), -1);
746 static const struct user_regset sparc32_regsets[] = {
752 * PSR, PC, nPC, Y, WIM, TBR
755 .core_note_type = NT_PRSTATUS,
757 .size = sizeof(u32), .align = sizeof(u32),
758 .regset_get = genregs32_get, .set = genregs32_set
764 * FPU QUEUE COUNT (8-bit char)
765 * FPU QUEUE ENTRYSIZE (8-bit char)
766 * FPU ENABLED (8-bit char)
768 * FPU QUEUE (64 32-bit ints)
771 .core_note_type = NT_PRFPREG,
773 .size = sizeof(u32), .align = sizeof(u32),
774 .regset_get = fpregs32_get, .set = fpregs32_set
778 static int getregs_get(struct task_struct *target,
779 const struct user_regset *regset,
782 const struct pt_regs *regs = task_pt_regs(target);
785 if (target == current)
788 membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
789 membuf_store(&to, (u32)(regs->tpc));
790 membuf_store(&to, (u32)(regs->tnpc));
791 membuf_store(&to, (u32)(regs->y));
792 for (i = 1; i < 16; i++)
793 membuf_store(&to, (u32)regs->u_regs[i]);
797 static int setregs_set(struct task_struct *target,
798 const struct user_regset *regset,
799 unsigned int pos, unsigned int count,
800 const void *kbuf, const void __user *ubuf)
802 struct pt_regs *regs = task_pt_regs(target);
803 unsigned long tstate;
807 if (target == current)
810 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
812 0, 19 * sizeof(u32));
816 tstate = regs->tstate;
817 tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
818 tstate |= psr_to_tstate_icc(uregs[0]);
819 if (uregs[0] & PSR_SYSCALL)
820 tstate |= TSTATE_SYSCALL;
821 regs->tstate = tstate;
822 regs->tpc = uregs[1];
823 regs->tnpc = uregs[2];
826 for (i = 1; i < 15; i++)
827 regs->u_regs[i] = uregs[3 + i];
831 static int getfpregs_get(struct task_struct *target,
832 const struct user_regset *regset,
835 struct thread_info *t = task_thread_info(target);
837 if (target == current)
838 save_and_clear_fpu();
840 membuf_write(&to, t->fpregs, 32 * sizeof(u32));
841 if (t->fpsaved[0] & FPRS_FEF)
842 membuf_store(&to, (u32)t->xfsr[0]);
844 membuf_zero(&to, sizeof(u32));
845 return membuf_zero(&to, 35 * sizeof(u32));
848 static int setfpregs_set(struct task_struct *target,
849 const struct user_regset *regset,
850 unsigned int pos, unsigned int count,
851 const void *kbuf, const void __user *ubuf)
853 unsigned long *fpregs = task_thread_info(target)->fpregs;
857 if (target == current)
858 save_and_clear_fpu();
860 fprs = task_thread_info(target)->fpsaved[0];
862 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
864 0, 32 * sizeof(u32));
869 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
874 val = task_thread_info(target)->xfsr[0];
875 val &= 0xffffffff00000000UL;
877 task_thread_info(target)->xfsr[0] = val;
881 fprs |= (FPRS_FEF | FPRS_DL);
882 task_thread_info(target)->fpsaved[0] = fprs;
886 static const struct user_regset ptrace32_regsets[] = {
888 .n = 19, .size = sizeof(u32),
889 .regset_get = getregs_get, .set = setregs_set,
892 .n = 68, .size = sizeof(u32),
893 .regset_get = getfpregs_get, .set = setfpregs_set,
897 static const struct user_regset_view ptrace32_view = {
898 .regsets = ptrace32_regsets, .n = ARRAY_SIZE(ptrace32_regsets)
901 static const struct user_regset_view user_sparc32_view = {
902 .name = "sparc", .e_machine = EM_SPARC,
903 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
905 #endif /* CONFIG_COMPAT */
907 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
910 if (test_tsk_thread_flag(task, TIF_32BIT))
911 return &user_sparc32_view;
913 return &user_sparc64_view;
918 unsigned int regs[32];
924 unsigned int insnaddr;
929 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
930 compat_ulong_t caddr, compat_ulong_t cdata)
932 compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
933 struct pt_regs32 __user *pregs;
934 struct compat_fps __user *fps;
935 unsigned long addr2 = caddr2;
936 unsigned long addr = caddr;
937 unsigned long data = cdata;
940 pregs = (struct pt_regs32 __user *) addr;
941 fps = (struct compat_fps __user *) addr;
945 ret = (addr != 0) ? -EIO : 0;
949 ret = copy_regset_to_user(child, &ptrace32_view,
956 ret = copy_regset_from_user(child, &ptrace32_view,
962 case PTRACE_GETFPREGS:
963 ret = copy_regset_to_user(child, &ptrace32_view,
969 case PTRACE_SETFPREGS:
970 ret = copy_regset_from_user(child, &ptrace32_view,
976 case PTRACE_READTEXT:
977 case PTRACE_READDATA:
978 ret = ptrace_readdata(child, addr,
979 (char __user *)addr2, data);
986 case PTRACE_WRITETEXT:
987 case PTRACE_WRITEDATA:
988 ret = ptrace_writedata(child, (char __user *) addr2,
997 if (request == PTRACE_SPARC_DETACH)
998 request = PTRACE_DETACH;
999 ret = compat_ptrace_request(child, request, addr, data);
1005 #endif /* CONFIG_COMPAT */
1008 unsigned int regs[64];
1012 long arch_ptrace(struct task_struct *child, long request,
1013 unsigned long addr, unsigned long data)
1015 const struct user_regset_view *view = task_user_regset_view(current);
1016 unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
1017 struct pt_regs __user *pregs;
1018 struct fps __user *fps;
1019 void __user *addr2p;
1022 pregs = (struct pt_regs __user *) addr;
1023 fps = (struct fps __user *) addr;
1024 addr2p = (void __user *) addr2;
1027 case PTRACE_PEEKUSR:
1028 ret = (addr != 0) ? -EIO : 0;
1031 case PTRACE_GETREGS64:
1032 ret = copy_regset_to_user(child, &ptrace64_view,
1038 case PTRACE_SETREGS64:
1039 ret = copy_regset_from_user(child, &ptrace64_view,
1045 case PTRACE_GETFPREGS64:
1046 ret = copy_regset_to_user(child, view, REGSET_FP,
1052 case PTRACE_SETFPREGS64:
1053 ret = copy_regset_from_user(child, view, REGSET_FP,
1059 case PTRACE_READTEXT:
1060 case PTRACE_READDATA:
1061 ret = ptrace_readdata(child, addr, addr2p, data);
1068 case PTRACE_WRITETEXT:
1069 case PTRACE_WRITEDATA:
1070 ret = ptrace_writedata(child, addr2p, addr, data);
1078 if (request == PTRACE_SPARC_DETACH)
1079 request = PTRACE_DETACH;
1080 ret = ptrace_request(child, request, addr, data);
1087 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1091 /* do the secure computing check first */
1092 secure_computing_strict(regs->u_regs[UREG_G1]);
1094 if (test_thread_flag(TIF_NOHZ))
1097 if (test_thread_flag(TIF_SYSCALL_TRACE))
1098 ret = tracehook_report_syscall_entry(regs);
1100 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1101 trace_sys_enter(regs, regs->u_regs[UREG_G1]);
1103 audit_syscall_entry(regs->u_regs[UREG_G1], regs->u_regs[UREG_I0],
1104 regs->u_regs[UREG_I1], regs->u_regs[UREG_I2],
1105 regs->u_regs[UREG_I3]);
1110 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
1112 if (test_thread_flag(TIF_NOHZ))
1115 audit_syscall_exit(regs);
1117 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1118 trace_sys_exit(regs, regs->u_regs[UREG_I0]);
1120 if (test_thread_flag(TIF_SYSCALL_TRACE))
1121 tracehook_report_syscall_exit(regs, 0);
1123 if (test_thread_flag(TIF_NOHZ))
1128 * regs_query_register_offset() - query register offset from its name
1129 * @name: the name of a register
1131 * regs_query_register_offset() returns the offset of a register in struct
1132 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
1134 int regs_query_register_offset(const char *name)
1136 const struct pt_regs_offset *roff;
1138 for (roff = regoffset_table; roff->name != NULL; roff++)
1139 if (!strcmp(roff->name, name))
1140 return roff->offset;
1145 * regs_within_kernel_stack() - check the address in the stack
1146 * @regs: pt_regs which contains kernel stack pointer.
1147 * @addr: address which is checked.
1149 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
1150 * If @addr is within the kernel stack, it returns true. If not, returns false.
1152 static inline int regs_within_kernel_stack(struct pt_regs *regs,
1155 unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1156 return ((addr & ~(THREAD_SIZE - 1)) ==
1157 (ksp & ~(THREAD_SIZE - 1)));
1161 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1162 * @regs: pt_regs which contains kernel stack pointer.
1163 * @n: stack entry number.
1165 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1166 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
1169 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1171 unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1172 unsigned long *addr = (unsigned long *)ksp;
1174 if (regs_within_kernel_stack(regs, (unsigned long)addr))