aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/csource
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-10-16 12:18:50 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-10-16 14:21:54 +0200
commit85b1f93f8dbbc767c564e494a6353aa3517d5d49 (patch)
tree702d2318a2ddcf1a576294a6a4981c58abcfcf61 /pkg/csource
parentf78642861b4dbe396a67d5e2a750e22f83f3edd5 (diff)
executor, pkg/ipc: unify ipc protocol between linux and other OSes
We currently use more complex and functional protocol on linux, and a simple ad-hoc protocol on other OSes. This leads to code duplication in both ipc and executor. Linux supports coverage, shared memory communication and fork server, which would also be useful for most other OSes. Unify communication protocol and parametrize it by (1) use of shmem or only pipes, (2) use of fork server. This reduces duplication in ipc and executor and will allow to support the useful features for other OSes easily. Finally, this fixes akaros support as it currently uses syz-stress running on host (linux) and executor running on akaros.
Diffstat (limited to 'pkg/csource')
-rw-r--r--pkg/csource/akaros_common.go14
-rw-r--r--pkg/csource/csource.go1
-rw-r--r--pkg/csource/linux_common.go14
3 files changed, 17 insertions, 12 deletions
diff --git a/pkg/csource/akaros_common.go b/pkg/csource/akaros_common.go
index a02f0834c..74e7e310b 100644
--- a/pkg/csource/akaros_common.go
+++ b/pkg/csource/akaros_common.go
@@ -31,7 +31,6 @@ var commonHeaderAkaros = `
#endif
#define doexit exit
-#define NORETURN __attribute__((noreturn))
@@ -55,8 +54,14 @@ var commonHeaderAkaros = `
#endif
#if defined(SYZ_EXECUTOR)
-#ifndef SYSCALLAPI
+#if defined(__GNUC__)
#define SYSCALLAPI
+#define NORETURN __attribute__((noreturn))
+#define ALIGNED(N) __attribute__((aligned(N)))
+#else
+#define SYSCALLAPI WINAPI
+#define NORETURN __declspec(noreturn)
+#define ALIGNED(N) __declspec(align(N))
#endif
typedef long(SYSCALLAPI* syscall_t)(long, long, long, long, long, long, long, long, long);
@@ -88,7 +93,6 @@ const int kErrorStatus = 68;
NORETURN static void fail(const char* msg, ...)
{
int e = errno;
- fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
@@ -101,7 +105,6 @@ NORETURN static void fail(const char* msg, ...)
#if defined(SYZ_EXECUTOR)
NORETURN static void error(const char* msg, ...)
{
- fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
@@ -111,11 +114,10 @@ NORETURN static void error(const char* msg, ...)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT) && defined(SYZ_USE_TMP_DIR))
NORETURN static void exitf(const char* msg, ...)
{
int e = errno;
- fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index 1bc1ec5ba..6d06f101d 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -190,6 +190,7 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
re = regexp.MustCompile(`\t*debug_dump_data\(.*\);\n`)
out0 = re.ReplaceAllString(out0, "")
}
+ out0 = strings.Replace(out0, "NORETURN", "", -1)
// Remove duplicate new lines.
out1 := []byte(out0)
diff --git a/pkg/csource/linux_common.go b/pkg/csource/linux_common.go
index b86424ff9..acc1647e4 100644
--- a/pkg/csource/linux_common.go
+++ b/pkg/csource/linux_common.go
@@ -117,7 +117,6 @@ __attribute__((noreturn)) static void doexit(int status)
for (i = 0;; i++) {
}
}
-#define NORETURN __attribute__((noreturn))
#endif
#if defined(SYZ_EXECUTOR)
@@ -147,8 +146,14 @@ __attribute__((noreturn)) static void doexit(int status)
#endif
#if defined(SYZ_EXECUTOR)
-#ifndef SYSCALLAPI
+#if defined(__GNUC__)
#define SYSCALLAPI
+#define NORETURN __attribute__((noreturn))
+#define ALIGNED(N) __attribute__((aligned(N)))
+#else
+#define SYSCALLAPI WINAPI
+#define NORETURN __declspec(noreturn)
+#define ALIGNED(N) __declspec(align(N))
#endif
typedef long(SYSCALLAPI* syscall_t)(long, long, long, long, long, long, long, long, long);
@@ -180,7 +185,6 @@ const int kErrorStatus = 68;
NORETURN static void fail(const char* msg, ...)
{
int e = errno;
- fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
@@ -193,7 +197,6 @@ NORETURN static void fail(const char* msg, ...)
#if defined(SYZ_EXECUTOR)
NORETURN static void error(const char* msg, ...)
{
- fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
@@ -203,11 +206,10 @@ NORETURN static void error(const char* msg, ...)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT) && defined(SYZ_USE_TMP_DIR))
NORETURN static void exitf(const char* msg, ...)
{
int e = errno;
- fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);