November 01, 2002

I just tracked down an

I just tracked down an annoying bug in the Linux 2.4.18 kernel tonight. It seems that the ucontext_t passed as the third parameter to an SA_SIGINFO signal handler has the fpregs field of its uc_mcontext field set to NULL. That's not much of a concern -- if you're not using floating point at all you don't care, and if you are, well, the floating point state is stored in your ucontext_t's __fpregs_mem anyway.

The catch is that my code was crashing in setcontext(), even though I wasn't changing the context from what I'd been given. A little bit of debugging and disassembly later I realized that setcontext was dying while executing fldenv (%ecx), where %ecx was mycontext->uc_mcontext.fpregs. Since that was dereferencing NULL, it crashed.

The workaround is pretty easy -- when calling setcontext() with a context retrieved from an SA_SIGINFO signal handler on Linux, set mycontext->uc_mcontext.fpregs to &mycontext->__fpregs_mem first. Works like a charm, though it shouldn't be necessary in the first place.

Posted at 02:03 AM | Disclaimer