[compiler-rt] r183224 - [sanitizer] Fix __sanitizer_unaligned_* to work with unaligned data types.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Tue Jun 4 06:49:10 PDT 2013
Author: eugenis
Date: Tue Jun 4 08:49:10 2013
New Revision: 183224
URL: http://llvm.org/viewvc/llvm-project?rev=183224&view=rev
Log:
[sanitizer] Fix __sanitizer_unaligned_* to work with unaligned data types.
Modified:
compiler-rt/trunk/lib/asan/asan_poisoning.cc
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/msan/msan_interface_internal.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h
Modified: compiler-rt/trunk/lib/asan/asan_poisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=183224&r1=183223&r2=183224&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Tue Jun 4 08:49:10 2013
@@ -183,37 +183,37 @@ uptr __asan_region_is_poisoned(uptr beg,
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-u16 __sanitizer_unaligned_load16(const u16 *p) {
+u16 __sanitizer_unaligned_load16(const uu16 *p) {
CHECK_SMALL_REGION(p, sizeof(*p), false);
return *p;
}
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-u32 __sanitizer_unaligned_load32(const u32 *p) {
+u32 __sanitizer_unaligned_load32(const uu32 *p) {
CHECK_SMALL_REGION(p, sizeof(*p), false);
return *p;
}
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-u64 __sanitizer_unaligned_load64(const u64 *p) {
+u64 __sanitizer_unaligned_load64(const uu64 *p) {
CHECK_SMALL_REGION(p, sizeof(*p), false);
return *p;
}
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_unaligned_store16(u16 *p, u16 x) {
+void __sanitizer_unaligned_store16(uu16 *p, u16 x) {
CHECK_SMALL_REGION(p, sizeof(*p), true);
*p = x;
}
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_unaligned_store32(u32 *p, u32 x) {
+void __sanitizer_unaligned_store32(uu32 *p, u32 x) {
CHECK_SMALL_REGION(p, sizeof(*p), true);
*p = x;
}
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_unaligned_store64(u64 *p, u64 x) {
+void __sanitizer_unaligned_store64(uu64 *p, u64 x) {
CHECK_SMALL_REGION(p, sizeof(*p), true);
*p = x;
}
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=183224&r1=183223&r2=183224&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Tue Jun 4 08:49:10 2013
@@ -459,29 +459,29 @@ 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;
+u16 __sanitizer_unaligned_load16(const uu16 *p) {
+ __msan_retval_tls[0] = *(uu16 *)MEM_TO_SHADOW((uptr)p);
+ return *p;
+}
+u32 __sanitizer_unaligned_load32(const uu32 *p) {
+ __msan_retval_tls[0] = *(uu32 *)MEM_TO_SHADOW((uptr)p);
+ return *p;
+}
+u64 __sanitizer_unaligned_load64(const uu64 *p) {
+ __msan_retval_tls[0] = *(uu64 *)MEM_TO_SHADOW((uptr)p);
+ return *p;
+}
+void __sanitizer_unaligned_store16(uu16 *p, u16 x) {
+ *(uu16 *)MEM_TO_SHADOW((uptr)p) = __msan_param_tls[1];
+ *p = x;
+}
+void __sanitizer_unaligned_store32(uu32 *p, u32 x) {
+ *(uu32 *)MEM_TO_SHADOW((uptr)p) = __msan_param_tls[1];
+ *p = x;
+}
+void __sanitizer_unaligned_store64(uu64 *p, u64 x) {
+ *(uu64 *)MEM_TO_SHADOW((uptr)p) = __msan_param_tls[1];
+ *p = x;
}
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
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=183224&r1=183223&r2=183224&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:49:10 2013
@@ -125,22 +125,22 @@ void __msan_allocated_memory(const void*
void __msan_unpoison_param(uptr n);
SANITIZER_INTERFACE_ATTRIBUTE
-u16 __sanitizer_unaligned_load16(const void *p);
+u16 __sanitizer_unaligned_load16(const uu16 *p);
SANITIZER_INTERFACE_ATTRIBUTE
-u32 __sanitizer_unaligned_load32(const void *p);
+u32 __sanitizer_unaligned_load32(const uu32 *p);
SANITIZER_INTERFACE_ATTRIBUTE
-u64 __sanitizer_unaligned_load64(const void *p);
+u64 __sanitizer_unaligned_load64(const uu64 *p);
SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_unaligned_store16(void *p, u16 x);
+void __sanitizer_unaligned_store16(uu16 *p, u16 x);
SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_unaligned_store32(void *p, u32 x);
+void __sanitizer_unaligned_store32(uu32 *p, u32 x);
SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_unaligned_store64(void *p, u64 x);
+void __sanitizer_unaligned_store64(uu64 *p, u64 x);
} // extern "C"
#endif // MSAN_INTERFACE_INTERNAL_H
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=183224&r1=183223&r2=183224&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Tue Jun 4 08:49:10 2013
@@ -68,6 +68,14 @@ typedef signed int s32;
typedef signed long long s64; // NOLINT
typedef int fd_t;
+// Unaligned versions.
+typedef __attribute__((aligned(1))) u16 uu16;
+typedef __attribute__((aligned(1))) u32 uu32;
+typedef __attribute__((aligned(1))) u64 uu64;
+typedef __attribute__((aligned(1))) s16 us16;
+typedef __attribute__((aligned(1))) s32 us32;
+typedef __attribute__((aligned(1))) s64 us64;
+
// WARNING: OFF_T may be different from OS type off_t, depending on the value of
// _FILE_OFFSET_BITS. This definition of OFF_T matches the ABI of system calls
// like pread and mmap, as opposed to pread64 and mmap64.
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc?rev=183224&r1=183223&r2=183224&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface.cc Tue Jun 4 08:49:10 2013
@@ -38,34 +38,34 @@ void __tsan_write16(void *addr) {
MemoryWrite(cur_thread(), CALLERPC, (uptr)addr + 8, kSizeLog8);
}
-u16 __tsan_unaligned_read2(void *addr) {
+u16 __tsan_unaligned_read2(const uu16 *addr) {
UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 2, false, false);
- return *(u16*)addr;
+ return *addr;
}
-u32 __tsan_unaligned_read4(void *addr) {
+u32 __tsan_unaligned_read4(const uu32 *addr) {
UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 4, false, false);
- return *(u32*)addr;
+ return *addr;
}
-u64 __tsan_unaligned_read8(void *addr) {
+u64 __tsan_unaligned_read8(const uu64 *addr) {
UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 8, false, false);
- return *(u64*)addr;
+ return *addr;
}
-void __tsan_unaligned_write2(void *addr, u16 v) {
+void __tsan_unaligned_write2(uu16 *addr, u16 v) {
UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 2, true, false);
- *(u16*)addr = v;
+ *addr = v;
}
-void __tsan_unaligned_write4(void *addr, u32 v) {
+void __tsan_unaligned_write4(uu32 *addr, u32 v) {
UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 4, true, false);
- *(u32*)addr = v;
+ *addr = v;
}
-void __tsan_unaligned_write8(void *addr, u64 v) {
+void __tsan_unaligned_write8(uu64 *addr, u64 v) {
UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 8, true, false);
- *(u64*)addr = v;
+ *addr = v;
}
extern "C" {
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h?rev=183224&r1=183223&r2=183224&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface.h Tue Jun 4 08:49:10 2013
@@ -41,12 +41,12 @@ void __tsan_write4(void *addr) SANITIZER
void __tsan_write8(void *addr) SANITIZER_INTERFACE_ATTRIBUTE;
void __tsan_write16(void *addr) SANITIZER_INTERFACE_ATTRIBUTE;
-u16 __tsan_unaligned_read2(void *addr) SANITIZER_INTERFACE_ATTRIBUTE;
-u32 __tsan_unaligned_read4(void *addr) SANITIZER_INTERFACE_ATTRIBUTE;
-u64 __tsan_unaligned_read8(void *addr) SANITIZER_INTERFACE_ATTRIBUTE;
-void __tsan_unaligned_write2(void *addr, u16 v) SANITIZER_INTERFACE_ATTRIBUTE;
-void __tsan_unaligned_write4(void *addr, u32 v) SANITIZER_INTERFACE_ATTRIBUTE;
-void __tsan_unaligned_write8(void *addr, u64 v) SANITIZER_INTERFACE_ATTRIBUTE;
+u16 __tsan_unaligned_read2(const uu16 *addr) SANITIZER_INTERFACE_ATTRIBUTE;
+u32 __tsan_unaligned_read4(const uu32 *addr) SANITIZER_INTERFACE_ATTRIBUTE;
+u64 __tsan_unaligned_read8(const uu64 *addr) SANITIZER_INTERFACE_ATTRIBUTE;
+void __tsan_unaligned_write2(uu16 *addr, u16 v) SANITIZER_INTERFACE_ATTRIBUTE;
+void __tsan_unaligned_write4(uu32 *addr, u32 v) SANITIZER_INTERFACE_ATTRIBUTE;
+void __tsan_unaligned_write8(uu64 *addr, u64 v) SANITIZER_INTERFACE_ATTRIBUTE;
void __tsan_vptr_read(void **vptr_p) SANITIZER_INTERFACE_ATTRIBUTE;
void __tsan_vptr_update(void **vptr_p, void *new_val)
More information about the llvm-commits
mailing list