Commit dc5bb219 by Nicolas Capens Committed by Nicolas Capens

Disable MSan unpoisoning of memory writes

Prior to supporting MemorySanitizer instrumentation of Reactor routines, false positives in C++ code were avoided by marking all memory that was written to by the Reactor routines as unpoisoned. Now this can be disabled to avoid false negatives, i.e. uses of uninitialized data either in the Reactor routine or originating from it. REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION controls whether we get the new behavior or the old unpoisoning. Bug: b/155148722 Change-Id: Ia35e3cdc1a60ba44045869884c64e9875c030291 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49889 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent f890890f
...@@ -54,7 +54,11 @@ extern "C" signed __aeabi_idivmod(); ...@@ -54,7 +54,11 @@ extern "C" signed __aeabi_idivmod();
#endif #endif
#if __has_feature(memory_sanitizer) #if __has_feature(memory_sanitizer)
# include "sanitizer/msan_interface.h" // TODO(b/155148722): Remove when we no longer unpoison all writes.
// TODO(b/155148722): Remove when we no longer unpoison all writes.
# if !REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION
# include "sanitizer/msan_interface.h"
# endif
# include <dlfcn.h> // dlsym() # include <dlfcn.h> // dlsym()
...@@ -540,7 +544,11 @@ class ExternalSymbolGenerator : public llvm::orc::JITDylib::DefinitionGenerator ...@@ -540,7 +544,11 @@ class ExternalSymbolGenerator : public llvm::orc::JITDylib::DefinitionGenerator
# endif # endif
#endif #endif
#if __has_feature(memory_sanitizer) #if __has_feature(memory_sanitizer)
functions.try_emplace("msan_unpoison", reinterpret_cast<void *>(__msan_unpoison)); // TODO(b/155148722): Remove when we no longer unpoison all writes.
// TODO(b/155148722): Remove when we no longer unpoison all writes.
# if !REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION
functions.try_emplace("msan_unpoison", reinterpret_cast<void *>(__msan_unpoison));
# endif
functions.try_emplace("emutls_get_address", reinterpret_cast<void *>(rr::getTLSAddress)); functions.try_emplace("emutls_get_address", reinterpret_cast<void *>(rr::getTLSAddress));
functions.try_emplace("emutls_v.__msan_retval_tls", reinterpret_cast<void *>(static_cast<uintptr_t>(rr::MSanTLS::retval))); functions.try_emplace("emutls_v.__msan_retval_tls", reinterpret_cast<void *>(static_cast<uintptr_t>(rr::MSanTLS::retval)));
......
...@@ -985,7 +985,7 @@ Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatil ...@@ -985,7 +985,7 @@ Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatil
auto elTy = T(type); auto elTy = T(type);
ASSERT(V(ptr)->getType()->getContainedType(0) == elTy); ASSERT(V(ptr)->getType()->getContainedType(0) == elTy);
if(__has_feature(memory_sanitizer)) if(__has_feature(memory_sanitizer) && !REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION)
{ {
// Mark all memory writes as initialized by calling __msan_unpoison // Mark all memory writes as initialized by calling __msan_unpoison
// void __msan_unpoison(const volatile void *a, size_t size) // void __msan_unpoison(const volatile void *a, size_t size)
...@@ -1091,7 +1091,7 @@ void Nucleus::createMaskedStore(Value *ptr, Value *val, Value *mask, unsigned in ...@@ -1091,7 +1091,7 @@ void Nucleus::createMaskedStore(Value *ptr, Value *val, Value *mask, unsigned in
auto func = llvm::Intrinsic::getDeclaration(jit->module.get(), llvm::Intrinsic::masked_store, { elVecTy, elVecPtrTy }); auto func = llvm::Intrinsic::getDeclaration(jit->module.get(), llvm::Intrinsic::masked_store, { elVecTy, elVecPtrTy });
jit->builder->CreateCall(func, { V(val), V(ptr), align, i1Mask }); jit->builder->CreateCall(func, { V(val), V(ptr), align, i1Mask });
if(__has_feature(memory_sanitizer)) if(__has_feature(memory_sanitizer) && !REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION)
{ {
// Mark memory writes as initialized by calling __msan_unpoison // Mark memory writes as initialized by calling __msan_unpoison
// void __msan_unpoison(const volatile void *a, size_t size) // void __msan_unpoison(const volatile void *a, size_t size)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment