aboutsummaryrefslogtreecommitdiffstats
path: root/csource
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 /csource
parent7d7c9c550f5d83c652719be31a350a9f8f306b3c (diff)
executor: split setup_main_process into smaller functions
Diffstat (limited to 'csource')
-rw-r--r--csource/common.go36
-rw-r--r--csource/csource.go9
2 files changed, 23 insertions, 22 deletions
diff --git a/csource/common.go b/csource/common.go
index 8146de3f4..048df6f52 100644
--- a/csource/common.go
+++ b/csource/common.go
@@ -137,6 +137,12 @@ static void segv_handler(int sig, siginfo_t* info, void* uctx)
static void install_segv_handler()
{
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);
+
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
@@ -144,6 +150,17 @@ 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); \
@@ -1524,25 +1541,6 @@ static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1, uintptr_t a
}
}
-static void setup_main_process()
-{
- 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/csource/csource.go b/csource/csource.go
index cc4d0d944..b41c5ca11 100644
--- a/csource/csource.go
+++ b/csource/csource.go
@@ -74,7 +74,8 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
generateTestFunc(w, opts, calls, "loop")
fmt.Fprint(w, "int main()\n{\n")
- fmt.Fprintf(w, "\tsetup_main_process();\n")
+ fmt.Fprintf(w, "\tinstall_segv_handler();\n")
+ fmt.Fprintf(w, "\tuse_temporary_dir();\n")
fmt.Fprintf(w, "\tint pid = do_sandbox_%v(0, %v);\n", opts.Sandbox, opts.EnableTun)
fmt.Fprint(w, "\tint status = 0;\n")
fmt.Fprint(w, "\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
@@ -83,7 +84,8 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
generateTestFunc(w, opts, calls, "test")
if opts.Procs <= 1 {
fmt.Fprint(w, "int main()\n{\n")
- fmt.Fprintf(w, "\tsetup_main_process();\n")
+ fmt.Fprintf(w, "\tinstall_segv_handler();\n")
+ fmt.Fprintf(w, "\tuse_temporary_dir();\n")
fmt.Fprintf(w, "\tint pid = do_sandbox_%v(0, %v);\n", opts.Sandbox, opts.EnableTun)
fmt.Fprint(w, "\tint status = 0;\n")
fmt.Fprint(w, "\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")
@@ -93,7 +95,8 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
fmt.Fprint(w, "\tint i;")
fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", opts.Procs)
fmt.Fprint(w, "\t\tif (fork() == 0) {\n")
- fmt.Fprintf(w, "\t\t\tsetup_main_process();\n")
+ fmt.Fprintf(w, "\t\t\tinstall_segv_handler();\n")
+ fmt.Fprintf(w, "\t\t\tuse_temporary_dir();\n")
fmt.Fprintf(w, "\t\t\tint pid = do_sandbox_%v(i, %v);\n", opts.Sandbox, opts.EnableTun)
fmt.Fprint(w, "\t\t\tint status = 0;\n")
fmt.Fprint(w, "\t\t\twhile (waitpid(pid, &status, __WALL) != pid) {}\n")