summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2011-06-18 11:07:09 +0000
committermarius <marius@FreeBSD.org>2011-06-18 11:07:09 +0000
commit44781533ff6a37d1a1adef814b3f7c92f282a3dd (patch)
tree09c667a3840dcc7f44fe437d41a37446177d26f9 /lib/libthr
parent784b15655084691642334c13097cf2ecf023679d (diff)
downloadFreeBSD-src-44781533ff6a37d1a1adef814b3f7c92f282a3dd.zip
FreeBSD-src-44781533ff6a37d1a1adef814b3f7c92f282a3dd.tar.gz
Merge from r161730:
o Set TP using inline assembly to avoid dead code elimination. o Eliminate _tcb. Merge from r161840: Stylize: avoid using a global register variable. Merge from r157461: Simplify _get_curthread() and _tcb_ctor because libc and rtld now already allocate thread pointer space in tls block for initial thread. Merge from r177853: Replace function _umtx_op with _umtx_op_err, the later function directly returns errno, because errno can be mucked by user's signal handler and most of pthread api heavily depends on errno to be correct, this change should improve stability of the thread library. MFC after: 1 week
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/arch/sparc64/Makefile.inc2
-rw-r--r--lib/libthr/arch/sparc64/include/pthread_md.h23
-rw-r--r--lib/libthr/arch/sparc64/sparc64/_umtx_op_err.S38
-rw-r--r--lib/libthr/arch/sparc64/sparc64/pthread_md.c12
4 files changed, 54 insertions, 21 deletions
diff --git a/lib/libthr/arch/sparc64/Makefile.inc b/lib/libthr/arch/sparc64/Makefile.inc
index 2ee2247..88586b4 100644
--- a/lib/libthr/arch/sparc64/Makefile.inc
+++ b/lib/libthr/arch/sparc64/Makefile.inc
@@ -1,3 +1,3 @@
# $FreeBSD$
-SRCS+= pthread_md.c
+SRCS+= _umtx_op_err.S pthread_md.c
diff --git a/lib/libthr/arch/sparc64/include/pthread_md.h b/lib/libthr/arch/sparc64/include/pthread_md.h
index 7909291..7ee9654 100644
--- a/lib/libthr/arch/sparc64/include/pthread_md.h
+++ b/lib/libthr/arch/sparc64/include/pthread_md.h
@@ -50,10 +50,6 @@ struct tcb {
void *tcb_spare[1];
};
-register struct tcb *_tp __asm("%g7");
-
-#define _tcb (_tp)
-
/*
* The tcb constructors.
*/
@@ -64,26 +60,25 @@ void _tcb_dtor(struct tcb *);
static __inline void
_tcb_set(struct tcb *tcb)
{
- _tp = tcb;
+
+ __asm __volatile("mov %0, %%g7" : : "r" (tcb));
}
-/*
- * Get the current tcb.
- */
static __inline struct tcb *
_tcb_get(void)
{
- return (_tcb);
-}
+ register struct tcb *tp __asm("%g7");
-extern struct pthread *_thr_initial;
+ return (tp);
+}
static __inline struct pthread *
_get_curthread(void)
{
- if (_thr_initial)
- return (_tcb->tcb_thread);
- return (NULL);
+
+ return (_tcb_get()->tcb_thread);
}
+#define HAS__UMTX_OP_ERR 1
+
#endif /* _PTHREAD_MD_H_ */
diff --git a/lib/libthr/arch/sparc64/sparc64/_umtx_op_err.S b/lib/libthr/arch/sparc64/sparc64/_umtx_op_err.S
new file mode 100644
index 0000000..220d279
--- /dev/null
+++ b/lib/libthr/arch/sparc64/sparc64/_umtx_op_err.S
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 2011 Marius Strobl <marius@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY 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.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/syscall.h>
+
+#include <machine/utrap.h>
+
+ENTRY(_umtx_op_err)
+ mov SYS__umtx_op, %g1
+ retl
+ ta %xcc, ST_SYSCALL
+END(_umtx_op_err)
diff --git a/lib/libthr/arch/sparc64/sparc64/pthread_md.c b/lib/libthr/arch/sparc64/sparc64/pthread_md.c
index 3f8e105..e1d439a 100644
--- a/lib/libthr/arch/sparc64/sparc64/pthread_md.c
+++ b/lib/libthr/arch/sparc64/sparc64/pthread_md.c
@@ -24,10 +24,11 @@
* 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$");
+
#include <sys/types.h>
#include <rtld_tls.h>
@@ -37,13 +38,11 @@ struct tcb *
_tcb_ctor(struct pthread *thread, int initial)
{
struct tcb *tcb;
- void *oldtls;
if (initial)
- oldtls = _tp;
+ tcb = _tcb_get();
else
- oldtls = NULL;
- tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16);
+ tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
if (tcb)
tcb->tcb_thread = thread;
return (tcb);
@@ -52,5 +51,6 @@ _tcb_ctor(struct pthread *thread, int initial)
void
_tcb_dtor(struct tcb *tcb)
{
+
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
}
OpenPOWER on IntegriCloud