Use dynamic memory for *NSYNC waiters

This commit is contained in:
Justine Tunney 2023-11-10 01:42:06 -08:00
parent 15af5c2d7e
commit 241f949540
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 171 additions and 72 deletions

View file

@ -28,11 +28,11 @@ COSMOPOLITAN_C_START_
/* this header is included by 700+ files; therefore we */
/* hand-roll &__get_tls()->tib_errno to avoid #include */
/* cosmopolitan uses x28 as the tls register b/c apple */
#define errno \
(*({ \
errno_t *__ep; \
asm("sub\t%0,x28,#68" : "=r"(__ep)); \
__ep; \
#define errno \
(*({ \
errno_t *__ep; \
asm("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
__ep; \
}))
#else
#define errno (*__errno_location())

View file

@ -67,7 +67,7 @@ __gc: .ftrace2
// if this code fails
// check if CosmoTib's size changed
sub x8,x28,#128 // __get_tls()
sub x8,x28,#192 // __get_tls()
ldr x9,[x8,0x18] // tib::garbages
ldr x10,[x9] // g->i
ldr x8,[x9,8] // g->p

View file

@ -112,7 +112,7 @@ vfork:
// } else {
// __get_tls()->tib_flags &= ~TIB_FLAG_VFORKED;
// }
sub x1,x28,#0x80 // RELIES ON TLS TIB ABI!
sub x1,x28,#192 // sizeof(CosmoTib)
ldr x2,[x1,64]
cbnz x0,2f
orr x2,x2,#TIB_FLAG_VFORKED

View file

@ -32,6 +32,7 @@
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#include "third_party/nsync/futex.internal.h"
#include "third_party/nsync/wait_s.internal.h"
void _pthread_unwind(struct PosixThread *pt) {
struct _pthread_cleanup_buffer *cb;
@ -115,6 +116,9 @@ wontreturn void pthread_exit(void *rc) {
_weaken(__cxa_thread_finalize)();
}
_pthread_unkey(tib);
if (tib->tib_nsync) {
nsync_waiter_destroy(tib->tib_nsync);
}
_pthread_ungarbage();
_pthread_decimate();

View file

@ -37,6 +37,8 @@ struct CosmoTib {
uint32_t tib_sigstack_size;
uint32_t tib_sigstack_flags;
void **tib_keys;
void *tib_nsync;
void *tib_todo[63];
};
extern int __threaded;