riscv64: fix fesetenv(FE_DFL_ENV) crash
authorRuinland ChuanTzu Tsai <ruinland@andestech.com>
Mon, 2 Dec 2019 11:06:52 +0000 (19:06 +0800)
committerRich Felker <dalias@aerifal.cx>
Sat, 7 Dec 2019 17:58:39 +0000 (12:58 -0500)
When FE_DFL_ENV is passed to fesetenv(), the very first instruction
lw t1, 0(a0) will fail since a0 is -1.

src/fenv/riscv64/fenv.S

index f149003..0ea78bf 100644 (file)
@@ -45,8 +45,11 @@ fegetenv:
 .global fesetenv
 .type fesetenv, %function
 fesetenv:
+       li t2, -1
+       li t1, 0
+       beq a0, t2, 1f
        lw t1, 0(a0)
-       fscsr t0, t1
+1:     fscsr t1
        li a0, 0
        ret