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