[NTDLL]
authorAleksey Bragin <aleksey@reactos.org>
Wed, 6 Oct 2010 20:34:30 +0000 (20:34 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Wed, 6 Oct 2010 20:34:30 +0000 (20:34 +0000)
- LoadImageFileExecutionOptions() improvements:
 * Apply certain heap flags if the process is being debugged (only if NtGlobalFlags is not overridden).
 * Implement enabling page heap and reading image-specific configuration values.
- Add page heap configuration values to the Heap Manager.

svn path=/trunk/; revision=49025

reactos/dll/ntdll/ldr/startup.c
reactos/lib/rtl/heap_rewrite.c
reactos/lib/rtl/heapdbg.c

index 4af6ebd..d0981c8 100644 (file)
@@ -74,6 +74,10 @@ LoadImageFileExecutionOptions(PPEB Peb)
     UNICODE_STRING ImageName;
     UNICODE_STRING ImagePathName;
     ULONG ValueSize;
+    extern ULONG RtlpPageHeapGlobalFlags, RtlpPageHeapSizeRangeStart, RtlpPageHeapSizeRangeEnd;
+    extern ULONG RtlpPageHeapDllRangeStart, RtlpPageHeapDllRangeEnd;
+    extern WCHAR RtlpPageHeapTargetDlls[512];
+    extern BOOLEAN RtlpPageHeapEnabled;
 
     if (Peb->ProcessParameters &&
         Peb->ProcessParameters->ImagePathName.Length > 0)
@@ -113,10 +117,75 @@ LoadImageFileExecutionOptions(PPEB Peb)
             Peb->NtGlobalFlag = Value;
             DPRINT("GlobalFlag: Value=0x%lx\n", Value);
         }
-        /*
-         *  FIXME:
-         *   read more options
-         */
+        else
+        {
+            /* Add debugging flags if there is no GlobalFlags override */
+            if (Peb->BeingDebugged)
+            {
+                Peb->NtGlobalFlag |= FLG_HEAP_VALIDATE_PARAMETERS |
+                                     FLG_HEAP_ENABLE_FREE_CHECK |
+                                     FLG_HEAP_ENABLE_TAIL_CHECK;
+            }
+        }
+
+        /* Handle the case when page heap is enabled */
+        if (Peb->NtGlobalFlag & FLG_HEAP_PAGE_ALLOCS)
+        {
+            /* Disable all heap debugging flags so that no heap call goes via page heap branch */
+            Peb->NtGlobalFlag &= ~(FLG_HEAP_VALIDATE_PARAMETERS |
+                                   FLG_HEAP_VALIDATE_ALL |
+                                   FLG_HEAP_ENABLE_FREE_CHECK |
+                                   FLG_HEAP_ENABLE_TAIL_CHECK |
+                                   FLG_USER_STACK_TRACE_DB |
+                                   FLG_HEAP_ENABLE_TAGGING |
+                                   FLG_HEAP_ENABLE_TAG_BY_DLL);
+        }
+
+        /* Get page heap flags without checking return value */
+        LdrQueryImageFileExecutionOptions(&ImageName,
+                                          L"PageHeapFlags",
+                                          REG_DWORD,
+                                          (PVOID)&RtlpPageHeapGlobalFlags,
+                                          sizeof(RtlpPageHeapGlobalFlags),
+                                          &ValueSize);
+
+        LdrQueryImageFileExecutionOptions(&ImageName,
+                                          L"PageHeapSizeRangeStart",
+                                          REG_DWORD,
+                                          (PVOID)&RtlpPageHeapSizeRangeStart,
+                                          sizeof(RtlpPageHeapSizeRangeStart),
+                                          &ValueSize);
+
+        LdrQueryImageFileExecutionOptions(&ImageName,
+                                          L"PageHeapSizeRangeEnd",
+                                          REG_DWORD,
+                                          (PVOID)&RtlpPageHeapSizeRangeEnd,
+                                          sizeof(RtlpPageHeapSizeRangeEnd),
+                                          &ValueSize);
+
+        LdrQueryImageFileExecutionOptions(&ImageName,
+                                          L"PageHeapDllRangeStart",
+                                          REG_DWORD,
+                                          (PVOID)&RtlpPageHeapDllRangeStart,
+                                          sizeof(RtlpPageHeapDllRangeStart),
+                                          &ValueSize);
+
+        LdrQueryImageFileExecutionOptions(&ImageName,
+                                          L"PageHeapDllRangeEnd",
+                                          REG_DWORD,
+                                          (PVOID)&RtlpPageHeapDllRangeEnd,
+                                          sizeof(RtlpPageHeapDllRangeEnd),
+                                          &ValueSize);
+
+        LdrQueryImageFileExecutionOptions(&ImageName,
+                                          L"PageHeapTargetDlls",
+                                          REG_SZ,
+                                          (PVOID)RtlpPageHeapTargetDlls,
+                                          sizeof(RtlpPageHeapTargetDlls),
+                                          &ValueSize);
+
+        /* Now when all parameters are read, enable page heap */
+        RtlpPageHeapEnabled = TRUE;
     }
 }
 
index 606e257..08629cc 100644 (file)
@@ -269,7 +269,6 @@ RtlpSpecialHeapCreate(ULONG Flags,
                       PVOID Lock,
                       PRTL_HEAP_PARAMETERS Parameters) { return NULL; };
 
-BOOLEAN RtlpSpecialHeapEnabled = FALSE;
 HEAP_LOCK RtlpProcessHeapsListLock;
 PHEAP RtlpProcessHeaps[HEAP_MAX_PROCESS_HEAPS]; /* Usermode only */
 
@@ -1542,7 +1541,7 @@ RtlCreateHeap(ULONG Flags,
     BOOLEAN AllocateLock = FALSE;
 
     /* Check for a special heap */
-    if (RtlpSpecialHeapEnabled && !Addr && !Lock)
+    if (RtlpPageHeapEnabled && !Addr && !Lock)
     {
         Heap = RtlpSpecialHeapCreate(Flags, Addr, TotalSize, CommitSize, Lock, Parameters);
         if (Heap) return Heap;
index 5421fb0..d7bda96 100644 (file)
@@ -8,6 +8,17 @@
 
 /* INCLUDES ******************************************************************/
 
+#include <rtl.h>
+
+#define NDEBUG
+#include <debug.h>
+
+BOOLEAN RtlpPageHeapEnabled = FALSE;
+ULONG RtlpPageHeapGlobalFlags;
+ULONG RtlpPageHeapSizeRangeStart, RtlpPageHeapSizeRangeEnd;
+ULONG RtlpPageHeapDllRangeStart, RtlpPageHeapDllRangeEnd;
+WCHAR RtlpPageHeapTargetDlls[512];
+
 /* FUNCTIONS ******************************************************************/
 
 /* EOF */
\ No newline at end of file