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 void __tsan_read16_pc(void *addr
, void *pc
) {
40 MemoryRead(cur_thread(), (uptr
)pc
, (uptr
)addr
, kSizeLog8
);
41 MemoryRead(cur_thread(), (uptr
)pc
, (uptr
)addr
+ 8, kSizeLog8
);
44 void __tsan_write16_pc(void *addr
, void *pc
) {
45 MemoryWrite(cur_thread(), (uptr
)pc
, (uptr
)addr
, kSizeLog8
);
46 MemoryWrite(cur_thread(), (uptr
)pc
, (uptr
)addr
+ 8, kSizeLog8
);
49 // __tsan_unaligned_read/write calls are emitted by compiler.
51 void __tsan_unaligned_read2(const void *addr
) {
52 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 2, false, false);
55 void __tsan_unaligned_read4(const void *addr
) {
56 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 4, false, false);
59 void __tsan_unaligned_read8(const void *addr
) {
60 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 8, false, false);
63 void __tsan_unaligned_read16(const void *addr
) {
64 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 16, false, false);
67 void __tsan_unaligned_write2(void *addr
) {
68 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 2, true, false);
71 void __tsan_unaligned_write4(void *addr
) {
72 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 4, true, false);
75 void __tsan_unaligned_write8(void *addr
) {
76 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 8, true, false);
79 void __tsan_unaligned_write16(void *addr
) {
80 UnalignedMemoryAccess(cur_thread(), CALLERPC
, (uptr
)addr
, 16, true, false);
83 // __sanitizer_unaligned_load/store are for user instrumentation.
86 SANITIZER_INTERFACE_ATTRIBUTE
87 u16
__sanitizer_unaligned_load16(const uu16
*addr
) {
88 __tsan_unaligned_read2(addr
);
92 SANITIZER_INTERFACE_ATTRIBUTE
93 u32
__sanitizer_unaligned_load32(const uu32
*addr
) {
94 __tsan_unaligned_read4(addr
);
98 SANITIZER_INTERFACE_ATTRIBUTE
99 u64
__sanitizer_unaligned_load64(const uu64
*addr
) {
100 __tsan_unaligned_read8(addr
);
104 SANITIZER_INTERFACE_ATTRIBUTE
105 void __sanitizer_unaligned_store16(uu16
*addr
, u16 v
) {
106 __tsan_unaligned_write2(addr
);
110 SANITIZER_INTERFACE_ATTRIBUTE
111 void __sanitizer_unaligned_store32(uu32
*addr
, u32 v
) {
112 __tsan_unaligned_write4(addr
);
116 SANITIZER_INTERFACE_ATTRIBUTE
117 void __sanitizer_unaligned_store64(uu64
*addr
, u64 v
) {
118 __tsan_unaligned_write8(addr
);
123 void __tsan_acquire(void *addr
) {
124 Acquire(cur_thread(), CALLERPC
, (uptr
)addr
);
127 void __tsan_release(void *addr
) {
128 Release(cur_thread(), CALLERPC
, (uptr
)addr
);