xref: /freebsd/sys/contrib/libsodium/m4/ax_check_catchable_segv.m4 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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
11AC_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 when using the _AC_LANG compiler], CACHEVAR, [
15        AC_RUN_IFELSE([
16            AC_LANG_PROGRAM([[
17#include <signal.h>
18#include <stdlib.h>
19static void sig(int _) { exit(0); }
20            ]], [[
21volatile unsigned char * volatile x = (volatile unsigned char *) malloc(8);
22size_t i;
23
24signal(SIGSEGV, sig);
25signal(SIGBUS, sig);
26#if !defined(__SANITIZE_ADDRESS__) && !defined(__EMSCRIPTEN__)
27for (i = 0; i < 10000000; i += 1024) { x[-i] = x[i] = (unsigned char) i; }
28#endif
29free((void *) x);
30exit(1)
31            ]])],
32            [AS_VAR_SET(CACHEVAR, [yes])],
33            [AS_VAR_SET(CACHEVAR, [no])],
34            [AS_VAR_SET(CACHEVAR, [unknown])]
35        )
36    ])
37    AS_VAR_IF(CACHEVAR, yes,
38        [AC_DEFINE([HAVE_CATCHABLE_SEGV], [1], [Define if segmentation violations can be caught using signal handlers])],
39        [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.])]
40    )
41    AS_VAR_POPDEF([CACHEVAR])dnl
42])
43