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. */
57 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
59 if (copied
!= sizeof(tmp
))
61 ret
= put_user(tmp
,(unsigned long *) data
);
66 /* Read the word at location addr in the USER area. */
73 regs
= task_pt_regs(child
);
74 tmp
= 0; /* Default return value. */
78 case REG_AR_BASE
... REG_AR_BASE
+ XCHAL_NUM_AREGS
- 1:
80 int ar
= addr
- REG_AR_BASE
- regs
->windowbase
* 4;
81 ar
&= (XCHAL_NUM_AREGS
- 1);
82 if (ar
< 16 && ar
+ (regs
->wmask
>> 4) * 4 >= 0)
88 case REG_A_BASE
... REG_A_BASE
+ 15:
89 tmp
= regs
->areg
[addr
- REG_A_BASE
];
95 /* Note: PS.EXCM is not set while user task is running;
96 * its being set in regs is for exception handling
98 tmp
= (regs
->ps
& ~(1 << PS_EXCM_BIT
));
101 tmp
= regs
->windowbase
;
104 tmp
= regs
->windowstart
;
122 tmp
= regs
->exccause
;
125 tmp
= regs
->excvaddr
;
135 ret
= put_user(tmp
, (unsigned long *) data
);
139 case PTRACE_POKETEXT
: /* write the word at location addr. */
140 case PTRACE_POKEDATA
:
141 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
149 struct pt_regs
*regs
;
150 regs
= task_pt_regs(child
);
153 case REG_AR_BASE
... REG_AR_BASE
+ XCHAL_NUM_AREGS
- 1:
155 int ar
= addr
- REG_AR_BASE
- regs
->windowbase
* 4;
156 if (ar
< 16 && ar
+ (regs
->wmask
>> 4) * 4 >= 0)
157 regs
->areg
[ar
& (XCHAL_NUM_AREGS
- 1)] = data
;
162 case REG_A_BASE
... REG_A_BASE
+ 15:
163 regs
->areg
[addr
- REG_A_BASE
] = data
;
169 regs
->syscall
= data
;
173 regs
->windowbase
= data
;
176 regs
->windowstart
= data
;
181 /* The rest are not allowed. */
188 /* continue and stop at next (return from) syscall */
190 case PTRACE_CONT
: /* restart after signal. */
193 if (!valid_signal(data
))
195 if (request
== PTRACE_SYSCALL
)
196 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
198 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
199 child
->exit_code
= data
;
200 /* Make sure the single step bit is not set. */
201 child
->ptrace
&= ~PT_SINGLESTEP
;
202 wake_up_process(child
);
208 * make the child exit. Best I can do is send it a sigkill.
209 * perhaps it should be put in the status that it wants to
214 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
216 child
->exit_code
= SIGKILL
;
217 child
->ptrace
&= ~PT_SINGLESTEP
;
218 wake_up_process(child
);
221 case PTRACE_SINGLESTEP
:
223 if (!valid_signal(data
))
225 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
226 child
->ptrace
|= PT_SINGLESTEP
;
227 child
->exit_code
= data
;
228 wake_up_process(child
);
234 /* 'data' points to user memory in which to write.
235 * Mainly due to the non-live register values, we
236 * reformat the register values into something more
237 * standard. For convenience, we use the handy
238 * elf_gregset_t format. */
240 xtensa_gregset_t format
;
241 struct pt_regs
*regs
= task_pt_regs(child
);
243 do_copy_regs (&format
, regs
, child
);
245 /* Now, copy to user space nice and easy... */
247 if (copy_to_user((void *)data
, &format
, sizeof(elf_gregset_t
)))
254 /* 'data' points to user memory that contains the new
255 * values in the elf_gregset_t format. */
257 xtensa_gregset_t format
;
258 struct pt_regs
*regs
= task_pt_regs(child
);
260 if (copy_from_user(&format
,(void *)data
,sizeof(elf_gregset_t
))){
265 /* FIXME: Perhaps we want some sanity checks on
266 * these user-space values? See ARM version. Are
267 * debuggers a security concern? */
269 do_restore_regs (&format
, regs
, child
);
275 case PTRACE_GETFPREGS
:
277 /* 'data' points to user memory in which to write.
278 * For convenience, we use the handy
279 * elf_fpregset_t format. */
281 elf_fpregset_t fpregs
;
282 struct pt_regs
*regs
= task_pt_regs(child
);
284 do_save_fpregs (&fpregs
, regs
, child
);
286 /* Now, copy to user space nice and easy... */
288 if (copy_to_user((void *)data
, &fpregs
, sizeof(elf_fpregset_t
)))
294 case PTRACE_SETFPREGS
:
296 /* 'data' points to user memory that contains the new
297 * values in the elf_fpregset_t format.
299 elf_fpregset_t fpregs
;
300 struct pt_regs
*regs
= task_pt_regs(child
);
303 if (copy_from_user(&fpregs
, (void *)data
, sizeof(elf_fpregset_t
))) {
308 if (do_restore_fpregs (&fpregs
, regs
, child
))
313 case PTRACE_GETFPREGSIZE
:
314 /* 'data' points to 'unsigned long' set to the size
317 ret
= put_user(sizeof(elf_fpregset_t
), (unsigned long *) data
);
320 case PTRACE_DETACH
: /* detach a process that was attached. */
321 ret
= ptrace_detach(child
, data
);
325 ret
= ptrace_request(child
, request
, addr
, data
);
332 void do_syscall_trace(void)
335 * The 0x80 provides a way for the tracing parent to distinguish
336 * between a syscall stop and SIGTRAP delivery
338 ptrace_notify(SIGTRAP
|((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80 : 0));
341 * this isn't the same as continuing with a signal, but it will do
342 * for normal use. strace only continues with a signal if the
343 * stopping signal is not SIGTRAP. -brl
345 if (current
->exit_code
) {
346 send_sig(current
->exit_code
, current
, 1);
347 current
->exit_code
= 0;
351 void do_syscall_trace_enter(struct pt_regs
*regs
)
353 if (test_thread_flag(TIF_SYSCALL_TRACE
)
354 && (current
->ptrace
& PT_PTRACED
))
358 if (unlikely(current
->audit_context
))
359 audit_syscall_entry(current
, AUDIT_ARCH_XTENSA
..);
363 void do_syscall_trace_leave(struct pt_regs
*regs
)
365 if ((test_thread_flag(TIF_SYSCALL_TRACE
))
366 && (current
->ptrace
& PT_PTRACED
))