Pedro Henrique Penna d8acf2a7c5 sparse_mmap: add private copy-on-write file views (#4557)
`SparseMapping` can map files only as shared views, so writes to a
file-backed range always reach the file. Some callers need the opposite:
a view that starts with the file's contents, keeps every write private
to the process, and leaves the backing file untouched, for example when
restoring guest RAM from an immutable snapshot file.

## Summary

- add `new_mappable_from_file_copy_on_write` and
`SparseMapping::map_file_copy_on_write`
- on Unix, the mappable is a duplicate of the file descriptor, and the
view is mapped with `MAP_PRIVATE`; a file offset above `i64::MAX` is
rejected with `InvalidInput`
- on Windows, the mappable is a section created with `PAGE_WRITECOPY`,
and writable views are mapped with `PAGE_WRITECOPY`
- on Windows, refuse to split a copy-on-write view. Windows cannot unmap
part of a view, so `SparseMapping` splits one by re-mapping the rest
from the section, which would discard the view's private pages.
Unmapping or mapping over part of a view mapped (or later protected)
with `PAGE_WRITECOPY` or `PAGE_EXECUTE_WRITECOPY` now fails with
`ErrorKind::Unsupported`; whole views can still be unmapped or replaced
- existing shared mappings are unchanged
- add tests (adds `tempfile` as a dev-dependency):
- a cross-platform test that fills a writable private view, then checks
that the file bytes are unchanged and that a fresh view sees the
original contents
- cross-platform tests that unmapping or mapping over part of a written
view never discards the private writes of the rest of the view
  - a Unix test that an out-of-range file offset is rejected
- a Windows test that a read-only view can still be split, but not once
part of it is protected with `PAGE_WRITECOPY`

## Validation

On Windows x86-64 and Linux x86-64 (WSL2):

- `cargo check --locked -p sparse_mmap`
- `cargo clippy --all-targets -p sparse_mmap`
- `cargo doc --no-deps -p sparse_mmap`
- `cargo nextest run --profile agent -p sparse_mmap`
  - Windows: 18 passed, 1 skipped (the existing ignored large-page test)
  - Linux: 17 passed

Also ran `cargo xtask fmt --fix`.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ef640993-0003-4e49-b1ed-1b8b4776d0ef
Copilot-Session: bcd07604-9197-4195-950c-c86f57d6f081
2026-10-28 08:34:37 -07:00
.
2024-10-03 13:21:23 -07:00
.
2024-10-03 13:21:23 -07:00
2025-12-19 22:20:27 +00:00

OpenVMM

Build Status

OpenVMM is a modular, cross-platform Virtual Machine Monitor (VMM), written in Rust.

Although it can function as a traditional VMM, OpenVMM's development is currently focused on its role in the OpenHCL paravisor.

This repo is the home for both projects.

For more information, read our guide or our introductory blog post.

Getting Started

For info on how to run, build, and use OpenVMM, check out the The OpenVMM Guide.

The guide is published out of this repo via Markdown files. Please keep them up-to-date.

The maintainers of this project use Discord to collaborate with external contributors and users. Please join if you have any questions about contributing to or using OpenVMM/OpenHCL.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit Contributor License Agreements.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

S
Description
No description provided
Readme MIT 119 MiB
Languages
Rust 98.6%
TypeScript 0.5%
Python 0.3%
PowerShell 0.2%