mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 14:18:20 +00:00
cli: initialize wasienv memory in create-exe
This commit is contained in:
@@ -149,6 +149,24 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
#ifdef WASI
|
||||
// Read the exports.
|
||||
wasm_extern_vec_t exports;
|
||||
wasm_instance_exports(instance, &exports);
|
||||
wasm_memory_t* mem = NULL;
|
||||
for (size_t i = 0; i < exports.size; i++) {
|
||||
mem = wasm_extern_as_memory(exports.data[i]);
|
||||
if (mem) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mem) {
|
||||
fprintf(stderr, "Failed to create instance: Could not find memory in exports\n");
|
||||
print_wasmer_error();
|
||||
return -1;
|
||||
}
|
||||
wasi_env_set_memory(wasi_env, mem);
|
||||
|
||||
own wasm_func_t *start_function = wasi_get_start_function(instance);
|
||||
if (!start_function) {
|
||||
fprintf(stderr, "`_start` function not found\n");
|
||||
@@ -163,11 +181,14 @@ int main(int argc, char *argv[]) {
|
||||
fprintf(stderr, "Trap is not NULL: TODO:\n");
|
||||
return -1;
|
||||
}
|
||||
wasi_env_delete(wasi_env);
|
||||
#endif
|
||||
|
||||
// TODO: handle non-WASI start (maybe with invoke?)
|
||||
|
||||
#ifdef WASI
|
||||
wasi_env_delete(wasi_env);
|
||||
wasm_extern_vec_delete(&exports);
|
||||
#endif
|
||||
wasm_instance_delete(instance);
|
||||
wasm_module_delete(module);
|
||||
wasm_store_delete(store);
|
||||
|
||||
Reference in New Issue
Block a user