[PATCH] D72549: [TSan] Register threads created via pthread_create_from_mach_thread

Julian Lettner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 18:09:33 PST 2020


yln created this revision.
Herald added subscribers: llvm-commits, Sanitizers, jfb.
Herald added projects: Sanitizers, LLVM.

Previously, TSan was crashing on the first call into the runtime from
any thread created via `pthread_create_from_mach_thread` SPI.  These
threads were uninitialized, because TSan could not observe their
creation.  This meant that TSan crashed for Xcode's SwiftUI preview
(which uses remote code injection).

Threads created via `pthread_create_from_mach_thread` bypass the
`pthread_create` interceptor / `__tsan_thread_start_func thread`
function wrapper that usually ensures that threads are properly
registered.  In addition, we don't receive THREAD_CREATE/DESTROY events
in our pthread introspection hooks.  The reason for this is that those
would run in the context of the parent mach thread which makes them not
very useful.

Adding an interceptor for this SPI is not sufficient; it is typically
looked up in the parent process and then marshalled into the
instrumented process.

This change uses the following strategy to register these threads.  For
the THREAD_CREATE event, we attach enough information to the thread that
is being created so that in THREAD_START we can identify how the thread
that we are on was actually created.  For regular threads and GCD
workers there will be identifying information, for "special" threads
(threads for which we are unable to observe creation, e.g., threads
created via `pthread_create_from_mach_thread` from a Mach thread) the
absence of this information lets us infer that they are special.

rdar://57269889


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72549

Files:
  compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
  compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
  compiler-rt/lib/tsan/rtl/tsan_rtl.h
  compiler-rt/test/tsan/Darwin/mach-thread.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72549.237468.patch
Type: text/x-patch
Size: 11140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200111/5173c1b2/attachment.bin>


More information about the llvm-commits mailing list