Signed-off-by: Derek Lesho dereklesho52@Gmail.com --- dlls/ntoskrnl.exe/ntoskrnl.c | 1 + dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 2 ++ dlls/ntoskrnl.exe/ntoskrnl_private.h | 1 + dlls/ntoskrnl.exe/sync.c | 34 ++++++++++++++++++++++++++++ include/ddk/wdm.h | 4 ++++ 5 files changed, 42 insertions(+)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 46fd243d75..32ead1ff20 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -2518,6 +2518,7 @@ static void *create_thread_object( HANDLE handle ) ObDereferenceObject( thread->process );
thread->critical_region = FALSE; + thread->irql = PASSIVE_LEVEL;
return thread; } diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 399258cdfd..f4e6d8f710 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1,4 +1,5 @@ @ stdcall -fastcall ExAcquireFastMutexUnsafe(ptr) +@ stdcall ExAcquireFastMutex(ptr) @ stub ExAcquireRundownProtection @ stub ExAcquireRundownProtectionEx @ stub ExInitializeRundownProtection @@ -9,6 +10,7 @@ @ stdcall -fastcall -arch=i386 ExInterlockedPushEntrySList (ptr ptr ptr) NTOSKRNL_ExInterlockedPushEntrySList @ stub ExReInitializeRundownProtection @ stdcall -fastcall ExReleaseFastMutexUnsafe(ptr) +@ stdcall ExReleaseFastMutex(ptr) @ stdcall ExReleaseResourceLite(ptr) @ stub ExReleaseRundownProtection @ stub ExReleaseRundownProtectionEx diff --git a/dlls/ntoskrnl.exe/ntoskrnl_private.h b/dlls/ntoskrnl.exe/ntoskrnl_private.h index 940ff526f9..84f8387262 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl_private.h +++ b/dlls/ntoskrnl.exe/ntoskrnl_private.h @@ -38,6 +38,7 @@ struct _KTHREAD CLIENT_ID id; PEPROCESS process; BOOLEAN critical_region; + UCHAR irql; };
void *alloc_kernel_object( POBJECT_TYPE type, HANDLE handle, SIZE_T size, LONG ref ) DECLSPEC_HIDDEN; diff --git a/dlls/ntoskrnl.exe/sync.c b/dlls/ntoskrnl.exe/sync.c index bb2d318e56..15a602d3f4 100644 --- a/dlls/ntoskrnl.exe/sync.c +++ b/dlls/ntoskrnl.exe/sync.c @@ -689,3 +689,37 @@ void WINAPI ExReleaseFastMutexUnsafe( FAST_MUTEX *mutex ) if (InterlockedIncrement(&mutex->Count) < 1) KeSetEvent( &mutex->Event, IO_NO_INCREMENT, FALSE ); } + + +/********************************************************************* + * ExAcquireFastMutex (NTOSKRNL.@) + */ +DEFINE_FASTCALL1_WRAPPER(ExAcquireFastMutex) +void WINAPI ExAcquireFastMutex(PFAST_MUTEX mutex) +{ + KIRQL old_irql; + PKTHREAD thread = KeGetCurrentThread(); + + /* The safe variant raises thread to APC_LEVEL */ + old_irql = thread->irql; + thread->irql = APC_LEVEL; + + ExAcquireFastMutexUnsafe( mutex ); + + mutex->OldIrql = old_irql; +} + + + /********************************************************************* + * ExReleaseFastMutex (NTOSKRNL.@) + */ +DEFINE_FASTCALL1_WRAPPER(ExReleaseFastMutex) +void WINAPI ExReleaseFastMutex(PFAST_MUTEX mutex) +{ + KIRQL old_irql = mutex->OldIrql; + PKTHREAD thread = mutex->Owner; + + ExReleaseFastMutexUnsafe( mutex ); + + thread->irql = old_irql; +} diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 02c1bf3f20..3611c7cd90 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -168,6 +168,10 @@ typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX;
#define FM_LOCK_BIT 0x1
+/* irqls */ +#define PASSIVE_LEVEL 0 +#define APC_LEVEL 1 + typedef struct _FAST_MUTEX { LONG Count;