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/config.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
24 #include <linux/errno.h>
25 #include <linux/ptrace.h>
26 #include <linux/user.h>
27 #include <linux/security.h>
28 #include <linux/signal.h>
29 #include <linux/seccomp.h>
30 #include <linux/audit.h>
32 #include <linux/module.h>
35 #include <asm/uaccess.h>
37 #include <asm/pgtable.h>
38 #include <asm/system.h>
40 #include <asm/ptrace-common.h>
45 * Set of msr bits that gdb can change on behalf of a process.
47 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
48 #define MSR_DEBUGCHANGE 0
50 #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
52 #endif /* CONFIG_PPC32 */
55 * does not yet catch signals sent when the child dies.
56 * in exit.c or in signal.c.
61 * Get contents of register REGNO in task TASK.
63 static inline unsigned long get_reg(struct task_struct
*task
, int regno
)
65 if (regno
< sizeof(struct pt_regs
) / sizeof(unsigned long)
66 && task
->thread
.regs
!= NULL
)
67 return ((unsigned long *)task
->thread
.regs
)[regno
];
72 * Write contents of register REGNO in task TASK.
74 static inline int put_reg(struct task_struct
*task
, int regno
,
77 if (regno
<= PT_MQ
&& task
->thread
.regs
!= NULL
) {
79 data
= (data
& MSR_DEBUGCHANGE
)
80 | (task
->thread
.regs
->msr
& ~MSR_DEBUGCHANGE
);
81 ((unsigned long *)task
->thread
.regs
)[regno
] = data
;
89 * Get contents of AltiVec register state in task TASK
91 static inline int get_vrregs(unsigned long __user
*data
, struct task_struct
*task
)
95 if (!access_ok(VERIFY_WRITE
, data
, 133 * sizeof(unsigned long)))
98 /* copy AltiVec registers VR[0] .. VR[31] */
99 for (i
= 0; i
< 32; i
++)
100 for (j
= 0; j
< 4; j
++, data
++)
101 if (__put_user(task
->thread
.vr
[i
].u
[j
], data
))
105 for (i
= 0; i
< 4; i
++, data
++)
106 if (__put_user(task
->thread
.vscr
.u
[i
], data
))
110 if (__put_user(task
->thread
.vrsave
, data
))
117 * Write contents of AltiVec register state into task TASK.
119 static inline int set_vrregs(struct task_struct
*task
, unsigned long __user
*data
)
123 if (!access_ok(VERIFY_READ
, data
, 133 * sizeof(unsigned long)))
126 /* copy AltiVec registers VR[0] .. VR[31] */
127 for (i
= 0; i
< 32; i
++)
128 for (j
= 0; j
< 4; j
++, data
++)
129 if (__get_user(task
->thread
.vr
[i
].u
[j
], data
))
133 for (i
= 0; i
< 4; i
++, data
++)
134 if (__get_user(task
->thread
.vscr
.u
[i
], data
))
138 if (__get_user(task
->thread
.vrsave
, data
))
148 * For get_evrregs/set_evrregs functions 'data' has the following layout:
158 * Get contents of SPE register state in task TASK.
160 static inline int get_evrregs(unsigned long *data
, struct task_struct
*task
)
164 if (!access_ok(VERIFY_WRITE
, data
, 35 * sizeof(unsigned long)))
168 if (__put_user(task
->thread
.spefscr
, &data
[34]))
171 /* copy SPE registers EVR[0] .. EVR[31] */
172 for (i
= 0; i
< 32; i
++, data
++)
173 if (__put_user(task
->thread
.evr
[i
], data
))
177 if (__put_user64(task
->thread
.acc
, (unsigned long long *)data
))
184 * Write contents of SPE register state into task TASK.
186 static inline int set_evrregs(struct task_struct
*task
, unsigned long *data
)
190 if (!access_ok(VERIFY_READ
, data
, 35 * sizeof(unsigned long)))
194 if (__get_user(task
->thread
.spefscr
, &data
[34]))
197 /* copy SPE registers EVR[0] .. EVR[31] */
198 for (i
= 0; i
< 32; i
++, data
++)
199 if (__get_user(task
->thread
.evr
[i
], data
))
202 if (__get_user64(task
->thread
.acc
, (unsigned long long*)data
))
207 #endif /* CONFIG_SPE */
210 set_single_step(struct task_struct
*task
)
212 struct pt_regs
*regs
= task
->thread
.regs
;
215 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
216 task
->thread
.dbcr0
= DBCR0_IDM
| DBCR0_IC
;
225 clear_single_step(struct task_struct
*task
)
227 struct pt_regs
*regs
= task
->thread
.regs
;
230 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
231 task
->thread
.dbcr0
= 0;
232 regs
->msr
&= ~MSR_DE
;
234 regs
->msr
&= ~MSR_SE
;
238 #endif /* CONFIG_PPC32 */
241 * Called by kernel/ptrace.c when detaching..
243 * Make sure single step bits etc are not set.
245 void ptrace_disable(struct task_struct
*child
)
247 /* make sure the single step bit is not set. */
248 clear_single_step(child
);
251 long sys_ptrace(long request
, long pid
, long addr
, long data
)
253 struct task_struct
*child
;
257 if (request
== PTRACE_TRACEME
) {
258 /* are we already being traced? */
259 if (current
->ptrace
& PT_PTRACED
)
261 ret
= security_ptrace(current
->parent
, current
);
264 /* set the ptrace bit in the process flags. */
265 current
->ptrace
|= PT_PTRACED
;
270 read_lock(&tasklist_lock
);
271 child
= find_task_by_pid(pid
);
273 get_task_struct(child
);
274 read_unlock(&tasklist_lock
);
279 if (pid
== 1) /* you may not mess with init */
282 if (request
== PTRACE_ATTACH
) {
283 ret
= ptrace_attach(child
);
287 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
292 /* when I and D space are separate, these will need to be fixed. */
293 case PTRACE_PEEKTEXT
: /* read word at location addr. */
294 case PTRACE_PEEKDATA
: {
298 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
300 if (copied
!= sizeof(tmp
))
302 ret
= put_user(tmp
,(unsigned long __user
*) data
);
306 /* read the word at location addr in the USER area. */
307 case PTRACE_PEEKUSR
: {
308 unsigned long index
, tmp
;
311 /* convert to index and check */
313 index
= (unsigned long) addr
>> 2;
314 if ((addr
& 3) || (index
> PT_FPSCR
)
315 || (child
->thread
.regs
== NULL
))
317 index
= (unsigned long) addr
>> 3;
318 if ((addr
& 7) || (index
> PT_FPSCR
))
323 CHECK_FULL_REGS(child
->thread
.regs
);
325 if (index
< PT_FPR0
) {
326 tmp
= get_reg(child
, (int) index
);
328 flush_fp_to_thread(child
);
329 tmp
= ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
];
331 ret
= put_user(tmp
,(unsigned long __user
*) data
);
335 /* If I and D space are separate, this will have to be fixed. */
336 case PTRACE_POKETEXT
: /* write the word at location addr. */
337 case PTRACE_POKEDATA
:
339 if (access_process_vm(child
, addr
, &data
, sizeof(data
), 1)
345 /* write the word at location addr in the USER area */
346 case PTRACE_POKEUSR
: {
350 /* convert to index and check */
352 index
= (unsigned long) addr
>> 2;
353 if ((addr
& 3) || (index
> PT_FPSCR
)
354 || (child
->thread
.regs
== NULL
))
356 index
= (unsigned long) addr
>> 3;
357 if ((addr
& 7) || (index
> PT_FPSCR
))
362 CHECK_FULL_REGS(child
->thread
.regs
);
364 if (index
== PT_ORIG_R3
)
366 if (index
< PT_FPR0
) {
367 ret
= put_reg(child
, index
, data
);
369 flush_fp_to_thread(child
);
370 ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
376 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
377 case PTRACE_CONT
: { /* restart after signal. */
379 if (!valid_signal(data
))
381 if (request
== PTRACE_SYSCALL
)
382 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
384 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
385 child
->exit_code
= data
;
386 /* make sure the single step bit is not set. */
387 clear_single_step(child
);
388 wake_up_process(child
);
394 * make the child exit. Best I can do is send it a sigkill.
395 * perhaps it should be put in the status that it wants to
400 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
402 child
->exit_code
= SIGKILL
;
403 /* make sure the single step bit is not set. */
404 clear_single_step(child
);
405 wake_up_process(child
);
409 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
411 if (!valid_signal(data
))
413 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
414 set_single_step(child
);
415 child
->exit_code
= data
;
416 /* give it a chance to run. */
417 wake_up_process(child
);
423 case PTRACE_GET_DEBUGREG
: {
425 /* We only support one DABR and no IABRS at the moment */
428 ret
= put_user(child
->thread
.dabr
,
429 (unsigned long __user
*)data
);
433 case PTRACE_SET_DEBUGREG
:
434 ret
= ptrace_set_debugreg(child
, addr
, data
);
439 ret
= ptrace_detach(child
, data
);
443 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
445 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
446 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
448 for (i
= 0; i
< 32; i
++) {
449 ret
= put_user(*reg
, tmp
);
458 case PPC_PTRACE_SETREGS
: { /* Set GPRs 0 - 31. */
460 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
461 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
463 for (i
= 0; i
< 32; i
++) {
464 ret
= get_user(*reg
, tmp
);
473 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
475 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
476 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
478 flush_fp_to_thread(child
);
480 for (i
= 0; i
< 32; i
++) {
481 ret
= put_user(*reg
, tmp
);
490 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
492 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
493 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
495 flush_fp_to_thread(child
);
497 for (i
= 0; i
< 32; i
++) {
498 ret
= get_user(*reg
, tmp
);
506 #endif /* CONFIG_PPC64 */
508 #ifdef CONFIG_ALTIVEC
509 case PTRACE_GETVRREGS
:
510 /* Get the child altivec register state. */
511 flush_altivec_to_thread(child
);
512 ret
= get_vrregs((unsigned long __user
*)data
, child
);
515 case PTRACE_SETVRREGS
:
516 /* Set the child altivec register state. */
517 flush_altivec_to_thread(child
);
518 ret
= set_vrregs(child
, (unsigned long __user
*)data
);
522 case PTRACE_GETEVRREGS
:
523 /* Get the child spe register state. */
524 if (child
->thread
.regs
->msr
& MSR_SPE
)
526 ret
= get_evrregs((unsigned long __user
*)data
, child
);
529 case PTRACE_SETEVRREGS
:
530 /* Set the child spe register state. */
531 /* this is to clear the MSR_SPE bit to force a reload
532 * of register state from memory */
533 if (child
->thread
.regs
->msr
& MSR_SPE
)
535 ret
= set_evrregs(child
, (unsigned long __user
*)data
);
540 ret
= ptrace_request(child
, request
, addr
, data
);
544 put_task_struct(child
);
550 static void do_syscall_trace(void)
552 /* the 0x80 provides a way for the tracing parent to distinguish
553 between a syscall stop and SIGTRAP delivery */
554 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
558 * this isn't the same as continuing with a signal, but it will do
559 * for normal use. strace only continues with a signal if the
560 * stopping signal is not SIGTRAP. -brl
562 if (current
->exit_code
) {
563 send_sig(current
->exit_code
, current
, 1);
564 current
->exit_code
= 0;
568 void do_syscall_trace_enter(struct pt_regs
*regs
)
571 secure_computing(regs
->gpr
[0]);
574 if (test_thread_flag(TIF_SYSCALL_TRACE
)
575 && (current
->ptrace
& PT_PTRACED
))
578 if (unlikely(current
->audit_context
))
579 audit_syscall_entry(current
,
583 test_thread_flag(TIF_32BIT
)?AUDIT_ARCH_PPC
:AUDIT_ARCH_PPC64
,
586 regs
->gpr
[3], regs
->gpr
[4],
587 regs
->gpr
[5], regs
->gpr
[6]);
590 void do_syscall_trace_leave(struct pt_regs
*regs
)
593 secure_computing(regs
->gpr
[0]);
596 if (unlikely(current
->audit_context
))
597 audit_syscall_exit(current
,
598 (regs
->ccr
&0x1000)?AUDITSC_FAILURE
:AUDITSC_SUCCESS
,
601 if ((test_thread_flag(TIF_SYSCALL_TRACE
)
603 || test_thread_flag(TIF_SINGLESTEP
)
606 && (current
->ptrace
& PT_PTRACED
))
611 EXPORT_SYMBOL(do_syscall_trace_enter
);
612 EXPORT_SYMBOL(do_syscall_trace_leave
);
This page took 0.063345 seconds and 6 git commands to generate.