Skip to content

Commit 1b0113c

Browse files
committed
Use heapless crate instead of custom fixed string buffer
for panic string formatting Signed-off-by: adamperlin <[email protected]>
1 parent ea3bcac commit 1b0113c

File tree

8 files changed

+94
-111
lines changed

8 files changed

+94
-111
lines changed

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hyperlight_common/src/fixed_buf.rs

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/hyperlight_common/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,4 @@ pub mod mem;
4141
pub mod outb;
4242

4343
/// cbindgen:ignore
44-
pub mod resource;
45-
46-
pub mod fixed_buf;
44+
pub mod resource;

src/hyperlight_guest_bin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ hyperlight-guest-tracing = { workspace = true, default-features = false }
2727
buddy_system_allocator = "0.11.0"
2828
log = { version = "0.4", default-features = false }
2929
spin = "0.10.0"
30+
heapless = "0.9.1"
3031

3132
[lints]
3233
workspace = true

src/hyperlight_guest_bin/src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use exceptions::{gdt::load_gdt, idtr::load_idt};
2626
use guest_function::call::dispatch_function;
2727
use guest_function::register::GuestFunctionRegister;
2828
use guest_logger::init_logger;
29-
use hyperlight_common::fixed_buf::FixedStringBuf;
29+
use heapless::{String, CString};
3030
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
3131
use hyperlight_common::mem::HyperlightPEB;
3232
#[cfg(feature = "mem_profile")]
@@ -143,7 +143,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
143143
_panic_handler(info)
144144
}
145145

146-
static PANIC_BUF: Mutex<FixedStringBuf<512>> = Mutex::new(FixedStringBuf::new());
146+
static PANIC_BUF: Mutex<String<512>> = Mutex::new(String::<512>::new());
147147

148148
#[inline(always)]
149149
fn _panic_handler(info: &core::panic::PanicInfo) -> ! {
@@ -158,23 +158,22 @@ fn _panic_handler(info: &core::panic::PanicInfo) -> ! {
158158
}
159159
}
160160

161-
// create a CStr from the underlying array in PANIC_BUF using the as_cstr method.
162-
// this wraps CStr::from_bytes_until_nul which takes a borrowed byte slice
163-
// and does not allocate.
164-
let c_string_res = panic_buf_guard.as_c_str();
165-
if c_string_res.is_err() {
161+
let mut c_string: CString<512> = CString::new();
162+
let extend_ok = c_string.extend_from_bytes(panic_buf_guard.as_bytes());
163+
164+
if extend_ok.is_err() {
166165
unsafe {
167166
abort_with_code_and_message(
168167
&[ErrorCode::UnknownError as u8],
169-
c"panic: failed to convert to CStr".as_ptr(),
168+
c"panic: failed to convert to CString".as_ptr(),
170169
)
171170
}
172171
}
173172

174173
unsafe {
175174
abort_with_code_and_message(
176175
&[ErrorCode::UnknownError as u8],
177-
c_string_res.unwrap().as_ptr(),
176+
c_string.as_ptr(),
178177
)
179178
}
180179
}

src/hyperlight_host/tests/integration_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ fn guest_panic_no_alloc() {
552552
(),
553553
)
554554
.unwrap_err();
555-
println!("{:?}", res);
556555

557556
if let HyperlightError::StackOverflow() = res {
558557
panic!("panic on OOM caused stack overflow, this implies allocation in panic handler");

src/tests/rust_guests/callbackguest/Cargo.lock

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tests/rust_guests/simpleguest/Cargo.lock

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)