fix(libkernel): ignore MAP_EXCL in fixed anonymous mmap as measured on a PS5 #11173

Merged
p3n1cillin merged 2 commits from upstream-pr/11173 into main 2026-10-27 02:01:30 +00:00
p3n1cillin commented 2026-10-25 20:35:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-25T20:35:24Z.


What

mmap with MAP_FIXED | MAP_EXCL followed FreeBSD 11.4: over an occupied range or a reservation it failed with ENOMEM and left the range alone. The console behaves differently.

Prospero Win (PPSA99995) records this in patch 0570: the PS5 kernel accepts MAP_EXCL but ignores it. MAP_FIXED | MAP_EXCL | MAP_PRIVATE | MAP_ANON over an existing mapping replaces it without error, measured on firmware 12.02. Wine's initial reservations unmapped the title's own code that way, which is why that patch moved Wine to sceKernelReserveVirtualRange with the no-overwrite flag.

A title that relies on the console's behaviour gets ENOMEM here where the console succeeds.

  • Fixed anonymous mmap: now accepts MAP_EXCL and ignores it, so the range is replaced and zeroed exactly as with MAP_FIXED alone.
  • MAP_EXCL without MAP_FIXED: still EINVAL, following FreeBSD. That case is not measured.
  • Other calls: sceKernelReserveVirtualRange's own no-overwrite flag and the other mapping calls are unchanged.
  • Debt: the libkernel entry now cites Prospero Win's report, says it isn't measured here, and lists what remains unmeasured.

Tests that pinned the FreeBSD result now expect the console's:

  • GuestMemory: MAP_EXCL over a mapped page and over a reservation succeeds and zeroes the range, and the neighbouring pages keep their contents.
  • GuestLowAddressMemory: the same over a low-address mapping.
  • GuestKernelStackProtect (Windows): the case expecting MAP_EXCL over a stack page to be refused is removed. Plain MAP_FIXED may replace that page, so with MAP_EXCL ignored it isn't a refusal.

Tested

  • Windows 11 Pro (26300), WinLibs GCC 15.2.0, Release, full build on main 7a25f87620: all 395 tests registered by libc and libkernel pass.
  • WSL Ubuntu 26.04.1, GCC 15.2.0: guest_memory and guest_low_address_memory pass.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py reports only #10192, which rewrites the same libkernel debt entry for failed fixed reservations without changing MAP_EXCL. The two only conflict in that line's text.
  • Prospero Win itself no longer uses MAP_EXCL, so no title run shows the difference.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008449620 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11173). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-25T20:35:24Z. --- ### What `mmap` with `MAP_FIXED | MAP_EXCL` followed FreeBSD 11.4: over an occupied range or a reservation it failed with `ENOMEM` and left the range alone. The console behaves differently. Prospero Win (PPSA99995) records this in [patch 0570](https://github.com/mpereiraesaa/prospero-win/blob/59c48117119fd57cd33e7bc91c11fa0c8ebf8b3d/wine/patches/0570-ntdll-ps5-reserve-virtual-range.patch#L7-L10): the PS5 kernel accepts `MAP_EXCL` but ignores it. `MAP_FIXED | MAP_EXCL | MAP_PRIVATE | MAP_ANON` over an existing mapping replaces it without error, measured on firmware 12.02. Wine's initial reservations unmapped the title's own code that way, which is why that patch moved Wine to `sceKernelReserveVirtualRange` with the no-overwrite flag. A title that relies on the console's behaviour gets `ENOMEM` here where the console succeeds. - **Fixed anonymous `mmap`:** now accepts `MAP_EXCL` and ignores it, so the range is replaced and zeroed exactly as with `MAP_FIXED` alone. - **`MAP_EXCL` without `MAP_FIXED`:** still `EINVAL`, following FreeBSD. That case is not measured. - **Other calls:** `sceKernelReserveVirtualRange`'s own no-overwrite flag and the other mapping calls are unchanged. - **Debt:** the libkernel entry now cites Prospero Win's report, says it isn't measured here, and lists what remains unmeasured. Tests that pinned the FreeBSD result now expect the console's: - **`GuestMemory`:** `MAP_EXCL` over a mapped page and over a reservation succeeds and zeroes the range, and the neighbouring pages keep their contents. - **`GuestLowAddressMemory`:** the same over a low-address mapping. - **`GuestKernelStackProtect` (Windows):** the case expecting `MAP_EXCL` over a stack page to be refused is removed. Plain `MAP_FIXED` may replace that page, so with `MAP_EXCL` ignored it isn't a refusal. ### Tested - **Windows 11 Pro (26300), WinLibs GCC 15.2.0, Release, full build on `main` 7a25f87620:** all 395 tests registered by libc and libkernel pass. - **WSL Ubuntu 26.04.1, GCC 15.2.0:** `guest_memory` and `guest_low_address_memory` pass. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py` reports only #10192, which rewrites the same libkernel debt entry for failed fixed reservations without changing `MAP_EXCL`. The two only conflict in that line's text. - Prospero Win itself no longer uses `MAP_EXCL`, so no title run shows the difference. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 20:42:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T20:42:17Z.

