[ros-diffs] [dchapyshev] 42005: - Re-implement FreeLibrary (for support LOAD_LIBRARY_AS_DATAFILE) - HeapAlloc -> RtlAllocateHeap, GetProcessHeap -> RtlGetProcessHeap, HeapFree -> RtlFreeHeap, CloseHandle -> NtClose - Remove FIXME in LoadModule

dchapyshev at svn.reactos.org dchapyshev at svn.reactos.org
Fri Jul 17 19:15:17 CEST 2009


Author: dchapyshev
Date: Fri Jul 17 19:15:17 2009
New Revision: 42005

URL: http://svn.reactos.org/svn/reactos?rev=42005&view=rev
Log:
- Re-implement FreeLibrary (for support LOAD_LIBRARY_AS_DATAFILE)
- HeapAlloc -> RtlAllocateHeap, GetProcessHeap -> RtlGetProcessHeap, HeapFree -> RtlFreeHeap, CloseHandle -> NtClose
- Remove FIXME in LoadModule

Modified:
    trunk/reactos/dll/win32/kernel32/misc/ldr.c

Modified: trunk/reactos/dll/win32/kernel32/misc/ldr.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/ldr.c?rev=42005&r1=42004&r2=42005&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/ldr.c [iso-8859-1] Fri Jul 17 19:15:17 2009
@@ -20,6 +20,7 @@
 } LOADPARMS32;
 
 extern BOOLEAN InWindows;
+extern WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle;
 
 /* FUNCTIONS ****************************************************************/
 
@@ -349,8 +350,31 @@
 WINAPI
 FreeLibrary( HMODULE hLibModule )
 {
-	LdrUnloadDll(hLibModule);
-	return TRUE;
+    PVOID Module = (PVOID)((ULONG_PTR)hLibModule & ~1);
+    NTSTATUS Status;
+
+    if ((ULONG_PTR)hLibModule & 1)
+    {
+        if (!RtlImageNtHeader(Module))
+        {
+            SetLastErrorByStatus(STATUS_INVALID_IMAGE_FORMAT);
+            return FALSE;
+        }
+
+        Status = NtUnmapViewOfSection(NtCurrentProcess(), Module);
+    }
+    else
+    {
+        Status = LdrUnloadDll(hLibModule);
+    }
+
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastErrorByStatus(Status);
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
 
@@ -703,7 +727,7 @@
   }
 
   Length = (BYTE)LoadParams->lpCmdLine[0];
-  if(!(CommandLine = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+  if(!(CommandLine = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY,
                                strlen(lpModuleName) + Length + 2)))
   {
     SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@@ -727,7 +751,7 @@
   {
     DWORD Error;
 
-    HeapFree(GetProcessHeap(), 0, CommandLine);
+    RtlFreeHeap(RtlGetProcessHeap(), 0, CommandLine);
     /* return the right value */
     Error = GetLastError();
     switch(Error)
@@ -745,14 +769,16 @@
     return 0;
   }
 
-  HeapFree(GetProcessHeap(), 0, CommandLine);
+  RtlFreeHeap(RtlGetProcessHeap(), 0, CommandLine);
 
   /* Wait up to 15 seconds for the process to become idle */
-  /* FIXME: This is user32! Windows soft-loads this only if required. */
-  //WaitForInputIdle(ProcessInformation.hProcess, 15000);
-
-  CloseHandle(ProcessInformation.hThread);
-  CloseHandle(ProcessInformation.hProcess);
+  if (NULL != lpfnGlobalRegisterWaitForInputIdle)
+  {
+    lpfnGlobalRegisterWaitForInputIdle(ProcessInformation.hProcess, 15000);
+  }
+
+  NtClose(ProcessInformation.hThread);
+  NtClose(ProcessInformation.hProcess);
 
   return 33;
 }



More information about the Ros-diffs mailing list