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