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 ret
= generic_ptrace_pokedata(child
, addr
, data
);
136 struct pt_regs
*regs
;
137 regs
= task_pt_regs(child
);
140 case REG_AR_BASE
... REG_AR_BASE
+ XCHAL_NUM_AREGS
- 1:
142 int ar
= addr
- REG_AR_BASE
- regs
->windowbase
* 4;
143 if (ar
< 16 && ar
+ (regs
->wmask
>> 4) * 4 >= 0)
144 regs
->areg
[ar
& (XCHAL_NUM_AREGS
- 1)] = data
;
149 case REG_A_BASE
... REG_A_BASE
+ 15:
150 regs
->areg
[addr
- REG_A_BASE
] = data
;
156 regs
->syscall
= data
;
160 regs
->windowbase
= data
;
163 regs
->windowstart
= data
;
168 /* The rest are not allowed. */
175 /* continue and stop at next (return from) syscall */
177 case PTRACE_CONT
: /* restart after signal. */
180 if (!valid_signal(data
))
182 if (request
== PTRACE_SYSCALL
)
183 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
185 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
186 child
->exit_code
= data
;
187 /* Make sure the single step bit is not set. */
188 child
->ptrace
&= ~PT_SINGLESTEP
;
189 wake_up_process(child
);
195 * make the child exit. Best I can do is send it a sigkill.
196 * perhaps it should be put in the status that it wants to
201 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
203 child
->exit_code
= SIGKILL
;
204 child
->ptrace
&= ~PT_SINGLESTEP
;
205 wake_up_process(child
);
208 case PTRACE_SINGLESTEP
:
210 if (!valid_signal(data
))
212 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
213 child
->ptrace
|= PT_SINGLESTEP
;
214 child
->exit_code
= data
;
215 wake_up_process(child
);
221 /* 'data' points to user memory in which to write.
222 * Mainly due to the non-live register values, we
223 * reformat the register values into something more
224 * standard. For convenience, we use the handy
225 * elf_gregset_t format. */
227 xtensa_gregset_t format
;
228 struct pt_regs
*regs
= task_pt_regs(child
);
230 do_copy_regs (&format
, regs
, child
);
232 /* Now, copy to user space nice and easy... */
234 if (copy_to_user((void *)data
, &format
, sizeof(elf_gregset_t
)))
241 /* 'data' points to user memory that contains the new
242 * values in the elf_gregset_t format. */
244 xtensa_gregset_t format
;
245 struct pt_regs
*regs
= task_pt_regs(child
);
247 if (copy_from_user(&format
,(void *)data
,sizeof(elf_gregset_t
))){
252 /* FIXME: Perhaps we want some sanity checks on
253 * these user-space values? See ARM version. Are
254 * debuggers a security concern? */
256 do_restore_regs (&format
, regs
, child
);
262 case PTRACE_GETFPREGS
:
264 /* 'data' points to user memory in which to write.
265 * For convenience, we use the handy
266 * elf_fpregset_t format. */
268 elf_fpregset_t fpregs
;
269 struct pt_regs
*regs
= task_pt_regs(child
);
271 do_save_fpregs (&fpregs
, regs
, child
);
273 /* Now, copy to user space nice and easy... */
275 if (copy_to_user((void *)data
, &fpregs
, sizeof(elf_fpregset_t
)))
281 case PTRACE_SETFPREGS
:
283 /* 'data' points to user memory that contains the new
284 * values in the elf_fpregset_t format.
286 elf_fpregset_t fpregs
;
287 struct pt_regs
*regs
= task_pt_regs(child
);
290 if (copy_from_user(&fpregs
, (void *)data
, sizeof(elf_fpregset_t
))) {
295 if (do_restore_fpregs (&fpregs
, regs
, child
))
300 case PTRACE_GETFPREGSIZE
:
301 /* 'data' points to 'unsigned long' set to the size
304 ret
= put_user(sizeof(elf_fpregset_t
), (unsigned long *) data
);
308 ret
= ptrace_request(child
, request
, addr
, data
);
315 void do_syscall_trace(void)
318 * The 0x80 provides a way for the tracing parent to distinguish
319 * between a syscall stop and SIGTRAP delivery
321 ptrace_notify(SIGTRAP
|((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80 : 0));
324 * this isn't the same as continuing with a signal, but it will do
325 * for normal use. strace only continues with a signal if the
326 * stopping signal is not SIGTRAP. -brl
328 if (current
->exit_code
) {
329 send_sig(current
->exit_code
, current
, 1);
330 current
->exit_code
= 0;
334 void do_syscall_trace_enter(struct pt_regs
*regs
)
336 if (test_thread_flag(TIF_SYSCALL_TRACE
)
337 && (current
->ptrace
& PT_PTRACED
))
341 if (unlikely(current
->audit_context
))
342 audit_syscall_entry(current
, AUDIT_ARCH_XTENSA
..);
346 void do_syscall_trace_leave(struct pt_regs
*regs
)
348 if ((test_thread_flag(TIF_SYSCALL_TRACE
))
349 && (current
->ptrace
& PT_PTRACED
))