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;
91 for (i
= ARM_MAX_BRP
; i
< ARM_MAX_HBP_SLOTS
&& !bp
; ++i
) {
92 if (current
->thread
.debug
.hbp_watch
[i
] == bp
) {
93 info
.si_errno
= -((i
<< 1) + 1);
100 force_sig_info(SIGTRAP
, &info
, current
);
104 * Unregister breakpoints from this task and reset the pointers in
107 void flush_ptrace_hw_breakpoint(struct task_struct
*tsk
)
110 struct thread_struct
*t
= &tsk
->thread
;
112 for (i
= 0; i
< ARM_MAX_BRP
; i
++) {
113 if (t
->debug
.hbp_break
[i
]) {
114 unregister_hw_breakpoint(t
->debug
.hbp_break
[i
]);
115 t
->debug
.hbp_break
[i
] = NULL
;
119 for (i
= 0; i
< ARM_MAX_WRP
; i
++) {
120 if (t
->debug
.hbp_watch
[i
]) {
121 unregister_hw_breakpoint(t
->debug
.hbp_watch
[i
]);
122 t
->debug
.hbp_watch
[i
] = NULL
;
127 void ptrace_hw_copy_thread(struct task_struct
*tsk
)
129 memset(&tsk
->thread
.debug
, 0, sizeof(struct debug_info
));
132 static struct perf_event
*ptrace_hbp_get_event(unsigned int note_type
,
133 struct task_struct
*tsk
,
136 struct perf_event
*bp
= ERR_PTR(-EINVAL
);
139 case NT_ARM_HW_BREAK
:
140 if (idx
< ARM_MAX_BRP
)
141 bp
= tsk
->thread
.debug
.hbp_break
[idx
];
143 case NT_ARM_HW_WATCH
:
144 if (idx
< ARM_MAX_WRP
)
145 bp
= tsk
->thread
.debug
.hbp_watch
[idx
];
152 static int ptrace_hbp_set_event(unsigned int note_type
,
153 struct task_struct
*tsk
,
155 struct perf_event
*bp
)
160 case NT_ARM_HW_BREAK
:
161 if (idx
< ARM_MAX_BRP
) {
162 tsk
->thread
.debug
.hbp_break
[idx
] = bp
;
166 case NT_ARM_HW_WATCH
:
167 if (idx
< ARM_MAX_WRP
) {
168 tsk
->thread
.debug
.hbp_watch
[idx
] = bp
;
177 static struct perf_event
*ptrace_hbp_create(unsigned int note_type
,
178 struct task_struct
*tsk
,
181 struct perf_event
*bp
;
182 struct perf_event_attr attr
;
186 case NT_ARM_HW_BREAK
:
187 type
= HW_BREAKPOINT_X
;
189 case NT_ARM_HW_WATCH
:
190 type
= HW_BREAKPOINT_RW
;
193 return ERR_PTR(-EINVAL
);
196 ptrace_breakpoint_init(&attr
);
199 * Initialise fields to sane defaults
200 * (i.e. values that will pass validation).
203 attr
.bp_len
= HW_BREAKPOINT_LEN_4
;
207 bp
= register_user_hw_breakpoint(&attr
, ptrace_hbptriggered
, NULL
, tsk
);
211 err
= ptrace_hbp_set_event(note_type
, tsk
, idx
, bp
);
218 static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type
,
219 struct arch_hw_breakpoint_ctrl ctrl
,
220 struct perf_event_attr
*attr
)
222 int err
, len
, type
, disabled
= !ctrl
.enabled
;
224 attr
->disabled
= disabled
;
228 err
= arch_bp_generic_fields(ctrl
, &len
, &type
);
233 case NT_ARM_HW_BREAK
:
234 if ((type
& HW_BREAKPOINT_X
) != type
)
237 case NT_ARM_HW_WATCH
:
238 if ((type
& HW_BREAKPOINT_RW
) != type
)
246 attr
->bp_type
= type
;
251 static int ptrace_hbp_get_resource_info(unsigned int note_type
, u32
*info
)
257 case NT_ARM_HW_BREAK
:
258 num
= hw_breakpoint_slots(TYPE_INST
);
260 case NT_ARM_HW_WATCH
:
261 num
= hw_breakpoint_slots(TYPE_DATA
);
267 reg
|= debug_monitors_arch();
275 static int ptrace_hbp_get_ctrl(unsigned int note_type
,
276 struct task_struct
*tsk
,
280 struct perf_event
*bp
= ptrace_hbp_get_event(note_type
, tsk
, idx
);
285 *ctrl
= bp
? encode_ctrl_reg(counter_arch_bp(bp
)->ctrl
) : 0;
289 static int ptrace_hbp_get_addr(unsigned int note_type
,
290 struct task_struct
*tsk
,
294 struct perf_event
*bp
= ptrace_hbp_get_event(note_type
, tsk
, idx
);
299 *addr
= bp
? bp
->attr
.bp_addr
: 0;
303 static struct perf_event
*ptrace_hbp_get_initialised_bp(unsigned int note_type
,
304 struct task_struct
*tsk
,
307 struct perf_event
*bp
= ptrace_hbp_get_event(note_type
, tsk
, idx
);
310 bp
= ptrace_hbp_create(note_type
, tsk
, idx
);
315 static int ptrace_hbp_set_ctrl(unsigned int note_type
,
316 struct task_struct
*tsk
,
321 struct perf_event
*bp
;
322 struct perf_event_attr attr
;
323 struct arch_hw_breakpoint_ctrl ctrl
;
325 bp
= ptrace_hbp_get_initialised_bp(note_type
, tsk
, idx
);
332 decode_ctrl_reg(uctrl
, &ctrl
);
333 err
= ptrace_hbp_fill_attr_ctrl(note_type
, ctrl
, &attr
);
337 return modify_user_hw_breakpoint(bp
, &attr
);
340 static int ptrace_hbp_set_addr(unsigned int note_type
,
341 struct task_struct
*tsk
,
346 struct perf_event
*bp
;
347 struct perf_event_attr attr
;
349 bp
= ptrace_hbp_get_initialised_bp(note_type
, tsk
, idx
);
357 err
= modify_user_hw_breakpoint(bp
, &attr
);
361 #define PTRACE_HBP_ADDR_SZ sizeof(u64)
362 #define PTRACE_HBP_CTRL_SZ sizeof(u32)
363 #define PTRACE_HBP_PAD_SZ sizeof(u32)
365 static int hw_break_get(struct task_struct
*target
,
366 const struct user_regset
*regset
,
367 unsigned int pos
, unsigned int count
,
368 void *kbuf
, void __user
*ubuf
)
370 unsigned int note_type
= regset
->core_note_type
;
371 int ret
, idx
= 0, offset
, limit
;
376 ret
= ptrace_hbp_get_resource_info(note_type
, &info
);
380 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &info
, 0,
386 offset
= offsetof(struct user_hwdebug_state
, pad
);
387 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
, offset
,
388 offset
+ PTRACE_HBP_PAD_SZ
);
392 /* (address, ctrl) registers */
393 offset
= offsetof(struct user_hwdebug_state
, dbg_regs
);
394 limit
= regset
->n
* regset
->size
;
395 while (count
&& offset
< limit
) {
396 ret
= ptrace_hbp_get_addr(note_type
, target
, idx
, &addr
);
399 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &addr
,
400 offset
, offset
+ PTRACE_HBP_ADDR_SZ
);
403 offset
+= PTRACE_HBP_ADDR_SZ
;
405 ret
= ptrace_hbp_get_ctrl(note_type
, target
, idx
, &ctrl
);
408 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &ctrl
,
409 offset
, offset
+ PTRACE_HBP_CTRL_SZ
);
412 offset
+= PTRACE_HBP_CTRL_SZ
;
414 ret
= user_regset_copyout_zero(&pos
, &count
, &kbuf
, &ubuf
,
416 offset
+ PTRACE_HBP_PAD_SZ
);
419 offset
+= PTRACE_HBP_PAD_SZ
;
426 static int hw_break_set(struct task_struct
*target
,
427 const struct user_regset
*regset
,
428 unsigned int pos
, unsigned int count
,
429 const void *kbuf
, const void __user
*ubuf
)
431 unsigned int note_type
= regset
->core_note_type
;
432 int ret
, idx
= 0, offset
, limit
;
436 /* Resource info and pad */
437 offset
= offsetof(struct user_hwdebug_state
, dbg_regs
);
438 ret
= user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
, 0, offset
);
442 /* (address, ctrl) registers */
443 limit
= regset
->n
* regset
->size
;
444 while (count
&& offset
< limit
) {
445 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &addr
,
446 offset
, offset
+ PTRACE_HBP_ADDR_SZ
);
449 ret
= ptrace_hbp_set_addr(note_type
, target
, idx
, addr
);
452 offset
+= PTRACE_HBP_ADDR_SZ
;
454 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &ctrl
,
455 offset
, offset
+ PTRACE_HBP_CTRL_SZ
);
458 ret
= ptrace_hbp_set_ctrl(note_type
, target
, idx
, ctrl
);
461 offset
+= PTRACE_HBP_CTRL_SZ
;
463 ret
= user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
465 offset
+ PTRACE_HBP_PAD_SZ
);
468 offset
+= PTRACE_HBP_PAD_SZ
;
474 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
476 static int gpr_get(struct task_struct
*target
,
477 const struct user_regset
*regset
,
478 unsigned int pos
, unsigned int count
,
479 void *kbuf
, void __user
*ubuf
)
481 struct user_pt_regs
*uregs
= &task_pt_regs(target
)->user_regs
;
482 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, uregs
, 0, -1);
485 static int gpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
486 unsigned int pos
, unsigned int count
,
487 const void *kbuf
, const void __user
*ubuf
)
490 struct user_pt_regs newregs
;
492 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &newregs
, 0, -1);
496 if (!valid_user_regs(&newregs
))
499 task_pt_regs(target
)->user_regs
= newregs
;
504 * TODO: update fp accessors for lazy context switching (sync/flush hwstate)
506 static int fpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
507 unsigned int pos
, unsigned int count
,
508 void *kbuf
, void __user
*ubuf
)
510 struct user_fpsimd_state
*uregs
;
511 uregs
= &target
->thread
.fpsimd_state
.user_fpsimd
;
512 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, uregs
, 0, -1);
515 static int fpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
516 unsigned int pos
, unsigned int count
,
517 const void *kbuf
, const void __user
*ubuf
)
520 struct user_fpsimd_state newstate
;
522 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &newstate
, 0, -1);
526 target
->thread
.fpsimd_state
.user_fpsimd
= newstate
;
527 fpsimd_flush_task_state(target
);
531 static int tls_get(struct task_struct
*target
, const struct user_regset
*regset
,
532 unsigned int pos
, unsigned int count
,
533 void *kbuf
, void __user
*ubuf
)
535 unsigned long *tls
= &target
->thread
.tp_value
;
536 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, tls
, 0, -1);
539 static int tls_set(struct task_struct
*target
, const struct user_regset
*regset
,
540 unsigned int pos
, unsigned int count
,
541 const void *kbuf
, const void __user
*ubuf
)
546 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &tls
, 0, -1);
550 target
->thread
.tp_value
= tls
;
554 enum aarch64_regset
{
558 #ifdef CONFIG_HAVE_HW_BREAKPOINT
564 static const struct user_regset aarch64_regsets
[] = {
566 .core_note_type
= NT_PRSTATUS
,
567 .n
= sizeof(struct user_pt_regs
) / sizeof(u64
),
569 .align
= sizeof(u64
),
574 .core_note_type
= NT_PRFPREG
,
575 .n
= sizeof(struct user_fpsimd_state
) / sizeof(u32
),
577 * We pretend we have 32-bit registers because the fpsr and
578 * fpcr are 32-bits wide.
581 .align
= sizeof(u32
),
586 .core_note_type
= NT_ARM_TLS
,
588 .size
= sizeof(void *),
589 .align
= sizeof(void *),
593 #ifdef CONFIG_HAVE_HW_BREAKPOINT
594 [REGSET_HW_BREAK
] = {
595 .core_note_type
= NT_ARM_HW_BREAK
,
596 .n
= sizeof(struct user_hwdebug_state
) / sizeof(u32
),
598 .align
= sizeof(u32
),
602 [REGSET_HW_WATCH
] = {
603 .core_note_type
= NT_ARM_HW_WATCH
,
604 .n
= sizeof(struct user_hwdebug_state
) / sizeof(u32
),
606 .align
= sizeof(u32
),
613 static const struct user_regset_view user_aarch64_view
= {
614 .name
= "aarch64", .e_machine
= EM_AARCH64
,
615 .regsets
= aarch64_regsets
, .n
= ARRAY_SIZE(aarch64_regsets
)
619 #include <linux/compat.h>
626 static int compat_gpr_get(struct task_struct
*target
,
627 const struct user_regset
*regset
,
628 unsigned int pos
, unsigned int count
,
629 void *kbuf
, void __user
*ubuf
)
632 unsigned int i
, start
, num_regs
;
634 /* Calculate the number of AArch32 registers contained in count */
635 num_regs
= count
/ regset
->size
;
637 /* Convert pos into an register number */
638 start
= pos
/ regset
->size
;
640 if (start
+ num_regs
> regset
->n
)
643 for (i
= 0; i
< num_regs
; ++i
) {
644 unsigned int idx
= start
+ i
;
649 reg
= (void *)&task_pt_regs(target
)->pc
;
652 reg
= (void *)&task_pt_regs(target
)->pstate
;
655 reg
= (void *)&task_pt_regs(target
)->orig_x0
;
658 reg
= (void *)&task_pt_regs(target
)->regs
[idx
];
662 if (i
== 0 && NULL
!= target
&& target
->pid
== current
->pid
)
663 printk(KERN_WARNING
"coredump(%d) copy registers to kbuf\n", current
->pid
);
664 memcpy(kbuf
, reg
, sizeof(compat_ulong_t
));
665 kbuf
+= sizeof(compat_ulong_t
);
668 ret
= copy_to_user(ubuf
, reg
, sizeof(compat_ulong_t
));
673 ubuf
+= sizeof(compat_ulong_t
);
680 static int compat_gpr_set(struct task_struct
*target
,
681 const struct user_regset
*regset
,
682 unsigned int pos
, unsigned int count
,
683 const void *kbuf
, const void __user
*ubuf
)
685 struct pt_regs newregs
;
687 unsigned int i
, start
, num_regs
;
689 /* Calculate the number of AArch32 registers contained in count */
690 num_regs
= count
/ regset
->size
;
692 /* Convert pos into an register number */
693 start
= pos
/ regset
->size
;
695 if (start
+ num_regs
> regset
->n
)
698 newregs
= *task_pt_regs(target
);
700 for (i
= 0; i
< num_regs
; ++i
) {
701 unsigned int idx
= start
+ i
;
706 reg
= (void *)&newregs
.pc
;
709 reg
= (void *)&newregs
.pstate
;
712 reg
= (void *)&newregs
.orig_x0
;
715 reg
= (void *)&newregs
.regs
[idx
];
718 ret
= copy_from_user(reg
, ubuf
, sizeof(compat_ulong_t
));
723 ubuf
+= sizeof(compat_ulong_t
);
726 if (valid_user_regs(&newregs
.user_regs
))
727 *task_pt_regs(target
) = newregs
;
735 static int compat_vfp_get(struct task_struct
*target
,
736 const struct user_regset
*regset
,
737 unsigned int pos
, unsigned int count
,
738 void *kbuf
, void __user
*ubuf
)
740 struct user_fpsimd_state
*uregs
;
741 compat_ulong_t fpscr
;
744 uregs
= &target
->thread
.fpsimd_state
.user_fpsimd
;
747 * The VFP registers are packed into the fpsimd_state, so they all sit
748 * nicely together for us. We just need to create the fpscr separately.
750 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, uregs
, 0,
751 VFP_STATE_SIZE
- sizeof(compat_ulong_t
));
754 fpscr
= (uregs
->fpsr
& VFP_FPSCR_STAT_MASK
) |
755 (uregs
->fpcr
& VFP_FPSCR_CTRL_MASK
);
756 ret
= put_user(fpscr
, (compat_ulong_t
*)ubuf
);
762 static int compat_vfp_set(struct task_struct
*target
,
763 const struct user_regset
*regset
,
764 unsigned int pos
, unsigned int count
,
765 const void *kbuf
, const void __user
*ubuf
)
767 struct user_fpsimd_state
*uregs
;
768 compat_ulong_t fpscr
;
771 if (pos
+ count
> VFP_STATE_SIZE
)
774 uregs
= &target
->thread
.fpsimd_state
.user_fpsimd
;
776 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, uregs
, 0,
777 VFP_STATE_SIZE
- sizeof(compat_ulong_t
));
780 ret
= get_user(fpscr
, (compat_ulong_t
*)ubuf
);
781 uregs
->fpsr
= fpscr
& VFP_FPSCR_STAT_MASK
;
782 uregs
->fpcr
= fpscr
& VFP_FPSCR_CTRL_MASK
;
785 fpsimd_flush_task_state(target
);
789 static const struct user_regset aarch32_regsets
[] = {
790 [REGSET_COMPAT_GPR
] = {
791 .core_note_type
= NT_PRSTATUS
,
792 .n
= COMPAT_ELF_NGREG
,
793 .size
= sizeof(compat_elf_greg_t
),
794 .align
= sizeof(compat_elf_greg_t
),
795 .get
= compat_gpr_get
,
796 .set
= compat_gpr_set
798 [REGSET_COMPAT_VFP
] = {
799 .core_note_type
= NT_ARM_VFP
,
800 .n
= VFP_STATE_SIZE
/ sizeof(compat_ulong_t
),
801 .size
= sizeof(compat_ulong_t
),
802 .align
= sizeof(compat_ulong_t
),
803 .get
= compat_vfp_get
,
804 .set
= compat_vfp_set
808 static const struct user_regset_view user_aarch32_view
= {
809 .name
= "aarch32", .e_machine
= EM_ARM
,
810 .regsets
= aarch32_regsets
, .n
= ARRAY_SIZE(aarch32_regsets
)
813 static int compat_ptrace_read_user(struct task_struct
*tsk
, compat_ulong_t off
,
814 compat_ulong_t __user
*ret
)
821 if (off
== COMPAT_PT_TEXT_ADDR
)
822 tmp
= tsk
->mm
->start_code
;
823 else if (off
== COMPAT_PT_DATA_ADDR
)
824 tmp
= tsk
->mm
->start_data
;
825 else if (off
== COMPAT_PT_TEXT_END_ADDR
)
826 tmp
= tsk
->mm
->end_code
;
827 else if (off
< sizeof(compat_elf_gregset_t
))
828 return copy_regset_to_user(tsk
, &user_aarch32_view
,
829 REGSET_COMPAT_GPR
, off
,
830 sizeof(compat_ulong_t
), ret
);
831 else if (off
>= COMPAT_USER_SZ
)
836 return put_user(tmp
, ret
);
839 static int compat_ptrace_write_user(struct task_struct
*tsk
, compat_ulong_t off
,
843 mm_segment_t old_fs
= get_fs();
845 if (off
& 3 || off
>= COMPAT_USER_SZ
)
848 if (off
>= sizeof(compat_elf_gregset_t
))
852 ret
= copy_regset_from_user(tsk
, &user_aarch32_view
,
853 REGSET_COMPAT_GPR
, off
,
854 sizeof(compat_ulong_t
),
861 #ifdef CONFIG_HAVE_HW_BREAKPOINT
864 * Convert a virtual register number into an index for a thread_info
865 * breakpoint array. Breakpoints are identified using positive numbers
866 * whilst watchpoints are negative. The registers are laid out as pairs
867 * of (address, control), each pair mapping to a unique hw_breakpoint struct.
868 * Register 0 is reserved for describing resource information.
870 static int compat_ptrace_hbp_num_to_idx(compat_long_t num
)
872 return (abs(num
) - 1) >> 1;
875 static int compat_ptrace_hbp_get_resource_info(u32
*kdata
)
877 u8 num_brps
, num_wrps
, debug_arch
, wp_len
;
880 num_brps
= hw_breakpoint_slots(TYPE_INST
);
881 num_wrps
= hw_breakpoint_slots(TYPE_DATA
);
883 debug_arch
= debug_monitors_arch();
897 static int compat_ptrace_hbp_get(unsigned int note_type
,
898 struct task_struct
*tsk
,
905 int err
, idx
= compat_ptrace_hbp_num_to_idx(num
);;
908 err
= ptrace_hbp_get_addr(note_type
, tsk
, idx
, &addr
);
911 err
= ptrace_hbp_get_ctrl(note_type
, tsk
, idx
, &ctrl
);
918 static int compat_ptrace_hbp_set(unsigned int note_type
,
919 struct task_struct
*tsk
,
926 int err
, idx
= compat_ptrace_hbp_num_to_idx(num
);
930 err
= ptrace_hbp_set_addr(note_type
, tsk
, idx
, addr
);
933 err
= ptrace_hbp_set_ctrl(note_type
, tsk
, idx
, ctrl
);
939 static int compat_ptrace_gethbpregs(struct task_struct
*tsk
, compat_long_t num
,
940 compat_ulong_t __user
*data
)
944 mm_segment_t old_fs
= get_fs();
949 ret
= compat_ptrace_hbp_get(NT_ARM_HW_WATCH
, tsk
, num
, &kdata
);
951 } else if (num
== 0) {
952 ret
= compat_ptrace_hbp_get_resource_info(&kdata
);
955 ret
= compat_ptrace_hbp_get(NT_ARM_HW_BREAK
, tsk
, num
, &kdata
);
960 ret
= put_user(kdata
, data
);
965 static int compat_ptrace_sethbpregs(struct task_struct
*tsk
, compat_long_t num
,
966 compat_ulong_t __user
*data
)
970 mm_segment_t old_fs
= get_fs();
975 ret
= get_user(kdata
, data
);
981 ret
= compat_ptrace_hbp_set(NT_ARM_HW_WATCH
, tsk
, num
, &kdata
);
983 ret
= compat_ptrace_hbp_set(NT_ARM_HW_BREAK
, tsk
, num
, &kdata
);
988 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
990 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
991 compat_ulong_t caddr
, compat_ulong_t cdata
)
993 unsigned long addr
= caddr
;
994 unsigned long data
= cdata
;
995 void __user
*datap
= compat_ptr(data
);
1000 ret
= compat_ptrace_read_user(child
, addr
, datap
);
1003 case PTRACE_POKEUSR
:
1004 ret
= compat_ptrace_write_user(child
, addr
, data
);
1007 case COMPAT_PTRACE_GETREGS
:
1008 ret
= copy_regset_to_user(child
,
1011 0, sizeof(compat_elf_gregset_t
),
1015 case COMPAT_PTRACE_SETREGS
:
1016 ret
= copy_regset_from_user(child
,
1019 0, sizeof(compat_elf_gregset_t
),
1023 case COMPAT_PTRACE_GET_THREAD_AREA
:
1024 ret
= put_user((compat_ulong_t
)child
->thread
.tp_value
,
1025 (compat_ulong_t __user
*)datap
);
1028 case COMPAT_PTRACE_SET_SYSCALL
:
1029 task_pt_regs(child
)->syscallno
= data
;
1033 case COMPAT_PTRACE_GETVFPREGS
:
1034 ret
= copy_regset_to_user(child
,
1041 case COMPAT_PTRACE_SETVFPREGS
:
1042 ret
= copy_regset_from_user(child
,
1049 #ifdef CONFIG_HAVE_HW_BREAKPOINT
1050 case COMPAT_PTRACE_GETHBPREGS
:
1051 ret
= compat_ptrace_gethbpregs(child
, addr
, datap
);
1054 case COMPAT_PTRACE_SETHBPREGS
:
1055 ret
= compat_ptrace_sethbpregs(child
, addr
, datap
);
1060 ret
= compat_ptrace_request(child
, request
, addr
,
1067 #endif /* CONFIG_COMPAT */
1069 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
1071 #ifdef CONFIG_COMPAT
1072 if (is_compat_thread(task_thread_info(task
)))
1073 return &user_aarch32_view
;
1075 return &user_aarch64_view
;
1078 long arch_ptrace(struct task_struct
*child
, long request
,
1079 unsigned long addr
, unsigned long data
)
1084 case PTRACE_SET_SYSCALL
:
1085 task_pt_regs(child
)->syscallno
= data
;
1089 ret
= ptrace_request(child
, request
, addr
, data
);
1096 enum ptrace_syscall_dir
{
1097 PTRACE_SYSCALL_ENTER
= 0,
1098 PTRACE_SYSCALL_EXIT
,
1101 static void tracehook_report_syscall(struct pt_regs
*regs
,
1102 enum ptrace_syscall_dir dir
)
1105 unsigned long saved_reg
;
1108 * A scratch register (ip(r12) on AArch32, x7 on AArch64) is
1109 * used to denote syscall entry/exit:
1111 regno
= (is_compat_task() ? 12 : 7);
1112 saved_reg
= regs
->regs
[regno
];
1113 regs
->regs
[regno
] = dir
;
1115 if (dir
== PTRACE_SYSCALL_EXIT
)
1116 tracehook_report_syscall_exit(regs
, 0);
1117 else if (tracehook_report_syscall_entry(regs
))
1118 regs
->syscallno
= ~0UL;
1120 regs
->regs
[regno
] = saved_reg
;
1123 asmlinkage
int syscall_trace_enter(struct pt_regs
*regs
)
1125 unsigned int saved_syscallno
= regs
->syscallno
;
1127 /* Do the secure computing check first; failures should be fast. */
1128 if (secure_computing(regs
->syscallno
) == -1)
1129 return RET_SKIP_SYSCALL_TRACE
;
1131 if (test_thread_flag(TIF_SYSCALL_TRACE
))
1132 tracehook_report_syscall(regs
, PTRACE_SYSCALL_ENTER
);
1134 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT
))
1135 trace_sys_enter(regs
, regs
->syscallno
);
1137 if (IS_SKIP_SYSCALL(regs
->syscallno
)) {
1139 * RESTRICTION: we can't modify a return value of user
1140 * issued syscall(-1) here. In order to ease this flavor,
1141 * we need to treat whatever value in x0 as a return value,
1142 * but this might result in a bogus value being returned.
1145 * NOTE: syscallno may also be set to -1 if fatal signal is
1146 * detected in tracehook_report_syscall_entry(), but since
1147 * a value set to x0 here is not used in this case, we may
1150 if (!test_thread_flag(TIF_SYSCALL_TRACE
) ||
1151 (IS_SKIP_SYSCALL(saved_syscallno
)))
1152 regs
->regs
[0] = -ENOSYS
;
1155 audit_syscall_entry(syscall_get_arch(), regs
->syscallno
,
1156 regs
->orig_x0
, regs
->regs
[1], regs
->regs
[2], regs
->regs
[3]);
1158 return regs
->syscallno
;
1161 asmlinkage
void syscall_trace_exit(struct pt_regs
*regs
)
1163 audit_syscall_exit(regs
);
1165 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT
))
1166 trace_sys_exit(regs
, regs_return_value(regs
));
1168 if (test_thread_flag(TIF_SYSCALL_TRACE
))
1169 tracehook_report_syscall(regs
, PTRACE_SYSCALL_EXIT
);