Require backend:singlepass for suspend/resume.

This commit is contained in:
losfair
2019-06-26 12:46:01 +08:00
parent 9b4343eac5
commit 03e6311446
2 changed files with 40 additions and 32 deletions

View File

@ -44,6 +44,7 @@ pub mod vmcalls;
#[cfg(all(unix, target_arch = "x86_64"))] #[cfg(all(unix, target_arch = "x86_64"))]
pub use trampoline_x64 as trampoline; pub use trampoline_x64 as trampoline;
pub mod state; pub mod state;
#[cfg(all(unix, target_arch = "x86_64"))]
pub mod suspend; pub mod suspend;
use self::error::CompileResult; use self::error::CompileResult;

View File

@ -112,6 +112,7 @@ struct Run {
)] )]
loader: Option<LoaderName>, loader: Option<LoaderName>,
#[cfg(feature = "backend:singlepass")]
#[structopt(long = "image-file")] #[structopt(long = "image-file")]
image_file: Option<String>, image_file: Option<String>,
@ -508,48 +509,54 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
mapped_dirs, mapped_dirs,
); );
if let Some(ref name) = options.image_file { #[cfg(feature = "backend:singlepass")]
use wasmer_runtime_core::suspend::{patch_import_object, SuspendConfig}; {
patch_import_object( if let Some(ref name) = options.image_file {
&mut import_object, use wasmer_runtime_core::suspend::{patch_import_object, SuspendConfig};
SuspendConfig { patch_import_object(
image_path: name.clone(), &mut import_object,
}, SuspendConfig {
); image_path: name.clone(),
},
);
}
} }
let mut instance = module let mut instance = module
.instantiate(&import_object) .instantiate(&import_object)
.map_err(|e| format!("Can't instantiate module: {:?}", e))?; .map_err(|e| format!("Can't instantiate module: {:?}", e))?;
if let Some(ref name) = options.image_file { #[cfg(feature = "backend:singlepass")]
if options.resume { {
use wasmer_runtime_core::state::x64::invoke_call_return_on_stack_raw_image; if let Some(ref name) = options.image_file {
use wasmer_singlepass_backend::protect_unix::call_protected; if options.resume {
use wasmer_runtime_core::state::x64::invoke_call_return_on_stack_raw_image;
use wasmer_singlepass_backend::protect_unix::call_protected;
let mut file = File::open(name).expect("cannot open image file"); let mut file = File::open(name).expect("cannot open image file");
let mut image: Vec<u8> = vec![]; let mut image: Vec<u8> = vec![];
file.read_to_end(&mut image).unwrap(); file.read_to_end(&mut image).unwrap();
let msm = instance let msm = instance
.module .module
.runnable_module .runnable_module
.get_module_state_map() .get_module_state_map()
.unwrap();
let code_base =
instance.module.runnable_module.get_code().unwrap().as_ptr() as usize;
call_protected(|| unsafe {
invoke_call_return_on_stack_raw_image(
&msm,
code_base,
&image,
instance.context_mut(),
);
})
.map_err(|_| "ERROR")
.unwrap(); .unwrap();
let code_base =
instance.module.runnable_module.get_code().unwrap().as_ptr() as usize;
call_protected(|| unsafe {
invoke_call_return_on_stack_raw_image(
&msm,
code_base,
&image,
instance.context_mut(),
);
})
.map_err(|_| "ERROR")
.unwrap();
return Ok(()); return Ok(());
}
} }
} }