From 536ea6858ecfcac49060c805231bd1722d84a0cf Mon Sep 17 00:00:00 2001 From: zoulasc Date: Mon, 3 Feb 2020 15:35:08 -0500 Subject: [PATCH] NetBSD specific changes: - NetBSD overcommits - When mapping pages, use the maximum of the alignment requested and the compiled-in PAGE constant which might be greater than the current kernel pagesize, since we compile binaries with the maximum page size supported by the architecture (so that they work with all kernels). --- src/pages.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/pages.c b/src/pages.c index 75c8dd9d..62e84f04 100644 --- a/src/pages.c +++ b/src/pages.c @@ -14,6 +14,9 @@ #include #endif #endif +#ifdef __NetBSD__ +#include /* ilog2 */ +#endif /******************************************************************************/ /* Data. */ @@ -74,6 +77,18 @@ os_pages_map(void *addr, size_t size, size_t alignment, bool *commit) { * of existing mappings, and we only want to create new mappings. */ { +#ifdef __NetBSD__ + /* + * On NetBSD PAGE for a platform is defined to the + * maximum page size of all machine architectures + * for that platform, so that we can use the same + * binaries across all machine architectures. + */ + if (alignment > os_page || PAGE > os_page) { + unsigned int a = ilog2(MAX(alignment, PAGE)); + mmap_flags |= MAP_ALIGNED(a); + } +#endif int prot = *commit ? PAGES_PROT_COMMIT : PAGES_PROT_DECOMMIT; ret = mmap(addr, size, prot, mmap_flags, -1, 0); @@ -622,6 +637,8 @@ pages_boot(void) { mmap_flags |= MAP_NORESERVE; } # endif +#elif defined(__NetBSD__) + os_overcommits = true; #else os_overcommits = false; #endif