Now libthr only uses GDT based tls on i386. using LDT can only increase
clock cycles and has 8191 threads limitation.
This commit is contained in:
parent
a0a25ee25d
commit
8d38949442
@ -35,15 +35,9 @@
|
||||
|
||||
#include "pthread_md.h"
|
||||
|
||||
int _thr_using_setbase;
|
||||
|
||||
struct tcb *
|
||||
_tcb_ctor(struct pthread *thread, int initial)
|
||||
{
|
||||
#ifndef COMPAT_32BIT
|
||||
union descriptor ldt;
|
||||
void *base;
|
||||
#endif
|
||||
struct tcb *tcb;
|
||||
void *oldtls;
|
||||
int error;
|
||||
@ -54,51 +48,15 @@ _tcb_ctor(struct pthread *thread, int initial)
|
||||
oldtls = NULL;
|
||||
|
||||
tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16);
|
||||
if (tcb) {
|
||||
if (tcb)
|
||||
tcb->tcb_thread = thread;
|
||||
#ifndef COMPAT_32BIT
|
||||
tcb->tcb_ldt = -1;
|
||||
switch (_thr_using_setbase) {
|
||||
case 1: /* use i386_set_gsbase() in _kcb_set */
|
||||
break;
|
||||
case 0: /* Untested, try the get/set_gsbase routines once */
|
||||
error = i386_get_gsbase(&base);
|
||||
if (error == 0) {
|
||||
_thr_using_setbase = 1;
|
||||
break;
|
||||
}
|
||||
/* fall through */
|
||||
case 2: /* Use the user_ldt code, we must have an old kernel */
|
||||
_thr_using_setbase = 2;
|
||||
ldt.sd.sd_hibase = (unsigned int)tcb >> 24;
|
||||
ldt.sd.sd_lobase = (unsigned int)tcb & 0xFFFFFF;
|
||||
ldt.sd.sd_hilimit = (sizeof(struct tcb) >> 16) & 0xF;
|
||||
ldt.sd.sd_lolimit = sizeof(struct tcb) & 0xFFFF;
|
||||
ldt.sd.sd_type = SDT_MEMRWA;
|
||||
ldt.sd.sd_dpl = SEL_UPL;
|
||||
ldt.sd.sd_p = 1;
|
||||
ldt.sd.sd_xx = 0;
|
||||
ldt.sd.sd_def32 = 1;
|
||||
ldt.sd.sd_gran = 0; /* no more than 1M */
|
||||
tcb->tcb_ldt = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1);
|
||||
if (tcb->tcb_ldt < 0) {
|
||||
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
|
||||
tcb = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
void
|
||||
_tcb_dtor(struct tcb *tcb)
|
||||
{
|
||||
#ifndef COMPAT_32BIT
|
||||
if (tcb->tcb_ldt >= 0)
|
||||
i386_set_ldt(tcb->tcb_ldt, NULL, 1);
|
||||
#endif
|
||||
|
||||
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,6 @@ struct tcb {
|
||||
struct tcb *tcb_self; /* required by rtld */
|
||||
void *tcb_dtv; /* required by rtld */
|
||||
struct pthread *tcb_thread;
|
||||
int tcb_ldt;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -88,14 +87,7 @@ static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
#ifndef COMPAT_32BIT
|
||||
int val;
|
||||
|
||||
if (_thr_using_setbase == 1) {
|
||||
i386_set_gsbase(tcb);
|
||||
} else {
|
||||
val = (tcb->tcb_ldt << 3) | 7;
|
||||
__asm __volatile("movl %0, %%gs" : : "r" (val));
|
||||
}
|
||||
i386_set_gsbase(tcb);
|
||||
#else
|
||||
_amd64_set_gsbase(tcb);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user