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.
9 // Zapping of relocations
11 // ======================================================================================
13 #ifndef __ZAPRELOCS_H__
14 #define __ZAPRELOCS_H__
16 typedef BYTE ZapRelocationType; // IMAGE_REL_XXX enum
18 // Special NGEN-specific relocation type for fixups (absolute RVA in the middle 30 bits)
19 #define IMAGE_REL_BASED_ABSOLUTE_TAGGED 0x7E
21 // Special NGEN-specific relocation type for relative pointer (used to make NGen relocation section smaller)
22 #define IMAGE_REL_BASED_RELPTR 0x7D
23 #define IMAGE_REL_BASED_RELPTR32 0x7C
25 // Invalid reloc marker (used to mark end of the reloc array)
26 #define IMAGE_REL_INVALID 0xFF
28 // IMAGE_REL_BASED_PTR is architecture specific reloc of virtual address
30 #define IMAGE_REL_BASED_PTR IMAGE_REL_BASED_DIR64
32 #define IMAGE_REL_BASED_PTR IMAGE_REL_BASED_HIGHLOW
35 // Size of base relocs relocation page
36 #define RELOCATION_PAGE_SIZE 0x1000
39 // The ZapNode for regular PE base relocs
42 class ZapBaseRelocs : public ZapNode
46 // The page currently being written
50 // Reloc writer output
51 SArray<USHORT> m_SerializedRelocs;
56 ZapBaseRelocs(ZapImage * pImage)
59 // Everything is zero initialized by the allocator
62 void WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int targetOffset, ZapRelocationType type);
64 virtual DWORD GetSize()
66 return m_SerializedRelocs.GetCount() * sizeof(USHORT);
69 virtual ZapNodeType GetType()
71 return ZapNodeType_Relocs;
74 virtual void Save(ZapWriter * pZapWriter);
79 // Blob with associated relocations. Used for compiled code.
84 ZapRelocationType m_type;
86 ZapNode * m_pTargetNode;
89 class ZapBlobWithRelocs : public ZapBlob
94 ZapBlobWithRelocs(SIZE_T cbSize)
100 void SetRelocs(ZapReloc * pRelocs)
102 _ASSERTE(m_pRelocs == NULL);
103 _ASSERTE(pRelocs != NULL);
107 ZapReloc * GetRelocs()
112 virtual PBYTE GetData()
114 return (PBYTE)(this + 1);
117 virtual void Save(ZapWriter * pZapWriter);
119 // Returns number of straddler relocs, assuming RVA of the node is dwPos
120 COUNT_T GetCountOfStraddlerRelocations(DWORD dwPos);
122 // Create new zap blob node. The node *does* own copy of the memory.
123 static ZapBlobWithRelocs * NewBlob(ZapWriter * pWriter, PVOID pData, SIZE_T cbSize);
125 // Create new aligned zap blob node.
126 static ZapBlobWithRelocs * NewAlignedBlob(ZapWriter * pWriter, PVOID pData, SIZE_T cbSize, SIZE_T cbAlignment);
129 #endif // __ZAPRELOCS_H__