Check if mmap(2) works, not just the presence of MAP_ANON
In particular, mmap(2) doesn't return an aligner pointer on Emscripten.
This commit is contained in:
parent
60610da39d
commit
da2c9952db
@ -408,6 +408,7 @@ dnl Checks for functions and headers
|
||||
AS_IF([test "x$EMSCRIPTEN" = "x"],[
|
||||
AC_CHECK_FUNCS([arc4random arc4random_buf])
|
||||
AC_CHECK_FUNCS([mlock madvise mprotect explicit_bzero])
|
||||
AC_FUNC_MMAP
|
||||
])
|
||||
AC_CHECK_FUNCS([posix_memalign])
|
||||
|
||||
|
@ -35,7 +35,7 @@ void *
|
||||
alloc_region(escrypt_region_t * region, size_t size)
|
||||
{
|
||||
uint8_t * base, * aligned;
|
||||
#ifdef MAP_ANON
|
||||
#if defined(MAP_ANON) && defined(HAVE_MMAP)
|
||||
if ((base = (uint8_t *) mmap(NULL, size, PROT_READ | PROT_WRITE,
|
||||
#ifdef MAP_NOCORE
|
||||
MAP_ANON | MAP_PRIVATE | MAP_NOCORE,
|
||||
@ -75,7 +75,7 @@ int
|
||||
free_region(escrypt_region_t * region)
|
||||
{
|
||||
if (region->base) {
|
||||
#ifdef MAP_ANON
|
||||
#if defined(MAP_ANON) && defined(HAVE_MMAP)
|
||||
if (munmap(region->base, region->size))
|
||||
return -1; /* LCOV_EXCL_LINE */
|
||||
#else
|
||||
|
@ -32,7 +32,7 @@
|
||||
#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
|
||||
# define MAP_ANON MAP_ANONYMOUS
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(MAP_ANON) || defined(HAVE_POSIX_MEMALIGN)
|
||||
#if defined(_WIN32) || (defined(MAP_ANON) && defined(HAVE_MMAP)) || defined(HAVE_POSIX_MEMALIGN)
|
||||
# define HAVE_ALIGNED_MALLOC
|
||||
#endif
|
||||
#if defined(HAVE_MPROTECT) && !(defined(PROT_NONE) && defined(PROT_READ) && defined(PROT_WRITE))
|
||||
@ -298,7 +298,7 @@ _alloc_aligned(const size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
#ifdef MAP_ANON
|
||||
#if defined(MAP_ANON) && defined(HAVE_MMAP)
|
||||
if ((ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
|
||||
MAP_ANON | MAP_PRIVATE | MAP_NOCORE, -1, 0)) == MAP_FAILED) {
|
||||
ptr = NULL; /* LCOV_EXCL_LINE */
|
||||
@ -320,7 +320,7 @@ _alloc_aligned(const size_t size)
|
||||
static void
|
||||
_free_aligned(unsigned char * const ptr, const size_t size)
|
||||
{
|
||||
#ifdef MAP_ANON
|
||||
#if defined(MAP_ANON) && defined(HAVE_MMAP)
|
||||
(void) munmap(ptr, size);
|
||||
#elif defined(HAVE_POSIX_MEMALIGN)
|
||||
free(ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user