diff --git a/example_allocators/compartment_alloc/compartment_alloc.c b/example_allocators/compartment_alloc/compartment_alloc.c index 678a5a9..ae6f423 100644 --- a/example_allocators/compartment_alloc/compartment_alloc.c +++ b/example_allocators/compartment_alloc/compartment_alloc.c @@ -90,11 +90,9 @@ void *__capability malloc_compartment(size_t len, void *__capability compartment compartment.bytes_allocated = new_allocated; // We allocated some space! - // Create a capability pointing to it and return it. - // The capability is bounded by the data capability for this compartment. - allocated = cheri_cap_build((void *__capability) addr, (__uintcap_t) compartment.datacap); - allocated = cheri_address_set( - allocated, (long) addr); // not sure why this is necessary...cheri_cap_build should do this + // Create a capability pointing to it and return that. + // The capability inherits the metadata of data capability for this compartment. + allocated = cheri_address_set(compartment.datacap, (long) addr); allocated = cheri_bounds_set_exact(allocated, rounded_length); return allocated;