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