Use Darling reserved key definitions from libpthread

This commit is contained in:
Ariel Abreu 2023-10-04 23:32:09 -04:00
parent 55bcc0bf89
commit 7783b11291
No known key found for this signature in database
GPG Key ID: 5B88AAAF4280706F
4 changed files with 9 additions and 8 deletions

View File

@ -0,0 +1 @@
../../../../../../../../../../src/external/xnu/darling/src/libsystem_kernel/emulation/linux/tsd.h

@ -1 +1 @@
Subproject commit 1cdf76eab5b283fc282dbe605eb632da6e3a6e68
Subproject commit f07f265bfbcf071c1adfc808de971e053ea5edc5

2
src/external/xnu vendored

@ -1 +1 @@
Subproject commit b2bd57725b78e715b6cf396d451ca29a68e77748
Subproject commit 99020685f14fd3f7a9466fc692f16ecf440f3f39

View File

@ -27,16 +27,16 @@ struct tls_table {
};
// since we still need to handle some calls after pthread_terminate is called and libpthread unwinds its TLS right before calling pthread_terminate,
// we have to use a slightly hackier technique: using one of the system's reserved but unused TLS keys.
// key 200 seems like a good fit; it's in the reserved region but it's not currently listed in `pthread/tsd_private.h` as being in-use by anything.
// we have to use a slightly hackier technique: using one of the system's reserved but unused TLS keys; we use one from the range we currently reserve
// for Darling.
#define __PTK_XTRACE_TLS 200
#include <darling/emulation/tsd.h>
// TODO: also perform TLS cleanup for other threads when doing a fork
extern "C"
void xtrace_tls_thread_cleanup(void) {
tls_table_t table = (tls_table_t)_pthread_getspecific_direct(__PTK_XTRACE_TLS);
tls_table_t table = (tls_table_t)_pthread_getspecific_direct(__PTK_DARLING_XTRACE_TLS);
if (!table) {
xtrace_tls_debug("no table to cleanup for this thread");
return;
@ -58,7 +58,7 @@ extern "C"
void* xtrace_tls(void* key, size_t size, bool* created, xtrace_tls_destructor_f destructor) {
xtrace_tls_debug("looking up tls variable for key %p", key);
tls_table_t table = (tls_table_t)_pthread_getspecific_direct(__PTK_XTRACE_TLS);
tls_table_t table = (tls_table_t)_pthread_getspecific_direct(__PTK_DARLING_XTRACE_TLS);
xtrace_tls_debug("got %p as table pointer from pthread", table);
@ -70,7 +70,7 @@ void* xtrace_tls(void* key, size_t size, bool* created, xtrace_tls_destructor_f
xtrace_abort("xtrace: failed TLS table memory allocation");
}
table->size = 0;
_pthread_setspecific_direct(__PTK_XTRACE_TLS, table);
_pthread_setspecific_direct(__PTK_DARLING_XTRACE_TLS, table);
}
// check if the key is already present