Fix dbgshim race conditions
authorMike McLaughlin <mikem@microsoft.com>
Wed, 13 Apr 2016 20:42:51 +0000 (13:42 -0700)
committerMike McLaughlin <mikem@microsoft.com>
Thu, 21 Apr 2016 18:17:40 +0000 (11:17 -0700)
commitb7d76075a8d2321c14fc4b0a761d24c56621d078
treece553f1a694f6b2ba801c0330463ae73268bd366
parent07b9876d1590ee7404dca1bf70dfd71d50ba5758
Fix dbgshim race conditions

There are two race conditions in the register runtime startup logic: 1) in
CreateProcess (or CreateProcessForLaunch) between the fork() and the execv()
where for VS and mdbg we "see" the coreclr module loaded because the debugger
process and newly created child have the same modules loaded. 2) in attach
between when the child/debuggee loads the coreclr module and when coreclr
finishes initializes the global dac table. In both causes DebugActiveProcess
returns an error when one of the race conditions is hit.

The fix is to create the "continue" named semaphore on the coreclr/debuggee
process side and dbgshim uses that to determine if the coreclr process is
ready and initialized. Fixes issue #4244.

Open the old continue semaphore name and if it doesn't exists create a the new
continue semaphore name for backwards compatibility (see issue 4410).

Do PAL initalization on entry to the public functions instead of the DLLMain handler
which will only be called if the PAL's LoadLibrary is used to load dbgshim. It will be
a lot easier on the debuggers like mdbg to just use dlopen/dlsym and not have to
also call DLLMain.
src/dlls/dbgshim/dbgshim.cpp
src/pal/src/thread/process.cpp