Review: COMMENTED


I reviewed the change at head 8df80bdc3f124a86d1fe1a4fe6e12709569af1a7. The fixed-anonymous path now strips MAP_EXCL before calling the shared remap machinery, while retaining the existing MAP_EXCL-without-MAP_FIXED validation. The revised tests cover replacement of both a committed mapping and a reservation, zero-fill, and the non-fixed invalid case. I did not find a concrete issue in this narrow change.

tools/check_conventions.py --base upstream/main --head HEAD completed with no errors (it emits the existing long-debt-entry warning), and git diff --check passed. The PR reports passing Windows and focused Linux memory tests and includes the console behavior evidence; I have not reproduced the PS5 measurement. Hosted eligibility, conventions, intake, labels, and report passed, while product build jobs were skipped. This is a comment-only review, not an independent platform approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645168994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11173#pullrequestreview-5645168994). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T20:42:17Z. **Review:** COMMENTED --- I reviewed the change at head `8df80bdc3f124a86d1fe1a4fe6e12709569af1a7`. The fixed-anonymous path now strips `MAP_EXCL` before calling the shared remap machinery, while retaining the existing `MAP_EXCL`-without-`MAP_FIXED` validation. The revised tests cover replacement of both a committed mapping and a reservation, zero-fill, and the non-fixed invalid case. I did not find a concrete issue in this narrow change. `tools/check_conventions.py --base upstream/main --head HEAD` completed with no errors (it emits the existing long-debt-entry warning), and `git diff --check` passed. The PR reports passing Windows and focused Linux memory tests and includes the console behavior evidence; I have not reproduced the PS5 measurement. Hosted eligibility, conventions, intake, labels, and report passed, while product build jobs were skipped. This is a comment-only review, not an independent platform approval.
klosixgaming-arch commented 2026-10-25 21:45:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-25T21:45:48Z.

Review: COMMENTED


Reviewed head 8df80bdc3f by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine.

What it does. Fixed anonymous mmap with MAP_EXCL now ignores the flag: the range is replaced and zeroed as with MAP_FIXED alone, instead of failing with ENOMEM and leaving the range alone. MAP_EXCL without MAP_FIXED is still EINVAL. The code change is small and clean: placement is just MAP_FIXED, and DoMapAnon is called with exclusive = false.

My concern is the evidence, not the code. This flips behaviour from FreeBSD 11.4's (documented, safe) to a destructive one, so the quality of the measurement matters. The PR cites patch 0570 of Prospero Win, a Wine patch, whose comment says the PS5 kernel "accepts MAP_EXCL but ignores it", measured on firmware 12.02. That is a second-hand report from another project's patch, not a measurement in this repo, and the PR says no title run shows the difference ("Prospero Win itself no longer uses MAP_EXCL"). Titles that probe with MAP_EXCL expecting failure would now overwrite a live mapping silently.

