xref: /reactos/sdk/include/ndk/rtlfuncs.h (revision 3dcae2ce)
1 /*++ NDK Version: 0098
2 
3 Copyright (c) Alex Ionescu.  All rights reserved.
4 
5 Header Name:
6 
7     rtlfuncs.h
8 
9 Abstract:
10 
11     Function definitions for the Run-Time Library
12 
13 Author:
14 
15     Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006
16 
17 --*/
18 
19 #ifndef _RTLFUNCS_H
20 #define _RTLFUNCS_H
21 
22 //
23 // Dependencies
24 //
25 #include <umtypes.h>
26 #include <ntnls.h>
27 #include <rtltypes.h>
28 #include <pstypes.h>
29 #include <extypes.h>
30 #include "in6addr.h"
31 #include "inaddr.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #ifdef NTOS_MODE_USER
38 
39 //
40 // List Functions
41 //
42 FORCEINLINE
43 VOID
44 InitializeListHead(
45     _Out_ PLIST_ENTRY ListHead
46 )
47 {
48     ListHead->Flink = ListHead->Blink = ListHead;
49 }
50 
51 FORCEINLINE
52 VOID
53 InsertHeadList(
54     _Inout_ PLIST_ENTRY ListHead,
55     _Inout_ PLIST_ENTRY Entry
56 )
57 {
58     PLIST_ENTRY OldFlink;
59     OldFlink = ListHead->Flink;
60     Entry->Flink = OldFlink;
61     Entry->Blink = ListHead;
62     OldFlink->Blink = Entry;
63     ListHead->Flink = Entry;
64 }
65 
66 FORCEINLINE
67 VOID
68 InsertTailList(
69     _Inout_ PLIST_ENTRY ListHead,
70     _Inout_ PLIST_ENTRY Entry
71 )
72 {
73     PLIST_ENTRY OldBlink;
74     OldBlink = ListHead->Blink;
75     Entry->Flink = ListHead;
76     Entry->Blink = OldBlink;
77     OldBlink->Flink = Entry;
78     ListHead->Blink = Entry;
79 }
80 
81 _Must_inspect_result_
82 FORCEINLINE
83 BOOLEAN
84 IsListEmpty(
85     _In_ const LIST_ENTRY * ListHead
86 )
87 {
88     return (BOOLEAN)(ListHead->Flink == ListHead);
89 }
90 
91 FORCEINLINE
92 PSINGLE_LIST_ENTRY
93 PopEntryList(
94     _Inout_ PSINGLE_LIST_ENTRY ListHead
95 )
96 {
97     PSINGLE_LIST_ENTRY FirstEntry;
98     FirstEntry = ListHead->Next;
99     if (FirstEntry != NULL) {
100         ListHead->Next = FirstEntry->Next;
101     }
102 
103     return FirstEntry;
104 }
105 
106 FORCEINLINE
107 VOID
108 PushEntryList(
109     _Inout_ PSINGLE_LIST_ENTRY ListHead,
110     _Inout_ PSINGLE_LIST_ENTRY Entry
111 )
112 {
113     Entry->Next = ListHead->Next;
114     ListHead->Next = Entry;
115 }
116 
117 FORCEINLINE
118 BOOLEAN
119 RemoveEntryList(
120     _In_ PLIST_ENTRY Entry)
121 {
122     PLIST_ENTRY OldFlink;
123     PLIST_ENTRY OldBlink;
124 
125     OldFlink = Entry->Flink;
126     OldBlink = Entry->Blink;
127     OldFlink->Blink = OldBlink;
128     OldBlink->Flink = OldFlink;
129     return (BOOLEAN)(OldFlink == OldBlink);
130 }
131 
132 FORCEINLINE
133 PLIST_ENTRY
134 RemoveHeadList(
135     _Inout_ PLIST_ENTRY ListHead)
136 {
137     PLIST_ENTRY Flink;
138     PLIST_ENTRY Entry;
139 
140     Entry = ListHead->Flink;
141     Flink = Entry->Flink;
142     ListHead->Flink = Flink;
143     Flink->Blink = ListHead;
144     return Entry;
145 }
146 
147 FORCEINLINE
148 PLIST_ENTRY
149 RemoveTailList(
150     _Inout_ PLIST_ENTRY ListHead)
151 {
152     PLIST_ENTRY Blink;
153     PLIST_ENTRY Entry;
154 
155     Entry = ListHead->Blink;
156     Blink = Entry->Blink;
157     ListHead->Blink = Blink;
158     Blink->Flink = ListHead;
159     return Entry;
160 }
161 
162 //
163 // Unicode string macros
164 //
165 _At_(UnicodeString->Buffer, _Post_equal_to_(Buffer))
166 _At_(UnicodeString->Length, _Post_equal_to_(0))
167 _At_(UnicodeString->MaximumLength, _Post_equal_to_(BufferSize))
168 FORCEINLINE
169 VOID
170 RtlInitEmptyUnicodeString(
171     _Out_ PUNICODE_STRING UnicodeString,
172     _When_(BufferSize != 0, _Notnull_) _Writable_bytes_(BufferSize) __drv_aliasesMem PWCHAR Buffer,
173     _In_ USHORT BufferSize)
174 {
175     UnicodeString->Length = 0;
176     UnicodeString->MaximumLength = BufferSize;
177     UnicodeString->Buffer = Buffer;
178 }
179 
180 _At_(AnsiString->Buffer, _Post_equal_to_(Buffer))
181 _At_(AnsiString->Length, _Post_equal_to_(0))
182 _At_(AnsiString->MaximumLength, _Post_equal_to_(BufferSize))
183 FORCEINLINE
184 VOID
185 RtlInitEmptyAnsiString(
186     _Out_ PANSI_STRING AnsiString,
187     _When_(BufferSize != 0, _Notnull_) _Writable_bytes_(BufferSize) __drv_aliasesMem PCHAR Buffer,
188     _In_ USHORT BufferSize)
189 {
190     AnsiString->Length = 0;
191     AnsiString->MaximumLength = BufferSize;
192     AnsiString->Buffer = Buffer;
193 }
194 
195 //
196 // LUID Macros
197 //
198 #define RtlEqualLuid(L1, L2) (((L1)->HighPart == (L2)->HighPart) && \
199                               ((L1)->LowPart  == (L2)->LowPart))
200 FORCEINLINE
201 LUID
202 NTAPI_INLINE
203 RtlConvertUlongToLuid(
204     _In_ ULONG Ulong)
205 {
206     LUID TempLuid;
207 
208     TempLuid.LowPart = Ulong;
209     TempLuid.HighPart = 0;
210     return TempLuid;
211 }
212 
213 //
214 // ASSERT Macros
215 //
216 #ifndef ASSERT
217 #if DBG
218 
219 #define ASSERT( exp ) \
220     ((void)((!(exp)) ? \
221         (RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ),FALSE) : \
222         TRUE))
223 
224 #define ASSERTMSG( msg, exp ) \
225     ((void)((!(exp)) ? \
226         (RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, (PCHAR)msg ),FALSE) : \
227         TRUE))
228 
229 #else
230 
231 #define ASSERT( exp )         ((void) 0)
232 #define ASSERTMSG( msg, exp ) ((void) 0)
233 
234 #endif
235 #endif
236 
237 #ifdef NTOS_KERNEL_RUNTIME
238 
239 //
240 // Executing RTL functions at DISPATCH_LEVEL or higher will result in a
241 // bugcheck.
242 //
243 #define RTL_PAGED_CODE PAGED_CODE
244 
245 #else
246 
247 //
248 // This macro does nothing in user mode
249 //
250 #define RTL_PAGED_CODE()
251 
252 #endif
253 
254 //
255 // RTL Splay Tree Functions
256 //
257 #ifndef RTL_USE_AVL_TABLES
258 
259 NTSYSAPI
260 VOID
261 NTAPI
262 RtlInitializeGenericTable(
263     _Out_ PRTL_GENERIC_TABLE Table,
264     _In_ PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine,
265     _In_opt_ PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine,
266     _In_opt_ PRTL_GENERIC_FREE_ROUTINE FreeRoutine,
267     _In_opt_ PVOID TableContext
268 );
269 
270 NTSYSAPI
271 PVOID
272 NTAPI
273 RtlInsertElementGenericTable(
274     _In_ PRTL_GENERIC_TABLE Table,
275     _In_reads_bytes_(BufferSize) PVOID Buffer,
276     _In_ CLONG BufferSize,
277     _Out_opt_ PBOOLEAN NewElement
278 );
279 
280 NTSYSAPI
281 PVOID
282 NTAPI
283 RtlInsertElementGenericTableFull(
284     _In_ PRTL_GENERIC_TABLE Table,
285     _In_reads_bytes_(BufferSize) PVOID Buffer,
286     _In_ CLONG BufferSize,
287     _Out_opt_ PBOOLEAN NewElement,
288     _In_ PVOID NodeOrParent,
289     _In_ TABLE_SEARCH_RESULT SearchResult
290 );
291 
292 NTSYSAPI
293 BOOLEAN
294 NTAPI
295 RtlDeleteElementGenericTable(
296     _In_ PRTL_GENERIC_TABLE Table,
297     _In_ PVOID Buffer
298 );
299 
300 _Must_inspect_result_
301 NTSYSAPI
302 PVOID
303 NTAPI
304 RtlLookupElementGenericTable(
305     _In_ PRTL_GENERIC_TABLE Table,
306     _In_ PVOID Buffer
307 );
308 
309 NTSYSAPI
310 PVOID
311 NTAPI
312 RtlLookupElementGenericTableFull(
313     _In_ PRTL_GENERIC_TABLE Table,
314     _In_ PVOID Buffer,
315     _Out_ PVOID *NodeOrParent,
316     _Out_ TABLE_SEARCH_RESULT *SearchResult
317 );
318 
319 _Must_inspect_result_
320 NTSYSAPI
321 PVOID
322 NTAPI
323 RtlEnumerateGenericTable(
324     _In_ PRTL_GENERIC_TABLE Table,
325     _In_ BOOLEAN Restart
326 );
327 
328 _Must_inspect_result_
329 NTSYSAPI
330 PVOID
331 NTAPI
332 RtlEnumerateGenericTableWithoutSplaying(
333     _In_ PRTL_GENERIC_TABLE Table,
334     _Inout_ PVOID *RestartKey
335 );
336 
337 _Must_inspect_result_
338 NTSYSAPI
339 PVOID
340 NTAPI
341 RtlGetElementGenericTable(
342     _In_ PRTL_GENERIC_TABLE Table,
343     _In_ ULONG I
344 );
345 
346 NTSYSAPI
347 ULONG
348 NTAPI
349 RtlNumberGenericTableElements(
350     _In_ PRTL_GENERIC_TABLE Table
351 );
352 
353 _Must_inspect_result_
354 NTSYSAPI
355 BOOLEAN
356 NTAPI
357 RtlIsGenericTableEmpty(
358     _In_ PRTL_GENERIC_TABLE Table
359 );
360 
361 #endif /* !RTL_USE_AVL_TABLES */
362 
363 NTSYSAPI
364 PRTL_SPLAY_LINKS
365 NTAPI
366 RtlSplay(
367     _Inout_ PRTL_SPLAY_LINKS Links
368 );
369 
370 NTSYSAPI
371 PRTL_SPLAY_LINKS
372 NTAPI
373 RtlDelete(
374     _In_ PRTL_SPLAY_LINKS Links
375 );
376 
377 NTSYSAPI
378 VOID
379 NTAPI
380 RtlDeleteNoSplay(
381     _In_ PRTL_SPLAY_LINKS Links,
382     _Inout_ PRTL_SPLAY_LINKS *Root
383 );
384 
385 _Must_inspect_result_
386 NTSYSAPI
387 PRTL_SPLAY_LINKS
388 NTAPI
389 RtlSubtreeSuccessor(
390     _In_ PRTL_SPLAY_LINKS Links
391 );
392 
393 _Must_inspect_result_
394 NTSYSAPI
395 PRTL_SPLAY_LINKS
396 NTAPI
397 RtlSubtreePredecessor(
398     _In_ PRTL_SPLAY_LINKS Links
399 );
400 
401 _Must_inspect_result_
402 NTSYSAPI
403 PRTL_SPLAY_LINKS
404 NTAPI
405 RtlRealSuccessor(
406     _In_ PRTL_SPLAY_LINKS Links
407 );
408 
409 _Must_inspect_result_
410 NTSYSAPI
411 PRTL_SPLAY_LINKS
412 NTAPI
413 RtlRealPredecessor(
414     _In_ PRTL_SPLAY_LINKS Links
415 );
416 
417 #define RtlIsLeftChild(Links) \
418     (RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links))
419 
420 #define RtlIsRightChild(Links) \
421     (RtlRightChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links))
422 
423 #define RtlRightChild(Links) \
424     ((PRTL_SPLAY_LINKS)(Links))->RightChild
425 
426 #define RtlIsRoot(Links) \
427     (RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links))
428 
429 #define RtlLeftChild(Links) \
430     ((PRTL_SPLAY_LINKS)(Links))->LeftChild
431 
432 #define RtlParent(Links) \
433     ((PRTL_SPLAY_LINKS)(Links))->Parent
434 
435 // FIXME: use inline function
436 
437 #define RtlInitializeSplayLinks(Links)                  \
438     {                                                   \
439         PRTL_SPLAY_LINKS _SplayLinks;                   \
440         _SplayLinks = (PRTL_SPLAY_LINKS)(Links);        \
441         _SplayLinks->Parent = _SplayLinks;              \
442         _SplayLinks->LeftChild = NULL;                  \
443         _SplayLinks->RightChild = NULL;                 \
444     }
445 
446 #define RtlInsertAsLeftChild(ParentLinks,ChildLinks)    \
447     {                                                   \
448         PRTL_SPLAY_LINKS _SplayParent;                  \
449         PRTL_SPLAY_LINKS _SplayChild;                   \
450         _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
451         _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks);   \
452         _SplayParent->LeftChild = _SplayChild;          \
453         _SplayChild->Parent = _SplayParent;             \
454     }
455 
456 #define RtlInsertAsRightChild(ParentLinks,ChildLinks)   \
457     {                                                   \
458         PRTL_SPLAY_LINKS _SplayParent;                  \
459         PRTL_SPLAY_LINKS _SplayChild;                   \
460         _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
461         _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks);   \
462         _SplayParent->RightChild = _SplayChild;         \
463         _SplayChild->Parent = _SplayParent;             \
464     }
465 
466 //
467 // RTL AVL Tree Functions
468 //
469 NTSYSAPI
470 VOID
471 NTAPI
472 RtlInitializeGenericTableAvl(
473     _Out_ PRTL_AVL_TABLE Table,
474     _In_ PRTL_AVL_COMPARE_ROUTINE CompareRoutine,
475     _In_opt_ PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine,
476     _In_opt_ PRTL_AVL_FREE_ROUTINE FreeRoutine,
477     _In_opt_ PVOID TableContext
478 );
479 
480 NTSYSAPI
481 PVOID
482 NTAPI
483 RtlInsertElementGenericTableAvl(
484     _In_ PRTL_AVL_TABLE Table,
485     _In_reads_bytes_(BufferSize) PVOID Buffer,
486     _In_ CLONG BufferSize,
487     _Out_opt_ PBOOLEAN NewElement
488 );
489 
490 NTSYSAPI
491 PVOID
492 NTAPI
493 RtlInsertElementGenericTableFullAvl(
494     _In_ PRTL_AVL_TABLE Table,
495     _In_reads_bytes_(BufferSize) PVOID Buffer,
496     _In_ CLONG BufferSize,
497     _Out_opt_ PBOOLEAN NewElement,
498     _In_ PVOID NodeOrParent,
499     _In_ TABLE_SEARCH_RESULT SearchResult
500 );
501 
502 NTSYSAPI
503 BOOLEAN
504 NTAPI
505 RtlDeleteElementGenericTableAvl(
506     _In_ PRTL_AVL_TABLE Table,
507     _In_ PVOID Buffer
508 );
509 
510 _Must_inspect_result_
511 NTSYSAPI
512 PVOID
513 NTAPI
514 RtlLookupElementGenericTableAvl(
515     _In_ PRTL_AVL_TABLE Table,
516     _In_ PVOID Buffer
517 );
518 
519 NTSYSAPI
520 PVOID
521 NTAPI
522 RtlLookupElementGenericTableFullAvl(
523     _In_ PRTL_AVL_TABLE Table,
524     _In_ PVOID Buffer,
525     _Out_ PVOID *NodeOrParent,
526     _Out_ TABLE_SEARCH_RESULT *SearchResult
527 );
528 
529 _Must_inspect_result_
530 NTSYSAPI
531 PVOID
532 NTAPI
533 RtlEnumerateGenericTableAvl(
534     _In_ PRTL_AVL_TABLE Table,
535     _In_ BOOLEAN Restart
536 );
537 
538 _Must_inspect_result_
539 NTSYSAPI
540 PVOID
541 NTAPI
542 RtlEnumerateGenericTableWithoutSplayingAvl(
543     _In_ PRTL_AVL_TABLE Table,
544     _Inout_ PVOID *RestartKey
545 );
546 
547 _Must_inspect_result_
548 NTSYSAPI
549 PVOID
550 NTAPI
551 RtlLookupFirstMatchingElementGenericTableAvl(
552     _In_ PRTL_AVL_TABLE Table,
553     _In_ PVOID Buffer,
554     _Out_ PVOID *RestartKey
555 );
556 
557 _Must_inspect_result_
558 NTSYSAPI
559 PVOID
560 NTAPI
561 RtlEnumerateGenericTableLikeADirectory(
562     _In_ PRTL_AVL_TABLE Table,
563     _In_opt_ PRTL_AVL_MATCH_FUNCTION MatchFunction,
564     _In_opt_ PVOID MatchData,
565     _In_ ULONG NextFlag,
566     _Inout_ PVOID *RestartKey,
567     _Inout_ PULONG DeleteCount,
568     _In_ PVOID Buffer
569 );
570 
571 _Must_inspect_result_
572 NTSYSAPI
573 PVOID
574 NTAPI
575 RtlGetElementGenericTableAvl(
576     _In_ PRTL_AVL_TABLE Table,
577     _In_ ULONG I
578 );
579 
580 NTSYSAPI
581 ULONG
582 NTAPI
583 RtlNumberGenericTableElementsAvl(
584     _In_ PRTL_AVL_TABLE Table
585 );
586 
587 _Must_inspect_result_
588 NTSYSAPI
589 BOOLEAN
590 NTAPI
591 RtlIsGenericTableEmptyAvl(
592     _In_ PRTL_AVL_TABLE Table
593 );
594 
595 #ifdef RTL_USE_AVL_TABLES
596 
597 #define RtlInitializeGenericTable               RtlInitializeGenericTableAvl
598 #define RtlInsertElementGenericTable            RtlInsertElementGenericTableAvl
599 #define RtlInsertElementGenericTableFull        RtlInsertElementGenericTableFullAvl
600 #define RtlDeleteElementGenericTable            RtlDeleteElementGenericTableAvl
601 #define RtlLookupElementGenericTable            RtlLookupElementGenericTableAvl
602 #define RtlLookupElementGenericTableFull        RtlLookupElementGenericTableFullAvl
603 #define RtlEnumerateGenericTable                RtlEnumerateGenericTableAvl
604 #define RtlEnumerateGenericTableWithoutSplaying RtlEnumerateGenericTableWithoutSplayingAvl
605 #define RtlGetElementGenericTable               RtlGetElementGenericTableAvl
606 #define RtlNumberGenericTableElements           RtlNumberGenericTableElementsAvl
607 #define RtlIsGenericTableEmpty                  RtlIsGenericTableEmptyAvl
608 
609 #endif /* RTL_USE_AVL_TABLES */
610 
611 //
612 // Exception and Error Functions
613 //
614 NTSYSAPI
615 PVOID
616 NTAPI
617 RtlAddVectoredExceptionHandler(
618     _In_ ULONG FirstHandler,
619     _In_ PVECTORED_EXCEPTION_HANDLER VectoredHandler
620 );
621 
622 NTSYSAPI
623 ULONG
624 NTAPI
625 RtlRemoveVectoredExceptionHandler(
626     _In_ PVOID VectoredHandlerHandle
627 );
628 
629 NTSYSAPI
630 PVOID
631 NTAPI
632 RtlAddVectoredContinueHandler(
633     _In_ ULONG FirstHandler,
634     _In_ PVECTORED_EXCEPTION_HANDLER VectoredHandler
635 );
636 
637 NTSYSAPI
638 ULONG
639 NTAPI
640 RtlRemoveVectoredContinueHandler(
641     _In_ PVOID VectoredHandlerHandle
642 );
643 
644 NTSYSAPI
645 VOID
646 NTAPI
647 RtlSetUnhandledExceptionFilter(
648     _In_ PRTLP_UNHANDLED_EXCEPTION_FILTER TopLevelExceptionFilter
649 );
650 
651 NTSYSAPI
652 LONG
653 NTAPI
654 RtlUnhandledExceptionFilter(
655     _In_ struct _EXCEPTION_POINTERS* ExceptionInfo
656 );
657 
658 __analysis_noreturn
659 NTSYSAPI
660 VOID
661 NTAPI
662 RtlAssert(
663     _In_ PVOID FailedAssertion,
664     _In_ PVOID FileName,
665     _In_ ULONG LineNumber,
666     _In_opt_z_ PCHAR Message
667 );
668 
669 NTSYSAPI
670 PVOID
671 NTAPI
672 RtlEncodePointer(
673     _In_ PVOID Pointer
674 );
675 
676 NTSYSAPI
677 PVOID
678 NTAPI
679 RtlDecodePointer(
680     _In_ PVOID Pointer
681 );
682 
683 NTSYSAPI
684 PVOID
685 NTAPI
686 RtlEncodeSystemPointer(
687     _In_ PVOID Pointer
688 );
689 
690 NTSYSAPI
691 PVOID
692 NTAPI
693 RtlDecodeSystemPointer(
694     _In_ PVOID Pointer
695 );
696 
697 NTSYSAPI
698 NTSTATUS
699 NTAPI
700 RtlGetLastNtStatus(
701     VOID
702 );
703 
704 NTSYSAPI
705 ULONG
706 NTAPI
707 RtlGetLastWin32Error(
708     VOID
709 );
710 
711 NTSYSAPI
712 VOID
713 NTAPI
714 RtlSetLastWin32Error(
715     _In_ ULONG LastError
716 );
717 
718 NTSYSAPI
719 VOID
720 NTAPI
721 RtlSetLastWin32ErrorAndNtStatusFromNtStatus(
722     _In_ NTSTATUS Status
723 );
724 
725 NTSYSAPI
726 NTSTATUS
727 NTAPI
728 RtlSetThreadErrorMode(
729     _In_ ULONG NewMode,
730     _Out_opt_ PULONG OldMode
731 );
732 
733 NTSYSAPI
734 ULONG
735 NTAPI
736 RtlGetThreadErrorMode(
737     VOID
738 );
739 
740 #endif /* NTOS_MODE_USER */
741 
742 NTSYSAPI
743 VOID
744 NTAPI
745 RtlCaptureContext(
746     _Out_ PCONTEXT ContextRecord
747 );
748 
749 NTSYSAPI
750 BOOLEAN
751 NTAPI
752 RtlDispatchException(
753     _In_ PEXCEPTION_RECORD ExceptionRecord,
754     _In_ PCONTEXT Context
755 );
756 
757 _IRQL_requires_max_(APC_LEVEL)
758 _When_(Status < 0, _Out_range_(>, 0))
759 _When_(Status >= 0, _Out_range_(==, 0))
760 NTSYSAPI
761 ULONG
762 NTAPI
763 RtlNtStatusToDosError(
764     _In_ NTSTATUS Status
765 );
766 
767 _When_(Status < 0, _Out_range_(>, 0))
768 _When_(Status >= 0, _Out_range_(==, 0))
769 NTSYSAPI
770 ULONG
771 NTAPI
772 RtlNtStatusToDosErrorNoTeb(
773     _In_ NTSTATUS Status
774 );
775 
776 NTSYSAPI
777 NTSTATUS
778 NTAPI
779 RtlMapSecurityErrorToNtStatus(
780     _In_ ULONG SecurityError
781 );
782 
783 NTSYSAPI
784 VOID
785 NTAPI
786 RtlRaiseException(
787     _In_ PEXCEPTION_RECORD ExceptionRecord
788 );
789 
790 DECLSPEC_NORETURN
791 NTSYSAPI
792 VOID
793 NTAPI
794 RtlRaiseStatus(
795     _In_ NTSTATUS Status
796 );
797 
798 NTSYSAPI
799 VOID
800 NTAPI
801 RtlUnwind(
802     _In_opt_ PVOID TargetFrame,
803     _In_opt_ PVOID TargetIp,
804     _In_opt_ PEXCEPTION_RECORD ExceptionRecord,
805     _In_ PVOID ReturnValue
806 );
807 
808 #define RTL_STACK_WALKING_MODE_FRAMES_TO_SKIP_SHIFT 8
809 
810 #ifdef _M_AMD64
811 
812 NTSYSAPI
813 PRUNTIME_FUNCTION
814 NTAPI
815 RtlLookupFunctionEntry(
816     _In_ DWORD64 ControlPc,
817     _Out_ PDWORD64 ImageBase,
818     _Inout_opt_ PUNWIND_HISTORY_TABLE HistoryTable
819 );
820 
821 NTSYSAPI
822 PEXCEPTION_ROUTINE
823 NTAPI
824 RtlVirtualUnwind(
825     _In_ ULONG HandlerType,
826     _In_ ULONG64 ImageBase,
827     _In_ ULONG64 ControlPc,
828     _In_ PRUNTIME_FUNCTION FunctionEntry,
829     _Inout_ PCONTEXT Context,
830     _Outptr_ PVOID* HandlerData,
831     _Out_ PULONG64 EstablisherFrame,
832     _Inout_opt_ PKNONVOLATILE_CONTEXT_POINTERS ContextPointers
833 );
834 
835 #endif // _M_AMD64
836 
837 //
838 // Tracing Functions
839 //
840 NTSYSAPI
841 ULONG
842 NTAPI
843 RtlWalkFrameChain(
844     _Out_writes_(Count - (Flags >> RTL_STACK_WALKING_MODE_FRAMES_TO_SKIP_SHIFT)) PVOID *Callers,
845     _In_ ULONG Count,
846     _In_ ULONG Flags
847 );
848 
849 NTSYSAPI
850 USHORT
851 NTAPI
852 RtlLogStackBackTrace(
853     VOID
854 );
855 
856 #ifdef NTOS_MODE_USER
857 //
858 // Heap Functions
859 //
860 _Must_inspect_result_
861 _Ret_maybenull_
862 _Post_writable_byte_size_(Size)
863 NTSYSAPI
864 PVOID
865 NTAPI
866 RtlAllocateHeap(
867     _In_ PVOID HeapHandle,
868     _In_opt_ ULONG Flags,
869     _In_ SIZE_T Size
870 );
871 
872 _Must_inspect_result_
873 NTSYSAPI
874 PVOID
875 NTAPI
876 RtlCreateHeap(
877     _In_ ULONG Flags,
878     _In_opt_ PVOID BaseAddress,
879     _In_opt_ SIZE_T SizeToReserve,
880     _In_opt_ SIZE_T SizeToCommit,
881     _In_opt_ PVOID Lock,
882     _In_opt_ PRTL_HEAP_PARAMETERS Parameters
883 );
884 
885 NTSYSAPI
886 ULONG
887 NTAPI
888 RtlCreateTagHeap(
889     _In_ HANDLE HeapHandle,
890     _In_ ULONG Flags,
891     _In_opt_ PWSTR TagName,
892     _In_ PWSTR TagSubName
893 );
894 
895 ULONG
896 NTAPI
897 RtlCompactHeap(
898     _In_ HANDLE Heap,
899     _In_ ULONG Flags
900 );
901 
902 _Must_inspect_result_
903 NTSYSAPI
904 PVOID
905 NTAPI
906 RtlDebugCreateHeap(
907     _In_ ULONG Flags,
908     _In_opt_ PVOID BaseAddress,
909     _In_opt_ SIZE_T SizeToReserve,
910     _In_opt_ SIZE_T SizeToCommit,
911     _In_opt_ PVOID Lock,
912     _In_opt_ PRTL_HEAP_PARAMETERS Parameters
913 );
914 
915 NTSYSAPI
916 HANDLE
917 NTAPI
918 RtlDestroyHeap(
919     _In_ _Post_invalid_ HANDLE Heap
920 );
921 
922 NTSYSAPI
923 ULONG
924 NTAPI
925 RtlExtendHeap(
926     _In_ HANDLE Heap,
927     _In_ ULONG Flags,
928     _In_ PVOID P,
929     _In_ SIZE_T Size
930 );
931 
932 _Success_(return != 0)
933 NTSYSAPI
934 BOOLEAN
935 NTAPI
936 RtlFreeHeap(
937     _In_ HANDLE HeapHandle,
938     _In_opt_ ULONG Flags,
939     _In_ _Post_invalid_ PVOID P
940 );
941 
942 ULONG
943 NTAPI
944 RtlGetProcessHeaps(
945     _In_ ULONG HeapCount,
946     _Out_cap_(HeapCount) HANDLE *HeapArray
947 );
948 
949 _Success_(return != 0)
950 BOOLEAN
951 NTAPI
952 RtlGetUserInfoHeap(
953     _In_ PVOID HeapHandle,
954     _In_ ULONG Flags,
955     _In_ PVOID BaseAddress,
956     _Inout_opt_ PVOID *UserValue,
957     _Out_opt_ PULONG UserFlags
958 );
959 
960 NTSYSAPI
961 PVOID
962 NTAPI
963 RtlProtectHeap(
964     _In_ PVOID HeapHandle,
965     _In_ BOOLEAN Protect
966 );
967 
968 NTSYSAPI
969 NTSTATUS
970 NTAPI
971 RtlQueryHeapInformation(
972     _In_ PVOID HeapHandle,
973     _In_ HEAP_INFORMATION_CLASS HeapInformationClass,
974     _Out_ PVOID HeapInformation,
975     _In_ SIZE_T HeapInformationLength,
976     _When_(HeapInformationClass==HeapCompatibilityInformation, _On_failure_(_Out_opt_))
977         _Out_opt_ PSIZE_T ReturnLength
978 );
979 
980 _Ret_opt_z_
981 NTSYSAPI
982 PWSTR
983 NTAPI
984 RtlQueryTagHeap(
985     _In_ PVOID HeapHandle,
986     _In_ ULONG Flags,
987     _In_ USHORT TagIndex,
988     _In_ BOOLEAN ResetCounters,
989     _Out_ PRTL_HEAP_TAG_INFO HeapTagInfo
990 );
991 
992 _Must_inspect_result_
993 _Ret_maybenull_
994 _Post_writable_byte_size_(Size)
995 NTSYSAPI
996 PVOID
997 NTAPI
998 RtlReAllocateHeap(
999     _In_ HANDLE Heap,
1000     _In_opt_ ULONG Flags,
1001     _In_ _Post_invalid_ PVOID Ptr,
1002     _In_ SIZE_T Size
1003 );
1004 
1005 NTSYSAPI
1006 NTSTATUS
1007 NTAPI
1008 RtlSetHeapInformation(
1009     _In_ PVOID HeapHandle,
1010     _In_ HEAP_INFORMATION_CLASS HeapInformationClass,
1011     _When_(HeapInformationClass==HeapCompatibilityInformation,_In_) PVOID HeapInformation,
1012     _In_ SIZE_T HeapInformationLength
1013 );
1014 
1015 NTSYSAPI
1016 BOOLEAN
1017 NTAPI
1018 RtlLockHeap(
1019     _In_ HANDLE Heap
1020 );
1021 
1022 NTSYSAPI
1023 ULONG
1024 NTAPI
1025 RtlMultipleAllocateHeap(
1026     _In_ HANDLE HeapHandle,
1027     _In_ ULONG Flags,
1028     _In_ SIZE_T Size,
1029     _In_ ULONG Count,
1030     _Out_cap_(Count) _Deref_post_bytecap_(Size) PVOID * Array
1031 );
1032 
1033 NTSYSAPI
1034 ULONG
1035 NTAPI
1036 RtlMultipleFreeHeap(
1037     _In_ HANDLE HeapHandle,
1038     _In_ ULONG Flags,
1039     _In_ ULONG Count,
1040     _In_count_(Count) /* _Deref_ _Post_invalid_ */ PVOID * Array
1041 );
1042 
1043 NTSYSAPI
1044 NTSTATUS
1045 NTAPI
1046 RtlUsageHeap(
1047     _In_ HANDLE Heap,
1048     _In_ ULONG Flags,
1049     _Out_ PRTL_HEAP_USAGE Usage
1050 );
1051 
1052 NTSYSAPI
1053 BOOLEAN
1054 NTAPI
1055 RtlUnlockHeap(
1056     _In_ HANDLE Heap
1057 );
1058 
1059 BOOLEAN
1060 NTAPI
1061 RtlSetUserValueHeap(
1062     _In_ PVOID HeapHandle,
1063     _In_ ULONG Flags,
1064     _In_ PVOID BaseAddress,
1065     _In_ PVOID UserValue
1066 );
1067 
1068 BOOLEAN
1069 NTAPI
1070 RtlSetUserFlagsHeap(
1071     _In_ PVOID HeapHandle,
1072     _In_ ULONG Flags,
1073     _In_ PVOID BaseAddress,
1074     _In_ ULONG UserFlagsReset,
1075     _In_ ULONG UserFlagsSet
1076 );
1077 
1078 NTSYSAPI
1079 BOOLEAN
1080 NTAPI
1081 RtlValidateHeap(
1082     _In_ HANDLE Heap,
1083     _In_ ULONG Flags,
1084     _In_opt_ PVOID P
1085 );
1086 
1087 NTSYSAPI
1088 NTSTATUS
1089 NTAPI
1090 RtlWalkHeap(
1091     _In_ HANDLE HeapHandle,
1092     _In_ PVOID HeapEntry
1093 );
1094 
1095 #define RtlGetProcessHeap() (NtCurrentPeb()->ProcessHeap)
1096 
1097 #endif // NTOS_MODE_USER
1098 
1099 #define NtCurrentPeb() (NtCurrentTeb()->ProcessEnvironmentBlock)
1100 
1101 NTSYSAPI
1102 SIZE_T
1103 NTAPI
1104 RtlSizeHeap(
1105     _In_ PVOID HeapHandle,
1106     _In_ ULONG Flags,
1107     _In_ PVOID MemoryPointer
1108 );
1109 
1110 
1111 //
1112 // Security Functions
1113 //
1114 _IRQL_requires_max_(APC_LEVEL)
1115 NTSYSAPI
1116 NTSTATUS
1117 NTAPI
1118 RtlAbsoluteToSelfRelativeSD(
1119     _In_ PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
1120     _Out_writes_bytes_to_opt_(*BufferLength, *BufferLength) PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
1121     _Inout_ PULONG BufferLength
1122 );
1123 
1124 _IRQL_requires_max_(APC_LEVEL)
1125 NTSYSAPI
1126 NTSTATUS
1127 NTAPI
1128 RtlAddAccessAllowedAce(
1129     _Inout_ PACL Acl,
1130     _In_ ULONG Revision,
1131     _In_ ACCESS_MASK AccessMask,
1132     _In_ PSID Sid
1133 );
1134 
1135 _IRQL_requires_max_(APC_LEVEL)
1136 NTSYSAPI
1137 NTSTATUS
1138 NTAPI
1139 RtlAddAccessAllowedAceEx(
1140     _Inout_ PACL pAcl,
1141     _In_ ULONG dwAceRevision,
1142     _In_ ULONG AceFlags,
1143     _In_ ACCESS_MASK AccessMask,
1144     _In_ PSID pSid
1145 );
1146 
1147 NTSYSAPI
1148 NTSTATUS
1149 NTAPI
1150 RtlAddAccessAllowedObjectAce(
1151     _Inout_ PACL pAcl,
1152     _In_ ULONG dwAceRevision,
1153     _In_ ULONG AceFlags,
1154     _In_ ACCESS_MASK AccessMask,
1155     _In_opt_ GUID *ObjectTypeGuid,
1156     _In_opt_ GUID *InheritedObjectTypeGuid,
1157     _In_ PSID pSid
1158 );
1159 
1160 NTSYSAPI
1161 NTSTATUS
1162 NTAPI
1163 RtlAddAccessDeniedAce(
1164     _Inout_ PACL Acl,
1165     _In_ ULONG Revision,
1166     _In_ ACCESS_MASK AccessMask,
1167     _In_ PSID Sid
1168 );
1169 
1170 NTSYSAPI
1171 NTSTATUS
1172 NTAPI
1173 RtlAddAccessDeniedAceEx(
1174     _Inout_ PACL Acl,
1175     _In_ ULONG Revision,
1176     _In_ ULONG Flags,
1177     _In_ ACCESS_MASK AccessMask,
1178     _In_ PSID Sid
1179 );
1180 
1181 NTSYSAPI
1182 NTSTATUS
1183 NTAPI
1184 RtlAddAccessDeniedObjectAce(
1185     _Inout_ PACL pAcl,
1186     _In_ ULONG dwAceRevision,
1187     _In_ ULONG AceFlags,
1188     _In_ ACCESS_MASK AccessMask,
1189     _In_opt_ GUID *ObjectTypeGuid,
1190     _In_opt_ GUID *InheritedObjectTypeGuid,
1191     _In_ PSID pSid
1192 );
1193 
1194 NTSYSAPI
1195 NTSTATUS
1196 NTAPI
1197 RtlAddAce(
1198     _Inout_ PACL Acl,
1199     _In_ ULONG AceRevision,
1200     _In_ ULONG StartingAceIndex,
1201     _In_reads_bytes_(AceListLength) PVOID AceList,
1202     _In_ ULONG AceListLength
1203 );
1204 
1205 NTSYSAPI
1206 NTSTATUS
1207 NTAPI
1208 RtlAddAuditAccessAce(
1209     _Inout_ PACL Acl,
1210     _In_ ULONG Revision,
1211     _In_ ACCESS_MASK AccessMask,
1212     _In_ PSID Sid,
1213     _In_ BOOLEAN Success,
1214     _In_ BOOLEAN Failure
1215 );
1216 
1217 NTSYSAPI
1218 NTSTATUS
1219 NTAPI
1220 RtlAcquirePrivilege(
1221     _In_ PULONG Privilege,
1222     _In_ ULONG NumPriv,
1223     _In_ ULONG Flags,
1224     _Out_ PVOID *ReturnedState
1225 );
1226 
1227 NTSYSAPI
1228 NTSTATUS
1229 NTAPI
1230 RtlAddAuditAccessAceEx(
1231     _Inout_ PACL Acl,
1232     _In_ ULONG Revision,
1233     _In_ ULONG Flags,
1234     _In_ ACCESS_MASK AccessMask,
1235     _In_ PSID Sid,
1236     _In_ BOOLEAN Success,
1237     _In_ BOOLEAN Failure
1238 );
1239 
1240 NTSYSAPI
1241 NTSTATUS
1242 NTAPI
1243 RtlAddAuditAccessObjectAce(
1244     _Inout_ PACL Acl,
1245     _In_ ULONG Revision,
1246     _In_ ULONG Flags,
1247     _In_ ACCESS_MASK AccessMask,
1248     _In_opt_ GUID *ObjectTypeGuid,
1249     _In_opt_ GUID *InheritedObjectTypeGuid,
1250     _In_ PSID Sid,
1251     _In_ BOOLEAN Success,
1252     _In_ BOOLEAN Failure
1253 );
1254 
1255 NTSYSAPI
1256 NTSTATUS
1257 NTAPI
1258 RtlAddMandatoryAce(
1259     _Inout_ PACL Acl,
1260     _In_ ULONG Revision,
1261     _In_ ULONG Flags,
1262     _In_ ULONG MandatoryFlags,
1263     _In_ UCHAR AceType,
1264     _In_ PSID LabelSid);
1265 
1266 NTSYSAPI
1267 NTSTATUS
1268 NTAPI
1269 RtlAdjustPrivilege(
1270     _In_ ULONG Privilege,
1271     _In_ BOOLEAN NewValue,
1272     _In_ BOOLEAN ForThread,
1273     _Out_ PBOOLEAN OldValue
1274 );
1275 
1276 _Must_inspect_result_
1277 NTSYSAPI
1278 NTSTATUS
1279 NTAPI
1280 RtlAllocateAndInitializeSid(
1281     _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
1282     _In_ UCHAR SubAuthorityCount,
1283     _In_ ULONG SubAuthority0,
1284     _In_ ULONG SubAuthority1,
1285     _In_ ULONG SubAuthority2,
1286     _In_ ULONG SubAuthority3,
1287     _In_ ULONG SubAuthority4,
1288     _In_ ULONG SubAuthority5,
1289     _In_ ULONG SubAuthority6,
1290     _In_ ULONG SubAuthority7,
1291     _Outptr_ PSID *Sid
1292 );
1293 
1294 NTSYSAPI
1295 BOOLEAN
1296 NTAPI
1297 RtlAreAllAccessesGranted(
1298     ACCESS_MASK GrantedAccess,
1299     ACCESS_MASK DesiredAccess
1300 );
1301 
1302 NTSYSAPI
1303 BOOLEAN
1304 NTAPI
1305 RtlAreAnyAccessesGranted(
1306     ACCESS_MASK GrantedAccess,
1307     ACCESS_MASK DesiredAccess
1308 );
1309 
1310 _IRQL_requires_max_(APC_LEVEL)
1311 NTSYSAPI
1312 VOID
1313 NTAPI
1314 RtlCopyLuid (
1315     _Out_ PLUID DestinationLuid,
1316     _In_ PLUID SourceLuid
1317     );
1318 
1319 NTSYSAPI
1320 VOID
1321 NTAPI
1322 RtlCopyLuidAndAttributesArray(
1323     ULONG Count,
1324     PLUID_AND_ATTRIBUTES Src,
1325     PLUID_AND_ATTRIBUTES Dest
1326 );
1327 
1328 NTSYSAPI
1329 NTSTATUS
1330 NTAPI
1331 RtlCopySidAndAttributesArray(
1332     _In_ ULONG Count,
1333     _In_ PSID_AND_ATTRIBUTES Src,
1334     _In_ ULONG SidAreaSize,
1335     _In_ PSID_AND_ATTRIBUTES Dest,
1336     _In_ PSID SidArea,
1337     _Out_ PSID* RemainingSidArea,
1338     _Out_ PULONG RemainingSidAreaSize
1339 );
1340 
1341 _IRQL_requires_max_(APC_LEVEL)
1342 NTSYSAPI
1343 NTSTATUS
1344 NTAPI
1345 RtlConvertSidToUnicodeString(
1346     _Inout_ PUNICODE_STRING UnicodeString,
1347     _In_ PSID Sid,
1348     _In_ BOOLEAN AllocateDestinationString
1349 );
1350 
1351 _IRQL_requires_max_(APC_LEVEL)
1352 NTSYSAPI
1353 NTSTATUS
1354 NTAPI
1355 RtlCopySid(
1356     _In_ ULONG DestinationSidLength,
1357     _Out_writes_bytes_(DestinationSidLength) PSID DestinationSid,
1358     _In_ PSID SourceSid
1359 );
1360 
1361 NTSYSAPI
1362 NTSTATUS
1363 NTAPI
1364 RtlCreateAcl(
1365     PACL Acl,
1366     ULONG AclSize,
1367     ULONG AclRevision
1368 );
1369 
1370 NTSYSAPI
1371 NTSTATUS
1372 NTAPI
1373 RtlCreateSecurityDescriptor(
1374     _Out_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1375     _In_ ULONG Revision
1376 );
1377 
1378 NTSYSAPI
1379 NTSTATUS
1380 NTAPI
1381 RtlCreateSecurityDescriptorRelative(
1382     _Out_ PISECURITY_DESCRIPTOR_RELATIVE SecurityDescriptor,
1383     _In_ ULONG Revision
1384 );
1385 
1386 NTSYSAPI
1387 NTSTATUS
1388 NTAPI
1389 RtlCopySecurityDescriptor(
1390     _In_ PSECURITY_DESCRIPTOR pSourceSecurityDescriptor,
1391     _Out_ PSECURITY_DESCRIPTOR *pDestinationSecurityDescriptor
1392 );
1393 
1394 NTSYSAPI
1395 NTSTATUS
1396 NTAPI
1397 RtlDeleteAce(
1398     PACL Acl,
1399     ULONG AceIndex
1400 );
1401 
1402 NTSYSAPI
1403 BOOLEAN
1404 NTAPI
1405 RtlEqualPrefixSid(
1406     PSID Sid1,
1407     PSID Sid2
1408 );
1409 
1410 NTSYSAPI
1411 BOOLEAN
1412 NTAPI
1413 RtlEqualSid (
1414     _In_ PSID Sid1,
1415     _In_ PSID Sid2
1416 );
1417 
1418 NTSYSAPI
1419 BOOLEAN
1420 NTAPI
1421 RtlFirstFreeAce(
1422     PACL Acl,
1423     PACE* Ace
1424 );
1425 
1426 NTSYSAPI
1427 PVOID
1428 NTAPI
1429 RtlFreeSid(
1430     _In_ _Post_invalid_ PSID Sid
1431 );
1432 
1433 NTSYSAPI
1434 NTSTATUS
1435 NTAPI
1436 RtlGetAce(
1437     PACL Acl,
1438     ULONG AceIndex,
1439     PVOID *Ace
1440 );
1441 
1442 NTSYSAPI
1443 NTSTATUS
1444 NTAPI
1445 RtlGetControlSecurityDescriptor(
1446     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1447     _Out_ PSECURITY_DESCRIPTOR_CONTROL Control,
1448     _Out_ PULONG Revision
1449 );
1450 
1451 NTSYSAPI
1452 NTSTATUS
1453 NTAPI
1454 RtlGetDaclSecurityDescriptor(
1455     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1456     _Out_ PBOOLEAN DaclPresent,
1457     _Out_ PACL *Dacl,
1458     _Out_ PBOOLEAN DaclDefaulted
1459 );
1460 
1461 NTSYSAPI
1462 NTSTATUS
1463 NTAPI
1464 RtlGetSaclSecurityDescriptor(
1465     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1466     _Out_ PBOOLEAN SaclPresent,
1467     _Out_ PACL* Sacl,
1468     _Out_ PBOOLEAN SaclDefaulted
1469 );
1470 
1471 NTSYSAPI
1472 NTSTATUS
1473 NTAPI
1474 RtlGetGroupSecurityDescriptor(
1475     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1476     _Out_ PSID *Group,
1477     _Out_ PBOOLEAN GroupDefaulted
1478 );
1479 
1480 NTSYSAPI
1481 NTSTATUS
1482 NTAPI
1483 RtlGetOwnerSecurityDescriptor(
1484     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1485     _Out_ PSID *Owner,
1486     _Out_ PBOOLEAN OwnerDefaulted
1487 );
1488 
1489 NTSYSAPI
1490 BOOLEAN
1491 NTAPI
1492 RtlGetSecurityDescriptorRMControl(
1493     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1494     _Out_ PUCHAR RMControl
1495 );
1496 
1497 NTSYSAPI
1498 PSID_IDENTIFIER_AUTHORITY
1499 NTAPI
1500 RtlIdentifierAuthoritySid(PSID Sid);
1501 
1502 NTSYSAPI
1503 NTSTATUS
1504 NTAPI
1505 RtlImpersonateSelf(IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel);
1506 
1507 _IRQL_requires_max_(APC_LEVEL)
1508 NTSYSAPI
1509 NTSTATUS
1510 NTAPI
1511 RtlInitializeSid(
1512     _Out_ PSID Sid,
1513     _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
1514     _In_ UCHAR SubAuthorityCount
1515 );
1516 
1517 NTSYSAPI
1518 ULONG
1519 NTAPI
1520 RtlLengthRequiredSid(IN ULONG SubAuthorityCount);
1521 
1522 _IRQL_requires_max_(APC_LEVEL)
1523 NTSYSAPI
1524 ULONG
1525 NTAPI
1526 RtlLengthSecurityDescriptor(
1527     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor);
1528 
1529 NTSYSAPI
1530 ULONG
1531 NTAPI
1532 RtlLengthSid(IN PSID Sid);
1533 
1534 NTSYSAPI
1535 NTSTATUS
1536 NTAPI
1537 RtlMakeSelfRelativeSD(
1538     _In_ PSECURITY_DESCRIPTOR AbsoluteSD,
1539     _Out_ PSECURITY_DESCRIPTOR SelfRelativeSD,
1540     _Inout_ PULONG BufferLength);
1541 
1542 NTSYSAPI
1543 VOID
1544 NTAPI
1545 RtlMapGenericMask(
1546     PACCESS_MASK AccessMask,
1547     PGENERIC_MAPPING GenericMapping
1548 );
1549 
1550 #ifdef NTOS_MODE_USER
1551 
1552 NTSYSAPI
1553 NTSTATUS
1554 NTAPI
1555 RtlQueryInformationAcl(
1556     PACL Acl,
1557     PVOID Information,
1558     ULONG InformationLength,
1559     ACL_INFORMATION_CLASS InformationClass
1560 );
1561 
1562 #endif
1563 
1564 NTSYSAPI
1565 VOID
1566 NTAPI
1567 RtlReleasePrivilege(
1568     _In_ PVOID ReturnedState
1569 );
1570 
1571 #if (NTDDI_VERSION >= NTDDI_VISTA)
1572 
1573 NTSYSAPI
1574 NTSTATUS
1575 NTAPI
1576 RtlRemovePrivileges(
1577     _In_ HANDLE TokenHandle,
1578     _In_reads_opt_(PrivilegeCount) _When_(PrivilegeCount != 0, _Notnull_)
1579          PULONG PrivilegesToKeep,
1580     _In_ ULONG PrivilegeCount
1581 );
1582 
1583 #endif /* (NTDDI_VERSION >= NTDDI_VISTA) */
1584 
1585 _IRQL_requires_max_(APC_LEVEL)
1586 NTSYSAPI
1587 NTSTATUS
1588 NTAPI
1589 RtlSelfRelativeToAbsoluteSD(
1590     _In_ PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
1591     _Out_writes_bytes_to_opt_(*AbsoluteSecurityDescriptorSize, *AbsoluteSecurityDescriptorSize) PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
1592     _Inout_ PULONG AbsoluteSecurityDescriptorSize,
1593     _Out_writes_bytes_to_opt_(*DaclSize, *DaclSize) PACL Dacl,
1594     _Inout_ PULONG DaclSize,
1595     _Out_writes_bytes_to_opt_(*SaclSize, *SaclSize) PACL Sacl,
1596     _Inout_ PULONG SaclSize,
1597     _Out_writes_bytes_to_opt_(*OwnerSize, *OwnerSize) PSID Owner,
1598     _Inout_ PULONG OwnerSize,
1599     _Out_writes_bytes_to_opt_(*PrimaryGroupSize, *PrimaryGroupSize) PSID PrimaryGroup,
1600     _Inout_ PULONG PrimaryGroupSize
1601 );
1602 
1603 NTSYSAPI
1604 NTSTATUS
1605 NTAPI
1606 RtlSelfRelativeToAbsoluteSD2(
1607     _Inout_ PSECURITY_DESCRIPTOR SelfRelativeSD,
1608     _Out_ PULONG BufferSize
1609 );
1610 
1611 NTSYSAPI
1612 NTSTATUS
1613 NTAPI
1614 RtlSetAttributesSecurityDescriptor(
1615     _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1616     _In_ SECURITY_DESCRIPTOR_CONTROL Control,
1617     _Out_ PULONG Revision
1618 );
1619 
1620 NTSYSAPI
1621 NTSTATUS
1622 NTAPI
1623 RtlSetControlSecurityDescriptor(
1624     _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1625     _In_ SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
1626     _In_ SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
1627 );
1628 
1629 _IRQL_requires_max_(APC_LEVEL)
1630 NTSYSAPI
1631 NTSTATUS
1632 NTAPI
1633 RtlSetDaclSecurityDescriptor(
1634     _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1635     _In_ BOOLEAN DaclPresent,
1636     _In_opt_ PACL Dacl,
1637     _In_opt_ BOOLEAN DaclDefaulted
1638 );
1639 
1640 _IRQL_requires_max_(APC_LEVEL)
1641 NTSYSAPI
1642 NTSTATUS
1643 NTAPI
1644 RtlSetGroupSecurityDescriptor(
1645     _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1646     _In_opt_ PSID Group,
1647     _In_opt_ BOOLEAN GroupDefaulted
1648 );
1649 
1650 #ifdef NTOS_MODE_USER
1651 
1652 NTSYSAPI
1653 NTSTATUS
1654 NTAPI
1655 RtlSetInformationAcl(
1656     PACL Acl,
1657     PVOID Information,
1658     ULONG InformationLength,
1659     ACL_INFORMATION_CLASS InformationClass
1660 );
1661 
1662 #endif
1663 
1664 _IRQL_requires_max_(APC_LEVEL)
1665 NTSYSAPI
1666 NTSTATUS
1667 NTAPI
1668 RtlSetOwnerSecurityDescriptor(
1669     _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1670     _In_opt_ PSID Owner,
1671     _In_opt_ BOOLEAN OwnerDefaulted
1672 );
1673 
1674 NTSYSAPI
1675 NTSTATUS
1676 NTAPI
1677 RtlSetSaclSecurityDescriptor(
1678     _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1679     _In_ BOOLEAN SaclPresent,
1680     _In_ PACL Sacl,
1681     _In_ BOOLEAN SaclDefaulted
1682 );
1683 
1684 NTSYSAPI
1685 VOID
1686 NTAPI
1687 RtlSetSecurityDescriptorRMControl(
1688     _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1689     _In_ PUCHAR RMControl
1690 );
1691 
1692 NTSYSAPI
1693 PUCHAR
1694 NTAPI
1695 RtlSubAuthorityCountSid(
1696     _In_ PSID Sid
1697 );
1698 
1699 NTSYSAPI
1700 PULONG
1701 NTAPI
1702 RtlSubAuthoritySid(
1703     _In_ PSID Sid,
1704     _In_ ULONG SubAuthority
1705 );
1706 
1707 _IRQL_requires_max_(APC_LEVEL)
1708 _Must_inspect_result_
1709 NTSYSAPI
1710 BOOLEAN
1711 NTAPI
1712 RtlValidRelativeSecurityDescriptor(
1713     _In_reads_bytes_(SecurityDescriptorLength) PSECURITY_DESCRIPTOR SecurityDescriptorInput,
1714     _In_ ULONG SecurityDescriptorLength,
1715     _In_ SECURITY_INFORMATION RequiredInformation
1716 );
1717 
1718 NTSYSAPI
1719 BOOLEAN
1720 NTAPI
1721 RtlValidSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
1722 
1723 NTSYSAPI
1724 BOOLEAN
1725 NTAPI
1726 RtlValidSid(IN PSID Sid);
1727 
1728 NTSYSAPI
1729 BOOLEAN
1730 NTAPI
1731 RtlValidAcl(PACL Acl);
1732 
1733 NTSYSAPI
1734 NTSTATUS
1735 NTAPI
1736 RtlDeleteSecurityObject(
1737     _In_ PSECURITY_DESCRIPTOR *ObjectDescriptor
1738 );
1739 
1740 NTSYSAPI
1741 NTSTATUS
1742 NTAPI
1743 RtlNewSecurityObject(
1744     _In_ PSECURITY_DESCRIPTOR ParentDescriptor,
1745     _In_ PSECURITY_DESCRIPTOR CreatorDescriptor,
1746     _Out_ PSECURITY_DESCRIPTOR *NewDescriptor,
1747     _In_ BOOLEAN IsDirectoryObject,
1748     _In_ HANDLE Token,
1749     _In_ PGENERIC_MAPPING GenericMapping
1750 );
1751 
1752 NTSYSAPI
1753 NTSTATUS
1754 NTAPI
1755 RtlQuerySecurityObject(
1756     _In_ PSECURITY_DESCRIPTOR ObjectDescriptor,
1757     _In_ SECURITY_INFORMATION SecurityInformation,
1758     _Out_ PSECURITY_DESCRIPTOR ResultantDescriptor,
1759     _In_ ULONG DescriptorLength,
1760     _Out_ PULONG ReturnLength
1761 );
1762 
1763 NTSYSAPI
1764 NTSTATUS
1765 NTAPI
1766 RtlSetSecurityObject(
1767     _In_ SECURITY_INFORMATION SecurityInformation,
1768     _In_ PSECURITY_DESCRIPTOR ModificationDescriptor,
1769     _Out_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
1770     _In_ PGENERIC_MAPPING GenericMapping,
1771     _In_ HANDLE Token
1772 );
1773 
1774 //
1775 // Single-Character Functions
1776 //
1777 NTSYSAPI
1778 NTSTATUS
1779 NTAPI
1780 RtlLargeIntegerToChar(
1781     _In_ PLARGE_INTEGER Value,
1782     _In_ ULONG Base,
1783     _In_ ULONG Length,
1784     _Out_ PCHAR String
1785 );
1786 
1787 NTSYSAPI
1788 CHAR
1789 NTAPI
1790 RtlUpperChar(CHAR Source);
1791 
1792 NTSYSAPI
1793 WCHAR
1794 NTAPI
1795 RtlUpcaseUnicodeChar(WCHAR Source);
1796 
1797 NTSYSAPI
1798 WCHAR
1799 NTAPI
1800 RtlDowncaseUnicodeChar(IN WCHAR Source);
1801 
1802 NTSYSAPI
1803 NTSTATUS
1804 NTAPI
1805 RtlIntegerToChar(
1806     _In_ ULONG Value,
1807     _In_ ULONG Base,
1808     _In_ ULONG Length,
1809     _Out_ PCHAR String
1810 );
1811 
1812 NTSYSAPI
1813 NTSTATUS
1814 NTAPI
1815 RtlIntegerToUnicode(
1816     _In_ ULONG Value,
1817     _In_opt_ ULONG Base,
1818     _In_opt_ ULONG Length,
1819     _Inout_ LPWSTR String
1820 );
1821 
1822 _IRQL_requires_max_(PASSIVE_LEVEL)
1823 _At_(String->MaximumLength, _Const_)
1824 NTSYSAPI
1825 NTSTATUS
1826 NTAPI
1827 RtlIntegerToUnicodeString(
1828     _In_ ULONG Value,
1829     _In_opt_ ULONG Base,
1830     _Inout_ PUNICODE_STRING String
1831 );
1832 
1833 NTSYSAPI
1834 NTSTATUS
1835 NTAPI
1836 RtlCharToInteger(
1837     PCSZ String,
1838     ULONG Base,
1839     PULONG Value
1840 );
1841 
1842 //
1843 // Byte Swap Functions
1844 //
1845 #ifdef NTOS_MODE_USER
1846 
1847 unsigned short __cdecl _byteswap_ushort(unsigned short);
1848 unsigned long  __cdecl _byteswap_ulong (unsigned long);
1849 unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
1850 #ifdef _MSC_VER
1851 #pragma intrinsic(_byteswap_ushort)
1852 #pragma intrinsic(_byteswap_ulong)
1853 #pragma intrinsic(_byteswap_uint64)
1854 #endif // _MSC_VER
1855 #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
1856 #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
1857 #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
1858 
1859 #endif // NTOS_MODE_USER
1860 
1861 //
1862 // Unicode->Ansi String Functions
1863 //
1864 NTSYSAPI
1865 ULONG
1866 NTAPI
1867 RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString);
1868 
1869 #ifdef NTOS_MODE_USER
1870 
1871 #define RtlUnicodeStringToAnsiSize(STRING) (                  \
1872     NLS_MB_CODE_PAGE_TAG ?                                    \
1873     RtlxUnicodeStringToAnsiSize(STRING) :                     \
1874     ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
1875 )
1876 
1877 #endif
1878 
1879 NTSYSAPI
1880 NTSTATUS
1881 NTAPI
1882 RtlUnicodeStringToAnsiString(
1883     PANSI_STRING DestinationString,
1884     PCUNICODE_STRING SourceString,
1885     BOOLEAN AllocateDestinationString
1886 );
1887 
1888 //
1889 // Unicode->OEM String Functions
1890 //
1891 NTSYSAPI
1892 NTSTATUS
1893 NTAPI
1894 RtlUpcaseUnicodeStringToOemString(
1895     POEM_STRING DestinationString,
1896     PCUNICODE_STRING SourceString,
1897     BOOLEAN AllocateDestinationString
1898 );
1899 
1900 _IRQL_requires_max_(PASSIVE_LEVEL)
1901 _Must_inspect_result_
1902 //_At_(DestinationString->Buffer, _Post_bytecount_(DestinationString->Length))
1903 NTSYSAPI
1904 NTSTATUS
1905 NTAPI
1906 RtlUpcaseUnicodeStringToCountedOemString(
1907     _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1908     _When_(!AllocateDestinationString, _Inout_)
1909         POEM_STRING DestinationString,
1910     _In_ PCUNICODE_STRING SourceString,
1911     _In_ BOOLEAN AllocateDestinationString
1912 );
1913 
1914 NTSYSAPI
1915 NTSTATUS
1916 NTAPI
1917 RtlUnicodeStringToOemString(
1918     POEM_STRING DestinationString,
1919     PCUNICODE_STRING SourceString,
1920     BOOLEAN AllocateDestinationString
1921 );
1922 
1923 _IRQL_requires_max_(PASSIVE_LEVEL)
1924 _Must_inspect_result_
1925 NTSYSAPI
1926 NTSTATUS
1927 NTAPI
1928 RtlUnicodeStringToCountedOemString(
1929     _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1930     _When_(!AllocateDestinationString, _Inout_)
1931         POEM_STRING DestinationString,
1932     _In_ PCUNICODE_STRING SourceString,
1933     _In_ BOOLEAN AllocateDestinationString
1934 );
1935 
1936 NTSYSAPI
1937 NTSTATUS
1938 NTAPI
1939 RtlUpcaseUnicodeToOemN(
1940     PCHAR OemString,
1941     ULONG OemSize,
1942     PULONG ResultSize,
1943     PCWCH UnicodeString,
1944     ULONG UnicodeSize
1945 );
1946 
1947 NTSYSAPI
1948 ULONG
1949 NTAPI
1950 RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString);
1951 
1952 #ifdef NTOS_MODE_USER
1953 
1954 #define RtlUnicodeStringToOemSize(STRING) (                             \
1955     NLS_MB_OEM_CODE_PAGE_TAG ?                                          \
1956     RtlxUnicodeStringToOemSize(STRING) :                                \
1957     ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR)           \
1958 )
1959 
1960 #define RtlUnicodeStringToCountedOemSize(STRING) (                      \
1961     (ULONG)(RtlUnicodeStringToOemSize(STRING) - sizeof(ANSI_NULL))      \
1962 )
1963 
1964 #endif
1965 
1966 NTSYSAPI
1967 NTSTATUS
1968 NTAPI
1969 RtlUnicodeToOemN(
1970     PCHAR OemString,
1971     ULONG OemSize,
1972     PULONG ResultSize,
1973     PCWCH UnicodeString,
1974     ULONG UnicodeSize
1975 );
1976 
1977 //
1978 // Unicode->MultiByte String Functions
1979 //
1980 NTSYSAPI
1981 NTSTATUS
1982 NTAPI
1983 RtlUnicodeToMultiByteN(
1984     PCHAR MbString,
1985     ULONG MbSize,
1986     PULONG ResultSize,
1987     PCWCH UnicodeString,
1988     ULONG UnicodeSize
1989 );
1990 
1991 NTSYSAPI
1992 NTSTATUS
1993 NTAPI
1994 RtlUpcaseUnicodeToMultiByteN(
1995     PCHAR MbString,
1996     ULONG MbSize,
1997     PULONG ResultSize,
1998     PCWCH UnicodeString,
1999     ULONG UnicodeSize
2000 );
2001 
2002 NTSYSAPI
2003 NTSTATUS
2004 NTAPI
2005 RtlUnicodeToMultiByteSize(
2006     PULONG MbSize,
2007     PCWCH UnicodeString,
2008     ULONG UnicodeSize
2009 );
2010 
2011 NTSYSAPI
2012 ULONG
2013 NTAPI
2014 RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString);
2015 
2016 //
2017 // OEM to Unicode Functions
2018 //
2019 NTSYSAPI
2020 NTSTATUS
2021 NTAPI
2022 RtlOemStringToUnicodeString(
2023     PUNICODE_STRING DestinationString,
2024     PCOEM_STRING SourceString,
2025     BOOLEAN AllocateDestinationString
2026 );
2027 
2028 _IRQL_requires_max_(PASSIVE_LEVEL)
2029 NTSYSAPI
2030 NTSTATUS
2031 NTAPI
2032 RtlOemToUnicodeN(
2033     _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWCH UnicodeString,
2034     _In_ ULONG MaxBytesInUnicodeString,
2035     _Out_opt_ PULONG BytesInUnicodeString,
2036     _In_reads_bytes_(BytesInOemString) PCCH OemString,
2037     _In_ ULONG BytesInOemString
2038 );
2039 
2040 #ifdef NTOS_MODE_USER
2041 
2042 #define RtlOemStringToUnicodeSize(STRING) (                             \
2043     NLS_MB_OEM_CODE_PAGE_TAG ?                                          \
2044     RtlxOemStringToUnicodeSize(STRING) :                                \
2045     ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR)              \
2046 )
2047 
2048 #define RtlOemStringToCountedUnicodeSize(STRING) (                      \
2049     (ULONG)(RtlOemStringToUnicodeSize(STRING) - sizeof(UNICODE_NULL))   \
2050 )
2051 
2052 #endif
2053 
2054 //
2055 // Ansi->Unicode String Functions
2056 //
2057 _IRQL_requires_max_(APC_LEVEL)
2058 NTSYSAPI
2059 WCHAR
2060 NTAPI
2061 RtlAnsiCharToUnicodeChar(
2062   _Inout_ PUCHAR *SourceCharacter);
2063 
2064 NTSYSAPI
2065 NTSTATUS
2066 NTAPI
2067 RtlAnsiStringToUnicodeString(
2068     PUNICODE_STRING DestinationString,
2069     PCANSI_STRING SourceString,
2070     BOOLEAN AllocateDestinationString
2071 );
2072 
2073 NTSYSAPI
2074 ULONG
2075 NTAPI
2076 RtlxAnsiStringToUnicodeSize(
2077     PCANSI_STRING AnsiString
2078 );
2079 
2080 #ifdef NTOS_MODE_USER
2081 
2082 #define RtlAnsiStringToUnicodeSize(STRING) (                        \
2083     NLS_MB_CODE_PAGE_TAG ?                                          \
2084     RtlxAnsiStringToUnicodeSize(STRING) :                           \
2085     ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR)          \
2086 )
2087 
2088 #endif
2089 
2090 NTSYSAPI
2091 BOOLEAN
2092 NTAPI
2093 RtlCreateUnicodeStringFromAsciiz(
2094     _Out_ PUNICODE_STRING Destination,
2095     _In_ PCSZ Source
2096 );
2097 
2098 //
2099 // Unicode String Functions
2100 //
2101 NTSYSAPI
2102 NTSTATUS
2103 NTAPI
2104 RtlAppendUnicodeToString(
2105     PUNICODE_STRING Destination,
2106     PCWSTR Source
2107 );
2108 
2109 NTSYSAPI
2110 NTSTATUS
2111 NTAPI
2112 RtlAppendUnicodeStringToString(
2113     PUNICODE_STRING Destination,
2114     PCUNICODE_STRING Source
2115 );
2116 
2117 NTSYSAPI
2118 LONG
2119 NTAPI
2120 RtlCompareUnicodeString(
2121     PCUNICODE_STRING String1,
2122     PCUNICODE_STRING String2,
2123     BOOLEAN CaseInsensitive
2124 );
2125 
2126 _Must_inspect_result_
2127 NTSYSAPI
2128 LONG
2129 NTAPI
2130 RtlCompareUnicodeStrings(
2131     _In_reads_(String1Length) PCWCH String1,
2132     _In_ SIZE_T String1Length,
2133     _In_reads_(String2Length) PCWCH String2,
2134     _In_ SIZE_T String2Length,
2135     _In_ BOOLEAN CaseInSensitive
2136 );
2137 
2138 NTSYSAPI
2139 VOID
2140 NTAPI
2141 RtlCopyUnicodeString(
2142     PUNICODE_STRING DestinationString,
2143     PCUNICODE_STRING SourceString
2144 );
2145 
2146 NTSYSAPI
2147 BOOLEAN
2148 NTAPI
2149 RtlCreateUnicodeString(
2150     PUNICODE_STRING DestinationString,
2151     PCWSTR SourceString
2152 );
2153 
2154 #ifdef NTOS_MODE_USER
2155 
2156 NTSYSAPI
2157 NTSTATUS
2158 NTAPI
2159 RtlDowncaseUnicodeString(
2160     _Inout_ PUNICODE_STRING UniDest,
2161     _In_ PCUNICODE_STRING UniSource,
2162     _In_ BOOLEAN AllocateDestinationString
2163 );
2164 
2165 NTSYSAPI
2166 NTSTATUS
2167 NTAPI
2168 RtlDuplicateUnicodeString(
2169     _In_ ULONG Flags,
2170     _In_ PCUNICODE_STRING SourceString,
2171     _Out_ PUNICODE_STRING DestinationString
2172 );
2173 
2174 NTSYSAPI
2175 NTSTATUS
2176 NTAPI
2177 RtlFindCharInUnicodeString(
2178     _In_ ULONG Flags,
2179     _In_ PCUNICODE_STRING SearchString,
2180     _In_ PCUNICODE_STRING MatchString,
2181     _Out_ PUSHORT Position
2182 );
2183 
2184 //
2185 // Memory Functions
2186 //
2187 #if defined(_M_AMD64)
2188 
2189 FORCEINLINE
2190 VOID
2191 RtlFillMemoryUlong(
2192     _Out_writes_bytes_all_(Length) PVOID Destination,
2193     _In_ SIZE_T Length,
2194     _In_ ULONG Pattern)
2195 {
2196     PULONG Address = (PULONG)Destination;
2197     if ((Length /= 4) != 0) {
2198         if (((ULONG64)Address & 4) != 0) {
2199             *Address = Pattern;
2200             if ((Length -= 1) == 0) {
2201                 return;
2202             }
2203             Address += 1;
2204         }
2205         __stosq((PULONG64)(Address), Pattern | ((ULONG64)Pattern << 32), Length / 2);
2206         if ((Length & 1) != 0) Address[Length - 1] = Pattern;
2207     }
2208     return;
2209 }
2210 
2211 #define RtlFillMemoryUlonglong(Destination, Length, Pattern)                \
2212     __stosq((PULONG64)(Destination), Pattern, (Length) / 8)
2213 
2214 #else
2215 
2216 NTSYSAPI
2217 VOID
2218 NTAPI
2219 RtlFillMemoryUlong(
2220     _Out_writes_bytes_all_(Length) PVOID Destination,
2221     _In_ SIZE_T Length,
2222     _In_ ULONG Pattern
2223 );
2224 
2225 NTSYSAPI
2226 VOID
2227 NTAPI
2228 RtlFillMemoryUlonglong(
2229     _Out_ PVOID Destination,
2230     _In_ SIZE_T Length,
2231     _In_ ULONGLONG Pattern
2232 );
2233 
2234 #endif
2235 
2236 NTSYSAPI
2237 NTSTATUS
2238 NTAPI
2239 RtlCopyMappedMemory(
2240     _Out_writes_bytes_all_(Size) PVOID Destination,
2241     _In_reads_bytes_(Size) const VOID *Source,
2242     _In_ SIZE_T Size
2243 );
2244 
2245 NTSYSAPI
2246 SIZE_T
2247 NTAPI
2248 RtlCompareMemoryUlong(
2249     _In_ PVOID Source,
2250     _In_ SIZE_T Length,
2251     _In_ ULONG Pattern
2252 );
2253 
2254 #ifndef RtlEqualMemory
2255 #define RtlEqualMemory(Destination, Source, Length) \
2256     (!memcmp(Destination, Source, Length))
2257 #endif
2258 
2259 #define RtlCopyBytes RtlCopyMemory
2260 #define RtlFillBytes RtlFillMemory
2261 #define RtlZeroBytes RtlZeroMemory
2262 
2263 #endif
2264 
2265 NTSYSAPI
2266 BOOLEAN
2267 NTAPI
2268 RtlEqualUnicodeString(
2269     PCUNICODE_STRING String1,
2270     PCUNICODE_STRING String2,
2271     BOOLEAN CaseInsensitive
2272 );
2273 
2274 _IRQL_requires_max_(PASSIVE_LEVEL)
2275 NTSYSAPI
2276 VOID
2277 NTAPI
2278 RtlFreeUnicodeString(
2279     _Inout_ _At_(UnicodeString->Buffer, __drv_freesMem(Mem))
2280         PUNICODE_STRING UnicodeString
2281 );
2282 
2283 NTSYSAPI
2284 VOID
2285 NTAPI
2286 RtlEraseUnicodeString(
2287     _Inout_ PUNICODE_STRING String
2288 );
2289 
2290 NTSYSAPI
2291 NTSTATUS
2292 NTAPI
2293 RtlHashUnicodeString(
2294     _In_ CONST UNICODE_STRING *String,
2295     _In_ BOOLEAN CaseInSensitive,
2296     _In_ ULONG HashAlgorithm,
2297     _Out_ PULONG HashValue
2298 );
2299 
2300 _IRQL_requires_max_(DISPATCH_LEVEL)
2301 _At_(DestinationString->Buffer, _Post_equal_to_(SourceString))
2302 _When_(SourceString != NULL,
2303 _At_(DestinationString->Length, _Post_equal_to_(_String_length_(SourceString)))
2304 _At_(DestinationString->MaximumLength, _Post_equal_to_(DestinationString->Length + sizeof(CHAR))))
2305 _When_(SourceString == NULL,
2306 _At_(DestinationString->Length, _Post_equal_to_(0))
2307 _At_(DestinationString->MaximumLength, _Post_equal_to_(0)))
2308 NTSYSAPI
2309 VOID
2310 NTAPI
2311 RtlInitString(
2312     _Out_ PSTRING DestinationString,
2313     _In_opt_z_ __drv_aliasesMem PCSTR SourceString
2314 );
2315 
2316 _IRQL_requires_max_(DISPATCH_LEVEL)
2317 _At_(DestinationString->Buffer, _Post_equal_to_(SourceString))
2318 _When_(SourceString != NULL,
2319 _At_(DestinationString->Length, _Post_equal_to_(_String_length_(SourceString) * sizeof(WCHAR)))
2320 _At_(DestinationString->MaximumLength, _Post_equal_to_(DestinationString->Length + sizeof(WCHAR))))
2321 _When_(SourceString == NULL,
2322 _At_(DestinationString->Length, _Post_equal_to_(0))
2323 _At_(DestinationString->MaximumLength, _Post_equal_to_(0)))
2324 NTSYSAPI
2325 VOID
2326 NTAPI
2327 RtlInitUnicodeString(
2328     _Out_ PUNICODE_STRING DestinationString,
2329     _In_opt_z_ __drv_aliasesMem PCWSTR SourceString
2330 );
2331 
2332 _IRQL_requires_max_(DISPATCH_LEVEL)
2333 NTSYSAPI
2334 NTSTATUS
2335 NTAPI
2336 RtlInitUnicodeStringEx(
2337     _Out_ PUNICODE_STRING DestinationString,
2338     _In_opt_z_ __drv_aliasesMem PCWSTR SourceString
2339 );
2340 
2341 NTSYSAPI
2342 BOOLEAN
2343 NTAPI
2344 RtlIsTextUnicode(
2345     _In_ CONST VOID* Buffer,
2346     _In_ INT Size,
2347     _Inout_opt_ INT* Flags
2348 );
2349 
2350 _IRQL_requires_max_(PASSIVE_LEVEL)
2351 _Must_inspect_result_
2352 NTSYSAPI
2353 BOOLEAN
2354 NTAPI
2355 RtlPrefixString(
2356     _In_ const STRING *String1,
2357     _In_ const STRING *String2,
2358     _In_ BOOLEAN CaseInsensitive
2359 );
2360 
2361 _IRQL_requires_max_(PASSIVE_LEVEL)
2362 _Must_inspect_result_
2363 NTSYSAPI
2364 BOOLEAN
2365 NTAPI
2366 RtlPrefixUnicodeString(
2367     _In_ PCUNICODE_STRING String1,
2368     _In_ PCUNICODE_STRING String2,
2369     _In_ BOOLEAN CaseInsensitive
2370 );
2371 
2372 _IRQL_requires_max_(PASSIVE_LEVEL)
2373 NTSYSAPI
2374 VOID
2375 NTAPI
2376 RtlUpperString(
2377     _Inout_ PSTRING DestinationString,
2378     _In_ const STRING *SourceString
2379 );
2380 
2381 _IRQL_requires_max_(PASSIVE_LEVEL)
2382 _Must_inspect_result_
2383 NTSYSAPI
2384 LONG
2385 NTAPI
2386 RtlCompareString(
2387     _In_ const STRING *String1,
2388     _In_ const STRING *String2,
2389     _In_ BOOLEAN CaseInSensitive
2390 );
2391 
2392 NTSYSAPI
2393 VOID
2394 NTAPI
2395 RtlCopyString(
2396     _Out_ PSTRING DestinationString,
2397     _In_opt_ const STRING *SourceString
2398 );
2399 
2400 _IRQL_requires_max_(PASSIVE_LEVEL)
2401 _Must_inspect_result_
2402 NTSYSAPI
2403 BOOLEAN
2404 NTAPI
2405 RtlEqualString(
2406     _In_ const STRING *String1,
2407     _In_ const STRING *String2,
2408     _In_ BOOLEAN CaseInSensitive
2409 );
2410 
2411 _IRQL_requires_max_(APC_LEVEL)
2412 NTSYSAPI
2413 NTSTATUS
2414 NTAPI
2415 RtlAppendStringToString(
2416     _Inout_ PSTRING Destination,
2417     _In_ const STRING *Source
2418 );
2419 
2420 _IRQL_requires_max_(PASSIVE_LEVEL)
2421 _When_(AllocateDestinationString, _Must_inspect_result_)
2422 NTSYSAPI
2423 NTSTATUS
2424 NTAPI
2425 RtlUpcaseUnicodeString(
2426     _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
2427     _When_(!AllocateDestinationString, _Inout_)
2428         PUNICODE_STRING DestinationString,
2429     _In_ PCUNICODE_STRING SourceString,
2430     _In_ BOOLEAN AllocateDestinationString
2431 );
2432 
2433 _IRQL_requires_max_(PASSIVE_LEVEL)
2434 NTSYSAPI
2435 NTSTATUS
2436 NTAPI
2437 RtlUnicodeStringToInteger(
2438     _In_ PCUNICODE_STRING String,
2439     _In_opt_ ULONG Base,
2440     _Out_ PULONG Value
2441 );
2442 
2443 NTSYSAPI
2444 NTSTATUS
2445 NTAPI
2446 RtlValidateUnicodeString(
2447     _In_ ULONG Flags,
2448     _In_ PCUNICODE_STRING String
2449 );
2450 
2451 #define RTL_SKIP_BUFFER_COPY    0x00000001
2452 
2453 NTSYSAPI
2454 NTSTATUS
2455 NTAPI
2456 RtlpEnsureBufferSize(
2457     _In_ ULONG Flags,
2458     _Inout_ PRTL_BUFFER Buffer,
2459     _In_ SIZE_T RequiredSize
2460 );
2461 
2462 #ifdef NTOS_MODE_USER
2463 
2464 FORCEINLINE
2465 VOID
2466 RtlInitBuffer(
2467     _Inout_ PRTL_BUFFER Buffer,
2468     _In_ PUCHAR Data,
2469     _In_ ULONG DataSize
2470 )
2471 {
2472     Buffer->Buffer = Buffer->StaticBuffer = Data;
2473     Buffer->Size = Buffer->StaticSize = DataSize;
2474     Buffer->ReservedForAllocatedSize = 0;
2475     Buffer->ReservedForIMalloc = NULL;
2476 }
2477 
2478 FORCEINLINE
2479 NTSTATUS
2480 RtlEnsureBufferSize(
2481     _In_ ULONG Flags,
2482     _Inout_ PRTL_BUFFER Buffer,
2483     _In_ ULONG RequiredSize
2484 )
2485 {
2486     if (Buffer && RequiredSize <= Buffer->Size)
2487         return STATUS_SUCCESS;
2488     return RtlpEnsureBufferSize(Flags, Buffer, RequiredSize);
2489 }
2490 
2491 FORCEINLINE
2492 VOID
2493 RtlFreeBuffer(
2494     _Inout_ PRTL_BUFFER Buffer
2495 )
2496 {
2497     if (Buffer->Buffer != Buffer->StaticBuffer && Buffer->Buffer)
2498         RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer->Buffer);
2499     Buffer->Buffer = Buffer->StaticBuffer;
2500     Buffer->Size = Buffer->StaticSize;
2501 }
2502 
2503 NTSYSAPI
2504 VOID
2505 NTAPI
2506 RtlRunEncodeUnicodeString(
2507     _Inout_ PUCHAR Hash,
2508     _Inout_ PUNICODE_STRING String
2509 );
2510 
2511 NTSYSAPI
2512 VOID
2513 NTAPI
2514 RtlRunDecodeUnicodeString(
2515     _In_ UCHAR Hash,
2516     _Inout_ PUNICODE_STRING String
2517 );
2518 
2519 #endif /* NTOS_MODE_USER */
2520 
2521 //
2522 // Ansi String Functions
2523 //
2524 _IRQL_requires_max_(PASSIVE_LEVEL)
2525 NTSYSAPI
2526 VOID
2527 NTAPI
2528 RtlFreeAnsiString(
2529     _Inout_ _At_(AnsiString->Buffer, __drv_freesMem(Mem))
2530         PANSI_STRING AnsiString
2531 );
2532 
2533 _IRQL_requires_max_(DISPATCH_LEVEL)
2534 NTSYSAPI
2535 VOID
2536 NTAPI
2537 RtlInitAnsiString(
2538     _Out_ PANSI_STRING DestinationString,
2539     _In_opt_z_ __drv_aliasesMem PCSZ SourceString
2540 );
2541 
2542 _IRQL_requires_max_(DISPATCH_LEVEL)
2543 NTSYSAPI
2544 NTSTATUS
2545 NTAPI
2546 RtlInitAnsiStringEx(
2547     _Out_ PANSI_STRING DestinationString,
2548     _In_opt_z_ __drv_aliasesMem PCSZ SourceString
2549 );
2550 
2551 //
2552 // OEM String Functions
2553 //
2554 _IRQL_requires_max_(PASSIVE_LEVEL)
2555 NTSYSAPI
2556 VOID
2557 NTAPI
2558 RtlFreeOemString(
2559     _Inout_ _At_(OemString->Buffer, __drv_freesMem(Mem))
2560         POEM_STRING OemString
2561 );
2562 
2563 //
2564 // MultiByte->Unicode String Functions
2565 //
2566 _IRQL_requires_max_(PASSIVE_LEVEL)
2567 NTSYSAPI
2568 NTSTATUS
2569 NTAPI
2570 RtlMultiByteToUnicodeN(
2571     _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWCH UnicodeString,
2572     _In_ ULONG MaxBytesInUnicodeString,
2573     _Out_opt_ PULONG BytesInUnicodeString,
2574     _In_reads_bytes_(BytesInMultiByteString) const CHAR *MultiByteString,
2575     _In_ ULONG BytesInMultiByteString
2576 );
2577 
2578 _IRQL_requires_max_(PASSIVE_LEVEL)
2579 NTSYSAPI
2580 NTSTATUS
2581 NTAPI
2582 RtlMultiByteToUnicodeSize(
2583     _Out_ PULONG BytesInUnicodeString,
2584     _In_reads_bytes_(BytesInMultiByteString) const CHAR *MultiByteString,
2585     _In_ ULONG BytesInMultiByteString
2586 );
2587 
2588 //
2589 // Atom Functions
2590 //
2591 NTSYSAPI
2592 NTSTATUS
2593 NTAPI
2594 RtlAddAtomToAtomTable(
2595     _In_ PRTL_ATOM_TABLE AtomTable,
2596     _In_ PWSTR AtomName,
2597     _Out_ PRTL_ATOM Atom
2598 );
2599 
2600 NTSYSAPI
2601 NTSTATUS
2602 NTAPI
2603 RtlCreateAtomTable(
2604     _In_ ULONG TableSize,
2605     _Inout_ PRTL_ATOM_TABLE *AtomTable
2606 );
2607 
2608 NTSYSAPI
2609 NTSTATUS
2610 NTAPI
2611 RtlDeleteAtomFromAtomTable(
2612     _In_ PRTL_ATOM_TABLE AtomTable,
2613     _In_ RTL_ATOM Atom
2614 );
2615 
2616 NTSYSAPI
2617 NTSTATUS
2618 NTAPI
2619 RtlDestroyAtomTable(IN PRTL_ATOM_TABLE AtomTable);
2620 
2621 NTSYSAPI
2622 NTSTATUS
2623 NTAPI
2624 RtlQueryAtomInAtomTable(
2625     _In_ PRTL_ATOM_TABLE AtomTable,
2626     _In_ RTL_ATOM Atom,
2627     _Out_opt_ PULONG RefCount,
2628     _Out_opt_ PULONG PinCount,
2629     _Out_opt_z_bytecap_(*NameLength) PWSTR AtomName,
2630     _Inout_opt_ PULONG NameLength
2631 );
2632 
2633 NTSYSAPI
2634 NTSTATUS
2635 NTAPI
2636 RtlPinAtomInAtomTable(
2637     _In_ PRTL_ATOM_TABLE AtomTable,
2638     _In_ RTL_ATOM Atom
2639 );
2640 
2641 NTSYSAPI
2642 NTSTATUS
2643 NTAPI
2644 RtlLookupAtomInAtomTable(
2645     _In_ PRTL_ATOM_TABLE AtomTable,
2646     _In_ PWSTR AtomName,
2647     _Out_ PRTL_ATOM Atom
2648 );
2649 
2650 //
2651 // Process Management Functions
2652 //
2653 NTSYSAPI
2654 PPEB
2655 NTAPI
2656 RtlGetCurrentPeb(
2657     VOID
2658 );
2659 
2660 NTSYSAPI
2661 VOID
2662 NTAPI
2663 RtlAcquirePebLock(VOID);
2664 
2665 NTSYSAPI
2666 NTSTATUS
2667 NTAPI
2668 RtlCreateProcessParameters (
2669     _Out_ PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
2670     _In_ PUNICODE_STRING ImagePathName,
2671     _In_opt_ PUNICODE_STRING DllPath,
2672     _In_opt_ PUNICODE_STRING CurrentDirectory,
2673     _In_opt_ PUNICODE_STRING CommandLine,
2674     _In_opt_ PWSTR Environment,
2675     _In_opt_ PUNICODE_STRING WindowTitle,
2676     _In_opt_ PUNICODE_STRING DesktopInfo,
2677     _In_opt_ PUNICODE_STRING ShellInfo,
2678     _In_opt_ PUNICODE_STRING RuntimeInfo
2679 );
2680 
2681 NTSYSAPI
2682 NTSTATUS
2683 NTAPI
2684 RtlCreateUserProcess(
2685     _In_ PUNICODE_STRING ImageFileName,
2686     _In_ ULONG Attributes,
2687     _In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
2688     _In_opt_ PSECURITY_DESCRIPTOR ProcessSecutityDescriptor,
2689     _In_opt_ PSECURITY_DESCRIPTOR ThreadSecurityDescriptor,
2690     _In_opt_ HANDLE ParentProcess,
2691     _In_ BOOLEAN CurrentDirectory,
2692     _In_opt_ HANDLE DebugPort,
2693     _In_opt_ HANDLE ExceptionPort,
2694     _Out_ PRTL_USER_PROCESS_INFORMATION ProcessInfo
2695 );
2696 
2697 #if (NTDDI_VERSION >= NTDDI_WIN7)
2698 NTSYSAPI
2699 NTSTATUS
2700 NTAPI
2701 RtlCreateUserThread(
2702     _In_ PVOID ThreadContext,
2703     _Out_ HANDLE *OutThreadHandle,
2704     _Reserved_ PVOID Reserved1,
2705     _Reserved_ PVOID Reserved2,
2706     _Reserved_ PVOID Reserved3,
2707     _Reserved_ PVOID Reserved4,
2708     _Reserved_ PVOID Reserved5,
2709     _Reserved_ PVOID Reserved6,
2710     _Reserved_ PVOID Reserved7,
2711     _Reserved_ PVOID Reserved8
2712 );
2713 #else
2714 NTSYSAPI
2715 NTSTATUS
2716 NTAPI
2717 RtlCreateUserThread(
2718     _In_ HANDLE ProcessHandle,
2719     _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor,
2720     _In_ BOOLEAN CreateSuspended,
2721     _In_ ULONG StackZeroBits,
2722     _In_ SIZE_T StackReserve,
2723     _In_ SIZE_T StackCommit,
2724     _In_ PTHREAD_START_ROUTINE StartAddress,
2725     _In_ PVOID Parameter,
2726     _Out_opt_ PHANDLE ThreadHandle,
2727     _Out_opt_ PCLIENT_ID ClientId
2728 );
2729 #endif
2730 
2731 NTSYSAPI
2732 PRTL_USER_PROCESS_PARAMETERS
2733 NTAPI
2734 RtlDeNormalizeProcessParams(
2735     _In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters);
2736 
2737 NTSYSAPI
2738 NTSTATUS
2739 NTAPI
2740 RtlDestroyProcessParameters(
2741     _In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters);
2742 
2743 NTSYSAPI
2744 VOID
2745 NTAPI
2746 RtlExitUserThread(
2747     _In_ NTSTATUS Status);
2748 
2749 NTSYSAPI
2750 VOID
2751 NTAPI
2752 RtlInitializeContext(
2753     _In_ HANDLE ProcessHandle,
2754     _Out_ PCONTEXT ThreadContext,
2755     _In_opt_ PVOID ThreadStartParam,
2756     _In_ PTHREAD_START_ROUTINE ThreadStartAddress,
2757     _In_ PINITIAL_TEB InitialTeb
2758 );
2759 
2760 #ifdef _M_AMD64
2761 typedef struct _WOW64_CONTEXT *PWOW64_CONTEXT;
2762 
2763 NTSYSAPI
2764 NTSTATUS
2765 NTAPI
2766 RtlWow64GetThreadContext(
2767     _In_ HANDLE ThreadHandle,
2768     _Inout_ PWOW64_CONTEXT ThreadContext
2769 );
2770 
2771 
2772 NTSYSAPI
2773 NTSTATUS
2774 NTAPI
2775 RtlWow64SetThreadContext(
2776     _In_ HANDLE ThreadHandle,
2777     _In_ PWOW64_CONTEXT ThreadContext
2778 );
2779 #endif
2780 
2781 NTSYSAPI
2782 BOOLEAN
2783 NTAPI
2784 RtlIsThreadWithinLoaderCallout(VOID);
2785 
2786 NTSYSAPI
2787 PRTL_USER_PROCESS_PARAMETERS
2788 NTAPI
2789 RtlNormalizeProcessParams(
2790     _In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters);
2791 
2792 NTSYSAPI
2793 VOID
2794 NTAPI
2795 RtlReleasePebLock(VOID);
2796 
2797 NTSYSAPI
2798 NTSTATUS
2799 NTAPI
2800 RtlRemoteCall(
2801     _In_ HANDLE Process,
2802     _In_ HANDLE Thread,
2803     _In_ PVOID CallSite,
2804     _In_ ULONG ArgumentCount,
2805     _In_ PULONG Arguments,
2806     _In_ BOOLEAN PassContext,
2807     _In_ BOOLEAN AlreadySuspended
2808 );
2809 
2810 NTSYSAPI
2811 NTSTATUS
2812 __cdecl
2813 RtlSetProcessIsCritical(
2814     _In_ BOOLEAN NewValue,
2815     _Out_opt_ PBOOLEAN OldValue,
2816     _In_ BOOLEAN NeedBreaks
2817 );
2818 
2819 NTSYSAPI
2820 NTSTATUS
2821 __cdecl
2822 RtlSetThreadIsCritical(
2823     _In_ BOOLEAN NewValue,
2824     _Out_opt_ PBOOLEAN OldValue,
2825     _In_ BOOLEAN NeedBreaks
2826 );
2827 
2828 NTSYSAPI
2829 ULONG
2830 NTAPI
2831 RtlGetCurrentProcessorNumber(
2832     VOID
2833 );
2834 
2835 
2836 //
2837 // Thread Pool Functions
2838 //
2839 //
2840 NTSTATUS
2841 NTAPI
2842 RtlSetThreadPoolStartFunc(
2843     _In_ PRTL_START_POOL_THREAD StartPoolThread,
2844     _In_ PRTL_EXIT_POOL_THREAD ExitPoolThread
2845 );
2846 
2847 NTSYSAPI
2848 NTSTATUS
2849 NTAPI
2850 RtlDeregisterWaitEx(
2851     _In_ HANDLE hWaitHandle,
2852     _In_opt_ HANDLE hCompletionEvent
2853 );
2854 
2855 NTSYSAPI
2856 NTSTATUS
2857 NTAPI
2858 RtlDeregisterWait(
2859     _In_ HANDLE hWaitHandle
2860 );
2861 
2862 NTSYSAPI
2863 NTSTATUS
2864 NTAPI
2865 RtlQueueWorkItem(
2866     _In_ WORKERCALLBACKFUNC Function,
2867     _In_opt_ PVOID Context,
2868     _In_ ULONG Flags
2869 );
2870 
2871 NTSYSAPI
2872 NTSTATUS
2873 NTAPI
2874 RtlSetIoCompletionCallback(
2875     _In_ HANDLE FileHandle,
2876     _In_ PIO_APC_ROUTINE Callback,
2877     _In_ ULONG Flags
2878 );
2879 
2880 NTSYSAPI
2881 NTSTATUS
2882 NTAPI
2883 RtlRegisterWait(
2884     _In_ PHANDLE phNewWaitObject,
2885     _In_ HANDLE hObject,
2886     _In_ WAITORTIMERCALLBACKFUNC Callback,
2887     _In_ PVOID pvContext,
2888     _In_ ULONG ulMilliseconds,
2889     _In_ ULONG ulFlags
2890 );
2891 
2892 //
2893 // Environment/Path Functions
2894 //
2895 NTSYSAPI
2896 NTSTATUS
2897 NTAPI
2898 RtlCreateEnvironment(
2899     _In_ BOOLEAN Inherit,
2900     _Out_ PWSTR *Environment
2901 );
2902 
2903 NTSYSAPI
2904 NTSTATUS
2905 NTAPI
2906 RtlComputePrivatizedDllName_U(
2907     _In_ PUNICODE_STRING DllName,
2908     _Inout_ PUNICODE_STRING RealName,
2909     _Inout_ PUNICODE_STRING LocalName
2910 );
2911 
2912 NTSYSAPI
2913 VOID
2914 NTAPI
2915 RtlDestroyEnvironment(
2916     _In_ PWSTR Environment
2917 );
2918 
2919 NTSYSAPI
2920 BOOLEAN
2921 NTAPI
2922 RtlDoesFileExists_U(
2923     _In_ PCWSTR FileName
2924 );
2925 
2926 NTSYSAPI
2927 RTL_PATH_TYPE
2928 NTAPI
2929 RtlDetermineDosPathNameType_U(
2930     _In_ PCWSTR Path
2931 );
2932 
2933 NTSYSAPI
2934 ULONG
2935 NTAPI
2936 RtlDosSearchPath_U(
2937     _In_ PCWSTR Path,
2938     _In_ PCWSTR FileName,
2939     _In_ PCWSTR Extension,
2940     _In_ ULONG BufferSize,
2941     _Out_ PWSTR Buffer,
2942     _Out_ PWSTR *PartName
2943 );
2944 
2945 NTSYSAPI
2946 NTSTATUS
2947 NTAPI
2948 RtlDosSearchPath_Ustr(
2949     _In_ ULONG Flags,
2950     _In_ PUNICODE_STRING PathString,
2951     _In_ PUNICODE_STRING FileNameString,
2952     _In_ PUNICODE_STRING ExtensionString,
2953     _In_ PUNICODE_STRING CallerBuffer,
2954     _Inout_opt_ PUNICODE_STRING DynamicString,
2955     _Out_opt_ PUNICODE_STRING* FullNameOut,
2956     _Out_opt_ PSIZE_T FilePartSize,
2957     _Out_opt_ PSIZE_T LengthNeeded
2958 );
2959 
2960 NTSYSAPI
2961 BOOLEAN
2962 NTAPI
2963 RtlDosPathNameToNtPathName_U(
2964     _In_opt_z_ PCWSTR DosPathName,
2965     _Out_ PUNICODE_STRING NtPathName,
2966     _Out_opt_ PCWSTR *NtFileNamePart,
2967     _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo
2968 );
2969 
2970 
2971 #define RTL_UNCHANGED_UNK_PATH  1
2972 #define RTL_CONVERTED_UNC_PATH  2
2973 #define RTL_CONVERTED_NT_PATH   3
2974 #define RTL_UNCHANGED_DOS_PATH  4
2975 
2976 NTSYSAPI
2977 NTSTATUS
2978 NTAPI
2979 RtlNtPathNameToDosPathName(
2980     _In_ ULONG Flags,
2981     _Inout_ PRTL_UNICODE_STRING_BUFFER Path,
2982     _Out_opt_ PULONG PathType,
2983     _Out_opt_ PULONG Unknown
2984 );
2985 
2986 
2987 NTSYSAPI
2988 BOOLEAN
2989 NTAPI
2990 RtlDosPathNameToRelativeNtPathName_U(
2991     _In_ PCWSTR DosName,
2992     _Out_ PUNICODE_STRING NtName,
2993     _Out_ PCWSTR *PartName,
2994     _Out_ PRTL_RELATIVE_NAME_U RelativeName
2995 );
2996 
2997 _At_(Destination->Buffer, _Out_bytecap_(Destination->MaximumLength))
2998 NTSYSAPI
2999 NTSTATUS
3000 NTAPI
3001 RtlExpandEnvironmentStrings_U(
3002     _In_z_ PWSTR Environment,
3003     _In_ PUNICODE_STRING Source,
3004     _Inout_ PUNICODE_STRING Destination,
3005     _Out_ PULONG Length
3006 );
3007 
3008 NTSYSAPI
3009 ULONG
3010 NTAPI
3011 RtlGetCurrentDirectory_U(
3012     _In_ ULONG MaximumLength,
3013     _Out_bytecap_(MaximumLength) PWSTR Buffer
3014 );
3015 
3016 NTSYSAPI
3017 ULONG
3018 NTAPI
3019 RtlGetFullPathName_U(
3020     _In_ PCWSTR FileName,
3021     _In_ ULONG Size,
3022     _Out_z_bytecap_(Size) PWSTR Buffer,
3023     _Out_opt_ PWSTR *ShortName
3024 );
3025 
3026 #if (NTDDI_VERSION >= NTDDI_WIN7)
3027 NTSYSAPI
3028 NTSTATUS
3029 NTAPI
3030 RtlGetFullPathName_UEx(
3031     _In_ PWSTR FileName,
3032     _In_ ULONG BufferLength,
3033     _Out_ PWSTR Buffer,
3034     _Out_opt_ PWSTR *FilePart,
3035     _Out_opt_ RTL_PATH_TYPE *InputPathType
3036     );
3037 #endif
3038 
3039 NTSTATUS
3040 NTAPI
3041 RtlGetFullPathName_UstrEx(
3042     _In_ PUNICODE_STRING FileName,
3043     _In_opt_ PUNICODE_STRING StaticString,
3044     _In_opt_ PUNICODE_STRING DynamicString,
3045     _Out_opt_ PUNICODE_STRING *StringUsed,
3046     _Out_opt_ PSIZE_T FilePartSize,
3047     _Out_opt_ PBOOLEAN NameInvalid,
3048     _Out_ RTL_PATH_TYPE* PathType,
3049     _Out_opt_ PSIZE_T LengthNeeded
3050 );
3051 
3052 NTSYSAPI
3053 NTSTATUS
3054 NTAPI
3055 RtlGetLengthWithoutTrailingPathSeperators(
3056     _Reserved_ ULONG Flags,
3057     _In_ PCUNICODE_STRING PathString,
3058     _Out_ PULONG Length
3059 );
3060 
3061 NTSYSAPI
3062 ULONG
3063 NTAPI
3064 RtlGetLongestNtPathLength(
3065     VOID
3066 );
3067 
3068 NTSYSAPI
3069 ULONG
3070 NTAPI
3071 RtlIsDosDeviceName_U(
3072     _In_ PCWSTR Name
3073 );
3074 
3075 NTSYSAPI
3076 ULONG
3077 NTAPI
3078 RtlIsDosDeviceName_Ustr(
3079     _In_ PCUNICODE_STRING Name
3080 );
3081 
3082 _IRQL_requires_max_(PASSIVE_LEVEL)
3083 _Must_inspect_result_
3084 NTSYSAPI
3085 BOOLEAN
3086 NTAPI
3087 RtlIsNameLegalDOS8Dot3(
3088     _In_ PCUNICODE_STRING Name,
3089     _Inout_opt_ POEM_STRING OemName,
3090     _Out_opt_ PBOOLEAN NameContainsSpaces
3091 );
3092 
3093 NTSYSAPI
3094 NTSTATUS
3095 NTAPI
3096 RtlQueryEnvironmentVariable_U(
3097     _In_opt_ PWSTR Environment,
3098     _In_ PCUNICODE_STRING Name,
3099     _Out_ PUNICODE_STRING Value
3100 );
3101 
3102 VOID
3103 NTAPI
3104 RtlReleaseRelativeName(
3105     _In_ PRTL_RELATIVE_NAME_U RelativeName
3106 );
3107 
3108 NTSYSAPI
3109 NTSTATUS
3110 NTAPI
3111 RtlSetCurrentDirectory_U(
3112     _In_ PUNICODE_STRING name
3113 );
3114 
3115 NTSYSAPI
3116 NTSTATUS
3117 NTAPI
3118 RtlSetEnvironmentVariable(
3119     _In_z_ PWSTR *Environment,
3120     _In_ PUNICODE_STRING Name,
3121     _In_ PUNICODE_STRING Value
3122 );
3123 
3124 //
3125 // Critical Section/Resource Functions
3126 //
3127 NTSYSAPI
3128 NTSTATUS
3129 NTAPI
3130 RtlDeleteCriticalSection (
3131     _In_ PRTL_CRITICAL_SECTION CriticalSection
3132 );
3133 
3134 NTSYSAPI
3135 NTSTATUS
3136 NTAPI
3137 RtlEnterCriticalSection(
3138     _In_ PRTL_CRITICAL_SECTION CriticalSection
3139 );
3140 
3141 NTSYSAPI
3142 NTSTATUS
3143 NTAPI
3144 RtlInitializeCriticalSection(
3145     _In_ PRTL_CRITICAL_SECTION CriticalSection
3146 );
3147 
3148 NTSYSAPI
3149 NTSTATUS
3150 NTAPI
3151 RtlInitializeCriticalSectionAndSpinCount(
3152     _In_ PRTL_CRITICAL_SECTION CriticalSection,
3153     _In_ ULONG SpinCount
3154 );
3155 
3156 NTSYSAPI
3157 ULONG
3158 NTAPI
3159 RtlIsCriticalSectionLocked(
3160     _In_ PRTL_CRITICAL_SECTION CriticalSection
3161 );
3162 
3163 NTSYSAPI
3164 ULONG
3165 NTAPI
3166 RtlIsCriticalSectionLockedByThread(
3167     _In_ PRTL_CRITICAL_SECTION CriticalSection
3168 );
3169 
3170 NTSYSAPI
3171 NTSTATUS
3172 NTAPI
3173 RtlLeaveCriticalSection(
3174     _In_ PRTL_CRITICAL_SECTION CriticalSection
3175 );
3176 
3177 NTSYSAPI
3178 BOOLEAN
3179 NTAPI
3180 RtlTryEnterCriticalSection(
3181     _In_ PRTL_CRITICAL_SECTION CriticalSection
3182 );
3183 
3184 NTSYSAPI
3185 VOID
3186 NTAPI
3187 RtlpUnWaitCriticalSection(
3188     _In_ PRTL_CRITICAL_SECTION CriticalSection
3189 );
3190 
3191 NTSYSAPI
3192 NTSTATUS
3193 NTAPI
3194 RtlpWaitForCriticalSection(
3195     _In_ PRTL_CRITICAL_SECTION CriticalSection
3196 );
3197 
3198 NTSYSAPI
3199 BOOLEAN
3200 NTAPI
3201 RtlAcquireResourceExclusive(
3202     _In_ PRTL_RESOURCE Resource,
3203     _In_ BOOLEAN Wait
3204 );
3205 
3206 NTSYSAPI
3207 BOOLEAN
3208 NTAPI
3209 RtlAcquireResourceShared(
3210     _In_ PRTL_RESOURCE Resource,
3211     _In_ BOOLEAN Wait
3212 );
3213 
3214 NTSYSAPI
3215 VOID
3216 NTAPI
3217 RtlConvertExclusiveToShared(
3218     _In_ PRTL_RESOURCE Resource
3219 );
3220 
3221 NTSYSAPI
3222 VOID
3223 NTAPI
3224 RtlConvertSharedToExclusive(
3225     _In_ PRTL_RESOURCE Resource
3226 );
3227 
3228 NTSYSAPI
3229 VOID
3230 NTAPI
3231 RtlDeleteResource(
3232     _In_ PRTL_RESOURCE Resource
3233 );
3234 
3235 NTSYSAPI
3236 VOID
3237 NTAPI
3238 RtlDumpResource(
3239     _In_ PRTL_RESOURCE Resource
3240 );
3241 
3242 NTSYSAPI
3243 VOID
3244 NTAPI
3245 RtlInitializeResource(
3246     _In_ PRTL_RESOURCE Resource
3247 );
3248 
3249 NTSYSAPI
3250 VOID
3251 NTAPI
3252 RtlReleaseResource(
3253     _In_ PRTL_RESOURCE Resource
3254 );
3255 
3256 //
3257 // Compression Functions
3258 //
3259 NTSYSAPI //NT_RTL_COMPRESS_API
3260 NTSTATUS
3261 NTAPI
3262 RtlCompressBuffer(
3263     _In_ USHORT CompressionFormatAndEngine,
3264     _In_reads_bytes_(UncompressedBufferSize) PUCHAR UncompressedBuffer,
3265     _In_ ULONG UncompressedBufferSize,
3266     _Out_writes_bytes_to_(CompressedBufferSize, *FinalCompressedSize) PUCHAR CompressedBuffer,
3267     _In_ ULONG CompressedBufferSize,
3268     _In_ ULONG UncompressedChunkSize,
3269     _Out_ PULONG FinalCompressedSize,
3270     _In_ PVOID WorkSpace
3271 );
3272 
3273 _IRQL_requires_max_(APC_LEVEL)
3274 NTSYSAPI //NT_RTL_COMPRESS_API
3275 NTSTATUS
3276 NTAPI
3277 RtlDecompressBuffer(
3278     _In_ USHORT CompressionFormat,
3279     _Out_writes_bytes_to_(UncompressedBufferSize, *FinalUncompressedSize) PUCHAR UncompressedBuffer,
3280     _In_ ULONG UncompressedBufferSize,
3281     _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
3282     _In_ ULONG CompressedBufferSize,
3283     _Out_ PULONG FinalUncompressedSize
3284 );
3285 
3286 NTSYSAPI
3287 NTSTATUS
3288 NTAPI
3289 RtlGetCompressionWorkSpaceSize(
3290     _In_ USHORT CompressionFormatAndEngine,
3291     _Out_ PULONG CompressBufferWorkSpaceSize,
3292     _Out_ PULONG CompressFragmentWorkSpaceSize
3293 );
3294 
3295 //
3296 // Frame Functions
3297 //
3298 NTSYSAPI
3299 VOID
3300 NTAPI
3301 RtlPopFrame(
3302     _In_ PTEB_ACTIVE_FRAME Frame
3303 );
3304 
3305 NTSYSAPI
3306 VOID
3307 NTAPI
3308 RtlPushFrame(
3309     _In_ PTEB_ACTIVE_FRAME Frame
3310 );
3311 
3312 NTSYSAPI
3313 PTEB_ACTIVE_FRAME
3314 NTAPI
3315 RtlGetFrame(
3316     VOID
3317 );
3318 
3319 //
3320 // Debug Info Functions
3321 //
3322 NTSYSAPI
3323 PRTL_DEBUG_INFORMATION
3324 NTAPI
3325 RtlCreateQueryDebugBuffer(
3326     _In_ ULONG Size,
3327     _In_ BOOLEAN EventPair
3328 );
3329 
3330 NTSYSAPI
3331 NTSTATUS
3332 NTAPI
3333 RtlDestroyQueryDebugBuffer(IN PRTL_DEBUG_INFORMATION DebugBuffer);
3334 
3335 NTSYSAPI
3336 NTSTATUS
3337 NTAPI
3338 RtlQueryProcessDebugInformation(
3339     _In_ ULONG ProcessId,
3340     _In_ ULONG DebugInfoClassMask,
3341     _Inout_ PRTL_DEBUG_INFORMATION DebugBuffer
3342 );
3343 
3344 //
3345 // Bitmap Functions
3346 //
3347 #ifdef NTOS_MODE_USER
3348 
3349 NTSYSAPI
3350 BOOLEAN
3351 NTAPI
3352 RtlAreBitsClear(
3353     _In_ PRTL_BITMAP BitMapHeader,
3354     _In_ ULONG StartingIndex,
3355     _In_ ULONG Length
3356 );
3357 
3358 NTSYSAPI
3359 BOOLEAN
3360 NTAPI
3361 RtlAreBitsSet(
3362     _In_ PRTL_BITMAP BitMapHeader,
3363     _In_ ULONG StartingIndex,
3364     _In_ ULONG Length
3365 );
3366 
3367 NTSYSAPI
3368 VOID
3369 NTAPI
3370 RtlClearAllBits(
3371     _In_ PRTL_BITMAP BitMapHeader
3372 );
3373 
3374 NTSYSAPI
3375 VOID
3376 NTAPI
3377 RtlClearBit(
3378     _In_ PRTL_BITMAP BitMapHeader,
3379     _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber
3380 );
3381 
3382 NTSYSAPI
3383 VOID
3384 NTAPI
3385 RtlClearBits(
3386     _In_ PRTL_BITMAP BitMapHeader,
3387     _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToClear) ULONG StartingIndex,
3388     _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToClear
3389 );
3390 
3391 NTSYSAPI
3392 ULONG
3393 NTAPI
3394 RtlFindClearBits(
3395     _In_ PRTL_BITMAP BitMapHeader,
3396     _In_ ULONG NumberToFind,
3397     _In_ ULONG HintIndex
3398 );
3399 
3400 NTSYSAPI
3401 ULONG
3402 NTAPI
3403 RtlFindClearBitsAndSet(
3404     _In_ PRTL_BITMAP BitMapHeader,
3405     _In_ ULONG NumberToFind,
3406     _In_ ULONG HintIndex
3407 );
3408 
3409 NTSYSAPI
3410 ULONG
3411 NTAPI
3412 RtlFindFirstRunClear(
3413     _In_ PRTL_BITMAP BitMapHeader,
3414     _Out_ PULONG StartingIndex
3415 );
3416 
3417 NTSYSAPI
3418 ULONG
3419 NTAPI
3420 RtlFindClearRuns(
3421     _In_ PRTL_BITMAP BitMapHeader,
3422     _Out_writes_to_(SizeOfRunArray, return) PRTL_BITMAP_RUN RunArray,
3423     _In_range_(>, 0) ULONG SizeOfRunArray,
3424     _In_ BOOLEAN LocateLongestRuns
3425 );
3426 
3427 NTSYSAPI
3428 ULONG
3429 NTAPI
3430 RtlFindLastBackwardRunClear(
3431     _In_ PRTL_BITMAP BitMapHeader,
3432     _In_ ULONG FromIndex,
3433     _Out_ PULONG StartingRunIndex
3434 );
3435 
3436 NTSYSAPI
3437 CCHAR
3438 NTAPI
3439 RtlFindLeastSignificantBit(
3440     _In_ ULONGLONG Value
3441 );
3442 
3443 NTSYSAPI
3444 ULONG
3445 NTAPI
3446 RtlFindLongestRunClear(
3447     _In_ PRTL_BITMAP BitMapHeader,
3448     _Out_ PULONG StartingIndex
3449 );
3450 
3451 NTSYSAPI
3452 CCHAR
3453 NTAPI
3454 RtlFindMostSignificantBit(
3455     _In_ ULONGLONG Value
3456 );
3457 
3458 NTSYSAPI
3459 ULONG
3460 NTAPI
3461 RtlFindNextForwardRunClear(
3462     _In_ PRTL_BITMAP BitMapHeader,
3463     _In_ ULONG FromIndex,
3464     _Out_ PULONG StartingRunIndex
3465 );
3466 
3467 NTSYSAPI
3468 ULONG
3469 NTAPI
3470 RtlFindNextForwardRunSet(
3471     _In_ PRTL_BITMAP BitMapHeader,
3472     _In_ ULONG FromIndex,
3473     _Out_ PULONG StartingRunIndex
3474 );
3475 
3476 NTSYSAPI
3477 ULONG
3478 NTAPI
3479 RtlFindSetBits(
3480     _In_ PRTL_BITMAP BitMapHeader,
3481     _In_ ULONG NumberToFind,
3482     _In_ ULONG HintIndex
3483 );
3484 
3485 NTSYSAPI
3486 ULONG
3487 NTAPI
3488 RtlFindSetBitsAndClear(
3489     _In_ PRTL_BITMAP BitMapHeader,
3490     _In_ ULONG NumberToFind,
3491     _In_ ULONG HintIndex
3492 );
3493 
3494 #ifdef __REACTOS__ // ReactOS improvement
3495 _At_(BitMapHeader->SizeOfBitMap, _Post_equal_to_(SizeOfBitMap))
3496 _At_(BitMapHeader->Buffer, _Post_equal_to_(BitMapBuffer))
3497 #endif
3498 NTSYSAPI
3499 VOID
3500 NTAPI
3501 RtlInitializeBitMap(
3502     _Out_ PRTL_BITMAP BitMapHeader,
3503     _In_opt_ __drv_aliasesMem PULONG BitMapBuffer,
3504     _In_opt_ ULONG SizeOfBitMap
3505 );
3506 
3507 NTSYSAPI
3508 ULONG
3509 NTAPI
3510 RtlNumberOfClearBits(
3511     _In_ PRTL_BITMAP BitMapHeader
3512 );
3513 
3514 NTSYSAPI
3515 ULONG
3516 NTAPI
3517 RtlNumberOfSetBits(
3518     _In_ PRTL_BITMAP BitMapHeader
3519 );
3520 
3521 NTSYSAPI
3522 VOID
3523 NTAPI
3524 RtlSetBit(
3525     _In_ PRTL_BITMAP BitMapHeader,
3526     _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber
3527 );
3528 
3529 NTSYSAPI
3530 VOID
3531 NTAPI
3532 RtlSetBits(
3533     _In_ PRTL_BITMAP BitMapHeader,
3534     _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex,
3535     _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet
3536 );
3537 
3538 NTSYSAPI
3539 VOID
3540 NTAPI
3541 RtlSetAllBits(
3542     _In_ PRTL_BITMAP BitMapHeader
3543 );
3544 
3545 _Must_inspect_result_
3546 NTSYSAPI
3547 BOOLEAN
3548 NTAPI
3549 RtlTestBit(
3550     _In_ PRTL_BITMAP BitMapHeader,
3551     _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber
3552 );
3553 
3554 #if defined(_M_AMD64)
3555 _Must_inspect_result_
3556 FORCEINLINE
3557 BOOLEAN
3558 RtlCheckBit(
3559   _In_ PRTL_BITMAP BitMapHeader,
3560   _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitPosition)
3561 {
3562   return BitTest64((LONG64 CONST*)BitMapHeader->Buffer, (LONG64)BitPosition);
3563 }
3564 #else
3565 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP)/32]) >> ((BP)%32)) & 0x1)
3566 #endif /* defined(_M_AMD64) */
3567 
3568 #endif // NTOS_MODE_USER
3569 
3570 
3571 //
3572 // Timer Functions
3573 //
3574 NTSYSAPI
3575 NTSTATUS
3576 NTAPI
3577 RtlCreateTimer(
3578     _In_ HANDLE TimerQueue,
3579     _In_ PHANDLE phNewTimer,
3580     _In_ WAITORTIMERCALLBACKFUNC Callback,
3581     _In_ PVOID Parameter,
3582     _In_ ULONG DueTime,
3583     _In_ ULONG Period,
3584     _In_ ULONG Flags
3585 );
3586 
3587 NTSYSAPI
3588 NTSTATUS
3589 NTAPI
3590 RtlCreateTimerQueue(PHANDLE TimerQueue);
3591 
3592 NTSYSAPI
3593 NTSTATUS
3594 NTAPI
3595 RtlDeleteTimer(
3596     _In_ HANDLE TimerQueue,
3597     _In_ HANDLE Timer,
3598     _In_ HANDLE CompletionEvent
3599 );
3600 
3601 NTSYSAPI
3602 NTSTATUS
3603 NTAPI
3604 RtlUpdateTimer(
3605     _In_ HANDLE TimerQueue,
3606     _In_ HANDLE Timer,
3607     _In_ ULONG DueTime,
3608     _In_ ULONG Period
3609 );
3610 
3611 NTSYSAPI
3612 NTSTATUS
3613 NTAPI
3614 RtlDeleteTimerQueueEx(
3615     _In_ HANDLE TimerQueue,
3616     _In_opt_ HANDLE CompletionEvent
3617 );
3618 
3619 NTSYSAPI
3620 NTSTATUS
3621 NTAPI
3622 RtlDeleteTimerQueue(HANDLE TimerQueue);
3623 
3624 //
3625 // SList functions
3626 //
3627 PSLIST_ENTRY
3628 FASTCALL
3629 InterlockedPushListSList(
3630     _Inout_ PSLIST_HEADER ListHead,
3631     _Inout_ __drv_aliasesMem PSLIST_ENTRY List,
3632     _Inout_ PSLIST_ENTRY ListEnd,
3633     _In_ ULONG Count
3634 );
3635 
3636 //
3637 // Range List functions
3638 //
3639 NTSYSAPI
3640 VOID
3641 NTAPI
3642 RtlInitializeRangeList(
3643     _Out_ PRTL_RANGE_LIST RangeList
3644 );
3645 
3646 NTSYSAPI
3647 VOID
3648 NTAPI
3649 RtlFreeRangeList(
3650     _In_ PRTL_RANGE_LIST RangeList
3651 );
3652 
3653 NTSYSAPI
3654 NTSTATUS
3655 NTAPI
3656 RtlCopyRangeList(
3657     _Out_ PRTL_RANGE_LIST CopyRangeList,
3658     _In_ PRTL_RANGE_LIST RangeList
3659 );
3660 
3661 NTSYSAPI
3662 NTSTATUS
3663 NTAPI
3664 RtlMergeRangeLists(
3665     _Out_ PRTL_RANGE_LIST MergedRangeList,
3666     _In_ PRTL_RANGE_LIST RangeList1,
3667     _In_ PRTL_RANGE_LIST RangeList2,
3668     _In_ ULONG Flags
3669 );
3670 
3671 NTSYSAPI
3672 NTSTATUS
3673 NTAPI
3674 RtlInvertRangeList(
3675     _Out_ PRTL_RANGE_LIST InvertedRangeList,
3676     _In_ PRTL_RANGE_LIST RangeList
3677 );
3678 
3679 NTSYSAPI
3680 NTSTATUS
3681 NTAPI
3682 RtlAddRange(
3683     _Inout_ PRTL_RANGE_LIST RangeList,
3684     _In_ ULONGLONG Start,
3685     _In_ ULONGLONG End,
3686     _In_ UCHAR Attributes,
3687     _In_ ULONG Flags,
3688     _In_opt_ PVOID UserData,
3689     _In_opt_ PVOID Owner
3690 );
3691 
3692 NTSYSAPI
3693 NTSTATUS
3694 NTAPI
3695 RtlDeleteRange(
3696     _Inout_ PRTL_RANGE_LIST RangeList,
3697     _In_ ULONGLONG Start,
3698     _In_ ULONGLONG End,
3699     _In_ PVOID Owner
3700 );
3701 
3702 NTSYSAPI
3703 NTSTATUS
3704 NTAPI
3705 RtlDeleteOwnersRanges(
3706     _Inout_ PRTL_RANGE_LIST RangeList,
3707     _In_ _Maybenull_ PVOID Owner
3708 );
3709 
3710 NTSYSAPI
3711 NTSTATUS
3712 NTAPI
3713 RtlFindRange(
3714     _In_ PRTL_RANGE_LIST RangeList,
3715     _In_ ULONGLONG Minimum,
3716     _In_ ULONGLONG Maximum,
3717     _In_ ULONG Length,
3718     _In_ ULONG Alignment,
3719     _In_ ULONG Flags,
3720     _In_ UCHAR AttributeAvailableMask,
3721     _In_opt_ PVOID Context,
3722     _In_opt_ PRTL_CONFLICT_RANGE_CALLBACK Callback,
3723     _Out_ PULONGLONG Start
3724 );
3725 
3726 NTSYSAPI
3727 NTSTATUS
3728 NTAPI
3729 RtlIsRangeAvailable(
3730     _In_ PRTL_RANGE_LIST RangeList,
3731     _In_ ULONGLONG Start,
3732     _In_ ULONGLONG End,
3733     _In_ ULONG Flags,
3734     _In_ UCHAR AttributeAvailableMask,
3735     _In_opt_ PVOID Context,
3736     _In_opt_ PRTL_CONFLICT_RANGE_CALLBACK Callback,
3737     _Out_ PBOOLEAN Available
3738 );
3739 
3740 NTSYSAPI
3741 NTSTATUS
3742 NTAPI
3743 RtlGetFirstRange(
3744     _In_ PRTL_RANGE_LIST RangeList,
3745     _Out_ PRTL_RANGE_LIST_ITERATOR Iterator,
3746     _Outptr_ PRTL_RANGE *Range
3747 );
3748 
3749 NTSYSAPI
3750 NTSTATUS
3751 NTAPI
3752 RtlGetNextRange(
3753     _Inout_ PRTL_RANGE_LIST_ITERATOR Iterator,
3754     _Outptr_ PRTL_RANGE *Range,
3755     _In_ BOOLEAN MoveForwards
3756 );
3757 
3758 //
3759 // Debug Functions
3760 //
3761 ULONG
3762 __cdecl
3763 DbgPrint(
3764     _In_z_ _Printf_format_string_ PCSTR Format,
3765     ...
3766 );
3767 
3768 NTSYSAPI
3769 ULONG
3770 __cdecl
3771 DbgPrintEx(
3772     _In_ ULONG ComponentId,
3773     _In_ ULONG Level,
3774     _In_z_ _Printf_format_string_ PCSTR Format,
3775     ...
3776 );
3777 
3778 NTSYSAPI
3779 ULONG
3780 NTAPI
3781 DbgPrompt(
3782     _In_z_ PCCH Prompt,
3783     _Out_writes_bytes_(MaximumResponseLength) PCH Response,
3784     _In_ ULONG MaximumResponseLength
3785 );
3786 
3787 #undef DbgBreakPoint
3788 VOID
3789 NTAPI
3790 DbgBreakPoint(
3791     VOID
3792 );
3793 
3794 VOID
3795 NTAPI
3796 DbgLoadImageSymbols(
3797     _In_ PSTRING Name,
3798     _In_ PVOID Base,
3799     _In_ ULONG_PTR ProcessId
3800 );
3801 
3802 VOID
3803 NTAPI
3804 DbgUnLoadImageSymbols(
3805     _In_ PSTRING Name,
3806     _In_ PVOID Base,
3807     _In_ ULONG_PTR ProcessId
3808 );
3809 
3810 VOID
3811 NTAPI
3812 DbgCommandString(
3813     _In_ PCCH Name,
3814     _In_ PCCH Command
3815 );
3816 
3817 //
3818 // Generic Table Functions
3819 //
3820 #if defined(NTOS_MODE_USER) || defined(_NTIFS_)
3821 NTSYSAPI
3822 PVOID
3823 NTAPI
3824 RtlInsertElementGenericTable(
3825     _In_ PRTL_GENERIC_TABLE Table,
3826     _In_reads_bytes_(BufferSize) PVOID Buffer,
3827     _In_ CLONG BufferSize,
3828     _Out_opt_ PBOOLEAN NewElement
3829 );
3830 
3831 NTSYSAPI
3832 PVOID
3833 NTAPI
3834 RtlInsertElementGenericTableFull(
3835     _In_ PRTL_GENERIC_TABLE Table,
3836     _In_reads_bytes_(BufferSize) PVOID Buffer,
3837     _In_ CLONG BufferSize,
3838     _Out_opt_ PBOOLEAN NewElement,
3839     _In_ PVOID NodeOrParent,
3840     _In_ TABLE_SEARCH_RESULT SearchResult
3841 );
3842 
3843 NTSYSAPI
3844 BOOLEAN
3845 NTAPI
3846 RtlIsGenericTableEmpty(
3847     _In_ PRTL_GENERIC_TABLE Table
3848 );
3849 
3850 NTSYSAPI
3851 PVOID
3852 NTAPI
3853 RtlLookupElementGenericTableFull(
3854     _In_ PRTL_GENERIC_TABLE Table,
3855     _In_ PVOID Buffer,
3856     _Out_ PVOID *NodeOrParent,
3857     _Out_ TABLE_SEARCH_RESULT *SearchResult
3858 );
3859 #endif
3860 
3861 //
3862 // Handle Table Functions
3863 //
3864 NTSYSAPI
3865 PRTL_HANDLE_TABLE_ENTRY
3866 NTAPI
3867 RtlAllocateHandle(
3868     _In_ PRTL_HANDLE_TABLE HandleTable,
3869     _Inout_ PULONG Index
3870 );
3871 
3872 NTSYSAPI
3873 VOID
3874 NTAPI
3875 RtlDestroyHandleTable(
3876     _Inout_ PRTL_HANDLE_TABLE HandleTable);
3877 
3878 NTSYSAPI
3879 BOOLEAN
3880 NTAPI
3881 RtlFreeHandle(
3882     _In_ PRTL_HANDLE_TABLE HandleTable,
3883     _In_ PRTL_HANDLE_TABLE_ENTRY Handle
3884 );
3885 
3886 NTSYSAPI
3887 VOID
3888 NTAPI
3889 RtlInitializeHandleTable(
3890     _In_ ULONG TableSize,
3891     _In_ ULONG HandleSize,
3892     _In_ PRTL_HANDLE_TABLE HandleTable
3893 );
3894 
3895 NTSYSAPI
3896 BOOLEAN
3897 NTAPI
3898 RtlIsValidHandle(
3899     _In_ PRTL_HANDLE_TABLE HandleTable,
3900     _In_ PRTL_HANDLE_TABLE_ENTRY Handle
3901 );
3902 
3903 _Success_(return!=FALSE)
3904 NTSYSAPI
3905 BOOLEAN
3906 NTAPI
3907 RtlIsValidIndexHandle(
3908     _In_ PRTL_HANDLE_TABLE HandleTable,
3909     _In_ ULONG Index,
3910     _Out_ PRTL_HANDLE_TABLE_ENTRY *Handle
3911 );
3912 
3913 //
3914 // PE Functions
3915 //
3916 NTSYSAPI
3917 NTSTATUS
3918 NTAPI
3919 RtlFindMessage(
3920     _In_ PVOID BaseAddress,
3921     _In_ ULONG Type,
3922     _In_ ULONG Language,
3923     _In_ ULONG MessageId,
3924     _Out_ PMESSAGE_RESOURCE_ENTRY *MessageResourceEntry
3925 );
3926 
3927 NTSYSAPI
3928 ULONG
3929 NTAPI
3930 RtlGetNtGlobalFlags(VOID);
3931 
3932 _Success_(return!=NULL)
3933 NTSYSAPI
3934 PVOID
3935 NTAPI
3936 RtlImageDirectoryEntryToData(
3937     _In_ PVOID BaseAddress,
3938     _In_ BOOLEAN MappedAsImage,
3939     _In_ USHORT Directory,
3940     _Out_ PULONG Size
3941 );
3942 
3943 NTSYSAPI
3944 PVOID
3945 NTAPI
3946 RtlImageRvaToVa(
3947     _In_ PIMAGE_NT_HEADERS NtHeader,
3948     _In_ PVOID BaseAddress,
3949     _In_ ULONG Rva,
3950     _Inout_opt_ PIMAGE_SECTION_HEADER *SectionHeader
3951 );
3952 
3953 NTSYSAPI
3954 PIMAGE_NT_HEADERS
3955 NTAPI
3956 RtlImageNtHeader(
3957     _In_ PVOID BaseAddress);
3958 
3959 NTSYSAPI
3960 NTSTATUS
3961 NTAPI
3962 RtlImageNtHeaderEx(
3963     _In_ ULONG Flags,
3964     _In_ PVOID BaseAddress,
3965     _In_ ULONGLONG Size,
3966     _Out_ PIMAGE_NT_HEADERS *NtHeader
3967 );
3968 
3969 NTSYSAPI
3970 PIMAGE_SECTION_HEADER
3971 NTAPI
3972 RtlImageRvaToSection(
3973     _In_ PIMAGE_NT_HEADERS NtHeader,
3974     _In_ PVOID BaseAddress,
3975     _In_ ULONG Rva
3976 );
3977 
3978 ULONG
3979 NTAPI
3980 LdrRelocateImageWithBias(
3981     _In_ PVOID BaseAddress,
3982     _In_ LONGLONG AdditionalBias,
3983     _In_opt_ PCSTR LoaderName,
3984     _In_ ULONG Success,
3985     _In_ ULONG Conflict,
3986     _In_ ULONG Invalid
3987 );
3988 
3989 //
3990 // Activation Context Functions
3991 //
3992 #ifdef NTOS_MODE_USER
3993 NTSYSAPI
3994 NTSTATUS
3995 NTAPI
3996 RtlActivateActivationContextEx(
3997     _In_ ULONG Flags,
3998     _In_ PTEB Teb,
3999     _In_ PVOID Context,
4000     _Out_ PULONG_PTR Cookie
4001 );
4002 
4003 NTSYSAPI
4004 NTSTATUS
4005 NTAPI
4006 RtlActivateActivationContext(
4007     _In_ ULONG Flags,
4008     _In_ HANDLE Handle,
4009     _Out_ PULONG_PTR Cookie
4010 );
4011 
4012 NTSYSAPI
4013 VOID
4014 NTAPI
4015 RtlAddRefActivationContext(
4016     _In_ PVOID Context
4017 );
4018 
4019 NTSYSAPI
4020 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
4021 FASTCALL
4022 RtlActivateActivationContextUnsafeFast(
4023     _In_ PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame,
4024     _In_ PVOID Context
4025 );
4026 
4027 NTSYSAPI
4028 NTSTATUS
4029 NTAPI
4030 RtlAllocateActivationContextStack(
4031     _In_ PACTIVATION_CONTEXT_STACK *Stack
4032 );
4033 
4034 NTSYSAPI
4035 NTSTATUS
4036 NTAPI
4037 RtlCreateActivationContext(
4038     _In_ ULONG Flags,
4039     _In_ PACTIVATION_CONTEXT_DATA ActivationContextData,
4040     _In_ ULONG ExtraBytes,
4041     _In_ PVOID NotificationRoutine,
4042     _In_ PVOID NotificationContext,
4043     _Out_ PACTIVATION_CONTEXT *ActCtx
4044 );
4045 
4046 NTSYSAPI
4047 NTSTATUS
4048 NTAPI
4049 RtlGetActiveActivationContext(
4050     _In_ PVOID *Context
4051 );
4052 
4053 NTSYSAPI
4054 VOID
4055 NTAPI
4056 RtlReleaseActivationContext(
4057     _In_ HANDLE handle
4058 );
4059 
4060 NTSYSAPI
4061 NTSTATUS
4062 NTAPI
4063 RtlDeactivateActivationContext(
4064     _In_ ULONG dwFlags,
4065     _In_ ULONG_PTR ulCookie
4066 );
4067 
4068 NTSYSAPI
4069 VOID
4070 NTAPI
4071 RtlFreeActivationContextStack(
4072     _In_ PACTIVATION_CONTEXT_STACK Stack
4073 );
4074 
4075 NTSYSAPI
4076 VOID
4077 NTAPI
4078 RtlFreeThreadActivationContextStack(VOID);
4079 
4080 NTSYSAPI
4081 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
4082 FASTCALL
4083 RtlDeactivateActivationContextUnsafeFast(
4084     _In_ PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame
4085 );
4086 
4087 NTSYSAPI
4088 NTSTATUS
4089 NTAPI
4090 RtlDosApplyFileIsolationRedirection_Ustr(
4091     _In_ ULONG Flags,
4092     _In_ PUNICODE_STRING OriginalName,
4093     _In_ PUNICODE_STRING Extension,
4094     _Inout_ PUNICODE_STRING StaticString,
4095     _Inout_ PUNICODE_STRING DynamicString,
4096     _Inout_ PUNICODE_STRING *NewName,
4097     _In_ PULONG NewFlags,
4098     _In_ PSIZE_T FileNameSize,
4099     _In_ PSIZE_T RequiredLength
4100 );
4101 
4102 NTSYSAPI
4103 NTSTATUS
4104 NTAPI
4105 RtlFindActivationContextSectionString(
4106     _In_ ULONG dwFlags,
4107     _In_ const GUID *ExtensionGuid,
4108     _In_ ULONG SectionType,
4109     _In_ const UNICODE_STRING *SectionName,
4110     _Inout_ PVOID ReturnedData
4111 );
4112 
4113 NTSYSAPI
4114 NTSTATUS
4115 NTAPI
4116 RtlQueryInformationActivationContext(
4117     _In_ DWORD dwFlags,
4118     _In_opt_ PVOID Context,
4119     _In_opt_ PVOID pvSubInstance,
4120     _In_ ULONG ulInfoClass,
4121     _Out_bytecap_(cbBuffer) PVOID pvBuffer,
4122     _In_opt_ SIZE_T cbBuffer,
4123     _Out_opt_ SIZE_T *pcbWrittenOrRequired
4124 );
4125 
4126 NTSYSAPI
4127 NTSTATUS
4128 NTAPI
4129 RtlQueryInformationActiveActivationContext(
4130     _In_ ULONG ulInfoClass,
4131     _Out_bytecap_(cbBuffer) PVOID pvBuffer,
4132     _In_opt_ SIZE_T cbBuffer,
4133     _Out_opt_ SIZE_T *pcbWrittenOrRequired
4134 );
4135 
4136 NTSYSAPI
4137 NTSTATUS
4138 NTAPI
4139 RtlZombifyActivationContext(
4140     PVOID Context
4141 );
4142 
4143 //
4144 // WOW64 Functions
4145 //
4146 NTSYSAPI
4147 NTSTATUS
4148 NTAPI
4149 RtlWow64EnableFsRedirection(
4150     _In_ BOOLEAN Wow64FsEnableRedirection
4151 );
4152 
4153 NTSYSAPI
4154 NTSTATUS
4155 NTAPI
4156 RtlWow64EnableFsRedirectionEx(
4157     _In_ PVOID Wow64FsEnableRedirection,
4158     _Out_ PVOID *OldFsRedirectionLevel
4159 );
4160 
4161 #endif
4162 
4163 //
4164 // Registry Functions
4165 //
4166 _IRQL_requires_max_(PASSIVE_LEVEL)
4167 _Must_inspect_result_
4168 NTSYSAPI
4169 NTSTATUS
4170 NTAPI
4171 RtlCheckRegistryKey(
4172     _In_ ULONG RelativeTo,
4173     _In_ PWSTR Path
4174 );
4175 
4176 NTSYSAPI
4177 NTSTATUS
4178 NTAPI
4179 RtlCreateRegistryKey(
4180     _In_ ULONG RelativeTo,
4181     _In_ PWSTR Path
4182 );
4183 
4184 NTSYSAPI
4185 NTSTATUS
4186 NTAPI
4187 RtlFormatCurrentUserKeyPath(
4188     _Out_ _At_(KeyPath->Buffer, __drv_allocatesMem(Mem) _Post_bytecap_(KeyPath->MaximumLength) _Post_bytecount_(KeyPath->Length))
4189         PUNICODE_STRING KeyPath
4190 );
4191 
4192 NTSYSAPI
4193 NTSTATUS
4194 NTAPI
4195 RtlOpenCurrentUser(
4196     _In_ ACCESS_MASK DesiredAccess,
4197     _Out_ PHANDLE KeyHandle
4198 );
4199 
4200 _IRQL_requires_max_(PASSIVE_LEVEL)
4201 NTSYSAPI
4202 NTSTATUS
4203 NTAPI
4204 RtlQueryRegistryValues(
4205     _In_ ULONG RelativeTo,
4206     _In_ PCWSTR Path,
4207     _Inout_ _At_(*(*QueryTable).EntryContext, _Pre_unknown_)
4208         PRTL_QUERY_REGISTRY_TABLE QueryTable,
4209     _In_opt_ PVOID Context,
4210     _In_opt_ PVOID Environment
4211 );
4212 
4213 _IRQL_requires_max_(PASSIVE_LEVEL)
4214 NTSYSAPI
4215 NTSTATUS
4216 NTAPI
4217 RtlWriteRegistryValue(
4218     _In_ ULONG RelativeTo,
4219     _In_ PCWSTR Path,
4220     _In_z_ PCWSTR ValueName,
4221     _In_ ULONG ValueType,
4222     _In_reads_bytes_opt_(ValueLength) PVOID ValueData,
4223     _In_ ULONG ValueLength
4224 );
4225 
4226 #ifdef NTOS_MODE_USER
4227 NTSYSAPI
4228 NTSTATUS
4229 NTAPI
4230 RtlpNtCreateKey(
4231     _Out_ HANDLE KeyHandle,
4232     _In_ ACCESS_MASK DesiredAccess,
4233     _In_ POBJECT_ATTRIBUTES ObjectAttributes,
4234     _In_ ULONG TitleIndex,
4235     _In_ PUNICODE_STRING Class,
4236     _Out_ PULONG Disposition
4237 );
4238 
4239 NTSYSAPI
4240 NTSTATUS
4241 NTAPI
4242 RtlpNtEnumerateSubKey(
4243     _In_ HANDLE KeyHandle,
4244     _Inout_ PUNICODE_STRING SubKeyName,
4245     _In_ ULONG Index,
4246     _In_ ULONG Unused
4247 );
4248 
4249 NTSYSAPI
4250 NTSTATUS
4251 NTAPI
4252 RtlpNtMakeTemporaryKey(
4253     _In_ HANDLE KeyHandle
4254 );
4255 
4256 NTSYSAPI
4257 NTSTATUS
4258 NTAPI
4259 RtlpNtOpenKey(
4260     _Out_ HANDLE KeyHandle,
4261     _In_ ACCESS_MASK DesiredAccess,
4262     _In_ POBJECT_ATTRIBUTES ObjectAttributes,
4263     _In_ ULONG Unused
4264 );
4265 
4266 NTSYSAPI
4267 NTSTATUS
4268 NTAPI
4269 RtlpNtQueryValueKey(
4270     _In_ HANDLE KeyHandle,
4271     _Out_opt_ PULONG Type,
4272     _Out_opt_ PVOID Data,
4273     _Inout_opt_ PULONG DataLength,
4274     _In_ ULONG Unused
4275 );
4276 
4277 NTSYSAPI
4278 NTSTATUS
4279 NTAPI
4280 RtlpNtSetValueKey(
4281     _In_ HANDLE KeyHandle,
4282     _In_ ULONG Type,
4283     _In_ PVOID Data,
4284     _In_ ULONG DataLength
4285 );
4286 #endif
4287 
4288 //
4289 // NLS Functions
4290 //
4291 NTSYSAPI
4292 VOID
4293 NTAPI
4294 RtlGetDefaultCodePage(
4295     _Out_ PUSHORT AnsiCodePage,
4296     _Out_ PUSHORT OemCodePage
4297 );
4298 
4299 NTSYSAPI
4300 VOID
4301 NTAPI
4302 RtlInitNlsTables(
4303     _In_ PUSHORT AnsiTableBase,
4304     _In_ PUSHORT OemTableBase,
4305     _In_ PUSHORT CaseTableBase,
4306     _Out_ PNLSTABLEINFO NlsTable
4307 );
4308 
4309 _IRQL_requires_max_(PASSIVE_LEVEL)
4310 NTSYSAPI
4311 VOID
4312 NTAPI
4313 RtlInitCodePageTable(
4314     _In_ PUSHORT TableBase,
4315     _Out_ PCPTABLEINFO CodePageTable
4316 );
4317 
4318 NTSYSAPI
4319 VOID
4320 NTAPI
4321 RtlResetRtlTranslations(
4322     _In_ PNLSTABLEINFO NlsTable);
4323 
4324 #if defined(NTOS_MODE_USER) && !defined(NO_RTL_INLINES)
4325 
4326 //
4327 // Misc conversion functions
4328 //
4329 static __inline
4330 LARGE_INTEGER
4331 NTAPI_INLINE
4332 RtlConvertLongToLargeInteger(
4333     _In_ LONG SignedInteger
4334 )
4335 {
4336     LARGE_INTEGER Result;
4337 
4338     Result.QuadPart = SignedInteger;
4339     return Result;
4340 }
4341 
4342 static __inline
4343 LARGE_INTEGER
4344 NTAPI_INLINE
4345 RtlEnlargedIntegerMultiply(
4346     _In_ LONG Multiplicand,
4347     _In_ LONG Multiplier
4348 )
4349 {
4350     LARGE_INTEGER Product;
4351 
4352     Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
4353     return Product;
4354 }
4355 
4356 static __inline
4357 ULONG
4358 NTAPI_INLINE
4359 RtlEnlargedUnsignedDivide(
4360     _In_ ULARGE_INTEGER Dividend,
4361     _In_ ULONG Divisor,
4362     _In_opt_ PULONG Remainder
4363 )
4364 {
4365     ULONG Quotient;
4366 
4367     Quotient = (ULONG)(Dividend.QuadPart / Divisor);
4368     if (Remainder) {
4369         *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
4370     }
4371 
4372     return Quotient;
4373 }
4374 
4375 static __inline
4376 LARGE_INTEGER
4377 NTAPI_INLINE
4378 RtlEnlargedUnsignedMultiply(
4379     _In_ ULONG Multiplicand,
4380     _In_ ULONG Multiplier
4381 )
4382 {
4383     LARGE_INTEGER Product;
4384 
4385     Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
4386     return Product;
4387 }
4388 
4389 #if defined(_AMD64_) || defined(_IA64_)
4390 static __inline
4391 LARGE_INTEGER
4392 NTAPI_INLINE
4393 RtlExtendedLargeIntegerDivide(
4394     _In_ LARGE_INTEGER Dividend,
4395     _In_ ULONG Divisor,
4396     _Out_opt_ PULONG Remainder)
4397 {
4398   LARGE_INTEGER ret;
4399   ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
4400   if (Remainder)
4401     *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
4402   return ret;
4403 }
4404 
4405 #else
4406 NTSYSAPI
4407 LARGE_INTEGER
4408 NTAPI
4409 RtlExtendedLargeIntegerDivide(
4410     _In_ LARGE_INTEGER Dividend,
4411     _In_ ULONG Divisor,
4412     _Out_opt_ PULONG Remainder
4413 );
4414 
4415 #endif /* defined(_AMD64_) || defined(_IA64_) */
4416 
4417 #endif
4418 
4419 
4420 NTSYSAPI
4421 ULONG
4422 NTAPI
4423 RtlUniform(
4424     _In_ PULONG Seed
4425 );
4426 
4427 NTSYSAPI
4428 ULONG
4429 NTAPI
4430 RtlRandom(
4431     _Inout_ PULONG Seed
4432 );
4433 
4434 NTSYSAPI
4435 ULONG
4436 NTAPI
4437 RtlComputeCrc32(
4438     _In_ ULONG InitialCrc,
4439     _In_ const UCHAR *Buffer,
4440     _In_ ULONG Length
4441 );
4442 
4443 //
4444 // Network Functions
4445 //
4446 NTSYSAPI
4447 PSTR
4448 NTAPI
4449 RtlIpv4AddressToStringA(
4450     _In_ const struct in_addr *Addr,
4451     _Out_writes_(16) PCHAR S
4452 );
4453 
4454 NTSYSAPI
4455 PWSTR
4456 NTAPI
4457 RtlIpv4AddressToStringW(
4458     _In_ const struct in_addr *Addr,
4459     _Out_writes_(16) PWCHAR S
4460 );
4461 
4462 NTSYSAPI
4463 NTSTATUS
4464 NTAPI
4465 RtlIpv4AddressToStringExA(
4466     _In_ const struct in_addr *Address,
4467     _In_ USHORT Port,
4468     _Out_writes_to_(*AddressStringLength, *AddressStringLength) PCHAR AddressString,
4469     _Inout_ PULONG AddressStringLength
4470 );
4471 
4472 NTSTATUS
4473 NTAPI
4474 RtlIpv4AddressToStringExW(
4475     _In_ const struct in_addr *Address,
4476     _In_ USHORT Port,
4477     _Out_writes_to_(*AddressStringLength, *AddressStringLength) PWCHAR AddressString,
4478     _Inout_ PULONG AddressStringLength
4479 );
4480 
4481 NTSYSAPI
4482 NTSTATUS
4483 NTAPI
4484 RtlIpv4StringToAddressA(
4485     _In_ PCSTR String,
4486     _In_ BOOLEAN Strict,
4487     _Out_ PCSTR *Terminator,
4488     _Out_ struct in_addr *Addr
4489 );
4490 
4491 NTSYSAPI
4492 NTSTATUS
4493 NTAPI
4494 RtlIpv4StringToAddressW(
4495     _In_ PCWSTR String,
4496     _In_ BOOLEAN Strict,
4497     _Out_ PCWSTR *Terminator,
4498     _Out_ struct in_addr *Addr
4499 );
4500 
4501 NTSYSAPI
4502 NTSTATUS
4503 NTAPI
4504 RtlIpv4StringToAddressExA(
4505     _In_ PCSTR AddressString,
4506     _In_ BOOLEAN Strict,
4507     _Out_ struct in_addr *Address,
4508     _Out_ PUSHORT Port
4509 );
4510 
4511 NTSYSAPI
4512 NTSTATUS
4513 NTAPI
4514 RtlIpv4StringToAddressExW(
4515     _In_ PCWSTR AddressString,
4516     _In_ BOOLEAN Strict,
4517     _Out_ struct in_addr *Address,
4518     _Out_ PUSHORT Port
4519 );
4520 
4521 NTSYSAPI
4522 PSTR
4523 NTAPI
4524 RtlIpv6AddressToStringA(
4525     _In_ const struct in6_addr *Addr,
4526     _Out_writes_(46) PSTR S
4527 );
4528 
4529 NTSYSAPI
4530 PWSTR
4531 NTAPI
4532 RtlIpv6AddressToStringW(
4533     _In_ const struct in6_addr *Addr,
4534     _Out_writes_(46) PWSTR S
4535 );
4536 
4537 NTSYSAPI
4538 NTSTATUS
4539 NTAPI
4540 RtlIpv6AddressToStringExA(
4541     _In_ const struct in6_addr *Address,
4542     _In_ ULONG ScopeId,
4543     _In_ USHORT Port,
4544     _Out_writes_to_(*AddressStringLength, *AddressStringLength) PSTR AddressString,
4545     _Inout_ PULONG AddressStringLength
4546 );
4547 
4548 NTSYSAPI
4549 NTSTATUS
4550 NTAPI
4551 RtlIpv6AddressToStringExW(
4552     _In_ const struct in6_addr *Address,
4553     _In_ ULONG ScopeId,
4554     _In_ USHORT Port,
4555     _Out_writes_to_(*AddressStringLength, *AddressStringLength) PWCHAR AddressString,
4556     _Inout_ PULONG AddressStringLength
4557 );
4558 
4559 NTSYSAPI
4560 NTSTATUS
4561 NTAPI
4562 RtlIpv6StringToAddressA(
4563     _In_ PCSTR String,
4564     _Out_ PCSTR *Terminator,
4565     _Out_ struct in6_addr *Addr
4566 );
4567 
4568 NTSYSAPI
4569 NTSTATUS
4570 NTAPI
4571 RtlIpv6StringToAddressW(
4572     _In_ PCWSTR String,
4573     _Out_ PCWSTR *Terminator,
4574     _Out_ struct in6_addr *Addr
4575 );
4576 
4577 NTSYSAPI
4578 NTSTATUS
4579 NTAPI
4580 RtlIpv6StringToAddressExA(
4581     _In_ PCSTR AddressString,
4582     _Out_ struct in6_addr *Address,
4583     _Out_ PULONG ScopeId,
4584     _Out_ PUSHORT Port
4585 );
4586 
4587 NTSYSAPI
4588 NTSTATUS
4589 NTAPI
4590 RtlIpv6StringToAddressExW(
4591     _In_ PCWSTR AddressString,
4592     _Out_ struct in6_addr *Address,
4593     _Out_ PULONG ScopeId,
4594     _Out_ PUSHORT Port
4595 );
4596 
4597 
4598 //
4599 // Time Functions
4600 //
4601 NTSYSAPI
4602 BOOLEAN
4603 NTAPI
4604 RtlCutoverTimeToSystemTime(
4605     _In_ PTIME_FIELDS CutoverTimeFields,
4606     _Out_ PLARGE_INTEGER SystemTime,
4607     _In_ PLARGE_INTEGER CurrentTime,
4608     _In_ BOOLEAN ThisYearsCutoverOnly);
4609 
4610 NTSYSAPI
4611 NTSTATUS
4612 NTAPI
4613 RtlQueryTimeZoneInformation(
4614     _Out_ PRTL_TIME_ZONE_INFORMATION TimeZoneInformation);
4615 
4616 NTSYSAPI
4617 VOID
4618 NTAPI
4619 RtlSecondsSince1970ToTime(
4620     _In_ ULONG SecondsSince1970,
4621     _Out_ PLARGE_INTEGER Time
4622 );
4623 
4624 NTSYSAPI
4625 NTSTATUS
4626 NTAPI
4627 RtlSetTimeZoneInformation(
4628     _In_ PRTL_TIME_ZONE_INFORMATION TimeZoneInformation);
4629 
4630 _Success_(return != FALSE)
4631 NTSYSAPI
4632 BOOLEAN
4633 NTAPI
4634 RtlTimeFieldsToTime(
4635     _In_ PTIME_FIELDS TimeFields,
4636     _Out_ PLARGE_INTEGER Time
4637 );
4638 
4639 _Success_(return != FALSE)
4640 NTSYSAPI
4641 BOOLEAN
4642 NTAPI
4643 RtlTimeToSecondsSince1970(
4644     _In_ PLARGE_INTEGER Time,
4645     _Out_ PULONG ElapsedSeconds
4646 );
4647 
4648 NTSYSAPI
4649 VOID
4650 NTAPI
4651 RtlTimeToTimeFields(
4652     PLARGE_INTEGER Time,
4653     PTIME_FIELDS TimeFields
4654 );
4655 
4656 NTSYSAPI
4657 NTSTATUS
4658 NTAPI
4659 RtlSystemTimeToLocalTime(
4660     _In_ PLARGE_INTEGER SystemTime,
4661     _Out_ PLARGE_INTEGER LocalTime
4662 );
4663 
4664 //
4665 // Version Functions
4666 //
4667 _IRQL_requires_max_(PASSIVE_LEVEL)
4668 _Must_inspect_result_
4669 NTSYSAPI
4670 NTSTATUS
4671 NTAPI
4672 RtlVerifyVersionInfo(
4673     _In_ PRTL_OSVERSIONINFOEXW VersionInfo,
4674     _In_ ULONG TypeMask,
4675     _In_ ULONGLONG ConditionMask
4676 );
4677 
4678 _IRQL_requires_max_(PASSIVE_LEVEL)
4679 NTSYSAPI
4680 NTSTATUS
4681 NTAPI
4682 RtlGetVersion(
4683     _Out_
4684     _At_(lpVersionInformation->dwOSVersionInfoSize, _Pre_ _Valid_)
4685     _When_(lpVersionInformation->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW),
4686         _At_((PRTL_OSVERSIONINFOEXW)lpVersionInformation, _Out_))
4687         PRTL_OSVERSIONINFOW lpVersionInformation
4688 );
4689 
4690 _IRQL_requires_max_(PASSIVE_LEVEL)
4691 NTSYSAPI
4692 BOOLEAN
4693 NTAPI
4694 RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType);
4695 
4696 #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
4697 //
4698 // Synchronization functions
4699 //
4700 NTSYSAPI
4701 VOID
4702 NTAPI
4703 RtlInitializeConditionVariable(
4704     _Out_ PRTL_CONDITION_VARIABLE ConditionVariable);
4705 
4706 NTSYSAPI
4707 VOID
4708 NTAPI
4709 RtlWakeConditionVariable(
4710     _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable);
4711 
4712 NTSYSAPI
4713 VOID
4714 NTAPI
4715 RtlWakeAllConditionVariable(
4716     _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable);
4717 
4718 NTSYSAPI
4719 NTSTATUS
4720 NTAPI
4721 RtlSleepConditionVariableCS(
4722     _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable,
4723     _Inout_ PRTL_CRITICAL_SECTION CriticalSection,
4724     _In_opt_ PLARGE_INTEGER TimeOut);
4725 
4726 NTSYSAPI
4727 NTSTATUS
4728 NTAPI
4729 RtlSleepConditionVariableSRW(
4730     _Inout_ PRTL_CONDITION_VARIABLE ConditionVariable,
4731     _Inout_ PRTL_SRWLOCK SRWLock,
4732     _In_opt_ PLARGE_INTEGER TimeOut,
4733     _In_ ULONG Flags);
4734 #endif
4735 
4736 //
4737 // Secure Memory Functions
4738 //
4739 #ifdef NTOS_MODE_USER
4740 NTSYSAPI
4741 NTSTATUS
4742 NTAPI
4743 RtlRegisterSecureMemoryCacheCallback(
4744     _In_ PRTL_SECURE_MEMORY_CACHE_CALLBACK Callback);
4745 
4746 NTSYSAPI
4747 BOOLEAN
4748 NTAPI
4749 RtlFlushSecureMemoryCache(
4750     _In_ PVOID MemoryCache,
4751     _In_opt_ SIZE_T MemoryLength
4752 );
4753 #endif
4754 
4755 //
4756 // Boot Status Data Functions
4757 //
4758 #ifdef NTOS_MODE_USER
4759 NTSYSAPI
4760 NTSTATUS
4761 NTAPI
4762 RtlCreateBootStatusDataFile(
4763     VOID
4764 );
4765 
4766 NTSYSAPI
4767 NTSTATUS
4768 NTAPI
4769 RtlGetSetBootStatusData(
4770     _In_ HANDLE FileHandle,
4771     _In_ BOOLEAN WriteMode,
4772     _In_ RTL_BSD_ITEM_TYPE DataClass,
4773     _In_ PVOID Buffer,
4774     _In_ ULONG BufferSize,
4775     _Out_opt_ PULONG ReturnLength
4776 );
4777 
4778 NTSYSAPI
4779 NTSTATUS
4780 NTAPI
4781 RtlLockBootStatusData(
4782     _Out_ PHANDLE FileHandle
4783 );
4784 
4785 NTSYSAPI
4786 NTSTATUS
4787 NTAPI
4788 RtlUnlockBootStatusData(
4789     _In_ HANDLE FileHandle
4790 );
4791 #endif
4792 
4793 #ifdef NTOS_MODE_USER
4794 _Must_inspect_result_
4795 NTSYSAPI
4796 NTSTATUS
4797 NTAPI
4798 RtlGUIDFromString(
4799     _In_ PUNICODE_STRING GuidString,
4800     _Out_ GUID *Guid);
4801 
4802 _Must_inspect_result_
4803 NTSYSAPI
4804 NTSTATUS
4805 NTAPI
4806 RtlStringFromGUID(
4807   _In_ REFGUID Guid,
4808   _Out_ _At_(GuidString->Buffer, __drv_allocatesMem(Mem))
4809     PUNICODE_STRING GuidString);
4810 
4811 NTSYSAPI
4812 NTSTATUS
4813 NTAPI
4814 RtlComputeImportTableHash(
4815     _In_ HANDLE hFile,
4816     _Out_ PCHAR Hash,
4817     _In_ ULONG ImportTableHashRevision
4818 );
4819 #endif
4820 
4821 //
4822 // MemoryStream functions
4823 //
4824 #ifdef NTOS_MODE_USER
4825 
4826 NTSYSAPI
4827 VOID
4828 NTAPI
4829 RtlInitMemoryStream(
4830     _Out_ PRTL_MEMORY_STREAM Stream
4831 );
4832 
4833 NTSYSAPI
4834 VOID
4835 NTAPI
4836 RtlInitOutOfProcessMemoryStream(
4837     _Out_ PRTL_MEMORY_STREAM Stream
4838 );
4839 
4840 NTSYSAPI
4841 VOID
4842 NTAPI
4843 RtlFinalReleaseOutOfProcessMemoryStream(
4844     _In_ PRTL_MEMORY_STREAM Stream
4845 );
4846 
4847 NTSYSAPI
4848 HRESULT
4849 NTAPI
4850 RtlQueryInterfaceMemoryStream(
4851     _In_ struct IStream *This,
4852     _In_ REFIID RequestedIid,
4853     _Outptr_ PVOID *ResultObject
4854 );
4855 
4856 NTSYSAPI
4857 ULONG
4858 NTAPI
4859 RtlAddRefMemoryStream(
4860     _In_ struct IStream *This
4861 );
4862 
4863 NTSYSAPI
4864 ULONG
4865 NTAPI
4866 RtlReleaseMemoryStream(
4867     _In_ struct IStream *This
4868 );
4869 
4870 NTSYSAPI
4871 HRESULT
4872 NTAPI
4873 RtlReadMemoryStream(
4874     _In_ struct IStream *This,
4875     _Out_writes_bytes_(Length) PVOID Buffer,
4876     _In_ ULONG Length,
4877     _Out_opt_ PULONG BytesRead
4878 );
4879 
4880 NTSYSAPI
4881 HRESULT
4882 NTAPI
4883 RtlReadOutOfProcessMemoryStream(
4884     _In_ struct IStream *This,
4885     _Out_writes_bytes_(Length) PVOID Buffer,
4886     _In_ ULONG Length,
4887     _Out_opt_ PULONG BytesRead
4888 );
4889 
4890 NTSYSAPI
4891 HRESULT
4892 NTAPI
4893 RtlSeekMemoryStream(
4894     _In_ struct IStream *This,
4895     _In_ LARGE_INTEGER RelativeOffset,
4896     _In_ ULONG Origin,
4897     _Out_opt_ PULARGE_INTEGER ResultOffset
4898 );
4899 
4900 NTSYSAPI
4901 HRESULT
4902 NTAPI
4903 RtlCopyMemoryStreamTo(
4904     _In_ struct IStream *This,
4905     _In_ struct IStream *Target,
4906     _In_ ULARGE_INTEGER Length,
4907     _Out_opt_ PULARGE_INTEGER BytesRead,
4908     _Out_opt_ PULARGE_INTEGER BytesWritten
4909 );
4910 
4911 NTSYSAPI
4912 HRESULT
4913 NTAPI
4914 RtlCopyOutOfProcessMemoryStreamTo(
4915     _In_ struct IStream *This,
4916     _In_ struct IStream *Target,
4917     _In_ ULARGE_INTEGER Length,
4918     _Out_opt_ PULARGE_INTEGER BytesRead,
4919     _Out_opt_ PULARGE_INTEGER BytesWritten
4920 );
4921 
4922 NTSYSAPI
4923 HRESULT
4924 NTAPI
4925 RtlStatMemoryStream(
4926     _In_ struct IStream *This,
4927     _Out_ struct tagSTATSTG *Stats,
4928     _In_ ULONG Flags
4929 );
4930 
4931 // Dummy functions
4932 NTSYSAPI
4933 HRESULT
4934 NTAPI
4935 RtlWriteMemoryStream(
4936     _In_ struct IStream *This,
4937     _In_reads_bytes_(Length) CONST VOID *Buffer,
4938     _In_ ULONG Length,
4939     _Out_opt_ PULONG BytesWritten
4940 );
4941 
4942 NTSYSAPI
4943 HRESULT
4944 NTAPI
4945 RtlSetMemoryStreamSize(
4946     _In_ struct IStream *This,
4947     _In_ ULARGE_INTEGER NewSize
4948 );
4949 
4950 NTSYSAPI
4951 HRESULT
4952 NTAPI
4953 RtlCommitMemoryStream(
4954     _In_ struct IStream *This,
4955     _In_ ULONG CommitFlags
4956 );
4957 
4958 NTSYSAPI
4959 HRESULT
4960 NTAPI
4961 RtlRevertMemoryStream(
4962     _In_ struct IStream *This
4963 );
4964 
4965 NTSYSAPI
4966 HRESULT
4967 NTAPI
4968 RtlLockMemoryStreamRegion(
4969     _In_ struct IStream *This,
4970     _In_ ULARGE_INTEGER Offset,
4971     _In_ ULARGE_INTEGER Length,
4972     _In_ ULONG LockType
4973 );
4974 
4975 NTSYSAPI
4976 HRESULT
4977 NTAPI
4978 RtlUnlockMemoryStreamRegion(
4979     _In_ struct IStream *This,
4980     _In_ ULARGE_INTEGER Offset,
4981     _In_ ULARGE_INTEGER Length,
4982     _In_ ULONG LockType
4983 );
4984 
4985 NTSYSAPI
4986 HRESULT
4987 NTAPI
4988 RtlCloneMemoryStream(
4989     _In_ struct IStream *This,
4990     _Outptr_ struct IStream **ResultStream
4991 );
4992 
4993 NTSYSAPI
4994 NTSTATUS
4995 NTAPI
4996 RtlGetNativeSystemInformation(
4997     _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass,
4998     _Out_writes_bytes_to_opt_(SystemInformationLength, *ReturnLength) PVOID SystemInformation,
4999     _In_ ULONG SystemInformationLength,
5000     _Out_opt_ PULONG ReturnLength
5001 );
5002 
5003 #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) || (DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA)
5004 
5005 NTSYSAPI
5006 VOID
5007 NTAPI
5008 RtlRunOnceInitialize(
5009     _Out_ PRTL_RUN_ONCE RunOnce);
5010 
5011 _Maybe_raises_SEH_exception_
5012 NTSYSAPI
5013 NTSTATUS
5014 NTAPI
5015 RtlRunOnceExecuteOnce(
5016     _Inout_ PRTL_RUN_ONCE RunOnce,
5017     _In_ __inner_callback PRTL_RUN_ONCE_INIT_FN InitFn,
5018     _Inout_opt_ PVOID Parameter,
5019     _Outptr_opt_result_maybenull_ PVOID *Context);
5020 
5021 _Must_inspect_result_
5022 NTSYSAPI
5023 NTSTATUS
5024 NTAPI
5025 RtlRunOnceBeginInitialize(
5026     _Inout_ PRTL_RUN_ONCE RunOnce,
5027     _In_ ULONG Flags,
5028     _Outptr_opt_result_maybenull_ PVOID *Context);
5029 
5030 NTSYSAPI
5031 NTSTATUS
5032 NTAPI
5033 RtlRunOnceComplete(
5034     _Inout_ PRTL_RUN_ONCE RunOnce,
5035     _In_ ULONG Flags,
5036     _In_opt_ PVOID Context);
5037 
5038 #endif
5039 
5040 #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) || (defined(__REACTOS__) && defined(_NTDLLBUILD_))
5041 /* Put NTSYSAPI back when this will be really exported. Only statically linked for now */
5042 // NTSYSAPI
5043 VOID
5044 NTAPI
5045 RtlInitializeSRWLock(OUT PRTL_SRWLOCK SRWLock);
5046 
5047 // NTSYSAPI
5048 VOID
5049 NTAPI
5050 RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock);
5051 
5052 // NTSYSAPI
5053 VOID
5054 NTAPI
5055 RtlAcquireSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock);
5056 
5057 // NTSYSAPI
5058 VOID
5059 NTAPI
5060 RtlReleaseSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock);
5061 
5062 // NTSYSAPI
5063 VOID
5064 NTAPI
5065 RtlReleaseSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock);
5066 
5067 #endif /* Win vista or Reactos Ntdll build */
5068 
5069 #if (_WIN32_WINNT >= _WIN32_WINNT_WIN7) || (defined(__REACTOS__) && defined(_NTDLLBUILD_))
5070 
5071 // NTSYSAPI
5072 BOOLEAN
5073 NTAPI
5074 RtlTryAcquireSRWLockShared(PRTL_SRWLOCK SRWLock);
5075 
5076 // NTSYSAPI
5077 BOOLEAN
5078 NTAPI
5079 RtlTryAcquireSRWLockExclusive(PRTL_SRWLOCK SRWLock);
5080 
5081 #endif /* Win7 or Reactos Ntdll build */
5082 
5083 #endif // NTOS_MODE_USER
5084 
5085 NTSYSAPI
5086 NTSTATUS
5087 NTAPI
5088 RtlFindActivationContextSectionGuid(
5089     ULONG flags,
5090     const GUID *extguid,
5091     ULONG section_kind,
5092     const GUID *guid,
5093     void *ptr
5094 );
5095 
5096 #ifdef __cplusplus
5097 }
5098 #endif
5099 
5100 #endif
5101