Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

595 lines
21 KiB

  1. //===-- llvm/Support/COFF.h -------------------------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains an definitions used in Windows COFF Files.
  11. //
  12. // Structures and enums defined within this file where created using
  13. // information from Microsoft's publicly available PE/COFF format document:
  14. //
  15. // Microsoft Portable Executable and Common Object File Format Specification
  16. // Revision 8.1 - February 15, 2008
  17. //
  18. // As of 5/2/2010, hosted by Microsoft at:
  19. // http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx
  20. //
  21. //===----------------------------------------------------------------------===//
  22. #ifndef LLVM_SUPPORT_COFF_H
  23. #define LLVM_SUPPORT_COFF_H
  24. #include "llvm/Support/DataTypes.h"
  25. #include <cassert>
  26. #include <cstring>
  27. namespace llvm {
  28. namespace COFF {
  29. // Sizes in bytes of various things in the COFF format.
  30. enum {
  31. HeaderSize = 20,
  32. NameSize = 8,
  33. SymbolSize = 18,
  34. SectionSize = 40,
  35. RelocationSize = 10
  36. };
  37. struct header {
  38. uint16_t Machine;
  39. uint16_t NumberOfSections;
  40. uint32_t TimeDateStamp;
  41. uint32_t PointerToSymbolTable;
  42. uint32_t NumberOfSymbols;
  43. uint16_t SizeOfOptionalHeader;
  44. uint16_t Characteristics;
  45. };
  46. enum MachineTypes {
  47. MT_Invalid = 0xffff,
  48. IMAGE_FILE_MACHINE_UNKNOWN = 0x0,
  49. IMAGE_FILE_MACHINE_AM33 = 0x13,
  50. IMAGE_FILE_MACHINE_AMD64 = 0x8664,
  51. IMAGE_FILE_MACHINE_ARM = 0x1C0,
  52. IMAGE_FILE_MACHINE_ARMV7 = 0x1C4,
  53. IMAGE_FILE_MACHINE_EBC = 0xEBC,
  54. IMAGE_FILE_MACHINE_I386 = 0x14C,
  55. IMAGE_FILE_MACHINE_IA64 = 0x200,
  56. IMAGE_FILE_MACHINE_M32R = 0x9041,
  57. IMAGE_FILE_MACHINE_MIPS16 = 0x266,
  58. IMAGE_FILE_MACHINE_MIPSFPU = 0x366,
  59. IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466,
  60. IMAGE_FILE_MACHINE_POWERPC = 0x1F0,
  61. IMAGE_FILE_MACHINE_POWERPCFP = 0x1F1,
  62. IMAGE_FILE_MACHINE_R4000 = 0x166,
  63. IMAGE_FILE_MACHINE_SH3 = 0x1A2,
  64. IMAGE_FILE_MACHINE_SH3DSP = 0x1A3,
  65. IMAGE_FILE_MACHINE_SH4 = 0x1A6,
  66. IMAGE_FILE_MACHINE_SH5 = 0x1A8,
  67. IMAGE_FILE_MACHINE_THUMB = 0x1C2,
  68. IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169
  69. };
  70. enum Characteristics {
  71. C_Invalid = 0,
  72. /// The file does not contain base relocations and must be loaded at its
  73. /// preferred base. If this cannot be done, the loader will error.
  74. IMAGE_FILE_RELOCS_STRIPPED = 0x0001,
  75. /// The file is valid and can be run.
  76. IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002,
  77. /// COFF line numbers have been stripped. This is deprecated and should be
  78. /// 0.
  79. IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004,
  80. /// COFF symbol table entries for local symbols have been removed. This is
  81. /// deprecated and should be 0.
  82. IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008,
  83. /// Aggressively trim working set. This is deprecated and must be 0.
  84. IMAGE_FILE_AGGRESSIVE_WS_TRIM = 0x0010,
  85. /// Image can handle > 2GiB addresses.
  86. IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020,
  87. /// Little endian: the LSB precedes the MSB in memory. This is deprecated
  88. /// and should be 0.
  89. IMAGE_FILE_BYTES_REVERSED_LO = 0x0080,
  90. /// Machine is based on a 32bit word architecture.
  91. IMAGE_FILE_32BIT_MACHINE = 0x0100,
  92. /// Debugging info has been removed.
  93. IMAGE_FILE_DEBUG_STRIPPED = 0x0200,
  94. /// If the image is on removable media, fully load it and copy it to swap.
  95. IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400,
  96. /// If the image is on network media, fully load it and copy it to swap.
  97. IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800,
  98. /// The image file is a system file, not a user program.
  99. IMAGE_FILE_SYSTEM = 0x1000,
  100. /// The image file is a DLL.
  101. IMAGE_FILE_DLL = 0x2000,
  102. /// This file should only be run on a uniprocessor machine.
  103. IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000,
  104. /// Big endian: the MSB precedes the LSB in memory. This is deprecated
  105. /// and should be 0.
  106. IMAGE_FILE_BYTES_REVERSED_HI = 0x8000
  107. };
  108. struct symbol {
  109. char Name[NameSize];
  110. uint32_t Value;
  111. uint16_t SectionNumber;
  112. uint16_t Type;
  113. uint8_t StorageClass;
  114. uint8_t NumberOfAuxSymbols;
  115. };
  116. enum SymbolFlags {
  117. SF_TypeMask = 0x0000FFFF,
  118. SF_TypeShift = 0,
  119. SF_ClassMask = 0x00FF0000,
  120. SF_ClassShift = 16,
  121. SF_WeakExternal = 0x01000000
  122. };
  123. enum SymbolSectionNumber {
  124. IMAGE_SYM_DEBUG = -2,
  125. IMAGE_SYM_ABSOLUTE = -1,
  126. IMAGE_SYM_UNDEFINED = 0
  127. };
  128. /// Storage class tells where and what the symbol represents
  129. enum SymbolStorageClass {
  130. SSC_Invalid = 0xff,
  131. IMAGE_SYM_CLASS_END_OF_FUNCTION = -1, ///< Physical end of function
  132. IMAGE_SYM_CLASS_NULL = 0, ///< No symbol
  133. IMAGE_SYM_CLASS_AUTOMATIC = 1, ///< Stack variable
  134. IMAGE_SYM_CLASS_EXTERNAL = 2, ///< External symbol
  135. IMAGE_SYM_CLASS_STATIC = 3, ///< Static
  136. IMAGE_SYM_CLASS_REGISTER = 4, ///< Register variable
  137. IMAGE_SYM_CLASS_EXTERNAL_DEF = 5, ///< External definition
  138. IMAGE_SYM_CLASS_LABEL = 6, ///< Label
  139. IMAGE_SYM_CLASS_UNDEFINED_LABEL = 7, ///< Undefined label
  140. IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = 8, ///< Member of structure
  141. IMAGE_SYM_CLASS_ARGUMENT = 9, ///< Function argument
  142. IMAGE_SYM_CLASS_STRUCT_TAG = 10, ///< Structure tag
  143. IMAGE_SYM_CLASS_MEMBER_OF_UNION = 11, ///< Member of union
  144. IMAGE_SYM_CLASS_UNION_TAG = 12, ///< Union tag
  145. IMAGE_SYM_CLASS_TYPE_DEFINITION = 13, ///< Type definition
  146. IMAGE_SYM_CLASS_UNDEFINED_STATIC = 14, ///< Undefined static
  147. IMAGE_SYM_CLASS_ENUM_TAG = 15, ///< Enumeration tag
  148. IMAGE_SYM_CLASS_MEMBER_OF_ENUM = 16, ///< Member of enumeration
  149. IMAGE_SYM_CLASS_REGISTER_PARAM = 17, ///< Register parameter
  150. IMAGE_SYM_CLASS_BIT_FIELD = 18, ///< Bit field
  151. /// ".bb" or ".eb" - beginning or end of block
  152. IMAGE_SYM_CLASS_BLOCK = 100,
  153. /// ".bf" or ".ef" - beginning or end of function
  154. IMAGE_SYM_CLASS_FUNCTION = 101,
  155. IMAGE_SYM_CLASS_END_OF_STRUCT = 102, ///< End of structure
  156. IMAGE_SYM_CLASS_FILE = 103, ///< File name
  157. /// Line number, reformatted as symbol
  158. IMAGE_SYM_CLASS_SECTION = 104,
  159. IMAGE_SYM_CLASS_WEAK_EXTERNAL = 105, ///< Duplicate tag
  160. /// External symbol in dmert public lib
  161. IMAGE_SYM_CLASS_CLR_TOKEN = 107
  162. };
  163. enum SymbolBaseType {
  164. IMAGE_SYM_TYPE_NULL = 0, ///< No type information or unknown base type.
  165. IMAGE_SYM_TYPE_VOID = 1, ///< Used with void pointers and functions.
  166. IMAGE_SYM_TYPE_CHAR = 2, ///< A character (signed byte).
  167. IMAGE_SYM_TYPE_SHORT = 3, ///< A 2-byte signed integer.
  168. IMAGE_SYM_TYPE_INT = 4, ///< A natural integer type on the target.
  169. IMAGE_SYM_TYPE_LONG = 5, ///< A 4-byte signed integer.
  170. IMAGE_SYM_TYPE_FLOAT = 6, ///< A 4-byte floating-point number.
  171. IMAGE_SYM_TYPE_DOUBLE = 7, ///< An 8-byte floating-point number.
  172. IMAGE_SYM_TYPE_STRUCT = 8, ///< A structure.
  173. IMAGE_SYM_TYPE_UNION = 9, ///< An union.
  174. IMAGE_SYM_TYPE_ENUM = 10, ///< An enumerated type.
  175. IMAGE_SYM_TYPE_MOE = 11, ///< A member of enumeration (a specific value).
  176. IMAGE_SYM_TYPE_BYTE = 12, ///< A byte; unsigned 1-byte integer.
  177. IMAGE_SYM_TYPE_WORD = 13, ///< A word; unsigned 2-byte integer.
  178. IMAGE_SYM_TYPE_UINT = 14, ///< An unsigned integer of natural size.
  179. IMAGE_SYM_TYPE_DWORD = 15 ///< An unsigned 4-byte integer.
  180. };
  181. enum SymbolComplexType {
  182. IMAGE_SYM_DTYPE_NULL = 0, ///< No complex type; simple scalar variable.
  183. IMAGE_SYM_DTYPE_POINTER = 1, ///< A pointer to base type.
  184. IMAGE_SYM_DTYPE_FUNCTION = 2, ///< A function that returns a base type.
  185. IMAGE_SYM_DTYPE_ARRAY = 3, ///< An array of base type.
  186. /// Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
  187. SCT_COMPLEX_TYPE_SHIFT = 4
  188. };
  189. struct section {
  190. char Name[NameSize];
  191. uint32_t VirtualSize;
  192. uint32_t VirtualAddress;
  193. uint32_t SizeOfRawData;
  194. uint32_t PointerToRawData;
  195. uint32_t PointerToRelocations;
  196. uint32_t PointerToLineNumbers;
  197. uint16_t NumberOfRelocations;
  198. uint16_t NumberOfLineNumbers;
  199. uint32_t Characteristics;
  200. };
  201. enum SectionCharacteristics {
  202. SC_Invalid = 0xffffffff,
  203. IMAGE_SCN_TYPE_NO_PAD = 0x00000008,
  204. IMAGE_SCN_CNT_CODE = 0x00000020,
  205. IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040,
  206. IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080,
  207. IMAGE_SCN_LNK_OTHER = 0x00000100,
  208. IMAGE_SCN_LNK_INFO = 0x00000200,
  209. IMAGE_SCN_LNK_REMOVE = 0x00000800,
  210. IMAGE_SCN_LNK_COMDAT = 0x00001000,
  211. IMAGE_SCN_GPREL = 0x00008000,
  212. IMAGE_SCN_MEM_PURGEABLE = 0x00020000,
  213. IMAGE_SCN_MEM_16BIT = 0x00020000,
  214. IMAGE_SCN_MEM_LOCKED = 0x00040000,
  215. IMAGE_SCN_MEM_PRELOAD = 0x00080000,
  216. IMAGE_SCN_ALIGN_1BYTES = 0x00100000,
  217. IMAGE_SCN_ALIGN_2BYTES = 0x00200000,
  218. IMAGE_SCN_ALIGN_4BYTES = 0x00300000,
  219. IMAGE_SCN_ALIGN_8BYTES = 0x00400000,
  220. IMAGE_SCN_ALIGN_16BYTES = 0x00500000,
  221. IMAGE_SCN_ALIGN_32BYTES = 0x00600000,
  222. IMAGE_SCN_ALIGN_64BYTES = 0x00700000,
  223. IMAGE_SCN_ALIGN_128BYTES = 0x00800000,
  224. IMAGE_SCN_ALIGN_256BYTES = 0x00900000,
  225. IMAGE_SCN_ALIGN_512BYTES = 0x00A00000,
  226. IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000,
  227. IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000,
  228. IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000,
  229. IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000,
  230. IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000,
  231. IMAGE_SCN_MEM_DISCARDABLE = 0x02000000,
  232. IMAGE_SCN_MEM_NOT_CACHED = 0x04000000,
  233. IMAGE_SCN_MEM_NOT_PAGED = 0x08000000,
  234. IMAGE_SCN_MEM_SHARED = 0x10000000,
  235. IMAGE_SCN_MEM_EXECUTE = 0x20000000,
  236. IMAGE_SCN_MEM_READ = 0x40000000,
  237. IMAGE_SCN_MEM_WRITE = 0x80000000
  238. };
  239. struct relocation {
  240. uint32_t VirtualAddress;
  241. uint32_t SymbolTableIndex;
  242. uint16_t Type;
  243. };
  244. enum RelocationTypeX86 {
  245. IMAGE_REL_I386_ABSOLUTE = 0x0000,
  246. IMAGE_REL_I386_DIR16 = 0x0001,
  247. IMAGE_REL_I386_REL16 = 0x0002,
  248. IMAGE_REL_I386_DIR32 = 0x0006,
  249. IMAGE_REL_I386_DIR32NB = 0x0007,
  250. IMAGE_REL_I386_SEG12 = 0x0009,
  251. IMAGE_REL_I386_SECTION = 0x000A,
  252. IMAGE_REL_I386_SECREL = 0x000B,
  253. IMAGE_REL_I386_TOKEN = 0x000C,
  254. IMAGE_REL_I386_SECREL7 = 0x000D,
  255. IMAGE_REL_I386_REL32 = 0x0014,
  256. IMAGE_REL_AMD64_ABSOLUTE = 0x0000,
  257. IMAGE_REL_AMD64_ADDR64 = 0x0001,
  258. IMAGE_REL_AMD64_ADDR32 = 0x0002,
  259. IMAGE_REL_AMD64_ADDR32NB = 0x0003,
  260. IMAGE_REL_AMD64_REL32 = 0x0004,
  261. IMAGE_REL_AMD64_REL32_1 = 0x0005,
  262. IMAGE_REL_AMD64_REL32_2 = 0x0006,
  263. IMAGE_REL_AMD64_REL32_3 = 0x0007,
  264. IMAGE_REL_AMD64_REL32_4 = 0x0008,
  265. IMAGE_REL_AMD64_REL32_5 = 0x0009,
  266. IMAGE_REL_AMD64_SECTION = 0x000A,
  267. IMAGE_REL_AMD64_SECREL = 0x000B,
  268. IMAGE_REL_AMD64_SECREL7 = 0x000C,
  269. IMAGE_REL_AMD64_TOKEN = 0x000D,
  270. IMAGE_REL_AMD64_SREL32 = 0x000E,
  271. IMAGE_REL_AMD64_PAIR = 0x000F,
  272. IMAGE_REL_AMD64_SSPAN32 = 0x0010
  273. };
  274. enum RelocationTypesARM {
  275. IMAGE_REL_ARM_ABSOLUTE = 0x0000,
  276. IMAGE_REL_ARM_ADDR32 = 0x0001,
  277. IMAGE_REL_ARM_ADDR32NB = 0x0002,
  278. IMAGE_REL_ARM_BRANCH24 = 0x0003,
  279. IMAGE_REL_ARM_BRANCH11 = 0x0004,
  280. IMAGE_REL_ARM_TOKEN = 0x0005,
  281. IMAGE_REL_ARM_BLX24 = 0x0008,
  282. IMAGE_REL_ARM_BLX11 = 0x0009,
  283. IMAGE_REL_ARM_SECTION = 0x000E,
  284. IMAGE_REL_ARM_SECREL = 0x000F,
  285. IMAGE_REL_ARM_MOV32A = 0x0010,
  286. IMAGE_REL_ARM_MOV32T = 0x0011,
  287. IMAGE_REL_ARM_BRANCH20T = 0x0012,
  288. IMAGE_REL_ARM_BRANCH24T = 0x0014,
  289. IMAGE_REL_ARM_BLX23T = 0x0015
  290. };
  291. enum COMDATType {
  292. IMAGE_COMDAT_SELECT_NODUPLICATES = 1,
  293. IMAGE_COMDAT_SELECT_ANY,
  294. IMAGE_COMDAT_SELECT_SAME_SIZE,
  295. IMAGE_COMDAT_SELECT_EXACT_MATCH,
  296. IMAGE_COMDAT_SELECT_ASSOCIATIVE,
  297. IMAGE_COMDAT_SELECT_LARGEST,
  298. IMAGE_COMDAT_SELECT_NEWEST
  299. };
  300. // Auxiliary Symbol Formats
  301. struct AuxiliaryFunctionDefinition {
  302. uint32_t TagIndex;
  303. uint32_t TotalSize;
  304. uint32_t PointerToLinenumber;
  305. uint32_t PointerToNextFunction;
  306. uint8_t unused[2];
  307. };
  308. struct AuxiliarybfAndefSymbol {
  309. uint8_t unused1[4];
  310. uint16_t Linenumber;
  311. uint8_t unused2[6];
  312. uint32_t PointerToNextFunction;
  313. uint8_t unused3[2];
  314. };
  315. struct AuxiliaryWeakExternal {
  316. uint32_t TagIndex;
  317. uint32_t Characteristics;
  318. uint8_t unused[10];
  319. };
  320. /// These are not documented in the spec, but are located in WinNT.h.
  321. enum WeakExternalCharacteristics {
  322. IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1,
  323. IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2,
  324. IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3
  325. };
  326. struct AuxiliaryFile {
  327. uint8_t FileName[18];
  328. };
  329. struct AuxiliarySectionDefinition {
  330. uint32_t Length;
  331. uint16_t NumberOfRelocations;
  332. uint16_t NumberOfLinenumbers;
  333. uint32_t CheckSum;
  334. uint16_t Number;
  335. uint8_t Selection;
  336. uint8_t unused[3];
  337. };
  338. union Auxiliary {
  339. AuxiliaryFunctionDefinition FunctionDefinition;
  340. AuxiliarybfAndefSymbol bfAndefSymbol;
  341. AuxiliaryWeakExternal WeakExternal;
  342. AuxiliaryFile File;
  343. AuxiliarySectionDefinition SectionDefinition;
  344. };
  345. /// @brief The Import Directory Table.
  346. ///
  347. /// There is a single array of these and one entry per imported DLL.
  348. struct ImportDirectoryTableEntry {
  349. uint32_t ImportLookupTableRVA;
  350. uint32_t TimeDateStamp;
  351. uint32_t ForwarderChain;
  352. uint32_t NameRVA;
  353. uint32_t ImportAddressTableRVA;
  354. };
  355. /// @brief The PE32 Import Lookup Table.
  356. ///
  357. /// There is an array of these for each imported DLL. It represents either
  358. /// the ordinal to import from the target DLL, or a name to lookup and import
  359. /// from the target DLL.
  360. ///
  361. /// This also happens to be the same format used by the Import Address Table
  362. /// when it is initially written out to the image.
  363. struct ImportLookupTableEntry32 {
  364. uint32_t data;
  365. /// @brief Is this entry specified by ordinal, or name?
  366. bool isOrdinal() const { return data & 0x80000000; }
  367. /// @brief Get the ordinal value of this entry. isOrdinal must be true.
  368. uint16_t getOrdinal() const {
  369. assert(isOrdinal() && "ILT entry is not an ordinal!");
  370. return data & 0xFFFF;
  371. }
  372. /// @brief Set the ordinal value and set isOrdinal to true.
  373. void setOrdinal(uint16_t o) {
  374. data = o;
  375. data |= 0x80000000;
  376. }
  377. /// @brief Get the Hint/Name entry RVA. isOrdinal must be false.
  378. uint32_t getHintNameRVA() const {
  379. assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!");
  380. return data;
  381. }
  382. /// @brief Set the Hint/Name entry RVA and set isOrdinal to false.
  383. void setHintNameRVA(uint32_t rva) { data = rva; }
  384. };
  385. /// @brief The DOS compatible header at the front of all PEs.
  386. struct DOSHeader {
  387. uint16_t Magic;
  388. uint16_t UsedBytesInTheLastPage;
  389. uint16_t FileSizeInPages;
  390. uint16_t NumberOfRelocationItems;
  391. uint16_t HeaderSizeInParagraphs;
  392. uint16_t MinimumExtraParagraphs;
  393. uint16_t MaximumExtraParagraphs;
  394. uint16_t InitialRelativeSS;
  395. uint16_t InitialSP;
  396. uint16_t Checksum;
  397. uint16_t InitialIP;
  398. uint16_t InitialRelativeCS;
  399. uint16_t AddressOfRelocationTable;
  400. uint16_t OverlayNumber;
  401. uint16_t Reserved[4];
  402. uint16_t OEMid;
  403. uint16_t OEMinfo;
  404. uint16_t Reserved2[10];
  405. uint32_t AddressOfNewExeHeader;
  406. };
  407. struct PEHeader {
  408. uint32_t Signature;
  409. header COFFHeader;
  410. uint16_t Magic;
  411. uint8_t MajorLinkerVersion;
  412. uint8_t MinorLinkerVersion;
  413. uint32_t SizeOfCode;
  414. uint32_t SizeOfInitializedData;
  415. uint32_t SizeOfUninitializedData;
  416. uint32_t AddressOfEntryPoint; // RVA
  417. uint32_t BaseOfCode; // RVA
  418. uint32_t BaseOfData; // RVA
  419. uint64_t ImageBase;
  420. uint32_t SectionAlignment;
  421. uint32_t FileAlignment;
  422. uint16_t MajorOperatingSystemVersion;
  423. uint16_t MinorOperatingSystemVersion;
  424. uint16_t MajorImageVersion;
  425. uint16_t MinorImageVersion;
  426. uint16_t MajorSubsystemVersion;
  427. uint16_t MinorSubsystemVersion;
  428. uint32_t Win32VersionValue;
  429. uint32_t SizeOfImage;
  430. uint32_t SizeOfHeaders;
  431. uint32_t CheckSum;
  432. uint16_t Subsystem;
  433. uint16_t DLLCharacteristics;
  434. uint64_t SizeOfStackReserve;
  435. uint64_t SizeOfStackCommit;
  436. uint64_t SizeOfHeapReserve;
  437. uint64_t SizeOfHeapCommit;
  438. uint32_t LoaderFlags;
  439. uint32_t NumberOfRvaAndSize;
  440. };
  441. struct DataDirectory {
  442. uint32_t RelativeVirtualAddress;
  443. uint32_t Size;
  444. };
  445. enum WindowsSubsystem {
  446. IMAGE_SUBSYSTEM_UNKNOWN = 0, ///< An unknown subsystem.
  447. IMAGE_SUBSYSTEM_NATIVE = 1, ///< Device drivers and native Windows processes
  448. IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, ///< The Windows GUI subsystem.
  449. IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, ///< The Windows character subsystem.
  450. IMAGE_SUBSYSTEM_POSIX_CUI = 7, ///< The POSIX character subsystem.
  451. IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9, ///< Windows CE.
  452. IMAGE_SUBSYSTEM_EFI_APPLICATION = 10, ///< An EFI application.
  453. IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11, ///< An EFI driver with boot
  454. /// services.
  455. IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12, ///< An EFI driver with run-time
  456. /// services.
  457. IMAGE_SUBSYSTEM_EFI_ROM = 13, ///< An EFI ROM image.
  458. IMAGE_SUBSYSTEM_XBOX = 14 ///< XBOX.
  459. };
  460. enum DLLCharacteristics {
  461. /// DLL can be relocated at load time.
  462. IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040,
  463. /// Code integrity checks are enforced.
  464. IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY = 0x0080,
  465. IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100, ///< Image is NX compatible.
  466. /// Isolation aware, but do not isolate the image.
  467. IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION = 0x0200,
  468. /// Does not use structured exception handling (SEH). No SEH handler may be
  469. /// called in this image.
  470. IMAGE_DLL_CHARACTERISTICS_NO_SEH = 0x0400,
  471. /// Do not bind the image.
  472. IMAGE_DLL_CHARACTERISTICS_NO_BIND = 0x0800,
  473. IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER = 0x2000, ///< A WDM driver.
  474. /// Terminal Server aware.
  475. IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000
  476. };
  477. enum DebugType {
  478. IMAGE_DEBUG_TYPE_UNKNOWN = 0,
  479. IMAGE_DEBUG_TYPE_COFF = 1,
  480. IMAGE_DEBUG_TYPE_CODEVIEW = 2,
  481. IMAGE_DEBUG_TYPE_FPO = 3,
  482. IMAGE_DEBUG_TYPE_MISC = 4,
  483. IMAGE_DEBUG_TYPE_EXCEPTION = 5,
  484. IMAGE_DEBUG_TYPE_FIXUP = 6,
  485. IMAGE_DEBUG_TYPE_OMAP_TO_SRC = 7,
  486. IMAGE_DEBUG_TYPE_OMAP_FROM_SRC = 8,
  487. IMAGE_DEBUG_TYPE_BORLAND = 9,
  488. IMAGE_DEBUG_TYPE_CLSID = 11
  489. };
  490. enum BaseRelocationType {
  491. IMAGE_REL_BASED_ABSOLUTE = 0,
  492. IMAGE_REL_BASED_HIGH = 1,
  493. IMAGE_REL_BASED_LOW = 2,
  494. IMAGE_REL_BASED_HIGHLOW = 3,
  495. IMAGE_REL_BASED_HIGHADJ = 4,
  496. IMAGE_REL_BASED_MIPS_JMPADDR = 5,
  497. IMAGE_REL_BASED_ARM_MOV32A = 5,
  498. IMAGE_REL_BASED_ARM_MOV32T = 7,
  499. IMAGE_REL_BASED_MIPS_JMPADDR16 = 9,
  500. IMAGE_REL_BASED_DIR64 = 10
  501. };
  502. enum ImportType {
  503. IMPORT_CODE = 0,
  504. IMPORT_DATA = 1,
  505. IMPORT_CONST = 2
  506. };
  507. enum ImportNameType {
  508. /// Import is by ordinal. This indicates that the value in the Ordinal/Hint
  509. /// field of the import header is the import's ordinal. If this constant is
  510. /// not specified, then the Ordinal/Hint field should always be interpreted
  511. /// as the import's hint.
  512. IMPORT_ORDINAL = 0,
  513. /// The import name is identical to the public symbol name
  514. IMPORT_NAME = 1,
  515. /// The import name is the public symbol name, but skipping the leading ?,
  516. /// @, or optionally _.
  517. IMPORT_NAME_NOPREFIX = 2,
  518. /// The import name is the public symbol name, but skipping the leading ?,
  519. /// @, or optionally _, and truncating at the first @.
  520. IMPORT_NAME_UNDECORATE = 3
  521. };
  522. struct ImportHeader {
  523. uint16_t Sig1; ///< Must be IMAGE_FILE_MACHINE_UNKNOWN (0).
  524. uint16_t Sig2; ///< Must be 0xFFFF.
  525. uint16_t Version;
  526. uint16_t Machine;
  527. uint32_t TimeDateStamp;
  528. uint32_t SizeOfData;
  529. uint16_t OrdinalHint;
  530. uint16_t TypeInfo;
  531. ImportType getType() const {
  532. return static_cast<ImportType>(TypeInfo & 0x3);
  533. }
  534. ImportNameType getNameType() const {
  535. return static_cast<ImportNameType>((TypeInfo & 0x1C) >> 3);
  536. }
  537. };
  538. } // End namespace COFF.
  539. } // End namespace llvm.
  540. #endif