2 * Copyright (C) 2000-2003, Axis Communications AB.
5 #include <linux/kernel.h>
6 #include <linux/sched.h>
9 #include <linux/errno.h>
10 #include <linux/ptrace.h>
11 #include <linux/user.h>
12 #include <linux/signal.h>
13 #include <linux/security.h>
15 #include <asm/uaccess.h>
17 #include <asm/pgtable.h>
18 #include <asm/processor.h>
21 * Determines which bits in DCCR the user has access to.
22 * 1 = access, 0 = no access.
24 #define DCCR_MASK 0x0000001f /* XNZVC */
27 * Get contents of register REGNO in task TASK.
29 inline long get_reg(struct task_struct *task, unsigned int regno)
31 /* USP is a special case, it's not in the pt_regs struct but
32 * in the tasks thread struct
36 return task->thread.usp;
37 else if (regno < PT_MAX)
38 return ((unsigned long *)task_pt_regs(task))[regno];
44 * Write contents of register REGNO in task TASK.
46 inline int put_reg(struct task_struct *task, unsigned int regno,
50 task->thread.usp = data;
51 else if (regno < PT_MAX)
52 ((unsigned long *)task_pt_regs(task))[regno] = data;
59 * Called by kernel/ptrace.c when detaching.
61 * Make sure the single step bit is not set.
64 ptrace_disable(struct task_struct *child)
66 /* Todo - pending singlesteps? */
67 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
71 * Note that this implementation of ptrace behaves differently from vanilla
72 * ptrace. Contrary to what the man page says, in the PTRACE_PEEKTEXT,
73 * PTRACE_PEEKDATA, and PTRACE_PEEKUSER requests the data variable is not
74 * ignored. Instead, the data variable is expected to point at a location
75 * (in user space) where the result of the ptrace call is written (instead of
78 long arch_ptrace(struct task_struct *child, long request,
79 unsigned long addr, unsigned long data)
82 unsigned int regno = addr >> 2;
83 unsigned long __user *datap = (unsigned long __user *)data;
86 /* Read word at location address. */
89 ret = generic_ptrace_peekdata(child, addr, data);
92 /* Read the word at location address in the USER area. */
93 case PTRACE_PEEKUSR: {
97 if ((addr & 3) || regno > PT_MAX)
100 tmp = get_reg(child, regno);
101 ret = put_user(tmp, datap);
105 /* Write the word at location address. */
106 case PTRACE_POKETEXT:
107 case PTRACE_POKEDATA:
108 ret = generic_ptrace_pokedata(child, addr, data);
111 /* Write the word at location address in the USER area. */
114 if ((addr & 3) || regno > PT_MAX)
117 if (regno == PT_DCCR) {
118 /* don't allow the tracing process to change stuff like
119 * interrupt enable, kernel/user bit, dma enables etc.
122 data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
124 if (put_reg(child, regno, data))
129 /* Get all GP registers from the child. */
130 case PTRACE_GETREGS: {
135 for (i = 0; i <= PT_MAX; i++) {
136 tmp = get_reg(child, i);
138 if (put_user(tmp, datap)) {
149 /* Set all GP registers in the child. */
150 case PTRACE_SETREGS: {
155 for (i = 0; i <= PT_MAX; i++) {
156 if (get_user(tmp, datap)) {
163 tmp |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
166 put_reg(child, i, tmp);
174 ret = ptrace_request(child, request, addr, data);
181 void do_syscall_trace(void)
183 if (!test_thread_flag(TIF_SYSCALL_TRACE))
186 if (!(current->ptrace & PT_PTRACED))
189 /* the 0x80 provides a way for the tracing parent to distinguish
190 between a syscall stop and SIGTRAP delivery */
191 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
195 * This isn't the same as continuing with a signal, but it will do for
198 if (current->exit_code) {
199 send_sig(current->exit_code, current, 1);
200 current->exit_code = 0;