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 <trace/syscall.h>
29 #include <linux/compat.h>
30 #include <linux/elf.h>
31 #include <linux/context_tracking.h>
34 #include <linux/uaccess.h>
35 #include <asm/psrcompat.h>
36 #include <asm/visasm.h>
37 #include <asm/spitfire.h>
39 #include <asm/cpudata.h>
40 #include <asm/cacheflush.h>
42 #define CREATE_TRACE_POINTS
43 #include <trace/events/syscalls.h>
47 /* #define ALLOW_INIT_TRACING */
49 struct pt_regs_offset {
54 #define REG_OFFSET_NAME(n, r) \
55 {.name = n, .offset = (PT_V9_##r)}
56 #define REG_OFFSET_END {.name = NULL, .offset = 0}
58 static const struct pt_regs_offset regoffset_table[] = {
59 REG_OFFSET_NAME("g0", G0),
60 REG_OFFSET_NAME("g1", G1),
61 REG_OFFSET_NAME("g2", G2),
62 REG_OFFSET_NAME("g3", G3),
63 REG_OFFSET_NAME("g4", G4),
64 REG_OFFSET_NAME("g5", G5),
65 REG_OFFSET_NAME("g6", G6),
66 REG_OFFSET_NAME("g7", G7),
68 REG_OFFSET_NAME("i0", I0),
69 REG_OFFSET_NAME("i1", I1),
70 REG_OFFSET_NAME("i2", I2),
71 REG_OFFSET_NAME("i3", I3),
72 REG_OFFSET_NAME("i4", I4),
73 REG_OFFSET_NAME("i5", I5),
74 REG_OFFSET_NAME("i6", I6),
75 REG_OFFSET_NAME("i7", I7),
77 REG_OFFSET_NAME("tstate", TSTATE),
78 REG_OFFSET_NAME("pc", TPC),
79 REG_OFFSET_NAME("npc", TNPC),
80 REG_OFFSET_NAME("y", Y),
81 REG_OFFSET_NAME("lr", I7),
87 * Called by kernel/ptrace.c when detaching..
89 * Make sure single step bits etc are not set.
91 void ptrace_disable(struct task_struct *child)
96 /* To get the necessary page struct, access_process_vm() first calls
97 * get_user_pages(). This has done a flush_dcache_page() on the
98 * accessed page. Then our caller (copy_{to,from}_user_page()) did
99 * to memcpy to read/write the data from that page.
101 * Now, the only thing we have to do is:
102 * 1) flush the D-cache if it's possible than an illegal alias
104 * 2) flush the I-cache if this is pre-cheetah and we did a write
106 void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
107 unsigned long uaddr, void *kaddr,
108 unsigned long len, int write)
110 BUG_ON(len > PAGE_SIZE);
112 if (tlb_type == hypervisor)
117 #ifdef DCACHE_ALIASING_POSSIBLE
118 /* If bit 13 of the kernel address we used to access the
119 * user page is the same as the virtual address that page
120 * is mapped to in the user's address space, we can skip the
123 if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
124 unsigned long start = __pa(kaddr);
125 unsigned long end = start + len;
126 unsigned long dcache_line_size;
128 dcache_line_size = local_cpu_data().dcache_line_size;
130 if (tlb_type == spitfire) {
131 for (; start < end; start += dcache_line_size)
132 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
134 start &= ~(dcache_line_size - 1);
135 for (; start < end; start += dcache_line_size)
136 __asm__ __volatile__(
137 "stxa %%g0, [%0] %1\n\t"
141 "i" (ASI_DCACHE_INVALIDATE));
145 if (write && tlb_type == spitfire) {
146 unsigned long start = (unsigned long) kaddr;
147 unsigned long end = start + len;
148 unsigned long icache_line_size;
150 icache_line_size = local_cpu_data().icache_line_size;
152 for (; start < end; start += icache_line_size)
158 EXPORT_SYMBOL_GPL(flush_ptrace_access);
160 static int get_from_target(struct task_struct *target, unsigned long uaddr,
163 if (target == current) {
164 if (copy_from_user(kbuf, (void __user *) uaddr, len))
167 int len2 = access_process_vm(target, uaddr, kbuf, len,
175 static int set_to_target(struct task_struct *target, unsigned long uaddr,
178 if (target == current) {
179 if (copy_to_user((void __user *) uaddr, kbuf, len))
182 int len2 = access_process_vm(target, uaddr, kbuf, len,
183 FOLL_FORCE | FOLL_WRITE);
190 static int regwindow64_get(struct task_struct *target,
191 const struct pt_regs *regs,
192 struct reg_window *wbuf)
194 unsigned long rw_addr = regs->u_regs[UREG_I6];
196 if (!test_thread_64bit_stack(rw_addr)) {
197 struct reg_window32 win32;
200 if (get_from_target(target, rw_addr, &win32, sizeof(win32)))
202 for (i = 0; i < 8; i++)
203 wbuf->locals[i] = win32.locals[i];
204 for (i = 0; i < 8; i++)
205 wbuf->ins[i] = win32.ins[i];
207 rw_addr += STACK_BIAS;
208 if (get_from_target(target, rw_addr, wbuf, sizeof(*wbuf)))
215 static int regwindow64_set(struct task_struct *target,
216 const struct pt_regs *regs,
217 struct reg_window *wbuf)
219 unsigned long rw_addr = regs->u_regs[UREG_I6];
221 if (!test_thread_64bit_stack(rw_addr)) {
222 struct reg_window32 win32;
225 for (i = 0; i < 8; i++)
226 win32.locals[i] = wbuf->locals[i];
227 for (i = 0; i < 8; i++)
228 win32.ins[i] = wbuf->ins[i];
230 if (set_to_target(target, rw_addr, &win32, sizeof(win32)))
233 rw_addr += STACK_BIAS;
234 if (set_to_target(target, rw_addr, wbuf, sizeof(*wbuf)))
246 static int genregs64_get(struct task_struct *target,
247 const struct user_regset *regset,
250 const struct pt_regs *regs = task_pt_regs(target);
251 struct reg_window window;
253 if (target == current)
256 membuf_write(&to, regs->u_regs, 16 * sizeof(u64));
259 if (regwindow64_get(target, regs, &window))
261 membuf_write(&to, &window, 16 * sizeof(u64));
262 /* TSTATE, TPC, TNPC */
263 membuf_write(&to, ®s->tstate, 3 * sizeof(u64));
264 return membuf_store(&to, (u64)regs->y);
267 static int genregs64_set(struct task_struct *target,
268 const struct user_regset *regset,
269 unsigned int pos, unsigned int count,
270 const void *kbuf, const void __user *ubuf)
272 struct pt_regs *regs = task_pt_regs(target);
275 if (target == current)
278 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
280 0, 16 * sizeof(u64));
281 if (!ret && count && pos < (32 * sizeof(u64))) {
282 struct reg_window window;
284 if (regwindow64_get(target, regs, &window))
287 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
293 regwindow64_set(target, regs, &window))
297 if (!ret && count > 0) {
298 unsigned long tstate;
301 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
306 /* Only the condition codes and the "in syscall"
307 * state can be modified in the %tstate register.
309 tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
310 regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
311 regs->tstate |= tstate;
317 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
324 unsigned long y = regs->y;
326 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
335 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
336 36 * sizeof(u64), -1);
341 static int fpregs64_get(struct task_struct *target,
342 const struct user_regset *regset,
345 struct thread_info *t = task_thread_info(target);
348 if (target == current)
349 save_and_clear_fpu();
351 fprs = t->fpsaved[0];
354 membuf_write(&to, t->fpregs, 16 * sizeof(u64));
356 membuf_zero(&to, 16 * sizeof(u64));
359 membuf_write(&to, t->fpregs + 16, 16 * sizeof(u64));
361 membuf_zero(&to, 16 * sizeof(u64));
362 if (fprs & FPRS_FEF) {
363 membuf_store(&to, t->xfsr[0]);
364 membuf_store(&to, t->gsr[0]);
366 membuf_zero(&to, 2 * sizeof(u64));
368 return membuf_store(&to, fprs);
371 static int fpregs64_set(struct task_struct *target,
372 const struct user_regset *regset,
373 unsigned int pos, unsigned int count,
374 const void *kbuf, const void __user *ubuf)
376 unsigned long *fpregs = task_thread_info(target)->fpregs;
380 if (target == current)
381 save_and_clear_fpu();
383 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
385 0, 32 * sizeof(u64));
387 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
388 task_thread_info(target)->xfsr,
392 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
393 task_thread_info(target)->gsr,
397 fprs = task_thread_info(target)->fpsaved[0];
398 if (!ret && count > 0) {
399 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
405 fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
406 task_thread_info(target)->fpsaved[0] = fprs;
409 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
410 35 * sizeof(u64), -1);
414 static const struct user_regset sparc64_regsets[] = {
420 * TSTATE, TPC, TNPC, Y
423 .core_note_type = NT_PRSTATUS,
425 .size = sizeof(u64), .align = sizeof(u64),
426 .regset_get = genregs64_get, .set = genregs64_set
435 .core_note_type = NT_PRFPREG,
437 .size = sizeof(u64), .align = sizeof(u64),
438 .regset_get = fpregs64_get, .set = fpregs64_set
442 static int getregs64_get(struct task_struct *target,
443 const struct user_regset *regset,
446 const struct pt_regs *regs = task_pt_regs(target);
448 if (target == current)
451 membuf_write(&to, regs->u_regs + 1, 15 * sizeof(u64));
452 membuf_store(&to, (u64)0);
453 membuf_write(&to, ®s->tstate, 3 * sizeof(u64));
454 return membuf_store(&to, (u64)regs->y);
457 static int setregs64_set(struct task_struct *target,
458 const struct user_regset *regset,
459 unsigned int pos, unsigned int count,
460 const void *kbuf, const void __user *ubuf)
462 struct pt_regs *regs = task_pt_regs(target);
463 unsigned long y = regs->y;
464 unsigned long tstate;
467 if (target == current)
470 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
476 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
477 15 * sizeof(u64), 16 * sizeof(u64));
479 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
485 /* Only the condition codes and the "in syscall"
486 * state can be modified in the %tstate register.
488 tstate &= (TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
489 regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
490 regs->tstate |= tstate;
493 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
500 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
509 static const struct user_regset ptrace64_regsets[] = {
514 * TSTATE, TPC, TNPC, Y
517 .n = 20, .size = sizeof(u64),
518 .regset_get = getregs64_get, .set = setregs64_set,
522 static const struct user_regset_view ptrace64_view = {
523 .regsets = ptrace64_regsets, .n = ARRAY_SIZE(ptrace64_regsets)
526 static const struct user_regset_view user_sparc64_view = {
527 .name = "sparc64", .e_machine = EM_SPARCV9,
528 .regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
532 static int genregs32_get(struct task_struct *target,
533 const struct user_regset *regset,
536 const struct pt_regs *regs = task_pt_regs(target);
540 if (target == current)
543 for (i = 0; i < 16; i++)
544 membuf_store(&to, (u32)regs->u_regs[i]);
547 if (get_from_target(target, regs->u_regs[UREG_I6],
548 uregs, sizeof(uregs)))
550 membuf_write(&to, uregs, 16 * sizeof(u32));
551 membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
552 membuf_store(&to, (u32)(regs->tpc));
553 membuf_store(&to, (u32)(regs->tnpc));
554 membuf_store(&to, (u32)(regs->y));
555 return membuf_zero(&to, 2 * sizeof(u32));
558 static int genregs32_set(struct task_struct *target,
559 const struct user_regset *regset,
560 unsigned int pos, unsigned int count,
561 const void *kbuf, const void __user *ubuf)
563 struct pt_regs *regs = task_pt_regs(target);
564 compat_ulong_t __user *reg_window;
565 const compat_ulong_t *k = kbuf;
566 const compat_ulong_t __user *u = ubuf;
569 if (target == current)
573 count /= sizeof(reg);
576 for (; count > 0 && pos < 16; count--)
577 regs->u_regs[pos++] = *k++;
579 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
581 if (target == current) {
582 for (; count > 0 && pos < 32; count--) {
583 if (put_user(*k++, ®_window[pos++]))
587 for (; count > 0 && pos < 32; count--) {
588 if (access_process_vm(target,
593 FOLL_FORCE | FOLL_WRITE)
601 for (; count > 0 && pos < 16; count--) {
602 if (get_user(reg, u++))
604 regs->u_regs[pos++] = reg;
607 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
609 if (target == current) {
610 for (; count > 0 && pos < 32; count--) {
611 if (get_user(reg, u++) ||
612 put_user(reg, ®_window[pos++]))
616 for (; count > 0 && pos < 32; count--) {
617 if (get_user(reg, u++))
619 if (access_process_vm(target,
623 FOLL_FORCE | FOLL_WRITE)
632 unsigned long tstate;
636 else if (get_user(reg, u++))
641 tstate = regs->tstate;
642 tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
643 tstate |= psr_to_tstate_icc(reg);
644 if (reg & PSR_SYSCALL)
645 tstate |= TSTATE_SYSCALL;
646 regs->tstate = tstate;
669 count *= sizeof(reg);
671 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
672 38 * sizeof(reg), -1);
676 static int fpregs32_get(struct task_struct *target,
677 const struct user_regset *regset,
680 struct thread_info *t = task_thread_info(target);
683 if (target == current)
684 save_and_clear_fpu();
686 enabled = t->fpsaved[0] & FPRS_FEF;
688 membuf_write(&to, t->fpregs, 32 * sizeof(u32));
689 membuf_zero(&to, sizeof(u32));
691 membuf_store(&to, (u32)t->xfsr[0]);
693 membuf_zero(&to, sizeof(u32));
694 membuf_store(&to, (u32)((enabled << 8) | (8 << 16)));
695 return membuf_zero(&to, 64 * sizeof(u32));
698 static int fpregs32_set(struct task_struct *target,
699 const struct user_regset *regset,
700 unsigned int pos, unsigned int count,
701 const void *kbuf, const void __user *ubuf)
703 unsigned long *fpregs = task_thread_info(target)->fpregs;
707 if (target == current)
708 save_and_clear_fpu();
710 fprs = task_thread_info(target)->fpsaved[0];
712 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
714 0, 32 * sizeof(u32));
716 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
719 if (!ret && count > 0) {
723 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
728 val = task_thread_info(target)->xfsr[0];
729 val &= 0xffffffff00000000UL;
731 task_thread_info(target)->xfsr[0] = val;
735 fprs |= (FPRS_FEF | FPRS_DL);
736 task_thread_info(target)->fpsaved[0] = fprs;
739 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
740 34 * sizeof(u32), -1);
744 static const struct user_regset sparc32_regsets[] = {
750 * PSR, PC, nPC, Y, WIM, TBR
753 .core_note_type = NT_PRSTATUS,
755 .size = sizeof(u32), .align = sizeof(u32),
756 .regset_get = genregs32_get, .set = genregs32_set
762 * FPU QUEUE COUNT (8-bit char)
763 * FPU QUEUE ENTRYSIZE (8-bit char)
764 * FPU ENABLED (8-bit char)
766 * FPU QUEUE (64 32-bit ints)
769 .core_note_type = NT_PRFPREG,
771 .size = sizeof(u32), .align = sizeof(u32),
772 .regset_get = fpregs32_get, .set = fpregs32_set
776 static int getregs_get(struct task_struct *target,
777 const struct user_regset *regset,
780 const struct pt_regs *regs = task_pt_regs(target);
783 if (target == current)
786 membuf_store(&to, (u32)tstate_to_psr(regs->tstate));
787 membuf_store(&to, (u32)(regs->tpc));
788 membuf_store(&to, (u32)(regs->tnpc));
789 membuf_store(&to, (u32)(regs->y));
790 for (i = 1; i < 16; i++)
791 membuf_store(&to, (u32)regs->u_regs[i]);
795 static int setregs_set(struct task_struct *target,
796 const struct user_regset *regset,
797 unsigned int pos, unsigned int count,
798 const void *kbuf, const void __user *ubuf)
800 struct pt_regs *regs = task_pt_regs(target);
801 unsigned long tstate;
805 if (target == current)
808 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
810 0, 19 * sizeof(u32));
814 tstate = regs->tstate;
815 tstate &= ~(TSTATE_ICC | TSTATE_XCC | TSTATE_SYSCALL);
816 tstate |= psr_to_tstate_icc(uregs[0]);
817 if (uregs[0] & PSR_SYSCALL)
818 tstate |= TSTATE_SYSCALL;
819 regs->tstate = tstate;
820 regs->tpc = uregs[1];
821 regs->tnpc = uregs[2];
824 for (i = 1; i < 15; i++)
825 regs->u_regs[i] = uregs[3 + i];
829 static int getfpregs_get(struct task_struct *target,
830 const struct user_regset *regset,
833 struct thread_info *t = task_thread_info(target);
835 if (target == current)
836 save_and_clear_fpu();
838 membuf_write(&to, t->fpregs, 32 * sizeof(u32));
839 if (t->fpsaved[0] & FPRS_FEF)
840 membuf_store(&to, (u32)t->xfsr[0]);
842 membuf_zero(&to, sizeof(u32));
843 return membuf_zero(&to, 35 * sizeof(u32));
846 static int setfpregs_set(struct task_struct *target,
847 const struct user_regset *regset,
848 unsigned int pos, unsigned int count,
849 const void *kbuf, const void __user *ubuf)
851 unsigned long *fpregs = task_thread_info(target)->fpregs;
855 if (target == current)
856 save_and_clear_fpu();
858 fprs = task_thread_info(target)->fpsaved[0];
860 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
862 0, 32 * sizeof(u32));
867 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
872 val = task_thread_info(target)->xfsr[0];
873 val &= 0xffffffff00000000UL;
875 task_thread_info(target)->xfsr[0] = val;
879 fprs |= (FPRS_FEF | FPRS_DL);
880 task_thread_info(target)->fpsaved[0] = fprs;
884 static const struct user_regset ptrace32_regsets[] = {
886 .n = 19, .size = sizeof(u32),
887 .regset_get = getregs_get, .set = setregs_set,
890 .n = 68, .size = sizeof(u32),
891 .regset_get = getfpregs_get, .set = setfpregs_set,
895 static const struct user_regset_view ptrace32_view = {
896 .regsets = ptrace32_regsets, .n = ARRAY_SIZE(ptrace32_regsets)
899 static const struct user_regset_view user_sparc32_view = {
900 .name = "sparc", .e_machine = EM_SPARC,
901 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
903 #endif /* CONFIG_COMPAT */
905 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
908 if (test_tsk_thread_flag(task, TIF_32BIT))
909 return &user_sparc32_view;
911 return &user_sparc64_view;
916 unsigned int regs[32];
922 unsigned int insnaddr;
927 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
928 compat_ulong_t caddr, compat_ulong_t cdata)
930 compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
931 struct pt_regs32 __user *pregs;
932 struct compat_fps __user *fps;
933 unsigned long addr2 = caddr2;
934 unsigned long addr = caddr;
935 unsigned long data = cdata;
938 pregs = (struct pt_regs32 __user *) addr;
939 fps = (struct compat_fps __user *) addr;
943 ret = (addr != 0) ? -EIO : 0;
947 ret = copy_regset_to_user(child, &ptrace32_view,
954 ret = copy_regset_from_user(child, &ptrace32_view,
960 case PTRACE_GETFPREGS:
961 ret = copy_regset_to_user(child, &ptrace32_view,
967 case PTRACE_SETFPREGS:
968 ret = copy_regset_from_user(child, &ptrace32_view,
974 case PTRACE_READTEXT:
975 case PTRACE_READDATA:
976 ret = ptrace_readdata(child, addr,
977 (char __user *)addr2, data);
984 case PTRACE_WRITETEXT:
985 case PTRACE_WRITEDATA:
986 ret = ptrace_writedata(child, (char __user *) addr2,
995 if (request == PTRACE_SPARC_DETACH)
996 request = PTRACE_DETACH;
997 ret = compat_ptrace_request(child, request, addr, data);
1003 #endif /* CONFIG_COMPAT */
1006 unsigned int regs[64];
1010 long arch_ptrace(struct task_struct *child, long request,
1011 unsigned long addr, unsigned long data)
1013 const struct user_regset_view *view = task_user_regset_view(current);
1014 unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
1015 struct pt_regs __user *pregs;
1016 struct fps __user *fps;
1017 void __user *addr2p;
1020 pregs = (struct pt_regs __user *) addr;
1021 fps = (struct fps __user *) addr;
1022 addr2p = (void __user *) addr2;
1025 case PTRACE_PEEKUSR:
1026 ret = (addr != 0) ? -EIO : 0;
1029 case PTRACE_GETREGS64:
1030 ret = copy_regset_to_user(child, &ptrace64_view,
1036 case PTRACE_SETREGS64:
1037 ret = copy_regset_from_user(child, &ptrace64_view,
1043 case PTRACE_GETFPREGS64:
1044 ret = copy_regset_to_user(child, view, REGSET_FP,
1050 case PTRACE_SETFPREGS64:
1051 ret = copy_regset_from_user(child, view, REGSET_FP,
1057 case PTRACE_READTEXT:
1058 case PTRACE_READDATA:
1059 ret = ptrace_readdata(child, addr, addr2p, data);
1066 case PTRACE_WRITETEXT:
1067 case PTRACE_WRITEDATA:
1068 ret = ptrace_writedata(child, addr2p, addr, data);
1076 if (request == PTRACE_SPARC_DETACH)
1077 request = PTRACE_DETACH;
1078 ret = ptrace_request(child, request, addr, data);
1085 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1089 /* do the secure computing check first */
1090 secure_computing_strict(regs->u_regs[UREG_G1]);
1092 if (test_thread_flag(TIF_NOHZ))
1095 if (test_thread_flag(TIF_SYSCALL_TRACE))
1096 ret = ptrace_report_syscall_entry(regs);
1098 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1099 trace_sys_enter(regs, regs->u_regs[UREG_G1]);
1101 audit_syscall_entry(regs->u_regs[UREG_G1], regs->u_regs[UREG_I0],
1102 regs->u_regs[UREG_I1], regs->u_regs[UREG_I2],
1103 regs->u_regs[UREG_I3]);
1108 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
1110 if (test_thread_flag(TIF_NOHZ))
1113 audit_syscall_exit(regs);
1115 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1116 trace_sys_exit(regs, regs->u_regs[UREG_I0]);
1118 if (test_thread_flag(TIF_SYSCALL_TRACE))
1119 ptrace_report_syscall_exit(regs, 0);
1121 if (test_thread_flag(TIF_NOHZ))
1126 * regs_query_register_offset() - query register offset from its name
1127 * @name: the name of a register
1129 * regs_query_register_offset() returns the offset of a register in struct
1130 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
1132 int regs_query_register_offset(const char *name)
1134 const struct pt_regs_offset *roff;
1136 for (roff = regoffset_table; roff->name != NULL; roff++)
1137 if (!strcmp(roff->name, name))
1138 return roff->offset;
1143 * regs_within_kernel_stack() - check the address in the stack
1144 * @regs: pt_regs which contains kernel stack pointer.
1145 * @addr: address which is checked.
1147 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
1148 * If @addr is within the kernel stack, it returns true. If not, returns false.
1150 static inline int regs_within_kernel_stack(struct pt_regs *regs,
1153 unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1154 return ((addr & ~(THREAD_SIZE - 1)) ==
1155 (ksp & ~(THREAD_SIZE - 1)));
1159 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1160 * @regs: pt_regs which contains kernel stack pointer.
1161 * @n: stack entry number.
1163 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1164 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
1167 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1169 unsigned long ksp = kernel_stack_pointer(regs) + STACK_BIAS;
1170 unsigned long *addr = (unsigned long *)ksp;
1172 if (regs_within_kernel_stack(regs, (unsigned long)addr))