Files
reactos/ntoskrnl/include/internal/ps_i.h
Hermès Bélusca-Maïto a4621bb280 [NTOS:PS][NTDLL_APITESTS] Implement ThreadNameInformation for NtQuery/SetInformationThread() (#8484)
The `ThreadNameInformation` (#38) class is the Windows 10.1607+ way
of assigning a human-readable name (i.e. description) to a given
thread object, that is visible to debuggers and diagnostic tools
(e.g. WinDbg `!thread` command, Process Explorer ...), which is
useful for debugging scenarios.[^1]

Before this, the only way to assign a name to a thread for debugging
purposes was to raise a specific exception, that had to be caught and
interpreted by a supported debugger.[^2][^3]

When the thread object is being deleted (`kill.c!PspDeleteThread()`),
free the thread name if set (courtesy of Ahmed Arif, PR #8796).

References:
[^1]: https://learn.microsoft.com/en-us/visualstudio/debugger/tips-for-debugging-threads
[^2]: https://learn.microsoft.com/en-us/archive/blogs/stevejs/naming-threads-in-win32-and-net
[^3]: https://ofekshilon.com/2009/04/10/naming-threads/
2026-03-29 19:35:34 +02:00

642 lines
10 KiB
C

/*
* PROJECT: ReactOS Kernel
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Info Classes for the Process Manager
* COPYRIGHT: Copyright Alex Ionescu <alex.ionescu@reactos.org>
* Copyright Thomas Weidenmueller <w3seek@reactos.org>
* Copyright 2020-2021 George Bișoc <george.bisoc@reactos.org>
*/
#include "icif.h"
//
// Process Information Classes
//
static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
{
/* ProcessBasicInformation */
IQS_SAME
(
PROCESS_BASIC_INFORMATION,
ULONG,
ICIF_QUERY
),
/* ProcessQuotaLimits */
IQS_SAME
(
QUOTA_LIMITS,
ULONG,
/* NOTE: ICIF_SIZE_VARIABLE is for QUOTA_LIMITS_EX support */
ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
),
/* ProcessIoCounters */
IQS_SAME
(
IO_COUNTERS,
ULONG,
ICIF_QUERY
),
/* ProcessVmCounters */
IQS_SAME
(
VM_COUNTERS,
ULONG,
ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
),
/* ProcessTimes */
IQS_SAME
(
KERNEL_USER_TIMES,
ULONG,
ICIF_QUERY
),
/* ProcessBasePriority */
IQS_SAME
(
KPRIORITY,
ULONG,
ICIF_SET
),
/* ProcessRaisePriority */
IQS_SAME
(
ULONG,
ULONG,
ICIF_SET
),
/* ProcessDebugPort */
IQS_SAME
(
HANDLE,
ULONG,
ICIF_QUERY
),
/* ProcessExceptionPort */
IQS_SAME
(
HANDLE,
HANDLE,
ICIF_SET
),
/* ProcessAccessToken */
IQS_SAME
(
PROCESS_ACCESS_TOKEN,
ULONG,
ICIF_SET
),
/* ProcessLdtInformation */
IQS_SAME
(
PROCESS_LDT_INFORMATION,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessLdtSize */
IQS_SAME
(
PROCESS_LDT_SIZE,
ULONG,
ICIF_SET
),
/* ProcessDefaultHardErrorMode */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessIoPortHandlers */
IQS_SAME
(
UCHAR,
ULONG,
ICIF_SET
),
/* ProcessPooledUsageAndLimits */
IQS_SAME
(
POOLED_USAGE_AND_LIMITS,
ULONG,
ICIF_QUERY
),
/* ProcessWorkingSetWatch */
IQS_SAME
(
PROCESS_WS_WATCH_INFORMATION,
ULONG,
ICIF_QUERY | ICIF_SET | ICIF_SET_SIZE_VARIABLE
),
/* ProcessUserModeIOPL is only implemented in x86 */
#if defined (_X86_)
IQS_NO_TYPE_LENGTH
(
ULONG,
ICIF_SET
),
#else
IQS_NONE,
#endif
/* ProcessEnableAlignmentFaultFixup */
IQS
(
BOOLEAN,
ULONG,
BOOLEAN,
CHAR,
ICIF_SET
),
/* ProcessPriorityClass */
IQS
(
PROCESS_PRIORITY_CLASS,
ULONG,
PROCESS_PRIORITY_CLASS,
CHAR,
ICIF_QUERY | ICIF_SET
),
/* ProcessWx86Information */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessHandleCount */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY
),
/* ProcessAffinityMask */
IQS_SAME
(
KAFFINITY,
KAFFINITY,
ICIF_SET
),
/* ProcessPriorityBoost */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessDeviceMap */
IQS
(
RTL_FIELD_TYPE(PROCESS_DEVICEMAP_INFORMATION, Query),
ULONG,
RTL_FIELD_TYPE(PROCESS_DEVICEMAP_INFORMATION, Set),
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessSessionInformation */
IQS_SAME
(
PROCESS_SESSION_INFORMATION,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessForegroundInformation */
IQS
(
CHAR,
ULONG,
BOOLEAN,
CHAR,
ICIF_SET
),
/* ProcessWow64Information */
IQS_SAME
(
ULONG_PTR,
ULONG,
ICIF_QUERY
),
/* ProcessImageFileName */
IQS_SAME
(
UNICODE_STRING,
ULONG,
ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
),
/* ProcessLUIDDeviceMapsEnabled */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY
),
/* ProcessBreakOnTermination */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessDebugObjectHandle */
IQS_SAME
(
HANDLE,
ULONG,
ICIF_QUERY
),
/* ProcessDebugFlags */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessHandleTracing */
IQS
(
PROCESS_HANDLE_TRACING_QUERY,
ULONG,
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessIoPriority */
IQS_NONE,
/* ProcessExecuteFlags */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ProcessTlsInformation */
IQS_NONE,
/* ProcessCookie */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY
),
/* ProcessImageInformation */
IQS_SAME
(
SECTION_IMAGE_INFORMATION,
ULONG,
ICIF_QUERY
),
/* ProcessCycleTime */
IQS_NONE,
/* ProcessPagePriority */
IQS_NONE,
/* ProcessInstrumentationCallback */
IQS_NONE,
/* ProcessThreadStackAllocation */
IQS_NONE,
/* ProcessWorkingSetWatchEx */
IQS_NONE,
/* ProcessImageFileNameWin32 */
IQS_SAME
(
UNICODE_STRING,
ULONG_PTR,
ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
),
/* ProcessImageFileMapping */
IQS_NONE,
/* ProcessAffinityUpdateMode */
IQS_NONE,
/* ProcessMemoryAllocationMode */
IQS_NONE,
};
//
// Thread Information Classes
//
static const INFORMATION_CLASS_INFO PsThreadInfoClass[] =
{
/* ThreadBasicInformation */
IQS_SAME
(
THREAD_BASIC_INFORMATION,
ULONG,
ICIF_QUERY
),
/* ThreadTimes */
IQS_SAME
(
KERNEL_USER_TIMES,
ULONG,
ICIF_QUERY
),
/* ThreadPriority */
IQS_SAME
(
KPRIORITY,
ULONG,
ICIF_SET
),
/* ThreadBasePriority */
IQS_SAME
(
LONG,
ULONG,
ICIF_SET
),
/* ThreadAffinityMask */
IQS_SAME
(
KAFFINITY,
ULONG,
ICIF_SET
),
/* ThreadImpersonationToken */
IQS_SAME
(
HANDLE,
ULONG,
ICIF_SET
),
/* ThreadDescriptorTableEntry is only implemented in x86 as well as the descriptor entry */
#if defined(_X86_)
IQS_SAME
(
DESCRIPTOR_TABLE_ENTRY,
ULONG,
ICIF_QUERY
),
#else
IQS_NONE,
#endif
/* ThreadEnableAlignmentFaultFixup */
IQS
(
CHAR,
CHAR,
BOOLEAN,
UCHAR,
ICIF_SET
),
/* ThreadEventPair_Reusable */
IQS_NONE,
/* ThreadQuerySetWin32StartAddress */
IQS
(
PVOID,
ULONG,
ULONG_PTR,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ThreadZeroTlsCell */
IQS_SAME
(
ULONG,
ULONG,
ICIF_SET
),
/* ThreadPerformanceCount */
IQS_SAME
(
LARGE_INTEGER,
ULONG,
ICIF_QUERY
),
/* ThreadAmILastThread */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY
),
/* ThreadIdealProcessor */
IQS_SAME
(
ULONG_PTR,
ULONG,
ICIF_SET
),
/* ThreadPriorityBoost */
IQS
(
ULONG,
ULONG,
ULONG_PTR,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ThreadSetTlsArrayAddress */
IQS_SAME
(
PVOID,
ULONG,
ICIF_SET | ICIF_SIZE_VARIABLE
),
/* ThreadIsIoPending */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY
),
/* ThreadHideFromDebugger */
{
#if (NTDDI_VERSION >= NTDDI_VISTA)
sizeof(BOOLEAN), /* Query support only on Vista and above */
#else
0,
#endif
sizeof(ULONG), // UCHAR
0, /* No size for Set */
sizeof(ULONG),
#if (NTDDI_VERSION >= NTDDI_VISTA)
ICIF_QUERY |
#endif
ICIF_SET
},
/* ThreadBreakOnTermination */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY | ICIF_SET
),
/* ThreadSwitchLegacyState */
IQS_SAME
(
ULONG,
ULONG,
ICIF_SET
),
/* ThreadIsTerminated */
IQS_SAME
(
ULONG,
ULONG,
ICIF_QUERY
),
/* ThreadLastSystemCall */
IQS_NONE,
/* ThreadIoPriority */
IQS_NONE,
/* ThreadCycleTime */
IQS_NONE,
/* ThreadPagePriority */
IQS_NONE,
/* ThreadActualBasePriority */
IQS_NONE,
/* ThreadTebInformation */
IQS_NONE,
/* ThreadCSwitchMon */
IQS_NONE,
// TODO: Specify the probing info when implementing these classes (see commit 60aad33ed0 PR #8487)
// and adjust rostests/apitests/ntdll/probelib.c!QuerySetThreadValidator() as necessary.
#if 1
// Windows 7
/* ThreadCSwitchPmu */
IQS_NONE,
/* ThreadWow64Context */
IQS_NONE,
/* ThreadGroupInformation */
IQS_NONE,
/* ThreadUmsInformation */
IQS_NONE,
/* ThreadCounterProfiling */
IQS_NONE,
/* ThreadIdealProcessorEx */
IQS_NONE,
// Windows 8
/* ThreadCpuAccountingInformation */
IQS_NONE,
// Windows 8.1
/* ThreadSuspendCount */
IQS_NONE,
// Windows 10
/* ThreadHeterogeneousCpuPolicy */
IQS_NONE,
/* ThreadContainerId */
IQS_NONE,
/* ThreadNameInformation */
IQS_SAME
(
UNICODE_STRING,
ULONG_PTR,
ICIF_QUERY | ICIF_SET | ICIF_SIZE_VARIABLE
),
/* ThreadSelectedCpuSets */
IQS_NONE,
/* ThreadSystemThreadInformation */
IQS_NONE,
/* ThreadActualGroupAffinity */
IQS_NONE,
/* ThreadDynamicCodePolicyInfo */
IQS_NONE,
/* ThreadExplicitCaseSensitivity */
IQS_NONE,
/* ThreadWorkOnBehalfTicket */
IQS_NONE,
/* ThreadSubsystemInformation */
IQS_NONE,
/* ThreadDbgkWerReportActive */
IQS_NONE,
/* ThreadAttachContainer */
IQS_NONE,
/* ThreadManageWritesToExecutableMemory */
IQS_NONE,
/* ThreadPowerThrottlingState */
IQS_NONE,
/* ThreadWorkloadClass */
IQS_NONE,
/* ThreadCreateStateChange */
IQS_NONE,
/* ThreadApplyStateChange */
IQS_NONE,
/* ThreadStrongerBadHandleChecks */
IQS_NONE,
/* ThreadEffectiveIoPriority */
IQS_NONE,
/* ThreadEffectivePagePriority */
IQS_NONE,
#endif
};