Skip to content

Commit baf25b4

Browse files
committed
Avoid recursion in panic! macro.
Based on a patch by Alejandro Martinez Ruiz. Signed-off-by: Piotr Sikora <[email protected]>
1 parent c609755 commit baf25b4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/hostcalls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ extern "C" {
2121
fn proxy_log(level: LogLevel, message_data: *const u8, message_size: usize) -> Status;
2222
}
2323

24+
pub(crate) fn log_noresult(level: LogLevel, message: &str) {
25+
unsafe {
26+
let _ = proxy_log(level, message.as_ptr(), message.len());
27+
}
28+
}
29+
2430
pub fn log(level: LogLevel, message: &str) -> Result<(), Status> {
2531
unsafe {
2632
match proxy_log(level, message.as_ptr(), message.len()) {

src/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn set_log_level(level: LogLevel) {
2626
if !INITIALIZED.load(Ordering::Relaxed) {
2727
log::set_logger(&LOGGER).unwrap();
2828
panic::set_hook(Box::new(|panic_info| {
29-
hostcalls::log(LogLevel::Critical, &panic_info.to_string()).unwrap();
29+
hostcalls::log_noresult(LogLevel::Critical, &panic_info.to_string());
3030
}));
3131
INITIALIZED.store(true, Ordering::Relaxed);
3232
}

0 commit comments

Comments
 (0)