summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2005-04-14 00:13:20 +0000
committerpeter <peter@FreeBSD.org>2005-04-14 00:13:20 +0000
commit03d84df307a00f27dbe7ad670e417913823b9ad3 (patch)
tree3bc91ca2f4ad9d0cf3cefd3e67c2e9cd3a45c151
parent1fad513bbc7fd4cfb911a7e8b6bf217dc31f2606 (diff)
downloadFreeBSD-src-03d84df307a00f27dbe7ad670e417913823b9ad3.zip
FreeBSD-src-03d84df307a00f27dbe7ad670e417913823b9ad3.tar.gz
Use the i386_set_gsbase() syscall if it is implemented in the kernel.
This is a little hairy here because the allocation and usage of this functionality is split into two places in libpthread.
-rw-r--r--lib/libkse/arch/i386/i386/pthread_md.c47
-rw-r--r--lib/libkse/arch/i386/include/pthread_md.h10
-rw-r--r--lib/libpthread/arch/i386/i386/pthread_md.c47
-rw-r--r--lib/libpthread/arch/i386/include/pthread_md.h10
4 files changed, 82 insertions, 32 deletions
diff --git a/lib/libkse/arch/i386/i386/pthread_md.c b/lib/libkse/arch/i386/i386/pthread_md.c
index cca4339..96cdac0 100644
--- a/lib/libkse/arch/i386/i386/pthread_md.c
+++ b/lib/libkse/arch/i386/i386/pthread_md.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include "rtld_tls.h"
#include "pthread_md.h"
+int _thr_using_setbase;
+
struct tcb *
_tcb_ctor(struct pthread *thread, int initial)
{
@@ -78,8 +80,10 @@ _kcb_ctor(struct kse *kse)
{
#ifndef COMPAT_32BIT
union descriptor ldt;
+ void *base;
#endif
struct kcb *kcb;
+ int error;
kcb = malloc(sizeof(struct kcb));
if (kcb != NULL) {
@@ -87,20 +91,35 @@ _kcb_ctor(struct kse *kse)
kcb->kcb_self = kcb;
kcb->kcb_kse = kse;
#ifndef COMPAT_32BIT
- 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);
+ 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;
}
#endif
}
diff --git a/lib/libkse/arch/i386/include/pthread_md.h b/lib/libkse/arch/i386/include/pthread_md.h
index 92d4275..e339391 100644
--- a/lib/libkse/arch/i386/include/pthread_md.h
+++ b/lib/libkse/arch/i386/include/pthread_md.h
@@ -40,6 +40,8 @@
extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *);
extern int _thr_getcontext(mcontext_t *);
+extern int _thr_using_setbase;
+
#define KSE_STACKSIZE 16384
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
@@ -155,8 +157,12 @@ _kcb_set(struct kcb *kcb)
#ifndef COMPAT_32BIT
int val;
- val = (kcb->kcb_ldt << 3) | 7;
- __asm __volatile("movl %0, %%gs" : : "r" (val));
+ if (_thr_using_setbase == 1) {
+ i386_set_gsbase(kcb);
+ } else {
+ val = (kcb->kcb_ldt << 3) | 7;
+ __asm __volatile("movl %0, %%gs" : : "r" (val));
+ }
#else
_amd64_set_gsbase(kcb);
#endif
diff --git a/lib/libpthread/arch/i386/i386/pthread_md.c b/lib/libpthread/arch/i386/i386/pthread_md.c
index cca4339..96cdac0 100644
--- a/lib/libpthread/arch/i386/i386/pthread_md.c
+++ b/lib/libpthread/arch/i386/i386/pthread_md.c
@@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include "rtld_tls.h"
#include "pthread_md.h"
+int _thr_using_setbase;
+
struct tcb *
_tcb_ctor(struct pthread *thread, int initial)
{
@@ -78,8 +80,10 @@ _kcb_ctor(struct kse *kse)
{
#ifndef COMPAT_32BIT
union descriptor ldt;
+ void *base;
#endif
struct kcb *kcb;
+ int error;
kcb = malloc(sizeof(struct kcb));
if (kcb != NULL) {
@@ -87,20 +91,35 @@ _kcb_ctor(struct kse *kse)
kcb->kcb_self = kcb;
kcb->kcb_kse = kse;
#ifndef COMPAT_32BIT
- 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);
+ 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;
}
#endif
}
diff --git a/lib/libpthread/arch/i386/include/pthread_md.h b/lib/libpthread/arch/i386/include/pthread_md.h
index 92d4275..e339391 100644
--- a/lib/libpthread/arch/i386/include/pthread_md.h
+++ b/lib/libpthread/arch/i386/include/pthread_md.h
@@ -40,6 +40,8 @@
extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *);
extern int _thr_getcontext(mcontext_t *);
+extern int _thr_using_setbase;
+
#define KSE_STACKSIZE 16384
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
@@ -155,8 +157,12 @@ _kcb_set(struct kcb *kcb)
#ifndef COMPAT_32BIT
int val;
- val = (kcb->kcb_ldt << 3) | 7;
- __asm __volatile("movl %0, %%gs" : : "r" (val));
+ if (_thr_using_setbase == 1) {
+ i386_set_gsbase(kcb);
+ } else {
+ val = (kcb->kcb_ldt << 3) | 7;
+ __asm __volatile("movl %0, %%gs" : : "r" (val));
+ }
#else
_amd64_set_gsbase(kcb);
#endif
OpenPOWER on IntegriCloud