src/allocator.c

changeset 1539
2cbdb482d325
parent 1395
395ad9f8da44
child 1540
411cf6fd268f
--- a/src/allocator.c	Thu Dec 04 18:57:54 2025 +0100
+++ b/src/allocator.c	Fri Dec 05 16:11:39 2025 +0100
@@ -31,6 +31,35 @@
 #include <errno.h>
 #include <string.h>
 
+#ifdef _WIN32
+#include <Windows.h>
+#include <sysinfoapi.h>
+unsigned long system_page_size(void) {
+    static unsigned long ps = 0;
+    if (ps == 0) {
+        SYSTEM_INFO sysinfo;
+        GetSystemInfo(&sysinfo);
+        ps = (unsigned long) sysinfo.dwPageSize;
+    }
+    return ps;
+}
+#else
+#include <unistd.h>
+unsigned long system_page_size(void) {
+    static unsigned long ps = 0;
+    if (ps == 0) {
+        long sc = sysconf(_SC_PAGESIZE);
+        if (sc < 0) {
+            // fallback for systems which do not report a value here
+            ps = 4096; // LCOV_EXCL_LINE
+        } else {
+            ps = (unsigned long) sc;
+        }
+    }
+    return ps;
+}
+#endif
+
 static void *cx_malloc_stdlib(
         cx_attr_unused void *d,
         size_t n

mercurial