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.
12 * Copyright (C) 2000 Ulf Carlsson
14 * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit
17 #include <linux/compiler.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
21 #include <linux/errno.h>
22 #include <linux/ptrace.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/user.h>
26 #include <linux/security.h>
27 #include <linux/signal.h>
31 #include <asm/mipsregs.h>
32 #include <asm/pgtable.h>
34 #include <asm/system.h>
35 #include <asm/uaccess.h>
36 #include <asm/bootinfo.h>
39 * Tracing a 32-bit process with a 64-bit strace and vice versa will not
40 * work. I don't know how to fix this.
42 asmlinkage
int sys32_ptrace(int request
, int pid
, int addr
, int data
)
44 struct task_struct
*child
;
48 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
49 (int) request
, (int) pid
, (unsigned long) addr
,
50 (unsigned long) data
);
54 if (request
== PTRACE_TRACEME
) {
55 /* are we already being traced? */
56 if (current
->ptrace
& PT_PTRACED
)
58 if ((ret
= security_ptrace(current
->parent
, current
)))
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 /* when I and D space are separate, these will need to be fixed. */
89 case PTRACE_PEEKTEXT
: /* read word at location addr. */
90 case PTRACE_PEEKDATA
: {
94 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
96 if (copied
!= sizeof(tmp
))
98 ret
= put_user(tmp
, (unsigned int *) (unsigned long) data
);
102 /* Read the word at location addr in the USER area. */
103 case PTRACE_PEEKUSR
: {
104 struct pt_regs
*regs
;
107 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
108 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
109 ret
= 0; /* Default return value. */
113 tmp
= regs
->regs
[addr
];
115 case FPR_BASE
... FPR_BASE
+ 31:
116 if (tsk_used_math(child
)) {
117 fpureg_t
*fregs
= get_fpu_regs(child
);
120 * The odd registers are actually the high
121 * order bits of the values stored in the even
122 * registers - unless we're using r2k_switch.S.
125 tmp
= (unsigned long) (fregs
[((addr
& ~1) - 32)] >> 32);
127 tmp
= (unsigned long) (fregs
[(addr
- 32)] & 0xffffffff);
129 tmp
= -1; /* FP not yet used */
136 tmp
= regs
->cp0_cause
;
139 tmp
= regs
->cp0_badvaddr
;
149 tmp
= child
->thread
.fpu
.hard
.fcr31
;
151 tmp
= child
->thread
.fpu
.soft
.fcr31
;
153 case FPC_EIR
: { /* implementation / version register */
159 flags
= read_c0_status();
161 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
162 write_c0_status(flags
);
170 ret
= put_user(tmp
, (unsigned *) (unsigned long) data
);
174 /* when I and D space are separate, this will have to be fixed. */
175 case PTRACE_POKETEXT
: /* write the word at location addr. */
176 case PTRACE_POKEDATA
:
178 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
184 case PTRACE_POKEUSR
: {
185 struct pt_regs
*regs
;
187 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
188 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
192 regs
->regs
[addr
] = data
;
194 case FPR_BASE
... FPR_BASE
+ 31: {
195 fpureg_t
*fregs
= get_fpu_regs(child
);
197 if (!tsk_used_math(child
)) {
198 /* FP not yet used */
199 memset(&child
->thread
.fpu
.hard
, ~0,
200 sizeof(child
->thread
.fpu
.hard
));
201 child
->thread
.fpu
.hard
.fcr31
= 0;
204 * The odd registers are actually the high order bits
205 * of the values stored in the even registers - unless
206 * we're using r2k_switch.S.
209 fregs
[(addr
& ~1) - FPR_BASE
] &= 0xffffffff;
210 fregs
[(addr
& ~1) - FPR_BASE
] |= ((unsigned long long) data
) << 32;
212 fregs
[addr
- FPR_BASE
] &= ~0xffffffffLL
;
213 /* Must cast, lest sign extension fill upper
215 fregs
[addr
- FPR_BASE
] |= (unsigned int)data
;
220 regs
->cp0_epc
= data
;
230 child
->thread
.fpu
.hard
.fcr31
= data
;
232 child
->thread
.fpu
.soft
.fcr31
= data
;
235 /* The rest are not allowed. */
242 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
243 case PTRACE_CONT
: { /* restart after signal. */
245 if (!valid_signal(data
))
247 if (request
== PTRACE_SYSCALL
) {
248 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
251 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
253 child
->exit_code
= data
;
254 wake_up_process(child
);
260 * make the child exit. Best I can do is send it a sigkill.
261 * perhaps it should be put in the status that it wants to
266 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
268 child
->exit_code
= SIGKILL
;
269 wake_up_process(child
);
272 case PTRACE_DETACH
: /* detach a process that was attached. */
273 ret
= ptrace_detach(child
, data
);
277 ret
= ptrace_request(child
, request
, addr
, data
);
282 put_task_struct(child
);