mmap seems to be in both the top half and bottom half of wasi-sdk's muslc https://github.com/WebAssembly/wasi-libc/blob/1dfe5c302d1c5ab621f7abf04620fae92700fd22/libc-top-half/musl/src/mman/mmap.c and https://github.com/WebAssembly/wasi-libc/blob/1dfe5c302d1c5ab621f7abf04620fae92700fd22/libc-bottom-half/mman/mman.c . The top half is a weak reference so does that means it's not used, in which case why does it exist?
The top half code is there because we didn't go through musl and delete everything that we're not using. It's disabled either via #ifdef
or via the Makefile.
Thank you!
Scott Waye has marked this topic as resolved.
WASI and Wasm don't have a real mmap
, so musl
's mmap code which just expects to invoke a system call isn't usable. In the bottom half code, we have code that emulates some amount of mmap
functionality using malloc
+ read
Yes, I'm looking at the bottom half and the fact that it injects a struct at the start, which presumably is why it doesn't attempt to do the page aligning
It could align internally, but the value returned would not be aligned as the struct would offset the usable space.
I guess it could, wastefully, allocate an extra page which just contained the struct.
@Scott Waye , yes, that's it. Getting non-aligned memory can be problematic or not depending on your needs. Also, the page size in Wasm is 64KiB (vs. 4KiB in x86_64), so the amount of wasted memory would be quite big.
Last updated: Dec 23 2024 at 12:05 UTC