Provide option to CMake for Page Size (#664)

* Pickup page size from unistd.h

This uses the PAGESIZE constant from the unistd.h on POSIX.
This should make the code more resilient to being compiled on platforms with
different page sizes.

* Allow pagesize to come from cmake.

* Update src/snmalloc/pal/pal_posix.h

Co-authored-by: Nathaniel Filardo <105816689+nwf-msr@users.noreply.github.com>

---------

Co-authored-by: Nathaniel Filardo <105816689+nwf-msr@users.noreply.github.com>
This commit is contained in:
Matthew Parkinson
2024-09-25 11:27:31 +01:00
committed by GitHub
parent fb776da909
commit ab4fe84804
2 changed files with 13 additions and 1 deletions

View File

@@ -8,6 +8,7 @@
#endif
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
@@ -129,8 +130,15 @@ namespace snmalloc
| Entropy
#endif
;
#ifdef SNMALLOC_PAGESIZE
static_assert(
bits::is_pow2(SNMALLOC_PAGESIZE), "Page size must be a power of 2");
static constexpr size_t page_size = SNMALLOC_PAGESIZE;
#elif defined(PAGESIZE)
static constexpr size_t page_size = max(Aal::smallest_page_size, PAGESIZE);
#else
static constexpr size_t page_size = Aal::smallest_page_size;
#endif
/**
* Address bits are potentially mediated by some POSIX OSes, but generally