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:
@ -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");
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user