48#define MAX_WORKERTHREADS 0x100
49#define WORKERTHREAD_CREATION_THRESHOLD 0x5
78#define IsThreadPoolInitialized() (*((volatile LONG*)&ThreadPoolInitialized) == 1)
128 else if (InitStatus == 2)
136 Timeout.QuadPart = -10000000LL;
140 }
while (InitStatus != 1);
169 volatile LONG WorkerInitialized = 0;
180 while (WorkerInitialized == 0)
223 DPRINT(
"RtlpExecuteWorkItem: Function: 0x%p Context: 0x%p ImpersonationToken: 0x%p\n",
WorkItem.Function,
WorkItem.Context,
WorkItem.TokenHandle);
243 DPRINT1(
"Failed to revert worker thread to self!!! Status: 0x%x\n",
Status);
340 DPRINT(
"RtlpExecuteIoWorkItem: Function: 0x%p Context: 0x%p ImpersonationToken: 0x%p\n",
WorkItem.Function,
WorkItem.Context,
WorkItem.TokenHandle);
360 DPRINT1(
"Failed to revert worker thread to self!!! Status: 0x%x\n",
Status);
370 IoThread->
Flags &= ~WT_EXECUTELONGFUNCTION;
412 CurrentEntry = CurrentEntry->
Flink;
425 DPRINT1(
"Failed to find a worker thread for the persistent IO thread!\n");
451 CurrentEntry = CurrentEntry->
Flink;
459 DPRINT1(
"Failed to find a worker thread for the work item 0x%p!\n",
WorkItem);
473 WorkItem->Flags &= ~WT_EXECUTELONGFUNCTION;
504 DPRINT1(
"Failed to queue APC for work item 0x%p\n",
WorkItem->Function);
524 if (ThreadHandle ==
NULL)
538 CreatedHandle =
TRUE;
584 DPRINT1(
"Failed to create handle to own thread! Status: 0x%x\n",
Status);
609 Timeout.QuadPart = -50000000LL;
632 Timeout.QuadPart = -0x7FFFFFFFFFFFFFFFLL;
666 DPRINT1(
"Failed to acquire the thread pool lock!!! Status: 0x%x\n",
Status);
684 ULONG TimeoutCount = 0;
705 Timeout.QuadPart = -50000000LL;
743 if (TimeoutCount++ > 2 &&
815 DPRINT1(
"Failed to get impersonation token! Status: 0x%x\n",
Status);
935 sizeof(FileCompletionInfo),
#define InterlockedIncrement
#define InterlockedExchange
#define InterlockedDecrement
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
#define NT_SUCCESS(StatCode)
@ ThreadImpersonationToken
static const WCHAR Cleanup[]
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
#define InitializeListHead(ListHead)
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
@ FileCompletionInformation
#define EXCEPTION_EXECUTE_HANDLER
#define InterlockedCompareExchange
NTSTATUS NTAPI NtSetIoCompletion(IN HANDLE IoCompletionPortHandle, IN PVOID CompletionKey, IN PVOID CompletionContext, IN NTSTATUS CompletionStatus, IN ULONG CompletionInformation)
NTSTATUS NTAPI NtRemoveIoCompletion(IN HANDLE IoCompletionHandle, OUT PVOID *KeyContext, OUT PVOID *ApcContext, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER Timeout OPTIONAL)
NTSTATUS NTAPI NtCreateIoCompletion(OUT PHANDLE IoCompletionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG NumberOfConcurrentThreads)
struct _ThreadInfo ThreadInfo
#define IO_COMPLETION_ALL_ACCESS
static OUT PIO_STATUS_BLOCK IoStatusBlock
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlCreateUserThread(_In_ PVOID ThreadContext, _Out_ HANDLE *OutThreadHandle, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3, _Reserved_ PVOID Reserved4, _Reserved_ PVOID Reserved5, _Reserved_ PVOID Reserved6, _Reserved_ PVOID Reserved7, _Reserved_ PVOID Reserved8)
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSTATUS(NTAPI * PRTL_START_POOL_THREAD)(_In_ PTHREAD_START_ROUTINE Function, _In_ PVOID Parameter, _Out_ PHANDLE ThreadHandle)
NTSTATUS(NTAPI * PRTL_EXIT_POOL_THREAD)(_In_ NTSTATUS ExitStatus)
ULONG(NTAPI * PTHREAD_START_ROUTINE)(PVOID Parameter)
VOID(NTAPI * WORKERCALLBACKFUNC)(_In_ PVOID Context)
NTSTATUS NtTerminateThread(IN HANDLE ThreadHandle OPTIONAL, IN NTSTATUS ExitStatus)
#define NtCurrentProcess()
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
NTSTATUS NTAPI NtDelayExecution(IN BOOLEAN Alertable, IN PLARGE_INTEGER DelayInterval)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
VOID(* PIO_APC_ROUTINE)(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved)
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
NTSTATUS NTAPI NtQueueApcThread(IN HANDLE ThreadHandle, IN PKNORMAL_ROUTINE ApcRoutine, IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
NTSTATUS NTAPI NtOpenThreadToken(_In_ HANDLE ThreadHandle, _In_ ACCESS_MASK DesiredAccess, _In_ BOOLEAN OpenAsSelf, _Out_ PHANDLE TokenHandle)
Opens a token that is tied to a thread handle.
#define STATUS_CANT_OPEN_ANONYMOUS
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
#define _SEH2_GetExceptionCode()
#define _SEH2_EXCEPT(...)
#define WT_EXECUTEINPERSISTENTIOTHREAD
NTSTATUS RtlpInitializeTimerThread(VOID)
static NTSTATUS RtlpInitializeThreadPool(VOID)
static NTSTATUS RtlpGetImpersonationToken(OUT PHANDLE TokenHandle)
#define WORKERTHREAD_CREATION_THRESHOLD
static HANDLE ThreadPoolCompletionPort
static LONG ThreadPoolWorkerThreads
struct _RTLP_IOWORKERTHREAD * PRTLP_IOWORKERTHREAD
static LONG ThreadPoolWorkerThreadsLongRequests
NTSTATUS NTAPI RtlQueueWorkItem(IN WORKERCALLBACKFUNC Function, IN PVOID Context OPTIONAL, IN ULONG Flags)
#define MAX_WORKERTHREADS
static BOOLEAN RtlpIsIoPending(IN HANDLE ThreadHandle OPTIONAL)
static ULONG NTAPI RtlpWorkerThreadProc(IN PVOID Parameter)
static LIST_ENTRY ThreadPoolIOWorkerThreadsList
NTSTATUS NTAPI RtlSetThreadPoolStartFunc(IN PRTL_START_POOL_THREAD StartPoolThread, IN PRTL_EXIT_POOL_THREAD ExitPoolThread)
struct _RTLP_WORKITEM * PRTLP_WORKITEM
static PRTLP_IOWORKERTHREAD PersistentIoThread
NTSTATUS NTAPI RtlSetIoCompletionCallback(IN HANDLE FileHandle, IN PIO_APC_ROUTINE Callback, IN ULONG Flags)
static LONG ThreadPoolIOWorkerThreadsLongRequests
#define IsThreadPoolInitialized()
static ULONG NTAPI RtlpIoWorkerThreadProc(IN PVOID Parameter)
NTSTATUS NTAPI RtlpStartThread(IN PTHREAD_START_ROUTINE Function, IN PVOID Parameter, OUT PHANDLE ThreadHandle)
static NTSTATUS RtlpStartWorkerThread(PTHREAD_START_ROUTINE StartRoutine)
static LONG ThreadPoolInitialized
struct _RTLP_WORKITEM RTLP_WORKITEM
static LONG ThreadPoolWorkerThreadsRequests
static RTL_CRITICAL_SECTION ThreadPoolLock
static NTSTATUS RtlpQueueIoWorkerThread(IN OUT PRTLP_WORKITEM WorkItem)
PRTL_EXIT_POOL_THREAD RtlpExitThreadFunc
static VOID NTAPI RtlpExecuteIoWorkItem(IN OUT PVOID NormalContext, IN OUT PVOID SystemArgument1, IN OUT PVOID SystemArgument2)
struct _RTLP_IOWORKERTHREAD RTLP_IOWORKERTHREAD
static VOID NTAPI RtlpExecuteWorkItem(IN OUT PVOID NormalContext, IN OUT PVOID SystemArgument1, IN OUT PVOID SystemArgument2)
static NTSTATUS RtlpQueueWorkerThread(IN OUT PRTLP_WORKITEM WorkItem)
PRTL_START_POOL_THREAD RtlpStartThreadFunc
static LONG ThreadPoolIOWorkerThreads
NTSTATUS NTAPI RtlpExitThread(IN NTSTATUS ExitStatus)
static LONG ThreadPoolIOWorkerThreadsRequests
PULONG MinorVersion OPTIONAL
struct _LIST_ENTRY * Flink
WORKERCALLBACKFUNC Function
#define CONTAINING_RECORD(address, type, field)
_In_ WDFDPC _In_ BOOLEAN Wait
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
#define WT_TRANSFER_IMPERSONATION
#define WT_EXECUTEINPERSISTENTTHREAD
#define WT_EXECUTEINIOTHREAD
#define WT_EXECUTELONGFUNCTION
#define WT_EXECUTEINUITHREAD
_Must_inspect_result_ _In_ ULONG Flags
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
#define DUPLICATE_SAME_ACCESS
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
_Inout_opt_ PVOID Parameter
#define TOKEN_IMPERSONATE
#define NtCurrentThread()