Skip to contentSkip to conversation

user-cr: make powerpc eclone stack setup more robust

PATCH New Nathan Lynch 1 participant 2 messages Feb 5, 2010 1 message not in the archive Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 user-cr: make powerpc eclone stack setup more robust

For ppc64, it's not sufficient to merely align the stack pointer (clone_args->child_stack); we must also set up a stack frame (48 bytes). Encapsulate the stack setup details in a helper function (stack_setup_frame) which makes appropriate adjustments.

Although the genstack implementation provides zeroed stack pages, it's best not to rely on that implementation detail, so explicitly zero the back chain pointer in stack_setup_frame as well.

---
 clone_ppc.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
clone_ppc.c +18 -8
index f047a9e..2d8b0f8 100644
@@ -31,6 +31,22 @@ extern int __eclone(int (*fn)(void *arg),
 		    size_t args_size,
 		    pid_t *pids);
 
+#ifdef __powerpc64__
+#define MIN_STACK_FRAME 48
+#else
+#define MIN_STACK_FRAME 16
+#endif
+
+static unsigned long stack_setup_frame(unsigned long base, unsigned long size)
+{
+	unsigned long *sp;
+
+	sp =  (unsigned long *)(((base + size - 1) & ~0xf) - MIN_STACK_FRAME);
+	*sp = 0;
+
+	return (unsigned long)sp;
+}
+
 int eclone(int (*fn)(void *), void *fn_arg, int clone_flags_low,
 	   struct clone_args *clone_args, pid_t *pids)
 {
@@ -38,15 +54,9 @@ int eclone(int (*fn)(void *), void *fn_arg, int clone_flags_low,
 	unsigned long child_sp;
 	int newpid;
 
-	/* The stack pointer for the child is communicated to the
-	 * kernel via clone_args.child_stack, and to the __eclone
-	 * assembly wrapper via the child_sp argument [r4].  So we
-	 * need to align child_sp here and ensure that the wrapper and
-	 * the kernel receive the same value.
-	 */
 	if (clone_args->child_stack)
-		child_sp = (clone_args->child_stack +
-			    clone_args->child_stack_size - 1) & ~0xf;
+		child_sp = stack_setup_frame(clone_args->child_stack,
+					     clone_args->child_stack_size);
 	else
 		child_sp = 0;
 
Signature · 1 line
1.6.0.6

A message that is not in the archive (sent off-list or not yet received): 1265403602-1083-1-git-send-email-ntl-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 2/2 user-cr: add ppc64 eclone wrapper

---
 Makefile       |    8 +++++
 clone_ppc64.c  |    1 +
 clone_ppc64_.S |   96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 clone_ppc64.c
 create mode 100644 clone_ppc64_.S
Makefile +8 -0
index 35188f9..11db11f 100644
@@ -45,6 +45,14 @@ endif
 
 # on powerpc, need also assembly file
 ifeq ($(SUBARCH),ppc)
+CFLAGS += -m32
+ASFLAGS += -m32
+restart: clone_$(SUBARCH)_.o
+nsexeccwp: clone_$(SUBARCH)_.o
+endif
+ifeq ($(SUBARCH),ppc64)
+CFLAGS += -m64
+ASFLAGS += -m64
 restart: clone_$(SUBARCH)_.o
 nsexeccwp: clone_$(SUBARCH)_.o
 endif
clone_ppc64.c new file +1 -0
new file mode 100644
index 0000000..5aec466
@@ -0,0 +1 @@
+#include "clone_ppc.c"
clone_ppc64_.S new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
1.6.0.6