aboutsummaryrefslogtreecommitdiffstats
path: root/executor/executor_windows.h
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-07-20 20:26:05 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-07-24 12:04:27 +0200
commit9fe4bdc5f1037a409e82299f36117030114c7b94 (patch)
treed3d73c1f69ded8152436be47684a07baa0e7f6ec /executor/executor_windows.h
parentdb7957bc09bf5715d33e4c56b8614579aa94000a (diff)
executor: overhaul
Make as much code as possible shared between all OSes. In particular main is now common across all OSes. Make more code shared between executor and csource (in particular, loop function and threaded execution logic). Also make loop and threaded logic shared across all OSes. Make more posix/unix code shared across OSes (e.g. signal handling, pthread creation, etc). Plus other changes along similar lines. Also support test OS in executor (based on portable posix) and add 4 arches that cover all execution modes (fork server/no fork server, shmem/no shmem). This change paves way for testing of executor code and allows to preserve consistency across OSes and executor/csource.
Diffstat (limited to 'executor/executor_windows.h')
-rw-r--r--executor/executor_windows.h72
1 files changed, 10 insertions, 62 deletions
diff --git a/executor/executor_windows.h b/executor/executor_windows.h
index b29095011..a6159fb44 100644
--- a/executor/executor_windows.h
+++ b/executor/executor_windows.h
@@ -1,74 +1,22 @@
// Copyright 2017 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.
+#include <io.h>
#include <windows.h>
-typedef HANDLE osthread_t;
+#include "nocover.h"
-void thread_start(osthread_t* t, void* (*fn)(void*), void* arg)
+static void os_init(int argc, char** argv, void* data, size_t data_size)
{
- *t = CreateThread(NULL, 128 << 10, (LPTHREAD_START_ROUTINE)fn, arg, 0, NULL);
- if (*t == NULL)
- exitf("CreateThread failed");
+ if (VirtualAlloc(data, data_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE) != data)
+ fail("mmap of data segment failed");
}
-struct event_t {
- CRITICAL_SECTION cs;
- CONDITION_VARIABLE cv;
- int state;
-};
-
-void event_init(event_t* ev)
-{
- InitializeCriticalSection(&ev->cs);
- InitializeConditionVariable(&ev->cv);
- ev->state = 0;
-}
-
-void event_reset(event_t* ev)
-{
- ev->state = 0;
-}
-
-void event_set(event_t* ev)
-{
- EnterCriticalSection(&ev->cs);
- if (ev->state)
- fail("event already set");
- ev->state = true;
- LeaveCriticalSection(&ev->cs);
- WakeAllConditionVariable(&ev->cv);
-}
-
-void event_wait(event_t* ev)
-{
- EnterCriticalSection(&ev->cs);
- while (!ev->state)
- SleepConditionVariableCS(&ev->cv, &ev->cs, INFINITE);
- LeaveCriticalSection(&ev->cs);
-}
-
-bool event_isset(event_t* ev)
-{
- EnterCriticalSection(&ev->cs);
- bool res = ev->state;
- LeaveCriticalSection(&ev->cs);
- return res;
-}
-
-bool event_timedwait(event_t* ev, uint64 timeout_ms)
+static long execute_syscall(const call_t* c, long a[kMaxArgs])
{
- EnterCriticalSection(&ev->cs);
- uint64 start = current_time_ms();
- for (;;) {
- if (ev->state)
- break;
- uint64 now = current_time_ms();
- if (now - start > timeout_ms)
- break;
- SleepConditionVariableCS(&ev->cv, &ev->cs, timeout_ms - (now - start));
+ __try {
+ return c->call(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
+ } __except (EXCEPTION_EXECUTE_HANDLER) {
+ return -1;
}
- bool res = ev->state;
- LeaveCriticalSection(&ev->cs);
- return res;
}