-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly Implement brk/sbrk and mmap #4
Comments
My opinion here:
|
Even if we call from our microvisor back into the runtime to do the memory mapping, etc., to me this seems preferable. I'd advise we don't have system calls that are directly handled by the runtime / caging infrastructure, if we can at all avoid it. |
Yeah I agree. I think the three things that the runtime currently does that we'd move or modify is 1. Creating a new instance of a cage (important for fork) 2. Creating new threads (for pthread_create, currently done by wasi-threads) 3. Modifying the bounds of linear memory (important for brk/mmap). So those are the scenarios that we probably need to put some thought into. |
We discussed how to move this forward today in the weekly meeting. Thank you @yizhuoliang for joining us. Here's how were breaking this down to proceed libc/wasmtime integration
RawPOSIX integration
Its important that any use of the vmmap occurs in the dispatcher step and not in the actual syscalls, ie mmap finds a hole address and sends that address w/ MAP_FIXED into mmap_syscall, or write() checks the address in the dispatcher before calling a valid write_syscall. |
I spoke with Dennis a bit about mmap yesterday and our thoughts are that there could be a separate memory region for each process for mmaps. We could statically allocate a larger part of the address space than mmap needs and then grow / shrink in response to requests. Happy to discuss if this isn't clear. Let me know if this is similar to your thoughts. I'm more trying to understand what the options are, rather than to push hard for a specific solution. |
In theory this is how the VMMap would handle things on a pretty basic level. I think there's several reasons why using the VMMap instead of a "greedy" implementation is preferrable/necessary:
|
The VMMap port for Rust is like 95% finished and looks like it is implemented in a way that should be much more performant than NaCl's implementation. So I believe we have a path forward here. |
Added in #56 |
We implemented
brk
/sbrk
in glibc (userspace) by over-allocating to a page-aligned address and exposing a pseudo-break to the caller. This makesmalloc
fully functional for small chunks usingsbrk
. For larger chunks,malloc
triggers themmap
path, which is not yet handled. Now, we should movebrk
/sbrk
to the runtime space as syscalls and add a mutex to the pseudo-break to prevent race conditions.We also need to properly handle
mmap
. The WASI-libc implementation ofmmap
is an emulation ofmalloc
, which, after discussing with Nick and Coulson, is not acceptable by us. Therefore, we need to handle it in the runtime. For now, I used an ad-hoc solution by usingmalloc
as well.The text was updated successfully, but these errors were encountered: