[compiler-rt] r250761 - [msan] Intercept mincore.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 19 16:39:12 PDT 2015
Author: eugenis
Date: Mon Oct 19 18:39:11 2015
New Revision: 250761
URL: http://llvm.org/viewvc/llvm-project?rev=250761&view=rev
Log:
[msan] Intercept mincore.
Added:
compiler-rt/trunk/test/msan/Linux/mincore.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=250761&r1=250760&r2=250761&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Oct 19 18:39:11 2015
@@ -5219,6 +5219,23 @@ INTERCEPTOR(int, pthread_setcanceltype,
#define INIT_PTHREAD_SETCANCEL
#endif
+#if SANITIZER_INTERCEPT_MINCORE
+INTERCEPTOR(int, mincore, void *addr, uptr length, unsigned char *vec) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, mincore, addr, length, vec);
+ int res = REAL(mincore)(addr, length, vec);
+ if (res == 0) {
+ uptr page_size = GetPageSizeCached();
+ uptr vec_size = ((length + page_size - 1) & (~(page_size - 1))) / page_size;
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, vec, vec_size);
+ }
+ return res;
+}
+#define INIT_MINCORE COMMON_INTERCEPT_FUNCTION(mincore);
+#else
+#define INIT_MINCORE
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -5391,4 +5408,5 @@ static void InitializeCommonInterceptors
INIT_FOPENCOOKIE;
INIT_SEM;
INIT_PTHREAD_SETCANCEL;
+ INIT_MINCORE;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=250761&r1=250760&r2=250761&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Oct 19 18:39:11 2015
@@ -258,6 +258,7 @@
#define SANITIZER_INTERCEPT_FOPENCOOKIE SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_SEM SI_LINUX || SI_FREEBSD
#define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_NOT_WINDOWS
+#define SANITIZER_INTERCEPT_MINCORE SI_LINUX
#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX
Added: compiler-rt/trunk/test/msan/Linux/mincore.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/Linux/mincore.cc?rev=250761&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/mincore.cc (added)
+++ compiler-rt/trunk/test/msan/Linux/mincore.cc Mon Oct 19 18:39:11 2015
@@ -0,0 +1,36 @@
+// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sanitizer/msan_interface.h>
+
+int main(void) {
+ unsigned char vec[20];
+ int res;
+ size_t PS = sysconf(_SC_PAGESIZE);
+ void *addr = mmap(nullptr, 20 * PS, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+
+ __msan_poison(&vec, sizeof(vec));
+ res = mincore(addr, 10 * PS, vec);
+ assert(res == 0);
+ assert(__msan_test_shadow(vec, sizeof(vec)) == 10);
+
+ __msan_poison(&vec, sizeof(vec));
+ res = mincore(addr, 10 * PS + 42, vec);
+ assert(res == 0);
+ assert(__msan_test_shadow(vec, sizeof(vec)) == 11);
+
+ __msan_poison(&vec, sizeof(vec));
+ res = mincore(addr, 10 * PS - 1, vec);
+ assert(res == 0);
+ assert(__msan_test_shadow(vec, sizeof(vec)) == 10);
+
+ __msan_poison(&vec, sizeof(vec));
+ res = mincore(addr, 1, vec);
+ assert(res == 0);
+ assert(__msan_test_shadow(vec, sizeof(vec)) == 1);
+
+ return 0;
+}
More information about the llvm-commits
mailing list