]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Handle stack memory on NetBSD as on OpenBSD 13412/head
authorTom Ivar Helbekkmo <tih@hamartun.priv.no>
Sun, 22 Oct 2023 18:26:32 +0000 (20:26 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Oct 2023 10:41:55 +0000 (12:41 +0200)
(cherry picked from commit d6ff1755940d77ca502bf21a8f2d4d690252d0d2)

pdns/recursordist/lazy_allocator.hh

index 39665b6ad266a350e3d10c5ccc5cde13fb207f1a..5e6964bdde5cfb18e1a596aa55dca7659d64e473 100644 (file)
@@ -27,8 +27,8 @@
 #include <sys/mman.h>
 #include <unistd.h>
 
-// On OpenBSD mem used as stack should be marked MAP_STACK
-#ifdef __OpenBSD__
+// On OpenBSD and NetBSD mem used as stack should be marked MAP_STACK
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 #define PDNS_MAP_STACK MAP_STACK
 #else
 #define PDNS_MAP_STACK 0
@@ -82,8 +82,8 @@ struct lazy_allocator
     const auto padding = getAlignmentPadding(requestedSize, pageSize);
     const size_type allocatedSize = requestedSize + padding + (pageSize * 2);
 
-#ifdef __OpenBSD__
-    // OpenBSD does not like mmap MAP_STACK regions that have
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+    // OpenBSD and NetBSD don't like mmap MAP_STACK regions that have
     // PROT_NONE, so allocate r/w and mprotect the guard pages
     // explictly.
     const int protection = PROT_READ | PROT_WRITE;
@@ -96,7 +96,7 @@ struct lazy_allocator
     }
     char* basePointer = static_cast<char*>(p);
     void* usablePointer = basePointer + pageSize;
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) || defined(__NetBSD__)
     int res = mprotect(basePointer, pageSize, PROT_NONE);
     if (res != 0) {
       munmap(p, allocatedSize);