[PATCH v8 0/2] MR2044: ntoskrnl.exe: Implement acquiring and releasing guarded mutexes
according to MSDN they are implemented in the same way as a fast mutex. -- v8: ntoskrnl.exe: Implement KeReleaseGuardedMutex. ntoskrnl.exe: Implement KeAcquireGuardedMutex. https://gitlab.winehq.org/wine/wine/-/merge_requests/2044
From: Etaash Mathamsetty <etaash.mathamsetty@gmail.com> --- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 ++ dlls/ntoskrnl.exe/sync.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 4426e5066e0..cea2538c719 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -52,6 +52,8 @@ @ stdcall -fastcall IofCompleteRequest(ptr long) @ stdcall -arch=!i386 KeAcquireInStackQueuedSpinLock(ptr ptr) @ stdcall -fastcall KeAcquireInStackQueuedSpinLockAtDpcLevel(ptr ptr) +@ stdcall KeAcquireGuardedMutexUnsafe(ptr) +@ stdcall KeAcquireGuardedMutex(ptr) @ stdcall KeEnterGuardedRegion() @ stdcall KeExpandKernelStackAndCallout(ptr ptr long) @ stdcall KeExpandKernelStackAndCalloutEx(ptr ptr long long ptr) diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 2183df351b2..773c241a17e 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -438,6 +438,29 @@ void WINAPI KeInitializeGuardedMutex(PKGUARDED_MUTEX mutex) KeInitializeEvent(&mutex->Event, SynchronizationEvent, FALSE); } +/*********************************************************************** + * KeAcquireGuardedMutexUnsafe (NTOSKRNL.EXE.@) + */ +void WINAPI KeAcquireGuardedMutexUnsafe(PKGUARDED_MUTEX mutex) +{ + LONG count; + + TRACE("mutex %p.\n", mutex); + + count = InterlockedDecrement( &mutex->Count ); + if (count < 0) + KeWaitForSingleObject( &mutex->Event, Executive, KernelMode, FALSE, NULL ); +} + +/*********************************************************************** + * KeAcquireGuardedMutex (NTOSKRNL.EXE.@) + */ +void WINAPI KeAcquireGuardedMutex(PKGUARDED_MUTEX mutex) +{ + /* FIXME: Enter Guarded Region */ + KeAcquireGuardedMutexUnsafe(mutex); +} + static void CALLBACK ke_timer_complete_proc(PTP_CALLBACK_INSTANCE instance, void *timer_, PTP_TIMER tp_timer) { KTIMER *timer = timer_; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2044
From: Etaash Mathamsetty <etaash.mathamsetty@gmail.com> --- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 ++ dlls/ntoskrnl.exe/sync.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index cea2538c719..70999698499 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -60,6 +60,8 @@ @ stdcall KeLeaveGuardedRegion() @ stdcall -arch=!i386 KeReleaseInStackQueuedSpinLock(ptr) @ stdcall -fastcall KeReleaseInStackQueuedSpinLockFromDpcLevel(ptr) +@ stdcall KeReleaseGuardedMutexUnsafe(ptr) +@ stdcall KeReleaseGuardedMutex(ptr) @ stub KeSetTimeUpdateNotifyRoutine @ stub KefAcquireSpinLockAtDpcLevel @ stub KefReleaseSpinLockFromDpcLevel diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 773c241a17e..ea97c0deead 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -461,6 +461,29 @@ void WINAPI KeAcquireGuardedMutex(PKGUARDED_MUTEX mutex) KeAcquireGuardedMutexUnsafe(mutex); } +/*********************************************************************** + * KeReleaseGuardedMutexUnsafe (NTOSKRNL.EXE.@) + */ +void WINAPI KeReleaseGuardedMutexUnsafe(PKGUARDED_MUTEX mutex) +{ + LONG count; + + TRACE("mutex %p.\n", mutex); + + count = InterlockedIncrement( &mutex->Count ); + if (count < 1) + KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); +} + +/*********************************************************************** + * KeReleaseGuardedMutex (NTOSKRNL.EXE.@) + */ +void WINAPI KeReleaseGuardedMutex(PKGUARDED_MUTEX mutex) +{ + KeReleaseGuardedMutexUnsafe(mutex); + /* FIXME: Leave Guarded Region */ +} + static void CALLBACK ke_timer_complete_proc(PTP_CALLBACK_INSTANCE instance, void *timer_, PTP_TIMER tp_timer) { KTIMER *timer = timer_; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2044
On Wed Jan 28 07:10:25 2026 +0000, Etaash Mathamsetty wrote:
Both unsafe and safe versions are fastcall? in wine the fast lock (safe version) is winapi (stdcall) for safe and fastcall for unsafe also what about KeInitializeGuardedMutex?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/2044#note_128233
participants (2)
-
Etaash Mathamsetty -
Etaash Mathamsetty (@etaash.mathamsetty)