]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - arch/ppc64/kernel/ptrace.c
2 * linux/arch/ppc64/kernel/ptrace.c
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Derived from "arch/m68k/kernel/ptrace.c"
8 * Copyright (C) 1994 by Hamish Macdonald
9 * Taken from linux/kernel/ptrace.c and modified for M680x0.
10 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
12 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
13 * and Paul Mackerras (paulus@linuxcare.com.au).
15 * This file is subject to the terms and conditions of the GNU General
16 * Public License. See the file README.legal in the main directory of
17 * this archive for more details.
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/errno.h>
26 #include <linux/ptrace.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/audit.h>
30 #include <linux/seccomp.h>
32 #include <asm/uaccess.h>
34 #include <asm/pgtable.h>
35 #include <asm/system.h>
36 #include <asm/ptrace-common.h>
39 * does not yet catch signals sent when the child dies.
40 * in exit.c or in signal.c.
44 * Called by kernel/ptrace.c when detaching..
46 * Make sure single step bits etc are not set.
48 void ptrace_disable(struct task_struct
*child
)
50 /* make sure the single step bit is not set. */
51 clear_single_step(child
);
54 int sys_ptrace(long request
, long pid
, long addr
, long data
)
56 struct task_struct
*child
;
60 if (request
== PTRACE_TRACEME
) {
61 /* are we already being traced? */
62 if (current
->ptrace
& PT_PTRACED
)
64 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 __user
*) data
);
109 /* read the word at location addr in the USER area. */
110 case PTRACE_PEEKUSR
: {
115 /* convert to index and check */
116 index
= (unsigned long) addr
>> 3;
117 if ((addr
& 7) || (index
> PT_FPSCR
))
120 if (index
< PT_FPR0
) {
121 tmp
= get_reg(child
, (int)index
);
123 flush_fp_to_thread(child
);
124 tmp
= ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
];
126 ret
= put_user(tmp
,(unsigned long __user
*) data
);
130 /* If I and D space are separate, this will have to be fixed. */
131 case PTRACE_POKETEXT
: /* write the word at location addr. */
132 case PTRACE_POKEDATA
:
134 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
140 /* write the word at location addr in the USER area */
141 case PTRACE_POKEUSR
: {
145 /* convert to index and check */
146 index
= (unsigned long) addr
>> 3;
147 if ((addr
& 7) || (index
> PT_FPSCR
))
150 if (index
== PT_ORIG_R3
)
152 if (index
< PT_FPR0
) {
153 ret
= put_reg(child
, index
, data
);
155 flush_fp_to_thread(child
);
156 ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
162 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
163 case PTRACE_CONT
: { /* restart after signal. */
165 if ((unsigned long) data
> _NSIG
)
167 if (request
== PTRACE_SYSCALL
)
168 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
170 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
171 child
->exit_code
= data
;
172 /* make sure the single step bit is not set. */
173 clear_single_step(child
);
174 wake_up_process(child
);
180 * make the child exit. Best I can do is send it a sigkill.
181 * perhaps it should be put in the status that it wants to
186 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
188 child
->exit_code
= SIGKILL
;
189 /* make sure the single step bit is not set. */
190 clear_single_step(child
);
191 wake_up_process(child
);
195 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
197 if ((unsigned long) data
> _NSIG
)
199 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
200 set_single_step(child
);
201 child
->exit_code
= data
;
202 /* give it a chance to run. */
203 wake_up_process(child
);
209 ret
= ptrace_detach(child
, data
);
212 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
214 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
215 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
217 for (i
= 0; i
< 32; i
++) {
218 ret
= put_user(*reg
, tmp
);
227 case PPC_PTRACE_SETREGS
: { /* Set GPRs 0 - 31. */
229 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
230 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
232 for (i
= 0; i
< 32; i
++) {
233 ret
= get_user(*reg
, tmp
);
242 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
244 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
245 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
247 flush_fp_to_thread(child
);
249 for (i
= 0; i
< 32; i
++) {
250 ret
= put_user(*reg
, tmp
);
259 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
261 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
262 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
264 flush_fp_to_thread(child
);
266 for (i
= 0; i
< 32; i
++) {
267 ret
= get_user(*reg
, tmp
);
277 ret
= ptrace_request(child
, request
, addr
, data
);
281 put_task_struct(child
);
287 static void do_syscall_trace(void)
289 /* the 0x80 provides a way for the tracing parent to distinguish
290 between a syscall stop and SIGTRAP delivery */
291 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
295 * this isn't the same as continuing with a signal, but it will do
296 * for normal use. strace only continues with a signal if the
297 * stopping signal is not SIGTRAP. -brl
299 if (current
->exit_code
) {
300 send_sig(current
->exit_code
, current
, 1);
301 current
->exit_code
= 0;
305 void do_syscall_trace_enter(struct pt_regs
*regs
)
307 if (unlikely(current
->audit_context
))
308 audit_syscall_entry(current
, regs
->gpr
[0],
309 regs
->gpr
[3], regs
->gpr
[4],
310 regs
->gpr
[5], regs
->gpr
[6]);
312 if (test_thread_flag(TIF_SYSCALL_TRACE
)
313 && (current
->ptrace
& PT_PTRACED
))
317 void do_syscall_trace_leave(struct pt_regs
*regs
)
319 secure_computing(regs
->gpr
[0]);
321 if (unlikely(current
->audit_context
))
322 audit_syscall_exit(current
, regs
->result
);
324 if ((test_thread_flag(TIF_SYSCALL_TRACE
)
325 || test_thread_flag(TIF_SINGLESTEP
))
326 && (current
->ptrace
& PT_PTRACED
))