Add some type safety to other pagemap accesses.

Introduce a descriptor for the pagemap config and check that the source
descriptor is compatible with the destination type.
This commit is contained in:
David Chisnall
2019-04-09 14:59:09 +01:00
parent 51fbdf3a44
commit a93f43fd2f
5 changed files with 79 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
#define USE_RESERVE_MULTIPLE 1
#define NO_BOOTSTRAP_ALLOCATOR
#define IS_ADDRESS_SPACE_CONSTRAINED
#define SNMALLOC_EXPOSE_PAGEMAP
#define SNMALLOC_NAME_MANGLE(a) enclave_##a
// Redefine the namespace, so we can have two versions.
#define snmalloc snmalloc_enclave

View File

@@ -1,6 +1,7 @@
#undef IS_ADDRESS_SPACE_CONSTRAINED
#define SNMALLOC_NAME_MANGLE(a) host_##a
#define NO_BOOTSTRAP_ALLOCATOR
#define SNMALLOC_EXPOSE_PAGEMAP
// Redefine the namespace, so we can have two versions.
#define snmalloc snmalloc_host
#include "../../../override/malloc.cc"
#include "../../../override/malloc.cc"

View File

@@ -32,6 +32,11 @@ extern "C" void host_free(void*);
extern "C" void* enclave_malloc(size_t);
extern "C" void enclave_free(void*);
extern "C" void*
enclave_snmalloc_get_global_pagemap(snmalloc::PagemapConfig const**);
extern "C" void*
host_snmalloc_get_global_pagemap(snmalloc::PagemapConfig const**);
using namespace snmalloc;
int main()
{
@@ -42,6 +47,10 @@ int main()
oe_end = (uint8_t*)oe_base + size;
std::cout << "Allocated region " << oe_base << " - " << oe_end << std::endl;
// Call these functions to trigger asserts if the cast-to-self doesn't work.
enclave_snmalloc_get_global_pagemap(nullptr);
host_snmalloc_get_global_pagemap(nullptr);
auto a = host_malloc(128);
auto b = enclave_malloc(128);