mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roland McGrath <roland@redhat.com>
To: Russell King <rmk@arm.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>, linux-kernel@vger.kernel.org
Subject: [PATCH 06/17] arm: user_regset: general regs
Date: Fri, 24 Apr 2009 17:10:19 -0700 (PDT)	[thread overview]
Message-ID: <20090425001019.20460FC3C8@magilla.sf.frob.com> (raw)
In-Reply-To: Roland McGrath's message of  Friday, 24 April 2009 17:06:34 -0700 <20090425000634.313E4FC3C8@magilla.sf.frob.com>

This converts PTRACE_GETREGS/PTRACE_SETREGS into user_regset form.
There should be no change in the ptrace behavior.

Signed-off-by: Roland McGrath <roland@redhat.com>
---
 arch/arm/kernel/ptrace.c |   72 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index effada1..fbb18e4 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -15,6 +15,8 @@
 #include <linux/smp.h>
 #include <linux/ptrace.h>
 #include <linux/tracehook.h>
+#include <linux/regset.h>
+#include <linux/elf.h>
 #include <linux/user.h>
 #include <linux/security.h>
 #include <linux/init.h>
@@ -547,30 +549,38 @@ static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
 /*
  * Get all user integer registers.
  */
-static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
+static int gpr_get(struct task_struct *target,
+		   const struct user_regset *regset,
+		   unsigned int pos, unsigned int count,
+		   void *kbuf, void __user *ubuf)
 {
-	struct pt_regs *regs = task_pt_regs(tsk);
-
-	return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
+	struct pt_regs *regs = task_pt_regs(target);
+	return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+				   regs, 0, sizeof(*regs));
 }
 
 /*
  * Set all user integer registers.
  */
-static int ptrace_setregs(struct task_struct *tsk, void __user *uregs)
+static int gpr_set(struct task_struct *target,
+		   const struct user_regset *regset,
+		   unsigned int pos, unsigned int count,
+		   const void *kbuf, const void __user *ubuf)
 {
+	struct pt_regs *regs = task_pt_regs(target);
 	struct pt_regs newregs;
 	int ret;
 
-	ret = -EFAULT;
-	if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
-		struct pt_regs *regs = task_pt_regs(tsk);
+	if (pos != 0 || count != sizeof(newregs))
+		newregs = *regs;
 
-		ret = -EINVAL;
-		if (valid_user_regs(&newregs)) {
+	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+				 &newregs, 0, sizeof(newregs));
+	if (!ret) {
+		if (valid_user_regs(&newregs))
 			*regs = newregs;
-			ret = 0;
-		}
+		else
+			ret = -EINVAL;
 	}
 
 	return ret;
@@ -702,6 +712,34 @@ static int ptrace_setvfpregs(struct task_struct *tsk, void __user *data)
 }
 #endif
 
+/*
+ * Indices in arm_regsets[] array.  These are used only in arch_ptrace(),
+ * below.  The ordering that matters is that the NT_PRSTATUS regset is
+ * first.  Other than that, ever use outside this file should just look at
+ * the contents of the table entries.
+ */
+enum {
+	REGSET_GPR,
+};
+
+static const struct user_regset arm_regsets[] = {
+	[REGSET_GPR] = {
+		.core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
+		.size = sizeof(long), .align = sizeof(long),
+		.get = gpr_get, .set = gpr_set
+	},
+};
+
+static const struct user_regset_view user_arm_view = {
+	.name = "arm", .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
+	.regsets = arm_regsets, .n = ARRAY_SIZE(arm_regsets)
+};
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+	return &user_arm_view;
+}
+
 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 {
 	int ret;
@@ -742,12 +780,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		goto common;
 
 	case PTRACE_GETREGS:
-		ret = ptrace_getregs(child, (void __user *)data);
-		break;
+		return copy_regset_to_user(child, &user_arm_view, REGSET_GPR,
+					   0, sizeof(struct pt_regs),
+					   (void __user *) data);
 
 	case PTRACE_SETREGS:
-		ret = ptrace_setregs(child, (void __user *)data);
-		break;
+		return copy_regset_from_user(child, &user_arm_view, REGSET_GPR,
+					     0, sizeof(struct pt_regs),
+					     (const void __user *) data);
 
 	case PTRACE_GETFPREGS:
 		ret = ptrace_getfpregs(child, (void __user *)data);

  parent reply	other threads:[~2009-04-25  0:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-25  0:06 [PATCH 0/17] tracehook & user_regset for ARM Roland McGrath
2009-04-25  0:07 ` [PATCH 01/17] arm: arch_ptrace clean-up Roland McGrath
2009-06-19  9:13   ` Russell King
2009-06-24  6:55     ` Roland McGrath
2009-04-25  0:08 ` [PATCH 02/17] arm: arch_ptrace indentation Roland McGrath
2009-04-25  0:08 ` [PATCH 03/17] arm: tracehook_report_syscall Roland McGrath
2009-04-25  0:09 ` [PATCH 04/17] arm: tracehook_signal_handler Roland McGrath
2009-04-25  0:09 ` [PATCH 05/17] arm: TIF_NOTIFY_RESUME Roland McGrath
2009-04-25  0:10 ` Roland McGrath [this message]
2009-04-25  0:10 ` [PATCH 07/17] arm: user_regset: FPU regs Roland McGrath
2009-04-25  0:11 ` [PATCH 08/17] arm: CORE_DUMP_USE_REGSET Roland McGrath
2009-04-25  0:11 ` [PATCH 09/17] arm: user_regset: VFP regs Roland McGrath
2009-04-25  0:12 ` [PATCH 10/17] arm: user_regset: VFP in core dumps Roland McGrath
2009-04-25  0:12 ` [PATCH 11/17] arm: user_regset: iWMMXt regs Roland McGrath
2009-04-25  0:12 ` [PATCH 12/17] arm: user_regset: iWMMXt in core dumps Roland McGrath
2009-04-27 22:43   ` Paul Mundt
2009-04-28  2:53     ` Roland McGrath
2009-04-25  0:13 ` [PATCH 13/17] arm: user_regset: Crunch regs Roland McGrath
2009-04-25  0:13 ` [PATCH 14/17] arm: user_regset: Crunch in core dumps Roland McGrath
2009-04-25  0:14 ` [PATCH 15/17] arm: user_regset: thread pointer " Roland McGrath
2009-04-25  0:15 ` [PATCH 16/17] arm: asm/syscall.h (unfinished) Roland McGrath
2009-06-19  9:31   ` Russell King
2009-06-24  8:56     ` Roland McGrath
2009-04-25  0:15 ` [PATCH 17/17] arm: HAVE_ARCH_TRACEHOOK Roland McGrath
2009-06-06 14:42 ` [PATCH 0/17] tracehook & user_regset for ARM Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090425001019.20460FC3C8@magilla.sf.frob.com \
    --to=roland@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®