mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-19 18:15:18 -07:00
Portability improvements (#1105)
* Move `raise` code to be behind an autoconf check This moves the call to `raise` behind a `HAVE_RAISE` autoconf check, in addition to `__wasm__`. This is intended to help porting to other platforms that don't support `raise` (e.g. modern game consoles). * Add autoconf check for `sysconf` Only try to invoke `sysconf` if the target platform supports it, and don't warn about unknown page size if `PAGE_SIZE` was defined. Add an include for `sys/param.h` to increase likelihood of finding `PAGE_SIZE`. This is intended to help porting to other platforms that don't support `sysconf` (e.g. modern game consoles) that have a fixed hardware page size. * Don't try to use raise & sysconf in a WASI environment Co-authored-by: Frank Denis <124872+jedisct1@users.noreply.github.com>
This commit is contained in:
parent
fe1d6d11aa
commit
64129657a5
@ -594,7 +594,7 @@ AC_SUBST(CFLAGS_AESNI)
|
|||||||
AC_SUBST(CFLAGS_PCLMUL)
|
AC_SUBST(CFLAGS_PCLMUL)
|
||||||
AC_SUBST(CFLAGS_RDRAND)
|
AC_SUBST(CFLAGS_RDRAND)
|
||||||
|
|
||||||
AC_CHECK_HEADERS([sys/mman.h sys/random.h intrin.h sys/auxv.h])
|
AC_CHECK_HEADERS([sys/mman.h sys/param.h sys/random.h intrin.h sys/auxv.h])
|
||||||
|
|
||||||
AC_MSG_CHECKING([if _xgetbv() is available])
|
AC_MSG_CHECKING([if _xgetbv() is available])
|
||||||
AC_LINK_IFELSE(
|
AC_LINK_IFELSE(
|
||||||
@ -820,8 +820,9 @@ AS_IF([test "x$EMSCRIPTEN" = "x"],[
|
|||||||
AC_CHECK_FUNCS([arc4random arc4random_buf])
|
AC_CHECK_FUNCS([arc4random arc4random_buf])
|
||||||
AS_IF([test "x$WASI" = "x"],[
|
AS_IF([test "x$WASI" = "x"],[
|
||||||
AC_CHECK_FUNCS([mmap mlock madvise mprotect])
|
AC_CHECK_FUNCS([mmap mlock madvise mprotect])
|
||||||
|
AC_CHECK_FUNCS([raise])
|
||||||
|
AC_CHECK_FUNCS([sysconf])
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_MSG_CHECKING(for getrandom with a standard API)
|
AC_MSG_CHECKING(for getrandom with a standard API)
|
||||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef __wasm__
|
#if defined(HAVE_RAISE) && !defined(__wasm__)
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -17,6 +17,10 @@
|
|||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_PARAM_H
|
||||||
|
# include <sys/param.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# include <wincrypt.h>
|
# include <wincrypt.h>
|
||||||
@ -402,7 +406,7 @@ int
|
|||||||
_sodium_alloc_init(void)
|
_sodium_alloc_init(void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_ALIGNED_MALLOC
|
#ifdef HAVE_ALIGNED_MALLOC
|
||||||
# if defined(_SC_PAGESIZE)
|
# if defined(_SC_PAGESIZE) && defined(HAVE_SYSCONF)
|
||||||
long page_size_ = sysconf(_SC_PAGESIZE);
|
long page_size_ = sysconf(_SC_PAGESIZE);
|
||||||
if (page_size_ > 0L) {
|
if (page_size_ > 0L) {
|
||||||
page_size = (size_t) page_size_;
|
page_size = (size_t) page_size_;
|
||||||
@ -411,7 +415,7 @@ _sodium_alloc_init(void)
|
|||||||
SYSTEM_INFO si;
|
SYSTEM_INFO si;
|
||||||
GetSystemInfo(&si);
|
GetSystemInfo(&si);
|
||||||
page_size = (size_t) si.dwPageSize;
|
page_size = (size_t) si.dwPageSize;
|
||||||
# else
|
# elif !defined(PAGE_SIZE)
|
||||||
# warning Unknown page size
|
# warning Unknown page size
|
||||||
# endif
|
# endif
|
||||||
if (page_size < CANARY_SIZE || page_size < sizeof(size_t)) {
|
if (page_size < CANARY_SIZE || page_size < sizeof(size_t)) {
|
||||||
@ -503,7 +507,7 @@ _mprotect_readwrite(void *ptr, size_t size)
|
|||||||
__attribute__((noreturn)) static void
|
__attribute__((noreturn)) static void
|
||||||
_out_of_bounds(void)
|
_out_of_bounds(void)
|
||||||
{
|
{
|
||||||
# ifndef __wasm__
|
# if defined(HAVE_RAISE) && !defined(__wasm__)
|
||||||
# ifdef SIGSEGV
|
# ifdef SIGSEGV
|
||||||
raise(SIGSEGV);
|
raise(SIGSEGV);
|
||||||
# elif defined(SIGKILL)
|
# elif defined(SIGKILL)
|
||||||
|
Loading…
Reference in New Issue
Block a user