Skip to content

Commit

Permalink
Merge pull request #453 from processhacker/master
Browse files Browse the repository at this point in the history
[pull] master from processhacker:master
  • Loading branch information
pull[bot] authored Apr 16, 2022
2 parents acf1fc2 + 2148a15 commit 0827d2b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 40 deletions.
1 change: 1 addition & 0 deletions ProcessHacker/include/phapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern PH_STARTUP_PARAMETERS PhStartupParameters;

extern PH_PROVIDER_THREAD PhPrimaryProviderThread;
extern PH_PROVIDER_THREAD PhSecondaryProviderThread;
extern PH_PROVIDER_THREAD PhTertiaryProviderThread;

#define PH_SCALE_DPI(Value) PhMultiplyDivide(Value, PhGlobalDpi, 96) // phapppub

Expand Down
1 change: 1 addition & 0 deletions ProcessHacker/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ PH_STARTUP_PARAMETERS PhStartupParameters;

PH_PROVIDER_THREAD PhPrimaryProviderThread;
PH_PROVIDER_THREAD PhSecondaryProviderThread;
PH_PROVIDER_THREAD PhTertiaryProviderThread;

static PPH_LIST DialogList = NULL;
static PPH_LIST FilterList = NULL;
Expand Down
5 changes: 4 additions & 1 deletion ProcessHacker/mainwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,18 @@ VOID PhMwpInitializeProviders(

PhInitializeProviderThread(&PhPrimaryProviderThread, PhCsUpdateInterval);
PhInitializeProviderThread(&PhSecondaryProviderThread, PhCsUpdateInterval);
PhInitializeProviderThread(&PhTertiaryProviderThread, PhCsUpdateInterval);

PhRegisterProvider(&PhPrimaryProviderThread, PhProcessProviderUpdate, NULL, &PhMwpProcessProviderRegistration);
PhRegisterProvider(&PhPrimaryProviderThread, PhServiceProviderUpdate, NULL, &PhMwpServiceProviderRegistration);
PhRegisterProvider(&PhSecondaryProviderThread, PhServiceProviderUpdate, NULL, &PhMwpServiceProviderRegistration);
PhRegisterProvider(&PhPrimaryProviderThread, PhNetworkProviderUpdate, NULL, &PhMwpNetworkProviderRegistration);

PhSetEnabledProvider(&PhMwpProcessProviderRegistration, TRUE);
PhSetEnabledProvider(&PhMwpServiceProviderRegistration, TRUE);

PhStartProviderThread(&PhPrimaryProviderThread);
PhStartProviderThread(&PhSecondaryProviderThread);
PhStartProviderThread(&PhTertiaryProviderThread);
}

