Process Hacker
ntrtl.h
Go to the documentation of this file.
1 #ifndef _NTRTL_H
2 #define _NTRTL_H
3 
4 // Linked lists
5 
6 FORCEINLINE VOID InitializeListHead(
7  _Out_ PLIST_ENTRY ListHead
8  )
9 {
10  ListHead->Flink = ListHead->Blink = ListHead;
11 }
12 
13 _Check_return_ FORCEINLINE BOOLEAN IsListEmpty(
14  _In_ PLIST_ENTRY ListHead
15  )
16 {
17  return ListHead->Flink == ListHead;
18 }
19 
20 FORCEINLINE BOOLEAN RemoveEntryList(
21  _In_ PLIST_ENTRY Entry
22  )
23 {
24  PLIST_ENTRY Blink;
25  PLIST_ENTRY Flink;
26 
27  Flink = Entry->Flink;
28  Blink = Entry->Blink;
29  Blink->Flink = Flink;
30  Flink->Blink = Blink;
31 
32  return Flink == Blink;
33 }
34 
35 FORCEINLINE PLIST_ENTRY RemoveHeadList(
36  _Inout_ PLIST_ENTRY ListHead
37  )
38 {
39  PLIST_ENTRY Flink;
40  PLIST_ENTRY Entry;
41 
42  Entry = ListHead->Flink;
43  Flink = Entry->Flink;
44  ListHead->Flink = Flink;
45  Flink->Blink = ListHead;
46 
47  return Entry;
48 }
49 
50 FORCEINLINE PLIST_ENTRY RemoveTailList(
51  _Inout_ PLIST_ENTRY ListHead
52  )
53 {
54  PLIST_ENTRY Blink;
55  PLIST_ENTRY Entry;
56 
57  Entry = ListHead->Blink;
58  Blink = Entry->Blink;
59  ListHead->Blink = Blink;
60  Blink->Flink = ListHead;
61 
62  return Entry;
63 }
64 
65 FORCEINLINE VOID InsertTailList(
66  _Inout_ PLIST_ENTRY ListHead,
67  _Inout_ PLIST_ENTRY Entry
68  )
69 {
70  PLIST_ENTRY Blink;
71 
72  Blink = ListHead->Blink;
73  Entry->Flink = ListHead;
74  Entry->Blink = Blink;
75  Blink->Flink = Entry;
76  ListHead->Blink = Entry;
77 }
78 
79 FORCEINLINE VOID InsertHeadList(
80  _Inout_ PLIST_ENTRY ListHead,
81  _Inout_ PLIST_ENTRY Entry
82  )
83 {
84  PLIST_ENTRY Flink;
85 
86  Flink = ListHead->Flink;
87  Entry->Flink = Flink;
88  Entry->Blink = ListHead;
89  Flink->Blink = Entry;
90  ListHead->Flink = Entry;
91 }
92 
93 FORCEINLINE VOID AppendTailList(
94  _Inout_ PLIST_ENTRY ListHead,
95  _Inout_ PLIST_ENTRY ListToAppend
96  )
97 {
98  PLIST_ENTRY ListEnd = ListHead->Blink;
99 
100  ListHead->Blink->Flink = ListToAppend;
101  ListHead->Blink = ListToAppend->Blink;
102  ListToAppend->Blink->Flink = ListHead;
103  ListToAppend->Blink = ListEnd;
104 }
105 
106 FORCEINLINE PSINGLE_LIST_ENTRY PopEntryList(
107  _Inout_ PSINGLE_LIST_ENTRY ListHead
108  )
109 {
110  PSINGLE_LIST_ENTRY FirstEntry;
111 
112  FirstEntry = ListHead->Next;
113 
114  if (FirstEntry)
115  ListHead->Next = FirstEntry->Next;
116 
117  return FirstEntry;
118 }
119 
120 FORCEINLINE VOID PushEntryList(
121  _Inout_ PSINGLE_LIST_ENTRY ListHead,
122  _Inout_ PSINGLE_LIST_ENTRY Entry
123  )
124 {
125  Entry->Next = ListHead->Next;
126  ListHead->Next = Entry;
127 }
128 
129 // AVL and splay trees
130 
132 {
138 
140 {
145 
147  _In_ struct _RTL_AVL_TABLE *Table,
148  _In_ PVOID FirstStruct,
149  _In_ PVOID SecondStruct
150  );
151 
152 typedef PVOID (NTAPI *PRTL_AVL_ALLOCATE_ROUTINE)(
153  _In_ struct _RTL_AVL_TABLE *Table,
154  _In_ CLONG ByteSize
155  );
156 
157 typedef VOID (NTAPI *PRTL_AVL_FREE_ROUTINE)(
158  _In_ struct _RTL_AVL_TABLE *Table,
159  _In_ _Post_invalid_ PVOID Buffer
160  );
161 
162 typedef NTSTATUS (NTAPI *PRTL_AVL_MATCH_FUNCTION)(
163  _In_ struct _RTL_AVL_TABLE *Table,
164  _In_ PVOID UserData,
165  _In_ PVOID MatchData
166  );
167 
168 typedef struct _RTL_BALANCED_LINKS
169 {
173  CHAR Balance;
174  UCHAR Reserved[3];
176 
177 typedef struct _RTL_AVL_TABLE
178 {
183  ULONG DepthOfTree;
184  PRTL_BALANCED_LINKS RestartKey;
185  ULONG DeleteCount;
191 
192 NTSYSAPI
193 VOID
194 NTAPI
196  _Out_ PRTL_AVL_TABLE Table,
197  _In_ PRTL_AVL_COMPARE_ROUTINE CompareRoutine,
198  _In_ PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine,
199  _In_ PRTL_AVL_FREE_ROUTINE FreeRoutine,
200  _In_opt_ PVOID TableContext
201  );
202 
203 NTSYSAPI
204 PVOID
205 NTAPI
207  _In_ PRTL_AVL_TABLE Table,
208  _In_reads_bytes_(BufferSize) PVOID Buffer,
209  _In_ CLONG BufferSize,
210  _Out_opt_ PBOOLEAN NewElement
211  );
212 
213 NTSYSAPI
214 PVOID
215 NTAPI
217  _In_ PRTL_AVL_TABLE Table,
218  _In_reads_bytes_(BufferSize) PVOID Buffer,
219  _In_ CLONG BufferSize,
220  _Out_opt_ PBOOLEAN NewElement,
221  _In_ PVOID NodeOrParent,
222  _In_ TABLE_SEARCH_RESULT SearchResult
223  );
224 
225 NTSYSAPI
226 BOOLEAN
227 NTAPI
229  _In_ PRTL_AVL_TABLE Table,
230  _In_ PVOID Buffer
231  );
232 
233 _Check_return_
234 NTSYSAPI
235 PVOID
236 NTAPI
238  _In_ PRTL_AVL_TABLE Table,
239  _In_ PVOID Buffer
240  );
241 
242 NTSYSAPI
243 PVOID
244 NTAPI
246  _In_ PRTL_AVL_TABLE Table,
247  _In_ PVOID Buffer,
248  _Out_ PVOID *NodeOrParent,
249  _Out_ TABLE_SEARCH_RESULT *SearchResult
250  );
251 
252 _Check_return_
253 NTSYSAPI
254 PVOID
255 NTAPI
257  _In_ PRTL_AVL_TABLE Table,
258  _In_ BOOLEAN Restart
259  );
260 
261 _Check_return_
262 NTSYSAPI
263 PVOID
264 NTAPI
266  _In_ PRTL_AVL_TABLE Table,
267  _Inout_ PVOID *RestartKey
268  );
269 
270 _Check_return_
271 NTSYSAPI
272 PVOID
273 NTAPI
275  _In_ PRTL_AVL_TABLE Table,
276  _In_ PVOID Buffer,
277  _Out_ PVOID *RestartKey
278  );
279 
280 _Check_return_
281 NTSYSAPI
282 PVOID
283 NTAPI
285  _In_ PRTL_AVL_TABLE Table,
286  _In_opt_ PRTL_AVL_MATCH_FUNCTION MatchFunction,
287  _In_opt_ PVOID MatchData,
288  _In_ ULONG NextFlag,
289  _Inout_ PVOID *RestartKey,
290  _Inout_ PULONG DeleteCount,
291  _In_ PVOID Buffer
292  );
293 
294 _Check_return_
295 NTSYSAPI
296 PVOID
297 NTAPI
299  _In_ PRTL_AVL_TABLE Table,
300  _In_ ULONG I
301  );
302 
303 NTSYSAPI
304 ULONG
305 NTAPI
307  _In_ PRTL_AVL_TABLE Table
308  );
309 
310 _Check_return_
311 NTSYSAPI
312 BOOLEAN
313 NTAPI
315  _In_ PRTL_AVL_TABLE Table
316  );
317 
318 typedef struct _RTL_SPLAY_LINKS
319 {
324 
325 #define RtlInitializeSplayLinks(Links) \
326  { \
327  PRTL_SPLAY_LINKS _SplayLinks; \
328  _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
329  _SplayLinks->Parent = _SplayLinks; \
330  _SplayLinks->LeftChild = NULL; \
331  _SplayLinks->RightChild = NULL; \
332  }
333 
334 #define RtlParent(Links) ((PRTL_SPLAY_LINKS)(Links)->Parent)
335 #define RtlLeftChild(Links) ((PRTL_SPLAY_LINKS)(Links)->LeftChild)
336 #define RtlRightChild(Links) ((PRTL_SPLAY_LINKS)(Links)->RightChild)
337 #define RtlIsRoot(Links) ((RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links)))
338 #define RtlIsLeftChild(Links) ((RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)))
339 #define RtlIsRightChild(Links) ((RtlRightChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)))
340 
341 #define RtlInsertAsLeftChild(ParentLinks, ChildLinks) \
342  { \
343  PRTL_SPLAY_LINKS _SplayParent; \
344  PRTL_SPLAY_LINKS _SplayChild; \
345  _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
346  _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
347  _SplayParent->LeftChild = _SplayChild; \
348  _SplayChild->Parent = _SplayParent; \
349  }
350 
351 #define RtlInsertAsRightChild(ParentLinks, ChildLinks) \
352  { \
353  PRTL_SPLAY_LINKS _SplayParent; \
354  PRTL_SPLAY_LINKS _SplayChild; \
355  _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
356  _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
357  _SplayParent->RightChild = _SplayChild; \
358  _SplayChild->Parent = _SplayParent; \
359  }
360 
361 NTSYSAPI
362 PRTL_SPLAY_LINKS
363 NTAPI
364 RtlSplay(
365  _Inout_ PRTL_SPLAY_LINKS Links
366  );
367 
368 NTSYSAPI
369 PRTL_SPLAY_LINKS
370 NTAPI
371 RtlDelete(
372  _In_ PRTL_SPLAY_LINKS Links
373  );
374 
375 NTSYSAPI
376 VOID
377 NTAPI
379  _In_ PRTL_SPLAY_LINKS Links,
380  _Inout_ PRTL_SPLAY_LINKS *Root
381  );
382 
383 _Check_return_
384 NTSYSAPI
385 PRTL_SPLAY_LINKS
386 NTAPI
388  _In_ PRTL_SPLAY_LINKS Links
389  );
390 
391 _Check_return_
392 NTSYSAPI
393 PRTL_SPLAY_LINKS
394 NTAPI
396  _In_ PRTL_SPLAY_LINKS Links
397  );
398 
399 _Check_return_
400 NTSYSAPI
401 PRTL_SPLAY_LINKS
402 NTAPI
404  _In_ PRTL_SPLAY_LINKS Links
405  );
406 
407 _Check_return_
408 NTSYSAPI
409 PRTL_SPLAY_LINKS
410 NTAPI
412  _In_ PRTL_SPLAY_LINKS Links
413  );
414 
415 struct _RTL_GENERIC_TABLE;
416 
417 typedef RTL_GENERIC_COMPARE_RESULTS (NTAPI *PRTL_GENERIC_COMPARE_ROUTINE)(
418  _In_ struct _RTL_GENERIC_TABLE *Table,
419  _In_ PVOID FirstStruct,
420  _In_ PVOID SecondStruct
421  );
422 
423 typedef PVOID (NTAPI *PRTL_GENERIC_ALLOCATE_ROUTINE)(
424  _In_ struct _RTL_GENERIC_TABLE *Table,
425  _In_ CLONG ByteSize
426  );
427 
429  _In_ struct _RTL_GENERIC_TABLE *Table,
430  _In_ _Post_invalid_ PVOID Buffer
431  );
432 
433 typedef struct _RTL_GENERIC_TABLE
434 {
435  PRTL_SPLAY_LINKS TableRoot;
436  LIST_ENTRY InsertOrderList;
437  PLIST_ENTRY OrderedPointer;
440  PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine;
445 
446 NTSYSAPI
447 VOID
448 NTAPI
450  _Out_ PRTL_GENERIC_TABLE Table,
451  _In_ PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine,
452  _In_ PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine,
453  _In_ PRTL_GENERIC_FREE_ROUTINE FreeRoutine,
454  _In_opt_ PVOID TableContext
455  );
456 
457 NTSYSAPI
458 PVOID
459 NTAPI
461  _In_ PRTL_GENERIC_TABLE Table,
462  _In_reads_bytes_(BufferSize) PVOID Buffer,
463  _In_ CLONG BufferSize,
464  _Out_opt_ PBOOLEAN NewElement
465  );
466 
467 NTSYSAPI
468 PVOID
469 NTAPI
471  _In_ PRTL_GENERIC_TABLE Table,
472  _In_reads_bytes_(BufferSize) PVOID Buffer,
473  _In_ CLONG BufferSize,
474  _Out_opt_ PBOOLEAN NewElement,
475  _In_ PVOID NodeOrParent,
476  _In_ TABLE_SEARCH_RESULT SearchResult
477  );
478 
479 NTSYSAPI
480 BOOLEAN
481 NTAPI
483  _In_ PRTL_GENERIC_TABLE Table,
484  _In_ PVOID Buffer
485  );
486 
487 _Check_return_
488 NTSYSAPI
489 PVOID
490 NTAPI
492  _In_ PRTL_GENERIC_TABLE Table,
493  _In_ PVOID Buffer
494  );
495 
496 NTSYSAPI
497 PVOID
498 NTAPI
500  _In_ PRTL_GENERIC_TABLE Table,
501  _In_ PVOID Buffer,
502  _Out_ PVOID *NodeOrParent,
503  _Out_ TABLE_SEARCH_RESULT *SearchResult
504  );
505 
506 _Check_return_
507 NTSYSAPI
508 PVOID
509 NTAPI
511  _In_ PRTL_GENERIC_TABLE Table,
512  _In_ BOOLEAN Restart
513  );
514 
515 _Check_return_
516 NTSYSAPI
517 PVOID
518 NTAPI
520  _In_ PRTL_GENERIC_TABLE Table,
521  _Inout_ PVOID *RestartKey
522  );
523 
524 _Check_return_
525 NTSYSAPI
526 PVOID
527 NTAPI
529  _In_ PRTL_GENERIC_TABLE Table,
530  _In_ ULONG I
531  );
532 
533 NTSYSAPI
534 ULONG
535 NTAPI
537  _In_ PRTL_GENERIC_TABLE Table
538  );
539 
540 _Check_return_
541 NTSYSAPI
542 BOOLEAN
543 NTAPI
545  _In_ PRTL_GENERIC_TABLE Table
546  );
547 
548 // RB trees
549 
550 typedef struct _RTL_RB_TREE
551 {
555 
556 #if (PHNT_VERSION >= PHNT_WIN8)
557 
558 // rev
559 NTSYSAPI
560 VOID
561 NTAPI
563  _In_ PRTL_RB_TREE Tree,
564  _In_opt_ PRTL_BALANCED_NODE Parent,
565  _In_ BOOLEAN Right,
566  _Out_ PRTL_BALANCED_NODE Node
567  );
568 
569 // rev
570 NTSYSAPI
571 VOID
572 NTAPI
574  _In_ PRTL_RB_TREE Tree,
575  _In_ PRTL_BALANCED_NODE Node
576  );
577 
578 #endif
579 
580 // Hash tables
581 
582 // begin_ntddk
583 
584 #define RTL_HASH_ALLOCATED_HEADER 0x00000001
585 #define RTL_HASH_RESERVED_SIGNATURE 0
586 
588 {
589  LIST_ENTRY Linkage;
590  ULONG_PTR Signature;
592 
593 #define HASH_ENTRY_KEY(x) ((x)->Signature)
594 
596 {
597  PLIST_ENTRY ChainHead;
598  PLIST_ENTRY PrevLinkage;
599  ULONG_PTR Signature;
601 
603 {
605  PLIST_ENTRY ChainHead;
606  ULONG BucketIndex;
608 
610 {
611  // Entries initialized at creation.
612  ULONG Flags;
613  ULONG Shift;
614 
615  // Entries used in bucket computation.
616  ULONG TableSize;
617  ULONG Pivot;
618  ULONG DivisorMask;
619 
620  // Counters.
621  ULONG NumEntries;
624 
625  // The directory. This field is for internal use only.
626  PVOID Directory;
628 
629 #if (PHNT_VERSION >= PHNT_WIN7)
630 
631 FORCEINLINE
632 VOID
634  _Inout_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context
635  )
636 {
637  Context->ChainHead = NULL;
638  Context->PrevLinkage = NULL;
639 }
640 
641 FORCEINLINE
642 VOID
644  _Inout_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context,
645  _In_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
646  )
647 {
648  Context->ChainHead = Enumerator->ChainHead;
649  Context->PrevLinkage = Enumerator->HashEntry.Linkage.Blink;
650 }
651 
652 FORCEINLINE
653 VOID
655  _Inout_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context
656  )
657 {
658  UNREFERENCED_PARAMETER(Context);
659  return;
660 }
661 
662 FORCEINLINE
663 ULONG
665  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
666  )
667 {
668  return HashTable->TableSize;
669 }
670 
671 FORCEINLINE
672 ULONG
674  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
675  )
676 {
677  return HashTable->NonEmptyBuckets;
678 }
679 
680 FORCEINLINE
681 ULONG
683  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
684  )
685 {
686  return HashTable->TableSize - HashTable->NonEmptyBuckets;
687 }
688 
689 FORCEINLINE
690 ULONG
692  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
693  )
694 {
695  return HashTable->NumEntries;
696 }
697 
698 FORCEINLINE
699 ULONG
701  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
702  )
703 {
704  return HashTable->NumEnumerators;
705 }
706 
707 _Must_inspect_result_
708 NTSYSAPI
709 BOOLEAN
710 NTAPI
712  _Inout_ _When_(*HashTable == NULL, __drv_allocatesMem(Mem)) PRTL_DYNAMIC_HASH_TABLE *HashTable,
713  _In_ ULONG Shift,
714  _In_ _Reserved_ ULONG Flags
715  );
716 
717 NTSYSAPI
718 VOID
719 NTAPI
721  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
722  );
723 
724 NTSYSAPI
725 BOOLEAN
726 NTAPI
728  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
729  _In_ PRTL_DYNAMIC_HASH_TABLE_ENTRY Entry,
730  _In_ ULONG_PTR Signature,
731  _Inout_opt_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context
732  );
733 
734 NTSYSAPI
735 BOOLEAN
736 NTAPI
738  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
739  _In_ PRTL_DYNAMIC_HASH_TABLE_ENTRY Entry,
740  _Inout_opt_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context
741  );
742 
743 _Must_inspect_result_
744 NTSYSAPI
745 PRTL_DYNAMIC_HASH_TABLE_ENTRY
746 NTAPI
748  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
749  _In_ ULONG_PTR Signature,
750  _Out_opt_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context
751  );
752 
753 _Must_inspect_result_
754 NTSYSAPI
755 PRTL_DYNAMIC_HASH_TABLE_ENTRY
756 NTAPI
758  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
759  _In_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context
760  );
761 
762 NTSYSAPI
763 BOOLEAN
764 NTAPI
766  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
767  _Out_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
768  );
769 
770 _Must_inspect_result_
771 NTSYSAPI
772 PRTL_DYNAMIC_HASH_TABLE_ENTRY
773 NTAPI
775  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
776  _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
777  );
778 
779 NTSYSAPI
780 VOID
781 NTAPI
783  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
784  _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
785  );
786 
787 NTSYSAPI
788 BOOLEAN
789 NTAPI
791  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
792  _Out_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
793  );
794 
795 _Must_inspect_result_
796 NTSYSAPI
797 PRTL_DYNAMIC_HASH_TABLE_ENTRY
798 NTAPI
800  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
801  _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
802  );
803 
804 NTSYSAPI
805 VOID
806 NTAPI
808  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
809  _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
810  );
811 
812 NTSYSAPI
813 BOOLEAN
814 NTAPI
816  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
817  );
818 
819 NTSYSAPI
820 BOOLEAN
821 NTAPI
823  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable
824  );
825 
826 #endif
827 
828 #if (PHNT_VERSION >= PHNT_THRESHOLD)
829 
830 NTSYSAPI
831 BOOLEAN
832 NTAPI
834  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
835  _Out_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
836  );
837 
838 _Must_inspect_result_
839 NTSYSAPI
840 PRTL_DYNAMIC_HASH_TABLE_ENTRY
841 NTAPI
843  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
844  _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
845  );
846 
847 NTSYSAPI
848 VOID
849 NTAPI
851  _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
852  _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator
853  );
854 
855 #endif
856 
857 // end_ntddk
858 
859 // Critical sections
860 
861 NTSYSAPI
862 NTSTATUS
863 NTAPI
865  _Out_ PRTL_CRITICAL_SECTION CriticalSection
866  );
867 
868 NTSYSAPI
869 NTSTATUS
870 NTAPI
872  _Inout_ PRTL_CRITICAL_SECTION CriticalSection,
873  _In_ ULONG SpinCount
874  );
875 
876 NTSYSAPI
877 NTSTATUS
878 NTAPI
880  _Inout_ PRTL_CRITICAL_SECTION CriticalSection
881  );
882 
883 NTSYSAPI
884 NTSTATUS
885 NTAPI
887  _Inout_ PRTL_CRITICAL_SECTION CriticalSection
888  );
889 
890 NTSYSAPI
891 NTSTATUS
892 NTAPI
894  _Inout_ PRTL_CRITICAL_SECTION CriticalSection
895  );
896 
897 NTSYSAPI
898 LOGICAL
899 NTAPI
901  _Inout_ PRTL_CRITICAL_SECTION CriticalSection
902  );
903 
904 NTSYSAPI
905 LOGICAL
906 NTAPI
908  _In_ PRTL_CRITICAL_SECTION CriticalSection
909  );
910 
911 NTSYSAPI
912 LOGICAL
913 NTAPI
915  _In_ PRTL_CRITICAL_SECTION CriticalSection
916  );
917 
918 NTSYSAPI
919 ULONG
920 NTAPI
922  _In_ PRTL_CRITICAL_SECTION CriticalSection
923  );
924 
925 NTSYSAPI
926 ULONG
927 NTAPI
929  _Inout_ PRTL_CRITICAL_SECTION CriticalSection,
930  _In_ ULONG SpinCount
931  );
932 
933 #if (PHNT_VERSION >= PHNT_VISTA)
934 // private
935 NTSYSAPI
936 HANDLE
937 NTAPI
939  _In_ HANDLE EventHandle
940  );
941 #endif
942 
943 NTSYSAPI
944 VOID
945 NTAPI
947  _In_ HANDLE hThread
948  );
949 
950 // Resources
951 
952 typedef struct _RTL_RESOURCE
953 {
954  RTL_CRITICAL_SECTION CriticalSection;
955 
960 
961  LONG NumberOfActive; // negative: exclusive acquire; zero: not acquired; positive: shared acquire(s)
963 
964  ULONG Flags; // RTL_RESOURCE_FLAG_*
965 
966  PRTL_RESOURCE_DEBUG DebugInfo;
968 
969 #define RTL_RESOURCE_FLAG_LONG_TERM ((ULONG)0x00000001)
970 
971 NTSYSAPI
972 VOID
973 NTAPI
975  _Out_ PRTL_RESOURCE Resource
976  );
977 
978 NTSYSAPI
979 VOID
980 NTAPI
982  _Inout_ PRTL_RESOURCE Resource
983  );
984 
985 NTSYSAPI
986 BOOLEAN
987 NTAPI
989  _Inout_ PRTL_RESOURCE Resource,
990  _In_ BOOLEAN Wait
991  );
992 
993 NTSYSAPI
994 BOOLEAN
995 NTAPI
997  _Inout_ PRTL_RESOURCE Resource,
998  _In_ BOOLEAN Wait
999  );
1000 
1001 NTSYSAPI
1002 VOID
1003 NTAPI
1005  _Inout_ PRTL_RESOURCE Resource
1006  );
1007 
1008 NTSYSAPI
1009 VOID
1010 NTAPI
1012  _Inout_ PRTL_RESOURCE Resource
1013  );
1014 
1015 NTSYSAPI
1016 VOID
1017 NTAPI
1019  _Inout_ PRTL_RESOURCE Resource
1020  );
1021 
1022 // Slim reader-writer locks, condition variables, and barriers
1023 
1024 #if (PHNT_VERSION >= PHNT_VISTA)
1025 
1026 // winbase:InitializeSRWLock
1027 NTSYSAPI
1028 VOID
1029 NTAPI
1031  _Out_ PRTL_SRWLOCK SRWLock
1032  );
1033 
1034 // winbase:AcquireSRWLockExclusive
1035 NTSYSAPI
1036 VOID
1037 NTAPI
1039  _Inout_ PRTL_SRWLOCK SRWLock
1040  );
1041 
1042 // winbase:AcquireSRWLockShared
1043 NTSYSAPI
1044 VOID
1045 NTAPI
1047  _Inout_ PRTL_SRWLOCK SRWLock
1048  );
1049 
1050 // winbase:ReleaseSRWLockExclusive
1051 NTSYSAPI
1052 VOID
1053 NTAPI
1055  _Inout_ PRTL_SRWLOCK SRWLock
1056  );
1057 
1058 // winbase:ReleaseSRWLockShared
1059 NTSYSAPI
1060 VOID
1061 NTAPI
1063  _Inout_ PRTL_SRWLOCK SRWLock
1064  );
1065 
1066 // winbase:TryAcquireSRWLockExclusive
1067 NTSYSAPI
1068 BOOLEAN
1069 NTAPI
1071  _Inout_ PRTL_SRWLOCK SRWLock
1072  );
1073 
1074 // winbase:TryAcquireSRWLockShared
1075 NTSYSAPI
1076 BOOLEAN
1077 NTAPI
1079  _Inout_ PRTL_SRWLOCK SRWLock
1080  );
1081 
1082 #if (PHNT_VERSION >= PHNT_WIN7)
1083 // rev
1084 NTSYSAPI
1085 VOID
1086 NTAPI
1088  _Inout_ PRTL_SRWLOCK SRWLock
1089  );
1090 #endif
1091 
1092 #endif
1093 
1094 #if (PHNT_VERSION >= PHNT_VISTA)
1095 
1096 // winbase:InitializeConditionVariable
1097 NTSYSAPI
1098 VOID
1099 NTAPI
1101  _Out_ PRTL_CONDITION_VARIABLE ConditionVariable
1102  );
1103 
1104 // private
1105 NTSYSAPI
1106 NTSTATUS
1107 NTAPI
1109  _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable,
1110  _Inout_ PRTL_CRITICAL_SECTION CriticalSection,
1111  _In_opt_ PLARGE_INTEGER Timeout
1112  );
1113 
1114 // private
1115 NTSYSAPI
1116 NTSTATUS
1117 NTAPI
1119  _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable,
1120  _Inout_ PRTL_SRWLOCK SRWLock,
1121  _In_opt_ PLARGE_INTEGER Timeout,
1122  _In_ ULONG Flags
1123  );
1124 
1125 // winbase:WakeConditionVariable
1126 NTSYSAPI
1127 VOID
1128 NTAPI
1130  _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable
1131  );
1132 
1133 // winbase:WakeAllConditionVariable
1134 NTSYSAPI
1135 VOID
1136 NTAPI
1138  _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable
1139  );
1140 
1141 #endif
1142 
1143 // begin_rev
1144 #define RTL_BARRIER_FLAGS_SPIN_ONLY 0x00000001 // never block on event - always spin
1145 #define RTL_BARRIER_FLAGS_BLOCK_ONLY 0x00000002 // always block on event - never spin
1146 #define RTL_BARRIER_FLAGS_NO_DELETE 0x00000004 // use if barrier will never be deleted
1147 // end_rev
1148 
1149 // begin_private
1150 
1151 #if (PHNT_VERSION >= PHNT_VISTA)
1152 
1153 NTSYSAPI
1154 NTSTATUS
1155 NTAPI
1157  _Out_ PRTL_BARRIER Barrier,
1158  _In_ ULONG TotalThreads,
1159  _In_ ULONG SpinCount
1160  );
1161 
1162 NTSYSAPI
1163 NTSTATUS
1164 NTAPI
1166  _In_ PRTL_BARRIER Barrier
1167  );
1168 
1169 NTSYSAPI
1170 BOOLEAN
1171 NTAPI
1172 RtlBarrier(
1173  _Inout_ PRTL_BARRIER Barrier,
1174  _In_ ULONG Flags
1175  );
1176 
1177 NTSYSAPI
1178 BOOLEAN
1179 NTAPI
1181  _Inout_ PRTL_BARRIER Barrier,
1182  _In_ ULONG Flags
1183  );
1184 
1185 #endif
1186 
1187 // end_private
1188 
1189 // Strings
1190 
1191 #ifndef PHNT_NO_INLINE_INIT_STRING
1192 FORCEINLINE VOID RtlInitString(
1193  _Out_ PSTRING DestinationString,
1194  _In_opt_ PSTR SourceString
1195  )
1196 {
1197  if (SourceString)
1198  DestinationString->MaximumLength = (DestinationString->Length = (USHORT)strlen(SourceString)) + 1;
1199  else
1200  DestinationString->MaximumLength = DestinationString->Length = 0;
1201 
1202  DestinationString->Buffer = SourceString;
1203 }
1204 #else
1205 NTSYSAPI
1206 VOID
1207 NTAPI
1209  _Out_ PSTRING DestinationString,
1210  _In_opt_ PSTR SourceString
1211  );
1212 #endif
1213 
1214 #if (PHNT_VERSION >= PHNT_THRESHOLD)
1215 NTSYSAPI
1216 NTSTATUS
1217 NTAPI
1219  _Out_ PSTRING DestinationString,
1220  _In_opt_z_ PCSZ SourceString
1221  );
1222 #endif
1223 
1224 #ifndef PHNT_NO_INLINE_INIT_STRING
1226  _Out_ PANSI_STRING DestinationString,
1227  _In_opt_ PSTR SourceString
1228  )
1229 {
1230  if (SourceString)
1231  DestinationString->MaximumLength = (DestinationString->Length = (USHORT)strlen(SourceString)) + 1;
1232  else
1233  DestinationString->MaximumLength = DestinationString->Length = 0;
1234 
1235  DestinationString->Buffer = SourceString;
1236 }
1237 #else
1238 NTSYSAPI
1239 VOID
1240 NTAPI
1242  _Out_ PANSI_STRING DestinationString,
1243  _In_opt_ PSTR SourceString
1244  );
1245 #endif
1246 
1247 #if (PHNT_VERSION >= PHNT_WS03)
1248 NTSYSAPI
1249 NTSTATUS
1250 NTAPI
1252  _Out_ PANSI_STRING DestinationString,
1253  _In_opt_z_ PCSZ SourceString
1254  );
1255 #endif
1256 
1257 NTSYSAPI
1258 VOID
1259 NTAPI
1261  _In_ PANSI_STRING AnsiString
1262  );
1263 
1264 NTSYSAPI
1265 VOID
1266 NTAPI
1268  _In_ POEM_STRING OemString
1269  );
1270 
1271 NTSYSAPI
1272 VOID
1273 NTAPI
1275  _In_ PSTRING DestinationString,
1276  _In_opt_ PSTRING SourceString
1277  );
1278 
1279 NTSYSAPI
1280 CHAR
1281 NTAPI
1282 RtlUpperChar(
1283  _In_ CHAR Character
1284  );
1285 
1286 _Must_inspect_result_
1287 NTSYSAPI
1288 LONG
1289 NTAPI
1291  _In_ PSTRING String1,
1292  _In_ PSTRING String2,
1293  _In_ BOOLEAN CaseInSensitive
1294  );
1295 
1296 _Must_inspect_result_
1297 NTSYSAPI
1298 BOOLEAN
1299 NTAPI
1301  _In_ PSTRING String1,
1302  _In_ PSTRING String2,
1303  _In_ BOOLEAN CaseInSensitive
1304  );
1305 
1306 _Must_inspect_result_
1307 NTSYSAPI
1308 BOOLEAN
1309 NTAPI
1311  _In_ PSTRING String1,
1312  _In_ PSTRING String2,
1313  _In_ BOOLEAN CaseInSensitive
1314  );
1315 
1316 NTSYSAPI
1317 NTSTATUS
1318 NTAPI
1320  _In_ PSTRING Destination,
1321  _In_ PSTRING Source
1322  );
1323 
1324 NTSYSAPI
1325 NTSTATUS
1326 NTAPI
1328  _In_ PSTRING Destination,
1329  _In_opt_ PSTR Source
1330  );
1331 
1332 NTSYSAPI
1333 VOID
1334 NTAPI
1336  _In_ PSTRING DestinationString,
1337  _In_ PSTRING SourceString
1338  );
1339 
1340 #ifndef PHNT_NO_INLINE_INIT_STRING
1342  _Out_ PUNICODE_STRING DestinationString,
1343  _In_opt_ PWSTR SourceString
1344  )
1345 {
1346  if (SourceString)
1347  DestinationString->MaximumLength = (DestinationString->Length = (USHORT)(wcslen(SourceString) * sizeof(WCHAR))) + sizeof(WCHAR);
1348  else
1349  DestinationString->MaximumLength = DestinationString->Length = 0;
1350 
1351  DestinationString->Buffer = SourceString;
1352 }
1353 #else
1354 NTSYSAPI
1355 VOID
1356 NTAPI
1358  _Out_ PUNICODE_STRING DestinationString,
1359  _In_opt_ PWSTR SourceString
1360  );
1361 #endif
1362 
1363 NTSYSAPI
1364 NTSTATUS
1365 NTAPI
1367  _Out_ PUNICODE_STRING DestinationString,
1368  _In_opt_ PWSTR SourceString
1369  );
1370 
1371 NTSYSAPI
1372 BOOLEAN
1373 NTAPI
1375  _Out_ PUNICODE_STRING DestinationString,
1376  _In_ PWSTR SourceString
1377  );
1378 
1379 NTSYSAPI
1380 BOOLEAN
1381 NTAPI
1383  _Out_ PUNICODE_STRING DestinationString,
1384  _In_ PSTR SourceString
1385  );
1386 
1387 NTSYSAPI
1388 VOID
1389 NTAPI
1391  _In_ PUNICODE_STRING UnicodeString
1392  );
1393 
1394 #define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE (0x00000001)
1395 #define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING (0x00000002)
1396 
1397 NTSYSAPI
1398 NTSTATUS
1399 NTAPI
1401  _In_ ULONG Flags,
1402  _In_ PUNICODE_STRING StringIn,
1403  _Out_ PUNICODE_STRING StringOut
1404  );
1405 
1406 NTSYSAPI
1407 VOID
1408 NTAPI
1410  _In_ PUNICODE_STRING DestinationString,
1411  _In_ PUNICODE_STRING SourceString
1412  );
1413 
1414 NTSYSAPI
1415 WCHAR
1416 NTAPI
1418  _In_ WCHAR SourceCharacter
1419  );
1420 
1421 NTSYSAPI
1422 WCHAR
1423 NTAPI
1425  _In_ WCHAR SourceCharacter
1426  );
1427 
1428 _Must_inspect_result_
1429 NTSYSAPI
1430 LONG
1431 NTAPI
1433  _In_ PUNICODE_STRING String1,
1434  _In_ PUNICODE_STRING String2,
1435  _In_ BOOLEAN CaseInSensitive
1436  );
1437 
1438 #if (PHNT_VERSION >= PHNT_VISTA)
1439 _Must_inspect_result_
1440 NTSYSAPI
1441 LONG
1442 NTAPI
1444  _In_reads_(String1Length) PWCH String1,
1445  _In_ SIZE_T String1Length,
1446  _In_reads_(String2Length) PWCH String2,
1447  _In_ SIZE_T String2Length,
1448  _In_ BOOLEAN CaseInSensitive
1449  );
1450 #endif
1451 
1452 _Must_inspect_result_
1453 NTSYSAPI
1454 BOOLEAN
1455 NTAPI
1457  _In_ PUNICODE_STRING String1,
1458  _In_ PUNICODE_STRING String2,
1459  _In_ BOOLEAN CaseInSensitive
1460  );
1461 
1462 #define HASH_STRING_ALGORITHM_DEFAULT 0
1463 #define HASH_STRING_ALGORITHM_X65599 1
1464 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
1465 
1466 NTSYSAPI
1467 NTSTATUS
1468 NTAPI
1470  _In_ PUNICODE_STRING String,
1471  _In_ BOOLEAN CaseInSensitive,
1472  _In_ ULONG HashAlgorithm,
1473  _Out_ PULONG HashValue
1474  );
1475 
1476 NTSYSAPI
1477 NTSTATUS
1478 NTAPI
1480  _In_ ULONG Flags,
1481  _In_ PUNICODE_STRING String
1482  );
1483 
1484 _Must_inspect_result_
1485 NTSYSAPI
1486 BOOLEAN
1487 NTAPI
1489  _In_ PCUNICODE_STRING String1,
1490  _In_ PCUNICODE_STRING String2,
1491  _In_ BOOLEAN CaseInSensitive
1492  );
1493 
1494 #if (PHNT_VERSION >= PHNT_THRESHOLD)
1495 _Must_inspect_result_
1496 NTSYSAPI
1497 BOOLEAN
1498 NTAPI
1500  _In_ PCUNICODE_STRING String1,
1501  _In_ PCUNICODE_STRING String2,
1502  _In_ BOOLEAN CaseInSensitive
1503  );
1504 #endif
1505 
1506 #define RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END 0x00000001
1507 #define RTL_FIND_CHAR_IN_UNICODE_STRING_COMPLEMENT_CHAR_SET 0x00000002
1508 #define RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE 0x00000004
1509 
1510 NTSYSAPI
1511 NTSTATUS
1512 NTAPI
1514  _In_ ULONG Flags,
1515  _In_ PUNICODE_STRING StringToSearch,
1516  _In_ PUNICODE_STRING CharSet,
1517  _Out_ PUSHORT NonInclusivePrefixLength
1518  );
1519 
1520 NTSYSAPI
1521 NTSTATUS
1522 NTAPI
1524  _In_ PUNICODE_STRING Destination,
1525  _In_ PUNICODE_STRING Source
1526  );
1527 
1528 NTSYSAPI
1529 NTSTATUS
1530 NTAPI
1532  _In_ PUNICODE_STRING Destination,
1533  _In_opt_ PWSTR Source
1534  );
1535 
1536 NTSYSAPI
1537 NTSTATUS
1538 NTAPI
1540  _Inout_ PUNICODE_STRING DestinationString,
1541  _In_ PUNICODE_STRING SourceString,
1542  _In_ BOOLEAN AllocateDestinationString
1543  );
1544 
1545 NTSYSAPI
1546 NTSTATUS
1547 NTAPI
1549  _Inout_ PUNICODE_STRING DestinationString,
1550  _In_ PUNICODE_STRING SourceString,
1551  _In_ BOOLEAN AllocateDestinationString
1552  );
1553 
1554 NTSYSAPI
1555 VOID
1556 NTAPI
1558  _Inout_ PUNICODE_STRING String
1559  );
1560 
1561 NTSYSAPI
1562 NTSTATUS
1563 NTAPI
1565  _Inout_ PUNICODE_STRING DestinationString,
1566  _In_ PANSI_STRING SourceString,
1567  _In_ BOOLEAN AllocateDestinationString
1568  );
1569 
1570 NTSYSAPI
1571 NTSTATUS
1572 NTAPI
1574  _Inout_ PANSI_STRING DestinationString,
1575  _In_ PUNICODE_STRING SourceString,
1576  _In_ BOOLEAN AllocateDestinationString
1577  );
1578 
1579 NTSYSAPI
1580 WCHAR
1581 NTAPI
1583  _Inout_ PUCHAR *SourceCharacter
1584  );
1585 
1586 NTSYSAPI
1587 NTSTATUS
1588 NTAPI
1590  _Inout_ PANSI_STRING DestinationString,
1591  _In_ PUNICODE_STRING SourceString,
1592  _In_ BOOLEAN AllocateDestinationString
1593  );
1594 
1595 NTSYSAPI
1596 NTSTATUS
1597 NTAPI
1599  _Inout_ PUNICODE_STRING DestinationString,
1600  _In_ POEM_STRING SourceString,
1601  _In_ BOOLEAN AllocateDestinationString
1602  );
1603 
1604 NTSYSAPI
1605 NTSTATUS
1606 NTAPI
1608  _Inout_ POEM_STRING DestinationString,
1609  _In_ PUNICODE_STRING SourceString,
1610  _In_ BOOLEAN AllocateDestinationString
1611  );
1612 
1613 NTSYSAPI
1614 NTSTATUS
1615 NTAPI
1617  _Inout_ POEM_STRING DestinationString,
1618  _In_ PUNICODE_STRING SourceString,
1619  _In_ BOOLEAN AllocateDestinationString
1620  );
1621 
1622 NTSYSAPI
1623 NTSTATUS
1624 NTAPI
1626  _Inout_ POEM_STRING DestinationString,
1627  _In_ PUNICODE_STRING SourceString,
1628  _In_ BOOLEAN AllocateDestinationString
1629  );
1630 
1631 NTSYSAPI
1632 NTSTATUS
1633 NTAPI
1635  _Inout_ POEM_STRING DestinationString,
1636  _In_ PUNICODE_STRING SourceString,
1637  _In_ BOOLEAN AllocateDestinationString
1638  );
1639 
1640 NTSYSAPI
1641 NTSTATUS
1642 NTAPI
1644  _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWCH UnicodeString,
1645  _In_ ULONG MaxBytesInUnicodeString,
1646  _Out_opt_ PULONG BytesInUnicodeString,
1647  _In_reads_bytes_(BytesInMultiByteString) PSTR MultiByteString,
1648  _In_ ULONG BytesInMultiByteString
1649  );
1650 
1651 NTSYSAPI
1652 NTSTATUS
1653 NTAPI
1655  _Out_ PULONG BytesInUnicodeString,
1656  _In_reads_bytes_(BytesInMultiByteString) PSTR MultiByteString,
1657  _In_ ULONG BytesInMultiByteString
1658  );
1659 
1660 NTSYSAPI
1661 NTSTATUS
1662 NTAPI
1664  _Out_writes_bytes_to_(MaxBytesInMultiByteString, *BytesInMultiByteString) PCHAR MultiByteString,
1665  _In_ ULONG MaxBytesInMultiByteString,
1666  _Out_opt_ PULONG BytesInMultiByteString,
1667  _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1668  _In_ ULONG BytesInUnicodeString
1669  );
1670 
1671 NTSYSAPI
1672 NTSTATUS
1673 NTAPI
1675  _Out_ PULONG BytesInMultiByteString,
1676  _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1677  _In_ ULONG BytesInUnicodeString
1678  );
1679 
1680 NTSYSAPI
1681 NTSTATUS
1682 NTAPI
1684  _Out_writes_bytes_to_(MaxBytesInMultiByteString, *BytesInMultiByteString) PCHAR MultiByteString,
1685  _In_ ULONG MaxBytesInMultiByteString,
1686  _Out_opt_ PULONG BytesInMultiByteString,
1687  _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1688  _In_ ULONG BytesInUnicodeString
1689  );
1690 
1691 NTSYSAPI
1692 NTSTATUS
1693 NTAPI
1695  _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWSTR UnicodeString,
1696  _In_ ULONG MaxBytesInUnicodeString,
1697  _Out_opt_ PULONG BytesInUnicodeString,
1698  _In_reads_bytes_(BytesInOemString) PCH OemString,
1699  _In_ ULONG BytesInOemString
1700  );
1701 
1702 NTSYSAPI
1703 NTSTATUS
1704 NTAPI
1706  _Out_writes_bytes_to_(MaxBytesInOemString, *BytesInOemString) PCHAR OemString,
1707  _In_ ULONG MaxBytesInOemString,
1708  _Out_opt_ PULONG BytesInOemString,
1709  _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1710  _In_ ULONG BytesInUnicodeString
1711  );
1712 
1713 NTSYSAPI
1714 NTSTATUS
1715 NTAPI
1717  _Out_writes_bytes_to_(MaxBytesInOemString, *BytesInOemString) PCHAR OemString,
1718  _In_ ULONG MaxBytesInOemString,
1719  _Out_opt_ PULONG BytesInOemString,
1720  _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1721  _In_ ULONG BytesInUnicodeString
1722  );
1723 
1724 NTSYSAPI
1725 NTSTATUS
1726 NTAPI
1728  _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWCH UnicodeString,
1729  _In_ ULONG MaxBytesInUnicodeString,
1730  _Out_opt_ PULONG BytesInUnicodeString,
1731  _In_reads_bytes_(BytesInMultiByteString) PCH MultiByteString,
1732  _In_ ULONG BytesInMultiByteString,
1733  _Out_ PULONG pdwSpecialChar
1734  );
1735 
1736 #if (PHNT_VERSION >= PHNT_WIN7)
1737 NTSYSAPI
1738 NTSTATUS
1739 NTAPI
1741  _Out_writes_bytes_to_(UnicodeStringMaxByteCount, *UnicodeStringActualByteCount) PWSTR UnicodeStringDestination,
1742  _In_ ULONG UnicodeStringMaxByteCount,
1743  _Out_ PULONG UnicodeStringActualByteCount,
1744  _In_reads_bytes_(UTF8StringByteCount) PCH UTF8StringSource,
1745  _In_ ULONG UTF8StringByteCount
1746  );
1747 #endif
1748 
1749 #if (PHNT_VERSION >= PHNT_WIN7)
1750 NTSYSAPI
1751 NTSTATUS
1752 NTAPI
1754  _Out_writes_bytes_to_(UTF8StringMaxByteCount, *UTF8StringActualByteCount) PCHAR UTF8StringDestination,
1755  _In_ ULONG UTF8StringMaxByteCount,
1756  _Out_ PULONG UTF8StringActualByteCount,
1757  _In_reads_bytes_(UnicodeStringByteCount) PWCH UnicodeStringSource,
1758  _In_ ULONG UnicodeStringByteCount
1759  );
1760 #endif
1761 
1762 NTSYSAPI
1763 NTSTATUS
1764 NTAPI
1766  _In_ PCPTABLEINFO CustomCP,
1767  _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWCH UnicodeString,
1768  _In_ ULONG MaxBytesInUnicodeString,
1769  _Out_opt_ PULONG BytesInUnicodeString,
1770  _In_reads_bytes_(BytesInCustomCPString) PCH CustomCPString,
1771  _In_ ULONG BytesInCustomCPString
1772  );
1773 
1774 NTSYSAPI
1775 NTSTATUS
1776 NTAPI
1778  _In_ PCPTABLEINFO CustomCP,
1779  _Out_writes_bytes_to_(MaxBytesInCustomCPString, *BytesInCustomCPString) PCH CustomCPString,
1780  _In_ ULONG MaxBytesInCustomCPString,
1781  _Out_opt_ PULONG BytesInCustomCPString,
1782  _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1783  _In_ ULONG BytesInUnicodeString
1784  );
1785 
1786 NTSYSAPI
1787 NTSTATUS
1788 NTAPI
1790  _In_ PCPTABLEINFO CustomCP,
1791  _Out_writes_bytes_to_(MaxBytesInCustomCPString, *BytesInCustomCPString) PCH CustomCPString,
1792  _In_ ULONG MaxBytesInCustomCPString,
1793  _Out_opt_ PULONG BytesInCustomCPString,
1794  _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1795  _In_ ULONG BytesInUnicodeString
1796  );
1797 
1798 NTSYSAPI
1799 VOID
1800 NTAPI
1802  _In_ PUSHORT TableBase,
1803  _Out_ PCPTABLEINFO CodePageTable
1804  );
1805 
1806 NTSYSAPI
1807 VOID
1808 NTAPI
1810  _In_ PUSHORT AnsiNlsBase,
1811  _In_ PUSHORT OemNlsBase,
1812  _In_ PUSHORT LanguageNlsBase,
1813  _Out_ PNLSTABLEINFO TableInfo
1814  );
1815 
1816 NTSYSAPI
1817 VOID
1818 NTAPI
1820  _In_ PNLSTABLEINFO TableInfo
1821  );
1822 
1823 NTSYSAPI
1824 BOOLEAN
1825 NTAPI
1827  _In_ PVOID Buffer,
1828  _In_ ULONG Size,
1829  _Inout_opt_ PULONG Result
1830  );
1831 
1832 typedef enum _RTL_NORM_FORM
1833 {
1834  NormOther = 0x0,
1835  NormC = 0x1,
1836  NormD = 0x2,
1837  NormKC = 0x5,
1838  NormKD = 0x6,
1839  NormIdna = 0xd,
1846 } RTL_NORM_FORM;
1847 
1848 #if (PHNT_VERSION >= PHNT_VISTA)
1849 NTSYSAPI
1850 NTSTATUS
1851 NTAPI
1853  _In_ ULONG NormForm, // RTL_NORM_FORM
1854  _In_ PCWSTR SourceString,
1855  _In_ LONG SourceStringLength,
1856  _Out_writes_to_(*DestinationStringLength, *DestinationStringLength) PWSTR DestinationString,
1857  _Inout_ PLONG DestinationStringLength
1858  );
1859 #endif
1860 
1861 #if (PHNT_VERSION >= PHNT_VISTA)
1862 NTSYSAPI
1863 NTSTATUS
1864 NTAPI
1866  _In_ ULONG NormForm, // RTL_NORM_FORM
1867  _In_ PCWSTR SourceString,
1868  _In_ LONG SourceStringLength,
1869  _Out_ PBOOLEAN Normalized
1870  );
1871 #endif
1872 
1873 #if (PHNT_VERSION >= PHNT_WIN7)
1874 // ntifs:FsRtlIsNameInExpression
1875 NTSYSAPI
1876 BOOLEAN
1877 NTAPI
1879  _In_ PUNICODE_STRING Expression,
1880  _In_ PUNICODE_STRING Name,
1881  _In_ BOOLEAN IgnoreCase,
1882  _In_opt_ PWCH UpcaseTable
1883  );
1884 #endif
1885 
1886 NTSYSAPI
1887 BOOLEAN
1888 NTAPI
1890  _In_ PUNICODE_STRING String1,
1891  _In_ PUNICODE_STRING String2
1892  );
1893 
1894 NTSYSAPI
1895 BOOLEAN
1896 NTAPI
1898  _In_ PUNICODE_STRING String1,
1899  _In_ PUNICODE_STRING String2
1900  );
1901 
1902 NTSYSAPI
1903 NTSTATUS
1904 NTAPI
1906  _Out_ PUNICODE_STRING ComputerNameString,
1907  _In_ PCUNICODE_STRING DnsHostNameString,
1908  _In_ BOOLEAN AllocateComputerNameString
1909  );
1910 
1911 NTSYSAPI
1912 NTSTATUS
1913 NTAPI
1915  _In_ PGUID Guid,
1916  _Out_ PUNICODE_STRING GuidString
1917  );
1918 
1919 NTSYSAPI
1920 NTSTATUS
1921 NTAPI
1923  _In_ PUNICODE_STRING GuidString,
1924  _Out_ PGUID Guid
1925  );
1926 
1927 #if (PHNT_VERSION >= PHNT_VISTA)
1928 NTSYSAPI
1929 LONG
1930 NTAPI
1932  _In_ PUNICODE_STRING Altitude1,
1933  _In_ PUNICODE_STRING Altitude2
1934  );
1935 #endif
1936 
1937 // Prefix
1938 
1939 typedef struct _PREFIX_TABLE_ENTRY
1940 {
1947 
1948 typedef struct _PREFIX_TABLE
1949 {
1952  PPREFIX_TABLE_ENTRY NextPrefixTree;
1954 
1955 NTSYSAPI
1956 VOID
1957 NTAPI
1959  _Out_ PPREFIX_TABLE PrefixTable
1960  );
1961 
1962 NTSYSAPI
1963 BOOLEAN
1964 NTAPI
1966  _In_ PPREFIX_TABLE PrefixTable,
1967  _In_ PSTRING Prefix,
1968  _Out_ PPREFIX_TABLE_ENTRY PrefixTableEntry
1969  );
1970 
1971 NTSYSAPI
1972 VOID
1973 NTAPI
1975  _In_ PPREFIX_TABLE PrefixTable,
1976  _In_ PPREFIX_TABLE_ENTRY PrefixTableEntry
1977  );
1978 
1979 NTSYSAPI
1980 PPREFIX_TABLE_ENTRY
1981 NTAPI
1983  _In_ PPREFIX_TABLE PrefixTable,
1984  _In_ PSTRING FullName
1985  );
1986 
1988 {
1996 
1998 {
2001  PUNICODE_PREFIX_TABLE_ENTRY NextPrefixTree;
2002  PUNICODE_PREFIX_TABLE_ENTRY LastNextEntry;
2004 
2005 NTSYSAPI
2006 VOID
2007 NTAPI
2009  _Out_ PUNICODE_PREFIX_TABLE PrefixTable
2010  );
2011 
2012 NTSYSAPI
2013 BOOLEAN
2014 NTAPI
2016  _In_ PUNICODE_PREFIX_TABLE PrefixTable,
2017  _In_ PUNICODE_STRING Prefix,
2018  _Out_ PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
2019  );
2020 
2021 NTSYSAPI
2022 VOID
2023 NTAPI
2025  _In_ PUNICODE_PREFIX_TABLE PrefixTable,
2026  _In_ PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
2027  );
2028 
2029 NTSYSAPI
2030 PUNICODE_PREFIX_TABLE_ENTRY
2031 NTAPI
2033  _In_ PUNICODE_PREFIX_TABLE PrefixTable,
2034  _In_ PUNICODE_STRING FullName,
2035  _In_ ULONG CaseInsensitiveIndex
2036  );
2037 
2038 NTSYSAPI
2039 PUNICODE_PREFIX_TABLE_ENTRY
2040 NTAPI
2042  _In_ PUNICODE_PREFIX_TABLE PrefixTable,
2043  _In_ BOOLEAN Restart
2044  );
2045 
2046 // Compression
2047 
2049 {
2050  USHORT CompressionFormatAndEngine; // COMPRESSION_FORMAT_* and COMPRESSION_ENGINE_*
2051 
2053  UCHAR ChunkShift;
2055  UCHAR Reserved;
2056 
2058 
2061 
2062 NTSYSAPI
2063 NTSTATUS
2064 NTAPI
2066  _In_ USHORT CompressionFormatAndEngine,
2067  _Out_ PULONG CompressBufferWorkSpaceSize,
2068  _Out_ PULONG CompressFragmentWorkSpaceSize
2069  );
2070 
2071 NTSYSAPI
2072 NTSTATUS
2073 NTAPI
2075  _In_ USHORT CompressionFormatAndEngine,
2076  _In_reads_bytes_(UncompressedBufferSize) PUCHAR UncompressedBuffer,
2077  _In_ ULONG UncompressedBufferSize,
2078  _Out_writes_bytes_to_(CompressedBufferSize, *FinalCompressedSize) PUCHAR CompressedBuffer,
2079  _In_ ULONG CompressedBufferSize,
2080  _In_ ULONG UncompressedChunkSize,
2081  _Out_ PULONG FinalCompressedSize,
2082  _In_ PVOID WorkSpace
2083  );
2084 
2085 NTSYSAPI
2086 NTSTATUS
2087 NTAPI
2089  _In_ USHORT CompressionFormat,
2090  _Out_writes_bytes_to_(UncompressedBufferSize, *FinalUncompressedSize) PUCHAR UncompressedBuffer,
2091  _In_ ULONG UncompressedBufferSize,
2092  _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2093  _In_ ULONG CompressedBufferSize,
2094  _Out_ PULONG FinalUncompressedSize
2095  );
2096 
2097 #if (PHNT_VERSION >= PHNT_WIN8)
2098 NTSYSAPI
2099 NTSTATUS
2100 NTAPI
2102  _In_ USHORT CompressionFormat,
2103  _Out_writes_bytes_to_(UncompressedBufferSize, *FinalUncompressedSize) PUCHAR UncompressedBuffer,
2104  _In_ ULONG UncompressedBufferSize,
2105  _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2106  _In_ ULONG CompressedBufferSize,
2107  _Out_ PULONG FinalUncompressedSize,
2108  _In_ PVOID WorkSpace
2109  );
2110 #endif
2111 
2112 NTSYSAPI
2113 NTSTATUS
2114 NTAPI
2116  _In_ USHORT CompressionFormat,
2117  _Out_writes_bytes_to_(UncompressedFragmentSize, *FinalUncompressedSize) PUCHAR UncompressedFragment,
2118  _In_ ULONG UncompressedFragmentSize,
2119  _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2120  _In_ ULONG CompressedBufferSize,
2121  _In_range_(<, CompressedBufferSize) ULONG FragmentOffset,
2122  _Out_ PULONG FinalUncompressedSize,
2123  _In_ PVOID WorkSpace
2124  );
2125 
2126 NTSYSAPI
2127 NTSTATUS
2128 NTAPI
2130  _In_ USHORT CompressionFormat,
2131  _Inout_ PUCHAR *CompressedBuffer,
2132  _In_ PUCHAR EndOfCompressedBufferPlus1,
2133  _Out_ PUCHAR *ChunkBuffer,
2134  _Out_ PULONG ChunkSize
2135  );
2136 
2137 NTSYSAPI
2138 NTSTATUS
2139 NTAPI
2141  _In_ USHORT CompressionFormat,
2142  _Inout_ PUCHAR *CompressedBuffer,
2143  _In_ PUCHAR EndOfCompressedBufferPlus1,
2144  _Out_ PUCHAR *ChunkBuffer,
2145  _In_ ULONG ChunkSize
2146  );
2147 
2148 NTSYSAPI
2149 NTSTATUS
2150 NTAPI
2152  _Out_writes_bytes_(UncompressedBufferSize) PUCHAR UncompressedBuffer,
2153  _In_ ULONG UncompressedBufferSize,
2154  _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2155  _In_ ULONG CompressedBufferSize,
2156  _In_reads_bytes_(CompressedTailSize) PUCHAR CompressedTail,
2157  _In_ ULONG CompressedTailSize,
2158  _In_ PCOMPRESSED_DATA_INFO CompressedDataInfo
2159  );
2160 
2161 NTSYSAPI
2162 NTSTATUS
2163 NTAPI
2165  _In_reads_bytes_(UncompressedBufferSize) PUCHAR UncompressedBuffer,
2166  _In_ ULONG UncompressedBufferSize,
2167  _Out_writes_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2168  _In_range_(>=, (UncompressedBufferSize - (UncompressedBufferSize / 16))) ULONG CompressedBufferSize,
2169  _Inout_updates_bytes_(CompressedDataInfoLength) PCOMPRESSED_DATA_INFO CompressedDataInfo,
2170  _In_range_(>, sizeof(COMPRESSED_DATA_INFO)) ULONG CompressedDataInfoLength,
2171  _In_ PVOID WorkSpace
2172  );
2173 
2174 // Locale
2175 
2176 #if (PHNT_VERSION >= PHNT_VISTA)
2177 
2178 // private
2179 NTSYSAPI
2180 NTSTATUS
2181 NTAPI
2183  _In_ LCID LcidValue,
2184  _In_ ULONG Base,
2185  _In_ ULONG Padding, // string is padded to this width
2186  _Out_writes_(Size) PWSTR pResultBuf,
2187  _In_ ULONG Size
2188  );
2189 
2190 // private
2191 NTSYSAPI
2192 BOOLEAN
2193 NTAPI
2195  _In_ PWSTR LocaleName,
2196  _In_ ULONG Flags
2197  );
2198 
2199 // private
2200 NTSYSAPI
2201 NTSTATUS
2202 NTAPI
2204  _In_ PWSTR LocaleName,
2205  _Inout_ PUNICODE_STRING ParentLocaleName,
2206  _In_ ULONG Flags,
2207  _In_ BOOLEAN AllocateDestinationString
2208  );
2209 
2210 // private
2211 NTSYSAPI
2212 NTSTATUS
2213 NTAPI
2215  _In_ LCID lcid, // sic
2216  _Inout_ PUNICODE_STRING LocaleName,
2217  _In_ ULONG Flags,
2218  _In_ BOOLEAN AllocateDestinationString
2219  );
2220 
2221 // private
2222 NTSYSAPI
2223 NTSTATUS
2224 NTAPI
2226  _In_ PWSTR LocaleName,
2227  _Out_ PLCID lcid,
2228  _In_ ULONG Flags
2229  );
2230 
2231 // private
2232 NTSYSAPI
2233 BOOLEAN
2234 NTAPI
2236  _In_ LCID Lcid,
2237  _Inout_ PUNICODE_STRING String
2238  );
2239 
2240 // private
2241 NTSYSAPI
2242 BOOLEAN
2243 NTAPI
2245  _In_ PUNICODE_STRING String,
2246  _Out_ PLCID Lcid
2247  );
2248 
2249 // private
2250 NTSYSAPI
2251 VOID
2252 NTAPI
2254  VOID
2255  );
2256 
2257 #endif
2258 
2259 #if (PHNT_VERSION >= PHNT_WIN7)
2260 
2261 // rev
2262 NTSYSAPI
2263 NTSTATUS
2264 NTAPI
2266  _Out_ PVOID *BaseAddress,
2267  _Out_ PLCID DefaultLocaleId,
2268  _Out_ PLARGE_INTEGER DefaultCasingTableSize
2269  );
2270 
2271 #endif
2272 
2273 // PEB
2274 
2275 NTSYSAPI
2276 VOID
2277 NTAPI
2279  VOID
2280  );
2281 
2282 NTSYSAPI
2283 VOID
2284 NTAPI
2286  VOID
2287  );
2288 
2289 #if (PHNT_VERSION >= PHNT_VISTA)
2290 // private
2291 NTSYSAPI
2292 LOGICAL
2293 NTAPI
2295  VOID
2296  );
2297 #endif
2298 
2299 NTSYSAPI
2300 NTSTATUS
2301 NTAPI
2303  _In_ ULONG Size,
2304  _Out_ PVOID *Block
2305  );
2306 
2307 NTSYSAPI
2308 NTSTATUS
2309 NTAPI
2310 RtlFreeToPeb(
2311  _In_ PVOID Block,
2312  _In_ ULONG Size
2313  );
2314 
2315 // Processes
2316 
2317 #define DOS_MAX_COMPONENT_LENGTH 255
2318 #define DOS_MAX_PATH_LENGTH (DOS_MAX_COMPONENT_LENGTH + 5)
2319 
2320 typedef struct _CURDIR
2321 {
2323  HANDLE Handle;
2324 } CURDIR, *PCURDIR;
2325 
2326 #define RTL_USER_PROC_CURDIR_CLOSE 0x00000002
2327 #define RTL_USER_PROC_CURDIR_INHERIT 0x00000003
2328 
2330 {
2331  USHORT Flags;
2332  USHORT Length;
2333  ULONG TimeStamp;
2336 
2337 #define RTL_MAX_DRIVE_LETTERS 32
2338 #define RTL_DRIVE_LETTER_VALID (USHORT)0x0001
2339 
2341 {
2343  ULONG Length;
2344 
2345  ULONG Flags;
2346  ULONG DebugFlags;
2347 
2353 
2359 
2360  ULONG StartingX;
2361  ULONG StartingY;
2362  ULONG CountX;
2363  ULONG CountY;
2367 
2375 
2382 
2383 #define RTL_USER_PROC_PARAMS_NORMALIZED 0x00000001
2384 #define RTL_USER_PROC_PROFILE_USER 0x00000002
2385 #define RTL_USER_PROC_PROFILE_KERNEL 0x00000004
2386 #define RTL_USER_PROC_PROFILE_SERVER 0x00000008
2387 #define RTL_USER_PROC_RESERVE_1MB 0x00000020
2388 #define RTL_USER_PROC_RESERVE_16MB 0x00000040
2389 #define RTL_USER_PROC_CASE_SENSITIVE 0x00000080
2390 #define RTL_USER_PROC_DISABLE_HEAP_DECOMMIT 0x00000100
2391 #define RTL_USER_PROC_DLL_REDIRECTION_LOCAL 0x00001000
2392 #define RTL_USER_PROC_APP_MANIFEST_PRESENT 0x00002000
2393 #define RTL_USER_PROC_IMAGE_KEY_MISSING 0x00004000
2394 #define RTL_USER_PROC_OPTIN_PROCESS 0x00020000
2395 
2396 NTSYSAPI
2397 NTSTATUS
2398 NTAPI
2400  _Out_ PRTL_USER_PROCESS_PARAMETERS *pProcessParameters,
2401  _In_ PUNICODE_STRING ImagePathName,
2402  _In_opt_ PUNICODE_STRING DllPath,
2403  _In_opt_ PUNICODE_STRING CurrentDirectory,
2404  _In_opt_ PUNICODE_STRING CommandLine,
2405  _In_opt_ PVOID Environment,
2406  _In_opt_ PUNICODE_STRING WindowTitle,
2407  _In_opt_ PUNICODE_STRING DesktopInfo,
2408  _In_opt_ PUNICODE_STRING ShellInfo,
2409  _In_opt_ PUNICODE_STRING RuntimeData
2410  );
2411 
2412 #if (PHNT_VERSION >= PHNT_VISTA)
2413 // private
2414 NTSYSAPI
2415 NTSTATUS
2416 NTAPI
2418  _Out_ PRTL_USER_PROCESS_PARAMETERS *pProcessParameters,
2419  _In_ PUNICODE_STRING ImagePathName,
2420  _In_opt_ PUNICODE_STRING DllPath,
2421  _In_opt_ PUNICODE_STRING CurrentDirectory,
2422  _In_opt_ PUNICODE_STRING CommandLine,
2423  _In_opt_ PVOID Environment,
2424  _In_opt_ PUNICODE_STRING WindowTitle,
2425  _In_opt_ PUNICODE_STRING DesktopInfo,
2426  _In_opt_ PUNICODE_STRING ShellInfo,
2427  _In_opt_ PUNICODE_STRING RuntimeData,
2428  _In_ ULONG Flags // pass RTL_USER_PROC_PARAMS_NORMALIZED to keep parameters normalized
2429  );
2430 #endif
2431 
2432 NTSYSAPI
2433 NTSTATUS
2434 NTAPI
2436  _In_ _Post_invalid_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters
2437  );
2438 
2439 NTSYSAPI
2440 PRTL_USER_PROCESS_PARAMETERS
2441 NTAPI
2443  _Inout_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters
2444  );
2445 
2446 NTSYSAPI
2447 PRTL_USER_PROCESS_PARAMETERS
2448 NTAPI
2450  _Inout_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters
2451  );
2452 
2454 {
2455  ULONG Length;
2456  HANDLE Process;
2457  HANDLE Thread;
2461 
2462 // private
2463 NTSYSAPI
2464 NTSTATUS
2465 NTAPI
2467  _In_ PUNICODE_STRING NtImagePathName,
2468  _In_ ULONG AttributesDeprecated,
2469  _In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
2470  _In_opt_ PSECURITY_DESCRIPTOR ProcessSecurityDescriptor,
2471  _In_opt_ PSECURITY_DESCRIPTOR ThreadSecurityDescriptor,
2472  _In_opt_ HANDLE ParentProcess,
2473  _In_ BOOLEAN InheritHandles,
2474  _In_opt_ HANDLE DebugPort,
2475  _In_opt_ HANDLE TokenHandle, // used to be ExceptionPort
2476  _Out_ PRTL_USER_PROCESS_INFORMATION ProcessInformation
2477  );
2478 
2479 #if (PHNT_VERSION >= PHNT_VISTA)
2480 DECLSPEC_NORETURN
2481 NTSYSAPI
2482 VOID
2483 NTAPI
2485  _In_ NTSTATUS ExitStatus
2486  );
2487 #else
2488 
2489 #define RtlExitUserProcess RtlExitUserProcess_R
2490 
2491 DECLSPEC_NORETURN
2492 FORCEINLINE VOID RtlExitUserProcess_R(
2493  _In_ NTSTATUS ExitStatus
2494  )
2495 {
2496  ExitProcess(ExitStatus);
2497 }
2498 
2499 #endif
2500 
2501 #if (PHNT_VERSION >= PHNT_VISTA)
2502 
2503 // begin_rev
2504 #define RTL_CLONE_PROCESS_FLAGS_CREATE_SUSPENDED 0x00000001
2505 #define RTL_CLONE_PROCESS_FLAGS_INHERIT_HANDLES 0x00000002
2506 #define RTL_CLONE_PROCESS_FLAGS_NO_SYNCHRONIZE 0x00000004 // don't update synchronization objects
2507 // end_rev
2508 
2509 // private
2510 NTSYSAPI
2511 NTSTATUS
2512 NTAPI
2514  _In_ ULONG ProcessFlags,
2515  _In_opt_ PSECURITY_DESCRIPTOR ProcessSecurityDescriptor,
2516  _In_opt_ PSECURITY_DESCRIPTOR ThreadSecurityDescriptor,
2517  _In_opt_ HANDLE DebugPort,
2518  _Out_ PRTL_USER_PROCESS_INFORMATION ProcessInformation
2519  );
2520 
2521 // private
2522 NTSYSAPI
2523 VOID
2524 NTAPI
2526  _Inout_ PRTL_CRITICAL_SECTION CriticalSection
2527  );
2528 
2529 // private
2530 NTSYSAPI
2531 VOID
2532 NTAPI
2534  _Inout_ PRTL_SRWLOCK SRWLock,
2535  _In_ LOGICAL Shared // TRUE to set to shared acquire
2536  );
2537 
2538 // private
2540 {
2545 
2546 #if (PHNT_VERSION >= PHNT_WIN7)
2547 // rev
2548 NTSYSAPI
2549 NTSTATUS
2550 NTAPI
2552  _In_ HANDLE ProcessHandle,
2553  _In_ ULONG Flags,
2554  _In_opt_ PVOID StartRoutine,
2555  _In_opt_ PVOID StartContext,
2556  _In_opt_ HANDLE EventHandle,
2557  _Out_opt_ PRTLP_PROCESS_REFLECTION_REFLECTION_INFORMATION ReflectionInformation
2558  );
2559 #endif
2560 
2561 #endif
2562 
2563 NTSYSAPI
2564 NTSTATUS
2565 STDAPIVCALLTYPE
2567  _In_ BOOLEAN NewValue,
2568  _Out_opt_ PBOOLEAN OldValue,
2569  _In_ BOOLEAN CheckFlag
2570  );
2571 
2572 NTSYSAPI
2573 NTSTATUS
2574 STDAPIVCALLTYPE
2576  _In_ BOOLEAN NewValue,
2577  _Out_opt_ PBOOLEAN OldValue,
2578  _In_ BOOLEAN CheckFlag
2579  );
2580 
2581 // Threads
2582 
2583 typedef NTSTATUS (NTAPI *PUSER_THREAD_START_ROUTINE)(
2584  _In_ PVOID ThreadParameter
2585  );
2586 
2587 NTSYSAPI
2588 NTSTATUS
2589 NTAPI
2591  _In_ HANDLE Process,
2592  _In_opt_ PSECURITY_DESCRIPTOR ThreadSecurityDescriptor,
2593  _In_ BOOLEAN CreateSuspended,
2594  _In_opt_ ULONG ZeroBits,
2595  _In_opt_ SIZE_T MaximumStackSize,
2596  _In_opt_ SIZE_T CommittedStackSize,
2597  _In_ PUSER_THREAD_START_ROUTINE StartAddress,
2598  _In_opt_ PVOID Parameter,
2599  _Out_opt_ PHANDLE Thread,
2600  _Out_opt_ PCLIENT_ID ClientId
2601  );
2602 
2603 #if (PHNT_VERSION >= PHNT_VISTA) // should be PHNT_WINXP, but is PHNT_VISTA for consistency with RtlExitUserProcess
2604 DECLSPEC_NORETURN
2605 NTSYSAPI
2606 VOID
2607 NTAPI
2609  _In_ NTSTATUS ExitStatus
2610  );
2611 #else
2612 
2613 #define RtlExitUserThread RtlExitUserThread_R
2614 
2615 DECLSPEC_NORETURN
2616 FORCEINLINE VOID RtlExitUserThread_R(
2617  _In_ NTSTATUS ExitStatus
2618  )
2619 {
2620  ExitThread(ExitStatus);
2621 }
2622 
2623 #endif
2624 
2625 #if (PHNT_VERSION >= PHNT_VISTA)
2626 
2627 // private
2628 NTSYSAPI
2629 NTSTATUS
2630 NTAPI
2632  _In_opt_ SIZE_T CommittedStackSize,
2633  _In_opt_ SIZE_T MaximumStackSize,
2634  _In_opt_ ULONG_PTR ZeroBits,
2635  _In_ SIZE_T PageSize,
2636  _In_ ULONG_PTR ReserveAlignment,
2637  _Out_ PINITIAL_TEB InitialTeb
2638  );
2639 
2640 // private
2641 NTSYSAPI
2642 NTSTATUS
2643 NTAPI
2645  _In_ PVOID AllocationBase
2646  );
2647 
2648 #endif
2649 
2650 NTSYSAPI
2651 VOID
2652 NTAPI
2654  _In_ HANDLE Process,
2655  _Out_ PCONTEXT Context,
2656  _In_opt_ PVOID Parameter,
2657  _In_opt_ PVOID InitialPc,
2658  _In_opt_ PVOID InitialSp
2659  );
2660 
2661 NTSYSAPI
2662 NTSTATUS
2663 NTAPI
2665  _In_ HANDLE Process,
2666  _In_ HANDLE Thread,
2667  _In_ PVOID CallSite,
2668  _In_ ULONG ArgumentCount,
2669  _In_opt_ PULONG_PTR Arguments,
2670  _In_ BOOLEAN PassContext,
2671  _In_ BOOLEAN AlreadySuspended
2672  );
2673 
2674 #ifdef _WIN64
2675 // rev
2676 NTSYSAPI
2677 NTSTATUS
2678 NTAPI
2679 RtlWow64GetThreadContext(
2680  _In_ HANDLE ThreadHandle,
2681  _Inout_ PWOW64_CONTEXT ThreadContext
2682  );
2683 #endif
2684 
2685 #ifdef _WIN64
2686 // rev
2687 NTSYSAPI
2688 NTSTATUS
2689 NTAPI
2690 RtlWow64SetThreadContext(
2691  _In_ HANDLE ThreadHandle,
2692  _In_ PWOW64_CONTEXT ThreadContext
2693  );
2694 #endif
2695 
2696 // Runtime exception handling
2697 
2698 #ifdef _WIN64
2699 
2700 // private
2701 typedef enum _FUNCTION_TABLE_TYPE
2702 {
2703  RF_SORTED,
2704  RF_UNSORTED,
2705  RF_CALLBACK,
2706  RF_KERNEL_DYNAMIC
2707 } FUNCTION_TABLE_TYPE;
2708 
2709 // private
2710 typedef struct _DYNAMIC_FUNCTION_TABLE
2711 {
2712  LIST_ENTRY ListEntry;
2713  PRUNTIME_FUNCTION FunctionTable;
2714  LARGE_INTEGER TimeStamp;
2715  ULONG64 MinimumAddress;
2716  ULONG64 MaximumAddress;
2717  ULONG64 BaseAddress;
2718  PGET_RUNTIME_FUNCTION_CALLBACK Callback;
2719  PVOID Context;
2720  PWSTR OutOfProcessCallbackDll;
2721  FUNCTION_TABLE_TYPE Type;
2722  ULONG EntryCount;
2723 } DYNAMIC_FUNCTION_TABLE, *PDYNAMIC_FUNCTION_TABLE;
2724 
2725 // rev
2726 NTSYSAPI
2727 PLIST_ENTRY
2728 NTAPI
2729 RtlGetFunctionTableListHead(
2730  VOID
2731  );
2732 
2733 #endif
2734 
2735 // Images
2736 
2737 NTSYSAPI
2738 PVOID
2739 NTAPI
2741  _In_ PVOID PcValue,
2742  _Out_ PVOID *BaseOfImage
2743  );
2744 
2745 NTSYSAPI
2746 PIMAGE_NT_HEADERS
2747 NTAPI
2749  _In_ PVOID Base
2750  );
2751 
2752 #define RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK 0x00000001
2753 
2754 NTSYSAPI
2755 NTSTATUS
2756 NTAPI
2758  _In_ ULONG Flags,
2759  _In_ PVOID Base,
2760  _In_ ULONG64 Size,
2761  _Out_ PIMAGE_NT_HEADERS *OutHeaders
2762  );
2763 
2764 NTSYSAPI
2765 PVOID
2766 NTAPI
2768  _In_ PIMAGE_NT_HEADERS NtHeaders,
2769  _In_ PVOID BaseOfImage,
2770  _In_ ULONG VirtualAddress
2771  );
2772 
2773 NTSYSAPI
2774 PIMAGE_SECTION_HEADER
2775 NTAPI
2777  _In_ PIMAGE_NT_HEADERS NtHeaders,
2778  _In_ PVOID BaseOfImage,
2779  _In_ ULONG VirtualAddress
2780  );
2781 
2782 NTSYSAPI
2783 PVOID
2784 NTAPI
2786  _In_ PVOID BaseOfImage,
2787  _In_ BOOLEAN MappedAsImage,
2788  _In_ USHORT DirectoryEntry,
2789  _Out_ PULONG Size
2790  );
2791 
2792 NTSYSAPI
2793 PIMAGE_SECTION_HEADER
2794 NTAPI
2796  _In_ PIMAGE_NT_HEADERS NtHeaders,
2797  _In_ PVOID Base,
2798  _In_ ULONG Rva
2799  );
2800 
2801 NTSYSAPI
2802 PVOID
2803 NTAPI
2805  _In_ PIMAGE_NT_HEADERS NtHeaders,
2806  _In_ PVOID Base,
2807  _In_ ULONG Rva,
2808  _Inout_opt_ PIMAGE_SECTION_HEADER *LastRvaSection
2809  );
2810 
2811 // Memory
2812 
2813 NTSYSAPI
2814 SIZE_T
2815 NTAPI
2817  _In_ PVOID Source,
2818  _In_ SIZE_T Length,
2819  _In_ ULONG Pattern
2820  );
2821 
2822 NTSYSAPI
2823 VOID
2824 NTAPI
2826  _Out_ PVOID Destination,
2827  _In_ SIZE_T Length,
2828  _In_ ULONG Pattern
2829  );
2830 
2831 NTSYSAPI
2832 VOID
2833 NTAPI
2835  _Out_ PVOID Destination,
2836  _In_ SIZE_T Length,
2837  _In_ ULONGLONG Pattern
2838  );
2839 
2840 // Environment
2841 
2842 NTSYSAPI
2843 NTSTATUS
2844 NTAPI
2846  _In_ BOOLEAN CloneCurrentEnvironment,
2847  _Out_ PVOID *Environment
2848  );
2849 
2850 // begin_rev
2851 #define RTL_CREATE_ENVIRONMENT_TRANSLATE 0x1 // translate from multi-byte to Unicode
2852 #define RTL_CREATE_ENVIRONMENT_TRANSLATE_FROM_OEM 0x2 // translate from OEM to Unicode (Translate flag must also be set)
2853 #define RTL_CREATE_ENVIRONMENT_EMPTY 0x4 // create empty environment block
2854 // end_rev
2855 
2856 #if (PHNT_VERSION >= PHNT_VISTA)
2857 // private
2858 NTSYSAPI
2859 NTSTATUS
2860 NTAPI
2862  _In_ PVOID SourceEnv,
2863  _Out_ PVOID *Environment,
2864  _In_ ULONG Flags
2865  );
2866 #endif
2867 
2868 NTSYSAPI
2869 NTSTATUS
2870 NTAPI
2872  _In_ PVOID Environment
2873  );
2874 
2875 NTSYSAPI
2876 NTSTATUS
2877 NTAPI
2879  _In_ PVOID Environment,
2880  _Out_opt_ PVOID *PreviousEnvironment
2881  );
2882 
2883 #if (PHNT_VERSION >= PHNT_VISTA)
2884 // private
2885 NTSYSAPI
2886 NTSTATUS
2887 NTAPI
2889  _In_opt_ PWSTR *Environment,
2890  _In_reads_(NameLength) PWSTR Name,
2891  _In_ SIZE_T NameLength,
2892  _In_reads_(ValueLength) PWSTR Value,
2893  _In_ SIZE_T ValueLength
2894  );
2895 #endif
2896 
2897 NTSYSAPI
2898 NTSTATUS
2899 NTAPI
2901  _In_opt_ PVOID *Environment,
2902  _In_ PUNICODE_STRING Name,
2903  _In_ PUNICODE_STRING Value
2904  );
2905 
2906 #if (PHNT_VERSION >= PHNT_VISTA)
2907 // private
2908 NTSYSAPI
2909 NTSTATUS
2910 NTAPI
2912  _In_opt_ PVOID Environment,
2913  _In_reads_(NameLength) PWSTR Name,
2914  _In_ SIZE_T NameLength,
2915  _Out_writes_(ValueLength) PWSTR Value,
2916  _In_ SIZE_T ValueLength,
2917  _Out_ PSIZE_T ReturnLength
2918  );
2919 #endif
2920 
2921 NTSYSAPI
2922 NTSTATUS
2923 NTAPI
2925  _In_opt_ PVOID Environment,
2926  _In_ PUNICODE_STRING Name,
2927  _Out_ PUNICODE_STRING Value
2928  );
2929 
2930 #if (PHNT_VERSION >= PHNT_VISTA)
2931 // private
2932 NTSYSAPI
2933 NTSTATUS
2934 NTAPI
2936  _In_opt_ PVOID Environment,
2937  _In_reads_(SrcLength) PWSTR Src,
2938  _In_ SIZE_T SrcLength,
2939  _Out_writes_(DstLength) PWSTR Dst,
2940  _In_ SIZE_T DstLength,
2941  _Out_opt_ PSIZE_T ReturnLength
2942  );
2943 #endif
2944 
2945 NTSYSAPI
2946 NTSTATUS
2947 NTAPI
2949  _In_opt_ PVOID Environment,
2950  _In_ PUNICODE_STRING Source,
2951  _Out_ PUNICODE_STRING Destination,
2952  _Out_opt_ PULONG ReturnedLength
2953  );
2954 
2955 NTSYSAPI
2956 NTSTATUS
2957 NTAPI
2959  _In_ PWCHAR NewEnvironment,
2960  _In_ SIZE_T NewEnvironmentSize
2961  );
2962 
2963 // Current directory and paths
2964 
2965 typedef struct _RTLP_CURDIR_REF *PRTLP_CURDIR_REF;
2966 
2967 typedef struct _RTL_RELATIVE_NAME_U
2968 {
2971  PRTLP_CURDIR_REF CurDirRef;
2973 
2974 typedef enum _RTL_PATH_TYPE
2975 {
2984 } RTL_PATH_TYPE;
2985 
2986 NTSYSAPI
2988 NTAPI
2990  _In_ PWSTR DosFileName
2991  );
2992 
2993 NTSYSAPI
2994 ULONG
2995 NTAPI
2997  _In_ PWSTR DosFileName
2998  );
2999 
3000 NTSYSAPI
3001 ULONG
3002 NTAPI
3004  _In_ PWSTR FileName,
3005  _In_ ULONG BufferLength,
3006  _Out_writes_bytes_(BufferLength) PWSTR Buffer,
3007  _Out_opt_ PWSTR *FilePart
3008  );
3009 
3010 #if (PHNT_VERSION >= PHNT_WIN7)
3011 // rev
3012 NTSYSAPI
3013 NTSTATUS
3014 NTAPI
3016  _In_ PWSTR FileName,
3017  _In_ ULONG BufferLength,
3018  _Out_writes_bytes_(BufferLength) PWSTR Buffer,
3019  _Out_opt_ PWSTR *FilePart,
3020  _Out_opt_ RTL_PATH_TYPE *InputPathType
3021  );
3022 #endif
3023 
3024 #if (PHNT_VERSION >= PHNT_WS03)
3025 NTSYSAPI
3026 NTSTATUS
3027 NTAPI
3029  _In_ PUNICODE_STRING FileName,
3030  _Inout_ PUNICODE_STRING StaticString,
3031  _Out_opt_ PUNICODE_STRING DynamicString,
3032  _Out_opt_ PUNICODE_STRING *StringUsed,
3033  _Out_opt_ SIZE_T *FilePartPrefixCch,
3034  _Out_opt_ PBOOLEAN NameInvalid,
3035  _Out_ RTL_PATH_TYPE *InputPathType,
3036  _Out_opt_ SIZE_T *BytesRequired
3037  );
3038 #endif
3039 
3040 NTSYSAPI
3041 ULONG
3042 NTAPI
3044  _In_ ULONG BufferLength,
3045  _Out_writes_bytes_(BufferLength) PWSTR Buffer
3046  );
3047 
3048 NTSYSAPI
3049 NTSTATUS
3050 NTAPI
3052  _In_ PUNICODE_STRING PathName
3053  );
3054 
3055 NTSYSAPI
3056 ULONG
3057 NTAPI
3059  VOID
3060  );
3061 
3062 NTSYSAPI
3063 BOOLEAN
3064 NTAPI
3066  _In_ PWSTR DosFileName,
3067  _Out_ PUNICODE_STRING NtFileName,
3068  _Out_opt_ PWSTR *FilePart,
3069  _Out_opt_ PRTL_RELATIVE_NAME_U RelativeName
3070  );
3071 
3072 #if (PHNT_VERSION >= PHNT_WS03)
3073 NTSYSAPI
3074 NTSTATUS
3075 NTAPI
3077  _In_ PWSTR DosFileName,
3078  _Out_ PUNICODE_STRING NtFileName,
3079  _Out_opt_ PWSTR *FilePart,
3080  _Out_opt_ PRTL_RELATIVE_NAME_U RelativeName
3081  );
3082 #endif
3083 
3084 #if (PHNT_VERSION >= PHNT_WS03)
3085 NTSYSAPI
3086 BOOLEAN
3087 NTAPI
3089  _In_ PWSTR DosFileName,
3090  _Out_ PUNICODE_STRING NtFileName,
3091  _Out_opt_ PWSTR *FilePart,
3092  _Out_opt_ PRTL_RELATIVE_NAME_U RelativeName
3093  );
3094 #endif
3095 
3096 #if (PHNT_VERSION >= PHNT_WS03)
3097 NTSYSAPI
3098 NTSTATUS
3099 NTAPI
3101  _In_ PWSTR DosFileName,
3102  _Out_ PUNICODE_STRING NtFileName,
3103  _Out_opt_ PWSTR *FilePart,
3104  _Out_opt_ PRTL_RELATIVE_NAME_U RelativeName
3105  );
3106 #endif
3107 
3108 #if (PHNT_VERSION >= PHNT_WS03)
3109 NTSYSAPI
3110 VOID
3111 NTAPI
3113  _Inout_ PRTL_RELATIVE_NAME_U RelativeName
3114  );
3115 #endif
3116 
3117 NTSYSAPI
3118 ULONG
3119 NTAPI
3121  _In_ PWSTR Path,
3122  _In_ PWSTR FileName,
3123  _In_opt_ PWSTR Extension,
3124  _In_ ULONG BufferLength,
3125  _Out_writes_bytes_(BufferLength) PWSTR Buffer,
3126  _Out_opt_ PWSTR *FilePart
3127  );
3128 
3129 #define RTL_DOS_SEARCH_PATH_FLAG_APPLY_ISOLATION_REDIRECTION 0x00000001
3130 #define RTL_DOS_SEARCH_PATH_FLAG_DISALLOW_DOT_RELATIVE_PATH_SEARCH 0x00000002
3131 #define RTL_DOS_SEARCH_PATH_FLAG_APPLY_DEFAULT_EXTENSION_WHEN_NOT_RELATIVE_PATH_EVEN_IF_FILE_HAS_EXTENSION 0x00000004)
3132 
3133 NTSYSAPI
3134 NTSTATUS
3135 NTAPI
3137  _In_ ULONG Flags,
3138  _In_ PUNICODE_STRING Path,
3139  _In_ PUNICODE_STRING FileName,
3140  _In_opt_ PUNICODE_STRING DefaultExtension,
3141  _Out_opt_ PUNICODE_STRING StaticString,
3142  _Out_opt_ PUNICODE_STRING DynamicString,
3143  _Out_opt_ PCUNICODE_STRING *FullFileNameOut,
3144  _Out_opt_ SIZE_T *FilePartPrefixCch,
3145  _Out_opt_ SIZE_T *BytesRequired
3146  );
3147 
3148 NTSYSAPI
3149 BOOLEAN
3150 NTAPI
3152  _In_ PWSTR FileName
3153  );
3154 
3155 // Heaps
3156 
3157 typedef struct _RTL_HEAP_ENTRY
3158 {
3159  SIZE_T Size;
3160  USHORT Flags;
3162  union
3163  {
3164  struct
3165  {
3166  SIZE_T Settable;
3167  ULONG Tag;
3168  } s1;
3169  struct
3170  {
3172  PVOID FirstBlock;
3173  } s2;
3174  } u;
3176 
3177 #define RTL_HEAP_BUSY (USHORT)0x0001
3178 #define RTL_HEAP_SEGMENT (USHORT)0x0002
3179 #define RTL_HEAP_SETTABLE_VALUE (USHORT)0x0010
3180 #define RTL_HEAP_SETTABLE_FLAG1 (USHORT)0x0020
3181 #define RTL_HEAP_SETTABLE_FLAG2 (USHORT)0x0040
3182 #define RTL_HEAP_SETTABLE_FLAG3 (USHORT)0x0080
3183 #define RTL_HEAP_SETTABLE_FLAGS (USHORT)0x00e0
3184 #define RTL_HEAP_UNCOMMITTED_RANGE (USHORT)0x0100
3185 #define RTL_HEAP_PROTECTED_ENTRY (USHORT)0x0200
3186 
3187 typedef struct _RTL_HEAP_TAG
3188 {
3192  USHORT TagIndex;
3194  WCHAR TagName[24];
3196 
3198 {
3200  ULONG Flags;
3209  ULONG Reserved[5];
3210  PRTL_HEAP_TAG Tags;
3211  PRTL_HEAP_ENTRY Entries;
3213 
3214 typedef struct _RTL_PROCESS_HEAPS
3215 {
3219 
3220 typedef NTSTATUS (NTAPI *PRTL_HEAP_COMMIT_ROUTINE)(
3221  _In_ PVOID Base,
3222  _Inout_ PVOID *CommitAddress,
3223  _Inout_ PSIZE_T CommitSize
3224  );
3225 
3226 typedef struct _RTL_HEAP_PARAMETERS
3227 {
3228  ULONG Length;
3238  SIZE_T Reserved[2];
3240 
3241 #define HEAP_SETTABLE_USER_VALUE 0x00000100
3242 #define HEAP_SETTABLE_USER_FLAG1 0x00000200
3243 #define HEAP_SETTABLE_USER_FLAG2 0x00000400
3244 #define HEAP_SETTABLE_USER_FLAG3 0x00000800
3245 #define HEAP_SETTABLE_USER_FLAGS 0x00000e00
3246 
3247 #define HEAP_CLASS_0 0x00000000 // Process heap
3248 #define HEAP_CLASS_1 0x00001000 // Private heap
3249 #define HEAP_CLASS_2 0x00002000 // Kernel heap
3250 #define HEAP_CLASS_3 0x00003000 // GDI heap
3251 #define HEAP_CLASS_4 0x00004000 // User heap
3252 #define HEAP_CLASS_5 0x00005000 // Console heap
3253 #define HEAP_CLASS_6 0x00006000 // User desktop heap
3254 #define HEAP_CLASS_7 0x00007000 // CSR shared heap
3255 #define HEAP_CLASS_8 0x00008000 // CSR port heap
3256 #define HEAP_CLASS_MASK 0x0000f000
3257 
3258 NTSYSAPI
3259 PVOID
3260 NTAPI
3262  _In_ ULONG Flags,
3263  _In_opt_ PVOID HeapBase,
3264  _In_opt_ SIZE_T ReserveSize,
3265  _In_opt_ SIZE_T CommitSize,
3266  _In_opt_ PVOID Lock,
3267  _In_opt_ PRTL_HEAP_PARAMETERS Parameters
3268  );
3269 
3270 NTSYSAPI
3271 PVOID
3272 NTAPI
3274  _In_ _Post_invalid_ PVOID HeapHandle
3275  );
3276 
3277 NTSYSAPI
3278 PVOID
3279 NTAPI
3281  _In_ PVOID HeapHandle,
3282  _In_opt_ ULONG Flags,
3283  _In_ SIZE_T Size
3284  );
3285 
3286 NTSYSAPI
3287 BOOLEAN
3288 NTAPI
3289 RtlFreeHeap(
3290  _In_ PVOID HeapHandle,
3291  _In_opt_ ULONG Flags,
3292  _In_ _Post_invalid_ PVOID BaseAddress
3293  );
3294 
3295 NTSYSAPI
3296 SIZE_T
3297 NTAPI
3298 RtlSizeHeap(
3299  _In_ PVOID HeapHandle,
3300  _In_ ULONG Flags,
3301  _In_ PVOID BaseAddress
3302  );
3303 
3304 NTSYSAPI
3305 NTSTATUS
3306 NTAPI
3307 RtlZeroHeap(
3308  _In_ PVOID HeapHandle,
3309  _In_ ULONG Flags
3310  );
3311 
3312 NTSYSAPI
3313 VOID
3314 NTAPI
3316  _In_ PVOID HeapHandle,
3317  _In_ BOOLEAN MakeReadOnly
3318  );
3319 
3320 #define RtlProcessHeap() (NtCurrentPeb()->ProcessHeap)
3321 
3322 NTSYSAPI
3323 BOOLEAN
3324 NTAPI
3325 RtlLockHeap(
3326  _In_ PVOID HeapHandle
3327  );
3328 
3329 NTSYSAPI
3330 BOOLEAN
3331 NTAPI
3333  _In_ PVOID HeapHandle
3334  );
3335 
3336 NTSYSAPI
3337 PVOID
3338 NTAPI
3340  _In_ PVOID HeapHandle,
3341  _In_ ULONG Flags,
3342  _In_ PVOID BaseAddress,
3343  _In_ SIZE_T Size
3344  );
3345 
3346 NTSYSAPI
3347 BOOLEAN
3348 NTAPI
3350  _In_ PVOID HeapHandle,
3351  _In_ ULONG Flags,
3352  _In_ PVOID BaseAddress,
3353  _Out_opt_ PVOID *UserValue,
3354  _Out_opt_ PULONG UserFlags
3355  );
3356 
3357 NTSYSAPI
3358 BOOLEAN
3359 NTAPI
3361  _In_ PVOID HeapHandle,
3362  _In_ ULONG Flags,
3363  _In_ PVOID BaseAddress,
3364  _In_ PVOID UserValue
3365  );
3366 
3367 NTSYSAPI
3368 BOOLEAN
3369 NTAPI
3371  _In_ PVOID HeapHandle,
3372  _In_ ULONG Flags,
3373  _In_ PVOID BaseAddress,
3374  _In_ ULONG UserFlagsReset,
3375  _In_ ULONG UserFlagsSet
3376  );
3377 
3378 typedef struct _RTL_HEAP_TAG_INFO
3379 {
3384 
3385 #define RTL_HEAP_MAKE_TAG HEAP_MAKE_TAG_FLAGS
3386 
3387 NTSYSAPI
3388 ULONG
3389 NTAPI
3391  _In_ PVOID HeapHandle,
3392  _In_ ULONG Flags,
3393  _In_opt_ PWSTR TagPrefix,
3394  _In_ PWSTR TagNames
3395  );
3396 
3397 NTSYSAPI
3398 PWSTR
3399 NTAPI
3401  _In_ PVOID HeapHandle,
3402  _In_ ULONG Flags,
3403  _In_ USHORT TagIndex,
3404  _In_ BOOLEAN ResetCounters,
3405  _Out_opt_ PRTL_HEAP_TAG_INFO TagInfo
3406  );
3407 
3408 NTSYSAPI
3409 NTSTATUS
3410 NTAPI
3412  _In_ PVOID HeapHandle,
3413  _In_ ULONG Flags,
3414  _In_ PVOID Base,
3415  _In_ SIZE_T Size
3416  );
3417 
3418 NTSYSAPI
3419 SIZE_T
3420 NTAPI
3422  _In_ PVOID HeapHandle,
3423  _In_ ULONG Flags
3424  );
3425 
3426 NTSYSAPI
3427 BOOLEAN
3428 NTAPI
3430  _In_ PVOID HeapHandle,
3431  _In_ ULONG Flags,
3432  _In_ PVOID BaseAddress
3433  );
3434 
3435 NTSYSAPI
3436 BOOLEAN
3437 NTAPI
3439  VOID
3440  );
3441 
3442 NTSYSAPI
3443 ULONG
3444 NTAPI
3446  _In_ ULONG NumberOfHeaps,
3447  _Out_ PVOID *ProcessHeaps
3448  );
3449 
3450 typedef NTSTATUS (NTAPI *PRTL_ENUM_HEAPS_ROUTINE)(
3451  _In_ PVOID HeapHandle,
3452  _In_ PVOID Parameter
3453  );
3454 
3455 NTSYSAPI
3456 NTSTATUS
3457 NTAPI
3459  _In_ PRTL_ENUM_HEAPS_ROUTINE EnumRoutine,
3460  _In_ PVOID Parameter
3461  );
3462 
3464 {
3466  PVOID Address;
3467  SIZE_T Size;
3469  USHORT TagIndex;
3471 
3472 typedef struct _RTL_HEAP_USAGE
3473 {
3474  ULONG Length;
3479  PRTL_HEAP_USAGE_ENTRY Entries;
3480  PRTL_HEAP_USAGE_ENTRY AddedEntries;
3481  PRTL_HEAP_USAGE_ENTRY RemovedEntries;
3482  ULONG_PTR Reserved[8];
3484 
3485 #define HEAP_USAGE_ALLOCATED_BLOCKS HEAP_REALLOC_IN_PLACE_ONLY
3486 #define HEAP_USAGE_FREE_BUFFER HEAP_ZERO_MEMORY
3487 
3488 NTSYSAPI
3489 NTSTATUS
3490 NTAPI
3491 RtlUsageHeap(
3492  _In_ PVOID HeapHandle,
3493  _In_ ULONG Flags,
3494  _Inout_ PRTL_HEAP_USAGE Usage
3495  );
3496 
3497 typedef struct _RTL_HEAP_WALK_ENTRY
3498 {
3500  SIZE_T DataSize;
3503  USHORT Flags;
3504  union
3505  {
3506  struct
3507  {
3508  SIZE_T Settable;
3509  USHORT TagIndex;
3511  ULONG Reserved[2];
3512  } Block;
3513  struct
3514  {
3517  PVOID FirstEntry;
3518  PVOID LastEntry;
3519  } Segment;
3520  };
3522 
3523 NTSYSAPI
3524 NTSTATUS
3525 NTAPI
3526 RtlWalkHeap(
3527  _In_ PVOID HeapHandle,
3528  _Inout_ PRTL_HEAP_WALK_ENTRY Entry
3529  );
3530 
3531 // rev
3532 #define HeapDebuggingInformation 0x80000002
3533 
3534 // rev
3535 typedef NTSTATUS (NTAPI *PRTL_HEAP_LEAK_ENUMERATION_ROUTINE)(
3536  _In_ LONG Reserved,
3537  _In_ PVOID HeapHandle,
3538  _In_ PVOID BaseAddress,
3539  _In_ SIZE_T BlockSize,
3540  _In_ ULONG StackTraceDepth,
3541  _In_ PVOID *StackTrace
3542  );
3543 
3544 // symbols
3546 {
3555 
3556 NTSYSAPI
3557 NTSTATUS
3558 NTAPI
3560  _In_ PVOID HeapHandle,
3561  _In_ HEAP_INFORMATION_CLASS HeapInformationClass,
3562  _Out_opt_ PVOID HeapInformation,
3563  _In_opt_ SIZE_T HeapInformationLength,
3564  _Out_opt_ PSIZE_T ReturnLength
3565  );
3566 
3567 NTSYSAPI
3568 NTSTATUS
3569 NTAPI
3571  _In_ PVOID HeapHandle,
3572  _In_ HEAP_INFORMATION_CLASS HeapInformationClass,
3573  _In_opt_ PVOID HeapInformation,
3574  _In_opt_ SIZE_T HeapInformationLength
3575  );
3576 
3577 NTSYSAPI
3578 ULONG
3579 NTAPI
3581  _In_ PVOID HeapHandle,
3582  _In_ ULONG Flags,
3583  _In_ SIZE_T Size,
3584  _In_ ULONG Count,
3585  _Out_ PVOID *Array
3586  );
3587 
3588 NTSYSAPI
3589 ULONG
3590 NTAPI
3592  _In_ PVOID HeapHandle,
3593  _In_ ULONG Flags,
3594  _In_ ULONG Count,
3595  _In_ PVOID *Array
3596  );
3597 
3598 #if (PHNT_VERSION >= PHNT_WIN7)
3599 NTSYSAPI
3600 VOID
3601 NTAPI
3603  VOID
3604  );
3605 #endif
3606 
3607 // Memory zones
3608 
3609 // begin_private
3610 
3612 {
3614  SIZE_T Size;
3615  PVOID Next;
3616  PVOID Limit;
3618 
3619 typedef struct _RTL_MEMORY_ZONE
3620 {
3622  RTL_SRWLOCK Lock;
3623  ULONG LockCount;
3624  PRTL_MEMORY_ZONE_SEGMENT FirstSegment;
3626 
3627 #if (PHNT_VERSION >= PHNT_VISTA)
3628 
3629 NTSYSAPI
3630 NTSTATUS
3631 NTAPI
3633  _Out_ PVOID *MemoryZone,
3634  _In_ SIZE_T InitialSize,
3635  _Reserved_ ULONG Flags
3636  );
3637 
3638 NTSYSAPI
3639 NTSTATUS
3640 NTAPI
3642  _In_ _Post_invalid_ PVOID MemoryZone
3643  );
3644 
3645 NTSYSAPI
3646 NTSTATUS
3647 NTAPI
3649  _In_ PVOID MemoryZone,
3650  _In_ SIZE_T BlockSize,
3651  _Out_ PVOID *Block
3652  );
3653 
3654 NTSYSAPI
3655 NTSTATUS
3656 NTAPI
3658  _In_ PVOID MemoryZone
3659  );
3660 
3661 NTSYSAPI
3662 NTSTATUS
3663 NTAPI
3665  _In_ PVOID MemoryZone
3666  );
3667 
3668 NTSYSAPI
3669 NTSTATUS
3670 NTAPI
3672  _In_ PVOID MemoryZone
3673  );
3674 
3675 #endif
3676 
3677 // end_private
3678 
3679 // Memory block lookaside lists
3680 
3681 // begin_private
3682 
3683 #if (PHNT_VERSION >= PHNT_VISTA)
3684 
3685 NTSYSAPI
3686 NTSTATUS
3687 NTAPI
3689  _Out_ PVOID *MemoryBlockLookaside,
3690  _Reserved_ ULONG Flags,
3691  _In_ ULONG InitialSize,
3692  _In_ ULONG MinimumBlockSize,
3693  _In_ ULONG MaximumBlockSize
3694  );
3695 
3696 NTSYSAPI
3697 NTSTATUS
3698 NTAPI
3700  _In_ PVOID MemoryBlockLookaside
3701  );
3702 
3703 NTSYSAPI
3704 NTSTATUS
3705 NTAPI
3707  _In_ PVOID MemoryBlockLookaside,
3708  _In_ ULONG BlockSize,
3709  _Out_ PVOID *Block
3710  );
3711 
3712 NTSYSAPI
3713 NTSTATUS
3714 NTAPI
3716  _In_ PVOID MemoryBlockLookaside,
3717  _In_ PVOID Block
3718  );
3719 
3720 NTSYSAPI
3721 NTSTATUS
3722 NTAPI
3724  _In_ PVOID MemoryBlockLookaside,
3725  _In_ ULONG Increment
3726  );
3727 
3728 NTSYSAPI
3729 NTSTATUS
3730 NTAPI
3732  _In_ PVOID MemoryBlockLookaside
3733  );
3734 
3735 NTSYSAPI
3736 NTSTATUS
3737 NTAPI
3739  _In_ PVOID MemoryBlockLookaside
3740  );
3741 
3742 NTSYSAPI
3743 NTSTATUS
3744 NTAPI
3746  _In_ PVOID MemoryBlockLookaside
3747  );
3748 
3749 #endif
3750 
3751 // end_private
3752 
3753 // Transactions
3754 
3755 #if (PHNT_VERSION >= PHNT_VISTA)
3756 // private
3757 NTSYSAPI
3758 HANDLE
3759 NTAPI
3761  VOID
3762  );
3763 #endif
3764 
3765 #if (PHNT_VERSION >= PHNT_VISTA)
3766 // private
3767 NTSYSAPI
3768 LOGICAL
3769 NTAPI
3771  _In_ HANDLE TransactionHandle
3772  );
3773 #endif
3774 
3775 // LUIDs
3776 
3777 FORCEINLINE BOOLEAN RtlIsEqualLuid(
3778  _In_ PLUID L1,
3779  _In_ PLUID L2
3780  )
3781 {
3782  return L1->LowPart == L2->LowPart &&
3783  L1->HighPart == L2->HighPart;
3784 }
3785 
3786 FORCEINLINE BOOLEAN RtlIsZeroLuid(
3787  _In_ PLUID L1
3788  )
3789 {
3790  return (L1->LowPart | L1->HighPart) == 0;
3791 }
3792 
3793 FORCEINLINE LUID RtlConvertLongToLuid(
3794  _In_ LONG Long
3795  )
3796 {
3797  LUID tempLuid;
3798  LARGE_INTEGER tempLi;
3799 
3800  tempLi.QuadPart = Long;
3801  tempLuid.LowPart = tempLi.LowPart;
3802  tempLuid.HighPart = tempLi.HighPart;
3803 
3804  return tempLuid;
3805 }
3806 
3807 FORCEINLINE LUID RtlConvertUlongToLuid(
3808  _In_ ULONG Ulong
3809  )
3810 {
3811  LUID tempLuid;
3812 
3813  tempLuid.LowPart = Ulong;
3814  tempLuid.HighPart = 0;
3815 
3816  return tempLuid;
3817 }
3818 
3819 NTSYSAPI
3820 VOID
3821 NTAPI
3822 RtlCopyLuid(
3823  _Out_ PLUID DestinationLuid,
3824  _In_ PLUID SourceLuid
3825  );
3826 
3827 // Debugging
3828 
3829 // private
3831 {
3832  ULONG SizeStruct;
3833  ULONG Option;
3834  UCHAR OptionData[1];
3836 
3837 // private
3839 {
3843  ULONG_PTR ViewBaseDelta;
3848  ULONG Flags;
3849  SIZE_T OffsetFree;
3850  SIZE_T CommitSize;
3851  SIZE_T ViewSize;
3852  union
3853  {
3856  };
3857  struct _RTL_PROCESS_BACKTRACES *BackTraces;
3859  struct _RTL_PROCESS_LOCKS *Locks;
3862  PRTL_PROCESS_VERIFIER_OPTIONS VerifierOptions;
3866  PVOID Reserved[4];
3868 
3869 NTSYSAPI
3870 PRTL_DEBUG_INFORMATION
3871 NTAPI
3873  _In_opt_ ULONG MaximumCommit,
3874  _In_ BOOLEAN UseEventPair
3875  );
3876 
3877 NTSYSAPI
3878 NTSTATUS
3879 NTAPI
3881  _In_ PRTL_DEBUG_INFORMATION Buffer
3882  );
3883 
3884 #if (PHNT_VERSION >= PHNT_VISTA)
3885 
3886 // private
3887 NTSYSAPI
3888 PVOID
3889 NTAPI
3891  _Inout_ PRTL_DEBUG_INFORMATION Buffer,
3892  _In_ SIZE_T Size
3893  );
3894 
3895 // private
3896 NTSYSAPI
3897 VOID
3898 NTAPI
3900  _Inout_ PRTL_DEBUG_INFORMATION Buffer,
3901  _In_ PVOID p,
3902  _In_ SIZE_T Size
3903  );
3904 
3905 #endif
3906 
3907 #define RTL_QUERY_PROCESS_MODULES 0x00000001
3908 #define RTL_QUERY_PROCESS_BACKTRACES 0x00000002
3909 #define RTL_QUERY_PROCESS_HEAP_SUMMARY 0x00000004
3910 #define RTL_QUERY_PROCESS_HEAP_TAGS 0x00000008
3911 #define RTL_QUERY_PROCESS_HEAP_ENTRIES 0x00000010
3912 #define RTL_QUERY_PROCESS_LOCKS 0x00000020
3913 #define RTL_QUERY_PROCESS_MODULES32 0x00000040
3914 #define RTL_QUERY_PROCESS_VERIFIER_OPTIONS 0x00000080 // rev
3915 #define RTL_QUERY_PROCESS_MODULESEX 0x00000100 // rev
3916 #define RTL_QUERY_PROCESS_HEAP_ENTRIES_EX 0x00000200 // ?
3917 #define RTL_QUERY_PROCESS_CS_OWNER 0x00000400 // rev
3918 #define RTL_QUERY_PROCESS_NONINVASIVE 0x80000000
3919 
3920 NTSYSAPI
3921 NTSTATUS
3922 NTAPI
3924  _In_ HANDLE UniqueProcessId,
3925  _In_ ULONG Flags,
3926  _Inout_ PRTL_DEBUG_INFORMATION Buffer
3927  );
3928 
3929 // Messages
3930 
3931 NTSYSAPI
3932 NTSTATUS
3933 NTAPI
3935  _In_ PVOID DllHandle,
3936  _In_ ULONG MessageTableId,
3937  _In_ ULONG MessageLanguageId,
3938  _In_ ULONG MessageId,
3939  _Out_ PMESSAGE_RESOURCE_ENTRY *MessageEntry
3940  );
3941 
3942 NTSYSAPI
3943 NTSTATUS
3944 NTAPI
3946  _In_ PWSTR MessageFormat,
3947  _In_ ULONG MaximumWidth,
3948  _In_ BOOLEAN IgnoreInserts,
3949  _In_ BOOLEAN ArgumentsAreAnsi,
3950  _In_ BOOLEAN ArgumentsAreAnArray,
3951  _In_ va_list *Arguments,
3952  _Out_writes_bytes_to_(Length, *ReturnLength) PWSTR Buffer,
3953  _In_ ULONG Length,
3954  _Out_opt_ PULONG ReturnLength
3955  );
3956 
3958 {
3959  ULONG fFlags;
3961  SIZE_T iwSrc;
3962  SIZE_T iwDst;
3963  SIZE_T iwDstSpace;
3964  va_list lpvArgStart;
3966 
3967 #define INIT_PARSE_MESSAGE_CONTEXT(ctx) \
3968  { \
3969  (ctx)->fFlags = 0; \
3970  }
3971 
3972 #define TEST_PARSE_MESSAGE_CONTEXT_FLAG(ctx, flag) ((ctx)->fFlags & (flag))
3973 #define SET_PARSE_MESSAGE_CONTEXT_FLAG(ctx, flag) ((ctx)->fFlags |= (flag))
3974 #define CLEAR_PARSE_MESSAGE_CONTEXT_FLAG(ctx, flag) ((ctx)->fFlags &= ~(flag))
3975 
3976 NTSYSAPI
3977 NTSTATUS
3978 NTAPI
3980  _In_ PWSTR MessageFormat,
3981  _In_ ULONG MaximumWidth,
3982  _In_ BOOLEAN IgnoreInserts,
3983  _In_ BOOLEAN ArgumentsAreAnsi,
3984  _In_ BOOLEAN ArgumentsAreAnArray,
3985  _In_ va_list *Arguments,
3986  _Out_writes_bytes_to_(Length, *ReturnLength) PWSTR Buffer,
3987  _In_ ULONG Length,
3988  _Out_opt_ PULONG ReturnLength,
3989  _Out_opt_ PPARSE_MESSAGE_CONTEXT ParseContext
3990  );
3991 
3992 // Errors
3993 
3994 NTSYSAPI
3995 ULONG
3996 NTAPI
3998  _In_ NTSTATUS Status
3999  );
4000 
4001 NTSYSAPI
4002 ULONG
4003 NTAPI
4005  _In_ NTSTATUS Status
4006  );
4007 
4008 NTSYSAPI
4009 NTSTATUS
4010 NTAPI
4012  VOID
4013  );
4014 
4015 NTSYSAPI
4016 LONG
4017 NTAPI
4019  VOID
4020  );
4021 
4022 NTSYSAPI
4023 VOID
4024 NTAPI
4026  _In_ NTSTATUS Status
4027  );
4028 
4029 NTSYSAPI
4030 VOID
4031 NTAPI
4033  _In_ LONG Win32Error
4034  );
4035 
4036 NTSYSAPI
4037 VOID
4038 NTAPI
4040  _In_ LONG Win32Error
4041  );
4042 
4043 #define RTL_ERRORMODE_NOGPFAULTERRORBOX 0x0020
4044 #define RTL_ERRORMODE_NOOPENFILEERRORBOX 0x0040
4045 
4046 NTSYSAPI
4047 ULONG
4048 NTAPI
4050  VOID
4051  );
4052 
4053 NTSYSAPI
4054 NTSTATUS
4055 NTAPI
4057  _In_ ULONG NewMode,
4058  _Out_opt_ PULONG OldMode
4059  );
4060 
4061 // Windows Error Reporting
4062 
4063 #if (PHNT_VERSION >= PHNT_VISTA)
4064 // private
4065 NTSYSAPI
4066 NTSTATUS
4067 NTAPI
4069  _In_ PEXCEPTION_RECORD ExceptionRecord,
4070  _In_ PCONTEXT ContextRecord,
4071  _In_ ULONG Flags
4072  );
4073 #endif
4074 
4075 #if (PHNT_VERSION >= PHNT_VISTA)
4076 // private
4077 NTSYSAPI
4078 NTSTATUS
4079 NTAPI
4081  _In_ ULONG ProcessId,
4082  _In_ HANDLE CrashReportSharedMem,
4083  _In_ ULONG Flags,
4084  _Out_ PHANDLE CrashVerticalProcessHandle
4085  );
4086 #endif
4087 
4088 #if (PHNT_VERSION >= PHNT_WIN7)
4089 // rev
4090 NTSYSAPI
4091 NTSTATUS
4092 NTAPI
4094  _In_ HANDLE ProcessHandle,
4095  _In_ NTSTATUS ExitStatus
4096  );
4097 #endif
4098 
4099 // Vectored Exception Handlers
4100 
4101 NTSYSAPI
4102 PVOID
4103 NTAPI
4105  _In_ ULONG First,
4106  _In_ PVECTORED_EXCEPTION_HANDLER Handler
4107  );
4108 
4109 NTSYSAPI
4110 ULONG
4111 NTAPI
4113  _In_ PVOID Handle
4114  );
4115 
4116 NTSYSAPI
4117 PVOID
4118 NTAPI
4120  _In_ ULONG First,
4121  _In_ PVECTORED_EXCEPTION_HANDLER Handler
4122  );
4123 
4124 NTSYSAPI
4125 ULONG
4126 NTAPI
4128  _In_ PVOID Handle
4129  );
4130 
4131 // Random
4132 
4133 NTSYSAPI
4134 ULONG
4135 NTAPI
4136 RtlUniform(
4137  _Inout_ PULONG Seed
4138  );
4139 
4140 NTSYSAPI
4141 ULONG
4142 NTAPI
4143 RtlRandom(
4144  _Inout_ PULONG Seed
4145  );
4146 
4147 NTSYSAPI
4148 ULONG
4149 NTAPI
4150 RtlRandomEx(
4151  _Inout_ PULONG Seed
4152  );
4153 
4154 NTSYSAPI
4155 NTSTATUS
4156 NTAPI
4158  _In_ HANDLE hFile,
4159  _Out_writes_bytes_(16) PCHAR Hash,
4160  _In_ ULONG ImportTableHashRevision // must be 1
4161  );
4162 
4163 // Integer conversion
4164 
4165 NTSYSAPI
4166 NTSTATUS
4167 NTAPI
4169  _In_ ULONG Value,
4170  _In_opt_ ULONG Base,
4171  _In_ LONG OutputLength, // negative to pad to width
4172  _Out_ PSTR String
4173  );
4174 
4175 NTSYSAPI
4176 NTSTATUS
4177 NTAPI
4179  _In_ PSTR String,
4180  _In_opt_ ULONG Base,
4181  _Out_ PULONG Value
4182  );
4183 
4184 NTSYSAPI
4185 NTSTATUS
4186 NTAPI
4188  _In_ PLARGE_INTEGER Value,
4189  _In_opt_ ULONG Base,
4190  _In_ LONG OutputLength,
4191  _Out_ PSTR String
4192  );
4193 
4194 NTSYSAPI
4195 NTSTATUS
4196 NTAPI
4198  _In_ ULONG Value,
4199  _In_opt_ ULONG Base,
4200  _Inout_ PUNICODE_STRING String
4201  );
4202 
4203 NTSYSAPI
4204 NTSTATUS
4205 NTAPI
4207  _In_ ULONGLONG Value,
4208  _In_opt_ ULONG Base,
4209  _Inout_ PUNICODE_STRING String
4210  );
4211 
4212 #ifdef _WIN64
4213 #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
4214 #else
4215 #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
4216 #endif
4217 
4218 NTSYSAPI
4219 NTSTATUS
4220 NTAPI
4222  _In_ PUNICODE_STRING String,
4223  _In_opt_ ULONG Base,
4224  _Out_ PULONG Value
4225  );
4226 
4227 // IPv4/6 conversion
4228 
4229 struct in_addr;
4230 struct in6_addr;
4231 
4232 NTSYSAPI
4233 PWSTR
4234 NTAPI
4236  _In_ struct in_addr *Addr,
4237  _Out_writes_(16) PWSTR S
4238  );
4239 
4240 NTSYSAPI
4241 NTSTATUS
4242 NTAPI
4244  _In_ struct in_addr *Address,
4245  _In_ USHORT Port,
4246  _Out_writes_to_(*AddressStringLength, *AddressStringLength) PWSTR AddressString,
4247  _Inout_ PULONG AddressStringLength
4248  );
4249 
4250 NTSYSAPI
4251 PWSTR
4252 NTAPI
4254  _In_ struct in6_addr *Addr,
4255  _Out_writes_(65) PWSTR S
4256  );
4257 
4258 NTSYSAPI
4259 NTSTATUS
4260 NTAPI
4262  _In_ struct in6_addr *Address,
4263  _In_ ULONG ScopeId,
4264  _In_ USHORT Port,
4265  _Out_writes_to_(*AddressStringLength, *AddressStringLength) PWSTR AddressString,
4266  _Inout_ PULONG AddressStringLength
4267  );
4268 
4269 NTSYSAPI
4270 NTSTATUS
4271 NTAPI
4273  _In_ PWSTR S,
4274  _In_ BOOLEAN Strict,
4275  _Out_ PWSTR *Terminator,
4276  _Out_ struct in_addr *Addr
4277  );
4278 
4279 NTSYSAPI
4280 NTSTATUS
4281 NTAPI
4283  _In_ PWSTR AddressString,
4284  _In_ BOOLEAN Strict,
4285  _Out_ struct in_addr *Address,
4286  _Out_ PUSHORT Port
4287  );
4288 
4289 NTSYSAPI
4290 NTSTATUS
4291 NTAPI
4293  _In_ PWSTR S,
4294  _Out_ PWSTR *Terminator,
4295  _Out_ struct in6_addr *Addr
4296  );
4297 
4298 NTSYSAPI
4299 NTSTATUS
4300 NTAPI
4302  _In_ PWSTR AddressString,
4303  _Out_ struct in6_addr *Address,
4304  _Out_ PULONG ScopeId,
4305  _Out_ PUSHORT Port
4306  );
4307 
4308 #define RtlIpv4AddressToString RtlIpv4AddressToStringW
4309 #define RtlIpv4AddressToStringEx RtlIpv4AddressToStringExW
4310 #define RtlIpv6AddressToString RtlIpv6AddressToStringW
4311 #define RtlIpv6AddressToStringEx RtlIpv6AddressToStringExW
4312 #define RtlIpv4StringToAddress RtlIpv4StringToAddressW
4313 #define RtlIpv4StringToAddressEx RtlIpv4StringToAddressExW
4314 #define RtlIpv6StringToAddress RtlIpv6StringToAddressW
4315 #define RtlIpv6StringToAddressEx RtlIpv6StringToAddressExW
4316 
4317 // Time
4318 
4319 typedef struct _TIME_FIELDS
4320 {
4321  CSHORT Year; // 1601...
4322  CSHORT Month; // 1..12
4323  CSHORT Day; // 1..31
4324  CSHORT Hour; // 0..23
4325  CSHORT Minute; // 0..59
4326  CSHORT Second; // 0..59
4328  CSHORT Weekday; // 0..6 = Sunday..Saturday
4330 
4331 NTSYSAPI
4332 BOOLEAN
4333 NTAPI
4335  _In_ PTIME_FIELDS CutoverTime,
4336  _Out_ PLARGE_INTEGER SystemTime,
4337  _In_ PLARGE_INTEGER CurrentSystemTime,
4338  _In_ BOOLEAN ThisYear
4339  );
4340 
4341 NTSYSAPI
4342 NTSTATUS
4343 NTAPI
4345  _In_ PLARGE_INTEGER SystemTime,
4346  _Out_ PLARGE_INTEGER LocalTime
4347  );
4348 
4349 NTSYSAPI
4350 NTSTATUS
4351 NTAPI
4353  _In_ PLARGE_INTEGER LocalTime,
4354  _Out_ PLARGE_INTEGER SystemTime
4355  );
4356 
4357 NTSYSAPI
4358 VOID
4359 NTAPI
4361  _In_ PLARGE_INTEGER Time,
4362  _Out_ PTIME_FIELDS TimeFields
4363  );
4364 
4365 NTSYSAPI
4366 VOID
4367 NTAPI
4369  _In_ PLARGE_INTEGER Time,
4370  _Out_ PTIME_FIELDS TimeFields
4371  );
4372 
4373 NTSYSAPI
4374 BOOLEAN
4375 NTAPI
4377  _In_ PTIME_FIELDS TimeFields, // Weekday is ignored
4378  _Out_ PLARGE_INTEGER Time
4379  );
4380 
4381 NTSYSAPI
4382 BOOLEAN
4383 NTAPI
4385  _In_ PLARGE_INTEGER Time,
4386  _Out_ PULONG ElapsedSeconds
4387  );
4388 
4389 NTSYSAPI
4390 VOID
4391 NTAPI
4393  _In_ ULONG ElapsedSeconds,
4394  _Out_ PLARGE_INTEGER Time
4395  );
4396 
4397 NTSYSAPI
4398 BOOLEAN
4399 NTAPI
4401  _In_ PLARGE_INTEGER Time,
4402  _Out_ PULONG ElapsedSeconds
4403  );
4404 
4405 NTSYSAPI
4406 VOID
4407 NTAPI
4409  _In_ ULONG ElapsedSeconds,
4410  _Out_ PLARGE_INTEGER Time
4411  );
4412 
4413 // Time zones
4414 
4416 {
4418  WCHAR StandardName[32];
4421  WCHAR DaylightName[32];
4425 
4426 NTSYSAPI
4427 NTSTATUS
4428 NTAPI
4430  _Out_ PRTL_TIME_ZONE_INFORMATION TimeZoneInformation
4431  );
4432 
4433 NTSYSAPI
4434 NTSTATUS
4435 NTAPI
4437  _In_ PRTL_TIME_ZONE_INFORMATION TimeZoneInformation
4438  );
4439 
4440 // Bitmaps
4441 
4442 typedef struct _RTL_BITMAP
4443 {
4445  PULONG Buffer;
4447 
4448 NTSYSAPI
4449 VOID
4450 NTAPI
4452  _Out_ PRTL_BITMAP BitMapHeader,
4453  _In_ PULONG BitMapBuffer,
4454  _In_ ULONG SizeOfBitMap
4455  );
4456 
4457 #if (PHNT_MODE == PHNT_MODE_KERNEL)
4458 NTSYSAPI
4459 VOID
4460 NTAPI
4461 RtlClearBit(
4462  _In_ PRTL_BITMAP BitMapHeader,
4463  _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber
4464  );
4465 #endif
4466 
4467 #if (PHNT_MODE == PHNT_MODE_KERNEL)
4468 NTSYSAPI
4469 VOID
4470 NTAPI
4471 RtlSetBit(
4472  _In_ PRTL_BITMAP BitMapHeader,
4473  _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber
4474  );
4475 #endif
4476 
4477 _Check_return_
4478 NTSYSAPI
4479 BOOLEAN
4480 NTAPI
4481 RtlTestBit(
4482  _In_ PRTL_BITMAP BitMapHeader,
4483  _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber
4484  );
4485 
4486 NTSYSAPI
4487 VOID
4488 NTAPI
4490  _In_ PRTL_BITMAP BitMapHeader
4491  );
4492 
4493 NTSYSAPI
4494 VOID
4495 NTAPI
4497  _In_ PRTL_BITMAP BitMapHeader
4498  );
4499 
4500 _Success_(return != -1)
4501 _Check_return_
4502 NTSYSAPI
4503 ULONG
4504 NTAPI
4505 RtlFindClearBits(
4506  _In_ PRTL_BITMAP BitMapHeader,
4507  _In_ ULONG NumberToFind,
4508  _In_ ULONG HintIndex
4509  );
4510 
4511 _Success_(return != -1)
4512 _Check_return_
4513 NTSYSAPI
4514 ULONG
4515 NTAPI
4516 RtlFindSetBits(
4517  _In_ PRTL_BITMAP BitMapHeader,
4518  _In_ ULONG NumberToFind,
4519  _In_ ULONG HintIndex
4520  );
4521 
4522 _Success_(return != -1)
4523 NTSYSAPI
4524 ULONG
4525 NTAPI
4526 RtlFindClearBitsAndSet(
4527  _In_ PRTL_BITMAP BitMapHeader,
4528  _In_ ULONG NumberToFind,
4529  _In_ ULONG HintIndex
4530  );
4531 
4532 _Success_(return != -1)
4533 NTSYSAPI
4534 ULONG
4535 NTAPI
4536 RtlFindSetBitsAndClear(
4537  _In_ PRTL_BITMAP BitMapHeader,
4538  _In_ ULONG NumberToFind,
4539  _In_ ULONG HintIndex
4540  );
4541 
4542 NTSYSAPI
4543 VOID
4544 NTAPI
4545 RtlClearBits(
4546  _In_ PRTL_BITMAP BitMapHeader,
4547  _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToClear) ULONG StartingIndex,
4548  _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToClear
4549  );
4550 
4551 NTSYSAPI
4552 VOID
4553 NTAPI
4554 RtlSetBits(
4555  _In_ PRTL_BITMAP BitMapHeader,
4556  _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex,
4557  _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet
4558  );
4559 
4560 typedef struct _RTL_BITMAP_RUN
4561 {
4565 
4566 NTSYSAPI
4567 ULONG
4568 NTAPI
4570  _In_ PRTL_BITMAP BitMapHeader,
4571  _Out_writes_to_(SizeOfRunArray, return) PRTL_BITMAP_RUN RunArray,
4572  _In_range_(>, 0) ULONG SizeOfRunArray,
4573  _In_ BOOLEAN LocateLongestRuns
4574  );
4575 
4576 NTSYSAPI
4577 ULONG
4578 NTAPI
4580  _In_ PRTL_BITMAP BitMapHeader,
4581  _Out_ PULONG StartingIndex
4582  );
4583 
4584 NTSYSAPI
4585 ULONG
4586 NTAPI
4588  _In_ PRTL_BITMAP BitMapHeader,
4589  _Out_ PULONG StartingIndex
4590  );
4591 
4592 _Check_return_
4593 FORCEINLINE
4594 BOOLEAN
4596  _In_ PRTL_BITMAP BitMapHeader,
4597  _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitPosition
4598  )
4599 {
4600 #ifdef _WIN64
4601  return BitTest64((LONG64 const *)BitMapHeader->Buffer, (LONG64)BitPosition);
4602 #else
4603  return (((PLONG)BitMapHeader->Buffer)[BitPosition / 32] >> (BitPosition % 32)) & 0x1;
4604 #endif
4605 }
4606 
4607 NTSYSAPI
4608 ULONG
4609 NTAPI
4611  _In_ PRTL_BITMAP BitMapHeader
4612  );
4613 
4614 NTSYSAPI
4615 ULONG
4616 NTAPI
4618  _In_ PRTL_BITMAP BitMapHeader
4619  );
4620 
4621 _Check_return_
4622 NTSYSAPI
4623 BOOLEAN
4624 NTAPI
4626  _In_ PRTL_BITMAP BitMapHeader,
4627  _In_ ULONG StartingIndex,
4628  _In_ ULONG Length
4629  );
4630 
4631 _Check_return_
4632 NTSYSAPI
4633 BOOLEAN
4634 NTAPI
4636  _In_ PRTL_BITMAP BitMapHeader,
4637  _In_ ULONG StartingIndex,
4638  _In_ ULONG Length
4639  );
4640 
4641 NTSYSAPI
4642 ULONG
4643 NTAPI
4645  _In_ PRTL_BITMAP BitMapHeader,
4646  _In_ ULONG FromIndex,
4647  _Out_ PULONG StartingRunIndex
4648  );
4649 
4650 NTSYSAPI
4651 ULONG
4652 NTAPI
4654  _In_ PRTL_BITMAP BitMapHeader,
4655  _In_ ULONG FromIndex,
4656  _Out_ PULONG StartingRunIndex
4657  );
4658 
4659 #if (PHNT_VERSION >= PHNT_WIN7)
4660 
4661 // rev
4662 NTSYSAPI
4663 VOID
4664 NTAPI
4666  _In_ PRTL_BITMAP BitMapHeader,
4667  _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToClear) ULONG StartingIndex,
4668  _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToClear
4669  );
4670 
4671 // rev
4672 NTSYSAPI
4673 VOID
4674 NTAPI
4676  _In_ PRTL_BITMAP BitMapHeader,
4677  _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex,
4678  _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet
4679  );
4680 
4681 #endif
4682 
4683 // Handle tables
4684 
4686 {
4687  union
4688  {
4689  ULONG Flags; // allocated entries have the low bit set
4691  };
4693 
4694 #define RTL_HANDLE_ALLOCATED (USHORT)0x0001
4695 
4696 typedef struct _RTL_HANDLE_TABLE
4697 {
4700  ULONG Reserved[2];
4701  PRTL_HANDLE_TABLE_ENTRY FreeHandles;
4702  PRTL_HANDLE_TABLE_ENTRY CommittedHandles;
4703  PRTL_HANDLE_TABLE_ENTRY UnCommittedHandles;
4704  PRTL_HANDLE_TABLE_ENTRY MaxReservedHandles;
4706 
4707 NTSYSAPI
4708 VOID
4709 NTAPI
4711  _In_ ULONG MaximumNumberOfHandles,
4712  _In_ ULONG SizeOfHandleTableEntry,
4713  _Out_ PRTL_HANDLE_TABLE HandleTable
4714  );
4715 
4716 NTSYSAPI
4717 NTSTATUS
4718 NTAPI
4720  _Inout_ PRTL_HANDLE_TABLE HandleTable
4721  );
4722 
4723 NTSYSAPI
4724 PRTL_HANDLE_TABLE_ENTRY
4725 NTAPI
4727  _In_ PRTL_HANDLE_TABLE HandleTable,
4728  _Out_opt_ PULONG HandleIndex
4729  );
4730 
4731 NTSYSAPI
4732 BOOLEAN
4733 NTAPI
4735  _In_ PRTL_HANDLE_TABLE HandleTable,
4736  _In_ PRTL_HANDLE_TABLE_ENTRY Handle
4737  );
4738 
4739 NTSYSAPI
4740 BOOLEAN
4741 NTAPI
4743  _In_ PRTL_HANDLE_TABLE HandleTable,
4744  _In_ PRTL_HANDLE_TABLE_ENTRY Handle
4745  );
4746 
4747 NTSYSAPI
4748 BOOLEAN
4749 NTAPI
4751  _In_ PRTL_HANDLE_TABLE HandleTable,
4752  _In_ ULONG HandleIndex,
4753  _Out_ PRTL_HANDLE_TABLE_ENTRY *Handle
4754  );
4755 
4756 // Atom tables
4757 
4758 #define RTL_ATOM_MAXIMUM_INTEGER_ATOM (RTL_ATOM)0xc000
4759 #define RTL_ATOM_INVALID_ATOM (RTL_ATOM)0x0000
4760 #define RTL_ATOM_TABLE_DEFAULT_NUMBER_OF_BUCKETS 37
4761 #define RTL_ATOM_MAXIMUM_NAME_LENGTH 255
4762 #define RTL_ATOM_PINNED 0x01
4763 
4764 NTSYSAPI
4765 NTSTATUS
4766 NTAPI
4768  _In_ ULONG NumberOfBuckets,
4769  _Out_ PVOID *AtomTableHandle
4770  );
4771 
4772 NTSYSAPI
4773 NTSTATUS
4774 NTAPI
4776  _In_ _Post_invalid_ PVOID AtomTableHandle
4777  );
4778 
4779 NTSYSAPI
4780 NTSTATUS
4781 NTAPI
4783  _In_ PVOID AtomTableHandle,
4784  _In_ BOOLEAN IncludePinnedAtoms
4785  );
4786 
4787 NTSYSAPI
4788 NTSTATUS
4789 NTAPI
4791  _In_ PVOID AtomTableHandle,
4792  _In_ PWSTR AtomName,
4793  _Inout_opt_ PRTL_ATOM Atom
4794  );
4795 
4796 NTSYSAPI
4797 NTSTATUS
4798 NTAPI
4800  _In_ PVOID AtomTableHandle,
4801  _In_ PWSTR AtomName,
4802  _Out_opt_ PRTL_ATOM Atom
4803  );
4804 
4805 NTSYSAPI
4806 NTSTATUS
4807 NTAPI
4809  _In_ PVOID AtomTableHandle,
4810  _In_ RTL_ATOM Atom
4811  );
4812 
4813 NTSYSAPI
4814 NTSTATUS
4815 NTAPI
4817  _In_ PVOID AtomTableHandle,
4818  _In_ RTL_ATOM Atom
4819  );
4820 
4821 NTSYSAPI
4822 NTSTATUS
4823 NTAPI
4825  _In_ PVOID AtomTableHandle,
4826  _In_ RTL_ATOM Atom,
4827  _Out_opt_ PULONG AtomUsage,
4828  _Out_opt_ PULONG AtomFlags,
4829  _Inout_updates_bytes_to_opt_(*AtomNameLength, *AtomNameLength) PWSTR AtomName,
4830  _Inout_opt_ PULONG AtomNameLength
4831  );
4832 
4833 #if (PHNT_VERSION >= PHNT_VISTA)
4834 // rev
4835 NTSYSAPI
4836 BOOLEAN
4837 NTAPI
4839  _In_ PWSTR AtomName,
4840  _Out_opt_ PUSHORT IntegerAtom
4841  );
4842 #endif
4843 
4844 // SIDs
4845 
4846 _Check_return_
4847 NTSYSAPI
4848 BOOLEAN
4849 NTAPI
4850 RtlValidSid(
4851  _In_ PSID Sid
4852  );
4853 
4854 _Check_return_
4855 NTSYSAPI
4856 BOOLEAN
4857 NTAPI
4858 RtlEqualSid(
4859  _In_ PSID Sid1,
4860  _In_ PSID Sid2
4861  );
4862 
4863 NTSYSAPI
4864 ULONG
4865 NTAPI
4867  _In_ ULONG SubAuthorityCount
4868  );
4869 
4870 NTSYSAPI
4871 PVOID
4872 NTAPI
4873 RtlFreeSid(
4874  _In_ _Post_invalid_ PSID Sid
4875  );
4876 
4877 _Check_return_
4878 NTSYSAPI
4879 NTSTATUS
4880 NTAPI
4882  _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
4883  _In_ UCHAR SubAuthorityCount,
4884  _In_ ULONG SubAuthority0,
4885  _In_ ULONG SubAuthority1,
4886  _In_ ULONG SubAuthority2,
4887  _In_ ULONG SubAuthority3,
4888  _In_ ULONG SubAuthority4,
4889  _In_ ULONG SubAuthority5,
4890  _In_ ULONG SubAuthority6,
4891  _In_ ULONG SubAuthority7,
4892  _Outptr_ PSID *Sid
4893  );
4894 
4895 NTSYSAPI
4896 NTSTATUS
4897 NTAPI
4899  _Out_ PSID Sid,
4900  _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
4901  _In_ UCHAR SubAuthorityCount
4902  );
4903 
4904 #if (PHNT_VERSION >= PHNT_THRESHOLD)
4905 NTSYSAPI
4906 NTSTATUS
4907 NTAPI
4909  _Out_writes_bytes_(SECURITY_SID_SIZE(SubAuthorityCount)) PSID Sid,
4910  _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
4911  _In_ UCHAR SubAuthorityCount,
4912  ...
4913  );
4914 #endif
4915 
4916 NTSYSAPI
4917 PSID_IDENTIFIER_AUTHORITY
4918 NTAPI
4920  _In_ PSID Sid
4921  );
4922 
4923 NTSYSAPI
4924 PULONG
4925 NTAPI
4927  _In_ PSID Sid,
4928  _In_ ULONG SubAuthority
4929  );
4930 
4931 NTSYSAPI
4932 PUCHAR
4933 NTAPI
4935  _In_ PSID Sid
4936  );
4937 
4938 NTSYSAPI
4939 ULONG
4940 NTAPI
4941 RtlLengthSid(
4942  _In_ PSID Sid
4943  );
4944 
4945 NTSYSAPI
4946 NTSTATUS
4947 NTAPI
4948 RtlCopySid(
4949  _In_ ULONG DestinationSidLength,
4950  _In_reads_bytes_(DestinationSidLength) PSID DestinationSid,
4951  _In_ PSID SourceSid
4952  );
4953 
4954 #if (PHNT_VERSION >= PHNT_VISTA)
4955 NTSYSAPI
4956 NTSTATUS
4957 NTAPI
4960  _Out_writes_bytes_opt_(*ServiceSidLength) PSID ServiceSid,
4961  _Inout_ PULONG ServiceSidLength
4962  );
4963 #endif
4964 
4965 #if (PHNT_VERSION >= PHNT_VISTA)
4966 // private
4967 NTSYSAPI
4968 NTSTATUS
4969 NTAPI
4971  _In_ PSID Sid1,
4972  _In_ PSID Sid2,
4973  _Out_ PBOOLEAN pbDominate
4974  );
4975 #endif
4976 
4977 #if (PHNT_VERSION >= PHNT_VISTA)
4978 // private
4979 NTSYSAPI
4980 NTSTATUS
4981 NTAPI
4983  _In_ PSID Sid1,
4984  _In_ PSID Sid2,
4985  _Out_ PBOOLEAN pbEqual
4986  );
4987 #endif
4988 
4989 #if (PHNT_VERSION >= PHNT_VISTA)
4990 // private
4991 NTSYSAPI
4992 NTSTATUS
4993 NTAPI
4995  _In_ PSID Sid1,
4996  _In_ PSID Sid2,
4997  _Out_ PBOOLEAN pbHigher
4998  );
4999 #endif
5000 
5001 #if (PHNT_VERSION >= PHNT_WIN7)
5002 NTSYSAPI
5003 NTSTATUS
5004 NTAPI
5006  _In_ PUNICODE_STRING Name,
5007  _In_ ULONG BaseSubAuthority,
5008  _Out_writes_bytes_(*SidLength) PSID Sid,
5009  _Inout_ PULONG SidLength
5010  );
5011 #endif
5012 
5013 #if (PHNT_VERSION >= PHNT_WIN7)
5014 NTSYSAPI
5015 NTSTATUS
5016 NTAPI
5018  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5019  _In_ PSID OldSid,
5020  _In_ PSID NewSid,
5021  _Out_ ULONG *NumChanges
5022  );
5023 #endif
5024 
5025 #define MAX_UNICODE_STACK_BUFFER_LENGTH 256
5026 
5027 NTSYSAPI
5028 NTSTATUS
5029 NTAPI
5031  _Inout_ PUNICODE_STRING UnicodeString,
5032  _In_ PSID Sid,
5033  _In_ BOOLEAN AllocateDestinationString
5034  );
5035 
5036 #if (PHNT_VERSION >= PHNT_VISTA)
5037 // private
5038 NTSYSAPI
5039 NTSTATUS
5040 NTAPI
5042  _In_reads_(SidCount) PSID_AND_ATTRIBUTES SidAttr,
5043  _In_ ULONG SidCount,
5044  _Out_ PSID_AND_ATTRIBUTES_HASH SidAttrHash
5045  );
5046 #endif
5047 
5048 #if (PHNT_VERSION >= PHNT_VISTA)
5049 // private
5050 NTSYSAPI
5051 PSID_AND_ATTRIBUTES
5052 NTAPI
5054  _In_ PSID_AND_ATTRIBUTES_HASH SidAttrHash,
5055  _In_ PSID Sid
5056  );
5057 #endif
5058 
5059 // Security Descriptors
5060 
5061 NTSYSAPI
5062 NTSTATUS
5063 NTAPI
5065  _Out_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5066  _In_ ULONG Revision
5067  );
5068 
5069 _Check_return_
5070 NTSYSAPI
5071 BOOLEAN
5072 NTAPI
5074  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor
5075  );
5076 
5077 NTSYSAPI
5078 ULONG
5079 NTAPI
5081  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor
5082  );
5083 
5084 _Check_return_
5085 NTSYSAPI
5086 BOOLEAN
5087 NTAPI
5089  _In_reads_bytes_(SecurityDescriptorLength) PSECURITY_DESCRIPTOR SecurityDescriptorInput,
5090  _In_ ULONG SecurityDescriptorLength,
5091  _In_ SECURITY_INFORMATION RequiredInformation
5092  );
5093 
5094 NTSYSAPI
5095 NTSTATUS
5096 NTAPI
5098  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5099  _Out_ PSECURITY_DESCRIPTOR_CONTROL Control,
5100  _Out_ PULONG Revision
5101  );
5102 
5103 NTSYSAPI
5104 NTSTATUS
5105 NTAPI
5107  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5108  _In_ SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
5109  _In_ SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
5110  );
5111 
5112 NTSYSAPI
5113 NTSTATUS
5114 NTAPI
5116  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5117  _In_ SECURITY_DESCRIPTOR_CONTROL Control,
5118  _Out_ PULONG Revision
5119  );
5120 
5121 NTSYSAPI
5122 BOOLEAN
5123 NTAPI
5125  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5126  _Out_ PUCHAR RMControl
5127  );
5128 
5129 NTSYSAPI
5130 VOID
5131 NTAPI
5133  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5134  _In_opt_ PUCHAR RMControl
5135  );
5136 
5137 NTSYSAPI
5138 NTSTATUS
5139 NTAPI
5141  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5142  _In_ BOOLEAN DaclPresent,
5143  _In_opt_ PACL Dacl,
5144  _In_opt_ BOOLEAN DaclDefaulted
5145  );
5146 
5147 NTSYSAPI
5148 NTSTATUS
5149 NTAPI
5151  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5152  _Out_ PBOOLEAN DaclPresent,
5153  _Out_ PACL *Dacl,
5154  _Out_ PBOOLEAN DaclDefaulted
5155  );
5156 
5157 NTSYSAPI
5158 NTSTATUS
5159 NTAPI
5161  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5162  _In_ BOOLEAN SaclPresent,
5163  _In_opt_ PACL Sacl,
5164  _In_opt_ BOOLEAN SaclDefaulted
5165  );
5166 
5167 NTSYSAPI
5168 NTSTATUS
5169 NTAPI
5171  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5172  _Out_ PBOOLEAN SaclPresent,
5173  _Out_ PACL *Sacl,
5174  _Out_ PBOOLEAN SaclDefaulted
5175  );
5176 
5177 NTSYSAPI
5178 NTSTATUS
5179 NTAPI
5181  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5182  _Out_ PBOOLEAN SaclPresent,
5183  _Out_ PACL *Sacl,
5184  _Out_ PBOOLEAN SaclDefaulted
5185  );
5186 
5187 NTSYSAPI
5188 NTSTATUS
5189 NTAPI
5191  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5192  _In_opt_ PSID Owner,
5193  _In_opt_ BOOLEAN OwnerDefaulted
5194  );
5195 
5196 NTSYSAPI
5197 NTSTATUS
5198 NTAPI
5200  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5201  _Out_ PSID *Owner,
5202  _Out_ PBOOLEAN OwnerDefaulted
5203  );
5204 
5205 NTSYSAPI
5206 NTSTATUS
5207 NTAPI
5209  _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5210  _In_opt_ PSID Group,
5211  _In_opt_ BOOLEAN GroupDefaulted
5212  );
5213 
5214 NTSYSAPI
5215 NTSTATUS
5216 NTAPI
5218  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
5219  _Out_ PSID *Group,
5220  _Out_ PBOOLEAN GroupDefaulted
5221  );
5222 
5223 NTSYSAPI
5224 NTSTATUS
5225 NTAPI
5227  _In_ PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
5228  _Out_writes_bytes_(*BufferLength) PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
5229  _Inout_ PULONG BufferLength
5230  );
5231 
5232 NTSYSAPI
5233 NTSTATUS
5234 NTAPI
5236  _In_ PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
5237  _Out_writes_bytes_to_opt_(*BufferLength, *BufferLength) PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
5238  _Inout_ PULONG BufferLength
5239  );
5240 
5241 NTSYSAPI
5242 NTSTATUS
5243 NTAPI
5245  _In_ PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
5246  _Out_writes_bytes_to_opt_(*AbsoluteSecurityDescriptorSize, *AbsoluteSecurityDescriptorSize) PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
5247  _Inout_ PULONG AbsoluteSecurityDescriptorSize,
5248  _Out_writes_bytes_to_opt_(*DaclSize, *DaclSize) PACL Dacl,
5249  _Inout_ PULONG DaclSize,
5250  _Out_writes_bytes_to_opt_(*SaclSize, *SaclSize) PACL Sacl,
5251  _Inout_ PULONG SaclSize,
5252  _Out_writes_bytes_to_opt_(*OwnerSize, *OwnerSize) PSID Owner,
5253  _Inout_ PULONG OwnerSize,
5254  _Out_writes_bytes_to_opt_(*PrimaryGroupSize, *PrimaryGroupSize) PSID PrimaryGroup,
5255  _Inout_ PULONG PrimaryGroupSize
5256  );
5257 
5258 // private
5259 NTSYSAPI
5260 NTSTATUS
5261 NTAPI
5263  _Inout_ PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
5264  _Inout_ PULONG pBufferSize
5265  );
5266 
5267 // Access masks
5268 
5269 NTSYSAPI
5270 BOOLEAN
5271 NTAPI
5273  _In_ ACCESS_MASK GrantedAccess,
5274  _In_ ACCESS_MASK DesiredAccess
5275  );
5276 
5277 NTSYSAPI
5278 BOOLEAN
5279 NTAPI
5281  _In_ ACCESS_MASK GrantedAccess,
5282  _In_ ACCESS_MASK DesiredAccess
5283  );
5284 
5285 NTSYSAPI
5286 VOID
5287 NTAPI
5289  _Inout_ PACCESS_MASK AccessMask,
5290  _In_ PGENERIC_MAPPING GenericMapping
5291  );
5292 
5293 // ACLs
5294 
5295 NTSYSAPI
5296 NTSTATUS
5297 NTAPI
5298 RtlCreateAcl(
5299  _Out_writes_bytes_(AclLength) PACL Acl,
5300  _In_ ULONG AclLength,
5301  _In_ ULONG AclRevision
5302  );
5303 
5304 NTSYSAPI
5305 BOOLEAN
5306 NTAPI
5307 RtlValidAcl(
5308  _In_ PACL Acl
5309  );
5310 
5311 NTSYSAPI
5312 NTSTATUS
5313 NTAPI
5315  _In_ PACL Acl,
5316  _Out_writes_bytes_(AclInformationLength) PVOID AclInformation,
5317  _In_ ULONG AclInformationLength,
5318  _In_ ACL_INFORMATION_CLASS AclInformationClass
5319  );
5320 
5321 NTSYSAPI
5322 NTSTATUS
5323 NTAPI
5325  _Inout_ PACL Acl,
5326  _In_reads_bytes_(AclInformationLength) PVOID AclInformation,
5327  _In_ ULONG AclInformationLength,
5328  _In_ ACL_INFORMATION_CLASS AclInformationClass
5329  );
5330 
5331 NTSYSAPI
5332 NTSTATUS
5333 NTAPI
5334 RtlAddAce(
5335  _Inout_ PACL Acl,
5336  _In_ ULONG AceRevision,
5337  _In_ ULONG StartingAceIndex,
5338  _In_reads_bytes_(AceListLength) PVOID AceList,
5339  _In_ ULONG AceListLength
5340  );
5341 
5342 NTSYSAPI
5343 NTSTATUS
5344 NTAPI
5345 RtlDeleteAce(
5346  _Inout_ PACL Acl,
5347  _In_ ULONG AceIndex
5348  );
5349 
5350 NTSYSAPI
5351 NTSTATUS
5352 NTAPI
5353 RtlGetAce(
5354  _In_ PACL Acl,
5355  _In_ ULONG AceIndex,
5356  _Outptr_ PVOID *Ace
5357  );
5358 
5359 NTSYSAPI
5360 BOOLEAN
5361 NTAPI
5363  _In_ PACL Acl,
5364  _Out_ PVOID *FirstFree
5365  );
5366 
5367 #if (PHNT_VERSION >= PHNT_VISTA)
5368 // private
5369 NTSYSAPI
5370 PVOID
5371 NTAPI
5373  _In_ PACL pAcl,
5374  _In_ UCHAR AceType,
5375  _Out_opt_ PULONG pIndex
5376  );
5377 #endif
5378 
5379 #if (PHNT_VERSION >= PHNT_VISTA)
5380 // private
5381 NTSYSAPI
5382 BOOLEAN
5383 NTAPI
5385  _In_ PACL pAcl
5386  );
5387 #endif
5388 
5389 NTSYSAPI
5390 NTSTATUS
5391 NTAPI
5393  _Inout_ PACL Acl,
5394  _In_ ULONG AceRevision,
5395  _In_ ACCESS_MASK AccessMask,
5396  _In_ PSID Sid
5397  );
5398 
5399 NTSYSAPI
5400 NTSTATUS
5401 NTAPI
5403  _Inout_ PACL Acl,
5404  _In_ ULONG AceRevision,
5405  _In_ ULONG AceFlags,
5406  _In_ ACCESS_MASK AccessMask,
5407  _In_ PSID Sid
5408  );
5409 
5410 NTSYSAPI
5411 NTSTATUS
5412 NTAPI
5414  _Inout_ PACL Acl,
5415  _In_ ULONG AceRevision,
5416  _In_ ACCESS_MASK AccessMask,
5417  _In_ PSID Sid
5418  );
5419 
5420 NTSYSAPI
5421 NTSTATUS
5422 NTAPI
5424  _Inout_ PACL Acl,
5425  _In_ ULONG AceRevision,
5426  _In_ ULONG AceFlags,
5427  _In_ ACCESS_MASK AccessMask,
5428  _In_ PSID Sid
5429  );
5430 
5431 NTSYSAPI
5432 NTSTATUS
5433 NTAPI
5435  _Inout_ PACL Acl,
5436  _In_ ULONG AceRevision,
5437  _In_ ACCESS_MASK AccessMask,
5438  _In_ PSID Sid,
5439  _In_ BOOLEAN AuditSuccess,
5440  _In_ BOOLEAN AuditFailure
5441  );
5442 
5443 NTSYSAPI
5444 NTSTATUS
5445 NTAPI
5447  _Inout_ PACL Acl,
5448  _In_ ULONG AceRevision,
5449  _In_ ULONG AceFlags,
5450  _In_ ACCESS_MASK AccessMask,
5451  _In_ PSID Sid,
5452  _In_ BOOLEAN AuditSuccess,
5453  _In_ BOOLEAN AuditFailure
5454  );
5455 
5456 NTSYSAPI
5457 NTSTATUS
5458 NTAPI
5460  _Inout_ PACL Acl,
5461  _In_ ULONG AceRevision,
5462  _In_ ULONG AceFlags,
5463  _In_ ACCESS_MASK AccessMask,
5464  _In_opt_ PGUID ObjectTypeGuid,
5465  _In_opt_ PGUID InheritedObjectTypeGuid,
5466  _In_ PSID Sid
5467  );
5468 
5469 NTSYSAPI
5470 NTSTATUS
5471 NTAPI
5473  _Inout_ PACL Acl,
5474  _In_ ULONG AceRevision,
5475  _In_ ULONG AceFlags,
5476  _In_ ACCESS_MASK AccessMask,
5477  _In_opt_ PGUID ObjectTypeGuid,
5478  _In_opt_ PGUID InheritedObjectTypeGuid,
5479  _In_ PSID Sid
5480  );
5481 
5482 NTSYSAPI
5483 NTSTATUS
5484 NTAPI
5486  _Inout_ PACL Acl,
5487  _In_ ULONG AceRevision,
5488  _In_ ULONG AceFlags,
5489  _In_ ACCESS_MASK AccessMask,
5490  _In_opt_ PGUID ObjectTypeGuid,
5491  _In_opt_ PGUID InheritedObjectTypeGuid,
5492  _In_ PSID Sid,
5493  _In_ BOOLEAN AuditSuccess,
5494  _In_ BOOLEAN AuditFailure
5495  );
5496 
5497 NTSYSAPI
5498 NTSTATUS
5499 NTAPI
5501  _Inout_ PACL Acl,
5502  _In_ ULONG AceRevision,
5503  _In_ UCHAR AceType,
5504  _In_ ACCESS_MASK AccessMask,
5505  _In_ PSID ServerSid,
5506  _In_ PSID ClientSid
5507  );
5508 
5509 #if (PHNT_VERSION >= PHNT_VISTA)
5510 // private
5511 NTSYSAPI
5512 NTSTATUS
5513 NTAPI
5515  _Inout_ PACL Acl,
5516  _In_ ULONG AceRevision,
5517  _In_ ULONG AceFlags,
5518  _In_ PSID Sid,
5519  _In_ UCHAR AceType,
5520  _In_ ACCESS_MASK AccessMask
5521  );
5522 #endif
5523 
5524 // Security objects
5525 
5526 NTSYSAPI
5527 NTSTATUS
5528 NTAPI
5530  _In_opt_ PSECURITY_DESCRIPTOR ParentDescriptor,
5531  _In_opt_ PSECURITY_DESCRIPTOR CreatorDescriptor,
5532  _Out_ PSECURITY_DESCRIPTOR *NewDescriptor,
5533  _In_ BOOLEAN IsDirectoryObject,
5534  _In_opt_ HANDLE Token,
5535  _In_ PGENERIC_MAPPING GenericMapping
5536  );
5537 
5538 NTSYSAPI
5539 NTSTATUS
5540 NTAPI
5542  _In_opt_ PSECURITY_DESCRIPTOR ParentDescriptor,
5543  _In_opt_ PSECURITY_DESCRIPTOR CreatorDescriptor,
5544  _Out_ PSECURITY_DESCRIPTOR *NewDescriptor,
5545  _In_opt_ GUID *ObjectType,
5546  _In_ BOOLEAN IsDirectoryObject,
5547  _In_ ULONG AutoInheritFlags, // SEF_*
5548  _In_opt_ HANDLE Token,
5549  _In_ PGENERIC_MAPPING GenericMapping
5550  );
5551 
5552 NTSYSAPI
5553 NTSTATUS
5554 NTAPI
5556  _In_opt_ PSECURITY_DESCRIPTOR ParentDescriptor,
5557  _In_opt_ PSECURITY_DESCRIPTOR CreatorDescriptor,
5558  _Out_ PSECURITY_DESCRIPTOR *NewDescriptor,
5559  _In_opt_ GUID **ObjectType,
5560  _In_ ULONG GuidCount,
5561  _In_ BOOLEAN IsDirectoryObject,
5562  _In_ ULONG AutoInheritFlags, // SEF_*
5563  _In_opt_ HANDLE Token,
5564  _In_ PGENERIC_MAPPING GenericMapping
5565  );
5566 
5567 NTSYSAPI
5568 NTSTATUS
5569 NTAPI
5571  _Inout_ PSECURITY_DESCRIPTOR *ObjectDescriptor
5572  );
5573 
5574 NTSYSAPI
5575 NTSTATUS
5576 NTAPI
5578  _In_ PSECURITY_DESCRIPTOR ObjectDescriptor,
5579  _In_ SECURITY_INFORMATION SecurityInformation,
5580  _Out_opt_ PSECURITY_DESCRIPTOR ResultantDescriptor,
5581  _In_ ULONG DescriptorLength,
5582  _Out_ PULONG ReturnLength
5583  );
5584 
5585 NTSYSAPI
5586 NTSTATUS
5587 NTAPI
5589  _In_ SECURITY_INFORMATION SecurityInformation,
5590  _In_ PSECURITY_DESCRIPTOR ModificationDescriptor,
5591  _Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
5592  _In_ PGENERIC_MAPPING GenericMapping,
5593  _In_opt_ HANDLE Token
5594  );
5595 
5596 NTSYSAPI
5597 NTSTATUS
5598 NTAPI
5600  _In_ SECURITY_INFORMATION SecurityInformation,
5601  _In_ PSECURITY_DESCRIPTOR ModificationDescriptor,
5602  _Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
5603  _In_ ULONG AutoInheritFlags, // SEF_*
5604  _In_ PGENERIC_MAPPING GenericMapping,
5605  _In_opt_ HANDLE Token
5606  );
5607 
5608 NTSYSAPI
5609 NTSTATUS
5610 NTAPI
5612  _In_opt_ PSECURITY_DESCRIPTOR ParentDescriptor,
5613  _In_ PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,
5614  _Out_ PSECURITY_DESCRIPTOR *NewSecurityDescriptor,
5615  _In_opt_ GUID *ObjectType,
5616  _In_ BOOLEAN IsDirectoryObject,
5617  _In_ PGENERIC_MAPPING GenericMapping
5618  );
5619 
5620 NTSYSAPI
5621 NTSTATUS
5622 NTAPI
5624  _In_ BOOLEAN ParentDescriptorChanged,
5625  _In_ BOOLEAN CreatorDescriptorChanged,
5626  _In_ PLUID OldClientTokenModifiedId,
5627  _Out_ PLUID NewClientTokenModifiedId,
5628  _In_opt_ PSECURITY_DESCRIPTOR ParentDescriptor,
5629  _In_opt_ PSECURITY_DESCRIPTOR CreatorDescriptor,
5630  _Out_ PSECURITY_DESCRIPTOR *NewDescriptor,
5631  _In_ BOOLEAN IsDirectoryObject,
5632  _In_ HANDLE Token,
5633  _In_ PGENERIC_MAPPING GenericMapping
5634  );
5635 
5636 NTSYSAPI
5637 NTSTATUS
5638 NTAPI
5640  _In_ PSECURITY_DESCRIPTOR InputSecurityDescriptor,
5641  _Out_ PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
5642  );
5643 
5644 // Misc. security
5645 
5646 NTSYSAPI
5647 VOID
5648 NTAPI
5650  _Inout_ PUCHAR Seed,
5651  _In_ PUNICODE_STRING String
5652  );
5653 
5654 NTSYSAPI
5655 VOID
5656 NTAPI
5658  _In_ UCHAR Seed,
5659  _In_ PUNICODE_STRING String
5660  );
5661 
5662 NTSYSAPI
5663 NTSTATUS
5664 NTAPI
5666  _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
5667  );
5668 
5669 #if (PHNT_VERSION >= PHNT_VISTA)
5670 // private
5671 NTSYSAPI
5672 NTSTATUS
5673 NTAPI
5675  _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
5676  _In_opt_ ACCESS_MASK AdditionalAccess,
5677  _Out_opt_ PHANDLE ThreadToken
5678  );
5679 #endif
5680 
5681 NTSYSAPI
5682 NTSTATUS
5683 NTAPI
5685  _In_ ULONG Privilege,
5686  _In_ BOOLEAN Enable,
5687  _In_ BOOLEAN Client,
5688  _Out_ PBOOLEAN WasEnabled
5689  );
5690 
5691 #define RTL_ACQUIRE_PRIVILEGE_REVERT 0x00000001
5692 #define RTL_ACQUIRE_PRIVILEGE_PROCESS 0x00000002
5693 
5694 NTSYSAPI
5695 NTSTATUS
5696 NTAPI
5698  _In_ PULONG Privilege,
5699  _In_ ULONG NumPriv,
5700  _In_ ULONG Flags,
5701  _Out_ PVOID *ReturnedState
5702  );
5703 
5704 NTSYSAPI
5705 VOID
5706 NTAPI
5708  _In_ PVOID StatePointer
5709  );
5710 
5711 #if (PHNT_VERSION >= PHNT_VISTA)
5712 // private
5713 NTSYSAPI
5714 NTSTATUS
5715 NTAPI
5717  _In_ HANDLE hToken,
5718  _In_ PULONG PrivilegesToKeep,
5719  _In_ ULONG PrivilegeCount
5720  );
5721 #endif
5722 
5723 #if (PHNT_VERSION >= PHNT_WIN8)
5724 
5725 NTSYSAPI
5726 NTSTATUS
5727 NTAPI
5729  _In_opt_ HANDLE Handle,
5730  _In_opt_ PVOID Object,
5731  _Out_ PBOOLEAN UntrustedObject
5732  );
5733 
5734 NTSYSAPI
5735 ULONG
5736 NTAPI
5738  _In_opt_ PCUNICODE_STRING ComponentName
5739  );
5740 
5741 #endif
5742 
5743 // Private namespaces
5744 
5745 #if (PHNT_VERSION >= PHNT_VISTA)
5746 
5747 // begin_private
5748 
5749 NTSYSAPI
5750 PVOID
5751 NTAPI
5753  _In_ PUNICODE_STRING Name,
5754  _In_ ULONG Flags
5755  );
5756 
5757 NTSYSAPI
5758 VOID
5759 NTAPI
5761  _In_ PVOID BoundaryDescriptor
5762  );
5763 
5764 NTSYSAPI
5765 NTSTATUS
5766 NTAPI
5768  _Inout_ PVOID *BoundaryDescriptor,
5769  _In_ PSID RequiredSid
5770  );
5771 
5772 #if (PHNT_VERSION >= PHNT_WIN7)
5773 // rev
5774 NTSYSAPI
5775 NTSTATUS
5776 NTAPI
5778  _Inout_ PVOID *BoundaryDescriptor,
5779  _In_ PSID IntegrityLabel
5780  );
5781 #endif
5782 
5783 // end_private
5784 
5785 #endif
5786 
5787 // Version
5788 
5789 NTSYSAPI
5790 NTSTATUS
5791 NTAPI
5793  _Out_ PRTL_OSVERSIONINFOW lpVersionInformation
5794  );
5795 
5796 NTSYSAPI
5797 NTSTATUS
5798 NTAPI
5800  _In_ PRTL_OSVERSIONINFOEXW VersionInfo,
5801  _In_ ULONG TypeMask,
5802  _In_ ULONGLONG ConditionMask
5803  );
5804 
5805 // System information
5806 
5807 NTSYSAPI
5808 ULONG
5809 NTAPI
5811  VOID
5812  );
5813 
5814 NTSYSAPI
5815 BOOLEAN
5816 NTAPI
5818  _Out_ PNT_PRODUCT_TYPE NtProductType
5819  );
5820 
5821 // rev
5822 NTSYSAPI
5823 VOID
5824 NTAPI
5826  _Out_opt_ PULONG pNtMajorVersion,
5827  _Out_opt_ PULONG pNtMinorVersion,
5828  _Out_opt_ PULONG pNtBuildNumber
5829  );
5830 
5832 {
5836 
5837 #if (PHNT_VERSION >= PHNT_THRESHOLD)
5838 NTSYSAPI
5840 NTAPI
5842  _In_ ULONG Flags
5843  );
5844 #endif
5845 
5846 // Thread pool (old)
5847 
5848 NTSYSAPI
5849 NTSTATUS
5850 NTAPI
5852  _Out_ PHANDLE WaitHandle,
5853  _In_ HANDLE Handle,
5854  _In_ WAITORTIMERCALLBACKFUNC Function,
5855  _In_ PVOID Context,
5856  _In_ ULONG Milliseconds,
5857  _In_ ULONG Flags
5858  );
5859 
5860 NTSYSAPI
5861 NTSTATUS
5862 NTAPI
5864  _In_ HANDLE WaitHandle
5865  );
5866 
5867 NTSYSAPI
5868 NTSTATUS
5869 NTAPI
5871  _In_ HANDLE WaitHandle,
5872  _In_ HANDLE Event
5873  );
5874 
5875 NTSYSAPI
5876 NTSTATUS
5877 NTAPI
5879  _In_ WORKERCALLBACKFUNC Function,
5880  _In_ PVOID Context,
5881  _In_ ULONG Flags
5882  );
5883 
5884 NTSYSAPI
5885 NTSTATUS
5886 NTAPI
5888  _In_ HANDLE FileHandle,
5889  _In_ APC_CALLBACK_FUNCTION CompletionProc,
5890  _In_ ULONG Flags
5891  );
5892 
5893 NTSYSAPI
5894 NTSTATUS
5895 NTAPI
5897  _Out_ PHANDLE TimerQueueHandle
5898  );
5899 
5900 NTSYSAPI
5901 NTSTATUS
5902 NTAPI
5904  _In_ HANDLE TimerQueueHandle,
5905  _Out_ PHANDLE Handle,
5906  _In_ WAITORTIMERCALLBACKFUNC Function,
5907  _In_ PVOID Context,
5908  _In_ ULONG DueTime,
5909  _In_ ULONG Period,
5910  _In_ ULONG Flags
5911  );
5912 
5913 NTSYSAPI
5914 NTSTATUS
5915 NTAPI
5917  _In_ HANDLE TimerQueueHandle,
5918  _In_ HANDLE TimerHandle,
5919  _In_ ULONG DueTime,
5920  _In_ ULONG Period
5921  );
5922 
5923 NTSYSAPI
5924 NTSTATUS
5925 NTAPI
5927  _In_ HANDLE TimerQueueHandle,
5928  _In_ HANDLE TimerToCancel,
5929  _In_ HANDLE Event
5930  );
5931 
5932 NTSYSAPI
5933 NTSTATUS
5934 NTAPI
5936  _In_ HANDLE TimerQueueHandle
5937  );
5938 
5939 NTSYSAPI
5940 NTSTATUS
5941 NTAPI
5943  _In_ HANDLE TimerQueueHandle,
5944  _In_ HANDLE Event
5945  );
5946 
5947 // Registry access
5948 
5949 NTSYSAPI
5950 NTSTATUS
5951 NTAPI
5953  _Out_ PUNICODE_STRING CurrentUserKeyPath
5954  );
5955 
5956 NTSYSAPI
5957 NTSTATUS
5958 NTAPI
5960  _In_ ACCESS_MASK DesiredAccess,
5961  _Out_ PHANDLE CurrentUserKey
5962  );
5963 
5964 #define RTL_REGISTRY_ABSOLUTE 0
5965 #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
5966 #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
5967 #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
5968 #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
5969 #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
5970 #define RTL_REGISTRY_MAXIMUM 6
5971 #define RTL_REGISTRY_HANDLE 0x40000000
5972 #define RTL_REGISTRY_OPTIONAL 0x80000000
5973 
5974 NTSYSAPI
5975 NTSTATUS
5976 NTAPI
5978  _In_ ULONG RelativeTo,
5979  _In_ PWSTR Path
5980  );
5981 
5982 NTSYSAPI
5983 NTSTATUS
5984 NTAPI
5986  _In_ ULONG RelativeTo,
5987  _In_ PWSTR Path
5988  );
5989 
5990 typedef NTSTATUS (NTAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
5991  _In_ PWSTR ValueName,
5992  _In_ ULONG ValueType,
5993  _In_ PVOID ValueData,
5994  _In_ ULONG ValueLength,
5995  _In_ PVOID Context,
5996  _In_ PVOID EntryContext
5997  );
5998 
6000 {
6002  ULONG Flags;
6003  PWSTR Name;
6009 
6010 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
6011 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
6012 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
6013 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
6014 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
6015 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
6016 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
6017 
6018 NTSYSAPI
6019 NTSTATUS
6020 NTAPI
6022  _In_ ULONG RelativeTo,
6023  _In_ PWSTR Path,
6024  _In_ PRTL_QUERY_REGISTRY_TABLE QueryTable,
6025  _In_ PVOID Context,
6026  _In_opt_ PVOID Environment
6027  );
6028 
6029 NTSYSAPI
6030 NTSTATUS
6031 NTAPI
6033  _In_ ULONG RelativeTo,
6034  _In_ PWSTR Path,
6035  _In_ PWSTR ValueName,
6036  _In_ ULONG ValueType,
6037  _In_ PVOID ValueData,
6038  _In_ ULONG ValueLength
6039  );
6040 
6041 NTSYSAPI
6042 NTSTATUS
6043 NTAPI
6045  _In_ ULONG RelativeTo,
6046  _In_ PWSTR Path,
6047  _In_ PWSTR ValueName
6048  );
6049 
6050 // Debugging
6051 
6052 NTSYSAPI
6053 VOID
6054 NTAPI
6056  VOID
6057  );
6058 
6059 NTSYSAPI
6060 VOID
6061 NTAPI
6063  VOID
6064  );
6065 
6066 NTSYSAPI
6067 VOID
6068 NTAPI
6070  _In_ ULONG Status
6071  );
6072 
6073 #define DBG_STATUS_CONTROL_C 1
6074 #define DBG_STATUS_SYSRQ 2
6075 #define DBG_STATUS_BUGCHECK_FIRST 3
6076 #define DBG_STATUS_BUGCHECK_SECOND 4
6077 #define DBG_STATUS_FATAL 5
6078 #define DBG_STATUS_DEBUG_CONTROL 6
6079 #define DBG_STATUS_WORKER 7
6080 
6081 NTSYSAPI
6082 ULONG
6083 __cdecl
6084 DbgPrint(
6085  _In_z_ _Printf_format_string_ PSTR Format,
6086  ...
6087  );
6088 
6089 NTSYSAPI
6090 ULONG
6091 __cdecl
6092 DbgPrintEx(
6093  _In_ ULONG ComponentId,
6094  _In_ ULONG Level,
6095  _In_z_ _Printf_format_string_ PSTR Format,
6096  ...
6097  );
6098 
6099 NTSYSAPI
6100 ULONG
6101 NTAPI
6102 vDbgPrintEx(
6103  _In_ ULONG ComponentId,
6104  _In_ ULONG Level,
6105  _In_z_ PCH Format,
6106  _In_ va_list arglist
6107  );
6108 
6109 NTSYSAPI
6110 ULONG
6111 NTAPI
6113  _In_z_ PCH Prefix,
6114  _In_ ULONG ComponentId,
6115  _In_ ULONG Level,
6116  _In_z_ PCH Format,
6117  _In_ va_list arglist
6118  );
6119 
6120 NTSYSAPI
6121 NTSTATUS
6122 NTAPI
6124  _In_ ULONG ComponentId,
6125  _In_ ULONG Level
6126  );
6127 
6128 NTSYSAPI
6129 NTSTATUS
6130 NTAPI
6132  _In_ ULONG ComponentId,
6133  _In_ ULONG Level,
6134  _In_ BOOLEAN State
6135  );
6136 
6137 NTSYSAPI
6138 ULONG
6139 NTAPI
6140 DbgPrompt(
6141  _In_ PCH Prompt,
6142  _Out_writes_bytes_(Length) PCH Response,
6143  _In_ ULONG Length
6144  );
6145 
6146 // Thread profiling
6147 
6148 #if (PHNT_VERSION >= PHNT_WIN7)
6149 
6150 // begin_rev
6151 
6152 NTSYSAPI
6153 NTSTATUS
6154 NTAPI
6156  _In_ HANDLE ThreadHandle,
6157  _In_ ULONG Flags,
6158  _In_ ULONG64 HardwareCounters,
6159  _Out_ PVOID *PerformanceDataHandle
6160  );
6161 
6162 NTSYSAPI
6163 NTSTATUS
6164 NTAPI
6166  _In_ PVOID PerformanceDataHandle
6167  );
6168 
6169 NTSYSAPI
6170 NTSTATUS
6171 NTAPI
6173  _In_ HANDLE ThreadHandle,
6174  _Out_ PBOOLEAN Enabled
6175  );
6176 
6177 NTSYSAPI
6178 NTSTATUS
6179 NTAPI
6181  _In_ HANDLE PerformanceDataHandle,
6182  _In_ ULONG Flags,
6183  _Out_ PPERFORMANCE_DATA PerformanceData
6184  );
6185 
6186 // end_rev
6187 
6188 #endif
6189 
6190 // Misc.
6191 
6192 NTSYSAPI
6193 ULONG
6194 NTAPI
6196  VOID
6197  );
6198 
6199 NTSYSAPI
6200 ULONG32
6201 NTAPI
6203  _In_ ULONG32 PartialCrc,
6204  _In_ PVOID Buffer,
6205  _In_ ULONG Length
6206  );
6207 
6208 NTSYSAPI
6209 PVOID
6210 NTAPI
6212  _In_ PVOID Ptr
6213  );
6214 
6215 NTSYSAPI
6216 PVOID
6217 NTAPI
6219  _In_ PVOID Ptr
6220  );
6221 
6222 NTSYSAPI
6223 PVOID
6224 NTAPI
6226  _In_ PVOID Ptr
6227  );
6228 
6229 NTSYSAPI
6230 PVOID
6231 NTAPI
6233  _In_ PVOID Ptr
6234  );
6235 
6236 NTSYSAPI
6237 BOOLEAN
6238 NTAPI
6240  VOID
6241  );
6242 
6243 // begin_private
6244 
6246 {
6247  ULONG Flags;
6248  struct
6249  {
6250  ULONG ElevationEnabled : 1;
6253  ULONG ReservedBits : 29;
6254  };
6256 
6257 #if (PHNT_VERSION >= PHNT_VISTA)
6258 NTSYSAPI
6259 NTSTATUS
6260 NTAPI
6262  _Out_ PRTL_ELEVATION_FLAGS Flags
6263  );
6264 #endif
6265 
6266 // end_private
6267 
6268 #if (PHNT_VERSION >= PHNT_VISTA)
6269 // private
6270 NTSYSAPI
6271 NTSTATUS
6272 NTAPI
6274  VOID
6275  );
6276 #endif
6277 
6278 #if (PHNT_VERSION >= PHNT_VISTA)
6279 // private
6280 NTSYSAPI
6281 NTSTATUS
6282 NTAPI
6284  VOID
6285  );
6286 #endif
6287 
6288 #if (PHNT_VERSION >= PHNT_VISTA)
6289 // private
6290 NTSYSAPI
6291 NTSTATUS
6292 NTAPI
6294  VOID
6295  );
6296 #endif
6297 
6298 #if (PHNT_VERSION >= PHNT_VISTA)
6299 // private
6300 NTSYSAPI
6301 NTSTATUS
6302 NTAPI
6304  _In_ PVOID Address
6305  );
6306 #endif
6307 
6308 #if (PHNT_VERSION >= PHNT_VISTA)
6309 // private
6310 NTSYSAPI
6311 NTSTATUS
6312 NTAPI
6314  _In_ PVOID Address
6315  );
6316 #endif
6317 
6318 // begin_msdn:"Winternl"
6319 
6320 #define RTL_UNLOAD_EVENT_TRACE_NUMBER 64
6321 
6322 // private
6324 {
6326  SIZE_T SizeOfImage;
6327  ULONG Sequence;
6329  ULONG CheckSum;
6330  WCHAR ImageName[32];
6331  ULONG Version[2];
6333 
6334 NTSYSAPI
6335 PRTL_UNLOAD_EVENT_TRACE
6336 NTAPI
6338  VOID
6339  );
6340 
6341 #if (PHNT_VERSION >= PHNT_VISTA)
6342 NTSYSAPI
6343 VOID
6344 NTAPI
6346  _Out_ PULONG *ElementSize,
6347  _Out_ PULONG *ElementCount,
6348  _Out_ PVOID *EventTrace // works across all processes
6349  );
6350 #endif
6351 
6352 // end_msdn
6353 
6354 #if (PHNT_VERSION >= PHNT_WIN7)
6355 // rev
6356 NTSYSAPI
6357 LOGICAL
6358 NTAPI
6360  _Out_ PLARGE_INTEGER PerformanceCounter
6361  );
6362 #endif
6363 
6364 #if (PHNT_VERSION >= PHNT_WIN7)
6365 // rev
6366 NTSYSAPI
6367 LOGICAL
6368 NTAPI
6370  _Out_ PLARGE_INTEGER PerformanceFrequency
6371  );
6372 #endif
6373 
6374 #if (PHNT_VERSION >= PHNT_WIN8)
6375 
6376 NTSYSAPI
6377 ULONG
6378 NTAPI
6379 RtlCrc32(
6380  _In_reads_bytes_(Size) const void *Buffer,
6381  _In_ size_t Size,
6382  _In_ ULONG InitialCrc
6383  );
6384 
6385 NTSYSAPI
6386 ULONGLONG
6387 NTAPI
6388 RtlCrc64(
6389  _In_reads_bytes_(Size) const void *Buffer,
6390  _In_ size_t Size,
6391  _In_ ULONGLONG InitialCrc
6392  );
6393 
6394 #endif
6395 
6396 #endif