Serge E. Hallyn wrote:
> Quoting Seiichi Ikarashi (s.ikara...@jp.fujitsu.com):
>> Like this?
> 
> Cool, thanks, and thanks for fixing up the do_clone_tests().  However,
> you pass the bottom instead of the top of the stack to clone.  See
> the use of 'childstack' in the original do_clone_tests().

I just copied it from testcases/kernel/syscalls/clone/clone01.c,
which passes the stack bottom to clone2() for __ia64__.
Since you pointed it out, I investigated a little.
In glibc-2.5.24, nptl/allocatestack.c:allocate_stack()
sets the stack variable as the bottom of the stack for
NEED_SEPARATE_REGISTER_STACK-defined arch, namely ia64.
In linux-2.6.28, arch/ia64/kernel/process.c:copy_thread()
sets child_ptregs->r12 as user_stack_base (the 2nd arg of __clone2)
+ user_stack_size (the 3rd arg of __clone2) - 16.
The r12 is the stack pointer on ia64.
So I bet passing the bottom is right in this case.

> 
> This still leaves two places to get the per-arch junk right, so how
> about using do_clone() inside of do_clone_tests()?

You're right.

Signed-off-by: Seiichi Ikarashi <s.ikara...@jp.fujitsu.com>

Regards,
--- ltp-full-20081231/testcases/kernel/containers/libclone/libclone.c	2008-02-14 17:49:30.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/libclone/libclone.c	2009-01-16 11:39:32.000000000 +0900
@@ -18,30 +18,43 @@
 
 /* Serge: should I be passing in strings for error messages? */
 
