Skip to content
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

[fix 857] panic when target module don't have exported _start function #858

Merged
Merged
70 changes: 3 additions & 67 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
@@ -430,7 +430,7 @@ fn execute_wasi(
f.read_to_end(&mut out).unwrap();
Some(
wasmer_runtime_core::state::InstanceImage::from_bytes(&out)
.expect("failed to decode image"),
.map_err(|_| format!("failed to decode image"))?,
)
} else {
None
@@ -810,72 +810,8 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
env_vars,
module,
mapped_dirs,
);

#[allow(unused_mut)] // mut used in feature
let mut instance = module
.instantiate(&import_object)
.map_err(|e| format!("Can't instantiate WASI module: {:?}", e))?;

let start: Func<(), ()> = instance.func("_start").map_err(|e| format!("{:?}", e))?;

#[cfg(feature = "managed")]
{
let start_raw: extern "C" fn(&mut wasmer_runtime_core::vm::Ctx) =
unsafe { ::std::mem::transmute(start.get_vm_func()) };

unsafe {
run_tiering(
module.info(),
&wasm_binary,
if let Some(ref path) = options.resume {
let mut f = File::open(path).unwrap();
let mut out: Vec<u8> = vec![];
f.read_to_end(&mut out).unwrap();
Some(
wasmer_runtime_core::state::InstanceImage::from_bytes(&out)
.map_err(|_| format!("failed to decode image"))?,
)
} else {
None
},
&import_object,
start_raw,
&mut instance,
options
.optimized_backends
.iter()
.map(|&backend| -> Box<dyn Fn() -> Box<dyn Compiler> + Send> {
Box::new(move || get_compiler_by_backend(backend).unwrap())
})
.collect(),
interactive_shell,
)?
};
}

#[cfg(not(feature = "managed"))]
{
use wasmer_runtime::error::RuntimeError;
let result = start.call();

if let Err(ref err) = result {
match err {
RuntimeError::Trap { msg } => {
return Err(format!("wasm trap occured: {}", msg))
}
#[cfg(feature = "wasi")]
RuntimeError::Error { data } => {
if let Some(error_code) = data.downcast_ref::<wasmer_wasi::ExitCode>() {
std::process::exit(error_code.code as i32)
}
}
#[cfg(not(feature = "wasi"))]
RuntimeError::Error { .. } => (),
}
return Err(format!("error: {:?}", err));
}
}
&wasm_binary,
)?;
} else {
let import_object = wasmer_runtime_core::import::ImportObject::new();
let instance = module
You are viewing a condensed version of this merge commit. You can view the full changes here.