Use mapped sections for fonts instead of paged pool memory.
Modified: branches/win32k rewrite attempt/win32k/objects/text.c

Modified: branches/win32k rewrite attempt/win32k/objects/text.c
--- branches/win32k rewrite attempt/win32k/objects/text.c	2005-08-02 20:33:33 UTC (rev 16977)
+++ branches/win32k rewrite attempt/win32k/objects/text.c	2005-08-02 20:34:51 UTC (rev 16978)
@@ -256,22 +256,24 @@
    HANDLE FileHandle;
    OBJECT_ATTRIBUTES ObjectAttributes;
    FILE_STANDARD_INFORMATION FileStdInfo;
-   PVOID Buffer;
+   PVOID Buffer = NULL;
    IO_STATUS_BLOCK Iosb;
    INT Error;
    FT_Face Face;
    ANSI_STRING AnsiFaceName;
    PFONT_ENTRY Entry;
+   PSECTION_OBJECT SectionObject;
+   ULONG ViewSize = 0;
 
    /* Open the font file */
 
    InitializeObjectAttributes(&ObjectAttributes, FileName, 0, NULL, NULL);
    Status = ZwOpenFile(
       &FileHandle,
-      GENERIC_READ | SYNCHRONIZE,
+      FILE_GENERIC_READ | SYNCHRONIZE,
       &ObjectAttributes,
       &Iosb,
-      0,
+      FILE_SHARE_READ,
       FILE_SYNCHRONOUS_IO_NONALERT);
 
    if (!NT_SUCCESS(Status))
@@ -280,59 +282,25 @@
       return 0;
    }
 
-   /* Get the size of the file */
-
-   Status = ZwQueryInformationFile(
-      FileHandle,
-      &Iosb,
-      &FileStdInfo,
-      sizeof(FileStdInfo),
-      FileStandardInformation);
-
+   Status = MmCreateSection(&SectionObject, SECTION_ALL_ACCESS,
+                            NULL, NULL, PAGE_READONLY,
+                            0, FileHandle, NULL);
    if (!NT_SUCCESS(Status))
    {
-      DPRINT("Could not get file size\n");
+      DPRINT("Could not map file: %wZ\n", FileName);
       ZwClose(FileHandle);
       return 0;
    }
 
-   /* Allocate pageable memory for the font */
+   ZwClose(FileHandle);
 
-   Buffer = ExAllocatePoolWithTag(
-      PagedPool,
-      FileStdInfo.EndOfFile.u.LowPart,
-      TAG_FNTFILE);
-
-   if (Buffer == NULL)
-   {
-      DPRINT("Could not allocate memory for font");
-      ZwClose(FileHandle);
-      return 0;
-   }
-
-   /* Load the font into memory chunk */
-
-   Status = ZwReadFile(
-      FileHandle,
-      NULL,
-      NULL,
-      NULL,
-      &Iosb,
-      Buffer,
-      FileStdInfo.EndOfFile.u.LowPart,
-      NULL,
-      NULL);
-
+   Status = MmMapViewInSystemSpace(SectionObject, &Buffer, &ViewSize);
    if (!NT_SUCCESS(Status))
    {
-      DPRINT("Could not read the font file into memory");
-      ExFreePool(Buffer);
-      ZwClose(FileHandle);
-      return 0;
+      DPRINT("Could not map file: %wZ\n", FileName);
+      return Status;
    }
 
-   ZwClose(FileHandle);
-
    IntLockFreeType;
    Error = FT_New_Memory_Face(
       library,
@@ -348,7 +316,7 @@
          DPRINT("Unknown font file format\n");
       else
          DPRINT("Error reading font file (error code: %u)\n", Error);
-      ExFreePool(Buffer);
+      ObDereferenceObject(SectionObject);
       return 0;
    }
 
@@ -356,7 +324,7 @@
    if (!Entry)
    {
       FT_Done_Face(Face);
-      ExFreePool(Buffer);
+      ObDereferenceObject(SectionObject);
       SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
       return 0;
    }
@@ -365,7 +333,7 @@
    if(FontGDI == NULL)
    {
       FT_Done_Face(Face);
-      ExFreePool(Buffer);
+      ObDereferenceObject(SectionObject);
       ExFreePool(Entry);
       SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
       return 0;