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/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_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