From e99cbd3542c0e0d463b9d6e1423cb82b42b556fc Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 18 Nov 2024 23:03:15 +0900 Subject: [PATCH] add `panic-logging` feature to `enclave-runtime` crate Signed-off-by: Jun Kimura --- enclave-modules/runtime/Cargo.toml | 4 ++++ enclave-modules/runtime/src/lib.rs | 9 ++++++--- enclave/Cargo.toml | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/enclave-modules/runtime/Cargo.toml b/enclave-modules/runtime/Cargo.toml index 0a251ceb..2a6f0566 100644 --- a/enclave-modules/runtime/Cargo.toml +++ b/enclave-modules/runtime/Cargo.toml @@ -17,3 +17,7 @@ host-api = { path = "../host-api" } ecall-handler = { path = "../ecall-handler" } enclave-environment = { path = "../environment" } ecall-commands = { path = "../../modules/ecall-commands", default-features = false } + +[features] +default = [] +panic-logging = [] diff --git a/enclave-modules/runtime/src/lib.rs b/enclave-modules/runtime/src/lib.rs index 0ea01fcd..56907096 100644 --- a/enclave-modules/runtime/src/lib.rs +++ b/enclave-modules/runtime/src/lib.rs @@ -31,12 +31,15 @@ mod errors; static ALLOC: sgx_alloc::System = sgx_alloc::System; #[cfg(not(test))] +#[allow(unused_variables)] #[panic_handler] fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! { + #[cfg(feature = "panic-logging")] + let msg = alloc::format!("[enclave] panic: {:?}\n", info).into_bytes(); + #[cfg(not(feature = "panic-logging"))] + let msg = alloc::format!("[enclave] panic\n").into_bytes(); let _ = host_api::api::execute_command(host_api::ocall_commands::Command::Log( - host_api::ocall_commands::LogCommand { - msg: alloc::format!("[enclave] panic: {:?}\n", info).into_bytes(), - }, + host_api::ocall_commands::LogCommand { msg }, )); sgx_abort(); } diff --git a/enclave/Cargo.toml b/enclave/Cargo.toml index d7b4893d..701282b7 100644 --- a/enclave/Cargo.toml +++ b/enclave/Cargo.toml @@ -9,7 +9,10 @@ name = "proxy_enclave" crate-type = ["staticlib"] [features] -default = [] +default = ["panic-logging"] +panic-logging = [ + "enclave-runtime/panic-logging", +] [dependencies] enclave-runtime = { path = "../enclave-modules/runtime" }