Fix provider boost alerting when the driver is enabled #813
This commit is contained in:
@@ -40,6 +40,7 @@ typedef struct _PH_PROVIDER_THREAD
|
||||
{
|
||||
HANDLE ThreadHandle;
|
||||
HANDLE TimerHandle;
|
||||
HANDLE EventHandle;
|
||||
ULONG Interval;
|
||||
PH_PROVIDER_THREAD_STATE State;
|
||||
|
||||
|
||||
+28
-13
@@ -3,6 +3,7 @@
|
||||
* provider system
|
||||
*
|
||||
* Copyright (C) 2009-2016 wj32
|
||||
* Copyright (C) 2021 dmex
|
||||
*
|
||||
* This file is part of Process Hacker.
|
||||
*
|
||||
@@ -38,6 +39,11 @@
|
||||
* synchronization.
|
||||
*/
|
||||
|
||||
// NOTE: The provider originally used alertable waits but this conflicted with the kernel driver
|
||||
// which also uses alertable waits for callbacks. The provider was changed to use synchronization
|
||||
// events which are less efficient and require more resources. These additions should be reverted
|
||||
// back to using alertable waits after the kernel driver has been ported over to the newer framework (dmex)
|
||||
|
||||
#include <ph.h>
|
||||
#include <provider.h>
|
||||
|
||||
@@ -91,7 +97,7 @@ VOID PhDeleteProviderThread(
|
||||
|
||||
#ifdef DEBUG
|
||||
PhAcquireQueuedLockExclusive(&PhDbgProviderListLock);
|
||||
if ((index = PhFindItemList(PhDbgProviderList, ProviderThread)) != -1)
|
||||
if ((index = PhFindItemList(PhDbgProviderList, ProviderThread)) != ULONG_MAX)
|
||||
PhRemoveItemList(PhDbgProviderList, index);
|
||||
PhReleaseQueuedLockExclusive(&PhDbgProviderListLock);
|
||||
#endif
|
||||
@@ -109,6 +115,10 @@ NTSTATUS NTAPI PhpProviderThreadStart(
|
||||
PPH_PROVIDER_FUNCTION providerFunction;
|
||||
PVOID object;
|
||||
LIST_ENTRY tempListHead;
|
||||
HANDLE objects[2];
|
||||
|
||||
objects[0] = providerThread->TimerHandle;
|
||||
objects[1] = providerThread->EventHandle;
|
||||
|
||||
PhInitializeAutoPool(&autoPool);
|
||||
|
||||
@@ -128,13 +138,13 @@ NTSTATUS NTAPI PhpProviderThreadStart(
|
||||
|
||||
// Main loop.
|
||||
|
||||
// We check the status variable for STATUS_ALERTED, which means that someone is requesting
|
||||
// that a provider be boosted. Note that if they alert this thread while we are not waiting
|
||||
// on the timer, when we do perform the wait it will return immediately with STATUS_ALERTED.
|
||||
// We check the status variable for STATUS_WAIT_1, which means that someone is requesting
|
||||
// that a provider be boosted. Note that if they signal the event while we are not waiting
|
||||
// on the timer, when we do perform the wait it will return immediately with STATUS_WAIT_1.
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (status == STATUS_ALERTED)
|
||||
if (status == STATUS_WAIT_1)
|
||||
{
|
||||
// Check if we have any more providers to boost. Note that this always works because
|
||||
// boosted providers are always in front of normal providers. Therefore we will
|
||||
@@ -154,7 +164,7 @@ NTSTATUS NTAPI PhpProviderThreadStart(
|
||||
// Add the provider to the temp list.
|
||||
InsertTailList(&tempListHead, listEntry);
|
||||
|
||||
if (status != STATUS_ALERTED)
|
||||
if (status != STATUS_WAIT_1)
|
||||
{
|
||||
if (!registration->Enabled || registration->Unregistering)
|
||||
continue;
|
||||
@@ -174,7 +184,7 @@ NTSTATUS NTAPI PhpProviderThreadStart(
|
||||
}
|
||||
}
|
||||
|
||||
if (status == STATUS_ALERTED)
|
||||
if (status == STATUS_WAIT_1)
|
||||
{
|
||||
assert(registration->Boosting);
|
||||
registration->Boosting = FALSE;
|
||||
@@ -215,11 +225,13 @@ NTSTATUS NTAPI PhpProviderThreadStart(
|
||||
|
||||
PhReleaseQueuedLockExclusive(&providerThread->Lock);
|
||||
|
||||
// Perform an alertable wait so we can be woken up by someone telling us to boost providers,
|
||||
// Perform a wait so we can be woken up by someone telling us to boost providers,
|
||||
// or to terminate.
|
||||
status = NtWaitForSingleObject(
|
||||
providerThread->TimerHandle,
|
||||
TRUE,
|
||||
status = NtWaitForMultipleObjects(
|
||||
RTL_NUMBER_OF(objects),
|
||||
objects,
|
||||
WaitAny,
|
||||
FALSE,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
@@ -241,6 +253,9 @@ VOID PhStartProviderThread(
|
||||
if (ProviderThread->State != ProviderThreadStopped)
|
||||
return;
|
||||
|
||||
// Create the boost event.
|
||||
NtCreateEvent(&ProviderThread->EventHandle, EVENT_ALL_ACCESS, NULL, SynchronizationEvent, FALSE);
|
||||
|
||||
// Create and set the timer.
|
||||
NtCreateTimer(&ProviderThread->TimerHandle, TIMER_ALL_ACCESS, NULL, SynchronizationTimer);
|
||||
PhSetIntervalProviderThread(ProviderThread, ProviderThread->Interval);
|
||||
@@ -264,7 +279,7 @@ VOID PhStopProviderThread(
|
||||
|
||||
// Signal to the thread that we are shutting down, and wait for it to exit.
|
||||
ProviderThread->State = ProviderThreadStopping;
|
||||
NtAlertThread(ProviderThread->ThreadHandle); // wake it up
|
||||
NtSetEvent(ProviderThread->EventHandle, NULL); // wake it up
|
||||
NtWaitForSingleObject(ProviderThread->ThreadHandle, FALSE, NULL);
|
||||
|
||||
// Free resources.
|
||||
@@ -418,7 +433,7 @@ BOOLEAN PhBoostProvider(
|
||||
PhReleaseQueuedLockExclusive(&providerThread->Lock);
|
||||
|
||||
// Wake up the thread.
|
||||
NtAlertThread(providerThread->ThreadHandle);
|
||||
NtSetEvent(providerThread->EventHandle, NULL);
|
||||
|
||||
if (FutureRunId)
|
||||
*FutureRunId = futureRunId;
|
||||
|
||||
Reference in New Issue
Block a user