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