[AVIFIL32]
[reactos.git] / reactos / dll / ntdll / ldr / ldrapi.c
index 68a8910..5107649 100644 (file)
@@ -19,16 +19,75 @@ LIST_ENTRY LdrpUnloadHead;
 LONG LdrpLoaderLockAcquisitonCount;
 BOOLEAN LdrpShowRecursiveLoads, LdrpBreakOnRecursiveDllLoads;
 UNICODE_STRING LdrApiDefaultExtension = RTL_CONSTANT_STRING(L".DLL");
+ULONG AlternateResourceModuleCount;
 
 /* FUNCTIONS *****************************************************************/
 
+NTSTATUS
+NTAPI
+LdrFindCreateProcessManifest(IN ULONG Flags,
+                             IN PVOID Image,
+                             IN PVOID IdPath,
+                             IN ULONG IdPathLength,
+                             IN PVOID OutDataEntry)
+{
+    UNIMPLEMENTED;
+    return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+NTAPI
+LdrDestroyOutOfProcessImage(IN PVOID Image)
+{
+    UNIMPLEMENTED;
+    return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+NTAPI
+LdrCreateOutOfProcessImage(IN ULONG Flags,
+                           IN HANDLE ProcessHandle,
+                           IN HANDLE DllHandle,
+                           IN PVOID Unknown3)
+{
+    UNIMPLEMENTED;
+    return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+NTAPI
+LdrAccessOutOfProcessResource(IN PVOID Unknown,
+                              IN PVOID Image,
+                              IN PVOID Unknown1,
+                              IN PVOID Unknown2,
+                              IN PVOID Unknown3)
+{
+    UNIMPLEMENTED;
+    return STATUS_NOT_IMPLEMENTED;
+}
+
+VOID
+NTAPI
+LdrSetDllManifestProber(IN PVOID ProberFunction)
+{
+    UNIMPLEMENTED;
+}
+
+BOOLEAN
+NTAPI
+LdrAlternateResourcesEnabled(VOID)
+{
+    /* ReactOS does not support this */
+    return FALSE;
+}
+
 ULONG_PTR
 FORCEINLINE
 LdrpMakeCookie(VOID)
 {
     /* Generate a cookie */
     return (((ULONG_PTR)NtCurrentTeb()->RealClientId.UniqueThread & 0xFFF) << 16) |
-                        _InterlockedIncrement(&LdrpLoaderLockAcquisitonCount);
+                        (_InterlockedIncrement(&LdrpLoaderLockAcquisitonCount) & 0xFFFF);
 }
 
 /*
@@ -301,14 +360,14 @@ LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
         if ((ShowSnaps) || (LdrpShowRecursiveLoads) || (LdrpBreakOnRecursiveDllLoads))
         {
             /* Print out debug messages */
-            DPRINT1("[%lx, %lx] LDR: Recursive DLL Load\n",
+            DPRINT1("[%p, %p] LDR: Recursive DLL Load\n",
                     Teb->RealClientId.UniqueProcess,
                     Teb->RealClientId.UniqueThread);
-            DPRINT1("[%lx, %lx]      Previous DLL being loaded \"%wZ\"\n",
+            DPRINT1("[%p, %p]      Previous DLL being loaded \"%wZ\"\n",
                     Teb->RealClientId.UniqueProcess,
                     Teb->RealClientId.UniqueThread,
                     OldTldDll);
-            DPRINT1("[%lx, %lx]      DLL being requested \"%wZ\"\n",
+            DPRINT1("[%p, %p]      DLL being requested \"%wZ\"\n",
                     Teb->RealClientId.UniqueProcess,
                     Teb->RealClientId.UniqueThread,
                     DllName);
@@ -316,13 +375,13 @@ LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
             /* Was it initializing too? */
             if (!LdrpCurrentDllInitializer)
             {
-                DPRINT1("[%lx, %lx] LDR: No DLL Initializer was running\n",
+                DPRINT1("[%p, %p] LDR: No DLL Initializer was running\n",
                         Teb->RealClientId.UniqueProcess,
                         Teb->RealClientId.UniqueThread);
             }
             else
             {
-                DPRINT1("[%lx, %lx]      DLL whose initializer was currently running \"%wZ\"\n",
+                DPRINT1("[%p, %p]      DLL whose initializer was currently running \"%wZ\"\n",
                         Teb->ClientId.UniqueProcess,
                         Teb->ClientId.UniqueThread,
                         &LdrpCurrentDllInitializer->BaseDllName);
@@ -774,7 +833,7 @@ LdrVerifyImageMatchesChecksum(IN HANDLE FileHandle,
 {
     FILE_STANDARD_INFORMATION FileStandardInfo;
     PIMAGE_IMPORT_DESCRIPTOR ImportData;
-    PIMAGE_SECTION_HEADER LastSection;
+    PIMAGE_SECTION_HEADER LastSection = NULL;
     IO_STATUS_BLOCK IoStatusBlock;
     PIMAGE_NT_HEADERS NtHeader;
     HANDLE SectionHandle;
@@ -911,7 +970,7 @@ NTSTATUS
 NTAPI
 LdrQueryProcessModuleInformationEx(IN ULONG ProcessId,
                                    IN ULONG Reserved,
-                                   IN PRTL_PROCESS_MODULES ModuleInformation,
+                                   OUT PRTL_PROCESS_MODULES ModuleInformation,
                                    IN ULONG Size,
                                    OUT PULONG ReturnedSize OPTIONAL)
 {
@@ -929,21 +988,21 @@ LdrQueryProcessModuleInformationEx(IN ULONG ProcessId,
     /* Acquire loader lock */
     RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
 
-    /* Check if we were given enough space */
-    if (Size < UsedSize)
-    {
-        Status = STATUS_INFO_LENGTH_MISMATCH;
-    }
-    else
-    {
-        ModuleInformation->NumberOfModules = 0;
-        ModulePtr = &ModuleInformation->Modules[0];
-        Status = STATUS_SUCCESS;
-    }
-
-    /* Traverse the list of modules */
     _SEH2_TRY
     {
+        /* Check if we were given enough space */
+        if (Size < UsedSize)
+        {
+            Status = STATUS_INFO_LENGTH_MISMATCH;
+        }
+        else
+        {
+            ModuleInformation->NumberOfModules = 0;
+            ModulePtr = &ModuleInformation->Modules[0];
+            Status = STATUS_SUCCESS;
+        }
+
+        /* Traverse the list of modules */
         ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
         Entry = ModuleListHead->Flink;
 
@@ -1238,7 +1297,7 @@ quickie:
                             (Status != STATUS_DLL_NOT_FOUND) &&
                             (Status != STATUS_OBJECT_NAME_NOT_FOUND)))
         {
-            DPRINT1("LDR: LdrAddRefDll(%p) 0x%08lx\n", BaseAddress);
+            DPRINT1("LDR: LdrAddRefDll(%p) 0x%08lx\n", BaseAddress, Status);
         }
     }
 
@@ -1292,7 +1351,7 @@ LdrUnloadDll(IN PVOID BaseAddress)
             /* Set up the Act Ctx */
             ActCtx.Size = sizeof(ActCtx);
             ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER;
-            RtlZeroMemory(&ActCtx.Frame, sizeof(ActCtx));
+            RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME));
 
             /* Activate the ActCtx */
             RtlActivateActivationContextUnsafeFast(&ActCtx,
@@ -1336,7 +1395,7 @@ LdrUnloadDll(IN PVOID BaseAddress)
             /* Show message */
             if (ShowSnaps)
             {
-                DPRINT1("(%d) [%ws] %ws (%lx) deinit %lx\n",
+                DPRINT1("(%lu) [%ws] %ws (%lx) deinit %p\n",
                         LdrpActiveUnloadCount,
                         LdrEntry->BaseDllName.Buffer,
                         LdrEntry->FullDllName.Buffer,
@@ -1374,18 +1433,6 @@ LdrUnloadDll(IN PVOID BaseAddress)
     NextEntry = LdrpUnloadHead.Flink;
     while (NextEntry != &LdrpUnloadHead)
     {
-        /* If we have an active entry */
-        if (CurrentEntry)
-        {
-            /* Remove it */
-            RemoveEntryList(&CurrentEntry->InLoadOrderLinks);
-            CurrentEntry = NULL;
-
-            /* Reset list pointers */
-            NextEntry = LdrpUnloadHead.Flink;
-            if (NextEntry == &LdrpUnloadHead) break;
-        }
-
         /* Get the current entry */
         LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, HashLinks);
 
@@ -1410,13 +1457,13 @@ LdrUnloadDll(IN PVOID BaseAddress)
             /* Show message */
             if (ShowSnaps)
             {
-                DPRINT1("LDR: Calling deinit %lx\n", EntryPoint);
+                DPRINT1("LDR: Calling deinit %p\n", EntryPoint);
             }
 
             /* Set up the Act Ctx */
             ActCtx.Size = sizeof(ActCtx);
             ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER;
-            RtlZeroMemory(&ActCtx.Frame, sizeof(ActCtx));
+            RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME));
 
             /* Activate the ActCtx */
             RtlActivateActivationContextUnsafeFast(&ActCtx,
@@ -1535,15 +1582,57 @@ LdrProcessRelocationBlock(IN ULONG_PTR Address,
     return LdrProcessRelocationBlockLongLong(Address, Count, TypeOffset, Delta);
 }
 
+/* FIXME: Add to ntstatus.mc */
+#define STATUS_MUI_FILE_NOT_FOUND        ((NTSTATUS)0xC00B0001L)
+
 /*
- * @unimplemented
+ * @implemented
+ */
+NTSTATUS
+NTAPI
+LdrLoadAlternateResourceModule(IN PVOID Module,
+                               IN PWSTR Buffer)
+{
+    /* Is MUI Support enabled? */
+    if (!LdrAlternateResourcesEnabled()) return STATUS_SUCCESS;
+
+    UNIMPLEMENTED;
+    return STATUS_MUI_FILE_NOT_FOUND;
+}
+
+/*
+ * @implemented
  */
 BOOLEAN
 NTAPI
 LdrUnloadAlternateResourceModule(IN PVOID BaseAddress)
 {
-    static BOOLEAN WarnedOnce = FALSE;
-    if (WarnedOnce == FALSE) { UNIMPLEMENTED; WarnedOnce = TRUE; }
+    ULONG_PTR Cookie;
+
+    /* Acquire the loader lock */
+    LdrLockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, NULL, &Cookie);
+
+    /* Check if there's any alternate resources loaded */
+    if (AlternateResourceModuleCount)
+    {
+        UNIMPLEMENTED;
+    }
+
+    /* Release the loader lock */
+    LdrUnlockLoaderLock(1, Cookie);
+
+    /* All done */
+    return TRUE;
+}
+
+/*
+ * @unimplemented
+ */
+BOOLEAN
+NTAPI
+LdrFlushAlternateResourceModules(VOID)
+{
+    UNIMPLEMENTED;
     return FALSE;
 }