From 386e968ccb08bdd763e1915eafc39d8fb9df2226 Mon Sep 17 00:00:00 2001 From: "Zheng, Qi" Date: Sun, 29 Jan 2023 10:52:47 +0800 Subject: [PATCH] [libos] Enable backtrace for memory allocation failure --- src/libos/src/entry.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libos/src/entry.rs b/src/libos/src/entry.rs index 568896b1..4196f06b 100644 --- a/src/libos/src/entry.rs +++ b/src/libos/src/entry.rs @@ -103,6 +103,9 @@ pub extern "C" fn occlum_ecall_init( // Enable global backtrace unsafe { backtrace::enable_backtrace(&ENCLAVE_PATH, PrintFormat::Short) }; + + // Add hook for allocation error + std::alloc::set_alloc_error_hook(oom_handle); }); // Parse host file @@ -149,6 +152,11 @@ pub extern "C" fn occlum_ecall_init( 0 } +// hook for memory allocation error +fn oom_handle(layout: std::alloc::Layout) { + panic!("memory allocation of {} bytes failed\n", layout.size()); +} + #[no_mangle] pub extern "C" fn occlum_ecall_new_process( path_buf: *const c_char,