feat(libkernel): accept MAP_ALIGNED_SUPER in mmap #1909

Merged
TheAggie merged 1 commit from upstream-pr/1909 into main 2026-10-10 08:44:58 +00:00
TheAggie commented 2026-10-08 23:23:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T23:23:37Z.


What

mmap rejected any flag beyond MAP_PRIVATE | MAP_ANON for anonymous mappings. Quake II (PPSA99007, the Yamagi-based homebrew port) adds MAP_ALIGNED_SUPER (0x1000000, FreeBSD's MAP_ALIGNED(1)) to its hunk allocations of 2 MiB and more.

With that flag, an anonymous private mapping is now placed on a 2 MiB superpage boundary. DoMapAnon takes the alignment, defaulting to the 16 KiB page as before, and passes it to the existing MapAligned. Other flags are still rejected.

Test (guest_memory): a MAP_ALIGNED_SUPER mapping of 2 MiB + one page is 2 MiB aligned, writable at both ends and tracked with its full size, and unmaps. Another unsupported flag combination (0x2001002) is still rejected.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.

  • The full suite (489 tests) passes on current main with this PR and four other small PRs of mine merged together (SCHED_OTHER priority range, MAP_ALIGNED_SUPER, the compatible pad vibration mode, empty-PT_TLS stack-guard reads, pthread_attr scope/getters). It was run from the generated CTestTestfile.cmake commands because antivirus blocks ctest.exe on this machine.
  • tools/check_conventions.py --base origin/main passes on this branch alone.

Not tested on Linux or macOS.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4793972738 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1909). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T23:23:37Z. --- ### What `mmap` rejected any flag beyond `MAP_PRIVATE | MAP_ANON` for anonymous mappings. Quake II (PPSA99007, the Yamagi-based homebrew port) adds `MAP_ALIGNED_SUPER` (`0x1000000`, FreeBSD's `MAP_ALIGNED(1)`) to its hunk allocations of 2 MiB and more. With that flag, an anonymous private mapping is now placed on a 2 MiB superpage boundary. `DoMapAnon` takes the alignment, defaulting to the 16 KiB page as before, and passes it to the existing `MapAligned`. Other flags are still rejected. Test (`guest_memory`): a `MAP_ALIGNED_SUPER` mapping of 2 MiB + one page is 2 MiB aligned, writable at both ends and tracked with its full size, and unmaps. Another unsupported flag combination (`0x2001002`) is still rejected. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. - The full suite (489 tests) passes on current `main` with this PR and four other small PRs of mine merged together (SCHED_OTHER priority range, MAP_ALIGNED_SUPER, the compatible pad vibration mode, empty-PT_TLS stack-guard reads, pthread_attr scope/getters). It was run from the generated `CTestTestfile.cmake` commands because antivirus blocks `ctest.exe` on this machine. - `tools/check_conventions.py --base origin/main` passes on this branch alone. Not tested on Linux or macOS. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
klosixgaming-arch commented 2026-10-09 00:40:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-09T00:40:56Z.

Review: APPROVED


Clean, correct support for MAP_ALIGNED_SUPER (0x1000000) in the anonymous mmap path: the flag is accepted on top of MAP_PRIVATE|MAP_ANONYMOUS (any other bit still returns ENOTSUPPORTED/45), the 2 MiB superpage alignment is threaded through DoMapAnon → MapAligned, and the default stays PS5_PAGE_SIZE so existing callers are unaffected. The test verifies the returned pointer is actually 2 MiB-aligned, that the full superpage + page span is readable/writable as a single allocation, and that an unsupported flag combination is still rejected.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5464488902 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1909#pullrequestreview-5464488902). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-09T00:40:56Z. **Review:** APPROVED --- Clean, correct support for `MAP_ALIGNED_SUPER` (0x1000000) in the anonymous `mmap` path: the flag is accepted on top of `MAP_PRIVATE|MAP_ANONYMOUS` (any other bit still returns ENOTSUPPORTED/45), the 2 MiB superpage alignment is threaded through `DoMapAnon` → `MapAligned`, and the default stays `PS5_PAGE_SIZE` so existing callers are unaffected. The test verifies the returned pointer is actually 2 MiB-aligned, that the full `superpage + page` span is readable/writable as a single allocation, and that an unsupported flag combination is still rejected. Written with AI assistance.
Dextroid17 commented 2026-10-09 02:58:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T02:58:10Z.

