wasmer_compiler/types/
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;
9use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
10#[cfg(feature = "enable-serde")]
11use serde::{Deserialize, Serialize};
12
13/// Compiled function unwind information.
14///
15/// > Note: Windows OS have a different way of representing the [unwind info],
16/// > That's why we keep the Windows data and the Unix frame layout in different
17/// > fields.
18///
19/// [unwind info]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
20#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
21#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))]
22#[derive(RkyvSerialize, RkyvDeserialize, Archive, Debug, Clone, PartialEq, Eq)]
23#[rkyv(derive(Debug))]
24pub enum CompiledFunctionUnwindInfo {
25    /// Windows UNWIND_INFO.
26    WindowsX64(Vec<u8>),
27
28    /// The unwind info is added to the Dwarf section in `Compilation`.
29    Dwarf,
30}
31
32/// Generic reference to data in a `CompiledFunctionUnwindInfo`
33#[allow(missing_docs)]
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub enum CompiledFunctionUnwindInfoReference<'a> {
36    WindowsX64(&'a [u8]),
37    Dwarf,
38    CompactUnwind,
39}
40
41/// Any struct that acts like a `CompiledFunctionUnwindInfo`.
42#[allow(missing_docs)]
43pub trait CompiledFunctionUnwindInfoLike<'a> {
44    fn get(&'a self) -> CompiledFunctionUnwindInfoReference<'a>;
45}
46
47impl<'a> CompiledFunctionUnwindInfoLike<'a> for CompiledFunctionUnwindInfo {
48    fn get(&'a self) -> CompiledFunctionUnwindInfoReference<'a> {
49        match self {
50            Self::WindowsX64(v) => CompiledFunctionUnwindInfoReference::WindowsX64(v.as_ref()),
51            Self::Dwarf => CompiledFunctionUnwindInfoReference::Dwarf,
52        }
53    }
54}
55
56impl<'a> CompiledFunctionUnwindInfoLike<'a> for ArchivedCompiledFunctionUnwindInfo {
57    fn get(&'a self) -> CompiledFunctionUnwindInfoReference<'a> {
58        match self {
59            Self::WindowsX64(v) => CompiledFunctionUnwindInfoReference::WindowsX64(v.as_ref()),
60            Self::Dwarf => CompiledFunctionUnwindInfoReference::Dwarf,
61        }
62    }
63}