HANG delivering signal that interrupted DR at "safe spot"
As part of 35a6c542 (#2660) for #2659 (closed) I added immediate delivery of a signal at a safe spot, in particular THREAD_SYNCH_NO_LOCKS.
However, this includes signals interrupting DR code. A signal can interrupt a safe spot at its tail end during its call to something like dr_mark_safe_to_suspend() which then calls set_synch_state() which grabs the tsd->synch_lock spinlock before setting the tsd->synch_perm back to an unsafe value. At that interruption point, it is unsafe to deliver a signal, because translate_sigcontext() calls translate_mcontext() which tries to grab tsd->synch_lock and then hangs.
On the one hand, it seems unsafe to deliver a signal when DR was interrupted, period. OTOH, this THREAD_SYNCH_NO_LOCKS is supposed to mean that no locks are held. Is this synch_lock problem limited to a self-interruption? No, it seems like a SIGUSR2 could interrupt another thread and "suspend" it at a similar point where it holds synch_lock, and the synch_with_all_threads code would then hang when it tried to acquire synch_lock.
So the ideal solution is to eliminate this lock being separate from clearing synch_perm, and we can then keep this signal delivery?