Enable Windows XIP (#944)

Enable running XIP file on Windows platform.
And add more strict checks for wamrc to report error when the input file
is same with output file, or the input file is AOT file but not wasm file.
This commit is contained in:
Wenyong Huang
2022-01-10 15:59:58 +08:00
committed by GitHub
parent ae18a03f60
commit 4b5543cc1a
4 changed files with 59 additions and 7 deletions

View File

@ -234,6 +234,7 @@ main(int argc, char *argv[])
int log_verbose_level = 2;
#endif
bool is_repl_mode = false;
bool is_xip_file = false;
#if WASM_ENABLE_LIBC_WASI != 0
const char *dir_list[8] = { NULL };
uint32 dir_list_size = 0;
@ -382,6 +383,27 @@ main(int argc, char *argv[])
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
goto fail1;
#if WASM_ENABLE_AOT != 0
if (wasm_runtime_is_xip_file(wasm_file_buf, wasm_file_size)) {
uint8 *wasm_file_mapped;
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))) {
printf("mmap memory failed\n");
wasm_runtime_free(wasm_file_buf);
goto fail1;
}
bh_memcpy_s(wasm_file_mapped, wasm_file_size, wasm_file_buf,
wasm_file_size);
wasm_runtime_free(wasm_file_buf);
wasm_file_buf = wasm_file_mapped;
is_xip_file = true;
}
#endif
#if WASM_ENABLE_MULTI_MODULE != 0
wasm_runtime_set_module_reader(module_reader_callback, moudle_destroyer);
#endif
@ -422,7 +444,10 @@ fail3:
fail2:
/* free the file buffer */
wasm_runtime_free(wasm_file_buf);
if (!is_xip_file)
wasm_runtime_free(wasm_file_buf);
else
os_munmap(wasm_file_buf, wasm_file_size);
fail1:
/* destroy runtime environment */