diff --git a/Cargo.lock b/Cargo.lock index 7b091b80d..42b4d99bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4225,7 +4225,6 @@ dependencies = [ "idol", "idol-runtime", "lib-dice", - "mutable-statics", "num-traits", "ringbuf", "salty", @@ -4233,6 +4232,7 @@ dependencies = [ "serde_with 3.6.1", "sha3", "stage0-handoff", + "static-cell", "unwrap-lite", "userlib", "zerocopy 0.6.6", diff --git a/task/attest/Cargo.toml b/task/attest/Cargo.toml index 8a0772e28..9055c92f3 100644 --- a/task/attest/Cargo.toml +++ b/task/attest/Cargo.toml @@ -8,13 +8,13 @@ arrayvec.workspace = true lib-dice = { path = "../../lib/dice" } hubpack = { workspace = true } idol-runtime = { workspace = true } -mutable-statics = { path = "../../lib/mutable-statics" } num-traits = { workspace = true } ringbuf = { path = "../../lib/ringbuf" } salty.workspace = true serde = { workspace = true } serde_with = { version = "3.3.0", default-features = false, features = ["macros"] } stage0-handoff = { path = "../../lib/stage0-handoff" } +static-cell = { path = "../../lib/static-cell" } attest-api = { path = "../attest-api" } attest-data.workspace = true sha3.workspace = true diff --git a/task/attest/src/main.rs b/task/attest/src/main.rs index 94bafd003..704a160b2 100644 --- a/task/attest/src/main.rs +++ b/task/attest/src/main.rs @@ -89,11 +89,19 @@ struct AttestServer { cert_data: Option, measurements: Log, } - -impl Default for AttestServer { - fn default() -> Self { - static LOG_BUF: ClaimOnceCell<[u8; Log::MAX_SIZE]> = - ClaimOnceCell::new([0; Log::MAX_SIZE]); +impl AttestServer { + /// Claims static resources and loads data. + // + /// # Panics + /// + /// This function panics if called more than once. + fn claim_static_resources() -> Self { + let buf = { + use static_cell::ClaimOnceCell; + static LOG_BUF: ClaimOnceCell<[u8; Log::MAX_SIZE]> = + ClaimOnceCell::new([0; Log::MAX_SIZE]); + LOG_BUF.claim() + }; let alias_data: Option = load_data_from_region(&ALIAS_DATA); let alias_keypair = alias_data @@ -103,14 +111,12 @@ impl Default for AttestServer { Self { alias_data, alias_keypair, - buf: LOG_BUF.claim(), + buf, cert_data: load_data_from_region(&CERT_DATA), measurements: Log::default(), } } -} -impl AttestServer { fn get_cert_bytes_from_index( &self, index: u32, @@ -396,7 +402,7 @@ fn main() -> ! { ringbuf_entry!(Trace::Startup); let mut buffer = [0; idl::INCOMING_SIZE]; - let mut attest = AttestServer::default(); + let mut attest = AttestServer::claim_static_resources(); loop { idol_runtime::dispatch(&mut buffer, &mut attest); }