Port-m68k archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Segfault in lrintf() and similar functions



In article <4aa7f1d033b.42160ed8%mail.owl.de@localhost>,
Frank Wille  <frank%phoenix.owl.de@localhost> wrote:
>Hi,
>
>it seems we have a serious problem in some new C99 math functions, which
>use fenv_t to save/restore the FPU environment. It is also responsible for
>X-server segfaults, when moving the mouse (at least on NetBSD/amiga).
>
>The following source reproduces the problem:
>
>---8<---
>typedef unsigned long uint32_t;
>typedef struct {
>        uint32_t fpcr;
>        uint32_t fpsr;
>        uint32_t fppc;
>} fenv_t;
>
>#define __fgetenv(__envp) \
>    __asm__ __volatile__ ("fmovem%.l %/fpcr/%/fpsr/%/fpiar,%0" : "=m"
>(*__envp))
>#define __set_fpsr(__fpsr) \
>    __asm__ __volatile__ ("fmove%.l %0,%/fpsr" : : "dm" (__fpsr))  
>#define FE_ALL_EXCEPT (0xf8)
>
>static inline int
>feholdexcept(fenv_t *__envp)
>{
>        int __fpsr;
>        __fgetenv(__envp);
>        __fpsr = __envp->fpsr & ~FE_ALL_EXCEPT;
>        __set_fpsr(__fpsr);     /* clear all */
>        return 0;
>}
>
>int main(void)
>{
>    fenv_t env;
>    return feholdexcept(&env);
>}
>---8<---
>
>I am currently testing this modification to sys/arch/m68k/include/fenv.h,
>which seems to fix it. I would commit that, when there are no objections:
>
>--- fenv.h      22 Mar 2017 23:11:09 -0000      1.6
>+++ fenv.h      9 Sep 2017 15:46:17 -0000
>@@ -210,7 +210,7 @@
> __fenv_static inline int
> fegetenv(fenv_t *__envp)
> {
>-       __fgetenv(__envp);
>+       __fgetenv(*__envp);
> 
>        return 0;
> }
>@@ -220,7 +220,7 @@
> {
>        fexcept_t __fpcr, __fpsr;
> 
>-       __fgetenv(__envp);
>+       __fgetenv(*__envp);
>        __fpsr = __envp->fpsr & ~FE_ALL_EXCEPT;
>        __set_fpsr(__fpsr);     /* clear all */
>        __fpcr = __envp->fpcr & ~(FE_ALL_EXCEPT << 6);
>

Go for it. It is clearly a bug.

christos



Home | Main Index | Thread Index | Old Index