aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common_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/common_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/common_windows.h')
-rw-r--r--executor/common_windows.h94
1 files changed, 72 insertions, 22 deletions
diff --git a/executor/common_windows.h b/executor/common_windows.h
index d52092017..c4fdcd66f 100644
--- a/executor/common_windows.h
+++ b/executor/common_windows.h
@@ -5,26 +5,13 @@
#include <windows.h>
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) || \
- defined(SYZ_USE_TMP_DIR) || defined(SYZ_HANDLE_SEGV) || defined(SYZ_TUN_ENABLE) || \
- defined(SYZ_SANDBOX_NAMESPACE) || defined(SYZ_SANDBOX_SETUID) || \
- defined(SYZ_SANDBOX_NONE) || defined(SYZ_FAULT_INJECTION) || defined(__NR_syz_kvm_setup_cpu)
-__attribute__((noreturn)) static void doexit(int status)
-{
- _exit(status);
- for (;;) {
- }
-}
-#endif
-
#include "common.h"
-#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV)
+#if SYZ_EXECUTOR || SYZ_HANDLE_SEGV
static void install_segv_handler()
{
}
-// TODO(dvyukov): implement me
#define NONFAILING(...) \
__try { \
__VA_ARGS__; \
@@ -32,28 +19,91 @@ static void install_segv_handler()
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
-static uint64 current_time_ms()
+#if SYZ_EXECUTOR || SYZ_REPEAT
+uint64 current_time_ms()
{
return GetTickCount64();
}
#endif
-#if defined(SYZ_EXECUTOR)
+#if SYZ_EXECUTOR || SYZ_THREADED || SYZ_REPEAT
static void sleep_ms(uint64 ms)
{
Sleep(ms);
}
#endif
-#if defined(SYZ_EXECUTOR) || defined(SYZ_FAULT_INJECTION)
-static int inject_fault(int nth)
+#if SYZ_EXECUTOR || SYZ_THREADED
+static void thread_start(void* (*fn)(void*), void* arg)
+{
+ HANDLE th = CreateThread(NULL, 128 << 10, (LPTHREAD_START_ROUTINE)fn, arg, 0, NULL);
+ if (th == NULL)
+ exitf("CreateThread failed");
+}
+
+struct event_t {
+ CRITICAL_SECTION cs;
+ CONDITION_VARIABLE cv;
+ int state;
+};
+
+static void event_init(event_t* ev)
+{
+ InitializeCriticalSection(&ev->cs);
+ InitializeConditionVariable(&ev->cv);
+ ev->state = 0;
+}
+
+static void event_reset(event_t* ev)
{
- return 0;
+ ev->state = 0;
}
-static int fault_injected(int fail_fd)
+static void event_set(event_t* ev)
{
- return 0;
+ EnterCriticalSection(&ev->cs);
+ if (ev->state)
+ fail("event already set");
+ ev->state = 1;
+ LeaveCriticalSection(&ev->cs);
+ WakeAllConditionVariable(&ev->cv);
+}
+
+static void event_wait(event_t* ev)
+{
+ EnterCriticalSection(&ev->cs);
+ while (!ev->state)
+ SleepConditionVariableCS(&ev->cv, &ev->cs, INFINITE);
+ LeaveCriticalSection(&ev->cs);
+}
+
+static int event_isset(event_t* ev)
+{
+ EnterCriticalSection(&ev->cs);
+ int res = ev->state;
+ LeaveCriticalSection(&ev->cs);
+ return res;
+}
+
+static int event_timedwait(event_t* ev, uint64 timeout_ms)
+{
+ 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));
+ }
+ int res = ev->state;
+ LeaveCriticalSection(&ev->cs);
+ return res;
}
#endif
+
+#define setup_loop()
+#define reset_loop()
+#define setup_test()
+#define reset_test()