is_thread_tls_initialized() fails to distinguish a thread in a new thread group from a fork child
This is the problem, the || part:
return (tid == get_sys_thread_id() ||
/* We assume we can safely de-ref the dcontext now */
/* The child of a fork will initially come here */
os_tls->state.spill_space.dcontext->owning_process ==
get_parent_id());
A thread with CLONE_VM but not CLONE_THREAD will end up with a different thread id but will inherit the parent TLS (for use of MSR anyway where the zeroing of TLS_SEG has no effect: we plan to remove that zeroing anyway in #2088). It will pass is_thread_tls_initialized() which will wreak all kinds of havoc as it shares its parent's dcontext, resulting in strange crashes and hangs.
The plan is to redesign how is_thread_tls_initialized() works from the ground up. Xref #1986 (closed) and other cases where is_thread_tls_initialized() is also just not good enough.