From 001a12ed59c354aa759ff3e104748c36803cfaa2 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Mon, 8 Mar 2021 15:12:22 -0800 Subject: [PATCH] [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. --- libc/src/__support/CMakeLists.txt | 1 + libc/utils/FPUtil/CMakeLists.txt | 1 + libc/utils/FPUtil/x86_64/FEnv.h | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt index 980b510..32f538e 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 2c1c166..43ee643 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 3fb4881..1196aba 100644 --- a/libc/utils/FPUtil/x86_64/FEnv.h +++ b/libc/utils/FPUtil/x86_64/FEnv.h @@ -12,6 +12,8 @@ #include #include +#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) { -- 2.7.4