Skip to content

feat(libkernel): accept MAP_ALIGNED_SUPER in mmap - #1909

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
TheAggie:feat/libkernel-mmap-aligned-super
Oct 10, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
TheAggie:feat/libkernel-mmap-aligned-super

Conversation

@TheAggie

@TheAggie TheAggie commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

@klosixgaming-arch klosixgaming-arch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Dextroid17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

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

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
An anonymous private mapping with MAP_ALIGNED_SUPER (FreeBSD MAP_ALIGNED(1))
is placed on a 2 MiB superpage boundary. Yamagi Quake II requests it for its
hunk allocations of 2 MiB and more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TheAggie
TheAggie force-pushed the feat/libkernel-mmap-aligned-super branch from 38537c9 to 456dc87 Compare October 10, 2026 05:57
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit 874c144 into boykopovar:main Oct 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants