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}
39
40/// Any struct that acts like a `CompiledFunctionUnwindInfo`.
41#[allow(missing_docs)]
42pub trait CompiledFunctionUnwindInfoLike<'a> {
43    fn get(&'a self) -> CompiledFunctionUnwindInfoReference<'a>;
44}
45
46impl<'a> CompiledFunctionUnwindInfoLike<'a> for CompiledFunctionUnwindInfo {
47    fn get(&'a self) -> CompiledFunctionUnwindInfoReference<'a> {
48        match self {
49            Self::WindowsX64(v) => CompiledFunctionUnwindInfoReference::WindowsX64(v.as_ref()),
50            Self::Dwarf => CompiledFunctionUnwindInfoReference::Dwarf,
51        }
52    }
53}
54
55impl<'a> CompiledFunctionUnwindInfoLike<'a> for ArchivedCompiledFunctionUnwindInfo {
56    fn get(&'a self) -> CompiledFunctionUnwindInfoReference<'a> {
57        match self {
58            Self::WindowsX64(v) => CompiledFunctionUnwindInfoReference::WindowsX64(v.as_ref()),
59            Self::Dwarf => CompiledFunctionUnwindInfoReference::Dwarf,
60        }
61    }
62}