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//
6
7#ifndef PEIMAGEVIEW_INL_
8#define PEIMAGEVIEW_INL_
9
10#include "util.hpp"
11#include "peimage.h"
12
13inline const SString &PEImageLayout::GetPath()
14{
15 LIMITED_METHOD_CONTRACT;
16 return m_pOwner?m_pOwner->GetPath():SString::Empty();
17}
18
19inline void PEImageLayout::AddRef()
20{
21 CONTRACT_VOID
22 {
23 PRECONDITION(m_refCount>0 && m_refCount < COUNT_T_MAX);
24 NOTHROW;
25 GC_NOTRIGGER;
26 }
27 CONTRACT_END;
28
29 FastInterlockIncrement(&m_refCount);
30
31 RETURN;
32}
33
34inline ULONG PEImageLayout::Release()
35{
36 CONTRACTL
37 {
38 DESTRUCTOR_CHECK;
39 NOTHROW;
40 MODE_ANY;
41 FORBID_FAULT;
42 }
43 CONTRACTL_END;
44
45#ifdef DACCESS_COMPILE
46 // when DAC accesses layouts via PEImage it does not addref
47 if (m_pOwner)
48 return m_refCount;
49#endif
50
51 ULONG result=FastInterlockDecrement(&m_refCount);
52 if (result == 0 )
53 {
54 delete this;
55 }
56 return result;
57}
58
59
60inline PEImageLayout::~PEImageLayout()
61{
62 CONTRACTL
63 {
64 DESTRUCTOR_CHECK;
65 NOTHROW;
66 GC_TRIGGERS;
67 MODE_ANY;
68 }
69 CONTRACTL_END;
70}
71
72inline PEImageLayout::PEImageLayout()
73 : m_refCount(1)
74 , m_pOwner(NULL)
75{
76 LIMITED_METHOD_CONTRACT;
77}
78
79inline void PEImageLayout::Startup()
80{
81 CONTRACT_VOID
82 {
83 THROWS;
84 GC_NOTRIGGER;
85 MODE_ANY;
86 POSTCONDITION(CheckStartup());
87 INJECT_FAULT(COMPlusThrowOM(););
88 }
89 CONTRACT_END;
90
91 if (CheckStartup())
92 RETURN;
93
94 RETURN;
95}
96
97inline CHECK PEImageLayout::CheckStartup()
98{
99 WRAPPER_NO_CONTRACT;
100 CHECK_OK;
101}
102
103inline BOOL PEImageLayout::CompareBase(UPTR base, UPTR mapping)
104{
105 CONTRACTL
106 {
107 PRECONDITION(CheckPointer((PEImageLayout *)mapping));
108 PRECONDITION(CheckPointer((PEImageLayout *)(base<<1),NULL_OK));
109 SO_TOLERANT;
110 NOTHROW;
111 GC_NOTRIGGER;
112 MODE_ANY;
113 }
114 CONTRACTL_END;
115 if (base==NULL) //we were searching for 'Any'
116 return TRUE;
117 return ((PEImageLayout*)mapping)->GetBase()==((PEImageLayout*)(base<<1))->GetBase();
118
119}
120
121#endif //PEIMAGEVIEW_INL_
122