3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Derived from "arch/m68k/kernel/ptrace.c"
6 * Copyright (C) 1994 by Hamish Macdonald
7 * Taken from linux/kernel/ptrace.c and modified for M680x0.
8 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
10 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
11 * and Paul Mackerras (paulus@samba.org).
13 * This file is subject to the terms and conditions of the GNU General
14 * Public License. See the file README.legal in the main directory of
15 * this archive for more details.
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
21 #include <linux/smp.h>
22 #include <linux/errno.h>
23 #include <linux/ptrace.h>
24 #include <linux/user.h>
25 #include <linux/security.h>
26 #include <linux/signal.h>
27 #include <linux/seccomp.h>
28 #include <linux/audit.h>
30 #include <linux/module.h>
33 #include <asm/uaccess.h>
35 #include <asm/pgtable.h>
36 #include <asm/system.h>
39 #include "ptrace-ppc64.h"
41 #include "ptrace-ppc32.h"
44 #include "ptrace-common.h"
47 * does not yet catch signals sent when the child dies.
48 * in exit.c or in signal.c.
52 * Called by kernel/ptrace.c when detaching..
54 * Make sure single step bits etc are not set.
56 void ptrace_disable(struct task_struct
*child
)
58 /* make sure the single step bit is not set. */
59 clear_single_step(child
);
62 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
67 /* when I and D space are separate, these will need to be fixed. */
68 case PTRACE_PEEKTEXT
: /* read word at location addr. */
69 case PTRACE_PEEKDATA
: {
73 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
75 if (copied
!= sizeof(tmp
))
77 ret
= put_user(tmp
,(unsigned long __user
*) data
);
81 /* read the word at location addr in the USER area. */
82 case PTRACE_PEEKUSR
: {
83 unsigned long index
, tmp
;
86 /* convert to index and check */
88 index
= (unsigned long) addr
>> 2;
89 if ((addr
& 3) || (index
> PT_FPSCR
)
90 || (child
->thread
.regs
== NULL
))
92 index
= (unsigned long) addr
>> 3;
93 if ((addr
& 7) || (index
> PT_FPSCR
))
98 CHECK_FULL_REGS(child
->thread
.regs
);
100 if (index
< PT_FPR0
) {
101 tmp
= get_reg(child
, (int) index
);
103 flush_fp_to_thread(child
);
104 tmp
= ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
];
106 ret
= put_user(tmp
,(unsigned long __user
*) data
);
110 /* If I and D space are separate, this will have to be fixed. */
111 case PTRACE_POKETEXT
: /* write the word at location addr. */
112 case PTRACE_POKEDATA
:
114 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
120 /* write the word at location addr in the USER area */
121 case PTRACE_POKEUSR
: {
125 /* convert to index and check */
127 index
= (unsigned long) addr
>> 2;
128 if ((addr
& 3) || (index
> PT_FPSCR
)
129 || (child
->thread
.regs
== NULL
))
131 index
= (unsigned long) addr
>> 3;
132 if ((addr
& 7) || (index
> PT_FPSCR
))
137 CHECK_FULL_REGS(child
->thread
.regs
);
139 if (index
== PT_ORIG_R3
)
141 if (index
< PT_FPR0
) {
142 ret
= put_reg(child
, index
, data
);
144 flush_fp_to_thread(child
);
145 ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
151 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
152 case PTRACE_CONT
: { /* restart after signal. */
154 if (!valid_signal(data
))
156 if (request
== PTRACE_SYSCALL
)
157 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
159 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
160 child
->exit_code
= data
;
161 /* make sure the single step bit is not set. */
162 clear_single_step(child
);
163 wake_up_process(child
);
169 * make the child exit. Best I can do is send it a sigkill.
170 * perhaps it should be put in the status that it wants to
175 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
177 child
->exit_code
= SIGKILL
;
178 /* make sure the single step bit is not set. */
179 clear_single_step(child
);
180 wake_up_process(child
);
184 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
186 if (!valid_signal(data
))
188 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
189 set_single_step(child
);
190 child
->exit_code
= data
;
191 /* give it a chance to run. */
192 wake_up_process(child
);
198 case PTRACE_GET_DEBUGREG
: {
200 /* We only support one DABR and no IABRS at the moment */
203 ret
= put_user(child
->thread
.dabr
,
204 (unsigned long __user
*)data
);
208 case PTRACE_SET_DEBUGREG
:
209 ret
= ptrace_set_debugreg(child
, addr
, data
);
214 ret
= ptrace_detach(child
, data
);
217 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
219 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
220 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
222 for (i
= 0; i
< 32; i
++) {
223 ret
= put_user(*reg
, tmp
);
232 case PPC_PTRACE_SETREGS
: { /* Set GPRs 0 - 31. */
234 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
235 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
237 for (i
= 0; i
< 32; i
++) {
238 ret
= get_user(*reg
, tmp
);
248 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
250 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
251 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
253 flush_fp_to_thread(child
);
255 for (i
= 0; i
< 32; i
++) {
256 ret
= put_user(*reg
, tmp
);
265 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
267 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
268 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
270 flush_fp_to_thread(child
);
272 for (i
= 0; i
< 32; i
++) {
273 ret
= get_user(*reg
, tmp
);
281 #endif /* CONFIG_PPC64 */
283 #ifdef CONFIG_ALTIVEC
284 case PTRACE_GETVRREGS
:
285 /* Get the child altivec register state. */
286 flush_altivec_to_thread(child
);
287 ret
= get_vrregs((unsigned long __user
*)data
, child
);
290 case PTRACE_SETVRREGS
:
291 /* Set the child altivec register state. */
292 flush_altivec_to_thread(child
);
293 ret
= set_vrregs(child
, (unsigned long __user
*)data
);
297 case PTRACE_GETEVRREGS
:
298 /* Get the child spe register state. */
299 if (child
->thread
.regs
->msr
& MSR_SPE
)
301 ret
= get_evrregs((unsigned long __user
*)data
, child
);
304 case PTRACE_SETEVRREGS
:
305 /* Set the child spe register state. */
306 /* this is to clear the MSR_SPE bit to force a reload
307 * of register state from memory */
308 if (child
->thread
.regs
->msr
& MSR_SPE
)
310 ret
= set_evrregs(child
, (unsigned long __user
*)data
);
315 ret
= ptrace_request(child
, request
, addr
, data
);
322 static void do_syscall_trace(void)
324 /* the 0x80 provides a way for the tracing parent to distinguish
325 between a syscall stop and SIGTRAP delivery */
326 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
330 * this isn't the same as continuing with a signal, but it will do
331 * for normal use. strace only continues with a signal if the
332 * stopping signal is not SIGTRAP. -brl
334 if (current
->exit_code
) {
335 send_sig(current
->exit_code
, current
, 1);
336 current
->exit_code
= 0;
340 void do_syscall_trace_enter(struct pt_regs
*regs
)
342 secure_computing(regs
->gpr
[0]);
344 if (test_thread_flag(TIF_SYSCALL_TRACE
)
345 && (current
->ptrace
& PT_PTRACED
))
348 if (unlikely(current
->audit_context
)) {
350 if (!test_thread_flag(TIF_32BIT
))
351 audit_syscall_entry(AUDIT_ARCH_PPC64
,
353 regs
->gpr
[3], regs
->gpr
[4],
354 regs
->gpr
[5], regs
->gpr
[6]);
357 audit_syscall_entry(AUDIT_ARCH_PPC
,
359 regs
->gpr
[3] & 0xffffffff,
360 regs
->gpr
[4] & 0xffffffff,
361 regs
->gpr
[5] & 0xffffffff,
362 regs
->gpr
[6] & 0xffffffff);
366 void do_syscall_trace_leave(struct pt_regs
*regs
)
368 if (unlikely(current
->audit_context
))
369 audit_syscall_exit((regs
->ccr
&0x10000000)?AUDITSC_FAILURE
:AUDITSC_SUCCESS
,
372 if ((test_thread_flag(TIF_SYSCALL_TRACE
)
373 || test_thread_flag(TIF_SINGLESTEP
))
374 && (current
->ptrace
& PT_PTRACED
))