1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-23 20:15:19 -07:00

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:
Frank Denis 2014-11-24 10:22:50 -08:00
parent 60610da39d
commit da2c9952db
3 changed files with 6 additions and 5 deletions

View File

@ -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])

View File

@ -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

View File

@ -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);