Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpthread/arch/i386 Avoid getcontext() as it triggers c...
details: https://anonhg.NetBSD.org/src/rev/ff668a4d5779
branches: trunk
changeset: 777749:ff668a4d5779
user: joerg <joerg%NetBSD.org@localhost>
date: Fri Mar 02 23:19:47 2012 +0000
description:
Avoid getcontext() as it triggers clobbering warnings. Use inline
assembler to get the fields directly. Saves a system call as side
effect.
diffstat:
lib/libpthread/arch/i386/pthread_md.h | 42 +++++++++++-----------------------
1 files changed, 14 insertions(+), 28 deletions(-)
diffs (56 lines):
diff -r 0018a9a69d6d -r ff668a4d5779 lib/libpthread/arch/i386/pthread_md.h
--- a/lib/libpthread/arch/i386/pthread_md.h Fri Mar 02 23:13:55 2012 +0000
+++ b/lib/libpthread/arch/i386/pthread_md.h Fri Mar 02 23:19:47 2012 +0000
@@ -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 @@
#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")
Home |
Main Index |
Thread Index |
Old Index