#export "_thread_start" _thread_start
#export "_thread_exit" _thread_exit
}
+
+__spawn_process :: (path: str) -> i32 #foreign "env" "spawn_process" ---
\ No newline at end of file
#ifdef _BH_LINUX
#include <pthread.h>
#include <signal.h>
+ #include <sys/wait.h>
#endif
#ifndef WASMER_VERSION
return NULL;
}
+static wasm_trap_t* onyx_spawn_process_impl(const wasm_val_vec_t* params, wasm_val_vec_t* results) {
+ char* process_str = (char *) wasm_memory_data(wasm_memory) + params->data[0].of.i32;
+ i32 process_len = params->data[1].of.i32;
+
+ char process_path[1024];
+ process_len = bh_min(1023, process_len);
+ memcpy(process_path, process_str, process_len);
+ process_path[process_len] = '\0';
+
+ #ifdef _BH_LINUX
+ if (fork() == 0) {
+ execv(process_path, NULL);
+ }
+
+ i32 status;
+ wait(&status);
+ results->data[0] = WASM_I32_VAL(WEXITSTATUS(status));
+ #endif
+
+ return NULL;
+}
void onyx_run_wasm(bh_buffer wasm_bytes) {
wasm_instance_t* instance = NULL;
import = wasm_func_as_extern(wasm_func);
goto import_found;
}
+
+ if (wasm_name_equals_string(import_name, "spawn_process")) {
+ wasm_functype_t* func_type = wasm_functype_new_2_1(wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32());
+
+ wasm_func_t* wasm_func = wasm_func_new(wasm_store, func_type, onyx_spawn_process_impl);
+ import = wasm_func_as_extern(wasm_func);
+ goto import_found;
+ }
}
goto bad_import;