[NTOS][NDK][RTL] A bunch of 'wrong size' fixes
[reactos.git] / dll / ntdll / ldr / ldrapi.c
index a7b25f0..c33b21e 100644 (file)
 /* GLOBALS *******************************************************************/
 
 LIST_ENTRY LdrpUnloadHead;
-LONG LdrpLoaderLockAcquisitonCount;
+LONG LdrpLoaderLockAcquisitionCount;
 BOOLEAN LdrpShowRecursiveLoads, LdrpBreakOnRecursiveDllLoads;
 UNICODE_STRING LdrApiDefaultExtension = RTL_CONSTANT_STRING(L".DLL");
 ULONG AlternateResourceModuleCount;
+extern PLDR_MANIFEST_PROBER_ROUTINE LdrpManifestProberRoutine;
 
 /* FUNCTIONS *****************************************************************/
 
@@ -69,9 +70,10 @@ LdrAccessOutOfProcessResource(IN PVOID Unknown,
 
 VOID
 NTAPI
-LdrSetDllManifestProber(IN PVOID ProberFunction)
+LdrSetDllManifestProber(
+    _In_ PLDR_MANIFEST_PROBER_ROUTINE Routine)
 {
-    UNIMPLEMENTED;
+    LdrpManifestProberRoutine = Routine;
 }
 
 BOOLEAN
@@ -82,13 +84,13 @@ LdrAlternateResourcesEnabled(VOID)
     return FALSE;
 }
 
-ULONG_PTR
 FORCEINLINE
