@@ -28,30 +28,8 @@ use crate::io::set_panic;
28
28
#[ cfg( test) ]
29
29
use realstd:: io:: set_panic;
30
30
31
- // This must be kept in sync with the implementations in libpanic_unwind.
32
- //
33
- // This is *not* checked in anyway; the compiler does not allow us to use a
34
- // type/macro/anything from panic_unwind, since we're then linking in the
35
- // panic_unwind runtime even during -Cpanic=abort.
36
- //
37
- // Essentially this must be the type of `imp::Payload` in libpanic_unwind.
38
- cfg_if:: cfg_if! {
39
- if #[ cfg( not( feature = "panic_unwind" ) ) ] {
40
- type Payload = ( ) ;
41
- } else if #[ cfg( target_os = "emscripten" ) ] {
42
- type Payload = * mut u8 ;
43
- } else if #[ cfg( target_arch = "wasm32" ) ] {
44
- type Payload = * mut u8 ;
45
- } else if #[ cfg( target_os = "hermit" ) ] {
46
- type Payload = * mut u8 ;
47
- } else if #[ cfg( all( target_env = "msvc" , target_arch = "aarch64" ) ) ] {
48
- type Payload = * mut u8 ;
49
- } else if #[ cfg( target_env = "msvc" ) ] {
50
- type Payload = [ u64 ; 2 ] ;
51
- } else {
52
- type Payload = * mut u8 ;
53
- }
54
- }
31
+ // Include the definition of UnwindPayload from libpanic_unwind.
32
+ include ! ( "../libpanic_unwind/payload.rs" ) ;
55
33
56
34
// Binary interface to the panic runtime that the standard library depends on.
57
35
//
@@ -67,7 +45,7 @@ cfg_if::cfg_if! {
67
45
extern "C" {
68
46
/// The payload ptr here is actually the same as the payload ptr for the try
69
47
/// intrinsic (i.e., is really `*mut [u64; 2]` or `*mut *mut u8`).
70
- fn __rust_panic_cleanup ( payload : * mut u8 ) -> * mut ( dyn Any + Send + ' static ) ;
48
+ fn __rust_panic_cleanup ( payload : TryPayload ) -> * mut ( dyn Any + Send + ' static ) ;
71
49
72
50
/// `payload` is actually a `*mut &mut dyn BoxMeUp` but that would cause FFI warnings.
73
51
/// It cannot be `Box<dyn BoxMeUp>` because the other end of this call does not depend
@@ -297,7 +275,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
297
275
// method of calling a catch panic whilst juggling ownership.
298
276
let mut data = Data { f : ManuallyDrop :: new ( f) } ;
299
277
300
- let mut payload: MaybeUninit < Payload > = MaybeUninit :: uninit ( ) ;
278
+ let mut payload: MaybeUninit < TryPayload > = MaybeUninit :: uninit ( ) ;
301
279
302
280
let data_ptr = & mut data as * mut _ as * mut u8 ;
303
281
let payload_ptr = payload. as_mut_ptr ( ) as * mut _ ;
@@ -312,8 +290,8 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
312
290
// optimizer (in most cases this function is not inlined even as a normal,
313
291
// non-cold function, though, as of the writing of this comment).
314
292
#[ cold]
315
- unsafe fn cleanup ( mut payload : Payload ) -> Box < dyn Any + Send + ' static > {
316
- let obj = Box :: from_raw ( __rust_panic_cleanup ( & mut payload as * mut _ as * mut u8 ) ) ;
293
+ unsafe fn cleanup ( payload : TryPayload ) -> Box < dyn Any + Send + ' static > {
294
+ let obj = Box :: from_raw ( __rust_panic_cleanup ( payload) ) ;
317
295
update_panic_count ( -1 ) ;
318
296
obj
319
297
}
0 commit comments