diff options
| author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-25 08:58:13 +0000 |
|---|---|---|
| committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2013-10-25 08:58:13 +0000 |
| commit | be9cdbb58cfd35291e51291390ac845fb7156095 (patch) | |
| tree | d3f591a85bae53ec75a37fb6d5218ec59665af99 /compiler-rt | |
| parent | 273670aaaaf97c6a8b289d6303de10cf0aad868a (diff) | |
| download | bcm5719-llvm-be9cdbb58cfd35291e51291390ac845fb7156095.tar.gz bcm5719-llvm-be9cdbb58cfd35291e51291390ac845fb7156095.zip | |
[sanitizer] Intercept random_r.
llvm-svn: 193396
Diffstat (limited to 'compiler-rt')
| -rw-r--r-- | compiler-rt/lib/msan/tests/msan_test.cc | 13 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc | 15 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_stat.cc | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_stat.h | 1 |
5 files changed, 31 insertions, 0 deletions
diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc index a8efd3cc5a7..9f6d7d50d0f 100644 --- a/compiler-rt/lib/msan/tests/msan_test.cc +++ b/compiler-rt/lib/msan/tests/msan_test.cc @@ -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]; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 4beedd216ec..e69a21d0b58 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2526,6 +2526,20 @@ INTERCEPTOR(int, shmctl, int shmid, int cmd, void *buf) { #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 cmd, void *buf) { INIT_ETHER; \ INIT_ETHER_R; \ INIT_SHMCTL; \ + INIT_RANDOM_R; \ /**/ diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 401c7d3a5e7..8610f1b84ed 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -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 diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc index 30177e71dfe..64c2bd0129d 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc @@ -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 "; diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h index 5b8c60f0514..bf7d6c8af18 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_stat.h +++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h @@ -388,6 +388,7 @@ enum StatType { StatInt_ether_hostton, StatInt_ether_line, StatInt_shmctl, + StatInt_random_r, // Dynamic annotations. StatAnnotation, |

