-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathnttp.h
More file actions
861 lines (806 loc) · 27.4 KB
/
nttp.h
File metadata and controls
861 lines (806 loc) · 27.4 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
/*
* Thread Pool support functions
*
* This file is part of System Informer.
*/
#ifndef _NTTP_H
#define _NTTP_H
// Some types are already defined in winnt.h.
typedef struct _TP_ALPC TP_ALPC, *PTP_ALPC;
// private
/**
* Defines the callback function for ALPC completion notifications.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in,out] Context Optional application-defined data specified when the ALPC completion object was created.
* \param[in] Alpc A pointer to the ALPC completion object.
*/
typedef _Function_class_(TP_ALPC_CALLBACK)
VOID NTAPI TP_ALPC_CALLBACK(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_Inout_opt_ PVOID Context,
_In_ PTP_ALPC Alpc
);
typedef TP_ALPC_CALLBACK *PTP_ALPC_CALLBACK;
// rev
/**
* Defines the extended callback function for ALPC completion notifications.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in,out] Context Optional application-defined data specified when the ALPC completion object was created.
* \param[in] Alpc A pointer to the ALPC completion object.
* \param[in] ApcContext A pointer to additional APC context data for the completion callback.
*/
typedef _Function_class_(TP_ALPC_CALLBACK_EX)
VOID NTAPI TP_ALPC_CALLBACK_EX(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_Inout_opt_ PVOID Context,
_In_ PTP_ALPC Alpc,
_In_ PVOID ApcContext
);
typedef TP_ALPC_CALLBACK_EX *PTP_ALPC_CALLBACK_EX;
// winbase:CreateThreadpool
/**
* Allocates a new pool of threads to execute callbacks.
*
* \param[out] PoolReturn Pointer to a variable that receives the address of the newly allocated thread pool.
* \param[in] Reserved Reserved for future use. Must be NULL.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-createthreadpool
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocPool(
_Out_ PTP_POOL *PoolReturn,
_Reserved_ PVOID Reserved
);
// winbase:CloseThreadpool
/**
* Closes the specified thread pool.
*
* \param[in,out] Pool A pointer to a TP_POOL structure that defines the thread pool.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpool
*/
NTSYSAPI
VOID
NTAPI
TpReleasePool(
_Inout_ PTP_POOL Pool
);
// winbase:SetThreadpoolThreadMaximum
/**
* Sets the maximum number of threads that the specified thread pool can allocate to process callbacks.
*
* \param[in,out] Pool A pointer to a TP_POOL structure that defines the thread pool.
* \param[in] MaxThreads The maximum number of threads.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpoolthreadmaximum
*/
NTSYSAPI
VOID
NTAPI
TpSetPoolMaxThreads(
_Inout_ PTP_POOL Pool,
_In_ ULONG MaxThreads
);
// winbase:SetThreadpoolThreadMinimum
/**
* Sets the minimum number of threads that the specified thread pool must make available to process callbacks.
*
* \param[in,out] Pool A pointer to a TP_POOL structure that defines the thread pool.
* \param[in] MinThreads The minimum number of threads.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpoolthreadminimum
*/
NTSYSAPI
NTSTATUS
NTAPI
TpSetPoolMinThreads(
_Inout_ PTP_POOL Pool,
_In_ ULONG MinThreads
);
// winbase:QueryThreadpoolStackInformation
/**
* Retrieves the stack reserve and commit sizes for threads in the specified thread pool.
*
* \param[in] Pool A pointer to a TP_POOL structure that defines the thread pool.
* \param[out] PoolStackInformation A pointer to a TP_POOL_STACK_INFORMATION structure that receives the stack reserve and commit size.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-querythreadpoolstackinformation
*/
NTSYSAPI
NTSTATUS
NTAPI
TpQueryPoolStackInformation(
_In_ PTP_POOL Pool,
_Out_ PTP_POOL_STACK_INFORMATION PoolStackInformation
);
// winbase:SetThreadpoolStackInformation
/**
* Sets the stack reserve and commit sizes for threads in the specified thread pool.
*
* \param[in,out] Pool A pointer to a TP_POOL structure that defines the thread pool.
* \param[in] PoolStackInformation A pointer to a TP_POOL_STACK_INFORMATION structure that specifies stack reserve and commit sizes.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpoolstackinformation
*/
NTSYSAPI
NTSTATUS
NTAPI
TpSetPoolStackInformation(
_Inout_ PTP_POOL Pool,
_In_ PTP_POOL_STACK_INFORMATION PoolStackInformation
);
// rev
/**
* Sets the base priority for worker threads in the specified thread pool.
*
* \param[in,out] Pool A pointer to a TP_POOL structure that defines the thread pool.
* \param[in] BasePriority The new base priority value for worker threads.
* \return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
TpSetPoolThreadBasePriority(
_Inout_ PTP_POOL Pool,
_In_ ULONG BasePriority
);
// winbase:CreateThreadpoolCleanupGroup
/**
* Creates a cleanup group that applications can use to track one or more thread pool callbacks.
*
* \param[out] CleanupGroup A pointer to a TP_CLEANUP_GROUP structure of the newly allocated cleanup group.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-createthreadpoolcleanupgroup
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocCleanupGroup(
_Out_ PTP_CLEANUP_GROUP *CleanupGroup
);
// winbase:CloseThreadpoolCleanupGroup
/**
* Closes the specified cleanup group.
*
* \param[in,out] CleanupGroup A pointer to a TP_CLEANUP_GROUP structure that defines the cleanup group.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpoolcleanupgroup
*/
NTSYSAPI
VOID
NTAPI
TpReleaseCleanupGroup(
_Inout_ PTP_CLEANUP_GROUP CleanupGroup
);
// winbase:CloseThreadpoolCleanupGroupMembers
/**
* Releases the members of the specified cleanup group.
*
* \param[in,out] CleanupGroup A pointer to a TP_CLEANUP_GROUP structure that defines the cleanup group.
* \param[in] CancelPendingCallbacks If TRUE, pending callbacks that have not started are canceled.
* \param[in,out] CleanupParameter Optional application-defined context to pass to cleanup callbacks.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpoolcleanupgroupmembers
*/
NTSYSAPI
VOID
NTAPI
TpReleaseCleanupGroupMembers(
_Inout_ PTP_CLEANUP_GROUP CleanupGroup,
_In_ LOGICAL CancelPendingCallbacks,
_Inout_opt_ PVOID CleanupParameter
);
// winbase:SetEventWhenCallbackReturns
/**
* Sets an event object when the current callback function returns.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in] Event A handle to an event object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-seteventwhencallbackreturns
*/
NTSYSAPI
VOID
NTAPI
TpCallbackSetEventOnCompletion(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_In_ HANDLE Event
);
// winbase:ReleaseSemaphoreWhenCallbackReturns
/**
* Releases a semaphore when the current callback function returns.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in] Semaphore A handle to a semaphore object.
* \param[in] ReleaseCount The amount by which to increment the semaphore's current count.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-releasesemaphorewhencallbackreturns
*/
NTSYSAPI
VOID
NTAPI
TpCallbackReleaseSemaphoreOnCompletion(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_In_ HANDLE Semaphore,
_In_ ULONG ReleaseCount
);
// winbase:ReleaseMutexWhenCallbackReturns
/**
* Releases a mutex when the current callback function returns.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in] Mutex A handle to a mutex object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-releasemutexwhencallbackreturns
*/
NTSYSAPI
VOID
NTAPI
TpCallbackReleaseMutexOnCompletion(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_In_ HANDLE Mutex
);
// winbase:LeaveCriticalSectionWhenCallbackReturns
/**
* Leaves a critical section when the current callback function returns.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in,out] CriticalSection A pointer to a critical section object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-leavecriticalsectionwhencallbackreturns
*/
NTSYSAPI
VOID
NTAPI
TpCallbackLeaveCriticalSectionOnCompletion(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_Inout_ PRTL_CRITICAL_SECTION CriticalSection
);
// winbase:FreeLibraryWhenCallbackReturns
/**
* Frees the specified DLL when the current callback function returns.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in] DllHandle A module handle for the DLL to unload.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-freelibrarywhencallbackreturns
*/
NTSYSAPI
VOID
NTAPI
TpCallbackUnloadDllOnCompletion(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_In_ PVOID DllHandle
);
// winbase:CallbackMayRunLong
/**
* Indicates that the callback may not return quickly.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-callbackmayrunlong
*/
NTSYSAPI
NTSTATUS
NTAPI
TpCallbackMayRunLong(
_Inout_ PTP_CALLBACK_INSTANCE Instance
);
// winbase:DisassociateCurrentThreadFromCallback
/**
* Removes the association between the current thread and the callback instance.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-disassociatecurrentthreadfromcallback
*/
NTSYSAPI
VOID
NTAPI
TpDisassociateCallback(
_Inout_ PTP_CALLBACK_INSTANCE Instance
);
/**
* Defines the callback function that is executed by a thread pool worker thread.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in,out] Context Optional application-defined data passed to the callback.
* \return None.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nc-threadpoolapiset-ptp_simple_callback
*/
typedef _Function_class_(TP_CALLBACK_ROUTINE)
VOID NTAPI TP_CALLBACK_ROUTINE(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_Inout_opt_ PVOID Context
);
typedef TP_CALLBACK_ROUTINE* PTP_CALLBACK_ROUTINE;
// winbase:TrySubmitThreadpoolCallback
/**
* Requests that a thread pool worker thread call the specified callback function.
*
* \param[in] Callback The callback function.
* \param[in,out] Context Optional application-defined data to pass to the callback function.
* \param[in] CallbackEnviron A pointer to a TP_CALLBACK_ENVIRON structure that defines the environment in which to execute the callback function.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-trysubmitthreadpoolcallback
*/
NTSYSAPI
NTSTATUS
NTAPI
TpSimpleTryPost(
_In_ PTP_CALLBACK_ROUTINE Callback,
_Inout_opt_ PVOID Context,
_In_opt_ PTP_CALLBACK_ENVIRON CallbackEnviron
);
// winbase:CreateThreadpoolWork
/**
* Allocates a work object.
*
* \param[out] WorkReturn A pointer to a variable that receives the new work object.
* \param[in] Callback The callback function to execute.
* \param[in,out] Context Optional application-defined data to pass to the callback function.
* \param[in] CallbackEnviron Optional callback environment for the callback.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-createthreadpoolwork
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocWork(
_Out_ PTP_WORK *WorkReturn,
_In_ PTP_WORK_CALLBACK Callback,
_Inout_opt_ PVOID Context,
_In_opt_ PTP_CALLBACK_ENVIRON CallbackEnviron
);
// winbase:CloseThreadpoolWork
/**
* Closes the specified work object.
*
* \param[in,out] Work A pointer to a TP_WORK structure that defines the work object.
* \return None.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpoolwork
*/
NTSYSAPI
VOID
NTAPI
TpReleaseWork(
_Inout_ PTP_WORK Work
);
// winbase:SubmitThreadpoolWork
/**
* Submits a work object to the thread pool.
*
* \param[in,out] Work A pointer to a TP_WORK structure that defines the work object.
* \return None.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-submitthreadpoolwork
*/
NTSYSAPI
VOID
NTAPI
TpPostWork(
_Inout_ PTP_WORK Work
);
// winbase:WaitForThreadpoolWorkCallbacks
/**
* Waits for outstanding work callbacks to complete and optionally cancels pending callbacks.
*
* \param[in,out] Work A pointer to a TP_WORK structure that defines the work object.
* \param[in] CancelPendingCallbacks If TRUE, pending callbacks that have not started are canceled.
* \return None.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-waitforthreadpoolworkcallbacks
*/
NTSYSAPI
VOID
NTAPI
TpWaitForWork(
_Inout_ PTP_WORK Work,
_In_ LOGICAL CancelPendingCallbacks
);
// winbase:CreateThreadpoolTimer
/**
* Allocates a timer object.
*
* \param[out] Timer A pointer to a variable that receives the new timer object.
* \param[in] Callback The callback function to execute when the timer expires.
* \param[in,out] Context Optional application-defined data to pass to the callback function.
* \param[in] CallbackEnviron Optional callback environment for the callback.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-createthreadpooltimer
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocTimer(
_Out_ PTP_TIMER *Timer,
_In_ PTP_TIMER_CALLBACK Callback,
_Inout_opt_ PVOID Context,
_In_opt_ PTP_CALLBACK_ENVIRON CallbackEnviron
);
// winbase:CloseThreadpoolTimer
/**
* Closes the specified timer object.
*
* \param[in,out] Timer A pointer to a TP_TIMER structure that defines the timer object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpooltimer
*/
NTSYSAPI
VOID
NTAPI
TpReleaseTimer(
_Inout_ PTP_TIMER Timer
);
// winbase:SetThreadpoolTimer
/**
* Sets the due time and periodic interval for the specified timer object.
*
* \param[in,out] Timer A pointer to a TP_TIMER structure that defines the timer object.
* \param[in] DueTime A pointer to a FILETIME-based value that specifies when the timer expires.
* \param[in] Period The period, in milliseconds, for periodic timer callbacks.
* \param[in] WindowLength The maximum amount of time, in milliseconds, that can elapse before the timer callback is invoked.
* \return None.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpooltimer
*/
NTSYSAPI
VOID
NTAPI
TpSetTimer(
_Inout_ PTP_TIMER Timer,
_In_opt_ PLARGE_INTEGER DueTime,
_In_ ULONG Period,
_In_opt_ ULONG WindowLength
);
#if (PHNT_VERSION >= PHNT_WINDOWS_8)
// winbase:SetThreadpoolTimerEx
/**
* Sets the due time and periodic interval for the specified timer object and returns status.
*
* \param[in,out] Timer A pointer to a TP_TIMER structure that defines the timer object.
* \param[in] DueTime A pointer to a FILETIME-based value that specifies when the timer expires.
* \param[in] Period The period, in milliseconds, for periodic timer callbacks.
* \param[in] WindowLength The maximum amount of time, in milliseconds, that can elapse before the timer callback is invoked.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpooltimerex
*/
NTSYSAPI
NTSTATUS
NTAPI
TpSetTimerEx(
_Inout_ PTP_TIMER Timer,
_In_opt_ PLARGE_INTEGER DueTime,
_In_ ULONG Period,
_In_opt_ ULONG WindowLength
);
#endif
// winbase:IsThreadpoolTimerSet
/**
* Determines whether a timer object is currently set.
*
* \param[in] Timer A pointer to a TP_TIMER structure that defines the timer object.
* \return LOGICAL TRUE if the timer is set; otherwise FALSE.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-isthreadpooltimerset
*/
NTSYSAPI
LOGICAL
NTAPI
TpIsTimerSet(
_In_ PTP_TIMER Timer
);
// winbase:WaitForThreadpoolTimerCallbacks
/**
* Waits for outstanding timer callbacks to complete and optionally cancels pending callbacks.
*
* \param[in,out] Timer A pointer to a TP_TIMER structure that defines the timer object.
* \param[in] CancelPendingCallbacks If TRUE, pending callbacks that have not started are canceled.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-waitforthreadpooltimercallbacks
*/
NTSYSAPI
VOID
NTAPI
TpWaitForTimer(
_Inout_ PTP_TIMER Timer,
_In_ LOGICAL CancelPendingCallbacks
);
// winbase:CreateThreadpoolWait
/**
* Allocates a wait object.
*
* \param[out] WaitReturn A pointer to a variable that receives the new wait object.
* \param[in] Callback The callback function to execute when the wait is satisfied or times out.
* \param[in,out] Context Optional application-defined data to pass to the callback function.
* \param[in] CallbackEnviron Optional callback environment for the callback.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-createthreadpoolwait
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocWait(
_Out_ PTP_WAIT *WaitReturn,
_In_ PTP_WAIT_CALLBACK Callback,
_Inout_opt_ PVOID Context,
_In_opt_ PTP_CALLBACK_ENVIRON CallbackEnviron
);
// winbase:CloseThreadpoolWait
/**
* Closes the specified wait object.
*
* \param[in,out] Wait A pointer to a TP_WAIT structure that defines the wait object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpoolwait
*/
NTSYSAPI
VOID
NTAPI
TpReleaseWait(
_Inout_ PTP_WAIT Wait
);
// winbase:SetThreadpoolWait
/**
* Sets the object to wait on and optional timeout for a wait object.
*
* \param[in,out] Wait A pointer to a TP_WAIT structure that defines the wait object.
* \param[in] Handle A handle to the object to wait on.
* \param[in] Timeout A pointer to a FILETIME-based timeout value.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpoolwait
*/
NTSYSAPI
VOID
NTAPI
TpSetWait(
_Inout_ PTP_WAIT Wait,
_In_opt_ HANDLE Handle,
_In_opt_ PLARGE_INTEGER Timeout
);
#if (PHNT_VERSION >= PHNT_WINDOWS_8)
// winbase:SetThreadpoolWaitEx
/**
* Sets the object to wait on and optional timeout for a wait object and returns status.
*
* \param[in,out] Wait A pointer to a TP_WAIT structure that defines the wait object.
* \param[in] Handle A handle to the object to wait on.
* \param[in] Timeout A pointer to a FILETIME-based timeout value.
* \param[in] Reserved Reserved for future use.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-setthreadpoolwaitex
*/
NTSYSAPI
NTSTATUS
NTAPI
TpSetWaitEx(
_Inout_ PTP_WAIT Wait,
_In_opt_ HANDLE Handle,
_In_opt_ PLARGE_INTEGER Timeout,
_In_opt_ PVOID Reserved
);
#endif
// winbase:WaitForThreadpoolWaitCallbacks
/**
* Waits for outstanding wait callbacks to complete and optionally cancels pending callbacks.
*
* \param[in,out] Wait A pointer to a TP_WAIT structure that defines the wait object.
* \param[in] CancelPendingCallbacks If TRUE, pending callbacks that have not started are canceled.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-waitforthreadpoolwaitcallbacks
*/
NTSYSAPI
VOID
NTAPI
TpWaitForWait(
_Inout_ PTP_WAIT Wait,
_In_ LOGICAL CancelPendingCallbacks
);
// private
/**
* Defines the callback function for asynchronous I/O completion callbacks.
*
* \param[in,out] Instance A pointer to a TP_CALLBACK_INSTANCE structure that defines the callback instance.
* \param[in,out] Context Optional application-defined data passed to the callback.
* \param[in] ApcContext A pointer to the asynchronous procedure call (APC) context.
* \param[in] IoSB A pointer to an IO_STATUS_BLOCK structure that contains the final I/O status.
* \param[in] Io A pointer to the I/O completion object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nc-threadpoolapiset-ptp_win32_io_callback
*/
typedef _Function_class_(TP_IO_CALLBACK)
VOID NTAPI TP_IO_CALLBACK(
_Inout_ PTP_CALLBACK_INSTANCE Instance,
_Inout_opt_ PVOID Context,
_In_ PVOID ApcContext,
_In_ PIO_STATUS_BLOCK IoSB,
_In_ PTP_IO Io
);
typedef TP_IO_CALLBACK *PTP_IO_CALLBACK;
// winbase:CreateThreadpoolIo
/**
* Allocates an I/O completion object associated with a file handle.
*
* \param[out] IoReturn A pointer to a variable that receives the new I/O completion object.
* \param[in] File A file handle associated with an I/O completion port.
* \param[in] Callback The callback function to execute when asynchronous I/O completes.
* \param[in,out] Context Optional application-defined data to pass to the callback function.
* \param[in] CallbackEnviron Optional callback environment for the callback.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-createthreadpoolio
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocIoCompletion(
_Out_ PTP_IO *IoReturn,
_In_ HANDLE File,
_In_ PTP_IO_CALLBACK Callback,
_Inout_opt_ PVOID Context,
_In_opt_ PTP_CALLBACK_ENVIRON CallbackEnviron
);
// winbase:CloseThreadpoolIo
/**
* Closes the specified I/O completion object.
*
* \param[in,out] Io A pointer to a TP_IO structure that defines the I/O completion object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpoolio
*/
NTSYSAPI
VOID
NTAPI
TpReleaseIoCompletion(
_Inout_ PTP_IO Io
);
// winbase:StartThreadpoolIo
/**
* Marks the start of one or more asynchronous I/O operations on the I/O completion object.
*
* \param[in,out] Io A pointer to a TP_IO structure that defines the I/O completion object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-startthreadpoolio
*/
NTSYSAPI
VOID
NTAPI
TpStartAsyncIoOperation(
_Inout_ PTP_IO Io
);
// winbase:CancelThreadpoolIo
/**
* Cancels callbacks for outstanding asynchronous I/O operations.
*
* \param[in,out] Io A pointer to a TP_IO structure that defines the I/O completion object.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-cancelthreadpoolio
*/
NTSYSAPI
VOID
NTAPI
TpCancelAsyncIoOperation(
_Inout_ PTP_IO Io
);
// winbase:WaitForThreadpoolIoCallbacks
/**
* Waits for outstanding I/O callbacks to complete and optionally cancels pending callbacks.
*
* \param[in,out] Io A pointer to a TP_IO structure that defines the I/O completion object.
* \param[in] CancelPendingCallbacks If TRUE, pending callbacks that have not started are canceled.
* \sa https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-waitforthreadpooliocallbacks
*/
NTSYSAPI
VOID
NTAPI
TpWaitForIoCompletion(
_Inout_ PTP_IO Io,
_In_ LOGICAL CancelPendingCallbacks
);
// private
/**
* Allocates an ALPC completion object.
*
* \param[out] AlpcReturn A pointer to a variable that receives the new ALPC completion object.
* \param[in] AlpcPort A handle to an ALPC port.
* \param[in] Callback The callback function to execute for ALPC completions.
* \param[in,out] Context Optional application-defined data to pass to the callback function.
* \param[in] CallbackEnviron Optional callback environment for the callback.
* \return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocAlpcCompletion(
_Out_ PTP_ALPC *AlpcReturn,
_In_ HANDLE AlpcPort,
_In_ PTP_ALPC_CALLBACK Callback,
_Inout_opt_ PVOID Context,
_In_opt_ PTP_CALLBACK_ENVIRON CallbackEnviron
);
// rev
/**
* Allocates an ALPC completion object with extended callback context.
*
* \param[out] AlpcReturn A pointer to a variable that receives the new ALPC completion object.
* \param[in] AlpcPort A handle to an ALPC port.
* \param[in] Callback The extended callback function to execute for ALPC completions.
* \param[in,out] Context Optional application-defined data to pass to the callback function.
* \param[in] CallbackEnviron Optional callback environment for the callback.
* \return NTSTATUS Successful or errant status.
*/
NTSYSAPI
NTSTATUS
NTAPI
TpAllocAlpcCompletionEx(
_Out_ PTP_ALPC *AlpcReturn,
_In_ HANDLE AlpcPort,
_In_ PTP_ALPC_CALLBACK_EX Callback,
_Inout_opt_ PVOID Context,
_In_opt_ PTP_CALLBACK_ENVIRON CallbackEnviron
);
// private
/**
* Releases an ALPC completion object.
*
* \param[in,out] Alpc A pointer to a TP_ALPC structure that defines the ALPC completion object.
*/
NTSYSAPI
VOID
NTAPI
TpReleaseAlpcCompletion(
_Inout_ PTP_ALPC Alpc
);
// private
/**
* Waits for ALPC completion processing to finish.
*
* \param[in,out] Alpc A pointer to a TP_ALPC structure that defines the ALPC completion object.
*/
NTSYSAPI
VOID
NTAPI
TpWaitForAlpcCompletion(
_Inout_ PTP_ALPC Alpc
);
// rev
/**
* Registers the ALPC completion list for the specified ALPC completion object.
*
* \param[in,out] Alpc A pointer to a TP_ALPC structure that defines the ALPC completion object.
*/
NTSYSAPI
VOID
NTAPI
TpAlpcRegisterCompletionList(
_Inout_ PTP_ALPC Alpc
);
// rev
/**
* Unregisters the ALPC completion list for the specified ALPC completion object.
*
* \param[in,out] Alpc A pointer to a TP_ALPC structure that defines the ALPC completion object.
* \return None.
*/
NTSYSAPI
VOID
NTAPI
TpAlpcUnregisterCompletionList(
_Inout_ PTP_ALPC Alpc
);
// private
typedef enum _TP_TRACE_TYPE
{
TpTraceThreadPriority = 1,
TpTraceThreadAffinity,
MaxTpTraceType
} TP_TRACE_TYPE;
// private
/**
* Captures caller context for thread pool tracing.
*
* \param[in] Type The trace operation type.
* \return None.
*/
NTSYSAPI
VOID
NTAPI
TpCaptureCaller(
_In_ TP_TRACE_TYPE Type
);
// private
/**
* Checks whether a worker thread should terminate.
*
* \param[in] Thread A handle to the worker thread.
* \return None.
*/
NTSYSAPI
VOID
NTAPI
TpCheckTerminateWorker(
_In_ HANDLE Thread
);
#endif // _NTTP_H