1AC_DEFUN([CHECK_LIBC_COMPAT], [ 2# Check for libc headers 3AC_CHECK_HEADERS([err.h readpassphrase.h]) 4# Check for general libc functions 5AC_CHECK_FUNCS([asprintf freezero memmem]) 6AC_CHECK_FUNCS([readpassphrase reallocarray recallocarray]) 7AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) 8AC_CHECK_FUNCS([timegm _mkgmtime timespecsub]) 9AC_CHECK_FUNCS([getprogname syslog syslog_r]) 10AC_CACHE_CHECK([for getpagesize], ac_cv_func_getpagesize, [ 11 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 12// Since Android NDK v16 getpagesize is defined as inline inside unistd.h 13#ifdef __ANDROID__ 14# include <unistd.h> 15#endif 16 ]], [[ 17 getpagesize(); 18]])], 19 [ ac_cv_func_getpagesize="yes" ], 20 [ ac_cv_func_getpagesize="no" 21 ]) 22]) 23AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) 24AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) 25AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) 26AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) 27AM_CONDITIONAL([HAVE_READPASSPHRASE], [test "x$ac_cv_func_readpassphrase" = xyes]) 28AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) 29AM_CONDITIONAL([HAVE_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" = xyes]) 30AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes]) 31AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes]) 32AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes]) 33AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes]) 34AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes]) 35AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes]) 36AM_CONDITIONAL([HAVE_TIMEGM], [test "x$ac_cv_func_timegm" = xyes]) 37AM_CONDITIONAL([HAVE_GETPROGNAME], [test "x$ac_cv_func_getprogname" = xyes]) 38AM_CONDITIONAL([HAVE_SYSLOG], [test "x$ac_cv_func_syslog" = xyes]) 39AM_CONDITIONAL([HAVE_SYSLOG_R], [test "x$ac_cv_func_syslog_r" = xyes]) 40]) 41 42AC_DEFUN([CHECK_SYSCALL_COMPAT], [ 43AC_CHECK_FUNCS([accept4 pipe2 pledge poll socketpair]) 44AM_CONDITIONAL([HAVE_ACCEPT4], [test "x$ac_cv_func_accept4" = xyes]) 45AM_CONDITIONAL([HAVE_PIPE2], [test "x$ac_cv_func_pipe2" = xyes]) 46AM_CONDITIONAL([HAVE_PLEDGE], [test "x$ac_cv_func_pledge" = xyes]) 47AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes]) 48AM_CONDITIONAL([HAVE_SOCKETPAIR], [test "x$ac_cv_func_socketpair" = xyes]) 49]) 50 51AC_DEFUN([CHECK_B64_NTOP], [ 52AC_SEARCH_LIBS([b64_ntop],[resolv]) 53AC_SEARCH_LIBS([__b64_ntop],[resolv]) 54AC_CACHE_CHECK([for b64_ntop], ac_cv_have_b64_ntop_arg, [ 55 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 56#include <sys/types.h> 57#include <sys/socket.h> 58#include <netinet/in.h> 59#include <arpa/inet.h> 60#include <resolv.h> 61 ]], [[ b64_ntop(NULL, 0, NULL, 0); ]])], 62 [ ac_cv_have_b64_ntop_arg="yes" ], 63 [ ac_cv_have_b64_ntop_arg="no" 64 ]) 65]) 66AM_CONDITIONAL([HAVE_B64_NTOP], [test "x$ac_cv_func_b64_ntop_arg" = xyes]) 67]) 68 69AC_DEFUN([CHECK_CRYPTO_COMPAT], [ 70# Check crypto-related libc functions and syscalls 71AC_CHECK_FUNCS([arc4random arc4random_buf arc4random_uniform]) 72AC_CHECK_FUNCS([explicit_bzero getauxval]) 73 74AC_CACHE_CHECK([for getentropy], ac_cv_func_getentropy, [ 75 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 76#include <sys/types.h> 77#include <unistd.h> 78 79/* 80 * Explanation: 81 * 82 * - iOS <= 10.1 fails because of missing sys/random.h 83 * 84 * - in macOS 10.12 getentropy is not tagged as introduced in 85 * 10.12 so we cannot use it for target < 10.12 86 */ 87#ifdef __APPLE__ 88# include <AvailabilityMacros.h> 89# include <TargetConditionals.h> 90 91# if (TARGET_OS_IPHONE || TARGET_OS_SIMULATOR) 92# include <sys/random.h> /* Not available as of iOS <= 10.1 */ 93# else 94 95# include <sys/random.h> /* Pre 10.12 systems should die here */ 96 97/* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */ 98# ifndef MAC_OS_X_VERSION_10_12 99# define MAC_OS_X_VERSION_10_12 101200 /* Robustness */ 100# endif 101# if defined(MAC_OS_X_VERSION_MIN_REQUIRED) 102# if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 103# error "Targeting on Mac OSX 10.11 or earlier" 104# endif 105# endif 106 107# endif 108#endif /* __APPLE__ */ 109 ]], [[ 110 char buffer; 111 (void)getentropy(&buffer, sizeof (buffer)); 112]])], 113 [ ac_cv_func_getentropy="yes" ], 114 [ ac_cv_func_getentropy="no" 115 ]) 116]) 117 118AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp]) 119AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes]) 120AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes]) 121AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes]) 122AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes]) 123AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes]) 124AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes]) 125AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes]) 126 127# Override arc4random_buf implementations with known issues 128AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], 129 [test "x$USE_BUILTIN_ARC4RANDOM" != xyes \ 130 -a "x$ac_cv_func_arc4random_buf" = xyes]) 131 132# Check for getentropy fallback dependencies 133AC_CHECK_FUNCS([getauxval]) 134AC_SEARCH_LIBS([dl_iterate_phdr],[dl]) 135AC_CHECK_FUNCS([dl_iterate_phdr]) 136 137AC_SEARCH_LIBS([pthread_once],[pthread]) 138AC_SEARCH_LIBS([pthread_mutex_lock],[pthread]) 139AC_SEARCH_LIBS([clock_gettime],[rt posix4]) 140AC_CHECK_FUNCS([clock_gettime]) 141AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes]) 142]) 143 144AC_DEFUN([CHECK_VA_COPY], [ 145AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ 146 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 147#include <stdarg.h> 148va_list x,y; 149 ]], [[ va_copy(x,y); ]])], 150 [ ac_cv_have_va_copy="yes" ], 151 [ ac_cv_have_va_copy="no" 152 ]) 153]) 154if test "x$ac_cv_have_va_copy" = "xyes" ; then 155 AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists]) 156fi 157 158AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [ 159 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 160#include <stdarg.h> 161va_list x,y; 162 ]], [[ __va_copy(x,y); ]])], 163 [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no" 164 ]) 165]) 166if test "x$ac_cv_have___va_copy" = "xyes" ; then 167 AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists]) 168fi 169]) 170