fix(libkernel): map Windows shared memory with the regular file checks #12296

Merged
JJenkx merged 1 commit from upstream-pr/12296 into main 2026-10-30 01:04:05 +00:00
JJenkx commented 2026-10-28 07:58:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T07:58:49Z.


What

On Windows, mmap sent a shared memory descriptor straight to the shared file mapper (DoMapFileBacked). It skipped the access checks and the private path that a regular file descriptor takes. Shared memory objects are files there: anonymous objects are delete-on-close temporary files, and named objects are files under AnyPS5/shm. Skipping those steps produced two errors:

  • MAP_PRIVATE of a named or anonymous object failed with EOPNOTSUPP (45), because DoMapFileBacked refuses private mappings on Windows. FreeBSD maps them, and a private mapping of a regular file on Windows already works as a copy of the file read at mmap (MapPrivateFileCopy).
  • A writable MAP_SHARED mapping of a read-only descriptor failed with EIO (5): the section was created read-only and the writable view then failed. FreeBSD and the regular-file path return EACCES.

Shared memory descriptors now take the same handle lookup, access checks and private copy as a regular file. Only the refusal of directories, the random device and non-disk handles stays limited to other descriptors. Shared mappings still go through the same section code as before.

A new Windows test, guest_named_shm_windows_mapping (GuestNamedShmWindowsMapping.cpp), maps a named object:

  • shared, through two descriptors;
  • against pread and pwrite;
  • at an offset;
  • private, with its stores staying out of the object;
  • read-only, plus a refused writable shared mapping of a read-only descriptor;
  • after shm_unlink.

Until now no Windows test mapped a named object; the named-object mapping tests are Linux-only. The libkernel debt entry that said so is updated, and is now shorter than on main.

