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/audit.h>
23 #include <linux/compat.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
27 #include <linux/smp.h>
28 #include <linux/ptrace.h>
29 #include <linux/user.h>
30 #include <linux/seccomp.h>
31 #include <linux/security.h>
32 #include <linux/init.h>
33 #include <linux/signal.h>
34 #include <linux/uaccess.h>
35 #include <linux/perf_event.h>
36 #include <linux/hw_breakpoint.h>
37 #include <linux/regset.h>
38 #include <linux/tracehook.h>
39 #include <linux/elf.h>
41 #include <asm/compat.h>
42 #include <asm/debug-monitors.h>
43 #include <asm/pgtable.h>
44 #include <asm/syscall.h>
45 #include <asm/traps.h>
46 #include <asm/system_misc.h>
48 #define CREATE_TRACE_POINTS
49 #include <trace/events/syscalls.h>
52 * TODO: does not yet catch signals sent when the child dies.
53 * in exit.c or in signal.c.
57 * Called by kernel/ptrace.c when detaching..
59 void ptrace_disable(struct task_struct *child)
63 #ifdef CONFIG_HAVE_HW_BREAKPOINT
65 * Handle hitting a HW-breakpoint.
67 static void ptrace_hbptriggered(struct perf_event *bp,
68 struct perf_sample_data *data,
71 struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
75 .si_code = TRAP_HWBKPT,
76 .si_addr = (void __user *)(bkpt->trigger),
82 if (!is_compat_task())
85 for (i = 0; i < ARM_MAX_BRP; ++i) {
86 if (current->thread.debug.hbp_break[i] == bp) {
87 info.si_errno = (i << 1) + 1;
92 for (i = 0; i < ARM_MAX_WRP; ++i) {
93 if (current->thread.debug.hbp_watch[i] == bp) {
94 info.si_errno = -((i << 1) + 1);
101 force_sig_info(SIGTRAP, &info, current);
105 * Unregister breakpoints from this task and reset the pointers in
108 void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
111 struct thread_struct *t = &tsk->thread;
113 for (i = 0; i < ARM_MAX_BRP; i++) {
114 if (t->debug.hbp_break[i]) {
115 unregister_hw_breakpoint(t->debug.hbp_break[i]);
116 t->debug.hbp_break[i] = NULL;
120 for (i = 0; i < ARM_MAX_WRP; i++) {
121 if (t->debug.hbp_watch[i]) {
122 unregister_hw_breakpoint(t->debug.hbp_watch[i]);
123 t->debug.hbp_watch[i] = NULL;
128 void ptrace_hw_copy_thread(struct task_struct *tsk)
130 memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
133 static struct perf_event *ptrace_hbp_get_event(unsigned int note_type,
134 struct task_struct *tsk,
137 struct perf_event *bp = ERR_PTR(-EINVAL);
140 case NT_ARM_HW_BREAK:
141 if (idx < ARM_MAX_BRP)
142 bp = tsk->thread.debug.hbp_break[idx];
144 case NT_ARM_HW_WATCH:
145 if (idx < ARM_MAX_WRP)
146 bp = tsk->thread.debug.hbp_watch[idx];
153 static int ptrace_hbp_set_event(unsigned int note_type,
154 struct task_struct *tsk,
156 struct perf_event *bp)
161 case NT_ARM_HW_BREAK:
162 if (idx < ARM_MAX_BRP) {
163 tsk->thread.debug.hbp_break[idx] = bp;
167 case NT_ARM_HW_WATCH:
168 if (idx < ARM_MAX_WRP) {
169 tsk->thread.debug.hbp_watch[idx] = bp;
178 static struct perf_event *ptrace_hbp_create(unsigned int note_type,
179 struct task_struct *tsk,
182 struct perf_event *bp;
183 struct perf_event_attr attr;
187 case NT_ARM_HW_BREAK:
188 type = HW_BREAKPOINT_X;
190 case NT_ARM_HW_WATCH:
191 type = HW_BREAKPOINT_RW;
194 return ERR_PTR(-EINVAL);
197 ptrace_breakpoint_init(&attr);
200 * Initialise fields to sane defaults
201 * (i.e. values that will pass validation).
204 attr.bp_len = HW_BREAKPOINT_LEN_4;
208 bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk);
212 err = ptrace_hbp_set_event(note_type, tsk, idx, bp);
219 static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
220 struct arch_hw_breakpoint_ctrl ctrl,
221 struct perf_event_attr *attr)
223 int err, len, type, disabled = !ctrl.enabled;
225 attr->disabled = disabled;
229 err = arch_bp_generic_fields(ctrl, &len, &type);
234 case NT_ARM_HW_BREAK:
235 if ((type & HW_BREAKPOINT_X) != type)
238 case NT_ARM_HW_WATCH:
239 if ((type & HW_BREAKPOINT_RW) != type)
247 attr->bp_type = type;
252 static int ptrace_hbp_get_resource_info(unsigned int note_type, u32 *info)
258 case NT_ARM_HW_BREAK:
259 num = hw_breakpoint_slots(TYPE_INST);
261 case NT_ARM_HW_WATCH:
262 num = hw_breakpoint_slots(TYPE_DATA);
268 reg |= debug_monitors_arch();
276 static int ptrace_hbp_get_ctrl(unsigned int note_type,
277 struct task_struct *tsk,
281 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
286 *ctrl = bp ? encode_ctrl_reg(counter_arch_bp(bp)->ctrl) : 0;
290 static int ptrace_hbp_get_addr(unsigned int note_type,
291 struct task_struct *tsk,
295 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
300 *addr = bp ? bp->attr.bp_addr : 0;
304 static struct perf_event *ptrace_hbp_get_initialised_bp(unsigned int note_type,
305 struct task_struct *tsk,
308 struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
311 bp = ptrace_hbp_create(note_type, tsk, idx);
316 static int ptrace_hbp_set_ctrl(unsigned int note_type,
317 struct task_struct *tsk,
322 struct perf_event *bp;
323 struct perf_event_attr attr;
324 struct arch_hw_breakpoint_ctrl ctrl;
326 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
333 decode_ctrl_reg(uctrl, &ctrl);
334 err = ptrace_hbp_fill_attr_ctrl(note_type, ctrl, &attr);
338 return modify_user_hw_breakpoint(bp, &attr);
341 static int ptrace_hbp_set_addr(unsigned int note_type,
342 struct task_struct *tsk,
347 struct perf_event *bp;
348 struct perf_event_attr attr;
350 bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
358 err = modify_user_hw_breakpoint(bp, &attr);
362 #define PTRACE_HBP_ADDR_SZ sizeof(u64)
363 #define PTRACE_HBP_CTRL_SZ sizeof(u32)
364 #define PTRACE_HBP_PAD_SZ sizeof(u32)
366 static int hw_break_get(struct task_struct *target,
367 const struct user_regset *regset,
368 unsigned int pos, unsigned int count,
369 void *kbuf, void __user *ubuf)
371 unsigned int note_type = regset->core_note_type;
372 int ret, idx = 0, offset, limit;
377 ret = ptrace_hbp_get_resource_info(note_type, &info);
381 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &info, 0,
387 offset = offsetof(struct user_hwdebug_state, pad);
388 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, offset,
389 offset + PTRACE_HBP_PAD_SZ);
393 /* (address, ctrl) registers */
394 offset = offsetof(struct user_hwdebug_state, dbg_regs);
395 limit = regset->n * regset->size;
396 while (count && offset < limit) {
397 ret = ptrace_hbp_get_addr(note_type, target, idx, &addr);
400 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &addr,
401 offset, offset + PTRACE_HBP_ADDR_SZ);
404 offset += PTRACE_HBP_ADDR_SZ;
406 ret = ptrace_hbp_get_ctrl(note_type, target, idx, &ctrl);
409 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &ctrl,
410 offset, offset + PTRACE_HBP_CTRL_SZ);
413 offset += PTRACE_HBP_CTRL_SZ;
415 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
417 offset + PTRACE_HBP_PAD_SZ);
420 offset += PTRACE_HBP_PAD_SZ;
427 static int hw_break_set(struct task_struct *target,
428 const struct user_regset *regset,
429 unsigned int pos, unsigned int count,
430 const void *kbuf, const void __user *ubuf)
432 unsigned int note_type = regset->core_note_type;
433 int ret, idx = 0, offset, limit;
437 /* Resource info and pad */
438 offset = offsetof(struct user_hwdebug_state, dbg_regs);
439 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 0, offset);
443 /* (address, ctrl) registers */
444 limit = regset->n * regset->size;
445 while (count && offset < limit) {
446 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &addr,
447 offset, offset + PTRACE_HBP_ADDR_SZ);
450 ret = ptrace_hbp_set_addr(note_type, target, idx, addr);
453 offset += PTRACE_HBP_ADDR_SZ;
455 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl,
456 offset, offset + PTRACE_HBP_CTRL_SZ);
459 ret = ptrace_hbp_set_ctrl(note_type, target, idx, ctrl);
462 offset += PTRACE_HBP_CTRL_SZ;
464 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
466 offset + PTRACE_HBP_PAD_SZ);
469 offset += PTRACE_HBP_PAD_SZ;
475 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
477 static int gpr_get(struct task_struct *target,
478 const struct user_regset *regset,
479 unsigned int pos, unsigned int count,
480 void *kbuf, void __user *ubuf)
482 struct user_pt_regs *uregs = &task_pt_regs(target)->user_regs;
483 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
486 static int gpr_set(struct task_struct *target, const struct user_regset *regset,
487 unsigned int pos, unsigned int count,
488 const void *kbuf, const void __user *ubuf)
491 struct user_pt_regs newregs;
493 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newregs, 0, -1);
497 if (!valid_user_regs(&newregs))
500 task_pt_regs(target)->user_regs = newregs;
505 * TODO: update fp accessors for lazy context switching (sync/flush hwstate)
507 static int fpr_get(struct task_struct *target, const struct user_regset *regset,
508 unsigned int pos, unsigned int count,
509 void *kbuf, void __user *ubuf)
511 struct user_fpsimd_state *uregs;
512 uregs = &target->thread.fpsimd_state.user_fpsimd;
513 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
516 static int fpr_set(struct task_struct *target, const struct user_regset *regset,
517 unsigned int pos, unsigned int count,
518 const void *kbuf, const void __user *ubuf)
521 struct user_fpsimd_state newstate;
523 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate, 0, -1);
527 target->thread.fpsimd_state.user_fpsimd = newstate;
528 fpsimd_flush_task_state(target);
532 static int tls_get(struct task_struct *target, const struct user_regset *regset,
533 unsigned int pos, unsigned int count,
534 void *kbuf, void __user *ubuf)
536 unsigned long *tls = &target->thread.tp_value;
537 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, tls, 0, -1);
540 static int tls_set(struct task_struct *target, const struct user_regset *regset,
541 unsigned int pos, unsigned int count,
542 const void *kbuf, const void __user *ubuf)
547 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &tls, 0, -1);
551 target->thread.tp_value = tls;
555 static int system_call_get(struct task_struct *target,
556 const struct user_regset *regset,
557 unsigned int pos, unsigned int count,
558 void *kbuf, void __user *ubuf)
560 int syscallno = task_pt_regs(target)->syscallno;
562 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
566 static int system_call_set(struct task_struct *target,
567 const struct user_regset *regset,
568 unsigned int pos, unsigned int count,
569 const void *kbuf, const void __user *ubuf)
573 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &syscallno, 0, -1);
577 task_pt_regs(target)->syscallno = syscallno;
581 enum aarch64_regset {
585 #ifdef CONFIG_HAVE_HW_BREAKPOINT
592 static const struct user_regset aarch64_regsets[] = {
594 .core_note_type = NT_PRSTATUS,
595 .n = sizeof(struct user_pt_regs) / sizeof(u64),
597 .align = sizeof(u64),
602 .core_note_type = NT_PRFPREG,
603 .n = sizeof(struct user_fpsimd_state) / sizeof(u32),
605 * We pretend we have 32-bit registers because the fpsr and
606 * fpcr are 32-bits wide.
609 .align = sizeof(u32),
614 .core_note_type = NT_ARM_TLS,
616 .size = sizeof(void *),
617 .align = sizeof(void *),
621 #ifdef CONFIG_HAVE_HW_BREAKPOINT
622 [REGSET_HW_BREAK] = {
623 .core_note_type = NT_ARM_HW_BREAK,
624 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
626 .align = sizeof(u32),
630 [REGSET_HW_WATCH] = {
631 .core_note_type = NT_ARM_HW_WATCH,
632 .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
634 .align = sizeof(u32),
639 [REGSET_SYSTEM_CALL] = {
640 .core_note_type = NT_ARM_SYSTEM_CALL,
643 .align = sizeof(int),
644 .get = system_call_get,
645 .set = system_call_set,
649 static const struct user_regset_view user_aarch64_view = {
650 .name = "aarch64", .e_machine = EM_AARCH64,
651 .regsets = aarch64_regsets, .n = ARRAY_SIZE(aarch64_regsets)
655 #include <linux/compat.h>
662 static int compat_gpr_get(struct task_struct *target,
663 const struct user_regset *regset,
664 unsigned int pos, unsigned int count,
665 void *kbuf, void __user *ubuf)
668 unsigned int i, start, num_regs;
670 /* Calculate the number of AArch32 registers contained in count */
671 num_regs = count / regset->size;
673 /* Convert pos into an register number */
674 start = pos / regset->size;
676 if (start + num_regs > regset->n)
679 for (i = 0; i < num_regs; ++i) {
680 unsigned int idx = start + i;
685 reg = task_pt_regs(target)->pc;
688 reg = task_pt_regs(target)->pstate;
691 reg = task_pt_regs(target)->orig_x0;
694 reg = task_pt_regs(target)->regs[idx];
698 memcpy(kbuf, ®, sizeof(reg));
701 ret = copy_to_user(ubuf, ®, sizeof(reg));
714 static int compat_gpr_set(struct task_struct *target,
715 const struct user_regset *regset,
716 unsigned int pos, unsigned int count,
717 const void *kbuf, const void __user *ubuf)
719 struct pt_regs newregs;
721 unsigned int i, start, num_regs;
723 /* Calculate the number of AArch32 registers contained in count */
724 num_regs = count / regset->size;
726 /* Convert pos into an register number */
727 start = pos / regset->size;
729 if (start + num_regs > regset->n)
732 newregs = *task_pt_regs(target);
734 for (i = 0; i < num_regs; ++i) {
735 unsigned int idx = start + i;
739 memcpy(®, kbuf, sizeof(reg));
742 ret = copy_from_user(®, ubuf, sizeof(reg));
756 newregs.pstate = reg;
759 newregs.orig_x0 = reg;
762 newregs.regs[idx] = reg;
767 if (valid_user_regs(&newregs.user_regs))
768 *task_pt_regs(target) = newregs;
775 static int compat_vfp_get(struct task_struct *target,
776 const struct user_regset *regset,
777 unsigned int pos, unsigned int count,
778 void *kbuf, void __user *ubuf)
780 struct user_fpsimd_state *uregs;
781 compat_ulong_t fpscr;
784 uregs = &target->thread.fpsimd_state.user_fpsimd;
787 * The VFP registers are packed into the fpsimd_state, so they all sit
788 * nicely together for us. We just need to create the fpscr separately.
790 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
791 VFP_STATE_SIZE - sizeof(compat_ulong_t));
794 fpscr = (uregs->fpsr & VFP_FPSCR_STAT_MASK) |
795 (uregs->fpcr & VFP_FPSCR_CTRL_MASK);
796 ret = put_user(fpscr, (compat_ulong_t *)ubuf);
802 static int compat_vfp_set(struct task_struct *target,
803 const struct user_regset *regset,
804 unsigned int pos, unsigned int count,
805 const void *kbuf, const void __user *ubuf)
807 struct user_fpsimd_state *uregs;
808 compat_ulong_t fpscr;
811 if (pos + count > VFP_STATE_SIZE)
814 uregs = &target->thread.fpsimd_state.user_fpsimd;
816 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
817 VFP_STATE_SIZE - sizeof(compat_ulong_t));
820 ret = get_user(fpscr, (compat_ulong_t *)ubuf);
821 uregs->fpsr = fpscr & VFP_FPSCR_STAT_MASK;
822 uregs->fpcr = fpscr & VFP_FPSCR_CTRL_MASK;
825 fpsimd_flush_task_state(target);
829 static const struct user_regset aarch32_regsets[] = {
830 [REGSET_COMPAT_GPR] = {
831 .core_note_type = NT_PRSTATUS,
832 .n = COMPAT_ELF_NGREG,
833 .size = sizeof(compat_elf_greg_t),
834 .align = sizeof(compat_elf_greg_t),
835 .get = compat_gpr_get,
836 .set = compat_gpr_set
838 [REGSET_COMPAT_VFP] = {
839 .core_note_type = NT_ARM_VFP,
840 .n = VFP_STATE_SIZE / sizeof(compat_ulong_t),
841 .size = sizeof(compat_ulong_t),
842 .align = sizeof(compat_ulong_t),
843 .get = compat_vfp_get,
844 .set = compat_vfp_set
848 static const struct user_regset_view user_aarch32_view = {
849 .name = "aarch32", .e_machine = EM_ARM,
850 .regsets = aarch32_regsets, .n = ARRAY_SIZE(aarch32_regsets)
853 static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,
854 compat_ulong_t __user *ret)
861 if (off == COMPAT_PT_TEXT_ADDR)
862 tmp = tsk->mm->start_code;
863 else if (off == COMPAT_PT_DATA_ADDR)
864 tmp = tsk->mm->start_data;
865 else if (off == COMPAT_PT_TEXT_END_ADDR)
866 tmp = tsk->mm->end_code;
867 else if (off < sizeof(compat_elf_gregset_t))
868 return copy_regset_to_user(tsk, &user_aarch32_view,
869 REGSET_COMPAT_GPR, off,
870 sizeof(compat_ulong_t), ret);
871 else if (off >= COMPAT_USER_SZ)
876 return put_user(tmp, ret);
879 static int compat_ptrace_write_user(struct task_struct *tsk, compat_ulong_t off,
883 mm_segment_t old_fs = get_fs();
885 if (off & 3 || off >= COMPAT_USER_SZ)
888 if (off >= sizeof(compat_elf_gregset_t))
892 ret = copy_regset_from_user(tsk, &user_aarch32_view,
893 REGSET_COMPAT_GPR, off,
894 sizeof(compat_ulong_t),
901 #ifdef CONFIG_HAVE_HW_BREAKPOINT
904 * Convert a virtual register number into an index for a thread_info
905 * breakpoint array. Breakpoints are identified using positive numbers
906 * whilst watchpoints are negative. The registers are laid out as pairs
907 * of (address, control), each pair mapping to a unique hw_breakpoint struct.
908 * Register 0 is reserved for describing resource information.
910 static int compat_ptrace_hbp_num_to_idx(compat_long_t num)
912 return (abs(num) - 1) >> 1;
915 static int compat_ptrace_hbp_get_resource_info(u32 *kdata)
917 u8 num_brps, num_wrps, debug_arch, wp_len;
920 num_brps = hw_breakpoint_slots(TYPE_INST);
921 num_wrps = hw_breakpoint_slots(TYPE_DATA);
923 debug_arch = debug_monitors_arch();
937 static int compat_ptrace_hbp_get(unsigned int note_type,
938 struct task_struct *tsk,
945 int err, idx = compat_ptrace_hbp_num_to_idx(num);;
948 err = ptrace_hbp_get_addr(note_type, tsk, idx, &addr);
951 err = ptrace_hbp_get_ctrl(note_type, tsk, idx, &ctrl);
958 static int compat_ptrace_hbp_set(unsigned int note_type,
959 struct task_struct *tsk,
966 int err, idx = compat_ptrace_hbp_num_to_idx(num);
970 err = ptrace_hbp_set_addr(note_type, tsk, idx, addr);
973 err = ptrace_hbp_set_ctrl(note_type, tsk, idx, ctrl);
979 static int compat_ptrace_gethbpregs(struct task_struct *tsk, compat_long_t num,
980 compat_ulong_t __user *data)
984 mm_segment_t old_fs = get_fs();
989 ret = compat_ptrace_hbp_get(NT_ARM_HW_WATCH, tsk, num, &kdata);
991 } else if (num == 0) {
992 ret = compat_ptrace_hbp_get_resource_info(&kdata);
995 ret = compat_ptrace_hbp_get(NT_ARM_HW_BREAK, tsk, num, &kdata);
1000 ret = put_user(kdata, data);
1005 static int compat_ptrace_sethbpregs(struct task_struct *tsk, compat_long_t num,
1006 compat_ulong_t __user *data)
1010 mm_segment_t old_fs = get_fs();
1015 ret = get_user(kdata, data);
1021 ret = compat_ptrace_hbp_set(NT_ARM_HW_WATCH, tsk, num, &kdata);
1023 ret = compat_ptrace_hbp_set(NT_ARM_HW_BREAK, tsk, num, &kdata);
1028 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
1030 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1031 compat_ulong_t caddr, compat_ulong_t cdata)
1033 unsigned long addr = caddr;
1034 unsigned long data = cdata;
1035 void __user *datap = compat_ptr(data);
1039 case PTRACE_PEEKUSR:
1040 ret = compat_ptrace_read_user(child, addr, datap);
1043 case PTRACE_POKEUSR:
1044 ret = compat_ptrace_write_user(child, addr, data);
1047 case COMPAT_PTRACE_GETREGS:
1048 ret = copy_regset_to_user(child,
1051 0, sizeof(compat_elf_gregset_t),
1055 case COMPAT_PTRACE_SETREGS:
1056 ret = copy_regset_from_user(child,
1059 0, sizeof(compat_elf_gregset_t),
1063 case COMPAT_PTRACE_GET_THREAD_AREA:
1064 ret = put_user((compat_ulong_t)child->thread.tp_value,
1065 (compat_ulong_t __user *)datap);
1068 case COMPAT_PTRACE_SET_SYSCALL:
1069 task_pt_regs(child)->syscallno = data;
1073 case COMPAT_PTRACE_GETVFPREGS:
1074 ret = copy_regset_to_user(child,
1081 case COMPAT_PTRACE_SETVFPREGS:
1082 ret = copy_regset_from_user(child,
1089 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1090 case COMPAT_PTRACE_GETHBPREGS:
1091 ret = compat_ptrace_gethbpregs(child, addr, datap);
1094 case COMPAT_PTRACE_SETHBPREGS:
1095 ret = compat_ptrace_sethbpregs(child, addr, datap);
1100 ret = compat_ptrace_request(child, request, addr,
1107 #endif /* CONFIG_COMPAT */
1109 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1111 #ifdef CONFIG_COMPAT
1112 if (is_compat_thread(task_thread_info(task)))
1113 return &user_aarch32_view;
1115 return &user_aarch64_view;
1118 long arch_ptrace(struct task_struct *child, long request,
1119 unsigned long addr, unsigned long data)
1121 return ptrace_request(child, request, addr, data);
1124 enum ptrace_syscall_dir {
1125 PTRACE_SYSCALL_ENTER = 0,
1126 PTRACE_SYSCALL_EXIT,
1129 static void tracehook_report_syscall(struct pt_regs *regs,
1130 enum ptrace_syscall_dir dir)
1133 unsigned long saved_reg;
1136 * A scratch register (ip(r12) on AArch32, x7 on AArch64) is
1137 * used to denote syscall entry/exit:
1139 regno = (is_compat_task() ? 12 : 7);
1140 saved_reg = regs->regs[regno];
1141 regs->regs[regno] = dir;
1143 if (dir == PTRACE_SYSCALL_EXIT)
1144 tracehook_report_syscall_exit(regs, 0);
1145 else if (tracehook_report_syscall_entry(regs))
1146 regs->syscallno = ~0UL;
1148 regs->regs[regno] = saved_reg;
1151 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1153 /* Do the secure computing check first; failures should be fast. */
1154 if (secure_computing() == -1)
1157 if (test_thread_flag(TIF_SYSCALL_TRACE))
1158 tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
1160 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
1161 trace_sys_enter(regs, regs->syscallno);
1163 audit_syscall_entry(regs->syscallno, regs->orig_x0, regs->regs[1],
1164 regs->regs[2], regs->regs[3]);
1166 return regs->syscallno;
1169 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
1171 audit_syscall_exit(regs);
1173 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
1174 trace_sys_exit(regs, regs_return_value(regs));
1176 if (test_thread_flag(TIF_SYSCALL_TRACE))
1177 tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);