2 * Based on arch/arm/kernel/ptrace.c
5 * edited by Linus Torvalds
6 * ARM modifications Copyright (C) 2000 Russell King
7 * Copyright (C) 2012 ARM Ltd.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/compat.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
26 #include <linux/smp.h>
27 #include <linux/ptrace.h>
28 #include <linux/user.h>
29 #include <linux/security.h>
30 #include <linux/init.h>
31 #include <linux/signal.h>
32 #include <linux/uaccess.h>
33 #include <linux/perf_event.h>
34 #include <linux/hw_breakpoint.h>
35 #include <linux/regset.h>
36 #include <linux/tracehook.h>
37 #include <linux/elf.h>
39 #include <asm/compat.h>
40 #include <asm/debug-monitors.h>
41 #include <asm/pgtable.h>
42 #include <asm/traps.h>
43 #include <asm/system_misc.h>
45 #define CREATE_TRACE_POINTS
46 #include <trace/events/syscalls.h>
49 * TODO: does not yet catch signals sent when the child dies.
50 * in exit.c or in signal.c.
54 * Called by kernel/ptrace.c when detaching..
56 void ptrace_disable(struct task_struct *child)
60 #ifdef CONFIG_HAVE_HW_BREAKPOINT
62 * Handle hitting a HW-breakpoint.
64 static void ptrace_hbptriggered(struct perf_event *bp,
65 struct perf_sample_data *data,
68 struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
72 .si_code = TRAP_HWBKPT,
73 .si_addr = (void __user *)(bkpt->trigger),
79 if (!is_compat_task())
82 for (i = 0; i < ARM_MAX_BRP; ++i) {
83 if (current->thread.debug.hbp_break[i] == bp) {
84 info.si_errno = (i << 1) + 1;
88 for (i = ARM_MAX_BRP; i < ARM_MAX_HBP_SLOTS && !bp; ++i) {
89 if (current->thread.debug.hbp_watch[i] == bp) {
90 info.si_errno = -((i << 1) + 1);
97 force_sig_info(SIGTRAP, &info, current);
101 * Unregister breakpoints from this task and reset the pointers in
104 void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
107 struct thread_struct *t = &tsk->thread;
109 for (i = 0; i < ARM_MAX_BRP; i++) {
110 if (t->debug.hbp_break[i]) {
111 unregister_hw_breakpoint(t->debug.hbp_break[i]);
112 t->debug.hbp_break[i] = NULL;
116 for (i = 0; i < ARM_MAX_WRP; i++) {
117 if (t->debug.hbp_watch[i]) {
118 unregister_hw_breakpoint(t->debug.hbp_watch[i]);
119 t->debug.hbp_watch[i] = NULL;
124 void ptrace_hw_copy_thread(struct task_struct *tsk)
126 memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
129 static struct perf_event *ptrace_hbp_get_event(unsigned int note_type,
130 struct task_struct *tsk,
133 struct perf_event *bp = ERR_PTR(-EINVAL);
136 case NT_ARM_HW_BREAK:
137 if (idx < ARM_MAX_BRP)
138 bp = tsk->thread.debug.hbp_break[idx];
140 case NT_ARM_HW_WATCH:
141 if (idx < ARM_MAX_WRP)
142 bp = tsk->thread.debug.hbp_watch[idx];
149 static int ptrace_hbp_set_event(unsigned int note_type,
150 struct task_struct *tsk,
152 struct perf_event *bp)
157 case NT_ARM_HW_BREAK:
158 if (idx < ARM_MAX_BRP) {
159 tsk->thread.debug.hbp_break[idx] = bp;
163 case NT_ARM_HW_WATCH:
164 if (idx < ARM_MAX_WRP) {
165 tsk->thread.debug.hbp_watch[idx] = bp;
174 static struct perf_event *ptrace_hbp_create(unsigned int note_type,
175 struct task_struct *tsk,
178 struct perf_event *bp;
179 struct perf_event_attr attr;
183 case NT_ARM_HW_BREAK:
184 type = HW_BREAKPOINT_X;
186 case NT_ARM_HW_WATCH:
187 type = HW_BREAKPOINT_RW;
190 return ERR_PTR(-EINVAL);
193 ptrace_breakpoint_init(&attr);
196 * Initialise fields to sane defaults
197 * (i.e. values that will pass validation).
200 attr.bp_len = HW_BREAKPOINT_LEN_4;
204 bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk);
208 err = ptrace_hbp_set_event(note_type, tsk, idx, bp);
215 static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
216 struct arch_hw_breakpoint_ctrl ctrl,
217 struct perf_event_attr *attr)
219 int err, len, type, disabled = !ctrl.enabled;
221 attr->disabled = disabled;
225 err = arch_bp_generic_fields(ctrl, &len, &type);
230 case NT_ARM_HW_BREAK:
231 if ((type & HW_BREAKPOINT_X) != type)
234 case NT_ARM_HW_WATCH:
235 if ((type & HW_BREAKPOINT_RW) != type)
243 attr->bp_type = type;
248 static int ptrace_hbp_get_resource_info(unsigned int note_type, u32 *info)
254 case NT_ARM_HW_BREAK:
255 num = hw_breakpoint_slots(TYPE_INST);
257 case NT_ARM_HW_WATCH:
258 num = hw_breakpoint_slots(TYPE_DATA);
264 reg |= debug_monitors_arch();
272 static int ptrace_hbp_get_ctrl(unsigned int note_type,
273 struct task_struct *tsk,
277 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
282 *ctrl = bp ? encode_ctrl_reg(counter_arch_bp(bp)->ctrl) : 0;
286 static int ptrace_hbp_get_addr(unsigned int note_type,
287 struct task_struct *tsk,
291 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
296 *addr = bp ? bp->attr.bp_addr : 0;
300 static struct perf_event *ptrace_hbp_get_initialised_bp(unsigned int note_type,
301 struct task_struct *tsk,
304 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
307 bp = ptrace_hbp_create(note_type, tsk, idx);
312 static int ptrace_hbp_set_ctrl(unsigned int note_type,
313 struct task_struct *tsk,
318 struct perf_event *bp;
319 struct perf_event_attr attr;
320 struct arch_hw_breakpoint_ctrl ctrl;
322 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
329 decode_ctrl_reg(uctrl, &ctrl);
330 err = ptrace_hbp_fill_attr_ctrl(note_type, ctrl, &attr);
334 return modify_user_hw_breakpoint(bp, &attr);
337 static int ptrace_hbp_set_addr(unsigned int note_type,
338 struct task_struct *tsk,
343 struct perf_event *bp;
344 struct perf_event_attr attr;
346 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
354 err = modify_user_hw_breakpoint(bp, &attr);
358 #define PTRACE_HBP_ADDR_SZ sizeof(u64)
359 #define PTRACE_HBP_CTRL_SZ sizeof(u32)
360 #define PTRACE_HBP_PAD_SZ sizeof(u32)
362 static int hw_break_get(struct task_struct *target,
363 const struct user_regset *regset,
364 unsigned int pos, unsigned int count,
365 void *kbuf, void __user *ubuf)
367 unsigned int note_type = regset->core_note_type;
368 int ret, idx = 0, offset, limit;
373 ret = ptrace_hbp_get_resource_info(note_type, &info);
377 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &info, 0,
383 offset = offsetof(struct user_hwdebug_state, pad);
384 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, offset,
385 offset + PTRACE_HBP_PAD_SZ);
389 /* (address, ctrl) registers */
390 offset = offsetof(struct user_hwdebug_state, dbg_regs);
391 limit = regset->n * regset->size;
392 while (count && offset < limit) {
393 ret = ptrace_hbp_get_addr(note_type, target, idx, &addr);
396 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &addr,
397 offset, offset + PTRACE_HBP_ADDR_SZ);
400 offset += PTRACE_HBP_ADDR_SZ;
402 ret = ptrace_hbp_get_ctrl(note_type, target, idx, &ctrl);
405 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &ctrl,
406 offset, offset + PTRACE_HBP_CTRL_SZ);
409 offset += PTRACE_HBP_CTRL_SZ;
411 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
413 offset + PTRACE_HBP_PAD_SZ);
416 offset += PTRACE_HBP_PAD_SZ;
423 static int hw_break_set(struct task_struct *target,
424 const struct user_regset *regset,
425 unsigned int pos, unsigned int count,
426 const void *kbuf, const void __user *ubuf)
428 unsigned int note_type = regset->core_note_type;
429 int ret, idx = 0, offset, limit;
433 /* Resource info and pad */
434 offset = offsetof(struct user_hwdebug_state, dbg_regs);
435 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 0, offset);
439 /* (address, ctrl) registers */
440 limit = regset->n * regset->size;
441 while (count && offset < limit) {
442 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &addr,
443 offset, offset + PTRACE_HBP_ADDR_SZ);
446 ret = ptrace_hbp_set_addr(note_type, target, idx, addr);
449 offset += PTRACE_HBP_ADDR_SZ;
451 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl,
452 offset, offset + PTRACE_HBP_CTRL_SZ);
455 ret = ptrace_hbp_set_ctrl(note_type, target, idx, ctrl);
458 offset += PTRACE_HBP_CTRL_SZ;
460 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
462 offset + PTRACE_HBP_PAD_SZ);
465 offset += PTRACE_HBP_PAD_SZ;
471 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
473 static int gpr_get(struct task_struct *target,
474 const struct user_regset *regset,
475 unsigned int pos, unsigned int count,
476 void *kbuf, void __user *ubuf)
478 struct user_pt_regs *uregs = &task_pt_regs(target)->user_regs;
479 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
482 static int gpr_set(struct task_struct *target, const struct user_regset *regset,
483 unsigned int pos, unsigned int count,
484 const void *kbuf, const void __user *ubuf)
487 struct user_pt_regs newregs;
489 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newregs, 0, -1);
493 if (!valid_user_regs(&newregs))
496 task_pt_regs(target)->user_regs = newregs;
501 * TODO: update fp accessors for lazy context switching (sync/flush hwstate)
503 static int fpr_get(struct task_struct *target, const struct user_regset *regset,
504 unsigned int pos, unsigned int count,
505 void *kbuf, void __user *ubuf)
507 struct user_fpsimd_state *uregs;
508 uregs = &target->thread.fpsimd_state.user_fpsimd;
509 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
512 static int fpr_set(struct task_struct *target, const struct user_regset *regset,
513 unsigned int pos, unsigned int count,
514 const void *kbuf, const void __user *ubuf)
517 struct user_fpsimd_state newstate;
519 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate, 0, -1);
523 target->thread.fpsimd_state.user_fpsimd = newstate;
524 fpsimd_flush_task_state(target);
528 static int tls_get(struct task_struct *target, const struct user_regset *regset,
529 unsigned int pos, unsigned int count,
530 void *kbuf, void __user *ubuf)
532 unsigned long *tls = &target->thread.tp_value;
533 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, tls, 0, -1);
536 static int tls_set(struct task_struct *target, const struct user_regset *regset,
537 unsigned int pos, unsigned int count,
538 const void *kbuf, const void __user *ubuf)
543 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &tls, 0, -1);
547 target->thread.tp_value = tls;
551 enum aarch64_regset {
555 #ifdef CONFIG_HAVE_HW_BREAKPOINT
561 static const struct user_regset aarch64_regsets[] = {
563 .core_note_type = NT_PRSTATUS,
564 .n = sizeof(struct user_pt_regs) / sizeof(u64),
566 .align = sizeof(u64),
571 .core_note_type = NT_PRFPREG,
572 .n = sizeof(struct user_fpsimd_state) / sizeof(u32),
574 * We pretend we have 32-bit registers because the fpsr and
575 * fpcr are 32-bits wide.
578 .align = sizeof(u32),
583 .core_note_type = NT_ARM_TLS,
585 .size = sizeof(void *),
586 .align = sizeof(void *),
590 #ifdef CONFIG_HAVE_HW_BREAKPOINT
591 [REGSET_HW_BREAK] = {
592 .core_note_type = NT_ARM_HW_BREAK,
593 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
595 .align = sizeof(u32),
599 [REGSET_HW_WATCH] = {
600 .core_note_type = NT_ARM_HW_WATCH,
601 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
603 .align = sizeof(u32),
610 static const struct user_regset_view user_aarch64_view = {
611 .name = "aarch64", .e_machine = EM_AARCH64,
612 .regsets = aarch64_regsets, .n = ARRAY_SIZE(aarch64_regsets)
616 #include <linux/compat.h>
623 static int compat_gpr_get(struct task_struct *target,
624 const struct user_regset *regset,
625 unsigned int pos, unsigned int count,
626 void *kbuf, void __user *ubuf)
629 unsigned int i, start, num_regs;
631 /* Calculate the number of AArch32 registers contained in count */
632 num_regs = count / regset->size;
634 /* Convert pos into an register number */
635 start = pos / regset->size;
637 if (start + num_regs > regset->n)
640 for (i = 0; i < num_regs; ++i) {
641 unsigned int idx = start + i;
646 reg = task_pt_regs(target)->pc;
649 reg = task_pt_regs(target)->pstate;
652 reg = task_pt_regs(target)->orig_x0;
655 reg = task_pt_regs(target)->regs[idx];
658 ret = copy_to_user(ubuf, ®, sizeof(reg));
668 static int compat_gpr_set(struct task_struct *target,
669 const struct user_regset *regset,
670 unsigned int pos, unsigned int count,
671 const void *kbuf, const void __user *ubuf)
673 struct pt_regs newregs;
675 unsigned int i, start, num_regs;
677 /* Calculate the number of AArch32 registers contained in count */
678 num_regs = count / regset->size;
680 /* Convert pos into an register number */
681 start = pos / regset->size;
683 if (start + num_regs > regset->n)
686 newregs = *task_pt_regs(target);
688 for (i = 0; i < num_regs; ++i) {
689 unsigned int idx = start + i;
692 ret = copy_from_user(®, ubuf, sizeof(reg));
703 newregs.pstate = reg;
706 newregs.orig_x0 = reg;
709 newregs.regs[idx] = reg;
714 if (valid_user_regs(&newregs.user_regs))
715 *task_pt_regs(target) = newregs;
722 static int compat_vfp_get(struct task_struct *target,
723 const struct user_regset *regset,
724 unsigned int pos, unsigned int count,
725 void *kbuf, void __user *ubuf)
727 struct user_fpsimd_state *uregs;
728 compat_ulong_t fpscr;
731 uregs = &target->thread.fpsimd_state.user_fpsimd;
734 * The VFP registers are packed into the fpsimd_state, so they all sit
735 * nicely together for us. We just need to create the fpscr separately.
737 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
738 VFP_STATE_SIZE - sizeof(compat_ulong_t));
741 fpscr = (uregs->fpsr & VFP_FPSCR_STAT_MASK) |
742 (uregs->fpcr & VFP_FPSCR_CTRL_MASK);
743 ret = put_user(fpscr, (compat_ulong_t *)ubuf);
749 static int compat_vfp_set(struct task_struct *target,
750 const struct user_regset *regset,
751 unsigned int pos, unsigned int count,
752 const void *kbuf, const void __user *ubuf)
754 struct user_fpsimd_state *uregs;
755 compat_ulong_t fpscr;
758 if (pos + count > VFP_STATE_SIZE)
761 uregs = &target->thread.fpsimd_state.user_fpsimd;
763 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
764 VFP_STATE_SIZE - sizeof(compat_ulong_t));
767 ret = get_user(fpscr, (compat_ulong_t *)ubuf);
768 uregs->fpsr = fpscr & VFP_FPSCR_STAT_MASK;
769 uregs->fpcr = fpscr & VFP_FPSCR_CTRL_MASK;
772 fpsimd_flush_task_state(target);
776 static const struct user_regset aarch32_regsets[] = {
777 [REGSET_COMPAT_GPR] = {
778 .core_note_type = NT_PRSTATUS,
779 .n = COMPAT_ELF_NGREG,
780 .size = sizeof(compat_elf_greg_t),
781 .align = sizeof(compat_elf_greg_t),
782 .get = compat_gpr_get,
783 .set = compat_gpr_set
785 [REGSET_COMPAT_VFP] = {
786 .core_note_type = NT_ARM_VFP,
787 .n = VFP_STATE_SIZE / sizeof(compat_ulong_t),
788 .size = sizeof(compat_ulong_t),
789 .align = sizeof(compat_ulong_t),
790 .get = compat_vfp_get,
791 .set = compat_vfp_set
795 static const struct user_regset_view user_aarch32_view = {
796 .name = "aarch32", .e_machine = EM_ARM,
797 .regsets = aarch32_regsets, .n = ARRAY_SIZE(aarch32_regsets)
800 static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,
801 compat_ulong_t __user *ret)
808 if (off == COMPAT_PT_TEXT_ADDR)
809 tmp = tsk->mm->start_code;
810 else if (off == COMPAT_PT_DATA_ADDR)
811 tmp = tsk->mm->start_data;
812 else if (off == COMPAT_PT_TEXT_END_ADDR)
813 tmp = tsk->mm->end_code;
814 else if (off < sizeof(compat_elf_gregset_t))
815 return copy_regset_to_user(tsk, &user_aarch32_view,
816 REGSET_COMPAT_GPR, off,
817 sizeof(compat_ulong_t), ret);
818 else if (off >= COMPAT_USER_SZ)
823 return put_user(tmp, ret);
826 static int compat_ptrace_write_user(struct task_struct *tsk, compat_ulong_t off,
831 if (off & 3 || off >= COMPAT_USER_SZ)
834 if (off >= sizeof(compat_elf_gregset_t))
837 ret = copy_regset_from_user(tsk, &user_aarch32_view,
838 REGSET_COMPAT_GPR, off,
839 sizeof(compat_ulong_t),
844 #ifdef CONFIG_HAVE_HW_BREAKPOINT
847 * Convert a virtual register number into an index for a thread_info
848 * breakpoint array. Breakpoints are identified using positive numbers
849 * whilst watchpoints are negative. The registers are laid out as pairs
850 * of (address, control), each pair mapping to a unique hw_breakpoint struct.
851 * Register 0 is reserved for describing resource information.
853 static int compat_ptrace_hbp_num_to_idx(compat_long_t num)
855 return (abs(num) - 1) >> 1;
858 static int compat_ptrace_hbp_get_resource_info(u32 *kdata)
860 u8 num_brps, num_wrps, debug_arch, wp_len;
863 num_brps = hw_breakpoint_slots(TYPE_INST);
864 num_wrps = hw_breakpoint_slots(TYPE_DATA);
866 debug_arch = debug_monitors_arch();
880 static int compat_ptrace_hbp_get(unsigned int note_type,
881 struct task_struct *tsk,
888 int err, idx = compat_ptrace_hbp_num_to_idx(num);;
891 err = ptrace_hbp_get_addr(note_type, tsk, idx, &addr);
894 err = ptrace_hbp_get_ctrl(note_type, tsk, idx, &ctrl);
901 static int compat_ptrace_hbp_set(unsigned int note_type,
902 struct task_struct *tsk,
909 int err, idx = compat_ptrace_hbp_num_to_idx(num);
913 err = ptrace_hbp_set_addr(note_type, tsk, idx, addr);
916 err = ptrace_hbp_set_ctrl(note_type, tsk, idx, ctrl);
922 static int compat_ptrace_gethbpregs(struct task_struct *tsk, compat_long_t num,
923 compat_ulong_t __user *data)
927 mm_segment_t old_fs = get_fs();
932 ret = compat_ptrace_hbp_get(NT_ARM_HW_WATCH, tsk, num, &kdata);
934 } else if (num == 0) {
935 ret = compat_ptrace_hbp_get_resource_info(&kdata);
938 ret = compat_ptrace_hbp_get(NT_ARM_HW_BREAK, tsk, num, &kdata);
943 ret = put_user(kdata, data);
948 static int compat_ptrace_sethbpregs(struct task_struct *tsk, compat_long_t num,
949 compat_ulong_t __user *data)
953 mm_segment_t old_fs = get_fs();
958 ret = get_user(kdata, data);
964 ret = compat_ptrace_hbp_set(NT_ARM_HW_WATCH, tsk, num, &kdata);
966 ret = compat_ptrace_hbp_set(NT_ARM_HW_BREAK, tsk, num, &kdata);
971 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
973 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
974 compat_ulong_t caddr, compat_ulong_t cdata)
976 unsigned long addr = caddr;
977 unsigned long data = cdata;
978 void __user *datap = compat_ptr(data);
983 ret = compat_ptrace_read_user(child, addr, datap);
987 ret = compat_ptrace_write_user(child, addr, data);
990 case COMPAT_PTRACE_GETREGS:
991 ret = copy_regset_to_user(child,
994 0, sizeof(compat_elf_gregset_t),
998 case COMPAT_PTRACE_SETREGS:
999 ret = copy_regset_from_user(child,
1002 0, sizeof(compat_elf_gregset_t),
1006 case COMPAT_PTRACE_GET_THREAD_AREA:
1007 ret = put_user((compat_ulong_t)child->thread.tp_value,
1008 (compat_ulong_t __user *)datap);
1011 case COMPAT_PTRACE_SET_SYSCALL:
1012 task_pt_regs(child)->syscallno = data;
1016 case COMPAT_PTRACE_GETVFPREGS:
1017 ret = copy_regset_to_user(child,
1024 case COMPAT_PTRACE_SETVFPREGS:
1025 ret = copy_regset_from_user(child,
1032 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1033 case COMPAT_PTRACE_GETHBPREGS:
1034 ret = compat_ptrace_gethbpregs(child, addr, datap);
1037 case COMPAT_PTRACE_SETHBPREGS:
1038 ret = compat_ptrace_sethbpregs(child, addr, datap);
1043 ret = compat_ptrace_request(child, request, addr,
1050 #endif /* CONFIG_COMPAT */
1052 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1054 #ifdef CONFIG_COMPAT
1055 if (is_compat_thread(task_thread_info(task)))
1056 return &user_aarch32_view;
1058 return &user_aarch64_view;
1061 long arch_ptrace(struct task_struct *child, long request,
1062 unsigned long addr, unsigned long data)
1064 return ptrace_request(child, request, addr, data);
1067 enum ptrace_syscall_dir {
1068 PTRACE_SYSCALL_ENTER = 0,
1069 PTRACE_SYSCALL_EXIT,
1072 static void tracehook_report_syscall(struct pt_regs *regs,
1073 enum ptrace_syscall_dir dir)
1076 unsigned long saved_reg;
1079 * A scratch register (ip(r12) on AArch32, x7 on AArch64) is
1080 * used to denote syscall entry/exit:
1082 regno = (is_compat_task() ? 12 : 7);
1083 saved_reg = regs->regs[regno];
1084 regs->regs[regno] = dir;
1086 if (dir == PTRACE_SYSCALL_EXIT)
1087 tracehook_report_syscall_exit(regs, 0);
1088 else if (tracehook_report_syscall_entry(regs))
1089 regs->syscallno = ~0UL;
1091 regs->regs[regno] = saved_reg;
1094 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1096 if (test_thread_flag(TIF_SYSCALL_TRACE))
1097 tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
1099 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
1100 trace_sys_enter(regs, regs->syscallno);
1102 return regs->syscallno;
1105 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
1107 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
1108 trace_sys_exit(regs, regs_return_value(regs));
1110 if (test_thread_flag(TIF_SYSCALL_TRACE))
1111 tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);