diff --git a/src/mem/allocconfig.h b/src/mem/allocconfig.h index 9b30d9f..ec38b90 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -4,40 +4,6 @@ namespace snmalloc { - void error(const char* const str); - - /** - * Flags in a bitfield of optional features that a PAL may support. These - * should be set in the PAL's `pal_features` static constexpr field. - */ - enum PalFeatures : uint64_t - { - /** - * This PAL supports low memory notifications. It must implement a - * `low_memory_epoch` method that returns a `uint64_t` of the number of - * times that a low-memory notification has been raised and an - * `expensive_low_memory_check()` method that returns a `bool` indicating - * whether low memory conditions are still in effect. - */ - LowMemoryNotification = (1 << 0), - /** - * This PAL natively supports allocation with a guaranteed alignment. If - * this is not supported, then we will over-allocate and round the - * allocation. - * - * A PAL that does supports this must expose a `request()` method that takes - * a size and alignment. A PAL that does *not* support it must expose a - * `request()` method that takes only a size. - */ - AlignedAllocation = (1 << 1) - }; - - enum ZeroMem - { - NoZero, - YesZero - }; - // 0 intermediate bits results in power of 2 small allocs. 1 intermediate // bit gives additional sizeclasses at the midpoint between each power of 2. // 2 intermediate bits gives 3 intermediate sizeclasses, etc. diff --git a/src/override/malloc.cc b/src/override/malloc.cc index f89190e..d2192b8 100644 --- a/src/override/malloc.cc +++ b/src/override/malloc.cc @@ -205,16 +205,20 @@ extern "C" return ENOENT; } - SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(get_global_pagemap)(void) +#ifdef SNMALLOC_EXPOSE_PAGEMAP + SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_get_global_pagemap)(void) { return &snmalloc::global_pagemap; } +#endif +#ifdef SNMALLOC_EXPOSE_RESERVE SNMALLOC_EXPORT void* - SNMALLOC_NAME_MANGLE(reserve_shared)(size_t* size, size_t align) + SNMALLOC_NAME_MANGLE(snmalloc_reserve_shared)(size_t* size, size_t align) { return snmalloc::default_memory_provider.reserve(size, align); } +#endif #if !defined(__PIC__) && !defined(NO_BOOTSTRAP_ALLOCATOR) // The following functions are required to work before TLS is set up, in diff --git a/src/pal/pal.h b/src/pal/pal.h index 44a7bcb..a5a43ae 100644 --- a/src/pal/pal.h +++ b/src/pal/pal.h @@ -1,5 +1,12 @@ #pragma once +#include "pal_consts.h" + +namespace snmalloc +{ + void error(const char* const str); +} + // If simultating OE, then we need the underlying platform #if !defined(OPEN_ENCLAVE) || defined(OPEN_ENCLAVE_SIMULATION) # include "pal_apple.h" diff --git a/src/pal/pal_consts.h b/src/pal/pal_consts.h new file mode 100644 index 0000000..ad6724e --- /dev/null +++ b/src/pal/pal_consts.h @@ -0,0 +1,34 @@ +namespace snmalloc +{ + /** + * Flags in a bitfield of optional features that a PAL may support. These + * should be set in the PAL's `pal_features` static constexpr field. + */ + enum PalFeatures : uint64_t + { + /** + * This PAL supports low memory notifications. It must implement a + * `low_memory_epoch` method that returns a `uint64_t` of the number of + * times that a low-memory notification has been raised and an + * `expensive_low_memory_check()` method that returns a `bool` indicating + * whether low memory conditions are still in effect. + */ + LowMemoryNotification = (1 << 0), + /** + * This PAL natively supports allocation with a guaranteed alignment. If + * this is not supported, then we will over-allocate and round the + * allocation. + * + * A PAL that does supports this must expose a `request()` method that takes + * a size and alignment. A PAL that does *not* support it must expose a + * `request()` method that takes only a size. + */ + AlignedAllocation = (1 << 1) + }; + + enum ZeroMem + { + NoZero, + YesZero + }; +}