From 5b90b4286173ce054e90c91f796736bdb314da9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 22 Sep 2013 15:14:24 +0000 Subject: [PATCH] [RTL] - Implement and export RtlGetCriticalSectionRecursionCount (introduced in NT 5.2 SP1, see http://www.geoffchappell.com/studies/windows/win32/ntdll/history/names52.htm) which definition comes from http://processhacker.sourceforge.net/doc/ntrtl_8h.html#a26bd65dfad63985a247700c2c2ab9e86. - Fix the return type of RtlSetCriticalSectionSpinCount. - Export the already-existing RtlQueryInformationActiveActivationContext API. RtlQueryInformationActiveActivationContext and RtlGetCriticalSectionRecursionCount are needed by Win2k3 user32.dll and winsrv.dll . svn path=/trunk/; revision=60302 --- reactos/dll/ntdll/def/ntdll.spec | 4 +-- reactos/lib/rtl/critical.c | 43 ++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/reactos/dll/ntdll/def/ntdll.spec b/reactos/dll/ntdll/def/ntdll.spec index 9d144c743e3..32e07c84f5c 100644 --- a/reactos/dll/ntdll/def/ntdll.spec +++ b/reactos/dll/ntdll/def/ntdll.spec @@ -614,7 +614,7 @@ @ stdcall RtlGetCallersAddress(ptr ptr) @ stdcall RtlGetCompressionWorkSpaceSize(long ptr ptr) @ stdcall RtlGetControlSecurityDescriptor(ptr ptr ptr) -;@ stdcall RtlGetCriticalSectionRecursionCount +@ stdcall RtlGetCriticalSectionRecursionCount(ptr) @ stdcall RtlGetCurrentDirectory_U(long ptr) @ stdcall RtlGetCurrentPeb() @ stdcall RtlGetCurrentProcessorNumber() ; 5.2 SP1 and higher @@ -780,7 +780,7 @@ @ stdcall RtlQueryHeapInformation(long long ptr long ptr) @ stdcall RtlQueryInformationAcl(ptr ptr long long) @ stdcall RtlQueryInformationActivationContext(long long ptr long ptr long ptr) -;@ stdcall RtlQueryInformationActiveActivationContext +@ stdcall RtlQueryInformationActiveActivationContext(long ptr long ptr) ;@ stdcall RtlQueryInterfaceMemoryStream ;@ stdcall RtlQueryProcessBackTraceInformation @ stdcall RtlQueryProcessDebugInformation(long long ptr) diff --git a/reactos/lib/rtl/critical.c b/reactos/lib/rtl/critical.c index 80afe4de445..917cbf2dda9 100644 --- a/reactos/lib/rtl/critical.c +++ b/reactos/lib/rtl/critical.c @@ -299,7 +299,7 @@ RtlpAllocateDebugInfo(VOID) } /* We are out of static buffer, allocate dynamic */ - return RtlAllocateHeap(NtCurrentPeb()->ProcessHeap, + return RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(RTL_CRITICAL_SECTION_DEBUG)); } @@ -436,7 +436,7 @@ RtlDeleteCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) * SpinCount is ignored on single-processor systems. * *--*/ -DWORD +ULONG NTAPI RtlSetCriticalSectionSpinCount(PRTL_CRITICAL_SECTION CriticalSection, ULONG SpinCount) @@ -618,6 +618,45 @@ RtlInitializeCriticalSectionAndSpinCount(PRTL_CRITICAL_SECTION CriticalSection, return STATUS_SUCCESS; } +/*++ + * RtlGetCriticalSectionRecursionCount + * @implemented NT5.2 SP1 + * + * Retrieves the recursion count of a given critical section. + * + * Params: + * CriticalSection - Critical section to retrieve its recursion count. + * + * Returns: + * The recursion count. + * + * Remarks: + * We return the recursion count of the critical section if it is owned + * by the current thread, and otherwise we return zero. + * + *--*/ +LONG +NTAPI +RtlGetCriticalSectionRecursionCount(PRTL_CRITICAL_SECTION CriticalSection) +{ + if (CriticalSection->OwningThread == NtCurrentTeb()->ClientId.UniqueThread) + { + /* + * The critical section is owned by the current thread, + * therefore retrieve its actual recursion count. + */ + return CriticalSection->RecursionCount; + } + else + { + /* + * It is not owned by the current thread, so + * for this thread there is no recursion. + */ + return 0; + } +} + /*++ * RtlLeaveCriticalSection * @implemented NT4