xref: /reactos/dll/ntdll/include/ntdllp.h (revision 682f85ad)
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 NTAPI
102 LdrpGetProcedureAddress(IN PVOID BaseAddress,
103                         IN PANSI_STRING Name,
104                         IN ULONG Ordinal,
105                         OUT PVOID *ProcedureAddress,
106                         IN BOOLEAN ExecuteInit);
107 
108 PLDR_DATA_TABLE_ENTRY NTAPI
109 LdrpAllocateDataTableEntry(IN PVOID BaseAddress);
110 
111 VOID NTAPI
112 LdrpInsertMemoryTableEntry(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
113 
114 NTSTATUS NTAPI
115 LdrpLoadDll(IN BOOLEAN Redirected,
116             IN PWSTR DllPath OPTIONAL,
117             IN PULONG DllCharacteristics OPTIONAL,
118             IN PUNICODE_STRING DllName,
119             OUT PVOID *BaseAddress,
120             IN BOOLEAN CallInit);
121 
122 VOID NTAPI
123 LdrpUpdateLoadCount2(IN PLDR_DATA_TABLE_ENTRY LdrEntry,
124                      IN ULONG Flags);
125 
126 ULONG NTAPI
127 LdrpClearLoadInProgress(VOID);
128 
129 NTSTATUS
130 NTAPI
131 LdrpSetProtection(PVOID ViewBase,
132                   BOOLEAN Restore);
133 
134 BOOLEAN
135 NTAPI
136 LdrpCheckForLoadedDllHandle(IN PVOID Base,
137                             OUT PLDR_DATA_TABLE_ENTRY *LdrEntry);
138 
139 BOOLEAN NTAPI
140 LdrpCheckForLoadedDll(IN PWSTR DllPath,
141                       IN PUNICODE_STRING DllName,
142                       IN BOOLEAN Flag,
143                       IN BOOLEAN RedirectedDll,
144                       OUT PLDR_DATA_TABLE_ENTRY *LdrEntry);
145 
146 NTSTATUS NTAPI
147 LdrpMapDll(IN PWSTR SearchPath OPTIONAL,
148            IN PWSTR DllPath2,
149            IN PWSTR DllName OPTIONAL,
150            IN PULONG DllCharacteristics,
151            IN BOOLEAN Static,
152            IN BOOLEAN Redirect,
153            OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry);
154 
155 PVOID NTAPI
156 LdrpFetchAddressOfEntryPoint(PVOID ImageBase);
157 
158 VOID NTAPI
159 LdrpFreeUnicodeString(PUNICODE_STRING String);
160 
161 VOID NTAPI
162 LdrpRecordUnloadEvent(_In_ PLDR_DATA_TABLE_ENTRY LdrEntry);
163 
164 VOID NTAPI
165 LdrpGetShimEngineInterface(VOID);
166 
167 VOID
168 NTAPI
169 LdrpLoadShimEngine(IN PWSTR ImageName,
170                    IN PUNICODE_STRING ProcessImage,
171                    IN PVOID pShimData);
172 
173 VOID NTAPI
174 LdrpUnloadShimEngine(VOID);
175 
176 /* verifier.c */
177 
178 NTSTATUS NTAPI
179 LdrpInitializeApplicationVerifierPackage(IN HANDLE KeyHandle,
180                                          IN PPEB Peb,
181                                          IN BOOLEAN SystemWide,
182                                          IN BOOLEAN ReadAdvancedOptions);
183 
184 NTSTATUS NTAPI
185 AVrfInitializeVerifier(VOID);
186 
187 VOID NTAPI
188 AVrfDllLoadNotification(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
189 
190 VOID NTAPI
191 AVrfDllUnloadNotification(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
192 
193 VOID NTAPI
194 AVrfPageHeapDllNotification(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
195 
196 
197 /* FIXME: Cleanup this mess */
198 typedef NTSTATUS (NTAPI *PEPFUNC)(PPEB);
199 NTSTATUS LdrMapSections(HANDLE ProcessHandle,
200                         PVOID ImageBase,
201                         HANDLE SectionHandle,
202                         PIMAGE_NT_HEADERS NTHeaders);
203 NTSTATUS LdrMapNTDllForProcess(HANDLE ProcessHandle,
204                                PHANDLE NTDllSectionHandle);
205 ULONG
206 LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders);
207 
208 NTSTATUS
209 NTAPI
210 LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL,
211                      IN LPSTR ImportName,
212                      OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry,
213                      OUT PBOOLEAN Existing);
214 
215 VOID
216 NTAPI
217 LdrpFinalizeAndDeallocateDataTableEntry(IN PLDR_DATA_TABLE_ENTRY Entry);
218 
219 
220 /* path.c */
221 BOOLEAN
222 NTAPI
223 RtlDoesFileExists_UStr(
224     IN PUNICODE_STRING FileName
225 );
226 
227 /* EOF */
228