summaryrefslogtreecommitdiffstats
path: root/lib/libthr/arch
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2005-04-14 00:44:07 +0000
committerpeter <peter@FreeBSD.org>2005-04-14 00:44:07 +0000
commitc1d476c9316f2c96a976a3e20893ab8a3c73a131 (patch)
tree611ec345f547abff63632b8070c9a981779b7e3b /lib/libthr/arch
parent03d84df307a00f27dbe7ad670e417913823b9ad3 (diff)
downloadFreeBSD-src-c1d476c9316f2c96a976a3e20893ab8a3c73a131.zip
FreeBSD-src-c1d476c9316f2c96a976a3e20893ab8a3c73a131.tar.gz
Adapt the libpthread patch for using i386_set_gsbase() to libthr.
Diffstat (limited to 'lib/libthr/arch')
-rw-r--r--lib/libthr/arch/i386/i386/pthread_md.c47
-rw-r--r--lib/libthr/arch/i386/include/pthread_md.h10
2 files changed, 41 insertions, 16 deletions
diff --git a/lib/libthr/arch/i386/i386/pthread_md.c b/lib/libthr/arch/i386/i386/pthread_md.c
index e0adb25..d17343c 100644
--- a/lib/libthr/arch/i386/i386/pthread_md.c
+++ b/lib/libthr/arch/i386/i386/pthread_md.c
@@ -35,14 +35,18 @@
#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;
if (initial)
__asm __volatile("movl %%gs:0, %0" : "=r" (oldtls));
@@ -53,20 +57,35 @@ _tcb_ctor(struct pthread *thread, int initial)
if (tcb) {
tcb->tcb_thread = thread;
#ifndef COMPAT_32BIT
- 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;
+ 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
}
diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h
index 721ddac..ac3cc9c 100644
--- a/lib/libthr/arch/i386/include/pthread_md.h
+++ b/lib/libthr/arch/i386/include/pthread_md.h
@@ -39,6 +39,8 @@
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
+extern int _thr_using_setbase;
+
/*
* Variant II tcb, first two members are required by rtld,
* %gs points to the structure.
@@ -88,8 +90,12 @@ _tcb_set(struct tcb *tcb)
#ifndef COMPAT_32BIT
int val;
- val = (tcb->tcb_ldt << 3) | 7;
- __asm __volatile("movl %0, %%gs" : : "r" (val));
+ if (_thr_using_setbase == 1) {
+ i386_set_gsbase(tcb);
+ } else {
+ val = (tcb->tcb_ldt << 3) | 7;
+ __asm __volatile("movl %0, %%gs" : : "r" (val));
+ }
#else
_amd64_set_gsbase(tcb);
#endif
OpenPOWER on IntegriCloud