xref: /reactos/sdk/include/ndk/ldrtypes.h (revision 53221834)
1 /*++ NDK Version: 0098
2 
3 Copyright (c) Alex Ionescu.  All rights reserved.
4 
5 Header Name:
6 
7     ldrtypes.h
8 
9 Abstract:
10 
11     Type definitions for the Loader.
12 
13 Author:
14 
15     Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006
16 
17 --*/
18 
19 #ifndef _LDRTYPES_H
20 #define _LDRTYPES_H
21 
22 //
23 // Dependencies
24 //
25 #include <umtypes.h>
26 
27 //
28 // Resource Type Levels
29 //
30 #define RESOURCE_TYPE_LEVEL                     0
31 #define RESOURCE_NAME_LEVEL                     1
32 #define RESOURCE_LANGUAGE_LEVEL                 2
33 #define RESOURCE_DATA_LEVEL                     3
34 
35 //
36 // Loader Data Table Entry Flags
37 //
38 #define LDRP_STATIC_LINK                        0x00000002
39 #define LDRP_IMAGE_DLL                          0x00000004
40 #define LDRP_SHIMENG_SUPPRESSED_ENTRY           0x00000008
41 #define LDRP_IMAGE_INTEGRITY_FORCED             0x00000020
42 #define LDRP_LOAD_IN_PROGRESS                   0x00001000
43 #define LDRP_UNLOAD_IN_PROGRESS                 0x00002000
44 #define LDRP_ENTRY_PROCESSED                    0x00004000
45 #define LDRP_ENTRY_INSERTED                     0x00008000
46 #define LDRP_CURRENT_LOAD                       0x00010000
47 #define LDRP_FAILED_BUILTIN_LOAD                0x00020000
48 #define LDRP_DONT_CALL_FOR_THREADS              0x00040000
49 #define LDRP_PROCESS_ATTACH_CALLED              0x00080000
50 #define LDRP_DEBUG_SYMBOLS_LOADED               0x00100000
51 #define LDRP_IMAGE_NOT_AT_BASE                  0x00200000
52 #define LDRP_COR_IMAGE                          0x00400000
53 #define LDR_COR_OWNS_UNMAP                      0x00800000
54 #define LDRP_SYSTEM_MAPPED                      0x01000000
55 #define LDRP_IMAGE_VERIFYING                    0x02000000
56 #define LDRP_DRIVER_DEPENDENT_DLL               0x04000000
57 #define LDRP_ENTRY_NATIVE                       0x08000000
58 #define LDRP_REDIRECTED                         0x10000000
59 #define LDRP_NON_PAGED_DEBUG_INFO               0x20000000
60 #define LDRP_MM_LOADED                          0x40000000
61 #define LDRP_COMPAT_DATABASE_PROCESSED          0x80000000
62 
63 //
64 // Dll Characteristics for LdrLoadDll
65 //
66 #define LDR_IGNORE_CODE_AUTHZ_LEVEL                 0x00001000
67 
68 //
69 // LdrAddRef Flags
70 //
71 #define LDR_ADDREF_DLL_PIN                          0x00000001
72 
73 //
74 // LdrLockLoaderLock Flags
75 //
76 #define LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS   0x00000001
77 #define LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY          0x00000002
78 
79 //
80 // LdrUnlockLoaderLock Flags
81 //
82 #define LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS 0x00000001
83 
84 //
85 // LdrGetDllHandleEx Flags
86 //
87 #define LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT    0x00000001
88 #define LDR_GET_DLL_HANDLE_EX_PIN                   0x00000002
89 
90 
91 #define LDR_LOCK_LOADER_LOCK_DISPOSITION_INVALID           0
92 #define LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED     1
93 #define LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED 2
94 
95 //
96 // FIXME: THIS SHOULD *NOT* BE USED!
97 //
98 #define IMAGE_SCN_TYPE_NOLOAD                   0x00000002
99 
100 //
101 // Loader datafile/imagemapping macros
102 //
103 #define LDR_IS_DATAFILE(handle)     (((ULONG_PTR)(handle)) & (ULONG_PTR)1)
104 #define LDR_IS_IMAGEMAPPING(handle) (((ULONG_PTR)(handle)) & (ULONG_PTR)2)
105 #define LDR_IS_RESOURCE(handle)     (LDR_IS_IMAGEMAPPING(handle) || LDR_IS_DATAFILE(handle))
106 
107 //
108 // Activation Context
109 //
110 typedef PVOID PACTIVATION_CONTEXT;
111 
112 //
113 // Loader Data stored in the PEB
114 //
115 typedef struct _PEB_LDR_DATA
116 {
117     ULONG Length;
118     BOOLEAN Initialized;
119     PVOID SsHandle;
120     LIST_ENTRY InLoadOrderModuleList;
121     LIST_ENTRY InMemoryOrderModuleList;
122     LIST_ENTRY InInitializationOrderModuleList;
123     PVOID EntryInProgress;
124 #if (NTDDI_VERSION >= NTDDI_WIN7)
125     UCHAR ShutdownInProgress;
126     PVOID ShutdownThreadId;
127 #endif
128 } PEB_LDR_DATA, *PPEB_LDR_DATA;
129 
130 //
131 // Loader Data Table Entry
132 //
133 // NOTE: The field 'InMemoryOrderLinks' MUST have that name.
134 // It's hard-coded into WinDbg for PEB dumping!
135 //
136 typedef struct _LDR_DATA_TABLE_ENTRY
137 {
138     LIST_ENTRY InLoadOrderLinks;
139     LIST_ENTRY InMemoryOrderLinks;
140     LIST_ENTRY InInitializationOrderLinks;
141     PVOID DllBase;
142     PVOID EntryPoint;
143     ULONG SizeOfImage;
144     UNICODE_STRING FullDllName;
145     UNICODE_STRING BaseDllName;
146     ULONG Flags;
147     USHORT LoadCount;
148     USHORT TlsIndex;
149     union
150     {
151         LIST_ENTRY HashLinks;
152         struct
153         {
154             PVOID SectionPointer;
155             ULONG CheckSum;
156         };
157     };
158     union
159     {
160         ULONG TimeDateStamp;
161         PVOID LoadedImports;
162     };
163     PACTIVATION_CONTEXT EntryPointActivationContext;
164     PVOID PatchInformation;
165 } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
166 
167 //
168 // Loaded Imports Reference Counting in Kernel
169 //
170 typedef struct _LOAD_IMPORTS
171 {
172     SIZE_T Count;
173     PLDR_DATA_TABLE_ENTRY Entry[1];
174 } LOAD_IMPORTS, *PLOAD_IMPORTS;
175 
176 //
177 // Loader Resource Information
178 //
179 typedef struct _LDR_RESOURCE_INFO
180 {
181     ULONG_PTR Type;
182     ULONG_PTR Name;
183     ULONG_PTR Language;
184 } LDR_RESOURCE_INFO, *PLDR_RESOURCE_INFO;
185 
186 typedef struct _LDR_ENUM_RESOURCE_INFO
187 {
188     ULONG_PTR Type;
189     ULONG_PTR Name;
190     ULONG_PTR Language;
191     PVOID Data;
192     SIZE_T Size;
193     ULONG_PTR Reserved;
194 } LDR_ENUM_RESOURCE_INFO, *PLDR_ENUM_RESOURCE_INFO;
195 
196 //
197 // DLL Notifications
198 //
199 typedef struct _LDR_DLL_LOADED_NOTIFICATION_DATA
200 {
201     ULONG Flags;
202     PUNICODE_STRING FullDllName;
203     PUNICODE_STRING BaseDllName;
204     PVOID DllBase;
205     ULONG SizeOfImage;
206 } LDR_DLL_LOADED_NOTIFICATION_DATA, *PLDR_DLL_LOADED_NOTIFICATION_DATA;
207 
208 typedef VOID
209 (NTAPI *PLDR_DLL_LOADED_NOTIFICATION_CALLBACK)(
210     _In_ BOOLEAN Type,
211     _In_ struct _LDR_DLL_LOADED_NOTIFICATION_DATA *Data
212 );
213 
214 typedef struct _LDR_DLL_LOADED_NOTIFICATION_ENTRY
215 {
216     LIST_ENTRY NotificationListEntry;
217     PLDR_DLL_LOADED_NOTIFICATION_CALLBACK Callback;
218 } LDR_DLL_LOADED_NOTIFICATION_ENTRY, *PLDR_DLL_LOADED_NOTIFICATION_ENTRY;
219 
220 //
221 // Alternate Resources Support
222 //
223 typedef struct _ALT_RESOURCE_MODULE
224 {
225     LANGID LangId;
226     PVOID ModuleBase;
227 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
228     PVOID ModuleManifest;
229 #endif
230     PVOID AlternateModule;
231 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
232     HANDLE AlternateFileHandle;
233     ULONG ModuleCheckSum;
234     ULONG ErrorCode;
235 #endif
236 } ALT_RESOURCE_MODULE, *PALT_RESOURCE_MODULE;
237 
238 //
239 // Callback function for LdrEnumerateLoadedModules
240 //
241 typedef VOID (NTAPI LDR_ENUM_CALLBACK)(_In_ PLDR_DATA_TABLE_ENTRY ModuleInformation, _In_ PVOID Parameter, _Out_ BOOLEAN *Stop);
242 typedef LDR_ENUM_CALLBACK *PLDR_ENUM_CALLBACK;
243 
244 //
245 // Manifest prober routine set via LdrSetDllManifestProber
246 //
247 typedef NTSTATUS (NTAPI LDR_MANIFEST_PROBER_ROUTINE)(_In_ PVOID DllHandle, _In_ PCWSTR FullDllName, _Out_ PVOID *ActCtx);
248 typedef LDR_MANIFEST_PROBER_ROUTINE *PLDR_MANIFEST_PROBER_ROUTINE;
249 
250 //
251 // DLL Main Routine
252 //
253 typedef BOOLEAN
254 (NTAPI *PDLL_INIT_ROUTINE)(
255     _In_ PVOID DllHandle,
256     _In_ ULONG Reason,
257     _In_opt_ PCONTEXT Context
258 );
259 
260 #endif
261