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/security.h>
23 #include <linux/signal.h>
25 #include <asm/pgtable.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
29 #include <asm/ptrace.h>
32 #define TEST_KERNEL // verify kernel operations FIXME: remove
36 * Called by kernel/ptrace.c when detaching..
38 * Make sure single step bits etc are not set.
41 void ptrace_disable(struct task_struct
*child
)
46 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
51 case PTRACE_PEEKTEXT
: /* read word at location addr. */
53 ret
= generic_ptrace_peekdata(child
, addr
, data
);
56 /* Read the word at location addr in the USER area. */
63 regs
= task_pt_regs(child
);
64 tmp
= 0; /* Default return value. */
68 case REG_AR_BASE
... REG_AR_BASE
+ XCHAL_NUM_AREGS
- 1:
70 int ar
= addr
- REG_AR_BASE
- regs
->windowbase
* 4;
71 ar
&= (XCHAL_NUM_AREGS
- 1);
72 if (ar
< 16 && ar
+ (regs
->wmask
>> 4) * 4 >= 0)
78 case REG_A_BASE
... REG_A_BASE
+ 15:
79 tmp
= regs
->areg
[addr
- REG_A_BASE
];
85 /* Note: PS.EXCM is not set while user task is running;
86 * its being set in regs is for exception handling
88 tmp
= (regs
->ps
& ~(1 << PS_EXCM_BIT
));
91 tmp
= regs
->windowbase
;
94 tmp
= regs
->windowstart
;
112 tmp
= regs
->exccause
;
115 tmp
= regs
->excvaddr
;
125 ret
= put_user(tmp
, (unsigned long *) data
);
129 case PTRACE_POKETEXT
: /* write the word at location addr. */
130 case PTRACE_POKEDATA
:
131 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
139 struct pt_regs
*regs
;
140 regs
= task_pt_regs(child
);
143 case REG_AR_BASE
... REG_AR_BASE
+ XCHAL_NUM_AREGS
- 1:
145 int ar
= addr
- REG_AR_BASE
- regs
->windowbase
* 4;
146 if (ar
< 16 && ar
+ (regs
->wmask
>> 4) * 4 >= 0)
147 regs
->areg
[ar
& (XCHAL_NUM_AREGS
- 1)] = data
;
152 case REG_A_BASE
... REG_A_BASE
+ 15:
153 regs
->areg
[addr
- REG_A_BASE
] = data
;
159 regs
->syscall
= data
;
163 regs
->windowbase
= data
;
166 regs
->windowstart
= data
;
171 /* The rest are not allowed. */
178 /* continue and stop at next (return from) syscall */
180 case PTRACE_CONT
: /* restart after signal. */
183 if (!valid_signal(data
))
185 if (request
== PTRACE_SYSCALL
)
186 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
188 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
189 child
->exit_code
= data
;
190 /* Make sure the single step bit is not set. */
191 child
->ptrace
&= ~PT_SINGLESTEP
;
192 wake_up_process(child
);
198 * make the child exit. Best I can do is send it a sigkill.
199 * perhaps it should be put in the status that it wants to
204 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
206 child
->exit_code
= SIGKILL
;
207 child
->ptrace
&= ~PT_SINGLESTEP
;
208 wake_up_process(child
);
211 case PTRACE_SINGLESTEP
:
213 if (!valid_signal(data
))
215 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
216 child
->ptrace
|= PT_SINGLESTEP
;
217 child
->exit_code
= data
;
218 wake_up_process(child
);
224 /* 'data' points to user memory in which to write.
225 * Mainly due to the non-live register values, we
226 * reformat the register values into something more
227 * standard. For convenience, we use the handy
228 * elf_gregset_t format. */
230 xtensa_gregset_t format
;
231 struct pt_regs
*regs
= task_pt_regs(child
);
233 do_copy_regs (&format
, regs
, child
);
235 /* Now, copy to user space nice and easy... */
237 if (copy_to_user((void *)data
, &format
, sizeof(elf_gregset_t
)))
244 /* 'data' points to user memory that contains the new
245 * values in the elf_gregset_t format. */
247 xtensa_gregset_t format
;
248 struct pt_regs
*regs
= task_pt_regs(child
);
250 if (copy_from_user(&format
,(void *)data
,sizeof(elf_gregset_t
))){
255 /* FIXME: Perhaps we want some sanity checks on
256 * these user-space values? See ARM version. Are
257 * debuggers a security concern? */
259 do_restore_regs (&format
, regs
, child
);
265 case PTRACE_GETFPREGS
:
267 /* 'data' points to user memory in which to write.
268 * For convenience, we use the handy
269 * elf_fpregset_t format. */
271 elf_fpregset_t fpregs
;
272 struct pt_regs
*regs
= task_pt_regs(child
);
274 do_save_fpregs (&fpregs
, regs
, child
);
276 /* Now, copy to user space nice and easy... */
278 if (copy_to_user((void *)data
, &fpregs
, sizeof(elf_fpregset_t
)))
284 case PTRACE_SETFPREGS
:
286 /* 'data' points to user memory that contains the new
287 * values in the elf_fpregset_t format.
289 elf_fpregset_t fpregs
;
290 struct pt_regs
*regs
= task_pt_regs(child
);
293 if (copy_from_user(&fpregs
, (void *)data
, sizeof(elf_fpregset_t
))) {
298 if (do_restore_fpregs (&fpregs
, regs
, child
))
303 case PTRACE_GETFPREGSIZE
:
304 /* 'data' points to 'unsigned long' set to the size
307 ret
= put_user(sizeof(elf_fpregset_t
), (unsigned long *) data
);
310 case PTRACE_DETACH
: /* detach a process that was attached. */
311 ret
= ptrace_detach(child
, data
);
315 ret
= ptrace_request(child
, request
, addr
, data
);
322 void do_syscall_trace(void)
325 * The 0x80 provides a way for the tracing parent to distinguish
326 * between a syscall stop and SIGTRAP delivery
328 ptrace_notify(SIGTRAP
|((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80 : 0));
331 * this isn't the same as continuing with a signal, but it will do
332 * for normal use. strace only continues with a signal if the
333 * stopping signal is not SIGTRAP. -brl
335 if (current
->exit_code
) {
336 send_sig(current
->exit_code
, current
, 1);
337 current
->exit_code
= 0;
341 void do_syscall_trace_enter(struct pt_regs
*regs
)
343 if (test_thread_flag(TIF_SYSCALL_TRACE
)
344 && (current
->ptrace
& PT_PTRACED
))
348 if (unlikely(current
->audit_context
))
349 audit_syscall_entry(current
, AUDIT_ARCH_XTENSA
..);
353 void do_syscall_trace_leave(struct pt_regs
*regs
)
355 if ((test_thread_flag(TIF_SYSCALL_TRACE
))
356 && (current
->ptrace
& PT_PTRACED
))