Commit Graph

1 Commits

Author SHA1 Message Date
DotDebian 4dea441f01
fix(libkernel): do not expose stale thread-specific values through a reused pthread key
scePthreadKeyDelete frees a key slot and the next scePthreadKeyCreate
hands the same index out again, but every thread kept the value it had
stored under that index. The new key read the previous key's value
instead of NULL, and at thread exit its destructor was called on that
stale pointer.

Each slot now carries a sequence number, as in FreeBSD libthr. A thread
value is visible to scePthreadGetspecific and to the exit destructors
only while its sequence matches the slot's, so a new key starts as NULL
in every thread, as POSIX requires, and a deleted key reads NULL.

scePthreadGetspecific stays lock-free and scePthreadSetspecific no
longer takes the key lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 00:26:20 +00:00