summaryrefslogtreecommitdiff
path: root/src/ipcman/ipcmanagerimpl.inl
blob: 4cf4017e4c2cad78890691f0a4adc0056b657e7f (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
// 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: IPCManagerImpl.inl
//
// Defines Classes to implement InterProcess Communication Manager for a COM+
//
//*****************************************************************************

#ifndef _IPCManagerImpl_INL_
#define _IPCManagerImpl_INL_

#include "ipcmanagerimpl.h"

//-----------------------------------------------------------------------------
// Return true if the IPCBlockTable is available.
//-----------------------------------------------------------------------------
inline BOOL IPCWriterImpl::IsBlockTableOpen() const
{
    LIMITED_METHOD_CONTRACT;
    SUPPORTS_DAC;
    return (m_pBlockTable != NULL);
}

//-----------------------------------------------------------------------------
// Return true if our LegacyPrivate block is available.
//-----------------------------------------------------------------------------
inline BOOL IPCWriterImpl::IsLegacyPrivateBlockOpen() const
{
    LIMITED_METHOD_CONTRACT;
    SUPPORTS_DAC;
    return (m_ptrLegacyPrivateBlock != NULL);
}

//-----------------------------------------------------------------------------
// Returns a BOOL indicating whether the Wow64 structs should be used instead
// of the normal structs.
//
// It is NOT safe to call this function before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline BOOL IPCReaderImpl::UseWow64StructsLegacy()
{
#if !defined(_X86_)
    _ASSERTE(m_fInitialized);
    return m_fIsTarget32Bit;
#else
    return FALSE;
#endif
}

//-----------------------------------------------------------------------------
// Returns the value of the flags field of the specified IPC block. This is
// safe to call before m_fIsTarget32Bit has been initialized since the flags 
// field is in the same position for 32-bit and 64-bit targets.
//
// It is safe to call this function before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline USHORT IPCReaderImpl::GetFlagsLegacy(void * pBlock)
{
    return ((LegacyPrivateIPCHeader*)pBlock)->m_Flags;
}

//-----------------------------------------------------------------------------
// Returns the value of the block size field of the specified IPC block. 
//
// It is safe to call this function before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline DWORD IPCReaderImpl::GetBlockSizeLegacy(void * pBlock)
{
    return ((LegacyPrivateIPCHeader*)pBlock)->m_blockSize;
}

//-----------------------------------------------------------------------------
// Returns true if the specified entry is empty and false if the entry is
// usable. This is an internal helper that enforces the formal definition 
// for an "empty" entry
//
// Arguments:
//   Id - index of the entry to check
//
// It is NOT safe to call this function before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline BOOL IPCReaderImpl::Internal_CheckEntryEmptyLegacyPublic(DWORD Id)
{
    // Directory has offset in bytes of block
    return (GetDirectoryLegacy(m_ptrLegacyPublicBlock)[Id].m_Offset == EMPTY_ENTRY_OFFSET);
}

//-----------------------------------------------------------------------------
// Returns a BYTE* to a block within a header. This is an internal 
// helper that encapsulates error-prone math.
//
// Arguments:
//   Id - index of the entry containing the desired LegacyPublic block
//
// It is NOT safe to call this function before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline BYTE * IPCReaderImpl::Internal_GetBlockLegacyPublic(DWORD Id)
{
    // This block has been removed. Callee should have caught that and not called us.
    _ASSERTE(!Internal_CheckEntryEmptyLegacyPublic(Id));

    return ((BYTE*) m_ptrLegacyPublicBlock) + (SIZE_T)GetOffsetBaseLegacy() + 
        (SIZE_T)GetNumEntriesLegacy(m_ptrLegacyPublicBlock) * sizeof(IPCEntry) + 
        (SIZE_T)GetDirectoryLegacy(m_ptrLegacyPublicBlock)[Id].m_Offset;
}

//-----------------------------------------------------------------------------
// Returns a value that is used to calculate the actual offset of an entry in
// an IPC block. Internal_GetBlockLegacyPublic() shows how to use GetOffsetBaseLegacy()
// to calculate the actual offset of an entry.
//
// It is NOT safe to call this funciton before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline DWORD IPCReaderImpl::GetOffsetBaseLegacy()
{
    if (UseWow64StructsLegacy())
        return LEGACY_IPC_ENTRY_OFFSET_BASE_WOW64;

    return LEGACY_IPC_ENTRY_OFFSET_BASE;
}

//-----------------------------------------------------------------------------
// Returns the expected value for the specified offset of the first entry in
// an IPC block.
//
// It is NOT safe to call this funciton before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline DWORD IPCReaderImpl::GetFirstExpectedOffsetLegacy()
{
    if (GetOffsetBaseLegacy() == 0)
        return sizeof(LegacyPrivateIPCHeader);
    
    return 0;
}

//-----------------------------------------------------------------------------
// Returns the number of entries in the specified IPC block.
//
// It is NOT safe to call this funciton before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline DWORD IPCReaderImpl::GetNumEntriesLegacy(void * pBlock)
{
    if (UseWow64StructsLegacy())    
        return ((LegacyPrivateIPCHeaderTemplate<DWORD>*)pBlock)->m_numEntries;
    
    return ((LegacyPrivateIPCHeader*)pBlock)->m_numEntries;
}

//-----------------------------------------------------------------------------
// Returns a pointer to the directory ('m_table') in the specified IPC block.
//
// It is NOT safe to call this funciton before m_fIsTarget32Bit has been 
// initialized.
//-----------------------------------------------------------------------------
inline IPCEntry * IPCReaderImpl::GetDirectoryLegacy(void * pBlock)
{
    if (UseWow64StructsLegacy())
        return ((FullIPCHeaderLegacyPublicTemplate<DWORD>*)pBlock)->m_table;

    return ((FullIPCHeaderLegacyPublicTemplate<HINSTANCE>*)pBlock)->m_table;
}

//-----------------------------------------------------------------------------
// Compile-time asserts that check the values of LEGACY_IPC_ENTRY_OFFSET_BASE and
// LEGACY_IPC_ENTRY_OFFSET_BASE_WOW64
//-----------------------------------------------------------------------------

#ifdef _TARGET_X86_
    C_ASSERT(sizeof(LegacyPrivateIPCHeaderTemplate<HINSTANCE>) == LEGACY_IPC_ENTRY_OFFSET_BASE);
#endif

C_ASSERT(sizeof(LegacyPrivateIPCHeaderTemplate<DWORD>) == LEGACY_IPC_ENTRY_OFFSET_BASE_WOW64);


#endif // _IPCManagerImpl_INL_