From af442a22d956464e7df703b290fa49d78dda3dfa Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 24 Sep 2017 11:13:37 +0200 Subject: executor, sys/windows: initial windows support --- pkg/ast/scanner.go | 3 ++ pkg/csource/common.go | 113 +++++++++++++++++++++++--------------------- pkg/csource/csource_test.go | 6 ++- 3 files changed, 66 insertions(+), 56 deletions(-) (limited to 'pkg') diff --git a/pkg/ast/scanner.go b/pkg/ast/scanner.go index 8a15dd8f9..bd2171506 100644 --- a/pkg/ast/scanner.go +++ b/pkg/ast/scanner.go @@ -241,6 +241,9 @@ func (s *scanner) Ok() bool { func (s *scanner) next() { s.off++ + for s.off < len(s.data) && s.data[s.off] == '\r' { + s.off++ + } if s.off == len(s.data) { // Always emit NEWLINE before EOF. // Makes lots of things simpler as we always diff --git a/pkg/csource/common.go b/pkg/csource/common.go index 588a0cd45..c38f805da 100644 --- a/pkg/csource/common.go +++ b/pkg/csource/common.go @@ -10,6 +10,19 @@ var commonHeader = ` #include #include +#if defined(SYZ_EXECUTOR) || defined(SYZ_THREADED) || defined(SYZ_COLLIDE) +#include +#include +#endif +#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) +#include +#include +#include +#include +#include +#include +#include +#endif #if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) #include #endif @@ -103,6 +116,7 @@ __attribute__((noreturn)) static void doexit(int status) for (i = 0;; i++) { } } +#define NORETURN __attribute__((noreturn)) #endif #if defined(SYZ_EXECUTOR) @@ -114,10 +128,6 @@ __attribute__((noreturn)) static void doexit(int status) #include #include -#if defined(SYZ_EXECUTOR) || defined(SYZ_THREADED) || defined(SYZ_COLLIDE) -#include -#include -#endif #if defined(SYZ_EXECUTOR) || defined(SYZ_USE_TMP_DIR) #include #include @@ -130,15 +140,6 @@ __attribute__((noreturn)) static void doexit(int status) #include #include #endif -#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) -#include -#include -#include -#include -#include -#include -#include -#endif #if defined(SYZ_EXECUTOR) || defined(SYZ_DEBUG) #include #include @@ -171,7 +172,7 @@ const int kErrorStatus = 68; #if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) || \ defined(SYZ_USE_TMP_DIR) || defined(SYZ_TUN_ENABLE) || defined(SYZ_SANDBOX_NAMESPACE) || \ defined(SYZ_SANDBOX_SETUID) || defined(SYZ_FAULT_INJECTION) || defined(__NR_syz_kvm_setup_cpu) -__attribute__((noreturn)) static void fail(const char* msg, ...) +NORETURN static void fail(const char* msg, ...) { int e = errno; fflush(stdout); @@ -185,7 +186,7 @@ __attribute__((noreturn)) static void fail(const char* msg, ...) #endif #if defined(SYZ_EXECUTOR) -__attribute__((noreturn)) static void error(const char* msg, ...) +NORETURN static void error(const char* msg, ...) { fflush(stdout); va_list args; @@ -198,7 +199,7 @@ __attribute__((noreturn)) static void error(const char* msg, ...) #endif #if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) -__attribute__((noreturn)) static void exitf(const char* msg, ...) +NORETURN static void exitf(const char* msg, ...) { int e = errno; fflush(stdout); @@ -242,35 +243,6 @@ static void debug(const char* msg, ...) } #endif -#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV) -static __thread int skip_segv; -static __thread jmp_buf segv_env; - -static void segv_handler(int sig, siginfo_t* info, void* uctx) -{ - uintptr_t addr = (uintptr_t)info->si_addr; - const uintptr_t prog_start = 1 << 20; - const uintptr_t prog_end = 100 << 20; - if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { - debug("SIGSEGV on %p, skipping\n", addr); - _longjmp(segv_env, 1); - } - debug("SIGSEGV on %p, exiting\n", addr); - doexit(sig); - for (;;) { - } -} - -#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); \ - } -#endif - #if defined(SYZ_EXECUTOR) || defined(SYZ_USE_CHECKSUMS) struct csum_inet { uint32_t acc; @@ -302,19 +274,25 @@ static uint16_t csum_inet_digest(struct csum_inet* csum) return ~csum->acc; } #endif +#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV) +static __thread int skip_segv; +static __thread jmp_buf segv_env; -#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) -static uint64_t current_time_ms() +static void segv_handler(int sig, siginfo_t* info, void* uctx) { - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts)) - fail("clock_gettime failed"); - return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; + uintptr_t addr = (uintptr_t)info->si_addr; + const uintptr_t prog_start = 1 << 20; + const uintptr_t prog_end = 100 << 20; + if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { + debug("SIGSEGV on %p, skipping\n", addr); + _longjmp(segv_env, 1); + } + debug("SIGSEGV on %p, exiting\n", addr); + doexit(sig); + for (;;) { + } } -#endif -#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV) static void install_segv_handler() { struct sigaction sa; @@ -330,6 +308,33 @@ static void install_segv_handler() sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } + +#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); \ + } +#endif + +#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) +static uint64_t current_time_ms() +{ + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts)) + fail("clock_gettime failed"); + return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; +} +#endif + +#if defined(SYZ_EXECUTOR) +static void sleep_ms(uint64_t ms) +{ + usleep(ms * 1000); +} #endif #if defined(SYZ_EXECUTOR) || defined(SYZ_USE_TMP_DIR) diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go index fac64be82..6334c40bf 100644 --- a/pkg/csource/csource_test.go +++ b/pkg/csource/csource_test.go @@ -101,8 +101,10 @@ func TestOne(t *testing.T) { } for _, target := range prog.AllTargets() { if target.OS == "fuchsia" { - // TODO(dvyukov): support fuchsia - continue + continue // TODO(dvyukov): support fuchsia + } + if target.OS == "windows" { + continue // TODO(dvyukov): support windows } target := target t.Run(target.OS+"/"+target.Arch, func(t *testing.T) { -- cgit mrf-deployment