Repository navigation
Expand file tree
/
Copy pathCpuSetNativeMethods.cs
More file actions
83 lines (73 loc) · 3.05 KB
/
Copy pathCpuSetNativeMethods.cs
File metadata and controls
83 lines (73 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* 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_SET_INFORMATION = 0x00000200,
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,
}
}