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