@@ -46,7 +46,7 @@ const int kMagicConst_CRC32 = 0xb906c3ea;
4646# define NACL_WINDOWS_MINGW
4747#endif
4848
49- #if !defined(NACL_WINDOWS_MSC_64 ) && !defined( NACL_WINDOWS_MINGW )
49+ #if !defined(NACL_WINDOWS_MSC_64 )
5050static int asm_HasMMX (void ) {
5151 volatile int before , after ;
5252 before = kMagicConst ;
@@ -394,20 +394,34 @@ static int asm_HasCX8(void) {
394394#endif /* 0 */
395395#endif /* 64-bit Windows */
396396
397- #if defined(NACL_WINDOWS_MSC_64 ) || defined( NACL_WINDOWS_MINGW )
397+ #if defined(NACL_WINDOWS_MSC_64 )
398398static int CheckCPUFeatureDetection (NaClCPUFeaturesX86 * cpuf ) {
399399 /* Unfortunately the asm_ tests will not work on 64-bit Windows */
400400 return 0 ;
401401}
402402#else
403- #if (NACL_LINUX || NACL_OSX )
403+ #if (NACL_LINUX || NACL_OSX || defined( NACL_WINDOWS_MINGW ) )
404404/* Linux/MacOS signal handling code, for trapping illegal instruction faults */
405405static int sawbadinstruction = 0 ;
406- static struct sigaction crash_detect ;
407406static int signum ;
408407
409- sigjmp_buf crash_load ;
408+ #if defined(NACL_WINDOWS_MINGW )
409+ static PVOID crash_handler ;
410+ static jmp_buf crash_load ;
411+ #else
412+ static struct sigaction crash_detect ;
413+ static sigjmp_buf crash_load ;
414+ #endif
410415
416+ #if defined(NACL_WINDOWS_MINGW )
417+ static LONG CALLBACK handler_load (EXCEPTION_POINTERS * ep )
418+ {
419+ if (ep -> ExceptionRecord -> ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION ) {
420+ longjmp (crash_load , SIGILL );
421+ }
422+ return EXCEPTION_CONTINUE_SEARCH ;
423+ }
424+ #else
411425void handler_load (int signal_num ) {
412426 siglongjmp (crash_load , signal_num );
413427}
@@ -435,13 +449,18 @@ void all_sigs(struct sigaction *new_action,
435449 (void ) sigaction (SIGCHLD , & ign , 0 );
436450 (void ) sigaction (SIGTSTP , & ign , 0 );
437451}
452+ #endif
438453
439454static void SignalInit (void ) {
440455 sawbadinstruction = 0 ;
456+ #if defined(NACL_WINDOWS_MINGW )
457+ crash_handler = AddVectoredExceptionHandler (1 , handler_load );
458+ #else
441459 crash_detect .sa_handler = handler_load ;
442460 sigemptyset (& crash_detect .sa_mask );
443461 crash_detect .sa_flags = SA_RESETHAND ;
444462 all_sigs (& crash_detect , 0 );
463+ #endif
445464}
446465
447466static void SetSawBadInst (void ) {
@@ -458,7 +477,13 @@ static int SawBadInst(void) {
458477 */
459478static int DoTest (int (* thetest )(void ), const char * s ) {
460479 SignalInit ();
461- if (0 != (signum = sigsetjmp (crash_load , 1 ))) {
480+
481+ #if defined(NACL_WINDOWS_MINGW )
482+ signum = setjmp (crash_load );
483+ #else
484+ signum = sigsetjmp (crash_load , 1 );
485+ #endif
486+ if (0 != signum ) {
462487 SetSawBadInst ();
463488 if (SIGILL == signum ) {
464489 fprintf (stderr , "%s: illegal instruction\n" , s );
@@ -470,10 +495,16 @@ static int DoTest(int (*thetest)(void), const char *s) {
470495 int hasfeature = thetest ();
471496 if (hasfeature && (! SawBadInst ())) {
472497 printf ("[Has %s]\n" , s );
498+ #if defined(NACL_WINDOWS_MINGW )
499+ RemoveVectoredExceptionHandler (crash_handler );
500+ #endif
473501 return 0 ;
474502 }
475503 }
476504 printf ("no %s\n" , s );
505+ #if defined(NACL_WINDOWS_MINGW )
506+ RemoveVectoredExceptionHandler (crash_handler );
507+ #endif
477508 return 1 ;
478509}
479510#elif NACL_WINDOWS
0 commit comments