OpenEnclave PAL: Store enclave heap base/end in inline variables. (#201)
PALOpenEnclave object is lazily constructed. I couldn't figure out a straight-forward way to pass the heap bounds to the constructor of PALOpenEnclave object. As an alternative, store the bounds in inline static variables of the PALOpenEnclave class and set them via static setup_initial_range function. - two_alloc_types/alloc1.cc Define oe_allocator_init to forward base, end values to PALOpenEnclave::setup_inital_range - two_alloc_types/main.cc Use oe_allocator_init function to set up heap range. - fixed_region/fixed_region.cc Initialize heap range via call to PALOpenEnclave::setup_inital_range. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
4c22c5b02f
commit
c7736a2def
@@ -10,18 +10,6 @@
|
||||
#endif
|
||||
#define assert please_use_SNMALLOC_ASSERT
|
||||
|
||||
void* oe_base;
|
||||
void* oe_end;
|
||||
extern "C" const void* __oe_get_heap_base()
|
||||
{
|
||||
return oe_base;
|
||||
}
|
||||
|
||||
extern "C" const void* __oe_get_heap_end()
|
||||
{
|
||||
return oe_end;
|
||||
}
|
||||
|
||||
extern "C" void* oe_memset_s(void* p, size_t p_size, int c, size_t size)
|
||||
{
|
||||
UNUSED(p_size);
|
||||
@@ -43,8 +31,9 @@ int main()
|
||||
// For 1MiB superslabs, SUPERSLAB_BITS + 4 is not big enough for the example.
|
||||
size_t large_class = 28 - SUPERSLAB_BITS;
|
||||
size_t size = 1ULL << (SUPERSLAB_BITS + large_class);
|
||||
oe_base = mp.reserve<true>(large_class);
|
||||
oe_end = (uint8_t*)oe_base + size;
|
||||
void* oe_base = mp.reserve<true>(large_class);
|
||||
void* oe_end = (uint8_t*)oe_base + size;
|
||||
PALOpenEnclave::setup_initial_range(oe_base, oe_end);
|
||||
std::cout << "Allocated region " << oe_base << " - " << oe_end << std::endl;
|
||||
|
||||
auto a = ThreadAlloc::get();
|
||||
|
||||
@@ -9,3 +9,8 @@
|
||||
// Redefine the namespace, so we can have two versions.
|
||||
#define snmalloc snmalloc_enclave
|
||||
#include "../../../override/malloc.cc"
|
||||
|
||||
extern "C" void oe_allocator_init(void* base, void* end)
|
||||
{
|
||||
snmalloc_enclave::PALOpenEnclave::setup_initial_range(base, end);
|
||||
}
|
||||
|
||||
@@ -5,18 +5,6 @@
|
||||
#include <string.h>
|
||||
#include <test/setup.h>
|
||||
|
||||
void* oe_base;
|
||||
void* oe_end;
|
||||
extern "C" const void* __oe_get_heap_base()
|
||||
{
|
||||
return oe_base;
|
||||
}
|
||||
|
||||
extern "C" const void* __oe_get_heap_end()
|
||||
{
|
||||
return oe_end;
|
||||
}
|
||||
|
||||
extern "C" void* oe_memset_s(void* p, size_t p_size, int c, size_t size)
|
||||
{
|
||||
UNUSED(p_size);
|
||||
@@ -28,6 +16,7 @@ extern "C" void oe_abort()
|
||||
abort();
|
||||
}
|
||||
|
||||
extern "C" void oe_allocator_init(void* base, void* end);
|
||||
extern "C" void* host_malloc(size_t);
|
||||
extern "C" void host_free(void*);
|
||||
|
||||
@@ -51,8 +40,9 @@ int main()
|
||||
// For 1MiB superslabs, SUPERSLAB_BITS + 2 is not big enough for the example.
|
||||
size_t large_class = 26 - SUPERSLAB_BITS;
|
||||
size_t size = 1ULL << (SUPERSLAB_BITS + large_class);
|
||||
oe_base = mp.reserve<true>(large_class);
|
||||
oe_end = (uint8_t*)oe_base + size;
|
||||
void* oe_base = mp.reserve<true>(large_class);
|
||||
void* oe_end = (uint8_t*)oe_base + size;
|
||||
oe_allocator_init(oe_base, oe_end);
|
||||
std::cout << "Allocated region " << oe_base << " - " << oe_end << std::endl;
|
||||
|
||||
// Call these functions to trigger asserts if the cast-to-self doesn't work.
|
||||
|
||||
Reference in New Issue
Block a user