1 //===-- tsan_interface.cc -------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //===----------------------------------------------------------------------===//
12 #include "tsan_interface.h"
13 #include "tsan_interface_ann.h"
15 #include "sanitizer_common/sanitizer_internal_defs.h"
17 #define CALLERPC ((uptr)__builtin_return_address(0))
19 using namespace __tsan
; // NOLINT
26 Initialize(cur_thread());
29 void __tsan_read16(void *addr
) {
30 MemoryRead(cur_thread(), CALLERPC
, (uptr
)addr
, kSizeLog8
);
31 MemoryRead(cur_thread(), CALLERPC
, (uptr
)addr
+ 8, kSizeLog8
);
34 void __tsan_write16(void *addr
) {
35 MemoryWrite(cur_thread(), CALLERPC
, (uptr
)addr
, kSizeLog8
);
36 MemoryWrite(cur_thread(), CALLERPC
, (uptr
)addr
+ 8, kSizeLog8
);
39 u16
__tsan_unaligned_read2(const uu16
*addr
) {
40 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 2, false, false);
44 u32
__tsan_unaligned_read4(const uu32
*addr
) {
45 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 4, false, false);
49 u64
__tsan_unaligned_read8(const uu64
*addr
) {
50 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 8, false, false);
54 void __tsan_unaligned_write2(uu16
*addr
, u16 v
) {
55 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 2, true, false);
59 void __tsan_unaligned_write4(uu32
*addr
, u32 v
) {
60 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 4, true, false);
64 void __tsan_unaligned_write8(uu64
*addr
, u64 v
) {
65 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 8, true, false);
70 SANITIZER_INTERFACE_ATTRIBUTE
71 uint16_t __sanitizer_unaligned_load16(void *addr
)
72 ALIAS("__tsan_unaligned_read2");
73 SANITIZER_INTERFACE_ATTRIBUTE
74 uint32_t __sanitizer_unaligned_load32(void *addr
)
75 ALIAS("__tsan_unaligned_read4");
76 SANITIZER_INTERFACE_ATTRIBUTE
77 uint64_t __sanitizer_unaligned_load64(void *addr
)
78 ALIAS("__tsan_unaligned_read8");
79 SANITIZER_INTERFACE_ATTRIBUTE
80 void __sanitizer_unaligned_store16(void *addr
, uint16_t v
)
81 ALIAS("__tsan_unaligned_write2");
82 SANITIZER_INTERFACE_ATTRIBUTE
83 void __sanitizer_unaligned_store32(void *addr
, uint32_t v
)
84 ALIAS("__tsan_unaligned_write4");
85 SANITIZER_INTERFACE_ATTRIBUTE
86 void __sanitizer_unaligned_store64(void *addr
, uint64_t v
)
87 ALIAS("__tsan_unaligned_write8");
90 void __tsan_acquire(void *addr
) {
91 Acquire(cur_thread(), CALLERPC
, (uptr
)addr
);
94 void __tsan_release(void *addr
) {
95 Release(cur_thread(), CALLERPC
, (uptr
)addr
);