-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LLVM backend enabled for Windows #598
Changes from all commits
12f8f3d
180e476
8917873
22f8b3f
97c6956
1d0ac80
020b948
0256a6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
[package] | ||
name = "wasmer-llvm-backend" | ||
version = "0.5.7" | ||
authors = ["Lachlan Sneff <[email protected]>"] | ||
authors = ["The Wasmer Engineering Team <[email protected]>"] | ||
edition = "2018" | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.7" } | ||
inkwell = { git = "https://github.com/wasmerio/inkwell", branch = "llvm8-0", features = ["llvm8-0"] } | ||
wasmparser = "0.34.0" | ||
hashbrown = "0.1.8" | ||
smallvec = "0.6.8" | ||
|
@@ -16,6 +15,15 @@ libc = "0.2.49" | |
nix = "0.14.0" | ||
capstone = { version = "0.5.0", optional = true } | ||
|
||
[dependencies.inkwell] | ||
git = "https://github.com/wasmerio/inkwell" | ||
branch = "llvm8-0" | ||
default-features = false | ||
features = ["llvm8-0", "target-x86"] | ||
|
||
[target.'cfg(windows)'.dependencies] | ||
winapi = { version = "0.3", features = ["memoryapi"] } | ||
|
||
[build-dependencies] | ||
cc = "1.0" | ||
lazy_static = "1.2.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn round_up_to_page_size(size: usize) -> usize { | ||
(size + (4096 - 1)) & !(4096 - 1) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
mod common; | ||
|
||
#[cfg(unix)] | ||
mod unix; | ||
#[cfg(unix)] | ||
pub use self::unix::*; | ||
|
||
#[cfg(target_family = "windows")] | ||
compile_error!("windows not yet supported for the llvm-based compiler backend"); | ||
mod win; | ||
#[cfg(target_family = "windows")] | ||
pub use self::win::*; | ||
|
||
#[cfg(not(any(unix, target_family = "windows")))] | ||
compile_error!("Your system is not yet supported for the llvm-based compiler backend"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
use libc::{c_void, siginfo_t}; | ||
use super::common::round_up_to_page_size; | ||
use crate::structs::{LLVMResult, MemProtect}; | ||
use libc::{ | ||
c_void, mmap, mprotect, munmap, siginfo_t, MAP_ANON, MAP_PRIVATE, PROT_EXEC, PROT_NONE, | ||
PROT_READ, PROT_WRITE, | ||
}; | ||
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGSEGV}; | ||
use std::ptr; | ||
|
||
/// `__register_frame` and `__deregister_frame` on macos take a single fde as an | ||
/// argument, so we need to parse the fde table here. | ||
|
@@ -68,3 +74,60 @@ extern "C" fn signal_trap_handler( | |
throw_trap(2); | ||
} | ||
} | ||
|
||
pub unsafe fn alloc_memory( | ||
size: usize, | ||
protect: MemProtect, | ||
ptr_out: &mut *mut u8, | ||
size_out: &mut usize, | ||
) -> LLVMResult { | ||
let size = round_up_to_page_size(size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the rust mmap follows POSIX mmap, neither the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referring to previous comment:
|
||
let ptr = mmap( | ||
ptr::null_mut(), | ||
size, | ||
match protect { | ||
MemProtect::NONE => PROT_NONE, | ||
MemProtect::READ => PROT_READ, | ||
MemProtect::READ_WRITE => PROT_READ | PROT_WRITE, | ||
MemProtect::READ_EXECUTE => PROT_READ | PROT_EXEC, | ||
}, | ||
MAP_PRIVATE | MAP_ANON, | ||
-1, | ||
0, | ||
); | ||
if ptr as isize == -1 { | ||
return LLVMResult::ALLOCATE_FAILURE; | ||
} | ||
*ptr_out = ptr as _; | ||
*size_out = size; | ||
LLVMResult::OK | ||
} | ||
|
||
pub unsafe fn protect_memory(ptr: *mut u8, size: usize, protect: MemProtect) -> LLVMResult { | ||
let res = mprotect( | ||
ptr as _, | ||
round_up_to_page_size(size), | ||
match protect { | ||
MemProtect::NONE => PROT_NONE, | ||
MemProtect::READ => PROT_READ, | ||
MemProtect::READ_WRITE => PROT_READ | PROT_WRITE, | ||
MemProtect::READ_EXECUTE => PROT_READ | PROT_EXEC, | ||
}, | ||
); | ||
|
||
if res == 0 { | ||
LLVMResult::OK | ||
} else { | ||
LLVMResult::PROTECT_FAILURE | ||
} | ||
} | ||
|
||
pub unsafe fn dealloc_memory(ptr: *mut u8, size: usize) -> LLVMResult { | ||
let res = munmap(ptr as _, round_up_to_page_size(size)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need round_up_to_page_size here either (though it helps to keep the sizes to mmap and munmap the same). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referring to previous comment:
|
||
|
||
if res == 0 { | ||
LLVMResult::OK | ||
} else { | ||
LLVMResult::DEALLOC_FAILURE | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Page size is not always 4kib on any given system. Windows and Linux both support different sized pages in the same running system.
On unix, it's
libc::sysconf(_SC_PAGESIZE)
but not on Windows, which suggests maybe this isn't really platform common.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was same code as before, just moved into a new file.
Perhaps we can address this in a separate PR?