-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compiling version running on Windows
- Loading branch information
1 parent
803c896
commit f9aabee
Showing
8 changed files
with
164 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cfg_if::cfg_if! { | ||
if #[cfg(all(windows, target_arch = "x86_64"))] { | ||
mod windows_x64; | ||
pub use self::windows_x64::*; | ||
} else if #[cfg(all(windows, target_arch = "x86"))] { | ||
mod windows_x32; | ||
pub use self::windows_x32::*; | ||
} else if #[cfg(unix)] { | ||
mod systemv; | ||
pub use self::systemv::*; | ||
} else { | ||
compile_error!("unsupported target platform for unwind"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//! Module for Windows x64 ABI unwind registry. | ||
use wasmer_compiler::CompiledFunctionUnwindInfo; | ||
use winapi::um::winnt; | ||
|
||
/// Represents a registry of function unwind information for Windows x64 ABI. | ||
pub struct UnwindRegistry { | ||
base_address: usize, | ||
functions: Vec<winnt::RUNTIME_FUNCTION>, | ||
published: bool, | ||
} | ||
|
||
impl UnwindRegistry { | ||
/// Creates a new unwind registry with the given base address. | ||
pub fn new(base_address: usize) -> Self { | ||
Self { | ||
base_address, | ||
functions: Vec::new(), | ||
published: false, | ||
} | ||
} | ||
|
||
/// Registers a function given the start offset, length, and unwind information. | ||
pub fn register( | ||
&mut self, | ||
func_start: u32, | ||
func_len: u32, | ||
info: &CompiledFunctionUnwindInfo, | ||
) -> Result<(), String> { | ||
if self.published { | ||
return Err("unwind registry has already been published".to_string()); | ||
} | ||
|
||
match info { | ||
CompiledFunctionUnwindInfo::WindowsX64(_) => { | ||
let mut entry = winnt::RUNTIME_FUNCTION::default(); | ||
|
||
entry.BeginAddress = func_start; | ||
entry.EndAddress = func_start + func_len; | ||
|
||
// The unwind information should be immediately following the function | ||
// with padding for 4 byte alignment | ||
unsafe { | ||
*entry.u.UnwindInfoAddress_mut() = (entry.EndAddress + 3) & !3; | ||
} | ||
|
||
self.functions.push(entry); | ||
|
||
Ok(()) | ||
} | ||
_ => Err("unsupported unwind information".to_string()), | ||
} | ||
} | ||
|
||
/// Publishes all registered functions. | ||
pub fn publish(&mut self) -> Result<(), String> { | ||
if self.published { | ||
return Err("unwind registry has already been published".to_string()); | ||
} | ||
|
||
self.published = true; | ||
|
||
if !self.functions.is_empty() { | ||
// Windows heap allocations are 32-bit aligned, but assert just in case | ||
assert_eq!( | ||
(self.functions.as_mut_ptr() as u64) % 4, | ||
0, | ||
"function table allocation was not aligned" | ||
); | ||
|
||
unsafe { | ||
if winnt::RtlAddFunctionTable( | ||
self.functions.as_mut_ptr(), | ||
self.functions.len() as u32, | ||
self.base_address as u64, | ||
) == 0 | ||
{ | ||
return Err("failed to register function table".to_string()); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Drop for UnwindRegistry { | ||
fn drop(&mut self) { | ||
if self.published { | ||
unsafe { | ||
winnt::RtlDeleteFunctionTable(self.functions.as_mut_ptr()); | ||
} | ||
} | ||
} | ||
} |