Fix tls leak for non-primary thread (2)#4151
Open
rosenkolev1 wants to merge 1 commit intoshadps4-emu:mainfrom
Open
Fix tls leak for non-primary thread (2)#4151rosenkolev1 wants to merge 1 commit intoshadps4-emu:mainfrom
rosenkolev1 wants to merge 1 commit intoshadps4-emu:mainfrom
Conversation
Contributor
|
@raphaelthegreat Everything seems to be fine? |
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.
Attempt 1 - Removed all the fluff and left only the actual change.
Spoke with @red-prig a little and was told this change might make sense after all and that I can try opening a PR again.
The goal
To solve this.
The fix
We call
TcbCtor()->Linker::AllocateTlsForThread()and allocate tls memory for non-primary threads viaheap_api->heap_malloc()orstd::malloc()ataddr_out. InTcbDtor(), we don't callLinker::FreeTlsForNonPrimaryThread(tls_base)(tls_base==addr_outis the sam, we only call it for thedtv_tableentries.I don't believe we can call
TcbDtorfor the primary thread (that is, the "Game:Main" thread). When debugging the game, the code is never entered for that thread, only for non-primary threads. When we exit the emulator, I see we dostd::quick_exitand no destructors or additional GC logic for that thread is being hit.Still, if there is a case where that logic can be hit for the primary thread (or we want to be safe anyway), we can simply record if the thread is primary or not inside
TcbCtor()and guard against that insideTcbDtor()via a simple flag.Linker::FreeTlsForNonPrimaryThread()should handle freeing the memory the same way it was allocated, I don't think theheap_apican change mid-game after its set initially. Besides, we already free thedtv_tableentries with the same way. When debugging the game, theheap_apiis set before any non-primary threads are created and I didn't hit a case where the heap API changes afterwards.For what it's worth, I played the game 2 times, each for ~2-3 hours at a time, with the change applied and didn't get any crashes.