Review: COMMENTED


Verified on Linux — and this one has a behavioural differential.

  • Arm A (this PR): guest_memory_tests builds and passes, exit 0.
  • Arm B (control): the three DirectMemory files back at main with the test kept, rebuilt the same way → the test aborts, exit 134 (its Require is std::abort()), i.e. on main the flag is still refused. So both the acceptance and the superpage placement come from this change.

Claim cross-check: DoMapAnon takes the alignment and defaults it to PS5_PAGE_SIZE, the anonymous path passes SuperpageSize (2 MiB) only when GuestAlignedSuper (0x1000000) is set, and the guard became (flags & ~GuestAlignedSuper) != (GuestPrivate | GuestAnonymous) — every other flag is still refused. The test covers both halves: a 2 MiB + one page mapping lands on a 2 MiB boundary, is writable at both ends and tracked at its full size, and 0x2001002 is still rejected.

Two notes:

  • A grep for the title's MAP_ALIGNED_SUPER finds nothing in the tree, because the code calls it GuestAlignedSuper and SuperpageSize. Worth spelling both out in the body, since a future reader will search the FreeBSD name.
  • Question: does the alignment still hold when the guest passes an address hint (*addr != nullptr)? MapAligned receives *addr, and the test maps with a null hint — if a hint can win over the superpage alignment, a caller checking its own alignment would see something else.

The title is named (Quake II PPSA99007).

Not verified: Windows, the author's platform.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465208550 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1909#pullrequestreview-5465208550). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T02:58:10Z. **Review:** COMMENTED --- Verified on Linux — and this one has a behavioural differential. - **Arm A (this PR)**: `guest_memory_tests` builds and passes, **exit 0**. - **Arm B (control)**: the three `DirectMemory` files back at `main` with the test kept, rebuilt the same way → the test **aborts, exit 134** (its `Require` is `std::abort()`), i.e. on `main` the flag is still refused. So both the acceptance and the superpage placement come from this change. **Claim cross-check**: `DoMapAnon` takes the alignment and defaults it to `PS5_PAGE_SIZE`, the anonymous path passes `SuperpageSize` (2 MiB) only when `GuestAlignedSuper` (`0x1000000`) is set, and the guard became `(flags & ~GuestAlignedSuper) != (GuestPrivate | GuestAnonymous)` — every other flag is still refused. The test covers both halves: a 2 MiB + one page mapping lands on a 2 MiB boundary, is writable at both ends and tracked at its full size, and `0x2001002` is still rejected. Two notes: - A grep for the title's `MAP_ALIGNED_SUPER` finds nothing in the tree, because the code calls it `GuestAlignedSuper` and `SuperpageSize`. Worth spelling both out in the body, since a future reader will search the FreeBSD name. - **Question**: does the alignment still hold when the guest passes an address hint (`*addr != nullptr`)? `MapAligned` receives `*addr`, and the test maps with a null hint — if a hint can win over the superpage alignment, a caller checking its own alignment would see something else. The title is named (Quake II PPSA99007). Not verified: Windows, the author's platform. Written with AI assistance.
oneandonlydean commented 2026-10-09 20:14:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:14:48Z.


Same as #1868: Quake II stops at system (#1859) and mkstemp (#1613) on main first. Please reopen when it reaches the mmap call.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088511485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1909#issuecomment-6088511485). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:14:48Z. --- Same as #1868: Quake II stops at `system` (#1859) and `mkstemp` (#1613) on main first. Please reopen when it reaches the `mmap` call.
adriadam10 commented 2026-10-10 08:44:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:44:55Z.


Checked on Linux: build and ctest green (guest_memory passes); with the three non-test files reverted the new test fails, so it covers the change. Other flag bits are still rejected, and the default alignment is unchanged. Confirmed also by @Dextroid17's A/B run. Regarding the note about Quake II stopping earlier: the change is generic and correct on its own, so merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095800445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1909#issuecomment-6095800445). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T08:44:55Z. --- Checked on Linux: build and ctest green (`guest_memory` passes); with the three non-test files reverted the new test fails, so it covers the change. Other flag bits are still rejected, and the default alignment is unchanged. Confirmed also by @Dextroid17's A/B run. Regarding the note about Quake II stopping earlier: the change is generic and correct on its own, so merging.
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!1909
No description provided.