9 added + 8 modified, total 17 files
reactos/include
diff -u -r1.1 -r1.1.2.1
--- elf.h 25 Nov 2004 18:24:08 -0000 1.1
+++ elf.h 8 Dec 2004 20:01:38 -0000 1.1.2.1
@@ -1,488 +1,20 @@
-#ifndef __INCLUDE_ELF_H
-#define __INCLUDE_ELF_H
+#ifndef _REACTOS_ELF_H_
+#define _REACTOS_ELF_H_ 1
-
-#ifdef __64BITS__ /* FIXME: how to check for 64 bits? */
-# define ELF_ARCH_SIZE 64
-#else
-# define ELF_ARCH_SIZE 32
-#endif
-
-
-/* 32-bit data types */
-typedef unsigned long ELF32_ADDR; /* Unsigned program address */
-typedef unsigned short ELF32_HALF; /* Unsigned medium integer */
-typedef unsigned long ELF32_OFF; /* Unsigned file offset */
-typedef unsigned long ELF32_SWORD; /* Signed large integer */
-typedef unsigned long ELF32_WORD; /* Unsigned large integer */
-typedef ELF32_OFF ELF32_HASHELT; /* Hash element? */
-
-/* Elf data encodings */
-#define IMAGE_ELF_DATA_NONE 0 /* Invalid data encoding */
-#define IMAGE_ELF_DATA_2LSB 1 /* 2's complement, LSB first */
-#define IMAGE_ELF_DATA_2MSB 2 /* 2's complement, MSB first */
-
-/* Elf object file types */
-#define IMAGE_ELF_TYPE_NONE 0 /* No file type */
-#define IMAGE_ELF_TYPE_REL 1 /* Relocatable file */
-#define IMAGE_ELF_TYPE_EXEC 2 /* Executable file */
-#define IMAGE_ELF_TYPE_DYN 3 /* Shared object file */
-#define IMAGE_ELF_TYPE_CORE 4 /* Core file */
-
-/* Elf machines */
-#define IMAGE_ELF_MACHINE_NONE 0 /* No machine */
-#define IMAGE_ELF_MACHINE_M32 1 /* AT&T WE 32100 */
-#define IMAGE_ELF_MACHINE_SPARC 2 /* SPARC */
-#define IMAGE_ELF_MACHINE_386 3 /* Intel 80386 */
-#define IMAGE_ELF_MACHINE_68K 4 /* Motorola 68000 */
-#define IMAGE_ELF_MACHINE_88K 5 /* Motorola 88000 */
- /* 6 is reserved */
-#define IMAGE_ELF_MACHINE_860 7 /* Intel 80860 */
-#define IMAGE_ELF_MACHINE_MIPS 8 /* MIPS RS3000 (MIPS I) */
-#define IMAGE_ELF_MACHINE_S370 9 /* IBM System/370 Processor */
-#define IMAGE_ELF_MACHINE_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
- /* 11-14 are reserved */
-#define IMAGE_ELF_MACHINE_PARISC 15 /* Hewlett-Packard PA-RISC */
- /* 16 is reserved */
-#define IMAGE_ELF_MACHINE_VPP500 17 /* Fujitsu VPP500 */
-#define IMAGE_ELF_MACHINE_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
-#define IMAGE_ELF_MACHINE_960 19 /* Intel 80960 */
-#define IMAGE_ELF_MACHINE_PPC 20 /* PowerPC */
-#define IMAGE_ELF_MACHINE_PPC64 21 /* 64-bit PowerPC */
- /* 22-35 are reserved */
-#define IMAGE_ELF_MACHINE_V800 36 /* NEC V800 */
-#define IMAGE_ELF_MACHINE_FR20 37 /* Fujitsu FR20 */
-#define IMAGE_ELF_MACHINE_RH32 38 /* TRW RH-32 */
-#define IMAGE_ELF_MACHINE_RCE 39 /* Motorola RCE */
-#define IMAGE_ELF_MACHINE_ARM 40 /* Advanced RISC Machines ARM */
-#define IMAGE_ELF_MACHINE_ALPHA 41 /* Digital Alpha */
-#define IMAGE_ELF_MACHINE_SH 42 /* Hitachi SH */
-#define IMAGE_ELF_MACHINE_SPARCV9 43 /* SPARC Version 9 */
-#define IMAGE_ELF_MACHINE_TRICORE 44 /* Siemens Tricore embedded processor */
-#define IMAGE_ELF_MACHINE_ARC 45 /* Argonaut RISC Core, Argonaut Technologies Inc. */
-#define IMAGE_ELF_MACHINE_H8_300 46 /* Hitachi H8/300 */
-#define IMAGE_ELF_MACHINE_H8_300H 47 /* Hitachi H8/300H */
-#define IMAGE_ELF_MACHINE_H8S 48 /* Hitachi H8S */
-#define IMAGE_ELF_MACHINE_H8_500 49 /* Hitachi H8/500 */
-#define IMAGE_ELF_MACHINE_IA_64 50 /* Intel IA-64 processor architecture */
-#define IMAGE_ELF_MACHINE_MIPS_X 51 /* Stanford MIPS-X */
-#define IMAGE_ELF_MACHINE_COLDFIRE 52 /* Motorola ColdFire */
-#define IMAGE_ELF_MACHINE_68HC12 53 /* Motorola M68HC12 */
-#define IMAGE_ELF_MACHINE_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
-#define IMAGE_ELF_MACHINE_PCP 55 /* Siemens PCP */
-#define IMAGE_ELF_MACHINE_NCPU 56 /* Sony nCPU embedded RISC processor */
-#define IMAGE_ELF_MACHINE_NDR1 57 /* Denso NDR1 microprocessor */
-#define IMAGE_ELF_MACHINE_STARCORE 58 /* Motorola Star*Core processor */
-#define IMAGE_ELF_MACHINE_ME16 59 /* Toyota ME16 processor */
-#define IMAGE_ELF_MACHINE_ST100 60 /* STMicroelectronics ST100 processor */
-#define IMAGE_ELF_MACHINE_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded processor family */
- /* 62-65 are reserved */
-#define IMAGE_ELF_MACHINE_FX66 66 /* Siemens FX66 microcontroller */
-#define IMAGE_ELF_MACHINE_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */
-#define IMAGE_ELF_MACHINE_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */
-#define IMAGE_ELF_MACHINE_68HC16 69 /* Motorola MC68HC16 Microcontroller */
-#define IMAGE_ELF_MACHINE_68HC11 70 /* Motorola MC68HC11 Microcontroller */
-#define IMAGE_ELF_MACHINE_68HC08 71 /* Motorola MC68HC08 Microcontroller */
-#define IMAGE_ELF_MACHINE_68HC05 72 /* Motorola MC68HC05 Microcontroller */
-#define IMAGE_ELF_MACHINE_SVX 73 /* Silicon Graphics SVx */
-#define IMAGE_ELF_MACHINE_ST19 74 /* STMicroelectronics ST19 8-bit microcontroller */
-#define IMAGE_ELF_MACHINE_VAX 75 /* Digital VAX */
-#define IMAGE_ELF_MACHINE_CRIS 76 /* Axis Communications 32-bit embedded processor */
-#define IMAGE_ELF_MACHINE_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */
-#define IMAGE_ELF_MACHINE_FIREPATH 78 /* Element 14 64-bit DSP Processor */
-#define IMAGE_ELF_MACHINE_ZSP 79 /* LSI Logic 16-bit DSP Processor */
-#define IMAGE_ELF_MACHINE_MMIX 80 /* Donald Knuth's educational 64-bit processor */
-#define IMAGE_ELF_MACHINE_HUANY 81 /* Harvard University machine-independent object files */
-#define IMAGE_ELF_MACHINE_PRISM 82 /* SiTera Prism */
-#define IMAGE_ELF_MACHINE_AVR 83 /* Atmel AVR 8-bit microcontroller */
-#define IMAGE_ELF_MACHINE_FR30 84 /* Fujitsu FR30 */
-#define IMAGE_ELF_MACHINE_D10V 85 /* Mitsubishi D10V */
-#define IMAGE_ELF_MACHINE_D30V 86 /* Mitsubishi D30V */
-#define IMAGE_ELF_MACHINE_V850 87 /* NEC v850 */
-#define IMAGE_ELF_MACHINE_M32R 88 /* Mitsubishi M32R */
-#define IMAGE_ELF_MACHINE_MN10300 89 /* Matsushita MN10300 */
-#define IMAGE_ELF_MACHINE_MN10200 90 /* Matsushita MN10200 */
-#define IMAGE_ELF_MACHINE_PJ 91 /* picoJava */
-#define IMAGE_ELF_MACHINE_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
-
-/* Elf versions */
-#define IMAGE_ELF_VERSION_NONE 0 /* Invalid version */
-#define IMAGE_ELF_VERSION_CURRENT 1 /* Current version */
-
-/* Elf identification */
-#define IMAGE_ELF_SIZEOF_IDENT 16
-#define IMAGE_ELF_IDENT_MAGIC0 0 /* Magic */
-#define IMAGE_ELF_IDENT_MAGIC1 1
-#define IMAGE_ELF_IDENT_MAGIC2 2
-#define IMAGE_ELF_IDENT_MAGIC3 3
-#define IMAGE_ELF_IDENT_CLASS 4 /* File class */
-#define IMAGE_ELF_IDENT_DATA 5 /* Data encoding */
-#define IMAGE_ELF_IDENT_VERSION 6 /* File version */
-#define IMAGE_ELF_IDENT_OSABI 7 /* Operating system/ABI identification */
-#define IMAGE_ELF_IDENT_ABIVERSION 8 /* ABI version */
-#define IMAGE_ELF_IDENT_PAD 9 /* Start of padding bytes */
-
-/* Magic numbers */
-#define IMAGE_ELF_MAGIC0 0x7f
-#define IMAGE_ELF_MAGIC1 'E'
-#define IMAGE_ELF_MAGIC2 'L'
-#define IMAGE_ELF_MAGIC3 'F'
-
-/* Elf file classes */
-#define IMAGE_ELF_CLASS_NONE 0 /* Invalid class */
-#define IMAGE_ELF_CLASS_32 1 /* 32-bit object */
-#define IMAGE_ELF_CLASS_64 2 /* 64-bit object */
-
-/* Check elf magic */
-#define IMAGE_IS_ELF(hdr) ((hdr).Ident[IMAGE_ELF_IDENT_MAGIC0] == IMAGE_ELF_MAGIC0 && \
- (hdr).Ident[IMAGE_ELF_IDENT_MAGIC1] == IMAGE_ELF_MAGIC1 && \
- (hdr).Ident[IMAGE_ELF_IDENT_MAGIC2] == IMAGE_ELF_MAGIC2 && \
- (hdr).Ident[IMAGE_ELF_IDENT_MAGIC3] == IMAGE_ELF_MAGIC3)
-
-
-
-/* 32-bit Elf header */
-typedef struct _IMAGE_ELF32_HEADER {
- unsigned char Ident[IMAGE_ELF_SIZEOF_IDENT]; /* Identification */
- ELF32_HALF Type; /* Object file type */
- ELF32_HALF Machine; /* Required architecture */
- ELF32_WORD Version; /* Object file version */
- ELF32_ADDR Entry; /* Virtual address of entry point */
- ELF32_OFF PhOff; /* Program header table offset in file */
- ELF32_OFF ShOff; /* Section header offset in file */
- ELF32_WORD Flags; /* Processor specific flags - zero for SPARC and x86 */
- ELF32_HALF EhSize; /* Elf header size in bytes (this struct) */
- ELF32_HALF PhEntSize; /* Size of an entry in the program header table */
- ELF32_HALF PhNum; /* Number of entries in the program header table */
- ELF32_HALF ShEntSize; /* Size of an entry in the section header table */
- ELF32_HALF ShNum; /* Number of entries in the section header table */
- ELF32_HALF ShStrNdx; /* Index into the section header table for the entry of the section name string table */
-} IMAGE_ELF32_HEADER, *PIMAGE_ELF32_HEADER;
-
-
-
-
-
-/* Special section indexes */
-#define IMAGE_ELF_SECTION_INDEX_UNDEF 0
-/*#define IMAGE_ELF_SECTION_INDEX_LORESERVE 0xff00
-#define IMAGE_ELF_SECTION_INDEX_LOPROC 0xff00
-#define IMAGE_ELF_SECTION_INDEX_HIPROC 0xff1f*/
-#define IMAGE_ELF_SECTION_INDEX_ABS 0xfff1
-#define IMAGE_ELF_SECTION_INDEX_COMMON 0xfff2
-/*#define IMAGE_ELF_SECTION_INDEX_HIRESERVE 0xffff*/
-
-/* Section types */
-#define IMAGE_ELF_SECTION_TYPE_NULL 0 /* Incactive section header */
-#define IMAGE_ELF_SECTION_TYPE_PROGBITS 1 /* Program defined section */
-#define IMAGE_ELF_SECTION_TYPE_SYMTAB 2 /* Symbol table (for link editing) */
-#define IMAGE_ELF_SECTION_TYPE_STRTAB 3 /* String table */
-#define IMAGE_ELF_SECTION_TYPE_RELA 4 /* Relocation table (with explicit addends) */
-#define IMAGE_ELF_SECTION_TYPE_HASH 5 /* Symbol hash table */
-#define IMAGE_ELF_SECTION_TYPE_DYNAMIC 6 /* Information for dynamic linking */
-#define IMAGE_ELF_SECTION_TYPE_NOTE 7 /* Note section ;-) */
-#define IMAGE_ELF_SECTION_TYPE_NOBITS 8 /* Occupies no space in the file, otherwise like PROGBITS */
-#define IMAGE_ELF_SECTION_TYPE_REL 9 /* Relocation table (without explicit addends) */
-#define IMAGE_ELF_SECTION_TYPE_SHLIB 10 /* Reserved, unspecified */
-#define IMAGE_ELF_SECTION_TYPE_DYNSYM 11 /* Symbol table (for dynamic linking) */
-/*#define IMAGE_ELF_SECTION_TYPE_LOPROC 0x70000000
-#define IMAGE_ELF_SECTION_TYPE_HIPROC 0x7fffffff
-#define IMAGE_ELF_SECTION_TYPE_LOUSER 0x80000000
-#define IMAGE_ELF_SECTION_TYPE_HIUSER 0xffffffff*/
-
-/* Section flags/attributes */
-#define SHF_WRITE 0x1 /* Section must be writeable */
-#define SHF_ALLOC 0x2 /* Section must be loaded/mapped into memory */
-#define SHF_EXECINSTR 0x4 /* The section contains executable code */
-/*#define SHF_MASKPROC 0xf0000000*/
-
-/* 32-bit Section header entry */
-typedef struct _IMAGE_ELF32_SECTION_HEADER {
- ELF32_WORD Name; /* Name of the section (index into the section header string table) */
- ELF32_WORD Type; /* Type of section */
- ELF32_WORD Flags; /* Attributes */
- ELF32_ADDR Addr; /* Virtual address to load section at */
- ELF32_OFF Offset; /* Offset into the file of the section's data */
- ELF32_WORD Size; /* Size of the section */
- ELF32_WORD Link; /* Section header table index link... */
- ELF32_WORD Info; /* Extra information... */
- ELF32_WORD AddrAlign; /* Required alignment */
- ELF32_WORD EntSize; /* Size of entries in the table */
-} IMAGE_ELF32_SECTION_HEADER, *PIMAGE_ELF32_SECTION_HEADER;
-
-
-
-
-
-/* Symbol table indexes */
-#define IMAGE_ELF_SYMBOL_INDEX_UNDEF 0 /* Undefined symbol */
-
-/* Symbol binding/types */
-#define IMAGE_ELF32_SYMBOL_BIND(Info) ((Info) >> 4)
-#define IMAGE_ELF32_SYMBOL_TYPE(Info) ((Info) & 0x0f)
-#define IMAGE_ELF32_SYMBOL_INFO(Bind, Type) (((Bind) << 4) | ((Type) & 0x0f))
-
-#define IMAGE_ELF_SYMBOL_BINDING_LOCAL 0 /* Local ("static") symbol */
-#define IMAGE_ELF_SYMBOL_BINDING_GLOBAL 1 /* Global symbol */
-#define IMAGE_ELF_SYMBOL_BINDING_WEAK 2 /* Weak symbol... */
-/*#define IMAGE_ELF_SYMBOL_BINDING_LOPROC 13
-#define IMAGE_ELF_SYMBOL_BINDING_HIPROC 15*/
-
-#define IMAGE_ELF_SYMBOL_TYPE_NOTYPE 0 /* Unspecified symbol type */
-#define IMAGE_ELF_SYMBOL_TYPE_OBJECT 1 /* Data object (i.e. an array, variable, ...) */
-#define IMAGE_ELF_SYMBOL_TYPE_FUNC 2 /* Function (or other executable code) */
-#define IMAGE_ELF_SYMBOL_TYPE_SECTION 3 /* Symbol for relocating (usually has local binding) */
-#define IMAGE_ELF_SYMBOL_TYPE_FILE 4 /* Name of the associated source file */
-#define IMAGE_ELF_SYMBOL_TYPE_LOPROC 13
-#define IMAGE_ELF_SYMBOL_TYPE_HIPROC 15
-
-/* 32-bit Symbol entry */
-typedef struct _IMAGE_ELF32_SYMBOL {
- ELF32_WORD Name; /* Symbol name (index into the symbol string table) */
- ELF32_ADDR Value; /* Value of symbol */
- ELF32_WORD Size; /* Size of symbol (0 means unknown) */
- unsigned char Info; /* Type and binding attributes */
- unsigned char Other; /* Unused - 0 */
- ELF32_HALF Shndx; /* Section index */
-} IMAGE_ELF32_SYMBOL, *PIMAGE_ELF32_SYMBOL;
-
-
-
-
-
-/* Relocation macros */
-#define IMAGE_ELF32_RELOC_SYM(Info) ((Info) >> 8)
-#define IMAGE_ELF32_RELOC_TYPE(Info) ((unsigned char)(Info))
-#define IMAGE_ELF32_RELOC_INFO(Sym,Type) (((Sym) << 8) | (unsigned char)(Type))
-
-/* 386 Relocation types */
-#define IMAGE_ELF_RELOC_386_NONE 0 /* none */
-#define IMAGE_ELF_RELOC_386_32 1
-#define IMAGE_ELF_RELOC_386_PC32 2
-#define IMAGE_ELF_RELOC_386_GOT32 3
-#define IMAGE_ELF_RELOC_386_PLT32 4
-#define IMAGE_ELF_RELOC_386_COPY 5
-#define IMAGE_ELF_RELOC_386_GLOB_DAT 6
-#define IMAGE_ELF_RELOC_386_JMP_SLOT 7
-#define IMAGE_ELF_RELOC_386_RELATIVE 8
-#define IMAGE_ELF_RELOC_386_GOTOFF 9
-#define IMAGE_ELF_RELOC_386_GOTPC 10
-
-/* 386 TLS Relocation types */
-#define IMAGE_ELF_RELOC_386_TLS_GD_PLT 12
-#define IMAGE_ELF_RELOC_386_TLS_LDM_PLT 13
-#define IMAGE_ELF_RELOC_386_TLS_TPOFF 14
-#define IMAGE_ELF_RELOC_386_TLS_IE 15
-#define IMAGE_ELF_RELOC_386_TLS_GOTIE 16
-#define IMAGE_ELF_RELOC_386_TLS_LE 17
-#define IMAGE_ELF_RELOC_386_TLS_GD 18
-#define IMAGE_ELF_RELOC_386_TLS_LDM 19
-#define IMAGE_ELF_RELOC_386_TLS_LDO_32 32
-#define IMAGE_ELF_RELOC_386_TLS_DTPMOD32 35
-#define IMAGE_ELF_RELOC_386_TLS_DTPOFF32 36
-
-/* 32-bit Relocation entries */
-typedef struct _IMAGE_ELF32_RELOC {
- ELF32_ADDR Offset; /* Section offset/virtual address */
- ELF32_WORD Info; /* Symbol table index/relocation type */
-} IMAGE_ELF32_RELOC, *PIMAGE_ELF32_RELOC;
-
-typedef struct _IMAGE_ELF32_RELOCA {
- ELF32_ADDR Offset; /* Section offset/virtual address */
- ELF32_WORD Info; /* Symbol table index/relocation type */
- ELF32_SWORD Addend; /* Addend */
-} IMAGE_ELF32_RELOCA, *PIMAGE_ELF32_RELOCA;
-
-
-
-
-
-/* Program header/segment types */
-#define IMAGE_ELF_SEGMENT_TYPE_NULL 0 /* Unused array entry */
-#define IMAGE_ELF_SEGMENT_TYPE_LOAD 1 /* Loadable segment */
-#define IMAGE_ELF_SEGMENT_TYPE_DYNAMIC 2 /* Dynamic linking info... */
-#define IMAGE_ELF_SEGMENT_TYPE_INTERP 3 /* Interpreter */
-#define IMAGE_ELF_SEGMENT_TYPE_NOTE 4 /* Note... */
-#define IMAGE_ELF_SEGMENT_TYPE_SHLIB 5 /* Reserved but unspecified */
-#define IMAGE_ELF_SEGMENT_TYPE_PHDR 6 /* Program header table */
-#define IMAGE_ELF_SEGMENT_TYPE_TLS 7 /* Thread local storage */
-
-#define IMAGE_ELF_SEGMENT_TYPE_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */
-#define IMAGE_ELF_SEGMENT_TYPE_GNU_STACK 0x6474e551 /* Indicates stack executability */
-/*#define IMAGE_ELF_SEGMENT_TYPE_LOPROC 0x70000000
-#define IMAGE_ELF_SEGMENT_TYPE_HIPROC 0x7fffffff*/
-
-/* Program header/segment flags */
-#define IMAGE_ELF_SEGMENT_FLAG_EXEC 0x01
-#define IMAGE_ELF_SEGMENT_FLAG_WRITE 0x02
-#define IMAGE_ELF_SEGMENT_FLAG_READ 0x04
-/*#define IMAGE_ELF_SEGMENT_FLAG_MASKPROC 0xf0000000*/
-
-/* 32-bit Program header entry */
-typedef struct _IMAGE_ELF32_PROGRAM_HEADER {
- ELF32_WORD Type; /* Type of segment */
- ELF32_OFF Offset; /* File offset of segment data */
- ELF32_ADDR VAddr; /* Virtual address to load segment at */
- ELF32_ADDR PAddr; /* Physical address to load segment at */
- ELF32_WORD FileSz; /* Size in file of segment */
- ELF32_WORD MemSz; /* Size in memory of segment */
- ELF32_WORD Flags; /* Flags of segment */
- ELF32_WORD Align; /* Required alignment */
-} IMAGE_ELF32_PROGRAM_HEADER, *PIMAGE_ELF32_PROGRAM_HEADER;
-
-
-
-
-
-/* Dynamic array tags */
-#define IMAGE_ELF_DYNAMIC_TAG_NULL 0 /* End of array */
-#define IMAGE_ELF_DYNAMIC_TAG_NEEDED 1 /* Dependency */
-#define IMAGE_ELF_DYNAMIC_TAG_PLTRELSZ 2 /* Size in bytes of the relocation entries associated with the plt */
-#define IMAGE_ELF_DYNAMIC_TAG_PLTGOT 3 /* Address associated with got/plt */
-#define IMAGE_ELF_DYNAMIC_TAG_HASH 4 /* Hash table for symbol table indicated by SYMTAB */
-#define IMAGE_ELF_DYNAMIC_TAG_STRTAB 5 /* Address of string table */
-#define IMAGE_ELF_DYNAMIC_TAG_SYMTAB 6 /* Address of the symbol table */
-#define IMAGE_ELF_DYNAMIC_TAG_RELA 7 /* Address of reloc table with addends */
-#define IMAGE_ELF_DYNAMIC_TAG_RELASZ 8 /* Size of reloc table in bytes */
-#define IMAGE_ELF_DYNAMIC_TAG_RELAENT 9 /* Size of reloc table entry in bytes? */
-#define IMAGE_ELF_DYNAMIC_TAG_STRSZ 10 /* Size of the string table in bytes */
-#define IMAGE_ELF_DYNAMIC_TAG_SYMENT 11 /* Size of symbol table entry in bytes */
-#define IMAGE_ELF_DYNAMIC_TAG_INIT 12 /* Address of initialization function */
-#define IMAGE_ELF_DYNAMIC_TAG_FINI 13 /* Address of termination function */
-#define IMAGE_ELF_DYNAMIC_TAG_SONAME 14 /* Name of the shared object (string table offset) */
-#define IMAGE_ELF_DYNAMIC_TAG_RPATH 15 /* Library search path (string table offset) */
-#define IMAGE_ELF_DYNAMIC_TAG_SYMBOLIC 16 /* Alter runtime-linkers symbol resolution... */
-#define IMAGE_ELF_DYNAMIC_TAG_REL 17 /* Address of reloc table without addends */
-#define IMAGE_ELF_DYNAMIC_TAG_RELSZ 18 /* Size of reloc table in bytes */
-#define IMAGE_ELF_DYNAMIC_TAG_RELENT 19 /* Size of reloc table entry in bytes? */
-#define IMAGE_ELF_DYNAMIC_TAG_PLTREL 20 /* Type of relocation entry for plt (...TAG_REL or ...TAG_RELA) */
-#define IMAGE_ELF_DYNAMIC_TAG_DEBUG 21 /* Used for debugging */
-#define IMAGE_ELF_DYNAMIC_TAG_TEXTREL 22 /* If present informs the linker that a relocation might update a non-writable segment */
-#define IMAGE_ELF_DYNAMIC_TAG_JMPREL 23 /* Address of relocation entries associated solely with the plt */
-#define IMAGE_ELF_DYNAMIC_TAG_FILTER 24 /* Specifies the name of a shared objects for which this one acts as a filter */
-
-#define IMAGE_ELF_DYNAMIC_TAG_RUNPATH 29 /* String table offset of a null-terminated library search path string. */
-#define IMAGE_ELF_DYNAMIC_TAG_FLAGS 30 /* Object specific flag values. */
-
-/* Dynamic flags (for IMAGE_ELF_DYNAMIC_TAG_FLAGS) */
-#define IMAGE_ELF_DYNAMIC_FLAG_ORIGIN 0x0001 /* Indicates that the object being loaded may make reference to the $ORIGIN substitution string.*/
-#define IMAGE_ELF_DYNAMIC_FLAG_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */
-#define IMAGE_ELF_DYNAMIC_FLAG_TEXTREL 0x0004 /* Indicates there may be relocations in non-writable segments. */
-#define IMAGE_ELF_DYNAMIC_FLAG_BIND_NOW 0x0008 /* Indicates that the dynamic linker should process all relocations for the object
- containing this entry before transferring control to the program. */
-#define IMAGE_ELF_DYNAMIC_FLAG_STATIC_TLS 0x0010 /* Indicates that the shared object or executable contains code using a static
- thread-local storage scheme. */
-
-/* Dynamic array entry */
-typedef struct _IMAGE_ELF32_DYNAMIC {
- ELF32_SWORD Tag;
- union {
- ELF32_WORD Val;
- ELF32_ADDR Ptr;
- } Un;
-} IMAGE_ELF32_DYNAMIC, *PIMAGE_ELF32_DYNAMIC;
-
-
-
-
-
-/* Auxiliary types */
-#define IMAGE_ELF_AUX_TYPE_NULL 0 /* Terminates the vector. */
-#define IMAGE_ELF_AUX_TYPE_IGNORE 1 /* Ignored entry. */
-#define IMAGE_ELF_AUX_TYPE_EXECFD 2 /* File descriptor of program to load. */
-#define IMAGE_ELF_AUX_TYPE_PHDR 3 /* Program header of program already loaded. */
-#define IMAGE_ELF_AUX_TYPE_PHENT 4 /* Size of each program header entry. */
-#define IMAGE_ELF_AUX_TYPE_PHNUM 5 /* Number of program header entries. */
-#define IMAGE_ELF_AUX_TYPE_PAGESZ 6 /* Page size in bytes. */
-#define IMAGE_ELF_AUX_TYPE_BASE 7 /* Interpreter's base address. */
-#define IMAGE_ELF_AUX_TYPE_FLAGS 8 /* Flags (unused for i386). */
-#define IMAGE_ELF_AUX_TYPE_ENTRY 9 /* Where interpreter should transfer control. */
+/* Machine-independent and word-size-independent definitions */
+#include <elf/common.h>
/*
- * The following non-standard values are used for passing information
- * from John Polstra's testbed program to the dynamic linker. These
- * are expected to go away soon.
- *
- * Unfortunately, these overlap the Linux non-standard values, so they
- * must not be used in the same context.
+ * Word-size-dependent definitions. All ReactOS builds support all of them,
+ * even if (obviously) code for the wrong architecture cannot be executed - the
+ * files can still be used in machine-independent ways, e.g. as resource DLLs
*/
-#define IMAGE_ELF_AUX_TYPE_BRK 10 /* Starting point for sbrk and brk. */
-#define IMAGE_ELF_AUX_TYPE_DEBUG 11 /* Debugging level. */
+#include <elf/elf32.h>
+#include <elf/elf64.h>
-/*
- * The following non-standard values are used in Linux ELF binaries.
- */
-#define IMAGE_ELF_AUX_TYPE_NOTELF 10 /* Program is not ELF ?? */
-#define IMAGE_ELF_AUX_TYPE_UID 11 /* Real uid. */
-#define IMAGE_ELF_AUX_TYPE_EUID 12 /* Effective uid. */
-#define IMAGE_ELF_AUX_TYPE_GID 13 /* Real gid. */
-#define IMAGE_ELF_AUX_TYPE_EGID 14 /* Effective gid. */
+/* Machine-dependent definitions */
+#include <elf/machine.h>
-#define IMAGE_ELF_AUX_TYPE_COUNT 15 /* Count of defined aux entry types. */
-
-
-/* Auxiliary vector entry on initial stack */
-typedef struct _IMAGE_ELF32_AUXINFO {
- ELF32_SWORD Type; /* Entry type. */
- union {
- ELF32_SWORD Val; /* Integer value. */
- ELF32_ADDR Ptr; /* Address. */
- void (*Fcn)(void); /* Function pointer (not used). */
- } Un;
-} IMAGE_ELF32_AUXINFO, *PIMAGE_ELF32_AUXINFO;
-
-
-
-
-
-/* arch data types */
-
-#if ELF_ARCH_SIZE == 32
-
-#define IMAGE_ELF_SYMBOL_BIND(args...) IMAGE_ELF32_SYMBOL_BIND(args)
-#define IMAGE_ELF_SYMBOL_TYPE(args...) IMAGE_ELF32_SYMBOL_TYPE(args)
-#define IMAGE_ELF_SYMBOL_INFO(args...) IMAGE_ELF32_SYMBOL_INFO(args)
-
-#define IMAGE_ELF_RELOC_SYM(args...) IMAGE_ELF32_RELOC_SYM(args)
-#define IMAGE_ELF_RELOC_TYPE(args...) IMAGE_ELF32_RELOC_TYPE(args)
-#define IMAGE_ELF_RELOC_INFO(args...) IMAGE_ELF32_RELOC_INFO(args)
-
-typedef ELF32_ADDR ELF_ADDR;
-typedef ELF32_HALF ELF_HALF;
-typedef ELF32_OFF ELF_OFF;
-typedef ELF32_SWORD ELF_SWORD;
-typedef ELF32_WORD ELF_WORD;
-typedef ELF32_HASHELT ELF_HASHELT;
-
-typedef IMAGE_ELF32_HEADER IMAGE_ELF_HEADER, *PIMAGE_ELF_HEADER;
-typedef IMAGE_ELF32_SECTION_HEADER IMAGE_ELF_SECTION_HEADER, *PIMAGE_ELF_SECTION_HEADER;
-typedef IMAGE_ELF32_SYMBOL IMAGE_ELF_SYMBOL, *PIMAGE_ELF_SYMBOL;
-typedef IMAGE_ELF32_RELOC IMAGE_ELF_RELOC, *PIMAGE_ELF_RELOC;
-typedef IMAGE_ELF32_RELOCA IMAGE_ELF_RELOCA, *PIMAGE_ELF_RELOCA;
-typedef IMAGE_ELF32_PROGRAM_HEADER IMAGE_ELF_PROGRAM_HEADER, *PIMAGE_ELF_PROGRAM_HEADER;
-typedef IMAGE_ELF32_DYNAMIC IMAGE_ELF_DYNAMIC, *PIMAGE_ELF_DYNAMIC;
-typedef IMAGE_ELF32_AUXINFO IMAGE_ELF_AUXINFO, *PIMAGE_ELF_AUXINFO;
-
-#elif ELF_ARCH_SIZE == 64
-# error 64 bits unsupported
-#else
-# error Undefined architecture size!
-#endif
-
-
-
-
-/* target macros */
-#ifdef _M_IX86
-# define IMAGE_ELF_TARGET_CLASS IMAGE_ELF_CLASS_32
-# define IMAGE_ELF_TARGET_DATA IMAGE_ELF_DATA_2LSB
-# define IMAGE_ELF_TARGET_MACHINE IMAGE_ELF_MACHINE_386
-# define IMAGE_ELF_TARGET_VERSION 1
-#else
-# error Unsupported architecture!
#endif
-#undef ELF_ARCH_SIZE
-
-#endif /* __INCLUDE_ELF_H */
-
+/* EOF */
reactos/include/elf
diff -N common.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ common.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
@@ -0,0 +1,299 @@
+/*-
+ * Copyright (c) 1998 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sys/elf_common.h,v 1.15 2004/05/05 02:38:54 marcel Exp $
+ */
+
+#ifndef _SYS_ELF_COMMON_H_
+#define _SYS_ELF_COMMON_H_ 1
+
+/*
+ * ELF definitions that are independent of architecture or word size.
+ */
+
+/*
+ * Note header. The ".note" section contains an array of notes. Each
+ * begins with this header, aligned to a word boundary. Immediately
+ * following the note header is n_namesz bytes of name, padded to the
+ * next word boundary. Then comes n_descsz bytes of descriptor, again
+ * padded to a word boundary. The values of n_namesz and n_descsz do
+ * not include the padding.
+ */
+
+typedef struct {
+ UINT32 n_namesz; /* Length of name. */
+ UINT32 n_descsz; /* Length of descriptor. */
+ UINT32 n_type; /* Type of this note. */
+} Elf_Note;
+
+/* Indexes into the e_ident array. Keep synced with
+ http://www.sco.com/developer/gabi/ch4.eheader.html */
+#define EI_MAG0 0 /* Magic number, byte 0. */
+#define EI_MAG1 1 /* Magic number, byte 1. */
+#define EI_MAG2 2 /* Magic number, byte 2. */
+#define EI_MAG3 3 /* Magic number, byte 3. */
+#define EI_CLASS 4 /* Class of machine. */
+#define EI_DATA 5 /* Data format. */
+#define EI_VERSION 6 /* ELF format version. */
+#define EI_OSABI 7 /* Operating system / ABI identification */
+#define EI_ABIVERSION 8 /* ABI version */
+#define OLD_EI_BRAND 8 /* Start of architecture identification. */
+#define EI_PAD 9 /* Start of padding (per SVR4 ABI). */
+#define EI_NIDENT 16 /* Size of e_ident array. */
+
+/* Values for the magic number bytes. */
+#define ELFMAG0 0x7f
+#define ELFMAG1 'E'
+#define ELFMAG2 'L'
+#define ELFMAG3 'F'
+#define ELFMAG "\177ELF" /* magic string */
+#define SELFMAG 4 /* magic string size */
+
+/* Values for e_ident[EI_VERSION] and e_version. */
+#define EV_NONE 0
+#define EV_CURRENT 1
+
+/* Values for e_ident[EI_CLASS]. */
+#define ELFCLASSNONE 0 /* Unknown class. */
+#define ELFCLASS32 1 /* 32-bit architecture. */
+#define ELFCLASS64 2 /* 64-bit architecture. */
+
+/* Values for e_ident[EI_DATA]. */
+#define ELFDATANONE 0 /* Unknown data format. */
+#define ELFDATA2LSB 1 /* 2's complement little-endian. */
+#define ELFDATA2MSB 2 /* 2's complement big-endian. */
+
+/* Values for e_ident[EI_OSABI]. */
+#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
+#define ELFOSABI_NONE ELFOSABI_SYSV /* symbol used in old spec */
+#define ELFOSABI_HPUX 1 /* HP-UX operating system */
+#define ELFOSABI_NETBSD 2 /* NetBSD */
+#define ELFOSABI_LINUX 3 /* GNU/Linux */
+#define ELFOSABI_HURD 4 /* GNU/Hurd */
+#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */
+#define ELFOSABI_SOLARIS 6 /* Solaris */
+#define ELFOSABI_MONTEREY 7 /* Monterey */
+#define ELFOSABI_IRIX 8 /* IRIX */
+#define ELFOSABI_FREEBSD 9 /* FreeBSD */
+#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
+#define ELFOSABI_MODESTO 11 /* Novell Modesto */
+#define ELFOSABI_OPENBSD 12 /* OpenBSD */
+#define ELFOSABI_ARM 97 /* ARM */
+#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
+
+/* e_ident */
+#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
+ (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
+ (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
+ (ehdr).e_ident[EI_MAG3] == ELFMAG3)
+
+/* Values for e_type. */
+#define ET_NONE 0 /* Unknown type. */
+#define ET_REL 1 /* Relocatable. */
+#define ET_EXEC 2 /* Executable. */
+#define ET_DYN 3 /* Shared object. */
+#define ET_CORE 4 /* Core file. */
+
+/* Values for e_machine. */
+#define EM_NONE 0 /* Unknown machine. */
+#define EM_M32 1 /* AT&T WE32100. */
+#define EM_SPARC 2 /* Sun SPARC. */
+#define EM_386 3 /* Intel i386. */
+#define EM_68K 4 /* Motorola 68000. */
+#define EM_88K 5 /* Motorola 88000. */
+#define EM_486 6 /* Intel i486. */
+#define EM_860 7 /* Intel i860. */
+#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
+
+/* Extensions. This list is not complete. */
+#define EM_S370 9 /* IBM System/370 */
+#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ /* Depreciated */
+#define EM_PARISC 15 /* HPPA */
+#define EM_SPARC32PLUS 18 /* SPARC v8plus */
+#define EM_PPC 20 /* PowerPC 32-bit */
+#define EM_PPC64 21 /* PowerPC 64-bit */
+#define EM_ARM 40 /* ARM */
+#define EM_SPARCV9 43 /* SPARC v9 64-bit */
+#define EM_IA_64 50 /* Intel IA-64 Processor */
+#define EM_X86_64 62 /* Advanced Micro Devices x86-64 */
+#define EM_ALPHA 0x9026 /* Alpha (written in the absence of an ABI */
+
+/* Special section indexes. */
+#define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */
+#define SHN_LORESERVE 0xff00 /* First of reserved range. */
+#define SHN_LOPROC 0xff00 /* First processor-specific. */
+#define SHN_HIPROC 0xff1f /* Last processor-specific. */
+#define SHN_ABS 0xfff1 /* Absolute values. */
+#define SHN_COMMON 0xfff2 /* Common data. */
+#define SHN_HIRESERVE 0xffff /* Last of reserved range. */
+
+/* sh_type */
+#define SHT_NULL 0 /* inactive */
+#define SHT_PROGBITS 1 /* program defined information */
+#define SHT_SYMTAB 2 /* symbol table section */
+#define SHT_STRTAB 3 /* string table section */
+#define SHT_RELA 4 /* relocation section with addends */
+#define SHT_HASH 5 /* symbol hash table section */
+#define SHT_DYNAMIC 6 /* dynamic section */
+#define SHT_NOTE 7 /* note section */
+#define SHT_NOBITS 8 /* no space section */
+#define SHT_REL 9 /* relocation section - no addends */
+#define SHT_SHLIB 10 /* reserved - purpose unknown */
+#define SHT_DYNSYM 11 /* dynamic symbol table section */
+#define SHT_NUM 12 /* number of section types */
+#define SHT_LOOS 0x60000000 /* First of OS specific semantics */
+#define SHT_HIOS 0x6fffffff /* Last of OS specific semantics */
+#define SHT_LOPROC 0x70000000 /* reserved range for processor */
+#define SHT_HIPROC 0x7fffffff /* specific section header types */
+#define SHT_LOUSER 0x80000000 /* reserved range for application */
+#define SHT_HIUSER 0xffffffff /* specific indexes */
+
+/* Flags for sh_flags. */
+#define SHF_WRITE 0x1 /* Section contains writable data. */
+#define SHF_ALLOC 0x2 /* Section occupies memory. */
+#define SHF_EXECINSTR 0x4 /* Section contains instructions. */
+#define SHF_TLS 0x400 /* Section contains TLS data. */
+#define SHF_MASKPROC 0xf0000000 /* Reserved for processor-specific. */
+
+/* Values for p_type. */
+#define PT_NULL 0 /* Unused entry. */
+#define PT_LOAD 1 /* Loadable segment. */
+#define PT_DYNAMIC 2 /* Dynamic linking information segment. */
+#define PT_INTERP 3 /* Pathname of interpreter. */
+#define PT_NOTE 4 /* Auxiliary information. */
+#define PT_SHLIB 5 /* Reserved (not used). */
+#define PT_PHDR 6 /* Location of program header itself. */
+#define PT_TLS 7 /* Thread local storage segment */
+
+#define PT_COUNT 8 /* Number of defined p_type values. */
+
+#define PT_LOOS 0x60000000 /* OS-specific */
+#define PT_HIOS 0x6fffffff /* OS-specific */
+#define PT_LOPROC 0x70000000 /* First processor-specific type. */
+#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */
+
+/* Values for p_flags. */
+#define PF_X 0x1 /* Executable. */
+#define PF_W 0x2 /* Writable. */
+#define PF_R 0x4 /* Readable. */
+
+/* Values for d_tag. */
+#define DT_NULL 0 /* Terminating entry. */
+#define DT_NEEDED 1 /* String table offset of a needed shared
+ library. */
+#define DT_PLTRELSZ 2 /* Total size in bytes of PLT relocations. */
+#define DT_PLTGOT 3 /* Processor-dependent address. */
+#define DT_HASH 4 /* Address of symbol hash table. */
+#define DT_STRTAB 5 /* Address of string table. */
+#define DT_SYMTAB 6 /* Address of symbol table. */
+#define DT_RELA 7 /* Address of ElfNN_Rela relocations. */
+#define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */
+#define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */
+#define DT_STRSZ 10 /* Size of string table. */
+#define DT_SYMENT 11 /* Size of each symbol table entry. */
+#define DT_INIT 12 /* Address of initialization function. */
+#define DT_FINI 13 /* Address of finalization function. */
+#define DT_SONAME 14 /* String table offset of shared object
+ name. */
+#define DT_RPATH 15 /* String table offset of library path. [sup] */
+#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. [sup] */
+#define DT_REL 17 /* Address of ElfNN_Rel relocations. */
+#define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */
+#define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */
+#define DT_PLTREL 20 /* Type of relocation used for PLT. */
+#define DT_DEBUG 21 /* Reserved (not used). */
+#define DT_TEXTREL 22 /* Indicates there may be relocations in
+ non-writable segments. [sup] */
+#define DT_JMPREL 23 /* Address of PLT relocations. */
+#define DT_BIND_NOW 24 /* [sup] */
+#define DT_INIT_ARRAY 25 /* Address of the array of pointers to
+ initialization functions */
+#define DT_FINI_ARRAY 26 /* Address of the array of pointers to
+ termination functions */
+#define DT_INIT_ARRAYSZ 27 /* Size in bytes of the array of
+ initialization functions. */
+#define DT_FINI_ARRAYSZ 28 /* Size in bytes of the array of
+ terminationfunctions. */
+#define DT_RUNPATH 29 /* String table offset of a null-terminated
+ library search path string. */
+#define DT_FLAGS 30 /* Object specific flag values. */
+#define DT_ENCODING 32 /* Values greater than or equal to DT_ENCODING
+ and less than DT_LOOS follow the rules for
+ the interpretation of the d_un union
+ as follows: even == 'd_ptr', even == 'd_val'
+ or none */
+#define DT_PREINIT_ARRAY 32 /* Address of the array of pointers to
+ pre-initialization functions. */
+#define DT_PREINIT_ARRAYSZ 33 /* Size in bytes of the array of
+ pre-initialization functions. */
+
+#define DT_COUNT 33 /* Number of defined d_tag values. */
+
+#define DT_LOOS 0x6000000d /* First OS-specific */
+#define DT_HIOS 0x6fff0000 /* Last OS-specific */
+#define DT_LOPROC 0x70000000 /* First processor-specific type. */
+#define DT_HIPROC 0x7fffffff /* Last processor-specific type. */
+
+/* Values for DT_FLAGS */
+#define DF_ORIGIN 0x0001 /* Indicates that the object being loaded may
+ make reference to the $ORIGIN substitution
+ string */
+#define DF_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */
+#define DF_TEXTREL 0x0004 /* Indicates there may be relocations in
+ non-writable segments. */
+#define DF_BIND_NOW 0x0008 /* Indicates that the dynamic linker should
+ process all relocations for the object
+ containing this entry before transferring
+ control to the program. */
+#define DF_STATIC_TLS 0x0010 /* Indicates that the shared object or
+ executable contains code using a static
+ thread-local storage scheme. */
+
+/* Values for n_type. Used in core files. */
+#define NT_PRSTATUS 1 /* Process status. */
+#define NT_FPREGSET 2 /* Floating point registers. */
+#define NT_PRPSINFO 3 /* Process state info. */
+
+/* Symbol Binding - ELFNN_ST_BIND - st_info */
+#define STB_LOCAL 0 /* Local symbol */
+#define STB_GLOBAL 1 /* Global symbol */
+#define STB_WEAK 2 /* like global - lower precedence */
+#define STB_LOPROC 13 /* reserved range for processor */
+#define STB_HIPROC 15 /* specific symbol bindings */
+
+/* Symbol type - ELFNN_ST_TYPE - st_info */
+#define STT_NOTYPE 0 /* Unspecified type. */
+#define STT_OBJECT 1 /* Data object. */
+#define STT_FUNC 2 /* Function. */
+#define STT_SECTION 3 /* Section. */
+#define STT_FILE 4 /* Source file. */
+#define STT_TLS 6 /* TLS object. */
+#define STT_LOPROC 13 /* reserved range for processor */
+#define STT_HIPROC 15 /* specific symbol types */
+
+/* Special symbol table indexes. */
+#define STN_UNDEF 0 /* Undefined symbol index. */
+
+#endif /* !_SYS_ELF_COMMON_H_ */
reactos/include/elf
diff -N elf-i386.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ elf-i386.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
@@ -0,0 +1,149 @@
+/*-
+ * Copyright (c) 1996-1997 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/i386/include/elf.h,v 1.16 2004/08/02 19:12:17 dfr Exp $
+ */
+
+#ifndef _MACHINE_ELF_H_
+#define _MACHINE_ELF_H_ 1
+
+/*
+ * ELF definitions for the i386 architecture.
+ */
+
+#ifndef __ELF_WORD_SIZE
+#define __ELF_WORD_SIZE 32 /* Used by <elf/generic.h> */
+#endif
+
+#include <elf/generic.h>
+
+#define ELF_ARCH EM_386
+
+#define ELF_MACHINE_OK(x) ((x) == EM_386 || (x) == EM_486)
+
+/*
+ * Auxiliary vector entries for passing information to the interpreter.
+ *
+ * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
+ * but POSIX lays claim to all symbols ending with "_t".
+ */
+
+typedef struct { /* Auxiliary vector entry on initial stack */
+ int a_type; /* Entry type. */
+ union {
+ long a_val; /* Integer value. */
+ void *a_ptr; /* Address. */
+ void (*a_fcn)(void); /* Function pointer (not used). */
+ } a_un;
+} Elf32_Auxinfo;
+
+#if __ELF_WORD_SIZE == 64
+/* Fake for amd64 loader support */
+typedef struct {
+ int fake;
+} Elf64_Auxinfo;
+#endif
+
+__ElfType(Auxinfo);
+
+/* Values for a_type. */
+#define AT_NULL 0 /* Terminates the vector. */
+#define AT_IGNORE 1 /* Ignored entry. */
+#define AT_EXECFD 2 /* File descriptor of program to load. */
+#define AT_PHDR 3 /* Program header of program already loaded. */
+#define AT_PHENT 4 /* Size of each program header entry. */
+#define AT_PHNUM 5 /* Number of program header entries. */
+#define AT_PAGESZ 6 /* Page size in bytes. */
+#define AT_BASE 7 /* Interpreter's base address. */
+#define AT_FLAGS 8 /* Flags (unused for i386). */
+#define AT_ENTRY 9 /* Where interpreter should transfer control. */
+
+/*
+ * The following non-standard values are used for passing information
+ * from John Polstra's testbed program to the dynamic linker. These
+ * are expected to go away soon.
+ *
+ * Unfortunately, these overlap the Linux non-standard values, so they
+ * must not be used in the same context.
+ */
+#define AT_BRK 10 /* Starting point for sbrk and brk. */
+#define AT_DEBUG 11 /* Debugging level. */
+
+/*
+ * The following non-standard values are used in Linux ELF binaries.
+ */
+#define AT_NOTELF 10 /* Program is not ELF ?? */
+#define AT_UID 11 /* Real uid. */
+#define AT_EUID 12 /* Effective uid. */
+#define AT_GID 13 /* Real gid. */
+#define AT_EGID 14 /* Effective gid. */
+
+#define AT_COUNT 15 /* Count of defined aux entry types. */
+
+/*
+ * Relocation types.
+ */
+
+#define R_386_NONE 0 /* No relocation. */
+#define R_386_32 1 /* Add symbol value. */
+#define R_386_PC32 2 /* Add PC-relative symbol value. */
+#define R_386_GOT32 3 /* Add PC-relative GOT offset. */
+#define R_386_PLT32 4 /* Add PC-relative PLT offset. */
+#define R_386_COPY 5 /* Copy data from shared object. */
+#define R_386_GLOB_DAT 6 /* Set GOT entry to data address. */
+#define R_386_JMP_SLOT 7 /* Set GOT entry to code address. */
+#define R_386_RELATIVE 8 /* Add load address of shared object. */
+#define R_386_GOTOFF 9 /* Add GOT-relative symbol address. */
+#define R_386_GOTPC 10 /* Add PC-relative GOT table address. */
+#define R_386_TLS_TPOFF 14 /* Negative offset in static TLS block */
+#define R_386_TLS_IE 15 /* Absolute address of GOT for -ve static TLS */
+#define R_386_TLS_GOTIE 16 /* GOT entry for negative static TLS block */
+#define R_386_TLS_LE 17 /* Negative offset relative to static TLS */
+#define R_386_TLS_GD 18 /* 32 bit offset to GOT (index,off) pair */
+#define R_386_TLS_LDM 19 /* 32 bit offset to GOT (index,zero) pair */
+#define R_386_TLS_GD_32 24 /* 32 bit offset to GOT (index,off) pair */
+#define R_386_TLS_GD_PUSH 25 /* pushl instruction for Sun ABI GD sequence */
+#define R_386_TLS_GD_CALL 26 /* call instruction for Sun ABI GD sequence */
+#define R_386_TLS_GD_POP 27 /* popl instruction for Sun ABI GD sequence */
+#define R_386_TLS_LDM_32 28 /* 32 bit offset to GOT (index,zero) pair */
+#define R_386_TLS_LDM_PUSH 29 /* pushl instruction for Sun ABI LD sequence */
+#define R_386_TLS_LDM_CALL 30 /* call instruction for Sun ABI LD sequence */
+#define R_386_TLS_LDM_POP 31 /* popl instruction for Sun ABI LD sequence */
+#define R_386_TLS_LDO_32 32 /* 32 bit offset from start of TLS block */
+#define R_386_TLS_IE_32 33 /* 32 bit offset to GOT static TLS offset entry */
+#define R_386_TLS_LE_32 34 /* 32 bit offset within static TLS block */
+#define R_386_TLS_DTPMOD32 35 /* GOT entry containing TLS index */
+#define R_386_TLS_DTPOFF32 36 /* GOT entry containing TLS offset */
+#define R_386_TLS_TPOFF32 37 /* GOT entry of -ve static TLS offset */
+
+#define R_386_COUNT 38 /* Count of defined relocation types. */
+
+/* Define "machine" characteristics */
+#define ELF_TARG_CLASS ELFCLASS32
+#define ELF_TARG_DATA ELFDATA2LSB
+#define ELF_TARG_MACH EM_386
+#define ELF_TARG_VER 1
+
+#endif /* !_MACHINE_ELF_H_ */
reactos/include/elf
diff -N elf32.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ elf32.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
@@ -0,0 +1,154 @@
+/*-
+ * Copyright (c) 1996-1998 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sys/elf32.h,v 1.8 2002/05/30 08:32:18 dfr Exp $
+ */
+
+#ifndef _SYS_ELF32_H_
+#define _SYS_ELF32_H_ 1
+
+/*
+ * ELF definitions common to all 32-bit architectures.
+ */
+
+typedef UINT32 Elf32_Addr;
+typedef USHORT Elf32_Half;
+typedef UINT32 Elf32_Off;
+typedef INT32 Elf32_Sword;
+typedef UINT32 Elf32_Word;
+typedef UINT32 Elf32_Size;
+typedef Elf32_Off Elf32_Hashelt;
+
+/*
+ * ELF header.
+ */
+
+typedef struct {
+ unsigned char e_ident[EI_NIDENT]; /* File identification. */
+ Elf32_Half e_type; /* File type. */
+ Elf32_Half e_machine; /* Machine architecture. */
+ Elf32_Word e_version; /* ELF format version. */
+ Elf32_Addr e_entry; /* Entry point. */
+ Elf32_Off e_phoff; /* Program header file offset. */
+ Elf32_Off e_shoff; /* Section header file offset. */
+ Elf32_Word e_flags; /* Architecture-specific flags. */
+ Elf32_Half e_ehsize; /* Size of ELF header in bytes. */
+ Elf32_Half e_phentsize; /* Size of program header entry. */
+ Elf32_Half e_phnum; /* Number of program header entries. */
+ Elf32_Half e_shentsize; /* Size of section header entry. */
+ Elf32_Half e_shnum; /* Number of section header entries. */
+ Elf32_Half e_shstrndx; /* Section name strings section. */
+} Elf32_Ehdr;
+
+/*
+ * Section header.
+ */
+
+typedef struct {
+ Elf32_Word sh_name; /* Section name (index into the
+ section header string table). */
+ Elf32_Word sh_type; /* Section type. */
+ Elf32_Word sh_flags; /* Section flags. */
+ Elf32_Addr sh_addr; /* Address in memory image. */
+ Elf32_Off sh_offset; /* Offset in file. */
+ Elf32_Size sh_size; /* Size in bytes. */
+ Elf32_Word sh_link; /* Index of a related section. */
+ Elf32_Word sh_info; /* Depends on section type. */
+ Elf32_Size sh_addralign; /* Alignment in bytes. */
+ Elf32_Size sh_entsize; /* Size of each entry in section. */
+} Elf32_Shdr;
+
+/*
+ * Program header.
+ */
+
+typedef struct {
+ Elf32_Word p_type; /* Entry type. */
+ Elf32_Off p_offset; /* File offset of contents. */
+ Elf32_Addr p_vaddr; /* Virtual address in memory image. */
+ Elf32_Addr p_paddr; /* Physical address (not used). */
+ Elf32_Size p_filesz; /* Size of contents in file. */
+ Elf32_Size p_memsz; /* Size of contents in memory. */
+ Elf32_Word p_flags; /* Access permission flags. */
+ Elf32_Size p_align; /* Alignment in memory and file. */
+} Elf32_Phdr;
+
+/*
+ * Dynamic structure. The ".dynamic" section contains an array of them.
+ */
+
+typedef struct {
+ Elf32_Sword d_tag; /* Entry type. */
+ union {
+ Elf32_Size d_val; /* Integer value. */
+ Elf32_Addr d_ptr; /* Address value. */
+ } d_un;
+} Elf32_Dyn;
+
+/*
+ * Relocation entries.
+ */
+
+/* Relocations that don't need an addend field. */
+typedef struct {
+ Elf32_Addr r_offset; /* Location to be relocated. */
+ Elf32_Word r_info; /* Relocation type and symbol index. */
+} Elf32_Rel;
+
+/* Relocations that need an addend field. */
+typedef struct {
+ Elf32_Addr r_offset; /* Location to be relocated. */
+ Elf32_Word r_info; /* Relocation type and symbol index. */
+ Elf32_Sword r_addend; /* Addend. */
+} Elf32_Rela;
+
+/* Macros for accessing the fields of r_info. */
+#define ELF32_R_SYM(info) ((info) >> 8)
+#define ELF32_R_TYPE(info) ((unsigned char)(info))
+
+/* Macro for constructing r_info from field values. */
+#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
+
+/*
+ * Symbol table entries.
+ */
+
+typedef struct {
+ Elf32_Word st_name; /* String table index of name. */
+ Elf32_Addr st_value; /* Symbol value. */
+ Elf32_Size st_size; /* Size of associated object. */
+ unsigned char st_info; /* Type and binding information. */
+ unsigned char st_other; /* Reserved (not used). */
+ Elf32_Half st_shndx; /* Section index of symbol. */
+} Elf32_Sym;
+
+/* Macros for accessing the fields of st_info. */
+#define ELF32_ST_BIND(info) ((info) >> 4)
+#define ELF32_ST_TYPE(info) ((info) & 0xf)
+
+/* Macro for constructing st_info from field values. */
+#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
+
+#endif /* !_SYS_ELF32_H_ */
reactos/include/elf
diff -N elf64.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ elf64.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
@@ -0,0 +1,167 @@
+/*-
+ * Copyright (c) 1996-1998 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sys/elf64.h,v 1.10 2002/05/30 08:32:18 dfr Exp $
+ */
+
+#ifndef _SYS_ELF64_H_
+#define _SYS_ELF64_H_ 1
+
+/*
+ * ELF definitions common to all 64-bit architectures.
+ */
+
+typedef UINT64 Elf64_Addr;
+typedef UINT32 Elf64_Half;
+typedef UINT64 Elf64_Off;
+typedef INT64 Elf64_Sword;
+typedef UINT64 Elf64_Word;
+typedef UINT64 Elf64_Size;
+typedef USHORT Elf64_Quarter;
+
+/*
+ * Types of dynamic symbol hash table bucket and chain elements.
+ *
+ * This is inconsistent among 64 bit architectures, so a machine dependent
+ * typedef is required.
+ */
+
+#ifdef _ALPHA_
+typedef Elf64_Off Elf64_Hashelt;
+#else
+typedef Elf64_Half Elf64_Hashelt;
+#endif
+
+/*
+ * ELF header.
+ */
+
+typedef struct {
+ unsigned char e_ident[EI_NIDENT]; /* File identification. */
+ Elf64_Quarter e_type; /* File type. */
+ Elf64_Quarter e_machine; /* Machine architecture. */
+ Elf64_Half e_version; /* ELF format version. */
+ Elf64_Addr e_entry; /* Entry point. */
+ Elf64_Off e_phoff; /* Program header file offset. */
+ Elf64_Off e_shoff; /* Section header file offset. */
+ Elf64_Half e_flags; /* Architecture-specific flags. */
+ Elf64_Quarter e_ehsize; /* Size of ELF header in bytes. */
+ Elf64_Quarter e_phentsize; /* Size of program header entry. */
+ Elf64_Quarter e_phnum; /* Number of program header entries. */
+ Elf64_Quarter e_shentsize; /* Size of section header entry. */
+ Elf64_Quarter e_shnum; /* Number of section header entries. */
+ Elf64_Quarter e_shstrndx; /* Section name strings section. */
+} Elf64_Ehdr;
+
+/*
+ * Section header.
+ */
+
+typedef struct {
+ Elf64_Half sh_name; /* Section name (index into the
+ section header string table). */
+ Elf64_Half sh_type; /* Section type. */
+ Elf64_Size sh_flags; /* Section flags. */
+ Elf64_Addr sh_addr; /* Address in memory image. */
+ Elf64_Off sh_offset; /* Offset in file. */
+ Elf64_Size sh_size; /* Size in bytes. */
+ Elf64_Half sh_link; /* Index of a related section. */
+ Elf64_Half sh_info; /* Depends on section type. */
+ Elf64_Size sh_addralign; /* Alignment in bytes. */
+ Elf64_Size sh_entsize; /* Size of each entry in section. */
+} Elf64_Shdr;
+
+/*
+ * Program header.
+ */
+
+typedef struct {
+ Elf64_Half p_type; /* Entry type. */
+ Elf64_Half p_flags; /* Access permission flags. */
+ Elf64_Off p_offset; /* File offset of contents. */
+ Elf64_Addr p_vaddr; /* Virtual address in memory image. */
+ Elf64_Addr p_paddr; /* Physical address (not used). */
+ Elf64_Size p_filesz; /* Size of contents in file. */
+ Elf64_Size p_memsz; /* Size of contents in memory. */
+ Elf64_Size p_align; /* Alignment in memory and file. */
+} Elf64_Phdr;
+
+/*
+ * Dynamic structure. The ".dynamic" section contains an array of them.
+ */
+
+typedef struct {
+ Elf64_Size d_tag; /* Entry type. */
+ union {
+ Elf64_Size d_val; /* Integer value. */
+ Elf64_Addr d_ptr; /* Address value. */
+ } d_un;
+} Elf64_Dyn;
+
+/*
+ * Relocation entries.
+ */
+
+/* Relocations that don't need an addend field. */
+typedef struct {
+ Elf64_Addr r_offset; /* Location to be relocated. */
+ Elf64_Size r_info; /* Relocation type and symbol index. */
+} Elf64_Rel;
+
+/* Relocations that need an addend field. */
+typedef struct {
+ Elf64_Addr r_offset; /* Location to be relocated. */
+ Elf64_Size r_info; /* Relocation type and symbol index. */
+ Elf64_Off r_addend; /* Addend. */
+} Elf64_Rela;
+
+/* Macros for accessing the fields of r_info. */
+#define ELF64_R_SYM(info) ((info) >> 32)
+#define ELF64_R_TYPE(info) ((unsigned char)(info))
+
+/* Macro for constructing r_info from field values. */
+#define ELF64_R_INFO(sym, type) (((sym) << 32) + (unsigned char)(type))
+
+/*
+ * Symbol table entries.
+ */
+
+typedef struct {
+ Elf64_Half st_name; /* String table index of name. */
+ unsigned char st_info; /* Type and binding information. */
+ unsigned char st_other; /* Reserved (not used). */
+ Elf64_Quarter st_shndx; /* Section index of symbol. */
+ Elf64_Addr st_value; /* Symbol value. */
+ Elf64_Size st_size; /* Size of associated object. */
+} Elf64_Sym;
+
+/* Macros for accessing the fields of st_info. */
+#define ELF64_ST_BIND(info) ((info) >> 4)
+#define ELF64_ST_TYPE(info) ((info) & 0xf)
+
+/* Macro for constructing st_info from field values. */
+#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
+
+#endif /* !_SYS_ELF64_H_ */
reactos/include/elf
diff -N generic.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ generic.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 1998 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sys/elf_generic.h,v 1.6 2002/07/20 02:56:11 peter Exp $
+ */
+
+#ifndef _SYS_ELF_GENERIC_H_
+#define _SYS_ELF_GENERIC_H_ 1
+
+/* [REACTOS] TODO: we need to define this somewhere global */
+#define __ELF_CONCAT1(x,y) x ## y
+#define __ELF_CONCAT(x,y) __ELF_CONCAT1(x,y)
+
+/*
+ * Definitions of generic ELF names which relieve applications from
+ * needing to know the word size.
+ */
+
+#if __ELF_WORD_SIZE != 32 && __ELF_WORD_SIZE != 64
+#error "__ELF_WORD_SIZE must be defined as 32 or 64"
+#endif
+
+#define ELF_CLASS __ELF_CONCAT(ELFCLASS,__ELF_WORD_SIZE)
+
+#if 0
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define ELF_DATA ELFDATA2LSB
+#elif BYTE_ORDER == BIG_ENDIAN
+#define ELF_DATA ELFDATA2MSB
+#else
+#error "Unknown byte order"
+#endif
+#else
+/* [REACTOS] FIXME: we need to add this to our build system */
+#define ELF_DATA ELFDATA2LSB
+#endif
+
+#define __elfN(x) __ELF_CONCAT(__ELF_CONCAT(__ELF_CONCAT(elf,__ELF_WORD_SIZE),_),x)
+#define __ElfN(x) __ELF_CONCAT(__ELF_CONCAT(__ELF_CONCAT(Elf,__ELF_WORD_SIZE),_),x)
+#define __ELFN(x) __ELF_CONCAT(__ELF_CONCAT(__ELF_CONCAT(ELF,__ELF_WORD_SIZE),_),x)
+#define __ElfType(x) typedef __ElfN(x) __ELF_CONCAT(Elf_,x)
+
+__ElfType(Addr);
+__ElfType(Half);
+__ElfType(Off);
+__ElfType(Sword);
+__ElfType(Word);
+__ElfType(Size);
+__ElfType(Hashelt);
+__ElfType(Ehdr);
+__ElfType(Shdr);
+__ElfType(Phdr);
+__ElfType(Dyn);
+__ElfType(Rel);
+__ElfType(Rela);
+__ElfType(Sym);
+
+#define ELF_R_SYM __ELFN(R_SYM)
+#define ELF_R_TYPE __ELFN(R_TYPE)
+#define ELF_R_INFO __ELFN(R_INFO)
+#define ELF_ST_BIND __ELFN(ST_BIND)
+#define ELF_ST_TYPE __ELFN(ST_TYPE)
+#define ELF_ST_INFO __ELFN(ST_INFO)
+
+#endif /* !_SYS_ELF_GENERIC_H_ */
reactos/include/elf
diff -N machine.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ machine.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
@@ -0,0 +1,10 @@
+#ifndef _REACTOS_ELF_MACHINE_H_
+#define _REACTOS_ELF_MACHINE_H_ 1
+
+#ifdef _M_IX86
+#include <elf/elf-i386.h>
+#else
+#error Unsupported target architecture
+#endif
+
+#endif
reactos/include/pseh
diff -u -r1.10 -r1.10.2.1
--- framebased.h 19 Nov 2004 23:58:33 -0000 1.10
+++ framebased.h 8 Dec 2004 20:01:39 -0000 1.10.2.1
@@ -37,29 +37,39 @@
*/
#ifdef _SEH_NO_NATIVE_NLG
# include <pseh/setjmp.h>
-# define longjmp _SEHLongJmp
-# define setjmp _SEHSetJmp
-# define jmp_buf _SEHJmpBuf_t
#else
# include <setjmp.h>
+# define _SEHLongJmp longjmp
+# define _SEHSetJmp setjmp
+# define _SEHJmpBuf_t jmp_buf
#endif
typedef struct __SEHFrame
{
_SEHPortableFrame_t SEH_Header;
- jmp_buf SEH_JmpBuf;
+ _SEHJmpBuf_t SEH_JmpBuf;
void * SEH_Locals;
}
_SEHFrame_t;
-static __declspec(noreturn) void __stdcall _SEHCompilerSpecificHandler
+/*
+ Note: just define __inline to an empty symbol if your C compiler doesn't
+ support it
+*/
+#ifdef __cplusplus
+# ifndef __inline
+# define __inline inline
+# endif
+#endif
+
+static __declspec(noreturn) __inline void __stdcall _SEHCompilerSpecificHandler
(
_SEHPortableFrame_t * frame
)
{
_SEHFrame_t * myframe;
myframe = (_SEHFrame_t *)(((char *)frame) - offsetof(_SEHFrame_t, SEH_Header));
- longjmp(myframe->SEH_JmpBuf, 1);
+ _SEHLongJmp(myframe->SEH_JmpBuf, 1);
}
#define _SEH_FILTER(NAME_) \
@@ -69,6 +79,8 @@
struct __SEHPortableFrame * _SEHPortableFrame \
)
+#define _SEH_STATIC_FILTER(ACTION_) ((_SEHFilter_t)((ACTION_) + 2))
+
#define _SEH_FINALLY(NAME_) \
void __stdcall NAME_ \
( \
@@ -78,7 +90,7 @@
#define _SEH_TRY_FINALLY(FINALLY_) \
_SEH_TRY_FILTER_FINALLY \
( \
- (_SEHFilter_t)(_SEH_CONTINUE_SEARCH + 1), \
+ _SEH_STATIC_FILTER(_SEH_CONTINUE_SEARCH), \
(FINALLY_) \
)
@@ -90,7 +102,7 @@
#define _SEH_TRY_HANDLE_FINALLY(FINALLY_) \
_SEH_TRY_FILTER_FINALLY \
( \
- (_SEHFilter_t)(_SEH_EXECUTE_HANDLER + 1), \
+ _SEH_STATIC_FILTER(_SEH_EXECUTE_HANDLER), \
(FINALLY_) \
)
@@ -117,7 +129,7 @@
_SEHPortableFrame = &_SEHFrame->SEH_Header; \
(void)_SEHPortableFrame; \
\
- if(setjmp(_SEHFrame->SEH_JmpBuf) == 0) \
+ if(_SEHSetJmp(_SEHFrame->SEH_JmpBuf) == 0) \
{ \
_SEHEnter(&_SEHFrame->SEH_Header); \
\
reactos/include/reactos
diff -N exeformat.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ exeformat.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
@@ -0,0 +1,38 @@
+#ifndef REACTOS_EXEFORMAT_H_INCLUDED_
+#define REACTOS_EXEFORMAT_H_INCLUDED_ 1
+
+#define FACILITY_ROS_EXEFMT (0x10)
+
+/*
+ * Returned by ExeFormat loaders to tell the caller the format isn't supported,
+ * as opposed to STATUS_INVALID_IMAGE_FORMAT meaning the format is supported,
+ * but the particular file is malformed
+ */
+#define STATUS_ROS_EXEFMT_UNKNOWN_FORMAT /* TODO */
+
+/*
+ * Returned by MmCreateSection to signal successful loading of an executable
+ * image, saving the caller the effort of determining the executable's format
+ * again
+ */
+#define FACILITY_ROS_EXEFMT_FORMAT (0x11)
+#define STATUS_ROS_EXEFMT_LOADED_FORMAT /* TODO */
+
+/* non-standard format, ZwQuerySection required to retrieve the format tag */
+#define EXEFMT_LOADED_EXTENDED (0x0000FFFF)
+
+/* Windows PE/PE+ */
+#define EXEFMT_LOADED_PE32 (0x00000000)
+#define EXEFMT_LOADED_PE64 (0x00000001)
+
+/* Wine ELF */
+#define EXEFMT_LOADED_WINE32 (0x00000002)
+#define EXEFMT_LOADED_WINE64 (0x00000003)
+
+/* regular ELF */
+#define EXEFMT_LOADED_ELF32 (0x00000004)
+#define EXEFMT_LOADED_ELF64 (0x00000005)
+
+#endif
+
+/* EOF */
reactos/lib/ntdll/ldr
diff -u -r1.1.2.1 -r1.1.2.2
--- elf.c 2 Dec 2004 02:44:18 -0000 1.1.2.1
+++ elf.c 8 Dec 2004 20:01:40 -0000 1.1.2.2
@@ -1,4 +1,4 @@
-/* $Id: elf.c,v 1.1.2.1 2004/12/02 02:44:18 hyperion Exp $
+/* $Id: elf.c,v 1.1.2.2 2004/12/08 20:01:40 hyperion Exp $
*/
/*
@@ -42,6 +42,8 @@
* John Polstra <jdp@polstra.com>.
*/
+#if 0
+
#ifndef __GNUC__
#error "GCC is needed to compile this file"
#endif
@@ -450,6 +452,8 @@
return (func_ptr_type) obj_main->entry;
}
+#endif /* 0 */
+
Elf_Addr
_rtld_bind(Obj_Entry *obj, Elf_Word reloff)
{
@@ -489,6 +493,8 @@
return target;
}
+#if 0
+
/*
* Error reporting function. Use it like printf. If formats the message
* into a buffer, and sets things up so that the next call to dlerror()
@@ -547,6 +553,8 @@
errx(1, "%s", msg);
}
+#endif /* 0 */
+
/*
* Process a shared object's DYNAMIC section, and save the important
* information in its Obj_Entry structure.
@@ -786,6 +794,8 @@
return obj;
}
+#if 0
+
static Obj_Entry *
dlcheck(void *handle)
{
@@ -825,6 +835,8 @@
return false;
}
+#endif /* 0 */
+
/*
* Hash function for symbol table lookup. Don't even think about changing
* this. It is specified by the System V ABI.
@@ -845,6 +857,8 @@
return h;
}
+#if 0
+
/*
* Find the library with the given name, and return its full pathname.
* The returned string is dynamically allocated. Generates an error
@@ -896,6 +910,8 @@
return NULL;
}
+#endif /* 0 */
+
/*
* Given a symbol number in a referencing object, find the corresponding
* definition of the symbol. Returns a pointer to the symbol, or NULL if
@@ -970,6 +986,8 @@
return def;
}
+#if 0
+
/*
* Return the search path from the ldconfig hints file, reading it if
* necessary. Returns NULL if there are problems with the hints file,
@@ -1429,6 +1447,8 @@
*list = newlist;
}
+#endif /* 0 */
+
/*
* Relocate newly-loaded shared objects. The argument is a pointer to
* the Obj_Entry for the first such object. All objects from the first
@@ -1497,6 +1517,8 @@
return 0;
}
+#if 0
+
/*
* Cleanup procedure. It will be called (by the atexit mechanism) just
* before the process exits.
@@ -2286,6 +2308,8 @@
return def;
}
+#endif /* 0 */
+
/*
* Search the symbol table of a single shared object for a symbol of
* the given name. Returns a pointer to the symbol, or NULL if no
@@ -2321,6 +2345,8 @@
return NULL;
}
+#if 0
+
static void
trace_loaded_objects(Obj_Entry *obj)
{
@@ -2792,3 +2818,5 @@
{
free_tls(tcb, tcbsize, tcbalign);
}
+
+#endif /* 0 */
reactos/lib/pseh
diff -u -r1.5 -r1.5.10.1
--- framebased.c 1 Jul 2004 02:40:23 -0000 1.5
+++ framebased.c 8 Dec 2004 20:01:40 -0000 1.5.10.1
@@ -77,11 +77,11 @@
switch((UINT_PTR)frame->SPF_Handlers->SH_Filter)
{
- case _SEH_EXECUTE_HANDLER + 1:
- case _SEH_CONTINUE_SEARCH + 1:
- case _SEH_CONTINUE_EXECUTION + 1:
+ case (UINT_PTR)_SEH_STATIC_FILTER(_SEH_EXECUTE_HANDLER):
+ case (UINT_PTR)_SEH_STATIC_FILTER(_SEH_CONTINUE_SEARCH):
+ case (UINT_PTR)_SEH_STATIC_FILTER(_SEH_CONTINUE_EXECUTION):
{
- ret = (int)((UINT_PTR)frame->SPF_Handlers->SH_Filter) - 1;
+ ret = (int)((UINT_PTR)frame->SPF_Handlers->SH_Filter) - 2;
break;
}
reactos/lib/pseh/i386
diff -u -r1.6 -r1.6.10.1
--- framebased.asm 3 Jul 2004 18:41:56 -0000 1.6
+++ framebased.asm 8 Dec 2004 20:01:40 -0000 1.6.10.1
@@ -18,8 +18,6 @@
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.
-; DON'T USE THE "cpu" DIRECTIVE BECAUSE NASM 0.98 DOESN'T SUPPORT IT
-; cpu 486
segment .text use32
global __SEHCleanHandlerEnvironment
reactos/lib/pseh/i386
diff -u -r1.4 -r1.4.10.1
--- setjmp.asm 3 Jul 2004 18:41:56 -0000 1.4
+++ setjmp.asm 8 Dec 2004 20:01:40 -0000 1.4.10.1
@@ -18,8 +18,6 @@
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.
-; DON'T USE THE "cpu" DIRECTIVE BECAUSE NASM 0.98 DOESN'T SUPPORT IT
-; cpu 486
segment .text use32
; Note: the undecorated names are for Borland C++ (and possibly other compilers
reactos/ntoskrnl/include/internal
diff -u -r1.93 -r1.93.2.1
--- mm.h 20 Nov 2004 16:46:05 -0000 1.93
+++ mm.h 8 Dec 2004 20:01:40 -0000 1.93.2.1
@@ -86,38 +86,35 @@
#define MM_PAGEFILE_SEGMENT (0x1)
#define MM_DATAFILE_SEGMENT (0x2)
-#define MM_SECTION_SEGMENT_BSS (0x1)
-
typedef struct _MM_SECTION_SEGMENT
{
ULONG FileOffset;
ULONG Protection;
- ULONG Attributes;
ULONG Length;
ULONG RawLength;
FAST_MUTEX Lock;
- ULONG ReferenceCount;
+ LONG ReferenceCount;/* WRONG TYPE */
SECTION_PAGE_DIRECTORY PageDirectory;
- ULONG Flags;
- PVOID VirtualAddress;
+ /*ULONG Flags;*/ /* USELESS */
+ ULONG VirtualAddress;/* WRONG TYPE */
ULONG Characteristics;
- BOOLEAN WriteCopy;
+ /*BOOLEAN WriteCopy;*/ /* USELESS */
} MM_SECTION_SEGMENT, *PMM_SECTION_SEGMENT;
typedef struct _MM_IMAGE_SECTION_OBJECT
{
- PVOID ImageBase;
- PVOID EntryPoint;
- ULONG StackReserve;
- ULONG StackCommit;
+ ULONG_PTR ImageBase;/* WRONG TYPE */
+ ULONG EntryPoint;/* WRONG TYPE */
+ ULONG_PTR StackReserve;/* WRONG TYPE */
+ ULONG_PTR StackCommit;/* WRONG TYPE */
ULONG Subsystem;
- ULONG MinorSubsystemVersion;
- ULONG MajorSubsystemVersion;
ULONG ImageCharacteristics;
+ USHORT MinorSubsystemVersion;/* WRONG TYPE */
+ USHORT MajorSubsystemVersion;/* WRONG TYPE */
USHORT Machine;
BOOLEAN Executable;
ULONG NrSegments;
- MM_SECTION_SEGMENT Segments[0];
+ PMM_SECTION_SEGMENT Segments;/* WRONG TYPE */
} MM_IMAGE_SECTION_OBJECT, *PMM_IMAGE_SECTION_OBJECT;
typedef struct _SECTION_OBJECT
reactos/ntoskrnl/mm
diff -N exefmt.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ exefmt.c 8 Dec 2004 20:01:41 -0000 1.1.2.1
@@ -0,0 +1,118 @@
+/*
+ * ReactOS kernel
+ * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/* $Id: exefmt.c,v 1.1.2.1 2004/12/08 20:01:41 hyperion Exp $
+ *
+ * PROJECT: ReactOS kernel
+ * FILE: ntoskrnl/mm/pe.c
+ * PURPOSE: Multiple executable format support
+ * PROGRAMMER: KJK::Hyperion <hackbunny@reactos.com>
+ * UPDATE HISTORY:
+ * 2004-12-06 Created
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <internal/debug.h>
+
+typedef NTSTATUS (NTAPI * PEXEFMT_CREATE_SECTION)
+(
+ IN CONST VOID * FileHeader,
+ IN SIZE_T FileHeaderSize,
+ IN PFILE_OBJECT File,
+ IN PLARGE_INTEGER FileSize,
+ OUT PMM_IMAGE_SECTION_OBJECT * ImageSectionObject,
+ IN PEXEFMT_LOADER_READ_FILE ReadFileFunc,
+ IN PEXEFMT_LOADER_ALLOCATE_SECTION AllocateSectionFunc
+);
+
+static const PEXEFMT_CREATE_SECTION ExeFmtpCreateSectionFormats[] =
+{
+ PeFmtCreateSection
+};
+
+PMM_IMAGE_SECTION_OBJECT
+NTAPI
+ExeFmtpAllocateSection
+(
+ IN ULONG NrSegments
+)
+{
+ SIZE_T cbSize;
+ PMM_IMAGE_SECTION_OBJECT p;
+
+ cbSize =
+ FIELD_OFFSET(MM_IMAGE_SECTION_OBJECT, Segments) +
+ NrSegments * sizeof(MM_SECTION_SEGMENT);
+
+ p = ExAllocatePoolWithTag(NonPagedPool, cbSize, TAG_MM_SECTION_SEGMENT);
+
+ if(p)
+ {
+ RtlZeroMemory(p, cbSize);
+ p->NrSegments = NrSegments;
+ }
+
+ return p;
+}
+
+NTSTATUS
+NTAPI
+ExeFmtCreateSection
+(
+ IN CONST VOID * FileHeader,
+ IN SIZE_T FileHeaderSize,
+ IN PFILE_OBJECT File,
+ IN PLARGE_INTEGER FileSize,
+ IN OUT PMM_IMAGE_SECTION_OBJECT * ImageSectionObject
+)
+{
+ SIZE_T i;
+ NTSTATUS nStatus;
+
+ for(i = 0; i < RTL_NUMBER_OF(ExeFmtpCreateSectionFormats); ++ i)
+ {
+ *ImageSectionObject = NULL;
+
+ nStatus = ExeFmtpCreateSectionFormats[i]
+ (
+ FileHeader,
+ FileHeaderSize,
+ File,
+ FileSize,
+ ImageSectionObject,
+ MmspPageRead,
+ MmspAllocateImageSection
+ );
+
+ if(nStatus != STATUS_ROS_EXEFMT_UNKNOWN_FORMAT && NT_SUCCESS(nStatus))
+ {
+ ASSERT(*ImageSectionObject);
+ return nStatus;
+ }
+
+ if(*ImageSectionObject)
+ ExFreePool(*ImageSectionObject);
+ }
+
+ return STATUS_INVALID_IMAGE_FORMAT;
+}
+
+/* EOF */
reactos/ntoskrnl/mm
diff -N pe.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ pe.c 8 Dec 2004 20:01:41 -0000 1.1.2.1
@@ -0,0 +1,752 @@
+/*
+ * ReactOS kernel
+ * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/* $Id: pe.c,v 1.1.2.1 2004/12/08 20:01:41 hyperion Exp $
+ *
+ * PROJECT: ReactOS kernel
+ * FILE: ntoskrnl/mm/pe.c
+ * PURPOSE: Loader for PE executables
+ * PROGRAMMER: KJK::Hyperion <hackbunny@reactos.com>
+ * UPDATE HISTORY:
+ * 2004-12-06 Created
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <internal/debug.h>
+
+static ULONG SectionCharacteristicsToProtect[16] =
+{
+ PAGE_NOACCESS, /* 0 = NONE */
+ PAGE_NOACCESS, /* 1 = SHARED */
+ PAGE_EXECUTE, /* 2 = EXECUTABLE */
+ PAGE_EXECUTE, /* 3 = EXECUTABLE, SHARED */
+ PAGE_READONLY, /* 4 = READABLE */
+ PAGE_READONLY, /* 5 = READABLE, SHARED */
+ PAGE_EXECUTE_READ, /* 6 = READABLE, EXECUTABLE */
+ PAGE_EXECUTE_READ, /* 7 = READABLE, EXECUTABLE, SHARED */
+ PAGE_WRITECOPY, /* 8 = WRITABLE */
+ PAGE_READWRITE, /* 9 = WRITABLE, SHARED */
+ PAGE_EXECUTE_WRITECOPY, /* 10 = WRITABLE, EXECUTABLE */
+ PAGE_EXECUTE_READWRITE, /* 11 = WRITABLE, EXECUTABLE, SHARED */
+ PAGE_WRITECOPY, /* 12 = WRITABLE, READABLE */
+ PAGE_READWRITE, /* 13 = WRITABLE, READABLE, SHARED */
+ PAGE_EXECUTE_WRITECOPY, /* 14 = WRITABLE, READABLE, EXECUTABLE */
+ PAGE_EXECUTE_READWRITE, /* 15 = WRITABLE, READABLE, EXECUTABLE, SHARED */
+};
+
+/* TODO: Intsafe should be made into a library, as it's generally useful */
+BOOLEAN FASTCALL Intsafe_CanAddULongPtr
+(
+ IN ULONG_PTR Addend1,
+ IN ULONG_PTR Addend2
+)
+{
+ return Addend1 <= (MAXULONG_PTR - Addend2);
+}
+
+BOOLEAN FASTCALL Intsafe_AddULongPtr
+(
+ OUT PULONG_PTR Result,
+ IN ULONG_PTR Addend1,
+ IN ULONG_PTR Addend2
+)
+{
+ if(!Intsafe_CanAddULongPtr(Addend1, Addend2))
+ return FALSE;
+
+ *Result = Addend1 + Addend2;
+ return TRUE;
+}
+
+BOOLEAN FASTCALL Intsafe_CanMulULongPtr
+(
+ IN ULONG_PTR Factor1,
+ IN ULONG_PTR Factor2
+)
+{
+ return Factor1 <= (MAXULONG_PTR / Factor2);
+}
+
+BOOLEAN FASTCALL Intsafe_MulULongPtr
+(
+ OUT PULONG_PTR Result,
+ IN ULONG_PTR Factor1,
+ IN ULONG_PTR Factor2
+)
+{
+ if(!Intsafe_CanMulULongPtr(Factor1, Factor2))
+ return FALSE;
+
+ *Result = Factor1 * Factor2;
+ return TRUE;
+}
+
+BOOLEAN FASTCALL Intsafe_CanAddULong32
+(
+ IN ULONG Addend1,
+ IN ULONG Addend2
+)
+{
+ return Addend1 <= (MAXULONG - Addend2);
+}
+
+BOOLEAN FASTCALL Intsafe_AddULong32
+(
+ OUT PULONG Result,
+ IN ULONG Addend1,
+ IN ULONG Addend2
+)
+{
+ if(!Intsafe_CanAddULong32(Addend1, Addend2))
+ return FALSE;
+
+ *Result = Addend1 + Addend2;
+ return TRUE;
+}
+
+BOOLEAN FASTCALL Intsafe_CanMulULong32
+(
+ IN ULONG Factor1,
+ IN ULONG Factor2
+)
+{
+ return Factor1 <= (MAXULONG / Factor2);
+}
+
+BOOLEAN FASTCALL Intsafe_MulULong32
+(
+ OUT PULONG Result,
+ IN ULONG Factor1,
+ IN ULONG Factor2
+)
+{
+ if(!Intsafe_CanMulULong32(Factor1, Factor2))
+ return FALSE;
+
+ *Result = Factor1 * Factor2;
+ return TRUE;
+}
+
+BOOLEAN FASTCALL Intsafe_CanOffsetPointer
+(
+ IN PVOID Pointer,
+ IN SIZE_T Offset
+)
+{
+ /* FIXME: (PVOID)MAXULONG_PTR isn't necessarily a valid address */
+ return Intsafe_CanAddULongPtr((ULONG_PTR)Pointer, Offset);
+}
+
+BOOLEAN FASTCALL IsPowerOf2(IN ULONG Number)
+{
+ if(Number == 0)
+ return FALSE;
+
+ while((Number % 2) == 0)
+ Number /= 2;
+
+ return Number == 1;
+}
+
+ULONG FASTCALL GetExcess(IN ULONG Address, IN ULONG Alignment)
+{
+ ASSERT(IsPowerOf2(Alignment));
+ return Address & ~(Alignment - 1);
+}
+
+BOOLEAN FASTCALL IsAligned(IN ULONG Address, IN ULONG Alignment)
+{
+ return GetExcess(Address, Alignment) == 0;
+}
+
+BOOLEAN FASTCALL AlignUp
+(
+ OUT PULONG AlignedAddress,
+ IN ULONG Address,
+ IN ULONG Alignment
+)
+{
+ return Intsafe_AddULong32
+ (
+ AlignedAddress,
+ Address,
+ Alignment - GetExcess(Address, Alignment)
+ );
+}
+
+/*
+ References:
+ [1] Microsoft Corporation, "Microsoft Portable Executable and Common Object
+ File Format Specification", revision 6.0 (February 1999)
+*/
+NTSTATUS NTAPI PeFmtCreateSection
+(
+ IN CONST VOID * FileHeader,
+ IN SIZE_T FileHeaderSize,
+ IN PFILE_OBJECT File,
+ OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject,
+ OUT PULONG Flags,
+ IN PEXEFMT_LOADER_READ_FILE ReadFileFunc,
+ IN PEXEFMT_LOADER_ALLOCATE_SEGMENTS AllocateSegmentsFunc
+)
+{
+ NTSTATUS nStatus;
+ ULONG cbFileHeaderOffsetSize;
+ ULONG cbSectionHeadersOffset;
+ ULONG cbSectionHeadersSize;
+ ULONG cbSectionHeadersOffsetSize;
+ ULONG cbHeadersSize;
+ ULONG nSectionAlignment;
+ ULONG nFileAlignment;
+ PIMAGE_DOS_HEADER pidhDosHeader;
+ PIMAGE_NT_HEADERS32 pinhNtHeader;
+ PIMAGE_OPTIONAL_HEADER32 piohOptHeader;
+ PIMAGE_SECTION_HEADER pishSectionHeaders;
+ PMM_SECTION_SEGMENTS pssSegments;
+ LARGE_INTEGER lnOffset;
+ PVOID pBuffer;
+ ULONG nPrevVirtualEndOfSegment;
+ ULONG nPrevFileEndOfSegment;
+ ULONG i;
+
+ ASSERT(FileHeader);
+ ASSERT(FileHeaderSize > 0);
+ ASSERT(File);
+ ASSERT(ImageSectionObject);
+ ASSERT(ReadFileFunc);
+ ASSERT(AllocateSegmentsFunc);
+
+ ASSERT(Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize));
+
+ ASSERT(FileHeaderSize >= sizeof(IMAGE_DOS_HEADER));
+ ASSERT(((UINT_PTR)FileHeader % TYPE_ALIGNMENT(IMAGE_DOS_HEADER)) == 0);
+
+ pBuffer = NULL;
+ pidhDosHeader = FileHeader;
+
+ /* DOS HEADER */
+ nStatus = STATUS_ROS_EXEFMT_UNKNOWN_FORMAT;
+
+ /* no MZ signature */
+ if(pidhDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
+ goto l_Return;
+
+ /* not a Windows executable */
+ if(pidhDosHeader->e_lfanew <= 0)
+ goto l_Return;
+
+ /* NT HEADER */
+ nStatus = STATUS_INVALID_IMAGE_FORMAT;
+
+ if(!Intsafe_AddULong32(&cbFileHeaderOffsetSize, pidhDosHeader->e_lfanew, RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader)))
+ goto l_Return;
+
+ if(FileHeaderSize < cbFileHeaderOffsetSize)
+ pinhNtHeader = NULL;
+ else
+ {
+ /*
+ we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
+ and FileHeaderSize >= cbFileHeaderOffsetSize, so this holds true too
+ */
+ ASSERT(Intsafe_CanOffsetPointer(FileHeader, pidhDosHeader->e_lfanew));
+ pinhNtHeader = (PVOID)((UINT_PTR)FileHeader + pidhDosHeader->e_lfanew);
+ }
+
+ ASSERT(sizeof(IMAGE_NT_HEADERS32) <= sizeof(IMAGE_NT_HEADERS64));
+ ASSERT(TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) == TYPE_ALIGNMENT(IMAGE_NT_HEADERS64));
+ ASSERT(RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader) == RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS64, FileHeader));
+ ASSERT(FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader) == FIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader));
+
+ /*
+ the buffer doesn't contain the NT file header, or the alignment is wrong: we
+ need to read the header from the file
+ */
+ if
+ (
+ FileHeaderSize < cbFileHeaderOffsetSize ||
+ (UINT_PTR)pinhNtHeader % TYPE_ALIGNMENT(IMAGE_NT_HEADERS32) != 0
+ )
+ {
+ SIZE_T cbNtHeaderSize;
+ SIZE_T cbReadSize;
+
+l_ReadHeaderFromFile:
+
+ nStatus = STATUS_INSUFFICIENT_RESOURCES;
+
+ /* allocate the buffer. We use the largest size (IMAGE_NT_HEADERS64) */
+ pBuffer = ExAllocatePoolWithTag
+ (
+ NonPagedPool,
+ sizeof(IMAGE_NT_HEADERS64),
+ TAG('P', 'e', 'F', 'm')
+ );
+
+ if(pBuffer == NULL)
+ goto l_Return;
+
+ lnOffset.QuadPart = pidhDosHeader->e_lfanew;
+
+ /* read the header from the file */
+ nStatus = ReadFileFunc
+ (
+ File,
+ pBuffer,
+ sizeof(IMAGE_NT_HEADERS64),
+ &lnOffset,
+ &cbReadSize
+ );
+
+ if(!NT_SUCCESS(nStatus))
+ goto l_Return;
+
+ nStatus = STATUS_UNSUCCESSFUL;
+
+ if(cbReadSize == 0)
+ goto l_Return;
+
+ nStatus = STATUS_INVALID_IMAGE_FORMAT;
+
+ /* the buffer doesn't contain the file header */
+ if(cbReadSize < RTL_SIZEOF_THROUGH_FIELD(IMAGE_NT_HEADERS32, FileHeader))
+ goto l_Return;
+
+ pinhNtHeader = pBuffer;
+
+ /* invalid NT header */
+ if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE)
+ goto l_Return;
+
+ if(!Intsafe_AddULong32(&cbNtHeaderSize, pinhNtHeader->FileHeader.SizeOfOptionalHeader, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
+ goto l_Return;
+
+ nStatus = STATUS_UNSUCCESSFUL;
+
+ /* the buffer doesn't contain the whole NT header */
+ if(cbReadSize < cbNtHeaderSize)
+ goto l_Return;
+ }
+ else
+ {
+ SIZE_T cbOptHeaderOffsetSize;
+
+ nStatus = STATUS_INVALID_IMAGE_FORMAT;
+
+ /* don't trust an invalid NT header */
+ if(pinhNtHeader->Signature != IMAGE_NT_SIGNATURE)
+ goto l_Return;
+
+ if(!Intsafe_AddULong32(&cbOptHeaderOffsetSize, pidhDosHeader->e_lfanew, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
+ goto l_Return;
+
+ if(!Intsafe_AddULong32(&cbOptHeaderOffsetSize, cbOptHeaderOffsetSize, pinhNtHeader->FileHeader.SizeOfOptionalHeader))
+ goto l_Return;
+
+ /* the buffer doesn't contain the whole NT header: read it from the file */
+ if(cbOptHeaderOffsetSize > FileHeaderSize)
+ goto l_ReadHeaderFromFile;
+ }
+
+ /* read information from the NT header */
+ piohOptHeader = &pinhNtHeader->OptionalHeader;
+ cbOptHeaderSize = pinhNtHeader->FileHeader.SizeOfOptionalHeader;
+
+ nStatus = STATUS_INVALID_IMAGE_FORMAT;
+
+ if(!RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Magic))
+ goto l_Return;
+
+ /* ASSUME: RtlZeroMemory(ImageSectionObject, sizeof(*ImageSectionObject)); */
+
+ switch(piohOptHeader->Magic)
+ {
+ case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
+ case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
+ break;
+
+ default:
+ goto l_Return;
+ }
+
+ if
+ (
+ RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SectionAlignment) &&
+ RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, FileAlignment)
+ )
+ {
+ /* See [1], section 3.4.2 */
+ if(piohOptHeader->SectionAlignment < PAGE_SIZE)
+ {
+ if(piohOptHeader->FileAlignment != piohOptHeader->SectionAlignment)
+ goto l_Return;
+ }
+ else if(piohOptHeader->SectionAlignment < piohOptHeader->FileAlignment)
+ goto l_Return;
+
+ nSectionAlignment = piohOptHeader->SectionAlignment;
+ nFileAlignment = piohOptHeader->FileAlignment;
+
+ if(!IsPowerOf2(nSectionAlignment) || !IsPowerOf2(nFileAlignment))
+ goto l_Return;
+ }
+ else
+ {
+ nSectionAlignment = PAGE_SIZE;
+ nFileAlignment = PAGE_SIZE;
+ }
+
+ ASSERT(IsPowerOf2(nSectionAlignment));
+ ASSERT(IsPowerOf2(nFileAlignment));
+
+ switch(piohOptHeader->Magic)
+ {
+ /* PE32 */
+ case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
+ {
+ if(cbOptHeaderSize > sizeof(IMAGE_OPTIONAL_HEADER32))
+ goto l_Return;
+
+ if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, ImageBase))
+ ImageSectionObject->ImageBase = (PVOID)piohOptHeader->ImageBase;
+
+ if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfStackReserve))
+ ImageSectionObject->StackReserve = piohOptHeader->SizeOfStackReserve;
+
+ if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfStackCommit))
+ ImageSectionObject->StackCommit = piohOptHeader->SizeOfStackCommit;
+
+ break;
+ }
+
+ /* PE32+ */
+ case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
+ {
+ PIMAGE_OPTIONAL_HEADER64 pioh64OptHeader;
+
+ if(cbOptHeaderSize > sizeof(IMAGE_OPTIONAL_HEADER64))
+ goto l_Return;
+
+ pioh64OptHeader = (PIMAGE_OPTIONAL_HEADER64)piohOptHeader;
+
+ if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, ImageBase))
+ {
+ if(pioh64OptHeader->ImageBase > MAXULONG_PTR)
+ goto l_Return;
+
+ ImageSectionObject->ImageBase = (PVOID)pioh64OptHeader->ImageBase;
+ }
+
+ if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfStackReserve))
+ {
+ if(pioh64OptHeader->SizeOfStackReserve > MAXULONG_PTR)
+ goto l_Return;
+
+ ImageSectionObject->StackReserve = pioh64OptHeader->SizeOfStackReserve;
+ }
+
+ if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfStackCommit))
+ {
+ if(pioh64OptHeader->SizeOfStackCommit > MAXULONG_PTR)
+ goto l_Return;
+
+ ImageSectionObject->StackCommit = pioh64OptHeader->SizeOfStackCommit;
+ }
+
+ break;
+ }
+ }
+
+#if 0
+ /* some defaults */
+ if(ImageSectionObject->StackReserve == 0)
+ ImageSectionObject->StackReserve = 0x40000;
+
+ if(ImageSectionObject->StackCommit == 0)
+ ImageSectionObject->StackCommit = 0x1000;
+
+ if(ImageSectionObject->ImageBase == NULL)
+ {
+ if(pinhNtHeader->FileHeader.Characteristics & IMAGE_FILE_DLL)
+ ImageSectionObject->ImageBase = (PVOID)0x10000000;
+ else
+ ImageSectionObject->ImageBase = (PVOID)0x00400000;
+ }
+#endif
+
+ /* [1], section 3.4.2 */
+ if((ULONG_PTR)ImageSectionObject->ImageBase % 0x10000)
+ goto l_Return;
+
+ /*
+ ASSUME: all the fields used here have the same offset and size in both
+ IMAGE_OPTIONAL_HEADER32 and IMAGE_OPTIONAL_HEADER64
+ */
+ if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, Subsystem))
+ {
+ ImageSectionObject->Subsystem = piohOptHeader->Subsystem;
+
+ if
+ (
+ RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MinorSubsystemVersion) &&
+ RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, MajorSubsystemVersion)
+ )
+ {
+ ImageSectionObject->MinorSubsystemVersion = piohOptHeader->MinorSubsystemVersion;
+ ImageSectionObject->MajorSubsystemVersion = piohOptHeader->MajorSubsystemVersion;
+ }
+ }
+
+ if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, AddressOfEntryPoint))
+ ImageSectionObject->EntryPoint = (PVOID)piohOptHeader->AddressOfEntryPoint;
+
+ if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfCode))
+ ImageSectionObject->Executable = piohOptHeader->SizeOfCode != 0;
+ else
+ ImageSectionObject->Executable = TRUE;
+
+ ImageSectionObject->ImageCharacteristics = pinhNtHeader->FileHeader.Characteristics;
+ ImageSectionObject->Machine = pinhNtHeader->FileHeader.Machine;
+
+ /* SECTION HEADERS */
+ nStatus = STATUS_INVALID_IMAGE_FORMAT;
+
+ /* see [1], section 3.3 */
+ if(pinhNtHeader->FileHeader.NumberOfSections > 96)
+ goto l_Return;
+
+ /*
+ the additional segment is for the file's headers. They need to be present for
+ the benefit of the dynamic loader (to locate exports, defaults for thread
+ parameters, resources, etc.)
+ */
+ ImageSectionObject->NrSegments = pinhNtHeader->FileHeader.NumberOfSections + 1;
+
+ /* file offset for the section headers */
+ if(!Intsafe_AddULong32(&cbSectionHeadersOffset, pidhDosHeader->e_lfanew, FIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader)))
+ goto l_Return;
+
+ if(!Intsafe_AddULong32(&cbSectionHeadersOffset, cbSectionHeadersOffset, pinhNtHeader->FileHeader.SizeOfOptionalHeader))
+ goto l_Return;
+
+ /* size of the section headers */
+ ASSERT(Intsafe_CanMulULong32(pinhNtHeader->FileHeader.NumberOfSections, sizeof(IMAGE_SECTION_HEADER)));
+ cbSectionHeadersSize = pinhNtHeader->FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER);
+
+ if(!Intsafe_AddULong32(&cbSectionHeadersOffsetSize, cbSectionHeadersOffset, cbSectionHeadersSize))
+ goto l_Return;
+
+ /* size of the executable's headers */
+ if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfHeaders))
+ {
+ if(!IsAligned(piohOptHeader->SizeOfHeaders, nFileAlignment))
+ goto l_Return;
+
+ if(cbSectionHeadersSize > piohOptHeader->SizeOfHeaders)
+ goto l_Return;
+
+ cbHeadersSize = piohOptHeader->SizeOfHeaders;
+ }
+ else if(!AlignUp(&cbHeadersSize, cbSectionHeadersOffsetSize, nFileAlignment))
+ goto l_Return;
+
+ if(pBuffer)
+ {
+ ExFreePool(pBuffer);
+ pBuffer = NULL;
+ }
+ /* WARNING: pinhNtHeader IS NO LONGER USABLE */
+ /* WARNING: piohOptHeader IS NO LONGER USABLE */
+ /* WARNING: pioh64OptHeader IS NO LONGER USABLE */
+
+ if(FileHeaderSize < cbSectionHeadersOffsetSize)
+ pishSectionHeaders = NULL;
+ else
+ {
+ /*
+ we already know that Intsafe_CanOffsetPointer(FileHeader, FileHeaderSize),
+ and FileHeaderSize >= cbSectionHeadersOffsetSize, so this holds true too
+ */
+ ASSERT(Intsafe_CanOffsetPointer(FileHeader, cbSectionHeadersOffset));
+ pishSectionHeaders = (PVOID)((UINT_PTR)FileHeader + cbSectionHeadersOffset);
+ }
+
+ /*
+ the buffer doesn't contain the section headers, or the alignment is wrong:
+ read the headers from the file
+ */
+ if
+ (
+ FileHeaderSize < cbSectionHeadersOffsetSize ||
+ (UINT_PTR)pishSectionHeaders % TYPE_ALIGNMENT(IMAGE_SECTION_HEADER) != 0
+ )
+ {
+ SIZE_T cbReadSize;
+
+ nStatus = STATUS_INSUFFICIENT_RESOURCES;
+
+ /* allocate the buffer */
+ pBuffer = ExAllocatePoolWithTag
+ (
+ NonPagedPool,
+ cbSectionHeadersSize,
+ TAG('P', 'e', 'F', 'm')
+ );
+
+ if(pBuffer == NULL)
+ goto l_Return;
+
+ lnOffset.QuadPart = cbSectionHeadersOffset;
+
+ /* read the header from the file */
+ nStatus = ReadFileFunc
+ (
+ File,
+ pBuffer,
+ cbSectionHeadersSize,
+ &lnOffset,
+ &cbReadSize
+ );
+
+ if(!NT_SUCCESS(nStatus))
+ goto l_Return;
+
+ nStatus = STATUS_UNSUCCESSFUL;
+
+ /* the buffer doesn't contain all the section headers */
+ if(cbReadSize < cbSectionHeadersSize)
+ goto l_Return;
+ }
+
+ /* SEGMENTS */
+ /* allocate the segments */
+ nStatus = STATUS_INSUFFICIENT_RESOURCES;
+ ImageSectionObject->Segments = AllocateSegmentsFunc(ImageSectionObject->NrSegments);
+
+ if(ImageSectionObject->Segments == NULL)
+ goto l_Return;
+
+ /* initialize the headers segment */
+ pssSegments = ImageSectionObject->Segments;
+
+ ASSERT(IsAligned(cbHeadersSize, nFileAlignment));
+
+ if(!AlignUp(&nPrevVirtualEndOfSegment, cbHeadersSize, nSectionAlignment))
+ goto l_Return;
+
+ pssSegments[0].FileOffset = 0;
+ pssSegments[0].Protection = PAGE_READONLY;
+ pssSegments[0].Length = nPrevVirtualEndOfSegment;
+ pssSegments[0].RawLength = nPrevFileEndOfSegment;
+ pssSegments[0].VirtualAddress = 0;
+ pssSegments[0].Characteristics = 0;
+
+ /* skip the headers segment */
+ ++ pssSegments;
+
+ nStatus = STATUS_INVALID_IMAGE_FORMAT;
+
+ /* convert the executable sections into segments. See also [1], section 4 */
+ for(i = 0; i < ImageSectionObject->NrSegments - 1; ++ i)
+ {
+ ULONG nCharacteristics;
+
+ /* validate the alignment */
+ if(!IsAligned(pishSectionHeaders[i].SizeOfRawData, nFileAlignment))
+ goto l_Return;
+
+ if(!IsAligned(pishSectionHeaders[i].PointerToRawData, nFileAlignment))
+ goto l_Return;
+
+ if(!IsAligned(pishSectionHeaders[i].Misc.VirtualSize, nSectionAlignment))
+ goto l_Return;
+
+ if(!IsAligned(pishSectionHeaders[i].VirtualAddress, nSectionAlignment))
+ goto l_Return;
+
+ /* sections must be contiguous, ordered by base address and non-overlapping */
+ if(pishSectionHeaders[i].PointerToRawData != nPrevFileEndOfSegment)
+ goto l_Return;
+
+ if(pishSectionHeaders[i].VirtualAddress != nPrevVirtualEndOfSegment)
+ goto l_Return;
+
+ /* conversion */
+ pssSegments[i].FileOffset = pishSectionHeaders[i].PointerToRawData;
+
+ nCharacteristics = pishSectionHeaders[i].Characteristics;
+
+ /* no explicit protection */
+ if(nCharacteristics & (IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE) == 0)
+ {
+ if(nCharacteristics & IMAGE_SCN_CNT_CODE)
+ nCharacteristics |= IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ;
+
+ if(nCharacteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)
+ nCharacteristics |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
+
+ if(nCharacteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
+ nCharacteristics |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
+ }
+
+ /* see table above */
+ pssSegments[i].Protection = SectionCharacteristicsToProtect[nCharacteristics >> 28];
+
+ pssSegments[i].RawLength = pishSectionHeaders[i].SizeOfRawData;
+
+ if(pishSectionHeaders[i].Misc.VirtualSize != 0)
+ pssSegments[i].Length = pishSectionHeaders[i].Misc.VirtualSize;
+ else
+ pssSegments[i].Length = pishSectionHeaders[i].SizeOfRawData;
+
+ /* ExInitializeFastMutex(&pssSegments[i].Lock); */
+ /* pssSegments[i].ReferenceCount = 1; */
+ /* RtlZeroMemory(&pssSegments[i].PageDirectory, sizeof(pssSegments[i].PageDirectory)); */
+ pssSegments[i].VirtualAddress = pishSectionHeaders[i].VirtualAddress;
+ pssSegments[i].Characteristics = pishSectionHeaders[i].Characteristics;
+
+ /* ensure the image is no larger than 4GB */
+ if(!Intsafe_AddULong32(&nPrevFileEndOfSegment, pssSegments[i].FileOffset, pssSegments[i].RawLength))
+ goto l_Return;
+
+ if(!Intsafe_AddULong32(&nPrevVirtualEndOfSegment, pssSegments[i].VirtualAddress, pssSegments[i].Length))
+ goto l_Return;
+ }
+
+ /* spare our caller some work in validating the segments */
+ *Flags |=
+ EXEFMT_LOAD_ASSUME_SEGMENTS_SORTED |
+ EXEFMT_LOAD_ASSUME_SEGMENTS_NO_OVERLAP;
+
+ if(nSectionAlignment >= PAGE_SIZE)
+ *Flags |= EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED;
+
+ /* Success */
+ nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT & EXEFMT_LOADED_PE32;
+
+l_Return;
+ if(pBuffer)
+ ExFreePool(pBuffer);
+
+ return nStatus;
+}
+
+/* EOF */
reactos/ntoskrnl/mm
diff -u -r1.166.2.1 -r1.166.2.2
--- section.c 25 Nov 2004 19:48:30 -0000 1.166.2.1
+++ section.c 8 Dec 2004 20:01:41 -0000 1.166.2.2
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* $Id: section.c,v 1.166.2.1 2004/11/25 19:48:30 hyperion Exp $
+/* $Id: section.c,v 1.166.2.2 2004/12/08 20:01:41 hyperion Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/section.c
@@ -29,8 +29,6 @@
/* INCLUDES *****************************************************************/
#include <ntoskrnl.h>
-#include <elf.h>
-
#define NDEBUG
#include <internal/debug.h>
@@ -118,6 +116,88 @@
return KeWaitForSingleObject(&File->Lock, 0, KernelMode, FALSE, NULL);
}
+static VOID
+MmspReleaseFileLock(PFILE_OBJECT File)
+{
+ KeSetEvent(&File->Lock, IO_NO_INCREMENT, FALSE);
+}
+
+static
+NTSTATUS
+NTAPI
+MmspPageRead(IN PFILE_OBJECT FileObject,
+ OUT PVOID Buffer,
+ IN SIZE_T BufferSize,
+ IN LARGE_INTEGER Offset,
+ OUT SIZE_T * ReadSize)
+{
+ NTSTATUS Status;
+ KEVENT Event;
+ MDL Mdl;
+ IO_STATUS_BLOCK Iosb;
+
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+ MmInitializeMdl(&Mdl, Buffer, BufferSize);
+ MmBuildMdlForNonPagedPool(&Mdl);
+
+ Status = IoPageRead(FileObject,
+ &Mdl,
+ Offset,
+ &Event,
+ &Iosb);
+
+ if (Status == STATUS_PENDING)
+ KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+
+ *ReadSize = Iosb.Information;
+ return Iosb.Status;
+}
+
+static
+NTSTATUS
+NTAPI
+MmspQueryFileSize(IN PFILE_OBJECT FileObject,
+ OUT PLARGE_INTEGER FileSize)
+{
+ PDEVICE_OBJECT DeviceObject;
+ KEVENT Event;
+ PIRP Irp;
+ IO_STATUS_BLOCK Iosb;
+ PIO_STACK_LOCATION StackPtr;
+ FILE_END_OF_FILE_INFORMATION Eof;
+
+ DeviceObject = IoGetRelatedDeviceObject(FileObject);
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+
+ Irp = IoBuildSynchronousFsdRequest(IRP_MJ_QUERY_INFORMATION,
+ DeviceObject,
+ &Eof,
+ sizeof(Eof),
+ NULL,
+ &Event,
+ &Iosb);
+
+ if (Irp == NULL)
+ return (STATUS_INSUFFICIENT_RESOURCES);
+
+ StackPtr = IoGetNextIrpStackLocation(Irp);
+ StackPtr->FileObject = FileObject;
+ StackPtr->Parameters.QueryFile.Length = sizeof(Eof);
+ StackPtr->Parameters.QueryFile.FileInformationClass = FileEndOfFileInformation;
+
+ if (IoCallDriver(DeviceObject, Irp) == STATUS_PENDING)
+ KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+
+ if (NT_SUCCESS(Iosb.Status))
+ {
+ if (!RTL_CONTAINS_FIELD(&Eof, Iosb.Information, EndOfFile))
+ return STATUS_UNSUCCESSFUL;
+
+ *FileSize = Eof.EndOfFile;
+ }
+
+ return Iosb.Status;
+}
VOID
MmFreePageTablesSectionSegment(PMM_SECTION_SEGMENT Segment)
@@ -2489,38 +2569,6 @@
return(STATUS_SUCCESS);
}
-static ULONG SectionCharacteristicsToProtect[16] =
- {
- PAGE_NOACCESS, // 0 = NONE
- PAGE_NOACCESS, // 1 = SHARED
- PAGE_EXECUTE, // 2 = EXECUTABLE
- PAGE_EXECUTE, // 3 = EXECUTABLE, SHARED
- PAGE_READONLY, // 4 = READABLE
- PAGE_READONLY, // 5 = READABLE, SHARED
- PAGE_EXECUTE_READ, // 6 = READABLE, EXECUTABLE
- PAGE_EXECUTE_READ, // 7 = READABLE, EXECUTABLE, SHARED
- PAGE_READWRITE, // 8 = WRITABLE
- PAGE_READWRITE, // 9 = WRITABLE, SHARED
- PAGE_EXECUTE_READWRITE, // 10 = WRITABLE, EXECUTABLE
- PAGE_EXECUTE_READWRITE, // 11 = WRITABLE, EXECUTABLE, SHARED
- PAGE_READWRITE, // 12 = WRITABLE, READABLE
- PAGE_READWRITE, // 13 = WRITABLE, READABLE, SHARED
- PAGE_EXECUTE_READWRITE, // 14 = WRITABLE, READABLE, EXECUTABLE,
- PAGE_EXECUTE_READWRITE, // 15 = WRITABLE, READABLE, EXECUTABLE, SHARED
- };
-
-static ULONG ElfProgramHeaderFlagsToProtect[8] =
- {
- PAGE_NOACCESS, /* 0 = NONE */
- PAGE_EXECUTE, /* 1 = EXECUTABLE */
- PAGE_READWRITE, /* 2 = WRITABLE */
- PAGE_EXECUTE_READWRITE, /* 3 = WRITABLE, EXECUTABLE */
- PAGE_READONLY, /* 4 = READABLE */
- PAGE_EXECUTE_READ, /* 5 = READABLE, EXECUTABLE */
- PAGE_READWRITE, /* 6 = READABLE, WRITABLE */
- PAGE_EXECUTE_READWRITE, /* 7 = READABLE, EXECUTABLE, WRITABLE */
- };
-
NTSTATUS
MmCreateImageSection(PSECTION_OBJECT *SectionObject,
ACCESS_MASK DesiredAccess,
@@ -2528,49 +2576,42 @@
PLARGE_INTEGER UMaximumSize,
ULONG SectionPageProtection,
ULONG AllocationAttributes,
- HANDLE FileHandle)
+ PFILE_OBJECT FileObject)
{
- PSECTION_OBJECT Section;
NTSTATUS Status;
- PFILE_OBJECT FileObject;
- union {
- IMAGE_DOS_HEADER DosHeader;
-#ifdef _ELF_SUPPORT
- IMAGE_ELF_HEADER ElfHeader;
-#endif /* _ELF_SUPPORT */
- } FileHeader;
- IO_STATUS_BLOCK Iosb;
- LARGE_INTEGER Offset;
- IMAGE_NT_HEADERS PEHeader;
- PMM_SECTION_SEGMENT SectionSegments;
- ULONG NrSegments;
+ PSECTION_OBJECT Section;
PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
- ULONG i;
- ULONG Size;
- ULONG Characteristics;
- ULONG FileAccess = 0;
/*
* Specifying a maximum size is meaningless for an image section
*/
if (UMaximumSize != NULL)
- {
return(STATUS_INVALID_PARAMETER_4);
- }
/*
- * Reference the file handle
+ * Create the section
*/
- Status = ObReferenceObjectByHandle(FileHandle,
- FileAccess,
- IoFileObjectType,
- UserMode,
- (PVOID*)(PVOID)&FileObject,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- return Status;
- }
+ Status = ObCreateObject (ExGetPreviousMode(),
+ MmSectionObjectType,
+ ObjectAttributes,
+ ExGetPreviousMode(),
+ NULL,
+ sizeof(SECTION_OBJECT),
+ 0,
+ 0,
+ (PVOID*)&Section);
+
+ if (!NT_SUCCESS(nStatus))
+ return nStatus;
+
+ /*
+ * Initialize it
+ */
+ Section->SectionPageProtection = SectionPageProtection;
+ Section->AllocationAttributes = AllocationAttributes;
+ InitializeListHead(&Section->ViewListHead);
+ KeInitializeSpinLock(&Section->ViewListLock);
+ Section->FileObject = FileObject;
/*
* Initialized caching for this file object if previously caching
@@ -2580,754 +2621,114 @@
if (!NT_SUCCESS(Status) || FileObject->SectionObjectPointer->ImageSectionObject == NULL)
{
- PIMAGE_SECTION_HEADER ImageSections = NULL;
-#ifdef _ELF_SUPPORT
- PIMAGE_ELF_PROGRAM_HEADER ElfImagePHeaders = NULL;
- BOOL ElfImageDynamic = FALSE;
- PCHAR ElfImageInterp = NULL;
-#endif
-
- /*
- * Read the DOS/ELF header and check the signature
- */
- Offset.QuadPart = 0;
- Status = ZwReadFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &Iosb,
- &FileHeader,
- sizeof(FileHeader),
- &Offset,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(FileObject);
- return(Status);
- }
+ PVOID FileHeader;
+ SIZE_T FileHeaderSize;
+ LARGE_INTEGER FileSize;
+ ULONG i;
/*
- * Check the DOS/ELF signature
+ * Allocate the image section object
*/
- if (Iosb.Information != sizeof(FileHeader) ||
- (FileHeader.DosHeader.e_magic != IMAGE_DOS_SIGNATURE &&
-#ifdef _ELF_SUPPORT
- !IMAGE_IS_ELF(FileHeader.ElfHeader)))
-#else
- TRUE))
-#endif
- {
- ObDereferenceObject(FileObject);
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
+ ImageSectionObject = ExAllocatePoolWithTag (NonPagedPool,
+ sizeof(MM_IMAGE_SECTION_OBJECT),
+ TAG_MM_SECTION_SEGMENT);
- if (FileHeader.DosHeader.e_magic == IMAGE_DOS_SIGNATURE)
+ if (ImageSectionObject == NULL)
{
- /*
- * Read the PE header
- */
- Offset.QuadPart = FileHeader.DosHeader.e_lfanew;
- Status = ZwReadFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &Iosb,
- &PEHeader,
- sizeof(PEHeader),
- &Offset,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(FileObject);
- return(Status);
- }
-
- /*
- * Check the signature
- */
- if (Iosb.Information != sizeof(PEHeader) ||
- PEHeader.Signature != IMAGE_NT_SIGNATURE)
- {
- ObDereferenceObject(FileObject);
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
-
- /*
- * Read in the section headers
- */
- Offset.QuadPart = FileHeader.DosHeader.e_lfanew + sizeof(PEHeader);
- ImageSections = ExAllocatePool(NonPagedPool,
- PEHeader.FileHeader.NumberOfSections *
- sizeof(IMAGE_SECTION_HEADER));
- if (ImageSections == NULL)
- {
- ObDereferenceObject(FileObject);
- return(STATUS_NO_MEMORY);
- }
-
- Status = ZwReadFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &Iosb,
- ImageSections,
- PEHeader.FileHeader.NumberOfSections *
- sizeof(IMAGE_SECTION_HEADER),
- &Offset,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ImageSections);
- return(Status);
- }
- if (Iosb.Information != (PEHeader.FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER)))
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ImageSections);
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
- NrSegments = PEHeader.FileHeader.NumberOfSections;
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto l_DereferenceSection;
}
- else
- {
-#ifdef _ELF_SUPPORT
- BOOL ElfImageOk = TRUE;
-
- assert(IMAGE_IS_ELF(FileHeader.ElfHeader));
-
- /*
- * Check the ELF type, target, ...
- */
- if (FileHeader.ElfHeader.Ident[IMAGE_ELF_IDENT_CLASS] != IMAGE_ELF_TARGET_CLASS ||
- FileHeader.ElfHeader.Ident[IMAGE_ELF_IDENT_DATA] != IMAGE_ELF_TARGET_DATA)
- {
- DPRINT1("ELF: unsupported file layout\n");
- ElfImageOk = FALSE;
- }
- else if (FileHeader.ElfHeader.Ident[IMAGE_ELF_IDENT_VERSION] != IMAGE_ELF_VERSION_CURRENT ||
- FileHeader.ElfHeader.Version != IMAGE_ELF_VERSION_CURRENT)
- {
- DPRINT1("ELF: unsupported file version\n");
- ElfImageOk = FALSE;
- }
- else if (FileHeader.ElfHeader.Type != IMAGE_ELF_TYPE_EXEC &&
- FileHeader.ElfHeader.Type != IMAGE_ELF_TYPE_DYN)
- {
- DPRINT1("ELF: unsupported file type\n");
- ElfImageOk = FALSE;
- }
- else if (FileHeader.ElfHeader.Machine != IMAGE_ELF_TARGET_MACHINE)
- {
- DPRINT1("ELF: unsupported machine\n");
- ElfImageOk = FALSE;
- }
- else if (FileHeader.ElfHeader.PhEntSize != sizeof(IMAGE_ELF_PROGRAM_HEADER))
- {
- DPRINT1("ELF: invalid object: ElfHeader.PhEntSize != sizeof(IMAGE_ELF_PROGRAM_HEADER)\n");
- ElfImageOk = FALSE;
- }
- else if (FileHeader.ElfHeader.PhOff == 0)
- {
- DPRINT1("ELF: file does not contain a program header table (PhOff == 0)\n");
- ElfImageOk = FALSE;
- }
- else if (FileHeader.ElfHeader.PhNum == 0)
- {
- DPRINT1("ELF: file does not contain a program header table (PhNum == 0)\n");
- ElfImageOk = FALSE;
- }
-
- if (!ElfImageOk)
- {
- ObDereferenceObject(FileObject);
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
-
- /*
- * Read in the program header table
- */
- Offset.QuadPart = FileHeader.ElfHeader.PhOff;
- ElfImagePHeaders = ExAllocatePool(NonPagedPool,
- FileHeader.ElfHeader.PhNum *
- sizeof(IMAGE_ELF_PROGRAM_HEADER));
- if (ElfImagePHeaders == NULL)
- {
- ObDereferenceObject(FileObject);
- return(STATUS_NO_MEMORY);
- }
-
- Status = ZwReadFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &Iosb,
- ElfImagePHeaders,
- FileHeader.ElfHeader.PhNum *
- sizeof(IMAGE_ELF_PROGRAM_HEADER),
- &Offset,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- return(Status);
- }
- if (Iosb.Information != (FileHeader.ElfHeader.PhNum * sizeof(IMAGE_ELF_PROGRAM_HEADER)))
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
-
- /*
- * Get some important program headers (.dynamic, .interp), count number of loadable segments
- */
- NrSegments = 0;
- for (i = 0; i < FileHeader.ElfHeader.PhNum; i++)
- {
- switch (ElfImagePHeaders[i].Type)
- {
- case IMAGE_ELF_SEGMENT_TYPE_NULL:
- case IMAGE_ELF_SEGMENT_TYPE_PHDR:
- break;
-
- case IMAGE_ELF_SEGMENT_TYPE_LOAD:
- /* Check alignment of segment */
- if (ElfImagePHeaders[i].Align > 1 && ElfImagePHeaders[i].Align < PAGE_SIZE)
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- if (ElfImageInterp != NULL)
- ExFreePool(ElfImageInterp);
-
- DPRINT1("ELF: IMAGE_ELF_SEGMENT_TYPE_LOAD Segment %d not page-aligned\n", i);
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
- NrSegments++;
- break;
-
- case IMAGE_ELF_SEGMENT_TYPE_DYNAMIC: /* dynamically linked image */
- ElfImageDynamic = TRUE;
- break;
- case IMAGE_ELF_SEGMENT_TYPE_INTERP:
- /* Allocate memory for interpreter */
- if (ElfImageInterp != NULL)
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- ExFreePool(ElfImageInterp);
- DPRINT1("ELF: Only one IMAGE_ELF_SEGMENT_TYPE_INTERP segment allowed\n");
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
- Size = max(ElfImagePHeaders[i].MemSz, ElfImagePHeaders[i].FileSz + 1);
- ElfImageInterp = ExAllocatePool(NonPagedPool, Size);
- if (ElfImageInterp == NULL)
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- return(STATUS_NO_MEMORY);
- }
-
- /* Read interpreter path */
- Offset.QuadPart = ElfImagePHeaders[i].Offset;
- Status = ZwReadFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &Iosb,
- ElfImageInterp,
- ElfImagePHeaders[i].FileSz,
- &Offset,
- 0);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- ExFreePool(ElfImageInterp);
- return(Status);
- }
- if (Iosb.Information != ElfImagePHeaders[i].FileSz)
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- ExFreePool(ElfImageInterp);
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
- ElfImageInterp[Size - 1] = '\0';
- break;
-
-#if 0
- case IMAGE_ELF_SEGMENT_TYPE_GNU_STACK:
- ElfImageStackExec = TRUE; /* Stack should be executable */
- break;
-#endif
- default: /* Unknown/unused type */
- DPRINT1("ELF: Segment %d has unknown type %d\n", i, ElfImagePHeaders[i].Type);
- break;
- }
- }
-
- if (NrSegments == 0) /* No loadable segments found */
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- if (ElfImageInterp != NULL)
- ExFreePool(ElfImageInterp);
- DPRINT1("ELF: No loadable segments found!\n");
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
-
- if (ElfImageDynamic)
- {
- HANDLE hInterpFile;
- OBJECT_ATTRIBUTES Attribs;
- ANSI_STRING AnsiInterp;
- UNICODE_STRING UnicodeInterp;
-
- if(ElfImageInterp == NULL)
- {
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
- DPRINT1("ELF: Dynamic image needs interpreter!\n");
- return(STATUS_INVALID_IMAGE_FORMAT);
- }
-
- /*
- * Release resources
- */
- ObDereferenceObject(FileObject);
- ExFreePool(ElfImagePHeaders);
-
- /*
- * The ELF file contains an interpreter, let's try to map it instead...
- */
- RtlInitAnsiString(&AnsiInterp, ElfImageInterp);
- Status = RtlAnsiStringToUnicodeString(&UnicodeInterp, &AnsiInterp, TRUE);
- ExFreePool(ElfImageInterp);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ELF: Couldn't convert interpreter from ansi to unicode!\n");
- return(Status);
- }
-
- InitializeObjectAttributes(&Attribs,
- &UnicodeInterp,
- (OBJ_CASE_INSENSITIVE | OBJ_INHERIT), /* FIXME: which flags to use? */
- NULL,
- NULL);
-
- Status = ZwCreateFile(&hInterpFile,
- GENERIC_READ | GENERIC_EXECUTE,
- &Attribs,
- &Iosb,
- NULL,
- FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ,
- FILE_OPEN,
- FILE_NON_DIRECTORY_FILE,
- NULL,
- 0);
-
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ELF: Couldn't open interpreter '%wZ'!\n", &UnicodeInterp);
- RtlFreeUnicodeString(&UnicodeInterp);
- return(Status);
- }
- RtlFreeUnicodeString(&UnicodeInterp);
-
- Status = MmCreateImageSection(SectionObject,
- DesiredAccess,
- NULL,
- NULL,
- PAGE_EXECUTE | PAGE_WRITECOPY,
- SEC_IMAGE,
- hInterpFile);
- ZwClose(hInterpFile);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ELF: Couldn't create section for interpreter (0x%x)\n", Status);
- }
- return(Status); /* The interpreter should take care of the rest... */
- }
-
- NrSegments = FileHeader.ElfHeader.PhNum;
-
-#else /* _ELF_SUPPORT */
- assert(0); /* should never be executed */
-#endif
- }
+ Section->ImageSection = ImageSectionObject;
/*
- * Create the section
+ * Lock the file
*/
- Status = ObCreateObject (ExGetPreviousMode(),
- MmSectionObjectType,
- ObjectAttributes,
- ExGetPreviousMode(),
- NULL,
- sizeof(SECTION_OBJECT),
- 0,
- 0,
- (PVOID*)(PVOID)&Section);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(FileObject);
- if (ImageSections != NULL)
- ExFreePool(ImageSections);
-#ifdef _ELF_SUPPORT
- if (ElfImagePHeaders != NULL)
- ExFreePool(ElfImagePHeaders);
- if (ElfImageInterp != NULL)
- ExFreePool(ElfImageInterp);
-#endif
- return(Status);
- }
+ Status = MmspWaitForFileLock(FileObject);
+ if (!NT_SUCCESS(nStatus))
+ goto l_FreeImageSection;
+
/*
- * Initialize it
+ * Query the file's size
*/
- Section->SectionPageProtection = SectionPageProtection;
- Section->AllocationAttributes = AllocationAttributes;
- Section->ImageSection = NULL;
- InitializeListHead(&Section->ViewListHead);
- KeInitializeSpinLock(&Section->ViewListLock);
+ Status = MmspQueryFileSize(FileObject, &FileSize);
- /*
- * Check file access required
- */
- if (SectionPageProtection & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE))
- {
- FileAccess = FILE_READ_DATA | FILE_WRITE_DATA;
- }
- else
- {
- FileAccess = FILE_READ_DATA;
- }
+ if (!NT_SUCCESS(Status))
+ goto l_UnlockFile;
- /*
- * Lock the file
- */
- Status = MmspWaitForFileLock(FileObject);
- if (Status != STATUS_SUCCESS)
+ if (FileSize.QuadPart < FileHeaderSize)
{
- ObDereferenceObject(Section);
- ObDereferenceObject(FileObject);
- if (ImageSections != NULL)
- ExFreePool(ImageSections);
-#ifdef _ELF_SUPPORT
- if (ElfImagePHeaders != NULL)
- ExFreePool(ElfImagePHeaders);
- if (ElfImageInterp != NULL)
- ExFreePool(ElfImageInterp);
-#endif
- return(Status);
+ Status = STATUS_UNSUCCESSFUL;
+ goto l_UnlockFile;
}
/*
- * allocate and fill the section segments to describe the mapping
+ * Read the beginning of the file (2 pages). Should be enough to contain
+ * all (or most) of the headers
*/
- NrSegments += 1; /* the first segment is special i guess... */
- Size = sizeof(MM_IMAGE_SECTION_OBJECT) + sizeof(MM_SECTION_SEGMENT) * NrSegments;
- ImageSectionObject = ExAllocatePoolWithTag(NonPagedPool, Size, TAG_MM_SECTION_SEGMENT);
- if (ImageSectionObject == NULL)
- {
- KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
- ObDereferenceObject(Section);
- ObDereferenceObject(FileObject);
- if (ImageSections != NULL)
- ExFreePool(ImageSections);
-#ifdef _ELF_SUPPORT
- if (ElfImagePHeaders != NULL)
- ExFreePool(ElfImagePHeaders);
- if (ElfImageInterp != NULL)
- ExFreePool(ElfImageInterp);
-#endif
- return(STATUS_NO_MEMORY);
- }
- Section->ImageSection = ImageSectionObject;
- ImageSectionObject->NrSegments = NrSegments;
- SectionSegments = ImageSectionObject->Segments;
+ FileHeaderSize = PAGE_SIZE * 2;
+ FileHeader = ExAllocatePool(NonPagedPool, FileHeaderSize);
- if (FileHeader.DosHeader.e_magic == IMAGE_DOS_SIGNATURE)
+ if (FileHeader == NULL)
{
- ImageSectionObject->ImageBase = (PVOID)PEHeader.OptionalHeader.ImageBase;
- ImageSectionObject->EntryPoint = (PVOID)PEHeader.OptionalHeader.AddressOfEntryPoint;
- ImageSectionObject->StackReserve = PEHeader.OptionalHeader.SizeOfStackReserve;
- ImageSectionObject->StackCommit = PEHeader.OptionalHeader.SizeOfStackCommit;
- ImageSectionObject->Subsystem = PEHeader.OptionalHeader.Subsystem;
- ImageSectionObject->MinorSubsystemVersion = PEHeader.OptionalHeader.MinorSubsystemVersion;
- ImageSectionObject->MajorSubsystemVersion = PEHeader.OptionalHeader.MajorSubsystemVersion;
- ImageSectionObject->ImageCharacteristics = PEHeader.FileHeader.Characteristics;
- ImageSectionObject->Machine = PEHeader.FileHeader.Machine;
- ImageSectionObject->Executable = (PEHeader.OptionalHeader.SizeOfCode != 0);
-
- SectionSegments[0].FileOffset = 0;
- SectionSegments[0].Characteristics = IMAGE_SECTION_CHAR_DATA;
- SectionSegments[0].Protection = PAGE_READONLY;
- SectionSegments[0].RawLength = PAGE_SIZE;
- SectionSegments[0].Length = PAGE_SIZE;
- SectionSegments[0].Flags = 0;
- SectionSegments[0].ReferenceCount = 1;
- SectionSegments[0].VirtualAddress = 0;
- SectionSegments[0].WriteCopy = TRUE;
- SectionSegments[0].Attributes = 0;
- ExInitializeFastMutex(&SectionSegments[0].Lock);
- RtlZeroMemory(&SectionSegments[0].PageDirectory, sizeof(SECTION_PAGE_DIRECTORY));
- for (i = 1; i < NrSegments; i++)
- {
- SectionSegments[i].FileOffset = ImageSections[i-1].PointerToRawData;
- SectionSegments[i].Characteristics = ImageSections[i-1].Characteristics;
-
- /*
- * Set up the protection and write copy variables.
- */
- Characteristics = ImageSections[i - 1].Characteristics;
- if (Characteristics & (IMAGE_SECTION_CHAR_READABLE|IMAGE_SECTION_CHAR_WRITABLE|IMAGE_SECTION_CHAR_EXECUTABLE))
- {
- SectionSegments[i].Protection = SectionCharacteristicsToProtect[Characteristics >> 28];
- SectionSegments[i].WriteCopy = !(Characteristics & IMAGE_SECTION_CHAR_SHARED);
- }
- else if (Characteristics & IMAGE_SECTION_CHAR_CODE)
- {
- SectionSegments[i].Protection = PAGE_EXECUTE_READ;
- SectionSegments[i].WriteCopy = TRUE;
- }
- else if (Characteristics & IMAGE_SECTION_CHAR_DATA)
- {
- SectionSegments[i].Protection = PAGE_READWRITE;
- SectionSegments[i].WriteCopy = TRUE;
- }
- else if (Characteristics & IMAGE_SECTION_CHAR_BSS)
- {
- SectionSegments[i].Protection = PAGE_READWRITE;
- SectionSegments[i].WriteCopy = TRUE;
- }
- else
- {
- SectionSegments[i].Protection = PAGE_NOACCESS;
- SectionSegments[i].WriteCopy = TRUE;
- }
-
- /*
- * Set up the attributes.
- */
- if (Characteristics & IMAGE_SECTION_CHAR_CODE)
- {
- SectionSegments[i].Attributes = 0;
- }
- else if (Characteristics & IMAGE_SECTION_CHAR_DATA)
- {
- SectionSegments[i].Attributes = 0;
- }
- else if (Characteristics & IMAGE_SECTION_CHAR_BSS)
- {
- SectionSegments[i].Attributes = MM_SECTION_SEGMENT_BSS;
- }
- else
- {
- SectionSegments[i].Attributes = 0;
- }
-
- SectionSegments[i].RawLength = ImageSections[i-1].SizeOfRawData;
- if (ImageSections[i-1].Misc.VirtualSize != 0)
- {
- SectionSegments[i].Length = ImageSections[i-1].Misc.VirtualSize;
- }
- else
- {
- SectionSegments[i].Length = ImageSections[i-1].SizeOfRawData;
- }
- SectionSegments[i].Flags = 0;
- SectionSegments[i].ReferenceCount = 1;
- SectionSegments[i].VirtualAddress = (PVOID)ImageSections[i-1].VirtualAddress;
- ExInitializeFastMutex(&SectionSegments[i].Lock);
- RtlZeroMemory(&SectionSegments[i].PageDirectory, sizeof(SECTION_PAGE_DIRECTORY));
- }
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto l_UnlockFile;
}
- else
- {
-#ifdef _ELF_SUPPORT
- ULONG j;
- ImageSectionObject->ImageBase = (PVOID)ElfImagePHeaders[0].VAddr;
- ImageSectionObject->EntryPoint = (PVOID)FileHeader.ElfHeader.Entry;
- if (FileHeader.ElfHeader.Entry != (ELF_ADDR)NULL)
- {
- ImageSectionObject->EntryPoint = (PVOID)((UINT_PTR)FileHeader.ElfHeader.Entry -
- (UINT_PTR)ImageSectionObject->ImageBase);
- }
- ImageSectionObject->StackReserve = 0x10000; /* FIXME: does ELF provide such info? */
- ImageSectionObject->StackCommit = 0x1000; /* FIXME: does ELF provide such info? */
- ImageSectionObject->Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI; /* FIXME: we need to extend ELF */
- ImageSectionObject->MajorSubsystemVersion = 4;
- ImageSectionObject->MinorSubsystemVersion = 0; /* WinNT 4.0 */
- ImageSectionObject->Executable = TRUE;
- ImageSectionObject->ImageCharacteristics = IMAGE_FILE_32BIT_MACHINE;
- if (FileHeader.ElfHeader.Type == IMAGE_ELF_TYPE_EXEC)
- {
- ImageSectionObject->ImageCharacteristics |= IMAGE_FILE_EXECUTABLE_IMAGE;
- }
- else
- {
- assert(FileHeader.ElfHeader.Type == IMAGE_ELF_TYPE_DYN);
- ImageSectionObject->ImageCharacteristics |= IMAGE_FILE_DLL;
- }
-
- if (FileHeader.ElfHeader.Machine == IMAGE_ELF_MACHINE_386)
- ImageSectionObject->Machine = IMAGE_FILE_MACHINE_I386;
- else
- {
- /*
- * This should never be reached because we check if
- * ElfHeader.Machine is IMAGE_ELF_TARGET_MACHINE above
- * and fail if it is not.
- */
- assert(0);
- }
+ Offset.QuadPart = 0;
+ Status = MmspPageRead (FileObject,
+ FileHeader,
+ FileHeaderSize,
+ &Offset,
+ &FileHeaderSize);
- /* FIXME: what is this first segment used for? */
- SectionSegments[0].FileOffset = 0;
- SectionSegments[0].Characteristics = IMAGE_SECTION_CHAR_DATA;
- SectionSegments[0].Protection = PAGE_READONLY;
- SectionSegments[0].RawLength = PAGE_SIZE;
- SectionSegments[0].Length = PAGE_SIZE;
- SectionSegments[0].Flags = 0;
- SectionSegments[0].ReferenceCount = 1;
- SectionSegments[0].VirtualAddress = 0;
- SectionSegments[0].WriteCopy = TRUE;
- SectionSegments[0].Attributes = 0;
- ExInitializeFastMutex(&SectionSegments[0].Lock);
- RtlZeroMemory(&SectionSegments[0].PageDirectory, sizeof(SECTION_PAGE_DIRECTORY));
- for (i = 1, j = 0; j < (NrSegments - 1); j++)
- {
- if (ElfImagePHeaders[j].Type != IMAGE_ELF_SEGMENT_TYPE_LOAD)
- continue;
+ if (!NT_SUCCESS(Status))
+ goto l_UnlockFile;
- SectionSegments[i].FileOffset = ElfImagePHeaders[j].Offset;
+ if (FileHeaderSize == 0)
+ {
+ Status = STATUS_UNSUCCESSFUL;
+ goto l_UnlockFile;
+ }
- /*
- * Fill in characteristics
- */
- Characteristics = 0;
- if (ElfImagePHeaders[j].Flags & IMAGE_ELF_SEGMENT_FLAG_READ)
- Characteristics |= IMAGE_SECTION_CHAR_READABLE;
- if (ElfImagePHeaders[j].Flags & IMAGE_ELF_SEGMENT_FLAG_WRITE)
- Characteristics |= IMAGE_SECTION_CHAR_WRITABLE;
- if (ElfImagePHeaders[j].Flags & IMAGE_ELF_SEGMENT_FLAG_EXEC)
- Characteristics |= IMAGE_SECTION_CHAR_EXECUTABLE | IMAGE_SECTION_CHAR_CODE;
- else /* not executable, must be some kind of data */
- Characteristics |= (ElfImagePHeaders[j].FileSz > 0) ? IMAGE_SECTION_CHAR_DATA :
- IMAGE_SECTION_CHAR_BSS;
- SectionSegments[i].Characteristics = Characteristics;
+ /* Just in case */
+ FileSize.QuadPart = RtlRosMax(FileSize.QuadPart, FileHeaderSize);
- /*
- * Set up the protection and write copy variables.
- */
- SectionSegments[i].Protection = ElfProgramHeaderFlagsToProtect[ElfImagePHeaders[j].Flags & 7];
- SectionSegments[i].WriteCopy = TRUE; /* ELF does not support shared segments */
+ /* FIXME */
- /*
- * Set up the attributes.
- */
- if (Characteristics & IMAGE_SECTION_CHAR_CODE)
- {
- SectionSegments[i].Attributes = 0;
- }
- else if (Characteristics & IMAGE_SECTION_CHAR_DATA)
- {
- SectionSegments[i].Attributes = 0;
- }
- else if (Characteristics & IMAGE_SECTION_CHAR_BSS)
- {
- SectionSegments[i].Attributes = MM_SECTION_SEGMENT_BSS;
- }
- else
- {
- SectionSegments[i].Attributes = 0;
- }
+ ExFreePool(FileHeader);
- SectionSegments[i].RawLength = ElfImagePHeaders[j].FileSz;
- SectionSegments[i].Length = ElfImagePHeaders[j].MemSz; /* FIXME: I hope these are correct */
+ if (!NT_SUCCESS(Status))
+ goto l_UnlockFile;
- SectionSegments[i].Flags = 0;
- SectionSegments[i].ReferenceCount = 1;
- SectionSegments[i].VirtualAddress = (PVOID)((UINT_PTR)ElfImagePHeaders[j].VAddr -
- (UINT_PTR)ImageSectionObject->ImageBase);
- ExInitializeFastMutex(&SectionSegments[i].Lock);
- RtlZeroMemory(&SectionSegments[i].PageDirectory, sizeof(SECTION_PAGE_DIRECTORY));
-
- i++;
- }
- ImageSectionObject->NrSegments = i;
-
-#else /* if !_ELF_SUPPORT */
- assert(0);
-#endif /* !_ELF_SUPPORT */
- }
if (0 != InterlockedCompareExchange((PLONG)&FileObject->SectionObjectPointer->ImageSectionObject,
(LONG)ImageSectionObject, 0))
{
/*
- * An other thread has initialized the same image in the background
+ * An other thread has initialized the some image in the background
*/
ExFreePool(ImageSectionObject);
ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
Section->ImageSection = ImageSectionObject;
- SectionSegments = ImageSectionObject->Segments;
- for (i = 0; i < NrSegments; i++)
+ for (i = 0; i < ImageSectionObject->NrSegments; i++)
{
- InterlockedIncrement((LONG *)&SectionSegments[i].ReferenceCount);
+ InterlockedIncrement((LONG *)&ImageSectionObject->Segments[i].ReferenceCount);
}
}
- if (ImageSections != NULL)
- ExFreePool(ImageSections);
- if (ElfImagePHeaders != NULL)
- ExFreePool(ElfImagePHeaders);
- }
- else
- {
- /*
- * Create the section
- */
- Status = ObCreateObject (ExGetPreviousMode(),
- MmSectionObjectType,
- ObjectAttributes,
- ExGetPreviousMode(),
- NULL,
- sizeof(SECTION_OBJECT),
- 0,
[truncated at 1000 lines; 82 more skipped]
CVSspam 0.2.8