reactos/include
diff -u -r1.19 -r1.19.32.1
--- pe.h 3 Aug 2003 15:34:52 -0000 1.19
+++ pe.h 9 Dec 2004 19:31:26 -0000 1.19.32.1
@@ -104,7 +104,46 @@
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
-} IMAGE_OPTIONAL_HEADER,*PIMAGE_OPTIONAL_HEADER;
+} IMAGE_OPTIONAL_HEADER32,*PIMAGE_OPTIONAL_HEADER32;
+typedef struct _IMAGE_OPTIONAL_HEADER64 {
+ WORD Magic;
+ BYTE MajorLinkerVersion;
+ BYTE MinorLinkerVersion;
+ DWORD SizeOfCode;
+ DWORD SizeOfInitializedData;
+ DWORD SizeOfUninitializedData;
+ DWORD AddressOfEntryPoint;
+ DWORD BaseOfCode;
+ ULONGLONG ImageBase;
+ DWORD SectionAlignment;
+ DWORD FileAlignment;
+ WORD MajorOperatingSystemVersion;
+ WORD MinorOperatingSystemVersion;
+ WORD MajorImageVersion;
+ WORD MinorImageVersion;
+ WORD MajorSubsystemVersion;
+ WORD MinorSubsystemVersion;
+ DWORD Reserved1;
+ DWORD SizeOfImage;
+ DWORD SizeOfHeaders;
+ DWORD CheckSum;
+ WORD Subsystem;
+ WORD DllCharacteristics;
+ ULONGLONG SizeOfStackReserve;
+ ULONGLONG SizeOfStackCommit;
+ ULONGLONG SizeOfHeapReserve;
+ ULONGLONG SizeOfHeapCommit;
+ DWORD LoaderFlags;
+ DWORD NumberOfRvaAndSizes;
+ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_OPTIONAL_HEADER64,*PIMAGE_OPTIONAL_HEADER64;
+#ifdef _WIN64
+typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
+typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
+#else
+typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
+typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
+#endif
typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
WORD Magic;
BYTE MajorLinkerVersion;
@@ -180,8 +219,20 @@
typedef struct _IMAGE_NT_HEADERS {
DWORD Signature;
IMAGE_FILE_HEADER FileHeader;
- IMAGE_OPTIONAL_HEADER OptionalHeader;
-} IMAGE_NT_HEADERS,*PIMAGE_NT_HEADERS;
+ IMAGE_OPTIONAL_HEADER32 OptionalHeader;
+} IMAGE_NT_HEADERS32,*PIMAGE_NT_HEADERS32;
+typedef struct _IMAGE_NT_HEADERS64 {
+ DWORD Signature;
+ IMAGE_FILE_HEADER FileHeader;
+ IMAGE_OPTIONAL_HEADER64 OptionalHeader;
+} IMAGE_NT_HEADERS64,*PIMAGE_NT_HEADERS64;
+#ifdef _WIN64
+typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS;
+typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS;
+#else
+typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS;
+typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
+#endif
typedef struct _IMAGE_ROM_HEADERS {
IMAGE_FILE_HEADER FileHeader;
IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
@@ -555,8 +606,14 @@
#define IMAGE_SIZEOF_FILE_HEADER 20
#define IMAGE_FILE_MACHINE_UNKNOWN 0
#define IMAGE_NT_SIGNATURE 0x00004550
-#define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
+#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
+#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
#define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
+#ifdef _WIN64
+#define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
+#else
+#define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
+#endif
#define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
#define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56
reactos/include/reactos
diff -u -r1.1.2.1 -r1.1.2.2
--- exeformat.h 8 Dec 2004 20:01:39 -0000 1.1.2.1
+++ exeformat.h 9 Dec 2004 19:31:26 -0000 1.1.2.2
@@ -1,6 +1,33 @@
#ifndef REACTOS_EXEFORMAT_H_INCLUDED_
#define REACTOS_EXEFORMAT_H_INCLUDED_ 1
+/*
+ * LOADER API
+ */
+#define EXEFMT_LOAD_ASSUME_SEGMENTS_SORTED (1 << 0)
+#define EXEFMT_LOAD_ASSUME_SEGMENTS_NO_OVERLAP (1 << 1)
+#define EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED (1 << 2)
+/*
+ * CALLBACKS
+ */
+typedef NTSTATUS (NTAPI * PEXEFMT_LOADER_READ_FILE)
+(
+ IN struct _FILE_OBJECT * FileObject,
+ OUT PVOID Buffer,
+ IN ULONG BufferSize,
+ IN PLARGE_INTEGER Offset,
+ OUT PULONG ReadSize
+);
+
+typedef PMM_SECTION_SEGMENT (NTAPI * PEXEFMT_LOADER_ALLOCATE_SEGMENTS)
+(
+ IN ULONG NrSegments
+);
+
+/*
+ * STATUS CONSTANTS
+ */
+
#define FACILITY_ROS_EXEFMT (0x10)
/*
@@ -8,20 +35,21 @@
* 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 */
+#define STATUS_ROS_EXEFMT_UNKNOWN_FORMAT (0xA0100001)
/*
* Returned by MmCreateSection to signal successful loading of an executable
* image, saving the caller the effort of determining the executable's format
- * again
+ * again. The full status to return is obtained by performing a bitwise OR of
+ * STATUS_ROS_EXEFMT_LOADED_FORMAT and the appropriate EXEFMT_LOADED_XXX
*/
#define FACILITY_ROS_EXEFMT_FORMAT (0x11)
-#define STATUS_ROS_EXEFMT_LOADED_FORMAT /* TODO */
+#define STATUS_ROS_EXEFMT_LOADED_FORMAT (0x60110000)
/* non-standard format, ZwQuerySection required to retrieve the format tag */
#define EXEFMT_LOADED_EXTENDED (0x0000FFFF)
-/* Windows PE/PE+ */
+/* Windows PE32/PE32+ */
#define EXEFMT_LOADED_PE32 (0x00000000)
#define EXEFMT_LOADED_PE64 (0x00000001)
reactos/ntoskrnl/mm
diff -u -r1.1.2.1 -r1.1.2.2
--- pe.c 8 Dec 2004 20:01:41 -0000 1.1.2.1
+++ pe.c 9 Dec 2004 19:31:26 -0000 1.1.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: pe.c,v 1.1.2.1 2004/12/08 20:01:41 hyperion Exp $
+/* $Id: pe.c,v 1.1.2.2 2004/12/09 19:31:26 hyperion Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/pe.c
@@ -24,14 +24,18 @@
* PROGRAMMER: KJK::Hyperion <hackbunny@reactos.com>
* UPDATE HISTORY:
* 2004-12-06 Created
+ * 2004-12-09 Compiles
*/
/* INCLUDES *****************************************************************/
#include <ntoskrnl.h>
+
#define NDEBUG
#include <internal/debug.h>
+#include <reactos/exeformat.h>
+
static ULONG SectionCharacteristicsToProtect[16] =
{
PAGE_NOACCESS, /* 0 = NONE */
@@ -147,7 +151,7 @@
BOOLEAN FASTCALL Intsafe_CanOffsetPointer
(
- IN PVOID Pointer,
+ IN CONST VOID * Pointer,
IN SIZE_T Offset
)
{
@@ -155,6 +159,21 @@
return Intsafe_CanAddULongPtr((ULONG_PTR)Pointer, Offset);
}
+/* TODO: these are standard DDK/PSDK macros */
+#ifndef RTL_FIELD_SIZE
+#define RTL_FIELD_SIZE(TYPE_, FIELD_) (sizeof(((TYPE_ *)0)->FIELD_))
+#endif
+
+#ifndef RTL_SIZEOF_THROUGH_FIELD
+#define RTL_SIZEOF_THROUGH_FIELD(TYPE_, FIELD_) \
+ (FIELD_OFFSET(TYPE_, FIELD_) + RTL_FIELD_SIZE(TYPE_, FIELD_))
+#endif
+
+#ifndef RTL_CONTAINS_FIELD
+#define RTL_CONTAINS_FIELD(P_, SIZE_, FIELD_) \
+ ((((char *)(P_)) + (SIZE_)) > (((char *)(&((P_)->FIELD_))) + sizeof((P_)->FIELD_)))
+#endif
+
BOOLEAN FASTCALL IsPowerOf2(IN ULONG Number)
{
if(Number == 0)
@@ -213,14 +232,15 @@
ULONG cbSectionHeadersOffset;
ULONG cbSectionHeadersSize;
ULONG cbSectionHeadersOffsetSize;
+ ULONG cbOptHeaderSize;
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;
+ const IMAGE_DOS_HEADER * pidhDosHeader;
+ const IMAGE_NT_HEADERS32 * pinhNtHeader;
+ const IMAGE_OPTIONAL_HEADER32 * piohOptHeader;
+ const IMAGE_SECTION_HEADER * pishSectionHeaders;
+ PMM_SECTION_SEGMENT pssSegments;
LARGE_INTEGER lnOffset;
PVOID pBuffer;
ULONG nPrevVirtualEndOfSegment;
@@ -426,7 +446,7 @@
goto l_Return;
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, ImageBase))
- ImageSectionObject->ImageBase = (PVOID)piohOptHeader->ImageBase;
+ ImageSectionObject->ImageBase = piohOptHeader->ImageBase;
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfStackReserve))
ImageSectionObject->StackReserve = piohOptHeader->SizeOfStackReserve;
@@ -452,7 +472,7 @@
if(pioh64OptHeader->ImageBase > MAXULONG_PTR)
goto l_Return;
- ImageSectionObject->ImageBase = (PVOID)pioh64OptHeader->ImageBase;
+ ImageSectionObject->ImageBase = pioh64OptHeader->ImageBase;
}
if(RTL_CONTAINS_FIELD(pioh64OptHeader, cbOptHeaderSize, SizeOfStackReserve))
@@ -516,7 +536,7 @@
}
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, AddressOfEntryPoint))
- ImageSectionObject->EntryPoint = (PVOID)piohOptHeader->AddressOfEntryPoint;
+ ImageSectionObject->EntryPoint = piohOptHeader->AddressOfEntryPoint;
if(RTL_CONTAINS_FIELD(piohOptHeader, cbOptHeaderSize, SizeOfCode))
ImageSectionObject->Executable = piohOptHeader->SizeOfCode != 0;
@@ -695,7 +715,7 @@
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_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;
@@ -742,7 +762,7 @@
/* Success */
nStatus = STATUS_ROS_EXEFMT_LOADED_FORMAT & EXEFMT_LOADED_PE32;
-l_Return;
+l_Return:
if(pBuffer)
ExFreePool(pBuffer);