#pragma once #include "pal_posix.h" #include namespace snmalloc { /** * Generic *BSD PAL mixin. This provides features that are common to the BSD * family. */ template class PALBSD : public PALPOSIX { public: /** * Bitmap of PalFeatures flags indicating the optional features that this * PAL supports. * * The generic BSD PAL does not add any features that are not supported by * generic POSIX systems, but explicitly declares this variable to remind * anyone who extends this class that they may need to modify this field. */ static constexpr uint64_t pal_features = PALPOSIX::pal_features; /** * Notify platform that we will not be using these pages. * * BSD systems provide the `MADV_FREE` flag to `madvise`, which allows the * operating system to replace the pages with CoW copies of a zero page at * any point between the call and the next write to that page. */ static void notify_not_using(void* p, size_t size) noexcept { SNMALLOC_ASSERT(is_aligned_block(p, size)); // Call this Pal to simulate the Windows decommit in CI. #ifdef USE_POSIX_COMMIT_CHECKS memset(p, 0x5a, size); #endif madvise(p, size, MADV_FREE); #ifdef USE_POSIX_COMMIT_CHECKS mprotect(p, size, PROT_NONE); #endif } }; } // namespace snmalloc