From db3580a9d8fac394afa3efd6cc55027f269cd9dc Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Wed, 13 Jan 2021 15:23:56 +0000 Subject: [PATCH] Small tweaks to make the sandbox mode happy. Allow replacing the type of GlobalVirtual at compile time. Make that type a friend of Pool so that it can allocate things. --- src/mem/largealloc.h | 13 ++++++++++++- src/mem/pool.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index 90b88da9d..8d714baff 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -368,7 +368,18 @@ namespace snmalloc } }; - using GlobalVirtual = MemoryProviderStateMixin; +#ifndef SNMALLOC_DEFAULT_MEMORY_PROVIDER +# define SNMALLOC_DEFAULT_MEMORY_PROVIDER MemoryProviderStateMixin +#endif + + /** + * The type of the default memory allocator. This can be changed by defining + * `SNMALLOC_DEFAULT_MEMORY_PROVIDER` before including this file. By default + * it is `MemoryProviderStateMixin` a class that allocates directly from + * the platform abstraction layer. + */ + using GlobalVirtual = SNMALLOC_DEFAULT_MEMORY_PROVIDER; + /** * The memory provider that will be used if no other provider is explicitly * passed as an argument. diff --git a/src/mem/pool.h b/src/mem/pool.h index 69de2ca7a..713cbfa37 100644 --- a/src/mem/pool.h +++ b/src/mem/pool.h @@ -24,6 +24,7 @@ namespace snmalloc friend Pooled; template friend class MemoryProviderStateMixin; + friend SNMALLOC_DEFAULT_MEMORY_PROVIDER; std::atomic_flag lock = ATOMIC_FLAG_INIT; MPMCStack stack;