Clean out the leftovers from the i386_set_gsbase() TLS conversion.

Like on libthr, there is an i386_set_gsbase() stub implementation here
to avoid libc.so.5 issues.  This should likely be a weak symbol and I
expect this will be fixed soon.

Approved by:	re
This commit is contained in:
peter 2005-06-29 23:15:36 +00:00
parent d939998368
commit db8830bc2d
6 changed files with 18 additions and 137 deletions
lib
libc/i386/gen
libkse/arch/i386
libpthread/arch/i386
libexec/rtld-elf/i386

@ -28,28 +28,11 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <machine/segments.h>
#include <machine/sysarch.h> #include <machine/sysarch.h>
void void
_set_tp(void *tp) _set_tp(void *tp)
{ {
union descriptor ldt;
int error, sel;
error = i386_set_gsbase(tp); i386_set_gsbase(tp);
if (error == 0)
return;
memset(&ldt, 0, sizeof(ldt));
ldt.sd.sd_lolimit = 0xffff; /* 4G limit */
ldt.sd.sd_lobase = ((uintptr_t)tp) & 0xffffff;
ldt.sd.sd_type = SDT_MEMRWA;
ldt.sd.sd_dpl = SEL_UPL;
ldt.sd.sd_p = 1; /* present */
ldt.sd.sd_hilimit = 0xf; /* 4G limit */
ldt.sd.sd_def32 = 1; /* 32 bit */
ldt.sd.sd_gran = 1; /* limit in pages */
ldt.sd.sd_hibase = (((uintptr_t)tp) >> 24) & 0xff;
sel = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1);
__asm __volatile("movl %0,%%gs" : : "rm" ((sel << 3) | 7));
} }

@ -30,7 +30,6 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h> #include <sys/types.h>
#include <machine/cpufunc.h> #include <machine/cpufunc.h>
#include <machine/segments.h>
#include <machine/sysarch.h> #include <machine/sysarch.h>
#include <unistd.h> #include <unistd.h>
@ -42,8 +41,6 @@ __FBSDID("$FreeBSD$");
#include "rtld_tls.h" #include "rtld_tls.h"
#include "pthread_md.h" #include "pthread_md.h"
int _thr_using_setbase;
struct tcb * struct tcb *
_tcb_ctor(struct pthread *thread, int initial) _tcb_ctor(struct pthread *thread, int initial)
{ {
@ -78,46 +75,14 @@ _tcb_dtor(struct tcb *tcb)
struct kcb * struct kcb *
_kcb_ctor(struct kse *kse) _kcb_ctor(struct kse *kse)
{ {
union descriptor ldt;
void *base; void *base;
struct kcb *kcb; struct kcb *kcb;
int error;
kcb = malloc(sizeof(struct kcb)); kcb = malloc(sizeof(struct kcb));
if (kcb != NULL) { if (kcb != NULL) {
bzero(kcb, sizeof(struct kcb)); bzero(kcb, sizeof(struct kcb));
kcb->kcb_self = kcb; kcb->kcb_self = kcb;
kcb->kcb_kse = kse; kcb->kcb_kse = kse;
switch (_thr_using_setbase) {
case 1: /* use i386_set_gsbase() in _kcb_set */
kcb->kcb_ldt = -1;
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)kcb >> 24;
ldt.sd.sd_lobase = (unsigned int)kcb & 0xFFFFFF;
ldt.sd.sd_hilimit = (sizeof(struct kcb) >> 16) & 0xF;
ldt.sd.sd_lolimit = sizeof(struct kcb) & 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 */
kcb->kcb_ldt = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1);
if (kcb->kcb_ldt < 0) {
free(kcb);
return (NULL);
}
break;
}
} }
return (kcb); return (kcb);
} }
@ -125,9 +90,12 @@ _kcb_ctor(struct kse *kse)
void void
_kcb_dtor(struct kcb *kcb) _kcb_dtor(struct kcb *kcb)
{ {
if (kcb->kcb_ldt >= 0) {
i386_set_ldt(kcb->kcb_ldt, NULL, 1);
kcb->kcb_ldt = -1; /* just in case */
}
free(kcb); free(kcb);
} }
int
i386_set_gsbase(void *addr)
{
return (sysarch(I386_SET_GSBASE, &addr));
}

@ -40,8 +40,6 @@
extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *); extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *);
extern int _thr_getcontext(mcontext_t *); extern int _thr_getcontext(mcontext_t *);
extern int _thr_using_setbase;
#define KSE_STACKSIZE 16384 #define KSE_STACKSIZE 16384
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) #define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
@ -60,7 +58,6 @@ struct pthread;
struct kcb { struct kcb {
struct tcb *kcb_curtcb; struct tcb *kcb_curtcb;
struct kcb *kcb_self; /* self reference */ struct kcb *kcb_self; /* self reference */
int kcb_ldt;
struct kse *kcb_kse; struct kse *kcb_kse;
struct kse_mailbox kcb_kmbx; struct kse_mailbox kcb_kmbx;
}; };
@ -154,15 +151,7 @@ void _kcb_dtor(struct kcb *);
static __inline void static __inline void
_kcb_set(struct kcb *kcb) _kcb_set(struct kcb *kcb)
{ {
int val;
if (_thr_using_setbase == 1) {
i386_set_gsbase(kcb); i386_set_gsbase(kcb);
} else {
val = (kcb->kcb_ldt << 3) | 7;
__asm __volatile("movl %0, %%gs" : : "r" (val));
}
} }
/* Get the current kcb. */ /* Get the current kcb. */

