diff options
Diffstat (limited to 'sysdep')
-rw-r--r-- | sysdep/unix/alloc.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/sysdep/unix/alloc.c b/sysdep/unix/alloc.c index c525f713..f6296afe 100644 --- a/sysdep/unix/alloc.c +++ b/sysdep/unix/alloc.c @@ -16,41 +16,36 @@ #include <sys/mman.h> #endif +long page_size = 0; + #ifdef HAVE_MMAP -static u64 page_size = 0; static _Bool use_fake = 0; #else -static const u64 page_size = 4096; /* Fake page size */ +static _Bool use_fake = 1; #endif -u64 get_page_size(void) +void resource_sys_init(void) { - if (page_size) - return page_size; - #ifdef HAVE_MMAP - if (page_size = sysconf(_SC_PAGESIZE)) - { - if ((u64_popcount(page_size) > 1) || (page_size > 16384)) - { - /* Too big or strange page, use the aligned allocator instead */ - page_size = 4096; - use_fake = 1; - } - return page_size; - } + if (!(page_size = sysconf(_SC_PAGESIZE))) + die("System page size must be non-zero"); - bug("Page size must be non-zero"); + if ((u64_popcount(page_size) > 1) || (page_size > 16384)) + { #endif + /* Too big or strange page, use the aligned allocator instead */ + page_size = 4096; + use_fake = 1; + } } void * -alloc_page(void) +alloc_sys_page(void) { #ifdef HAVE_MMAP if (!use_fake) { - void *ret = mmap(NULL, get_page_size(), PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + void *ret = mmap(NULL, page_size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ret == MAP_FAILED) bug("mmap(%lu) failed: %m", page_size); return ret; @@ -66,12 +61,12 @@ alloc_page(void) } void -free_page(void *ptr) +free_sys_page(void *ptr) { #ifdef HAVE_MMAP if (!use_fake) { - if (munmap(ptr, get_page_size()) < 0) + if (munmap(ptr, page_size) < 0) bug("munmap(%p) failed: %m", ptr); } else |