From 5e787ba521a6fcbd8a4cf4ad02edcc40264a1346 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 3 Aug 2005 16:03:15 +0000 Subject: [PATCH] Hack to make the main heap critical section have a proper debug info structure. --- dlls/ntdll/critsection.c | 26 +++++++++++--------------- dlls/ntdll/heap.c | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/dlls/ntdll/critsection.c b/dlls/ntdll/critsection.c index bf00bbbfd2..0c77224903 100644 --- a/dlls/ntdll/critsection.c +++ b/dlls/ntdll/critsection.c @@ -114,22 +114,18 @@ NTSTATUS WINAPI RtlInitializeCriticalSection( RTL_CRITICAL_SECTION *crit ) */ NTSTATUS WINAPI RtlInitializeCriticalSectionAndSpinCount( RTL_CRITICAL_SECTION *crit, ULONG spincount ) { - if (!GetProcessHeap()) crit->DebugInfo = NULL; - else + crit->DebugInfo = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(RTL_CRITICAL_SECTION_DEBUG)); + if (crit->DebugInfo) { - crit->DebugInfo = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(RTL_CRITICAL_SECTION_DEBUG)); - if (crit->DebugInfo) - { - crit->DebugInfo->Type = 0; - crit->DebugInfo->CreatorBackTraceIndex = 0; - crit->DebugInfo->CriticalSection = crit; - crit->DebugInfo->ProcessLocksList.Blink = &(crit->DebugInfo->ProcessLocksList); - crit->DebugInfo->ProcessLocksList.Flink = &(crit->DebugInfo->ProcessLocksList); - crit->DebugInfo->EntryCount = 0; - crit->DebugInfo->ContentionCount = 0; - crit->DebugInfo->Spare[0] = 0; - crit->DebugInfo->Spare[1] = 0; - } + crit->DebugInfo->Type = 0; + crit->DebugInfo->CreatorBackTraceIndex = 0; + crit->DebugInfo->CriticalSection = crit; + crit->DebugInfo->ProcessLocksList.Blink = &(crit->DebugInfo->ProcessLocksList); + crit->DebugInfo->ProcessLocksList.Flink = &(crit->DebugInfo->ProcessLocksList); + crit->DebugInfo->EntryCount = 0; + crit->DebugInfo->ContentionCount = 0; + crit->DebugInfo->Spare[0] = 0; + crit->DebugInfo->Spare[1] = 0; } crit->LockCount = -1; crit->RecursionCount = 0; diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 7490c8940a..548df128a4 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -172,6 +172,14 @@ static inline void clear_block( void *ptr, SIZE_T size ) memset( ptr, 0, size ); } +static RTL_CRITICAL_SECTION_DEBUG process_heap_critsect_debug = +{ + 0, 0, NULL, /* will be set later */ + { &process_heap_critsect_debug.ProcessLocksList, &process_heap_critsect_debug.ProcessLocksList }, + 0, 0, { 0, (DWORD)(__FILE__ ": main process heap section") } +}; + + /*********************************************************************** * HEAP_Dump */ @@ -611,7 +619,18 @@ static BOOL HEAP_InitSubHeap( HEAP *heap, LPVOID address, DWORD flags, /* Initialize critical section */ - RtlInitializeCriticalSection( &heap->critSection ); + if (!processHeap) /* do it by hand to avoid memory allocations */ + { + heap->critSection.DebugInfo = &process_heap_critsect_debug; + heap->critSection.LockCount = -1; + heap->critSection.RecursionCount = 0; + heap->critSection.OwningThread = 0; + heap->critSection.LockSemaphore = 0; + heap->critSection.SpinCount = 0; + process_heap_critsect_debug.CriticalSection = &heap->critSection; + } + else RtlInitializeCriticalSection( &heap->critSection ); + if (flags & HEAP_SHARED) { /* let's assume that only one thread at a time will try to do this */