2 * linux/arch/sh/kernel/ptrace.c
4 * Original x86 implementation:
6 * edited by Linus Torvalds
8 * SuperH version: Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
9 * Audit support: Yuichi Nakamura <ynakam@hitachisoft.jp>
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
14 #include <linux/smp.h>
15 #include <linux/errno.h>
16 #include <linux/ptrace.h>
17 #include <linux/user.h>
18 #include <linux/slab.h>
19 #include <linux/security.h>
20 #include <linux/signal.h>
22 #include <linux/audit.h>
23 #include <linux/seccomp.h>
24 #include <linux/tracehook.h>
25 #include <asm/uaccess.h>
26 #include <asm/pgtable.h>
27 #include <asm/system.h>
28 #include <asm/processor.h>
29 #include <asm/mmu_context.h>
30 #include <asm/syscalls.h>
33 * does not yet catch signals sent when the child dies.
34 * in exit.c or in signal.c.
38 * This routine will get a word off of the process kernel stack.
40 static inline int get_stack_long(struct task_struct *task, int offset)
44 stack = (unsigned char *)task_pt_regs(task);
46 return (*((int *)stack));
50 * This routine will put a word on the process kernel stack.
52 static inline int put_stack_long(struct task_struct *task, int offset,
57 stack = (unsigned char *)task_pt_regs(task);
59 *(unsigned long *) stack = data;
63 void user_enable_single_step(struct task_struct *child)
65 struct pt_regs *regs = task_pt_regs(child);
68 pc = get_stack_long(child, (long)®s->pc);
70 /* Next scheduling will set up UBC */
71 if (child->thread.ubc_pc == 0)
74 child->thread.ubc_pc = pc;
76 set_tsk_thread_flag(child, TIF_SINGLESTEP);
79 void user_disable_single_step(struct task_struct *child)
81 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
84 * Ensure the UBC is not programmed at the next context switch.
86 * Normally this is not needed but there are sequences such as
87 * singlestep, signal delivery, and continue that leave the
88 * ubc_pc non-zero leading to spurious SIGTRAPs.
90 if (child->thread.ubc_pc != 0) {
92 child->thread.ubc_pc = 0;
97 * Called by kernel/ptrace.c when detaching..
99 * Make sure single step bits etc are not set.
101 void ptrace_disable(struct task_struct *child)
103 user_disable_single_step(child);
106 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
108 struct user * dummy = NULL;
109 unsigned long __user *datap = (unsigned long __user *)data;
113 /* read the word at location addr in the USER area. */
114 case PTRACE_PEEKUSR: {
118 if ((addr & 3) || addr < 0 ||
119 addr > sizeof(struct user) - 3)
122 if (addr < sizeof(struct pt_regs))
123 tmp = get_stack_long(child, addr);
124 else if (addr >= (long) &dummy->fpu &&
125 addr < (long) &dummy->u_fpvalid) {
126 if (!tsk_used_math(child)) {
127 if (addr == (long)&dummy->fpu.fpscr)
132 tmp = ((long *)&child->thread.fpu)
133 [(addr - (long)&dummy->fpu) >> 2];
134 } else if (addr == (long) &dummy->u_fpvalid)
135 tmp = !!tsk_used_math(child);
138 ret = put_user(tmp, datap);
142 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
144 if ((addr & 3) || addr < 0 ||
145 addr > sizeof(struct user) - 3)
148 if (addr < sizeof(struct pt_regs))
149 ret = put_stack_long(child, addr, data);
150 else if (addr >= (long) &dummy->fpu &&
151 addr < (long) &dummy->u_fpvalid) {
152 set_stopped_child_used_math(child);
153 ((long *)&child->thread.fpu)
154 [(addr - (long)&dummy->fpu) >> 2] = data;
156 } else if (addr == (long) &dummy->u_fpvalid) {
157 conditional_stopped_child_used_math(data, child);
163 case PTRACE_GETDSPREGS: {
167 dp = ((unsigned long) child) + THREAD_SIZE -
168 sizeof(struct pt_dspregs);
169 if (*((int *) (dp - 4)) == SR_FD) {
170 copy_to_user((void *)addr, (void *) dp,
171 sizeof(struct pt_dspregs));
177 case PTRACE_SETDSPREGS: {
181 dp = ((unsigned long) child) + THREAD_SIZE -
182 sizeof(struct pt_dspregs);
183 if (*((int *) (dp - 4)) == SR_FD) {
184 copy_from_user((void *) dp, (void *)addr,
185 sizeof(struct pt_dspregs));
191 #ifdef CONFIG_BINFMT_ELF_FDPIC
192 case PTRACE_GETFDPIC: {
193 unsigned long tmp = 0;
196 case PTRACE_GETFDPIC_EXEC:
197 tmp = child->mm->context.exec_fdpic_loadmap;
199 case PTRACE_GETFDPIC_INTERP:
200 tmp = child->mm->context.interp_fdpic_loadmap;
207 if (put_user(tmp, datap)) {
215 ret = ptrace_request(child, request, addr, data);
222 static inline int audit_arch(void)
226 #ifdef CONFIG_CPU_LITTLE_ENDIAN
227 arch |= __AUDIT_ARCH_LE;
233 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
237 secure_computing(regs->regs[0]);
239 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
240 tracehook_report_syscall_entry(regs))
242 * Tracing decided this syscall should not happen.
243 * We'll return a bogus call number to get an ENOSYS
244 * error, but leave the original number in regs->regs[0].
248 if (unlikely(current->audit_context))
249 audit_syscall_entry(audit_arch(), regs->regs[3],
250 regs->regs[4], regs->regs[5],
251 regs->regs[6], regs->regs[7]);
253 return ret ?: regs->regs[0];
256 asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
260 if (unlikely(current->audit_context))
261 audit_syscall_exit(AUDITSC_RESULT(regs->regs[0]),
264 step = test_thread_flag(TIF_SINGLESTEP);
265 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
266 tracehook_report_syscall_exit(regs, step);