1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
6 #include <linux/audit.h>
7 #include <linux/ptrace.h>
8 #include <linux/sched.h>
9 #include <linux/uaccess.h>
10 #include <asm/ptrace-abi.h>
12 void user_enable_single_step(struct task_struct *child)
14 set_tsk_thread_flag(child, TIF_SINGLESTEP);
16 #ifdef SUBARCH_SET_SINGLESTEPPING
17 SUBARCH_SET_SINGLESTEPPING(child, 1);
21 void user_disable_single_step(struct task_struct *child)
23 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
25 #ifdef SUBARCH_SET_SINGLESTEPPING
26 SUBARCH_SET_SINGLESTEPPING(child, 0);
31 * Called by kernel/ptrace.c when detaching..
33 void ptrace_disable(struct task_struct *child)
35 user_disable_single_step(child);
38 extern int peek_user(struct task_struct * child, long addr, long data);
39 extern int poke_user(struct task_struct * child, long addr, long data);
41 long arch_ptrace(struct task_struct *child, long request,
42 unsigned long addr, unsigned long data)
45 unsigned long __user *p = (void __user *)data;
49 /* read the word at location addr in the USER area. */
51 ret = peek_user(child, addr, data);
54 /* write the word at location addr in the USER area */
56 ret = poke_user(child, addr, data);
60 case PTRACE_SYSEMU_SINGLESTEP:
65 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
66 if (!access_ok(p, MAX_REG_OFFSET)) {
70 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
71 __put_user(getreg(child, i), p);
79 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
80 unsigned long tmp = 0;
81 if (!access_ok(p, MAX_REG_OFFSET)) {
85 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
87 putreg(child, i, tmp);
94 case PTRACE_GET_THREAD_AREA:
95 ret = ptrace_get_thread_area(child, addr, vp);
98 case PTRACE_SET_THREAD_AREA:
99 ret = ptrace_set_thread_area(child, addr, vp);
103 ret = ptrace_request(child, request, addr, data);
105 ret = subarch_ptrace(child, request, addr, data);
112 static void send_sigtrap(struct uml_pt_regs *regs, int error_code)
114 /* Send us the fake SIGTRAP */
115 force_sig_fault(SIGTRAP, TRAP_BRKPT,
117 UPT_IS_USER(regs) ? (void __user *) UPT_IP(regs) : NULL);
121 * XXX Check TIF_SINGLESTEP for singlestepping check and
122 * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
124 int syscall_trace_enter(struct pt_regs *regs)
126 audit_syscall_entry(UPT_SYSCALL_NR(®s->regs),
127 UPT_SYSCALL_ARG1(®s->regs),
128 UPT_SYSCALL_ARG2(®s->regs),
129 UPT_SYSCALL_ARG3(®s->regs),
130 UPT_SYSCALL_ARG4(®s->regs));
132 if (!test_thread_flag(TIF_SYSCALL_TRACE))
135 return ptrace_report_syscall_entry(regs);
138 void syscall_trace_leave(struct pt_regs *regs)
140 int ptraced = current->ptrace;
142 audit_syscall_exit(regs);
144 /* Fake a debug trap */
145 if (test_thread_flag(TIF_SINGLESTEP))
146 send_sigtrap(®s->regs, 0);
148 if (!test_thread_flag(TIF_SYSCALL_TRACE))
151 ptrace_report_syscall_exit(regs, 0);
152 /* force do_signal() --> is_syscall() */
153 if (ptraced & PT_PTRACED)
154 set_thread_flag(TIF_SIGPENDING);