Signed-off-by: Zebediah Figura z.figura12@gmail.com --- include/ddk/wdm.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 81f41f5a97..c85b831a04 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -168,12 +168,14 @@ typedef struct _OBJECT_TYPE *POBJECT_TYPE; typedef struct _OBJECT_HANDLE_INFORMATION *POBJECT_HANDLE_INFORMATION; typedef struct _ZONE_HEADER *PZONE_HEADER;
+#define FM_LOCK_BIT 0x1 + typedef struct _FAST_MUTEX { LONG Count; PKTHREAD Owner; ULONG Contention; - KEVENT Gate; + KEVENT Event; ULONG OldIrql; } FAST_MUTEX, *PFAST_MUTEX;
@@ -1622,4 +1624,12 @@ NTSTATUS WINAPI ZwWaitForMultipleObjects(ULONG,const HANDLE*,BOOLEAN,BOOLEAN,co NTSTATUS WINAPI ZwWriteFile(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,const void*,ULONG,PLARGE_INTEGER,PULONG); NTSTATUS WINAPI ZwYieldExecution(void);
+static inline void ExInitializeFastMutex( FAST_MUTEX *mutex ) +{ + mutex->Count = FM_LOCK_BIT; + mutex->Owner = NULL; + mutex->Contention = 0; + KeInitializeEvent( &mutex->Event, SynchronizationEvent, FALSE ); +} + #endif
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 28 -------------------------- dlls/ntoskrnl.exe/sync.c | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 28 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 20bd401489..f2aecd8a56 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -729,34 +729,6 @@ done: return status; }
- -/*********************************************************************** - * ExAcquireFastMutexUnsafe (NTOSKRNL.EXE.@) - */ -#ifdef DEFINE_FASTCALL1_ENTRYPOINT -DEFINE_FASTCALL1_ENTRYPOINT(ExAcquireFastMutexUnsafe) -void WINAPI __regs_ExAcquireFastMutexUnsafe(PFAST_MUTEX FastMutex) -#else -void WINAPI ExAcquireFastMutexUnsafe(PFAST_MUTEX FastMutex) -#endif -{ - FIXME("(%p): stub\n", FastMutex); -} - - -/*********************************************************************** - * ExReleaseFastMutexUnsafe (NTOSKRNL.EXE.@) - */ -#ifdef DEFINE_FASTCALL1_ENTRYPOINT -DEFINE_FASTCALL1_ENTRYPOINT(ExReleaseFastMutexUnsafe) -void WINAPI __regs_ExReleaseFastMutexUnsafe(PFAST_MUTEX FastMutex) -#else -void WINAPI ExReleaseFastMutexUnsafe(PFAST_MUTEX FastMutex) -#endif -{ - FIXME("(%p): stub\n", FastMutex); -} - /*********************************************************************** * IoAllocateDriverObjectExtension (NTOSKRNL.EXE.@) */ diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 46ffc581f0..1ab37d13f6 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -562,3 +562,41 @@ LIST_ENTRY * WINAPI ExInterlockedRemoveHeadList( LIST_ENTRY *list, KSPIN_LOCK *l
return ret; } + +/*********************************************************************** + * ExAcquireFastMutexUnsafe (NTOSKRNL.EXE.@) + */ +#ifdef DEFINE_FASTCALL1_ENTRYPOINT +DEFINE_FASTCALL1_ENTRYPOINT(ExAcquireFastMutexUnsafe) +void WINAPI __regs_ExAcquireFastMutexUnsafe( FAST_MUTEX *mutex ) +#else +void WINAPI ExAcquireFastMutexUnsafe( FAST_MUTEX *mutex ) +#endif +{ + LONG count; + + TRACE("mutex %p.\n", mutex); + + count = InterlockedDecrement( &mutex->Count ); + if (count < 0) + KeWaitForSingleObject( &mutex->Event, Executive, KernelMode, FALSE, NULL ); +} + +/*********************************************************************** + * ExReleaseFastMutexUnsafe (NTOSKRNL.EXE.@) + */ +#ifdef DEFINE_FASTCALL1_ENTRYPOINT +DEFINE_FASTCALL1_ENTRYPOINT(ExReleaseFastMutexUnsafe) +void WINAPI __regs_ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) +#else +void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) +#endif +{ + LONG count; + + TRACE("mutex %p.\n", mutex); + + count = InterlockedIncrement( &mutex->Count ); + if (count < 1) + KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); +}
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/hal/hal.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/dlls/hal/hal.c b/dlls/hal/hal.c index 87962727da..3e9779626e 100644 --- a/dlls/hal/hal.c +++ b/dlls/hal/hal.c @@ -64,16 +64,20 @@ __ASM_STDCALL_FUNC( call_fastcall_func2, 12, "xchgl (%esp),%edx\n\t" "jmp *%eax" );
+extern void WINAPI ExAcquireFastMutexUnsafe( FAST_MUTEX * ); + DEFINE_FASTCALL1_ENTRYPOINT( ExAcquireFastMutex ) -VOID WINAPI DECLSPEC_HIDDEN __regs_ExAcquireFastMutex(PFAST_MUTEX FastMutex) +void WINAPI DECLSPEC_HIDDEN __regs_ExAcquireFastMutex( FAST_MUTEX *mutex ) { - FIXME("%p: stub\n", FastMutex); + call_fastcall_func1( ExAcquireFastMutexUnsafe, mutex ); }
+extern void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX * ); + DEFINE_FASTCALL1_ENTRYPOINT( ExReleaseFastMutex ) -VOID WINAPI DECLSPEC_HIDDEN __regs_ExReleaseFastMutex(PFAST_MUTEX FastMutex) +void WINAPI DECLSPEC_HIDDEN __regs_ExReleaseFastMutex( FAST_MUTEX *mutex ) { - FIXME("%p: stub\n", FastMutex); + call_fastcall_func1( ExReleaseFastMutexUnsafe, mutex ); }
DEFINE_FASTCALL1_ENTRYPOINT( ExTryToAcquireFastMutex )
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/hal/hal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/dlls/hal/hal.c b/dlls/hal/hal.c index 3e9779626e..6ef8765321 100644 --- a/dlls/hal/hal.c +++ b/dlls/hal/hal.c @@ -81,10 +81,11 @@ void WINAPI DECLSPEC_HIDDEN __regs_ExReleaseFastMutex( FAST_MUTEX *mutex ) }
DEFINE_FASTCALL1_ENTRYPOINT( ExTryToAcquireFastMutex ) -BOOLEAN WINAPI DECLSPEC_HIDDEN __regs_ExTryToAcquireFastMutex(PFAST_MUTEX FastMutex) +BOOLEAN WINAPI DECLSPEC_HIDDEN __regs_ExTryToAcquireFastMutex( FAST_MUTEX *mutex ) { - FIXME("(%p) stub\n", FastMutex); - return TRUE; + TRACE("mutex %p.\n", mutex); + + return (InterlockedCompareExchange( &mutex->Count, 0, 1 ) == 1); }
DEFINE_FASTCALL1_ENTRYPOINT( KfAcquireSpinLock )
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntoskrnl.exe/sync.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index 1ab37d13f6..065609117c 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -191,14 +191,14 @@ void WINAPI KeInitializeEvent( PRKEVENT event, EVENT_TYPE type, BOOLEAN state ) */ LONG WINAPI KeSetEvent( PRKEVENT event, KPRIORITY increment, BOOLEAN wait ) { - HANDLE handle = event->Header.WaitListHead.Blink; + HANDLE handle; LONG ret;
TRACE("event %p, increment %d, wait %u.\n", event, increment, wait);
EnterCriticalSection( &sync_cs ); ret = InterlockedExchange( &event->Header.SignalState, TRUE ); - if (handle) + if ((handle = event->Header.WaitListHead.Blink)) SetEvent( handle ); LeaveCriticalSection( &sync_cs );
@@ -210,14 +210,14 @@ LONG WINAPI KeSetEvent( PRKEVENT event, KPRIORITY increment, BOOLEAN wait ) */ LONG WINAPI KeResetEvent( PRKEVENT event ) { - HANDLE handle = event->Header.WaitListHead.Blink; + HANDLE handle; LONG ret;
TRACE("event %p.\n", event);
EnterCriticalSection( &sync_cs ); ret = InterlockedExchange( &event->Header.SignalState, FALSE ); - if (handle) + if ((handle = event->Header.WaitListHead.Blink)) ResetEvent( handle ); LeaveCriticalSection( &sync_cs );
@@ -252,7 +252,7 @@ void WINAPI KeInitializeSemaphore( PRKSEMAPHORE semaphore, LONG count, LONG limi LONG WINAPI KeReleaseSemaphore( PRKSEMAPHORE semaphore, KPRIORITY increment, LONG count, BOOLEAN wait ) { - HANDLE handle = semaphore->Header.WaitListHead.Blink; + HANDLE handle; LONG ret;
TRACE("semaphore %p, increment %d, count %d, wait %u.\n", @@ -260,7 +260,7 @@ LONG WINAPI KeReleaseSemaphore( PRKSEMAPHORE semaphore, KPRIORITY increment,
EnterCriticalSection( &sync_cs ); ret = InterlockedExchangeAdd( &semaphore->Header.SignalState, count ); - if (handle) + if ((handle = semaphore->Header.WaitListHead.Blink)) ReleaseSemaphore( handle, count, NULL ); LeaveCriticalSection( &sync_cs );
@@ -285,7 +285,6 @@ void WINAPI KeInitializeMutex( PRKMUTEX mutex, ULONG level ) */ LONG WINAPI KeReleaseMutex( PRKMUTEX mutex, BOOLEAN wait ) { - HANDLE handle = mutex->Header.WaitListHead.Blink; LONG ret;
TRACE("mutex %p, wait %u.\n", mutex, wait); @@ -294,7 +293,7 @@ LONG WINAPI KeReleaseMutex( PRKMUTEX mutex, BOOLEAN wait ) ret = mutex->Header.SignalState++; if (!ret && !mutex->Header.WaitListHead.Flink) { - CloseHandle( handle ); + CloseHandle( mutex->Header.WaitListHead.Blink ); mutex->Header.WaitListHead.Blink = NULL; } LeaveCriticalSection( &sync_cs ); @@ -330,7 +329,6 @@ void WINAPI KeInitializeTimer( KTIMER *timer ) */ BOOLEAN WINAPI KeSetTimerEx( KTIMER *timer, LARGE_INTEGER duetime, LONG period, KDPC *dpc ) { - BOOL manual = timer->Header.Type == TYPE_MANUAL_TIMER; BOOL ret;
TRACE("timer %p, duetime %s, period %d, dpc %p.\n", @@ -343,10 +341,12 @@ BOOLEAN WINAPI KeSetTimerEx( KTIMER *timer, LARGE_INTEGER duetime, LONG period, }
EnterCriticalSection( &sync_cs ); + ret = timer->Header.Inserted; timer->Header.Inserted = TRUE; - timer->Header.WaitListHead.Blink = CreateWaitableTimerW( NULL, manual, NULL ); + timer->Header.WaitListHead.Blink = CreateWaitableTimerW( NULL, timer->Header.Type == TYPE_MANUAL_TIMER, NULL ); SetWaitableTimer( timer->Header.WaitListHead.Blink, &duetime, period, NULL, NULL, FALSE ); + LeaveCriticalSection( &sync_cs );
return ret;