vmbase: Provide baremetal DiceClearMemory() as lib
As libdiced_open_dice_nostd has a missing symbol, DiceClearMemory(),
that must be provided at link time, export it for all (baremetal)
clients of vmbase as a static library to be linked into their
final executable.
Link it into pvmfw and Rialto and remove their duped implementations.
Bug: 357008987
Test: m libvmbase_dice_clear_memory pvmfw_bin rialto_bin
Change-Id: I8d28e0ec11e1407c71de3e8f5c75069389151141
diff --git a/guest/pvmfw/Android.bp b/guest/pvmfw/Android.bp
index cd09579..5c767a3 100644
--- a/guest/pvmfw/Android.bp
+++ b/guest/pvmfw/Android.bp
@@ -277,6 +277,7 @@
],
static_libs: [
"libpvmfw",
+ "libvmbase_dice_clear_memory",
],
linker_scripts: [
"image.ld",
diff --git a/guest/pvmfw/src/dice.rs b/guest/pvmfw/src/dice.rs
index 470711f..f3a2337 100644
--- a/guest/pvmfw/src/dice.rs
+++ b/guest/pvmfw/src/dice.rs
@@ -169,29 +169,6 @@
}
}
-/// 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]
-#[cfg(not(test))]
-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)
-}
-
#[cfg(test)]
mod tests {
use crate::{
diff --git a/guest/rialto/Android.bp b/guest/rialto/Android.bp
index 8afb8ba..a525168 100644
--- a/guest/rialto/Android.bp
+++ b/guest/rialto/Android.bp
@@ -35,6 +35,7 @@
],
static_libs: [
"librialto",
+ "libvmbase_dice_clear_memory",
],
linker_scripts: [
"image.ld",
diff --git a/guest/rialto/src/main.rs b/guest/rialto/src/main.rs
index 244010d..0b79e1e 100644
--- a/guest/rialto/src/main.rs
+++ b/guest/rialto/src/main.rs
@@ -199,28 +199,6 @@
}
}
-/// 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);