summaryrefslogtreecommitdiff
path: root/src/inc/ipcmanagerinterface.h
blob: ef71371273c30f3b0f91d965a275742c7cb27fcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//*****************************************************************************
// File: IPCManagerInterface.h
//
// Interface for InterProcess Communication with a COM+ process.
//
//*****************************************************************************


#ifndef _IPCMANAGERINTERFACE_H_
#define _IPCMANAGERINTERFACE_H_

#include "../ipcman/ipcheader.h"

struct PerfCounterIPCControlBlock;
struct AppDomainEnumerationIPCBlock;

#include "../ipcman/ipcmanagerimpl.h"

// These are the right that we will give to the global section and global events used
// in communicating between debugger and debugee
//
// SECTION_ALL_ACCESS is needed for the IPC block. Unfortunately, we DACL our events and
// IPC block identically. Or this particular right does not need to bleed into here. 
//
#define CLR_IPC_GENERIC_RIGHT (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | STANDARD_RIGHTS_ALL | SECTION_ALL_ACCESS)

//-----------------------------------------------------------------------------
// Writer - create a COM+ IPC Block with security attributes.
//-----------------------------------------------------------------------------
class IPCWriterInterface : public IPCWriterImpl
{
public:

    BOOL TryAllocBlock(DWORD numRetries);
    BOOL TryFreeBlock();

    //.............................................................................
    // Creation / Destruction only on implementation
    //.............................................................................
    HRESULT Init();
    void Terminate();

    //.............................................................................
    // Marks the data in the IPC block as initialized
    //.............................................................................
    void Publish();

    //.............................................................................
    // Accessor for the Perf block
    //.............................................................................
    PerfCounterIPCControlBlock * GetPerfBlock();
    
	void DestroySecurityAttributes(SECURITY_ATTRIBUTES *pSA);

#ifndef DACCESS_COMPILE

    //.............................................................................
    // Create the SxS Public IPC block. 
    //.............................................................................
    HRESULT CreateSxSPublicBlockOnPid(DWORD PID);

    //.............................................................................
    // Open the SxS Public IPC block that has alread been created.
    //.............................................................................
    HRESULT OpenSxSPublicBlockOnPid(DWORD PID);

    HRESULT GetSxSPublicSecurityAttributes(DWORD pid, SECURITY_ATTRIBUTES **ppSA);    

#endif 

    DWORD       GetBlockTableSize();
    PTR_VOID    GetBlockTableStart();

    /*********************************** LEGACY FUNCTIONS ***********************************
     *
     *  Though newer versions of the runtime do not open the LegacyPrivate block or the LegacyPublic
     *  block, we need functionality in the reader to inspect the LegacyPrivate block and LegacyPublic
     *  block so reading data from older runtimes.
     *
     ****************************************************************************************/

    //.............................................................................
    // The AppDomain block resides within the LegacyPrivate IPC block. 
    //.............................................................................
    AppDomainEnumerationIPCBlock * GetAppDomainBlock();
    
    //.............................................................................
    // Create the LegacyPrivate IPC block. If this fails because the IPC block has already been
    // created by another module then the phInstIPCBlockOwner argument will be set to the
    // HINSTANCE of the module that created the IPC block.
    // Set inService to TRUE if creating from within a service on behalf of a process.
    //.............................................................................
    HRESULT CreateLegacyPrivateBlockTempV4OnPid(DWORD PID, BOOL inService, HINSTANCE *phInstIPCBlockOwner);

    //.............................................................................
    // Open the LegacyPrivate IPC block that has alread been created.
    //.............................................................................
    HRESULT OpenLegacyPrivateBlockOnPid(DWORD PID);

    //.............................................................................
    // ReDacl our LegacyPrivate block after it has been created.
    //.............................................................................
    HRESULT ReDaclLegacyPrivateBlock(PSECURITY_DESCRIPTOR pSecurityDescriptor);

    //.............................................................................
    // Accessors - return info from header - 
    // These functions work on LegacyPrivate Block
    //.............................................................................
    DWORD       GetBlockSize();
    PTR_VOID    GetBlockStart();
    PCWSTR      GetInstancePath();
};