-int do_clone_tests(unsigned long clone_flags,
-			int(*fn1)(void *arg), void *arg1,
-			int(*fn2)(void *arg), void *arg2)
+int do_clone(unsigned long clone_flags,
+			int(*fn1)(void *arg), void *arg1)
 {
 	int ret;
 	int stack_size = getpagesize() * 4;
-	void *childstack, *stack = malloc (stack_size);
+	void *stack = malloc (stack_size);
 
 	if (!stack) {
 		perror("malloc");
 		return -1;
 	}
 
-	childstack = stack + stack_size;
-
-#ifdef __ia64__
-	ret = clone2(fn1, childstack, getpagesize(), clone_flags | SIGCHLD, arg1, NULL, NULL, NULL);
+#if defined(__hppa__)
+	ret = clone(fn1, stack, clone_flags, arg1);
+#elif defined(__ia64__)
+	ret = clone2(fn1, stack, stack_size, clone_flags, arg1, NULL, NULL, NULL);
 #else
-	ret = clone(fn1, childstack, clone_flags | SIGCHLD, arg1);
+	ret = clone(fn1, stack + stack_size, clone_flags, arg1);
 #endif
 
 	if (ret == -1) {
 		perror("clone");
 		free(stack);
+	}
+
+	return ret;
+}
+
+int do_clone_tests(unsigned long clone_flags,
+			int(*fn1)(void *arg), void *arg1,
+			int(*fn2)(void *arg), void *arg2)
+{
+	int ret;
+
+	ret = do_clone(clone_flags | SIGCHLD, fn1, arg1);
+
+	if (ret == -1) {
 		return -1;
 	}
 	if (fn2)
--- ltp-full-20081231/testcases/kernel/containers/libclone/libclone.h	2008-09-19 21:17:10.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/libclone/libclone.h	2009-01-15 17:50:57.000000000 +0900
@@ -55,7 +55,10 @@
 #define __NR_unshare SYS_unshare
 #endif
 
-#ifdef __ia64__
+#if defined (__s390__) || (__s390x__)
+#define clone __clone
+extern int __clone(int(void*),void*,int,void*);
+#elif defined(__ia64__)
 #define clone2 __clone2
 extern int  __clone2(int (*fn) (void *arg), void *child_stack_base,
                 size_t child_stack_size, int flags, void *arg,
@@ -89,6 +92,9 @@ extern int create_net_namespace(char *, 
  * Fn2 may be NULL.
  */
 
+int do_clone(unsigned long clone_flags,
+			int(*fn1)(void *arg), void *arg1);
+
 int do_clone_tests(unsigned long clone_flags,
 			int(*fn1)(void *arg), void *arg1,
 			int(*fn2)(void *arg), void *arg2);
--- ltp-full-20081231/testcases/kernel/containers/pidns/check_pidns_enabled.c	2007-12-28 18:40:55.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/check_pidns_enabled.c	2009-01-15 16:10:01.000000000 +0900
@@ -51,7 +51,6 @@ int dummy(void *v)
 /* MAIN */
 int main()
 {
-        void *childstack, *stack;
         int pid;
 
 	/* Test for the running kernel version
@@ -59,19 +58,8 @@ int main()
 	 */
         if (tst_kvercmp(2,6,24) < 0)
                 return 1;
-        stack = malloc(getpagesize());
-        if (!stack) {
-                perror("malloc");
-                return 2;
-        }
 
-        childstack = stack + getpagesize();
-
-#ifdef __ia64__
-        pid = clone2(dummy, childstack, getpagesize(), CLONE_NEWPID, NULL, NULL, NULL, NULL);
-#else
-        pid = clone(dummy, childstack, CLONE_NEWPID, NULL);
-#endif
+        pid = do_clone(CLONE_NEWPID, dummy, NULL);
 
 	/* Check for the clone function return value */
         if (pid == -1)
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns12.c	2008-12-16 21:34:49.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns12.c	2009-01-15 16:10:01.000000000 +0900
@@ -152,9 +152,7 @@ int child_fn(void *arg)
 
 int main(int argc, char *argv[])
 {
-	int status, stack_size=getpagesize() * 4;
-	void *stack = malloc (stack_size);
-	void *childstack;
+	int status;
 	pid_t pid, cpid;
 	char buf[5];
 
@@ -167,15 +165,7 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
-	/* Container creation on PID namespace */
-	if (!stack) {
-		tst_resm(TBROK, "parent: stack creation failed.");
-		cleanup();
-	}
-
-	childstack = stack + stack_size;
-
-	cpid = clone(child_fn, childstack, CLONE_NEWPID|SIGCHLD, NULL);
+	cpid = do_clone(CLONE_NEWPID|SIGCHLD, child_fn, NULL);
 	if (cpid < 0) {
 		tst_resm(TBROK, "parent: clone() failed(%s).",\
 				strerror(errno));
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns13.c	2008-12-16 21:34:49.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns13.c	2009-01-15 16:10:01.000000000 +0900
@@ -195,11 +195,8 @@ int child_fn(void *arg)
 
 int main(int argc, char *argv[])
 {
-	int status, stack_size=getpagesize() * 4;
+	int status;
 	int *cinit_no;
-	void *stack1 = malloc(stack_size);
-	void *stack2 = malloc(stack_size);
-	void *childstack1, *childstack2;
 	pid_t cpid1, cpid2;
 
 	/* create pipe */
@@ -208,22 +205,13 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
-	/* container creation on PID namespace */
-	if (!stack1 || !stack2) {
-		tst_resm(TBROK, "parent: stack creation failed.");
-		cleanup();
-	}
-
-	childstack1 = stack1 + stack_size;
-	childstack2 = stack2 + stack_size;
-
 	/* Create container 1 */
 	*cinit_no = 1;
-	cpid1 = clone(child_fn, childstack1, CLONE_NEWPID|SIGCHLD, cinit_no);
+	cpid1 = do_clone(CLONE_NEWPID|SIGCHLD, child_fn, cinit_no);
 
 	/* Create container 2 */
 	*cinit_no = 2;
-	cpid2 = clone(child_fn, childstack2, CLONE_NEWPID|SIGCHLD, cinit_no);
+	cpid2 = do_clone(CLONE_NEWPID|SIGCHLD, child_fn, cinit_no);
 	if (cpid1 < 0 || cpid2 < 0) {
 		tst_resm(TBROK, "parent: clone() failed.");
 		cleanup();
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns14.c	2008-12-12 23:36:47.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns14.c	2009-01-15 16:10:01.000000000 +0900
@@ -89,18 +89,10 @@ void cleanup()
 
 int main(int argc, char *argv[])
 {
-	int status, stack_size = getpagesize() * 4 ;
-	void *stack = malloc(stack_size);
-	void *childstack;
+	int status;
 	pid_t cpid;
 
-	/* Container creation on PID namespace */
-	if (!stack) {
-		tst_resm(TBROK, "stack creation failed.");
-		cleanup();
-	}
-	childstack = stack + stack_size;
-	cpid = clone(child_fn, childstack, CLONE_NEWPID | SIGCHLD, NULL);
+	cpid = do_clone(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
 
 	if (cpid < 0) {
 		tst_resm(TBROK, "clone() failed.");
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns16.c	2008-12-12 23:39:20.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns16.c	2009-01-15 16:10:01.000000000 +0900
@@ -123,21 +123,12 @@ int child_fn(void *ttype)
 ***********************************************************************/
 int main(int argc, char *argv[])
 {
-	int status, stack_size = getpagesize() * 4 ;
-	void *stack = malloc(stack_size);
-	void *childstack;
+	int status;
 	pid_t cpid;
 
 	globalpid = getpid();
 
-	/* Container creation on PID namespace */
-	if (!stack) {
-		tst_resm(TBROK, "stack creation failed.");
-		cleanup();
-	}
-
-	childstack = stack + stack_size;
-	cpid = clone(child_fn, childstack, CLONE_NEWPID | SIGCHLD, NULL);
+	cpid = do_clone(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
 
 	if (cpid < 0) {
 		tst_resm(TBROK, "clone() failed.");
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns20.c	2008-12-18 14:22:59.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns20.c	2009-01-15 16:10:01.000000000 +0900
@@ -170,9 +170,6 @@ int child_fn(void *arg)
 
 int main(int argc, char *argv[])
 {
-	int stack_size=getpagesize() * 4;
-	void *stack = malloc (stack_size);
-	void *childstack;
 	int status;
 	char buf[5];
 	pid_t cpid;
@@ -183,14 +180,7 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
-	/* container creation on PID namespace */
-	if (!stack) {
-		tst_resm(TBROK, "parent: stack creation failed.");
-		cleanup();
-	}
-
-	childstack = stack + stack_size;
-	cpid = clone(child_fn, childstack, CLONE_NEWPID|SIGCHLD, NULL);
+	cpid = do_clone(CLONE_NEWPID|SIGCHLD, child_fn, NULL);
 	if (cpid < 0) {
 		tst_resm(TBROK, "parent: clone() failed(%s)",\
 				strerror(errno));
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns21.c	2008-12-18 14:22:59.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns21.c	2009-01-15 16:10:01.000000000 +0900
@@ -172,9 +172,6 @@ int child_fn(void *arg)
 
 int main(int argc, char *argv[])
 {
-	int stack_size=getpagesize() * 4;
-	void *stack = malloc (stack_size);
-	void *childstack;
 	int status;
 	char buf[5];
 	pid_t cpid;
@@ -185,14 +182,7 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
-	/* container creation on PID namespace */
-	if (!stack) {
-		tst_resm(TBROK, "parent: stack creation failed.");
-		cleanup();
-	}
-
-	childstack = stack + stack_size;
-	cpid = clone(child_fn, childstack, CLONE_NEWPID|SIGCHLD, NULL);
+	cpid = do_clone(CLONE_NEWPID|SIGCHLD, child_fn, NULL);
 	if (cpid < 0) {
 		tst_resm(TBROK, "parent: clone() failed(%s)",\
 				strerror(errno));
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns30.c	2008-12-12 22:14:21.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns30.c	2009-01-15 16:10:01.000000000 +0900
@@ -274,20 +274,12 @@ int child_fn(void *arg)
 
 int main(int argc, char *argv[])
 {
-	int stack_size = getpagesize() * 4;
-	void *stack = malloc(stack_size);
-	void *childstack;
 	int status;
 	char buf[5];
 	pid_t cpid;
 	mqd_t mqd;
 	mqd_t rc;
 
-	if (!stack) {
-		tst_resm(TBROK, "parent: stack creation failed.");
-		cleanup(TBROK, NO_STEP, 0);
-	}
-
 	if (pipe(child_to_father) == -1) {
 		tst_resm(TBROK, "parent: pipe() failed. aborting!");
 		cleanup(TBROK, NO_STEP, 0);
@@ -308,8 +300,7 @@ int main(int argc, char *argv[])
 	tst_resm(TINFO, "parent: successfully created posix mqueue");
 
 	/* container creation on PID namespace */
-	childstack = stack + stack_size;
-	cpid = clone(child_fn, childstack, CLONE_NEWPID|SIGCHLD, NULL);
+	cpid = do_clone(CLONE_NEWPID|SIGCHLD, child_fn, NULL);
 	if (cpid < 0) {
 		tst_resm(TBROK, "parent: clone() failed(%s)", strerror(errno));
 		cleanup(TBROK, F_STEP_2, mqd);
--- ltp-full-20081231/testcases/kernel/containers/pidns/pidns31.c	2008-12-12 22:17:07.000000000 +0900
+++ ltp-full-20081231.modified/testcases/kernel/containers/pidns/pidns31.c	2009-01-15 16:10:01.000000000 +0900
@@ -247,9 +247,6 @@ static void father_signal_handler(int si
 
 int main(int argc, char *argv[])
 {
-	int stack_size = getpagesize() * 4;
-	void *stack = malloc(stack_size);
-	void *childstack;
 	pid_t cpid;
 	mqd_t mqd;
 	struct sigevent notif;
@@ -257,11 +254,6 @@ int main(int argc, char *argv[])
 	int status;
 	struct notify_info info;
 
-	if (!stack) {
-		tst_resm(TBROK, "parent: stack creation failed.");
-		cleanup(TBROK, NO_STEP, 0);
-	}
-
 	if (pipe(father_to_child) == -1) {
 		tst_resm(TBROK, "parent: pipe() failed. aborting!");
 		cleanup(TBROK, NO_STEP, 0);
@@ -277,8 +269,7 @@ int main(int argc, char *argv[])
 	tst_resm(TINFO, "parent: successfully created posix mqueue");
 
 	/* container creation on PID namespace */
-	childstack = stack + stack_size;
-	cpid = clone(child_fn, childstack, CLONE_NEWPID|SIGCHLD, NULL);
+	cpid = do_clone(CLONE_NEWPID|SIGCHLD, child_fn, NULL);
 	if (cpid < 0) {
 		tst_resm(TBROK, "parent: clone() failed(%s)", strerror(errno));
 		cleanup(TBROK, F_STEP_1, mqd);
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to