summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authorjoerg <joerg@NetBSD.org>2012-03-02 23:19:47 +0000
committerjoerg <joerg@NetBSD.org>2012-03-02 23:19:47 +0000
commitbc9bb2a0e7ab3d13e21e530970eab838305c1dfd (patch)
tree6e7b1db356ca0e449e7c9947a54b919951886b55 /lib/libpthread
parentc8e3d02188d62e15ad75af64b64464a181c711e8 (diff)
Avoid getcontext() as it triggers clobbering warnings. Use inline
assembler to get the fields directly. Saves a system call as side effect.
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/arch/i386/pthread_md.h42
1 files changed, 14 insertions, 28 deletions
diff --git a/lib/libpthread/arch/i386/pthread_md.h b/lib/libpthread/arch/i386/pthread_md.h
index 50abf040bff..1fd734586c5 100644
--- a/lib/libpthread/arch/i386/pthread_md.h
+++ b/lib/libpthread/arch/i386/pthread_md.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.h,v 1.19 2011/02/24 04:28:43 joerg Exp $ */
+/* $NetBSD: pthread_md.h,v 1.20 2012/03/02 23:19:47 joerg Exp $ */
/*-
* Copyright (c) 2001, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,33 +46,19 @@ pthread__sp(void)
#define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_UESP])
-/*
- * Set initial, sane values for registers whose values aren't just
- * "don't care".
- *
- * We use the current context instead of a guessed one because we cannot
- * assume how the GDT entries are ordered: what is true on i386 is not
- * true anymore on amd64.
- */
-#define _INITCONTEXT_U_MD(ucp) \
- do { \
- ucontext_t ucur; \
- (void)getcontext(&ucur); \
- (ucp)->uc_mcontext.__gregs[_REG_GS] = \
- ucur.uc_mcontext.__gregs[_REG_GS], \
- (ucp)->uc_mcontext.__gregs[_REG_FS] = \
- ucur.uc_mcontext.__gregs[_REG_FS], \
- (ucp)->uc_mcontext.__gregs[_REG_ES] = \
- ucur.uc_mcontext.__gregs[_REG_ES], \
- (ucp)->uc_mcontext.__gregs[_REG_DS] = \
- ucur.uc_mcontext.__gregs[_REG_DS], \
- (ucp)->uc_mcontext.__gregs[_REG_CS] = \
- ucur.uc_mcontext.__gregs[_REG_CS], \
- (ucp)->uc_mcontext.__gregs[_REG_SS] = \
- ucur.uc_mcontext.__gregs[_REG_SS], \
- (ucp)->uc_mcontext.__gregs[_REG_EFL] = \
- ucur.uc_mcontext.__gregs[_REG_EFL]; \
- } while (/*CONSTCOND*/0);
+static inline void
+_initcontext_u_md(ucontext_t *ucp)
+{
+ __asm ("pushfl; popl %0" : "=a" (ucp->uc_mcontext.__gregs[_REG_EFL]));
+ __asm ("pushl %%cs; popl %0" : "=a" (ucp->uc_mcontext.__gregs[_REG_CS]));
+ __asm ("movl %%ds, %0" : "=a" (ucp->uc_mcontext.__gregs[_REG_DS]));
+ __asm ("movl %%es, %0" : "=a" (ucp->uc_mcontext.__gregs[_REG_ES]));
+ __asm ("movl %%fs, %0" : "=a" (ucp->uc_mcontext.__gregs[_REG_FS]));
+ __asm ("movl %%gs, %0" : "=a" (ucp->uc_mcontext.__gregs[_REG_GS]));
+ __asm ("movl %%ss, %0" : "=a" (ucp->uc_mcontext.__gregs[_REG_SS]));
+}
+
+#define _INITCONTEXT_U_MD(ucp) _initcontext_u_md(ucp);
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")