diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-06-29 10:47:42 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-06-29 10:47:42 +0200 |
| commit | 7b45fa115b57d0a6424c369483b320acfe6a1de7 (patch) | |
| tree | fbc8b30b977926c3345509358bfdc76eaa2ca495 /executor/common_linux.h | |
| parent | 1a3c2436df1f7c9c0271aad092558d943a0ee19e (diff) | |
pkg/csource: support fuchsia
Lots of assorted heavylifting to support csource on fuchsia.
Diffstat (limited to 'executor/common_linux.h')
| -rw-r--r-- | executor/common_linux.h | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h index 661f58c94..18acaaa7e 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -1192,6 +1192,17 @@ static void sandbox_common() debug("unshare(CLONE_SYSVSEM): %d\n", errno); } } + +int wait_for_loop(int pid) +{ + if (pid < 0) + fail("sandbox fork failed"); + debug("spawned loop pid %d\n", pid); + int status = 0; + while (waitpid(-1, &status, __WALL) != pid) { + } + return WEXITSTATUS(status); +} #endif #if defined(SYZ_EXECUTOR) || defined(SYZ_SANDBOX_NONE) @@ -1207,10 +1218,8 @@ static int do_sandbox_none(void) debug("unshare(CLONE_NEWPID): %d\n", errno); } int pid = fork(); - if (pid < 0) - fail("sandbox fork failed"); - if (pid) - return pid; + if (pid <= 0) + return wait_for_loop(pid); #if defined(SYZ_EXECUTOR) || defined(SYZ_ENABLE_CGROUPS) setup_cgroups(); @@ -1237,10 +1246,8 @@ static int do_sandbox_setuid(void) if (unshare(CLONE_NEWPID)) fail("unshare(CLONE_NEWPID)"); int pid = fork(); - if (pid < 0) - fail("sandbox fork failed"); - if (pid) - return pid; + if (pid <= 0) + return wait_for_loop(pid); #if defined(SYZ_EXECUTOR) || defined(SYZ_ENABLE_CGROUPS) setup_cgroups(); @@ -1404,9 +1411,7 @@ static int do_sandbox_namespace(void) mprotect(sandbox_stack, 4096, PROT_NONE); // to catch stack underflows pid = clone(namespace_sandbox_proc, &sandbox_stack[sizeof(sandbox_stack) - 64], CLONE_NEWUSER | CLONE_NEWPID, 0); - if (pid < 0) - fail("sandbox clone failed"); - return pid; + return wait_for_loop(pid); } #endif @@ -2205,7 +2210,7 @@ static void execute(int num_calls) ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); - if (running) + if (__atomic_load_n(&running, __ATOMIC_RELAXED)) usleep((call == num_calls - 1) ? 10000 : 1000); break; } |
