[Ada] Fix assertion failure on pragma Compile_Time_Error in generic unit
[official-gcc.git] / libsanitizer / tsan / tsan_interface.cc
blobd98ff15f56258cf4d99bc770be17e10a7d78eb38
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_flush_memory() {
30 FlushShadowMemory();
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.
89 extern "C" {
90 SANITIZER_INTERFACE_ATTRIBUTE
91 u16 __sanitizer_unaligned_load16(const uu16 *addr) {
92 __tsan_unaligned_read2(addr);
93 return *addr;
96 SANITIZER_INTERFACE_ATTRIBUTE
97 u32 __sanitizer_unaligned_load32(const uu32 *addr) {
98 __tsan_unaligned_read4(addr);
99 return *addr;
102 SANITIZER_INTERFACE_ATTRIBUTE
103 u64 __sanitizer_unaligned_load64(const uu64 *addr) {
104 __tsan_unaligned_read8(addr);
105 return *addr;
108 SANITIZER_INTERFACE_ATTRIBUTE
109 void __sanitizer_unaligned_store16(uu16 *addr, u16 v) {
110 __tsan_unaligned_write2(addr);
111 *addr = v;
114 SANITIZER_INTERFACE_ATTRIBUTE
115 void __sanitizer_unaligned_store32(uu32 *addr, u32 v) {
116 __tsan_unaligned_write4(addr);
117 *addr = v;
120 SANITIZER_INTERFACE_ATTRIBUTE
121 void __sanitizer_unaligned_store64(uu64 *addr, u64 v) {
122 __tsan_unaligned_write8(addr);
123 *addr = v;
125 } // extern "C"
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);