mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 13:58:38 +00:00
Use wasi_env_set_instance instead of wasi_env_set_memory
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
mod capture_files;
|
mod capture_files;
|
||||||
|
|
||||||
use super::{wasm_extern_t, wasm_memory_t, wasm_module_t, wasm_store_t};
|
use super::{wasm_extern_t, wasm_instance_t, wasm_module_t, wasm_store_t};
|
||||||
// required due to really weird Rust resolution rules for macros
|
// required due to really weird Rust resolution rules for macros
|
||||||
// https://github.com/rust-lang/rust/issues/57966
|
// https://github.com/rust-lang/rust/issues/57966
|
||||||
use crate::c_try;
|
use crate::c_try;
|
||||||
@@ -115,8 +115,15 @@ pub extern "C" fn wasi_env_new(mut config: Box<wasi_config_t>) -> Option<Box<was
|
|||||||
pub extern "C" fn wasi_env_delete(_state: Option<Box<wasi_env_t>>) {}
|
pub extern "C" fn wasi_env_delete(_state: Option<Box<wasi_env_t>>) {}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasi_env_set_memory(env: &mut wasi_env_t, memory: &wasm_memory_t) {
|
pub extern "C" fn wasi_env_set_instance(env: &mut wasi_env_t, instance: &wasm_instance_t) -> bool {
|
||||||
env.inner.set_memory(memory.inner.clone());
|
let memory = if let Ok(memory) = instance.inner.exports.get_memory("memory") {
|
||||||
|
memory
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
env.inner.set_memory(memory.clone());
|
||||||
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -100,13 +100,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
}
|
}
|
||||||
fprintf(stderr, "found %zu exports\n", exports.size);
|
fprintf(stderr, "found %zu exports\n", exports.size);
|
||||||
|
|
||||||
printf("Getting memory...\n");
|
wasi_env_set_instance(wasi_env, instance);
|
||||||
const wasm_memory_t* memory = wasm_extern_as_memory(exports.data[0]);
|
|
||||||
if (! memory) {
|
|
||||||
printf("Could not get memory!\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
wasi_env_set_memory(wasi_env, memory);
|
|
||||||
const wasm_func_t* run_func = wasm_extern_as_func(exports.data[1]);
|
const wasm_func_t* run_func = wasm_extern_as_func(exports.data[1]);
|
||||||
if (run_func == NULL) {
|
if (run_func == NULL) {
|
||||||
printf("> Error accessing export!\n");
|
printf("> Error accessing export!\n");
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ void wasi_env_delete(own wasi_env_t*);
|
|||||||
|
|
||||||
// Get an array of imports that can be used to instantiate the given module.
|
// Get an array of imports that can be used to instantiate the given module.
|
||||||
bool wasi_get_imports(wasm_store_t* store,
|
bool wasi_get_imports(wasm_store_t* store,
|
||||||
wasm_module_t* module,
|
const wasm_module_t* module,
|
||||||
wasi_env_t* wasi_env,
|
wasi_env_t* wasi_env,
|
||||||
wasm_extern_t** imports);
|
wasm_extern_t** imports);
|
||||||
|
|
||||||
// TODO: investigate removing this part of the API
|
// Set up the `wasi_env_t` so that the WASI host functions can access WASI's memory.
|
||||||
// Set the memory in the `wasi_env_t` so that the WASI host functions can access WASI's memory.
|
// Returns whether or not it succeeded.
|
||||||
void wasi_env_set_memory(wasi_env_t*, const wasm_memory_t*);
|
bool wasi_env_set_instance(wasi_env_t*, const wasm_instance_t*);
|
||||||
|
|
||||||
// Read from WASI's buffered stdout if stdout has not been inherited with
|
// Read from WASI's buffered stdout if stdout has not been inherited with
|
||||||
// `wasi_config_inherit_stdout`.
|
// `wasi_config_inherit_stdout`.
|
||||||
|
|||||||
Reference in New Issue
Block a user