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
);
60 if (request
== PTRACE_TRACEME
) {
61 ret
= ptrace_traceme();
65 child
= ptrace_get_task_struct(pid
);
71 if (request
== PTRACE_ATTACH
) {
72 ret
= ptrace_attach(child
);
76 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
81 /* when I and D space are separate, these will need to be fixed. */
82 case PTRACE_PEEKTEXT
: /* read word at location addr. */
83 case PTRACE_PEEKDATA
: {
87 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
89 if (copied
!= sizeof(tmp
))
91 ret
= put_user(tmp
, (unsigned int __user
*) (unsigned long) data
);
96 * Read 4 bytes of the other process' storage
97 * data is a pointer specifying where the user wants the
99 * addr is a pointer in the user's storage that contains an 8 byte
100 * address in the other process of the 4 bytes that is to be read
101 * (this is run in a 32-bit process looking at a 64-bit process)
102 * when I and D space are separate, these will need to be fixed.
104 case PTRACE_PEEKTEXT_3264
:
105 case PTRACE_PEEKDATA_3264
: {
108 u32 __user
* addrOthers
;
112 /* Get the addr in the other process that we want to read */
113 if (get_user(addrOthers
, (u32 __user
* __user
*) (unsigned long) addr
) != 0)
116 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
118 if (copied
!= sizeof(tmp
))
120 ret
= put_user(tmp
, (u32 __user
*) (unsigned long) data
);
124 /* Read the word at location addr in the USER area. */
125 case PTRACE_PEEKUSR
: {
126 struct pt_regs
*regs
;
129 regs
= task_pt_regs(child
);
130 ret
= 0; /* Default return value. */
134 tmp
= regs
->regs
[addr
];
136 case FPR_BASE
... FPR_BASE
+ 31:
137 if (tsk_used_math(child
)) {
138 fpureg_t
*fregs
= get_fpu_regs(child
);
141 * The odd registers are actually the high
142 * order bits of the values stored in the even
143 * registers - unless we're using r2k_switch.S.
146 tmp
= (unsigned long) (fregs
[((addr
& ~1) - 32)] >> 32);
148 tmp
= (unsigned long) (fregs
[(addr
- 32)] & 0xffffffff);
150 tmp
= -1; /* FP not yet used */
157 tmp
= regs
->cp0_cause
;
160 tmp
= regs
->cp0_badvaddr
;
169 tmp
= child
->thread
.fpu
.fcr31
;
171 case FPC_EIR
: { /* implementation / version register */
173 #ifdef CONFIG_MIPS_MT_SMTC
174 unsigned int irqflags
;
175 unsigned int mtflags
;
176 #endif /* CONFIG_MIPS_MT_SMTC */
185 #ifdef CONFIG_MIPS_MT_SMTC
186 /* Read-modify-write of Status must be atomic */
187 local_irq_save(irqflags
);
189 #endif /* CONFIG_MIPS_MT_SMTC */
191 if (cpu_has_mipsmt
) {
192 unsigned int vpflags
= dvpe();
193 flags
= read_c0_status();
195 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
196 write_c0_status(flags
);
199 flags
= read_c0_status();
201 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
202 write_c0_status(flags
);
204 #ifdef CONFIG_MIPS_MT_SMTC
206 local_irq_restore(irqflags
);
207 #endif /* CONFIG_MIPS_MT_SMTC */
211 case DSP_BASE
... DSP_BASE
+ 5: {
219 dregs
= __get_dsp_regs(child
);
220 tmp
= (unsigned long) (dregs
[addr
- DSP_BASE
]);
229 tmp
= child
->thread
.dsp
.dspcontrol
;
236 ret
= put_user(tmp
, (unsigned __user
*) (unsigned long) data
);
240 /* when I and D space are separate, this will have to be fixed. */
241 case PTRACE_POKETEXT
: /* write the word at location addr. */
242 case PTRACE_POKEDATA
:
244 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
251 * Write 4 bytes into the other process' storage
252 * data is the 4 bytes that the user wants written
253 * addr is a pointer in the user's storage that contains an
254 * 8 byte address in the other process where the 4 bytes
255 * that is to be written
256 * (this is run in a 32-bit process looking at a 64-bit process)
257 * when I and D space are separate, these will need to be fixed.
259 case PTRACE_POKETEXT_3264
:
260 case PTRACE_POKEDATA_3264
: {
261 u32 __user
* addrOthers
;
263 /* Get the addr in the other process that we want to write into */
265 if (get_user(addrOthers
, (u32 __user
* __user
*) (unsigned long) addr
) != 0)
268 if (access_process_vm(child
, (u64
)addrOthers
, &data
,
269 sizeof(data
), 1) == sizeof(data
))
275 case PTRACE_POKEUSR
: {
276 struct pt_regs
*regs
;
278 regs
= task_pt_regs(child
);
282 regs
->regs
[addr
] = data
;
284 case FPR_BASE
... FPR_BASE
+ 31: {
285 fpureg_t
*fregs
= get_fpu_regs(child
);
287 if (!tsk_used_math(child
)) {
288 /* FP not yet used */
289 memset(&child
->thread
.fpu
, ~0,
290 sizeof(child
->thread
.fpu
));
291 child
->thread
.fpu
.fcr31
= 0;
294 * The odd registers are actually the high order bits
295 * of the values stored in the even registers - unless
296 * we're using r2k_switch.S.
299 fregs
[(addr
& ~1) - FPR_BASE
] &= 0xffffffff;
300 fregs
[(addr
& ~1) - FPR_BASE
] |= ((unsigned long long) data
) << 32;
302 fregs
[addr
- FPR_BASE
] &= ~0xffffffffLL
;
303 /* Must cast, lest sign extension fill upper
305 fregs
[addr
- FPR_BASE
] |= (unsigned int)data
;
310 regs
->cp0_epc
= data
;
319 child
->thread
.fpu
.fcr31
= data
;
321 case DSP_BASE
... DSP_BASE
+ 5: {
329 dregs
= __get_dsp_regs(child
);
330 dregs
[addr
- DSP_BASE
] = data
;
338 child
->thread
.dsp
.dspcontrol
= data
;
341 /* The rest are not allowed. */
349 ret
= ptrace_getregs(child
, (__s64 __user
*) (__u64
) data
);
353 ret
= ptrace_setregs(child
, (__s64 __user
*) (__u64
) data
);
356 case PTRACE_GETFPREGS
:
357 ret
= ptrace_getfpregs(child
, (__u32 __user
*) (__u64
) data
);
360 case PTRACE_SETFPREGS
:
361 ret
= ptrace_setfpregs(child
, (__u32 __user
*) (__u64
) data
);
364 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
365 case PTRACE_CONT
: { /* restart after signal. */
367 if (!valid_signal(data
))
369 if (request
== PTRACE_SYSCALL
) {
370 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
373 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
375 child
->exit_code
= data
;
376 wake_up_process(child
);
382 * make the child exit. Best I can do is send it a sigkill.
383 * perhaps it should be put in the status that it wants to
388 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
390 child
->exit_code
= SIGKILL
;
391 wake_up_process(child
);
394 case PTRACE_GET_THREAD_AREA
:
395 ret
= put_user(task_thread_info(child
)->tp_value
,
396 (unsigned int __user
*) (unsigned long) data
);
399 case PTRACE_DETACH
: /* detach a process that was attached. */
400 ret
= ptrace_detach(child
, data
);
403 case PTRACE_GETEVENTMSG
:
404 ret
= put_user(child
->ptrace_message
,
405 (unsigned int __user
*) (unsigned long) data
);
408 case PTRACE_GET_THREAD_AREA_3264
:
409 ret
= put_user(task_thread_info(child
)->tp_value
,
410 (unsigned long __user
*) (unsigned long) data
);
414 ret
= ptrace_request(child
, request
, addr
, data
);
419 put_task_struct(child
);