vita: exit through newlib and let pte own its per-thread slot behind a switch - #24
Open
frangarcj wants to merge 3 commits into
Open
vita: exit through newlib and let pte own its per-thread slot behind a switch#24frangarcj wants to merge 3 commits into
frangarcj wants to merge 3 commits into
Conversation
With struct _reent in native TLS a thread's newlib buffers die with its TLS block, so exiting through vita_exit_thread/vita_exit_delete_thread is the only way to reclaim them. Assisted-by: Claude Opus 5
Newlib's kernel-TLS slot table exists to host struct _reent. With the reent in native TLS the table is a directory of pointers to memory pte already mallocs itself, so pte can hold the kernel slot directly and newlib can drop the table, the mutex and the slot along with it. The key list moves into pspThreadData, collapsing the two slots pte used into one. The slot stays a kernel TLS slot rather than a TPIDRURO-relative block because pte_osThreadCancel, pte_osThreadDelete and pte_osThreadWaitForEnd reach another thread's data through its thid. __VITA_NEWLIB_THREAD_SLOT__ selects between the two, defaulting to the newlib slot, so this builds and behaves exactly as before against every newlib that still provides it. Assisted-by: Claude Opus 5
__VITA_NEWLIB_THREAD_SLOT__ -> __VITA_NEWLIB_OWNS_THREAD_SLOT__. Assisted-by: Claude Opus 5
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 does this change?
Three changes on the Vita OSAL. Threads exit through newlib's
vita_exit_thread/vita_exit_delete_threadinstead of callingsceKernelExitThread/sceKernelExitDeleteThreaddirectly, so newlib can reclaim the thread's own buffers before its TLS block disappears. The per-thread slot pthread-embedded uses can be owned by pthread-embedded itself instead of newlib, behind the__VITA_NEWLIB_THREAD_SLOT__switch newlib exports in<sys/vita_thread.h>; at the default value everything behaves as today. The last commit follows newlib's rename of that switch.Why is this change needed?
Phase A of vitasdk/.github#3. With
struct _reentin native TLS, a thread's newlib buffers die with its TLS block, and the only place that can reclaim them is the exiting thread itself; routing the exit through newlib's entry points is what makes that possible. The switch lets pthread-embedded stop depending on newlib's 256-entry slot table once newlib no longer owns it, without changing behaviour before then.Testing
newlib-testsbuilt against the native-TLS newlib with this pthread-embedded, 88 tests, 82 pass, 0 failures, 6 skips; the TLS group includes pthread churn with heap bounds,errnoisolation between pthreads, and C++thread_localconstruction/destruction on pthread return.Compatibility
No API change. At the default switch value, no ABI or behaviour change. Requires the newlib that declares
vita_exit_thread/vita_exit_delete_thread(vitasdk/newlib#115); older newlib does not declare them and the link fails loudly rather than silently. Part of RFC vitasdk/.github#3.Third-party material
None.
AI assistance
Additional context
RFC: vitasdk/.github#3. Companion: vitasdk/newlib#115, vitasdk/vita-toolchain#294.