Extend os_mmap to support map file from fd (#2763)

Add an extra argument `os_file_handle file` for `os_mmap` to support
mapping file from a file fd, and remove `os_get_invalid_handle` from
`posix_file.c` and `win_file.c`, instead, add it in the `platform_internal.h`
files to remove the dependency on libc-wasi.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi
2023-11-16 08:28:54 +08:00
committed by GitHub
parent 0b8a904193
commit 24aa1cb408
35 changed files with 127 additions and 45 deletions

View File

@ -250,7 +250,8 @@ handle_cmd_load_module(uint64 *args, uint32 argc)
if (total_size >= UINT32_MAX
|| !(enclave_module = (EnclaveModule *)os_mmap(
NULL, (uint32)total_size, map_prot, map_flags))) {
NULL, (uint32)total_size, map_prot, map_flags,
os_get_invalid_handle()))) {
set_error_buf(error_buf, error_buf_size,
"WASM module load failed: mmap memory failed.");
*(void **)args_org = NULL;

View File

@ -848,8 +848,8 @@ main(int argc, char *argv[])
int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC;
int map_flags = MMAP_MAP_32BIT;
if (!(wasm_file_mapped =
os_mmap(NULL, (uint32)wasm_file_size, map_prot, map_flags))) {
if (!(wasm_file_mapped = os_mmap(NULL, (uint32)wasm_file_size, map_prot,
map_flags, os_get_invalid_handle()))) {
printf("mmap memory failed\n");
wasm_runtime_free(wasm_file_buf);
goto fail1;

View File

@ -488,8 +488,8 @@ main(int argc, char *argv[])
int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC;
int map_flags = MMAP_MAP_32BIT;
if (!(wasm_file_mapped =
os_mmap(NULL, (uint32)wasm_file_size, map_prot, map_flags))) {
if (!(wasm_file_mapped = os_mmap(NULL, (uint32)wasm_file_size, map_prot,
map_flags, os_get_invalid_handle()))) {
printf("mmap memory failed\n");
wasm_runtime_free(wasm_file_buf);
goto fail1;