Switch from mmap to memmap to support Windows
This commit is contained in:
committed by
Benjamin Bouvier
parent
ec8f72bf20
commit
9edbfed65f
@@ -17,6 +17,6 @@ cranelift-preopt = { path = "../cranelift-preopt", version = "0.40.0" }
|
||||
file-per-thread-logger = "0.1.2"
|
||||
filecheck = "0.4.0"
|
||||
log = "0.4.6"
|
||||
mmap = "0.1.1"
|
||||
memmap = "0.7.0"
|
||||
num_cpus = "1.8.0"
|
||||
region = "2.1.2"
|
||||
|
||||
@@ -4,7 +4,7 @@ use cranelift_codegen::ir::Function;
|
||||
use cranelift_codegen::isa::{CallConv, TargetIsa};
|
||||
use cranelift_codegen::{settings, Context};
|
||||
use cranelift_native::builder as host_isa_builder;
|
||||
use mmap::{MapOption, MemoryMap};
|
||||
use memmap::MmapMut;
|
||||
use region;
|
||||
use region::Protection;
|
||||
|
||||
@@ -67,19 +67,23 @@ impl FunctionRunner {
|
||||
let code_info = context
|
||||
.compile(self.isa.as_ref())
|
||||
.map_err(|e| e.to_string())?;
|
||||
let code_page = MemoryMap::new(code_info.total_size as usize, &[MapOption::MapWritable])
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut code_page =
|
||||
MmapMut::map_anon(code_info.total_size as usize).map_err(|e| e.to_string())?;
|
||||
let callable_fn: fn() -> bool = unsafe {
|
||||
context.emit_to_memory(
|
||||
self.isa.as_ref(),
|
||||
code_page.data(),
|
||||
code_page.as_mut_ptr(),
|
||||
relocs,
|
||||
traps,
|
||||
stackmaps,
|
||||
);
|
||||
region::protect(code_page.data(), code_page.len(), Protection::ReadExecute)
|
||||
region::protect(
|
||||
code_page.as_mut_ptr(),
|
||||
code_page.len(),
|
||||
Protection::ReadExecute,
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
mem::transmute(code_page.data())
|
||||
mem::transmute(code_page.as_mut_ptr())
|
||||
};
|
||||
|
||||
// execute
|
||||
|
||||
Reference in New Issue
Block a user