aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Bergren <bdragon@FreeBSD.org>2021-03-01 02:35:53 +0000
committerBrandon Bergren <bdragon@FreeBSD.org>2021-03-01 02:37:48 +0000
commitdd95b39235dd81c890aa3cce02a5bb7f91f23803 (patch)
treece0be34338852495d619c02af27fee965b257ba7
parent55eb51ab6649c3c10bf201f82a4ec410fe4da4a2 (diff)
downloadsrc-dd95b39235dd81c890aa3cce02a5bb7f91f23803.tar.gz
src-dd95b39235dd81c890aa3cce02a5bb7f91f23803.zip
[PowerPC64] Fix multiple issues in fpsetmask().
Building R exposed a problem in fpsetmask() whereby we were not properly clamping the provided mask to the valid range. R initilizes the mask by calling fpsetmask(~0) on FreeBSD. Since we recently enabled precise exceptions, this was causing an immediate SIGFPE because we were attempting to set invalid bits in the fpscr. Properly limit the range of bits that can be set via fpsetmask(). While here, use the correct fp_except_t type instead of fp_rnd_t. Reported by: pkubaj (in IRC) MFC after: 1 week Sponsored by: Tag1 Consulting, Inc.
-rw-r--r--lib/libc/powerpc64/gen/fpsetmask.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/libc/powerpc64/gen/fpsetmask.c b/lib/libc/powerpc64/gen/fpsetmask.c
index 4d63552470be..f5d52eec5482 100644
--- a/lib/libc/powerpc64/gen/fpsetmask.c
+++ b/lib/libc/powerpc64/gen/fpsetmask.c
@@ -43,11 +43,11 @@ fp_except_t
fpsetmask(fp_except_t mask)
{
u_int64_t fpscr;
- fp_rnd_t old;
+ fp_except_t old;
__asm__("mffs %0" : "=f"(fpscr));
- old = (fp_rnd_t)((fpscr >> 3) & 0x1f);
- fpscr = (fpscr & 0xffffff07) | (mask << 3);
+ old = (fp_except_t)((fpscr >> 3) & 0x1f);
+ fpscr = (fpscr & 0xffffff07) | ((mask & 0x1f) << 3);
__asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr));
return (old);
}