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.
11 // ======================================================================================
13 #ifndef __ZAPMETADATA_H__
14 #define __ZAPMETADATA_H__
16 //-----------------------------------------------------------------------------
18 // ZapMetaData is the barebone ZapNode to save metadata scope
21 class ZapMetaData : public ZapNode
26 IMetaDataEmit * m_pEmit;
38 void SetMetaData(IUnknown * pEmit);
40 virtual DWORD GetSize();
42 virtual UINT GetAlignment()
47 virtual ZapNodeType GetType()
49 return ZapNodeType_MetaData;
52 virtual void Save(ZapWriter * pZapWriter);
55 //-----------------------------------------------------------------------------
57 // Helper node to copy RVA data to from IL to the NGEN image.
60 class ZapRVADataNode : public ZapNode
67 ZapRVADataNode(PVOID pData)
74 void UpdateSizeAndAlignment(DWORD dwSize, DWORD dwAlignment)
76 if (dwSize > m_dwSize)
79 if (dwAlignment > m_dwAlignment)
80 m_dwAlignment = dwAlignment;
88 virtual DWORD GetSize()
93 virtual UINT GetAlignment()
98 virtual ZapNodeType GetType()
100 return ZapNodeType_RVAFieldData;
103 virtual void Save(ZapWriter * pZapWriter)
105 pZapWriter->Write(m_pData, m_dwSize);
110 //-----------------------------------------------------------------------------
112 // ZapILMetaData copies both the metadata and IL to the NGEN image.
115 class ZapILMetaData : public ZapMetaData
119 class ILBlob : public ZapBlobPtr
122 ILBlob(PVOID pData, SIZE_T cbSize)
123 : ZapBlobPtr(pData, cbSize)
127 virtual UINT GetAlignment()
129 // The tiny header does not have any alignment requirements
130 return ((COR_ILMETHOD_TINY *)GetData())->IsTiny() ? sizeof(BYTE) : sizeof(DWORD);
134 // Hashtable with all IL method blobs. If two methods have same IL code
135 // we store it just once.
136 SHash< NoRemoveSHashTraits < ZapBlob::SHashTraits > > m_blobs;
144 class ILMethodTraits : public NoRemoveSHashTraits< DefaultSHashTraits<ILMethod> >
147 typedef const mdMethodDef key_t;
149 static key_t GetKey(element_t e)
151 LIMITED_METHOD_CONTRACT;
154 static BOOL Equals(key_t k1, key_t k2)
156 LIMITED_METHOD_CONTRACT;
159 static count_t Hash(key_t k)
161 LIMITED_METHOD_CONTRACT;
165 static const element_t Null() { LIMITED_METHOD_CONTRACT; ILMethod e; e.m_md = 0; e.m_pIL = NULL; return e; }
166 static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return e.m_md == 0; }
169 SHash< ILMethodTraits > m_ILMethods;
172 ZapILMetaData(ZapImage * pImage)
177 void Preallocate(COUNT_T cbILImage)
179 PREALLOCATE_HASHTABLE(ZapILMetaData::m_blobs, 0.0040, cbILImage);
180 PREALLOCATE_HASHTABLE(ZapILMetaData::m_ILMethods, 0.0044, cbILImage);
183 void EmitMethodIL(mdMethodDef md);
187 void CopyRVAFields();
189 virtual void Save(ZapWriter * pZapWriter);
191 ZapRVADataNode * GetRVAField(void * pData);
194 class RVADataTraits : public NoRemoveSHashTraits< DefaultSHashTraits<ZapRVADataNode *> >
199 static key_t GetKey(element_t e)
201 LIMITED_METHOD_CONTRACT;
204 static BOOL Equals(key_t k1, key_t k2)
206 LIMITED_METHOD_CONTRACT;
209 static count_t Hash(key_t k)
211 LIMITED_METHOD_CONTRACT;
215 static element_t Null() { LIMITED_METHOD_CONTRACT; return NULL; }
216 static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return e == NULL; }
219 SHash< RVADataTraits > m_rvaData;
222 #endif // __ZAPMETADATA_H__