2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1992 Ross Biro
7 * Copyright (C) Linus Torvalds
8 * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
9 * Copyright (C) 1996 David S. Miller
10 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
11 * Copyright (C) 1999 MIPS Technologies, Inc.
13 #include <linux/config.h>
14 #include <linux/compiler.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
18 #include <linux/errno.h>
19 #include <linux/ptrace.h>
20 #include <linux/smp.h>
21 #include <linux/smp_lock.h>
22 #include <linux/user.h>
24 #include <asm/mipsregs.h>
25 #include <asm/pgtable.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
29 #include <asm/bootinfo.h>
34 * Called by kernel/ptrace.c when detaching..
36 * Make sure single step bits etc are not set.
38 void ptrace_disable(struct task_struct
*child
)
43 asmlinkage
int sys_ptrace(long request
, long pid
, long addr
, long data
)
45 struct task_struct
*child
;
50 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
51 (int) request
, (int) pid
, (unsigned long) addr
,
52 (unsigned long) data
);
54 if (request
== PTRACE_TRACEME
) {
55 /* are we already being traced? */
56 if (current
->ptrace
& PT_PTRACED
) {
60 /* set the ptrace bit in the process flags. */
61 current
->ptrace
|= PT_PTRACED
;
66 read_lock(&tasklist_lock
);
67 child
= find_task_by_pid(pid
);
69 get_task_struct(child
);
70 read_unlock(&tasklist_lock
);
75 if (pid
== 1) /* you may not mess with init */
78 if (request
== PTRACE_ATTACH
) {
79 ret
= ptrace_attach(child
);
83 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
88 case PTRACE_PEEKTEXT
: /* read word at location addr. */
89 case PTRACE_PEEKDATA
: {
93 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
95 if (copied
!= sizeof(tmp
))
97 ret
= put_user(tmp
,(unsigned long *) data
);
101 /* Read the word at location addr in the USER area. */
102 case PTRACE_PEEKUSR
: {
103 struct pt_regs
*regs
;
106 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
107 KERNEL_STACK_SIZE
- 32 - sizeof(struct pt_regs
));
108 tmp
= 0; /* Default return value. */
112 tmp
= regs
->regs
[addr
];
114 case FPR_BASE
... FPR_BASE
+ 31:
115 if (child
->used_math
) {
116 unsigned long long *fregs
= get_fpu_regs(child
);
118 * The odd registers are actually the high
119 * order bits of the values stored in the even
120 * registers - unless we're using r2k_switch.S.
123 tmp
= (unsigned long) (fregs
[((addr
& ~1) - 32)] >> 32);
125 tmp
= (unsigned long) (fregs
[(addr
- 32)] & 0xffffffff);
127 tmp
= -1; /* FP not yet used */
134 tmp
= regs
->cp0_cause
;
137 tmp
= regs
->cp0_badvaddr
;
146 if (!(current_cpu_data
.options
& MIPS_CPU_FPU
))
147 tmp
= child
->thread
.fpu
.soft
.sr
;
149 tmp
= child
->thread
.fpu
.hard
.control
;
151 case FPC_EIR
: { /* implementation / version register */
154 if (!(current_cpu_data
.options
& MIPS_CPU_FPU
)) {
158 flags
= read_c0_status();
160 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
161 write_c0_status(flags
);
169 ret
= put_user(tmp
, (unsigned long *) data
);
173 case PTRACE_POKETEXT
: /* write the word at location addr. */
174 case PTRACE_POKEDATA
:
176 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
182 case PTRACE_POKEUSR
: {
183 struct pt_regs
*regs
;
185 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
186 KERNEL_STACK_SIZE
- 32 - sizeof(struct pt_regs
));
190 regs
->regs
[addr
] = data
;
192 case FPR_BASE
... FPR_BASE
+ 31: {
193 unsigned long long *fregs
;
194 fregs
= (unsigned long long *)get_fpu_regs(child
);
195 if (!child
->used_math
) {
196 /* FP not yet used */
197 memset(&child
->thread
.fpu
.hard
, ~0,
198 sizeof(child
->thread
.fpu
.hard
));
199 child
->thread
.fpu
.hard
.control
= 0;
202 * The odd registers are actually the high order bits
203 * of the values stored in the even registers - unless
204 * we're using r2k_switch.S.
207 fregs
[(addr
& ~1) - FPR_BASE
] &= 0xffffffff;
208 fregs
[(addr
& ~1) - FPR_BASE
] |= ((unsigned long long) data
) << 32;
210 fregs
[addr
- FPR_BASE
] &= ~0xffffffffLL
;
211 fregs
[addr
- FPR_BASE
] |= data
;
216 regs
->cp0_epc
= data
;
225 if (!(current_cpu_data
.options
& MIPS_CPU_FPU
))
226 child
->thread
.fpu
.soft
.sr
= data
;
228 child
->thread
.fpu
.hard
.control
= data
;
231 /* The rest are not allowed. */
238 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
239 case PTRACE_CONT
: { /* restart after signal. */
241 if ((unsigned long) data
> _NSIG
)
243 if (request
== PTRACE_SYSCALL
) {
244 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
247 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
249 child
->exit_code
= data
;
250 wake_up_process(child
);
256 * make the child exit. Best I can do is send it a sigkill.
257 * perhaps it should be put in the status that it wants to
262 if (child
->state
== TASK_ZOMBIE
) /* already dead */
264 child
->exit_code
= SIGKILL
;
265 wake_up_process(child
);
268 case PTRACE_DETACH
: /* detach a process that was attached. */
269 ret
= ptrace_detach(child
, data
);
273 ret
= ptrace_request(child
, request
, addr
, data
);
277 put_task_struct(child
);
284 * Notification of system call entry/exit
285 * - triggered by current->work.syscall_trace
287 asmlinkage
void do_syscall_trace(void)
289 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
291 if (!(current
->ptrace
& PT_PTRACED
))
294 /* The 0x80 provides a way for the tracing parent to distinguish
295 between a syscall stop and SIGTRAP delivery */
296 current
->exit_code
= SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
299 current
->state
= TASK_STOPPED
;
300 notify_parent(current
, SIGCHLD
);
304 * this isn't the same as continuing with a signal, but it will do
305 * for normal use. strace only continues with a signal if the
306 * stopping signal is not SIGTRAP. -brl
308 if (current
->exit_code
) {
309 send_sig(current
->exit_code
, current
, 1);
310 current
->exit_code
= 0;