@ -30,7 +30,6 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h> #include <sys/types.h>
#include <machine/cpufunc.h> #include <machine/cpufunc.h>
#include <machine/segments.h>
#include <machine/sysarch.h> #include <machine/sysarch.h>
#include <unistd.h> #include <unistd.h>
@ -42,8 +41,6 @@ __FBSDID("$FreeBSD$");
#include "rtld_tls.h" #include "rtld_tls.h"
#include "pthread_md.h" #include "pthread_md.h"
int _thr_using_setbase;
struct tcb * struct tcb *
_tcb_ctor(struct pthread *thread, int initial) _tcb_ctor(struct pthread *thread, int initial)
{ {
@ -78,46 +75,14 @@ _tcb_dtor(struct tcb *tcb)
struct kcb * struct kcb *
_kcb_ctor(struct kse *kse) _kcb_ctor(struct kse *kse)
{ {
union descriptor ldt;
void *base; void *base;
struct kcb *kcb; struct kcb *kcb;
int error;
kcb = malloc(sizeof(struct kcb)); kcb = malloc(sizeof(struct kcb));
if (kcb != NULL) { if (kcb != NULL) {
bzero(kcb, sizeof(struct kcb)); bzero(kcb, sizeof(struct kcb));
kcb->kcb_self = kcb; kcb->kcb_self = kcb;
kcb->kcb_kse = kse; kcb->kcb_kse = kse;
switch (_thr_using_setbase) {
case 1: /* use i386_set_gsbase() in _kcb_set */
kcb->kcb_ldt = -1;
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)kcb >> 24;
ldt.sd.sd_lobase = (unsigned int)kcb & 0xFFFFFF;
ldt.sd.sd_hilimit = (sizeof(struct kcb) >> 16) & 0xF;
ldt.sd.sd_lolimit = sizeof(struct kcb) & 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 */
kcb->kcb_ldt = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1);
if (kcb->kcb_ldt < 0) {
free(kcb);
return (NULL);
}
break;
}
} }
return (kcb); return (kcb);
} }
@ -125,9 +90,12 @@ _kcb_ctor(struct kse *kse)
void void
_kcb_dtor(struct kcb *kcb) _kcb_dtor(struct kcb *kcb)
{ {
if (kcb->kcb_ldt >= 0) {
i386_set_ldt(kcb->kcb_ldt, NULL, 1);
kcb->kcb_ldt = -1; /* just in case */
}
free(kcb); free(kcb);
} }
int
i386_set_gsbase(void *addr)
{
return (sysarch(I386_SET_GSBASE, &addr));
}

@ -40,8 +40,6 @@
extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *); extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *);
extern int _thr_getcontext(mcontext_t *); extern int _thr_getcontext(mcontext_t *);
extern int _thr_using_setbase;
#define KSE_STACKSIZE 16384 #define KSE_STACKSIZE 16384
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) #define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
@ -60,7 +58,6 @@ struct pthread;
struct kcb { struct kcb {
struct tcb *kcb_curtcb; struct tcb *kcb_curtcb;
struct kcb *kcb_self; /* self reference */ struct kcb *kcb_self; /* self reference */
int kcb_ldt;
struct kse *kcb_kse; struct kse *kcb_kse;
struct kse_mailbox kcb_kmbx; struct kse_mailbox kcb_kmbx;
}; };
@ -154,15 +151,7 @@ void _kcb_dtor(struct kcb *);
static __inline void static __inline void
_kcb_set(struct kcb *kcb) _kcb_set(struct kcb *kcb)
{ {
int val;
if (_thr_using_setbase == 1) {
i386_set_gsbase(kcb); i386_set_gsbase(kcb);
} else {
val = (kcb->kcb_ldt << 3) | 7;
__asm __volatile("movl %0, %%gs" : : "r" (val));
}
} }
/* Get the current kcb. */ /* Get the current kcb. */

@ -327,8 +327,6 @@ void
allocate_initial_tls(Obj_Entry *objs) allocate_initial_tls(Obj_Entry *objs)
{ {
void* tls; void* tls;
union descriptor ldt;
int error, sel;
/* /*
* Fix the size of the static TLS block by using the maximum * Fix the size of the static TLS block by using the maximum
@ -337,21 +335,7 @@ allocate_initial_tls(Obj_Entry *objs)
*/ */
tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA; tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
tls = allocate_tls(objs, NULL, 2*sizeof(Elf_Addr), sizeof(Elf_Addr)); tls = allocate_tls(objs, NULL, 2*sizeof(Elf_Addr), sizeof(Elf_Addr));
error = i386_set_gsbase(tls); i386_set_gsbase(tls);
if (error < 0) {
memset(&ldt, 0, sizeof(ldt));
ldt.sd.sd_lolimit = 0xffff; /* 4G limit */
ldt.sd.sd_lobase = ((Elf_Addr)tls) & 0xffffff;
ldt.sd.sd_type = SDT_MEMRWA;
ldt.sd.sd_dpl = SEL_UPL;
ldt.sd.sd_p = 1; /* present */
ldt.sd.sd_hilimit = 0xf; /* 4G limit */
ldt.sd.sd_def32 = 1; /* 32 bit */
ldt.sd.sd_gran = 1; /* limit in pages */
ldt.sd.sd_hibase = (((Elf_Addr)tls) >> 24) & 0xff;
sel = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1);
__asm __volatile("movl %0,%%gs" : : "rm" ((sel << 3) | 7));
}
} }
/* GNU ABI */ /* GNU ABI */