Skip to main content

reserve_guest_va_range

Function reserve_guest_va_range 

Source
pub fn reserve_guest_va_range() -> Result<(), Error>
Expand description

One-time process-wide reservation of the [guest_va_base(), guest_va_base() + GUEST_VA_SIZE) range. Done on host startup so later mmaps of guest-visible regions (snapshot, scratch, kernel shadow) can land at known fixed VAs via MAP_FIXED inside this reservation.

On Linux we use MAP_FIXED_NOREPLACE to claim the configured base atomically; failure means something is squatting on the range, which is almost certainly a misconfiguration — error loudly.

On macOS MAP_FIXED_NOREPLACE doesn’t exist, so we let the kernel pick a base via plain mmap. macOS ASLR almost never places mid-range addresses, but if it does we munmap and retry up to ~10 times; the successful base is then stored so guest_va_base() returns it.