xref: /reactos/sdk/include/xdk/rtlfuncs.h (revision ebaf247c)
1 /******************************************************************************
2  *                         Runtime Library Functions                          *
3  ******************************************************************************/
4 
5 $if (_WDMDDK_)
6 #define FAST_FAIL_LEGACY_GS_VIOLATION           0
7 #define FAST_FAIL_VTGUARD_CHECK_FAILURE         1
8 #define FAST_FAIL_STACK_COOKIE_CHECK_FAILURE    2
9 #define FAST_FAIL_CORRUPT_LIST_ENTRY            3
10 #define FAST_FAIL_INCORRECT_STACK               4
11 #define FAST_FAIL_INVALID_ARG                   5
12 #define FAST_FAIL_GS_COOKIE_INIT                6
13 #define FAST_FAIL_FATAL_APP_EXIT                7
14 #define FAST_FAIL_RANGE_CHECK_FAILURE           8
15 #define FAST_FAIL_UNSAFE_REGISTRY_ACCESS        9
16 #define FAST_FAIL_GUARD_ICALL_CHECK_FAILURE     10
17 #define FAST_FAIL_GUARD_WRITE_CHECK_FAILURE     11
18 #define FAST_FAIL_INVALID_FIBER_SWITCH          12
19 #define FAST_FAIL_INVALID_SET_OF_CONTEXT        13
20 #define FAST_FAIL_INVALID_REFERENCE_COUNT       14
21 #define FAST_FAIL_INVALID_JUMP_BUFFER           18
22 #define FAST_FAIL_MRDATA_MODIFIED               19
23 #define FAST_FAIL_INVALID_FAST_FAIL_CODE        0xFFFFFFFF
24 
25 DECLSPEC_NORETURN
26 FORCEINLINE
27 VOID
28 RtlFailFast(
29   _In_ ULONG Code)
30 {
31   __fastfail(Code);
32 }
33 
34 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS) && (defined(_M_CEE_PURE) || defined(_M_CEE_SAFE))
35 #define NO_KERNEL_LIST_ENTRY_CHECKS
36 #endif
37 
38 #if !defined(EXTRA_KERNEL_LIST_ENTRY_CHECKS) && defined(__REACTOS__)
39 #define EXTRA_KERNEL_LIST_ENTRY_CHECKS
40 #endif
41 
42 #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
43 
44 #define RTL_STATIC_LIST_HEAD(x) LIST_ENTRY x = { &x, &x }
45 
46 FORCEINLINE
47 VOID
48 InitializeListHead(
49   _Out_ PLIST_ENTRY ListHead)
50 {
51   ListHead->Flink = ListHead->Blink = ListHead;
52 }
53 
54 _Must_inspect_result_
55 FORCEINLINE
56 BOOLEAN
57 IsListEmpty(
58   _In_ const LIST_ENTRY * ListHead)
59 {
60   return (BOOLEAN)(ListHead->Flink == ListHead);
61 }
62 
63 FORCEINLINE
64 BOOLEAN
65 RemoveEntryListUnsafe(
66   _In_ PLIST_ENTRY Entry)
67 {
68   PLIST_ENTRY OldFlink;
69   PLIST_ENTRY OldBlink;
70 
71   OldFlink = Entry->Flink;
72   OldBlink = Entry->Blink;
73   OldFlink->Blink = OldBlink;
74   OldBlink->Flink = OldFlink;
75   return (BOOLEAN)(OldFlink == OldBlink);
76 }
77 
78 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS)
79 FORCEINLINE
80 VOID
81 FatalListEntryError(
82   _In_ PVOID P1,
83   _In_ PVOID P2,
84   _In_ PVOID P3)
85 {
86   UNREFERENCED_PARAMETER(P1);
87   UNREFERENCED_PARAMETER(P2);
88   UNREFERENCED_PARAMETER(P3);
89 
90   RtlFailFast(FAST_FAIL_CORRUPT_LIST_ENTRY);
91 }
92 
93 FORCEINLINE
94 VOID
95 RtlpCheckListEntry(
96   _In_ PLIST_ENTRY Entry)
97 {
98   if (Entry->Flink->Blink != Entry || Entry->Blink->Flink != Entry)
99     FatalListEntryError(Entry->Blink, Entry, Entry->Flink);
100 }
101 #endif
102 
103 FORCEINLINE
104 BOOLEAN
105 RemoveEntryList(
106   _In_ PLIST_ENTRY Entry)
107 {
108   PLIST_ENTRY OldFlink;
109   PLIST_ENTRY OldBlink;
110 
111   OldFlink = Entry->Flink;
112   OldBlink = Entry->Blink;
113 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS)
114 #ifdef EXTRA_KERNEL_LIST_ENTRY_CHECKS
115   if (OldFlink == Entry || OldBlink == Entry)
116     FatalListEntryError(OldBlink, Entry, OldFlink);
117 #endif
118   if (OldFlink->Blink != Entry || OldBlink->Flink != Entry)
119     FatalListEntryError(OldBlink, Entry, OldFlink);
120 #endif
121   OldFlink->Blink = OldBlink;
122   OldBlink->Flink = OldFlink;
123   return (BOOLEAN)(OldFlink == OldBlink);
124 }
125 
126 FORCEINLINE
127 PLIST_ENTRY
128 RemoveHeadList(
129   _Inout_ PLIST_ENTRY ListHead)
130 {
131   PLIST_ENTRY Flink;
132   PLIST_ENTRY Entry;
133 
134 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS) && DBG
135   RtlpCheckListEntry(ListHead);
136 #ifdef EXTRA_KERNEL_LIST_ENTRY_CHECKS
137   if (ListHead->Flink == ListHead || ListHead->Blink == ListHead)
138     FatalListEntryError(ListHead->Blink, ListHead, ListHead->Flink);
139 #endif
140 #endif
141   Entry = ListHead->Flink;
142   Flink = Entry->Flink;
143 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS)
144   if (Entry->Blink != ListHead || Flink->Blink != Entry)
145     FatalListEntryError(ListHead, Entry, Flink);
146 #endif
147   ListHead->Flink = Flink;
148   Flink->Blink = ListHead;
149   return Entry;
150 }
151 
152 FORCEINLINE
153 PLIST_ENTRY
154 RemoveTailList(
155   _Inout_ PLIST_ENTRY ListHead)
156 {
157   PLIST_ENTRY Blink;
158   PLIST_ENTRY Entry;
159 
160 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS) && DBG
161   RtlpCheckListEntry(ListHead);
162 #ifdef EXTRA_KERNEL_LIST_ENTRY_CHECKS
163   if (ListHead->Flink == ListHead || ListHead->Blink == ListHead)
164     FatalListEntryError(ListHead->Blink, ListHead, ListHead->Flink);
165 #endif
166 #endif
167   Entry = ListHead->Blink;
168   Blink = Entry->Blink;
169 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS)
170   if (Blink->Flink != Entry || Entry->Flink != ListHead)
171     FatalListEntryError(Blink, Entry, ListHead);
172 #endif
173   ListHead->Blink = Blink;
174   Blink->Flink = ListHead;
175   return Entry;
176 }
177 
178 FORCEINLINE
179 VOID
180 InsertTailList(
181   _Inout_ PLIST_ENTRY ListHead,
182   _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
183 {
184   PLIST_ENTRY OldBlink;
185 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS) && DBG
186   RtlpCheckListEntry(ListHead);
187 #endif
188   OldBlink = ListHead->Blink;
189   Entry->Flink = ListHead;
190   Entry->Blink = OldBlink;
191 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS)
192   if (OldBlink->Flink != ListHead)
193     FatalListEntryError(OldBlink->Blink, OldBlink, ListHead);
194 #endif
195   OldBlink->Flink = Entry;
196   ListHead->Blink = Entry;
197 }
198 
199 FORCEINLINE
200 VOID
201 InsertHeadList(
202   _Inout_ PLIST_ENTRY ListHead,
203   _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
204 {
205   PLIST_ENTRY OldFlink;
206 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS) && DBG
207   RtlpCheckListEntry(ListHead);
208 #endif
209   OldFlink = ListHead->Flink;
210   Entry->Flink = OldFlink;
211   Entry->Blink = ListHead;
212 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS)
213   if (OldFlink->Blink != ListHead)
214     FatalListEntryError(ListHead, OldFlink, OldFlink->Flink);
215 #endif
216   OldFlink->Blink = Entry;
217   ListHead->Flink = Entry;
218 }
219 
220 FORCEINLINE
221 VOID
222 AppendTailList(
223   _Inout_ PLIST_ENTRY ListHead,
224   _Inout_ PLIST_ENTRY ListToAppend)
225 {
226   PLIST_ENTRY ListEnd = ListHead->Blink;
227 
228 #if !defined(NO_KERNEL_LIST_ENTRY_CHECKS)
229   RtlpCheckListEntry(ListHead);
230   RtlpCheckListEntry(ListToAppend);
231 #endif
232   ListHead->Blink->Flink = ListToAppend;
233   ListHead->Blink = ListToAppend->Blink;
234   ListToAppend->Blink->Flink = ListHead;
235   ListToAppend->Blink = ListEnd;
236 }
237 
238 FORCEINLINE
239 PSINGLE_LIST_ENTRY
240 PopEntryList(
241   _Inout_ PSINGLE_LIST_ENTRY ListHead)
242 {
243   PSINGLE_LIST_ENTRY FirstEntry;
244   FirstEntry = ListHead->Next;
245   if (FirstEntry != NULL) {
246     ListHead->Next = FirstEntry->Next;
247   }
248   return FirstEntry;
249 }
250 
251 FORCEINLINE
252 VOID
253 PushEntryList(
254   _Inout_ PSINGLE_LIST_ENTRY ListHead,
255   _Inout_ __drv_aliasesMem PSINGLE_LIST_ENTRY Entry)
256 {
257   Entry->Next = ListHead->Next;
258   ListHead->Next = Entry;
259 }
260 
261 #endif /* !defined(MIDL_PASS) && !defined(SORTPP_PASS) */
262 
263 __analysis_noreturn
264 NTSYSAPI
265 VOID
266 NTAPI
267 RtlAssert(
268   _In_ PVOID FailedAssertion,
269   _In_ PVOID FileName,
270   _In_ ULONG LineNumber,
271   _In_opt_z_ PSTR Message);
272 
273 /* VOID
274  * RtlCopyMemory(
275  *     IN VOID UNALIGNED *Destination,
276  *     IN CONST VOID UNALIGNED *Source,
277  *     IN SIZE_T Length)
278  */
279 #define RtlCopyMemory(Destination, Source, Length) \
280     memcpy(Destination, Source, Length)
281 
282 #define RtlCopyBytes RtlCopyMemory
283 
284 #if defined(_M_AMD64)
285 NTSYSAPI
286 VOID
287 NTAPI
288 RtlCopyMemoryNonTemporal(
289   _Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination,
290   _In_reads_bytes_(Length) const VOID UNALIGNED *Source,
291   _In_ SIZE_T Length);
292 #else
293 #define RtlCopyMemoryNonTemporal RtlCopyMemory
294 #endif
295 
296 /* BOOLEAN
297  * RtlEqualLuid(
298  *     IN PLUID Luid1,
299  *     IN PLUID Luid2)
300  */
301 #define RtlEqualLuid(Luid1, Luid2) \
302     (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
303 
304 /* LOGICAL
305  * RtlEqualMemory(
306  *     IN VOID UNALIGNED *Destination,
307  *     IN CONST VOID UNALIGNED *Source,
308  *     IN SIZE_T Length)
309  */
310 #define RtlEqualMemory(Destination, Source, Length) \
311     (!memcmp(Destination, Source, Length))
312 
313 /* VOID
314  * RtlFillMemory(
315  *     IN VOID UNALIGNED *Destination,
316  *     IN SIZE_T Length,
317  *     IN UCHAR Fill)
318  */
319 #define RtlFillMemory(Destination, Length, Fill) \
320     memset(Destination, Fill, Length)
321 
322 #define RtlFillBytes RtlFillMemory
323 
324 _IRQL_requires_max_(PASSIVE_LEVEL)
325 NTSYSAPI
326 VOID
327 NTAPI
328 RtlFreeUnicodeString(
329   _Inout_ _At_(UnicodeString->Buffer, __drv_freesMem(Mem))
330     PUNICODE_STRING UnicodeString);
331 
332 _IRQL_requires_max_(PASSIVE_LEVEL)
333 _Must_inspect_result_
334 NTSYSAPI
335 NTSTATUS
336 NTAPI
337 RtlGUIDFromString(
338   _In_ PUNICODE_STRING GuidString,
339   _Out_ GUID *Guid);
340 
341 _IRQL_requires_max_(DISPATCH_LEVEL)
342 _At_(DestinationString->Buffer, _Post_equal_to_(SourceString))
343 _When_(SourceString != NULL,
344 _At_(DestinationString->Length, _Post_equal_to_(_String_length_(SourceString) * sizeof(WCHAR)))
345 _At_(DestinationString->MaximumLength, _Post_equal_to_(DestinationString->Length + sizeof(WCHAR))))
346 _When_(SourceString == NULL,
347 _At_(DestinationString->Length, _Post_equal_to_(0))
348 _At_(DestinationString->MaximumLength, _Post_equal_to_(0)))
349 NTSYSAPI
350 VOID
351 NTAPI
352 RtlInitUnicodeString(
353     _Out_ PUNICODE_STRING DestinationString,
354     _In_opt_z_ __drv_aliasesMem PCWSTR SourceString);
355 
356 /* VOID
357  * RtlMoveMemory(
358  *    IN VOID UNALIGNED *Destination,
359  *    IN CONST VOID UNALIGNED *Source,
360  *    IN SIZE_T Length)
361  */
362 #define RtlMoveMemory(Destination, Source, Length) \
363     memmove(Destination, Source, Length)
364 
365 _IRQL_requires_max_(PASSIVE_LEVEL)
366 _Must_inspect_result_
367 NTSYSAPI
368 NTSTATUS
369 NTAPI
370 RtlStringFromGUID(
371   _In_ REFGUID Guid,
372   _Out_ _At_(GuidString->Buffer, __drv_allocatesMem(Mem))
373     PUNICODE_STRING GuidString);
374 
375 /* VOID
376  * RtlZeroMemory(
377  *     IN VOID UNALIGNED *Destination,
378  *     IN SIZE_T Length)
379  */
380 #define RtlZeroMemory(Destination, Length) \
381     memset(Destination, 0, Length)
382 
383 #define RtlZeroBytes RtlZeroMemory
384 $endif (_WDMDDK_)
385 
386 #if (NTDDI_VERSION >= NTDDI_WIN2K)
387 
388 $if (_WDMDDK_)
389 _Must_inspect_result_
390 NTSYSAPI
391 BOOLEAN
392 NTAPI
393 RtlAreBitsClear(
394   _In_ PRTL_BITMAP BitMapHeader,
395   _In_ ULONG StartingIndex,
396   _In_ ULONG Length);
397 
398 _Must_inspect_result_
399 NTSYSAPI
400 BOOLEAN
401 NTAPI
402 RtlAreBitsSet(
403   _In_ PRTL_BITMAP BitMapHeader,
404   _In_ ULONG StartingIndex,
405   _In_ ULONG Length);
406 
407 _IRQL_requires_max_(PASSIVE_LEVEL)
408 _Must_inspect_result_
409 NTSYSAPI
410 NTSTATUS
411 NTAPI
412 RtlAnsiStringToUnicodeString(
413   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
414   _When_(!AllocateDestinationString, _Inout_)
415     PUNICODE_STRING DestinationString,
416   _In_ PANSI_STRING SourceString,
417   _In_ BOOLEAN AllocateDestinationString);
418 
419 _IRQL_requires_max_(PASSIVE_LEVEL)
420 NTSYSAPI
421 ULONG
422 NTAPI
423 RtlxAnsiStringToUnicodeSize(
424   _In_ PCANSI_STRING AnsiString);
425 
426 #define RtlAnsiStringToUnicodeSize(String) (               \
427   NLS_MB_CODE_PAGE_TAG ?                                   \
428   RtlxAnsiStringToUnicodeSize(String) :                    \
429   ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR)   \
430 )
431 
432 _Success_(1)
433 _Unchanged_(Destination->MaximumLength)
434 _Unchanged_(Destination->Buffer)
435 _When_(_Old_(Destination->Length) + Source->Length <= Destination->MaximumLength,
436   _At_(Destination->Length, _Post_equal_to_(_Old_(Destination->Length) + Source->Length))
437   _At_(return, _Out_range_(==, 0)))
438 _When_(_Old_(Destination->Length) + Source->Length > Destination->MaximumLength,
439   _Unchanged_(Destination->Length)
440   _At_(return, _Out_range_(<, 0)))
441 NTSYSAPI
442 NTSTATUS
443 NTAPI
444 RtlAppendUnicodeStringToString(
445   _Inout_ PUNICODE_STRING Destination,
446   _In_ PCUNICODE_STRING Source);
447 
448 _Success_(1)
449 _Unchanged_(Destination->MaximumLength)
450 _Unchanged_(Destination->Buffer)
451 /* _When_(_Old_(Destination->Length) + _String_length_(Source) * sizeof(WCHAR) <= Destination->MaximumLength,
452   _At_(Destination->Length, _Post_equal_to_(_Old_(Destination->Length) + _String_length_(Source) * sizeof(WCHAR)))
453   _At_(return, _Out_range_(==, 0)))
454 _When_(_Old_(Destination->Length) + _String_length_(Source) * sizeof(WCHAR) > Destination->MaximumLength,
455   _Unchanged_(Destination->Length)
456   _At_(return, _Out_range_(<, 0))) */
457 NTSYSAPI
458 NTSTATUS
459 NTAPI
460 RtlAppendUnicodeToString(
461   _Inout_ PUNICODE_STRING Destination,
462   _In_opt_z_ PCWSTR Source);
463 
464 _IRQL_requires_max_(PASSIVE_LEVEL)
465 _Must_inspect_result_
466 NTSYSAPI
467 NTSTATUS
468 NTAPI
469 RtlCheckRegistryKey(
470   _In_ ULONG RelativeTo,
471   _In_ PWSTR Path);
472 
473 NTSYSAPI
474 VOID
475 NTAPI
476 RtlClearAllBits(
477   _In_ PRTL_BITMAP BitMapHeader);
478 
479 NTSYSAPI
480 VOID
481 NTAPI
482 RtlClearBits(
483   _In_ PRTL_BITMAP BitMapHeader,
484   _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToClear) ULONG StartingIndex,
485   _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToClear);
486 
487 _Must_inspect_result_
488 NTSYSAPI
489 SIZE_T
490 NTAPI
491 RtlCompareMemory(
492   _In_ const VOID *Source1,
493   _In_ const VOID *Source2,
494   _In_ SIZE_T Length);
495 
496 _IRQL_requires_max_(PASSIVE_LEVEL)
497 _Must_inspect_result_
498 NTSYSAPI
499 LONG
500 NTAPI
501 RtlCompareUnicodeString(
502   _In_ PCUNICODE_STRING String1,
503   _In_ PCUNICODE_STRING String2,
504   _In_ BOOLEAN CaseInSensitive);
505 
506 _IRQL_requires_max_(PASSIVE_LEVEL)
507 _Must_inspect_result_
508 NTSYSAPI
509 LONG
510 NTAPI
511 RtlCompareUnicodeStrings(
512   _In_reads_(String1Length) PCWCH String1,
513   _In_ SIZE_T String1Length,
514   _In_reads_(String2Length) PCWCH String2,
515   _In_ SIZE_T String2Length,
516   _In_ BOOLEAN CaseInSensitive);
517 
518 _Unchanged_(DestinationString->Buffer)
519 _Unchanged_(DestinationString->MaximumLength)
520 _At_(DestinationString->Length,
521   _When_(SourceString->Length > DestinationString->MaximumLength,
522     _Post_equal_to_(DestinationString->MaximumLength))
523   _When_(SourceString->Length <= DestinationString->MaximumLength,
524     _Post_equal_to_(SourceString->Length)))
525 NTSYSAPI
526 VOID
527 NTAPI
528 RtlCopyUnicodeString(
529   _Inout_ PUNICODE_STRING DestinationString,
530   _In_opt_ PCUNICODE_STRING SourceString);
531 
532 _IRQL_requires_max_(PASSIVE_LEVEL)
533 NTSYSAPI
534 NTSTATUS
535 NTAPI
536 RtlCreateRegistryKey(
537   _In_ ULONG RelativeTo,
538   _In_ PWSTR Path);
539 
540 _IRQL_requires_max_(APC_LEVEL)
541 NTSYSAPI
542 NTSTATUS
543 NTAPI
544 RtlCreateSecurityDescriptor(
545   _Out_ PSECURITY_DESCRIPTOR SecurityDescriptor,
546   _In_ ULONG Revision);
547 
548 _IRQL_requires_max_(PASSIVE_LEVEL)
549 NTSYSAPI
550 NTSTATUS
551 NTAPI
552 RtlDeleteRegistryValue(
553   _In_ ULONG RelativeTo,
554   _In_ PCWSTR Path,
555   _In_z_ PCWSTR ValueName);
556 
557 _IRQL_requires_max_(PASSIVE_LEVEL)
558 _Must_inspect_result_
559 NTSYSAPI
560 BOOLEAN
561 NTAPI
562 RtlEqualUnicodeString(
563   _In_ CONST UNICODE_STRING *String1,
564   _In_ CONST UNICODE_STRING *String2,
565   _In_ BOOLEAN CaseInSensitive);
566 
567 #if !defined(_AMD64_) && !defined(_IA64_)
568 NTSYSAPI
569 LARGE_INTEGER
570 NTAPI
571 RtlExtendedIntegerMultiply(
572   _In_ LARGE_INTEGER Multiplicand,
573   _In_ LONG Multiplier);
574 
575 NTSYSAPI
576 LARGE_INTEGER
577 NTAPI
578 RtlExtendedLargeIntegerDivide(
579   _In_ LARGE_INTEGER Dividend,
580   _In_ ULONG Divisor,
581   _Out_opt_ PULONG Remainder);
582 #endif
583 
584 #if defined(_X86_) || defined(_IA64_)
585 NTSYSAPI
586 LARGE_INTEGER
587 NTAPI
588 RtlExtendedMagicDivide(
589     _In_ LARGE_INTEGER Dividend,
590     _In_ LARGE_INTEGER MagicDivisor,
591     _In_ CCHAR  ShiftCount);
592 #endif
593 
594 _IRQL_requires_max_(PASSIVE_LEVEL)
595 NTSYSAPI
596 VOID
597 NTAPI
598 RtlFreeAnsiString(
599   _Inout_ _At_(AnsiString->Buffer, __drv_freesMem(Mem))
600     PANSI_STRING AnsiString);
601 
602 _Success_(return != -1)
603 _Must_inspect_result_
604 NTSYSAPI
605 ULONG
606 NTAPI
607 RtlFindClearBits(
608   _In_ PRTL_BITMAP BitMapHeader,
609   _In_ ULONG NumberToFind,
610   _In_ ULONG HintIndex);
611 
612 _Success_(return != -1)
613 NTSYSAPI
614 ULONG
615 NTAPI
616 RtlFindClearBitsAndSet(
617   _In_ PRTL_BITMAP BitMapHeader,
618   _In_ ULONG NumberToFind,
619   _In_ ULONG HintIndex);
620 
621 NTSYSAPI
622 ULONG
623 NTAPI
624 RtlFindFirstRunClear(
625   _In_ PRTL_BITMAP BitMapHeader,
626   _Out_ PULONG StartingIndex);
627 
628 NTSYSAPI
629 ULONG
630 NTAPI
631 RtlFindClearRuns(
632   _In_ PRTL_BITMAP BitMapHeader,
633   _Out_writes_to_(SizeOfRunArray, return) PRTL_BITMAP_RUN RunArray,
634   _In_range_(>, 0) ULONG SizeOfRunArray,
635   _In_ BOOLEAN LocateLongestRuns);
636 
637 NTSYSAPI
638 ULONG
639 NTAPI
640 RtlFindLastBackwardRunClear(
641   _In_ PRTL_BITMAP BitMapHeader,
642   _In_ ULONG FromIndex,
643   _Out_ PULONG StartingRunIndex);
644 
645 _Success_(return != -1)
646 _Must_inspect_result_
647 NTSYSAPI
648 CCHAR
649 NTAPI
650 RtlFindLeastSignificantBit(
651   _In_ ULONGLONG Set);
652 
653 NTSYSAPI
654 ULONG
655 NTAPI
656 RtlFindLongestRunClear(
657   _In_ PRTL_BITMAP BitMapHeader,
658   _Out_ PULONG StartingIndex);
659 
660 _Success_(return != -1)
661 _Must_inspect_result_
662 NTSYSAPI
663 CCHAR
664 NTAPI
665 RtlFindMostSignificantBit(
666   _In_ ULONGLONG Set);
667 
668 NTSYSAPI
669 ULONG
670 NTAPI
671 RtlFindNextForwardRunClear(
672   _In_ PRTL_BITMAP BitMapHeader,
673   _In_ ULONG FromIndex,
674   _Out_ PULONG StartingRunIndex);
675 
676 _Success_(return != -1)
677 _Must_inspect_result_
678 NTSYSAPI
679 ULONG
680 NTAPI
681 RtlFindSetBits(
682   _In_ PRTL_BITMAP BitMapHeader,
683   _In_ ULONG NumberToFind,
684   _In_ ULONG HintIndex);
685 
686 _Success_(return != -1)
687 NTSYSAPI
688 ULONG
689 NTAPI
690 RtlFindSetBitsAndClear(
691   _In_ PRTL_BITMAP BitMapHeader,
692   _In_ ULONG NumberToFind,
693   _In_ ULONG HintIndex);
694 
695 _IRQL_requires_max_(DISPATCH_LEVEL)
696 NTSYSAPI
697 VOID
698 NTAPI
699 RtlInitAnsiString(
700   _Out_ PANSI_STRING DestinationString,
701   _In_opt_z_ __drv_aliasesMem PCSZ SourceString);
702 
703 _At_(BitMapHeader->SizeOfBitMap, _Post_equal_to_(SizeOfBitMap))
704 _At_(BitMapHeader->Buffer, _Post_equal_to_(BitMapBuffer))
705 NTSYSAPI
706 VOID
707 NTAPI
708 RtlInitializeBitMap(
709   _Out_ PRTL_BITMAP BitMapHeader,
710   _In_opt_ __drv_aliasesMem PULONG BitMapBuffer,
711   _In_opt_ ULONG SizeOfBitMap);
712 
713 _IRQL_requires_max_(DISPATCH_LEVEL)
714 NTSYSAPI
715 VOID
716 NTAPI
717 RtlInitString(
718   _Out_ PSTRING DestinationString,
719   _In_opt_z_ __drv_aliasesMem PCSZ SourceString);
720 
721 _IRQL_requires_max_(PASSIVE_LEVEL)
722 _At_(String->MaximumLength, _Const_)
723 NTSYSAPI
724 NTSTATUS
725 NTAPI
726 RtlIntegerToUnicodeString(
727   _In_ ULONG Value,
728   _In_opt_ ULONG Base,
729   _Inout_ PUNICODE_STRING String);
730 
731 _IRQL_requires_max_(PASSIVE_LEVEL)
732 _At_(String->MaximumLength, _Const_)
733 NTSYSAPI
734 NTSTATUS
735 NTAPI
736 RtlInt64ToUnicodeString(
737   _In_ ULONGLONG Value,
738   _In_opt_ ULONG Base,
739   _Inout_ PUNICODE_STRING String);
740 
741 #ifdef _WIN64
742 #define RtlIntPtrToUnicodeString(Value, Base, String) \
743     RtlInt64ToUnicodeString(Value, Base, String)
744 #else
745 #define RtlIntPtrToUnicodeString(Value, Base, String) \
746     RtlIntegerToUnicodeString(Value, Base, String)
747 #endif
748 
749 /* BOOLEAN
750  * RtlIsZeroLuid(
751  *     IN PLUID L1);
752  */
753 #define RtlIsZeroLuid(_L1) \
754     ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
755 
756 _IRQL_requires_max_(APC_LEVEL)
757 NTSYSAPI
758 ULONG
759 NTAPI
760 RtlLengthSecurityDescriptor(
761   _In_ PSECURITY_DESCRIPTOR SecurityDescriptor);
762 
763 NTSYSAPI
764 ULONG
765 NTAPI
766 RtlNumberOfClearBits(
767   _In_ PRTL_BITMAP BitMapHeader);
768 
769 NTSYSAPI
770 ULONG
771 NTAPI
772 RtlNumberOfSetBits(
773   _In_ PRTL_BITMAP BitMapHeader);
774 
775 _IRQL_requires_max_(PASSIVE_LEVEL)
776 NTSYSAPI
777 NTSTATUS
778 NTAPI
779 RtlQueryRegistryValues(
780     _In_ ULONG RelativeTo,
781     _In_ PCWSTR Path,
782     _Inout_ _At_(*(*QueryTable).EntryContext, _Pre_unknown_)
783         PRTL_QUERY_REGISTRY_TABLE QueryTable,
784     _In_opt_ PVOID Context,
785     _In_opt_ PVOID Environment);
786 
787 #define SHORT_SIZE  (sizeof(USHORT))
788 #define SHORT_MASK  (SHORT_SIZE - 1)
789 #define LONG_SIZE (sizeof(LONG))
790 #define LONGLONG_SIZE   (sizeof(LONGLONG))
791 #define LONG_MASK (LONG_SIZE - 1)
792 #define LONGLONG_MASK   (LONGLONG_SIZE - 1)
793 #define LOWBYTE_MASK 0x00FF
794 
795 #define FIRSTBYTE(VALUE)  ((VALUE) & LOWBYTE_MASK)
796 #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
797 #define THIRDBYTE(VALUE)  (((VALUE) >> 16) & LOWBYTE_MASK)
798 #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
799 
800 NTSYSAPI
801 VOID
802 NTAPI
803 RtlSetAllBits(
804   _In_ PRTL_BITMAP BitMapHeader);
805 
806 NTSYSAPI
807 VOID
808 NTAPI
809 RtlSetBits(
810   _In_ PRTL_BITMAP BitMapHeader,
811   _In_range_(0, BitMapHeader->SizeOfBitMap - NumberToSet) ULONG StartingIndex,
812   _In_range_(0, BitMapHeader->SizeOfBitMap - StartingIndex) ULONG NumberToSet);
813 
814 _IRQL_requires_max_(APC_LEVEL)
815 NTSYSAPI
816 NTSTATUS
817 NTAPI
818 RtlSetDaclSecurityDescriptor(
819   _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
820   _In_ BOOLEAN DaclPresent,
821   _In_opt_ PACL Dacl,
822   _In_opt_ BOOLEAN DaclDefaulted);
823 
824 #if defined(_AMD64_)
825 
826 /* VOID
827  * RtlStoreUlong(
828  *     IN PULONG Address,
829  *     IN ULONG Value);
830  */
831 #define RtlStoreUlong(Address,Value) \
832     *(ULONG UNALIGNED *)(Address) = (Value)
833 
834 /* VOID
835  * RtlStoreUlonglong(
836  *     IN OUT PULONGLONG Address,
837  *     ULONGLONG Value);
838  */
839 #define RtlStoreUlonglong(Address,Value) \
840     *(ULONGLONG UNALIGNED *)(Address) = (Value)
841 
842 /* VOID
843  * RtlStoreUshort(
844  *     IN PUSHORT Address,
845  *     IN USHORT Value);
846  */
847 #define RtlStoreUshort(Address,Value) \
848     *(USHORT UNALIGNED *)(Address) = (Value)
849 
850 /* VOID
851  * RtlRetrieveUshort(
852  *     PUSHORT DestinationAddress,
853  *    PUSHORT SourceAddress);
854  */
855 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
856     *(USHORT UNALIGNED *)(DestAddress) = *(USHORT)(SrcAddress)
857 
858 /* VOID
859  * RtlRetrieveUlong(
860  *    PULONG DestinationAddress,
861  *    PULONG SourceAddress);
862  */
863 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
864     *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
865 
866 #else
867 
868 #define RtlStoreUlong(Address,Value)                      \
869     if ((ULONG_PTR)(Address) & LONG_MASK) { \
870         ((PUCHAR) (Address))[LONG_LEAST_SIGNIFICANT_BIT]    = (UCHAR)(FIRSTBYTE(Value)); \
871         ((PUCHAR) (Address))[LONG_3RD_MOST_SIGNIFICANT_BIT] = (UCHAR)(SECONDBYTE(Value)); \
872         ((PUCHAR) (Address))[LONG_2ND_MOST_SIGNIFICANT_BIT] = (UCHAR)(THIRDBYTE(Value)); \
873         ((PUCHAR) (Address))[LONG_MOST_SIGNIFICANT_BIT]     = (UCHAR)(FOURTHBYTE(Value)); \
874     } \
875     else { \
876         *((PULONG)(Address)) = (ULONG) (Value); \
877     }
878 
879 #define RtlStoreUlonglong(Address,Value) \
880     if ((ULONG_PTR)(Address) & LONGLONG_MASK) { \
881         RtlStoreUlong((ULONG_PTR)(Address), \
882                       (ULONGLONG)(Value) & 0xFFFFFFFF); \
883         RtlStoreUlong((ULONG_PTR)(Address)+sizeof(ULONG), \
884                       (ULONGLONG)(Value) >> 32); \
885     } else { \
886         *((PULONGLONG)(Address)) = (ULONGLONG)(Value); \
887     }
888 
889 #define RtlStoreUshort(Address,Value) \
890     if ((ULONG_PTR)(Address) & SHORT_MASK) { \
891         ((PUCHAR) (Address))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
892         ((PUCHAR) (Address))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(Value)); \
893     } \
894     else { \
895         *((PUSHORT) (Address)) = (USHORT)Value; \
896     }
897 
898 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
899     if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
900     { \
901         ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
902         ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
903     } \
904     else \
905     { \
906         *((PUSHORT)(DestAddress))=*((PUSHORT)(SrcAddress)); \
907     }
908 
909 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
910     if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
911     { \
912         ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
913         ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
914         ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
915         ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
916     } \
917     else \
918     { \
919         *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
920     }
921 
922 #endif /* defined(_AMD64_) */
923 
924 #ifdef _WIN64
925 /* VOID
926  * RtlStoreUlongPtr(
927  *     IN OUT PULONG_PTR Address,
928  *     IN ULONG_PTR Value);
929  */
930 #define RtlStoreUlongPtr(Address,Value) RtlStoreUlonglong(Address,Value)
931 #else
932 #define RtlStoreUlongPtr(Address,Value) RtlStoreUlong(Address,Value)
933 #endif /* _WIN64 */
934 
935 _Success_(return!=FALSE)
936 _Must_inspect_result_
937 NTSYSAPI
938 BOOLEAN
939 NTAPI
940 RtlTimeFieldsToTime(
941     _In_ PTIME_FIELDS TimeFields,
942     _Out_ PLARGE_INTEGER Time);
943 
944 NTSYSAPI
945 VOID
946 NTAPI
947 RtlTimeToTimeFields(
948   _In_ PLARGE_INTEGER Time,
949   _Out_ PTIME_FIELDS TimeFields);
950 
951 NTSYSAPI
952 USHORT
953 FASTCALL
954 RtlUshortByteSwap(
955   _In_ USHORT Source);
956 
957 NTSYSAPI
958 ULONG
959 FASTCALL
960 RtlUlongByteSwap(
961   _In_ ULONG Source);
962 
963 NTSYSAPI
964 ULONGLONG
965 FASTCALL
966 RtlUlonglongByteSwap(
967   _In_ ULONGLONG Source);
968 
969 _When_(AllocateDestinationString,
970   _At_(DestinationString->MaximumLength,
971     _Out_range_(<=, (SourceString->MaximumLength / sizeof(WCHAR)))))
972 _When_(!AllocateDestinationString,
973   _At_(DestinationString->Buffer, _Const_)
974   _At_(DestinationString->MaximumLength, _Const_))
975 _IRQL_requires_max_(PASSIVE_LEVEL)
976 _When_(AllocateDestinationString, _Must_inspect_result_)
977 NTSYSAPI
978 NTSTATUS
979 NTAPI
980 RtlUnicodeStringToAnsiString(
981   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
982   _When_(!AllocateDestinationString, _Inout_)
983     PANSI_STRING DestinationString,
984   _In_ PCUNICODE_STRING SourceString,
985   _In_ BOOLEAN AllocateDestinationString);
986 
987 _IRQL_requires_max_(PASSIVE_LEVEL)
988 _Must_inspect_result_
989 NTSYSAPI
990 NTSTATUS
991 NTAPI
992 RtlUpcaseUnicodeStringToAnsiString(
993   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
994   _When_(!AllocateDestinationString, _Inout_)
995     PANSI_STRING DestinationString,
996   _In_ PCUNICODE_STRING SourceString,
997   _In_ BOOLEAN AllocateDestinationString);
998 
999 _IRQL_requires_max_(PASSIVE_LEVEL)
1000 NTSYSAPI
1001 ULONG
1002 NTAPI
1003 RtlxUnicodeStringToAnsiSize(
1004   _In_ PCUNICODE_STRING UnicodeString);
1005 
1006 #define RtlUnicodeStringToAnsiSize(String) (                  \
1007     NLS_MB_CODE_PAGE_TAG ?                                    \
1008     RtlxUnicodeStringToAnsiSize(String) :                     \
1009     ((String)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
1010 )
1011 
1012 _IRQL_requires_max_(PASSIVE_LEVEL)
1013 NTSYSAPI
1014 NTSTATUS
1015 NTAPI
1016 RtlUnicodeStringToInteger(
1017   _In_ PCUNICODE_STRING String,
1018   _In_opt_ ULONG Base,
1019   _Out_ PULONG Value);
1020 
1021 _IRQL_requires_max_(PASSIVE_LEVEL)
1022 NTSYSAPI
1023 WCHAR
1024 NTAPI
1025 RtlUpcaseUnicodeChar(
1026   _In_ WCHAR SourceCharacter);
1027 
1028 _IRQL_requires_max_(APC_LEVEL)
1029 _Must_inspect_result_
1030 NTSYSAPI
1031 BOOLEAN
1032 NTAPI
1033 RtlValidRelativeSecurityDescriptor(
1034   _In_reads_bytes_(SecurityDescriptorLength) PSECURITY_DESCRIPTOR SecurityDescriptorInput,
1035   _In_ ULONG SecurityDescriptorLength,
1036   _In_ SECURITY_INFORMATION RequiredInformation);
1037 
1038 _IRQL_requires_max_(APC_LEVEL)
1039 _Must_inspect_result_
1040 NTSYSAPI
1041 BOOLEAN
1042 NTAPI
1043 RtlValidSecurityDescriptor(
1044   _In_ PSECURITY_DESCRIPTOR SecurityDescriptor);
1045 
1046 _IRQL_requires_max_(PASSIVE_LEVEL)
1047 NTSYSAPI
1048 NTSTATUS
1049 NTAPI
1050 RtlGetVersion(
1051     _Out_
1052     _At_(lpVersionInformation->dwOSVersionInfoSize, _Pre_ _Valid_)
1053     _When_(lpVersionInformation->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW),
1054         _At_((PRTL_OSVERSIONINFOEXW)lpVersionInformation, _Out_))
1055         PRTL_OSVERSIONINFOW lpVersionInformation);
1056 
1057 _IRQL_requires_max_(PASSIVE_LEVEL)
1058 _Must_inspect_result_
1059 NTSYSAPI
1060 NTSTATUS
1061 NTAPI
1062 RtlVerifyVersionInfo(
1063     _In_ PRTL_OSVERSIONINFOEXW VersionInfo,
1064     _In_ ULONG TypeMask,
1065     _In_ ULONGLONG ConditionMask);
1066 
1067 _IRQL_requires_max_(PASSIVE_LEVEL)
1068 NTSYSAPI
1069 NTSTATUS
1070 NTAPI
1071 RtlWriteRegistryValue(
1072   _In_ ULONG RelativeTo,
1073   _In_ PCWSTR Path,
1074   _In_z_ PCWSTR ValueName,
1075   _In_ ULONG ValueType,
1076   _In_reads_bytes_opt_(ValueLength) PVOID ValueData,
1077   _In_ ULONG ValueLength);
1078 
1079 $endif (_WDMDDK_)
1080 $if (_NTDDK_)
1081 
1082 #ifndef RTL_USE_AVL_TABLES
1083 
1084 NTSYSAPI
1085 VOID
1086 NTAPI
1087 RtlInitializeGenericTable(
1088   _Out_ PRTL_GENERIC_TABLE Table,
1089   _In_ PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine,
1090   _In_ PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine,
1091   _In_ PRTL_GENERIC_FREE_ROUTINE FreeRoutine,
1092   _In_opt_ PVOID TableContext);
1093 
1094 NTSYSAPI
1095 PVOID
1096 NTAPI
1097 RtlInsertElementGenericTable(
1098   _In_ PRTL_GENERIC_TABLE Table,
1099   _In_reads_bytes_(BufferSize) PVOID Buffer,
1100   _In_ CLONG BufferSize,
1101   _Out_opt_ PBOOLEAN NewElement);
1102 
1103 NTSYSAPI
1104 PVOID
1105 NTAPI
1106 RtlInsertElementGenericTableFull(
1107   _In_ PRTL_GENERIC_TABLE Table,
1108   _In_reads_bytes_(BufferSize) PVOID Buffer,
1109   _In_ CLONG BufferSize,
1110   _Out_opt_ PBOOLEAN NewElement,
1111   _In_ PVOID NodeOrParent,
1112   _In_ TABLE_SEARCH_RESULT SearchResult);
1113 
1114 NTSYSAPI
1115 BOOLEAN
1116 NTAPI
1117 RtlDeleteElementGenericTable(
1118   _In_ PRTL_GENERIC_TABLE Table,
1119   _In_ PVOID Buffer);
1120 
1121 _Must_inspect_result_
1122 NTSYSAPI
1123 PVOID
1124 NTAPI
1125 RtlLookupElementGenericTable(
1126   _In_ PRTL_GENERIC_TABLE Table,
1127   _In_ PVOID Buffer);
1128 
1129 NTSYSAPI
1130 PVOID
1131 NTAPI
1132 RtlLookupElementGenericTableFull(
1133   _In_ PRTL_GENERIC_TABLE Table,
1134   _In_ PVOID Buffer,
1135   _Out_ PVOID *NodeOrParent,
1136   _Out_ TABLE_SEARCH_RESULT *SearchResult);
1137 
1138 _Must_inspect_result_
1139 NTSYSAPI
1140 PVOID
1141 NTAPI
1142 RtlEnumerateGenericTable(
1143   _In_ PRTL_GENERIC_TABLE Table,
1144   _In_ BOOLEAN Restart);
1145 
1146 _Must_inspect_result_
1147 NTSYSAPI
1148 PVOID
1149 NTAPI
1150 RtlEnumerateGenericTableWithoutSplaying(
1151   _In_ PRTL_GENERIC_TABLE Table,
1152   _Inout_ PVOID *RestartKey);
1153 
1154 _Must_inspect_result_
1155 NTSYSAPI
1156 PVOID
1157 NTAPI
1158 RtlGetElementGenericTable(
1159   _In_ PRTL_GENERIC_TABLE Table,
1160   _In_ ULONG I);
1161 
1162 NTSYSAPI
1163 ULONG
1164 NTAPI
1165 RtlNumberGenericTableElements(
1166   _In_ PRTL_GENERIC_TABLE Table);
1167 
1168 _Must_inspect_result_
1169 NTSYSAPI
1170 BOOLEAN
1171 NTAPI
1172 RtlIsGenericTableEmpty(
1173   _In_ PRTL_GENERIC_TABLE Table);
1174 
1175 #endif /* !RTL_USE_AVL_TABLES */
1176 
1177 #define RTL_STACK_WALKING_MODE_FRAMES_TO_SKIP_SHIFT     8
1178 
1179 NTSYSAPI
1180 PRTL_SPLAY_LINKS
1181 NTAPI
1182 RtlSplay(
1183   _Inout_ PRTL_SPLAY_LINKS Links);
1184 
1185 NTSYSAPI
1186 PRTL_SPLAY_LINKS
1187 NTAPI
1188 RtlDelete(
1189   _In_ PRTL_SPLAY_LINKS Links);
1190 
1191 NTSYSAPI
1192 VOID
1193 NTAPI
1194 RtlDeleteNoSplay(
1195   _In_ PRTL_SPLAY_LINKS Links,
1196   _Inout_ PRTL_SPLAY_LINKS *Root);
1197 
1198 _Must_inspect_result_
1199 NTSYSAPI
1200 PRTL_SPLAY_LINKS
1201 NTAPI
1202 RtlSubtreeSuccessor(
1203   _In_ PRTL_SPLAY_LINKS Links);
1204 
1205 _Must_inspect_result_
1206 NTSYSAPI
1207 PRTL_SPLAY_LINKS
1208 NTAPI
1209 RtlSubtreePredecessor(
1210   _In_ PRTL_SPLAY_LINKS Links);
1211 
1212 _Must_inspect_result_
1213 NTSYSAPI
1214 PRTL_SPLAY_LINKS
1215 NTAPI
1216 RtlRealSuccessor(
1217   _In_ PRTL_SPLAY_LINKS Links);
1218 
1219 _Must_inspect_result_
1220 NTSYSAPI
1221 PRTL_SPLAY_LINKS
1222 NTAPI
1223 RtlRealPredecessor(
1224   _In_ PRTL_SPLAY_LINKS Links);
1225 
1226 _IRQL_requires_max_(PASSIVE_LEVEL)
1227 _Must_inspect_result_
1228 NTSYSAPI
1229 BOOLEAN
1230 NTAPI
1231 RtlPrefixUnicodeString(
1232   _In_ PCUNICODE_STRING String1,
1233   _In_ PCUNICODE_STRING String2,
1234   _In_ BOOLEAN CaseInSensitive);
1235 
1236 _IRQL_requires_max_(PASSIVE_LEVEL)
1237 NTSYSAPI
1238 VOID
1239 NTAPI
1240 RtlUpperString(
1241   _Inout_ PSTRING DestinationString,
1242   _In_ const STRING *SourceString);
1243 
1244 _IRQL_requires_max_(PASSIVE_LEVEL)
1245 _When_(AllocateDestinationString, _Must_inspect_result_)
1246 NTSYSAPI
1247 NTSTATUS
1248 NTAPI
1249 RtlUpcaseUnicodeString(
1250   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1251   _When_(!AllocateDestinationString, _Inout_)
1252     PUNICODE_STRING DestinationString,
1253   _In_ PCUNICODE_STRING SourceString,
1254   _In_ BOOLEAN AllocateDestinationString);
1255 
1256 _IRQL_requires_max_(APC_LEVEL)
1257 NTSYSAPI
1258 VOID
1259 NTAPI
1260 RtlMapGenericMask(
1261   _Inout_ PACCESS_MASK AccessMask,
1262   _In_ PGENERIC_MAPPING GenericMapping);
1263 
1264 _IRQL_requires_max_(PASSIVE_LEVEL)
1265 NTSYSAPI
1266 NTSTATUS
1267 NTAPI
1268 RtlVolumeDeviceToDosName(
1269   _In_ PVOID VolumeDeviceObject,
1270   _Out_ PUNICODE_STRING DosName);
1271 
1272 _IRQL_requires_max_(PASSIVE_LEVEL)
1273 _Must_inspect_result_
1274 NTSYSAPI
1275 LONG
1276 NTAPI
1277 RtlCompareString(
1278   _In_ const STRING *String1,
1279   _In_ const STRING *String2,
1280   _In_ BOOLEAN CaseInSensitive);
1281 
1282 NTSYSAPI
1283 VOID
1284 NTAPI
1285 RtlCopyString(
1286   _Out_ PSTRING DestinationString,
1287   _In_opt_ const STRING *SourceString);
1288 
1289 _IRQL_requires_max_(PASSIVE_LEVEL)
1290 _Must_inspect_result_
1291 NTSYSAPI
1292 BOOLEAN
1293 NTAPI
1294 RtlEqualString(
1295   _In_ const STRING *String1,
1296   _In_ const STRING *String2,
1297   _In_ BOOLEAN CaseInSensitive);
1298 
1299 _IRQL_requires_max_(PASSIVE_LEVEL)
1300 NTSYSAPI
1301 NTSTATUS
1302 NTAPI
1303 RtlCharToInteger(
1304   _In_z_ PCSZ String,
1305   _In_opt_ ULONG Base,
1306   _Out_ PULONG Value);
1307 
1308 _IRQL_requires_max_(PASSIVE_LEVEL)
1309 NTSYSAPI
1310 CHAR
1311 NTAPI
1312 RtlUpperChar(
1313   _In_ CHAR Character);
1314 
1315 NTSYSAPI
1316 ULONG
1317 NTAPI
1318 RtlWalkFrameChain(
1319   _Out_writes_(Count - (Flags >> RTL_STACK_WALKING_MODE_FRAMES_TO_SKIP_SHIFT))
1320     PVOID *Callers,
1321   _In_ ULONG Count,
1322   _In_ ULONG Flags);
1323 
1324 $endif (_NTDDK_)
1325 $if (_NTIFS_)
1326 
1327 _Must_inspect_result_
1328 _Ret_maybenull_
1329 _Post_writable_byte_size_(Size)
1330 NTSYSAPI
1331 PVOID
1332 NTAPI
1333 RtlAllocateHeap(
1334   _In_ HANDLE HeapHandle,
1335   _In_opt_ ULONG Flags,
1336   _In_ SIZE_T Size);
1337 
1338 _Success_(return != 0)
1339 NTSYSAPI
1340 BOOLEAN
1341 NTAPI
1342 RtlFreeHeap(
1343   _In_ PVOID HeapHandle,
1344   _In_opt_ ULONG Flags,
1345   _In_ _Post_invalid_ PVOID BaseAddress);
1346 
1347 NTSYSAPI
1348 VOID
1349 NTAPI
1350 RtlCaptureContext(
1351   _Out_ PCONTEXT ContextRecord);
1352 
1353 _Ret_range_(<, MAXLONG)
1354 NTSYSAPI
1355 ULONG
1356 NTAPI
1357 RtlRandom(
1358   _Inout_ PULONG Seed);
1359 
1360 _IRQL_requires_max_(APC_LEVEL)
1361 _Success_(return != 0)
1362 _Must_inspect_result_
1363 NTSYSAPI
1364 BOOLEAN
1365 NTAPI
1366 RtlCreateUnicodeString(
1367   _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem))
1368     PUNICODE_STRING DestinationString,
1369   _In_z_ PCWSTR SourceString);
1370 
1371 _IRQL_requires_max_(PASSIVE_LEVEL)
1372 _Must_inspect_result_
1373 NTSYSAPI
1374 BOOLEAN
1375 NTAPI
1376 RtlPrefixString(
1377   _In_ const STRING *String1,
1378   _In_ const STRING *String2,
1379   _In_ BOOLEAN CaseInsensitive);
1380 
1381 _IRQL_requires_max_(APC_LEVEL)
1382 NTSYSAPI
1383 NTSTATUS
1384 NTAPI
1385 RtlAppendStringToString(
1386   _Inout_ PSTRING Destination,
1387   _In_ const STRING *Source);
1388 
1389 _IRQL_requires_max_(PASSIVE_LEVEL)
1390 _Must_inspect_result_
1391 NTSYSAPI
1392 NTSTATUS
1393 NTAPI
1394 RtlOemStringToUnicodeString(
1395   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1396   _When_(!AllocateDestinationString, _Inout_)
1397     PUNICODE_STRING DestinationString,
1398   _In_ PCOEM_STRING SourceString,
1399   _In_ BOOLEAN AllocateDestinationString);
1400 
1401 _IRQL_requires_max_(PASSIVE_LEVEL)
1402 _Must_inspect_result_
1403 NTSYSAPI
1404 NTSTATUS
1405 NTAPI
1406 RtlUnicodeStringToOemString(
1407   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1408   _When_(!AllocateDestinationString, _Inout_)
1409     POEM_STRING DestinationString,
1410   _In_ PCUNICODE_STRING SourceString,
1411   _In_ BOOLEAN AllocateDestinationString);
1412 
1413 _IRQL_requires_max_(PASSIVE_LEVEL)
1414 _Must_inspect_result_
1415 NTSYSAPI
1416 NTSTATUS
1417 NTAPI
1418 RtlUpcaseUnicodeStringToOemString(
1419   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1420   _When_(!AllocateDestinationString, _Inout_)
1421     POEM_STRING DestinationString,
1422   _In_ PCUNICODE_STRING SourceString,
1423   _In_ BOOLEAN AllocateDestinationString);
1424 
1425 _IRQL_requires_max_(PASSIVE_LEVEL)
1426 _Must_inspect_result_
1427 NTSYSAPI
1428 NTSTATUS
1429 NTAPI
1430 RtlOemStringToCountedUnicodeString(
1431   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1432   _When_(!AllocateDestinationString, _Inout_)
1433     PUNICODE_STRING DestinationString,
1434   _In_ PCOEM_STRING SourceString,
1435   _In_ BOOLEAN AllocateDestinationString);
1436 
1437 _IRQL_requires_max_(PASSIVE_LEVEL)
1438 _Must_inspect_result_
1439 NTSYSAPI
1440 NTSTATUS
1441 NTAPI
1442 RtlUnicodeStringToCountedOemString(
1443   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1444   _When_(!AllocateDestinationString, _Inout_)
1445     POEM_STRING DestinationString,
1446   _In_ PCUNICODE_STRING SourceString,
1447   _In_ BOOLEAN AllocateDestinationString);
1448 
1449 _IRQL_requires_max_(PASSIVE_LEVEL)
1450 _Must_inspect_result_
1451 NTSYSAPI
1452 NTSTATUS
1453 NTAPI
1454 RtlUpcaseUnicodeStringToCountedOemString(
1455   _When_(AllocateDestinationString, _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)))
1456   _When_(!AllocateDestinationString, _Inout_)
1457     POEM_STRING DestinationString,
1458   _In_ PCUNICODE_STRING SourceString,
1459   _In_ BOOLEAN AllocateDestinationString);
1460 
1461 _IRQL_requires_max_(PASSIVE_LEVEL)
1462 _When_(AllocateDestinationString, _Must_inspect_result_)
1463 NTSYSAPI
1464 NTSTATUS
1465 NTAPI
1466 RtlDowncaseUnicodeString(
1467   _When_(AllocateDestinationString, _Out_ _At_(UniDest->Buffer, __drv_allocatesMem(Mem)))
1468   _When_(!AllocateDestinationString, _Inout_)
1469     PUNICODE_STRING UniDest,
1470   _In_ PCUNICODE_STRING UniSource,
1471   _In_ BOOLEAN AllocateDestinationString);
1472 
1473 _IRQL_requires_max_(PASSIVE_LEVEL)
1474 NTSYSAPI
1475 VOID
1476 NTAPI
1477 RtlFreeOemString(
1478   _Inout_ _At_(OemString->Buffer, __drv_freesMem(Mem)) POEM_STRING OemString);
1479 
1480 _IRQL_requires_max_(PASSIVE_LEVEL)
1481 NTSYSAPI
1482 ULONG
1483 NTAPI
1484 RtlxUnicodeStringToOemSize(
1485   _In_ PCUNICODE_STRING UnicodeString);
1486 
1487 _IRQL_requires_max_(PASSIVE_LEVEL)
1488 NTSYSAPI
1489 ULONG
1490 NTAPI
1491 RtlxOemStringToUnicodeSize(
1492   _In_ PCOEM_STRING OemString);
1493 
1494 _IRQL_requires_max_(PASSIVE_LEVEL)
1495 NTSYSAPI
1496 NTSTATUS
1497 NTAPI
1498 RtlMultiByteToUnicodeN(
1499   _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWCH UnicodeString,
1500   _In_ ULONG MaxBytesInUnicodeString,
1501   _Out_opt_ PULONG BytesInUnicodeString,
1502   _In_reads_bytes_(BytesInMultiByteString) const CHAR *MultiByteString,
1503   _In_ ULONG BytesInMultiByteString);
1504 
1505 _IRQL_requires_max_(PASSIVE_LEVEL)
1506 NTSYSAPI
1507 NTSTATUS
1508 NTAPI
1509 RtlMultiByteToUnicodeSize(
1510   _Out_ PULONG BytesInUnicodeString,
1511   _In_reads_bytes_(BytesInMultiByteString) const CHAR *MultiByteString,
1512   _In_ ULONG BytesInMultiByteString);
1513 
1514 _IRQL_requires_max_(PASSIVE_LEVEL)
1515 NTSYSAPI
1516 NTSTATUS
1517 NTAPI
1518 RtlUnicodeToMultiByteSize(
1519   _Out_ PULONG BytesInMultiByteString,
1520   _In_reads_bytes_(BytesInUnicodeString) PCWCH UnicodeString,
1521   _In_ ULONG BytesInUnicodeString);
1522 
1523 _IRQL_requires_max_(PASSIVE_LEVEL)
1524 NTSYSAPI
1525 NTSTATUS
1526 NTAPI
1527 RtlUnicodeToMultiByteN(
1528   _Out_writes_bytes_to_(MaxBytesInMultiByteString, *BytesInMultiByteString) PCHAR MultiByteString,
1529   _In_ ULONG MaxBytesInMultiByteString,
1530   _Out_opt_ PULONG BytesInMultiByteString,
1531   _In_reads_bytes_(BytesInUnicodeString) PCWCH UnicodeString,
1532   _In_ ULONG BytesInUnicodeString);
1533 
1534 _IRQL_requires_max_(PASSIVE_LEVEL)
1535 NTSYSAPI
1536 NTSTATUS
1537 NTAPI
1538 RtlUpcaseUnicodeToMultiByteN(
1539   _Out_writes_bytes_to_(MaxBytesInMultiByteString, *BytesInMultiByteString) PCHAR MultiByteString,
1540   _In_ ULONG MaxBytesInMultiByteString,
1541   _Out_opt_ PULONG BytesInMultiByteString,
1542   _In_reads_bytes_(BytesInUnicodeString) PCWCH UnicodeString,
1543   _In_ ULONG BytesInUnicodeString);
1544 
1545 _IRQL_requires_max_(PASSIVE_LEVEL)
1546 NTSYSAPI
1547 NTSTATUS
1548 NTAPI
1549 RtlOemToUnicodeN(
1550   _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWSTR UnicodeString,
1551   _In_ ULONG MaxBytesInUnicodeString,
1552   _Out_opt_ PULONG BytesInUnicodeString,
1553   _In_reads_bytes_(BytesInOemString) PCCH OemString,
1554   _In_ ULONG BytesInOemString);
1555 
1556 _IRQL_requires_max_(PASSIVE_LEVEL)
1557 NTSYSAPI
1558 NTSTATUS
1559 NTAPI
1560 RtlUnicodeToOemN(
1561   _Out_writes_bytes_to_(MaxBytesInOemString, *BytesInOemString) PCHAR OemString,
1562   _In_ ULONG MaxBytesInOemString,
1563   _Out_opt_ PULONG BytesInOemString,
1564   _In_reads_bytes_(BytesInUnicodeString) PCWCH UnicodeString,
1565   _In_ ULONG BytesInUnicodeString);
1566 
1567 _IRQL_requires_max_(PASSIVE_LEVEL)
1568 NTSYSAPI
1569 NTSTATUS
1570 NTAPI
1571 RtlUpcaseUnicodeToOemN(
1572   _Out_writes_bytes_to_(MaxBytesInOemString, *BytesInOemString) PCHAR OemString,
1573   _In_ ULONG MaxBytesInOemString,
1574   _Out_opt_ PULONG BytesInOemString,
1575   _In_reads_bytes_(BytesInUnicodeString) PCWCH UnicodeString,
1576   _In_ ULONG BytesInUnicodeString);
1577 
1578 #if (NTDDI_VERSION >= NTDDI_VISTASP1)
1579 _IRQL_requires_max_(PASSIVE_LEVEL)
1580 NTSYSAPI
1581 NTSTATUS
1582 NTAPI
1583 RtlGenerate8dot3Name(
1584   _In_ PCUNICODE_STRING Name,
1585   _In_ BOOLEAN AllowExtendedCharacters,
1586   _Inout_ PGENERATE_NAME_CONTEXT Context,
1587   _Inout_ PUNICODE_STRING Name8dot3);
1588 #else
1589 _IRQL_requires_max_(PASSIVE_LEVEL)
1590 NTSYSAPI
1591 VOID
1592 NTAPI
1593 RtlGenerate8dot3Name(
1594   _In_ PCUNICODE_STRING Name,
1595   _In_ BOOLEAN AllowExtendedCharacters,
1596   _Inout_ PGENERATE_NAME_CONTEXT Context,
1597   _Inout_ PUNICODE_STRING Name8dot3);
1598 #endif
1599 
1600 _IRQL_requires_max_(PASSIVE_LEVEL)
1601 _Must_inspect_result_
1602 NTSYSAPI
1603 BOOLEAN
1604 NTAPI
1605 RtlIsNameLegalDOS8Dot3(
1606   _In_ PCUNICODE_STRING Name,
1607   _Inout_opt_ POEM_STRING OemName,
1608   _Out_opt_ PBOOLEAN NameContainsSpaces);
1609 
1610 _IRQL_requires_max_(PASSIVE_LEVEL)
1611 _Must_inspect_result_
1612 NTSYSAPI
1613 BOOLEAN
1614 NTAPI
1615 RtlIsValidOemCharacter(
1616   _Inout_ PWCHAR Char);
1617 
1618 _IRQL_requires_max_(PASSIVE_LEVEL)
1619 NTSYSAPI
1620 VOID
1621 NTAPI
1622 PfxInitialize(
1623   _Out_ PPREFIX_TABLE PrefixTable);
1624 
1625 _IRQL_requires_max_(PASSIVE_LEVEL)
1626 NTSYSAPI
1627 BOOLEAN
1628 NTAPI
1629 PfxInsertPrefix(
1630   _In_ PPREFIX_TABLE PrefixTable,
1631   _In_ __drv_aliasesMem PSTRING Prefix,
1632   _Out_ PPREFIX_TABLE_ENTRY PrefixTableEntry);
1633 
1634 _IRQL_requires_max_(PASSIVE_LEVEL)
1635 NTSYSAPI
1636 VOID
1637 NTAPI
1638 PfxRemovePrefix(
1639   _In_ PPREFIX_TABLE PrefixTable,
1640   _In_ PPREFIX_TABLE_ENTRY PrefixTableEntry);
1641 
1642 _IRQL_requires_max_(PASSIVE_LEVEL)
1643 _Must_inspect_result_
1644 NTSYSAPI
1645 PPREFIX_TABLE_ENTRY
1646 NTAPI
1647 PfxFindPrefix(
1648   _In_ PPREFIX_TABLE PrefixTable,
1649   _In_ PSTRING FullName);
1650 
1651 _IRQL_requires_max_(PASSIVE_LEVEL)
1652 NTSYSAPI
1653 VOID
1654 NTAPI
1655 RtlInitializeUnicodePrefix(
1656   _Out_ PUNICODE_PREFIX_TABLE PrefixTable);
1657 
1658 _IRQL_requires_max_(PASSIVE_LEVEL)
1659 NTSYSAPI
1660 BOOLEAN
1661 NTAPI
1662 RtlInsertUnicodePrefix(
1663   _In_ PUNICODE_PREFIX_TABLE PrefixTable,
1664   _In_ __drv_aliasesMem PUNICODE_STRING Prefix,
1665   _Out_ PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry);
1666 
1667 _IRQL_requires_max_(PASSIVE_LEVEL)
1668 NTSYSAPI
1669 VOID
1670 NTAPI
1671 RtlRemoveUnicodePrefix(
1672   _In_ PUNICODE_PREFIX_TABLE PrefixTable,
1673   _In_ PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry);
1674 
1675 _IRQL_requires_max_(PASSIVE_LEVEL)
1676 _Must_inspect_result_
1677 NTSYSAPI
1678 PUNICODE_PREFIX_TABLE_ENTRY
1679 NTAPI
1680 RtlFindUnicodePrefix(
1681   _In_ PUNICODE_PREFIX_TABLE PrefixTable,
1682   _In_ PUNICODE_STRING FullName,
1683   _In_ ULONG CaseInsensitiveIndex);
1684 
1685 _IRQL_requires_max_(PASSIVE_LEVEL)
1686 _Must_inspect_result_
1687 NTSYSAPI
1688 PUNICODE_PREFIX_TABLE_ENTRY
1689 NTAPI
1690 RtlNextUnicodePrefix(
1691   _In_ PUNICODE_PREFIX_TABLE PrefixTable,
1692   _In_ BOOLEAN Restart);
1693 
1694 _Must_inspect_result_
1695 NTSYSAPI
1696 SIZE_T
1697 NTAPI
1698 RtlCompareMemoryUlong(
1699   _In_reads_bytes_(Length) PVOID Source,
1700   _In_ SIZE_T Length,
1701   _In_ ULONG Pattern);
1702 
1703 _Success_(return != 0)
1704 NTSYSAPI
1705 BOOLEAN
1706 NTAPI
1707 RtlTimeToSecondsSince1980(
1708   _In_ PLARGE_INTEGER Time,
1709   _Out_ PULONG ElapsedSeconds);
1710 
1711 NTSYSAPI
1712 VOID
1713 NTAPI
1714 RtlSecondsSince1980ToTime(
1715   _In_ ULONG ElapsedSeconds,
1716   _Out_ PLARGE_INTEGER Time);
1717 
1718 _Success_(return != 0)
1719 _Must_inspect_result_
1720 NTSYSAPI
1721 BOOLEAN
1722 NTAPI
1723 RtlTimeToSecondsSince1970(
1724     _In_ PLARGE_INTEGER Time,
1725     _Out_ PULONG ElapsedSeconds);
1726 
1727 NTSYSAPI
1728 VOID
1729 NTAPI
1730 RtlSecondsSince1970ToTime(
1731   _In_ ULONG ElapsedSeconds,
1732   _Out_ PLARGE_INTEGER Time);
1733 
1734 _IRQL_requires_max_(APC_LEVEL)
1735 _Must_inspect_result_
1736 NTSYSAPI
1737 BOOLEAN
1738 NTAPI
1739 RtlValidSid(
1740   _In_ PSID Sid);
1741 
1742 _Must_inspect_result_
1743 NTSYSAPI
1744 BOOLEAN
1745 NTAPI
1746 RtlEqualSid(
1747   _In_ PSID Sid1,
1748   _In_ PSID Sid2);
1749 
1750 _IRQL_requires_max_(APC_LEVEL)
1751 _Must_inspect_result_
1752 NTSYSAPI
1753 BOOLEAN
1754 NTAPI
1755 RtlEqualPrefixSid(
1756   _In_ PSID Sid1,
1757   _In_ PSID Sid2);
1758 
1759 _IRQL_requires_max_(APC_LEVEL)
1760 NTSYSAPI
1761 ULONG
1762 NTAPI
1763 RtlLengthRequiredSid(
1764   _In_ ULONG SubAuthorityCount);
1765 
1766 NTSYSAPI
1767 PVOID
1768 NTAPI
1769 RtlFreeSid(
1770   _In_ _Post_invalid_ PSID Sid);
1771 
1772 _Must_inspect_result_
1773 NTSYSAPI
1774 NTSTATUS
1775 NTAPI
1776 RtlAllocateAndInitializeSid(
1777   _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
1778   _In_ UCHAR SubAuthorityCount,
1779   _In_ ULONG SubAuthority0,
1780   _In_ ULONG SubAuthority1,
1781   _In_ ULONG SubAuthority2,
1782   _In_ ULONG SubAuthority3,
1783   _In_ ULONG SubAuthority4,
1784   _In_ ULONG SubAuthority5,
1785   _In_ ULONG SubAuthority6,
1786   _In_ ULONG SubAuthority7,
1787   _Outptr_ PSID *Sid);
1788 
1789 _IRQL_requires_max_(APC_LEVEL)
1790 NTSYSAPI
1791 NTSTATUS
1792 NTAPI
1793 RtlInitializeSid(
1794   _Out_ PSID Sid,
1795   _In_ PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
1796   _In_ UCHAR SubAuthorityCount);
1797 
1798 NTSYSAPI
1799 PULONG
1800 NTAPI
1801 RtlSubAuthoritySid(
1802   _In_ PSID Sid,
1803   _In_ ULONG SubAuthority);
1804 
1805 _Post_satisfies_(return >= 8 && return <= SECURITY_MAX_SID_SIZE)
1806 NTSYSAPI
1807 ULONG
1808 NTAPI
1809 RtlLengthSid(
1810   _In_ PSID Sid);
1811 
1812 _IRQL_requires_max_(APC_LEVEL)
1813 NTSYSAPI
1814 NTSTATUS
1815 NTAPI
1816 RtlCopySid(
1817   _In_ ULONG DestinationSidLength,
1818   _Out_writes_bytes_(DestinationSidLength) PSID DestinationSid,
1819   _In_ PSID SourceSid);
1820 
1821 _IRQL_requires_max_(APC_LEVEL)
1822 NTSYSAPI
1823 NTSTATUS
1824 NTAPI
1825 RtlConvertSidToUnicodeString(
1826   _Inout_ PUNICODE_STRING UnicodeString,
1827   _In_ PSID Sid,
1828   _In_ BOOLEAN AllocateDestinationString);
1829 
1830 _IRQL_requires_max_(APC_LEVEL)
1831 NTSYSAPI
1832 VOID
1833 NTAPI
1834 RtlCopyLuid(
1835   _Out_ PLUID DestinationLuid,
1836   _In_ PLUID SourceLuid);
1837 
1838 _IRQL_requires_max_(APC_LEVEL)
1839 NTSYSAPI
1840 NTSTATUS
1841 NTAPI
1842 RtlCreateAcl(
1843   _Out_writes_bytes_(AclLength) PACL Acl,
1844   _In_ ULONG AclLength,
1845   _In_ ULONG AclRevision);
1846 
1847 _IRQL_requires_max_(APC_LEVEL)
1848 NTSYSAPI
1849 NTSTATUS
1850 NTAPI
1851 RtlAddAce(
1852   _Inout_ PACL Acl,
1853   _In_ ULONG AceRevision,
1854   _In_ ULONG StartingAceIndex,
1855   _In_reads_bytes_(AceListLength) PVOID AceList,
1856   _In_ ULONG AceListLength);
1857 
1858 _IRQL_requires_max_(APC_LEVEL)
1859 NTSYSAPI
1860 NTSTATUS
1861 NTAPI
1862 RtlDeleteAce(
1863   _Inout_ PACL Acl,
1864   _In_ ULONG AceIndex);
1865 
1866 NTSYSAPI
1867 NTSTATUS
1868 NTAPI
1869 RtlGetAce(
1870   _In_ PACL Acl,
1871   _In_ ULONG AceIndex,
1872   _Outptr_ PVOID *Ace);
1873 
1874 _IRQL_requires_max_(APC_LEVEL)
1875 NTSYSAPI
1876 NTSTATUS
1877 NTAPI
1878 RtlAddAccessAllowedAce(
1879   _Inout_ PACL Acl,
1880   _In_ ULONG AceRevision,
1881   _In_ ACCESS_MASK AccessMask,
1882   _In_ PSID Sid);
1883 
1884 _IRQL_requires_max_(APC_LEVEL)
1885 NTSYSAPI
1886 NTSTATUS
1887 NTAPI
1888 RtlAddAccessAllowedAceEx(
1889   _Inout_ PACL Acl,
1890   _In_ ULONG AceRevision,
1891   _In_ ULONG AceFlags,
1892   _In_ ACCESS_MASK AccessMask,
1893   _In_ PSID Sid);
1894 
1895 _IRQL_requires_max_(APC_LEVEL)
1896 NTSYSAPI
1897 NTSTATUS
1898 NTAPI
1899 RtlCreateSecurityDescriptorRelative(
1900   _Out_ PISECURITY_DESCRIPTOR_RELATIVE SecurityDescriptor,
1901   _In_ ULONG Revision);
1902 
1903 NTSYSAPI
1904 NTSTATUS
1905 NTAPI
1906 RtlGetDaclSecurityDescriptor(
1907   _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1908   _Out_ PBOOLEAN DaclPresent,
1909   _Out_ PACL *Dacl,
1910   _Out_ PBOOLEAN DaclDefaulted);
1911 
1912 _IRQL_requires_max_(APC_LEVEL)
1913 NTSYSAPI
1914 NTSTATUS
1915 NTAPI
1916 RtlSetOwnerSecurityDescriptor(
1917   _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1918   _In_opt_ PSID Owner,
1919   _In_opt_ BOOLEAN OwnerDefaulted);
1920 
1921 _IRQL_requires_max_(APC_LEVEL)
1922 NTSYSAPI
1923 NTSTATUS
1924 NTAPI
1925 RtlGetOwnerSecurityDescriptor(
1926   _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
1927   _Out_ PSID *Owner,
1928   _Out_ PBOOLEAN OwnerDefaulted);
1929 
1930 _IRQL_requires_max_(APC_LEVEL)
1931 _When_(Status < 0, _Out_range_(>, 0))
1932 _When_(Status >= 0, _Out_range_(==, 0))
1933 NTSYSAPI
1934 ULONG
1935 NTAPI
1936 RtlNtStatusToDosError(
1937   _In_ NTSTATUS Status);
1938 
1939 _IRQL_requires_max_(PASSIVE_LEVEL)
1940 NTSYSAPI
1941 NTSTATUS
1942 NTAPI
1943 RtlCustomCPToUnicodeN(
1944   _In_ PCPTABLEINFO CustomCP,
1945   _Out_writes_bytes_to_(MaxBytesInUnicodeString, *BytesInUnicodeString) PWCH UnicodeString,
1946   _In_ ULONG MaxBytesInUnicodeString,
1947   _Out_opt_ PULONG BytesInUnicodeString,
1948   _In_reads_bytes_(BytesInCustomCPString) PCH CustomCPString,
1949   _In_ ULONG BytesInCustomCPString);
1950 
1951 _IRQL_requires_max_(PASSIVE_LEVEL)
1952 NTSYSAPI
1953 NTSTATUS
1954 NTAPI
1955 RtlUnicodeToCustomCPN(
1956   _In_ PCPTABLEINFO CustomCP,
1957   _Out_writes_bytes_to_(MaxBytesInCustomCPString, *BytesInCustomCPString) PCH CustomCPString,
1958   _In_ ULONG MaxBytesInCustomCPString,
1959   _Out_opt_ PULONG BytesInCustomCPString,
1960   _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1961   _In_ ULONG BytesInUnicodeString);
1962 
1963 _IRQL_requires_max_(PASSIVE_LEVEL)
1964 NTSYSAPI
1965 NTSTATUS
1966 NTAPI
1967 RtlUpcaseUnicodeToCustomCPN(
1968   _In_ PCPTABLEINFO CustomCP,
1969   _Out_writes_bytes_to_(MaxBytesInCustomCPString, *BytesInCustomCPString) PCH CustomCPString,
1970   _In_ ULONG MaxBytesInCustomCPString,
1971   _Out_opt_ PULONG BytesInCustomCPString,
1972   _In_reads_bytes_(BytesInUnicodeString) PWCH UnicodeString,
1973   _In_ ULONG BytesInUnicodeString);
1974 
1975 _IRQL_requires_max_(PASSIVE_LEVEL)
1976 NTSYSAPI
1977 VOID
1978 NTAPI
1979 RtlInitCodePageTable(
1980   _In_ PUSHORT TableBase,
1981   _Out_ PCPTABLEINFO CodePageTable);
1982 
1983 $endif (_NTIFS_)
1984 
1985 #endif /* (NTDDI_VERSION >= NTDDI_WIN2K) */
1986 
1987 $if (_WDMDDK_)
1988 
1989 #if (NTDDI_VERSION >= NTDDI_WIN2KSP3)
1990 NTSYSAPI
1991 VOID
1992 FASTCALL
1993 RtlPrefetchMemoryNonTemporal(
1994   _In_ PVOID Source,
1995   _In_ SIZE_T Length);
1996 #endif
1997 
1998 $endif (_WDMDDK_)
1999 
2000 #if (NTDDI_VERSION >= NTDDI_WINXP)
2001 
2002 $if (_WDMDDK_)
2003 
2004 NTSYSAPI
2005 VOID
2006 NTAPI
2007 RtlClearBit(
2008   _In_ PRTL_BITMAP BitMapHeader,
2009   _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber);
2010 
2011 _IRQL_requires_max_(PASSIVE_LEVEL)
2012 NTSYSAPI
2013 WCHAR
2014 NTAPI
2015 RtlDowncaseUnicodeChar(
2016   _In_ WCHAR SourceCharacter);
2017 
2018 NTSYSAPI
2019 VOID
2020 NTAPI
2021 RtlSetBit(
2022   _In_ PRTL_BITMAP BitMapHeader,
2023   _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber);
2024 
2025 _Must_inspect_result_
2026 NTSYSAPI
2027 BOOLEAN
2028 NTAPI
2029 RtlTestBit(
2030   _In_ PRTL_BITMAP BitMapHeader,
2031   _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber);
2032 
2033 _IRQL_requires_max_(PASSIVE_LEVEL)
2034 NTSYSAPI
2035 NTSTATUS
2036 NTAPI
2037 RtlHashUnicodeString(
2038   _In_ CONST UNICODE_STRING *String,
2039   _In_ BOOLEAN CaseInSensitive,
2040   _In_ ULONG HashAlgorithm,
2041   _Out_ PULONG HashValue);
2042 
2043 $endif (_WDMDDK_)
2044 
2045 $if (_NTDDK_)
2046 
2047 NTSYSAPI
2048 VOID
2049 NTAPI
2050 RtlInitializeGenericTableAvl(
2051   _Out_ PRTL_AVL_TABLE Table,
2052   _In_ PRTL_AVL_COMPARE_ROUTINE CompareRoutine,
2053   _In_opt_ PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine,
2054   _In_opt_ PRTL_AVL_FREE_ROUTINE FreeRoutine,
2055   _In_opt_ PVOID TableContext);
2056 
2057 NTSYSAPI
2058 PVOID
2059 NTAPI
2060 RtlInsertElementGenericTableAvl(
2061   _In_ PRTL_AVL_TABLE Table,
2062   _In_reads_bytes_(BufferSize) PVOID Buffer,
2063   _In_ CLONG BufferSize,
2064   _Out_opt_ PBOOLEAN NewElement);
2065 
2066 NTSYSAPI
2067 PVOID
2068 NTAPI
2069 RtlInsertElementGenericTableFullAvl(
2070   _In_ PRTL_AVL_TABLE Table,
2071   _In_reads_bytes_(BufferSize) PVOID Buffer,
2072   _In_ CLONG BufferSize,
2073   _Out_opt_ PBOOLEAN NewElement,
2074   _In_ PVOID NodeOrParent,
2075   _In_ TABLE_SEARCH_RESULT SearchResult);
2076 
2077 NTSYSAPI
2078 BOOLEAN
2079 NTAPI
2080 RtlDeleteElementGenericTableAvl(
2081   _In_ PRTL_AVL_TABLE Table,
2082   _In_ PVOID Buffer);
2083 
2084 _Must_inspect_result_
2085 NTSYSAPI
2086 PVOID
2087 NTAPI
2088 RtlLookupElementGenericTableAvl(
2089   _In_ PRTL_AVL_TABLE Table,
2090   _In_ PVOID Buffer);
2091 
2092 NTSYSAPI
2093 PVOID
2094 NTAPI
2095 RtlLookupElementGenericTableFullAvl(
2096   _In_ PRTL_AVL_TABLE Table,
2097   _In_ PVOID Buffer,
2098   _Out_ PVOID *NodeOrParent,
2099   _Out_ TABLE_SEARCH_RESULT *SearchResult);
2100 
2101 _Must_inspect_result_
2102 NTSYSAPI
2103 PVOID
2104 NTAPI
2105 RtlEnumerateGenericTableAvl(
2106   _In_ PRTL_AVL_TABLE Table,
2107   _In_ BOOLEAN Restart);
2108 
2109 _Must_inspect_result_
2110 NTSYSAPI
2111 PVOID
2112 NTAPI
2113 RtlEnumerateGenericTableWithoutSplayingAvl(
2114   _In_ PRTL_AVL_TABLE Table,
2115   _Inout_ PVOID *RestartKey);
2116 
2117 _Must_inspect_result_
2118 NTSYSAPI
2119 PVOID
2120 NTAPI
2121 RtlLookupFirstMatchingElementGenericTableAvl(
2122   _In_ PRTL_AVL_TABLE Table,
2123   _In_ PVOID Buffer,
2124   _Out_ PVOID *RestartKey);
2125 
2126 _Must_inspect_result_
2127 NTSYSAPI
2128 PVOID
2129 NTAPI
2130 RtlEnumerateGenericTableLikeADirectory(
2131   _In_ PRTL_AVL_TABLE Table,
2132   _In_opt_ PRTL_AVL_MATCH_FUNCTION MatchFunction,
2133   _In_opt_ PVOID MatchData,
2134   _In_ ULONG NextFlag,
2135   _Inout_ PVOID *RestartKey,
2136   _Inout_ PULONG DeleteCount,
2137   _In_ PVOID Buffer);
2138 
2139 _Must_inspect_result_
2140 NTSYSAPI
2141 PVOID
2142 NTAPI
2143 RtlGetElementGenericTableAvl(
2144   _In_ PRTL_AVL_TABLE Table,
2145   _In_ ULONG I);
2146 
2147 NTSYSAPI
2148 ULONG
2149 NTAPI
2150 RtlNumberGenericTableElementsAvl(
2151   _In_ PRTL_AVL_TABLE Table);
2152 
2153 _Must_inspect_result_
2154 NTSYSAPI
2155 BOOLEAN
2156 NTAPI
2157 RtlIsGenericTableEmptyAvl(
2158   _In_ PRTL_AVL_TABLE Table);
2159 
2160 $endif (_NTDDK_)
2161 $if (_NTIFS_)
2162 
2163 _Must_inspect_result_
2164 NTSYSAPI
2165 PVOID
2166 NTAPI
2167 RtlCreateHeap(
2168   _In_ ULONG Flags,
2169   _In_opt_ PVOID HeapBase,
2170   _In_opt_ SIZE_T ReserveSize,
2171   _In_opt_ SIZE_T CommitSize,
2172   _In_opt_ PVOID Lock,
2173   _In_opt_ PRTL_HEAP_PARAMETERS Parameters);
2174 
2175 NTSYSAPI
2176 PVOID
2177 NTAPI
2178 RtlDestroyHeap(
2179   _In_ _Post_invalid_ PVOID HeapHandle);
2180 
2181 NTSYSAPI
2182 USHORT
2183 NTAPI
2184 RtlCaptureStackBackTrace(
2185   _In_ ULONG FramesToSkip,
2186   _In_ ULONG FramesToCapture,
2187   _Out_writes_to_(FramesToCapture, return) PVOID *BackTrace,
2188   _Out_opt_ PULONG BackTraceHash);
2189 
2190 _Ret_range_(<, MAXLONG)
2191 NTSYSAPI
2192 ULONG
2193 NTAPI
2194 RtlRandomEx(
2195   _Inout_ PULONG Seed);
2196 
2197 _IRQL_requires_max_(DISPATCH_LEVEL)
2198 NTSYSAPI
2199 NTSTATUS
2200 NTAPI
2201 RtlInitUnicodeStringEx(
2202   _Out_ PUNICODE_STRING DestinationString,
2203   _In_opt_z_ __drv_aliasesMem PCWSTR SourceString);
2204 
2205 _Must_inspect_result_
2206 NTSYSAPI
2207 NTSTATUS
2208 NTAPI
2209 RtlValidateUnicodeString(
2210   _In_ ULONG Flags,
2211   _In_ PCUNICODE_STRING String);
2212 
2213 _IRQL_requires_max_(PASSIVE_LEVEL)
2214 _Must_inspect_result_
2215 NTSYSAPI
2216 NTSTATUS
2217 NTAPI
2218 RtlDuplicateUnicodeString(
2219   _In_ ULONG Flags,
2220   _In_ PCUNICODE_STRING SourceString,
2221   _Out_ _At_(DestinationString->Buffer, __drv_allocatesMem(Mem)) PUNICODE_STRING DestinationString);
2222 
2223 NTSYSAPI
2224 NTSTATUS
2225 NTAPI
2226 RtlGetCompressionWorkSpaceSize(
2227   _In_ USHORT CompressionFormatAndEngine,
2228   _Out_ PULONG CompressBufferWorkSpaceSize,
2229   _Out_ PULONG CompressFragmentWorkSpaceSize);
2230 
2231 NTSYSAPI
2232 NTSTATUS
2233 NTAPI
2234 RtlCompressBuffer(
2235   _In_ USHORT CompressionFormatAndEngine,
2236   _In_reads_bytes_(UncompressedBufferSize) PUCHAR UncompressedBuffer,
2237   _In_ ULONG UncompressedBufferSize,
2238   _Out_writes_bytes_to_(CompressedBufferSize, *FinalCompressedSize) PUCHAR CompressedBuffer,
2239   _In_ ULONG CompressedBufferSize,
2240   _In_ ULONG UncompressedChunkSize,
2241   _Out_ PULONG FinalCompressedSize,
2242   _In_ PVOID WorkSpace);
2243 
2244 _IRQL_requires_max_(APC_LEVEL)
2245 NTSYSAPI
2246 NTSTATUS
2247 NTAPI
2248 RtlDecompressBuffer(
2249   _In_ USHORT CompressionFormat,
2250   _Out_writes_bytes_to_(UncompressedBufferSize, *FinalUncompressedSize) PUCHAR UncompressedBuffer,
2251   _In_ ULONG UncompressedBufferSize,
2252   _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2253   _In_ ULONG CompressedBufferSize,
2254   _Out_ PULONG FinalUncompressedSize);
2255 
2256 _IRQL_requires_max_(APC_LEVEL)
2257 NTSYSAPI
2258 NTSTATUS
2259 NTAPI
2260 RtlDecompressFragment(
2261   _In_ USHORT CompressionFormat,
2262   _Out_writes_bytes_to_(UncompressedFragmentSize, *FinalUncompressedSize) PUCHAR UncompressedFragment,
2263   _In_ ULONG UncompressedFragmentSize,
2264   _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2265   _In_ ULONG CompressedBufferSize,
2266   _In_range_(<, CompressedBufferSize) ULONG FragmentOffset,
2267   _Out_ PULONG FinalUncompressedSize,
2268   _In_ PVOID WorkSpace);
2269 
2270 _IRQL_requires_max_(APC_LEVEL)
2271 NTSYSAPI
2272 NTSTATUS
2273 NTAPI
2274 RtlDescribeChunk(
2275   _In_ USHORT CompressionFormat,
2276   _Inout_ PUCHAR *CompressedBuffer,
2277   _In_ PUCHAR EndOfCompressedBufferPlus1,
2278   _Out_ PUCHAR *ChunkBuffer,
2279   _Out_ PULONG ChunkSize);
2280 
2281 _IRQL_requires_max_(APC_LEVEL)
2282 NTSYSAPI
2283 NTSTATUS
2284 NTAPI
2285 RtlReserveChunk(
2286   _In_ USHORT CompressionFormat,
2287   _Inout_ PUCHAR *CompressedBuffer,
2288   _In_ PUCHAR EndOfCompressedBufferPlus1,
2289   _Out_ PUCHAR *ChunkBuffer,
2290   _In_ ULONG ChunkSize);
2291 
2292 _IRQL_requires_max_(APC_LEVEL)
2293 NTSYSAPI
2294 NTSTATUS
2295 NTAPI
2296 RtlDecompressChunks(
2297   _Out_writes_bytes_(UncompressedBufferSize) PUCHAR UncompressedBuffer,
2298   _In_ ULONG UncompressedBufferSize,
2299   _In_reads_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2300   _In_ ULONG CompressedBufferSize,
2301   _In_reads_bytes_(CompressedTailSize) PUCHAR CompressedTail,
2302   _In_ ULONG CompressedTailSize,
2303   _In_ PCOMPRESSED_DATA_INFO CompressedDataInfo);
2304 
2305 _IRQL_requires_max_(APC_LEVEL)
2306 NTSYSAPI
2307 NTSTATUS
2308 NTAPI
2309 RtlCompressChunks(
2310   _In_reads_bytes_(UncompressedBufferSize) PUCHAR UncompressedBuffer,
2311   _In_ ULONG UncompressedBufferSize,
2312   _Out_writes_bytes_(CompressedBufferSize) PUCHAR CompressedBuffer,
2313   _In_range_(>=, (UncompressedBufferSize - (UncompressedBufferSize / 16))) ULONG CompressedBufferSize,
2314   _Inout_updates_bytes_(CompressedDataInfoLength) PCOMPRESSED_DATA_INFO CompressedDataInfo,
2315   _In_range_(>, sizeof(COMPRESSED_DATA_INFO)) ULONG CompressedDataInfoLength,
2316   _In_ PVOID WorkSpace);
2317 
2318 _IRQL_requires_max_(APC_LEVEL)
2319 NTSYSAPI
2320 PSID_IDENTIFIER_AUTHORITY
2321 NTAPI
2322 RtlIdentifierAuthoritySid(
2323   _In_ PSID Sid);
2324 
2325 NTSYSAPI
2326 PUCHAR
2327 NTAPI
2328 RtlSubAuthorityCountSid(
2329   _In_ PSID Sid);
2330 
2331 _When_(Status < 0, _Out_range_(>, 0))
2332 _When_(Status >= 0, _Out_range_(==, 0))
2333 NTSYSAPI
2334 ULONG
2335 NTAPI
2336 RtlNtStatusToDosErrorNoTeb(
2337   _In_ NTSTATUS Status);
2338 
2339 _IRQL_requires_max_(PASSIVE_LEVEL)
2340 NTSYSAPI
2341 NTSTATUS
2342 NTAPI
2343 RtlCreateSystemVolumeInformationFolder(
2344   _In_ PCUNICODE_STRING VolumeRootPath);
2345 
2346 #if defined(_M_AMD64)
2347 
2348 FORCEINLINE
2349 VOID
2350 RtlFillMemoryUlong(
2351   _Out_writes_bytes_all_(Length) PVOID Destination,
2352   _In_ SIZE_T Length,
2353   _In_ ULONG Pattern)
2354 {
2355   PULONG Address = (PULONG)Destination;
2356   if ((Length /= 4) != 0) {
2357     if (((ULONG64)Address & 4) != 0) {
2358       *Address = Pattern;
2359       if ((Length -= 1) == 0) {
2360         return;
2361       }
2362       Address += 1;
2363     }
2364     __stosq((PULONG64)(Address), Pattern | ((ULONG64)Pattern << 32), Length / 2);
2365     if ((Length & 1) != 0) Address[Length - 1] = Pattern;
2366   }
2367   return;
2368 }
2369 
2370 #define RtlFillMemoryUlonglong(Destination, Length, Pattern)                \
2371     __stosq((PULONG64)(Destination), Pattern, (Length) / 8)
2372 
2373 #else
2374 
2375 NTSYSAPI
2376 VOID
2377 NTAPI
2378 RtlFillMemoryUlong(
2379   OUT PVOID Destination,
2380   IN SIZE_T Length,
2381   IN ULONG Pattern);
2382 
2383 NTSYSAPI
2384 VOID
2385 NTAPI
2386 RtlFillMemoryUlonglong(
2387   _Out_writes_bytes_all_(Length) PVOID Destination,
2388   _In_ SIZE_T Length,
2389   _In_ ULONGLONG Pattern);
2390 
2391 #endif /* defined(_M_AMD64) */
2392 $endif (_NTIFS_)
2393 
2394 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
2395 
2396 $if (_NTIFS_)
2397 #if (NTDDI_VERSION >= NTDDI_WS03)
2398 _IRQL_requires_max_(DISPATCH_LEVEL)
2399 NTSYSAPI
2400 NTSTATUS
2401 NTAPI
2402 RtlInitAnsiStringEx(
2403   _Out_ PANSI_STRING DestinationString,
2404   _In_opt_z_ __drv_aliasesMem PCSZ SourceString);
2405 #endif
2406 
2407 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
2408 
2409 _IRQL_requires_max_(APC_LEVEL)
2410 NTSYSAPI
2411 NTSTATUS
2412 NTAPI
2413 RtlGetSaclSecurityDescriptor(
2414   _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
2415   _Out_ PBOOLEAN SaclPresent,
2416   _Out_ PACL *Sacl,
2417   _Out_ PBOOLEAN SaclDefaulted);
2418 
2419 _IRQL_requires_max_(APC_LEVEL)
2420 NTSYSAPI
2421 NTSTATUS
2422 NTAPI
2423 RtlSetGroupSecurityDescriptor(
2424   _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
2425   _In_opt_ PSID Group,
2426   _In_opt_ BOOLEAN GroupDefaulted);
2427 
2428 _IRQL_requires_max_(APC_LEVEL)
2429 NTSYSAPI
2430 NTSTATUS
2431 NTAPI
2432 RtlGetGroupSecurityDescriptor(
2433   _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
2434   _Out_ PSID *Group,
2435   _Out_ PBOOLEAN GroupDefaulted);
2436 
2437 _IRQL_requires_max_(APC_LEVEL)
2438 NTSYSAPI
2439 NTSTATUS
2440 NTAPI
2441 RtlAbsoluteToSelfRelativeSD(
2442   _In_ PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
2443   _Out_writes_bytes_to_opt_(*BufferLength, *BufferLength) PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
2444   _Inout_ PULONG BufferLength);
2445 
2446 _IRQL_requires_max_(APC_LEVEL)
2447 NTSYSAPI
2448 NTSTATUS
2449 NTAPI
2450 RtlSelfRelativeToAbsoluteSD(
2451   _In_ PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
2452   _Out_writes_bytes_to_opt_(*AbsoluteSecurityDescriptorSize, *AbsoluteSecurityDescriptorSize) PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
2453   _Inout_ PULONG AbsoluteSecurityDescriptorSize,
2454   _Out_writes_bytes_to_opt_(*DaclSize, *DaclSize) PACL Dacl,
2455   _Inout_ PULONG DaclSize,
2456   _Out_writes_bytes_to_opt_(*SaclSize, *SaclSize) PACL Sacl,
2457   _Inout_ PULONG SaclSize,
2458   _Out_writes_bytes_to_opt_(*OwnerSize, *OwnerSize) PSID Owner,
2459   _Inout_ PULONG OwnerSize,
2460   _Out_writes_bytes_to_opt_(*PrimaryGroupSize, *PrimaryGroupSize) PSID PrimaryGroup,
2461   _Inout_ PULONG PrimaryGroupSize);
2462 
2463 #endif /* (NTDDI_VERSION >= NTDDI_WS03SP1) */
2464 $endif (_NTIFS_)
2465 
2466 #if (NTDDI_VERSION >= NTDDI_VISTA)
2467 
2468 $if (_WDMDDK_)
2469 NTSYSAPI
2470 ULONG
2471 NTAPI
2472 RtlNumberOfSetBitsUlongPtr(
2473   _In_ ULONG_PTR Target);
2474 
2475 NTSYSAPI
2476 ULONGLONG
2477 NTAPI
2478 RtlIoDecodeMemIoResource(
2479   _In_ struct _IO_RESOURCE_DESCRIPTOR *Descriptor,
2480   _Out_opt_ PULONGLONG Alignment,
2481   _Out_opt_ PULONGLONG MinimumAddress,
2482   _Out_opt_ PULONGLONG MaximumAddress);
2483 
2484 NTSYSAPI
2485 NTSTATUS
2486 NTAPI
2487 RtlIoEncodeMemIoResource(
2488   _In_ struct _IO_RESOURCE_DESCRIPTOR *Descriptor,
2489   _In_ UCHAR Type,
2490   _In_ ULONGLONG Length,
2491   _In_ ULONGLONG Alignment,
2492   _In_ ULONGLONG MinimumAddress,
2493   _In_ ULONGLONG MaximumAddress);
2494 
2495 NTSYSAPI
2496 ULONGLONG
2497 NTAPI
2498 RtlCmDecodeMemIoResource(
2499   _In_ struct _CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor,
2500   _Out_opt_ PULONGLONG Start);
2501 
2502 NTSYSAPI
2503 NTSTATUS
2504 NTAPI
2505 RtlFindClosestEncodableLength(
2506   _In_ ULONGLONG SourceLength,
2507   _Out_ PULONGLONG TargetLength);
2508 
2509 NTSYSAPI
2510 NTSTATUS
2511 NTAPI
2512 RtlCmEncodeMemIoResource(
2513   _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
2514   _In_ UCHAR Type,
2515   _In_ ULONGLONG Length,
2516   _In_ ULONGLONG Start);
2517 
2518 $endif (_WDMDDK_)
2519 $if (_NTDDK_)
2520 
2521 _IRQL_requires_max_(APC_LEVEL)
2522 NTSYSAPI
2523 VOID
2524 NTAPI
2525 RtlRunOnceInitialize(
2526   _Out_ PRTL_RUN_ONCE RunOnce);
2527 
2528 _IRQL_requires_max_(APC_LEVEL)
2529 _Maybe_raises_SEH_exception_
2530 NTSYSAPI
2531 NTSTATUS
2532 NTAPI
2533 RtlRunOnceExecuteOnce(
2534   _Inout_ PRTL_RUN_ONCE RunOnce,
2535   _In_ __inner_callback PRTL_RUN_ONCE_INIT_FN InitFn,
2536   _Inout_opt_ PVOID Parameter,
2537   _Outptr_opt_result_maybenull_ PVOID *Context);
2538 
2539 _IRQL_requires_max_(APC_LEVEL)
2540 _Must_inspect_result_
2541 NTSYSAPI
2542 NTSTATUS
2543 NTAPI
2544 RtlRunOnceBeginInitialize(
2545   _Inout_ PRTL_RUN_ONCE RunOnce,
2546   _In_ ULONG Flags,
2547   _Outptr_opt_result_maybenull_ PVOID *Context);
2548 
2549 _IRQL_requires_max_(APC_LEVEL)
2550 NTSYSAPI
2551 NTSTATUS
2552 NTAPI
2553 RtlRunOnceComplete(
2554   _Inout_ PRTL_RUN_ONCE RunOnce,
2555   _In_ ULONG Flags,
2556   _In_opt_ PVOID Context);
2557 
2558 NTSYSAPI
2559 BOOLEAN
2560 NTAPI
2561 RtlGetProductInfo(
2562   _In_ ULONG OSMajorVersion,
2563   _In_ ULONG OSMinorVersion,
2564   _In_ ULONG SpMajorVersion,
2565   _In_ ULONG SpMinorVersion,
2566   _Out_ PULONG ReturnedProductType);
2567 
2568 $endif (_NTDDK_)
2569 $if (_NTIFS_)
2570 NTSYSAPI
2571 NTSTATUS
2572 NTAPI
2573 RtlNormalizeString(
2574   _In_ ULONG NormForm,
2575   _In_ PCWSTR SourceString,
2576   _In_ LONG SourceStringLength,
2577   _Out_writes_to_(*DestinationStringLength, *DestinationStringLength) PWSTR DestinationString,
2578   _Inout_ PLONG DestinationStringLength);
2579 
2580 NTSYSAPI
2581 NTSTATUS
2582 NTAPI
2583 RtlIsNormalizedString(
2584   _In_ ULONG NormForm,
2585   _In_ PCWSTR SourceString,
2586   _In_ LONG SourceStringLength,
2587   _Out_ PBOOLEAN Normalized);
2588 
2589 NTSYSAPI
2590 NTSTATUS
2591 NTAPI
2592 RtlIdnToAscii(
2593   _In_ ULONG Flags,
2594   _In_ PCWSTR SourceString,
2595   _In_ LONG SourceStringLength,
2596   _Out_writes_to_(*DestinationStringLength, *DestinationStringLength) PWSTR DestinationString,
2597   _Inout_ PLONG DestinationStringLength);
2598 
2599 NTSYSAPI
2600 NTSTATUS
2601 NTAPI
2602 RtlIdnToUnicode(
2603   IN ULONG Flags,
2604   IN PCWSTR SourceString,
2605   IN LONG SourceStringLength,
2606   OUT PWSTR DestinationString,
2607   IN OUT PLONG DestinationStringLength);
2608 
2609 NTSYSAPI
2610 NTSTATUS
2611 NTAPI
2612 RtlIdnToNameprepUnicode(
2613   _In_ ULONG Flags,
2614   _In_ PCWSTR SourceString,
2615   _In_ LONG SourceStringLength,
2616   _Out_writes_to_(*DestinationStringLength, *DestinationStringLength) PWSTR DestinationString,
2617   _Inout_ PLONG DestinationStringLength);
2618 
2619 NTSYSAPI
2620 NTSTATUS
2621 NTAPI
2622 RtlCreateServiceSid(
2623   _In_ PUNICODE_STRING ServiceName,
2624   _Out_writes_bytes_opt_(*ServiceSidLength) PSID ServiceSid,
2625   _Inout_ PULONG ServiceSidLength);
2626 
2627 NTSYSAPI
2628 LONG
2629 NTAPI
2630 RtlCompareAltitudes(
2631   _In_ PCUNICODE_STRING Altitude1,
2632   _In_ PCUNICODE_STRING Altitude2);
2633 
2634 $endif (_NTIFS_)
2635 
2636 #endif /* (NTDDI_VERSION >= NTDDI_VISTA) */
2637 
2638 #if (NTDDI_VERSION >= NTDDI_WIN7)
2639 
2640 $if (_WDMDDK_)
2641 _IRQL_requires_max_(PASSIVE_LEVEL)
2642 _Must_inspect_result_
2643 NTSYSAPI
2644 NTSTATUS
2645 NTAPI
2646 RtlUnicodeToUTF8N(
2647   _Out_writes_bytes_to_(UTF8StringMaxByteCount, *UTF8StringActualByteCount)
2648     PCHAR UTF8StringDestination,
2649   _In_ ULONG UTF8StringMaxByteCount,
2650   _Out_ PULONG UTF8StringActualByteCount,
2651   _In_reads_bytes_(UnicodeStringByteCount) PCWCH UnicodeStringSource,
2652   _In_ ULONG UnicodeStringByteCount);
2653 
2654 _IRQL_requires_max_(PASSIVE_LEVEL)
2655 _Must_inspect_result_
2656 NTSYSAPI
2657 NTSTATUS
2658 NTAPI
2659 RtlUTF8ToUnicodeN(
2660   _Out_writes_bytes_to_(UnicodeStringMaxByteCount, *UnicodeStringActualByteCount)
2661     PWSTR UnicodeStringDestination,
2662   _In_ ULONG UnicodeStringMaxByteCount,
2663   _Out_ PULONG UnicodeStringActualByteCount,
2664   _In_reads_bytes_(UTF8StringByteCount) PCCH UTF8StringSource,
2665   _In_ ULONG UTF8StringByteCount);
2666 
2667 NTSYSAPI
2668 ULONG64
2669 NTAPI
2670 RtlGetEnabledExtendedFeatures(
2671   IN ULONG64 FeatureMask);
2672 
2673 $endif (_WDMDDK_)
2674 $if (_NTDDK_)
2675 
2676 _Must_inspect_result_
2677 NTSYSAPI
2678 BOOLEAN
2679 NTAPI
2680 RtlCreateHashTable(
2681   _Inout_ _When_(NULL == *HashTable, __drv_allocatesMem(Mem))
2682     PRTL_DYNAMIC_HASH_TABLE *HashTable,
2683   _In_ ULONG Shift,
2684   _In_ _Reserved_ ULONG Flags);
2685 
2686 NTSYSAPI
2687 VOID
2688 NTAPI
2689 RtlDeleteHashTable(
2690   _In_ _When_((HashTable->Flags & RTL_HASH_ALLOCATED_HEADER), __drv_freesMem(Mem) _Post_invalid_)
2691     PRTL_DYNAMIC_HASH_TABLE HashTable);
2692 
2693 NTSYSAPI
2694 BOOLEAN
2695 NTAPI
2696 RtlInsertEntryHashTable(
2697   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2698   _In_ __drv_aliasesMem PRTL_DYNAMIC_HASH_TABLE_ENTRY Entry,
2699   _In_ ULONG_PTR Signature,
2700   _Inout_opt_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context);
2701 
2702 NTSYSAPI
2703 BOOLEAN
2704 NTAPI
2705 RtlRemoveEntryHashTable(
2706   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2707   _In_ PRTL_DYNAMIC_HASH_TABLE_ENTRY Entry,
2708   _Inout_opt_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context);
2709 
2710 _Must_inspect_result_
2711 NTSYSAPI
2712 PRTL_DYNAMIC_HASH_TABLE_ENTRY
2713 NTAPI
2714 RtlLookupEntryHashTable(
2715   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2716   _In_ ULONG_PTR Signature,
2717   _Out_opt_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context);
2718 
2719 _Must_inspect_result_
2720 NTSYSAPI
2721 PRTL_DYNAMIC_HASH_TABLE_ENTRY
2722 NTAPI
2723 RtlGetNextEntryHashTable(
2724   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2725   _In_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context);
2726 
2727 NTSYSAPI
2728 BOOLEAN
2729 NTAPI
2730 RtlInitEnumerationHashTable(
2731   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2732   _Out_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator);
2733 
2734 _Must_inspect_result_
2735 NTSYSAPI
2736 PRTL_DYNAMIC_HASH_TABLE_ENTRY
2737 NTAPI
2738 RtlEnumerateEntryHashTable(
2739   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2740   _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator);
2741 
2742 NTSYSAPI
2743 VOID
2744 NTAPI
2745 RtlEndEnumerationHashTable(
2746   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2747   _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator);
2748 
2749 NTSYSAPI
2750 BOOLEAN
2751 NTAPI
2752 RtlInitWeakEnumerationHashTable(
2753   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2754   _Out_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator);
2755 
2756 _Must_inspect_result_
2757 NTSYSAPI
2758 PRTL_DYNAMIC_HASH_TABLE_ENTRY
2759 NTAPI
2760 RtlWeaklyEnumerateEntryHashTable(
2761   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2762   _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator);
2763 
2764 NTSYSAPI
2765 VOID
2766 NTAPI
2767 RtlEndWeakEnumerationHashTable(
2768   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable,
2769   _Inout_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator);
2770 
2771 NTSYSAPI
2772 BOOLEAN
2773 NTAPI
2774 RtlExpandHashTable(
2775   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable);
2776 
2777 NTSYSAPI
2778 BOOLEAN
2779 NTAPI
2780 RtlContractHashTable(
2781   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable);
2782 
2783 $endif (_NTDDK_)
2784 $if (_NTIFS_)
2785 _IRQL_requires_max_(PASSIVE_LEVEL)
2786 _Must_inspect_result_
2787 NTSYSAPI
2788 NTSTATUS
2789 NTAPI
2790 RtlUnicodeToUTF8N(
2791   _Out_writes_bytes_to_(UTF8StringMaxByteCount, *UTF8StringActualByteCount) PCHAR UTF8StringDestination,
2792   _In_ ULONG UTF8StringMaxByteCount,
2793   _Out_ PULONG UTF8StringActualByteCount,
2794   _In_reads_bytes_(UnicodeStringByteCount) PCWCH UnicodeStringSource,
2795   _In_ ULONG UnicodeStringByteCount);
2796 
2797 _IRQL_requires_max_(PASSIVE_LEVEL)
2798 _Must_inspect_result_
2799 NTSYSAPI
2800 NTSTATUS
2801 NTAPI
2802 RtlUTF8ToUnicodeN(
2803   _Out_writes_bytes_to_(UnicodeStringMaxByteCount, *UnicodeStringActualByteCount) PWSTR UnicodeStringDestination,
2804   _In_ ULONG UnicodeStringMaxByteCount,
2805   _Out_ PULONG UnicodeStringActualByteCount,
2806   _In_reads_bytes_(UTF8StringByteCount) PCCH UTF8StringSource,
2807   _In_ ULONG UTF8StringByteCount);
2808 
2809 _IRQL_requires_max_(APC_LEVEL)
2810 NTSYSAPI
2811 NTSTATUS
2812 NTAPI
2813 RtlReplaceSidInSd(
2814   _Inout_ PSECURITY_DESCRIPTOR SecurityDescriptor,
2815   _In_ PSID OldSid,
2816   _In_ PSID NewSid,
2817   _Out_ ULONG *NumChanges);
2818 
2819 NTSYSAPI
2820 NTSTATUS
2821 NTAPI
2822 RtlCreateVirtualAccountSid(
2823   _In_ PCUNICODE_STRING Name,
2824   _In_ ULONG BaseSubAuthority,
2825   _Out_writes_bytes_(*SidLength) PSID Sid,
2826   _Inout_ PULONG SidLength);
2827 $endif (_NTIFS_)
2828 
2829 #endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
2830 
2831 $if (_WDMDDK_)
2832 
2833 #if !defined(MIDL_PASS)
2834 /* inline funftions */
2835 //DECLSPEC_DEPRECATED_DDK_WINXP
2836 static __inline
2837 LARGE_INTEGER
2838 NTAPI_INLINE
2839 RtlConvertLongToLargeInteger(
2840   _In_ LONG SignedInteger)
2841 {
2842   LARGE_INTEGER ret;
2843   ret.QuadPart = SignedInteger;
2844   return ret;
2845 }
2846 
2847 //DECLSPEC_DEPRECATED_DDK_WINXP
2848 static __inline
2849 LARGE_INTEGER
2850 NTAPI_INLINE
2851 RtlConvertUlongToLargeInteger(
2852   _In_ ULONG UnsignedInteger)
2853 {
2854   LARGE_INTEGER ret;
2855   ret.QuadPart = UnsignedInteger;
2856   return ret;
2857 }
2858 
2859 //DECLSPEC_DEPRECATED_DDK_WINXP
2860 static __inline
2861 LARGE_INTEGER
2862 NTAPI_INLINE
2863 RtlLargeIntegerShiftLeft(
2864   _In_ LARGE_INTEGER LargeInteger,
2865   _In_ CCHAR ShiftCount)
2866 {
2867   LARGE_INTEGER Result;
2868 
2869   Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
2870   return Result;
2871 }
2872 
2873 //DECLSPEC_DEPRECATED_DDK_WINXP
2874 static __inline
2875 LARGE_INTEGER
2876 NTAPI_INLINE
2877 RtlLargeIntegerShiftRight(
2878   _In_ LARGE_INTEGER LargeInteger,
2879   _In_ CCHAR ShiftCount)
2880 {
2881   LARGE_INTEGER Result;
2882 
2883   Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
2884   return Result;
2885 }
2886 
2887 //DECLSPEC_DEPRECATED_DDK
2888 static __inline
2889 ULONG
2890 NTAPI_INLINE
2891 RtlEnlargedUnsignedDivide(
2892   _In_ ULARGE_INTEGER Dividend,
2893   _In_ ULONG Divisor,
2894   _Out_opt_ PULONG Remainder)
2895 {
2896   if (Remainder)
2897     *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
2898   return (ULONG)(Dividend.QuadPart / Divisor);
2899 }
2900 
2901 //DECLSPEC_DEPRECATED_DDK
2902 static __inline
2903 LARGE_INTEGER
2904 NTAPI_INLINE
2905 RtlLargeIntegerNegate(
2906   _In_ LARGE_INTEGER Subtrahend)
2907 {
2908   LARGE_INTEGER Difference;
2909 
2910   Difference.QuadPart = -Subtrahend.QuadPart;
2911   return Difference;
2912 }
2913 
2914 //DECLSPEC_DEPRECATED_DDK
2915 static __inline
2916 LARGE_INTEGER
2917 NTAPI_INLINE
2918 RtlLargeIntegerSubtract(
2919   _In_ LARGE_INTEGER Minuend,
2920   _In_ LARGE_INTEGER Subtrahend)
2921 {
2922   LARGE_INTEGER Difference;
2923 
2924   Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
2925   return Difference;
2926 }
2927 
2928 //DECLSPEC_DEPRECATED_DDK
2929 static __inline
2930 LARGE_INTEGER
2931 NTAPI_INLINE
2932 RtlEnlargedUnsignedMultiply(
2933   _In_ ULONG Multiplicand,
2934   _In_ ULONG Multiplier)
2935 {
2936   LARGE_INTEGER ret;
2937   ret.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
2938   return ret;
2939 }
2940 
2941 //DECLSPEC_DEPRECATED_DDK
2942 static __inline
2943 LARGE_INTEGER
2944 NTAPI_INLINE
2945 RtlEnlargedIntegerMultiply(
2946   _In_ LONG Multiplicand,
2947   _In_ LONG Multiplier)
2948 {
2949   LARGE_INTEGER ret;
2950   ret.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
2951   return ret;
2952 }
2953 
2954 _At_(AnsiString->Buffer, _Post_equal_to_(Buffer))
2955 _At_(AnsiString->Length, _Post_equal_to_(0))
2956 _At_(AnsiString->MaximumLength, _Post_equal_to_(BufferSize))
2957 FORCEINLINE
2958 VOID
2959 RtlInitEmptyAnsiString(
2960   _Out_ PANSI_STRING AnsiString,
2961   _Pre_maybenull_ _Pre_readable_size_(BufferSize) __drv_aliasesMem PCHAR Buffer,
2962   _In_ USHORT BufferSize)
2963 {
2964   AnsiString->Length = 0;
2965   AnsiString->MaximumLength = BufferSize;
2966   AnsiString->Buffer = Buffer;
2967 }
2968 
2969 _At_(UnicodeString->Buffer, _Post_equal_to_(Buffer))
2970 _At_(UnicodeString->Length, _Post_equal_to_(0))
2971 _At_(UnicodeString->MaximumLength, _Post_equal_to_(BufferSize))
2972 FORCEINLINE
2973 VOID
2974 RtlInitEmptyUnicodeString(
2975     _Out_ PUNICODE_STRING UnicodeString,
2976     _Writable_bytes_(BufferSize)
2977     _When_(BufferSize != 0, _Notnull_)
2978     __drv_aliasesMem PWSTR Buffer,
2979     _In_ USHORT BufferSize)
2980 {
2981     UnicodeString->Length = 0;
2982     UnicodeString->MaximumLength = BufferSize;
2983     UnicodeString->Buffer = Buffer;
2984 }
2985 $endif (_WDMDDK_)
2986 
2987 #if defined(_AMD64_) || defined(_IA64_)
2988 
2989 $if (_WDMDDK_)
2990 
2991 static __inline
2992 LARGE_INTEGER
2993 NTAPI_INLINE
2994 RtlExtendedIntegerMultiply(
2995   _In_ LARGE_INTEGER Multiplicand,
2996   _In_ LONG Multiplier)
2997 {
2998   LARGE_INTEGER ret;
2999   ret.QuadPart = Multiplicand.QuadPart * Multiplier;
3000   return ret;
3001 }
3002 
3003 static __inline
3004 LARGE_INTEGER
3005 NTAPI_INLINE
3006 RtlExtendedLargeIntegerDivide(
3007   _In_ LARGE_INTEGER Dividend,
3008   _In_ ULONG Divisor,
3009   _Out_opt_ PULONG Remainder)
3010 {
3011   LARGE_INTEGER ret;
3012   ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
3013   if (Remainder)
3014     *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3015   return ret;
3016 }
3017 
3018 $endif (_WDMDDK_)
3019 
3020 $if (_NTDDK_)
3021 
3022 //DECLSPEC_DEPRECATED_DDK_WINXP
3023 FORCEINLINE
3024 LARGE_INTEGER
3025 NTAPI_INLINE
3026 RtlLargeIntegerDivide(
3027   _In_ LARGE_INTEGER Dividend,
3028   _In_ LARGE_INTEGER Divisor,
3029   _Out_opt_ PLARGE_INTEGER Remainder)
3030 {
3031   LARGE_INTEGER ret;
3032   ret.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
3033   if (Remainder)
3034     Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
3035   return ret;
3036 }
3037 
3038 #else
3039 
3040 #if (NTDDI_VERSION >= NTDDI_WIN2K)
3041 NTSYSAPI
3042 LARGE_INTEGER
3043 NTAPI
3044 RtlLargeIntegerDivide(
3045   _In_ LARGE_INTEGER Dividend,
3046   _In_ LARGE_INTEGER Divisor,
3047   _Out_opt_ PLARGE_INTEGER Remainder);
3048 #endif
3049 
3050 $endif (_NTDDK_)
3051 
3052 #endif /* defined(_AMD64_) || defined(_IA64_) */
3053 
3054 $if (_WDMDDK_)
3055 
3056 #if defined(_AMD64_)
3057 
3058 #define MultiplyHigh __mulh
3059 #define UnsignedMultiplyHigh __umulh
3060 
3061 //DECLSPEC_DEPRECATED_DDK
3062 static __inline
3063 LARGE_INTEGER
3064 NTAPI_INLINE
3065 RtlExtendedMagicDivide(
3066   _In_ LARGE_INTEGER Dividend,
3067   _In_ LARGE_INTEGER MagicDivisor,
3068   _In_ CCHAR ShiftCount)
3069 {
3070   LARGE_INTEGER ret;
3071   ULONG64 ret64;
3072   BOOLEAN Pos;
3073   Pos = (Dividend.QuadPart >= 0);
3074   ret64 = UnsignedMultiplyHigh(Pos ? Dividend.QuadPart : -Dividend.QuadPart,
3075                                MagicDivisor.QuadPart);
3076   ret64 >>= ShiftCount;
3077   ret.QuadPart = Pos ? ret64 : -(LONG64)ret64;
3078   return ret;
3079 }
3080 #endif
3081 
3082 //DECLSPEC_DEPRECATED_DDK
3083 static __inline
3084 LARGE_INTEGER
3085 NTAPI_INLINE
3086 RtlLargeIntegerAdd(
3087   _In_ LARGE_INTEGER Addend1,
3088   _In_ LARGE_INTEGER Addend2)
3089 {
3090   LARGE_INTEGER ret;
3091   ret.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
3092   return ret;
3093 }
3094 
3095 /* VOID
3096  * RtlLargeIntegerAnd(
3097  *     IN OUT LARGE_INTEGER Result,
3098  *     IN LARGE_INTEGER Source,
3099  *     IN LARGE_INTEGER Mask);
3100  */
3101 #define RtlLargeIntegerAnd(Result, Source, Mask) \
3102     Result.QuadPart = Source.QuadPart & Mask.QuadPart
3103 
3104 //DECLSPEC_DEPRECATED_DDK
3105 static __inline
3106 LARGE_INTEGER
3107 NTAPI_INLINE
3108 RtlLargeIntegerArithmeticShift(
3109   _In_ LARGE_INTEGER LargeInteger,
3110   _In_ CCHAR ShiftCount)
3111 {
3112   LARGE_INTEGER ret;
3113   ret.QuadPart = LargeInteger.QuadPart >> ShiftCount;
3114   return ret;
3115 }
3116 
3117 /* BOOLEAN
3118  * RtlLargeIntegerEqualTo(
3119  *     IN LARGE_INTEGER  Operand1,
3120  *     IN LARGE_INTEGER  Operand2);
3121  */
3122 #define RtlLargeIntegerEqualTo(X,Y) \
3123     (!(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)))
3124 
3125 FORCEINLINE
3126 PVOID
3127 RtlSecureZeroMemory(
3128   _Out_writes_bytes_all_(Size) PVOID Pointer,
3129   _In_ SIZE_T Size)
3130 {
3131   volatile char* vptr = (volatile char*)Pointer;
3132 #if defined(_M_AMD64)
3133   __stosb((PUCHAR)vptr, 0, Size);
3134 #else
3135   char * endptr = (char *)vptr + Size;
3136   while (vptr < endptr) {
3137     *vptr = 0; vptr++;
3138   }
3139 #endif
3140    return Pointer;
3141 }
3142 
3143 #if defined(_M_AMD64)
3144 _Must_inspect_result_
3145 FORCEINLINE
3146 BOOLEAN
3147 RtlCheckBit(
3148   _In_ PRTL_BITMAP BitMapHeader,
3149   _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitPosition)
3150 {
3151   return BitTest64((LONG64 CONST*)BitMapHeader->Buffer, (LONG64)BitPosition);
3152 }
3153 #else
3154 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP)/32]) >> ((BP)%32)) & 0x1)
3155 #endif /* defined(_M_AMD64) */
3156 
3157 #define RtlLargeIntegerGreaterThan(X,Y) (                              \
3158     (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
3159     ((X).HighPart > (Y).HighPart)                                      \
3160 )
3161 
3162 #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) (                      \
3163     (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
3164     ((X).HighPart > (Y).HighPart)                                       \
3165 )
3166 
3167 #define RtlLargeIntegerNotEqualTo(X,Y) (                          \
3168     (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
3169 )
3170 
3171 #define RtlLargeIntegerLessThan(X,Y) (                                 \
3172     (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
3173     ((X).HighPart < (Y).HighPart)                                      \
3174 )
3175 
3176 #define RtlLargeIntegerLessThanOrEqualTo(X,Y) (                         \
3177     (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
3178     ((X).HighPart < (Y).HighPart)                                       \
3179 )
3180 
3181 #define RtlLargeIntegerGreaterThanZero(X) (       \
3182     (((X).HighPart == 0) && ((X).LowPart > 0)) || \
3183     ((X).HighPart > 0 )                           \
3184 )
3185 
3186 #define RtlLargeIntegerGreaterOrEqualToZero(X) ( (X).HighPart >= 0 )
3187 
3188 #define RtlLargeIntegerEqualToZero(X) ( !((X).LowPart | (X).HighPart) )
3189 
3190 #define RtlLargeIntegerNotEqualToZero(X) ( ((X).LowPart | (X).HighPart) )
3191 
3192 #define RtlLargeIntegerLessThanZero(X) ( ((X).HighPart < 0) )
3193 
3194 #define RtlLargeIntegerLessOrEqualToZero(X) ( ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) )
3195 
3196 #endif /* !defined(MIDL_PASS) */
3197 
3198 /* Byte Swap Functions */
3199 #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
3200 #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
3201 #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
3202 
3203 #if defined(_MSC_VER) && !defined(__clang__)
3204 # define __assert_annotationA(msg) __annotation(L"Debug", L"AssertFail", L ## msg)
3205 # define __assert_annotationW(msg) __annotation(L"Debug", L"AssertFail", msg)
3206 #else
3207 # define __assert_annotationA(msg) \
3208     DbgPrint("Assertion failed at %s(%d): %s\n", __FILE__, __LINE__, msg)
3209 # define __assert_annotationW(msg) \
3210     DbgPrint("Assertion failed at %s(%d): %S\n", __FILE__, __LINE__, msg)
3211 #endif
3212 
3213 #ifdef _PREFAST_
3214 # define NT_ANALYSIS_ASSUME(_exp) _Analysis_assume_(_exp)
3215 #elif DBG
3216 # define NT_ANALYSIS_ASSUME(_exp) ((void)0)
3217 #else
3218 # define NT_ANALYSIS_ASSUME(_exp) __noop(_exp)
3219 #endif
3220 
3221 #define NT_ASSERT_ACTION(exp) \
3222    (NT_ANALYSIS_ASSUME(exp), \
3223    ((!(exp)) ? \
3224       (__assert_annotationA(#exp), \
3225        DbgRaiseAssertionFailure(), FALSE) : TRUE))
3226 
3227 #define NT_ASSERTMSG_ACTION(msg, exp) \
3228    (NT_ANALYSIS_ASSUME(exp), \
3229    ((!(exp)) ? \
3230       (__assert_annotationA(msg), \
3231        DbgRaiseAssertionFailure(), FALSE) : TRUE))
3232 
3233 #define NT_ASSERTMSGW_ACTION(msg, exp) \
3234    (NT_ANALYSIS_ASSUME(exp), \
3235    ((!(exp)) ? \
3236       (__assert_annotationW(msg), \
3237        DbgRaiseAssertionFailure(), FALSE) : TRUE))
3238 
3239 #if DBG
3240 
3241 #define RTL_VERIFY(exp) \
3242   ((!(exp)) ? \
3243     RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)
3244 
3245 #define RTL_VERIFYMSG(msg, exp) \
3246   ((!(exp)) ? \
3247     RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, (PCHAR)msg ), FALSE : TRUE)
3248 
3249 #define RTL_SOFT_VERIFY(exp) \
3250   ((!(exp)) ? \
3251     DbgPrint("%s(%d): Soft assertion failed\n   Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE)
3252 
3253 #define RTL_SOFT_VERIFYMSG(msg, exp) \
3254   ((!(exp)) ? \
3255     DbgPrint("%s(%d): Soft assertion failed\n   Expression: %s\n   Message: %s\n", __FILE__, __LINE__, #exp, (msg)), FALSE : TRUE)
3256 
3257 /* The ASSERTs must be cast to void to avoid warnings about unused results. */
3258 #define ASSERT                 (void)RTL_VERIFY
3259 #define ASSERTMSG              (void)RTL_VERIFYMSG
3260 #define RTL_SOFT_ASSERT        (void)RTL_SOFT_VERIFY
3261 #define RTL_SOFT_ASSERTMSG     (void)RTL_SOFT_VERIFYMSG
3262 
3263 #define NT_VERIFY              NT_ASSERT_ACTION
3264 #define NT_VERIFYMSG           NT_ASSERTMSG_ACTION
3265 #define NT_VERIFYMSGW          NT_ASSERTMSGW_ACTION
3266 
3267 #define NT_ASSERT_ASSUME       (void)NT_ASSERT_ACTION
3268 #define NT_ASSERTMSG_ASSUME    (void)NT_ASSERTMSG_ACTION
3269 #define NT_ASSERTMSGW_ASSUME   (void)NT_ASSERTMSGW_ACTION
3270 
3271 #define NT_ASSERT_NOASSUME     (void)NT_ASSERT_ACTION
3272 #define NT_ASSERTMSG_NOASSUME  (void)NT_ASSERTMSG_ACTION
3273 #define NT_ASSERTMSGW_NOASSUME (void)NT_ASSERTMSGW_ACTION
3274 
3275 #else /* !DBG */
3276 
3277 #define ASSERT(exp)                  ((void)0)
3278 #define ASSERTMSG(msg, exp)          ((void)0)
3279 
3280 #define RTL_SOFT_ASSERT(exp)         ((void)0)
3281 #define RTL_SOFT_ASSERTMSG(msg, exp) ((void)0)
3282 
3283 #define RTL_VERIFY(exp)              ((exp) ? TRUE : FALSE)
3284 #define RTL_VERIFYMSG(msg, exp)      ((exp) ? TRUE : FALSE)
3285 
3286 #define RTL_SOFT_VERIFY(exp)         ((exp) ? TRUE : FALSE)
3287 #define RTL_SOFT_VERIFYMSG(msg, exp) ((exp) ? TRUE : FALSE)
3288 
3289 #define NT_VERIFY(exp)          (NT_ANALYSIS_ASSUME(exp), ((exp) ? TRUE : FALSE))
3290 #define NT_VERIFYMSG(msg, exp)  (NT_ANALYSIS_ASSUME(exp), ((exp) ? TRUE : FALSE))
3291 #define NT_VERIFYMSGW(msg, exp) (NT_ANALYSIS_ASSUME(exp), ((exp) ? TRUE : FALSE))
3292 
3293 #define NT_ASSERT_ASSUME(exp)          (NT_ANALYSIS_ASSUME(exp), (void)0)
3294 #define NT_ASSERTMSG_ASSUME(msg, exp)  (NT_ANALYSIS_ASSUME(exp), (void)0)
3295 #define NT_ASSERTMSGW_ASSUME(msg, exp) (NT_ANALYSIS_ASSUME(exp), (void)0)
3296 
3297 #define NT_ASSERT_NOASSUME(exp)          ((void)0)
3298 #define NT_ASSERTMSG_NOASSUME(msg, exp)  ((void)0)
3299 #define NT_ASSERTMSGW_NOASSUME(msg, exp) ((void)0)
3300 
3301 #endif /* DBG */
3302 
3303 #define NT_FRE_ASSERT     (void)NT_ASSERT_ACTION
3304 #define NT_FRE_ASSERTMSG  (void)NT_ASSERTMSG_ACTION
3305 #define NT_FRE_ASSERTMSGW (void)NT_ASSERTMSGW_ACTION
3306 
3307 #ifdef NT_ASSERT_ALWAYS_ASSUMES
3308 # define NT_ASSERT NT_ASSERT_ASSUME
3309 # define NT_ASSERTMSG NT_ASSERTMSG_ASSUME
3310 # define NT_ASSERTMSGW NT_ASSERTMSGW_ASSUME
3311 #else
3312 # define NT_ASSERT NT_ASSERT_NOASSUME
3313 # define NT_ASSERTMSG NT_ASSERTMSG_NOASSUME
3314 # define NT_ASSERTMSGW NT_ASSERTMSGW_NOASSUME
3315 #endif /* NT_ASSERT_ALWAYS_ASSUMES */
3316 
3317 #if defined(_MSC_VER) && (defined(__REACTOS__) || defined(ASSERT_ALWAYS_NT_ASSERT)) && !defined(_BLDR_)
3318 #undef ASSERT
3319 #define ASSERT NT_ASSERT
3320 #undef ASSERTMSG
3321 #define ASSERTMSG NT_ASSERTMSG
3322 #undef ASSERTMSGW
3323 #define ASSERTMSGW NT_ASSERTMSGW
3324 #undef RTL_VERIFY
3325 #define RTL_VERIFY NT_VERIFY
3326 #endif
3327 
3328 #define InitializeListHead32(ListHead) (\
3329     (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
3330 
3331 #if !defined(_WINBASE_)
3332 
3333 #if defined(_WIN64) && !defined(_NTSYSTEM_) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || !defined(_NTOSP_))
3334 
3335 NTKERNELAPI
3336 VOID
3337 InitializeSListHead(
3338   _Out_ PSLIST_HEADER SListHead);
3339 
3340 #else /* defined(_WIN64) &&  ... */
3341 
3342 /* HACK */
3343 _IRQL_requires_max_(APC_LEVEL)
3344 NTKERNELAPI
3345 DECLSPEC_NORETURN
3346 VOID
3347 NTAPI
3348 ExRaiseStatus(
3349   _In_ NTSTATUS Status);
3350 
3351 FORCEINLINE
3352 VOID
3353 InitializeSListHead(
3354   _Out_ PSLIST_HEADER SListHead)
3355 {
3356 #if defined(_WIN64)
3357     if (((ULONG_PTR)SListHead & 0xf) != 0) {
3358         ExRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
3359     }
3360 #if defined(_IA64_)
3361     SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
3362 #else
3363     SListHead->Region = 0;
3364 #endif /* _IA64_ */
3365 #endif /* _WIN64 */
3366     SListHead->Alignment = 0;
3367 }
3368 
3369 #endif /* defined(_WIN64) &&  ... */
3370 
3371 #ifdef _X86_
3372 
3373 NTKERNELAPI
3374 PSLIST_ENTRY
3375 FASTCALL
3376 InterlockedPushEntrySList(
3377   _Inout_ PSLIST_HEADER SListHead,
3378   _Inout_ __drv_aliasesMem PSLIST_ENTRY SListEntry);
3379 
3380 NTKERNELAPI
3381 PSLIST_ENTRY
3382 FASTCALL
3383 InterlockedPopEntrySList(
3384   _Inout_ PSLIST_HEADER SListHead);
3385 
3386 #define InterlockedFlushSList(SListHead) \
3387     ExInterlockedFlushSList(SListHead)
3388 
3389 #else /* !_X86_ */
3390 
3391 #define InterlockedPushEntrySList(SListHead, SListEntry) \
3392     ExpInterlockedPushEntrySList(SListHead, SListEntry)
3393 
3394 #define InterlockedPopEntrySList(SListHead) \
3395     ExpInterlockedPopEntrySList(SListHead)
3396 
3397 #define InterlockedFlushSList(SListHead) \
3398     ExpInterlockedFlushSList(SListHead)
3399 
3400 #endif /* _X86_ */
3401 
3402 #define QueryDepthSList(SListHead) \
3403     ExQueryDepthSList(SListHead)
3404 
3405 #endif /* !defined(_WINBASE_) */
3406 
3407 #define RTL_CONTEXT_EX_OFFSET(ContextEx, Chunk) ((ContextEx)->Chunk.Offset)
3408 #define RTL_CONTEXT_EX_LENGTH(ContextEx, Chunk) ((ContextEx)->Chunk.Length)
3409 #define RTL_CONTEXT_EX_CHUNK(Base, Layout, Chunk)       \
3410     ((PVOID)((PCHAR)(Base) + RTL_CONTEXT_EX_OFFSET(Layout, Chunk)))
3411 #define RTL_CONTEXT_OFFSET(Context, Chunk)              \
3412     RTL_CONTEXT_EX_OFFSET((PCONTEXT_EX)(Context + 1), Chunk)
3413 #define RTL_CONTEXT_LENGTH(Context, Chunk)              \
3414     RTL_CONTEXT_EX_LENGTH((PCONTEXT_EX)(Context + 1), Chunk)
3415 #define RTL_CONTEXT_CHUNK(Context, Chunk)               \
3416     RTL_CONTEXT_EX_CHUNK((PCONTEXT_EX)(Context + 1),    \
3417                          (PCONTEXT_EX)(Context + 1),    \
3418                          Chunk)
3419 
3420 BOOLEAN
3421 RTLVERLIB_DDI(RtlIsNtDdiVersionAvailable)(
3422   _In_ ULONG Version);
3423 
3424 BOOLEAN
3425 RTLVERLIB_DDI(RtlIsServicePackVersionInstalled)(
3426   _In_ ULONG Version);
3427 
3428 #ifndef RtlIsNtDdiVersionAvailable
3429 #define RtlIsNtDdiVersionAvailable WdmlibRtlIsNtDdiVersionAvailable
3430 #endif
3431 
3432 #ifndef RtlIsServicePackVersionInstalled
3433 #define RtlIsServicePackVersionInstalled WdmlibRtlIsServicePackVersionInstalled
3434 #endif
3435 
3436 #define RtlInterlockedSetBits(Flags, Flag) \
3437     InterlockedOr((PLONG)(Flags), Flag)
3438 
3439 #define RtlInterlockedAndBits(Flags, Flag) \
3440     InterlockedAnd((PLONG)(Flags), Flag)
3441 
3442 #define RtlInterlockedClearBits(Flags, Flag) \
3443     RtlInterlockedAndBits(Flags, ~(Flag))
3444 
3445 #define RtlInterlockedXorBits(Flags, Flag) \
3446     InterlockedXor(Flags, Flag)
3447 
3448 #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
3449     (VOID) RtlInterlockedSetBits(Flags, Flag)
3450 
3451 #define RtlInterlockedAndBitsDiscardReturn(Flags, Flag) \
3452     (VOID) RtlInterlockedAndBits(Flags, Flag)
3453 
3454 #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
3455     RtlInterlockedAndBitsDiscardReturn(Flags, ~(Flag))
3456 
3457 $endif (_WDMDDK_)
3458 
3459 $if (_NTDDK_)
3460 
3461 #ifdef RTL_USE_AVL_TABLES
3462 
3463 #define RtlInitializeGenericTable               RtlInitializeGenericTableAvl
3464 #define RtlInsertElementGenericTable            RtlInsertElementGenericTableAvl
3465 #define RtlInsertElementGenericTableFull        RtlInsertElementGenericTableFullAvl
3466 #define RtlDeleteElementGenericTable            RtlDeleteElementGenericTableAvl
3467 #define RtlLookupElementGenericTable            RtlLookupElementGenericTableAvl
3468 #define RtlLookupElementGenericTableFull        RtlLookupElementGenericTableFullAvl
3469 #define RtlEnumerateGenericTable                RtlEnumerateGenericTableAvl
3470 #define RtlEnumerateGenericTableWithoutSplaying RtlEnumerateGenericTableWithoutSplayingAvl
3471 #define RtlGetElementGenericTable               RtlGetElementGenericTableAvl
3472 #define RtlNumberGenericTableElements           RtlNumberGenericTableElementsAvl
3473 #define RtlIsGenericTableEmpty                  RtlIsGenericTableEmptyAvl
3474 
3475 #endif /* RTL_USE_AVL_TABLES */
3476 
3477 #define RtlInitializeSplayLinks(Links) {    \
3478   PRTL_SPLAY_LINKS _SplayLinks;            \
3479   _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
3480   _SplayLinks->Parent = _SplayLinks;   \
3481   _SplayLinks->LeftChild = NULL;       \
3482   _SplayLinks->RightChild = NULL;      \
3483 }
3484 
3485 #define RtlIsLeftChild(Links) \
3486     (RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links))
3487 
3488 #define RtlIsRightChild(Links) \
3489     (RtlRightChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links))
3490 
3491 #define RtlRightChild(Links) \
3492     ((PRTL_SPLAY_LINKS)(Links))->RightChild
3493 
3494 #define RtlIsRoot(Links) \
3495     (RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links))
3496 
3497 #define RtlLeftChild(Links) \
3498     ((PRTL_SPLAY_LINKS)(Links))->LeftChild
3499 
3500 #define RtlParent(Links) \
3501     ((PRTL_SPLAY_LINKS)(Links))->Parent
3502 
3503 #define RtlInsertAsLeftChild(ParentLinks,ChildLinks)    \
3504     {                                                   \
3505         PRTL_SPLAY_LINKS _SplayParent;                  \
3506         PRTL_SPLAY_LINKS _SplayChild;                   \
3507         _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
3508         _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks);   \
3509         _SplayParent->LeftChild = _SplayChild;          \
3510         _SplayChild->Parent = _SplayParent;             \
3511     }
3512 
3513 #define RtlInsertAsRightChild(ParentLinks,ChildLinks)   \
3514     {                                                   \
3515         PRTL_SPLAY_LINKS _SplayParent;                  \
3516         PRTL_SPLAY_LINKS _SplayChild;                   \
3517         _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
3518         _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks);   \
3519         _SplayParent->RightChild = _SplayChild;         \
3520         _SplayChild->Parent = _SplayParent;             \
3521     }
3522 
3523 #if !defined(MIDL_PASS)
3524 
3525 FORCEINLINE
3526 LUID
3527 NTAPI_INLINE
3528 RtlConvertLongToLuid(
3529   _In_ LONG Val)
3530 {
3531   LUID Luid;
3532   LARGE_INTEGER Temp;
3533 
3534   Temp.QuadPart = Val;
3535   Luid.LowPart = Temp.u.LowPart;
3536   Luid.HighPart = Temp.u.HighPart;
3537   return Luid;
3538 }
3539 
3540 FORCEINLINE
3541 LUID
3542 NTAPI_INLINE
3543 RtlConvertUlongToLuid(
3544   _In_ ULONG Val)
3545 {
3546   LUID Luid;
3547 
3548   Luid.LowPart = Val;
3549   Luid.HighPart = 0;
3550   return Luid;
3551 }
3552 
3553 #endif /* !defined(MIDL_PASS) */
3554 
3555 #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
3556 #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
3557     *CallersAddress = (PVOID)_ReturnAddress(); \
3558     *CallersCaller = NULL;
3559 #else
3560 #if (NTDDI_VERSION >= NTDDI_WIN2K)
3561 NTSYSAPI
3562 VOID
3563 NTAPI
3564 RtlGetCallersAddress(
3565   _Out_ PVOID *CallersAddress,
3566   _Out_ PVOID *CallersCaller);
3567 #endif
3568 #endif
3569 
3570 #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
3571 
3572 #if (NTDDI_VERSION >= NTDDI_WIN7)
3573 
3574 FORCEINLINE
3575 VOID
3576 NTAPI
3577 RtlInitHashTableContext(
3578   _Inout_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context)
3579 {
3580   Context->ChainHead = NULL;
3581   Context->PrevLinkage = NULL;
3582 }
3583 
3584 FORCEINLINE
3585 VOID
3586 NTAPI
3587 RtlInitHashTableContextFromEnumerator(
3588   _Inout_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context,
3589   _In_ PRTL_DYNAMIC_HASH_TABLE_ENUMERATOR Enumerator)
3590 {
3591   Context->ChainHead = Enumerator->ChainHead;
3592   Context->PrevLinkage = Enumerator->HashEntry.Linkage.Blink;
3593 }
3594 
3595 FORCEINLINE
3596 VOID
3597 NTAPI
3598 RtlReleaseHashTableContext(
3599   _Inout_ PRTL_DYNAMIC_HASH_TABLE_CONTEXT Context)
3600 {
3601   UNREFERENCED_PARAMETER(Context);
3602   return;
3603 }
3604 
3605 FORCEINLINE
3606 ULONG
3607 NTAPI
3608 RtlTotalBucketsHashTable(
3609   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable)
3610 {
3611   return HashTable->TableSize;
3612 }
3613 
3614 FORCEINLINE
3615 ULONG
3616 NTAPI
3617 RtlNonEmptyBucketsHashTable(
3618   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable)
3619 {
3620   return HashTable->NonEmptyBuckets;
3621 }
3622 
3623 FORCEINLINE
3624 ULONG
3625 NTAPI
3626 RtlEmptyBucketsHashTable(
3627   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable)
3628 {
3629   return HashTable->TableSize - HashTable->NonEmptyBuckets;
3630 }
3631 
3632 FORCEINLINE
3633 ULONG
3634 NTAPI
3635 RtlTotalEntriesHashTable(
3636   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable)
3637 {
3638   return HashTable->NumEntries;
3639 }
3640 
3641 FORCEINLINE
3642 ULONG
3643 NTAPI
3644 RtlActiveEnumeratorsHashTable(
3645   _In_ PRTL_DYNAMIC_HASH_TABLE HashTable)
3646 {
3647   return HashTable->NumEnumerators;
3648 }
3649 
3650 #endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
3651 
3652 #endif /* !defined(MIDL_PASS) && !defined(SORTPP_PASS) */
3653 
3654 $endif (_NTDDK_)
3655 $if (_NTIFS_)
3656 
3657 #define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE 1
3658 #define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING 2
3659 
3660 #define RtlUnicodeStringToOemSize(STRING) (NLS_MB_OEM_CODE_PAGE_TAG ?                                \
3661                                            RtlxUnicodeStringToOemSize(STRING) :                      \
3662                                            ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
3663 )
3664 
3665 #define RtlOemStringToUnicodeSize(STRING) (                 \
3666     NLS_MB_OEM_CODE_PAGE_TAG ?                              \
3667     RtlxOemStringToUnicodeSize(STRING) :                    \
3668     ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR)  \
3669 )
3670 
3671 #define RtlOemStringToCountedUnicodeSize(STRING) (                    \
3672     (ULONG)(RtlOemStringToUnicodeSize(STRING) - sizeof(UNICODE_NULL)) \
3673 )
3674 
3675 #define RtlOffsetToPointer(B,O) ((PCHAR)(((PCHAR)(B)) + ((ULONG_PTR)(O))))
3676 #define RtlPointerToOffset(B,P) ((ULONG)(((PCHAR)(P)) - ((PCHAR)(B))))
3677 $endif (_NTIFS_)
3678