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/kernel.h>
23 #include <linux/sched.h>
25 #include <linux/smp.h>
26 #include <linux/ptrace.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/init.h>
30 #include <linux/signal.h>
31 #include <linux/uaccess.h>
32 #include <linux/perf_event.h>
33 #include <linux/hw_breakpoint.h>
34 #include <linux/regset.h>
35 #include <linux/tracehook.h>
36 #include <linux/elf.h>
38 #include <asm/compat.h>
39 #include <asm/debug-monitors.h>
40 #include <asm/pgtable.h>
41 #include <asm/traps.h>
42 #include <asm/system_misc.h>
45 * TODO: does not yet catch signals sent when the child dies.
46 * in exit.c or in signal.c.
50 * Called by kernel/ptrace.c when detaching..
52 void ptrace_disable(struct task_struct *child)
57 * Handle hitting a breakpoint.
59 static int ptrace_break(struct pt_regs *regs)
64 .si_code = TRAP_BRKPT,
65 .si_addr = (void __user *)instruction_pointer(regs),
68 force_sig_info(SIGTRAP, &info, current);
72 static int arm64_break_trap(unsigned long addr, unsigned int esr,
75 return ptrace_break(regs);
78 #ifdef CONFIG_HAVE_HW_BREAKPOINT
80 * Handle hitting a HW-breakpoint.
82 static void ptrace_hbptriggered(struct perf_event *bp,
83 struct perf_sample_data *data,
86 struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
90 .si_code = TRAP_HWBKPT,
91 .si_addr = (void __user *)(bkpt->trigger),
97 if (!is_compat_task())
100 for (i = 0; i < ARM_MAX_BRP; ++i) {
101 if (current->thread.debug.hbp_break[i] == bp) {
102 info.si_errno = (i << 1) + 1;
106 for (i = ARM_MAX_BRP; i < ARM_MAX_HBP_SLOTS && !bp; ++i) {
107 if (current->thread.debug.hbp_watch[i] == bp) {
108 info.si_errno = -((i << 1) + 1);
115 force_sig_info(SIGTRAP, &info, current);
119 * Unregister breakpoints from this task and reset the pointers in
122 void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
125 struct thread_struct *t = &tsk->thread;
127 for (i = 0; i < ARM_MAX_BRP; i++) {
128 if (t->debug.hbp_break[i]) {
129 unregister_hw_breakpoint(t->debug.hbp_break[i]);
130 t->debug.hbp_break[i] = NULL;
134 for (i = 0; i < ARM_MAX_WRP; i++) {
135 if (t->debug.hbp_watch[i]) {
136 unregister_hw_breakpoint(t->debug.hbp_watch[i]);
137 t->debug.hbp_watch[i] = NULL;
142 void ptrace_hw_copy_thread(struct task_struct *tsk)
144 memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
147 static struct perf_event *ptrace_hbp_get_event(unsigned int note_type,
148 struct task_struct *tsk,
151 struct perf_event *bp = ERR_PTR(-EINVAL);
154 case NT_ARM_HW_BREAK:
155 if (idx < ARM_MAX_BRP)
156 bp = tsk->thread.debug.hbp_break[idx];
158 case NT_ARM_HW_WATCH:
159 if (idx < ARM_MAX_WRP)
160 bp = tsk->thread.debug.hbp_watch[idx];
167 static int ptrace_hbp_set_event(unsigned int note_type,
168 struct task_struct *tsk,
170 struct perf_event *bp)
175 case NT_ARM_HW_BREAK:
176 if (idx < ARM_MAX_BRP) {
177 tsk->thread.debug.hbp_break[idx] = bp;
181 case NT_ARM_HW_WATCH:
182 if (idx < ARM_MAX_WRP) {
183 tsk->thread.debug.hbp_watch[idx] = bp;
192 static struct perf_event *ptrace_hbp_create(unsigned int note_type,
193 struct task_struct *tsk,
196 struct perf_event *bp;
197 struct perf_event_attr attr;
201 case NT_ARM_HW_BREAK:
202 type = HW_BREAKPOINT_X;
204 case NT_ARM_HW_WATCH:
205 type = HW_BREAKPOINT_RW;
208 return ERR_PTR(-EINVAL);
211 ptrace_breakpoint_init(&attr);
214 * Initialise fields to sane defaults
215 * (i.e. values that will pass validation).
218 attr.bp_len = HW_BREAKPOINT_LEN_4;
222 bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk);
226 err = ptrace_hbp_set_event(note_type, tsk, idx, bp);
233 static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
234 struct arch_hw_breakpoint_ctrl ctrl,
235 struct perf_event_attr *attr)
237 int err, len, type, disabled = !ctrl.enabled;
239 attr->disabled = disabled;
243 err = arch_bp_generic_fields(ctrl, &len, &type);
248 case NT_ARM_HW_BREAK:
249 if ((type & HW_BREAKPOINT_X) != type)
252 case NT_ARM_HW_WATCH:
253 if ((type & HW_BREAKPOINT_RW) != type)
261 attr->bp_type = type;
266 static int ptrace_hbp_get_resource_info(unsigned int note_type, u32 *info)
272 case NT_ARM_HW_BREAK:
273 num = hw_breakpoint_slots(TYPE_INST);
275 case NT_ARM_HW_WATCH:
276 num = hw_breakpoint_slots(TYPE_DATA);
282 reg |= debug_monitors_arch();
290 static int ptrace_hbp_get_ctrl(unsigned int note_type,
291 struct task_struct *tsk,
295 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
300 *ctrl = bp ? encode_ctrl_reg(counter_arch_bp(bp)->ctrl) : 0;
304 static int ptrace_hbp_get_addr(unsigned int note_type,
305 struct task_struct *tsk,
309 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
314 *addr = bp ? bp->attr.bp_addr : 0;
318 static struct perf_event *ptrace_hbp_get_initialised_bp(unsigned int note_type,
319 struct task_struct *tsk,
322 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
325 bp = ptrace_hbp_create(note_type, tsk, idx);
330 static int ptrace_hbp_set_ctrl(unsigned int note_type,
331 struct task_struct *tsk,
336 struct perf_event *bp;
337 struct perf_event_attr attr;
338 struct arch_hw_breakpoint_ctrl ctrl;
340 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
347 decode_ctrl_reg(uctrl, &ctrl);
348 err = ptrace_hbp_fill_attr_ctrl(note_type, ctrl, &attr);
352 return modify_user_hw_breakpoint(bp, &attr);
355 static int ptrace_hbp_set_addr(unsigned int note_type,
356 struct task_struct *tsk,
361 struct perf_event *bp;
362 struct perf_event_attr attr;
364 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
372 err = modify_user_hw_breakpoint(bp, &attr);
376 #define PTRACE_HBP_ADDR_SZ sizeof(u64)
377 #define PTRACE_HBP_CTRL_SZ sizeof(u32)
378 #define PTRACE_HBP_PAD_SZ sizeof(u32)
380 static int hw_break_get(struct task_struct *target,
381 const struct user_regset *regset,
382 unsigned int pos, unsigned int count,
383 void *kbuf, void __user *ubuf)
385 unsigned int note_type = regset->core_note_type;
386 int ret, idx = 0, offset, limit;
391 ret = ptrace_hbp_get_resource_info(note_type, &info);
395 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &info, 0,
401 offset = offsetof(struct user_hwdebug_state, pad);
402 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, offset,
403 offset + PTRACE_HBP_PAD_SZ);
407 /* (address, ctrl) registers */
408 offset = offsetof(struct user_hwdebug_state, dbg_regs);
409 limit = regset->n * regset->size;
410 while (count && offset < limit) {
411 ret = ptrace_hbp_get_addr(note_type, target, idx, &addr);
414 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &addr,
415 offset, offset + PTRACE_HBP_ADDR_SZ);
418 offset += PTRACE_HBP_ADDR_SZ;
420 ret = ptrace_hbp_get_ctrl(note_type, target, idx, &ctrl);
423 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &ctrl,
424 offset, offset + PTRACE_HBP_CTRL_SZ);
427 offset += PTRACE_HBP_CTRL_SZ;
429 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
431 offset + PTRACE_HBP_PAD_SZ);
434 offset += PTRACE_HBP_PAD_SZ;
441 static int hw_break_set(struct task_struct *target,
442 const struct user_regset *regset,
443 unsigned int pos, unsigned int count,
444 const void *kbuf, const void __user *ubuf)
446 unsigned int note_type = regset->core_note_type;
447 int ret, idx = 0, offset, limit;
451 /* Resource info and pad */
452 offset = offsetof(struct user_hwdebug_state, dbg_regs);
453 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 0, offset);
457 /* (address, ctrl) registers */
458 limit = regset->n * regset->size;
459 while (count && offset < limit) {
460 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &addr,
461 offset, offset + PTRACE_HBP_ADDR_SZ);
464 ret = ptrace_hbp_set_addr(note_type, target, idx, addr);
467 offset += PTRACE_HBP_ADDR_SZ;
469 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl,
470 offset, offset + PTRACE_HBP_CTRL_SZ);
473 ret = ptrace_hbp_set_ctrl(note_type, target, idx, ctrl);
476 offset += PTRACE_HBP_CTRL_SZ;
478 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
480 offset + PTRACE_HBP_PAD_SZ);
483 offset += PTRACE_HBP_PAD_SZ;
489 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
491 static int gpr_get(struct task_struct *target,
492 const struct user_regset *regset,
493 unsigned int pos, unsigned int count,
494 void *kbuf, void __user *ubuf)
496 struct user_pt_regs *uregs = &task_pt_regs(target)->user_regs;
497 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
500 static int gpr_set(struct task_struct *target, const struct user_regset *regset,
501 unsigned int pos, unsigned int count,
502 const void *kbuf, const void __user *ubuf)
505 struct user_pt_regs newregs;
507 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newregs, 0, -1);
511 if (!valid_user_regs(&newregs))
514 task_pt_regs(target)->user_regs = newregs;
519 * TODO: update fp accessors for lazy context switching (sync/flush hwstate)
521 static int fpr_get(struct task_struct *target, const struct user_regset *regset,
522 unsigned int pos, unsigned int count,
523 void *kbuf, void __user *ubuf)
525 struct user_fpsimd_state *uregs;
526 uregs = &target->thread.fpsimd_state.user_fpsimd;
527 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
530 static int fpr_set(struct task_struct *target, const struct user_regset *regset,
531 unsigned int pos, unsigned int count,
532 const void *kbuf, const void __user *ubuf)
535 struct user_fpsimd_state newstate;
537 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate, 0, -1);
541 target->thread.fpsimd_state.user_fpsimd = newstate;
545 static int tls_get(struct task_struct *target, const struct user_regset *regset,
546 unsigned int pos, unsigned int count,
547 void *kbuf, void __user *ubuf)
549 unsigned long *tls = &target->thread.tp_value;
550 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, tls, 0, -1);
553 static int tls_set(struct task_struct *target, const struct user_regset *regset,
554 unsigned int pos, unsigned int count,
555 const void *kbuf, const void __user *ubuf)
560 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &tls, 0, -1);
564 target->thread.tp_value = tls;
568 enum aarch64_regset {
572 #ifdef CONFIG_HAVE_HW_BREAKPOINT
578 static const struct user_regset aarch64_regsets[] = {
580 .core_note_type = NT_PRSTATUS,
581 .n = sizeof(struct user_pt_regs) / sizeof(u64),
583 .align = sizeof(u64),
588 .core_note_type = NT_PRFPREG,
589 .n = sizeof(struct user_fpsimd_state) / sizeof(u32),
591 * We pretend we have 32-bit registers because the fpsr and
592 * fpcr are 32-bits wide.
595 .align = sizeof(u32),
600 .core_note_type = NT_ARM_TLS,
602 .size = sizeof(void *),
603 .align = sizeof(void *),
607 #ifdef CONFIG_HAVE_HW_BREAKPOINT
608 [REGSET_HW_BREAK] = {
609 .core_note_type = NT_ARM_HW_BREAK,
610 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
612 .align = sizeof(u32),
616 [REGSET_HW_WATCH] = {
617 .core_note_type = NT_ARM_HW_WATCH,
618 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
620 .align = sizeof(u32),
627 static const struct user_regset_view user_aarch64_view = {
628 .name = "aarch64", .e_machine = EM_AARCH64,
629 .regsets = aarch64_regsets, .n = ARRAY_SIZE(aarch64_regsets)
633 #include <linux/compat.h>
640 static int compat_gpr_get(struct task_struct *target,
641 const struct user_regset *regset,
642 unsigned int pos, unsigned int count,
643 void *kbuf, void __user *ubuf)
646 unsigned int i, start, num_regs;
648 /* Calculate the number of AArch32 registers contained in count */
649 num_regs = count / regset->size;
651 /* Convert pos into an register number */
652 start = pos / regset->size;
654 if (start + num_regs > regset->n)
657 for (i = 0; i < num_regs; ++i) {
658 unsigned int idx = start + i;
663 reg = task_pt_regs(target)->pc;
666 reg = task_pt_regs(target)->pstate;
669 reg = task_pt_regs(target)->orig_x0;
672 reg = task_pt_regs(target)->regs[idx];
675 ret = copy_to_user(ubuf, ®, sizeof(reg));
685 static int compat_gpr_set(struct task_struct *target,
686 const struct user_regset *regset,
687 unsigned int pos, unsigned int count,
688 const void *kbuf, const void __user *ubuf)
690 struct pt_regs newregs;
692 unsigned int i, start, num_regs;
694 /* Calculate the number of AArch32 registers contained in count */
695 num_regs = count / regset->size;
697 /* Convert pos into an register number */
698 start = pos / regset->size;
700 if (start + num_regs > regset->n)
703 newregs = *task_pt_regs(target);
705 for (i = 0; i < num_regs; ++i) {
706 unsigned int idx = start + i;
709 ret = copy_from_user(®, ubuf, sizeof(reg));
720 newregs.pstate = reg;
723 newregs.orig_x0 = reg;
726 newregs.regs[idx] = reg;
731 if (valid_user_regs(&newregs.user_regs))
732 *task_pt_regs(target) = newregs;
739 static int compat_vfp_get(struct task_struct *target,
740 const struct user_regset *regset,
741 unsigned int pos, unsigned int count,
742 void *kbuf, void __user *ubuf)
744 struct user_fpsimd_state *uregs;
745 compat_ulong_t fpscr;
748 uregs = &target->thread.fpsimd_state.user_fpsimd;
751 * The VFP registers are packed into the fpsimd_state, so they all sit
752 * nicely together for us. We just need to create the fpscr separately.
754 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
755 VFP_STATE_SIZE - sizeof(compat_ulong_t));
758 fpscr = (uregs->fpsr & VFP_FPSCR_STAT_MASK) |
759 (uregs->fpcr & VFP_FPSCR_CTRL_MASK);
760 ret = put_user(fpscr, (compat_ulong_t *)ubuf);
766 static int compat_vfp_set(struct task_struct *target,
767 const struct user_regset *regset,
768 unsigned int pos, unsigned int count,
769 const void *kbuf, const void __user *ubuf)
771 struct user_fpsimd_state *uregs;
772 compat_ulong_t fpscr;
775 if (pos + count > VFP_STATE_SIZE)
778 uregs = &target->thread.fpsimd_state.user_fpsimd;
780 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
781 VFP_STATE_SIZE - sizeof(compat_ulong_t));
784 ret = get_user(fpscr, (compat_ulong_t *)ubuf);
785 uregs->fpsr = fpscr & VFP_FPSCR_STAT_MASK;
786 uregs->fpcr = fpscr & VFP_FPSCR_CTRL_MASK;
792 static const struct user_regset aarch32_regsets[] = {
793 [REGSET_COMPAT_GPR] = {
794 .core_note_type = NT_PRSTATUS,
795 .n = COMPAT_ELF_NGREG,
796 .size = sizeof(compat_elf_greg_t),
797 .align = sizeof(compat_elf_greg_t),
798 .get = compat_gpr_get,
799 .set = compat_gpr_set
801 [REGSET_COMPAT_VFP] = {
802 .core_note_type = NT_ARM_VFP,
803 .n = VFP_STATE_SIZE / sizeof(compat_ulong_t),
804 .size = sizeof(compat_ulong_t),
805 .align = sizeof(compat_ulong_t),
806 .get = compat_vfp_get,
807 .set = compat_vfp_set
811 static const struct user_regset_view user_aarch32_view = {
812 .name = "aarch32", .e_machine = EM_ARM,
813 .regsets = aarch32_regsets, .n = ARRAY_SIZE(aarch32_regsets)
816 int aarch32_break_trap(struct pt_regs *regs)
820 void __user *pc = (void __user *)instruction_pointer(regs);
822 if (compat_thumb_mode(regs)) {
823 /* get 16-bit Thumb instruction */
824 get_user(instr, (u16 __user *)pc);
825 if (instr == AARCH32_BREAK_THUMB2_LO) {
826 /* get second half of 32-bit Thumb-2 instruction */
827 get_user(instr, (u16 __user *)(pc + 2));
828 bp = instr == AARCH32_BREAK_THUMB2_HI;
830 bp = instr == AARCH32_BREAK_THUMB;
833 /* 32-bit ARM instruction */
834 get_user(instr, (u32 __user *)pc);
835 bp = (instr & ~0xf0000000) == AARCH32_BREAK_ARM;
839 return ptrace_break(regs);
843 static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,
844 compat_ulong_t __user *ret)
851 if (off == COMPAT_PT_TEXT_ADDR)
852 tmp = tsk->mm->start_code;
853 else if (off == COMPAT_PT_DATA_ADDR)
854 tmp = tsk->mm->start_data;
855 else if (off == COMPAT_PT_TEXT_END_ADDR)
856 tmp = tsk->mm->end_code;
857 else if (off < sizeof(compat_elf_gregset_t))
858 return copy_regset_to_user(tsk, &user_aarch32_view,
859 REGSET_COMPAT_GPR, off,
860 sizeof(compat_ulong_t), ret);
861 else if (off >= COMPAT_USER_SZ)
866 return put_user(tmp, ret);
869 static int compat_ptrace_write_user(struct task_struct *tsk, compat_ulong_t off,
874 if (off & 3 || off >= COMPAT_USER_SZ)
877 if (off >= sizeof(compat_elf_gregset_t))
880 ret = copy_regset_from_user(tsk, &user_aarch32_view,
881 REGSET_COMPAT_GPR, off,
882 sizeof(compat_ulong_t),
887 #ifdef CONFIG_HAVE_HW_BREAKPOINT
890 * Convert a virtual register number into an index for a thread_info
891 * breakpoint array. Breakpoints are identified using positive numbers
892 * whilst watchpoints are negative. The registers are laid out as pairs
893 * of (address, control), each pair mapping to a unique hw_breakpoint struct.
894 * Register 0 is reserved for describing resource information.
896 static int compat_ptrace_hbp_num_to_idx(compat_long_t num)
898 return (abs(num) - 1) >> 1;
901 static int compat_ptrace_hbp_get_resource_info(u32 *kdata)
903 u8 num_brps, num_wrps, debug_arch, wp_len;
906 num_brps = hw_breakpoint_slots(TYPE_INST);
907 num_wrps = hw_breakpoint_slots(TYPE_DATA);
909 debug_arch = debug_monitors_arch();
923 static int compat_ptrace_hbp_get(unsigned int note_type,
924 struct task_struct *tsk,
931 int err, idx = compat_ptrace_hbp_num_to_idx(num);;
934 err = ptrace_hbp_get_addr(note_type, tsk, idx, &addr);
937 err = ptrace_hbp_get_ctrl(note_type, tsk, idx, &ctrl);
944 static int compat_ptrace_hbp_set(unsigned int note_type,
945 struct task_struct *tsk,
952 int err, idx = compat_ptrace_hbp_num_to_idx(num);
956 err = ptrace_hbp_set_addr(note_type, tsk, idx, addr);
959 err = ptrace_hbp_set_ctrl(note_type, tsk, idx, ctrl);
965 static int compat_ptrace_gethbpregs(struct task_struct *tsk, compat_long_t num,
966 compat_ulong_t __user *data)
970 mm_segment_t old_fs = get_fs();
975 ret = compat_ptrace_hbp_get(NT_ARM_HW_WATCH, tsk, num, &kdata);
977 } else if (num == 0) {
978 ret = compat_ptrace_hbp_get_resource_info(&kdata);
981 ret = compat_ptrace_hbp_get(NT_ARM_HW_BREAK, tsk, num, &kdata);
986 ret = put_user(kdata, data);
991 static int compat_ptrace_sethbpregs(struct task_struct *tsk, compat_long_t num,
992 compat_ulong_t __user *data)
996 mm_segment_t old_fs = get_fs();
1001 ret = get_user(kdata, data);
1007 ret = compat_ptrace_hbp_set(NT_ARM_HW_WATCH, tsk, num, &kdata);
1009 ret = compat_ptrace_hbp_set(NT_ARM_HW_BREAK, tsk, num, &kdata);
1014 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1016 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1017 compat_ulong_t caddr, compat_ulong_t cdata)
1019 unsigned long addr = caddr;
1020 unsigned long data = cdata;
1021 void __user *datap = compat_ptr(data);
1025 case PTRACE_PEEKUSR:
1026 ret = compat_ptrace_read_user(child, addr, datap);
1029 case PTRACE_POKEUSR:
1030 ret = compat_ptrace_write_user(child, addr, data);
1033 case COMPAT_PTRACE_GETREGS:
1034 ret = copy_regset_to_user(child,
1037 0, sizeof(compat_elf_gregset_t),
1041 case COMPAT_PTRACE_SETREGS:
1042 ret = copy_regset_from_user(child,
1045 0, sizeof(compat_elf_gregset_t),
1049 case COMPAT_PTRACE_GET_THREAD_AREA:
1050 ret = put_user((compat_ulong_t)child->thread.tp_value,
1051 (compat_ulong_t __user *)datap);
1054 case COMPAT_PTRACE_SET_SYSCALL:
1055 task_pt_regs(child)->syscallno = data;
1059 case COMPAT_PTRACE_GETVFPREGS:
1060 ret = copy_regset_to_user(child,
1067 case COMPAT_PTRACE_SETVFPREGS:
1068 ret = copy_regset_from_user(child,
1075 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1076 case COMPAT_PTRACE_GETHBPREGS:
1077 ret = compat_ptrace_gethbpregs(child, addr, datap);
1080 case COMPAT_PTRACE_SETHBPREGS:
1081 ret = compat_ptrace_sethbpregs(child, addr, datap);
1086 ret = compat_ptrace_request(child, request, addr,
1093 #endif /* CONFIG_COMPAT */
1095 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1097 #ifdef CONFIG_COMPAT
1098 if (is_compat_thread(task_thread_info(task)))
1099 return &user_aarch32_view;
1101 return &user_aarch64_view;
1104 long arch_ptrace(struct task_struct *child, long request,
1105 unsigned long addr, unsigned long data)
1107 return ptrace_request(child, request, addr, data);
1111 static int __init ptrace_break_init(void)
1113 hook_debug_fault_code(DBG_ESR_EVT_BRK, arm64_break_trap, SIGTRAP,
1114 TRAP_BRKPT, "ptrace BRK handler");
1117 core_initcall(ptrace_break_init);
1120 asmlinkage int syscall_trace(int dir, struct pt_regs *regs)
1122 unsigned long saved_reg;
1124 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1125 return regs->syscallno;
1127 if (is_compat_task()) {
1128 /* AArch32 uses ip (r12) for scratch */
1129 saved_reg = regs->regs[12];
1130 regs->regs[12] = dir;
1133 * Save X7. X7 is used to denote syscall entry/exit:
1134 * X7 = 0 -> entry, = 1 -> exit
1136 saved_reg = regs->regs[7];
1137 regs->regs[7] = dir;
1141 tracehook_report_syscall_exit(regs, 0);
1142 else if (tracehook_report_syscall_entry(regs))
1143 regs->syscallno = ~0UL;
1145 if (is_compat_task())
1146 regs->regs[12] = saved_reg;
1148 regs->regs[7] = saved_reg;
1150 return regs->syscallno;