Repository navigation
Unmap empty memory-mapped views on Unix - #136793
RutulPatel8 wants to merge 4 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-system-io |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the empty-view mapping disposal fix.
No open issues 🎉
What changed in this PR
Fixes the Unix empty-view mapping leak described in #133744 by recording the actual native mapping length so disposal can unmap it.
Changes:
- Records the one-byte native size used when mapping an empty view.
- Adds a Linux regression test using
mincoreto verify the mapping exists before disposal and is released afterward.
| File | Description |
|---|---|
src/libraries/System.IO.MemoryMappedFiles/tests/SafeMemoryMappedViewHandleTests.cs |
Adds the Linux disposal regression test and mincore interop declaration. |
src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs |
Records and uses the actual native size for empty mappings. |
Review effort: Balanced
| Assert.Equal(0, MinCore(address, 1, &residency)); | ||
| } | ||
|
|
||
| Assert.Equal(-1, MinCore(address, 1, &residency)); |
There was a problem hiding this comment.
What guarantees that some other thread won't map something else at this address?
|
I pushed e6d2209 to address the latest review: the empty-view native mapping length is now a shared internal constant used by creation and release, and the zero-length handle test runs on all platforms. The new CI run is in progress. @jkotas, could you take another look when it completes? |
|
The newly added test is failing on Windows: So it looks like Windows implementation does not hide the size of the dummy region from the public API. It changes the breaking change point of view for your original fix. We want both Windows and Unix implementations to behave same way, and it makes more sense to align with Windows implementation since it is older (ie more code out there depends on its corner-case behaviors). |
Fixes #133744
An empty Unix view maps one byte because
mmaprejects a zero-length mapping. Its safe handle reports a logical length of zero, so disposal previously calledmunmap(address, 0)and leaked the native mapping.Use a minimum unmap length of one byte in
SafeMemoryMappedViewHandle.ReleaseHandle, preserving the existing zero-length view semantics. The test asserts that an empty view still reports a zero-length handle.Validation: the System.IO.MemoryMappedFiles library builds across its configured targets, and the Unix test project builds with zero warnings or errors. The Unix test cannot run on this Windows host.