diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-07-31 09:12:20 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-07-31 09:12:20 +0000 |
commit | 1cd9e019dae22e01ce608a9b333dfb3e38045d6a (patch) | |
tree | 8dc5b11fadbbb946e7ad579780be91758cf6df7e /compiler-rt | |
parent | 77ad86681faf93230612fac1ae3dfe13476fa7cb (diff) | |
download | bcm5719-llvm-1cd9e019dae22e01ce608a9b333dfb3e38045d6a.tar.gz bcm5719-llvm-1cd9e019dae22e01ce608a9b333dfb3e38045d6a.zip |
[asan] End-to-end test for REP MOVS instrumentation.
Patch by Yuri Gorshenin.
llvm-svn: 214396
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/asan/tests/asan_asm_test.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/tests/asan_asm_test.cc b/compiler-rt/lib/asan/tests/asan_asm_test.cc index 86f806dd2f9..1d8b04d611b 100644 --- a/compiler-rt/lib/asan/tests/asan_asm_test.cc +++ b/compiler-rt/lib/asan/tests/asan_asm_test.cc @@ -22,6 +22,7 @@ namespace { template<typename T> void asm_write(T *ptr, T val); template<typename T> T asm_read(T *ptr); +template<typename T> void asm_rep_movs(T *dst, T *src, size_t n); } // End of anonymous namespace @@ -53,8 +54,17 @@ template<> Type asm_read<Type>(Type *ptr) { \ return res; \ } +#define DECLARE_ASM_REP_MOVS(Type, Movs) \ + template <> void asm_rep_movs<Type>(Type * dst, Type * src, size_t size) { \ + __asm__("rep " Movs " \n\t" \ + : \ + : "D"(dst), "S"(src), "c"(size) \ + : "rsi", "rdi", "rcx", "memory"); \ + } + DECLARE_ASM_WRITE(U8, "8", "movq", "r"); DECLARE_ASM_READ(U8, "8", "movq", "=r"); +DECLARE_ASM_REP_MOVS(U8, "movsq"); } // End of anonymous namespace @@ -86,6 +96,14 @@ template<> Type asm_read<Type>(Type *ptr) { \ return res; \ } +#define DECLARE_ASM_REP_MOVS(Type, Movs) \ + template <> void asm_rep_movs<Type>(Type * dst, Type * src, size_t size) { \ + __asm__("rep " Movs " \n\t" \ + : \ + : "D"(dst), "S"(src), "c"(size) \ + : "esi", "edi", "ecx", "memory"); \ + } + } // End of anonymous namespace #endif // defined(__i386__) && defined(__SSE2__) @@ -104,6 +122,10 @@ DECLARE_ASM_READ(U2, "2", "movw", "=r"); DECLARE_ASM_READ(U4, "4", "movl", "=r"); DECLARE_ASM_READ(__m128i, "16", "movaps", "=x"); +DECLARE_ASM_REP_MOVS(U1, "movsb"); +DECLARE_ASM_REP_MOVS(U2, "movsw"); +DECLARE_ASM_REP_MOVS(U4, "movsl"); + template<typename T> void TestAsmWrite(const char *DeathPattern) { T *buf = new T; EXPECT_DEATH(asm_write(&buf[1], static_cast<T>(0)), DeathPattern); @@ -157,6 +179,28 @@ void AsmStore(U4 r, U4 *a) { __asm__("movl %[r], (%[a]) \n\t" : : [a] "r" (a), [r] "r" (r) : "memory"); } +template <typename T> +void TestAsmRepMovs(const char *DeathPatternRead, + const char *DeathPatternWrite) { + T src_good[4] = { 0x0, 0x1, 0x2, 0x3 }; + T dst_good[4] = {}; + asm_rep_movs(dst_good, src_good, 4); + ASSERT_EQ(static_cast<T>(0x0), dst_good[0]); + ASSERT_EQ(static_cast<T>(0x1), dst_good[1]); + ASSERT_EQ(static_cast<T>(0x2), dst_good[2]); + ASSERT_EQ(static_cast<T>(0x3), dst_good[3]); + + T dst_bad[3]; + EXPECT_DEATH(asm_rep_movs(dst_bad, src_good, 4), DeathPatternWrite); + + T src_bad[3] = { 0x0, 0x1, 0x2 }; + EXPECT_DEATH(asm_rep_movs(dst_good, src_bad, 4), DeathPatternRead); + + T* dp = dst_bad + 4; + T* sp = src_bad + 4; + asm_rep_movs(dp, sp, 0); +} + } // End of anonymous namespace TEST(AddressSanitizer, asm_load_store) { @@ -209,6 +253,15 @@ TEST(AddressSanitizer, asm_flags) { ASSERT_EQ(0x1, r); } +TEST(AddressSanitizer, asm_rep_movs) { + TestAsmRepMovs<U1>("READ of size 1", "WRITE of size 1"); + TestAsmRepMovs<U2>("READ of size 2", "WRITE of size 2"); + TestAsmRepMovs<U4>("READ of size 4", "WRITE of size 4"); +#if defined(__x86_64__) + TestAsmRepMovs<U8>("READ of size 8", "WRITE of size 8"); +#endif // defined(__x86_64__) +} + #endif // defined(__x86_64__) || (defined(__i386__) && defined(__SSE2__)) #endif // defined(__linux__) |