Remove lib_open_dice_cbor dependency from nostd open-dice library
This cl adds the DiceMemoryClear to rialto.
This enables the removal of the lib_open_dice_cbor dependency
from libdiced_open_dice_nostd, as rialto no longer needs the
DiceMemoryClear implementation from lib_open_dice_cbor.
Test: atest libdiced_open_dice_nostd.integration_test
Test: m rialto_bin
Bug: 349524984
Change-Id: Iaa6ff88c1c5b58c45a41ff21902a4f9029137806
diff --git a/guest/rialto/src/main.rs b/guest/rialto/src/main.rs
index a98ec25..604f935 100644
--- a/guest/rialto/src/main.rs
+++ b/guest/rialto/src/main.rs
@@ -233,6 +233,28 @@
}
}
+/// Flushes data caches over the provided address range.
+///
+/// # Safety
+///
+/// The provided address and size must be to an address range that is valid for read and write
+/// (typically on the stack, .bss, .data, or provided BCC) from a single allocation
+/// (e.g. stack array).
+#[no_mangle]
+unsafe extern "C" fn DiceClearMemory(
+ _ctx: *mut core::ffi::c_void,
+ size: usize,
+ addr: *mut core::ffi::c_void,
+) {
+ use core::slice;
+ use vmbase::memory::flushed_zeroize;
+
+ // SAFETY: We require our caller to provide a valid range within a single object. The open-dice
+ // always calls this on individual stack-allocated arrays which ensures that.
+ let region = unsafe { slice::from_raw_parts_mut(addr as *mut u8, size) };
+ flushed_zeroize(region)
+}
+
generate_image_header!();
main!(main);
configure_heap!(SIZE_128KB * 2);