Skip to content

Commit db3580a

Browse files
committed
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.
1 parent c33f355 commit db3580a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/mem/largealloc.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,18 @@ namespace snmalloc
368368
}
369369
};
370370

371-
using GlobalVirtual = MemoryProviderStateMixin<Pal>;
371+
#ifndef SNMALLOC_DEFAULT_MEMORY_PROVIDER
372+
# define SNMALLOC_DEFAULT_MEMORY_PROVIDER MemoryProviderStateMixin<Pal>
373+
#endif
374+
375+
/**
376+
* The type of the default memory allocator. This can be changed by defining
377+
* `SNMALLOC_DEFAULT_MEMORY_PROVIDER` before including this file. By default
378+
* it is `MemoryProviderStateMixin<Pal>` a class that allocates directly from
379+
* the platform abstraction layer.
380+
*/
381+
using GlobalVirtual = SNMALLOC_DEFAULT_MEMORY_PROVIDER;
382+
372383
/**
373384
* The memory provider that will be used if no other provider is explicitly
374385
* passed as an argument.

src/mem/pool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace snmalloc
2424
friend Pooled<T>;
2525
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
2626
friend class MemoryProviderStateMixin;
27+
friend SNMALLOC_DEFAULT_MEMORY_PROVIDER;
2728

2829
std::atomic_flag lock = ATOMIC_FLAG_INIT;
2930
MPMCStack<T, PreZeroed> stack;

0 commit comments

Comments
 (0)