From owner-p4-projects@FreeBSD.ORG Fri Feb 25 13:19:37 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 679E416A4DF; Fri, 25 Feb 2005 13:19:37 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6E18616A4D3 for ; Fri, 25 Feb 2005 13:19:36 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 301F843D58 for ; Fri, 25 Feb 2005 13:19:35 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j1PDJZuB065572 for ; Fri, 25 Feb 2005 13:19:35 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j1PDJYjW065569 for perforce@freebsd.org; Fri, 25 Feb 2005 13:19:34 GMT (envelope-from davidxu@freebsd.org) Date: Fri, 25 Feb 2005 13:19:34 GMT Message-Id: <200502251319.j1PDJYjW065569@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 71819 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Feb 2005 13:19:38 -0000 http://perforce.freebsd.org/chv.cgi?CH=71819 Change 71819 by davidxu@davidxu_tiger on 2005/02/25 13:19:07 Sync with newest rtld tls code. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/arch/alpha/include/pthread_md.h#5 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/ia64/ia64/pthread_md.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/ia64/include/pthread_md.h#6 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/powerpc/include/pthread_md.h#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/powerpc/powerpc/pthread_md.c#2 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/sparc64/include/pthread_md.h#5 edit .. //depot/projects/davidxu_thread/src/lib/libthread/arch/sparc64/sparc64/pthread_md.c#4 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/alpha/include/pthread_md.h#5 (text+ko) ==== @@ -32,32 +32,15 @@ #include #include -#define DTV_OFFSET offsetof(struct tcb, tcb_tp.tp_tdv) +#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) -struct pthread; -struct tcb; -struct tdv; /* We don't know what this is yet? */ - -/* - * tp points to one of these. We define the static TLS as an array - * of long double to enforce 16-byte alignment of the TLS memory, - * struct alpha_tp, struct tcb and also struct kcb. Both static and - * dynamic allocation of any of these structures will result in a - * valid, well-aligned thread pointer. - */ -struct alpha_tp { - struct tdv *tp_tdv; /* dynamic TLS */ - uint64_t _reserved_; - long double tp_tls[0]; /* static TLS */ -}; - struct tcb { + void *tcb_dtv; struct pthread *tcb_thread; - struct alpha_tp tcb_tp; }; #define _tp __builtin_thread_pointer() -#define _tcb ((struct tcb*)((char*)(_tp) - offsetof(struct tcb, tcb_tp))) +#define _tcb ((struct tcb *)_tp) struct tcb *_tcb_ctor(struct pthread *, int); void _tcb_dtor(struct tcb *); @@ -66,7 +49,7 @@ static __inline void _tcb_set(struct tcb *tcb) { - __builtin_set_thread_pointer(&tcb->tcb_tp); + __builtin_set_thread_pointer(tcb); } static __inline struct tcb * ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/ia64/ia64/pthread_md.c#4 (text+ko) ==== @@ -48,14 +48,14 @@ oldtls = NULL; #if 1 - if ((tcb = malloc(sizeof(struct tcb))) != NULL) { + if ((tcb = malloc(sizeof(struct tcb))) != NULL) { memset(tcb, 0, sizeof(struct tcb)); - tcb->tcb_thread = thread; + tcb->tcb_thread = thread; } #else tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); if (tcb) { - tcb->tcb_thread = thread; + tcb->tcb_thread = thread; } #endif return (tcb); ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/ia64/include/pthread_md.h#6 (text+ko) ==== @@ -31,41 +31,28 @@ #include -#define DTV_OFFSET offsetof(struct tcb, tcb_tp.tp_tdv) - -struct pthread; -struct tcb; -struct tdv; /* We don't know what this is yet? */ +#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) -/* - * tp points to one of these. We define the static TLS as an array - * of long double to enforce 16-byte alignment of the TLS memory, - * struct ia64_tp, struct tcb and also struct kcb. Both static and - * dynamic allocation of any of these structures will result in a - * valid, well-aligned thread pointer. - */ -struct ia64_tp { - struct tdv *tp_tdv; /* dynamic TLS */ - uint64_t _reserved_; - long double tp_tls[0]; /* static TLS */ -}; - struct tcb { + void *tcb_dtv; struct pthread *tcb_thread; - struct ia64_tp tcb_tp; }; -register struct ia64_tp *_tp __asm("%r13"); +register struct tcb *_tp __asm("%r13"); -#define _tcb ((struct tcb*)((char*)(_tp) - offsetof(struct tcb, tcb_tp))) +#define _tcb _tp +/* + * The tcb constructors. + */ struct tcb *_tcb_ctor(struct pthread *, int); void _tcb_dtor(struct tcb *); +/* Called from the KSE to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) { - _tp = &tcb->tcb_tp; + _tp = tcb; } static __inline struct tcb * ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/powerpc/include/pthread_md.h#3 (text+ko) ==== @@ -36,36 +36,22 @@ #include #include -#define DTV_OFFSET offsetof(struct tcb, tcb_tp.tp_tdv) - -struct pthread; -struct tcb; -struct tdv; +#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) /* - * %r2 points to a struct kcb. + * %r2 points to end of struct tcb. Variant I tls, the + * tcb structure layout is fixed, totally 8 bytes on 32 bits + * machine, don't change it. */ -struct ppc32_tp { - struct tdv *tp_tdv; /* dynamic TLS */ - uint32_t _reserved_; - long double tp_tls[0]; /* static TLS */ -}; struct tcb { + void *tcb_dtv; struct pthread *tcb_thread; - struct ppc32_tp tcb_tp; }; -/* - * From the PowerPC32 TLS spec: - * - * "r2 is the thread pointer, and points 0x7000 past the end of the - * thread control block." Or, 0x7008 past the start of the 8-byte tcb - */ -#define TP_OFFSET 0x7008 -register uint8_t *_tpr __asm("%r2"); +register uint8_t *_tp __asm("%r2"); -#define _tcb ((struct tcb *)(_tpr - TP_OFFSET - offsetof(struct tcb, tcb_tp))) +#define _tcb ((struct tcb *)(_tp - sizeof(struct tcb))) struct tcb *_tcb_ctor(struct pthread *, int); void _tcb_dtor(struct tcb *); @@ -73,7 +59,7 @@ static __inline void _tcb_set(struct tcb *tcb) { - _tpr = (uint8_t *)&tcb->tcb_tp + TP_OFFSET; + _tp = (uint8_t *)tcb + sizeof(struct tcb); } static __inline struct tcb * ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/powerpc/powerpc/pthread_md.c#2 (text+ko) ==== @@ -22,13 +22,13 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ */ -#include -__FBSDID("$FreeBSD: src/lib/libpthread/arch/powerpc/powerpc/pthread_md.c,v 1.2 2004/08/16 05:41:39 grehan Exp $"); - #include #include +#include "rtld_tls.h" #include "pthread_md.h" /* @@ -38,39 +38,34 @@ _tcb_ctor(struct pthread *thread, int initial) { struct tcb *tcb; + void *oldtls; + if (initial) + oldtls = _tp; + else + oldtls = NULL; + +#if 1 if ((tcb = malloc(sizeof(struct tcb))) != NULL) { - bzero(tcb, sizeof(struct tcb)); + memset(tcb, 0, sizeof(struct tcb)); + tcb->tcb_thread = thread; + } +#else + tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); + if (tcb) { tcb->tcb_thread = thread; - /* Allocate TDV */ } +#endif return (tcb); + } void _tcb_dtor(struct tcb *tcb) { - /* Free TDV */ +#if 1 free(tcb); -} - -struct kcb * -_kcb_ctor(struct kse *kse) -{ - struct kcb *kcb; - - if ((kcb = malloc(sizeof(struct kcb))) != NULL) { - bzero(kcb, sizeof(struct kcb)); - kcb->kcb_faketcb.tcb_isfake = 1; - kcb->kcb_faketcb.tcb_tmbx.tm_flags = TMF_NOUPCALL; - kcb->kcb_curtcb = &kcb->kcb_faketcb; - kcb->kcb_kse = kse; - } - return (kcb); -} - -void -_kcb_dtor(struct kcb *kcb) -{ - free(kcb); +#else + _rtld_free_tls(tcb, sizeof(tcb), 16); +#endif } ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/sparc64/include/pthread_md.h#5 (text+ko) ==== @@ -35,43 +35,36 @@ #include -#define DTV_OFFSET offsetof(struct tcb, tcb_tp.tp_tdv) +#define DTV_OFFSET offsetof(struct tcb, tcb_dtv) struct pthread; -struct tcb; -struct tdv; /* We don't know what this is yet? */ - -/* - * %g6 points to one of these. We define the static TLS as an array - * of long double to enforce 16-byte alignment of the TLS memory. - * - * XXX - Both static and dynamic allocation of any of these structures - * will result in a valid, well-aligned thread pointer??? - */ -struct sparc64_tp { - struct tdv *tp_tdv; /* dynamic TLS */ - uint64_t _reserved_; - long double tp_tls[0]; /* static TLS */ -}; struct tcb { - struct pthread *tcb_thread; - struct sparc64_tp tcb_tp; + struct tcb *tcb_self; /* required by rtld */ + void *tcb_dtv; /* required by rtld */ + struct pthread *tcb_thread; /* our hook */ }; -register struct sparc64_tp *_tp __asm("%g6"); +register struct tcb *_tp __asm("%g7"); -#define _tcb ((struct tcb*)((char*)(_tp) - offsetof(struct tcb, tcb_tp))) +#define _tcb (_tp) +/* + * The tcb constructors. + */ struct tcb *_tcb_ctor(struct pthread *, int); void _tcb_dtor(struct tcb *); +/* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) { - _tp = &tcb->tcb_tp; + _tp = tcb; } +/* + * Get the current tcb. + */ static __inline struct tcb * _tcb_get(void) { ==== //depot/projects/davidxu_thread/src/lib/libthread/arch/sparc64/sparc64/pthread_md.c#4 (text+ko) ==== @@ -24,31 +24,38 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ -#include -__FBSDID("$FreeBSD: src/lib/libpthread/arch/sparc64/sparc64/pthread_md.c,v 1.3 2004/08/15 16:28:05 dfr Exp $"); - #include - #include #include - +#include "rtld_tls.h" #include "pthread_md.h" struct tcb * _tcb_ctor(struct pthread *thread, int initial) { struct tcb *tcb; + void *oldtls; - if ((tcb = malloc(sizeof(struct tcb))) != NULL) { + if (initial) { + oldtls = _tp; + } else { + oldtls = NULL; + } + + tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16); + if (tcb) { tcb->tcb_thread = thread; } + return (tcb); } void _tcb_dtor(struct tcb *tcb) { - free(tcb); + _rtld_free_tls(tcb, sizeof(struct tcb), 16); }