[libc-commits] [libc] 001a12e - [libc][NFC] Make x86_64 fenv functions msan safe.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Mon Mar 8 15:26:54 PST 2021
Author: Siva Chandra Reddy
Date: 2021-03-08T15:20:08-08:00
New Revision: 001a12ed59c354aa759ff3e104748c36803cfaa2
URL: https://github.com/llvm/llvm-project/commit/001a12ed59c354aa759ff3e104748c36803cfaa2
DIFF: https://github.com/llvm/llvm-project/commit/001a12ed59c354aa759ff3e104748c36803cfaa2.diff
LOG: [libc][NFC] Make x86_64 fenv functions msan safe.
These functions used inline asm to read FPU state. This change adds
explicit unpoisoning in these functions as the sanitizers don't see the
read operations.
Added:
Modified:
libc/src/__support/CMakeLists.txt
libc/utils/FPUtil/CMakeLists.txt
libc/utils/FPUtil/x86_64/FEnv.h
Removed:
################################################################################
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 980b510e374c..32f538e02a5e 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -2,4 +2,5 @@ add_header_library(
common
HDRS
common.h
+ sanitizer_annotations.h
)
diff --git a/libc/utils/FPUtil/CMakeLists.txt b/libc/utils/FPUtil/CMakeLists.txt
index 2c1c1661a578..43ee6433559e 100644
--- a/libc/utils/FPUtil/CMakeLists.txt
+++ b/libc/utils/FPUtil/CMakeLists.txt
@@ -31,6 +31,7 @@ add_header_library(
libc.include.math
libc.include.errno
libc.include.fenv
+ libc.src.__support.common
libc.utils.CPP.standalone_cpp
)
diff --git a/libc/utils/FPUtil/x86_64/FEnv.h b/libc/utils/FPUtil/x86_64/FEnv.h
index 3fb4881c5f2c..1196aba29807 100644
--- a/libc/utils/FPUtil/x86_64/FEnv.h
+++ b/libc/utils/FPUtil/x86_64/FEnv.h
@@ -12,6 +12,8 @@
#include <fenv.h>
#include <stdint.h>
+#include "src/__support/sanitizer_annotations.h"
+
namespace __llvm_libc {
namespace fputil {
@@ -95,6 +97,7 @@ static_assert(
static inline uint16_t getX87ControlWord() {
uint16_t w;
__asm__ __volatile__("fnstcw %0" : "=m"(w)::);
+ SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w));
return w;
}
@@ -105,6 +108,7 @@ static inline void writeX87ControlWord(uint16_t w) {
static inline uint16_t getX87StatusWord() {
uint16_t w;
__asm__ __volatile__("fnstsw %0" : "=m"(w)::);
+ SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w));
return w;
}
@@ -115,6 +119,7 @@ static inline void clearX87Exceptions() {
static inline uint32_t getMXCSR() {
uint32_t w;
__asm__ __volatile__("stmxcsr %0" : "=m"(w)::);
+ SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w));
return w;
}
@@ -124,6 +129,7 @@ static inline void writeMXCSR(uint32_t w) {
static inline void getX87StateDescriptor(X87StateDescriptor &s) {
__asm__ __volatile__("fnstenv %0" : "=m"(s));
+ SANITIZER_MEMORY_INITIALIZED(&s, sizeof(s));
}
static inline void writeX87StateDescriptor(const X87StateDescriptor &s) {
More information about the libc-commits
mailing list