From 1161eb4bff61908074699f6459eabce25839f966 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 24 Oct 2013 13:20:34 +0000 Subject: [msan] Unpoison errno in common interceptors. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193343 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/msan/lit_tests/errno.cc | 17 +++++++++++++++++ lib/msan/msan_interceptors.cc | 15 +++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 lib/msan/lit_tests/errno.cc diff --git a/lib/msan/lit_tests/errno.cc b/lib/msan/lit_tests/errno.cc new file mode 100644 index 00000000..af27ad0b --- /dev/null +++ b/lib/msan/lit_tests/errno.cc @@ -0,0 +1,17 @@ +// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t + +#include +#include +#include +#include + +int main() +{ + int x; + int *volatile p = &x; + errno = *p; + int res = read(-1, 0, 0); + assert(res == -1); + if (errno) printf("errno %d\n", errno); + return 0; +} diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc index 849949d3..aea2ef6b 100644 --- a/lib/msan/msan_interceptors.cc +++ b/lib/msan/msan_interceptors.cc @@ -1172,6 +1172,8 @@ int OnExit() { } // namespace __msan +extern "C" int *__errno_location(void); + // A version of CHECK_UNPOISED using a saved scope value. Used in common // interceptors. #define CHECK_UNPOISONED_CTX(ctx, x, n) \ @@ -1188,12 +1190,13 @@ int OnExit() { CHECK_UNPOISONED_CTX(ctx, ptr, size) #define COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, ptr, size) \ __msan_unpoison(ptr, size) -#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \ - if (msan_init_is_running) return REAL(func)(__VA_ARGS__); \ - MSanInterceptorContext msan_ctx = {IsInInterceptorScope()}; \ - ctx = (void *)&msan_ctx; \ - (void)ctx; \ - InterceptorScope interceptor_scope; \ +#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \ + if (msan_init_is_running) return REAL(func)(__VA_ARGS__); \ + MSanInterceptorContext msan_ctx = {IsInInterceptorScope()}; \ + ctx = (void *)&msan_ctx; \ + (void)ctx; \ + InterceptorScope interceptor_scope; \ + __msan_unpoison(__errno_location(), sizeof(int)); /* NOLINT */ \ ENSURE_MSAN_INITED(); #define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \ do { \ -- cgit v1.2.3