static void tcb_fixup(int mainthread) { void *tls, *newtcb, *oldtcb; size_t tls_size, tcb_size; // TODO(jsing): Remove once OpenBSD 6.1 is released and OpenBSD 5.9 is // no longer supported. // The OpenBSD ld.so(1) does not currently support PT_TLS. As a result, // we need to allocate our own TLS space while preserving the existing // TCB or TIB that has been setup via librthread. tcb_size = has_tib ? TIB_SIZE : TCB_SIZE; tls_size = TLS_SIZE + tcb_size; tls = malloc(tls_size); if(tls == NULL) abort(); // The signal trampoline expects the TLS slots to be zeroed. bzero(tls, TLS_SIZE); oldtcb = __get_tcb(); newtcb = tls + TLS_SIZE; bcopy(oldtcb, newtcb, tcb_size); if(has_tib) { // Fix up self pointer. *(uintptr_t *)(newtcb) = (uintptr_t)newtcb; } __set_tcb(newtcb); // NOTE(jsing, minux): we can't free oldtcb without causing double-free // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD // has proper support for PT_TLS. }
static void tcb_fixup(int mainthread) { void *newtcb, *oldtcb; // The OpenBSD ld.so(1) does not currently support PT_TLS. As a result, // we need to allocate our own TLS space while preserving the existing // TCB that has been setup via librthread. newtcb = malloc(TCB_SIZE + TLS_SIZE); if(newtcb == NULL) abort(); // The signal trampoline expects the TLS slots to be zeroed. bzero(newtcb, TLS_SIZE); oldtcb = __get_tcb(); bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE); __set_tcb(newtcb + TLS_SIZE); // NOTE(jsing, minux): we can't free oldtcb without causing double-free // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD // has proper support for PT_TLS. }