Asks:

  1. If a first-party measurement is possible (even a small payload under the hardware oracle the repo already uses for other syscalls), link it. If not, the debt entry should call this "reported by Prospero Win, firmware 12.02, not measured here", so the claim is not stronger than the source.
  2. The PR removes one refusal test and rewrites several others. Please add a test that a neighbouring page is untouched, since a mapping that "ignores EXCL" should still only replace the requested range.
  3. Check for a now-unused GuestMapExclusive or GuestMapNoOverwrite constant in PosixMemory.cpp; with -Werror an unused constexpr in an anonymous namespace may or may not warn on the supported compilers.

The overlap with #10192 is real but, as MarcZX10 checked, only in the text of one debt line.

I would approve once point 1 is settled one way or the other. I am not blocking because the PR describes its source honestly.

AI-assisted: yes. Written with AI assistance and reviewed by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645479927 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11173#pullrequestreview-5645479927). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-25T21:45:48Z. **Review:** COMMENTED --- Reviewed head `8df80bdc3f` by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine. **What it does.** Fixed anonymous `mmap` with `MAP_EXCL` now ignores the flag: the range is replaced and zeroed as with `MAP_FIXED` alone, instead of failing with `ENOMEM` and leaving the range alone. `MAP_EXCL` without `MAP_FIXED` is still `EINVAL`. The code change is small and clean: `placement` is just `MAP_FIXED`, and `DoMapAnon` is called with `exclusive = false`. **My concern is the evidence, not the code.** This flips behaviour from FreeBSD 11.4's (documented, safe) to a destructive one, so the quality of the measurement matters. The PR cites patch 0570 of Prospero Win, a Wine patch, whose comment says the PS5 kernel "accepts `MAP_EXCL` but ignores it", measured on firmware 12.02. That is a second-hand report from another project's patch, not a measurement in this repo, and the PR says no title run shows the difference ("Prospero Win itself no longer uses `MAP_EXCL`"). Titles that probe with `MAP_EXCL` expecting failure would now overwrite a live mapping silently. **Asks:** 1. If a first-party measurement is possible (even a small payload under the hardware oracle the repo already uses for other syscalls), link it. If not, the debt entry should call this "reported by Prospero Win, firmware 12.02, not measured here", so the claim is not stronger than the source. 2. The PR removes one refusal test and rewrites several others. Please add a test that a *neighbouring* page is untouched, since a mapping that "ignores EXCL" should still only replace the requested range. 3. Check for a now-unused `GuestMapExclusive` or `GuestMapNoOverwrite` constant in `PosixMemory.cpp`; with `-Werror` an unused constexpr in an anonymous namespace may or may not warn on the supported compilers. The overlap with #10192 is real but, as MarcZX10 checked, only in the text of one debt line. I would approve once point 1 is settled one way or the other. I am not blocking because the PR describes its source honestly. AI-assisted: yes. Written with AI assistance and reviewed by me.
klosixgaming-arch commented 2026-10-26 07:21:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-26T07:21:19Z.

Review: APPROVED


Re-reviewed head 2387f0ece7 by reading the diff since my first review. I did not build or run it.

My three points are addressed. The debt entry now says the behaviour is reported by Prospero Win (firmware 12.02) and not measured here, and that the no-MAP_FIXED case is not measured either. The test now checks that the pages before each replaced range keep their bytes. The constants are still in use. Approving, with the usual caveat that the claim is second-hand until someone measures it on a console.

AI-assisted: yes. Written with AI assistance and reviewed by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5648623797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11173#pullrequestreview-5648623797). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-26T07:21:19Z. **Review:** APPROVED --- Re-reviewed head `2387f0ece7` by reading the diff since my first review. I did not build or run it. My three points are addressed. The debt entry now says the behaviour is reported by Prospero Win (firmware 12.02) and not measured here, and that the no-`MAP_FIXED` case is not measured either. The test now checks that the pages before each replaced range keep their bytes. The constants are still in use. Approving, with the usual caveat that the claim is second-hand until someone measures it on a console. AI-assisted: yes. Written with AI assistance and reviewed by me.
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!11173
No description provided.