summaryrefslogtreecommitdiff
path: root/src/ipcman/ipcshared.h
blob: 865509dfc3ce3f4fe516412e61f140f8818ac2d8 (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
// 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: IPCShared.h
//
// Shared LegacyPrivate utility functions for COM+ IPC operations
//
//*****************************************************************************

#ifndef _IPCSHARED_H_
#define _IPCSHARED_H_


#include "ipcenums.h"


class SString;

// This is the name of the file backed session's name on the LS (debuggee)
// Name of the LegacyPrivate (per-process) block. %d resolved to a PID
#define CorLegacyPrivateIPCBlock       L"Cor_Private_IPCBlock_%d"
#define CorLegacyPrivateIPCBlockTempV4 L"Cor_Private_IPCBlock_v4_%d"
#define CorLegacyPublicIPCBlock        L"Cor_Public_IPCBlock_%d"
#define CorSxSPublicIPCBlock           L"Cor_SxSPublic_IPCBlock_%d"
#define CorSxSBoundaryDescriptor       L"Cor_CLR_IPCBlock_%d"
#define CorSxSWriterPrivateNamespacePrefix   L"Cor_CLR_WRITER"
#define CorSxSReaderPrivateNamespacePrefix   L"Cor_CLR_READER"
#define CorSxSVistaPublicIPCBlock      L"Cor_SxSPublic_IPCBlock"

#define CorLegacyPrivateIPCBlock_RS       L"CLR_PRIVATE_RS_IPCBlock_%d"
#define CorLegacyPrivateIPCBlock_RSTempV4 L"CLR_PRIVATE_RS_IPCBlock_v4_%d"
#define CorLegacyPublicIPCBlock_RS        L"CLR_PUBLIC_IPCBlock_%d"
#define CorSxSPublicIPCBlock_RS           L"CLR_SXSPUBLIC_IPCBlock_%d"

#define CorSxSPublicInstanceName            L"%s_p%d_r%d"
#define CorSxSPublicInstanceNameWhidbey     L"%s_p%d"

// NOTE: we cannot just remove this otherwise 'FeatureCoreClr' build breaks
//       since this is not defined in old SDK header
#ifndef CREATE_BOUNDARY_DESCRIPTOR_ADD_APPCONTAINER_SID
#define CREATE_BOUNDARY_DESCRIPTOR_ADD_APPCONTAINER_SID 0x1
#endif
// ENDNOTE

enum KernelObject
{
    Section,
    Event,
    PrivateNamespace,
    TotalKernelObjects
};


class IPCShared
{
public:
// Close a handle and pointer to any memory mapped file
    static void CloseMemoryMappedFile(HANDLE & hMemFile, void * & pBlock);

// Based on the pid, write a unique name for a memory mapped file
    static void GenerateName(DWORD pid, SString & sName);
    static void GenerateNameLegacyTempV4(DWORD pid, SString & sName);
    static void GenerateLegacyPublicName(DWORD pid, SString & sName);

    static HRESULT GenerateBlockTableName(DWORD pid, 
                                          SString & sName, 
                                          HANDLE & pBoundaryDesc, 
                                          HANDLE & pPrivateNamespace, 
                                          PSID* pSID, 
                                          BOOL bCreate);
    static HRESULT FreeHandles(HANDLE & hDescriptor, PSID & pSID);
    static HRESULT FreeHandles(HANDLE & hBoundaryDescriptor, PSID & pSID, HANDLE & hPrivateNamespace);
    static HRESULT CreateWinNTDescriptor(DWORD pid, BOOL bRestrictiveACL, SECURITY_ATTRIBUTES **ppSA, KernelObject whatObject);
    static HRESULT CreateWinNTDescriptor(DWORD pid, BOOL bRestrictiveACL, SECURITY_ATTRIBUTES **ppSA, KernelObject whatObject, EDescriptorType descType);
    static void DestroySecurityAttributes(SECURITY_ATTRIBUTES *pSA);

private:
    static const int MaxNumberACEs = 5;
    static BOOL InitializeGenericIPCAcl(DWORD pid, BOOL bRestrictiveACL, PACL *ppACL, KernelObject whatObject, EDescriptorType descType);
    static DWORD GetAccessFlagsForObject(KernelObject whatObject, BOOL bRestrictiveACL);
    static HRESULT GetSidForProcess(HINSTANCE hDll,
                                    DWORD pid,
                                    PSID *ppSID,
                                    __deref_out_opt char **ppBufferToFreeByCaller);
};

#endif