Repository navigation
fix(libc): keep the guest heap alive through static finalization - #19496
Merged
oneandonlydean merged 1 commit intoNov 13, 2026
Merged
Conversation
Contributor
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
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.
What
guest_heap_lifetimefails on macOS withguest heap during exit: mutex lock failed: Invalid argument. The guest heap (ArenaHeap::Get()) is a function-local static, so its destructor runs during static finalization, and anatexithandler registered before the heap's first use runs after it. Its size-classstd::mutexes are then destroyed. On glibc, locking a destroyed mutex happens to work; on macOSpthread_mutex_lockon a destroyed mutex fails withEINVAL, and libc++ throwsstd::system_error. A title whose static destructor oratexithandler allocates or frees guest memory therefore stops with that error at exit on macOS.ArenaHeap::Get()now returns a heap that is created once and never destroyed (static ArenaHeap& heap = *new ArenaHeap;). The heap only holds arena spans, free lists and locks, which the process releases at exit anyway, so nothing that the destructor did is lost. Linux and Windows get the same object lifetime.The draft #12849 (optional span reclaim) makes the same one-line change as part of a larger feature. This PR is that line alone, with the macOS failure it fixes; whichever lands second drops it.
Tested
macOS 27.2, Apple M4 Pro, x86-64 build under Rosetta 2,
maind4556df:main:guest_heap_lifetimefails (guest heap during exit: mutex lock failed: Invalid argument).guest_heap_lifetimepasses 5 runs out of 5;guest_heap_report_for_game,guest_heap_trace_info,guest_malloc_lifecycle,guest_reallocalignpass.Not run on Linux or Windows.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)