aboutsummaryrefslogtreecommitdiffstats
path: root/csource
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-08-28 14:59:48 +0200
committerDmitry Vyukov <dvyukov@google.com>2016-08-28 14:59:48 +0200
commit9b91ede8607ae78572fef7aed01f1afe3a033928 (patch)
tree645c01454385dfbb9ee42c2e314b0a6edbaca594 /csource
parentf0eccc70522c2107f70d9ab6626924612b3da80d (diff)
executor, csource: share some common code between executor and csource
Diffstat (limited to 'csource')
-rw-r--r--csource/csource.go40
1 files changed, 7 insertions, 33 deletions
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 <unistd.h>
-#include <sys/syscall.h>
-#include <string.h>
-#include <stdint.h>
-#include <pthread.h>
-#include <stdlib.h>
-#include <setjmp.h>
-#include <signal.h>
-
-__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")