[compiler-rt] r193396 - [sanitizer] Intercept random_r.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Fri Oct 25 01:58:14 PDT 2013
Author: eugenis
Date: Fri Oct 25 03:58:13 2013
New Revision: 193396
URL: http://llvm.org/viewvc/llvm-project?rev=193396&view=rev
Log:
[sanitizer] Intercept random_r.
Modified:
compiler-rt/trunk/lib/msan/tests/msan_test.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.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=193396&r1=193395&r2=193396&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Fri Oct 25 03:58:13 2013
@@ -1146,6 +1146,19 @@ TEST(MemorySanitizer, shmctl) {
ASSERT_GT(res, -1);
}
+TEST(MemorySanitizer, random_r) {
+ int32_t x;
+ char z[64];
+ struct random_data buf;
+
+ memset(z, 0, sizeof(z));
+ int res = initstate_r(0, z, sizeof(z), &buf);
+ ASSERT_EQ(0, res);
+
+ res = random_r(&buf, &x);
+ ASSERT_EQ(0, res);
+ EXPECT_NOT_POISONED(x);
+}
TEST(MemorySanitizer, confstr) {
char buf[3];
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=193396&r1=193395&r2=193396&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Oct 25 03:58:13 2013
@@ -2526,6 +2526,20 @@ INTERCEPTOR(int, shmctl, int shmid, int
#define INIT_SHMCTL
#endif
+#if SANITIZER_INTERCEPT_RANDOM_R
+INTERCEPTOR(int, random_r, void *buf, u32 *result) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, random_r, buf, result);
+ int res = REAL(random_r)(buf, result);
+ if (!res && result)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, result, sizeof(*result));
+ return res;
+}
+#define INIT_RANDOM_R INTERCEPT_FUNCTION(random_r);
+#else
+#define INIT_RANDOM_R
+#endif
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_STRCMP; \
INIT_STRNCMP; \
@@ -2620,4 +2634,5 @@ INTERCEPTOR(int, shmctl, int shmid, int
INIT_ETHER; \
INIT_ETHER_R; \
INIT_SHMCTL; \
+ INIT_RANDOM_R; \
/**/
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=193396&r1=193395&r2=193396&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Oct 25 03:58:13 2013
@@ -136,6 +136,7 @@
# define SANITIZER_INTERCEPT_ETHER SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_ETHER_R SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_SHMCTL SI_LINUX_NOT_ANDROID
+# define SANITIZER_INTERCEPT_RANDOM_R SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT__EXIT SI_LINUX
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=193396&r1=193395&r2=193396&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Fri Oct 25 03:58:13 2013
@@ -393,6 +393,7 @@ void StatOutput(u64 *stat) {
name[StatInt_ether_hostton] = " ether_hostton ";
name[StatInt_ether_line] = " ether_line ";
name[StatInt_shmctl] = " shmctl ";
+ name[StatInt_random_r] = " random_r ";
name[StatAnnotation] = "Dynamic annotations ";
name[StatAnnotateHappensBefore] = " HappensBefore ";
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=193396&r1=193395&r2=193396&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Fri Oct 25 03:58:13 2013
@@ -388,6 +388,7 @@ enum StatType {
StatInt_ether_hostton,
StatInt_ether_line,
StatInt_shmctl,
+ StatInt_random_r,
// Dynamic annotations.
StatAnnotation,
More information about the llvm-commits
mailing list