1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#[cfg(feature = "unwind")]
use cranelift_codegen::isa::unwind::{systemv::UnwindInfo as DwarfFDE, UnwindInfo};
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::{isa, Context};
use wasmer_compiler::{CompileError, CompiledFunctionUnwindInfo};
pub(crate) enum CraneliftUnwindInfo {
#[cfg(feature = "unwind")]
WindowsX64(Vec<u8>),
#[cfg(feature = "unwind")]
FDE(DwarfFDE),
None,
}
impl CraneliftUnwindInfo {
pub fn maybe_into_to_windows_unwind(self) -> Option<CompiledFunctionUnwindInfo> {
match self {
#[cfg(feature = "unwind")]
Self::WindowsX64(unwind_info) => {
Some(CompiledFunctionUnwindInfo::WindowsX64(unwind_info))
}
_ => None,
}
}
}
#[cfg(feature = "unwind")]
pub(crate) fn compiled_function_unwind_info(
isa: &dyn isa::TargetIsa,
context: &Context,
) -> Result<CraneliftUnwindInfo, CompileError> {
let unwind_info = context
.create_unwind_info(isa)
.map_err(|error| CompileError::Codegen(pretty_error(&context.func, Some(isa), error)))?;
match unwind_info {
Some(UnwindInfo::WindowsX64(unwind)) => {
let size = unwind.emit_size();
let mut data: Vec<u8> = vec![0; size];
unwind.emit(&mut data[..]);
Ok(CraneliftUnwindInfo::WindowsX64(data))
}
Some(UnwindInfo::SystemV(unwind)) => Ok(CraneliftUnwindInfo::FDE(unwind)),
Some(_) | None => Ok(CraneliftUnwindInfo::None),
}
}
#[cfg(not(feature = "unwind"))]
pub(crate) fn compiled_function_unwind_info(
isa: &dyn isa::TargetIsa,
context: &Context,
) -> Result<CraneliftUnwindInfo, CompileError> {
Ok(CraneliftUnwindInfo::None)
}