Implementation of stack-walking to find a handler. This function searches for a handler in the given range of stack frames, starting from the throw stub and up to a specified entry frame. # Safety The safety of this function is the same as [`crate::visit_frames`] where the values passed in configuring the frame pointer walk must be correct and Wasm-defined for this to not have UB.
(
unwind: &dyn Unwind,
frame_handler: F,
exit_pc: usize,
exit_trampoline_frame: usize,
entry_frame: usize,
)
| 43 | /// values passed in configuring the frame pointer walk must be correct and |
| 44 | /// Wasm-defined for this to not have UB. |
| 45 | pub unsafe fn find<F: Fn(&Frame) -> Option<(usize, usize)>>( |
| 46 | unwind: &dyn Unwind, |
| 47 | frame_handler: F, |
| 48 | exit_pc: usize, |
| 49 | exit_trampoline_frame: usize, |
| 50 | entry_frame: usize, |
| 51 | ) -> Option<Handler> { |
| 52 | // SAFETY: the safety of `visit_frames` relies on the correctness of the |
| 53 | // parameters passed in which is forwarded as a contract to this function |
| 54 | // tiself. |
| 55 | let result = unsafe { |
| 56 | crate::stackwalk::visit_frames( |
| 57 | unwind, |
| 58 | exit_pc, |
| 59 | exit_trampoline_frame, |
| 60 | entry_frame, |
| 61 | |frame| { |
| 62 | log::trace!("visit_frame: frame {frame:?}"); |
| 63 | if let Some((handler_pc, handler_sp)) = frame_handler(&frame) { |
| 64 | return ControlFlow::Break(Handler { |
| 65 | pc: handler_pc, |
| 66 | sp: handler_sp, |
| 67 | fp: frame.fp(), |
| 68 | }); |
| 69 | } |
| 70 | ControlFlow::Continue(()) |
| 71 | }, |
| 72 | ) |
| 73 | }; |
| 74 | match result { |
| 75 | ControlFlow::Break(handler) => Some(handler), |
| 76 | ControlFlow::Continue(()) => None, |
| 77 | } |
| 78 | } |
| 79 | } |