diff options
Diffstat (limited to 'src/dlls/dbgshim')
-rw-r--r-- | src/dlls/dbgshim/dbgshim.cpp | 63 | ||||
-rw-r--r-- | src/dlls/dbgshim/dbgshim.targets | 94 | ||||
-rw-r--r-- | src/dlls/dbgshim/dirs.proj | 19 |
3 files changed, 52 insertions, 124 deletions
diff --git a/src/dlls/dbgshim/dbgshim.cpp b/src/dlls/dbgshim/dbgshim.cpp index aeee778543..5f15cabe97 100644 --- a/src/dlls/dbgshim/dbgshim.cpp +++ b/src/dlls/dbgshim/dbgshim.cpp @@ -387,6 +387,19 @@ public: return hr; } + bool AreAllHandlesValid(HANDLE *handleArray, DWORD arrayLength) + { + for (int i = 0; i < (int)arrayLength; i++) + { + HANDLE h = handleArray[i]; + if (h == INVALID_HANDLE_VALUE) + { + return false; + } + } + return true; + } + HRESULT InternalEnumerateCLRs(HANDLE** ppHandleArray, _In_reads_(*pdwArrayLength) LPWSTR** ppStringArray, DWORD* pdwArrayLength) { int numTries = 0; @@ -394,18 +407,46 @@ public: while (numTries < 25) { + hr = EnumerateCLRs(m_processId, ppHandleArray, ppStringArray, pdwArrayLength); + // EnumerateCLRs uses the OS API CreateToolhelp32Snapshot which can return ERROR_BAD_LENGTH or // ERROR_PARTIAL_COPY. If we get either of those, we try wait 1/10th of a second try again (that - // is the recommendation of the OS API owners) - hr = EnumerateCLRs(m_processId, ppHandleArray, ppStringArray, pdwArrayLength); + // is the recommendation of the OS API owners). if ((hr != HRESULT_FROM_WIN32(ERROR_PARTIAL_COPY)) && (hr != HRESULT_FROM_WIN32(ERROR_BAD_LENGTH))) { - break; + // Just return any other error or if no handles were found (which means the coreclr module wasn't found yet). + if (FAILED(hr) || *ppHandleArray == NULL || *pdwArrayLength <= 0) + { + return hr; + } + // If EnumerateCLRs succeeded but any of the handles are INVALID_HANDLE_VALUE, then sleep and retry + // also. This fixes a race condition where dbgshim catches the coreclr module just being loaded but + // before g_hContinueStartupEvent has been initialized. + if (AreAllHandlesValid(*ppHandleArray, *pdwArrayLength)) + { + return hr; + } + // Clean up memory allocated in EnumerateCLRs since this path it succeeded + CloseCLREnumeration(*ppHandleArray, *ppStringArray, *pdwArrayLength); + + *ppHandleArray = NULL; + *ppStringArray = NULL; + *pdwArrayLength = 0; } + + // Sleep and retry enumerating the runtimes Sleep(100); numTries++; + + if (m_canceled) + { + break; + } } + // Indicate a timeout + hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT); + return hr; } @@ -517,9 +558,8 @@ public: bool coreclrExists = false; HRESULT hr = InvokeStartupCallback(&coreclrExists); - // Because the target process is suspended on create, the toolhelp apis fail with the below errors even - // with the retry logic in InternalEnumerateCLRs. - if (SUCCEEDED(hr) || (hr == HRESULT_FROM_WIN32(ERROR_PARTIAL_COPY)) || (hr == HRESULT_FROM_WIN32(ERROR_BAD_LENGTH))) + // The retry logic in InternalEnumerateCLRs failed if ERROR_TIMEOUT was returned. + if (SUCCEEDED(hr) || (hr == HRESULT_FROM_WIN32(ERROR_TIMEOUT))) { if (!coreclrExists && !m_canceled) { @@ -531,8 +571,11 @@ public: hr = InvokeStartupCallback(&coreclrExists); if (SUCCEEDED(hr)) { - // We should always find a coreclr module - _ASSERTE(coreclrExists); + // We should always find a coreclr module so fail if we don't + if (!coreclrExists) + { + hr = E_FAIL; + } } } } @@ -1120,8 +1163,6 @@ EnumerateCLRs( HANDLE hContinueStartupEvent = INVALID_HANDLE_VALUE; HRESULT hr = GetContinueStartupEvent(debuggeePID, pStringArray[idx], &hContinueStartupEvent); - _ASSERTE(SUCCEEDED(hr) == (hContinueStartupEvent != INVALID_HANDLE_VALUE)); - pEventArray[idx] = hContinueStartupEvent; #else pEventArray[idx] = NULL; @@ -1729,7 +1770,7 @@ GetContinueStartupEvent( ThrowHR(E_FAIL); } - if (NULL != continueEvent) + if (NULL != continueEvent && INVALID_HANDLE_VALUE != continueEvent) { if (!DuplicateHandle(hProcess, continueEvent, GetCurrentProcess(), &continueEvent, EVENT_MODIFY_STATE, FALSE, 0)) diff --git a/src/dlls/dbgshim/dbgshim.targets b/src/dlls/dbgshim/dbgshim.targets deleted file mode 100644 index 8332befa5a..0000000000 --- a/src/dlls/dbgshim/dbgshim.targets +++ /dev/null @@ -1,94 +0,0 @@ -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="dogfood"> - - <Import Project="$(_NTDRIVE)$(_NTROOT)\ndp\clr\xplat\utility.props"/> - <PropertyGroup> - <LinkUseCMT>true</LinkUseCMT> - <UserIncludes> - $(UserIncludes); - ..\; - $(VCToolsIncPath); - $(Clrbase)\src\Debug\shim; - </UserIncludes> - <OutputName>dbgshim</OutputName> - <TargetType>DYNLINK</TargetType> - <LinkSubsystem>windows</LinkSubsystem> - <CDefines>$(CDefines);UNICODE;_UNICODE;FEATURE_NO_HOST;SELF_NO_HOST</CDefines> - <DllDef>..\dbgshim.ntdef</DllDef> - <DllEntryPoint>_DllMainCRTStartup</DllEntryPoint> - <ExtDelayImpLib >false</ExtDelayImpLib> - <UseMsvcrt>false</UseMsvcrt> - <NoLinkGdi32>true</NoLinkGdi32> - </PropertyGroup> - - <PropertyGroup Condition="'$(HostMachineOS)' == 'windows'"> - <LinkDelayLoad Condition="'$(LinkDelayLoad)'!=''">$(LinkDelayLoad);</LinkDelayLoad> - <LinkDelayLoad>$(LinkDelayLoad)user32.dll;advapi32.dll;oleaut32.dll</LinkDelayLoad> - </PropertyGroup> - - <ItemGroup> - <LinkPreCrtLibs Include="$(ClrLibPath)\utilcodestaticnohost$(XPlatHostLibSuffix).lib" > - <!-- This project isn't factored like the others... there are many projects pointing to the current path of corguids --> - <ProjectReference Condition="'$(XPlatHostLibBuildDir)'=='HostLocal'">$(ClrSrcDirectory)utilcode\staticnohost\staticnohost.nativeproj</ProjectReference> - <ProjectReference Condition="'$(XPlatHostLibBuildDir)'=='HostWinx86'">$(ClrSrcDirectory)utilcode\staticnohostx86\staticnohost.nativeproj</ProjectReference> - <ProjectReference Condition="'$(XPlatHostLibBuildDir)'=='HostWinAMD64'">$(ClrSrcDirectory)utilcode\staticnohostamd64\staticnohost.nativeproj</ProjectReference> - </LinkPreCrtLibs> - </ItemGroup> - <ItemGroup> - <!-- This lib differs between Win32 and CoreSys, so I am specifically using XPlatHostSuffix, not XPlatHostLibSuffix --> - <!-- In retrospect the naming on those props aren't great, but I don't want to undo all the testing already done on this change - with potential errors refactoring to a new prop name. XPlatHostLibSuffix only varies on architecture whereas XPlatHostSuffix - varies on arch and OS --> - <TargetLib Include="$(ClrLibPath)\debugshim$(XPlatHostSuffix).lib" /> - <ProjectReference Include="$(ClrSrcDirectory)\Debug\shim\$(XPlatHostBuildDir)\debugshim.nativeproj" /> - <TargetLib Include="$(ClrLibPath)\dbgutil$(XPlatHostLibSuffix).lib" /> - <ProjectReference Include="$(ClrSrcDirectory)\Debug\dbgutil\$(XPlatHostLibBuildDir)\dbgutil.nativeproj" /> - </ItemGroup> - <ItemGroup Condition="'$(HostMachineOS)' == 'windows'"> - <TargetLib Include="$(ClrLibPath)\CorGUIDS$(XPlatHostLibSuffix).lib"> - <!-- This project isn't factored like the others... there are many projects pointing to the current path of corguids --> - <ProjectReference Condition="'$(XPlatHostLibBuildDir)'=='HostLocal'">$(ClrSrcDirectory)inc\corguids.nativeproj</ProjectReference> - <ProjectReference Condition="'$(XPlatHostLibBuildDir)'=='HostWinx86'">$(ClrSrcDirectory)incx86\corguids.nativeproj</ProjectReference> - <ProjectReference Condition="'$(XPlatHostLibBuildDir)'=='HostWinAMD64'">$(ClrSrcDirectory)incamd64\corguids.nativeproj</ProjectReference> - </TargetLib> - <Targetlib Include="$(SdkLibPath)\kernel32.lib" /> - <Targetlib Include="$(CrtLibPath)\libcmt$(BuildSuffix).lib" /> - <Targetlib Include="$(SdkLibPath)\uuid.lib" /> - <Targetlib Include="$(SdkLibPath)\user32.lib" /> - <Targetlib Include="$(SdkLibPath)\advapi32.lib" /> - <Targetlib Include="$(SdkLibPath)\oleaut32.lib" /> - <Targetlib Include="$(SdkLibPath)\WtsApi32.lib" /> - <Targetlib Include="$(SdkLibPath)\version.lib" /> - <Targetlib Include="$(SdkLibPath)\psapi.lib" /> - </ItemGroup> - <ItemGroup Condition="'$(HostMachineOS)' == 'OneCore' or '$(HostMachineOS)'=='OneCoreWin7Compat'"> - <TargetLib Include="$(CoreSystemCrt)" /> - <TargetLib Include="$(SdkLibPath)\uuid.lib" /> - </ItemGroup> - <ItemGroup Condition="'$(HostMachineOS)' == 'OneCoreWin7Compat'"> - <TargetLib Include="$(SdkLibPath)\bcrypt.lib" /> - <TargetLib Include="$(SdkLibPath)\crypt32.lib" /> - <TargetLib Include="$(SdkLibPath)\oleaut32.lib" /> - <TargetLib Include="$(SdkLibPath)\mincore_fw.lib" /> - </ItemGroup> - <ItemGroup Condition="'$(HostMachineOS)' == 'OneCore'"> - <TargetLib Include="$(SdkLibPath)\mincore.lib" /> - <TargetLib Include="$(SdkLibPath)\mincore_legacy.lib" /> - <TargetLib Include="$(SdkLibPath)\mincore_private.lib" /> - <TargetLib Include="$(SdkLibPath)\mincore_obsolete.lib" /> - </ItemGroup> - - <ItemGroup> - <RCResourceFile Include="..\dbgshim.rc" /> - </ItemGroup> - - <ItemGroup> - <CppCompile Include="..\dbgshim.cpp" /> - </ItemGroup> - - <ItemGroup> - <DataFile Include="..\dbgshim.h" /> - </ItemGroup> - - <Import Project="$(_NTDRIVE)$(_NTROOT)\ndp\clr\clr.targets" /> - -</Project> diff --git a/src/dlls/dbgshim/dirs.proj b/src/dlls/dbgshim/dirs.proj deleted file mode 100644 index dc91ac22f0..0000000000 --- a/src/dlls/dbgshim/dirs.proj +++ /dev/null @@ -1,19 +0,0 @@ -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(_NTDRIVE)$(_NTROOT)\ndp\clr\clr.props" /> - - <PropertyGroup> - <BuildCoreBinaries>true</BuildCoreBinaries> - <BuildSysBinaries>true</BuildSysBinaries> - </PropertyGroup> - - <!--The following projects will build during the CoreCLR build--> - <ItemGroup Condition="'$(FeatureCoreclr)' == 'true'"> - <ProjectFile Include="HostLocal\dbgshim.nativeproj" /> - <ProjectFile Include="HostWinx86\dbgshim.nativeproj" Condition="'$(BuildArchitecture)'=='i386'" /> - <ProjectFile Include="HostWinamd64\dbgshim.nativeproj" Condition="'$(BuildArchitecture)'=='amd64'" /> - <ProjectFile Include="HostOneCorex86\dbgshim.nativeproj" Condition="'$(BuildArchitecture)'=='i386'" /> - <ProjectFile Include="HostOneCoreamd64\dbgshim.nativeproj" Condition="'$(BuildArchitecture)'=='amd64'" /> - </ItemGroup> - - <Import Project="$(_NTDRIVE)$(_NTROOT)\tools\Microsoft.DevDiv.Traversal.targets" /> -</Project> |