summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-24 13:20:34 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-10-24 13:20:34 +0000
commit1161eb4bff61908074699f6459eabce25839f966 (patch)
tree8d28b910b366a4cef162ad24b59b375ee76febc8
parent450eee655289a622ab9acf87d863f38991b184c9 (diff)
downloadcompiler-rt-1161eb4bff61908074699f6459eabce25839f966.tar.gz
compiler-rt-1161eb4bff61908074699f6459eabce25839f966.tar.bz2
compiler-rt-1161eb4bff61908074699f6459eabce25839f966.tar.xz
[msan] Unpoison errno in common interceptors.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193343 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/msan/lit_tests/errno.cc17
-rw-r--r--lib/msan/msan_interceptors.cc15
2 files changed, 26 insertions, 6 deletions
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 <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+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 { \