Merge pull request #14619 from briansull/emitter-cleanup
[platform/upstream/coreclr.git] / src / vm / profattachclient.h
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 // ProfAttachClient.h
6 // 
7
8 // 
9 // Definition of ProfilingAPIAttachClient, which houses the prime portion of the
10 // implementation of the AttachProfiler() API, exported by mscoree.dll, and consumed by
11 // trigger processes in order to force the runtime of a target process to load a
12 // profiler. This handles opening a client connection to the pipe created by the target
13 // profilee, and sending requests across that pipe to force the target profilee (which
14 // acts as the pipe server) to attach a profiler.
15 // 
16
17 // ======================================================================================
18
19 #ifndef __PROF_ATTACH_CLIENT_H__
20 #define __PROF_ATTACH_CLIENT_H__
21
22 #ifdef FEATURE_PROFAPI_ATTACH_DETACH
23 extern "C" HRESULT STDMETHODCALLTYPE AttachProfiler(
24     DWORD dwProfileeProcessID,
25     DWORD dwMillisecondsMax,
26     const CLSID * pClsidProfiler,
27     LPCWSTR wszProfilerPath,
28     void * pvClientData,
29     UINT cbClientData,
30     LPCWSTR wszRuntimeVersion);
31 #endif // FEATURE_PROFAPI_ATTACH_DETACH
32 // ---------------------------------------------------------------------------------------
33 // Here's the beef. All the pipe client stuff running in the trigger process (via call to
34 // AttachProfiler()) is housed in this class. Note that these functions cannot assume a
35 // fully initialized runtime (e.g., it would be nonsensical for these functions to
36 // reference ProfilingAPIAttachDetach::s_hAttachEvent). These functions operate solely by
37 // finding the attach event & pipes by name, and using them to communicate with the
38 // target profilee app.
39
40 class ProfilingAPIAttachClient
41 {
42 public:
43     HRESULT AttachProfiler(
44         DWORD dwProfileeProcessID,
45         DWORD dwMillisecondsMax,
46         const CLSID * pClsidProfiler,
47         LPCWSTR wszProfilerPath,
48         void * pvClientData,
49         UINT cbClientData,
50         LPCWSTR wszRuntimeVersion);
51
52 protected:
53     // Client connection to the pipe that connects to the target profilee (server)
54     HandleHolder m_hPipeClient;
55
56     BOOL MightProcessExist(DWORD dwProcessID);
57     HRESULT SignalAttachEvent(LPCWSTR wszEventName);
58     HRESULT OpenPipeClient(
59         LPCWSTR wszPipeName,
60         DWORD dwMillisecondsMax);
61     HRESULT VerifyVersionIsCompatible(DWORD dwMillisecondsMax);
62     HRESULT SendAttachRequest(
63         DWORD dwMillisecondsMax, 
64         const CLSID * pClsidProfiler,
65         LPCWSTR wszProfilerPath,
66         void * pvClientData,
67         UINT cbClientData,
68         HRESULT * phrAttach);
69     HRESULT SendAndReceive(
70         DWORD dwMillisecondsMax,
71         LPVOID pvInBuffer,
72         DWORD cbInBuffer,
73         LPVOID pvOutBuffer,
74         DWORD cbOutBuffer,
75         DWORD * pcbReceived);
76 };
77
78 #endif //__PROF_ATTACH_CLIENT_H__