diff options
author | Jan Kotas <jkotas@microsoft.com> | 2016-11-01 23:07:49 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-11-01 23:07:49 +0300 |
commit | e78f2c99fa3a317aef3d6ed51cbc9d4fdec0df24 (patch) | |
tree | 9ee0b7e2525cf3b8ed61fd1184f245eb419414f1 /src/Native/Runtime/TypeManager.cpp | |
parent | 0fc8eff01c5a010af50dd85ee47bc9d65e25bee1 (diff) |
Rename ModuleManager to TypeManager
[tfs-changeset: 1636196]
Diffstat (limited to 'src/Native/Runtime/TypeManager.cpp')
-rw-r--r-- | src/Native/Runtime/TypeManager.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/Native/Runtime/TypeManager.cpp b/src/Native/Runtime/TypeManager.cpp new file mode 100644 index 000000000..f6a88b022 --- /dev/null +++ b/src/Native/Runtime/TypeManager.cpp @@ -0,0 +1,84 @@ +// 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. +#include "common.h" +#include "CommonTypes.h" +#include "CommonMacros.h" +#include "daccess.h" +#include "PalRedhawkCommon.h" +#include "PalRedhawk.h" +#include "holder.h" +#include "TypeManager.h" + +/* static */ +TypeManager * TypeManager::Create(void * pModuleHeader) +{ + ReadyToRunHeader * pReadyToRunHeader = (ReadyToRunHeader *)pModuleHeader; + + // Sanity check the signature magic + ASSERT(pReadyToRunHeader->Signature == ReadyToRunHeaderConstants::Signature); + if (pReadyToRunHeader->Signature != ReadyToRunHeaderConstants::Signature) + return nullptr; + + // Only the current major version is supported currently + ASSERT(pReadyToRunHeader->MajorVersion == ReadyToRunHeaderConstants::CurrentMajorVersion); + if (pReadyToRunHeader->MajorVersion != ReadyToRunHeaderConstants::CurrentMajorVersion) + return nullptr; + + return new (nothrow) TypeManager(pReadyToRunHeader); +} + +TypeManager::TypeManager(ReadyToRunHeader * pHeader) + : m_pHeader(pHeader), m_pDispatchMapTable(nullptr) +{ +} + +void * TypeManager::GetModuleSection(ReadyToRunSectionType sectionId, int * length) +{ + ModuleInfoRow * pModuleInfoRows = (ModuleInfoRow *)(m_pHeader + 1); + + ASSERT(m_pHeader->EntrySize == sizeof(ModuleInfoRow)); + + // TODO: Binary search + for (int i = 0; i < m_pHeader->NumberOfSections; i++) + { + ModuleInfoRow * pCurrent = pModuleInfoRows + i; + if ((int32_t)sectionId == pCurrent->SectionId) + { + *length = pCurrent->GetLength(); + return pCurrent->Start; + } + } + + *length = 0; + return nullptr; +} + +DispatchMap** TypeManager::GetDispatchMapLookupTable() +{ + if (m_pDispatchMapTable == nullptr) + { + int length = 0; + DispatchMap ** pDispatchMapTable = (DispatchMap **)GetModuleSection(ReadyToRunSectionType::InterfaceDispatchTable, &length); + m_pDispatchMapTable = pDispatchMapTable; + } + + return m_pDispatchMapTable; +} + +bool TypeManager::ModuleInfoRow::HasEndPointer() +{ + return Flags & (int32_t)ModuleInfoFlags::HasEndPointer; +} + +int TypeManager::ModuleInfoRow::GetLength() +{ + if (HasEndPointer()) + { + return (int)((PTR_UInt8)End - (PTR_UInt8)Start); + } + else + { + return sizeof(void*); + } +} |