Files
ThreadPilot/Platforms/Windows/IProcessCpuSetHandler.cs
T
Prime Build 9f56303e93 CPU topology v2 phase 7: improve affinity errors and priority guardrails (#13)
Improve affinity errors and priority guardrails

Centralize safe user-facing messages for process affinity, CPU Sets, protected processes, access denied cases, topology errors and priority guardrails.

- Add CpuSetApplyResult detailed path while preserving existing bool CPU Sets APIs
- Use detailed CPU Sets results in the CpuSelection affinity flow
- Centralize affinity/priority messages in ProcessOperationUserMessages
- Improve AccessDenied, anti-cheat/protected, invalid topology, process exited and legacy fallback blocked messages
- Add High priority warning
- Block Realtime priority for direct apply, profile load and registry priority requests
- Audit and log blocked Realtime priority attempts
- Prevent critical status messages from being cleared immediately
- Add tests for affinity messages, CPU Sets detailed failures, priority guardrails and status clearing

No persistent rules engine, registry affinity, preset/profile migration, version or tag changes.
2026-05-20 16:03:34 +02:00

84 lines
4.0 KiB
C#

/*
* ThreadPilot - Advanced Windows Process and Power Plan Manager
* Copyright (C) 2025 Prime Build
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace ThreadPilot.Platforms.Windows
{
using System;
using ThreadPilot.Models;
/// <summary>
/// Interface for handling CPU Set operations on a specific process.
/// </summary>
public interface IProcessCpuSetHandler : IDisposable
{
/// <summary>
/// Gets the process ID this handler manages.
/// </summary>
uint ProcessId { get; }
/// <summary>
/// Gets the executable name.
/// </summary>
string ExecutableName { get; }
/// <summary>
/// Applies a CPU affinity mask to the process using CPU Sets.
/// This legacy path is valid only for single-processor-group systems with up to
/// 64 logical processors. It will be superseded by <see cref="ApplyCpuSelection"/>
/// for topology-aware CPU Set selection.
/// </summary>
/// <param name="affinityMask">The affinity mask where each bit represents a logical processor.</param>
/// <param name="clearMask">If true, clears the CPU Set (allows all cores); if false, applies the mask.</param>
/// <returns>True if the operation succeeded, false otherwise.</returns>
bool ApplyCpuSetMask(long affinityMask, bool clearMask = false);
/// <summary>
/// Applies a CPU affinity mask to the process using CPU Sets and returns detailed failure information.
/// </summary>
/// <param name="affinityMask">The affinity mask where each bit represents a logical processor.</param>
/// <param name="clearMask">If true, clears the CPU Set (allows all cores); if false, applies the mask.</param>
/// <returns>Detailed CPU Set apply result.</returns>
CpuSetApplyResult ApplyCpuSetMaskDetailed(long affinityMask, bool clearMask = false);
/// <summary>
/// Applies a topology-aware CPU selection to the process using CPU Sets.
/// </summary>
/// <param name="selection">The CPU selection to apply. Ignored and allowed to be null when <paramref name="clearSelection"/> is true.</param>
/// <param name="clearSelection">If true, clears the CPU Set selection and ignores <paramref name="selection"/>.</param>
/// <returns>True if the operation succeeded, false otherwise.</returns>
bool ApplyCpuSelection(CpuSelection? selection, bool clearSelection = false);
/// <summary>
/// Applies a topology-aware CPU selection to the process using CPU Sets and returns detailed failure information.
/// </summary>
/// <param name="selection">The CPU selection to apply. Ignored and allowed to be null when <paramref name="clearSelection"/> is true.</param>
/// <param name="clearSelection">If true, clears the CPU Set selection and ignores <paramref name="selection"/>.</param>
/// <returns>Detailed CPU Set apply result.</returns>
CpuSetApplyResult ApplyCpuSelectionDetailed(CpuSelection? selection, bool clearSelection = false);
/// <summary>
/// Gets the average CPU usage for this process.
/// </summary>
/// <returns>CPU usage percentage (0-1 range), or -1 if unavailable.</returns>
double GetAverageCpuUsage();
/// <summary>
/// Gets a value indicating whether checks if the handler has valid handles to the process.
/// </summary>
bool IsValid { get; }
}
}