22
33use core:: ffi:: { c_int, c_void} ;
44
5+ // Use the unwinding crate as unwinder on Xous
6+ #[ cfg( target_os = "xous" ) ]
7+ pub use unwinding:: custom_eh_frame_finder:: {
8+ EhFrameFinder , FrameInfo , FrameInfoKind , set_custom_eh_frame_finder,
9+ } ;
10+
511#[ repr( C ) ]
612#[ derive( Debug , Copy , Clone , PartialEq ) ]
713pub enum _Unwind_Reason_Code {
@@ -24,65 +30,28 @@ pub type _Unwind_Ptr = *const u8;
2430pub type _Unwind_Trace_Fn =
2531 extern "C" fn ( ctx : * mut _Unwind_Context , arg : * mut c_void ) -> _Unwind_Reason_Code ;
2632
27- #[ cfg( target_arch = "x86" ) ]
28- pub const unwinder_private_data_size: usize = 5 ;
29-
30- #[ cfg( all( target_arch = "x86_64" , not( any( target_os = "windows" , target_os = "cygwin" ) ) ) ) ]
31- pub const unwinder_private_data_size: usize = 2 ;
32-
33- #[ cfg( all( target_arch = "x86_64" , any( target_os = "windows" , target_os = "cygwin" ) ) ) ]
34- pub const unwinder_private_data_size: usize = 6 ;
35-
36- #[ cfg( all( target_arch = "arm" , not( target_vendor = "apple" ) ) ) ]
37- pub const unwinder_private_data_size: usize = 20 ;
38-
39- #[ cfg( all( target_arch = "arm" , target_vendor = "apple" ) ) ]
40- pub const unwinder_private_data_size: usize = 5 ;
41-
42- #[ cfg( all( target_arch = "aarch64" , target_pointer_width = "64" , not( target_os = "windows" ) ) ) ]
43- pub const unwinder_private_data_size: usize = 2 ;
44-
45- #[ cfg( all( target_arch = "aarch64" , target_pointer_width = "64" , target_os = "windows" ) ) ]
46- pub const unwinder_private_data_size: usize = 6 ;
47-
48- #[ cfg( all( target_arch = "aarch64" , target_pointer_width = "32" ) ) ]
49- pub const unwinder_private_data_size: usize = 5 ;
50-
51- #[ cfg( target_arch = "m68k" ) ]
52- pub const unwinder_private_data_size: usize = 2 ;
53-
54- #[ cfg( any( target_arch = "mips" , target_arch = "mips32r6" ) ) ]
55- pub const unwinder_private_data_size: usize = 2 ;
56-
57- #[ cfg( target_arch = "csky" ) ]
58- pub const unwinder_private_data_size: usize = 2 ;
59-
60- #[ cfg( any( target_arch = "mips64" , target_arch = "mips64r6" ) ) ]
61- pub const unwinder_private_data_size: usize = 2 ;
62-
63- #[ cfg( any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ]
64- pub const unwinder_private_data_size: usize = 2 ;
65-
66- #[ cfg( target_arch = "s390x" ) ]
67- pub const unwinder_private_data_size: usize = 2 ;
68-
69- #[ cfg( any( target_arch = "sparc" , target_arch = "sparc64" ) ) ]
70- pub const unwinder_private_data_size: usize = 2 ;
71-
72- #[ cfg( any( target_arch = "riscv64" , target_arch = "riscv32" ) ) ]
73- pub const unwinder_private_data_size: usize = 2 ;
74-
75- #[ cfg( all( target_family = "wasm" , target_os = "emscripten" ) ) ]
76- pub const unwinder_private_data_size: usize = 20 ;
77-
78- #[ cfg( all( target_arch = "wasm32" , any( target_os = "linux" , target_os = "wasi" ) ) ) ]
79- pub const unwinder_private_data_size: usize = 2 ;
80-
81- #[ cfg( target_arch = "hexagon" ) ]
82- pub const unwinder_private_data_size: usize = 5 ;
83-
84- #[ cfg( any( target_arch = "loongarch32" , target_arch = "loongarch64" ) ) ]
85- pub const unwinder_private_data_size: usize = 2 ;
33+ pub const unwinder_private_data_size: usize = cfg_select ! {
34+ target_arch = "x86" => 5 ,
35+ all( target_arch = "x86_64" , not( any( target_os = "windows" , target_os = "cygwin" ) ) ) => 2 ,
36+ all( target_arch = "x86_64" , any( target_os = "windows" , target_os = "cygwin" ) ) => 6 ,
37+ all( target_arch = "arm" , not( target_vendor = "apple" ) ) => 20 ,
38+ all( target_arch = "arm" , target_vendor = "apple" ) => 5 ,
39+ all( target_arch = "aarch64" , target_pointer_width = "64" , not( target_os = "windows" ) ) => 2 ,
40+ all( target_arch = "aarch64" , target_pointer_width = "64" , target_os = "windows" ) => 6 ,
41+ all( target_arch = "aarch64" , target_pointer_width = "32" ) => 5 ,
42+ target_arch = "m68k" => 2 ,
43+ any( target_arch = "mips" , target_arch = "mips32r6" ) => 2 ,
44+ target_arch = "csky" => 2 ,
45+ any( target_arch = "mips64" , target_arch = "mips64r6" ) => 2 ,
46+ any( target_arch = "powerpc" , target_arch = "powerpc64" ) => 2 ,
47+ target_arch = "s390x" => 2 ,
48+ any( target_arch = "sparc" , target_arch = "sparc64" ) => 2 ,
49+ any( target_arch = "riscv64" , target_arch = "riscv32" ) => 2 ,
50+ all( target_family = "wasm" , target_os = "emscripten" ) => 20 ,
51+ all( target_arch = "wasm32" , any( target_os = "linux" , target_os = "wasi" ) ) => 2 ,
52+ target_arch = "hexagon" => 5 ,
53+ any( target_arch = "loongarch32" , target_arch = "loongarch64" ) => 2 ,
54+ } ;
8655
8756#[ repr( C ) ]
8857pub struct _Unwind_Exception {
@@ -91,6 +60,12 @@ pub struct _Unwind_Exception {
9160 pub private : [ _Unwind_Word ; unwinder_private_data_size] ,
9261}
9362
63+ // Check the size of _Unwind_Exception against the source of thruth when using the unwinding crate.
64+ #[ cfg( target_os = "xous" ) ]
65+ const _: ( ) = {
66+ assert ! ( size_of:: <unwinding:: abi:: UnwindException >( ) == size_of:: <_Unwind_Exception>( ) ) ;
67+ } ;
68+
9469pub enum _Unwind_Context { }
9570
9671pub type _Unwind_Exception_Cleanup_Fn =
@@ -105,10 +80,7 @@ pub type _Unwind_Exception_Cleanup_Fn =
10580// rustc_codegen_ssa::src::back::symbol_export, rustc_middle::middle::exported_symbols
10681// and RFC 2841
10782#[ cfg_attr(
108- all(
109- feature = "llvm-libunwind" ,
110- any( target_os = "fuchsia" , target_os = "linux" , target_os = "xous" )
111- ) ,
83+ all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" ) ) ,
11284 link( name = "unwind" , kind = "static" , modifiers = "-bundle" )
11385) ]
11486// Explicitly link the `unwind` library on WASI targets.
@@ -144,7 +116,7 @@ cfg_select! {
144116 pub const _UA_END_OF_STACK: c_int = 16 ;
145117
146118 #[ cfg_attr(
147- all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" , target_os = "xous" ) ) ,
119+ all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" ) ) ,
148120 link( name = "unwind" , kind = "static" , modifiers = "-bundle" )
149121 ) ]
150122 unsafe extern "C" {
@@ -203,7 +175,7 @@ cfg_select! {
203175 pub const UNWIND_IP_REG : c_int = 15 ;
204176
205177 #[ cfg_attr(
206- all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" , target_os = "xous" ) ) ,
178+ all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" ) ) ,
207179 link( name = "unwind" , kind = "static" , modifiers = "-bundle" )
208180 ) ]
209181 unsafe extern "C" {
@@ -283,14 +255,14 @@ cfg_select! {
283255 }
284256 _ => {
285257 #[ cfg_attr(
286- all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" , target_os = "xous" ) ) ,
258+ all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" ) ) ,
287259 link( name = "unwind" , kind = "static" , modifiers = "-bundle" )
288260 ) ]
289261 unsafe extern "C-unwind" {
290262 pub fn _Unwind_RaiseException( exception: * mut _Unwind_Exception) -> _Unwind_Reason_Code;
291263 }
292264 #[ cfg_attr(
293- all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" , target_os = "xous" ) ) ,
265+ all( feature = "llvm-libunwind" , any( target_os = "fuchsia" , target_os = "linux" ) ) ,
294266 link( name = "unwind" , kind = "static" , modifiers = "-bundle" )
295267 ) ]
296268 unsafe extern "C" {
0 commit comments