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/system.h>
19 #include <asm/processor.h>
22 * Determines which bits in DCCR the user has access to.
23 * 1 = access, 0 = no access.
25 #define DCCR_MASK 0x0000001f /* XNZVC */
28 * Get contents of register REGNO in task TASK.
30 inline long get_reg(struct task_struct *task, unsigned int regno)
32 /* USP is a special case, it's not in the pt_regs struct but
33 * in the tasks thread struct
37 return task->thread.usp;
38 else if (regno < PT_MAX)
39 return ((unsigned long *)task_pt_regs(task))[regno];
45 * Write contents of register REGNO in task TASK.
47 inline int put_reg(struct task_struct *task, unsigned int regno,
51 task->thread.usp = data;
52 else if (regno < PT_MAX)
53 ((unsigned long *)task_pt_regs(task))[regno] = data;
60 * Called by kernel/ptrace.c when detaching.
62 * Make sure the single step bit is not set.
65 ptrace_disable(struct task_struct *child)
67 /* Todo - pending singlesteps? */
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, long addr, long data)
81 unsigned long __user *datap = (unsigned long __user *)data;
84 /* Read word at location address. */
87 ret = generic_ptrace_peekdata(child, addr, data);
90 /* Read the word at location address in the USER area. */
91 case PTRACE_PEEKUSR: {
95 if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
98 tmp = get_reg(child, addr >> 2);
99 ret = put_user(tmp, datap);
103 /* Write the word at location address. */
104 case PTRACE_POKETEXT:
105 case PTRACE_POKEDATA:
108 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
114 /* Write the word at location address in the USER area. */
117 if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
122 if (addr == PT_DCCR) {
123 /* don't allow the tracing process to change stuff like
124 * interrupt enable, kernel/user bit, dma enables etc.
127 data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
129 if (put_reg(child, addr, data))
138 if (!valid_signal(data))
141 if (request == PTRACE_SYSCALL) {
142 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
145 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
148 child->exit_code = data;
150 /* TODO: make sure any pending breakpoint is killed */
151 wake_up_process(child);
156 /* Make the child exit by sending it a sigkill. */
160 if (child->exit_state == EXIT_ZOMBIE)
163 child->exit_code = SIGKILL;
165 /* TODO: make sure any pending breakpoint is killed */
166 wake_up_process(child);
169 /* Set the trap flag. */
170 case PTRACE_SINGLESTEP:
173 if (!valid_signal(data))
176 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
178 /* TODO: set some clever breakpoint mechanism... */
180 child->exit_code = data;
181 wake_up_process(child);
186 ret = ptrace_detach(child, data);
189 /* Get all GP registers from the child. */
190 case PTRACE_GETREGS: {
195 for (i = 0; i <= PT_MAX; i++) {
196 tmp = get_reg(child, i);
198 if (put_user(tmp, datap)) {
203 data += sizeof(long);
209 /* Set all GP registers in the child. */
210 case PTRACE_SETREGS: {
215 for (i = 0; i <= PT_MAX; i++) {
216 if (get_user(tmp, datap)) {
223 tmp |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
226 put_reg(child, i, tmp);
227 data += sizeof(long);
234 ret = ptrace_request(child, request, addr, data);
241 void do_syscall_trace(void)
243 if (!test_thread_flag(TIF_SYSCALL_TRACE))
246 if (!(current->ptrace & PT_PTRACED))
249 /* the 0x80 provides a way for the tracing parent to distinguish
250 between a syscall stop and SIGTRAP delivery */
251 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
255 * This isn't the same as continuing with a signal, but it will do for
258 if (current->exit_code) {
259 send_sig(current->exit_code, current, 1);
260 current->exit_code = 0;