From 9b91ede8607ae78572fef7aed01f1afe3a033928 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 28 Aug 2016 14:59:48 +0200 Subject: executor, csource: share some common code between executor and csource --- csource/csource.go | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) (limited to 'csource') diff --git a/csource/csource.go b/csource/csource.go index 1c59d5e8a..214483c5d 100644 --- a/csource/csource.go +++ b/csource/csource.go @@ -1,6 +1,8 @@ // Copyright 2015 syzkaller project authors. All rights reserved. // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. +//go:generate bash -c "echo -e '// AUTOGENERATED FROM executor/common.h\npackage csource\nvar commonHeader = `' > common.go; cat ../executor/common.h | grep -v // >> common.go; echo '`' >> common.go" + package csource import ( @@ -25,32 +27,9 @@ func Write(p *prog.Prog, opts Options) []byte { exec := p.SerializeForExec() w := new(bytes.Buffer) - fmt.Fprintf(w, `// autogenerated by syzkaller (http://github.com/google/syzkaller) -#include -#include -#include -#include -#include -#include -#include -#include - -__thread int skip_segv; -__thread jmp_buf segv_env; - -void handle_segv(int sig, siginfo_t* info, void* uctx) -{ - if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED)) - _longjmp(segv_env, 1); - exit(sig); -} - -#define NONFAILING(...) { \ - __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ - if (_setjmp(segv_env) == 0) { __VA_ARGS__; } \ - __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); } \ - -`) + fmt.Fprint(w, "// autogenerated by syzkaller (http://github.com/google/syzkaller)\n") + fmt.Fprint(w, commonHeader) + fmt.Fprint(w, "\n") handled := make(map[string]bool) for _, c := range p.Calls { @@ -72,13 +51,7 @@ void handle_segv(int sig, siginfo_t* info, void* uctx) fmt.Fprint(w, ` int main() { - struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - sa.sa_sigaction = handle_segv; - sa.sa_flags = SA_NODEFER | SA_SIGINFO; - sigaction(SIGSEGV, &sa, NULL); - sigaction(SIGBUS, &sa, NULL); - + install_segv_handler(); memset(r, -1, sizeof(r)); `) for _, c := range calls { @@ -100,6 +73,7 @@ int main() fmt.Fprintf(w, "\tlong i;\n") fmt.Fprintf(w, "\tpthread_t th[%v];\n", len(calls)) fmt.Fprintf(w, "\n") + fmt.Fprintf(w, "install_segv_handler();\n") fmt.Fprintf(w, "\tmemset(r, -1, sizeof(r));\n") fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", len(calls)) fmt.Fprintf(w, "\t\tpthread_create(&th[i], 0, thr, (void*)i);\n") -- cgit mrf-deployment