diff --git a/src/pal/pal_bsd.h b/src/pal/pal_bsd.h index c446dcb..c408619 100644 --- a/src/pal/pal_bsd.h +++ b/src/pal/pal_bsd.h @@ -31,7 +31,7 @@ namespace snmalloc * 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. */ - void notify_not_using(void* p, size_t size) noexcept + static void notify_not_using(void* p, size_t size) noexcept { SNMALLOC_ASSERT(is_aligned_block(p, size)); madvise(p, size, MADV_FREE); diff --git a/src/pal/pal_bsd_aligned.h b/src/pal/pal_bsd_aligned.h index d5d5766..7acefb7 100644 --- a/src/pal/pal_bsd_aligned.h +++ b/src/pal/pal_bsd_aligned.h @@ -29,7 +29,7 @@ namespace snmalloc * Reserve memory at a specific alignment. */ template - void* reserve_aligned(size_t size) noexcept + static void* reserve_aligned(size_t size) noexcept { // Alignment must be a power of 2. SNMALLOC_ASSERT(size == bits::next_pow2(size)); diff --git a/src/pal/pal_concept.h b/src/pal/pal_concept.h index 33f54f4..0407c85 100644 --- a/src/pal/pal_concept.h +++ b/src/pal/pal_concept.h @@ -35,20 +35,17 @@ namespace snmalloc * PALs expose a basic library of memory operations. */ template - concept ConceptPAL_memops = requires(PAL p, void* vp, size_t sz) + concept ConceptPAL_memops = requires(void* vp, size_t sz) { - { p.notify_not_using(vp, sz) } noexcept -> ConceptSame; + { PAL::notify_not_using(vp, sz) } noexcept -> ConceptSame; - /* For reasons unknown, these seem to tickle some bug in MSVC */ -# if !defined(_MSC_VER) - { p.template notify_using(vp, sz) } noexcept + { PAL::template notify_using(vp, sz) } noexcept -> ConceptSame; - { p.template notify_using(vp, sz) } noexcept + { PAL::template notify_using(vp, sz) } noexcept -> ConceptSame; -# endif - { p.template zero(vp, sz) } noexcept -> ConceptSame; - { p.template zero(vp, sz) } noexcept -> ConceptSame; + { PAL::template zero(vp, sz) } noexcept -> ConceptSame; + { PAL::template zero(vp, sz) } noexcept -> ConceptSame; }; /** @@ -57,7 +54,7 @@ namespace snmalloc template concept ConceptPAL_reserve_at_least = requires(PAL p, void* vp, size_t sz) { - { p.reserve_at_least(sz) } noexcept + { PAL::reserve_at_least(sz) } noexcept -> ConceptSame>; }; @@ -65,21 +62,21 @@ namespace snmalloc * Some PALs expose a richer allocator which understands aligned allocations */ template - concept ConceptPAL_reserve_aligned = requires(PAL p, size_t sz) + concept ConceptPAL_reserve_aligned = requires(size_t sz) { - { p.template reserve_aligned(sz) } noexcept -> ConceptSame; - { p.template reserve_aligned(sz) } noexcept -> ConceptSame; + { PAL::template reserve_aligned(sz) } noexcept -> ConceptSame; + { PAL::template reserve_aligned(sz) } noexcept + -> ConceptSame; }; /** * Some PALs can provide memory pressure callbacks. */ template - concept ConceptPAL_mem_low_notify = - requires(PAL p, PalNotificationObject* pno) + concept ConceptPAL_mem_low_notify = requires(PalNotificationObject* pno) { - { p.expensive_low_memory_check() } -> ConceptSame; - { p.register_for_low_memory_callback(pno) } -> ConceptSame; + { PAL::expensive_low_memory_check() } -> ConceptSame; + { PAL::register_for_low_memory_callback(pno) } -> ConceptSame; }; /** diff --git a/src/pal/pal_freebsd_kernel.h b/src/pal/pal_freebsd_kernel.h index 826c1dc..7bab485 100644 --- a/src/pal/pal_freebsd_kernel.h +++ b/src/pal/pal_freebsd_kernel.h @@ -34,7 +34,7 @@ namespace snmalloc } /// Notify platform that we will not be using these pages - void notify_not_using(void* p, size_t size) + static void notify_not_using(void* p, size_t size) { vm_offset_t addr = get_vm_offset(p); kmem_unback(kernel_object, addr, size); @@ -42,7 +42,7 @@ namespace snmalloc /// Notify platform that we will be using these pages template - void notify_using(void* p, size_t size) + static void notify_using(void* p, size_t size) { vm_offset_t addr = get_vm_offset(p); int flags = M_WAITOK | ((zero_mem == YesZero) ? M_ZERO : 0); @@ -54,13 +54,13 @@ namespace snmalloc /// OS specific function for zeroing memory template - void zero(void* p, size_t size) + static void zero(void* p, size_t size) { ::bzero(p, size); } template - void* reserve_aligned(size_t size) noexcept + static void* reserve_aligned(size_t size) noexcept { SNMALLOC_ASSERT(size == bits::next_pow2(size)); SNMALLOC_ASSERT(size >= minimum_alloc_size); diff --git a/src/pal/pal_haiku.h b/src/pal/pal_haiku.h index 05ba71a..1b7cc1e 100644 --- a/src/pal/pal_haiku.h +++ b/src/pal/pal_haiku.h @@ -31,7 +31,7 @@ namespace snmalloc * Notify platform that we will not be needing these pages. * Haiku does not provide madvise call per say only the posix equivalent. */ - void notify_not_using(void* p, size_t size) noexcept + static void notify_not_using(void* p, size_t size) noexcept { SNMALLOC_ASSERT(is_aligned_block(p, size)); posix_madvise(p, size, POSIX_MADV_DONTNEED); diff --git a/src/pal/pal_linux.h b/src/pal/pal_linux.h index a645c16..74999af 100644 --- a/src/pal/pal_linux.h +++ b/src/pal/pal_linux.h @@ -37,7 +37,7 @@ namespace snmalloc * clear the underlying memory range. */ template - void zero(void* p, size_t size) noexcept + static void zero(void* p, size_t size) noexcept { // QEMU does not seem to be giving the desired behaviour for // MADV_DONTNEED. switch back to memset only for QEMU. diff --git a/src/pal/pal_open_enclave.h b/src/pal/pal_open_enclave.h index 0183c9f..420c49d 100644 --- a/src/pal/pal_open_enclave.h +++ b/src/pal/pal_open_enclave.h @@ -62,7 +62,7 @@ namespace snmalloc } template - void zero(void* p, size_t size) noexcept + static void zero(void* p, size_t size) noexcept { oe_memset_s(p, size, 0, size); } diff --git a/src/pal/pal_plain.h b/src/pal/pal_plain.h index a7cd199..9d8c8d9 100644 --- a/src/pal/pal_plain.h +++ b/src/pal/pal_plain.h @@ -11,11 +11,11 @@ namespace snmalloc { public: // Notify platform that we will not be using these pages - void notify_not_using(void*, size_t) noexcept {} + static void notify_not_using(void*, size_t) noexcept {} // Notify platform that we will not be using these pages template - void notify_using(void* p, size_t size) noexcept + static void notify_using(void* p, size_t size) noexcept { if constexpr (zero_mem == YesZero) { diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index 03d39cc..6fbecad 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -131,7 +131,7 @@ namespace snmalloc * high memory pressure conditions, though on Linux this seems to impose * too much of a performance penalty. */ - void notify_not_using(void* p, size_t size) noexcept + static void notify_not_using(void* p, size_t size) noexcept { SNMALLOC_ASSERT(is_aligned_block(p, size)); #ifdef USE_POSIX_COMMIT_CHECKS @@ -150,7 +150,7 @@ namespace snmalloc * function. */ template - void notify_using(void* p, size_t size) noexcept + static void notify_using(void* p, size_t size) noexcept { SNMALLOC_ASSERT( is_aligned_block(p, size) || (zero_mem == NoZero)); @@ -163,7 +163,7 @@ namespace snmalloc #endif if constexpr (zero_mem == YesZero) - static_cast(this)->template zero(p, size); + zero(p, size); } /** @@ -178,7 +178,7 @@ namespace snmalloc * calling bzero at some point. */ template - void zero(void* p, size_t size) noexcept + static void zero(void* p, size_t size) noexcept { if (page_aligned || is_aligned_block(p, size)) { @@ -207,7 +207,7 @@ namespace snmalloc * POSIX does not define a portable interface for specifying alignment * greater than a page. */ - std::pair reserve_at_least(size_t size) noexcept + static std::pair reserve_at_least(size_t size) noexcept { SNMALLOC_ASSERT(size == bits::next_pow2(size)); diff --git a/src/pal/pal_windows.h b/src/pal/pal_windows.h index 1e6215f..39e0556 100644 --- a/src/pal/pal_windows.h +++ b/src/pal/pal_windows.h @@ -64,7 +64,7 @@ namespace snmalloc * Check whether the low memory state is still in effect. This is an * expensive operation and should not be on any fast paths. */ - bool expensive_low_memory_check() + static bool expensive_low_memory_check() { BOOL result; QueryMemoryResourceNotification(lowMemoryObject, &result); @@ -113,7 +113,7 @@ namespace snmalloc } /// Notify platform that we will not be using these pages - void notify_not_using(void* p, size_t size) noexcept + static void notify_not_using(void* p, size_t size) noexcept { SNMALLOC_ASSERT(is_aligned_block(p, size)); @@ -125,7 +125,7 @@ namespace snmalloc /// Notify platform that we will be using these pages template - void notify_using(void* p, size_t size) noexcept + static void notify_using(void* p, size_t size) noexcept { SNMALLOC_ASSERT( is_aligned_block(p, size) || (zero_mem == NoZero)); @@ -138,7 +138,7 @@ namespace snmalloc /// OS specific function for zeroing memory template - void zero(void* p, size_t size) noexcept + static void zero(void* p, size_t size) noexcept { if (page_aligned || is_aligned_block(p, size)) { @@ -151,13 +151,13 @@ namespace snmalloc } # ifdef USE_SYSTEMATIC_TESTING - size_t& systematic_bump_ptr() + static size_t& systematic_bump_ptr() { static size_t bump_ptr = (size_t)0x4000'0000'0000; return bump_ptr; } - std::pair reserve_at_least(size_t size) noexcept + static std::pair reserve_at_least(size_t size) noexcept { // Magic number for over-allocating chosen by the Pal // These should be further refined based on experiments. @@ -183,7 +183,7 @@ namespace snmalloc } # elif defined(PLATFORM_HAS_VIRTUALALLOC2) template - void* reserve_aligned(size_t size) noexcept + static void* reserve_aligned(size_t size) noexcept { SNMALLOC_ASSERT(size == bits::next_pow2(size)); SNMALLOC_ASSERT(size >= minimum_alloc_size); @@ -213,7 +213,7 @@ namespace snmalloc return ret; } # else - std::pair reserve_at_least(size_t size) noexcept + static std::pair reserve_at_least(size_t size) noexcept { SNMALLOC_ASSERT(size == bits::next_pow2(size));