+ULONG_PTR
 LdrpMakeCookie(VOID)
 {
     /* Generate a cookie */
     return (((ULONG_PTR)NtCurrentTeb()->RealClientId.UniqueThread & 0xFFF) << 16) |
-                        (_InterlockedIncrement(&LdrpLoaderLockAcquisitonCount) & 0xFFFF);
+            (_InterlockedIncrement(&LdrpLoaderLockAcquisitionCount) & 0xFFFF);
 }
 
 /*
@@ -210,9 +212,6 @@ LdrLockLoaderLock(IN ULONG Flags,
         return STATUS_INVALID_PARAMETER_3;
     }
 
-    /* Do or Do Not. There is no Try */
-    ASSERT((Disposition != NULL) || !(Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY));
-
     /* If the flag is set, make sure we have a valid pointer to use */
     if ((Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY) && !(Disposition))
     {
@@ -307,6 +306,7 @@ LdrLockLoaderLock(IN ULONG Flags,
  */
 NTSTATUS
 NTAPI
+DECLSPEC_HOTPATCH
 LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
            IN PULONG DllCharacteristics OPTIONAL,
            IN PUNICODE_STRING DllName,
@@ -316,15 +316,13 @@ LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
     UNICODE_STRING DllString1, DllString2;
     BOOLEAN RedirectedDll = FALSE;
     NTSTATUS Status;
-    ULONG Cookie;
+    ULONG_PTR Cookie;
     PUNICODE_STRING OldTldDll;
     PTEB Teb = NtCurrentTeb();
 
     /* Initialize the strings */
+    RtlInitEmptyUnicodeString(&DllString1, StringBuffer, sizeof(StringBuffer));
     RtlInitEmptyUnicodeString(&DllString2, NULL, 0);
-    DllString1.Buffer = StringBuffer;
-    DllString1.Length = 0;
-    DllString1.MaximumLength = sizeof(StringBuffer);
 
     /* Check if the SxS Assemblies specify another file */
     Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
@@ -409,8 +407,7 @@ LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
              (Status != STATUS_OBJECT_NAME_NOT_FOUND) &&
              (Status != STATUS_DLL_INIT_FAILED))
     {
-        // 85 == DPFLTR_LDR_ID;
-        DbgPrintEx(85,
+        DbgPrintEx(DPFLTR_LDR_ID,
                    DPFLTR_WARNING_LEVEL,
                    "LDR: %s - failing because LdrpLoadDll(%wZ) returned status %x\n",
                    __FUNCTION__,
@@ -479,7 +476,7 @@ LdrFindEntryForAddress(PVOID Address,
     while (NextEntry != ListHead)
     {
         /* Get the entry and NT Headers */
-        LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderModuleList);
+        LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
         NtHeader = RtlImageNtHeader(LdrEntry->DllBase);
         if (NtHeader)
         {
@@ -502,8 +499,11 @@ LdrFindEntryForAddress(PVOID Address,
     }
 
     /* Nothing found */
-    // 85 == DPFLTR_LDR_ID;
-    DbgPrintEx(85, DPFLTR_WARNING_LEVEL, "LDR: %s() exiting 0x%08lx\n", __FUNCTION__, STATUS_NO_MORE_ENTRIES);
+    DbgPrintEx(DPFLTR_LDR_ID,
+               DPFLTR_WARNING_LEVEL,
+               "LDR: %s() exiting 0x%08lx\n",
+               __FUNCTION__,
+               STATUS_NO_MORE_ENTRIES);
     return STATUS_NO_MORE_ENTRIES;
 }
 
@@ -580,7 +580,7 @@ LdrGetDllHandleEx(IN ULONG Flags,
     }
     else if (Status != STATUS_SXS_KEY_NOT_FOUND)
     {
-        /* Unrecoverable SxS failure; */
+        /* Unrecoverable SxS failure */
         goto Quickie;
     }
     else
@@ -1036,7 +1036,7 @@ LdrQueryProcessModuleInformationEx(IN ULONG ProcessId,
 
                 while (InitEntry != InitListHead)
                 {
-                    InitModule = CONTAINING_RECORD(InitEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
+                    InitModule = CONTAINING_RECORD(InitEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
 
                     /* Increase the index */
                     ModulePtr->InitOrderIndex++;
@@ -1117,7 +1117,7 @@ LdrEnumerateLoadedModules(IN BOOLEAN ReservedFlag,
     PLIST_ENTRY ListHead, ListEntry;
     PLDR_DATA_TABLE_ENTRY LdrEntry;
     NTSTATUS Status;
-    ULONG Cookie;
+    ULONG_PTR Cookie;
     BOOLEAN Stop = FALSE;
 
     /* Check parameters */
@@ -1232,7 +1232,7 @@ LdrAddRefDll(IN ULONG Flags,
 {
     PLDR_DATA_TABLE_ENTRY LdrEntry;
     NTSTATUS Status = STATUS_SUCCESS;
-    ULONG Cookie;
+    ULONG_PTR Cookie;
     BOOLEAN Locked = FALSE;
 
     /* Check for invalid flags */
@@ -1384,7 +1384,7 @@ LdrUnloadDll(IN PVOID BaseAddress)
         /* Get the entry */
         LdrEntry = CONTAINING_RECORD(NextEntry,
                                      LDR_DATA_TABLE_ENTRY,
-                                     InInitializationOrderModuleList);
+                                     InInitializationOrderLinks);
         NextEntry = NextEntry->Blink;
 
         /* Remove flag */
@@ -1404,12 +1404,17 @@ LdrUnloadDll(IN PVOID BaseAddress)
                         LdrEntry->EntryPoint);
             }
 
-            /* FIXME: Call Shim Engine and notify */
+            /* Call Shim Engine and notify */
+            if (g_ShimsEnabled)
+            {
+                VOID (NTAPI* SE_DllUnloaded)(PVOID) = RtlDecodeSystemPointer(g_pfnSE_DllUnloaded);
+                SE_DllUnloaded(LdrEntry);
+            }
 
             /* Unlink it */
             CurrentEntry = LdrEntry;
-            RemoveEntryList(&CurrentEntry->InInitializationOrderModuleList);
-            RemoveEntryList(&CurrentEntry->InMemoryOrderModuleList);
+            RemoveEntryList(&CurrentEntry->InInitializationOrderLinks);
+            RemoveEntryList(&CurrentEntry->InMemoryOrderLinks);
             RemoveEntryList(&CurrentEntry->HashLinks);
 
             /* If there's more then one active unload */
@@ -1417,7 +1422,7 @@ LdrUnloadDll(IN PVOID BaseAddress)
             {
                 /* Flush the cached DLL handle and clear the list */
                 LdrpLoadedDllHandleCache = NULL;
-                CurrentEntry->InMemoryOrderModuleList.Flink = NULL;
+                CurrentEntry->InMemoryOrderLinks.Flink = NULL;
             }
 
             /* Add the entry on the unload list */
@@ -1443,7 +1448,7 @@ LdrUnloadDll(IN PVOID BaseAddress)
         /* Set the entry and clear it from the list */
         CurrentEntry = LdrEntry;
         LdrpLoadedDllHandleCache = NULL;
-        CurrentEntry->InMemoryOrderModuleList.Flink = NULL;
+        CurrentEntry->InMemoryOrderLinks.Flink = NULL;
 
         /* Move it from the global to the local list */
         RemoveEntryList(&CurrentEntry->HashLinks);