diff --git a/src/mem/fixedglobalconfig.h b/src/mem/fixedglobalconfig.h index 146993d..4878453 100644 --- a/src/mem/fixedglobalconfig.h +++ b/src/mem/fixedglobalconfig.h @@ -11,20 +11,21 @@ namespace snmalloc /** * A single fixed address range allocator configuration */ + template class FixedGlobals : public CommonConfig { public: - using Backend = BackendAllocator, true>; + using Backend = BackendAllocator; private: - inline static Backend::GlobalState backend_state; + inline static typename Backend::GlobalState backend_state; inline static ChunkAllocatorState slab_allocator_state; inline static PoolState> alloc_pool; public: - static Backend::GlobalState& get_backend_state() + static typename Backend::GlobalState& get_backend_state() { return backend_state; } diff --git a/src/pal/pal.h b/src/pal/pal.h index 00111a9..d95ef0f 100644 --- a/src/pal/pal.h +++ b/src/pal/pal.h @@ -16,11 +16,11 @@ # include "pal_haiku.h" # include "pal_linux.h" # include "pal_netbsd.h" -# include "pal_noalloc.h" # include "pal_openbsd.h" # include "pal_solaris.h" # include "pal_windows.h" #endif +#include "pal_noalloc.h" #include "pal_plain.h" namespace snmalloc @@ -56,7 +56,7 @@ namespace snmalloc #if defined(SNMALLOC_MEMORY_PROVIDER) PALPlainMixin; #elif defined(OPEN_ENCLAVE) - PALPlainMixin; + PALOpenEnclave; #else DefaultPal; #endif diff --git a/src/pal/pal_open_enclave.h b/src/pal/pal_open_enclave.h index 3487d3f..d6036eb 100644 --- a/src/pal/pal_open_enclave.h +++ b/src/pal/pal_open_enclave.h @@ -1,10 +1,7 @@ #pragma once -#include "ds/address.h" -#include "ds/flaglock.h" -#include "pal_plain.h" +#include "pal_noalloc.h" -#include #ifdef OPEN_ENCLAVE extern "C" void* oe_memset_s(void* p, size_t p_size, int c, size_t size); extern "C" int oe_random(void* data, size_t size); @@ -12,55 +9,29 @@ extern "C" [[noreturn]] void oe_abort(); namespace snmalloc { - class PALOpenEnclave + class OpenEnclaveErrorHandler { - /// Base of OE heap - static inline void* heap_base = nullptr; - - /// Size of OE heap - static inline size_t heap_size; - - // This is infrequently used code, a spin lock simplifies the code - // considerably, and should never be on the fast path. - static inline std::atomic_flag spin_lock; - public: - /** - * This will be called by oe_allocator_init to set up enclave heap bounds. - */ - static void setup_initial_range(void* base, void* end) - { - heap_size = pointer_diff(base, end); - heap_base = base; - } - - /** - * Bitmap of PalFeatures flags indicating the optional features that this - * PAL supports. - */ - static constexpr uint64_t pal_features = Entropy; - - static constexpr size_t page_size = Aal::smallest_page_size; + static void print_stack_trace() {} [[noreturn]] static void error(const char* const str) { UNUSED(str); oe_abort(); } + }; - static std::pair - reserve_at_least(size_t request_size) noexcept - { - // First call returns the entire address space - // subsequent calls return {nullptr, 0} - FlagLock lock(spin_lock); - if (request_size > heap_size) - return {nullptr, 0}; + using OpenEnclaveBasePAL = PALNoAlloc; - auto result = std::make_pair(heap_base, heap_size); - heap_size = 0; - return result; - } + class PALOpenEnclave : public OpenEnclaveBasePAL + { + public: + /** + * Bitmap of PalFeatures flags indicating the optional features that this + * PAL supports. + */ + static constexpr uint64_t pal_features = + OpenEnclaveBasePAL::pal_features | Entropy; template static void zero(void* p, size_t size) noexcept diff --git a/src/test/func/fixed_region/fixed_region.cc b/src/test/func/fixed_region/fixed_region.cc index 99cf2aa..702aaee 100644 --- a/src/test/func/fixed_region/fixed_region.cc +++ b/src/test/func/fixed_region/fixed_region.cc @@ -11,7 +11,8 @@ using namespace snmalloc; -using FixedAlloc = LocalAllocator; +using CustomGlobals = FixedGlobals>; +using FixedAlloc = LocalAllocator; int main() { @@ -30,8 +31,8 @@ int main() std::cout << "Allocated region " << oe_base.unsafe_ptr() << " - " << pointer_offset(oe_base, size).unsafe_ptr() << std::endl; - FixedGlobals fixed_handle; - FixedGlobals::init(oe_base, size); + CustomGlobals fixed_handle; + CustomGlobals::init(oe_base, size); FixedAlloc a(fixed_handle); size_t object_size = 128; diff --git a/src/test/func/two_alloc_types/alloc1.cc b/src/test/func/two_alloc_types/alloc1.cc index 08efc38..2c15db5 100644 --- a/src/test/func/two_alloc_types/alloc1.cc +++ b/src/test/func/two_alloc_types/alloc1.cc @@ -10,7 +10,8 @@ #define SNMALLOC_PROVIDE_OWN_CONFIG namespace snmalloc { - using Alloc = LocalAllocator; + using CustomGlobals = FixedGlobals>; + using Alloc = LocalAllocator; } #define SNMALLOC_NAME_MANGLE(a) enclave_##a @@ -18,7 +19,7 @@ namespace snmalloc extern "C" void oe_allocator_init(void* base, void* end) { - snmalloc::FixedGlobals fixed_handle; + snmalloc::CustomGlobals fixed_handle; fixed_handle.init( CapPtr(base), address_cast(end) - address_cast(base)); }