aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-05-17 20:35:50 +0200
committerAndrey Konovalov <andreyknvl@google.com>2017-06-12 19:48:23 +0200
commite7366c123e8e62cab5e70998b56e832c77178a59 (patch)
tree94df9fe48407bf052c2732872208e553ef32d215 /executor
parent7d7c9c550f5d83c652719be31a350a9f8f306b3c (diff)
executor: split setup_main_process into smaller functions
Diffstat (limited to 'executor')
-rw-r--r--executor/common.h43
-rw-r--r--executor/executor.cc3
2 files changed, 23 insertions, 23 deletions
diff --git a/executor/common.h b/executor/common.h
index d7b403554..92467dc26 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -159,6 +159,15 @@ static void segv_handler(int sig, siginfo_t* info, void* uctx)
static void install_segv_handler()
{
struct sigaction sa;
+
+ // Don't need that SIGCANCEL/SIGSETXID glibc stuff.
+ // SIGCANCEL sent to main thread causes it to exit
+ // without bringing down the whole group.
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = SIG_IGN;
+ syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
+ syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
+
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
@@ -166,6 +175,18 @@ static void install_segv_handler()
sigaction(SIGBUS, &sa, NULL);
}
+static void use_temporary_dir()
+{
+ char tmpdir_template[] = "./syzkaller.XXXXXX";
+ char* tmpdir = mkdtemp(tmpdir_template);
+ if (!tmpdir)
+ fail("failed to mkdtemp");
+ if (chmod(tmpdir, 0777))
+ fail("failed to chmod");
+ if (chdir(tmpdir))
+ fail("failed to chdir");
+}
+
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
@@ -616,28 +637,6 @@ static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1, uintptr_t a
}
}
-static void setup_main_process()
-{
- // Don't need that SIGCANCEL/SIGSETXID glibc stuff.
- // SIGCANCEL sent to main thread causes it to exit
- // without bringing down the whole group.
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_IGN;
- syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
- syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
- install_segv_handler();
-
- char tmpdir_template[] = "./syzkaller.XXXXXX";
- char* tmpdir = mkdtemp(tmpdir_template);
- if (!tmpdir)
- fail("failed to mkdtemp");
- if (chmod(tmpdir, 0777))
- fail("failed to chmod");
- if (chdir(tmpdir))
- fail("failed to chdir");
-}
-
static void loop();
static void sandbox_common()
diff --git a/executor/executor.cc b/executor/executor.cc
index 800ac932e..04624cdc8 100644
--- a/executor/executor.cc
+++ b/executor/executor.cc
@@ -186,7 +186,8 @@ int main(int argc, char** argv)
uint64_t executor_pid = *((uint64_t*)input_data + 1);
cover_open();
- setup_main_process();
+ install_segv_handler();
+ use_temporary_dir();
int pid = -1;
switch (flag_sandbox) {