UserNotes: Fix saved priority getting set multiple times for saved processes
@@ -209,7 +209,7 @@ IO_PRIORITY_HINT GetProcessIoPriority(
)
{
HANDLE processHandle;
- IO_PRIORITY_HINT ioPriority = -1;
+ IO_PRIORITY_HINT ioPriority = ULONG_MAX;
if (NT_SUCCESS(PhOpenProcess(
&processHandle,
@@ -222,7 +222,7 @@ IO_PRIORITY_HINT GetProcessIoPriority(
&ioPriority
)))
{
- ioPriority = -1;
+ ioPriority = ULONG_MAX;
}
NtClose(processHandle);
@@ -406,8 +406,14 @@ VOID NTAPI MenuItemCallback(
}
else
{
+ IO_PRIORITY_HINT ioPriority;
+
object = CreateDbObject(FILE_TAG, &processItem->ProcessName->sr, NULL);
- object->IoPriorityPlusOne = GetProcessIoPriority(processItem->ProcessId) + 1;
+
+ if ((ioPriority = GetProcessIoPriority(processItem->ProcessId)) != ULONG_MAX)
+ {
+ object->IoPriorityPlusOne = ioPriority + 1;
+ }
}
UnlockDb();
@@ -427,8 +433,14 @@ VOID NTAPI MenuItemCallback(
}
else
{
+ IO_PRIORITY_HINT ioPriority;
+
object = CreateDbObject(COMMAND_LINE_TAG, &processItem->CommandLine->sr, NULL);
- object->IoPriorityPlusOne = GetProcessIoPriority(processItem->ProcessId) + 1;
+
+ if ((ioPriority = GetProcessIoPriority(processItem->ProcessId)) != ULONG_MAX)
+ {
+ object->IoPriorityPlusOne = ioPriority + 1;
+ }
}
UnlockDb();
@@ -1209,6 +1221,12 @@ VOID ProcessesUpdatedCallback(
if (object = FindDbObjectForProcess(processItem, INTENT_PROCESS_IO_PRIORITY))
{
if (object->IoPriorityPlusOne != 0)
+ {
+ IO_PRIORITY_HINT ioPriority;
+
+ ioPriority = GetProcessIoPriority(processItem->ProcessId);
+
+ if (ioPriority != ULONG_MAX && ioPriority != object->IoPriorityPlusOne - 1)
{
HANDLE processHandle;
@@ -1223,13 +1241,19 @@ VOID ProcessesUpdatedCallback(
}
}
}
+ }
if (object = FindDbObjectForProcess(processItem, INTENT_PROCESS_AFFINITY))
{
if (object->AffinityMask != 0)
{
+ ULONG_PTR affinityMask;
HANDLE processHandle;
+ if (NT_SUCCESS(GetProcessAffinity(processItem->ProcessId, &affinityMask)))
+ {
+ if (affinityMask != object->AffinityMask)
+ {
if (NT_SUCCESS(PhOpenProcess(
&processHandle,
PROCESS_SET_INFORMATION,
@@ -1241,6 +1265,8 @@ VOID ProcessesUpdatedCallback(
}
}
}
+ }
+ }
listEntry = listEntry->Flink;
}
