Conversation
Two static globals in src/syscall/mem.c, mmap_r{w,x}_gap_hint, described
a specific guest's region layout and would alias if 2 guest_t instances
ever coexisted in one process (test harnesses, future multi-VM use).
Move both fields into guest_t.
guest_reset zeroes them; guest_{init,init_from_shm} zero them via memset.
The public mmap_reset_hints() helper and its callers in src/syscall/exec.c
(right after guest_reset) and src/runtime/fork-state.c (right after
syscall_init in fork_ipc_recv_fd_table) are no longer needed and removed.
find_free_gap loses const on its guest_t argument to mutate the per-guest
hints; it is static so the change has no cross-TU API impact. The four
munmap/mremap rewind sites point at g->mmap_*_gap_hint instead.
Audited the rest of the module-level state in src/. Host-derived caches
(sysinfo, host_port, totalram, getloadavg, cached uname/groups/affinity/
rlimits) stay process-global by design: any future second guest in this
process would share the same host stats. Other process-scoped tables
(proc_table, next_guest_pid, pidfd/inotify/netlink/sysv-ipc/abstract-
socket tables, futex buckets, thread_table, signal state, procemu temp
dirs, log state) remain global because the current architecture is one
VM per macOS process (HVF restriction) and fork uses posix_spawn into a
fresh process. Documented the sysinfo cache inline as intentionally
process-scoped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two static globals in src/syscall/mem.c, mmap_r{w,x}_gap_hint, described a specific guest's region layout and would alias if 2 guest_t instances ever coexisted in one process (test harnesses, future multi-VM use). Move both fields into guest_t.
guest_reset zeroes them; guest_{init,init_from_shm} zero them via memset. The public mmap_reset_hints() helper and its callers in src/syscall/exec.c (right after guest_reset) and src/runtime/fork-state.c (right after syscall_init in fork_ipc_recv_fd_table) are no longer needed and removed. find_free_gap loses const on its guest_t argument to mutate the per-guest hints; it is static so the change has no cross-TU API impact. The four munmap/mremap rewind sites point at g->mmap_*_gap_hint instead.
Audited the rest of the module-level state in src/. Host-derived caches (sysinfo, host_port, totalram, getloadavg, cached uname/groups/affinity/ rlimits) stay process-global by design: any future second guest in this process would share the same host stats. Other process-scoped tables (proc_table, next_guest_pid, pidfd/inotify/netlink/sysv-ipc/abstract- socket tables, futex buckets, thread_table, signal state, procemu temp dirs, log state) remain global because the current architecture is one VM per macOS process (HVF restriction) and fork uses posix_spawn into a fresh process. Documented the sysinfo cache inline as intentionally process-scoped.
Summary by cubic
Isolate mmap gap-finder hints per guest to prevent cross-guest allocator state leaks and remove unnecessary global cleanup. This fixes aliasing in multi-guest test setups and prepares for future multi-VM scenarios.
mmap_rw_gap_hintandmmap_rx_gap_hintintoguest_t; zeroed inguest_resetand init paths.mmap_reset_hints()and its calls inexec.candfork-state.c.find_free_gapto take a non-constguest_t *to update per-guest hints; remainsstatic.sys_munmap/sys_mremapto rewindg->mmap_*_gap_hintinstead of globals.sysinfocache as intentionally process-scoped; no behavior change.Written for commit f1c1a63. Summary will update on new commits.