Author: fireball Date: Thu Oct 7 21:12:10 2010 New Revision: 49045
URL: http://svn.reactos.org/svn/reactos?rev=49045&view=rev Log: [NTDLL] - Load image execution options before creating process heap (so that GlobalFlag overrides can be taken into account). - Make LdrQueryImageFileExecutionOptions avoid heap usage when possible (and when it's not possible, fail with out of memory status). - Fixes a dramatic count of ~100 failures in "kernel32_winetest heap".
Modified: trunk/reactos/dll/ntdll/ldr/startup.c trunk/reactos/dll/ntdll/ldr/utils.c
Modified: trunk/reactos/dll/ntdll/ldr/startup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/startup.c?rev... ============================================================================== --- trunk/reactos/dll/ntdll/ldr/startup.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/startup.c [iso-8859-1] Thu Oct 7 21:12:10 2010 @@ -383,6 +383,9 @@ /* Initialize Critical Section Data */ RtlpInitDeferedCriticalSection();
+ /* Load execution options */ + LoadImageFileExecutionOptions(Peb); + /* create process heap */ RtlInitializeHeapManager(); Peb->ProcessHeap = RtlCreateHeap(HEAP_GROWABLE, @@ -447,9 +450,6 @@ /* Load compatibility settings */ LoadCompatibilitySettings(Peb);
- /* Load execution options */ - LoadImageFileExecutionOptions(Peb); - /* build full ntdll path */ wcscpy(FullNtDllPath, SharedUserData->NtSystemRoot); wcscat(FullNtDllPath, L"\system32\ntdll.dll");
Modified: trunk/reactos/dll/ntdll/ldr/utils.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/utils.c?rev=4... ============================================================================== --- trunk/reactos/dll/ntdll/ldr/utils.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/ldr/utils.c [iso-8859-1] Thu Oct 7 21:12:10 2010 @@ -3337,6 +3337,7 @@ OUT PULONG ReturnedLength OPTIONAL) { PKEY_VALUE_PARTIAL_INFORMATION KeyInfo; + CHAR KeyInfoBuffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 32]; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING ValueNameString; UNICODE_STRING KeyName; @@ -3377,15 +3378,8 @@ return Status; }
- KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 32; - KeyInfo = RtlAllocateHeap (RtlGetProcessHeap(), - HEAP_ZERO_MEMORY, - KeyInfoSize); - if (KeyInfo == NULL) - { - NtClose (KeyHandle); - return STATUS_INSUFFICIENT_RESOURCES; - } + KeyInfoSize = sizeof(KeyInfoBuffer); + KeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfoBuffer;
RtlInitUnicodeString (&ValueNameString, (PWSTR)ValueName); @@ -3397,10 +3391,13 @@ &ResultSize); if (Status == STATUS_BUFFER_OVERFLOW) { + /* We can allocate only if there is a process heap already */ + if (!RtlGetProcessHeap()) + { + NtClose (KeyHandle); + return STATUS_NO_MEMORY; + } KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + KeyInfo->DataLength; - RtlFreeHeap (RtlGetProcessHeap(), - 0, - KeyInfo); KeyInfo = RtlAllocateHeap (RtlGetProcessHeap(), HEAP_ZERO_MEMORY, KeyInfoSize); @@ -3421,7 +3418,7 @@
if (!NT_SUCCESS(Status)) { - if (KeyInfo != NULL) + if ((PCHAR)KeyInfo != KeyInfoBuffer) { RtlFreeHeap (RtlGetProcessHeap(), 0, @@ -3432,9 +3429,12 @@
if (KeyInfo->Type != Type) { - RtlFreeHeap (RtlGetProcessHeap(), - 0, - KeyInfo); + if ((PCHAR)KeyInfo != KeyInfoBuffer) + { + RtlFreeHeap (RtlGetProcessHeap(), + 0, + KeyInfo); + } return STATUS_OBJECT_TYPE_MISMATCH; }
@@ -3451,9 +3451,12 @@ &KeyInfo->Data, ResultSize);
- RtlFreeHeap (RtlGetProcessHeap(), - 0, - KeyInfo); + if ((PCHAR)KeyInfo != KeyInfoBuffer) + { + RtlFreeHeap (RtlGetProcessHeap(), + 0, + KeyInfo); + }
if (ReturnedLength != NULL) {