aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/include/asm/elf.h1
-rw-r--r--arch/arm/include/asm/ptrace.h6
-rw-r--r--arch/arm/kernel/ptrace.c348
3 files changed, 246 insertions, 109 deletions
diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
index c3cd8755e648..0e9ce8d9686e 100644
--- a/arch/arm/include/asm/elf.h
+++ b/arch/arm/include/asm/elf.h
@@ -108,6 +108,7 @@ struct task_struct;
108int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs); 108int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
109#define ELF_CORE_COPY_TASK_REGS dump_task_regs 109#define ELF_CORE_COPY_TASK_REGS dump_task_regs
110 110
111#define CORE_DUMP_USE_REGSET
111#define ELF_EXEC_PAGESIZE 4096 112#define ELF_EXEC_PAGESIZE 4096
112 113
113/* This is the location that an ET_DYN program is loaded if exec'ed. Typical 114/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h
index a8ff22b2a391..312d10877bd7 100644
--- a/arch/arm/include/asm/ptrace.h
+++ b/arch/arm/include/asm/ptrace.h
@@ -128,6 +128,12 @@ struct pt_regs {
128#define ARM_r0 uregs[0] 128#define ARM_r0 uregs[0]
129#define ARM_ORIG_r0 uregs[17] 129#define ARM_ORIG_r0 uregs[17]
130 130
131/*
132 * The size of the user-visible VFP state as seen by PTRACE_GET/SETVFPREGS
133 * and core dumps.
134 */
135#define ARM_VFPREGS_SIZE ( 32 * 8 /*fpregs*/ + 4 /*fpscr*/ )
136
131#ifdef __KERNEL__ 137#ifdef __KERNEL__
132 138
133#define user_mode(regs) \ 139#define user_mode(regs) \
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 8182f45ca493..97260060bf26 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -21,6 +21,7 @@
21#include <linux/uaccess.h> 21#include <linux/uaccess.h>
22#include <linux/perf_event.h> 22#include <linux/perf_event.h>
23#include <linux/hw_breakpoint.h> 23#include <linux/hw_breakpoint.h>
24#include <linux/regset.h>
24 25
25#include <asm/pgtable.h> 26#include <asm/pgtable.h>
26#include <asm/system.h> 27#include <asm/system.h>
@@ -308,58 +309,6 @@ static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
308 return put_user_reg(tsk, off >> 2, val); 309 return put_user_reg(tsk, off >> 2, val);
309} 310}
310 311
311/*
312 * Get all user integer registers.
313 */
314static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
315{
316 struct pt_regs *regs = task_pt_regs(tsk);
317
318 return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
319}
320
321/*
322 * Set all user integer registers.
323 */
324static int ptrace_setregs(struct task_struct *tsk, void __user *uregs)
325{
326 struct pt_regs newregs;
327 int ret;
328
329 ret = -EFAULT;
330 if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
331 struct pt_regs *regs = task_pt_regs(tsk);
332
333 ret = -EINVAL;
334 if (valid_user_regs(&newregs)) {
335 *regs = newregs;
336 ret = 0;
337 }
338 }
339
340 return ret;
341}
342
343/*
344 * Get the child FPU state.
345 */
346static int ptrace_getfpregs(struct task_struct *tsk, void __user *ufp)
347{
348 return copy_to_user(ufp, &task_thread_info(tsk)->fpstate,
349 sizeof(struct user_fp)) ? -EFAULT : 0;
350}
351
352/*
353 * Set the child FPU state.
354 */
355static int ptrace_setfpregs(struct task_struct *tsk, void __user *ufp)
356{
357 struct thread_info *thread = task_thread_info(tsk);
358 thread->used_cp[1] = thread->used_cp[2] = 1;
359 return copy_from_user(&thread->fpstate, ufp,
360 sizeof(struct user_fp)) ? -EFAULT : 0;
361}
362
363#ifdef CONFIG_IWMMXT 312#ifdef CONFIG_IWMMXT
364 313
365/* 314/*
@@ -418,56 +367,6 @@ static int ptrace_setcrunchregs(struct task_struct *tsk, void __user *ufp)
418} 367}
419#endif 368#endif
420 369
421#ifdef CONFIG_VFP
422/*
423 * Get the child VFP state.
424 */
425static int ptrace_getvfpregs(struct task_struct *tsk, void __user *data)
426{
427 struct thread_info *thread = task_thread_info(tsk);
428 union vfp_state *vfp = &thread->vfpstate;
429 struct user_vfp __user *ufp = data;
430
431 vfp_sync_hwstate(thread);
432
433 /* copy the floating point registers */
434 if (copy_to_user(&ufp->fpregs, &vfp->hard.fpregs,
435 sizeof(vfp->hard.fpregs)))
436 return -EFAULT;
437
438 /* copy the status and control register */
439 if (put_user(vfp->hard.fpscr, &ufp->fpscr))
440 return -EFAULT;
441
442 return 0;
443}
444
445/*
446 * Set the child VFP state.
447 */
448static int ptrace_setvfpregs(struct task_struct *tsk, void __user *data)
449{
450 struct thread_info *thread = task_thread_info(tsk);
451 union vfp_state *vfp = &thread->vfpstate;
452 struct user_vfp __user *ufp = data;
453
454 vfp_sync_hwstate(thread);
455
456 /* copy the floating point registers */
457 if (copy_from_user(&vfp->hard.fpregs, &ufp->fpregs,
458 sizeof(vfp->hard.fpregs)))
459 return -EFAULT;
460
461 /* copy the status and control register */
462 if (get_user(vfp->hard.fpscr, &ufp->fpscr))
463 return -EFAULT;
464
465 vfp_flush_hwstate(thread);
466
467 return 0;
468}
469#endif
470
471#ifdef CONFIG_HAVE_HW_BREAKPOINT 370#ifdef CONFIG_HAVE_HW_BREAKPOINT
472/* 371/*
473 * Convert a virtual register number into an index for a thread_info 372 * Convert a virtual register number into an index for a thread_info
@@ -694,6 +593,219 @@ out:
694} 593}
695#endif 594#endif
696 595
596/* regset get/set implementations */
597
598static int gpr_get(struct task_struct *target,
599 const struct user_regset *regset,
600 unsigned int pos, unsigned int count,
601 void *kbuf, void __user *ubuf)
602{
603 struct pt_regs *regs = task_pt_regs(target);
604
605 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
606 regs,
607 0, sizeof(*regs));
608}
609
610static int gpr_set(struct task_struct *target,
611 const struct user_regset *regset,
612 unsigned int pos, unsigned int count,
613 const void *kbuf, const void __user *ubuf)
614{
615 int ret;
616 struct pt_regs newregs;
617
618 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
619 &newregs,
620 0, sizeof(newregs));
621 if (ret)
622 return ret;
623
624 if (!valid_user_regs(&newregs))
625 return -EINVAL;
626
627 *task_pt_regs(target) = newregs;
628 return 0;
629}
630
631static int fpa_get(struct task_struct *target,
632 const struct user_regset *regset,
633 unsigned int pos, unsigned int count,
634 void *kbuf, void __user *ubuf)
635{
636 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
637 &task_thread_info(target)->fpstate,
638 0, sizeof(struct user_fp));
639}
640
641static int fpa_set(struct task_struct *target,
642 const struct user_regset *regset,
643 unsigned int pos, unsigned int count,
644 const void *kbuf, const void __user *ubuf)
645{
646 struct thread_info *thread = task_thread_info(target);
647
648 thread->used_cp[1] = thread->used_cp[2] = 1;
649
650 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
651 &thread->fpstate,
652 0, sizeof(struct user_fp));
653}
654
655#ifdef CONFIG_VFP
656/*
657 * VFP register get/set implementations.
658 *
659 * With respect to the kernel, struct user_fp is divided into three chunks:
660 * 16 or 32 real VFP registers (d0-d15 or d0-31)
661 * These are transferred to/from the real registers in the task's
662 * vfp_hard_struct. The number of registers depends on the kernel
663 * configuration.
664 *
665 * 16 or 0 fake VFP registers (d16-d31 or empty)
666 * i.e., the user_vfp structure has space for 32 registers even if
667 * the kernel doesn't have them all.
668 *
669 * vfp_get() reads this chunk as zero where applicable
670 * vfp_set() ignores this chunk
671 *
672 * 1 word for the FPSCR
673 *
674 * The bounds-checking logic built into user_regset_copyout and friends
675 * means that we can make a simple sequence of calls to map the relevant data
676 * to/from the specified slice of the user regset structure.
677 */
678static int vfp_get(struct task_struct *target,
679 const struct user_regset *regset,
680 unsigned int pos, unsigned int count,
681 void *kbuf, void __user *ubuf)
682{
683 int ret;
684 struct thread_info *thread = task_thread_info(target);
685 struct vfp_hard_struct const *vfp = &thread->vfpstate.hard;
686 const size_t user_fpregs_offset = offsetof(struct user_vfp, fpregs);
687 const size_t user_fpscr_offset = offsetof(struct user_vfp, fpscr);
688
689 vfp_sync_hwstate(thread);
690
691 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
692 &vfp->fpregs,
693 user_fpregs_offset,
694 user_fpregs_offset + sizeof(vfp->fpregs));
695 if (ret)
696 return ret;
697
698 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
699 user_fpregs_offset + sizeof(vfp->fpregs),
700 user_fpscr_offset);
701 if (ret)
702 return ret;
703
704 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
705 &vfp->fpscr,
706 user_fpscr_offset,
707 user_fpscr_offset + sizeof(vfp->fpscr));
708}
709
710/*
711 * For vfp_set() a read-modify-write is done on the VFP registers,
712 * in order to avoid writing back a half-modified set of registers on
713 * failure.
714 */
715static int vfp_set(struct task_struct *target,
716 const struct user_regset *regset,
717 unsigned int pos, unsigned int count,
718 const void *kbuf, const void __user *ubuf)
719{
720 int ret;
721 struct thread_info *thread = task_thread_info(target);
722 struct vfp_hard_struct new_vfp = thread->vfpstate.hard;
723 const size_t user_fpregs_offset = offsetof(struct user_vfp, fpregs);
724 const size_t user_fpscr_offset = offsetof(struct user_vfp, fpscr);
725
726 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
727 &new_vfp.fpregs,
728 user_fpregs_offset,
729 user_fpregs_offset + sizeof(new_vfp.fpregs));
730 if (ret)
731 return ret;
732
733 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
734 user_fpregs_offset + sizeof(new_vfp.fpregs),
735 user_fpscr_offset);
736 if (ret)
737 return ret;
738
739 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
740 &new_vfp.fpscr,
741 user_fpscr_offset,
742 user_fpscr_offset + sizeof(new_vfp.fpscr));
743 if (ret)
744 return ret;
745
746 vfp_sync_hwstate(thread);
747 thread->vfpstate.hard = new_vfp;
748 vfp_flush_hwstate(thread);
749
750 return 0;
751}
752#endif /* CONFIG_VFP */
753
754enum arm_regset {
755 REGSET_GPR,
756 REGSET_FPR,
757#ifdef CONFIG_VFP
758 REGSET_VFP,
759#endif
760};
761
762static const struct user_regset arm_regsets[] = {
763 [REGSET_GPR] = {
764 .core_note_type = NT_PRSTATUS,
765 .n = ELF_NGREG,
766 .size = sizeof(u32),
767 .align = sizeof(u32),
768 .get = gpr_get,
769 .set = gpr_set
770 },
771 [REGSET_FPR] = {
772 /*
773 * For the FPA regs in fpstate, the real fields are a mixture
774 * of sizes, so pretend that the registers are word-sized:
775 */
776 .core_note_type = NT_PRFPREG,
777 .n = sizeof(struct user_fp) / sizeof(u32),
778 .size = sizeof(u32),
779 .align = sizeof(u32),
780 .get = fpa_get,
781 .set = fpa_set
782 },
783#ifdef CONFIG_VFP
784 [REGSET_VFP] = {
785 /*
786 * Pretend that the VFP regs are word-sized, since the FPSCR is
787 * a single word dangling at the end of struct user_vfp:
788 */
789 .core_note_type = NT_ARM_VFP,
790 .n = ARM_VFPREGS_SIZE / sizeof(u32),
791 .size = sizeof(u32),
792 .align = sizeof(u32),
793 .get = vfp_get,
794 .set = vfp_set
795 },
796#endif /* CONFIG_VFP */
797};
798
799static const struct user_regset_view user_arm_view = {
800 .name = "arm", .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
801 .regsets = arm_regsets, .n = ARRAY_SIZE(arm_regsets)
802};
803
804const struct user_regset_view *task_user_regset_view(struct task_struct *task)
805{
806 return &user_arm_view;
807}
808
697long arch_ptrace(struct task_struct *child, long request, 809long arch_ptrace(struct task_struct *child, long request,
698 unsigned long addr, unsigned long data) 810 unsigned long addr, unsigned long data)
699{ 811{
@@ -710,19 +822,31 @@ long arch_ptrace(struct task_struct *child, long request,
710 break; 822 break;
711 823
712 case PTRACE_GETREGS: 824 case PTRACE_GETREGS:
713 ret = ptrace_getregs(child, datap); 825 ret = copy_regset_to_user(child,
826 &user_arm_view, REGSET_GPR,
827 0, sizeof(struct pt_regs),
828 datap);
714 break; 829 break;
715 830
716 case PTRACE_SETREGS: 831 case PTRACE_SETREGS:
717 ret = ptrace_setregs(child, datap); 832 ret = copy_regset_from_user(child,
833 &user_arm_view, REGSET_GPR,
834 0, sizeof(struct pt_regs),
835 datap);
718 break; 836 break;
719 837
720 case PTRACE_GETFPREGS: 838 case PTRACE_GETFPREGS:
721 ret = ptrace_getfpregs(child, datap); 839 ret = copy_regset_to_user(child,
840 &user_arm_view, REGSET_FPR,
841 0, sizeof(union fp_state),
842 datap);
722 break; 843 break;
723 844
724 case PTRACE_SETFPREGS: 845 case PTRACE_SETFPREGS:
725 ret = ptrace_setfpregs(child, datap); 846 ret = copy_regset_from_user(child,
847 &user_arm_view, REGSET_FPR,
848 0, sizeof(union fp_state),
849 datap);
726 break; 850 break;
727 851
728#ifdef CONFIG_IWMMXT 852#ifdef CONFIG_IWMMXT
@@ -757,11 +881,17 @@ long arch_ptrace(struct task_struct *child, long request,
757 881
758#ifdef CONFIG_VFP 882#ifdef CONFIG_VFP
759 case PTRACE_GETVFPREGS: 883 case PTRACE_GETVFPREGS:
760 ret = ptrace_getvfpregs(child, datap); 884 ret = copy_regset_to_user(child,
885 &user_arm_view, REGSET_VFP,
886 0, ARM_VFPREGS_SIZE,
887 datap);
761 break; 888 break;
762 889
763 case PTRACE_SETVFPREGS: 890 case PTRACE_SETVFPREGS:
764 ret = ptrace_setvfpregs(child, datap); 891 ret = copy_regset_from_user(child,
892 &user_arm_view, REGSET_VFP,
893 0, ARM_VFPREGS_SIZE,
894 datap);
765 break; 895 break;
766#endif 896#endif
767 897