summaryrefslogtreecommitdiff
path: root/src/md/hotdata/hotmetadata.cpp
blob: 2810eecd151efa6c49dd7748507ac8e3ad73feca (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
// 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: HotMetaData.cpp
// 

// 
// Class code:MetaData::HotMetaData represents a reader of hot data in MetaData hot stream.
// 
// ======================================================================================

#include "external.h"

#include "hotmetadata.h"
#include "hotdataformat.h"
#include "hotheapsdirectoryiterator.h"

namespace MetaData
{

// --------------------------------------------------------------------------------------
// 
// Class code:MetaData::HotMetaData represents a reader of hot data in MetaData hot stream.
// 
__checkReturn 
HRESULT 
HotMetaData::Initialize(
    DataBuffer data)
{
    m_Data = data;
    
    return S_OK;
} // HotMetaData::Initialize

// --------------------------------------------------------------------------------------
// 
// Returns iterator of stored hot heaps (code:HotHeap).
// 
__checkReturn 
HRESULT 
HotMetaData::GetHeapsDirectoryIterator(
    HotHeapsDirectoryIterator *pHeapsDirectoryIterator)
{
    if (m_Data.GetSize() < sizeof(struct HotMetaDataHeader))
    {
        Debug_ReportError("Invalid hot MetaData format - header doesn't fit into the hot data.");
        return METADATA_E_INVALID_FORMAT;
    }
    
    struct HotMetaDataHeader *pHeader;
    if (!m_Data.PeekDataAt<struct HotMetaDataHeader>(
        m_Data.GetSize() - sizeof(struct HotMetaDataHeader), 
        &pHeader))
    {
        Debug_ReportInternalError("There's a bug, because previous size check succeeded.");
        return METADATA_E_INTERNAL_ERROR;
    }
    // Get rid of the read header
    DataBuffer heapsData = m_Data;
    if (!heapsData.TruncateBySize(sizeof(struct HotMetaDataHeader)))
    {
        Debug_ReportInternalError("There's a bug, because previous size check succeeded.");
        return METADATA_E_INTERNAL_ERROR;
    }
    DataBuffer heapsDirectoryData = heapsData;
    if (!heapsDirectoryData.SkipToExactSize(pHeader->m_nHeapsDirectoryStart_NegativeOffset))
    {
        Debug_ReportError("Invalid hot MetaData format - heaps directory offset reaches in front of hot data.");
        return METADATA_E_INVALID_FORMAT;
    }
    if (!heapsData.TruncateBySize(pHeader->m_nHeapsDirectoryStart_NegativeOffset))
    {
        Debug_ReportInternalError("There's a bug, because previous call to SkipToExactSize succeeded.");
        return METADATA_E_INVALID_FORMAT;
    }
    
    pHeapsDirectoryIterator->Initialize(
        heapsDirectoryData, 
        heapsData);
    
    return S_OK;
} // HotMetaData::GetHeapsDirectoryIterator

};  // namespace MetaData