From 5bc6820c24d7fb63f969be4447e7fbebc0673797 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 29 Aug 2018 03:24:28 -0400 Subject: [PATCH] rely on mmap rounding to page size when possible --- malloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/malloc.c b/malloc.c index 4fb4d7e..2d7b20c 100644 --- a/malloc.c +++ b/malloc.c @@ -30,8 +30,6 @@ static_assert(sizeof(void *) == 8, "64-bit only"); #define ALIGNMENT_CEILING(s, alignment) (((s) + (alignment - 1)) & ((~(alignment)) + 1)) static void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect) { - usable_size = PAGE_CEILING(usable_size); - size_t real_size; if (unlikely(__builtin_add_overflow(usable_size, guard_size * 2, &real_size))) { errno = ENOMEM; @@ -50,13 +48,15 @@ static void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotec } static void deallocate_pages(void *usable, size_t usable_size, size_t guard_size) { - usable_size = PAGE_CEILING(usable_size); - memory_unmap((char *)usable - guard_size, usable_size + guard_size * 2); } static void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size) { usable_size = PAGE_CEILING(usable_size); + if (unlikely(!usable_size)) { + errno = ENOMEM; + return NULL; + } size_t alloc_size; if (unlikely(__builtin_add_overflow(usable_size, alignment - PAGE_SIZE, &alloc_size))) {