OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2010, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2010, 2012 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 25 matching lines...) Expand all Loading... | |
36 #include <stdint.h> | 36 #include <stdint.h> |
37 | 37 |
38 #if COMPILER(MSVC) | 38 #if COMPILER(MSVC) |
39 #include <windows.h> | 39 #include <windows.h> |
40 #endif | 40 #endif |
41 | 41 |
42 #if defined(THREAD_SANITIZER) | 42 #if defined(THREAD_SANITIZER) |
43 #include <sanitizer/tsan_interface_atomic.h> | 43 #include <sanitizer/tsan_interface_atomic.h> |
44 #endif | 44 #endif |
45 | 45 |
46 #if defined(ADDRESS_SANITIZER) | |
47 #include <sanitizer/asan_interface.h> | |
48 #endif | |
49 | |
46 namespace WTF { | 50 namespace WTF { |
47 | 51 |
48 #if COMPILER(MSVC) | 52 #if COMPILER(MSVC) |
49 | 53 |
50 // atomicAdd returns the result of the addition. | 54 // atomicAdd returns the result of the addition. |
51 ALWAYS_INLINE int atomicAdd(int volatile* addend, int increment) | 55 ALWAYS_INLINE int atomicAdd(int volatile* addend, int increment) |
52 { | 56 { |
53 return InterlockedExchangeAdd(reinterpret_cast<long volatile*>(addend), stat ic_cast<long>(increment)) + increment; | 57 return InterlockedExchangeAdd(reinterpret_cast<long volatile*>(addend), stat ic_cast<long>(increment)) + increment; |
54 } | 58 } |
55 | 59 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 | 122 |
119 ALWAYS_INLINE void releaseStore(volatile unsigned* ptr, unsigned value) | 123 ALWAYS_INLINE void releaseStore(volatile unsigned* ptr, unsigned value) |
120 { | 124 { |
121 __tsan_atomic32_store(reinterpret_cast<volatile int*>(ptr), static_cast<int> (value), __tsan_memory_order_release); | 125 __tsan_atomic32_store(reinterpret_cast<volatile int*>(ptr), static_cast<int> (value), __tsan_memory_order_release); |
122 } | 126 } |
123 | 127 |
124 ALWAYS_INLINE unsigned acquireLoad(volatile const unsigned* ptr) | 128 ALWAYS_INLINE unsigned acquireLoad(volatile const unsigned* ptr) |
125 { | 129 { |
126 return static_cast<unsigned>(__tsan_atomic32_load(reinterpret_cast<volatile const int*>(ptr), __tsan_memory_order_acquire)); | 130 return static_cast<unsigned>(__tsan_atomic32_load(reinterpret_cast<volatile const int*>(ptr), __tsan_memory_order_acquire)); |
127 } | 131 } |
132 | |
133 #if defined(ADDRESS_SANITIZER) | |
134 | |
135 __attribute__((no_sanitize_address)) ALWAYS_INLINE void asanReleaseStore(volatil e unsigned* ptr, unsigned value) | |
Alexander Potapenko
2014/09/09 09:40:30
This is not gonna work.
ASan doesn't provide the _
Mads Ager (chromium)
2014/09/09 09:51:36
Thanks! Since they can't be defined together in th
| |
136 { | |
137 __tsan_atomic32_store(reinterpret_cast<volatile int*>(ptr), static_cast<int> (value), __tsan_memory_order_release); | |
138 } | |
139 | |
140 __attribute__((no_sanitize_address)) ALWAYS_INLINE unsigned asanAcquireLoad(vola tile const unsigned* ptr) | |
141 { | |
142 return static_cast<unsigned>(__tsan_atomic32_load(reinterpret_cast<volatile const int*>(ptr), __tsan_memory_order_acquire)); | |
143 } | |
144 | |
145 #endif // defined(ADDRESS_SANITIZER) | |
146 | |
128 #else | 147 #else |
129 | 148 |
130 #if CPU(X86) || CPU(X86_64) | 149 #if CPU(X86) || CPU(X86_64) |
131 // Only compiler barrier is needed. | 150 // Only compiler barrier is needed. |
132 #if COMPILER(MSVC) | 151 #if COMPILER(MSVC) |
133 // Starting from Visual Studio 2005 compiler guarantees acquire and release | 152 // Starting from Visual Studio 2005 compiler guarantees acquire and release |
134 // semantics for operations on volatile variables. See MSDN entry for | 153 // semantics for operations on volatile variables. See MSDN entry for |
135 // MemoryBarrier macro. | 154 // MemoryBarrier macro. |
136 #define MEMORY_BARRIER() | 155 #define MEMORY_BARRIER() |
137 #else | 156 #else |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 *ptr = value; | 191 *ptr = value; |
173 } | 192 } |
174 | 193 |
175 ALWAYS_INLINE unsigned acquireLoad(volatile const unsigned* ptr) | 194 ALWAYS_INLINE unsigned acquireLoad(volatile const unsigned* ptr) |
176 { | 195 { |
177 unsigned value = *ptr; | 196 unsigned value = *ptr; |
178 MEMORY_BARRIER(); | 197 MEMORY_BARRIER(); |
179 return value; | 198 return value; |
180 } | 199 } |
181 | 200 |
201 #if defined(ADDRESS_SANITIZER) | |
202 | |
203 __attribute__((no_sanitize_address)) ALWAYS_INLINE void asanReleaseStore(volatil e unsigned* ptr, unsigned value) | |
204 { | |
205 MEMORY_BARRIER(); | |
206 *ptr = value; | |
207 } | |
208 | |
209 __attribute__((no_sanitize_address)) ALWAYS_INLINE unsigned asanAcquireLoad(vola tile const unsigned* ptr) | |
210 { | |
211 unsigned value = *ptr; | |
212 MEMORY_BARRIER(); | |
213 return value; | |
214 } | |
215 | |
216 #endif // defined(ADDRESS_SANITIZER) | |
217 | |
182 #undef MEMORY_BARRIER | 218 #undef MEMORY_BARRIER |
183 | 219 |
184 #endif | 220 #endif |
185 | 221 |
222 #if !defined(ADDRESS_SANITIZER) | |
223 | |
224 ALWAYS_INLINE void asanReleaseStore(volatile unsigned* ptr, unsigned value) | |
225 { | |
226 releaseStore(ptr, value); | |
227 } | |
228 | |
229 ALWAYS_INLINE unsigned asanAcquireLoad(volatile const unsigned* ptr) | |
230 { | |
231 return acquireLoad(ptr); | |
232 } | |
233 | |
234 #endif | |
235 | |
186 } // namespace WTF | 236 } // namespace WTF |
187 | 237 |
188 using WTF::atomicAdd; | 238 using WTF::atomicAdd; |
189 using WTF::atomicSubtract; | 239 using WTF::atomicSubtract; |
190 using WTF::atomicDecrement; | 240 using WTF::atomicDecrement; |
191 using WTF::atomicIncrement; | 241 using WTF::atomicIncrement; |
192 using WTF::atomicTestAndSetToOne; | 242 using WTF::atomicTestAndSetToOne; |
193 using WTF::atomicSetOneToZero; | 243 using WTF::atomicSetOneToZero; |
194 using WTF::acquireLoad; | 244 using WTF::acquireLoad; |
195 using WTF::releaseStore; | 245 using WTF::releaseStore; |
196 | 246 |
247 // These methods allow loading from and storing to poisoned memory. Only | |
248 // use these methods if you know what you are doing since they will | |
249 // silence use-after-poison errors from ASan. | |
250 using WTF::asanAcquireLoad; | |
251 using WTF::asanReleaseStore; | |
252 | |
197 #endif // Atomics_h | 253 #endif // Atomics_h |
OLD | NEW |