Skip to content

Commit

Permalink
add panic-logging feature to enclave-runtime crate
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Nov 18, 2024
1 parent d6ebfb5 commit e99cbd3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions enclave-modules/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
9 changes: 6 additions & 3 deletions enclave-modules/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit e99cbd3

Please sign in to comment.