Mark the profiler attach thread during attach
authorDavid Mason <davmason@microsoft.com>
Fri, 21 Jun 2019 09:20:57 +0000 (02:20 -0700)
committerGitHub <noreply@github.com>
Fri, 21 Jun 2019 09:20:57 +0000 (02:20 -0700)
src/vm/profilerdiagnosticprotocolhelper.cpp

index 3f81b51..3f96912 100644 (file)
@@ -102,12 +102,23 @@ void ProfilerDiagnosticProtocolHelper::AttachProfiler(DiagnosticsIpc::IpcMessage
         hr = CORPROF_E_RUNTIME_UNINITIALIZED;
         goto ErrExit;
     }
+    
+    // Certain actions are only allowable during attach, and this flag is how we track it.
+    ClrFlsSetThreadType(ThreadType_ProfAPI_Attach);
+
+    EX_TRY
+    {
+        hr = ProfilingAPIUtility::LoadProfilerForAttach(&payload->profilerGuid,
+                                                        payload->pwszProfilerPath,
+                                                        payload->pClientData,
+                                                        payload->cbClientData,
+                                                        payload->dwAttachTimeout);
+    }
+    EX_CATCH_HRESULT(hr);
+
+    // Clear the flag so this thread isn't permanently marked as the attach thread.
+    ClrFlsClearThreadType(ThreadType_ProfAPI_Attach);
 
-    hr = ProfilingAPIUtility::LoadProfilerForAttach(&payload->profilerGuid,
-                                                    payload->pwszProfilerPath,
-                                                    payload->pClientData,
-                                                    payload->cbClientData,
-                                                    payload->dwAttachTimeout);
 ErrExit:
     if (hr != S_OK)
     {