bh_arr_new(alloc, options.files, 2);
bh_arr_new(alloc, options.included_folders, 2);
- bh_arr_new(alloc, options.included_library_folders, 2);
// NOTE: Add the current folder
bh_arr_push(options.included_folders, CORE_INSTALLATION);
bh_arr_push(context.options->included_folders, include->name);
} else if (include->kind == Ast_Kind_Library_Path) {
- bh_arr_push(context.options->included_library_folders, include->name);
+ bh_arr_push(context.wasm_module->library_paths, include->name);
}
}
if (context.options->verbose_output > 0)
bh_printf("Running program:\n");
- return onyx_run_wasm(code_buffer);
+ return onyx_run_wasm(code_buffer, context.options->passthrough_argument_count, context.options->passthrough_argument_data);
}
#endif
bh_buffer_append(&libs_buff, leb, leb_len);
bh_buffer_append(&libs_buff, custom_name, strlen(custom_name));
+ leb = uint_to_uleb128((u64) bh_arr_length(module->library_paths), &leb_len);
+ bh_buffer_append(&libs_buff, leb, leb_len);
+
+ bh_arr_each(char *, lib, module->library_paths) {
+ assert(*lib != NULL);
+
+ u32 lib_len = strlen(*lib);
+ leb = uint_to_uleb128((u64) lib_len, &leb_len);
+ bh_buffer_append(&libs_buff, leb, leb_len);
+ bh_buffer_append(&libs_buff, *lib, lib_len);
+ }
+
leb = uint_to_uleb128((u64) bh_arr_length(module->libraries), &leb_len);
bh_buffer_append(&libs_buff, leb, leb_len);
}
WASM_INTEROP(onyx_spawn_thread_impl) {
- if (threads == NULL) bh_arr_new(global_heap_allocator, threads, 128);
+ if (threads == NULL) bh_arr_new(bh_heap_allocator(), threads, 128);
bh_arr_insert_end(threads, 1);
OnyxThread *thread = &bh_arr_last(threads);
typedef void *(*LibraryLinker)(OnyxRuntime *runtime);
static bh_arr(WasmFuncDefinition **) linkable_functions = NULL;
+static bh_arr(char *) library_paths = NULL;
static void onyx_load_library(char *name) {
#ifdef _BH_LINUX
if (name[i] == DIR_SEPARATOR) library = &name[i + 1];
}
- char *library_load_name = bh_aprintf(global_scratch_allocator, "onyx_library_%s", library);
+ char *library_load_name_tmp = bh_bprintf("onyx_library_%s", library);
+ char *library_load_name = alloca(strlen(library_load_name_tmp));
+ strcpy(library_load_name, library_load_name_tmp);
LibraryLinker library_load;
#ifdef _BH_LINUX
- char *library_name = lookup_included_file(name, ".", ".so", 1, context.options->included_library_folders, 1);
+ char *library_name = lookup_included_file(name, ".", ".so", 1, (const char **) library_paths, 1);
void* handle = dlopen(library_name, RTLD_LAZY);
if (handle == NULL) {
printf("ERROR LOADING LIBRARY %s: %s\n", name, dlerror());
#endif
#ifdef _BH_WINDOWS
- char *library_name = lookup_included_file(name, ".", ".dll", 1, context.options->included_library_folders, 1);
+ char *library_name = lookup_included_file(name, ".", ".dll", 1, (const char **) library_paths, 1);
HMODULE handle = LoadLibraryA(library_name);
if (handle == NULL) {
printf("ERROR LOADING LIBRARY %s: %d\n", name, GetLastError());
cursor += name_len;
u64 lib_count = uleb128_to_uint(wasm_bytes.data, &cursor);
+ fori (i, 0, (i64) lib_count) {
+ u64 lib_path_length = uleb128_to_uint(wasm_bytes.data, &cursor);
+ lib_path_length = bh_min(lib_path_length, 512);
+
+ char *lib_path = malloc(lib_path_length);
+ strncpy(lib_path, wasm_bytes.data + cursor, lib_path_length);
+ lib_path[lib_path_length] = '\0';
+ cursor += lib_path_length;
+
+ bh_arr_push(library_paths, lib_path);
+ }
+
+ lib_count = uleb128_to_uint(wasm_bytes.data, &cursor);
+
fori (i, 0, (i64) lib_count) {
u64 lib_name_length = uleb128_to_uint(wasm_bytes.data, &cursor);
lib_name_length = bh_min(lib_name_length, 256);
}
// Returns 1 if successful
-b32 onyx_run_wasm(bh_buffer wasm_bytes) {
+b32 onyx_run_wasm(bh_buffer wasm_bytes, int argc, char *argv[]) {
runtime = &wasm_runtime;
- bh_arr_new(global_heap_allocator, linkable_functions, 4);
+ bh_arr_new(bh_heap_allocator(), linkable_functions, 4);
onyx_lookup_and_load_custom_libraries(wasm_bytes);
wasmer_features_t* features = NULL;
wasm_config_set_features(wasm_config, features);
wasi_config = wasi_config_new("onyx");
- if (context.options->passthrough_argument_count > 0) {
- fori (i, 0, context.options->passthrough_argument_count) {
- wasi_config_arg(wasi_config, context.options->passthrough_argument_data[i]);
+ if (argc > 0) {
+ fori (i, 0, argc) {
+ wasi_config_arg(wasi_config, argv[i]);
}
}