Bewerken

Delen via


ZwSetInformationThread function (ntddk.h)

The ZwSetInformationThread routine sets the priority of a thread.

Syntax

NTSYSAPI NTSTATUS ZwSetInformationThread(
  [in] HANDLE          ThreadHandle,
  [in] THREADINFOCLASS ThreadInformationClass,
  [in] PVOID           ThreadInformation,
  [in] ULONG           ThreadInformationLength
);

Parameters

[in] ThreadHandle

Handle to the thread object. To create a new thread and get a handle to it, call PsCreateSystemThread. To specify the current thread, use the ZwCurrentThread macro.

[in] ThreadInformationClass

One of the system-defined values in the THREADINFOCLASS enumeration (see ntddk.h), ThreadPriority, ThreadBasePriority, ThreadPagePriority, or ThreadPowerThrottlingState.

[in] ThreadInformation

Pointer to a variable that specifies the information to set.

If ThreadInformationClass is ThreadPriority, this value must be > LOW_PRIORITY and <= HIGH_PRIORITY.

If ThreadInformationClass is ThreadBasePriority, this value must fall within the system's valid base-priority range and the original priority class for the given thread. That is, if a thread's priority class is variable, that thread's base priority cannot be reset to a real-time priority value, and vice versa.

If ThreadInformationClass is ThreadPagePriority, this value is a pointer to a PAGE_PRIORITY_INFORMATION structure, see ntddk.h. The PagePriority member value must be one of these values.

If ThreadInformationClass is ThreadPowerThrottlingState, this value is a pointer to a POWER_THROTTLING_THREAD_STATE structure, see ntddk.h. The PagePriority member value must be one of these values.

Value Meaning
MEMORY_PRIORITY_VERY_LOW Very low memory priority.
MEMORY_PRIORITY_LOW Low memory priority.
MEMORY_PRIORITY_MEDIUM Medium memory priority.
MEMORY_PRIORITY_BELOW_NORMAL Below normal memory priority.
MEMORY_PRIORITY_NORMAL Normal memory priority. This is the default priority for all threads and processes on the system.

[in] ThreadInformationLength

The size, in bytes, of ThreadInformation.

Return value

ZwSetInformationThread returns STATUS_SUCCESS on success, or the appropriate NTSTATUS error code on failure. Possible error codes include STATUS_INFO_LENGTH_MISMATCH or STATUS_INVALID_PARAMETER.

Remarks

ZwSetInformationThread can be called by higher-level drivers to set the priority of a thread for which they have a handle.

The caller must have THREAD_SET_INFORMATION access rights for the given thread in order to call this routine.

Usually, device and intermediate drivers that set up driver-created threads call KeSetBasePriorityThread or KeSetPriorityThread from their driver-created threads, rather than calling ZwSetInformationThread. However, a driver can call ZwSetInformationThread to raise the priority of a driver-created thread before that thread runs.

Kernel mode drivers can call the ZwSetInformationThread function with ThreadPagePriority to specify a thread's page priority.

To help improve system performance, drivers should use the function with ThreadPagePriority to lower the page priority of threads that perform background operations or access files and data that are not expected to be accessed again soon. For example, an anti-malware application might lower the priority of threads involved in scanning files.

To determine the page priority for a thread, call ZwQueryInformationThread.

If the call to this function occurs in user mode, you should use the name NtSetInformationThread instead of ZwSetInformationThread.

For calls from kernel-mode drivers, the NtXxx and ZwXxx versions of a Windows Native System Services routine can behave differently in the way that they handle and interpret input parameters. For more information about the relationship between the NtXxx and ZwXxx versions of a routine, see Using Nt and Zw Versions of the Native System Services Routines.

Requirements

Requirement Value
Target Platform Universal
Header ntddk.h (include Ntddk.h, Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL PASSIVE_LEVEL
DDI compliance rules HwStorPortProhibitedDDIs(storport), PowerIrpDDis(wdm)

See also

KeSetBasePriorityThread

KeSetPriorityThread

PsCreateSystemThread

Using Nt and Zw Versions of the Native System Services Routines