[WIN32K] Tag more pool allocations
[reactos.git] / reactos / subsystems / win32 / win32k / ldr / loader.c
index 2d815c0..bc867c2 100644 (file)
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 /* $Id$
  *
  */
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
 
 
-typedef struct _DRIVERS
-{
-       LIST_ENTRY ListEntry;
-       HANDLE ImageHandle;
-       UNICODE_STRING DriverName;
-}DRIVERS, *PDRIVERS;
-
 extern LIST_ENTRY GlobalDriverListHead;
 
+
 /*
  * Blatantly stolen from ldr/utils.c in ntdll.  I can't link ntdll from
  * here, though.
@@ -180,7 +174,7 @@ EngFindImageProcAddress(IN HANDLE Module,
       return NULL;
     }
   RtlInitAnsiString(&ProcNameString, ProcName);
-  Status = LdrGetProcedureAddress(Module,
+  Status = LdrGetProcedureAddress(((PDRIVERS)Module)->BaseAddress,
                                  &ProcNameString,
                                  0,
                                  &Function);
@@ -199,8 +193,8 @@ HANDLE
 APIENTRY
 EngLoadImage (LPWSTR DriverName)
 {
-       HANDLE hImageHandle = NULL;
        SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo;
+       PDRIVERS DriverInfo = NULL;
        NTSTATUS Status;
 
        RtlInitUnicodeString(&GdiDriverInfo.DriverName, DriverName);
@@ -213,14 +207,14 @@ EngLoadImage (LPWSTR DriverName)
                {
                        Current = CONTAINING_RECORD(CurrentEntry, DRIVERS, ListEntry);
                        if( Current && (0 == RtlCompareUnicodeString(&GdiDriverInfo.DriverName, &Current->DriverName, FALSE)) ) {
-                               hImageHandle = Current->ImageHandle;
+                               DriverInfo = Current;
                                break;
                        }
                        CurrentEntry = CurrentEntry->Flink;
                };
        }
 
-       if( !hImageHandle )
+       if( !DriverInfo )
        {
                /* the driver was not loaded before, so let's do that */
                Status = ZwSetSystemInformation(SystemLoadGdiDriverInformation, &GdiDriverInfo, sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
@@ -228,40 +222,18 @@ EngLoadImage (LPWSTR DriverName)
                        DPRINT1("ZwSetSystemInformation failed with Status 0x%lx\n", Status);
                }
                else {
-            PDRIVERS DriverInfo;
-                       hImageHandle = (HANDLE)GdiDriverInfo.ImageAddress;
-                       DriverInfo = ExAllocatePool(PagedPool, sizeof(DRIVERS));
+                       DriverInfo = ExAllocatePoolWithTag(PagedPool, sizeof(DRIVERS), TAG_DRIVER);
                        DriverInfo->DriverName.MaximumLength = GdiDriverInfo.DriverName.MaximumLength;
                        DriverInfo->DriverName.Length = GdiDriverInfo.DriverName.Length;
-                       DriverInfo->DriverName.Buffer = ExAllocatePool(PagedPool, GdiDriverInfo.DriverName.MaximumLength);
+                       DriverInfo->DriverName.Buffer = ExAllocatePoolWithTag(PagedPool, GdiDriverInfo.DriverName.MaximumLength, TAG_DRIVER);
                        RtlCopyUnicodeString(&DriverInfo->DriverName, &GdiDriverInfo.DriverName);
-                       DriverInfo->ImageHandle = hImageHandle;
+                       DriverInfo->SectionPointer = GdiDriverInfo.SectionPointer;
+            DriverInfo->BaseAddress = GdiDriverInfo.ImageAddress;
                        InsertHeadList(&GlobalDriverListHead, &DriverInfo->ListEntry);
                }
        }
 
-       return hImageHandle;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-APIENTRY
-EngLoadModule(LPWSTR ModuleName)
-{
-  SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo;
-  NTSTATUS Status;
-
-  // FIXME: should load as readonly
-
-  RtlInitUnicodeString (&GdiDriverInfo.DriverName, ModuleName);
-  Status = ZwSetSystemInformation (SystemLoadGdiDriverInformation,
-    &GdiDriverInfo, sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
-  if (!NT_SUCCESS(Status)) return NULL;
-
-  return (HANDLE)GdiDriverInfo.ImageAddress;
+       return DriverInfo;
 }
 
 VOID
@@ -269,11 +241,12 @@ APIENTRY
 EngUnloadImage ( IN HANDLE hModule )
 {
   NTSTATUS Status;
+  PDRIVERS DriverInfo = (PDRIVERS)hModule;
 
   DPRINT("hModule 0x%x\n", hModule);
 
   Status = ZwSetSystemInformation(SystemUnloadGdiDriverInformation,
-    &hModule, sizeof(HANDLE));
+    DriverInfo->SectionPointer, sizeof(PVOID));
 
   if(!NT_SUCCESS(Status))
   {
@@ -282,27 +255,9 @@ EngUnloadImage ( IN HANDLE hModule )
   }
   else
   {
-         /* remove from the list */
-         if( !IsListEmpty(&GlobalDriverListHead) )
-         {
-                 PLIST_ENTRY CurrentEntry = GlobalDriverListHead.Flink;
-                 PDRIVERS Current;
-                 /* probably the driver was already loaded, let's try to find it out */
-                 while( CurrentEntry != &GlobalDriverListHead )
-                 {
-                         Current = CONTAINING_RECORD(CurrentEntry, DRIVERS, ListEntry);
-
-                         if( Current ) {
-                                 if(Current->ImageHandle == hModule) {
-                                         ExFreePool(Current->DriverName.Buffer);
-                                         RemoveEntryList(&Current->ListEntry);
-                                         ExFreePool(Current);
-                                         break;
-                                 }
-                         }
-                         CurrentEntry = CurrentEntry->Flink;
-                 };
-         }
+    ExFreePool(DriverInfo->DriverName.Buffer);
+    RemoveEntryList(&DriverInfo->ListEntry);
+    ExFreePool(DriverInfo);
   }
 }