ReactOS 0.4.15-dev-8135-g1bc6c90
exeformat.h
Go to the documentation of this file.
1#ifndef REACTOS_EXEFORMAT_H_INCLUDED_
2#define REACTOS_EXEFORMAT_H_INCLUDED_ 1
3
4/*
5 * LOADER API
6 */
7/* OUT flags returned by a loader */
8#define EXEFMT_LOAD_ASSUME_SEGMENTS_SORTED (1 << 0)
9#define EXEFMT_LOAD_ASSUME_SEGMENTS_NO_OVERLAP (1 << 1)
10#define EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED (1 << 2)
11
12#define EXEFMT_LOAD_ASSUME_SEGMENTS_OK \
13 ( \
14 EXEFMT_LOAD_ASSUME_SEGMENTS_SORTED | \
15 EXEFMT_LOAD_ASSUME_SEGMENTS_NO_OVERLAP | \
16 EXEFMT_LOAD_ASSUME_SEGMENTS_PAGE_ALIGNED \
17 )
18
19/*
20 Minumum size of the buffer passed to each loader for identification of the
21 executable
22*/
23#define EXEFMT_LOAD_HEADER_SIZE (0x2000)
24
25/* Special values for the base address of images */
26/*
27 Base address can't be represented in an ULONG_PTR: any effective load address
28 will require relocation
29*/
30#define EXEFMT_LOAD_BASE_NONE ((ULONG_PTR)-1)
31
32/* Base address never matters, relocation never required */
33#define EXEFMT_LOAD_BASE_ANY ((ULONG_PTR)-2)
34
36(
40 OUT PVOID * Data,
41 OUT PVOID * AllocBase,
42 OUT PULONG ReadSize
43);
44
46(
47 IN ULONG NrSegments
48);
49
51(
52 IN CONST VOID * FileHeader,
53 IN SIZE_T FileHeaderSize,
55 OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject,
57 IN PEXEFMT_CB_READ_FILE ReadFileCb,
58 IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb
59);
60
61/*
62 * STATUS CONSTANTS
63 */
64
65#define FACILITY_ROS_EXEFMT (0x10)
66
67/*
68 * Returned by ExeFormat loaders to tell the caller the format isn't supported,
69 * as opposed to STATUS_INVALID_IMAGE_FORMAT meaning the format is supported,
70 * but the particular file is malformed
71 */
72#define STATUS_ROS_EXEFMT_UNKNOWN_FORMAT ((NTSTATUS)0xA0100001)
73
74/*
75 * Returned by MmCreateSection to signal successful loading of an executable
76 * image, saving the caller the effort of determining the executable's format
77 * again. The full status to return is obtained by performing a bitwise OR of
78 * STATUS_ROS_EXEFMT_LOADED_FORMAT and the appropriate EXEFMT_LOADED_XXX
79 */
80#define FACILITY_ROS_EXEFMT_FORMAT (0x11)
81#define STATUS_ROS_EXEFMT_LOADED_FORMAT ((NTSTATUS)0x60110000)
82
83/* non-standard format, ZwQuerySection required to retrieve the format tag */
84#define EXEFMT_LOADED_EXTENDED (0x0000FFFF)
85
86/* Windows PE32/PE32+ */
87#define EXEFMT_LOADED_PE32 (0x00000000)
88#define EXEFMT_LOADED_PE64 (0x00000001)
89
90/* Wine ELF */
91#define EXEFMT_LOADED_WINE32 (0x00000002)
92#define EXEFMT_LOADED_WINE64 (0x00000003)
93
94/* regular ELF */
95#define EXEFMT_LOADED_ELF32 (0x00000004)
96#define EXEFMT_LOADED_ELF64 (0x00000005)
97
98/* TODO: Intsafe should be made into a library, as it's generally useful */
100{
101 return Addend1 <= (MAXULONG_PTR - Addend2);
102}
103
105{
106 return Addend1 <= (MAXLONGLONG - Addend2);
107}
108
110{
111 return Addend1 <= (MAXULONG - Addend2);
112}
113
115{
116 if(!Intsafe_CanAddULong32(Addend1, Addend2))
117 return FALSE;
118
119 *Result = Addend1 + Addend2;
120 return TRUE;
121}
122
123static __inline BOOLEAN Intsafe_CanMulULong32(IN ULONG Factor1, IN ULONG Factor2)
124{
125 return Factor1 <= (MAXULONG / Factor2);
126}
127
129{
130 /* FIXME: (PVOID)MAXULONG_PTR isn't necessarily a valid address */
131 return Intsafe_CanAddULongPtr((ULONG_PTR)Pointer, Offset);
132}
133
135{
136 if(Number == 0)
137 return FALSE;
138 return (Number & (Number - 1)) == 0;
139}
140
142{
144 return Address & (Alignment - 1);
145}
146
148{
149 return ModPow2(Address, Alignment) == 0;
150}
151
152static __inline BOOLEAN AlignUp(OUT PULONG AlignedAddress, IN ULONG Address, IN ULONG Alignment)
153{
154 ULONG nExcess = ModPow2(Address, Alignment);
155
156 if(nExcess == 0)
157 {
158 *AlignedAddress = Address;
159 return nExcess == 0;
160 }
161 else
162 return Intsafe_AddULong32(AlignedAddress, Address, Alignment - nExcess);
163}
164
165#define PEFMT_FIELDS_EQUAL(TYPE1_, TYPE2_, FIELD_) \
166 ( \
167 (FIELD_OFFSET(TYPE1_, FIELD_) == FIELD_OFFSET(TYPE2_, FIELD_)) && \
168 (RTL_FIELD_SIZE(TYPE1_, FIELD_) == RTL_FIELD_SIZE(TYPE2_, FIELD_)) \
169 )
170#endif
171
172/* EOF */
unsigned char BOOLEAN
#define MAXULONG_PTR
Definition: basetsd.h:103
Definition: File.h:16
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NTSTATUS
Definition: precomp.h:21
static __inline BOOLEAN IsPowerOf2(IN ULONG Number)
Definition: exeformat.h:134
static __inline BOOLEAN Intsafe_CanAddLong64(IN LONG64 Addend1, IN LONG64 Addend2)
Definition: exeformat.h:104
static __inline ULONG ModPow2(IN ULONG Address, IN ULONG Alignment)
Definition: exeformat.h:141
NTSTATUS(NTAPI * PEXEFMT_CB_READ_FILE)(IN PVOID File, IN PLARGE_INTEGER Offset, IN ULONG Length, OUT PVOID *Data, OUT PVOID *AllocBase, OUT PULONG ReadSize)
Definition: exeformat.h:36
static __inline BOOLEAN Intsafe_CanMulULong32(IN ULONG Factor1, IN ULONG Factor2)
Definition: exeformat.h:123
NTSTATUS(NTAPI * PEXEFMT_LOADER)(IN CONST VOID *FileHeader, IN SIZE_T FileHeaderSize, IN PVOID File, OUT PMM_IMAGE_SECTION_OBJECT ImageSectionObject, OUT PULONG Flags, IN PEXEFMT_CB_READ_FILE ReadFileCb, IN PEXEFMT_CB_ALLOCATE_SEGMENTS AllocateSegmentsCb)
Definition: exeformat.h:51
static __inline BOOLEAN Intsafe_CanAddULong32(IN ULONG Addend1, IN ULONG Addend2)
Definition: exeformat.h:109
static __inline BOOLEAN AlignUp(OUT PULONG AlignedAddress, IN ULONG Address, IN ULONG Alignment)
Definition: exeformat.h:152
PMM_SECTION_SEGMENT(NTAPI * PEXEFMT_CB_ALLOCATE_SEGMENTS)(IN ULONG NrSegments)
Definition: exeformat.h:46
static __inline BOOLEAN IsAligned(IN ULONG Address, IN ULONG Alignment)
Definition: exeformat.h:147
static __inline BOOLEAN Intsafe_CanOffsetPointer(IN CONST VOID *Pointer, IN SIZE_T Offset)
Definition: exeformat.h:128
static __inline BOOLEAN Intsafe_CanAddULongPtr(IN ULONG_PTR Addend1, IN ULONG_PTR Addend2)
Definition: exeformat.h:99
static __inline BOOLEAN Intsafe_AddULong32(OUT PULONG Result, IN ULONG Addend1, IN ULONG Addend2)
Definition: exeformat.h:114
#define ASSERT(a)
Definition: mode.c:44
#define MAXLONGLONG
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
struct _MM_SECTION_SEGMENT * PMM_SECTION_SEGMENT
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
#define CONST
Definition: pedump.c:81
static WCHAR Address[46]
Definition: ping.c:68
#define MAXULONG
Definition: typedefs.h:251
uint32_t * PULONG
Definition: typedefs.h:59
int64_t LONG64
Definition: typedefs.h:68
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ LARGE_INTEGER Addend2
Definition: rtlfuncs.h:3087