Skip to content

Commit 360dddb

Browse files
committed
undind
1 parent 80cef20 commit 360dddb

File tree

9 files changed

+41
-35
lines changed

9 files changed

+41
-35
lines changed

compiler/rustc_target/src/spec/base/hermit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) fn opts() -> TargetOptions {
99
position_independent_executables: true,
1010
static_position_independent_executables: true,
1111
has_thread_local: true,
12-
panic_strategy: PanicStrategy::Abort,
12+
panic_strategy: PanicStrategy::Unwind,
1313
..Default::default()
1414
}
1515
}

compiler/rustc_target/src/spec/targets/x86_64_unknown_hermit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{StackProbeType, Target, TargetOptions, base};
1+
use crate::spec::{Target, TargetOptions, base};
22

33
pub(crate) fn target() -> Target {
44
Target {
@@ -18,7 +18,6 @@ pub(crate) fn target() -> Target {
1818
features: "+rdrnd,+rdseed".into(),
1919
plt_by_default: false,
2020
max_atomic_width: Some(64),
21-
stack_probes: StackProbeType::Inline,
2221
..base::hermit::opts()
2322
},
2423
}

library/panic_unwind/src/hermit.rs

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

library/panic_unwind/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ cfg_if::cfg_if! {
3434
if #[cfg(target_os = "emscripten")] {
3535
#[path = "emcc.rs"]
3636
mod imp;
37-
} else if #[cfg(target_os = "hermit")] {
38-
#[path = "hermit.rs"]
39-
mod imp;
4037
} else if #[cfg(target_os = "l4re")] {
4138
// L4Re is unix family but does not yet support unwinding.
4239
#[path = "dummy.rs"]
@@ -45,6 +42,7 @@ cfg_if::cfg_if! {
4542
all(target_family = "windows", target_env = "gnu"),
4643
target_os = "psp",
4744
target_os = "xous",
45+
target_os = "hermit",
4846
target_os = "solid_asp3",
4947
all(target_family = "unix", not(any(target_os = "espidf", target_os = "rtems", target_os = "nuttx"))),
5048
all(target_vendor = "fortanix", target_env = "sgx"),

library/std/src/sys/pal/hermit/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,40 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
7373
// NOTE: this is not guaranteed to run, for example when the program aborts.
7474
pub unsafe fn cleanup() {}
7575

76+
mod eh_unwinding {
77+
pub(crate) struct EhFrameFinder;
78+
// pub(crate) static mut EH_FRAME_ADDRESS: usize = 0;
79+
extern "C" {
80+
static mut EH_FRAME_ADDRESS: usize;
81+
}
82+
pub(crate) static EH_FRAME_SETTINGS: EhFrameFinder = EhFrameFinder;
83+
84+
unsafe impl unwind::EhFrameFinder for EhFrameFinder {
85+
fn find(&self, _pc: usize) -> Option<unwind::FrameInfo> {
86+
if unsafe { EH_FRAME_ADDRESS == 0 } {
87+
None
88+
} else {
89+
Some(unwind::FrameInfo {
90+
text_base: None,
91+
kind: unwind::FrameInfoKind::EhFrame(unsafe { EH_FRAME_ADDRESS }),
92+
})
93+
}
94+
}
95+
}
96+
}
97+
7698
#[cfg(not(test))]
7799
#[no_mangle]
78100
pub unsafe extern "C" fn runtime_entry(
79101
argc: i32,
80102
argv: *const *const c_char,
81103
env: *const *const c_char,
82104
) -> ! {
105+
{
106+
// unsafe { eh_unwinding::EH_FRAME_ADDRESS = 0x1200000 + 0x4c008 };
107+
unwind::set_custom_eh_frame_finder(&eh_unwinding::EH_FRAME_SETTINGS).ok();
108+
}
109+
83110
extern "C" {
84111
fn main(argc: isize, argv: *const *const c_char) -> i32;
85112
}

library/std/src/sys/personality/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ cfg_if::cfg_if! {
2929
} else if #[cfg(any(
3030
all(target_family = "windows", target_env = "gnu"),
3131
target_os = "psp",
32+
target_os = "hermit",
3233
target_os = "xous",
3334
target_os = "solid_asp3",
3435
all(target_family = "unix", not(target_os = "espidf"), not(target_os = "l4re"), not(target_os = "rtems"), not(target_os = "nuttx")),
@@ -40,7 +41,6 @@ cfg_if::cfg_if! {
4041
// - os=none ("bare metal" targets)
4142
// - os=uefi
4243
// - os=espidf
43-
// - os=hermit
4444
// - nvptx64-nvidia-cuda
4545
// - arch=avr
4646
}

library/unwind/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cfg-if = "1.0"
2121
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
2222
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }
2323

24-
[target.'cfg(target_os = "xous")'.dependencies]
24+
[target.'cfg(any(target_os = "hermit", target_os = "xous"))'.dependencies]
2525
unwinding = { version = "0.2.3", features = ['rustc-dep-of-std', 'unwinder', 'fde-custom'], default-features = false }
2626

2727
[features]

library/unwind/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ cfg_if::cfg_if! {
3333
))] {
3434
mod libunwind;
3535
pub use libunwind::*;
36-
} else if #[cfg(target_os = "xous")] {
36+
} else if #[cfg(any(
37+
target_os = "hermit",
38+
target_os = "xous",
39+
))] {
3740
mod unwinding;
3841
pub use unwinding::*;
3942
} else if #[cfg(target_family = "wasm")] {
@@ -42,7 +45,6 @@ cfg_if::cfg_if! {
4245
} else {
4346
// no unwinder on the system!
4447
// - os=none ("bare metal" targets)
45-
// - os=hermit
4648
// - os=uefi
4749
// - os=cuda
4850
// - nvptx64-nvidia-cuda

library/unwind/src/libunwind.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub type _Unwind_Exception_Cleanup_Fn =
105105
any(
106106
all(
107107
feature = "llvm-libunwind",
108-
any(target_os = "fuchsia", target_os = "linux", target_os = "xous")
108+
any(target_os = "fuchsia", target_os = "linux", target_os = "hermit", target_os = "xous")
109109
),
110110
all(target_os = "windows", target_env = "gnu", target_abi = "llvm")
111111
),
@@ -140,7 +140,7 @@ if #[cfg(any(target_vendor = "apple", target_os = "netbsd", not(target_arch = "a
140140
pub use _Unwind_Action::*;
141141

142142
#[cfg_attr(
143-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
143+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "hermit", target_os = "xous")),
144144
link(name = "unwind", kind = "static", modifiers = "-bundle")
145145
)]
146146
extern "C" {
@@ -198,7 +198,7 @@ if #[cfg(any(target_vendor = "apple", target_os = "netbsd", not(target_arch = "a
198198
pub const UNWIND_IP_REG: c_int = 15;
199199

200200
#[cfg_attr(
201-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
201+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "hermit", target_os = "xous")),
202202
link(name = "unwind", kind = "static", modifiers = "-bundle")
203203
)]
204204
extern "C" {
@@ -271,14 +271,14 @@ if #[cfg(all(target_vendor = "apple", not(target_os = "watchos"), target_arch =
271271
pub use _Unwind_SjLj_RaiseException as _Unwind_RaiseException;
272272
} else {
273273
#[cfg_attr(
274-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
274+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "hermit", target_os = "xous")),
275275
link(name = "unwind", kind = "static", modifiers = "-bundle")
276276
)]
277277
extern "C-unwind" {
278278
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
279279
}
280280
#[cfg_attr(
281-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
281+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "hermit", target_os = "xous")),
282282
link(name = "unwind", kind = "static", modifiers = "-bundle")
283283
)]
284284
extern "C" {

0 commit comments

Comments
 (0)