Stream: wasi

Topic: ✔ mmap in top half or bottom half


view this post on Zulip Scott Waye (May 04 2023 at 23:31):

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?

WASI libc implementation for WebAssembly. Contribute to WebAssembly/wasi-libc development by creating an account on GitHub.
WASI libc implementation for WebAssembly. Contribute to WebAssembly/wasi-libc development by creating an account on GitHub.

view this post on Zulip Dan Gohman (May 04 2023 at 23:33):

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.

view this post on Zulip Scott Waye (May 04 2023 at 23:34):

Thank you!

view this post on Zulip Notification Bot (May 04 2023 at 23:34):

Scott Waye has marked this topic as resolved.

view this post on Zulip Dan Gohman (May 04 2023 at 23:34):

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

view this post on Zulip Scott Waye (May 04 2023 at 23:41):

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

view this post on Zulip Scott Waye (May 04 2023 at 23:41):

It could align internally, but the value returned would not be aligned as the struct would offset the usable space.

view this post on Zulip Scott Waye (May 04 2023 at 23:42):

I guess it could, wastefully, allocate an extra page which just contained the struct.

view this post on Zulip Jesús González (May 10 2023 at 08:39):

@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: Nov 22 2024 at 16:03 UTC