[compiler-rt] r183221 - [msan] Implement __sanitizer_unaligned_*.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Tue Jun 4 06:08:36 PDT 2013
Author: eugenis
Date: Tue Jun 4 08:08:36 2013
New Revision: 183221
URL: http://llvm.org/viewvc/llvm-project?rev=183221&view=rev
Log:
[msan] Implement __sanitizer_unaligned_*.
Modified:
compiler-rt/trunk/lib/msan/msan.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=183221&r1=183220&r2=183221&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Tue Jun 4 08:08:36 2013
@@ -459,6 +459,31 @@ u32 __msan_get_umr_origin() {
return __msan_origin_tls;
}
+u16 __sanitizer_unaligned_load16(const void *p) {
+ __msan_retval_tls[0] = *(u16 *)MEM_TO_SHADOW((uptr)p);
+ return *(u16 *)p;
+}
+u32 __sanitizer_unaligned_load32(const void *p) {
+ __msan_retval_tls[0] = *(u32 *)MEM_TO_SHADOW((uptr)p);
+ return *(u32 *)p;
+}
+u64 __sanitizer_unaligned_load64(const void *p) {
+ __msan_retval_tls[0] = *(u64 *)MEM_TO_SHADOW((uptr)p);
+ return *(u64 *)p;
+}
+void __sanitizer_unaligned_store16(void *p, u16 x) {
+ *(u16 *)MEM_TO_SHADOW((uptr)p) = __msan_param_tls[1];
+ *(u16 *)p = x;
+}
+void __sanitizer_unaligned_store32(void *p, u32 x) {
+ *(u32 *)MEM_TO_SHADOW((uptr)p) = __msan_param_tls[1];
+ *(u32 *)p = x;
+}
+void __sanitizer_unaligned_store64(void *p, u64 x) {
+ *(u64 *)MEM_TO_SHADOW((uptr)p) = __msan_param_tls[1];
+ *(u64 *)p = x;
+}
+
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
extern "C" {
SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
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=183221&r1=183220&r2=183221&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interface_internal.h (original)
+++ compiler-rt/trunk/lib/msan/msan_interface_internal.h Tue Jun 4 08:08:36 2013
@@ -120,9 +120,27 @@ void __msan_partial_poison(const void* d
// Memory will be marked uninitialized, with origin at the call site.
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);
+SANITIZER_INTERFACE_ATTRIBUTE
+u16 __sanitizer_unaligned_load16(const void *p);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+u32 __sanitizer_unaligned_load32(const void *p);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+u64 __sanitizer_unaligned_load64(const void *p);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+void __sanitizer_unaligned_store16(void *p, u16 x);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+void __sanitizer_unaligned_store32(void *p, u32 x);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+void __sanitizer_unaligned_store64(void *p, u64 x);
+} // extern "C"
+
#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=183221&r1=183220&r2=183221&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Tue Jun 4 08:08:36 2013
@@ -2060,6 +2060,83 @@ TEST(MemorySanitizer, VolatileBitfield)
EXPECT_POISONED((unsigned)S->y);
}
+TEST(MemorySanitizer, UnalignedLoad) {
+ char x[32];
+ memset(x + 8, 0, 16);
+ EXPECT_POISONED(__sanitizer_unaligned_load16(x+6));
+ EXPECT_POISONED(__sanitizer_unaligned_load16(x+7));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load16(x+8));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load16(x+9));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load16(x+22));
+ EXPECT_POISONED(__sanitizer_unaligned_load16(x+23));
+ EXPECT_POISONED(__sanitizer_unaligned_load16(x+24));
+
+ EXPECT_POISONED(__sanitizer_unaligned_load32(x+4));
+ EXPECT_POISONED(__sanitizer_unaligned_load32(x+7));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load32(x+8));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load32(x+9));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load32(x+20));
+ EXPECT_POISONED(__sanitizer_unaligned_load32(x+21));
+ EXPECT_POISONED(__sanitizer_unaligned_load32(x+24));
+
+ EXPECT_POISONED(__sanitizer_unaligned_load64(x));
+ EXPECT_POISONED(__sanitizer_unaligned_load64(x+1));
+ EXPECT_POISONED(__sanitizer_unaligned_load64(x+7));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load64(x+8));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load64(x+9));
+ EXPECT_NOT_POISONED(__sanitizer_unaligned_load64(x+16));
+ EXPECT_POISONED(__sanitizer_unaligned_load64(x+17));
+ EXPECT_POISONED(__sanitizer_unaligned_load64(x+21));
+ EXPECT_POISONED(__sanitizer_unaligned_load64(x+24));
+}
+
+TEST(MemorySanitizer, UnalignedStore16) {
+ char x[5];
+ U2 y = 0;
+ __msan_poison(&y, 1);
+ __sanitizer_unaligned_store16(x + 1, y);
+ EXPECT_POISONED(x[0]);
+ EXPECT_POISONED(x[1]);
+ EXPECT_NOT_POISONED(x[2]);
+ EXPECT_POISONED(x[3]);
+ EXPECT_POISONED(x[4]);
+}
+
+TEST(MemorySanitizer, UnalignedStore32) {
+ char x[8];
+ U4 y4 = 0;
+ __msan_poison(&y4, 2);
+ __sanitizer_unaligned_store32(x+3, y4);
+ EXPECT_POISONED(x[0]);
+ EXPECT_POISONED(x[1]);
+ EXPECT_POISONED(x[2]);
+ EXPECT_POISONED(x[3]);
+ EXPECT_POISONED(x[4]);
+ EXPECT_NOT_POISONED(x[5]);
+ EXPECT_NOT_POISONED(x[6]);
+ EXPECT_POISONED(x[7]);
+}
+
+TEST(MemorySanitizer, UnalignedStore64) {
+ char x[16];
+ U8 y = 0;
+ __msan_poison(&y, 3);
+ __msan_poison(((char *)&y) + sizeof(y) - 2, 1);
+ __sanitizer_unaligned_store64(x+3, y);
+ EXPECT_POISONED(x[0]);
+ EXPECT_POISONED(x[1]);
+ EXPECT_POISONED(x[2]);
+ EXPECT_POISONED(x[3]);
+ EXPECT_POISONED(x[4]);
+ EXPECT_POISONED(x[5]);
+ EXPECT_NOT_POISONED(x[6]);
+ EXPECT_NOT_POISONED(x[7]);
+ EXPECT_NOT_POISONED(x[8]);
+ EXPECT_POISONED(x[9]);
+ EXPECT_NOT_POISONED(x[10]);
+ EXPECT_POISONED(x[11]);
+}
+
TEST(MemorySanitizerDr, StoreInDSOTest) {
if (!__msan_has_dynamic_component()) return;
char* s = new char[10];
More information about the llvm-commits
mailing list