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;
107 for (i = 0; i < ARM_MAX_WRP; ++i) {
108 if (current->thread.debug.hbp_watch[i] == bp) {
109 info.si_errno = -((i << 1) + 1);
116 force_sig_info(SIGTRAP, &info, current);
120 * Unregister breakpoints from this task and reset the pointers in
123 void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
126 struct thread_struct *t = &tsk->thread;
128 for (i = 0; i < ARM_MAX_BRP; i++) {
129 if (t->debug.hbp_break[i]) {
130 unregister_hw_breakpoint(t->debug.hbp_break[i]);
131 t->debug.hbp_break[i] = NULL;
135 for (i = 0; i < ARM_MAX_WRP; i++) {
136 if (t->debug.hbp_watch[i]) {
137 unregister_hw_breakpoint(t->debug.hbp_watch[i]);
138 t->debug.hbp_watch[i] = NULL;
143 void ptrace_hw_copy_thread(struct task_struct *tsk)
145 memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
148 static struct perf_event *ptrace_hbp_get_event(unsigned int note_type,
149 struct task_struct *tsk,
152 struct perf_event *bp = ERR_PTR(-EINVAL);
155 case NT_ARM_HW_BREAK:
156 if (idx < ARM_MAX_BRP)
157 bp = tsk->thread.debug.hbp_break[idx];
159 case NT_ARM_HW_WATCH:
160 if (idx < ARM_MAX_WRP)
161 bp = tsk->thread.debug.hbp_watch[idx];
168 static int ptrace_hbp_set_event(unsigned int note_type,
169 struct task_struct *tsk,
171 struct perf_event *bp)
176 case NT_ARM_HW_BREAK:
177 if (idx < ARM_MAX_BRP) {
178 tsk->thread.debug.hbp_break[idx] = bp;
182 case NT_ARM_HW_WATCH:
183 if (idx < ARM_MAX_WRP) {
184 tsk->thread.debug.hbp_watch[idx] = bp;
193 static struct perf_event *ptrace_hbp_create(unsigned int note_type,
194 struct task_struct *tsk,
197 struct perf_event *bp;
198 struct perf_event_attr attr;
202 case NT_ARM_HW_BREAK:
203 type = HW_BREAKPOINT_X;
205 case NT_ARM_HW_WATCH:
206 type = HW_BREAKPOINT_RW;
209 return ERR_PTR(-EINVAL);
212 ptrace_breakpoint_init(&attr);
215 * Initialise fields to sane defaults
216 * (i.e. values that will pass validation).
219 attr.bp_len = HW_BREAKPOINT_LEN_4;
223 bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk);
227 err = ptrace_hbp_set_event(note_type, tsk, idx, bp);
234 static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
235 struct arch_hw_breakpoint_ctrl ctrl,
236 struct perf_event_attr *attr)
238 int err, len, type, disabled = !ctrl.enabled;
240 attr->disabled = disabled;
244 err = arch_bp_generic_fields(ctrl, &len, &type);
249 case NT_ARM_HW_BREAK:
250 if ((type & HW_BREAKPOINT_X) != type)
253 case NT_ARM_HW_WATCH:
254 if ((type & HW_BREAKPOINT_RW) != type)
262 attr->bp_type = type;
267 static int ptrace_hbp_get_resource_info(unsigned int note_type, u32 *info)
273 case NT_ARM_HW_BREAK:
274 num = hw_breakpoint_slots(TYPE_INST);
276 case NT_ARM_HW_WATCH:
277 num = hw_breakpoint_slots(TYPE_DATA);
283 reg |= debug_monitors_arch();
291 static int ptrace_hbp_get_ctrl(unsigned int note_type,
292 struct task_struct *tsk,
296 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
301 *ctrl = bp ? encode_ctrl_reg(counter_arch_bp(bp)->ctrl) : 0;
305 static int ptrace_hbp_get_addr(unsigned int note_type,
306 struct task_struct *tsk,
310 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
315 *addr = bp ? bp->attr.bp_addr : 0;
319 static struct perf_event *ptrace_hbp_get_initialised_bp(unsigned int note_type,
320 struct task_struct *tsk,
323 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
326 bp = ptrace_hbp_create(note_type, tsk, idx);
331 static int ptrace_hbp_set_ctrl(unsigned int note_type,
332 struct task_struct *tsk,
337 struct perf_event *bp;
338 struct perf_event_attr attr;
339 struct arch_hw_breakpoint_ctrl ctrl;
341 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
348 decode_ctrl_reg(uctrl, &ctrl);
349 err = ptrace_hbp_fill_attr_ctrl(note_type, ctrl, &attr);
353 return modify_user_hw_breakpoint(bp, &attr);
356 static int ptrace_hbp_set_addr(unsigned int note_type,
357 struct task_struct *tsk,
362 struct perf_event *bp;
363 struct perf_event_attr attr;
365 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
373 err = modify_user_hw_breakpoint(bp, &attr);
377 #define PTRACE_HBP_ADDR_SZ sizeof(u64)
378 #define PTRACE_HBP_CTRL_SZ sizeof(u32)
379 #define PTRACE_HBP_PAD_SZ sizeof(u32)
381 static int hw_break_get(struct task_struct *target,
382 const struct user_regset *regset,
383 unsigned int pos, unsigned int count,
384 void *kbuf, void __user *ubuf)
386 unsigned int note_type = regset->core_note_type;
387 int ret, idx = 0, offset, limit;
392 ret = ptrace_hbp_get_resource_info(note_type, &info);
396 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &info, 0,
402 offset = offsetof(struct user_hwdebug_state, pad);
403 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, offset,
404 offset + PTRACE_HBP_PAD_SZ);
408 /* (address, ctrl) registers */
409 offset = offsetof(struct user_hwdebug_state, dbg_regs);
410 limit = regset->n * regset->size;
411 while (count && offset < limit) {
412 ret = ptrace_hbp_get_addr(note_type, target, idx, &addr);
415 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &addr,
416 offset, offset + PTRACE_HBP_ADDR_SZ);
419 offset += PTRACE_HBP_ADDR_SZ;
421 ret = ptrace_hbp_get_ctrl(note_type, target, idx, &ctrl);
424 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &ctrl,
425 offset, offset + PTRACE_HBP_CTRL_SZ);
428 offset += PTRACE_HBP_CTRL_SZ;
430 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
432 offset + PTRACE_HBP_PAD_SZ);
435 offset += PTRACE_HBP_PAD_SZ;
442 static int hw_break_set(struct task_struct *target,
443 const struct user_regset *regset,
444 unsigned int pos, unsigned int count,
445 const void *kbuf, const void __user *ubuf)
447 unsigned int note_type = regset->core_note_type;
448 int ret, idx = 0, offset, limit;
452 /* Resource info and pad */
453 offset = offsetof(struct user_hwdebug_state, dbg_regs);
454 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 0, offset);
458 /* (address, ctrl) registers */
459 limit = regset->n * regset->size;
460 while (count && offset < limit) {
461 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &addr,
462 offset, offset + PTRACE_HBP_ADDR_SZ);
465 ret = ptrace_hbp_set_addr(note_type, target, idx, addr);
468 offset += PTRACE_HBP_ADDR_SZ;
470 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl,
471 offset, offset + PTRACE_HBP_CTRL_SZ);
474 ret = ptrace_hbp_set_ctrl(note_type, target, idx, ctrl);
477 offset += PTRACE_HBP_CTRL_SZ;
479 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
481 offset + PTRACE_HBP_PAD_SZ);
484 offset += PTRACE_HBP_PAD_SZ;
490 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
492 static int gpr_get(struct task_struct *target,
493 const struct user_regset *regset,
494 unsigned int pos, unsigned int count,
495 void *kbuf, void __user *ubuf)
497 struct user_pt_regs *uregs = &task_pt_regs(target)->user_regs;
498 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
501 static int gpr_set(struct task_struct *target, const struct user_regset *regset,
502 unsigned int pos, unsigned int count,
503 const void *kbuf, const void __user *ubuf)
506 struct user_pt_regs newregs;
508 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newregs, 0, -1);
512 if (!valid_user_regs(&newregs))
515 task_pt_regs(target)->user_regs = newregs;
520 * TODO: update fp accessors for lazy context switching (sync/flush hwstate)
522 static int fpr_get(struct task_struct *target, const struct user_regset *regset,
523 unsigned int pos, unsigned int count,
524 void *kbuf, void __user *ubuf)
526 struct user_fpsimd_state *uregs;
527 uregs = &target->thread.fpsimd_state.user_fpsimd;
528 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
531 static int fpr_set(struct task_struct *target, const struct user_regset *regset,
532 unsigned int pos, unsigned int count,
533 const void *kbuf, const void __user *ubuf)
536 struct user_fpsimd_state newstate;
538 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate, 0, -1);
542 target->thread.fpsimd_state.user_fpsimd = newstate;
546 static int tls_get(struct task_struct *target, const struct user_regset *regset,
547 unsigned int pos, unsigned int count,
548 void *kbuf, void __user *ubuf)
550 unsigned long *tls = &target->thread.tp_value;
551 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, tls, 0, -1);
554 static int tls_set(struct task_struct *target, const struct user_regset *regset,
555 unsigned int pos, unsigned int count,
556 const void *kbuf, const void __user *ubuf)
561 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &tls, 0, -1);
565 target->thread.tp_value = tls;
569 enum aarch64_regset {
573 #ifdef CONFIG_HAVE_HW_BREAKPOINT
579 static const struct user_regset aarch64_regsets[] = {
581 .core_note_type = NT_PRSTATUS,
582 .n = sizeof(struct user_pt_regs) / sizeof(u64),
584 .align = sizeof(u64),
589 .core_note_type = NT_PRFPREG,
590 .n = sizeof(struct user_fpsimd_state) / sizeof(u32),
592 * We pretend we have 32-bit registers because the fpsr and
593 * fpcr are 32-bits wide.
596 .align = sizeof(u32),
601 .core_note_type = NT_ARM_TLS,
603 .size = sizeof(void *),
604 .align = sizeof(void *),
608 #ifdef CONFIG_HAVE_HW_BREAKPOINT
609 [REGSET_HW_BREAK] = {
610 .core_note_type = NT_ARM_HW_BREAK,
611 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
613 .align = sizeof(u32),
617 [REGSET_HW_WATCH] = {
618 .core_note_type = NT_ARM_HW_WATCH,
619 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
621 .align = sizeof(u32),
628 static const struct user_regset_view user_aarch64_view = {
629 .name = "aarch64", .e_machine = EM_AARCH64,
630 .regsets = aarch64_regsets, .n = ARRAY_SIZE(aarch64_regsets)
634 #include <linux/compat.h>
641 static int compat_gpr_get(struct task_struct *target,
642 const struct user_regset *regset,
643 unsigned int pos, unsigned int count,
644 void *kbuf, void __user *ubuf)
647 unsigned int i, start, num_regs;
649 /* Calculate the number of AArch32 registers contained in count */
650 num_regs = count / regset->size;
652 /* Convert pos into an register number */
653 start = pos / regset->size;
655 if (start + num_regs > regset->n)
658 for (i = 0; i < num_regs; ++i) {
659 unsigned int idx = start + i;
664 reg = (void *)&task_pt_regs(target)->pc;
667 reg = (void *)&task_pt_regs(target)->pstate;
670 reg = (void *)&task_pt_regs(target)->orig_x0;
673 reg = (void *)&task_pt_regs(target)->regs[idx];
676 ret = copy_to_user(ubuf, reg, sizeof(compat_ulong_t));
681 ubuf += sizeof(compat_ulong_t);
687 static int compat_gpr_set(struct task_struct *target,
688 const struct user_regset *regset,
689 unsigned int pos, unsigned int count,
690 const void *kbuf, const void __user *ubuf)
692 struct pt_regs newregs;
694 unsigned int i, start, num_regs;
696 /* Calculate the number of AArch32 registers contained in count */
697 num_regs = count / regset->size;
699 /* Convert pos into an register number */
700 start = pos / regset->size;
702 if (start + num_regs > regset->n)
705 newregs = *task_pt_regs(target);
707 for (i = 0; i < num_regs; ++i) {
708 unsigned int idx = start + i;
713 reg = (void *)&newregs.pc;
716 reg = (void *)&newregs.pstate;
719 reg = (void *)&newregs.orig_x0;
722 reg = (void *)&newregs.regs[idx];
725 ret = copy_from_user(reg, ubuf, sizeof(compat_ulong_t));
730 ubuf += sizeof(compat_ulong_t);
733 if (valid_user_regs(&newregs.user_regs))
734 *task_pt_regs(target) = newregs;
742 static int compat_vfp_get(struct task_struct *target,
743 const struct user_regset *regset,
744 unsigned int pos, unsigned int count,
745 void *kbuf, void __user *ubuf)
747 struct user_fpsimd_state *uregs;
748 compat_ulong_t fpscr;
751 uregs = &target->thread.fpsimd_state.user_fpsimd;
754 * The VFP registers are packed into the fpsimd_state, so they all sit
755 * nicely together for us. We just need to create the fpscr separately.
757 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
758 VFP_STATE_SIZE - sizeof(compat_ulong_t));
761 fpscr = (uregs->fpsr & VFP_FPSCR_STAT_MASK) |
762 (uregs->fpcr & VFP_FPSCR_CTRL_MASK);
763 ret = put_user(fpscr, (compat_ulong_t *)ubuf);
769 static int compat_vfp_set(struct task_struct *target,
770 const struct user_regset *regset,
771 unsigned int pos, unsigned int count,
772 const void *kbuf, const void __user *ubuf)
774 struct user_fpsimd_state *uregs;
775 compat_ulong_t fpscr;
778 if (pos + count > VFP_STATE_SIZE)
781 uregs = &target->thread.fpsimd_state.user_fpsimd;
783 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
784 VFP_STATE_SIZE - sizeof(compat_ulong_t));
787 ret = get_user(fpscr, (compat_ulong_t *)ubuf);
788 uregs->fpsr = fpscr & VFP_FPSCR_STAT_MASK;
789 uregs->fpcr = fpscr & VFP_FPSCR_CTRL_MASK;
795 static const struct user_regset aarch32_regsets[] = {
796 [REGSET_COMPAT_GPR] = {
797 .core_note_type = NT_PRSTATUS,
798 .n = COMPAT_ELF_NGREG,
799 .size = sizeof(compat_elf_greg_t),
800 .align = sizeof(compat_elf_greg_t),
801 .get = compat_gpr_get,
802 .set = compat_gpr_set
804 [REGSET_COMPAT_VFP] = {
805 .core_note_type = NT_ARM_VFP,
806 .n = VFP_STATE_SIZE / sizeof(compat_ulong_t),
807 .size = sizeof(compat_ulong_t),
808 .align = sizeof(compat_ulong_t),
809 .get = compat_vfp_get,
810 .set = compat_vfp_set
814 static const struct user_regset_view user_aarch32_view = {
815 .name = "aarch32", .e_machine = EM_ARM,
816 .regsets = aarch32_regsets, .n = ARRAY_SIZE(aarch32_regsets)
819 int aarch32_break_trap(struct pt_regs *regs)
823 void __user *pc = (void __user *)instruction_pointer(regs);
825 if (compat_thumb_mode(regs)) {
826 /* get 16-bit Thumb instruction */
827 get_user(instr, (u16 __user *)pc);
828 if (instr == AARCH32_BREAK_THUMB2_LO) {
829 /* get second half of 32-bit Thumb-2 instruction */
830 get_user(instr, (u16 __user *)(pc + 2));
831 bp = instr == AARCH32_BREAK_THUMB2_HI;
833 bp = instr == AARCH32_BREAK_THUMB;
836 /* 32-bit ARM instruction */
837 get_user(instr, (u32 __user *)pc);
838 bp = (instr & ~0xf0000000) == AARCH32_BREAK_ARM;
842 return ptrace_break(regs);
846 static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,
847 compat_ulong_t __user *ret)
854 if (off == COMPAT_PT_TEXT_ADDR)
855 tmp = tsk->mm->start_code;
856 else if (off == COMPAT_PT_DATA_ADDR)
857 tmp = tsk->mm->start_data;
858 else if (off == COMPAT_PT_TEXT_END_ADDR)
859 tmp = tsk->mm->end_code;
860 else if (off < sizeof(compat_elf_gregset_t))
861 return copy_regset_to_user(tsk, &user_aarch32_view,
862 REGSET_COMPAT_GPR, off,
863 sizeof(compat_ulong_t), ret);
864 else if (off >= COMPAT_USER_SZ)
869 return put_user(tmp, ret);
872 static int compat_ptrace_write_user(struct task_struct *tsk, compat_ulong_t off,
876 mm_segment_t old_fs = get_fs();
878 if (off & 3 || off >= COMPAT_USER_SZ)
881 if (off >= sizeof(compat_elf_gregset_t))
885 ret = copy_regset_from_user(tsk, &user_aarch32_view,
886 REGSET_COMPAT_GPR, off,
887 sizeof(compat_ulong_t),
894 #ifdef CONFIG_HAVE_HW_BREAKPOINT
897 * Convert a virtual register number into an index for a thread_info
898 * breakpoint array. Breakpoints are identified using positive numbers
899 * whilst watchpoints are negative. The registers are laid out as pairs
900 * of (address, control), each pair mapping to a unique hw_breakpoint struct.
901 * Register 0 is reserved for describing resource information.
903 static int compat_ptrace_hbp_num_to_idx(compat_long_t num)
905 return (abs(num) - 1) >> 1;
908 static int compat_ptrace_hbp_get_resource_info(u32 *kdata)
910 u8 num_brps, num_wrps, debug_arch, wp_len;
913 num_brps = hw_breakpoint_slots(TYPE_INST);
914 num_wrps = hw_breakpoint_slots(TYPE_DATA);
916 debug_arch = debug_monitors_arch();
930 static int compat_ptrace_hbp_get(unsigned int note_type,
931 struct task_struct *tsk,
938 int err, idx = compat_ptrace_hbp_num_to_idx(num);;
941 err = ptrace_hbp_get_addr(note_type, tsk, idx, &addr);
944 err = ptrace_hbp_get_ctrl(note_type, tsk, idx, &ctrl);
951 static int compat_ptrace_hbp_set(unsigned int note_type,
952 struct task_struct *tsk,
959 int err, idx = compat_ptrace_hbp_num_to_idx(num);
963 err = ptrace_hbp_set_addr(note_type, tsk, idx, addr);
966 err = ptrace_hbp_set_ctrl(note_type, tsk, idx, ctrl);
972 static int compat_ptrace_gethbpregs(struct task_struct *tsk, compat_long_t num,
973 compat_ulong_t __user *data)
977 mm_segment_t old_fs = get_fs();
982 ret = compat_ptrace_hbp_get(NT_ARM_HW_WATCH, tsk, num, &kdata);
984 } else if (num == 0) {
985 ret = compat_ptrace_hbp_get_resource_info(&kdata);
988 ret = compat_ptrace_hbp_get(NT_ARM_HW_BREAK, tsk, num, &kdata);
993 ret = put_user(kdata, data);
998 static int compat_ptrace_sethbpregs(struct task_struct *tsk, compat_long_t num,
999 compat_ulong_t __user *data)
1003 mm_segment_t old_fs = get_fs();
1008 ret = get_user(kdata, data);
1014 ret = compat_ptrace_hbp_set(NT_ARM_HW_WATCH, tsk, num, &kdata);
1016 ret = compat_ptrace_hbp_set(NT_ARM_HW_BREAK, tsk, num, &kdata);
1021 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1023 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1024 compat_ulong_t caddr, compat_ulong_t cdata)
1026 unsigned long addr = caddr;
1027 unsigned long data = cdata;
1028 void __user *datap = compat_ptr(data);
1032 case PTRACE_PEEKUSR:
1033 ret = compat_ptrace_read_user(child, addr, datap);
1036 case PTRACE_POKEUSR:
1037 ret = compat_ptrace_write_user(child, addr, data);
1040 case COMPAT_PTRACE_GETREGS:
1041 ret = copy_regset_to_user(child,
1044 0, sizeof(compat_elf_gregset_t),
1048 case COMPAT_PTRACE_SETREGS:
1049 ret = copy_regset_from_user(child,
1052 0, sizeof(compat_elf_gregset_t),
1056 case COMPAT_PTRACE_GET_THREAD_AREA:
1057 ret = put_user((compat_ulong_t)child->thread.tp_value,
1058 (compat_ulong_t __user *)datap);
1061 case COMPAT_PTRACE_SET_SYSCALL:
1062 task_pt_regs(child)->syscallno = data;
1066 case COMPAT_PTRACE_GETVFPREGS:
1067 ret = copy_regset_to_user(child,
1074 case COMPAT_PTRACE_SETVFPREGS:
1075 ret = copy_regset_from_user(child,
1082 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1083 case COMPAT_PTRACE_GETHBPREGS:
1084 ret = compat_ptrace_gethbpregs(child, addr, datap);
1087 case COMPAT_PTRACE_SETHBPREGS:
1088 ret = compat_ptrace_sethbpregs(child, addr, datap);
1093 ret = compat_ptrace_request(child, request, addr,
1100 #endif /* CONFIG_COMPAT */
1102 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1104 #ifdef CONFIG_COMPAT
1105 if (is_compat_thread(task_thread_info(task)))
1106 return &user_aarch32_view;
1108 return &user_aarch64_view;
1111 long arch_ptrace(struct task_struct *child, long request,
1112 unsigned long addr, unsigned long data)
1114 return ptrace_request(child, request, addr, data);
1118 static int __init ptrace_break_init(void)
1120 hook_debug_fault_code(DBG_ESR_EVT_BRK, arm64_break_trap, SIGTRAP,
1121 TRAP_BRKPT, "ptrace BRK handler");
1124 core_initcall(ptrace_break_init);
1127 asmlinkage int syscall_trace(int dir, struct pt_regs *regs)
1129 unsigned long saved_reg;
1131 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1132 return regs->syscallno;
1134 if (is_compat_task()) {
1135 /* AArch32 uses ip (r12) for scratch */
1136 saved_reg = regs->regs[12];
1137 regs->regs[12] = dir;
1140 * Save X7. X7 is used to denote syscall entry/exit:
1141 * X7 = 0 -> entry, = 1 -> exit
1143 saved_reg = regs->regs[7];
1144 regs->regs[7] = dir;
1148 tracehook_report_syscall_exit(regs, 0);
1149 else if (tracehook_report_syscall_entry(regs))
1150 regs->syscallno = ~0UL;
1152 if (is_compat_task())
1153 regs->regs[12] = saved_reg;
1155 regs->regs[7] = saved_reg;
1157 return regs->syscallno;