diff --git a/include-hax/fake_masm/macamd64.inc b/include-hax/fake_masm/macamd64.inc new file mode 100644 index 0000000000..970487f4dc --- /dev/null +++ b/include-hax/fake_masm/macamd64.inc @@ -0,0 +1,9 @@ +push_reg macro Reg + push Reg + .pushreg Reg + endm + +alloc_stack macro Size + sub rsp, Size + .allocstack Size + endm diff --git a/src/include/nacl_compiler_annotations.h b/src/include/nacl_compiler_annotations.h index c9baad67b7..b8e46d2f26 100644 --- a/src/include/nacl_compiler_annotations.h +++ b/src/include/nacl_compiler_annotations.h @@ -10,7 +10,7 @@ #include "native_client/src/include/build_config.h" /* MSVC supports "inline" only in C++ */ -#if NACL_WINDOWS +#if defined(_MSC_VER) # define INLINE __forceinline #else # define INLINE __inline__ diff --git a/src/include/portability.h b/src/include/portability.h index d0360ebfa9..42aab4d5a5 100644 --- a/src/include/portability.h +++ b/src/include/portability.h @@ -16,6 +16,7 @@ #ifndef NATIVE_CLIENT_SRC_INCLUDE_PORTABILITY_H_ #define NATIVE_CLIENT_SRC_INCLUDE_PORTABILITY_H_ 1 +#include #include #include "native_client/src/include/build_config.h" @@ -30,7 +31,9 @@ #if NACL_WINDOWS /* disable warnings for deprecated functions like getenv, etc. */ +#if defined(_MSC_VER) #pragma warning(disable : 4996) +#endif # include /* TODO: eliminate port_win.h */ # include "native_client/src/include/win/port_win.h" @@ -59,7 +62,7 @@ #define GG_UINT32_C(x) (x ## U) #define GG_UINT64_C(x) GG_ULONGLONG(x) -#if NACL_WINDOWS +#if NACL_WINDOWS && defined(_MSC_VER) #define GG_LONGLONG(x) x##I64 #define GG_ULONGLONG(x) x##UI64 #else diff --git a/src/include/portability_io.h b/src/include/portability_io.h index 75eedbf12d..8abafd023f 100644 --- a/src/include/portability_io.h +++ b/src/include/portability_io.h @@ -17,7 +17,9 @@ #if NACL_WINDOWS /* disable warnings for deprecated _snprintf */ +#if defined(_MSC_VER) #pragma warning(disable : 4996) +#endif #include #include @@ -43,7 +45,9 @@ /* missing from win stdio.h and fcntl.h */ /* from bits/fcntl.h */ +#if defined(_MSC_VER) #define O_ACCMODE 0003 +#endif #else diff --git a/src/include/portability_string.h b/src/include/portability_string.h index 9b86ead994..1c49954770 100644 --- a/src/include/portability_string.h +++ b/src/include/portability_string.h @@ -53,7 +53,9 @@ size_t strnlen(const char* str, size_t max); #if NACL_WINDOWS /* disable warnings for deprecated strncpy */ +#if defined(_MSC_VER) #pragma warning(disable : 4996) +#endif #define STRDUP _strdup #define STRTOLL _strtoi64 diff --git a/src/include/win/port_win.h b/src/include/win/port_win.h index 790a8fe3e8..8130db69c2 100644 --- a/src/include/win/port_win.h +++ b/src/include/win/port_win.h @@ -38,6 +38,7 @@ /* TODO: eliminated this file and move its contents to portability*.h */ +#if defined(_MSC_VER) /* wchar_t and unsigned short are not always equivalent*/ #pragma warning(disable : 4255) /* padding added after struct member */ @@ -46,6 +47,7 @@ #pragma warning(disable: 4826) /* conditional expression is constant */ #pragma warning(disable : 4127) +#endif /* TODO: limit this include to files that really need it */ #ifndef NOMINMAX @@ -74,7 +76,9 @@ typedef __int64_t int64_t; typedef __uint64_t uint64_t; typedef long off_t; +#if defined(_MSC_VER) typedef int mode_t; +#endif typedef long _off_t; typedef long int __loff_t; typedef unsigned long DWORD; @@ -94,7 +98,7 @@ typedef int32_t ssize_t; * * Only including range values actually used in our codebase. */ -#if _MSC_VER >= 1800 +#if !defined(_MSC_VER) || _MSC_VER >= 1800 #include #else # if !defined(UINT8_MAX) @@ -160,6 +164,8 @@ EXTERN_C_END /* from linux/limits.h, via sys/param.h */ +#if defined(_MSC_VER) #define PATH_MAX 4096 +#endif #endif /* NATIVE_CLIENT_SRC_INCLUDE_WIN_PORT_WIN_H_ */ diff --git a/src/shared/platform/win/lock_impl.h b/src/shared/platform/win/lock_impl.h index cb5f98b8d3..9024ea3a06 100644 --- a/src/shared/platform/win/lock_impl.h +++ b/src/shared/platform/win/lock_impl.h @@ -8,7 +8,7 @@ #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_WIN_LOCK_IMPL_H_ #define NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_WIN_LOCK_IMPL_H_ -#include +#include #include "native_client/src/include/nacl_macros.h" #include "native_client/src/shared/platform/nacl_sync.h" diff --git a/src/shared/platform/win/nacl_exit.c b/src/shared/platform/win/nacl_exit.c index a190175ff5..17c7741d89 100644 --- a/src/shared/platform/win/nacl_exit.c +++ b/src/shared/platform/win/nacl_exit.c @@ -39,7 +39,11 @@ void NaClAbort(void) { * http://code.google.com/p/nativeclient/issues/detail?id=2772). */ while (1) { +#if defined(_MSC_VER) __halt(); +#else + __asm__("hlt"); +#endif } } diff --git a/src/shared/platform/win/port_win.c b/src/shared/platform/win/port_win.c index 2f303ff10a..d743bd1c49 100644 --- a/src/shared/platform/win/port_win.c +++ b/src/shared/platform/win/port_win.c @@ -12,7 +12,7 @@ #include "native_client/src/include/portability.h" -#if ( DO_NOT_USE_FAST_ASSEMBLER_VERSION_FOR_FFS || defined(_WIN64) ) +#if ( DO_NOT_USE_FAST_ASSEMBLER_VERSION_FOR_FFS || defined(_WIN64) || !defined(_MSC_VER) ) int ffs(int x) { int r = 1; diff --git a/src/shared/platform/win/xlate_system_error.c b/src/shared/platform/win/xlate_system_error.c index cfaca7c266..b9d51f34fd 100644 --- a/src/shared/platform/win/xlate_system_error.c +++ b/src/shared/platform/win/xlate_system_error.c @@ -9,7 +9,7 @@ */ #include -#include +#include #include "native_client/src/shared/platform/nacl_log.h" #include "native_client/src/shared/platform/win/xlate_system_error.h" diff --git a/src/trusted/fault_injection/fault_injection.c b/src/trusted/fault_injection/fault_injection.c index 3d71f5f7b2..2fa29c35d9 100644 --- a/src/trusted/fault_injection/fault_injection.c +++ b/src/trusted/fault_injection/fault_injection.c @@ -66,6 +66,8 @@ */ # define NACL_HAS_STRNDUP 0 /* could use TLS if not built into a DLL, otherwise must use TLSALLOC */ +# define NACL_USE_TLS 0 +# define NACL_USE_TSD 0 # define NACL_USE_TLSALLOC 1 # include #endif diff --git a/src/trusted/platform_qualify/arch/x86/vcpuid.c b/src/trusted/platform_qualify/arch/x86/vcpuid.c index dbefa9b11c..a5ec005d4b 100644 --- a/src/trusted/platform_qualify/arch/x86/vcpuid.c +++ b/src/trusted/platform_qualify/arch/x86/vcpuid.c @@ -38,7 +38,15 @@ const int kMagicConst_ROUNDSS = 0xc0000000; const int kMagicConst_POPCNT = 13; const int kMagicConst_CRC32 = 0xb906c3ea; -#if !(NACL_WINDOWS && (NACL_BUILD_SUBARCH == 64)) +#if (NACL_WINDOWS && defined(_MSC_VER) && (NACL_BUILD_SUBARCH == 64)) +# define NACL_WINDOWS_MSC_64 +#endif + +#if (NACL_WINDOWS && !defined(_MSC_VER)) +# define NACL_WINDOWS_MINGW +#endif + +#if !defined(NACL_WINDOWS_MSC_64) static int asm_HasMMX(void) { volatile int before, after; before = kMagicConst; @@ -386,20 +394,34 @@ static int asm_HasCX8(void) { #endif /* 0 */ #endif /* 64-bit Windows */ -#if NACL_WINDOWS && (NACL_BUILD_SUBARCH == 64) +#if defined(NACL_WINDOWS_MSC_64) static int CheckCPUFeatureDetection(NaClCPUFeaturesX86 *cpuf) { /* Unfortunately the asm_ tests will not work on 64-bit Windows */ return 0; } #else -#if (NACL_LINUX || NACL_OSX) +#if (NACL_LINUX || NACL_OSX || defined(NACL_WINDOWS_MINGW)) /* Linux/MacOS signal handling code, for trapping illegal instruction faults */ static int sawbadinstruction = 0; -static struct sigaction crash_detect; static int signum; -sigjmp_buf crash_load; +#if defined(NACL_WINDOWS_MINGW) +static PVOID crash_handler; +static jmp_buf crash_load; +#else +static struct sigaction crash_detect; +static sigjmp_buf crash_load; +#endif +#if defined(NACL_WINDOWS_MINGW) +static LONG CALLBACK handler_load(EXCEPTION_POINTERS *ep) +{ + if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) { + longjmp(crash_load, SIGILL); + } + return EXCEPTION_CONTINUE_SEARCH; +} +#else void handler_load(int signal_num) { siglongjmp(crash_load, signal_num); } @@ -427,13 +449,18 @@ void all_sigs(struct sigaction *new_action, (void) sigaction(SIGCHLD, &ign, 0); (void) sigaction(SIGTSTP, &ign, 0); } +#endif static void SignalInit(void) { sawbadinstruction = 0; +#if defined(NACL_WINDOWS_MINGW) + crash_handler = AddVectoredExceptionHandler(1, handler_load); +#else crash_detect.sa_handler = handler_load; sigemptyset(&crash_detect.sa_mask); crash_detect.sa_flags = SA_RESETHAND; all_sigs(&crash_detect, 0); +#endif } static void SetSawBadInst(void) { @@ -450,7 +477,13 @@ static int SawBadInst(void) { */ static int DoTest(int (*thetest)(void), const char *s) { SignalInit(); - if (0 != (signum = sigsetjmp(crash_load, 1))) { + +#if defined(NACL_WINDOWS_MINGW) + signum = setjmp(crash_load); +#else + signum = sigsetjmp(crash_load, 1); +#endif + if (0 != signum) { SetSawBadInst(); if (SIGILL == signum) { fprintf(stderr, "%s: illegal instruction\n", s); @@ -462,10 +495,16 @@ static int DoTest(int (*thetest)(void), const char *s) { int hasfeature = thetest(); if (hasfeature && (! SawBadInst())) { printf("[Has %s]\n", s); +#if defined(NACL_WINDOWS_MINGW) + RemoveVectoredExceptionHandler(crash_handler); +#endif return 0; } } printf("no %s\n", s); +#if defined(NACL_WINDOWS_MINGW) + RemoveVectoredExceptionHandler(crash_handler); +#endif return 1; } #elif NACL_WINDOWS diff --git a/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c b/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c index 5757b6c904..15d543639e 100644 --- a/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c +++ b/src/trusted/service_runtime/arch/x86_32/sel_rt_32.c @@ -90,7 +90,7 @@ int NaClAppThreadInitArchSpecific(struct NaClAppThread *natp, * Save the system's state of the x87 FPU control word so we can restore * the same state when returning to trusted code. */ -#if NACL_WINDOWS +#if defined(_MSC_VER) { uint16_t sys_fcw; __asm { diff --git a/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm b/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm index d5dd93a9a1..6ead09486a 100644 --- a/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm +++ b/src/trusted/service_runtime/arch/x86_64/nacl_switch_unwind_win.asm @@ -2,7 +2,7 @@ ; Use of this source code is governed by a BSD-style license that can be ; found in the LICENSE file. -include ksamd64.inc +include macamd64.inc EXTERN NaClSwitch : QWORD diff --git a/src/trusted/service_runtime/nacl_signal.h b/src/trusted/service_runtime/nacl_signal.h index e3a8fa1732..2301ed407e 100644 --- a/src/trusted/service_runtime/nacl_signal.h +++ b/src/trusted/service_runtime/nacl_signal.h @@ -58,7 +58,7 @@ struct NaClExceptionFrame; #define NACL_ABI_WIFSIGNALED(status) ((((status) + 1) & 0x7f) > 1) #define NACL_ABI_W_EXITCODE(ret, sig) ((((ret) & 0xff) << 8) + ((sig) & 0x7f)) -#if NACL_WINDOWS +#if NACL_WINDOWS && defined(_MSC_VER) enum PosixSignals { SIGINT = 2, SIGQUIT = 3, diff --git a/src/trusted/service_runtime/sel_ldr.c b/src/trusted/service_runtime/sel_ldr.c index 4dbc7611cb..7bcf97c210 100644 --- a/src/trusted/service_runtime/sel_ldr.c +++ b/src/trusted/service_runtime/sel_ldr.c @@ -912,7 +912,7 @@ void NaClVmIoPendingCheck_mu(struct NaClApp *nap, * We need its symbol in the symbol table so don't inline it. * TODO(dje): add some explanation for the non-GDB person. */ -#if NACL_WINDOWS +#if NACL_WINDOWS && defined(_MSVC_VER) __declspec(dllexport noinline) #endif #ifdef __GNUC__ diff --git a/src/trusted/validator/validation_cache.c b/src/trusted/validator/validation_cache.c index b9d9536bb7..f8ce53e9ef 100644 --- a/src/trusted/validator/validation_cache.c +++ b/src/trusted/validator/validation_cache.c @@ -21,7 +21,7 @@ #include "native_client/src/trusted/validator/validation_metadata.h" #if NACL_WINDOWS -#include +#include #include #endif diff --git a/src/trusted/validator_ragel/bitmap.h b/src/trusted/validator_ragel/bitmap.h index dec2a0d2cb..798e392b72 100644 --- a/src/trusted/validator_ragel/bitmap.h +++ b/src/trusted/validator_ragel/bitmap.h @@ -15,7 +15,7 @@ #include "native_client/src/include/nacl_macros.h" #include "native_client/src/include/portability.h" -#if NACL_WINDOWS +#if defined(_MSC_VER) # define FORCEINLINE __forceinline #else # define FORCEINLINE __inline __attribute__ ((always_inline)) diff --git a/src/trusted/validator_ragel/decoding.h b/src/trusted/validator_ragel/decoding.h index 64087b7621..51a781d14e 100644 --- a/src/trusted/validator_ragel/decoding.h +++ b/src/trusted/validator_ragel/decoding.h @@ -19,7 +19,7 @@ #include "native_client/src/include/build_config.h" #include "native_client/src/trusted/validator_ragel/decoder.h" -#if NACL_WINDOWS +#if defined(_MSC_VER) # define FORCEINLINE __forceinline #else # define FORCEINLINE __inline __attribute__ ((always_inline))