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/config.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
20 #include <linux/errno.h>
21 #include <linux/ptrace.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
24 #include <linux/security.h>
25 #include <linux/signal.h>
27 #include <asm/pgtable.h>
29 #include <asm/system.h>
30 #include <asm/uaccess.h>
31 #include <asm/ptrace.h>
34 #define TEST_KERNEL // verify kernel operations FIXME: remove
38 * Called by kernel/ptrace.c when detaching..
40 * Make sure single step bits etc are not set.
43 void ptrace_disable(struct task_struct *child)
48 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
53 case PTRACE_PEEKTEXT: /* read word at location addr. */
59 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
61 if (copied != sizeof(tmp))
63 ret = put_user(tmp,(unsigned long *) data);
68 /* Read the word at location addr in the USER area. */
75 regs = xtensa_pt_regs(child);
76 tmp = 0; /* Default return value. */
80 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
82 int ar = addr - REG_AR_BASE - regs->windowbase * 4;
83 ar &= (XCHAL_NUM_AREGS - 1);
84 if (ar < 16 && ar + (regs->wmask >> 4) * 4 >= 0)
90 case REG_A_BASE ... REG_A_BASE + 15:
91 tmp = regs->areg[addr - REG_A_BASE];
97 /* Note: PS.EXCM is not set while user task is running;
98 * its being set in regs is for exception handling
100 tmp = (regs->ps & ~XCHAL_PS_EXCM_MASK);
103 tmp = regs->windowbase;
106 tmp = regs->windowstart;
124 tmp = regs->exccause;
127 tmp = regs->excvaddr;
137 ret = put_user(tmp, (unsigned long *) data);
141 case PTRACE_POKETEXT: /* write the word at location addr. */
142 case PTRACE_POKEDATA:
143 if (access_process_vm(child, addr, &data, sizeof(data), 1)
151 struct pt_regs *regs;
152 regs = xtensa_pt_regs(child);
155 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
157 int ar = addr - REG_AR_BASE - regs->windowbase * 4;
158 if (ar < 16 && ar + (regs->wmask >> 4) * 4 >= 0)
159 regs->areg[ar & (XCHAL_NUM_AREGS - 1)] = data;
164 case REG_A_BASE ... REG_A_BASE + 15:
165 regs->areg[addr - REG_A_BASE] = data;
171 regs->syscall = data;
175 regs->windowbase = data;
178 regs->windowstart = data;
183 /* The rest are not allowed. */
190 /* continue and stop at next (return from) syscall */
192 case PTRACE_CONT: /* restart after signal. */
195 if (!valid_signal(data))
197 if (request == PTRACE_SYSCALL)
198 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
200 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
201 child->exit_code = data;
202 /* Make sure the single step bit is not set. */
203 child->ptrace &= ~PT_SINGLESTEP;
204 wake_up_process(child);
210 * make the child exit. Best I can do is send it a sigkill.
211 * perhaps it should be put in the status that it wants to
216 if (child->state == EXIT_ZOMBIE) /* already dead */
218 child->exit_code = SIGKILL;
219 child->ptrace &= ~PT_SINGLESTEP;
220 wake_up_process(child);
223 case PTRACE_SINGLESTEP:
225 if (!valid_signal(data))
227 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
228 child->ptrace |= PT_SINGLESTEP;
229 child->exit_code = data;
230 wake_up_process(child);
236 /* 'data' points to user memory in which to write.
237 * Mainly due to the non-live register values, we
238 * reformat the register values into something more
239 * standard. For convenience, we use the handy
240 * elf_gregset_t format. */
242 xtensa_gregset_t format;
243 struct pt_regs *regs = xtensa_pt_regs(child);
245 do_copy_regs (&format, regs, child);
247 /* Now, copy to user space nice and easy... */
249 if (copy_to_user((void *)data, &format, sizeof(elf_gregset_t)))
256 /* 'data' points to user memory that contains the new
257 * values in the elf_gregset_t format. */
259 xtensa_gregset_t format;
260 struct pt_regs *regs = xtensa_pt_regs(child);
262 if (copy_from_user(&format,(void *)data,sizeof(elf_gregset_t))){
267 /* FIXME: Perhaps we want some sanity checks on
268 * these user-space values? See ARM version. Are
269 * debuggers a security concern? */
271 do_restore_regs (&format, regs, child);
277 case PTRACE_GETFPREGS:
279 /* 'data' points to user memory in which to write.
280 * For convenience, we use the handy
281 * elf_fpregset_t format. */
283 elf_fpregset_t fpregs;
284 struct pt_regs *regs = xtensa_pt_regs(child);
286 do_save_fpregs (&fpregs, regs, child);
288 /* Now, copy to user space nice and easy... */
290 if (copy_to_user((void *)data, &fpregs, sizeof(elf_fpregset_t)))
296 case PTRACE_SETFPREGS:
298 /* 'data' points to user memory that contains the new
299 * values in the elf_fpregset_t format.
301 elf_fpregset_t fpregs;
302 struct pt_regs *regs = xtensa_pt_regs(child);
305 if (copy_from_user(&fpregs, (void *)data, sizeof(elf_fpregset_t))) {
310 if (do_restore_fpregs (&fpregs, regs, child))
315 case PTRACE_GETFPREGSIZE:
316 /* 'data' points to 'unsigned long' set to the size
319 ret = put_user(sizeof(elf_fpregset_t), (unsigned long *) data);
322 case PTRACE_DETACH: /* detach a process that was attached. */
323 ret = ptrace_detach(child, data);
327 ret = ptrace_request(child, request, addr, data);
334 void do_syscall_trace(void)
336 if (!test_thread_flag(TIF_SYSCALL_TRACE))
339 if (!(current->ptrace & PT_PTRACED))
343 * The 0x80 provides a way for the tracing parent to distinguish
344 * between a syscall stop and SIGTRAP delivery
346 ptrace_notify(SIGTRAP|((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
349 * this isn't the same as continuing with a signal, but it will do
350 * for normal use. strace only continues with a signal if the
351 * stopping signal is not SIGTRAP. -brl
353 if (current->exit_code) {
354 send_sig(current->exit_code, current, 1);
355 current->exit_code = 0;