wasmer_compiler/
unwind.rs

1//! A `CompiledFunctionUnwindInfo` contains the function unwind information.
2//!
3//! The unwind information is used to determine which function
4//! called the function that threw the exception, and which
5//! function called that one, and so forth.
6//!
7//! [Learn more](https://en.wikipedia.org/wiki/Call_stack).
8use crate::lib::std::vec::Vec;
9
10/// Compiled function unwind information.
11///
12/// > Note: Windows OS have a different way of representing the [unwind info],
13/// > That's why we keep the Windows data and the Unix frame layout in different
14/// > fields.
15///
16/// [unwind info]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
17#[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, Debug, Clone, PartialEq, Eq)]
18pub enum CompiledFunctionUnwindInfo {
19    /// Windows UNWIND_INFO.
20    WindowsX64(Vec<u8>),
21
22    /// The unwind info is added to the Dwarf section in `Compilation`.
23    Dwarf,
24}
25
26/// See [`CompiledFunctionUnwindInfo`].
27#[derive(Clone, Copy)]
28pub enum CompiledFunctionUnwindInfoRef<'a> {
29    /// Windows UNWIND_INFO.
30    WindowsX64(&'a [u8]),
31    /// Unwind info is added to the Dwarf section in `Compilation`.
32    Dwarf,
33}
34
35impl<'a> From<&'a CompiledFunctionUnwindInfo> for CompiledFunctionUnwindInfoRef<'a> {
36    fn from(uw: &'a CompiledFunctionUnwindInfo) -> Self {
37        match uw {
38            CompiledFunctionUnwindInfo::WindowsX64(d) => {
39                CompiledFunctionUnwindInfoRef::WindowsX64(d)
40            }
41            CompiledFunctionUnwindInfo::Dwarf => CompiledFunctionUnwindInfoRef::Dwarf,
42        }
43    }
44}
45
46impl<'a> From<&'a ArchivedCompiledFunctionUnwindInfo> for CompiledFunctionUnwindInfoRef<'a> {
47    fn from(uw: &'a ArchivedCompiledFunctionUnwindInfo) -> Self {
48        match uw {
49            ArchivedCompiledFunctionUnwindInfo::WindowsX64(d) => {
50                CompiledFunctionUnwindInfoRef::WindowsX64(d)
51            }
52            ArchivedCompiledFunctionUnwindInfo::Dwarf => CompiledFunctionUnwindInfoRef::Dwarf,
53        }
54    }
55}