Merge branch main into dev/wasi-libc-windows
This commit is contained in:
@ -11,6 +11,8 @@
|
||||
typedef struct {
|
||||
const char *dir_list[8];
|
||||
uint32 dir_list_size;
|
||||
const char *map_dir_list[8];
|
||||
uint32 map_dir_list_size;
|
||||
const char *env_list[8];
|
||||
uint32 env_list_size;
|
||||
const char *addr_pool[8];
|
||||
@ -37,6 +39,12 @@ libc_wasi_print_help()
|
||||
"directories\n");
|
||||
printf(" to the program, for example:\n");
|
||||
printf(" --dir=<dir1> --dir=<dir2>\n");
|
||||
printf(" --map-dir=<guest::host> Grant wasi access to the given host "
|
||||
"directories\n");
|
||||
printf(" to the program at a specific guest "
|
||||
"path, for example:\n");
|
||||
printf(" --map-dir=<guest-path1::host-path1> "
|
||||
"--map-dir=<guest-path2::host-path2>\n");
|
||||
printf(" --addr-pool=<addrs> Grant wasi access to the given network "
|
||||
"addresses in\n");
|
||||
printf(" CIRD notation to the program, seperated "
|
||||
@ -84,6 +92,17 @@ libc_wasi_parse(char *arg, libc_wasi_parse_context_t *ctx)
|
||||
}
|
||||
ctx->dir_list[ctx->dir_list_size++] = arg + 6;
|
||||
}
|
||||
else if (!strncmp(arg, "--map-dir=", 10)) {
|
||||
if (arg[10] == '\0')
|
||||
return LIBC_WASI_PARSE_RESULT_NEED_HELP;
|
||||
if (ctx->map_dir_list_size
|
||||
>= sizeof(ctx->map_dir_list) / sizeof(char *)) {
|
||||
printf("Only allow max map dir number %d\n",
|
||||
(int)(sizeof(ctx->map_dir_list) / sizeof(char *)));
|
||||
return 1;
|
||||
}
|
||||
ctx->map_dir_list[ctx->map_dir_list_size++] = arg + 10;
|
||||
}
|
||||
else if (!strncmp(arg, "--env=", 6)) {
|
||||
char *tmp_env;
|
||||
|
||||
@ -145,8 +164,8 @@ libc_wasi_init(wasm_module_t wasm_module, int argc, char **argv,
|
||||
libc_wasi_parse_context_t *ctx)
|
||||
{
|
||||
wasm_runtime_set_wasi_args(wasm_module, ctx->dir_list, ctx->dir_list_size,
|
||||
NULL, 0, ctx->env_list, ctx->env_list_size, argv,
|
||||
argc);
|
||||
ctx->map_dir_list, ctx->map_dir_list_size,
|
||||
ctx->env_list, ctx->env_list_size, argv, argc);
|
||||
|
||||
wasm_runtime_set_wasi_addr_pool(wasm_module, ctx->addr_pool,
|
||||
ctx->addr_pool_size);
|
||||
|
||||
@ -194,8 +194,11 @@ app_instance_repl(wasm_module_inst_t module_inst)
|
||||
break;
|
||||
}
|
||||
if (app_argc != 0) {
|
||||
const char *exception;
|
||||
wasm_application_execute_func(module_inst, app_argv[0],
|
||||
app_argc - 1, app_argv + 1);
|
||||
if ((exception = wasm_runtime_get_exception(module_inst)))
|
||||
printf("%s\n", exception);
|
||||
}
|
||||
free(app_argv);
|
||||
}
|
||||
@ -406,7 +409,7 @@ module_reader_callback(package_type_t module_type, const char *module_name,
|
||||
const char *format = "%s/%s%s";
|
||||
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name)
|
||||
+ strlen(file_format) + 1;
|
||||
char *wasm_file_name = BH_MALLOC(sz);
|
||||
char *wasm_file_name = wasm_runtime_malloc(sz);
|
||||
if (!wasm_file_name) {
|
||||
return false;
|
||||
}
|
||||
@ -432,7 +435,37 @@ moudle_destroyer(uint8 *buffer, uint32 size)
|
||||
|
||||
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
|
||||
static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 };
|
||||
#else
|
||||
static void *
|
||||
malloc_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
unsigned int size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void *
|
||||
realloc_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
void *ptr, unsigned int size)
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
static void
|
||||
free_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
#endif /* end of WASM_ENABLE_GLOBAL_HEAP_POOL */
|
||||
|
||||
#if WASM_ENABLE_STATIC_PGO != 0
|
||||
static void
|
||||
@ -764,9 +797,13 @@ main(int argc, char *argv[])
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
#else
|
||||
init_args.mem_alloc_type = Alloc_With_Allocator;
|
||||
init_args.mem_alloc_option.allocator.malloc_func = malloc;
|
||||
init_args.mem_alloc_option.allocator.realloc_func = realloc;
|
||||
init_args.mem_alloc_option.allocator.free_func = free;
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
/* Set user data for the allocator is needed */
|
||||
/* init_args.mem_alloc_option.allocator.user_data = user_data; */
|
||||
#endif
|
||||
init_args.mem_alloc_option.allocator.malloc_func = malloc_func;
|
||||
init_args.mem_alloc_option.allocator.realloc_func = realloc_func;
|
||||
init_args.mem_alloc_option.allocator.free_func = free_func;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_FAST_JIT != 0
|
||||
|
||||
@ -161,8 +161,11 @@ app_instance_repl(wasm_module_inst_t module_inst)
|
||||
break;
|
||||
}
|
||||
if (app_argc != 0) {
|
||||
const char *exception;
|
||||
wasm_application_execute_func(module_inst, app_argv[0],
|
||||
app_argc - 1, app_argv + 1);
|
||||
if ((exception = wasm_runtime_get_exception(module_inst)))
|
||||
printf("%s\n", exception);
|
||||
}
|
||||
free(app_argv);
|
||||
}
|
||||
@ -172,7 +175,37 @@ app_instance_repl(wasm_module_inst_t module_inst)
|
||||
|
||||
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
|
||||
static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 };
|
||||
#else
|
||||
static void *
|
||||
malloc_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
unsigned int size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void *
|
||||
realloc_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
void *ptr, unsigned int size)
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
static void
|
||||
free_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
#endif /* end of WASM_ENABLE_GLOBAL_HEAP_POOL */
|
||||
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
static char *
|
||||
@ -200,7 +233,7 @@ module_reader_callback(package_type_t module_type, const char *module_name,
|
||||
const char *format = "%s/%s%s";
|
||||
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name)
|
||||
+ strlen(file_format) + 1;
|
||||
char *wasm_file_name = BH_MALLOC(sz);
|
||||
char *wasm_file_name = wasm_runtime_malloc(sz);
|
||||
if (!wasm_file_name) {
|
||||
return false;
|
||||
}
|
||||
@ -414,9 +447,13 @@ main(int argc, char *argv[])
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
#else
|
||||
init_args.mem_alloc_type = Alloc_With_Allocator;
|
||||
init_args.mem_alloc_option.allocator.malloc_func = malloc;
|
||||
init_args.mem_alloc_option.allocator.realloc_func = realloc;
|
||||
init_args.mem_alloc_option.allocator.free_func = free;
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
/* Set user data for the allocator is needed */
|
||||
/* init_args.mem_alloc_option.allocator.user_data = user_data; */
|
||||
#endif
|
||||
init_args.mem_alloc_option.allocator.malloc_func = malloc_func;
|
||||
init_args.mem_alloc_option.allocator.realloc_func = realloc_func;
|
||||
init_args.mem_alloc_option.allocator.free_func = free_func;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_JIT != 0
|
||||
|
||||
@ -248,7 +248,7 @@ fail1:
|
||||
|
||||
end = k_uptime_get_32();
|
||||
|
||||
printf("elpase: %d\n", (end - start));
|
||||
printf("elapsed: %d\n", (end - start));
|
||||
}
|
||||
|
||||
#define MAIN_THREAD_STACK_SIZE (CONFIG_MAIN_THREAD_STACK_SIZE)
|
||||
|
||||
Reference in New Issue
Block a user