summaryrefslogtreecommitdiff
path: root/src/ipcman/ipcheader.inl
blob: 85aed282c4dd6b3947a7214cd2143ffa8d0a063f (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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
//

// ==++==
//
 
//
// ==--==
//*****************************************************************************
// File: IPCHeader.inl
//
// Define the LegacyPrivate header format for COM+ memory mapped files. Everyone
// outside of IPCMan.lib will use the public header, IPCManagerInterface.h
//
//*****************************************************************************

#ifndef _IPCManagerPriv_inl_
#define _IPCManagerPriv_inl_

#include "ipcheader.h"

//=============================================================================
// Internal Helpers: Encapsulate any error-prone math / comparisons.
// The helpers are very streamlined and don't handle error conditions.
// Also, Table access functions use DWORD instead of typesafe Enums
// so they can be more flexible (not just for LegacyPrivate blocks).
//=============================================================================

//-----------------------------------------------------------------------------
// Returns true if the entry is empty and false if the entry is usable.
// This is an internal helper that Enforces a formal definition for an 
// "empty" entry
//
// Arguments:
//   block - IPC block of interest
//   Id - index of the desired entry in the IPC block's table
//-----------------------------------------------------------------------------
inline bool Internal_CheckEntryEmptyLegacyPrivate(
    const LegacyPrivateIPCControlBlock & block,   
    DWORD Id                                
)
{
// Directory has offset in bytes of block
    const DWORD offset = block.m_FullIPCHeader.m_table[Id].m_Offset;

    return (EMPTY_ENTRY_OFFSET == offset);
}

//-----------------------------------------------------------------------------
// Returns the base that entry offsets for the specified IPC block
// are relative to.
//
// Arguments:
//   block - IPC block of interest
//-----------------------------------------------------------------------------
inline SIZE_T Internal_GetOffsetBaseLegacyPrivate(const LegacyPrivateIPCControlBlock & block)
{
    return LEGACY_IPC_ENTRY_OFFSET_BASE + 
           block.m_FullIPCHeader.m_header.m_numEntries 
            * sizeof(IPCEntry);            // skip over directory (variable size)
}

//-----------------------------------------------------------------------------
// Returns a BYTE* to a block within a header. This is an internal 
// helper that encapsulates error-prone math.
//
// Arguments:
//   block - IPC block of interest
//   Id - index of the desired entry in the IPC block's table
//-----------------------------------------------------------------------------
inline BYTE* Internal_GetBlockLegacyPrivate(
    const LegacyPrivateIPCControlBlock & block,   
    DWORD Id                                
)
{

// Directory has offset in bytes of block
    const DWORD offset = block.m_FullIPCHeader.m_table[Id].m_Offset;


// This block has been removed. Callee should have caught that and not called us.
    _ASSERTE(!Internal_CheckEntryEmptyLegacyPrivate(block, Id));
    return
        ((BYTE*) &block)                    // base pointer to start of block
        + Internal_GetOffsetBaseLegacyPrivate(block)
        +offset;                            // jump to block
}

#endif // _IPCManagerPriv_inl_