Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Feb 2005 13:19:34 GMT
From:      David Xu <davidxu@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 71819 for review
Message-ID:  <200502251319.j1PDJYjW065569@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <stddef.h>
 #include <sys/types.h>
 
-#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 <stddef.h>
 
-#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 <stddef.h>
 #include <sys/types.h>
 
-#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 <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libpthread/arch/powerpc/powerpc/pthread_md.c,v 1.2 2004/08/16 05:41:39 grehan Exp $");
-
 #include <stdlib.h>
 #include <strings.h>
+#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 <stddef.h>
 
-#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 <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libpthread/arch/sparc64/sparc64/pthread_md.c,v 1.3 2004/08/15 16:28:05 dfr Exp $");
-
 #include <sys/types.h>
-
 #include <stdlib.h>
 #include <string.h>
-
+#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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200502251319.j1PDJYjW065569>