From 24aa1cb408290a7299772e42ace6111bec5197e1 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Thu, 16 Nov 2023 08:28:54 +0800 Subject: [PATCH] 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 --- core/app-mgr/app-manager/module_wasm_app.c | 2 +- core/iwasm/aot/aot_loader.c | 16 ++++++++++------ core/iwasm/aot/aot_runtime.c | 4 ++-- core/iwasm/common/wasm_exec_env.c | 3 ++- core/iwasm/fast-jit/jit_codecache.c | 4 ++-- core/iwasm/interpreter/wasm_runtime.c | 3 ++- core/shared/platform/alios/alios_platform.c | 2 +- core/shared/platform/alios/platform_internal.h | 6 ++++++ core/shared/platform/android/platform_internal.h | 6 ++++++ core/shared/platform/common/posix/posix_file.c | 6 ------ core/shared/platform/common/posix/posix_memmap.c | 8 ++++---- core/shared/platform/common/posix/posix_thread.c | 2 +- core/shared/platform/darwin/platform_internal.h | 6 ++++++ core/shared/platform/esp-idf/espidf_memmap.c | 2 +- core/shared/platform/esp-idf/platform_internal.h | 6 ++++++ core/shared/platform/freebsd/platform_internal.h | 8 ++++++++ .../platform/include/platform_api_vmcore.h | 2 +- .../platform/linux-sgx/platform_internal.h | 6 ++++++ core/shared/platform/linux-sgx/sgx_platform.c | 11 +++++++++-- core/shared/platform/linux/platform_internal.h | 6 ++++++ core/shared/platform/nuttx/nuttx_platform.c | 2 +- core/shared/platform/nuttx/platform_internal.h | 6 ++++++ core/shared/platform/riot/platform_internal.h | 6 ++++++ core/shared/platform/riot/riot_platform.c | 2 +- .../platform/rt-thread/platform_internal.h | 6 ++++++ core/shared/platform/rt-thread/rtt_platform.c | 2 +- core/shared/platform/vxworks/platform_internal.h | 6 ++++++ core/shared/platform/windows/platform_internal.h | 6 ++++++ core/shared/platform/windows/win_file.c | 6 ------ core/shared/platform/windows/win_memmap.c | 2 +- core/shared/platform/zephyr/platform_internal.h | 6 ++++++ core/shared/platform/zephyr/zephyr_platform.c | 2 +- .../linux-sgx/enclave-sample/Enclave/Enclave.cpp | 3 ++- product-mini/platforms/posix/main.c | 4 ++-- product-mini/platforms/windows/main.c | 4 ++-- 35 files changed, 127 insertions(+), 45 deletions(-) diff --git a/core/app-mgr/app-manager/module_wasm_app.c b/core/app-mgr/app-manager/module_wasm_app.c index 2005ad8e8..6fd929b10 100644 --- a/core/app-mgr/app-manager/module_wasm_app.c +++ b/core/app-mgr/app-manager/module_wasm_app.c @@ -1467,7 +1467,7 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch, int request_total_size, if (total_size >= UINT32_MAX || !(section->section_body = os_mmap(NULL, (uint32)total_size, map_prot, - map_flags))) { + map_flags, os_get_invalid_handle()))) { app_manager_printf( "Allocate executable memory failed!\n"); SEND_ERR_RESPONSE(recv_ctx.message.request_mid, diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 6575c8aca..37084ba8e 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -1574,8 +1574,9 @@ load_object_data_sections(const uint8 **p_buf, const uint8 *buf_end, /* Allocate memory for data */ if (data_sections[i].size > 0 - && !(data_sections[i].data = os_mmap(NULL, data_sections[i].size, - map_prot, map_flags))) { + && !(data_sections[i].data = + os_mmap(NULL, data_sections[i].size, map_prot, map_flags, + os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "allocate memory failed"); return false; } @@ -2470,7 +2471,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, if (size > UINT32_MAX || !(module->extra_plt_data = - os_mmap(NULL, (uint32)size, map_prot, map_flags))) { + os_mmap(NULL, (uint32)size, map_prot, map_flags, + os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "mmap memory failed"); goto fail; } @@ -2593,7 +2595,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, size = (uint64)sizeof(void *) * got_item_count; if (size > UINT32_MAX || !(module->got_func_ptrs = - os_mmap(NULL, (uint32)size, map_prot, map_flags))) { + os_mmap(NULL, (uint32)size, map_prot, map_flags, + os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "mmap memory failed"); goto fail; } @@ -3106,8 +3109,9 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, (uint64)section_size + aot_get_plt_table_size(); total_size = (total_size + 3) & ~((uint64)3); if (total_size >= UINT32_MAX - || !(aot_text = os_mmap(NULL, (uint32)total_size, - map_prot, map_flags))) { + || !(aot_text = + os_mmap(NULL, (uint32)total_size, map_prot, + map_flags, os_get_invalid_handle()))) { wasm_runtime_free(section); set_error_buf(error_buf, error_buf_size, "mmap memory failed"); diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index b5cc6c3a6..f747cb43f 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -537,8 +537,8 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent, * both i and memarg.offset are u32 in range 0 to 4G * so the range of ea is 0 to 8G */ - if (!(p = mapped_mem = - os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE))) { + if (!(p = mapped_mem = os_mmap(NULL, map_size, MMAP_PROT_NONE, + MMAP_MAP_NONE, os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "mmap memory failed"); return NULL; } diff --git a/core/iwasm/common/wasm_exec_env.c b/core/iwasm/common/wasm_exec_env.c index a794b3fd8..d524c7de0 100644 --- a/core/iwasm/common/wasm_exec_env.c +++ b/core/iwasm/common/wasm_exec_env.c @@ -58,7 +58,8 @@ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst, #ifdef OS_ENABLE_HW_BOUND_CHECK if (!(exec_env->exce_check_guard_page = - os_mmap(NULL, os_getpagesize(), MMAP_PROT_NONE, MMAP_MAP_NONE))) + os_mmap(NULL, os_getpagesize(), MMAP_PROT_NONE, MMAP_MAP_NONE, + os_get_invalid_handle()))) goto fail5; #endif diff --git a/core/iwasm/fast-jit/jit_codecache.c b/core/iwasm/fast-jit/jit_codecache.c index 73a034f34..ef2074747 100644 --- a/core/iwasm/fast-jit/jit_codecache.c +++ b/core/iwasm/fast-jit/jit_codecache.c @@ -17,8 +17,8 @@ jit_code_cache_init(uint32 code_cache_size) int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC; int map_flags = MMAP_MAP_NONE; - if (!(code_cache_pool = - os_mmap(NULL, code_cache_size, map_prot, map_flags))) { + if (!(code_cache_pool = os_mmap(NULL, code_cache_size, map_prot, map_flags, + os_get_invalid_handle()))) { return false; } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 6f8295665..720a78f03 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -324,7 +324,8 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent, * so the range of ea is 0 to 8G */ if (!(memory->memory_data = mapped_mem = - os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE))) { + os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE, + os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "mmap memory failed"); goto fail1; } diff --git a/core/shared/platform/alios/alios_platform.c b/core/shared/platform/alios/alios_platform.c index 60393ae52..24bf9c7ff 100644 --- a/core/shared/platform/alios/alios_platform.c +++ b/core/shared/platform/alios/alios_platform.c @@ -47,7 +47,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { if ((uint64)size >= UINT32_MAX) return NULL; diff --git a/core/shared/platform/alios/platform_internal.h b/core/shared/platform/alios/platform_internal.h index 7e9740e6b..dbdf74953 100644 --- a/core/shared/platform/alios/platform_internal.h +++ b/core/shared/platform/alios/platform_internal.h @@ -68,4 +68,10 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif /* end of _BH_PLATFORM_H */ diff --git a/core/shared/platform/android/platform_internal.h b/core/shared/platform/android/platform_internal.h index d59daf144..42e4e726c 100644 --- a/core/shared/platform/android/platform_internal.h +++ b/core/shared/platform/android/platform_internal.h @@ -150,6 +150,12 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/common/posix/posix_file.c b/core/shared/platform/common/posix/posix_file.c index a0005b592..a16509760 100644 --- a/core/shared/platform/common/posix/posix_file.c +++ b/core/shared/platform/common/posix/posix_file.c @@ -978,12 +978,6 @@ os_closedir(os_dir_stream dir_stream) return __WASI_ESUCCESS; } -os_file_handle -os_get_invalid_handle() -{ - return -1; -} - os_dir_stream os_get_invalid_dir_stream() { diff --git a/core/shared/platform/common/posix/posix_memmap.c b/core/shared/platform/common/posix/posix_memmap.c index 5d33dcc81..583557bb8 100644 --- a/core/shared/platform/common/posix/posix_memmap.c +++ b/core/shared/platform/common/posix/posix_memmap.c @@ -37,7 +37,7 @@ round_down(uintptr_t v, uintptr_t b) #endif void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { int map_prot = PROT_NONE; #if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__) @@ -114,7 +114,7 @@ os_mmap(void *hint, size_t size, int prot, int flags) /* try 10 times, step with 1MB each time */ for (i = 0; i < 10 && hint_addr < (uint8 *)(uintptr_t)(2ULL * BH_GB); i++) { - addr = mmap(hint_addr, request_size, map_prot, map_flags, -1, 0); + addr = mmap(hint_addr, request_size, map_prot, map_flags, file, 0); if (addr != MAP_FAILED) { if (addr > (uint8 *)(uintptr_t)(2ULL * BH_GB)) { /* unmap and try again if the mapped address doesn't @@ -136,7 +136,7 @@ os_mmap(void *hint, size_t size, int prot, int flags) if (addr == MAP_FAILED) { /* try 5 times */ for (i = 0; i < 5; i++) { - addr = mmap(hint, request_size, map_prot, map_flags, -1, 0); + addr = mmap(hint, request_size, map_prot, map_flags, file, 0); if (addr != MAP_FAILED) break; } @@ -266,4 +266,4 @@ os_icache_flush(void *start, size_t len) #if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__) sys_icache_invalidate(start, len); #endif -} \ No newline at end of file +} diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index 157490a78..616420c94 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -664,7 +664,7 @@ os_thread_signal_init(os_signal_handler handler) /* Initialize memory for signal alternate stack of current thread */ if (!(map_addr = os_mmap(NULL, map_size, MMAP_PROT_READ | MMAP_PROT_WRITE, - MMAP_MAP_NONE))) { + MMAP_MAP_NONE, os_get_invalid_handle()))) { os_printf("Failed to mmap memory for alternate stack\n"); goto fail1; } diff --git a/core/shared/platform/darwin/platform_internal.h b/core/shared/platform/darwin/platform_internal.h index 8cbaf652e..30b89624e 100644 --- a/core/shared/platform/darwin/platform_internal.h +++ b/core/shared/platform/darwin/platform_internal.h @@ -113,6 +113,12 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/esp-idf/espidf_memmap.c b/core/shared/platform/esp-idf/espidf_memmap.c index ce94a9549..9f3ec47a6 100644 --- a/core/shared/platform/esp-idf/espidf_memmap.c +++ b/core/shared/platform/esp-idf/espidf_memmap.c @@ -19,7 +19,7 @@ static portMUX_TYPE s_spinlock = portMUX_INITIALIZER_UNLOCKED; #endif void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { if (prot & MMAP_PROT_EXEC) { #if (WASM_MEM_DUAL_BUS_MIRROR != 0) diff --git a/core/shared/platform/esp-idf/platform_internal.h b/core/shared/platform/esp-idf/platform_internal.h index 6c8fa8e62..70c4fe7b1 100644 --- a/core/shared/platform/esp-idf/platform_internal.h +++ b/core/shared/platform/esp-idf/platform_internal.h @@ -113,6 +113,12 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/freebsd/platform_internal.h b/core/shared/platform/freebsd/platform_internal.h index 5f9b54362..5241c6456 100644 --- a/core/shared/platform/freebsd/platform_internal.h +++ b/core/shared/platform/freebsd/platform_internal.h @@ -112,6 +112,14 @@ os_sigreturn(); void os_set_signal_number_for_blocking_op(int signo); +typedef int os_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/include/platform_api_vmcore.h b/core/shared/platform/include/platform_api_vmcore.h index c803c12e4..559141f75 100644 --- a/core/shared/platform/include/platform_api_vmcore.h +++ b/core/shared/platform/include/platform_api_vmcore.h @@ -130,7 +130,7 @@ enum { }; void * -os_mmap(void *hint, size_t size, int prot, int flags); +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file); void os_munmap(void *addr, size_t size); int diff --git a/core/shared/platform/linux-sgx/platform_internal.h b/core/shared/platform/linux-sgx/platform_internal.h index 0dd730482..c96768e32 100644 --- a/core/shared/platform/linux-sgx/platform_internal.h +++ b/core/shared/platform/linux-sgx/platform_internal.h @@ -73,6 +73,12 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/linux-sgx/sgx_platform.c b/core/shared/platform/linux-sgx/sgx_platform.c index 1a90af4c6..32b956826 100644 --- a/core/shared/platform/linux-sgx/sgx_platform.c +++ b/core/shared/platform/linux-sgx/sgx_platform.c @@ -120,13 +120,20 @@ strcpy(char *dest, const char *src) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { int mprot = 0; uint64 aligned_size, page_size; void *ret = NULL; sgx_status_t st = 0; + if (os_is_handle_valid(&file)) { + os_printf("os_mmap(size=%u, prot=0x%x, file=%x) failed: file is not " + "supported.\n", + size, prot, file); + return NULL; + } + page_size = getpagesize(); aligned_size = (size + page_size - 1) & ~(page_size - 1); @@ -198,4 +205,4 @@ os_dcache_flush(void) void os_icache_flush(void *start, size_t len) -{} \ No newline at end of file +{} diff --git a/core/shared/platform/linux/platform_internal.h b/core/shared/platform/linux/platform_internal.h index f94c4b689..335070bf8 100644 --- a/core/shared/platform/linux/platform_internal.h +++ b/core/shared/platform/linux/platform_internal.h @@ -126,6 +126,12 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 92c17ed48..38e70076d 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -85,7 +85,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { #if (WASM_MEM_DUAL_BUS_MIRROR != 0) void *i_addr, *d_addr; diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index b20c4a2c7..2fb80a6e3 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -134,6 +134,12 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/riot/platform_internal.h b/core/shared/platform/riot/platform_internal.h index 9f29b8fd5..1f71ffdb2 100644 --- a/core/shared/platform/riot/platform_internal.h +++ b/core/shared/platform/riot/platform_internal.h @@ -80,4 +80,10 @@ int isnan(double x); /* clang-format on */ #endif +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif /* end of _BH_PLATFORM_H */ diff --git a/core/shared/platform/riot/riot_platform.c b/core/shared/platform/riot/riot_platform.c index 6fd6617b4..ad5927e51 100644 --- a/core/shared/platform/riot/riot_platform.c +++ b/core/shared/platform/riot/riot_platform.c @@ -50,7 +50,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { if (size > ((unsigned)~0)) return NULL; diff --git a/core/shared/platform/rt-thread/platform_internal.h b/core/shared/platform/rt-thread/platform_internal.h index 6abba7383..0c2e1d82b 100644 --- a/core/shared/platform/rt-thread/platform_internal.h +++ b/core/shared/platform/rt-thread/platform_internal.h @@ -49,4 +49,10 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif /* RTTHREAD_PLATFORM_INTERNAL_H */ diff --git a/core/shared/platform/rt-thread/rtt_platform.c b/core/shared/platform/rt-thread/rtt_platform.c index 6dc719f01..37b247d35 100644 --- a/core/shared/platform/rt-thread/rtt_platform.c +++ b/core/shared/platform/rt-thread/rtt_platform.c @@ -191,7 +191,7 @@ os_cond_wait(korp_cond *cond, korp_mutex *mutex) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { return rt_malloc(size); } diff --git a/core/shared/platform/vxworks/platform_internal.h b/core/shared/platform/vxworks/platform_internal.h index a3f7fecc6..930ff7777 100644 --- a/core/shared/platform/vxworks/platform_internal.h +++ b/core/shared/platform/vxworks/platform_internal.h @@ -100,6 +100,12 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/windows/platform_internal.h b/core/shared/platform/windows/platform_internal.h index a537161f6..8bb77e7cb 100644 --- a/core/shared/platform/windows/platform_internal.h +++ b/core/shared/platform/windows/platform_internal.h @@ -187,6 +187,12 @@ typedef uint32_t os_raw_file_handle; #define UWP_DEFAULT_VPRINTF #endif +static inline os_file_handle +os_get_invalid_handle() +{ + return NULL; +} + #ifdef __cplusplus } #endif diff --git a/core/shared/platform/windows/win_file.c b/core/shared/platform/windows/win_file.c index 6e827118a..7e153b34e 100644 --- a/core/shared/platform/windows/win_file.c +++ b/core/shared/platform/windows/win_file.c @@ -1466,12 +1466,6 @@ os_is_dir_stream_valid(os_dir_stream *dir_stream) return true; } -os_file_handle -os_get_invalid_handle() -{ - return NULL; -} - bool os_is_handle_valid(os_file_handle *handle) { diff --git a/core/shared/platform/windows/win_memmap.c b/core/shared/platform/windows/win_memmap.c index c4a6b0756..db0f38a56 100644 --- a/core/shared/platform/windows/win_memmap.c +++ b/core/shared/platform/windows/win_memmap.c @@ -29,7 +29,7 @@ access_to_win32_flags(int prot) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { DWORD alloc_type = MEM_RESERVE; DWORD protect; diff --git a/core/shared/platform/zephyr/platform_internal.h b/core/shared/platform/zephyr/platform_internal.h index 4d27e8b41..048387817 100644 --- a/core/shared/platform/zephyr/platform_internal.h +++ b/core/shared/platform/zephyr/platform_internal.h @@ -152,4 +152,10 @@ typedef int os_file_handle; typedef DIR *os_dir_stream; typedef int os_raw_file_handle; +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif diff --git a/core/shared/platform/zephyr/zephyr_platform.c b/core/shared/platform/zephyr/zephyr_platform.c index 715be8b94..1a5b6621d 100644 --- a/core/shared/platform/zephyr/zephyr_platform.c +++ b/core/shared/platform/zephyr/zephyr_platform.c @@ -173,7 +173,7 @@ strcspn(const char *s, const char *reject) #endif void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { if ((uint64)size >= UINT32_MAX) return NULL; diff --git a/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp b/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp index 164fa0b7d..b854c70b4 100644 --- a/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp +++ b/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp @@ -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; diff --git a/product-mini/platforms/posix/main.c b/product-mini/platforms/posix/main.c index d8076ead8..c225b0858 100644 --- a/product-mini/platforms/posix/main.c +++ b/product-mini/platforms/posix/main.c @@ -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; diff --git a/product-mini/platforms/windows/main.c b/product-mini/platforms/windows/main.c index 98b33ffb0..921b77265 100644 --- a/product-mini/platforms/windows/main.c +++ b/product-mini/platforms/windows/main.c @@ -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;