diff --git a/.gitignore b/.gitignore index dc61f34b5..4b9d305f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build*/ CMakeFiles/ .vscode/ +.vs/ *~ *.sw? diff --git a/src/override/malloc.cc b/src/override/malloc.cc index d9eea884d..d2192b8ba 100644 --- a/src/override/malloc.cc +++ b/src/override/malloc.cc @@ -205,6 +205,21 @@ extern "C" return ENOENT; } +#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(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 // statically-linked programs. These temporarily grab an allocator from the diff --git a/src/pal/pal.h b/src/pal/pal.h index 896d957fc..a5a43ae5b 100644 --- a/src/pal/pal.h +++ b/src/pal/pal.h @@ -1,34 +1,10 @@ #pragma once +#include "pal_consts.h" + 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) - }; } // If simultating OE, then we need the underlying platform @@ -56,14 +32,16 @@ namespace snmalloc PALFreeBSDKernel; # elif defined(__FreeBSD__) PALFBSD; +# else +# error Unsupported platform # endif #endif using Pal = -#ifdef OPEN_ENCLAVE - PALPlainMixin; -#elif defined(SNMALLOC_MEMORY_PROVIDER) +#if defined(SNMALLOC_MEMORY_PROVIDER) PALPlainMixin; +#elif defined(OPEN_ENCLAVE) + PALPlainMixin; #else DefaultPal; #endif diff --git a/src/pal/pal_consts.h b/src/pal/pal_consts.h new file mode 100644 index 000000000..8e32c6164 --- /dev/null +++ b/src/pal/pal_consts.h @@ -0,0 +1,28 @@ +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) + }; +}