From 9e6d5a03d4e9ba7e9c383e82b51e51a6de0baa5b Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sat, 6 Nov 2004 03:35:51 +0000 Subject: [PATCH] i386_set_ldt() is not available when running 32 bit binaries on amd64 kernels. Use the recently exposed direct-set routines instead. This is only activated for when we compile i386 support libraries on amd64. --- lib/libkse/arch/i386/i386/pthread_md.c | 6 ++++++ lib/libkse/arch/i386/include/pthread_md.h | 7 +++++++ lib/libpthread/arch/i386/i386/pthread_md.c | 6 ++++++ lib/libpthread/arch/i386/include/pthread_md.h | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/lib/libkse/arch/i386/i386/pthread_md.c b/lib/libkse/arch/i386/i386/pthread_md.c index 3d9bd368f109..cca433995ebb 100644 --- a/lib/libkse/arch/i386/i386/pthread_md.c +++ b/lib/libkse/arch/i386/i386/pthread_md.c @@ -76,7 +76,9 @@ _tcb_dtor(struct tcb *tcb) struct kcb * _kcb_ctor(struct kse *kse) { +#ifndef COMPAT_32BIT union descriptor ldt; +#endif struct kcb *kcb; kcb = malloc(sizeof(struct kcb)); @@ -84,6 +86,7 @@ _kcb_ctor(struct kse *kse) bzero(kcb, sizeof(struct kcb)); 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; @@ -99,6 +102,7 @@ _kcb_ctor(struct kse *kse) free(kcb); return (NULL); } +#endif } return (kcb); } @@ -106,9 +110,11 @@ _kcb_ctor(struct kse *kse) void _kcb_dtor(struct kcb *kcb) { +#ifndef COMPAT_32BIT if (kcb->kcb_ldt >= 0) { i386_set_ldt(kcb->kcb_ldt, NULL, 1); kcb->kcb_ldt = -1; /* just in case */ } +#endif free(kcb); } diff --git a/lib/libkse/arch/i386/include/pthread_md.h b/lib/libkse/arch/i386/include/pthread_md.h index da97c5c09bef..92d4275d44b2 100644 --- a/lib/libkse/arch/i386/include/pthread_md.h +++ b/lib/libkse/arch/i386/include/pthread_md.h @@ -32,7 +32,9 @@ #define _PTHREAD_MD_H_ #include +#include #include +#include #include extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *); @@ -150,10 +152,15 @@ void _kcb_dtor(struct kcb *); static __inline void _kcb_set(struct kcb *kcb) { +#ifndef COMPAT_32BIT int val; val = (kcb->kcb_ldt << 3) | 7; __asm __volatile("movl %0, %%gs" : : "r" (val)); +#else + _amd64_set_gsbase(kcb); +#endif + } /* Get the current kcb. */ diff --git a/lib/libpthread/arch/i386/i386/pthread_md.c b/lib/libpthread/arch/i386/i386/pthread_md.c index 3d9bd368f109..cca433995ebb 100644 --- a/lib/libpthread/arch/i386/i386/pthread_md.c +++ b/lib/libpthread/arch/i386/i386/pthread_md.c @@ -76,7 +76,9 @@ _tcb_dtor(struct tcb *tcb) struct kcb * _kcb_ctor(struct kse *kse) { +#ifndef COMPAT_32BIT union descriptor ldt; +#endif struct kcb *kcb; kcb = malloc(sizeof(struct kcb)); @@ -84,6 +86,7 @@ _kcb_ctor(struct kse *kse) bzero(kcb, sizeof(struct kcb)); 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; @@ -99,6 +102,7 @@ _kcb_ctor(struct kse *kse) free(kcb); return (NULL); } +#endif } return (kcb); } @@ -106,9 +110,11 @@ _kcb_ctor(struct kse *kse) void _kcb_dtor(struct kcb *kcb) { +#ifndef COMPAT_32BIT if (kcb->kcb_ldt >= 0) { i386_set_ldt(kcb->kcb_ldt, NULL, 1); kcb->kcb_ldt = -1; /* just in case */ } +#endif free(kcb); } diff --git a/lib/libpthread/arch/i386/include/pthread_md.h b/lib/libpthread/arch/i386/include/pthread_md.h index da97c5c09bef..92d4275d44b2 100644 --- a/lib/libpthread/arch/i386/include/pthread_md.h +++ b/lib/libpthread/arch/i386/include/pthread_md.h @@ -32,7 +32,9 @@ #define _PTHREAD_MD_H_ #include +#include #include +#include #include extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *); @@ -150,10 +152,15 @@ void _kcb_dtor(struct kcb *); static __inline void _kcb_set(struct kcb *kcb) { +#ifndef COMPAT_32BIT int val; val = (kcb->kcb_ldt << 3) | 7; __asm __volatile("movl %0, %%gs" : : "r" (val)); +#else + _amd64_set_gsbase(kcb); +#endif + } /* Get the current kcb. */