[PATCH v9 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. -- v9: ntoskrnl.exe: Implement KeReleaseGuardedMutex. 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 | 6 ++++-- dlls/ntoskrnl.exe/sync.c | 33 +++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index cea2538c719..60ce0fbb292 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -52,14 +52,16 @@ @ stdcall -fastcall IofCompleteRequest(ptr long) @ stdcall -arch=!i386 KeAcquireInStackQueuedSpinLock(ptr ptr) @ stdcall -fastcall KeAcquireInStackQueuedSpinLockAtDpcLevel(ptr ptr) -@ stdcall KeAcquireGuardedMutexUnsafe(ptr) -@ stdcall KeAcquireGuardedMutex(ptr) +@ stdcall -fastcall KeAcquireGuardedMutexUnsafe(ptr) +@ stdcall -fastcall KeAcquireGuardedMutex(ptr) @ stdcall KeEnterGuardedRegion() @ stdcall KeExpandKernelStackAndCallout(ptr ptr long) @ stdcall KeExpandKernelStackAndCalloutEx(ptr ptr long long ptr) @ stdcall KeLeaveGuardedRegion() @ stdcall -arch=!i386 KeReleaseInStackQueuedSpinLock(ptr) @ stdcall -fastcall KeReleaseInStackQueuedSpinLockFromDpcLevel(ptr) +@ stdcall -fastcall KeReleaseGuardedMutexUnsafe(ptr) +@ stdcall -fastcall KeReleaseGuardedMutex(ptr) @ stub KeSetTimeUpdateNotifyRoutine @ stub KefAcquireSpinLockAtDpcLevel @ stub KefReleaseSpinLockFromDpcLevel diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 773c241a17e..009a1085bce 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -441,26 +441,41 @@ void WINAPI KeInitializeGuardedMutex(PKGUARDED_MUTEX mutex) /*********************************************************************** * KeAcquireGuardedMutexUnsafe (NTOSKRNL.EXE.@) */ -void WINAPI KeAcquireGuardedMutexUnsafe(PKGUARDED_MUTEX mutex) +DEFINE_FASTCALL1_WRAPPER(KeAcquireGuardedMutexUnsafe) +void FASTCALL 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 ); + ExAcquireFastMutexUnsafe((PFAST_MUTEX)mutex); } /*********************************************************************** * KeAcquireGuardedMutex (NTOSKRNL.EXE.@) */ -void WINAPI KeAcquireGuardedMutex(PKGUARDED_MUTEX mutex) +DEFINE_FASTCALL1_WRAPPER(KeAcquireGuardedMutex) +void FASTCALL KeAcquireGuardedMutex(PKGUARDED_MUTEX mutex) { /* FIXME: Enter Guarded Region */ KeAcquireGuardedMutexUnsafe(mutex); } +/*********************************************************************** + * KeReleaseGuardedMutexUnsafe (NTOSKRNL.EXE.@) + */ +DEFINE_FASTCALL1_WRAPPER(KeReleaseGuardedMutexUnsafe) +void FASTCALL KeReleaseGuardedMutexUnsafe(PKGUARDED_MUTEX mutex) +{ + ExReleaseFastMutexUnsafe((PFAST_MUTEX)mutex); +} + +/*********************************************************************** + * KeReleaseGuardedMutex (NTOSKRNL.EXE.@) + */ +DEFINE_FASTCALL1_WRAPPER(KeReleaseGuardedMutex) +void FASTCALL 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
Ah shoot, I accidentally put both the fastcall changes into the second commit will fix it later -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2044#note_128236
Both unsafe and safe versions are fastcall? in wine the fast lock (safe version) is winapi (stdcall) for safe and fastcall for unsafe
All of the fast mutex and guarded mutex functions are fastcall according to NT headers. The import libraries agree. However, the distinction only matters on i386, and ExAcquireFastMutex/ExReleaseFastMutex don't exist on i386.
also what about KeInitializeGuardedMutex?
Also should be fastcall. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2044#note_128295
participants (3)
-
Elizabeth Figura (@zfigura) -
Etaash Mathamsetty -
Etaash Mathamsetty (@etaash.mathamsetty)