Created pal_consts.h. New exported functions are now prefixed with "snmalloc_".

This commit is contained in:
rschust
2019-04-09 13:35:13 +01:00
committed by David Chisnall
parent f0d18760fe
commit 71900ef947
4 changed files with 47 additions and 36 deletions

View File

@@ -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.

View File

@@ -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<true>(size, align);
}
#endif
#if !defined(__PIC__) && !defined(NO_BOOTSTRAP_ALLOCATOR)
// The following functions are required to work before TLS is set up, in

View File

@@ -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"

34
src/pal/pal_consts.h Normal file
View File

@@ -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
};
}