Tested

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, Vulkan drivers hidden. Base main 660a0b306d.

  • Without the fix (the new test on main's PosixMemory.cpp): it aborts at "a private mapping of the named object failed (guest errno 45)". With the private case moved last, it aborts at "a writable shared mapping of a read-only descriptor was not refused with EACCES (guest errno 5)". The shared, offset and pread/pwrite checks already pass on main.
  • With the fix: these 17 tests pass in each of 3 runs. They are every Windows test whose source calls mmap, plus the named shared-memory Windows tests: guest_named_shm_windows_mapping, guest_named_shm_windows (with its short_temp and long_short_temp variants), guest_shm_open, guest_jit_shared_memory, guest_memory, guest_mmap_fixed_anonymous, guest_low_address_memory, guest_mprotect_unmapped, guest_msync, guest_kernel_stack_protect, guest_posix_filesystem, guest_system_configuration and the guest_kernel_app_archive* tests.

Not tested on Linux or macOS. The change is inside the _WIN32 branch only.

Overlap. tools/pr_overlap.py reports two textual conflicts with no shared behaviour:

  • #11625 renames the line above this change (mappingDescriptor = sourceDescriptor); merged, the line takes that name and keeps this block.
  • #10645 edits the two debt entries right after the one changed here.

Proposed merge order: this PR first, then #11625 and #10645 take the small textual merge; asked on #11625 and #10645. If either author prefers to go first, this PR will declare Depends on that PR and be rebased after it lands. #12339's author agreed that this PR lands before #12339, whose copy of the same check then becomes unreachable.

Current Linux qualification — 2026-10-29

Rebased onto main 5454cd2e455 as dc1d801c4ce47fe1083ac473619f60400ad560f6. Production, regression and CMake topic additions/removals are preserved exactly. The debt resolution keeps main’s #12339 read/execute permission details alongside this PR’s regular-file mapping statement; all recursive submodule pointers match main.

Linux: libc/libkernel build, and five memory/shared-memory groups pass three repetitions (15 passes, zero skips). The actual Windows production translation unit also passes MinGW GCC16.2.0 cross syntax checking on Linux. That is not Windows execution: the existing Windows pause remains in force, so earlier actual Windows tests retain their historical source pins. Conventions and whitespace pass.

The #11625/#10645 author-order questions remain unanswered, so no agreement is claimed. #12339 has now merged; its production check and debt details are preserved in this refresh. AI-assisted: yes.

Evidence: immutable Linux qualification bundle. Its SHA-256 is ca6b35926bcc6d3f21a9650517894c86b65594e2e2b653c5c32cd1c1de89c835. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins.

AI-assisted: yes (Codex).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (proposed order above; awaiting #11625's and #10645's authors)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5047155882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12296). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T07:58:49Z. --- ### What On Windows, `mmap` sent a shared memory descriptor straight to the shared file mapper (`DoMapFileBacked`). It skipped the access checks and the private path that a regular file descriptor takes. Shared memory objects are files there: anonymous objects are delete-on-close temporary files, and named objects are files under `AnyPS5/shm`. Skipping those steps produced two errors: - `MAP_PRIVATE` of a named or anonymous object failed with `EOPNOTSUPP` (45), because `DoMapFileBacked` refuses private mappings on Windows. FreeBSD maps them, and a private mapping of a regular file on Windows already works as a copy of the file read at `mmap` (`MapPrivateFileCopy`). - A writable `MAP_SHARED` mapping of a read-only descriptor failed with `EIO` (5): the section was created read-only and the writable view then failed. FreeBSD and the regular-file path return `EACCES`. Shared memory descriptors now take the same handle lookup, access checks and private copy as a regular file. Only the refusal of directories, the random device and non-disk handles stays limited to other descriptors. Shared mappings still go through the same section code as before. A new Windows test, `guest_named_shm_windows_mapping` (`GuestNamedShmWindowsMapping.cpp`), maps a named object: - shared, through two descriptors; - against `pread` and `pwrite`; - at an offset; - private, with its stores staying out of the object; - read-only, plus a refused writable shared mapping of a read-only descriptor; - after `shm_unlink`. Until now no Windows test mapped a named object; the named-object mapping tests are Linux-only. The libkernel debt entry that said so is updated, and is now shorter than on `main`. ### Tested Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`, Vulkan drivers hidden. Base `main` `660a0b306d`. - **Without the fix** (the new test on `main`'s `PosixMemory.cpp`): it aborts at "a private mapping of the named object failed (guest errno 45)". With the private case moved last, it aborts at "a writable shared mapping of a read-only descriptor was not refused with EACCES (guest errno 5)". The shared, offset and `pread`/`pwrite` checks already pass on `main`. - **With the fix:** these 17 tests pass in each of 3 runs. They are every Windows test whose source calls `mmap`, plus the named shared-memory Windows tests: `guest_named_shm_windows_mapping`, `guest_named_shm_windows` (with its `short_temp` and `long_short_temp` variants), `guest_shm_open`, `guest_jit_shared_memory`, `guest_memory`, `guest_mmap_fixed_anonymous`, `guest_low_address_memory`, `guest_mprotect_unmapped`, `guest_msync`, `guest_kernel_stack_protect`, `guest_posix_filesystem`, `guest_system_configuration` and the `guest_kernel_app_archive*` tests. Not tested on Linux or macOS. The change is inside the `_WIN32` branch only. **Overlap.** `tools/pr_overlap.py` reports two textual conflicts with no shared behaviour: - #11625 renames the line above this change (`mappingDescriptor = sourceDescriptor`); merged, the line takes that name and keeps this block. - #10645 edits the two debt entries right after the one changed here. Proposed merge order: this PR first, then #11625 and #10645 take the small textual merge; asked on [#11625](https://github.com/boykopovar/AnyPS5/pull/11625#issuecomment-6466759733) and [#10645](https://github.com/boykopovar/AnyPS5/pull/10645#issuecomment-6466760203). If either author prefers to go first, this PR will declare **Depends on** that PR and be rebased after it lands. #12339's author [agreed](https://github.com/boykopovar/AnyPS5/pull/12296#issuecomment-6472565267) that this PR lands before #12339, whose copy of the same check then becomes unreachable. <!-- codex-maintenance-20261029-repeat-12296 --> **Current Linux qualification — 2026-10-29** Rebased onto `main` `5454cd2e455` as `dc1d801c4ce47fe1083ac473619f60400ad560f6`. Production, regression and CMake topic additions/removals are preserved exactly. The debt resolution keeps main’s #12339 read/execute permission details alongside this PR’s regular-file mapping statement; all recursive submodule pointers match main. Linux: libc/libkernel build, and five memory/shared-memory groups pass three repetitions (15 passes, zero skips). The actual Windows production translation unit also passes MinGW GCC16.2.0 cross syntax checking on Linux. That is not Windows execution: the existing Windows pause remains in force, so earlier actual Windows tests retain their historical source pins. Conventions and whitespace pass. The #11625/#10645 author-order questions remain unanswered, so no agreement is claimed. #12339 has now merged; its production check and debt details are preserved in this refresh. AI-assisted: yes. Evidence: [immutable Linux qualification bundle](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/cpu-complete-current-main-linux-20261029.tar.gz). Its SHA-256 is `ca6b35926bcc6d3f21a9650517894c86b65594e2e2b653c5c32cd1c1de89c835`. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins. AI-assisted: yes (Codex). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (proposed order above; awaiting #11625's and #10645's authors) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-28 08:45:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T08:45:23Z.

Review: APPROVED


Reviewed the Windows-only mapping change against the regular-file path and the new regression test. Descriptor lookup and access-mode checks now run for shared-memory handles as well, while disk-type refusal stays scoped to other descriptors; shared mappings still use the existing section mapper and private mappings use the copy path. The test covers shared visibility through two descriptors and pread/pwrite, nonzero offsets, private copy isolation, read-only access enforcement, and post-unlink lifetime. Current Windows CI and conventions pass; the author reports the relevant Windows mmap suite passing three times. Linux/macOS were not tested, but the code change is confined to _WIN32. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5679936117 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12296#pullrequestreview-5679936117). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T08:45:23Z. **Review:** APPROVED --- Reviewed the Windows-only mapping change against the regular-file path and the new regression test. Descriptor lookup and access-mode checks now run for shared-memory handles as well, while disk-type refusal stays scoped to other descriptors; shared mappings still use the existing section mapper and private mappings use the copy path. The test covers shared visibility through two descriptors and pread/pwrite, nonzero offsets, private copy isolation, read-only access enforcement, and post-unlink lifetime. Current Windows CI and conventions pass; the author reports the relevant Windows mmap suite passing three times. Linux/macOS were not tested, but the code change is confined to `_WIN32`. No blocking issue found.
MarcZX10 commented 2026-10-28 09:08:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T09:08:13Z.

Review: CHANGES_REQUESTED


The Windows shared-memory path now takes the same descriptor lookup, access checks, and private-copy path as regular files, and the added test covers shared mappings across descriptors, file I/O coherence, offsets, read-only access, EACCES, unlink lifetime, and private-copy isolation. Hosted conventions and Windows checks pass; the author reports the Windows behavior tests, while the other platform jobs are skipped. One repository-rule item remains: the overlap check explicitly reports a conflict with open PR #11625 in PosixMemory.cpp, and #11625 is still open. CONTRIBUTING.md asks authors to agree which overlapping PR lands first and record the merge order with Depends on; the current description says no dependency. Please coordinate with #11625’s author and update the merge-order line, then rebase after the selected PR lands so the combined change preserves both behaviors.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680181253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12296#pullrequestreview-5680181253). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T09:08:13Z. **Review:** CHANGES_REQUESTED --- The Windows shared-memory path now takes the same descriptor lookup, access checks, and private-copy path as regular files, and the added test covers shared mappings across descriptors, file I/O coherence, offsets, read-only access, `EACCES`, unlink lifetime, and private-copy isolation. Hosted conventions and Windows checks pass; the author reports the Windows behavior tests, while the other platform jobs are skipped. One repository-rule item remains: the overlap check explicitly reports a conflict with open PR #11625 in `PosixMemory.cpp`, and #11625 is still open. `CONTRIBUTING.md` asks authors to agree which overlapping PR lands first and record the merge order with `Depends on`; the current description says no dependency. Please coordinate with #11625’s author and update the merge-order line, then rebase after the selected PR lands so the combined change preserves both behaviors.
MarcZX10 commented 2026-10-28 09:44:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T09:44:05Z.

Review: DISMISSED


The implementation and Windows test coverage look sound, and the Windows hosted build passes. I am requesting one contribution-rule correction before approval: this PR itself identifies overlaps with #11625 (the mapping-descriptor line) and #10645 (the libkernel debt entry), but the description says “Either can land first” without showing agreement from those authors or declaring an order under Depends on. CONTRIBUTING requires the overlapping PR authors to agree on order and record it. Please coordinate and update the checklist; I found no new code defect in this pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680631157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12296#pullrequestreview-5680631157). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T09:44:05Z. **Review:** DISMISSED --- The implementation and Windows test coverage look sound, and the Windows hosted build passes. I am requesting one contribution-rule correction before approval: this PR itself identifies overlaps with #11625 (the mapping-descriptor line) and #10645 (the libkernel debt entry), but the description says “Either can land first” without showing agreement from those authors or declaring an order under `Depends on`. CONTRIBUTING requires the overlapping PR authors to agree on order and record it. Please coordinate and update the checklist; I found no new code defect in this pass.
adriadam10 commented 2026-10-28 11:30:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T11:30:36Z.

Review: CHANGES_REQUESTED


Checked the PosixMemory.cpp change and guest_named_shm_windows_mapping: shared-memory descriptors now take the same handle lookup, access checks and private copy as regular files, the directory/random-device/non-disk refusal stays limited to other descriptors, and the test pins EACCES (13) for the writable shared mapping of a read-only descriptor and private-store isolation. I found no code change to ask for, and the Windows run from @babyhuey shows no failures from this PR.

  • The only open item is the landing order with #11625 and #10645 that @MarcZX10's change request is holding. Neither author has answered the questions yet. Once one of them confirms an order (or says it does not matter), record it under Depends on if it puts another PR first, and ask @MarcZX10 to re-review; no other change is needed.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681907729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12296#pullrequestreview-5681907729). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-28T11:30:36Z. **Review:** CHANGES_REQUESTED --- Checked the `PosixMemory.cpp` change and `guest_named_shm_windows_mapping`: shared-memory descriptors now take the same handle lookup, access checks and private copy as regular files, the directory/random-device/non-disk refusal stays limited to other descriptors, and the test pins `EACCES` (13) for the writable shared mapping of a read-only descriptor and private-store isolation. I found no code change to ask for, and the Windows run from @babyhuey shows no failures from this PR. - The only open item is the landing order with #11625 and #10645 that @MarcZX10's change request is holding. Neither author has answered the questions yet. Once one of them confirms an order (or says it does not matter), record it under **Depends on** if it puts another PR first, and ask @MarcZX10 to re-review; no other change is needed.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12296
No description provided.