VOID PhMwpApplyUpdateInterval(
Expand All @@ -400,6 +402,7 @@ VOID PhMwpApplyUpdateInterval(
{
PhSetIntervalProviderThread(&PhPrimaryProviderThread, Interval);
PhSetIntervalProviderThread(&PhSecondaryProviderThread, Interval);
PhSetIntervalProviderThread(&PhTertiaryProviderThread, Interval);
}

VOID PhMwpInitializeControls(
Expand Down
2 changes: 1 addition & 1 deletion ProcessHacker/prpghndl.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ INT_PTR CALLBACK PhpProcessHandlesDlgProc(
processItem->ProcessId
);
PhRegisterProvider(
&PhSecondaryProviderThread,
&PhTertiaryProviderThread,
PhHandleProviderUpdate,
handlesContext->Provider,
&handlesContext->ProviderRegistration
Expand Down
2 changes: 1 addition & 1 deletion ProcessHacker/prpgmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ INT_PTR CALLBACK PhpProcessModulesDlgProc(
processItem->ProcessId
);
PhRegisterProvider(
&PhSecondaryProviderThread,
&PhTertiaryProviderThread,
PhModuleProviderUpdate,
modulesContext->Provider,
&modulesContext->ProviderRegistration
Expand Down
1 change: 0 additions & 1 deletion phlib/include/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ typedef struct _PH_PROVIDER_THREAD
{
HANDLE ThreadHandle;
HANDLE TimerHandle;
HANDLE EventHandle;
ULONG Interval;
PH_PROVIDER_THREAD_STATE State;

Expand Down
44 changes: 13 additions & 31 deletions phlib/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* provider system
*
* Copyright (C) 2009-2016 wj32
* Copyright (C) 2021 dmex
*
* This file is part of Process Hacker.
*
Expand Down Expand Up @@ -39,11 +38,6 @@
* 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>

Expand All @@ -65,7 +59,6 @@ VOID PhInitializeProviderThread(
{
ProviderThread->ThreadHandle = NULL;
ProviderThread->TimerHandle = NULL;
ProviderThread->EventHandle = NULL;
ProviderThread->Interval = Interval;
ProviderThread->State = ProviderThreadStopped;

Expand Down Expand Up @@ -98,7 +91,7 @@ VOID PhDeleteProviderThread(

#ifdef DEBUG
PhAcquireQueuedLockExclusive(&PhDbgProviderListLock);
if ((index = PhFindItemList(PhDbgProviderList, ProviderThread)) != ULONG_MAX)
if ((index = PhFindItemList(PhDbgProviderList, ProviderThread)) != -1)
PhRemoveItemList(PhDbgProviderList, index);
PhReleaseQueuedLockExclusive(&PhDbgProviderListLock);
#endif
Expand All @@ -116,10 +109,6 @@ 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);

Expand All @@ -139,13 +128,13 @@ NTSTATUS NTAPI PhpProviderThreadStart(

// Main loop.

// 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.
// 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.

while (TRUE)
{
if (status == STATUS_WAIT_1)
if (status == STATUS_ALERTED)
{
// 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
Expand All @@ -165,7 +154,7 @@ NTSTATUS NTAPI PhpProviderThreadStart(
// Add the provider to the temp list.
InsertTailList(&tempListHead, listEntry);

if (status != STATUS_WAIT_1)
if (status != STATUS_ALERTED)
{
if (!registration->Enabled || registration->Unregistering)
continue;
Expand All @@ -185,7 +174,7 @@ NTSTATUS NTAPI PhpProviderThreadStart(
}
}

if (status == STATUS_WAIT_1)
if (status == STATUS_ALERTED)
{
assert(registration->Boosting);
registration->Boosting = FALSE;
Expand Down Expand Up @@ -226,13 +215,11 @@ NTSTATUS NTAPI PhpProviderThreadStart(

PhReleaseQueuedLockExclusive(&providerThread->Lock);

// Perform a wait so we can be woken up by someone telling us to boost providers,
// Perform an alertable wait so we can be woken up by someone telling us to boost providers,
// or to terminate.
status = NtWaitForMultipleObjects(
RTL_NUMBER_OF(objects),
objects,
WaitAny,
FALSE,
status = NtWaitForSingleObject(
providerThread->TimerHandle,
TRUE,
NULL
);
}
Expand All @@ -254,9 +241,6 @@ 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);
Expand All @@ -280,16 +264,14 @@ VOID PhStopProviderThread(

// Signal to the thread that we are shutting down, and wait for it to exit.
ProviderThread->State = ProviderThreadStopping;
NtSetEvent(ProviderThread->EventHandle, NULL); // wake it up
NtAlertThread(ProviderThread->ThreadHandle); // wake it up
NtWaitForSingleObject(ProviderThread->ThreadHandle, FALSE, NULL);

// Free resources.
NtClose(ProviderThread->ThreadHandle);
NtClose(ProviderThread->TimerHandle);
NtClose(ProviderThread->EventHandle);
ProviderThread->ThreadHandle = NULL;
ProviderThread->TimerHandle = NULL;
ProviderThread->EventHandle = NULL;

ProviderThread->State = ProviderThreadStopped;
}
Expand Down Expand Up @@ -436,7 +418,7 @@ BOOLEAN PhBoostProvider(
PhReleaseQueuedLockExclusive(&providerThread->Lock);

// Wake up the thread.
NtSetEvent(providerThread->EventHandle, NULL);
NtAlertThread(providerThread->ThreadHandle);

if (FutureRunId)
*FutureRunId = futureRunId;
Expand Down
6 changes: 1 addition & 5 deletions plugins/NetworkTools/country.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ PPH_STRING NetToolsGetGeoLiteDbPath(
PhDereferenceObject(directory);
}

if (PhDoesFileExistsWin32(PhGetString(fileName)))
{
return fileName;
}
return fileName;
}

PhClearReference(&fileName);
Expand All @@ -73,7 +70,6 @@ BOOLEAN NetToolsGeoLiteInitialized(
)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static BOOLEAN initialized = FALSE;

if (PhBeginInitOnce(&initOnce))
{
Expand Down

0 comments on commit 0827d2b

Please sign in to comment.