From bdffe2484cfffefd2f3321cb42890be70887cf44 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 27 Sep 2017 11:44:15 +0200 Subject: executor: fix execution of windows syscalls First, they must be called with stdcall convention. Second, wrap them in __try/__except because they can crash. --- executor/common.h | 8 ++++++-- executor/common_windows.h | 1 + executor/executor_windows.cc | 11 ++++++----- pkg/csource/common.go | 7 ++++++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/executor/common.h b/executor/common.h index f5b525cc4..a283f7fbe 100644 --- a/executor/common.h +++ b/executor/common.h @@ -23,7 +23,11 @@ #endif #if defined(SYZ_EXECUTOR) -typedef long (*syscall_t)(long, long, long, long, long, long, long, long, long); +#ifndef SYSCALLAPI +#define SYSCALLAPI +#endif + +typedef long(SYSCALLAPI* syscall_t)(long, long, long, long, long, long, long, long, long); struct call_t { const char* name; @@ -156,4 +160,4 @@ static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } -#endif \ No newline at end of file +#endif diff --git a/executor/common_windows.h b/executor/common_windows.h index 80c197a4a..dbc6b67c3 100644 --- a/executor/common_windows.h +++ b/executor/common_windows.h @@ -7,6 +7,7 @@ #define doexit exit #define NORETURN +#define SYSCALLAPI WINAPI #include "common.h" diff --git a/executor/executor_windows.cc b/executor/executor_windows.cc index 7b30e1a96..862621951 100644 --- a/executor/executor_windows.cc +++ b/executor/executor_windows.cc @@ -52,10 +52,11 @@ int main(int argc, char** argv) long execute_syscall(call_t* c, long a0, long a1, long a2, long a3, long a4, long a5, long a6, long a7, long a8) { - debug("%s = %p\n", c->name, c->call); - long res = c->call(a0, a1, a2, a3, a4, a5, a6, a7, a8); - debug("%s = %ld\n", c->name, res); - return res; + __try { + return c->call(a0, a1, a2, a3, a4, a5, a6, a7, a8); + } __except (EXCEPTION_EXECUTE_HANDLER) { + return -1; + } } void cover_open() @@ -82,4 +83,4 @@ uint32_t* write_output(uint32_t v) void write_completed(uint32_t completed) { -} \ No newline at end of file +} diff --git a/pkg/csource/common.go b/pkg/csource/common.go index c38f805da..7f34a8753 100644 --- a/pkg/csource/common.go +++ b/pkg/csource/common.go @@ -146,7 +146,11 @@ __attribute__((noreturn)) static void doexit(int status) #endif #if defined(SYZ_EXECUTOR) -typedef long (*syscall_t)(long, long, long, long, long, long, long, long, long); +#ifndef SYSCALLAPI +#define SYSCALLAPI +#endif + +typedef long(SYSCALLAPI* syscall_t)(long, long, long, long, long, long, long, long, long); struct call_t { const char* name; @@ -274,6 +278,7 @@ 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; -- cgit mrf-deployment