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>
31 #include <asm/mipsregs.h>
32 #include <asm/mipsmtregs.h>
33 #include <asm/pgtable.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <asm/bootinfo.h>
39 int ptrace_getregs (struct task_struct
*child
, __s64 __user
*data
);
40 int ptrace_setregs (struct task_struct
*child
, __s64 __user
*data
);
42 int ptrace_getfpregs (struct task_struct
*child
, __u32 __user
*data
);
43 int ptrace_setfpregs (struct task_struct
*child
, __u32 __user
*data
);
46 * Tracing a 32-bit process with a 64-bit strace and vice versa will not
47 * work. I don't know how to fix this.
49 asmlinkage
int sys32_ptrace(int request
, int pid
, int addr
, int data
)
51 struct task_struct
*child
;
55 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
56 (int) request
, (int) pid
, (unsigned long) addr
,
57 (unsigned long) data
);
61 if (request
== PTRACE_TRACEME
) {
62 /* are we already being traced? */
63 if (current
->ptrace
& PT_PTRACED
)
65 if ((ret
= security_ptrace(current
->parent
, current
)))
67 /* set the ptrace bit in the process flags. */
68 current
->ptrace
|= PT_PTRACED
;
73 read_lock(&tasklist_lock
);
74 child
= find_task_by_pid(pid
);
76 get_task_struct(child
);
77 read_unlock(&tasklist_lock
);
82 if (pid
== 1) /* you may not mess with init */
85 if (request
== PTRACE_ATTACH
) {
86 ret
= ptrace_attach(child
);
90 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
95 /* when I and D space are separate, these will need to be fixed. */
96 case PTRACE_PEEKTEXT
: /* read word at location addr. */
97 case PTRACE_PEEKDATA
: {
101 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
103 if (copied
!= sizeof(tmp
))
105 ret
= put_user(tmp
, (unsigned int *) (unsigned long) data
);
110 * Read 4 bytes of the other process' storage
111 * data is a pointer specifying where the user wants the
112 * 4 bytes copied into
113 * addr is a pointer in the user's storage that contains an 8 byte
114 * address in the other process of the 4 bytes that is to be read
115 * (this is run in a 32-bit process looking at a 64-bit process)
116 * when I and D space are separate, these will need to be fixed.
118 case PTRACE_PEEKTEXT_3264
:
119 case PTRACE_PEEKDATA_3264
: {
122 u32 __user
* addrOthers
;
126 /* Get the addr in the other process that we want to read */
127 if (get_user(addrOthers
, (u32 __user
* __user
*) (unsigned long) addr
) != 0)
130 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
132 if (copied
!= sizeof(tmp
))
134 ret
= put_user(tmp
, (u32 __user
*) (unsigned long) data
);
138 /* Read the word at location addr in the USER area. */
139 case PTRACE_PEEKUSR
: {
140 struct pt_regs
*regs
;
143 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
144 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
145 ret
= 0; /* Default return value. */
149 tmp
= regs
->regs
[addr
];
151 case FPR_BASE
... FPR_BASE
+ 31:
152 if (tsk_used_math(child
)) {
153 fpureg_t
*fregs
= get_fpu_regs(child
);
156 * The odd registers are actually the high
157 * order bits of the values stored in the even
158 * registers - unless we're using r2k_switch.S.
161 tmp
= (unsigned long) (fregs
[((addr
& ~1) - 32)] >> 32);
163 tmp
= (unsigned long) (fregs
[(addr
- 32)] & 0xffffffff);
165 tmp
= -1; /* FP not yet used */
172 tmp
= regs
->cp0_cause
;
175 tmp
= regs
->cp0_badvaddr
;
185 tmp
= child
->thread
.fpu
.hard
.fcr31
;
187 tmp
= child
->thread
.fpu
.soft
.fcr31
;
189 case FPC_EIR
: { /* implementation / version register */
196 if (cpu_has_mipsmt
) {
197 unsigned int vpflags
= dvpe();
198 flags
= read_c0_status();
200 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
201 write_c0_status(flags
);
204 flags
= read_c0_status();
206 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
207 write_c0_status(flags
);
212 case DSP_BASE
... DSP_BASE
+ 5:
218 if (child
->thread
.dsp
.used_dsp
) {
219 dspreg_t
*dregs
= __get_dsp_regs(child
);
220 tmp
= (unsigned long) (dregs
[addr
- DSP_BASE
]);
222 tmp
= -1; /* DSP registers yet used */
231 tmp
= child
->thread
.dsp
.dspcontrol
;
238 ret
= put_user(tmp
, (unsigned *) (unsigned long) data
);
242 /* when I and D space are separate, this will have to be fixed. */
243 case PTRACE_POKETEXT
: /* write the word at location addr. */
244 case PTRACE_POKEDATA
:
246 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
253 * Write 4 bytes into the other process' storage
254 * data is the 4 bytes that the user wants written
255 * addr is a pointer in the user's storage that contains an
256 * 8 byte address in the other process where the 4 bytes
257 * that is to be written
258 * (this is run in a 32-bit process looking at a 64-bit process)
259 * when I and D space are separate, these will need to be fixed.
261 case PTRACE_POKETEXT_3264
:
262 case PTRACE_POKEDATA_3264
: {
263 u32 __user
* addrOthers
;
265 /* Get the addr in the other process that we want to write into */
267 if (get_user(addrOthers
, (u32 __user
* __user
*) (unsigned long) addr
) != 0)
270 if (access_process_vm(child
, (u64
)addrOthers
, &data
,
271 sizeof(data
), 1) == sizeof(data
))
277 case PTRACE_POKEUSR
: {
278 struct pt_regs
*regs
;
280 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
281 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
285 regs
->regs
[addr
] = data
;
287 case FPR_BASE
... FPR_BASE
+ 31: {
288 fpureg_t
*fregs
= get_fpu_regs(child
);
290 if (!tsk_used_math(child
)) {
291 /* FP not yet used */
292 memset(&child
->thread
.fpu
.hard
, ~0,
293 sizeof(child
->thread
.fpu
.hard
));
294 child
->thread
.fpu
.hard
.fcr31
= 0;
297 * The odd registers are actually the high order bits
298 * of the values stored in the even registers - unless
299 * we're using r2k_switch.S.
302 fregs
[(addr
& ~1) - FPR_BASE
] &= 0xffffffff;
303 fregs
[(addr
& ~1) - FPR_BASE
] |= ((unsigned long long) data
) << 32;
305 fregs
[addr
- FPR_BASE
] &= ~0xffffffffLL
;
306 /* Must cast, lest sign extension fill upper
308 fregs
[addr
- FPR_BASE
] |= (unsigned int)data
;
313 regs
->cp0_epc
= data
;
323 child
->thread
.fpu
.hard
.fcr31
= data
;
325 child
->thread
.fpu
.soft
.fcr31
= data
;
327 case DSP_BASE
... DSP_BASE
+ 5:
333 dspreg_t
*dregs
= __get_dsp_regs(child
);
334 dregs
[addr
- DSP_BASE
] = data
;
341 child
->thread
.dsp
.dspcontrol
= data
;
344 /* The rest are not allowed. */
352 ret
= ptrace_getregs (child
, (__u64 __user
*) (__u64
) data
);
356 ret
= ptrace_setregs (child
, (__u64 __user
*) (__u64
) data
);
359 case PTRACE_GETFPREGS
:
360 ret
= ptrace_getfpregs (child
, (__u32 __user
*) (__u64
) data
);
363 case PTRACE_SETFPREGS
:
364 ret
= ptrace_setfpregs (child
, (__u32 __user
*) (__u64
) data
);
367 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
368 case PTRACE_CONT
: { /* restart after signal. */
370 if (!valid_signal(data
))
372 if (request
== PTRACE_SYSCALL
) {
373 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
376 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
378 child
->exit_code
= data
;
379 wake_up_process(child
);
385 * make the child exit. Best I can do is send it a sigkill.
386 * perhaps it should be put in the status that it wants to
391 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
393 child
->exit_code
= SIGKILL
;
394 wake_up_process(child
);
397 case PTRACE_GET_THREAD_AREA
:
398 ret
= put_user(child
->thread_info
->tp_value
,
399 (unsigned int __user
*) (unsigned long) data
);
402 case PTRACE_DETACH
: /* detach a process that was attached. */
403 ret
= ptrace_detach(child
, data
);
406 case PTRACE_GETEVENTMSG
:
407 ret
= put_user(child
->ptrace_message
,
408 (unsigned int __user
*) (unsigned long) data
);
411 case PTRACE_GET_THREAD_AREA_3264
:
412 ret
= put_user(child
->thread_info
->tp_value
,
413 (unsigned long __user
*) (unsigned long) data
);
417 ret
= ptrace_request(child
, request
, addr
, data
);
422 put_task_struct(child
);