Complete HEAPMNG page-map coverage and high-address coalescing - #164
Open
zhanghm18GIT wants to merge 2 commits into
Open
Complete HEAPMNG page-map coverage and high-address coalescing#164zhanghm18GIT wants to merge 2 commits into
zhanghm18GIT wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughThe HEAPMNG hook now allocates a full 4 MiB page map for 32-bit address-space coverage and uses ChangesHEAPMNG 4 GiB support
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Jul 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The memo
Summary
This PR completes the existing
HFix4GBHEAPMNG bookkeeping across the full 32-bit page-index range.It makes two same-size immediate-value changes in the existing
hooks/HFix4GB.cpppatch:0x400000bytes for the page map instead of0x3FF000;0x100000as the right-neighbour one-past-end page bound instead of0xC0000.No function is replaced and no new runtime code path is introduced.
Closes #163.
Related game-level evidence:
Allocator limitations
Incomplete page-map capacity
At
0x00957E35, the currentHFix4GBpatch emits:A complete 32-bit address space contains:
4 KiB page indices.
At four bytes per page-map entry, complete arithmetic capacity is:
0x3FF000provides0xFFC00entries and leaves the highest0x400pages, corresponding to 4 MiB of virtual-address range, without a page-map entry.3 GiB right-neighbour bound
At
0x00958107, the allocator computes the page index immediately after a freed region and compares it with:0xC00004 KiB pages corresponds to 3 GiB.The replacement uses
0x100000, the one-past-end page index for the complete 4 GiB 32-bit range. The existingJAEtherefore continues to reject an index at or beyond the end of the page map while allowing valid indices in the 3–4 GiB range to participate in the right-neighbour lookup.Implementation
This PR modifies the repository's existing
hooks/HFix4GB.cppfile.Page-map allocation
At
0x00957E35:Exact bytes:
Right-neighbour guard
At
0x00958107:Exact bytes:
Both instructions retain their original five-byte length.
The pre-existing Lua-GC control-flow patches in
HFix4GB.cppare unchanged.Changelog
The existing 4 GB improvement entry is updated to describe complete page-map coverage and high-address free-region coalescing.
Safety and runtime impact
PUSHkeeps the same stack behavior and changes only the allocation-size immediate.CMPkeeps the same flag semantics and changes only the upper-bound immediate.JAEprevents lookup at or beyond page index0x100000.The original rationale for the smaller constants is not documented in the repository. The arithmetic and one-past-end boundary behavior are exact; maintainer review can determine whether either legacy constant represented an additional invariant outside the visible HEAPMNG bookkeeping.
Evidence
An equivalent local executable candidate was produced from the tested baseline by changing only these two immediates and recalculating the PE checksum.
Tested baseline:
Equivalent allocator candidate:
The equivalent binary participated in the lowest-growth documented stress run:
Heap Total remained at
1.406 GiBfrom session time00:39:07through at least00:48:08.A separate run with the paired M28-side cache active reached:
The executable identity of that counterexample is not recoverable from its log. The runtime evidence therefore establishes successful operation of a configuration containing this patch while the independent contribution of these two immediate changes remains to be isolated by controlled A/B testing.
The intended engine-level effect is complete page-map bookkeeping and the ability to consider valid high-address right neighbours during free-region coalescing.
Validation performed
Source and opcode validation
96af320e872a083fdb302fde7406d6d7f17c418d;HFix4GB.cppcontent checked against that commit;Binary reconstruction
A verifier applied the two instruction replacements to the tested baseline, recalculated the PE checksum, and reproduced the known candidate byte-for-byte:
The reconstructed output differs from the baseline only at:
The PE entry point, image base, section table, Large Address Aware flag, and unrelated patch bytes remain unchanged.
Boundary model
0x100000;0xFFC00;0x400pages / 4 MiB;0xFFFFF;0x100000;Runtime evidence
The equivalent local binary has been used in real FAF games. The documented low-growth run is linked through
fa#7195.Repository workflow / patcher execution remains pending on the upstream PR.
Regression test instructions
0x00957E35:68 00 00 40 00;0x00958107:3D 00 00 10 00.fa#7195.VirtualAllocgrowth reservations;0x0095854F;>= 0xC0000;Files changed
Checklist
moho.h,global.h, orInfo.txt