[llvm-commits] [compiler-rt] r172720 - in /compiler-rt/trunk/lib/msan: msan_interceptors.cc msan_platform_limits_posix.cc msan_platform_limits_posix.h tests/CMakeLists.txt tests/msan_test.cc
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu Jan 17 05:42:18 PST 2013
Author: eugenis
Date: Thu Jan 17 07:42:17 2013
New Revision: 172720
URL: http://llvm.org/viewvc/llvm-project?rev=172720&view=rev
Log:
[msan] More interceptors.
strtod and friends, dladdr, getrusage
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/msan/msan_platform_limits_posix.cc
compiler-rt/trunk/lib/msan/msan_platform_limits_posix.h
compiler-rt/trunk/lib/msan/tests/CMakeLists.txt
compiler-rt/trunk/lib/msan/tests/msan_test.cc
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=172720&r1=172719&r2=172720&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Jan 17 07:42:17 2013
@@ -247,6 +247,33 @@
return res;
}
+INTERCEPTOR(double, strtod, const char *nptr, char **endptr) { // NOLINT
+ ENSURE_MSAN_INITED();
+ double res = REAL(strtod)(nptr, endptr); // NOLINT
+ if (!__msan_has_dynamic_component()) {
+ __msan_unpoison(endptr, sizeof(*endptr));
+ }
+ return res;
+}
+
+INTERCEPTOR(float, strtof, const char *nptr, char **endptr) { // NOLINT
+ ENSURE_MSAN_INITED();
+ float res = REAL(strtof)(nptr, endptr); // NOLINT
+ if (!__msan_has_dynamic_component()) {
+ __msan_unpoison(endptr, sizeof(*endptr));
+ }
+ return res;
+}
+
+INTERCEPTOR(long double, strtold, const char *nptr, char **endptr) { // NOLINT
+ ENSURE_MSAN_INITED();
+ long double res = REAL(strtold)(nptr, endptr); // NOLINT
+ if (!__msan_has_dynamic_component()) {
+ __msan_unpoison(endptr, sizeof(*endptr));
+ }
+ return res;
+}
+
INTERCEPTOR(int, vsnprintf, char *str, uptr size,
const char *format, va_list ap) {
ENSURE_MSAN_INITED();
@@ -703,6 +730,35 @@
return res;
}
+struct dlinfo {
+ char *dli_fname;
+ void *dli_fbase;
+ char *dli_sname;
+ void *dli_saddr;
+};
+
+INTERCEPTOR(int, dladdr, void *addr, dlinfo *info) {
+ ENSURE_MSAN_INITED();
+ int res = REAL(dladdr)(addr, info);
+ if (res != 0) {
+ __msan_unpoison(info, sizeof(*info));
+ if (info->dli_fname)
+ __msan_unpoison(info->dli_fname, REAL(strlen)(info->dli_fname) + 1);
+ if (info->dli_sname)
+ __msan_unpoison(info->dli_sname, REAL(strlen)(info->dli_sname) + 1);
+ }
+ return res;
+}
+
+INTERCEPTOR(int, getrusage, int who, void *usage) {
+ ENSURE_MSAN_INITED();
+ int res = REAL(getrusage)(who, usage);
+ if (res == 0) {
+ __msan_unpoison(usage, __msan::struct_rusage_sz);
+ }
+ return res;
+}
+
// static
void *fast_memset(void *ptr, int c, SIZE_T n) {
// hack until we have a really fast internal_memset
@@ -844,6 +900,9 @@
INTERCEPT_FUNCTION(strtoll);
INTERCEPT_FUNCTION(strtoul);
INTERCEPT_FUNCTION(strtoull);
+ INTERCEPT_FUNCTION(strtod);
+ INTERCEPT_FUNCTION(strtof);
+ INTERCEPT_FUNCTION(strtold);
INTERCEPT_FUNCTION(vsprintf);
INTERCEPT_FUNCTION(vsnprintf);
INTERCEPT_FUNCTION(vswprintf);
@@ -886,6 +945,8 @@
INTERCEPT_FUNCTION(recv);
INTERCEPT_FUNCTION(recvfrom);
INTERCEPT_FUNCTION(recvmsg);
+ INTERCEPT_FUNCTION(dladdr);
+ INTERCEPT_FUNCTION(getrusage);
inited = 1;
}
} // namespace __msan
Modified: compiler-rt/trunk/lib/msan/msan_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_platform_limits_posix.cc?rev=172720&r1=172719&r2=172720&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_platform_limits_posix.cc Thu Jan 17 07:42:17 2013
@@ -20,6 +20,7 @@
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/resource.h>
#include <sys/vfs.h>
#include <sys/epoll.h>
@@ -36,6 +37,7 @@
unsigned struct_statfs_sz = sizeof(struct statfs);
unsigned struct_statfs64_sz = sizeof(struct statfs64);
unsigned struct_epoll_event_sz = sizeof(struct epoll_event);
+ unsigned struct_rusage_sz = sizeof(struct rusage);
void* __msan_get_msghdr_iov_iov_base(void* msg, int idx) {
return ((struct msghdr *)msg)->msg_iov[idx].iov_base;
Modified: compiler-rt/trunk/lib/msan/msan_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_platform_limits_posix.h?rev=172720&r1=172719&r2=172720&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/msan/msan_platform_limits_posix.h Thu Jan 17 07:42:17 2013
@@ -25,6 +25,7 @@
extern unsigned struct_statfs_sz;
extern unsigned struct_statfs64_sz;
extern unsigned struct_epoll_event_sz;
+ extern unsigned struct_rusage_sz;
void* __msan_get_msghdr_iov_iov_base(void* msg, int idx);
uptr __msan_get_msghdr_iov_iov_len(void* msg, int idx);
Modified: compiler-rt/trunk/lib/msan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/CMakeLists.txt?rev=172720&r1=172719&r2=172720&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/msan/tests/CMakeLists.txt Thu Jan 17 07:42:17 2013
@@ -59,6 +59,7 @@
set(MSAN_UNITTEST_LINK_FLAGS
-fsanitize=memory
-pie
+ -ldl
# FIXME: we build libcxx without cxxabi and need libstdc++ to provide it.
-lstdc++
)
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=172720&r1=172719&r2=172720&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu Jan 17 07:42:17 2013
@@ -22,6 +22,7 @@
#include <assert.h>
#include <wchar.h>
+#include <dlfcn.h>
#include <unistd.h>
#include <limits.h>
#include <sys/time.h>
@@ -683,6 +684,24 @@
v_s8 = (S8) e;
}
+TEST(MemorySanitizer, strtod) {
+ char *e;
+ assert(0 != strtod("1.5", &e));
+ v_s8 = (S8) e;
+}
+
+TEST(MemorySanitizer, strtof) {
+ char *e;
+ assert(0 != strtof("1.5", &e));
+ v_s8 = (S8) e;
+}
+
+TEST(MemorySanitizer, strtold) {
+ char *e;
+ assert(0 != strtold("1.5", &e));
+ v_s8 = (S8) e;
+}
+
TEST(MemorySanitizer, sprintf) { // NOLINT
char buff[10];
__msan_break_optimization(buff);
@@ -1191,6 +1210,42 @@
t = limit.rlim_max;
}
+TEST(MemorySanitizer, getrusage) {
+ struct rusage usage;
+ __msan_poison(&usage, sizeof(usage));
+ int result = getrusage(RUSAGE_SELF, &usage);
+ assert(result == 0);
+ volatile struct timeval t;
+ v_u8 = usage.ru_utime.tv_sec;
+ v_u8 = usage.ru_utime.tv_usec;
+ v_u8 = usage.ru_stime.tv_sec;
+ v_u8 = usage.ru_stime.tv_usec;
+ v_s8 = usage.ru_maxrss;
+ v_s8 = usage.ru_minflt;
+ v_s8 = usage.ru_majflt;
+ v_s8 = usage.ru_inblock;
+ v_s8 = usage.ru_oublock;
+ v_s8 = usage.ru_nvcsw;
+ v_s8 = usage.ru_nivcsw;
+}
+
+static void dladdr_testfn() {}
+
+TEST(MemorySanitizer, dladdr) {
+ Dl_info info;
+ __msan_poison(&info, sizeof(info));
+ int result = dladdr((const void*)dladdr_testfn, &info);
+ assert(result != 0);
+ v_u8 = (unsigned long)info.dli_fname;
+ if (info.dli_fname)
+ v_u8 = strlen(info.dli_fname);
+ v_u8 = (unsigned long)info.dli_fbase;
+ v_u8 = (unsigned long)info.dli_sname;
+ if (info.dli_sname)
+ v_u8 = strlen(info.dli_sname);
+ v_u8 = (unsigned long)info.dli_saddr;
+}
+
static void* SimpleThread_threadfn(void* data) {
return new int;
}
More information about the llvm-commits
mailing list