1 // TODO some minor issues
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
10 * Chris Zankel <chris@zankel.net>
11 * Scott Foehner<sfoehner@yahoo.com>,
13 * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
19 #include <linux/errno.h>
20 #include <linux/ptrace.h>
21 #include <linux/smp.h>
22 #include <linux/smp_lock.h>
23 #include <linux/security.h>
24 #include <linux/signal.h>
26 #include <asm/pgtable.h>
28 #include <asm/system.h>
29 #include <asm/uaccess.h>
30 #include <asm/ptrace.h>
33 #define TEST_KERNEL // verify kernel operations FIXME: remove
37 * Called by kernel/ptrace.c when detaching..
39 * Make sure single step bits etc are not set.
42 void ptrace_disable(struct task_struct *child)
47 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
52 case PTRACE_PEEKTEXT: /* read word at location addr. */
58 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
60 if (copied != sizeof(tmp))
62 ret = put_user(tmp,(unsigned long *) data);
67 /* Read the word at location addr in the USER area. */
74 regs = task_pt_regs(child);
75 tmp = 0; /* Default return value. */
79 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
81 int ar = addr - REG_AR_BASE - regs->windowbase * 4;
82 ar &= (XCHAL_NUM_AREGS - 1);
83 if (ar < 16 && ar + (regs->wmask >> 4) * 4 >= 0)
89 case REG_A_BASE ... REG_A_BASE + 15:
90 tmp = regs->areg[addr - REG_A_BASE];
96 /* Note: PS.EXCM is not set while user task is running;
97 * its being set in regs is for exception handling
99 tmp = (regs->ps & ~(1 << PS_EXCM_BIT));
102 tmp = regs->windowbase;
105 tmp = regs->windowstart;
123 tmp = regs->exccause;
126 tmp = regs->excvaddr;
136 ret = put_user(tmp, (unsigned long *) data);
140 case PTRACE_POKETEXT: /* write the word at location addr. */
141 case PTRACE_POKEDATA:
142 if (access_process_vm(child, addr, &data, sizeof(data), 1)
150 struct pt_regs *regs;
151 regs = task_pt_regs(child);
154 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
156 int ar = addr - REG_AR_BASE - regs->windowbase * 4;
157 if (ar < 16 && ar + (regs->wmask >> 4) * 4 >= 0)
158 regs->areg[ar & (XCHAL_NUM_AREGS - 1)] = data;
163 case REG_A_BASE ... REG_A_BASE + 15:
164 regs->areg[addr - REG_A_BASE] = data;
170 regs->syscall = data;
174 regs->windowbase = data;
177 regs->windowstart = data;
182 /* The rest are not allowed. */
189 /* continue and stop at next (return from) syscall */
191 case PTRACE_CONT: /* restart after signal. */
194 if (!valid_signal(data))
196 if (request == PTRACE_SYSCALL)
197 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
199 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
200 child->exit_code = data;
201 /* Make sure the single step bit is not set. */
202 child->ptrace &= ~PT_SINGLESTEP;
203 wake_up_process(child);
209 * make the child exit. Best I can do is send it a sigkill.
210 * perhaps it should be put in the status that it wants to
215 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
217 child->exit_code = SIGKILL;
218 child->ptrace &= ~PT_SINGLESTEP;
219 wake_up_process(child);
222 case PTRACE_SINGLESTEP:
224 if (!valid_signal(data))
226 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
227 child->ptrace |= PT_SINGLESTEP;
228 child->exit_code = data;
229 wake_up_process(child);
235 /* 'data' points to user memory in which to write.
236 * Mainly due to the non-live register values, we
237 * reformat the register values into something more
238 * standard. For convenience, we use the handy
239 * elf_gregset_t format. */
241 xtensa_gregset_t format;
242 struct pt_regs *regs = task_pt_regs(child);
244 do_copy_regs (&format, regs, child);
246 /* Now, copy to user space nice and easy... */
248 if (copy_to_user((void *)data, &format, sizeof(elf_gregset_t)))
255 /* 'data' points to user memory that contains the new
256 * values in the elf_gregset_t format. */
258 xtensa_gregset_t format;
259 struct pt_regs *regs = task_pt_regs(child);
261 if (copy_from_user(&format,(void *)data,sizeof(elf_gregset_t))){
266 /* FIXME: Perhaps we want some sanity checks on
267 * these user-space values? See ARM version. Are
268 * debuggers a security concern? */
270 do_restore_regs (&format, regs, child);
276 case PTRACE_GETFPREGS:
278 /* 'data' points to user memory in which to write.
279 * For convenience, we use the handy
280 * elf_fpregset_t format. */
282 elf_fpregset_t fpregs;
283 struct pt_regs *regs = task_pt_regs(child);
285 do_save_fpregs (&fpregs, regs, child);
287 /* Now, copy to user space nice and easy... */
289 if (copy_to_user((void *)data, &fpregs, sizeof(elf_fpregset_t)))
295 case PTRACE_SETFPREGS:
297 /* 'data' points to user memory that contains the new
298 * values in the elf_fpregset_t format.
300 elf_fpregset_t fpregs;
301 struct pt_regs *regs = task_pt_regs(child);
304 if (copy_from_user(&fpregs, (void *)data, sizeof(elf_fpregset_t))) {
309 if (do_restore_fpregs (&fpregs, regs, child))
314 case PTRACE_GETFPREGSIZE:
315 /* 'data' points to 'unsigned long' set to the size
318 ret = put_user(sizeof(elf_fpregset_t), (unsigned long *) data);
321 case PTRACE_DETACH: /* detach a process that was attached. */
322 ret = ptrace_detach(child, data);
326 ret = ptrace_request(child, request, addr, data);
333 void do_syscall_trace(void)
336 * The 0x80 provides a way for the tracing parent to distinguish
337 * between a syscall stop and SIGTRAP delivery
339 ptrace_notify(SIGTRAP|((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
342 * this isn't the same as continuing with a signal, but it will do
343 * for normal use. strace only continues with a signal if the
344 * stopping signal is not SIGTRAP. -brl
346 if (current->exit_code) {
347 send_sig(current->exit_code, current, 1);
348 current->exit_code = 0;
352 void do_syscall_trace_enter(struct pt_regs *regs)
354 if (test_thread_flag(TIF_SYSCALL_TRACE)
355 && (current->ptrace & PT_PTRACED))
359 if (unlikely(current->audit_context))
360 audit_syscall_entry(current, AUDIT_ARCH_XTENSA..);
364 void do_syscall_trace_leave(struct pt_regs *regs)
366 if ((test_thread_flag(TIF_SYSCALL_TRACE))
367 && (current->ptrace & PT_PTRACED))