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_flush_memory() {
33 void __tsan_read16(void *addr
) {
34 MemoryRead(cur_thread(), CALLERPC
, (uptr
)addr
, kSizeLog8
);
35 MemoryRead(cur_thread(), CALLERPC
, (uptr
)addr
+ 8, kSizeLog8
);
38 void __tsan_write16(void *addr
) {
39 MemoryWrite(cur_thread(), CALLERPC
, (uptr
)addr
, kSizeLog8
);
40 MemoryWrite(cur_thread(), CALLERPC
, (uptr
)addr
+ 8, kSizeLog8
);
43 void __tsan_read16_pc(void *addr
, void *pc
) {
44 MemoryRead(cur_thread(), (uptr
)pc
, (uptr
)addr
, kSizeLog8
);
45 MemoryRead(cur_thread(), (uptr
)pc
, (uptr
)addr
+ 8, kSizeLog8
);
48 void __tsan_write16_pc(void *addr
, void *pc
) {
49 MemoryWrite(cur_thread(), (uptr
)pc
, (uptr
)addr
, kSizeLog8
);
50 MemoryWrite(cur_thread(), (uptr
)pc
, (uptr
)addr
+ 8, kSizeLog8
);
53 // __tsan_unaligned_read/write calls are emitted by compiler.
55 void __tsan_unaligned_read2(const void *addr
) {
56 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 2, false, false);
59 void __tsan_unaligned_read4(const void *addr
) {
60 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 4, false, false);
63 void __tsan_unaligned_read8(const void *addr
) {
64 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 8, false, false);
67 void __tsan_unaligned_read16(const void *addr
) {
68 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 16, false, false);
71 void __tsan_unaligned_write2(void *addr
) {
72 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 2, true, false);
75 void __tsan_unaligned_write4(void *addr
) {
76 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 4, true, false);
79 void __tsan_unaligned_write8(void *addr
) {
80 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 8, true, false);
83 void __tsan_unaligned_write16(void *addr
) {
84 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 16, true, false);
87 // __sanitizer_unaligned_load/store are for user instrumentation.
90 SANITIZER_INTERFACE_ATTRIBUTE
91 u16
__sanitizer_unaligned_load16(const uu16
*addr
) {
92 __tsan_unaligned_read2(addr
);
96 SANITIZER_INTERFACE_ATTRIBUTE
97 u32
__sanitizer_unaligned_load32(const uu32
*addr
) {
98 __tsan_unaligned_read4(addr
);
102 SANITIZER_INTERFACE_ATTRIBUTE
103 u64
__sanitizer_unaligned_load64(const uu64
*addr
) {
104 __tsan_unaligned_read8(addr
);
108 SANITIZER_INTERFACE_ATTRIBUTE
109 void __sanitizer_unaligned_store16(uu16
*addr
, u16 v
) {
110 __tsan_unaligned_write2(addr
);
114 SANITIZER_INTERFACE_ATTRIBUTE
115 void __sanitizer_unaligned_store32(uu32
*addr
, u32 v
) {
116 __tsan_unaligned_write4(addr
);
120 SANITIZER_INTERFACE_ATTRIBUTE
121 void __sanitizer_unaligned_store64(uu64
*addr
, u64 v
) {
122 __tsan_unaligned_write8(addr
);
127 void __tsan_acquire(void *addr
) {
128 Acquire(cur_thread(), CALLERPC
, (uptr
)addr
);
131 void __tsan_release(void *addr
) {
132 Release(cur_thread(), CALLERPC
, (uptr
)addr
);