mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-28 12:05:06 +00:00
FreeBSD code reaches its thread pointer through %fs and macOS cannot set the fs base. The macOS relinker turns each %fs access of a guest image into a stub that reads the thread pointer from a pthread key and calls Aps5GuestTlsAllocate on a thread's first access, registers the TLS descriptor of an image with Aps5GuestTlsRegister, and routes __tls_get_addr to Aps5GuestTlsGetAddr. No library provided them, so a relinked executable could not start. - Aps5GuestTlsRegister validates the descriptor the relinker wrote and creates the key; its destructor frees the block of a thread. - Aps5GuestTlsAllocateThreadPointer allocates the block (the TLS template followed by zeros, then a 0x100-byte thread control block whose first word points at itself, as on FreeBSD) and stores the thread pointer under the key. - Aps5GuestTlsAllocate is the entry the stubs call: rax holds the descriptor and returns the thread pointer, every other register is preserved, the upper halves of the ymm registers only where AVX exists. - Aps5GuestTlsGetAddr returns the block of the thread plus the offset. Co-authored-by: mugurc <[email protected]>