[compiler-rt] r182004 - [msan] Intercept dl_iterate_phdr.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu May 16 06:00:25 PDT 2013
Author: eugenis
Date: Thu May 16 08:00:25 2013
New Revision: 182004
URL: http://llvm.org/viewvc/llvm-project?rev=182004&view=rev
Log:
[msan] Intercept dl_iterate_phdr.
Modified:
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/msan/msan_interface_internal.h
compiler-rt/trunk/lib/msan/tests/msan_test.cc
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=182004&r1=182003&r2=182004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Thu May 16 08:00:25 2013
@@ -331,6 +331,10 @@ void __msan_print_param_shadow() {
Printf("\n");
}
+void __msan_unpoison_param(uptr n) {
+ internal_memset(__msan_param_tls, 0, n * sizeof(*__msan_param_tls));
+}
+
sptr __msan_test_shadow(const void *x, uptr size) {
unsigned char *s = (unsigned char*)MEM_TO_SHADOW((uptr)x);
for (uptr i = 0; i < size; ++i)
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=182004&r1=182003&r2=182004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu May 16 08:00:25 2013
@@ -815,6 +815,31 @@ INTERCEPTOR(void *, dlopen, const char *
return (void *)map;
}
+typedef int (*dl_iterate_phdr_cb)(void *info, SIZE_T size, void *data);
+struct dl_iterate_phdr_data {
+ dl_iterate_phdr_cb callback;
+ void *data;
+};
+
+static int msan_dl_iterate_phdr_cb(void *info, SIZE_T size, void *data) {
+ if (info)
+ __msan_unpoison(info, size);
+ dl_iterate_phdr_data *cbdata = (dl_iterate_phdr_data *)data;
+ __msan_unpoison_param(3);
+ return cbdata->callback(info, size, cbdata->data);
+}
+
+INTERCEPTOR(int, dl_iterate_phdr, dl_iterate_phdr_cb callback, void *data) {
+ ENSURE_MSAN_INITED();
+ EnterLoader();
+ dl_iterate_phdr_data cbdata;
+ cbdata.callback = callback;
+ cbdata.data = data;
+ int res = REAL(dl_iterate_phdr)(msan_dl_iterate_phdr_cb, (void *)&cbdata);
+ ExitLoader();
+ return res;
+}
+
INTERCEPTOR(int, getrusage, int who, void *usage) {
ENSURE_MSAN_INITED();
int res = REAL(getrusage)(who, usage);
@@ -1138,6 +1163,7 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(recvmsg);
INTERCEPT_FUNCTION(dladdr);
INTERCEPT_FUNCTION(dlopen);
+ INTERCEPT_FUNCTION(dl_iterate_phdr);
INTERCEPT_FUNCTION(getrusage);
INTERCEPT_FUNCTION(sigaction);
INTERCEPT_FUNCTION(signal);
Modified: compiler-rt/trunk/lib/msan/msan_interface_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interface_internal.h?rev=182004&r1=182003&r2=182004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interface_internal.h (original)
+++ compiler-rt/trunk/lib/msan/msan_interface_internal.h Thu May 16 08:00:25 2013
@@ -122,4 +122,7 @@ SANITIZER_INTERFACE_ATTRIBUTE
void __msan_allocated_memory(const void* data, uptr size);
} // extern "C"
+// Unpoison first n function arguments.
+void __msan_unpoison_param(uptr n);
+
#endif // MSAN_INTERFACE_INTERNAL_H
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=182004&r1=182003&r2=182004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu May 16 08:00:25 2013
@@ -30,6 +30,7 @@
#include <dlfcn.h>
#include <grp.h>
#include <unistd.h>
+#include <link.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -1452,9 +1453,8 @@ TEST(MemorySanitizer, getrlimit) {
__msan_poison(&limit, sizeof(limit));
int result = getrlimit(RLIMIT_DATA, &limit);
assert(result == 0);
- volatile rlim_t t;
- t = limit.rlim_cur;
- t = limit.rlim_max;
+ EXPECT_NOT_POISONED(limit.rlim_cur);
+ EXPECT_NOT_POISONED(limit.rlim_max);
}
TEST(MemorySanitizer, getrusage) {
@@ -1462,7 +1462,6 @@ TEST(MemorySanitizer, getrusage) {
__msan_poison(&usage, sizeof(usage));
int result = getrusage(RUSAGE_SELF, &usage);
assert(result == 0);
- volatile struct timeval t;
EXPECT_NOT_POISONED(usage.ru_utime.tv_sec);
EXPECT_NOT_POISONED(usage.ru_utime.tv_usec);
EXPECT_NOT_POISONED(usage.ru_stime.tv_sec);
@@ -1493,6 +1492,22 @@ TEST(MemorySanitizer, dladdr) {
EXPECT_NOT_POISONED((unsigned long)info.dli_saddr);
}
+static int dl_phdr_callback(struct dl_phdr_info *info, size_t size, void *data) {
+ (*(int *)data)++;
+ EXPECT_NOT_POISONED(info->dlpi_addr);
+ EXPECT_NOT_POISONED(strlen(info->dlpi_name));
+ EXPECT_NOT_POISONED(info->dlpi_phnum);
+ for (int i = 0; i < info->dlpi_phnum; ++i)
+ EXPECT_NOT_POISONED(info->dlpi_phdr[i]);
+ return 0;
+}
+
+TEST(MemorySanitizer, dl_iterate_phdr) {
+ int count = 0;
+ int result = dl_iterate_phdr(dl_phdr_callback, &count);
+ assert(count > 0);
+}
+
namespace {
#ifdef __GLIBC__
extern "C" {
More information about the llvm-commits
mailing list