gcc/
[official-gcc.git] / libsanitizer / tsan / tsan_interface.cc
blobe056bd465bf0c21f3514b09c54e013f121fe0a80
1 //===-- tsan_interface.cc -------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
9 //
10 //===----------------------------------------------------------------------===//
12 #include "tsan_interface.h"
13 #include "tsan_interface_ann.h"
14 #include "tsan_rtl.h"
15 #include "sanitizer_common/sanitizer_internal_defs.h"
17 #define CALLERPC ((uptr)__builtin_return_address(0))
19 using namespace __tsan; // NOLINT
21 typedef u16 uint16_t;
22 typedef u32 uint32_t;
23 typedef u64 uint64_t;
25 void __tsan_init() {
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);
41 return *addr;
44 u32 __tsan_unaligned_read4(const uu32 *addr) {
45 UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 4, false, false);
46 return *addr;
49 u64 __tsan_unaligned_read8(const uu64 *addr) {
50 UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 8, false, false);
51 return *addr;
54 void __tsan_unaligned_write2(uu16 *addr, u16 v) {
55 UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 2, true, false);
56 *addr = v;
59 void __tsan_unaligned_write4(uu32 *addr, u32 v) {
60 UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 4, true, false);
61 *addr = v;
64 void __tsan_unaligned_write8(uu64 *addr, u64 v) {
65 UnalignedMemoryAccess(cur_thread(), CALLERPC, (uptr)addr, 8, true, false);
66 *addr = v;
69 extern "C" {
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);