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/regset.h>
25 #include <linux/elf.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>
41 * does not yet catch signals sent when the child dies.
42 * in exit.c or in signal.c.
46 * Set of msr bits that gdb can change on behalf of a process.
48 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
49 #define MSR_DEBUGCHANGE 0
51 #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
55 * Max register writeable via put_reg
58 #define PT_MAX_PUT_REG PT_MQ
60 #define PT_MAX_PUT_REG PT_CCR
63 static unsigned long get_user_msr(struct task_struct
*task
)
65 return task
->thread
.regs
->msr
| task
->thread
.fpexc_mode
;
68 static int set_user_msr(struct task_struct
*task
, unsigned long msr
)
70 task
->thread
.regs
->msr
&= ~MSR_DEBUGCHANGE
;
71 task
->thread
.regs
->msr
|= msr
& MSR_DEBUGCHANGE
;
76 * We prevent mucking around with the reserved area of trap
77 * which are used internally by the kernel.
79 static int set_user_trap(struct task_struct
*task
, unsigned long trap
)
81 task
->thread
.regs
->trap
= trap
& 0xfff0;
86 * Get contents of register REGNO in task TASK.
88 unsigned long ptrace_get_reg(struct task_struct
*task
, int regno
)
90 if (task
->thread
.regs
== NULL
)
94 return get_user_msr(task
);
96 if (regno
< (sizeof(struct pt_regs
) / sizeof(unsigned long)))
97 return ((unsigned long *)task
->thread
.regs
)[regno
];
103 * Write contents of register REGNO in task TASK.
105 int ptrace_put_reg(struct task_struct
*task
, int regno
, unsigned long data
)
107 if (task
->thread
.regs
== NULL
)
111 return set_user_msr(task
, data
);
112 if (regno
== PT_TRAP
)
113 return set_user_trap(task
, data
);
115 if (regno
<= PT_MAX_PUT_REG
) {
116 ((unsigned long *)task
->thread
.regs
)[regno
] = data
;
123 static int fpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
124 unsigned int pos
, unsigned int count
,
125 void *kbuf
, void __user
*ubuf
)
127 flush_fp_to_thread(target
);
129 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
130 offsetof(struct thread_struct
, fpr
[32]));
132 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
133 &target
->thread
.fpr
, 0, -1);
136 static int fpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
137 unsigned int pos
, unsigned int count
,
138 const void *kbuf
, const void __user
*ubuf
)
140 flush_fp_to_thread(target
);
142 BUILD_BUG_ON(offsetof(struct thread_struct
, fpscr
) !=
143 offsetof(struct thread_struct
, fpr
[32]));
145 return user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
146 &target
->thread
.fpr
, 0, -1);
149 static int get_fpregs(void __user
*data
, struct task_struct
*task
,
152 unsigned int count
= has_fpscr
? 33 : 32;
153 if (!access_ok(VERIFY_WRITE
, data
, count
* sizeof(double)))
155 return fpr_get(task
, NULL
, 0, count
* sizeof(double), NULL
, data
);
158 static int set_fpregs(void __user
*data
, struct task_struct
*task
,
161 unsigned int count
= has_fpscr
? 33 : 32;
162 if (!access_ok(VERIFY_READ
, data
, count
* sizeof(double)))
164 return fpr_set(task
, NULL
, 0, count
* sizeof(double), NULL
, data
);
168 #ifdef CONFIG_ALTIVEC
170 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
171 * The transfer totals 34 quadword. Quadwords 0-31 contain the
172 * corresponding vector registers. Quadword 32 contains the vscr as the
173 * last word (offset 12) within that quadword. Quadword 33 contains the
174 * vrsave as the first word (offset 0) within the quadword.
176 * This definition of the VMX state is compatible with the current PPC32
177 * ptrace interface. This allows signal handling and ptrace to use the
178 * same structures. This also simplifies the implementation of a bi-arch
179 * (combined (32- and 64-bit) gdb.
182 static int vr_active(struct task_struct
*target
,
183 const struct user_regset
*regset
)
185 flush_altivec_to_thread(target
);
186 return target
->thread
.used_vr
? regset
->n
: 0;
189 static int vr_get(struct task_struct
*target
, const struct user_regset
*regset
,
190 unsigned int pos
, unsigned int count
,
191 void *kbuf
, void __user
*ubuf
)
195 flush_altivec_to_thread(target
);
197 BUILD_BUG_ON(offsetof(struct thread_struct
, vscr
) !=
198 offsetof(struct thread_struct
, vr
[32]));
200 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
201 &target
->thread
.vr
, 0,
202 33 * sizeof(vector128
));
205 * Copy out only the low-order word of vrsave.
211 memset(&vrsave
, 0, sizeof(vrsave
));
212 vrsave
.word
= target
->thread
.vrsave
;
213 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
214 33 * sizeof(vector128
), -1);
220 static int vr_set(struct task_struct
*target
, const struct user_regset
*regset
,
221 unsigned int pos
, unsigned int count
,
222 const void *kbuf
, const void __user
*ubuf
)
226 flush_altivec_to_thread(target
);
228 BUILD_BUG_ON(offsetof(struct thread_struct
, vscr
) !=
229 offsetof(struct thread_struct
, vr
[32]));
231 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
232 &target
->thread
.vr
, 0, 33 * sizeof(vector128
));
233 if (!ret
&& count
> 0) {
235 * We use only the first word of vrsave.
241 memset(&vrsave
, 0, sizeof(vrsave
));
242 vrsave
.word
= target
->thread
.vrsave
;
243 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
244 33 * sizeof(vector128
), -1);
246 target
->thread
.vrsave
= vrsave
.word
;
253 * Get contents of AltiVec register state in task TASK
255 static int get_vrregs(unsigned long __user
*data
, struct task_struct
*task
)
257 if (!access_ok(VERIFY_WRITE
, data
,
258 33 * sizeof(vector128
) + sizeof(u32
)))
261 return vr_get(task
, NULL
, 0, 33 * sizeof(vector128
) + sizeof(u32
),
266 * Write contents of AltiVec register state into task TASK.
268 static int set_vrregs(struct task_struct
*task
, unsigned long __user
*data
)
270 if (!access_ok(VERIFY_READ
, data
, 33 * sizeof(vector128
) + sizeof(u32
)))
273 return vr_set(task
, NULL
, 0, 33 * sizeof(vector128
) + sizeof(u32
),
276 #endif /* CONFIG_ALTIVEC */
281 * For get_evrregs/set_evrregs functions 'data' has the following layout:
290 static int evr_active(struct task_struct
*target
,
291 const struct user_regset
*regset
)
293 flush_spe_to_thread(target
);
294 return target
->thread
.used_spe
? regset
->n
: 0;
297 static int evr_get(struct task_struct
*target
, const struct user_regset
*regset
,
298 unsigned int pos
, unsigned int count
,
299 void *kbuf
, void __user
*ubuf
)
303 flush_spe_to_thread(target
);
305 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
307 0, sizeof(target
->thread
.evr
));
309 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
310 offsetof(struct thread_struct
, spefscr
));
313 ret
= user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
315 sizeof(target
->thread
.evr
), -1);
320 static int evr_set(struct task_struct
*target
, const struct user_regset
*regset
,
321 unsigned int pos
, unsigned int count
,
322 const void *kbuf
, const void __user
*ubuf
)
326 flush_spe_to_thread(target
);
328 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
330 0, sizeof(target
->thread
.evr
));
332 BUILD_BUG_ON(offsetof(struct thread_struct
, acc
) + sizeof(u64
) !=
333 offsetof(struct thread_struct
, spefscr
));
336 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
338 sizeof(target
->thread
.evr
), -1);
344 * Get contents of SPE register state in task TASK.
346 static int get_evrregs(unsigned long __user
*data
, struct task_struct
*task
)
348 if (!access_ok(VERIFY_WRITE
, data
, 35 * sizeof(u32
)))
351 return evr_get(task
, NULL
, 0, 35 * sizeof(u32
), NULL
, data
);
355 * Write contents of SPE register state into task TASK.
357 static int set_evrregs(struct task_struct
*task
, unsigned long *data
)
359 if (!access_ok(VERIFY_READ
, data
, 35 * sizeof(u32
)))
362 return evr_set(task
, NULL
, 0, 35 * sizeof(u32
), NULL
, data
);
364 #endif /* CONFIG_SPE */
367 void user_enable_single_step(struct task_struct
*task
)
369 struct pt_regs
*regs
= task
->thread
.regs
;
372 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
373 task
->thread
.dbcr0
= DBCR0_IDM
| DBCR0_IC
;
379 set_tsk_thread_flag(task
, TIF_SINGLESTEP
);
382 void user_disable_single_step(struct task_struct
*task
)
384 struct pt_regs
*regs
= task
->thread
.regs
;
387 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
388 task
->thread
.dbcr0
= 0;
389 regs
->msr
&= ~MSR_DE
;
391 regs
->msr
&= ~MSR_SE
;
394 clear_tsk_thread_flag(task
, TIF_SINGLESTEP
);
397 static int ptrace_set_debugreg(struct task_struct
*task
, unsigned long addr
,
400 /* We only support one DABR and no IABRS at the moment */
404 /* The bottom 3 bits are flags */
405 if ((data
& ~0x7UL
) >= TASK_SIZE
)
408 /* Ensure translation is on */
409 if (data
&& !(data
& DABR_TRANSLATION
))
412 task
->thread
.dabr
= data
;
417 * Called by kernel/ptrace.c when detaching..
419 * Make sure single step bits etc are not set.
421 void ptrace_disable(struct task_struct
*child
)
423 /* make sure the single step bit is not set. */
424 user_disable_single_step(child
);
428 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
429 * we mark them as obsolete now, they will be removed in a future version
431 static long arch_ptrace_old(struct task_struct
*child
, long request
, long addr
,
437 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
439 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
440 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
442 CHECK_FULL_REGS(child
->thread
.regs
);
443 for (i
= 0; i
< 32; i
++) {
444 ret
= put_user(*reg
, tmp
);
453 case PPC_PTRACE_SETREGS
: { /* Set GPRs 0 - 31. */
455 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
456 unsigned long __user
*tmp
= (unsigned long __user
*)addr
;
458 CHECK_FULL_REGS(child
->thread
.regs
);
459 for (i
= 0; i
< 32; i
++) {
460 ret
= get_user(*reg
, tmp
);
469 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
470 flush_fp_to_thread(child
);
471 ret
= get_fpregs((void __user
*)addr
, child
, 0);
475 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
476 flush_fp_to_thread(child
);
477 ret
= set_fpregs((void __user
*)addr
, child
, 0);
485 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
490 /* when I and D space are separate, these will need to be fixed. */
491 case PTRACE_PEEKTEXT
: /* read word at location addr. */
492 case PTRACE_PEEKDATA
:
493 ret
= generic_ptrace_peekdata(child
, addr
, data
);
496 /* read the word at location addr in the USER area. */
497 case PTRACE_PEEKUSR
: {
498 unsigned long index
, tmp
;
501 /* convert to index and check */
503 index
= (unsigned long) addr
>> 2;
504 if ((addr
& 3) || (index
> PT_FPSCR
)
505 || (child
->thread
.regs
== NULL
))
507 index
= (unsigned long) addr
>> 3;
508 if ((addr
& 7) || (index
> PT_FPSCR
))
512 CHECK_FULL_REGS(child
->thread
.regs
);
513 if (index
< PT_FPR0
) {
514 tmp
= ptrace_get_reg(child
, (int) index
);
516 flush_fp_to_thread(child
);
517 tmp
= ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
];
519 ret
= put_user(tmp
,(unsigned long __user
*) data
);
523 /* If I and D space are separate, this will have to be fixed. */
524 case PTRACE_POKETEXT
: /* write the word at location addr. */
525 case PTRACE_POKEDATA
:
526 ret
= generic_ptrace_pokedata(child
, addr
, data
);
529 /* write the word at location addr in the USER area */
530 case PTRACE_POKEUSR
: {
534 /* convert to index and check */
536 index
= (unsigned long) addr
>> 2;
537 if ((addr
& 3) || (index
> PT_FPSCR
)
538 || (child
->thread
.regs
== NULL
))
540 index
= (unsigned long) addr
>> 3;
541 if ((addr
& 7) || (index
> PT_FPSCR
))
545 CHECK_FULL_REGS(child
->thread
.regs
);
546 if (index
< PT_FPR0
) {
547 ret
= ptrace_put_reg(child
, index
, data
);
549 flush_fp_to_thread(child
);
550 ((unsigned long *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
556 case PTRACE_GET_DEBUGREG
: {
558 /* We only support one DABR and no IABRS at the moment */
561 ret
= put_user(child
->thread
.dabr
,
562 (unsigned long __user
*)data
);
566 case PTRACE_SET_DEBUGREG
:
567 ret
= ptrace_set_debugreg(child
, addr
, data
);
571 case PTRACE_GETREGS64
:
573 case PTRACE_GETREGS
: { /* Get all pt_regs from the child. */
575 if (!access_ok(VERIFY_WRITE
, (void __user
*)data
,
576 sizeof(struct pt_regs
))) {
580 CHECK_FULL_REGS(child
->thread
.regs
);
582 for (ui
= 0; ui
< PT_REGS_COUNT
; ui
++) {
583 ret
|= __put_user(ptrace_get_reg(child
, ui
),
584 (unsigned long __user
*) data
);
585 data
+= sizeof(long);
591 case PTRACE_SETREGS64
:
593 case PTRACE_SETREGS
: { /* Set all gp regs in the child. */
596 if (!access_ok(VERIFY_READ
, (void __user
*)data
,
597 sizeof(struct pt_regs
))) {
601 CHECK_FULL_REGS(child
->thread
.regs
);
603 for (ui
= 0; ui
< PT_REGS_COUNT
; ui
++) {
604 ret
= __get_user(tmp
, (unsigned long __user
*) data
);
607 ptrace_put_reg(child
, ui
, tmp
);
608 data
+= sizeof(long);
613 case PTRACE_GETFPREGS
: { /* Get the child FPU state (FPR0...31 + FPSCR) */
614 flush_fp_to_thread(child
);
615 ret
= get_fpregs((void __user
*)data
, child
, 1);
619 case PTRACE_SETFPREGS
: { /* Set the child FPU state (FPR0...31 + FPSCR) */
620 flush_fp_to_thread(child
);
621 ret
= set_fpregs((void __user
*)data
, child
, 1);
625 #ifdef CONFIG_ALTIVEC
626 case PTRACE_GETVRREGS
:
627 /* Get the child altivec register state. */
628 flush_altivec_to_thread(child
);
629 ret
= get_vrregs((unsigned long __user
*)data
, child
);
632 case PTRACE_SETVRREGS
:
633 /* Set the child altivec register state. */
634 flush_altivec_to_thread(child
);
635 ret
= set_vrregs(child
, (unsigned long __user
*)data
);
639 case PTRACE_GETEVRREGS
:
640 /* Get the child spe register state. */
641 flush_spe_to_thread(child
);
642 ret
= get_evrregs((unsigned long __user
*)data
, child
);
645 case PTRACE_SETEVRREGS
:
646 /* Set the child spe register state. */
647 /* this is to clear the MSR_SPE bit to force a reload
648 * of register state from memory */
649 flush_spe_to_thread(child
);
650 ret
= set_evrregs(child
, (unsigned long __user
*)data
);
654 /* Old reverse args ptrace callss */
655 case PPC_PTRACE_GETREGS
: /* Get GPRs 0 - 31. */
656 case PPC_PTRACE_SETREGS
: /* Set GPRs 0 - 31. */
657 case PPC_PTRACE_GETFPREGS
: /* Get FPRs 0 - 31. */
658 case PPC_PTRACE_SETFPREGS
: /* Get FPRs 0 - 31. */
659 ret
= arch_ptrace_old(child
, request
, addr
, data
);
663 ret
= ptrace_request(child
, request
, addr
, data
);
669 static void do_syscall_trace(void)
671 /* the 0x80 provides a way for the tracing parent to distinguish
672 between a syscall stop and SIGTRAP delivery */
673 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
677 * this isn't the same as continuing with a signal, but it will do
678 * for normal use. strace only continues with a signal if the
679 * stopping signal is not SIGTRAP. -brl
681 if (current
->exit_code
) {
682 send_sig(current
->exit_code
, current
, 1);
683 current
->exit_code
= 0;
687 void do_syscall_trace_enter(struct pt_regs
*regs
)
689 secure_computing(regs
->gpr
[0]);
691 if (test_thread_flag(TIF_SYSCALL_TRACE
)
692 && (current
->ptrace
& PT_PTRACED
))
695 if (unlikely(current
->audit_context
)) {
697 if (!test_thread_flag(TIF_32BIT
))
698 audit_syscall_entry(AUDIT_ARCH_PPC64
,
700 regs
->gpr
[3], regs
->gpr
[4],
701 regs
->gpr
[5], regs
->gpr
[6]);
704 audit_syscall_entry(AUDIT_ARCH_PPC
,
706 regs
->gpr
[3] & 0xffffffff,
707 regs
->gpr
[4] & 0xffffffff,
708 regs
->gpr
[5] & 0xffffffff,
709 regs
->gpr
[6] & 0xffffffff);
713 void do_syscall_trace_leave(struct pt_regs
*regs
)
715 if (unlikely(current
->audit_context
))
716 audit_syscall_exit((regs
->ccr
&0x10000000)?AUDITSC_FAILURE
:AUDITSC_SUCCESS
,
719 if ((test_thread_flag(TIF_SYSCALL_TRACE
)
720 || test_thread_flag(TIF_SINGLESTEP
))
721 && (current
->ptrace
& PT_PTRACED
))
This page took 0.097741 seconds and 6 git commands to generate.