Module Name: src
Committed By: joerg
Date: Fri Mar 2 23:19:48 UTC 2012
Modified Files:
src/lib/libpthread/arch/i386: pthread_md.h
Log Message:
Avoid getcontext() as it triggers clobbering warnings. Use inline
assembler to get the fields directly. Saves a system call as side
effect.
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libpthread/arch/i386/pthread_md.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libpthread/arch/i386/pthread_md.h
diff -u src/lib/libpthread/arch/i386/pthread_md.h:1.19 src/lib/libpthread/arch/i386/pthread_md.h:1.20
--- src/lib/libpthread/arch/i386/pthread_md.h:1.19 Thu Feb 24 04:28:43 2011
+++ src/lib/libpthread/arch/i386/pthread_md.h Fri Mar 2 23:19:47 2012
@@ -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")