//-----------------------------------------------------------------------------
// IPCReader class connects to a COM+ IPC block and reads from it
// <TODO>@FUTURE - make global & private readers</TODO>
//-----------------------------------------------------------------------------
class IPCReaderInterface : public IPCReaderImpl
{
public:

    void MakeInstanceName(const WCHAR * szProcessName, DWORD pid, DWORD runtimeId, SString & sName);
    void MakeInstanceNameWhidbey(const WCHAR * szProcessName, DWORD pid, SString & sName);

    BOOL TryOpenBlock(IPCHeaderReadHelper & readHelper, DWORD blockIndex);

    //.............................................................................
    // Create & Destroy
    //.............................................................................
    ~IPCReaderInterface();

    HRESULT OpenLegacyPrivateBlockTempV4OnPid(DWORD pid);
    HRESULT OpenLegacyPrivateBlockTempV4OnPid(DWORD pid, DWORD dwDesiredAccess);

    HRESULT OpenLegacyPrivateBlockOnPid(DWORD pid);
    HRESULT OpenLegacyPrivateBlockOnPid(DWORD pid, DWORD dwDesiredAccess);
    HRESULT OpenLegacyPrivateBlockOnPidReadWrite(DWORD pid);
    HRESULT OpenLegacyPrivateBlockOnPidReadOnly(DWORD pid);
    void CloseLegacyPrivateBlock();

#ifndef DACCESS_COMPILE
    HRESULT OpenLegacyPublicBlockOnPid(DWORD pid);
    HRESULT OpenLegacyPublicBlockOnPid(DWORD pid, DWORD dwDesiredAccess);
    HRESULT OpenLegacyPublicBlockOnPidReadOnly(DWORD pid);    
    void CloseLegacyPublicBlock();

    HRESULT OpenBlockTableOnPid(DWORD pid);
    HRESULT OpenBlockTableOnPid(DWORD pid, DWORD dwDesiredAccess);
    HRESULT OpenBlockTableOnPidReadOnly(DWORD pid);    
    void CloseBlockTable();
#endif

    //.............................................................................
    // Accessors - return info from header
    // <TODO>@FUTURE - factor this into IPCWriterInterface as well.</TODO>
    //.............................................................................
    USHORT      GetBlockVersion();
    USHORT      GetLegacyPublicBlockVersion();
    HINSTANCE   GetInstance();
    USHORT      GetBuildYear();
    USHORT      GetBuildNumber();
    PVOID       GetBlockStart();
    PCWSTR      GetInstancePath();

    //........................................
    // Check the block to see if its valid
    //........................................
    BOOL IsValidLegacy(BOOL fIsLegacyPublicBlock);

#ifndef DACCESS_COMPILE
    //BOOL IsValidForSxSPublic(IPCControlBlock * pBlock);
#endif

    //.............................................................................
    // Get different sections of the IPC
    //.............................................................................
    void * GetLegacyPrivateBlock(ELegacyPrivateIPCClient eClient);
    void * GetLegacyPublicBlock(ELegacyPublicIPCClient eClient);    
#ifndef DACCESS_COMPILE
    //void * GetSxSPublicBlock(DWORD chunkIndex, EIPCClient eClient);    
#endif

    void * GetPerfBlockLegacyPrivate();
    void * GetPerfBlockLegacyPublic();    
#ifndef DACCESS_COMPILE
    //PerfCounterIPCControlBlock *    GetPerfBlockSxSPublic(DWORD chunkIndex);
#endif
    AppDomainEnumerationIPCBlock * GetAppDomainBlock();

    //.............................................................................
    // Return true if we're connected to a memory-mapped file, else false.
    //.............................................................................
    bool IsLegacyPrivateBlockOpen() const;
    bool IsLegacyPublicBlockOpen() const;
    bool IsBlockTableOpen() const;    

    HRESULT IsCompatablePlatformForDebuggerAndDebuggee(DWORD pid, BOOL * pfCompatible);
};

#endif