Improve WsCounters query performance (slightly), Remove unnecessary handles
@@ -822,17 +822,14 @@ static VOID PhpUpdateProcessNodeWsCounters(
if (!(ProcessNode->ValidMask & PHPN_WSCOUNTERS))
{
BOOLEAN success = FALSE;
- HANDLE processHandle;
- if (PH_IS_REAL_PROCESS_ID(ProcessNode->ProcessItem->ProcessId))
- {
- if (NT_SUCCESS(PhOpenProcess(&processHandle, PROCESS_QUERY_INFORMATION, ProcessNode->ProcessItem->ProcessId)))
+ if (
+ PH_IS_REAL_PROCESS_ID(ProcessNode->ProcessItem->ProcessId) &&
+ ProcessNode->ProcessItem->IsHandleValid // PROCESS_QUERY_INFORMATION
+ )
{
- if (NT_SUCCESS(PhGetProcessWsCounters(processHandle, &ProcessNode->WsCounters)))
+ if (NT_SUCCESS(PhGetProcessWsCounters(ProcessNode->ProcessItem->QueryHandle, &ProcessNode->WsCounters)))
success = TRUE;
-
- NtClose(processHandle);
- }
}
if (!success)
@@ -923,26 +920,19 @@ static VOID PhpUpdateProcessNodeDepStatus(
{
if (!(ProcessNode->ValidMask & PHPN_DEPSTATUS))
{
- HANDLE processHandle;
- ULONG depStatus;
-
- depStatus = 0;
+ ULONG depStatus = 0;
#ifdef _WIN64
- if (ProcessNode->ProcessItem->IsWow64)
+ if (
+ PH_IS_REAL_PROCESS_ID(ProcessNode->ProcessItem->ProcessId) &&
+ ProcessNode->ProcessItem->IsWow64 &&
+ ProcessNode->ProcessItem->IsHandleValid // PROCESS_QUERY_INFORMATION
+ )
#else
- if (TRUE)
+ if (PH_IS_REAL_PROCESS_ID(ProcessNode->ProcessItem->ProcessId))
#endif
{
- if (NT_SUCCESS(PhOpenProcess(
- &processHandle,
- PROCESS_QUERY_INFORMATION,
- ProcessNode->ProcessItem->ProcessId
- )))
- {
- PhGetProcessDepStatus(processHandle, &depStatus);
- NtClose(processHandle);
- }
+ PhGetProcessDepStatus(ProcessNode->ProcessItem->QueryHandle, &depStatus);
}
else
{
@@ -1004,7 +994,9 @@ static VOID PhpUpdateProcessOsContext(
{
NOTHING;
}
- else if (NT_SUCCESS(PhOpenProcess(&processHandle, PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, ProcessNode->ProcessId)))
+ else if (PH_IS_REAL_PROCESS_ID(ProcessNode->ProcessItem->ProcessId))
+ {
+ if (NT_SUCCESS(PhOpenProcess(&processHandle, PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, ProcessNode->ProcessId)))
{
if (NT_SUCCESS(PhGetProcessSwitchContext(processHandle, &ProcessNode->OsContextGuid)))
{
@@ -1024,6 +1016,7 @@ static VOID PhpUpdateProcessOsContext(
NtClose(processHandle);
}
+ }
ProcessNode->ValidMask |= PHPN_OSCONTEXT;
}
@@ -1065,7 +1058,7 @@ static VOID PhpUpdateProcessNodeImage(
{
ProcessNode->ImageSubsystem = IMAGE_SUBSYSTEM_POSIX_CUI;
}
- else
+ else if (PH_IS_REAL_PROCESS_ID(ProcessNode->ProcessItem->ProcessId))
{
HANDLE processHandle;
PROCESS_BASIC_INFORMATION basicInfo;
@@ -1270,6 +1263,8 @@ static VOID PhpUpdateProcessNodeDesktopInfo(
PhClearReference(&ProcessNode->DesktopInfoText);
+ if (PH_IS_REAL_PROCESS_ID(ProcessNode->ProcessItem->ProcessId))
+ {
if (NT_SUCCESS(PhOpenProcess(
&processHandle,
PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ,
@@ -1285,6 +1280,7 @@ static VOID PhpUpdateProcessNodeDesktopInfo(
NtClose(processHandle);
}
+ }
ProcessNode->ValidMask |= PHPN_DESKTOPINFO;
}
