From: Tom Ivar Helbekkmo Date: Sun, 22 Oct 2023 18:26:32 +0000 (+0200) Subject: Handle stack memory on NetBSD as on OpenBSD X-Git-Tag: rec-5.0.0-beta1~37^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6ff1755940d77ca502bf21a8f2d4d690252d0d2;p=thirdparty%2Fpdns.git Handle stack memory on NetBSD as on OpenBSD --- diff --git a/pdns/recursordist/lazy_allocator.hh b/pdns/recursordist/lazy_allocator.hh index ead82293af..05ab56b1fa 100644 --- a/pdns/recursordist/lazy_allocator.hh +++ b/pdns/recursordist/lazy_allocator.hh @@ -27,8 +27,8 @@ #include #include -// 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 // explicitly. const int protection = PROT_READ | PROT_WRITE; @@ -96,7 +96,7 @@ struct lazy_allocator } char* basePointer = static_cast(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);