diff options
Diffstat (limited to 'lib/libkse/arch/amd64')
-rw-r--r-- | lib/libkse/arch/amd64/amd64/pthread_md.c | 20 | ||||
-rw-r--r-- | lib/libkse/arch/amd64/include/pthread_md.h | 6 |
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/libkse/arch/amd64/amd64/pthread_md.c b/lib/libkse/arch/amd64/amd64/pthread_md.c index ead259a..67d4943 100644 --- a/lib/libkse/arch/amd64/amd64/pthread_md.c +++ b/lib/libkse/arch/amd64/amd64/pthread_md.c @@ -28,29 +28,37 @@ #include <stdlib.h> #include <strings.h> +#include "rtld_tls.h" #include "pthread_md.h" /* * The constructors. */ struct tcb * -_tcb_ctor(struct pthread *thread) +_tcb_ctor(struct pthread *thread, int initial) { struct tcb *tcb; + void *oldtls; - if ((tcb = malloc(sizeof(struct tcb))) != NULL) { - bzero(tcb, sizeof(struct tcb)); + if (initial) { + __asm __volatile("movq %%fs:0, %0" : "=r" (oldtls)); + } else { + oldtls = NULL; + } + + tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); + if (tcb) { tcb->tcb_thread = thread; - /* Allocate TDV */ + bzero(&tcb->tcb_tmbx, sizeof(tcb->tcb_tmbx)); } + return (tcb); } void _tcb_dtor(struct tcb *tcb) { - /* Free TDV */ - free(tcb); + _rtld_free_tls(tcb, sizeof(struct tcb), 16); } struct kcb * diff --git a/lib/libkse/arch/amd64/include/pthread_md.h b/lib/libkse/arch/amd64/include/pthread_md.h index 0f19044..86af4af 100644 --- a/lib/libkse/arch/amd64/include/pthread_md.h +++ b/lib/libkse/arch/amd64/include/pthread_md.h @@ -62,8 +62,10 @@ struct kcb { }; struct tcb { - struct tdv *tcb_tdv; + struct tcb *tcb_self; /* required by rtld */ + void *tcb_dtv; /* required by rtld */ struct pthread *tcb_thread; + void *tcb_spare[1]; /* align tcb_tmbx to 16 bytes */ struct kse_thr_mailbox tcb_tmbx; }; @@ -138,7 +140,7 @@ __kcb_readandclear64(volatile u_long *addr) /* * The constructors. */ -struct tcb *_tcb_ctor(struct pthread *); +struct tcb *_tcb_ctor(struct pthread *, int); void _tcb_dtor(struct tcb *tcb); struct kcb *_kcb_ctor(struct kse *); void _kcb_dtor(struct kcb *); |