Update uses of renamed BoxMeUp to PanicPayload

This commit is contained in:
syvb 2024-01-29 18:20:45 -05:00 committed by David Wood
parent e8c0bb0557
commit e9b3a0e613
1 changed files with 10 additions and 10 deletions

View File

@ -66,22 +66,22 @@ control passes to `rust_panic_with_hook`. This method is responsible
for invoking the global panic hook, and checking for double panics. Finally, for invoking the global panic hook, and checking for double panics. Finally,
we call `__rust_start_panic`, which is provided by the panic runtime. we call `__rust_start_panic`, which is provided by the panic runtime.
The call to `__rust_start_panic` is very weird - it is passed a `*mut &mut dyn BoxMeUp`, The call to `__rust_start_panic` is very weird - it is passed a `*mut &mut dyn PanicPayload`,
converted to an `usize`. Let's break this type down: converted to an `usize`. Let's break this type down:
1. `BoxMeUp` is an internal trait. It is implemented for `PanicPayload` 1. `PanicPayload` is an internal trait. It is implemented for `PanicPayload`
(a wrapper around the user-supplied payload type), and has a method (a wrapper around the user-supplied payload type), and has a method
`fn box_me_up(&mut self) -> *mut (dyn Any + Send)`. `fn take_box(&mut self) -> *mut (dyn Any + Send)`.
This method takes the user-provided payload (`T: Any + Send`), This method takes the user-provided payload (`T: Any + Send`),
boxes it, and converts the box to a raw pointer. boxes it, and converts the box to a raw pointer.
2. When we call `__rust_start_panic`, we have an `&mut dyn BoxMeUp`. 2. When we call `__rust_start_panic`, we have an `&mut dyn PanicPayload`.
However, this is a fat pointer (twice the size of a `usize`). However, this is a fat pointer (twice the size of a `usize`).
To pass this to the panic runtime across an FFI boundary, we take a mutable To pass this to the panic runtime across an FFI boundary, we take a mutable
reference *to this mutable reference* (`&mut &mut dyn BoxMeUp`), and convert it to a raw pointer reference *to this mutable reference* (`&mut &mut dyn PanicPayload`), and convert it to a raw
(`*mut &mut dyn BoxMeUp`). The outer raw pointer is a thin pointer, since it points to a `Sized` pointer (`*mut &mut dyn PanicPayload`). The outer raw pointer is a thin pointer, since it points to
type (a mutable reference). Therefore, we can convert this thin pointer into a `usize`, which a `Sized` type (a mutable reference). Therefore, we can convert this thin pointer into a `usize`,
is suitable for passing across an FFI boundary. which is suitable for passing across an FFI boundary.
Finally, we call `__rust_start_panic` with this `usize`. We have now entered the panic runtime. Finally, we call `__rust_start_panic` with this `usize`. We have now entered the panic runtime.
@ -96,8 +96,8 @@ as you would expect.
`panic_unwind` is the more interesting case. `panic_unwind` is the more interesting case.
In its implementation of `__rust_start_panic`, we take the `usize`, convert In its implementation of `__rust_start_panic`, we take the `usize`, convert
it back to a `*mut &mut dyn BoxMeUp`, dereference it, and call `box_me_up` it back to a `*mut &mut dyn PanicPayload`, dereference it, and call `take_box`
on the `&mut dyn BoxMeUp`. At this point, we have a raw pointer to the payload on the `&mut dyn PanicPayload`. At this point, we have a raw pointer to the payload
itself (a `*mut (dyn Send + Any)`): that is, a raw pointer to the actual value itself (a `*mut (dyn Send + Any)`): that is, a raw pointer to the actual value
provided by the user who called `panic!`. provided by the user who called `panic!`.