Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
_uwe: uw::_Unwind_Exception {
exception_class: RUST_EXCEPTION_CLASS,
exception_cleanup: Some(exception_cleanup),
private: [core::ptr::null(); uw::unwinder_private_data_size],
private: [core::ptr::null(); _],
},
canary: &CANARY,
cause: data,
Expand Down
3 changes: 0 additions & 3 deletions library/unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.0.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rust.git"
edition = "2024"
include = [
'/libunwind/*',
]

[lib]
test = false
Expand Down
5 changes: 1 addition & 4 deletions library/unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ cfg_select! {
target_os = "solid_asp3",
all(target_vendor = "fortanix", target_env = "sgx"),
all(target_os = "wasi", panic = "unwind"),
target_os = "xous",
) => {
mod libunwind;
pub use libunwind::*;
}
target_os = "xous" => {
mod unwinding;
pub use unwinding::*;
}
target_family = "wasm" => {
mod wasm;
pub use wasm::*;
Expand Down
106 changes: 39 additions & 67 deletions library/unwind/src/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

use core::ffi::{c_int, c_void};

// Use the unwinding crate as unwinder on Xous
#[cfg(target_os = "xous")]
pub use unwinding::custom_eh_frame_finder::{
EhFrameFinder, FrameInfo, FrameInfoKind, set_custom_eh_frame_finder,
};

#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum _Unwind_Reason_Code {
Expand All @@ -24,65 +30,28 @@ pub type _Unwind_Ptr = *const u8;
pub type _Unwind_Trace_Fn =
extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void) -> _Unwind_Reason_Code;

#[cfg(target_arch = "x86")]
pub const unwinder_private_data_size: usize = 5;

#[cfg(all(target_arch = "x86_64", not(any(target_os = "windows", target_os = "cygwin"))))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(all(target_arch = "x86_64", any(target_os = "windows", target_os = "cygwin")))]
pub const unwinder_private_data_size: usize = 6;

#[cfg(all(target_arch = "arm", not(target_vendor = "apple")))]
pub const unwinder_private_data_size: usize = 20;

#[cfg(all(target_arch = "arm", target_vendor = "apple"))]
pub const unwinder_private_data_size: usize = 5;

#[cfg(all(target_arch = "aarch64", target_pointer_width = "64", not(target_os = "windows")))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(all(target_arch = "aarch64", target_pointer_width = "64", target_os = "windows"))]
pub const unwinder_private_data_size: usize = 6;

#[cfg(all(target_arch = "aarch64", target_pointer_width = "32"))]
pub const unwinder_private_data_size: usize = 5;

#[cfg(target_arch = "m68k")]
pub const unwinder_private_data_size: usize = 2;

#[cfg(any(target_arch = "mips", target_arch = "mips32r6"))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(target_arch = "csky")]
pub const unwinder_private_data_size: usize = 2;

#[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(target_arch = "s390x")]
pub const unwinder_private_data_size: usize = 2;

#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(all(target_family = "wasm", target_os = "emscripten"))]
pub const unwinder_private_data_size: usize = 20;

#[cfg(all(target_arch = "wasm32", any(target_os = "linux", target_os = "wasi")))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(target_arch = "hexagon")]
pub const unwinder_private_data_size: usize = 5;

#[cfg(any(target_arch = "loongarch32", target_arch = "loongarch64"))]
pub const unwinder_private_data_size: usize = 2;
pub const unwinder_private_data_size: usize = cfg_select! {
target_arch = "x86" => 5,
all(target_arch = "x86_64", not(any(target_os = "windows", target_os = "cygwin"))) => 2,
all(target_arch = "x86_64", any(target_os = "windows", target_os = "cygwin")) => 6,
all(target_arch = "arm", not(target_vendor = "apple")) => 20,
all(target_arch = "arm", target_vendor = "apple") => 5,
all(target_arch = "aarch64", target_pointer_width = "64", not(target_os = "windows")) => 2,
all(target_arch = "aarch64", target_pointer_width = "64", target_os = "windows") => 6,
all(target_arch = "aarch64", target_pointer_width = "32") => 5,
target_arch = "m68k" => 2,
any(target_arch = "mips", target_arch = "mips32r6") => 2,
target_arch = "csky" => 2,
any(target_arch = "mips64", target_arch = "mips64r6") => 2,
any(target_arch = "powerpc", target_arch = "powerpc64") => 2,
target_arch = "s390x" => 2,
any(target_arch = "sparc", target_arch = "sparc64") => 2,
any(target_arch = "riscv64", target_arch = "riscv32") => 2,
all(target_family = "wasm", target_os = "emscripten") => 20,
all(target_arch = "wasm32", any(target_os = "linux", target_os = "wasi")) => 2,
target_arch = "hexagon" => 5,
any(target_arch = "loongarch32", target_arch = "loongarch64") => 2,
};

#[repr(C)]
pub struct _Unwind_Exception {
Expand All @@ -91,6 +60,12 @@ pub struct _Unwind_Exception {
pub private: [_Unwind_Word; unwinder_private_data_size],
}

// Check the size of _Unwind_Exception against the source of thruth when using the unwinding crate.
#[cfg(target_os = "xous")]
const _: () = {
assert!(size_of::<unwinding::abi::UnwindException>() == size_of::<_Unwind_Exception>());
};

pub enum _Unwind_Context {}

pub type _Unwind_Exception_Cleanup_Fn =
Expand All @@ -105,10 +80,7 @@ pub type _Unwind_Exception_Cleanup_Fn =
// rustc_codegen_ssa::src::back::symbol_export, rustc_middle::middle::exported_symbols
// and RFC 2841
#[cfg_attr(
all(
feature = "llvm-libunwind",
any(target_os = "fuchsia", target_os = "linux", target_os = "xous")
),
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
link(name = "unwind", kind = "static", modifiers = "-bundle")
)]
// Explicitly link the `unwind` library on WASI targets.
Expand Down Expand Up @@ -144,7 +116,7 @@ cfg_select! {
pub const _UA_END_OF_STACK: c_int = 16;

#[cfg_attr(
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
link(name = "unwind", kind = "static", modifiers = "-bundle")
)]
unsafe extern "C" {
Expand Down Expand Up @@ -203,7 +175,7 @@ cfg_select! {
pub const UNWIND_IP_REG: c_int = 15;

#[cfg_attr(
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
link(name = "unwind", kind = "static", modifiers = "-bundle")
)]
unsafe extern "C" {
Expand Down Expand Up @@ -283,14 +255,14 @@ cfg_select! {
}
_ => {
#[cfg_attr(
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
link(name = "unwind", kind = "static", modifiers = "-bundle")
)]
unsafe extern "C-unwind" {
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
}
#[cfg_attr(
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
link(name = "unwind", kind = "static", modifiers = "-bundle")
)]
unsafe extern "C" {
Expand Down
100 changes: 0 additions & 100 deletions library/unwind/src/unwinding.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/tools/miri/tests/pass/panic/unwind_dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn panic(data: Box<dyn Any + Send>) -> u32 {
_uwe: uw::_Unwind_Exception {
exception_class: miri_exception_class(),
exception_cleanup: Some(exception_cleanup),
private: [core::ptr::null(); uw::unwinder_private_data_size],
private: [core::ptr::null(); _],
},
cause: data,
});
Expand Down
Loading