Avoid getcontext() as it triggers clobbering warnings. Use inline

assembler to get the fields directly. Saves a system call as side
effect.
This commit is contained in:
joerg 2012-03-02 23:19:47 +00:00
parent 3e4f5725ad
commit d2be1428c2
1 changed files with 14 additions and 28 deletions

View File

@ -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")