diff options
Diffstat (limited to 'src/ipcman/ipcheader.inl')
-rw-r--r-- | src/ipcman/ipcheader.inl | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/ipcman/ipcheader.inl b/src/ipcman/ipcheader.inl new file mode 100644 index 0000000000..85aed282c4 --- /dev/null +++ b/src/ipcman/ipcheader.inl @@ -0,0 +1,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_ |