5f9f7b5409
Add process memory priority foundation Introduce backend support for process memory priority using Windows GetProcessInformation and SetProcessInformation while keeping the feature testable and safe. - Add ProcessMemoryPriority model with documented Windows memory priority levels - Add fakeable native API wrapper for process memory priority - Add ProcessMemoryPriorityService with safe error handling - Add ProcessOperationResult for process operation outcomes - Extend persistent process rules with memory priority support - Apply memory priority through PersistentRulesEngine when configured - Preserve anti-cheat/protected-process safety messaging - Add tests for native get/set, invalid process, access denied, unsupported API, enum mapping, persistent rules and JSON roundtrip No UI redesign, registry/IFEO persistence, Windows Service, preset generator, migration, version or tag changes.
89 lines
2.8 KiB
C#
89 lines
2.8 KiB
C#
/*
|
|
* ThreadPilot - Windows process memory priority native API abstraction.
|
|
*/
|
|
namespace ThreadPilot.Platforms.Windows
|
|
{
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
public interface IProcessMemoryPriorityNativeApi
|
|
{
|
|
bool IsSupported { get; }
|
|
|
|
SafeProcessHandle OpenProcess(ProcessAccessFlags access, bool inheritHandle, uint processId);
|
|
|
|
bool GetProcessInformation(
|
|
SafeProcessHandle process,
|
|
ProcessInformationClass processInformationClass,
|
|
ref MemoryPriorityInformation processInformation,
|
|
uint processInformationSize);
|
|
|
|
bool SetProcessInformation(
|
|
SafeProcessHandle process,
|
|
ProcessInformationClass processInformationClass,
|
|
ref MemoryPriorityInformation processInformation,
|
|
uint processInformationSize);
|
|
|
|
int GetLastWin32Error();
|
|
}
|
|
|
|
public sealed class ProcessMemoryPriorityNativeApi : IProcessMemoryPriorityNativeApi
|
|
{
|
|
public static ProcessMemoryPriorityNativeApi Instance { get; } = new();
|
|
|
|
private ProcessMemoryPriorityNativeApi()
|
|
{
|
|
}
|
|
|
|
public bool IsSupported => OperatingSystem.IsWindowsVersionAtLeast(6, 2);
|
|
|
|
public SafeProcessHandle OpenProcess(ProcessAccessFlags access, bool inheritHandle, uint processId)
|
|
{
|
|
return ProcessMemoryPriorityNativeMethods.OpenProcess(access, inheritHandle, processId);
|
|
}
|
|
|
|
public bool GetProcessInformation(
|
|
SafeProcessHandle process,
|
|
ProcessInformationClass processInformationClass,
|
|
ref MemoryPriorityInformation processInformation,
|
|
uint processInformationSize)
|
|
{
|
|
return ProcessMemoryPriorityNativeMethods.GetProcessInformation(
|
|
process,
|
|
processInformationClass,
|
|
ref processInformation,
|
|
processInformationSize);
|
|
}
|
|
|
|
public bool SetProcessInformation(
|
|
SafeProcessHandle process,
|
|
ProcessInformationClass processInformationClass,
|
|
ref MemoryPriorityInformation processInformation,
|
|
uint processInformationSize)
|
|
{
|
|
return ProcessMemoryPriorityNativeMethods.SetProcessInformation(
|
|
process,
|
|
processInformationClass,
|
|
ref processInformation,
|
|
processInformationSize);
|
|
}
|
|
|
|
public int GetLastWin32Error()
|
|
{
|
|
return Marshal.GetLastWin32Error();
|
|
}
|
|
}
|
|
|
|
public enum ProcessInformationClass
|
|
{
|
|
ProcessMemoryPriority = 0,
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct MemoryPriorityInformation
|
|
{
|
|
public uint MemoryPriority;
|
|
}
|
|
}
|