core/iwasm: Support mapped file system access on non-libuv WASI (#2628)
This patch enables mapping host directories to guest directories by parsing the `map_dir_list` argument in API `wasm_runtime_init_wasi` for libc-wasi. It follows the format `<guest-path>::<host-path>`. It also adds argument `--map-dir=<guest::host>` argument for `iwasm` common line tool, and allows to add multiple mappings: ```bash iwasm --map-dir=<guest-path1::host-path1> --map-dir=<guest-path2::host-path2> ... ```
This commit is contained in:
committed by
GitHub
parent
8038b9c524
commit
9b8fe049b3
@ -75,6 +75,9 @@ print_help()
|
||||
printf(" --dir=<dir> Grant wasi access to the given host 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 with ',',\n");
|
||||
printf(" for example:\n");
|
||||
@ -573,6 +576,8 @@ main(int argc, char *argv[])
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
const char *dir_list[8] = { NULL };
|
||||
uint32 dir_list_size = 0;
|
||||
const char *map_dir_list[8] = { NULL };
|
||||
uint32 map_dir_list_size = 0;
|
||||
const char *env_list[8] = { NULL };
|
||||
uint32 env_list_size = 0;
|
||||
const char *addr_pool[8] = { NULL };
|
||||
@ -711,6 +716,16 @@ main(int argc, char *argv[])
|
||||
}
|
||||
dir_list[dir_list_size++] = argv[0] + 6;
|
||||
}
|
||||
else if (!strncmp(argv[0], "--map-dir=", 10)) {
|
||||
if (argv[0][10] == '\0')
|
||||
return print_help();
|
||||
if (map_dir_list_size >= sizeof(map_dir_list) / sizeof(char *)) {
|
||||
printf("Only allow max map dir number %d\n",
|
||||
(int)(sizeof(map_dir_list) / sizeof(char *)));
|
||||
return 1;
|
||||
}
|
||||
map_dir_list[map_dir_list_size++] = argv[0] + 10;
|
||||
}
|
||||
else if (!strncmp(argv[0], "--env=", 6)) {
|
||||
char *tmp_env;
|
||||
|
||||
@ -920,8 +935,9 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
wasm_runtime_set_wasi_args(wasm_module, dir_list, dir_list_size, NULL, 0,
|
||||
env_list, env_list_size, argv, argc);
|
||||
wasm_runtime_set_wasi_args(wasm_module, dir_list, dir_list_size,
|
||||
map_dir_list, map_dir_list_size, env_list,
|
||||
env_list_size, argv, argc);
|
||||
|
||||
wasm_runtime_set_wasi_addr_pool(wasm_module, addr_pool, addr_pool_size);
|
||||
wasm_runtime_set_wasi_ns_lookup_pool(wasm_module, ns_lookup_pool,
|
||||
|
||||
Reference in New Issue
Block a user