diff --git a/src/test/func/two_alloc_types/alloc1.cc b/src/test/func/two_alloc_types/alloc1.cc new file mode 100644 index 00000000..f7333e43 --- /dev/null +++ b/src/test/func/two_alloc_types/alloc1.cc @@ -0,0 +1,10 @@ +#undef IS_ADDRESS_SPACE_CONSTRAINED +#define OPEN_ENCLAVE +#define OPEN_ENCLAVE_SIMULATION +#define USE_RESERVE_MULTIPLE 1 +#define NO_BOOTSTRAP_ALLOCATOR +#define IS_ADDRESS_SPACE_CONSTRAINED +#define SNMALLOC_NAME_MANGLE(a) enclave_##a +// Redefine the namespace, so we can have two versions. +#define snmalloc snmalloc_enclave +#include "../../../override/malloc.cc" diff --git a/src/test/func/two_alloc_types/alloc2.cc b/src/test/func/two_alloc_types/alloc2.cc new file mode 100644 index 00000000..f3a151be --- /dev/null +++ b/src/test/func/two_alloc_types/alloc2.cc @@ -0,0 +1,6 @@ +#undef IS_ADDRESS_SPACE_CONSTRAINED +#define SNMALLOC_NAME_MANGLE(a) host_##a +#define NO_BOOTSTRAP_ALLOCATOR +// Redefine the namespace, so we can have two versions. +#define snmalloc snmalloc_host +#include "../../../override/malloc.cc" \ No newline at end of file diff --git a/src/test/func/two_alloc_types/main.cc b/src/test/func/two_alloc_types/main.cc new file mode 100644 index 00000000..f34ee6d6 --- /dev/null +++ b/src/test/func/two_alloc_types/main.cc @@ -0,0 +1,53 @@ +#include "../../../snmalloc.h" + +#include +#include +#include + +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(void* p, int c, size_t size) +{ + return memset(p, c, size); +} + +extern "C" void oe_abort() +{ + abort(); +} + +extern "C" void* host_malloc(size_t); +extern "C" void host_free(void*); + +extern "C" void* enclave_malloc(size_t); +extern "C" void enclave_free(void*); + +using namespace snmalloc; +int main() +{ + DefaultPal pal; + + size_t size = 1ULL << 28; + oe_base = pal.reserve(&size, 0); + oe_end = (uint8_t*)oe_base + size; + std::cout << "Allocated region " << oe_base << " - " << oe_end << std::endl; + + auto a = host_malloc(128); + auto b = enclave_malloc(128); + + std::cout << "Host alloc " << a << std::endl; + std::cout << "Enclave alloc " << b << std::endl; + + host_free(a); + enclave_free(b); +}