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/config.h>
18 #include <linux/compiler.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
22 #include <linux/errno.h>
23 #include <linux/ptrace.h>
24 #include <linux/audit.h>
25 #include <linux/smp.h>
26 #include <linux/smp_lock.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/signal.h>
33 #include <asm/mipsregs.h>
34 #include <asm/pgtable.h>
36 #include <asm/system.h>
37 #include <asm/uaccess.h>
38 #include <asm/bootinfo.h>
41 * Called by kernel/ptrace.c when detaching..
43 * Make sure single step bits etc are not set.
45 void ptrace_disable(struct task_struct
*child
)
50 asmlinkage
int sys_ptrace(long request
, long pid
, long addr
, long data
)
52 struct task_struct
*child
;
56 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
57 (int) request
, (int) pid
, (unsigned long) addr
,
58 (unsigned long) data
);
62 if (request
== PTRACE_TRACEME
) {
63 /* are we already being traced? */
64 if (current
->ptrace
& PT_PTRACED
)
66 if ((ret
= security_ptrace(current
->parent
, current
)))
68 /* set the ptrace bit in the process flags. */
69 current
->ptrace
|= PT_PTRACED
;
74 read_lock(&tasklist_lock
);
75 child
= find_task_by_pid(pid
);
77 get_task_struct(child
);
78 read_unlock(&tasklist_lock
);
83 if (pid
== 1) /* you may not mess with init */
86 if (request
== PTRACE_ATTACH
) {
87 ret
= ptrace_attach(child
);
91 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
96 /* when I and D space are separate, these will need to be fixed. */
97 case PTRACE_PEEKTEXT
: /* read word at location addr. */
98 case PTRACE_PEEKDATA
: {
102 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
104 if (copied
!= sizeof(tmp
))
106 ret
= put_user(tmp
,(unsigned long *) data
);
110 /* Read the word at location addr in the USER area. */
111 case PTRACE_PEEKUSR
: {
112 struct pt_regs
*regs
;
113 unsigned long tmp
= 0;
115 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
116 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
117 ret
= 0; /* Default return value. */
121 tmp
= regs
->regs
[addr
];
123 case FPR_BASE
... FPR_BASE
+ 31:
124 if (tsk_used_math(child
)) {
125 fpureg_t
*fregs
= get_fpu_regs(child
);
129 * The odd registers are actually the high
130 * order bits of the values stored in the even
131 * registers - unless we're using r2k_switch.S.
134 tmp
= (unsigned long) (fregs
[((addr
& ~1) - 32)] >> 32);
136 tmp
= (unsigned long) (fregs
[(addr
- 32)] & 0xffffffff);
139 tmp
= fregs
[addr
- FPR_BASE
];
142 tmp
= -1; /* FP not yet used */
149 tmp
= regs
->cp0_cause
;
152 tmp
= regs
->cp0_badvaddr
;
162 tmp
= child
->thread
.fpu
.hard
.fcr31
;
164 tmp
= child
->thread
.fpu
.soft
.fcr31
;
166 case FPC_EIR
: { /* implementation / version register */
172 flags
= read_c0_status();
174 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
175 write_c0_status(flags
);
183 ret
= put_user(tmp
, (unsigned long *) data
);
187 /* when I and D space are separate, this will have to be fixed. */
188 case PTRACE_POKETEXT
: /* write the word at location addr. */
189 case PTRACE_POKEDATA
:
191 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
197 case PTRACE_POKEUSR
: {
198 struct pt_regs
*regs
;
200 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
201 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
205 regs
->regs
[addr
] = data
;
207 case FPR_BASE
... FPR_BASE
+ 31: {
208 fpureg_t
*fregs
= get_fpu_regs(child
);
210 if (!tsk_used_math(child
)) {
211 /* FP not yet used */
212 memset(&child
->thread
.fpu
.hard
, ~0,
213 sizeof(child
->thread
.fpu
.hard
));
214 child
->thread
.fpu
.hard
.fcr31
= 0;
218 * The odd registers are actually the high order bits
219 * of the values stored in the even registers - unless
220 * we're using r2k_switch.S.
223 fregs
[(addr
& ~1) - FPR_BASE
] &= 0xffffffff;
224 fregs
[(addr
& ~1) - FPR_BASE
] |= ((unsigned long long) data
) << 32;
226 fregs
[addr
- FPR_BASE
] &= ~0xffffffffLL
;
227 fregs
[addr
- FPR_BASE
] |= data
;
231 fregs
[addr
- FPR_BASE
] = data
;
236 regs
->cp0_epc
= data
;
246 child
->thread
.fpu
.hard
.fcr31
= data
;
248 child
->thread
.fpu
.soft
.fcr31
= data
;
251 /* The rest are not allowed. */
258 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
259 case PTRACE_CONT
: { /* restart after signal. */
261 if (!valid_signal(data
))
263 if (request
== PTRACE_SYSCALL
) {
264 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
267 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
269 child
->exit_code
= data
;
270 wake_up_process(child
);
276 * make the child exit. Best I can do is send it a sigkill.
277 * perhaps it should be put in the status that it wants to
282 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
284 child
->exit_code
= SIGKILL
;
285 wake_up_process(child
);
288 case PTRACE_DETACH
: /* detach a process that was attached. */
289 ret
= ptrace_detach(child
, data
);
293 ret
= ptrace_request(child
, request
, addr
, data
);
298 put_task_struct(child
);
304 static inline int audit_arch(void)
306 #ifdef CONFIG_CPU_LITTLE_ENDIAN
308 if (!(current
->thread
.mflags
& MF_32BIT_REGS
))
309 return AUDIT_ARCH_MIPSEL64
;
311 return AUDIT_ARCH_MIPSEL
;
313 #else /* big endian... */
315 if (!(current
->thread
.mflags
& MF_32BIT_REGS
))
316 return AUDIT_ARCH_MIPS64
;
318 return AUDIT_ARCH_MIPS
;
324 * Notification of system call entry/exit
325 * - triggered by current->work.syscall_trace
327 asmlinkage
void do_syscall_trace(struct pt_regs
*regs
, int entryexit
)
329 if (unlikely(current
->audit_context
) && entryexit
)
330 audit_syscall_exit(current
, AUDITSC_RESULT(regs
->regs
[2]), regs
->regs
[2]);
332 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
334 if (!(current
->ptrace
& PT_PTRACED
))
337 /* The 0x80 provides a way for the tracing parent to distinguish
338 between a syscall stop and SIGTRAP delivery */
339 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
) ?
343 * this isn't the same as continuing with a signal, but it will do
344 * for normal use. strace only continues with a signal if the
345 * stopping signal is not SIGTRAP. -brl
347 if (current
->exit_code
) {
348 send_sig(current
->exit_code
, current
, 1);
349 current
->exit_code
= 0;
352 if (unlikely(current
->audit_context
) && !entryexit
)
353 audit_syscall_entry(current
, audit_arch(), regs
->regs
[2],
354 regs
->regs
[4], regs
->regs
[5],
355 regs
->regs
[6], regs
->regs
[7]);