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/smp.h>
25 #include <linux/smp_lock.h>
26 #include <linux/user.h>
27 #include <linux/security.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 * Called by kernel/ptrace.c when detaching..
41 * Make sure single step bits etc are not set.
43 void ptrace_disable(struct task_struct *child)
48 asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
50 struct task_struct *child;
54 printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n",
55 (int) request, (int) pid, (unsigned long) addr,
56 (unsigned long) data);
60 if (request == PTRACE_TRACEME) {
61 /* are we already being traced? */
62 if (current->ptrace & PT_PTRACED)
64 if ((ret = security_ptrace(current->parent, current)))
66 /* set the ptrace bit in the process flags. */
67 current->ptrace |= PT_PTRACED;
72 read_lock(&tasklist_lock);
73 child = find_task_by_pid(pid);
75 get_task_struct(child);
76 read_unlock(&tasklist_lock);
81 if (pid == 1) /* you may not mess with init */
84 if (request == PTRACE_ATTACH) {
85 ret = ptrace_attach(child);
89 ret = ptrace_check_attach(child, request == PTRACE_KILL);
94 /* when I and D space are separate, these will need to be fixed. */
95 case PTRACE_PEEKTEXT: /* read word at location addr. */
96 case PTRACE_PEEKDATA: {
100 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
102 if (copied != sizeof(tmp))
104 ret = put_user(tmp,(unsigned long *) data);
108 /* Read the word at location addr in the USER area. */
109 case PTRACE_PEEKUSR: {
110 struct pt_regs *regs;
111 unsigned long tmp = 0;
113 regs = (struct pt_regs *) ((unsigned long) child->thread_info +
114 THREAD_SIZE - 32 - sizeof(struct pt_regs));
115 ret = 0; /* Default return value. */
119 tmp = regs->regs[addr];
121 case FPR_BASE ... FPR_BASE + 31:
122 if (child->used_math) {
123 fpureg_t *fregs = get_fpu_regs(child);
127 * The odd registers are actually the high
128 * order bits of the values stored in the even
129 * registers - unless we're using r2k_switch.S.
132 tmp = (unsigned long) (fregs[((addr & ~1) - 32)] >> 32);
134 tmp = (unsigned long) (fregs[(addr - 32)] & 0xffffffff);
137 tmp = fregs[addr - FPR_BASE];
140 tmp = -1; /* FP not yet used */
147 tmp = regs->cp0_cause;
150 tmp = regs->cp0_badvaddr;
160 tmp = child->thread.fpu.hard.fcr31;
162 tmp = child->thread.fpu.soft.fcr31;
164 case FPC_EIR: { /* implementation / version register */
170 flags = read_c0_status();
172 __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp));
173 write_c0_status(flags);
181 ret = put_user(tmp, (unsigned long *) data);
185 /* when I and D space are separate, this will have to be fixed. */
186 case PTRACE_POKETEXT: /* write the word at location addr. */
187 case PTRACE_POKEDATA:
189 if (access_process_vm(child, addr, &data, sizeof(data), 1)
195 case PTRACE_POKEUSR: {
196 struct pt_regs *regs;
198 regs = (struct pt_regs *) ((unsigned long) child->thread_info +
199 THREAD_SIZE - 32 - sizeof(struct pt_regs));
203 regs->regs[addr] = data;
205 case FPR_BASE ... FPR_BASE + 31: {
206 fpureg_t *fregs = get_fpu_regs(child);
208 if (!child->used_math) {
209 /* FP not yet used */
210 memset(&child->thread.fpu.hard, ~0,
211 sizeof(child->thread.fpu.hard));
212 child->thread.fpu.hard.fcr31 = 0;
216 * The odd registers are actually the high order bits
217 * of the values stored in the even registers - unless
218 * we're using r2k_switch.S.
221 fregs[(addr & ~1) - FPR_BASE] &= 0xffffffff;
222 fregs[(addr & ~1) - FPR_BASE] |= ((unsigned long long) data) << 32;
224 fregs[addr - FPR_BASE] &= ~0xffffffffLL;
225 fregs[addr - FPR_BASE] |= data;
229 fregs[addr - FPR_BASE] = data;
234 regs->cp0_epc = data;
244 child->thread.fpu.hard.fcr31 = data;
246 child->thread.fpu.soft.fcr31 = data;
249 /* The rest are not allowed. */
256 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
257 case PTRACE_CONT: { /* restart after signal. */
259 if ((unsigned long) data > _NSIG)
261 if (request == PTRACE_SYSCALL) {
262 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
265 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
267 child->exit_code = data;
268 wake_up_process(child);
274 * make the child exit. Best I can do is send it a sigkill.
275 * perhaps it should be put in the status that it wants to
280 if (child->state == TASK_ZOMBIE) /* already dead */
282 child->exit_code = SIGKILL;
283 wake_up_process(child);
286 case PTRACE_DETACH: /* detach a process that was attached. */
287 ret = ptrace_detach(child, data);
291 ret = ptrace_request(child, request, addr, data);
296 put_task_struct(child);
303 * Notification of system call entry/exit
304 * - triggered by current->work.syscall_trace
306 asmlinkage void do_syscall_trace(void)
308 if (!test_thread_flag(TIF_SYSCALL_TRACE))
310 if (!(current->ptrace & PT_PTRACED))
313 /* The 0x80 provides a way for the tracing parent to distinguish
314 between a syscall stop and SIGTRAP delivery */
315 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ?
319 * this isn't the same as continuing with a signal, but it will do
320 * for normal use. strace only continues with a signal if the
321 * stopping signal is not SIGTRAP. -brl
323 if (current->exit_code) {
324 send_sig(current->exit_code, current, 1);
325 current->exit_code = 0;