bytecodealliance / wasm-micro-runtime

WebAssembly Micro Runtime (WAMR)
Apache License 2.0
4.99k stars 628 forks source link

Can the XIP feature support Nuttx? #1172

Open dongsheng28849455 opened 2 years ago

dongsheng28849455 commented 2 years ago

Currently, wamr has already supported XIP feature on Windows&Posix, the entry is as below:

if (wasm_runtime_is_xip_file(wasm_file_buf, wasm_file_size)) {
    ...
    int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC;
    wasm_file_mapped =  os_mmap(NULL, (uint32)wasm_file_size, map_prot, map_flags);
   ...
   bh_memcpy_s(wasm_file_mapped, wasm_file_size, wasm_file_buf,  wasm_file_size);
   wasm_file_buf = wasm_file_mapped;
...
}
wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,  error_buf, sizeof(error_buf))

But It looks like that the .aot is mapped into RAM and not run inside AOT file directly?

And for Nuttx, os_mmap only the same with malloc, and some chip like esp32 does not support running text in PSRAM, which is allocated by malloc, how can the XIP work in such case? (like Nuttx-esp32)

I suppose that with following steps: 1, map the .aot within a segment of virtual space with MMAP_PROT_EXEC tag (do not allocate in RAM) 2, loading the .aot and parsing its function table without relocation. 3, enable indirect mode, let the internal funcion called by aot_call_indirect

Do you think that is reasonable and is there any suggestion about that?

no1wudi commented 2 years ago

In this case, you can implement your own iwasm utility (put the AOT-XIP file context in a special executable flash region and run from it) or implement proper os_mmap for your platform (like #1181).