[PATCH] D40262: Correct NetBSD support in pthread_once(3)/TSan
Kamil Rytarowski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 12:11:57 PST 2017
krytarowski created this revision.
krytarowski added a project: Sanitizers.
Herald added a subscriber: kubamracek.
The pthread_once(3)/NetBSD type is built with the following structure:
struct __pthread_once_st {
pthread_mutex_t pto_mutex;
int pto_done;
};
Set the pto_done position as shifted by __sanitizer::pthread_t_sz
from the beginning of the pthread_once struct.
This corrects deadlocks when the pthread_once(3) function
is used.
While there, switch if(SANITIZER_OS) constructs to ifdefs for simplicity.
Sponsored by <The NetBSD Foundation>
Repository:
rL LLVM
https://reviews.llvm.org/D40262
Files:
lib/tsan/rtl/tsan_interceptors.cc
Index: lib/tsan/rtl/tsan_interceptors.cc
===================================================================
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -1354,10 +1354,16 @@
if (o == 0 || f == 0)
return errno_EINVAL;
atomic_uint32_t *a;
- if (!SANITIZER_MAC)
- a = static_cast<atomic_uint32_t*>(o);
- else // On OS X, pthread_once_t has a header with a long-sized signature.
- a = static_cast<atomic_uint32_t*>((void *)((char *)o + sizeof(long_t)));
+
+#if SANITIZER_MAC
+ a = static_cast<atomic_uint32_t*>((void *)((char *)o + sizeof(long_t)));
+#elif SANITIZER_NETBSD
+ a = static_cast<atomic_uint32_t*>
+ ((void *)((char *)o + __sanitizer::pthread_t_sz));
+#else
+ a = static_cast<atomic_uint32_t*>(o);
+#endif
+
u32 v = atomic_load(a, memory_order_acquire);
if (v == 0 && atomic_compare_exchange_strong(a, &v, 1,
memory_order_relaxed)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40262.123630.patch
Type: text/x-patch
Size: 961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171120/99340281/attachment.bin>
More information about the llvm-commits
mailing list