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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
// 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.
// --------------------------------------------------------------------------------
// PEImageLayout.h
//
// --------------------------------------------------------------------------------
#ifndef PEIMAGELAYOUT_H_
#define PEIMAGELAYOUT_H_
// --------------------------------------------------------------------------------
// Required headers
// --------------------------------------------------------------------------------
#include "clrtypes.h"
#include "pedecoder.h"
#include "holder.h"
// --------------------------------------------------------------------------------
// Forward declarations
// --------------------------------------------------------------------------------
class Crst;
class PEImage;
typedef VPTR(class PEImageLayout) PTR_PEImageLayout;
class PEImageLayout : public PEDecoder
{
VPTR_BASE_CONCRETE_VTABLE_CLASS(PEImageLayout)
friend class PEModule;
public:
// ------------------------------------------------------------
// Public constants
// ------------------------------------------------------------
enum
{
LAYOUT_MAPPED =1,
LAYOUT_FLAT =2,
LAYOUT_LOADED =4,
LAYOUT_LOADED_FOR_INTROSPECTION =8,
LAYOUT_ANY =0xf
};
public:
#ifndef DACCESS_COMPILE
static PEImageLayout* CreateFlat(const void *flat, COUNT_T size,PEImage* pOwner);
static PEImageLayout* CreateFromStream(IStream* pIStream, PEImage* pOwner);
static PEImageLayout* CreateFromHMODULE(HMODULE mappedbase,PEImage* pOwner, BOOL bTakeOwnership);
static PEImageLayout* LoadFromFlat(PEImageLayout* pflatimage);
static PEImageLayout* Load(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError = TRUE);
static PEImageLayout* LoadFlat(HANDLE hFile, PEImage* pOwner);
static PEImageLayout* Map (HANDLE hFile, PEImage* pOwner);
#endif
PEImageLayout();
virtual ~PEImageLayout();
static void Startup();
static CHECK CheckStartup();
static BOOL CompareBase(UPTR path, UPTR mapping);
// Refcount above images.
void AddRef();
ULONG Release();
const SString& GetPath();
void ApplyBaseRelocations();
public:
#ifdef DACCESS_COMPILE
void EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
#endif
private:
Volatile<LONG> m_refCount;
public:
PEImage* m_pOwner;
DWORD m_Layout;
};
typedef ReleaseHolder<PEImageLayout> PEImageLayoutHolder;
//RawImageView is built on external data, does not need cleanup
class RawImageLayout: public PEImageLayout
{
VPTR_VTABLE_CLASS(RawImageLayout,PEImageLayout)
protected:
CLRMapViewHolder m_DataCopy;
#ifndef FEATURE_PAL
HModuleHolder m_LibraryHolder;
#endif // !FEATURE_PAL
public:
RawImageLayout(const void *flat, COUNT_T size,PEImage* pOwner);
RawImageLayout(const void *mapped, PEImage* pOwner, BOOL bTakeOwnerShip, BOOL bFixedUp);
};
// ConvertedImageView is for the case when we manually layout a flat image
class ConvertedImageLayout: public PEImageLayout
{
VPTR_VTABLE_CLASS(ConvertedImageLayout,PEImageLayout)
protected:
HandleHolder m_FileMap;
CLRMapViewHolder m_FileView;
public:
#ifndef DACCESS_COMPILE
ConvertedImageLayout(PEImageLayout* source);
#endif
};
class MappedImageLayout: public PEImageLayout
{
VPTR_VTABLE_CLASS(MappedImageLayout,PEImageLayout)
VPTR_UNIQUE(0x15)
protected:
#ifndef FEATURE_PAL
HandleHolder m_FileMap;
CLRMapViewHolder m_FileView;
#else
PALPEFileHolder m_LoadedFile;
#endif
public:
#ifndef DACCESS_COMPILE
MappedImageLayout(HANDLE hFile, PEImage* pOwner);
#endif
};
#if !defined(CROSSGEN_COMPILE) && !defined(FEATURE_PAL)
class LoadedImageLayout: public PEImageLayout
{
VPTR_VTABLE_CLASS(LoadedImageLayout,PEImageLayout)
protected:
HINSTANCE m_Module;
public:
#ifndef DACCESS_COMPILE
LoadedImageLayout(PEImage* pOwner, BOOL bNTSafeLoad, BOOL bThrowOnError);
~LoadedImageLayout()
{
CONTRACTL
{
NOTHROW;
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;
if (m_Module)
CLRFreeLibrary(m_Module);
}
#endif // !DACCESS_COMPILE
};
#endif // !CROSSGEN_COMPILE && !FEATURE_PAL
class FlatImageLayout: public PEImageLayout
{
VPTR_VTABLE_CLASS(FlatImageLayout,PEImageLayout)
VPTR_UNIQUE(0x59)
protected:
HandleHolder m_FileMap;
CLRMapViewHolder m_FileView;
public:
#ifndef DACCESS_COMPILE
FlatImageLayout(HANDLE hFile, PEImage* pOwner);
#endif
};
#endif // PEIMAGELAYOUT_H_
|