1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//
5// ProfDetach.h
6//
7
8//
9// Declaration of helper classes and structures used for Profiling API Detaching
10//
11// ======================================================================================
12
13#ifndef __PROFDETACH_H__
14#define __PROFDETACH_H__
15
16#ifdef FEATURE_PROFAPI_ATTACH_DETACH
17
18// The struct below is the medium by which RequestProfilerDetach communicates with
19// the DetachThread about a profiler being detached. Initial core attach /
20// detach feature crew will have only one global instance of this struct.
21// When we allow re-attach with neutered profilers, there will likely be a
22// linked list of these, one per profiler in the act of being detached.
23struct ProfilerDetachInfo
24{
25 ProfilerDetachInfo();
26 void Init();
27
28 // NULL if we're not trying to detach a profiler. Otherwise, this is the
29 // EEToProfInterfaceImpl instance we're detaching.
30 //
31 // FUTURE: Although m_pEEToProf, when non-NULL, is always the same as
32 // g_profControlBlock.pProfInterface, that will no longer be the case once we allow
33 // re-attach with neutered profilers.
34 EEToProfInterfaceImpl * m_pEEToProf;
35
36 // Time when profiler originally called RequestProfilerDetach()
37 ULONGLONG m_ui64DetachStartTime;
38
39 // # milliseconds hint profiler specified in RequestProfilerDetach()
40 DWORD m_dwExpectedCompletionMilliseconds;
41};
42
43//--------------------------------------------------------------------------
44// Static-only class to coordinate initialization of the various profiling
45// API detaching structures, plus other utility stuff.
46//
47class ProfilingAPIDetach
48{
49public:
50 static HRESULT Initialize();
51
52 static HRESULT RequestProfilerDetach(DWORD dwExpectedCompletionMilliseconds);
53
54 static HRESULT CreateDetachThread();
55 static DWORD WINAPI ProfilingAPIDetachThreadStart(LPVOID lpParameter);
56 static void ExecuteEvacuationLoop();
57 static BOOL IsProfilerEvacuated();
58
59 static EEToProfInterfaceImpl * GetEEToProfPtr();
60
61private:
62 static ProfilerDetachInfo s_profilerDetachInfo;
63
64 // Signaled by RequestProfilerDetach() when there is detach work ready to be
65 // done by the DetachThread
66 static CLREvent s_eventDetachWorkAvailable;
67
68 static void SleepWhileProfilerEvacuates();
69 static void UnloadProfiler();
70
71 // Prevent instantiation of ProfilingAPIDetach objects (should be static-only)
72 ProfilingAPIDetach();
73 ~ProfilingAPIDetach();
74};
75
76#endif // FEATURE_PROFAPI_ATTACH_DETACH
77
78#endif //__PROFDETACH_H__
79