13 #include <linux/kernel.h>
14 #include <linux/sched.h>
16 #include <linux/errno.h>
17 #include <linux/ptrace.h>
21 #include <linux/seccomp.h>
22 #include <linux/audit.h>
23 #include <linux/signal.h>
28 #include <linux/elf.h>
31 #include <asm/pgtable.h>
32 #include <asm/uaccess.h>
38 #include <asm/cacheflush.h>
40 #define CREATE_TRACE_POINTS
68 unsigned long uaddr,
void *kaddr,
69 unsigned long len,
int write)
78 #ifdef DCACHE_ALIASING_POSSIBLE
84 if ((uaddr ^ (
unsigned long) kaddr) & (1
UL << 13)) {
86 unsigned long end = start + len;
87 unsigned long dcache_line_size;
92 for (; start <
end; start += dcache_line_size)
93 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
95 start &= ~(dcache_line_size - 1);
96 for (; start <
end; start += dcache_line_size)
98 "stxa %%g0, [%0] %1\n\t"
106 if (write &&
tlb_type == spitfire) {
107 unsigned long start = (
unsigned long) kaddr;
108 unsigned long end = start + len;
109 unsigned long icache_line_size;
113 for (; start <
end; start += icache_line_size)
134 static int set_to_target(
struct task_struct *target,
unsigned long uaddr,
148 static int regwindow64_get(
struct task_struct *target,
150 struct reg_window *wbuf)
154 if (!test_thread_64bit_stack(rw_addr)) {
158 if (get_from_target(target, rw_addr, &win32,
sizeof(win32)))
160 for (i = 0; i < 8; i++)
161 wbuf->locals[i] = win32.locals[i];
162 for (i = 0; i < 8; i++)
163 wbuf->ins[i] = win32.ins[i];
166 if (get_from_target(target, rw_addr, wbuf,
sizeof(*wbuf)))
173 static int regwindow64_set(
struct task_struct *target,
175 struct reg_window *wbuf)
179 if (!test_thread_64bit_stack(rw_addr)) {
183 for (i = 0; i < 8; i++)
184 win32.locals[i] = wbuf->locals[i];
185 for (i = 0; i < 8; i++)
186 win32.ins[i] = wbuf->ins[i];
188 if (set_to_target(target, rw_addr, &win32,
sizeof(win32)))
192 if (set_to_target(target, rw_addr, wbuf,
sizeof(*wbuf)))
204 static int genregs64_get(
struct task_struct *target,
206 unsigned int pos,
unsigned int count,
207 void *kbuf,
void __user *ubuf)
215 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
217 0, 16 *
sizeof(
u64));
218 if (!ret && count && pos < (32 *
sizeof(
u64))) {
219 struct reg_window window;
221 if (regwindow64_get(target, regs, &window))
223 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
231 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
238 unsigned long y = regs->
y;
240 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
247 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
248 36 *
sizeof(
u64), -1);
254 static int genregs64_set(
struct task_struct *target,
256 unsigned int pos,
unsigned int count,
257 const void *kbuf,
const void __user *ubuf)
265 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
267 0, 16 *
sizeof(
u64));
268 if (!ret && count && pos < (32 *
sizeof(
u64))) {
271 if (regwindow64_get(target, regs, &
window))
274 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
280 regwindow64_set(target, regs, &
window))
284 if (!ret && count > 0) {
285 unsigned long tstate;
288 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
298 regs->tstate |= tstate;
304 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
313 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
322 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
323 36 *
sizeof(
u64), -1);
328 static int fpregs64_get(
struct task_struct *target,
330 unsigned int pos,
unsigned int count,
331 void *kbuf,
void __user *ubuf)
334 unsigned long fprs, fsr, gsr;
338 save_and_clear_fpu();
343 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
345 0, 16 *
sizeof(
u64));
347 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
353 ret = user_regset_copyout(&pos, &count,
359 ret = user_regset_copyout_zero(&pos, &count,
373 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
378 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
383 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
389 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
390 35 *
sizeof(
u64), -1);
395 static int fpregs64_set(
struct task_struct *target,
397 unsigned int pos,
unsigned int count,
398 const void *kbuf,
const void __user *ubuf)
405 save_and_clear_fpu();
407 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
409 0, 32 *
sizeof(
u64));
411 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
416 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
422 if (!ret && count > 0) {
423 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
429 fprs |= (FPRS_FEF | FPRS_DL |
FPRS_DU);
433 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
434 35 *
sizeof(
u64), -1);
438 static const struct user_regset sparc64_regsets[] = {
450 .get = genregs64_get, .set = genregs64_set
462 .get = fpregs64_get, .set = fpregs64_set
468 .regsets = sparc64_regsets, .
n =
ARRAY_SIZE(sparc64_regsets)
474 unsigned int pos,
unsigned int count,
475 void *kbuf,
void __user *ubuf)
487 count /=
sizeof(
reg);
490 for (; count > 0 && pos < 16; count--)
491 *k++ = regs->
u_regs[pos++];
496 for (; count > 0 && pos < 32; count--) {
497 if (
get_user(*k++, ®_window[pos++]))
501 for (; count > 0 && pos < 32; count--) {
513 for (; count > 0 && pos < 16; count--) {
521 for (; count > 0 && pos < 32; count--) {
522 if (
get_user(reg, ®_window[pos++]) ||
527 for (; count > 0 && pos < 32; count--) {
531 ®,
sizeof(reg), 0)
547 reg = tstate_to_psr(regs->tstate);
575 count *=
sizeof(
reg);
577 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
578 38 *
sizeof(reg), -1);
583 unsigned int pos,
unsigned int count,
584 const void *kbuf,
const void __user *ubuf)
596 count /=
sizeof(
reg);
599 for (; count > 0 && pos < 16; count--)
600 regs->
u_regs[pos++] = *k++;
605 for (; count > 0 && pos < 32; count--) {
606 if (
put_user(*k++, ®_window[pos++]))
610 for (; count > 0 && pos < 32; count--) {
623 for (; count > 0 && pos < 16; count--) {
632 for (; count > 0 && pos < 32; count--) {
638 for (; count > 0 && pos < 32; count--) {
642 ®,
sizeof(reg), 0)
657 unsigned long tstate;
666 tstate = regs->tstate;
668 tstate |= psr_to_tstate_icc(reg);
671 regs->tstate = tstate;
694 count *=
sizeof(
reg);
696 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
697 38 *
sizeof(reg), -1);
700 static int fpregs32_get(
struct task_struct *target,
702 unsigned int pos,
unsigned int count,
703 void *kbuf,
void __user *ubuf)
712 save_and_clear_fpu();
715 if (fprs & FPRS_FEF) {
723 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
725 0, 32 *
sizeof(
u32));
728 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
732 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
740 val = (enabled << 8) | (8 << 16);
741 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
748 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
749 35 *
sizeof(
u32), -1);
754 static int fpregs32_set(
struct task_struct *target,
756 unsigned int pos,
unsigned int count,
757 const void *kbuf,
const void __user *ubuf)
764 save_and_clear_fpu();
768 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
770 0, 32 *
sizeof(
u32));
772 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
775 if (!ret && count > 0) {
779 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
785 val &= 0xffffffff00000000
UL;
795 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
796 34 *
sizeof(
u32), -1);
800 static const struct user_regset sparc32_regsets[] = {
828 .get = fpregs32_get, .set = fpregs32_set
834 .regsets = sparc32_regsets, .
n =
ARRAY_SIZE(sparc32_regsets)
841 if (test_tsk_thread_flag(task, TIF_32BIT))
842 return &user_sparc32_view;
844 return &user_sparc64_view;
849 unsigned int regs[32];
855 unsigned int insnaddr;
867 unsigned long addr2 = caddr2;
868 unsigned long addr = caddr;
873 fps = (
struct compat_fps
__user *) addr;
877 ret = (addr != 0) ? -
EIO : 0;
905 ret = copy_regset_to_user(child, view,
REGSET_FP,
910 ret = copy_regset_to_user(child, view,
REGSET_FP,
918 clear_user(&fps->fpq[0], 32 *
sizeof(
unsigned int)))
924 ret = copy_regset_from_user(child, view,
REGSET_FP,
929 ret = copy_regset_from_user(child, view,
REGSET_FP,
938 (
char __user *)addr2, data);
958 ret = compat_ptrace_request(child, request, addr, data);
967 unsigned int regs[64];
972 unsigned long addr,
unsigned long data)
977 struct fps __user *fps;
981 pregs = (
struct pt_regs __user *) addr;
982 fps = (
struct fps __user *) addr;
983 addr2p = (
void __user *) addr2;
987 ret = (addr != 0) ? -
EIO : 0;
1019 ret = copy_regset_to_user(child, view,
REGSET_FP,
1026 ret = copy_regset_from_user(child, view,
REGSET_FP,
1068 ret = tracehook_report_syscall_entry(regs);
1073 audit_syscall_entry((test_thread_flag(TIF_32BIT) ?
1087 audit_syscall_exit(regs);
1093 tracehook_report_syscall_exit(regs, 0);