diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 692223a..efd7d4e 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -101,7 +101,7 @@ namespace snmalloc public: /** - * Construtor. Accesses the pagemap via the C ABI accessor and casts it to + * Constructor. Accesses the pagemap via the C ABI accessor and casts it to * the expected type, failing in cases of ABI mismatch. */ ExternalGlobalPagemap() diff --git a/src/mem/pagemap.h b/src/mem/pagemap.h index 75f786f..d635e4f 100644 --- a/src/mem/pagemap.h +++ b/src/mem/pagemap.h @@ -30,6 +30,10 @@ namespace snmalloc * hierarchical structure. */ bool is_flat_pagemap; + /** + * Number of bytes in a pointer. + */ + uint8_t sizeof_pointer; /** * The number of bits of the address used to index into the pagemap. */ @@ -202,7 +206,7 @@ namespace snmalloc * The pagemap configuration describing this instantiation of the template. */ static constexpr PagemapConfig config = { - 1, false, GRANULARITY_BITS, sizeof(T)}; + 1, false, sizeof(void*), GRANULARITY_BITS, sizeof(T)}; /** * Cast a `void*` to a pointer to this template instantiation, given a @@ -216,6 +220,7 @@ namespace snmalloc { if ( (c->version != 1) || (c->is_flat_pagemap) || + (c->sizeof_pointer == sizeof(void*)) || (c->pagemap_bits != GRANULARITY_BITS) || (c->size_of_entry != sizeof(T)) || (!std::is_integral_v)) { @@ -306,7 +311,7 @@ namespace snmalloc * The pagemap configuration describing this instantiation of the template. */ static constexpr PagemapConfig config = { - 1, true, GRANULARITY_BITS, sizeof(T)}; + 1, true, sizeof(void*), GRANULARITY_BITS, sizeof(T)}; /** * Cast a `void*` to a pointer to this template instantiation, given a @@ -320,6 +325,7 @@ namespace snmalloc { if ( (c->version != 1) || (!c->is_flat_pagemap) || + (c->sizeof_pointer == sizeof(void*)) || (c->pagemap_bits != GRANULARITY_BITS) || (c->size_of_entry != sizeof(T)) || (!std::is_integral_v)) { diff --git a/src/test/func/two_alloc_types/main.cc b/src/test/func/two_alloc_types/main.cc index baf22b3..a29a357 100644 --- a/src/test/func/two_alloc_types/main.cc +++ b/src/test/func/two_alloc_types/main.cc @@ -48,8 +48,9 @@ int main() 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_pagemap_global_get(nullptr); - host_snmalloc_pagemap_global_get(nullptr); + PagemapConfig *c; + enclave_snmalloc_pagemap_global_get(&c); + host_snmalloc_pagemap_global_get(&c); auto a = host_malloc(128); auto b = enclave_malloc(128);