]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/mips/kernel/ptrace.c
92f2c39afe2797b8fad03df6c96b4050a291bff3
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>
32 #include <asm/mipsregs.h>
33 #include <asm/pgtable.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <asm/bootinfo.h>
40 * Called by kernel/ptrace.c when detaching..
42 * Make sure single step bits etc are not set.
44 void ptrace_disable(struct task_struct
*child
)
49 asmlinkage
int sys_ptrace(long request
, long pid
, long addr
, long 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 long *) data
);
109 /* Read the word at location addr in the USER area. */
110 case PTRACE_PEEKUSR
: {
111 struct pt_regs
*regs
;
112 unsigned long tmp
= 0;
114 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
115 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
116 ret
= 0; /* Default return value. */
120 tmp
= regs
->regs
[addr
];
122 case FPR_BASE
... FPR_BASE
+ 31:
123 if (tsk_used_math(child
)) {
124 fpureg_t
*fregs
= get_fpu_regs(child
);
128 * The odd registers are actually the high
129 * order bits of the values stored in the even
130 * registers - unless we're using r2k_switch.S.
133 tmp
= (unsigned long) (fregs
[((addr
& ~1) - 32)] >> 32);
135 tmp
= (unsigned long) (fregs
[(addr
- 32)] & 0xffffffff);
138 tmp
= fregs
[addr
- FPR_BASE
];
141 tmp
= -1; /* FP not yet used */
148 tmp
= regs
->cp0_cause
;
151 tmp
= regs
->cp0_badvaddr
;
161 tmp
= child
->thread
.fpu
.hard
.fcr31
;
163 tmp
= child
->thread
.fpu
.soft
.fcr31
;
165 case FPC_EIR
: { /* implementation / version register */
171 flags
= read_c0_status();
173 __asm__
__volatile__("cfc1\t%0,$0": "=r" (tmp
));
174 write_c0_status(flags
);
182 ret
= put_user(tmp
, (unsigned long *) data
);
186 /* when I and D space are separate, this will have to be fixed. */
187 case PTRACE_POKETEXT
: /* write the word at location addr. */
188 case PTRACE_POKEDATA
:
190 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
196 case PTRACE_POKEUSR
: {
197 struct pt_regs
*regs
;
199 regs
= (struct pt_regs
*) ((unsigned long) child
->thread_info
+
200 THREAD_SIZE
- 32 - sizeof(struct pt_regs
));
204 regs
->regs
[addr
] = data
;
206 case FPR_BASE
... FPR_BASE
+ 31: {
207 fpureg_t
*fregs
= get_fpu_regs(child
);
209 if (!tsk_used_math(child
)) {
210 /* FP not yet used */
211 memset(&child
->thread
.fpu
.hard
, ~0,
212 sizeof(child
->thread
.fpu
.hard
));
213 child
->thread
.fpu
.hard
.fcr31
= 0;
217 * The odd registers are actually the high order bits
218 * of the values stored in the even registers - unless
219 * we're using r2k_switch.S.
222 fregs
[(addr
& ~1) - FPR_BASE
] &= 0xffffffff;
223 fregs
[(addr
& ~1) - FPR_BASE
] |= ((unsigned long long) data
) << 32;
225 fregs
[addr
- FPR_BASE
] &= ~0xffffffffLL
;
226 fregs
[addr
- FPR_BASE
] |= data
;
230 fregs
[addr
- FPR_BASE
] = data
;
235 regs
->cp0_epc
= data
;
245 child
->thread
.fpu
.hard
.fcr31
= data
;
247 child
->thread
.fpu
.soft
.fcr31
= data
;
250 /* The rest are not allowed. */
257 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
258 case PTRACE_CONT
: { /* restart after signal. */
260 if ((unsigned long) data
> _NSIG
)
262 if (request
== PTRACE_SYSCALL
) {
263 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
266 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
268 child
->exit_code
= data
;
269 wake_up_process(child
);
275 * make the child exit. Best I can do is send it a sigkill.
276 * perhaps it should be put in the status that it wants to
281 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
283 child
->exit_code
= SIGKILL
;
284 wake_up_process(child
);
287 case PTRACE_DETACH
: /* detach a process that was attached. */
288 ret
= ptrace_detach(child
, data
);
292 ret
= ptrace_request(child
, request
, addr
, data
);
297 put_task_struct(child
);
304 * Notification of system call entry/exit
305 * - triggered by current->work.syscall_trace
307 asmlinkage
void do_syscall_trace(struct pt_regs
*regs
, int entryexit
)
309 if (unlikely(current
->audit_context
)) {
311 audit_syscall_entry(current
, regs
->regs
[2],
312 regs
->regs
[4], regs
->regs
[5],
313 regs
->regs
[6], regs
->regs
[7]);
315 audit_syscall_exit(current
, regs
->regs
[2]);
318 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
320 if (!(current
->ptrace
& PT_PTRACED
))
323 /* The 0x80 provides a way for the tracing parent to distinguish
324 between a syscall stop and SIGTRAP delivery */
325 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
) ?
329 * this isn't the same as continuing with a signal, but it will do
330 * for normal use. strace only continues with a signal if the
331 * stopping signal is not SIGTRAP. -brl
333 if (current
->exit_code
) {
334 send_sig(current
->exit_code
, current
, 1);
335 current
->exit_code
= 0;