setjmp/longjmp: don't use stack-based jmp_buf, use TLS one
authorRobert Swiecki <robert@swiecki.net>
Thu, 3 Nov 2016 02:53:52 +0000 (03:53 +0100)
committerRobert Swiecki <robert@swiecki.net>
Thu, 3 Nov 2016 02:53:52 +0000 (03:53 +0100)
Makefile
subproc.c

index 1f2be1b99249516a0f2491a96ff58f2bfc404d75..d112c1bf4e0cbd8fecccabaee3782dd884efb806 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,7 @@ cmdline.o: cmdline.h common.h log.h util.h
 contain.o: contain.h common.h cgroup.h log.h mount.h net.h pid.h util.h uts.h
 log.o: log.h common.h
 cgroup.o: cgroup.h common.h log.h util.h
-mount.o: mount.h common.h log.h util.h
+mount.o: mount.h common.h log.h subproc.h util.h
 net.o: net.h common.h log.h subproc.h
 pid.o: pid.h common.h log.h subproc.h
 sandbox.o: sandbox.h common.h log.h
index d939c9d7c4f544aa192cf5fa6240808407bcd039..69b2921d18e2d47f3366a157aff5e906271c42a0 100644 (file)
--- a/subproc.c
+++ b/subproc.c
@@ -293,11 +293,12 @@ static bool subprocInitParent(struct nsjconf_t *nsjconf, pid_t pid, int pipefd)
 }
 
 static uint8_t subprocCloneStack[PTHREAD_STACK_MIN * 2];
+static __thread jmp_buf env;
 
-static int subprocCloneFunc(void *arg)
+static int subprocCloneFunc(void *arg __attribute__ ((unused)))
 {
-       jmp_buf *env_ptr = (jmp_buf *) arg;
-       longjmp(*env_ptr, 1);
+       longjmp(env, 1);
+       return 0;
 }
 
 /*
@@ -312,7 +313,6 @@ pid_t subprocClone(uintptr_t flags)
                return -1;
        }
 
-       jmp_buf env;
        if (setjmp(env) == 0) {
                /*
                 * Avoid the problem of the stack growing up/down under different CPU architectures, by using
@@ -320,7 +320,7 @@ pid_t subprocClone(uintptr_t flags)
                 */
                void *stack = &subprocCloneStack[sizeof(subprocCloneStack) / 2];
                /* Parent */
-               return clone(subprocCloneFunc, stack, flags, &env, NULL, NULL);
+               return clone(subprocCloneFunc, stack, flags, NULL, NULL, NULL);
        }
        /* Child */
        return 0;