Skip to content

Commit 97b15d9

Browse files
committed
std: xous: take eh_frame address from main args
The main() function takes an argument that contains the eh_frame address. Implement `unwinding` support by looking for unwinding data at this address. Signed-off-by: Sean Cross <[email protected]>
1 parent b62c547 commit 97b15d9

File tree

1 file changed

+30
-1
lines changed
  • library/std/src/sys/xous

1 file changed

+30
-1
lines changed

library/std/src/sys/xous/os.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ use crate::marker::PhantomData;
77
use crate::os::xous::ffi::Error as XousError;
88
use crate::path::{self, PathBuf};
99

10+
#[cfg(not(test))]
11+
#[cfg(feature = "panic_unwind")]
12+
mod eh_unwinding {
13+
pub(crate) struct EhFrameFinder(usize /* eh_frame */);
14+
pub(crate) static mut EH_FRAME_SETTINGS: EhFrameFinder = EhFrameFinder(0);
15+
impl EhFrameFinder {
16+
pub(crate) unsafe fn init(&mut self, eh_frame: usize) {
17+
unsafe {
18+
EH_FRAME_SETTINGS.0 = eh_frame;
19+
}
20+
}
21+
}
22+
unsafe impl unwind::EhFrameFinder for EhFrameFinder {
23+
fn find(&self, _pc: usize) -> Option<unwind::FrameInfo> {
24+
Some(unwind::FrameInfo {
25+
text_base: None,
26+
kind: unwind::FrameInfoKind::EhFrame(self.0),
27+
})
28+
}
29+
}
30+
}
31+
1032
#[cfg(not(test))]
1133
mod c_compat {
1234
use crate::os::xous::ffi::exit;
@@ -20,7 +42,14 @@ mod c_compat {
2042
}
2143

2244
#[no_mangle]
23-
pub extern "C" fn _start() {
45+
pub extern "C" fn _start(eh_frame: usize) {
46+
#[cfg(feature = "panic_unwind")]
47+
unsafe {
48+
super::eh_unwinding::EH_FRAME_SETTINGS.init(eh_frame);
49+
println!("Setting custom eh frame finder");
50+
unwind::set_custom_eh_frame_finder(&super::eh_unwinding::EH_FRAME_SETTINGS).ok();
51+
}
52+
crate::println!("About to enter main()");
2453
exit(unsafe { main() });
2554
}
2655

0 commit comments

Comments
 (0)