quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

ax_check_catchable_segv.m4 (1587B)


      1 # SYNOPSIS
      2 #
      3 #   AX_CHECK_CATCHABLE_SEGV
      4 #
      5 # DESCRIPTION
      6 #
      7 #  Check whether segmentation violations can be caught using signal handlers.
      8 
      9 #serial 1
     10 
     11 AC_DEFUN([AX_CHECK_CATCHABLE_SEGV], [dnl
     12     AC_PREREQ(2.64)
     13     AS_VAR_PUSHDEF([CACHEVAR], [ax_cv_check_[]_AC_LANG_ABBREV[]CATCHABLE_SEGV])dnl
     14     AC_CACHE_CHECK([whether segmentation violations can be caught], CACHEVAR, [
     15         AC_RUN_IFELSE([
     16             AC_LANG_PROGRAM([[
     17 #include <signal.h>
     18 #include <stdlib.h>
     19 static void sig(int _) { exit(0); }
     20             ]], [[
     21 volatile unsigned char * volatile x = (volatile unsigned char *) malloc(8);
     22 size_t i;
     23 
     24 #ifdef SIGPROT
     25 signal(SIGPROT, sig);
     26 #endif
     27 signal(SIGSEGV, sig);
     28 signal(SIGBUS, sig);
     29 #if !defined(__SANITIZE_ADDRESS__) && !defined(__EMSCRIPTEN__)
     30 *((volatile unsigned char *) -1) = 0xd0;
     31 *((volatile unsigned char *) 1) = 0xd0;
     32 for (i = 0; i < 10000000; i += 1024) { x[-i] = x[i] = (unsigned char) i; }
     33 #endif
     34 free((void *) x);
     35 exit(1)
     36             ]])],
     37             [AS_VAR_SET(CACHEVAR, [yes])],
     38             [AS_VAR_SET(CACHEVAR, [no])],
     39             [AS_VAR_SET(CACHEVAR, [unknown])]
     40         )
     41     ])
     42     AS_VAR_IF(CACHEVAR, yes,
     43         [AC_DEFINE([HAVE_CATCHABLE_SEGV], [1], [Define if segmentation violations can be caught using signal handlers])],
     44         [AC_MSG_WARN([On this platform, segmentation violations cannot be caught using signal handlers. This is expected if you enabled a tool such as Address Sanitizer (-fsanitize=address), but be aware that using Address Sanitizer may also significantly reduce performance.])]
     45     )
     46     AS_VAR_POPDEF([CACHEVAR])dnl
     47 ])