wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Can the XIP feature support Nuttx?

Open dongsheng28849455 opened this issue 3 years ago • 1 comments

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?

dongsheng28849455 avatar May 16 '22 06:05 dongsheng28849455

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).

no1wudi avatar May 23 '22 02:05 no1wudi