aboutsummaryrefslogtreecommitdiffstats
path: root/executor/executor_akaros.cc
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 /executor/executor_akaros.cc
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 'executor/executor_akaros.cc')
-rw-r--r--executor/executor_akaros.cc66
1 files changed, 14 insertions, 52 deletions
diff --git a/executor/executor_akaros.cc b/executor/executor_akaros.cc
index 15eafba71..e7d828a40 100644
--- a/executor/executor_akaros.cc
+++ b/executor/executor_akaros.cc
@@ -3,6 +3,9 @@
// +build
+// https://github.com/brho/akaros/issues/41
+#define DUP2_BROKEN
+
#define SYZ_EXECUTOR
#include "common_akaros.h"
@@ -12,83 +15,42 @@
#include "syscalls_akaros.h"
-char input_buffer[kMaxInput];
uint32_t output;
-struct in_header {
- uint64_t magic;
- uint64_t flags;
- uint64_t pid;
- uint64_t progSize;
- uint64_t execFlags;
- uint64_t prog[0];
-};
-
-struct out_header {
- uint64_t magic;
- uint64_t status;
-};
-
-const uint64_t kInMagic = 0xbadc0ffee;
-const uint64_t kOutMagic = 0xbadf00d;
-
int main(int argc, char** argv)
{
if (argc == 2 && strcmp(argv[1], "version") == 0) {
- puts("akaros " GOARCH " " SYZ_REVISION " " GIT_REVISION);
+ puts(GOOS " " GOARCH " " SYZ_REVISION " " GIT_REVISION);
return 0;
}
use_temporary_dir();
install_segv_handler();
+ setup_control_pipes();
+ receive_handshake();
+ reply_handshake();
+
for (;;) {
- size_t pos = 0;
- in_header* hdr = (in_header*)input_buffer;
- for (;;) {
- int rv = read(0, input_buffer + pos, sizeof(input_buffer) - pos);
- if (rv < 0)
- fail("read failed");
- if (rv == 0)
- fail("stdin closed, read %d", (int)pos);
- pos += rv;
- if (pos > sizeof(in_header)) {
- if (hdr->magic != kInMagic)
- fail("bad header magic 0x%llx", hdr->magic);
- if (pos > sizeof(in_header) + hdr->progSize)
- fail("excessive input data");
- if (pos == sizeof(in_header) + hdr->progSize)
- break;
- }
- }
- flag_debug = hdr->flags & (1 << 0);
- flag_threaded = hdr->flags & (1 << 2);
- flag_collide = hdr->flags & (1 << 3);
- if (!flag_threaded)
- flag_collide = false;
- debug("input %d, threaded=%d collide=%d pid=%llu\n",
- pos, flag_threaded, flag_collide, hdr->pid);
+ receive_execute();
char cwdbuf[128] = "/syz-tmpXXXXXX";
mkdtemp(cwdbuf);
int pid = fork();
if (pid < 0)
fail("fork failed");
if (pid == 0) {
- close(0);
- dup2(2, 1);
+ close(kInPipeFd);
+ close(kOutPipeFd);
if (chdir(cwdbuf))
fail("chdir failed");
- execute_one(hdr->prog);
+ execute_one();
doexit(0);
}
+ // TODO: timeout.
int status = 0;
while (waitpid(pid, &status, 0) != pid) {
}
remove_dir(cwdbuf);
- out_header out;
- out.magic = kOutMagic;
- out.status = 0;
- if (write(1, &out, sizeof(out)) != sizeof(out))
- fail("stdout write failed");
+ reply_execute(0);
}
return 0;
}