Rename heap_claim_fast.
diff --git a/examples/04.temporal_safety/allocate.cc b/examples/04.temporal_safety/allocate.cc index b2cb79b..71c736f 100644 --- a/examples/04.temporal_safety/allocate.cc +++ b/examples/04.temporal_safety/allocate.cc
@@ -84,9 +84,9 @@ Debug::log("heap quota: {}", heap_quota_remaining(MALLOC_CAPABILITY)); } - // Sub object with a fast claim + // Sub object with an ephemeral claim { - Debug::log("----- Sub object with a fast claim -----"); + Debug::log("----- Sub object with an ephemeral claim -----"); void *x = malloc(100); CHERI::Capability y{x}; @@ -96,12 +96,12 @@ Debug::log("Sub Object: {}", y); Debug::log("heap quota: {}", heap_quota_remaining(MALLOC_CAPABILITY)); - // Add a fast claim for y + // Add an ephemeral claim for y Timeout t{10}; - heap_claim_fast(&t, y); + heap_claim_ephemeral(&t, y); // In this freeing x will invalidate both x & y because free - // is a cross compartment call, which releases any fast claims. + // is a cross compartment call, which releases any ephemeral claims. free(x); Debug::log("After free"); Debug::log("Allocated : {}", x); @@ -119,7 +119,7 @@ Debug::log("Allocated : {}", x); Debug::log("heap quota: {}", heap_quota_remaining(MALLOC_CAPABILITY)); - // Get the claimant compartment to make a fast claim + // Get the claimant compartment to make a ephemeral claim make_claim(x); // free x. We get out quota back but x remains valid as
diff --git a/sdk/include/platform/arty-a7/platform-ethernet.hh b/sdk/include/platform/arty-a7/platform-ethernet.hh index 5cd3784..d568178 100644 --- a/sdk/include/platform/arty-a7/platform-ethernet.hh +++ b/sdk/include/platform/arty-a7/platform-ethernet.hh
@@ -755,7 +755,7 @@ // does not check the pointer which is coming from external // untrusted components. Timeout t{10}; - if ((heap_claim_fast(&t, buffer) < 0) || + if ((heap_claim_ephemeral(&t, buffer) < 0) || (!CHERI::check_pointer<CHERI::PermissionSet{ CHERI::Permission::Load}>(buffer, length))) {
diff --git a/sdk/include/platform/sunburst/platform-ethernet.hh b/sdk/include/platform/sunburst/platform-ethernet.hh index 017810c..8e69319 100644 --- a/sdk/include/platform/sunburst/platform-ethernet.hh +++ b/sdk/include/platform/sunburst/platform-ethernet.hh
@@ -734,7 +734,7 @@ // does not check the pointer which is coming from external // untrusted components. Timeout t{10}; - if ((heap_claim_fast(&t, buffer) < 0) || + if ((heap_claim_ephemeral(&t, buffer) < 0) || (!CHERI::check_pointer<CHERI::PermissionSet{ CHERI::Permission::Load}>(buffer, length))) {
diff --git a/sdk/include/stdlib.h b/sdk/include/stdlib.h index 183b0a3..83a2da0 100644 --- a/sdk/include/stdlib.h +++ b/sdk/include/stdlib.h
@@ -113,32 +113,33 @@ } } -enum [[clang::flag_enum]] AllocateWaitFlags{ - /** - * Non-blocking mode. This is equivalent to passing a timeout with no time - * remaining. - */ - AllocateWaitNone = 0, - /** - * If there is enough memory in the quarantine to fulfil the allocation, wait - * for the revoker to free objects from the quarantine. - */ - AllocateWaitRevocationNeeded = (1 << 0), - /** - * If the quota of the passed heap capability is exceeded, wait for other - * threads to free allocations. - */ - AllocateWaitQuotaExceeded = (1 << 1), - /** - * If the heap memory is exhausted, wait for any other thread of the system - * to free allocations. - */ - AllocateWaitHeapFull = (1 << 2), - /** - * Block on any of the above reasons. This is the default behavior. - */ - AllocateWaitAny = (AllocateWaitRevocationNeeded | AllocateWaitQuotaExceeded | - AllocateWaitHeapFull), +enum [[clang::flag_enum]] AllocateWaitFlags +{ + /** + * Non-blocking mode. This is equivalent to passing a timeout with no time + * remaining. + */ + AllocateWaitNone = 0, + /** + * If there is enough memory in the quarantine to fulfil the allocation, + * wait for the revoker to free objects from the quarantine. + */ + AllocateWaitRevocationNeeded = (1 << 0), + /** + * If the quota of the passed heap capability is exceeded, wait for other + * threads to free allocations. + */ + AllocateWaitQuotaExceeded = (1 << 1), + /** + * If the heap memory is exhausted, wait for any other thread of the system + * to free allocations. + */ + AllocateWaitHeapFull = (1 << 2), + /** + * Block on any of the above reasons. This is the default behavior. + */ + AllocateWaitAny = (AllocateWaitRevocationNeeded | + AllocateWaitQuotaExceeded | AllocateWaitHeapFull), }; /** @@ -236,9 +237,19 @@ * This function is provided by the compartment_helpers library, which must be * linked for it to be available. */ -int __cheri_libcall heap_claim_fast(Timeout *timeout, - const void *ptr, - const void *ptr2 __if_cxx(= nullptr)); +int __cheri_libcall heap_claim_ephemeral(Timeout *timeout, + const void *ptr, + const void *ptr2 __if_cxx(= nullptr)); + +__attribute__((deprecated("heap_claim_fast was a bad name. This function has " + "been renamed heap_claim_ephemeral"))) +__always_inline static int +heap_claim_fast(Timeout *timeout, + const void *ptr, + const void *ptr2 __if_cxx(= nullptr)) +{ + return heap_claim_ephemeral(timeout, ptr, ptr2); +} /** * Free a heap allocation. @@ -341,7 +352,7 @@ { Timeout t = {0, MALLOC_WAIT_TICKS}; void *ptr = heap_allocate_array( - &t, MALLOC_CAPABILITY, nmemb, size, AllocateWaitRevocationNeeded); + &t, MALLOC_CAPABILITY, nmemb, size, AllocateWaitRevocationNeeded); if (!__builtin_cheri_tag_get(ptr)) { ptr = NULL;
diff --git a/sdk/lib/compartment_helpers/claim_fast.cc b/sdk/lib/compartment_helpers/claim_fast.cc index 8d93a7a..0c33205 100644 --- a/sdk/lib/compartment_helpers/claim_fast.cc +++ b/sdk/lib/compartment_helpers/claim_fast.cc
@@ -7,7 +7,7 @@ #include <stdlib.h> #include <switcher.h> -int heap_claim_fast(Timeout *timeout, const void *ptr, const void *ptr2) +int heap_claim_ephemeral(Timeout *timeout, const void *ptr, const void *ptr2) { void **hazards = switcher_thread_hazard_slots(); auto *epochCounter{const_cast<
diff --git a/tests/allocator-test.cc b/tests/allocator-test.cc index 52ad944..80d5893 100644 --- a/tests/allocator-test.cc +++ b/tests/allocator-test.cc
@@ -465,7 +465,7 @@ static cheriot::atomic<int> state = 0; async([=]() { Timeout t{1}; - int claimed = heap_claim_fast(&t, ptr, ptr2); + int claimed = heap_claim_ephemeral(&t, ptr, ptr2); TEST(claimed == 0, "Heap claim failed: {}", claimed); state = 1; while (state.load() == 1) {}