83 lines
3.0 KiB
C#
83 lines
3.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 System.Runtime.InteropServices;
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
/// <summary>
|
|
/// P/Invoke declarations for Windows CPU Set APIs.
|
|
/// </summary>
|
|
internal static partial class CpuSetNativeMethods
|
|
{
|
|
[LibraryImport("kernel32.dll", SetLastError = true)]
|
|
public static partial SafeProcessHandle OpenProcess(ProcessAccessFlags access, [MarshalAs(UnmanagedType.Bool)] bool inheritHandle, uint processId);
|
|
|
|
[LibraryImport("kernel32.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static partial bool GetSystemCpuSetInformation(IntPtr Information, uint BufferLength, ref uint ReturnedLength, SafeProcessHandle Process, uint Flags);
|
|
|
|
[LibraryImport("kernel32.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static partial bool SetProcessDefaultCpuSets(SafeProcessHandle Process, uint[]? CpuSetIds, uint CpuSetIdCount);
|
|
|
|
[LibraryImport("kernel32.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static partial bool GetProcessTimes(SafeProcessHandle hProcess, out FILETIME lpCreationTime, out FILETIME lpExitTime, out FILETIME lpKernelTime, out FILETIME lpUserTime);
|
|
}
|
|
|
|
[Flags]
|
|
public enum ProcessAccessFlags : uint
|
|
{
|
|
PROCESS_QUERY_LIMITED_INFORMATION = 0x00001000,
|
|
PROCESS_SET_LIMITED_INFORMATION = 0x00002000,
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct FILETIME
|
|
{
|
|
public uint DwLowDateTime;
|
|
public uint DwHighDateTime;
|
|
|
|
public readonly ulong ULong => (((ulong)this.DwHighDateTime) << 32) + this.DwLowDateTime;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct SYSTEM_CPU_SET_INFORMATION
|
|
{
|
|
public uint Size;
|
|
public CPU_SET_INFORMATION_TYPE Type;
|
|
public uint Id;
|
|
public ushort Group;
|
|
public byte LogicalProcessorIndex;
|
|
public byte CoreIndex;
|
|
public byte LastLevelCacheIndex;
|
|
public byte NumaNodeIndex;
|
|
public byte EfficiencyClass;
|
|
public byte AllFlags;
|
|
public uint Reserved;
|
|
public ulong AllocationTag;
|
|
}
|
|
|
|
public enum CPU_SET_INFORMATION_TYPE : int
|
|
{
|
|
CpuSetInformation = 0,
|
|
}
|
|
}
|
|
|