From 454ae39c5dcd31ef80fa189ea866f99e205d2bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=AB=E7=84=9A=20=E5=AF=8C=E8=89=AF?= Date: Wed, 7 Dec 2022 10:41:43 +0800 Subject: [PATCH] firmware: fix crash on exception with host message (#2017) --- artiq/firmware/runtime/session.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index c9d1af4ee..e942d7bd9 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -452,18 +452,22 @@ fn process_kern_message(io: &Io, aux_mutex: &Mutex, let exceptions_with_channel: Vec> = exceptions.iter() .map(|exception| { if let Some(exn) = exception { - let msg = str::from_utf8(unsafe{slice::from_raw_parts(exn.message.as_ptr(), exn.message.len())}) - .unwrap() - .replace("{rtio_channel_info:0}", &format!("{}:{}", exn.param[0], resolve_channel_name(exn.param[0] as u32))); - Some(eh::eh_artiq::Exception { - id: exn.id, - file: exn.file, - line: exn.line, - column: exn.column, - function: exn.function, - message: unsafe {CSlice::new(msg.as_ptr(), msg.len())}, - param: exn.param - }) + if exn.message.len() == usize::MAX { // host string + Some(exn.clone()) + } else { + let msg = str::from_utf8(unsafe { slice::from_raw_parts(exn.message.as_ptr(), exn.message.len()) }) + .unwrap() + .replace("{rtio_channel_info:0}", &format!("{}:{}", exn.param[0], resolve_channel_name(exn.param[0] as u32))); + Some(eh::eh_artiq::Exception { + id: exn.id, + file: exn.file, + line: exn.line, + column: exn.column, + function: exn.function, + message: unsafe { CSlice::new(msg.as_ptr(), msg.len()) }, + param: exn.param, + }) + } } else { None } }) .collect();