xref: /reactos/dll/ntdll/include/ntdllp.h (revision 9cfd8dd9)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS System Libraries
4  * FILE:            dll/ntdll/include/ntdllp.h
5  * PURPOSE:         Native Library Internal Header
6  * PROGRAMMER:      Alex Ionescu (alex@relsoft.net)
7  */
8 
9 #pragma once
10 
11 #define LDR_HASH_TABLE_ENTRIES 32
12 #define LDR_GET_HASH_ENTRY(x) (RtlUpcaseUnicodeChar((x)) & (LDR_HASH_TABLE_ENTRIES - 1))
13 
14 /* LdrpUpdateLoadCount2 flags */
15 #define LDRP_UPDATE_REFCOUNT   0x01
16 #define LDRP_UPDATE_DEREFCOUNT 0x02
17 #define LDRP_UPDATE_PIN        0x03
18 
19 /* Loader flags */
20 #define IMAGE_LOADER_FLAGS_COMPLUS 0x00000001
21 #define IMAGE_LOADER_FLAGS_SYSTEM_GLOBAL 0x01000000
22 
23 /* Page heap flags */
24 #define DPH_FLAG_DLL_NOTIFY 0x40
25 
26 typedef struct _LDRP_TLS_DATA
27 {
28     LIST_ENTRY TlsLinks;
29     IMAGE_TLS_DIRECTORY TlsDirectory;
30 } LDRP_TLS_DATA, *PLDRP_TLS_DATA;
31 
32 typedef
33 NTSTATUS
34 (NTAPI* PLDR_APP_COMPAT_DLL_REDIRECTION_CALLBACK_FUNCTION)(
35     _In_ ULONG Flags,
36     _In_ PCWSTR DllName,
37     _In_ PCWSTR DllPath OPTIONAL,
38     _Inout_opt_ PULONG DllCharacteristics,
39     _In_ PVOID CallbackData,
40     _Outptr_ PWSTR* EffectiveDllPath);
41 
42 /* Global data */
43 extern RTL_CRITICAL_SECTION LdrpLoaderLock;
44 extern BOOLEAN LdrpInLdrInit;
45 extern PVOID LdrpHeap;
46 extern LIST_ENTRY LdrpHashTable[LDR_HASH_TABLE_ENTRIES];
47 extern BOOLEAN ShowSnaps;
48 extern UNICODE_STRING LdrpDefaultPath;
49 extern HANDLE LdrpKnownDllObjectDirectory;
50 extern ULONG LdrpNumberOfProcessors;
51 extern ULONG LdrpFatalHardErrorCount;
52 extern PUNICODE_STRING LdrpTopLevelDllBeingLoaded;
53 extern PLDR_DATA_TABLE_ENTRY LdrpCurrentDllInitializer;
54 extern UNICODE_STRING LdrApiDefaultExtension;
55 extern BOOLEAN LdrpLdrDatabaseIsSetup;
56 extern ULONG LdrpActiveUnloadCount;
57 extern BOOLEAN LdrpShutdownInProgress;
58 extern UNICODE_STRING LdrpKnownDllPath;
59 extern PLDR_DATA_TABLE_ENTRY LdrpGetModuleHandleCache, LdrpLoadedDllHandleCache;
60 extern BOOLEAN RtlpPageHeapEnabled;
61 extern ULONG RtlpDphGlobalFlags;
62 extern BOOLEAN g_ShimsEnabled;
63 extern PVOID g_pShimEngineModule;
64 extern PVOID g_pfnSE_DllLoaded;
65 extern PVOID g_pfnSE_DllUnloaded;
66 extern PVOID g_pfnSE_InstallBeforeInit;
67 extern PVOID g_pfnSE_InstallAfterInit;
68 extern PVOID g_pfnSE_ProcessDying;
69 
70 /* ldrinit.c */
71 NTSTATUS NTAPI LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL);
72 VOID NTAPI LdrpInitializeThread(IN PCONTEXT Context);
73 NTSTATUS NTAPI LdrpInitializeTls(VOID);
74 NTSTATUS NTAPI LdrpAllocateTls(VOID);
75 VOID NTAPI LdrpFreeTls(VOID);
76 VOID NTAPI LdrpCallTlsInitializers(IN PLDR_DATA_TABLE_ENTRY LdrEntry, IN ULONG Reason);
77 BOOLEAN NTAPI LdrpCallInitRoutine(IN PDLL_INIT_ROUTINE EntryPoint, IN PVOID BaseAddress, IN ULONG Reason, IN PVOID Context);
78 NTSTATUS NTAPI LdrpInitializeProcess(IN PCONTEXT Context, IN PVOID SystemArgument1);
79 VOID NTAPI LdrpInitFailure(NTSTATUS Status);
80 VOID NTAPI LdrpValidateImageForMp(IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry);
81 VOID NTAPI LdrpEnsureLoaderLockIsHeld(VOID);
82 
83 /* ldrpe.c */
84 NTSTATUS
85 NTAPI
86 LdrpSnapThunk(IN PVOID ExportBase,
87               IN PVOID ImportBase,
88               IN PIMAGE_THUNK_DATA OriginalThunk,
89               IN OUT PIMAGE_THUNK_DATA Thunk,
90               IN PIMAGE_EXPORT_DIRECTORY ExportEntry,
91               IN ULONG ExportSize,
92               IN BOOLEAN Static,
93               IN LPSTR DllName);
94 
95 NTSTATUS NTAPI
96 LdrpWalkImportDescriptor(IN LPWSTR DllPath OPTIONAL,
97                          IN PLDR_DATA_TABLE_ENTRY LdrEntry);
98 
99 
100 /* ldrutils.c */
101 NTSTATUS
102 NTAPI
103 LdrpGetProcedureAddress(
104     _In_ PVOID BaseAddress,
105     _In_opt_ _When_(Ordinal == 0, _Notnull_) PANSI_STRING Name,
106     _In_opt_ _When_(Name == NULL, _In_range_(>, 0)) ULONG Ordinal,
107     _Out_ PVOID *ProcedureAddress,
108     _In_ BOOLEAN ExecuteInit);
109 
110 PLDR_DATA_TABLE_ENTRY NTAPI
111 LdrpAllocateDataTableEntry(IN PVOID BaseAddress);
112 
113 VOID NTAPI
114 LdrpInsertMemoryTableEntry(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
115 
116 NTSTATUS NTAPI
117 LdrpLoadDll(IN BOOLEAN Redirected,
118             IN PWSTR DllPath OPTIONAL,
119             IN PULONG DllCharacteristics OPTIONAL,
120             IN PUNICODE_STRING DllName,
121             OUT PVOID *BaseAddress,
122             IN BOOLEAN CallInit);
123 
124 VOID NTAPI
125 LdrpUpdateLoadCount2(IN PLDR_DATA_TABLE_ENTRY LdrEntry,
126                      IN ULONG Flags);
127 
128 ULONG NTAPI
129 LdrpClearLoadInProgress(VOID);
130 
131 NTSTATUS
132 NTAPI
133 LdrpSetProtection(PVOID ViewBase,
134                   BOOLEAN Restore);
135 
136 BOOLEAN
137 NTAPI
138 LdrpCheckForLoadedDllHandle(IN PVOID Base,
139                             OUT PLDR_DATA_TABLE_ENTRY *LdrEntry);
140 
141 BOOLEAN NTAPI
142 LdrpCheckForLoadedDll(IN PWSTR DllPath,
143                       IN PUNICODE_STRING DllName,
144                       IN BOOLEAN Flag,
145                       IN BOOLEAN RedirectedDll,
146                       OUT PLDR_DATA_TABLE_ENTRY *LdrEntry);
147 
148 NTSTATUS NTAPI
149 LdrpMapDll(IN PWSTR SearchPath OPTIONAL,
150            IN PWSTR DllPath2,
151            IN PWSTR DllName OPTIONAL,
152            IN PULONG DllCharacteristics,
153            IN BOOLEAN Static,
154            IN BOOLEAN Redirect,
155            OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry);
156 
157 PVOID NTAPI
158 LdrpFetchAddressOfEntryPoint(PVOID ImageBase);
159 
160 VOID NTAPI
161 LdrpFreeUnicodeString(PUNICODE_STRING String);
162 
163 VOID NTAPI
164 LdrpRecordUnloadEvent(_In_ PLDR_DATA_TABLE_ENTRY LdrEntry);
165 
166 VOID NTAPI
167 LdrpGetShimEngineInterface(VOID);
168 
169 VOID
170 NTAPI
171 LdrpLoadShimEngine(IN PWSTR ImageName,
172                    IN PUNICODE_STRING ProcessImage,
173                    IN PVOID pShimData);
174 
175 VOID NTAPI
176 LdrpUnloadShimEngine(VOID);
177 
178 /* verifier.c */
179 
180 NTSTATUS NTAPI
181 LdrpInitializeApplicationVerifierPackage(IN HANDLE KeyHandle,
182                                          IN PPEB Peb,
183                                          IN BOOLEAN SystemWide,
184                                          IN BOOLEAN ReadAdvancedOptions);
185 
186 NTSTATUS NTAPI
187 AVrfInitializeVerifier(VOID);
188 
189 VOID NTAPI
190 AVrfDllLoadNotification(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
191 
192 VOID NTAPI
193 AVrfDllUnloadNotification(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
194 
195 VOID NTAPI
196 AVrfPageHeapDllNotification(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
197 
198 
199 /* FIXME: Cleanup this mess */
200 typedef NTSTATUS (NTAPI *PEPFUNC)(PPEB);
201 NTSTATUS LdrMapSections(HANDLE ProcessHandle,
202                         PVOID ImageBase,
203                         HANDLE SectionHandle,
204                         PIMAGE_NT_HEADERS NTHeaders);
205 NTSTATUS LdrMapNTDllForProcess(HANDLE ProcessHandle,
206                                PHANDLE NTDllSectionHandle);
207 ULONG
208 LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders);
209 
210 NTSTATUS
211 NTAPI
212 LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL,
213                      IN LPSTR ImportName,
214                      OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry,
215                      OUT PBOOLEAN Existing);
216 
217 VOID
218 NTAPI
219 LdrpFinalizeAndDeallocateDataTableEntry(IN PLDR_DATA_TABLE_ENTRY Entry);
220 
221 
222 /* path.c */
223 BOOLEAN
224 NTAPI
225 RtlDoesFileExists_UStr(
226     IN PUNICODE_STRING FileName
227 );
228 
229 VOID
230 NTAPI
231 RtlpInitializeKeyedEvent(
232     VOID);
233 
234 /* EOF */
235