[compiler-rt] r193343 - [msan] Unpoison errno in common interceptors.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Oct 24 06:20:34 PDT 2013


Author: eugenis
Date: Thu Oct 24 08:20:34 2013
New Revision: 193343

URL: http://llvm.org/viewvc/llvm-project?rev=193343&view=rev
Log:
[msan] Unpoison errno in common interceptors.

Added:
    compiler-rt/trunk/lib/msan/lit_tests/errno.cc   (with props)
Modified:
    compiler-rt/trunk/lib/msan/msan_interceptors.cc

Added: compiler-rt/trunk/lib/msan/lit_tests/errno.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/errno.cc?rev=193343&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/errno.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/errno.cc Thu Oct 24 08:20:34 2013
@@ -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;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/errno.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=193343&r1=193342&r2=193343&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Oct 24 08:20:34 2013
@@ -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 {                                         \





More information about the llvm-commits mailing list