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);
15 child->thread.singlestep_syscall = 0;
17 #ifdef SUBARCH_SET_SINGLESTEPPING
18 SUBARCH_SET_SINGLESTEPPING(child, 1);
22 void user_disable_single_step(struct task_struct *child)
24 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
25 child->thread.singlestep_syscall = 0;
27 #ifdef SUBARCH_SET_SINGLESTEPPING
28 SUBARCH_SET_SINGLESTEPPING(child, 0);
33 * Called by kernel/ptrace.c when detaching..
35 void ptrace_disable(struct task_struct *child)
37 user_disable_single_step(child);
40 extern int peek_user(struct task_struct * child, long addr, long data);
41 extern int poke_user(struct task_struct * child, long addr, long data);
43 long arch_ptrace(struct task_struct *child, long request,
44 unsigned long addr, unsigned long data)
47 unsigned long __user *p = (void __user *)data;
51 /* read the word at location addr in the USER area. */
53 ret = peek_user(child, addr, data);
56 /* write the word at location addr in the USER area */
58 ret = poke_user(child, addr, data);
62 case PTRACE_SYSEMU_SINGLESTEP:
67 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
68 if (!access_ok(p, MAX_REG_OFFSET)) {
72 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
73 __put_user(getreg(child, i), p);
81 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
82 unsigned long tmp = 0;
83 if (!access_ok(p, MAX_REG_OFFSET)) {
87 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
89 putreg(child, i, tmp);
96 case PTRACE_GET_THREAD_AREA:
97 ret = ptrace_get_thread_area(child, addr, vp);
100 case PTRACE_SET_THREAD_AREA:
101 ret = ptrace_set_thread_area(child, addr, vp);
105 ret = ptrace_request(child, request, addr, data);
107 ret = subarch_ptrace(child, request, addr, data);
114 static void send_sigtrap(struct uml_pt_regs *regs, int error_code)
116 /* Send us the fake SIGTRAP */
117 force_sig_fault(SIGTRAP, TRAP_BRKPT,
119 UPT_IS_USER(regs) ? (void __user *) UPT_IP(regs) : NULL);
123 * XXX Check TIF_SINGLESTEP for singlestepping check and
124 * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
126 int syscall_trace_enter(struct pt_regs *regs)
128 audit_syscall_entry(UPT_SYSCALL_NR(®s->regs),
129 UPT_SYSCALL_ARG1(®s->regs),
130 UPT_SYSCALL_ARG2(®s->regs),
131 UPT_SYSCALL_ARG3(®s->regs),
132 UPT_SYSCALL_ARG4(®s->regs));
134 if (!test_thread_flag(TIF_SYSCALL_TRACE))
137 return ptrace_report_syscall_entry(regs);
140 void syscall_trace_leave(struct pt_regs *regs)
142 int ptraced = current->ptrace;
144 audit_syscall_exit(regs);
146 /* Fake a debug trap */
147 if (test_thread_flag(TIF_SINGLESTEP))
148 send_sigtrap(®s->regs, 0);
150 if (!test_thread_flag(TIF_SYSCALL_TRACE))
153 ptrace_report_syscall_exit(regs, 0);
154 /* force do_signal() --> is_syscall() */
155 if (ptraced & PT_PTRACED)
156 set_thread_flag(TIF_SIGPENDING);