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>
31 #include <asm/byteorder.h>
35 #include <asm/mipsregs.h>
36 #include <asm/pgtable.h>
38 #include <asm/system.h>
39 #include <asm/uaccess.h>
40 #include <asm/bootinfo.h>
43 * Called by kernel/ptrace.c when detaching..
45 * Make sure single step bits etc are not set.
47 void ptrace_disable(struct task_struct *child)
52 asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
54 struct task_struct *child;
58 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
59 (int) request, (int) pid, (unsigned long) addr,
60 (unsigned long) data);
64 if (request == PTRACE_TRACEME) {
65 /* are we already being traced? */
66 if (current->ptrace & PT_PTRACED)
68 if ((ret = security_ptrace(current->parent, current)))
70 /* set the ptrace bit in the process flags. */
71 current->ptrace |= PT_PTRACED;
76 read_lock(&tasklist_lock);
77 child = find_task_by_pid(pid);
79 get_task_struct(child);
80 read_unlock(&tasklist_lock);
85 if (pid == 1) /* you may not mess with init */
88 if (request == PTRACE_ATTACH) {
89 ret = ptrace_attach(child);
93 ret = ptrace_check_attach(child, request == PTRACE_KILL);
98 /* when I and D space are separate, these will need to be fixed. */
99 case PTRACE_PEEKTEXT: /* read word at location addr. */
100 case PTRACE_PEEKDATA: {
104 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
106 if (copied != sizeof(tmp))
108 ret = put_user(tmp,(unsigned long __user *) data);
112 /* Read the word at location addr in the USER area. */
113 case PTRACE_PEEKUSR: {
114 struct pt_regs *regs;
115 unsigned long tmp = 0;
117 regs = (struct pt_regs *) ((unsigned long) child->thread_info +
118 THREAD_SIZE - 32 - sizeof(struct pt_regs));
119 ret = 0; /* Default return value. */
123 tmp = regs->regs[addr];
125 case FPR_BASE ... FPR_BASE + 31:
126 if (tsk_used_math(child)) {
127 fpureg_t *fregs = get_fpu_regs(child);
131 * The odd registers are actually the high
132 * order bits of the values stored in the even
133 * registers - unless we're using r2k_switch.S.
136 tmp = (unsigned long) (fregs[((addr & ~1) - 32)] >> 32);
138 tmp = (unsigned long) (fregs[(addr - 32)] & 0xffffffff);
141 tmp = fregs[addr - FPR_BASE];
144 tmp = -1; /* FP not yet used */
151 tmp = regs->cp0_cause;
154 tmp = regs->cp0_badvaddr;
164 tmp = child->thread.fpu.hard.fcr31;
166 tmp = child->thread.fpu.soft.fcr31;
168 case FPC_EIR: { /* implementation / version register */
174 flags = read_c0_status();
176 __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp));
177 write_c0_status(flags);
180 case DSP_BASE ... DSP_BASE + 5:
186 if (child->thread.dsp.used_dsp) {
187 dspreg_t *dregs = __get_dsp_regs(child);
188 tmp = (unsigned long) (dregs[addr - DSP_BASE]);
190 tmp = -1; /* DSP registers yet used */
199 tmp = child->thread.dsp.dspcontrol;
206 ret = put_user(tmp, (unsigned long __user *) data);
210 /* when I and D space are separate, this will have to be fixed. */
211 case PTRACE_POKETEXT: /* write the word at location addr. */
212 case PTRACE_POKEDATA:
214 if (access_process_vm(child, addr, &data, sizeof(data), 1)
220 case PTRACE_POKEUSR: {
221 struct pt_regs *regs;
223 regs = (struct pt_regs *) ((unsigned long) child->thread_info +
224 THREAD_SIZE - 32 - sizeof(struct pt_regs));
228 regs->regs[addr] = data;
230 case FPR_BASE ... FPR_BASE + 31: {
231 fpureg_t *fregs = get_fpu_regs(child);
233 if (!tsk_used_math(child)) {
234 /* FP not yet used */
235 memset(&child->thread.fpu.hard, ~0,
236 sizeof(child->thread.fpu.hard));
237 child->thread.fpu.hard.fcr31 = 0;
241 * The odd registers are actually the high order bits
242 * of the values stored in the even registers - unless
243 * we're using r2k_switch.S.
246 fregs[(addr & ~1) - FPR_BASE] &= 0xffffffff;
247 fregs[(addr & ~1) - FPR_BASE] |= ((unsigned long long) data) << 32;
249 fregs[addr - FPR_BASE] &= ~0xffffffffLL;
250 fregs[addr - FPR_BASE] |= data;
254 fregs[addr - FPR_BASE] = data;
259 regs->cp0_epc = data;
269 child->thread.fpu.hard.fcr31 = data;
271 child->thread.fpu.soft.fcr31 = data;
273 case DSP_BASE ... DSP_BASE + 5:
279 dspreg_t *dregs = __get_dsp_regs(child);
280 dregs[addr - DSP_BASE] = data;
287 child->thread.dsp.dspcontrol = data;
290 /* The rest are not allowed. */
297 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
298 case PTRACE_CONT: { /* restart after signal. */
300 if (!valid_signal(data))
302 if (request == PTRACE_SYSCALL) {
303 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
306 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
308 child->exit_code = data;
309 wake_up_process(child);
315 * make the child exit. Best I can do is send it a sigkill.
316 * perhaps it should be put in the status that it wants to
321 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
323 child->exit_code = SIGKILL;
324 wake_up_process(child);
327 case PTRACE_DETACH: /* detach a process that was attached. */
328 ret = ptrace_detach(child, data);
331 case PTRACE_GET_THREAD_AREA:
332 ret = put_user(child->thread_info->tp_value,
333 (unsigned long __user *) data);
337 ret = ptrace_request(child, request, addr, data);
342 put_task_struct(child);
348 static inline int audit_arch(void)
352 arch |= __AUDIT_ARCH_64BIT;
354 #if defined(__LITTLE_ENDIAN)
355 arch |= __AUDIT_ARCH_LE;
361 * Notification of system call entry/exit
362 * - triggered by current->work.syscall_trace
364 asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit)
366 if (unlikely(current->audit_context) && entryexit)
367 audit_syscall_exit(current, AUDITSC_RESULT(regs->regs[2]),
370 if (!(current->ptrace & PT_PTRACED))
372 if (!test_thread_flag(TIF_SYSCALL_TRACE))
375 /* The 0x80 provides a way for the tracing parent to distinguish
376 between a syscall stop and SIGTRAP delivery */
377 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ?
381 * this isn't the same as continuing with a signal, but it will do
382 * for normal use. strace only continues with a signal if the
383 * stopping signal is not SIGTRAP. -brl
385 if (current->exit_code) {
386 send_sig(current->exit_code, current, 1);
387 current->exit_code = 0;
390 if (unlikely(current->audit_context) && !entryexit)
391 audit_syscall_entry(current, audit_arch(), regs->regs[2],
392 regs->regs[4], regs->regs[5],
393 regs->regs[6], regs->regs[7]);