Date: Wed, 9 Jan 2002 19:36:08 +1100 (EST) From: Bruce Evans <bde@zeta.org.au> To: Nate Williams <nate@yogotech.com> Cc: Daniel Eischen <eischen@pcnet1.pcnet.com>, Dan Eischen <eischen@vigrid.com>, Peter Wemm <peter@wemm.org>, Archie Cobbs <archie@dellroad.org>, Alfred Perlstein <bright@mu.org>, <arch@FreeBSD.ORG> Subject: Re: Request for review: getcontext, setcontext, etc Message-ID: <20020109192223.H7698-100000@gamplex.bde.org> In-Reply-To: <15419.13318.535192.666599@caddis.yogotech.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 8 Jan 2002, Nate Williams wrote: > > > > Using "wait" before an FP control instruction is usually wrong because > > > > it prevents the "no-wait" feature of FP control operations from working. > > > > It causes any unmasked exceptions to be signaled immediately. > > > > > > Isn't this a good thing, since if the currently executing thread has > > > encountered an exception, it will be signaled during the current > > > thread's context? > > > > No. It breaks instruction sequences like: > > > > fldz > > fld1 > > fdiv %st,%st(1) # 1.0 / 0.0, exception on this instruction > > # but no trap yet > > fnstsw %ax # no trap yet since this is control instruction > > fnclex # forget about exception; no trap at all since > > # we did only control instructions after the > > # one that cause the exception > > > > > > It is especially wrong for fnsave in context switches because it > > > > causes the signals in the context of the context switcher instead of > > > > in the context of the thread that caused the exception. > > > > > > Which signals are you refering to? > > > > The SIGFPE that you get for `wait'. > > So, when is SIGFPE going to be triggered above, since it appears to be > masked by using fnstw vs. fstw. When the above is interrupted by a signal, and the signal handler wants to switch to another thread, and erroneously saves the context using fsave instead of fnsave. > In other words, how do I actually make sure that I receive the > exception/trapf for FP errors? Let the thread (appear to) continue normally by never triggering a trap for the exception if you switch its context. Using fnsave/frstor accomplishes this, except on broken (old) systems where fnsave traps anyway. The kernel has lots of complications to minimise the damage from this. It doesn't seem to be possible to prevent the spurious trap as require to not break instruction sequences like the above, but it is necessary to make the trap appear to occur in user context and not in kernel context where it actually occurs. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020109192223.H7698-100000>