| 1 | // Licensed to the .NET Foundation under one or more agreements. |
|---|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | // |
| 5 | // File: HotMetaData.cpp |
| 6 | // |
| 7 | |
| 8 | // |
| 9 | // Class code:MetaData::HotMetaData represents a reader of hot data in MetaData hot stream. |
| 10 | // |
| 11 | // ====================================================================================== |
| 12 | |
| 13 | #include "external.h" |
| 14 | |
| 15 | #include "hotmetadata.h" |
| 16 | #include "hotdataformat.h" |
| 17 | #include "hotheapsdirectoryiterator.h" |
| 18 | |
| 19 | namespace MetaData |
| 20 | { |
| 21 | |
| 22 | // -------------------------------------------------------------------------------------- |
| 23 | // |
| 24 | // Class code:MetaData::HotMetaData represents a reader of hot data in MetaData hot stream. |
| 25 | // |
| 26 | __checkReturn |
| 27 | HRESULT |
| 28 | HotMetaData::Initialize( |
| 29 | DataBuffer data) |
| 30 | { |
| 31 | m_Data = data; |
| 32 | |
| 33 | return S_OK; |
| 34 | } // HotMetaData::Initialize |
| 35 | |
| 36 | // -------------------------------------------------------------------------------------- |
| 37 | // |
| 38 | // Returns iterator of stored hot heaps (code:HotHeap). |
| 39 | // |
| 40 | __checkReturn |
| 41 | HRESULT |
| 42 | HotMetaData::GetHeapsDirectoryIterator( |
| 43 | HotHeapsDirectoryIterator *pHeapsDirectoryIterator) |
| 44 | { |
| 45 | if (m_Data.GetSize() < sizeof(struct HotMetaDataHeader)) |
| 46 | { |
| 47 | Debug_ReportError("Invalid hot MetaData format - header doesn't fit into the hot data."); |
| 48 | return METADATA_E_INVALID_FORMAT; |
| 49 | } |
| 50 | |
| 51 | struct HotMetaDataHeader *pHeader; |
| 52 | if (!m_Data.PeekDataAt<struct HotMetaDataHeader>( |
| 53 | m_Data.GetSize() - sizeof(struct HotMetaDataHeader), |
| 54 | &pHeader)) |
| 55 | { |
| 56 | Debug_ReportInternalError("There's a bug, because previous size check succeeded."); |
| 57 | return METADATA_E_INTERNAL_ERROR; |
| 58 | } |
| 59 | // Get rid of the read header |
| 60 | DataBuffer heapsData = m_Data; |
| 61 | if (!heapsData.TruncateBySize(sizeof(struct HotMetaDataHeader))) |
| 62 | { |
| 63 | Debug_ReportInternalError("There's a bug, because previous size check succeeded."); |
| 64 | return METADATA_E_INTERNAL_ERROR; |
| 65 | } |
| 66 | DataBuffer heapsDirectoryData = heapsData; |
| 67 | if (!heapsDirectoryData.SkipToExactSize(pHeader->m_nHeapsDirectoryStart_NegativeOffset)) |
| 68 | { |
| 69 | Debug_ReportError("Invalid hot MetaData format - heaps directory offset reaches in front of hot data."); |
| 70 | return METADATA_E_INVALID_FORMAT; |
| 71 | } |
| 72 | if (!heapsData.TruncateBySize(pHeader->m_nHeapsDirectoryStart_NegativeOffset)) |
| 73 | { |
| 74 | Debug_ReportInternalError("There's a bug, because previous call to SkipToExactSize succeeded."); |
| 75 | return METADATA_E_INVALID_FORMAT; |
| 76 | } |
| 77 | |
| 78 | pHeapsDirectoryIterator->Initialize( |
| 79 | heapsDirectoryData, |
| 80 | heapsData); |
| 81 | |
| 82 | return S_OK; |
| 83 | } // HotMetaData::GetHeapsDirectoryIterator |
| 84 | |
| 85 | }; // namespace MetaData |
| 86 |