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>
32 * does not yet catch signals sent when the child dies.
33 * in exit.c or in signal.c.
37 * This routine will get a word off of the process kernel stack.
39 static inline int get_stack_long(struct task_struct *task, int offset)
43 stack = (unsigned char *)task_pt_regs(task);
45 return (*((int *)stack));
49 * This routine will put a word on the process kernel stack.
51 static inline int put_stack_long(struct task_struct *task, int offset,
56 stack = (unsigned char *)task_pt_regs(task);
58 *(unsigned long *) stack = data;
62 void user_enable_single_step(struct task_struct *child)
64 struct pt_regs *regs = task_pt_regs(child);
67 pc = get_stack_long(child, (long)®s->pc);
69 /* Next scheduling will set up UBC */
70 if (child->thread.ubc_pc == 0)
73 child->thread.ubc_pc = pc;
75 set_tsk_thread_flag(child, TIF_SINGLESTEP);
78 void user_disable_single_step(struct task_struct *child)
80 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
83 * Ensure the UBC is not programmed at the next context switch.
85 * Normally this is not needed but there are sequences such as
86 * singlestep, signal delivery, and continue that leave the
87 * ubc_pc non-zero leading to spurious SIGTRAPs.
89 if (child->thread.ubc_pc != 0) {
91 child->thread.ubc_pc = 0;
96 * Called by kernel/ptrace.c when detaching..
98 * Make sure single step bits etc are not set.
100 void ptrace_disable(struct task_struct *child)
102 user_disable_single_step(child);
105 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
107 struct user * dummy = NULL;
111 /* read the word at location addr in the USER area. */
112 case PTRACE_PEEKUSR: {
116 if ((addr & 3) || addr < 0 ||
117 addr > sizeof(struct user) - 3)
120 if (addr < sizeof(struct pt_regs))
121 tmp = get_stack_long(child, addr);
122 else if (addr >= (long) &dummy->fpu &&
123 addr < (long) &dummy->u_fpvalid) {
124 if (!tsk_used_math(child)) {
125 if (addr == (long)&dummy->fpu.fpscr)
130 tmp = ((long *)&child->thread.fpu)
131 [(addr - (long)&dummy->fpu) >> 2];
132 } else if (addr == (long) &dummy->u_fpvalid)
133 tmp = !!tsk_used_math(child);
136 ret = put_user(tmp, (unsigned long __user *)data);
140 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
142 if ((addr & 3) || addr < 0 ||
143 addr > sizeof(struct user) - 3)
146 if (addr < sizeof(struct pt_regs))
147 ret = put_stack_long(child, addr, data);
148 else if (addr >= (long) &dummy->fpu &&
149 addr < (long) &dummy->u_fpvalid) {
150 set_stopped_child_used_math(child);
151 ((long *)&child->thread.fpu)
152 [(addr - (long)&dummy->fpu) >> 2] = data;
154 } else if (addr == (long) &dummy->u_fpvalid) {
155 conditional_stopped_child_used_math(data, child);
161 case PTRACE_GETDSPREGS: {
165 dp = ((unsigned long) child) + THREAD_SIZE -
166 sizeof(struct pt_dspregs);
167 if (*((int *) (dp - 4)) == SR_FD) {
168 copy_to_user((void *)addr, (void *) dp,
169 sizeof(struct pt_dspregs));
175 case PTRACE_SETDSPREGS: {
179 dp = ((unsigned long) child) + THREAD_SIZE -
180 sizeof(struct pt_dspregs);
181 if (*((int *) (dp - 4)) == SR_FD) {
182 copy_from_user((void *) dp, (void *)addr,
183 sizeof(struct pt_dspregs));
189 #ifdef CONFIG_BINFMT_ELF_FDPIC
190 case PTRACE_GETFDPIC: {
191 unsigned long tmp = 0;
194 case PTRACE_GETFDPIC_EXEC:
195 tmp = child->mm->context.exec_fdpic_loadmap;
197 case PTRACE_GETFDPIC_INTERP:
198 tmp = child->mm->context.interp_fdpic_loadmap;
205 if (put_user(tmp, (unsigned long *) data)) {
213 ret = ptrace_request(child, request, addr, data);
220 static inline int audit_arch(void)
224 #ifdef CONFIG_CPU_LITTLE_ENDIAN
225 arch |= __AUDIT_ARCH_LE;
231 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
235 secure_computing(regs->regs[0]);
237 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
238 tracehook_report_syscall_entry(regs))
240 * Tracing decided this syscall should not happen.
241 * We'll return a bogus call number to get an ENOSYS
242 * error, but leave the original number in regs->regs[0].
246 if (unlikely(current->audit_context))
247 audit_syscall_entry(audit_arch(), regs->regs[3],
248 regs->regs[4], regs->regs[5],
249 regs->regs[6], regs->regs[7]);
251 return ret ?: regs->regs[0];
254 asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
258 if (unlikely(current->audit_context))
259 audit_syscall_exit(AUDITSC_RESULT(regs->regs[0]),
262 step = test_thread_flag(TIF_SINGLESTEP);
263 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
264 tracehook_report_syscall_exit(regs, step);