Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7922 lines
184 KiB

  1. /*++ BUILD Version: 0005 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntrtl.h
  5. Abstract:
  6. Include file for NT runtime routines that are callable by both
  7. kernel mode code in the executive and user mode code in various
  8. NT subsystems.
  9. Author:
  10. Steve Wood (stevewo) 31-Mar-1989
  11. Environment:
  12. These routines are dynamically linked in the caller's executable and
  13. are callable in either kernel mode or user mode.
  14. Revision History:
  15. --*/
  16. #ifndef _NTRTL_
  17. #define _NTRTL_
  18. #if defined (_MSC_VER)
  19. #if ( _MSC_VER >= 800 )
  20. #pragma warning(disable:4514)
  21. #if _MSC_VER >= 1200
  22. #pragma warning(push)
  23. #endif
  24. #pragma warning(disable:4001)
  25. #pragma warning(disable:4201)
  26. #pragma warning(disable:4214)
  27. #endif
  28. #if (_MSC_VER > 1020)
  29. #pragma once
  30. #endif
  31. #endif
  32. // begin_ntddk begin_wdm begin_winnt begin_ntifs begin_nthal
  33. //
  34. // for move macros
  35. //
  36. #ifdef _MAC
  37. #ifndef _INC_STRING
  38. #include <string.h>
  39. #endif /* _INC_STRING */
  40. #else
  41. #include <string.h>
  42. #endif // _MAC
  43. // end_ntddk end_wdm end_winnt end_ntifs end_nthal
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. //
  48. // Inverted runtime function table support.
  49. //
  50. // These routines are called by kernel and user code and are not exported.
  51. //
  52. #if defined(_AMD64_) || defined(_IA64_)
  53. #define MAXIMUM_INVERTED_FUNCTION_TABLE_SIZE 160
  54. typedef struct _INVERTED_FUNCTION_TABLE_ENTRY {
  55. PRUNTIME_FUNCTION FunctionTable;
  56. PVOID ImageBase;
  57. ULONG SizeOfImage;
  58. ULONG SizeOfTable;
  59. #if defined(_IA64_)
  60. ULONG64 Gp;
  61. #endif
  62. } INVERTED_FUNCTION_TABLE_ENTRY, *PINVERTED_FUNCTION_TABLE_ENTRY;
  63. typedef struct _INVERTED_FUNCTION_TABLE {
  64. ULONG CurrentSize;
  65. ULONG MaximumSize;
  66. BOOLEAN Overflow;
  67. INVERTED_FUNCTION_TABLE_ENTRY TableEntry[MAXIMUM_INVERTED_FUNCTION_TABLE_SIZE];
  68. } INVERTED_FUNCTION_TABLE, *PINVERTED_FUNCTION_TABLE;
  69. VOID
  70. RtlInsertInvertedFunctionTable (
  71. PINVERTED_FUNCTION_TABLE InvertedTable,
  72. PVOID ImageBase,
  73. ULONG SizeOfImage
  74. );
  75. VOID
  76. RtlRemoveInvertedFunctionTable (
  77. PINVERTED_FUNCTION_TABLE InvertedTable,
  78. PVOID ImageBase
  79. );
  80. #endif // defined(_AMD64_) || defined(_IA64_)
  81. //
  82. // Define interlocked sequenced list structure.
  83. //
  84. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis begin_ntosp begin_winnt
  85. #ifndef _SLIST_HEADER_
  86. #define _SLIST_HEADER_
  87. #if defined(_WIN64)
  88. //
  89. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  90. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  91. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  92. //
  93. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  94. // SINGLE_LIST_ENTRY type.
  95. //
  96. #pragma warning(push)
  97. #pragma warning(disable:4324) // structure padded due to align()
  98. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  99. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  100. PSLIST_ENTRY Next;
  101. } SLIST_ENTRY;
  102. #pragma warning(pop)
  103. #else
  104. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  105. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  106. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  107. #endif
  108. #if defined(_WIN64)
  109. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  110. ULONGLONG Alignment;
  111. ULONGLONG Region;
  112. } SLIST_HEADER;
  113. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  114. #else
  115. typedef union _SLIST_HEADER {
  116. ULONGLONG Alignment;
  117. struct {
  118. SLIST_ENTRY Next;
  119. USHORT Depth;
  120. USHORT Sequence;
  121. };
  122. } SLIST_HEADER, *PSLIST_HEADER;
  123. #endif
  124. #endif
  125. // end_ntddk end_wdm end_nthal end_ntifs end_ntndis end_ntosp end_winnt
  126. VOID
  127. RtlMakeStackTraceDataPresent(
  128. VOID
  129. );
  130. // begin_winnt
  131. NTSYSAPI
  132. VOID
  133. NTAPI
  134. RtlInitializeSListHead (
  135. IN PSLIST_HEADER ListHead
  136. );
  137. NTSYSAPI
  138. PSLIST_ENTRY
  139. RtlFirstEntrySList (
  140. IN const SLIST_HEADER *ListHead
  141. );
  142. NTSYSAPI
  143. PSLIST_ENTRY
  144. NTAPI
  145. RtlInterlockedPopEntrySList (
  146. IN PSLIST_HEADER ListHead
  147. );
  148. NTSYSAPI
  149. PSLIST_ENTRY
  150. NTAPI
  151. RtlInterlockedPushEntrySList (
  152. IN PSLIST_HEADER ListHead,
  153. IN PSLIST_ENTRY ListEntry
  154. );
  155. NTSYSAPI
  156. PSLIST_ENTRY
  157. NTAPI
  158. RtlInterlockedFlushSList (
  159. IN PSLIST_HEADER ListHead
  160. );
  161. NTSYSAPI
  162. USHORT
  163. NTAPI
  164. RtlQueryDepthSList (
  165. IN PSLIST_HEADER ListHead
  166. );
  167. // end_winnt
  168. PSLIST_ENTRY
  169. FASTCALL
  170. RtlInterlockedPushListSList (
  171. IN PSLIST_HEADER ListHead,
  172. IN PSLIST_ENTRY List,
  173. IN PSLIST_ENTRY ListEnd,
  174. IN ULONG Count
  175. );
  176. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis
  177. //
  178. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  179. // define the ASSERT macro to expand to an empty expression.
  180. //
  181. // The ASSERT macro has been updated to be an expression instead of a statement.
  182. //
  183. NTSYSAPI
  184. VOID
  185. NTAPI
  186. RtlAssert(
  187. PVOID FailedAssertion,
  188. PVOID FileName,
  189. ULONG LineNumber,
  190. PCHAR Message
  191. );
  192. #if DBG
  193. #define ASSERT( exp ) \
  194. ((!(exp)) ? \
  195. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  196. TRUE)
  197. #define ASSERTMSG( msg, exp ) \
  198. ((!(exp)) ? \
  199. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  200. TRUE)
  201. #define RTL_SOFT_ASSERT(_exp) \
  202. ((!(_exp)) ? \
  203. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  204. TRUE)
  205. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  206. ((!(_exp)) ? \
  207. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  208. TRUE)
  209. #define RTL_VERIFY ASSERT
  210. #define RTL_VERIFYMSG ASSERTMSG
  211. #define RTL_SOFT_VERIFY RTL_SOFT_ASSERT
  212. #define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG
  213. #else
  214. #define ASSERT( exp ) ((void) 0)
  215. #define ASSERTMSG( msg, exp ) ((void) 0)
  216. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  217. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  218. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  219. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  220. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  221. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  222. #endif // DBG
  223. // end_ntddk end_wdm end_nthal end_ntifs end_ntndis
  224. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis
  225. //
  226. // Doubly-linked list manipulation routines.
  227. //
  228. //
  229. // VOID
  230. // InitializeListHead32(
  231. // PLIST_ENTRY32 ListHead
  232. // );
  233. //
  234. #define InitializeListHead32(ListHead) (\
  235. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  236. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  237. VOID
  238. FORCEINLINE
  239. InitializeListHead(
  240. IN PLIST_ENTRY ListHead
  241. )
  242. {
  243. ListHead->Flink = ListHead->Blink = ListHead;
  244. }
  245. //
  246. // BOOLEAN
  247. // IsListEmpty(
  248. // PLIST_ENTRY ListHead
  249. // );
  250. //
  251. #define IsListEmpty(ListHead) \
  252. ((ListHead)->Flink == (ListHead))
  253. BOOLEAN
  254. FORCEINLINE
  255. RemoveEntryList(
  256. IN PLIST_ENTRY Entry
  257. )
  258. {
  259. PLIST_ENTRY Blink;
  260. PLIST_ENTRY Flink;
  261. Flink = Entry->Flink;
  262. Blink = Entry->Blink;
  263. Blink->Flink = Flink;
  264. Flink->Blink = Blink;
  265. return (BOOLEAN)(Flink == Blink);
  266. }
  267. PLIST_ENTRY
  268. FORCEINLINE
  269. RemoveHeadList(
  270. IN PLIST_ENTRY ListHead
  271. )
  272. {
  273. PLIST_ENTRY Flink;
  274. PLIST_ENTRY Entry;
  275. Entry = ListHead->Flink;
  276. Flink = Entry->Flink;
  277. ListHead->Flink = Flink;
  278. Flink->Blink = ListHead;
  279. return Entry;
  280. }
  281. PLIST_ENTRY
  282. FORCEINLINE
  283. RemoveTailList(
  284. IN PLIST_ENTRY ListHead
  285. )
  286. {
  287. PLIST_ENTRY Blink;
  288. PLIST_ENTRY Entry;
  289. Entry = ListHead->Blink;
  290. Blink = Entry->Blink;
  291. ListHead->Blink = Blink;
  292. Blink->Flink = ListHead;
  293. return Entry;
  294. }
  295. VOID
  296. FORCEINLINE
  297. InsertTailList(
  298. IN PLIST_ENTRY ListHead,
  299. IN PLIST_ENTRY Entry
  300. )
  301. {
  302. PLIST_ENTRY Blink;
  303. Blink = ListHead->Blink;
  304. Entry->Flink = ListHead;
  305. Entry->Blink = Blink;
  306. Blink->Flink = Entry;
  307. ListHead->Blink = Entry;
  308. }
  309. VOID
  310. FORCEINLINE
  311. InsertHeadList(
  312. IN PLIST_ENTRY ListHead,
  313. IN PLIST_ENTRY Entry
  314. )
  315. {
  316. PLIST_ENTRY Flink;
  317. Flink = ListHead->Flink;
  318. Entry->Flink = Flink;
  319. Entry->Blink = ListHead;
  320. Flink->Blink = Entry;
  321. ListHead->Flink = Entry;
  322. }
  323. //
  324. //
  325. // PSINGLE_LIST_ENTRY
  326. // PopEntryList(
  327. // PSINGLE_LIST_ENTRY ListHead
  328. // );
  329. //
  330. #define PopEntryList(ListHead) \
  331. (ListHead)->Next;\
  332. {\
  333. PSINGLE_LIST_ENTRY FirstEntry;\
  334. FirstEntry = (ListHead)->Next;\
  335. if (FirstEntry != NULL) { \
  336. (ListHead)->Next = FirstEntry->Next;\
  337. } \
  338. }
  339. //
  340. // VOID
  341. // PushEntryList(
  342. // PSINGLE_LIST_ENTRY ListHead,
  343. // PSINGLE_LIST_ENTRY Entry
  344. // );
  345. //
  346. #define PushEntryList(ListHead,Entry) \
  347. (Entry)->Next = (ListHead)->Next; \
  348. (ListHead)->Next = (Entry)
  349. #endif // !MIDL_PASS
  350. // end_wdm end_nthal end_ntifs end_ntndis
  351. // end_ntddk
  352. // begin_ntifs
  353. //
  354. // This enumerated type is used as the function return value of the function
  355. // that is used to search the tree for a key. FoundNode indicates that the
  356. // function found the key. Insert as left indicates that the key was not found
  357. // and the node should be inserted as the left child of the parent. Insert as
  358. // right indicates that the key was not found and the node should be inserted
  359. // as the right child of the parent.
  360. //
  361. typedef enum _TABLE_SEARCH_RESULT{
  362. TableEmptyTree,
  363. TableFoundNode,
  364. TableInsertAsLeft,
  365. TableInsertAsRight
  366. } TABLE_SEARCH_RESULT;
  367. //
  368. // The results of a compare can be less than, equal, or greater than.
  369. //
  370. typedef enum _RTL_GENERIC_COMPARE_RESULTS {
  371. GenericLessThan,
  372. GenericGreaterThan,
  373. GenericEqual
  374. } RTL_GENERIC_COMPARE_RESULTS;
  375. //
  376. // Define the Avl version of the generic table package. Note a generic table
  377. // should really be an opaque type. We provide routines to manipulate the structure.
  378. //
  379. // A generic table is package for inserting, deleting, and looking up elements
  380. // in a table (e.g., in a symbol table). To use this package the user
  381. // defines the structure of the elements stored in the table, provides a
  382. // comparison function, a memory allocation function, and a memory
  383. // deallocation function.
  384. //
  385. // Note: the user compare function must impose a complete ordering among
  386. // all of the elements, and the table does not allow for duplicate entries.
  387. //
  388. //
  389. // Add an empty typedef so that functions can reference the
  390. // a pointer to the generic table struct before it is declared.
  391. //
  392. struct _RTL_AVL_TABLE;
  393. //
  394. // The comparison function takes as input pointers to elements containing
  395. // user defined structures and returns the results of comparing the two
  396. // elements.
  397. //
  398. typedef
  399. RTL_GENERIC_COMPARE_RESULTS
  400. (NTAPI *PRTL_AVL_COMPARE_ROUTINE) (
  401. struct _RTL_AVL_TABLE *Table,
  402. PVOID FirstStruct,
  403. PVOID SecondStruct
  404. );
  405. //
  406. // The allocation function is called by the generic table package whenever
  407. // it needs to allocate memory for the table.
  408. //
  409. typedef
  410. PVOID
  411. (NTAPI *PRTL_AVL_ALLOCATE_ROUTINE) (
  412. struct _RTL_AVL_TABLE *Table,
  413. CLONG ByteSize
  414. );
  415. //
  416. // The deallocation function is called by the generic table package whenever
  417. // it needs to deallocate memory from the table that was allocated by calling
  418. // the user supplied allocation function.
  419. //
  420. typedef
  421. VOID
  422. (NTAPI *PRTL_AVL_FREE_ROUTINE) (
  423. struct _RTL_AVL_TABLE *Table,
  424. PVOID Buffer
  425. );
  426. //
  427. // The match function takes as input the user data to be matched and a pointer
  428. // to some match data, which was passed along with the function pointer. It
  429. // returns TRUE for a match and FALSE for no match.
  430. //
  431. // RTL_AVL_MATCH_FUNCTION returns
  432. // STATUS_SUCCESS if the IndexRow matches
  433. // STATUS_NO_MATCH if the IndexRow does not match, but the enumeration should
  434. // continue
  435. // STATUS_NO_MORE_MATCHES if the IndexRow does not match, and the enumeration
  436. // should terminate
  437. //
  438. typedef
  439. NTSTATUS
  440. (NTAPI *PRTL_AVL_MATCH_FUNCTION) (
  441. struct _RTL_AVL_TABLE *Table,
  442. PVOID UserData,
  443. PVOID MatchData
  444. );
  445. //
  446. // Define the balanced tree links and Balance field. (No Rank field
  447. // defined at this time.)
  448. //
  449. // Callers should treat this structure as opaque!
  450. //
  451. // The root of a balanced binary tree is not a real node in the tree
  452. // but rather points to a real node which is the root. It is always
  453. // in the table below, and its fields are used as follows:
  454. //
  455. // Parent Pointer to self, to allow for detection of the root.
  456. // LeftChild NULL
  457. // RightChild Pointer to real root
  458. // Balance Undefined, however it is set to a convenient value
  459. // (depending on the algorithm) prior to rebalancing
  460. // in insert and delete routines.
  461. //
  462. typedef struct _RTL_BALANCED_LINKS {
  463. struct _RTL_BALANCED_LINKS *Parent;
  464. struct _RTL_BALANCED_LINKS *LeftChild;
  465. struct _RTL_BALANCED_LINKS *RightChild;
  466. CHAR Balance;
  467. UCHAR Reserved[3];
  468. } RTL_BALANCED_LINKS;
  469. typedef RTL_BALANCED_LINKS *PRTL_BALANCED_LINKS;
  470. //
  471. // To use the generic table package the user declares a variable of type
  472. // GENERIC_TABLE and then uses the routines described below to initialize
  473. // the table and to manipulate the table. Note that the generic table
  474. // should really be an opaque type.
  475. //
  476. typedef struct _RTL_AVL_TABLE {
  477. RTL_BALANCED_LINKS BalancedRoot;
  478. PVOID OrderedPointer;
  479. ULONG WhichOrderedElement;
  480. ULONG NumberGenericTableElements;
  481. ULONG DepthOfTree;
  482. PRTL_BALANCED_LINKS RestartKey;
  483. ULONG DeleteCount;
  484. PRTL_AVL_COMPARE_ROUTINE CompareRoutine;
  485. PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine;
  486. PRTL_AVL_FREE_ROUTINE FreeRoutine;
  487. PVOID TableContext;
  488. } RTL_AVL_TABLE;
  489. typedef RTL_AVL_TABLE *PRTL_AVL_TABLE;
  490. //
  491. // The procedure InitializeGenericTable takes as input an uninitialized
  492. // generic table variable and pointers to the three user supplied routines.
  493. // This must be called for every individual generic table variable before
  494. // it can be used.
  495. //
  496. NTSYSAPI
  497. VOID
  498. NTAPI
  499. RtlInitializeGenericTableAvl (
  500. PRTL_AVL_TABLE Table,
  501. PRTL_AVL_COMPARE_ROUTINE CompareRoutine,
  502. PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine,
  503. PRTL_AVL_FREE_ROUTINE FreeRoutine,
  504. PVOID TableContext
  505. );
  506. //
  507. // The function InsertElementGenericTable will insert a new element
  508. // in a table. It does this by allocating space for the new element
  509. // (this includes AVL links), inserting the element in the table, and
  510. // then returning to the user a pointer to the new element. If an element
  511. // with the same key already exists in the table the return value is a pointer
  512. // to the old element. The optional output parameter NewElement is used
  513. // to indicate if the element previously existed in the table. Note: the user
  514. // supplied Buffer is only used for searching the table, upon insertion its
  515. // contents are copied to the newly created element. This means that
  516. // pointer to the input buffer will not point to the new element.
  517. //
  518. NTSYSAPI
  519. PVOID
  520. NTAPI
  521. RtlInsertElementGenericTableAvl (
  522. PRTL_AVL_TABLE Table,
  523. PVOID Buffer,
  524. CLONG BufferSize,
  525. PBOOLEAN NewElement OPTIONAL
  526. );
  527. //
  528. // The function InsertElementGenericTableFull will insert a new element
  529. // in a table. It does this by allocating space for the new element
  530. // (this includes AVL links), inserting the element in the table, and
  531. // then returning to the user a pointer to the new element. If an element
  532. // with the same key already exists in the table the return value is a pointer
  533. // to the old element. The optional output parameter NewElement is used
  534. // to indicate if the element previously existed in the table. Note: the user
  535. // supplied Buffer is only used for searching the table, upon insertion its
  536. // contents are copied to the newly created element. This means that
  537. // pointer to the input buffer will not point to the new element.
  538. // This routine is passed the NodeOrParent and SearchResult from a
  539. // previous RtlLookupElementGenericTableFull.
  540. //
  541. NTSYSAPI
  542. PVOID
  543. NTAPI
  544. RtlInsertElementGenericTableFullAvl (
  545. PRTL_AVL_TABLE Table,
  546. PVOID Buffer,
  547. CLONG BufferSize,
  548. PBOOLEAN NewElement OPTIONAL,
  549. PVOID NodeOrParent,
  550. TABLE_SEARCH_RESULT SearchResult
  551. );
  552. //
  553. // The function DeleteElementGenericTable will find and delete an element
  554. // from a generic table. If the element is located and deleted the return
  555. // value is TRUE, otherwise if the element is not located the return value
  556. // is FALSE. The user supplied input buffer is only used as a key in
  557. // locating the element in the table.
  558. //
  559. NTSYSAPI
  560. BOOLEAN
  561. NTAPI
  562. RtlDeleteElementGenericTableAvl (
  563. PRTL_AVL_TABLE Table,
  564. PVOID Buffer
  565. );
  566. //
  567. // The function LookupElementGenericTable will find an element in a generic
  568. // table. If the element is located the return value is a pointer to
  569. // the user defined structure associated with the element, otherwise if
  570. // the element is not located the return value is NULL. The user supplied
  571. // input buffer is only used as a key in locating the element in the table.
  572. //
  573. NTSYSAPI
  574. PVOID
  575. NTAPI
  576. RtlLookupElementGenericTableAvl (
  577. PRTL_AVL_TABLE Table,
  578. PVOID Buffer
  579. );
  580. //
  581. // The function LookupElementGenericTableFull will find an element in a generic
  582. // table. If the element is located the return value is a pointer to
  583. // the user defined structure associated with the element. If the element is not
  584. // located then a pointer to the parent for the insert location is returned. The
  585. // user must look at the SearchResult value to determine which is being returned.
  586. // The user can use the SearchResult and parent for a subsequent FullInsertElement
  587. // call to optimize the insert.
  588. //
  589. NTSYSAPI
  590. PVOID
  591. NTAPI
  592. RtlLookupElementGenericTableFullAvl (
  593. PRTL_AVL_TABLE Table,
  594. PVOID Buffer,
  595. OUT PVOID *NodeOrParent,
  596. OUT TABLE_SEARCH_RESULT *SearchResult
  597. );
  598. //
  599. // The function EnumerateGenericTable will return to the caller one-by-one
  600. // the elements of of a table. The return value is a pointer to the user
  601. // defined structure associated with the element. The input parameter
  602. // Restart indicates if the enumeration should start from the beginning
  603. // or should return the next element. If the are no more new elements to
  604. // return the return value is NULL. As an example of its use, to enumerate
  605. // all of the elements in a table the user would write:
  606. //
  607. // for (ptr = EnumerateGenericTable(Table, TRUE);
  608. // ptr != NULL;
  609. // ptr = EnumerateGenericTable(Table, FALSE)) {
  610. // :
  611. // }
  612. //
  613. // NOTE: This routine does not modify the structure of the tree, but saves
  614. // the last node returned in the generic table itself, and for this
  615. // reason requires exclusive access to the table for the duration of
  616. // the enumeration.
  617. //
  618. NTSYSAPI
  619. PVOID
  620. NTAPI
  621. RtlEnumerateGenericTableAvl (
  622. PRTL_AVL_TABLE Table,
  623. BOOLEAN Restart
  624. );
  625. //
  626. // The function EnumerateGenericTableWithoutSplaying will return to the
  627. // caller one-by-one the elements of of a table. The return value is a
  628. // pointer to the user defined structure associated with the element.
  629. // The input parameter RestartKey indicates if the enumeration should
  630. // start from the beginning or should return the next element. If the
  631. // are no more new elements to return the return value is NULL. As an
  632. // example of its use, to enumerate all of the elements in a table the
  633. // user would write:
  634. //
  635. // RestartKey = NULL;
  636. // for (ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey);
  637. // ptr != NULL;
  638. // ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey)) {
  639. // :
  640. // }
  641. //
  642. // If RestartKey is NULL, the package will start from the least entry in the
  643. // table, otherwise it will start from the last entry returned.
  644. //
  645. // NOTE: This routine does not modify either the structure of the tree
  646. // or the generic table itself, but must insure that no deletes
  647. // occur for the duration of the enumeration, typically by having
  648. // at least shared access to the table for the duration.
  649. //
  650. NTSYSAPI
  651. PVOID
  652. NTAPI
  653. RtlEnumerateGenericTableWithoutSplayingAvl (
  654. PRTL_AVL_TABLE Table,
  655. PVOID *RestartKey
  656. );
  657. //
  658. // The function EnumerateGenericTableLikeADirectory will return to the
  659. // caller one-by-one the elements of of a table. The return value is a
  660. // pointer to the user defined structure associated with the element.
  661. // The input parameter RestartKey indicates if the enumeration should
  662. // start from the beginning or should return the next element. If the
  663. // are no more new elements to return the return value is NULL. As an
  664. // example of its use, to enumerate all of the elements in a table the
  665. // user would write:
  666. //
  667. // RestartKey = NULL;
  668. // for (ptr = EnumerateGenericTableLikeADirectory(Table, &RestartKey, ...);
  669. // ptr != NULL;
  670. // ptr = EnumerateGenericTableLikeADirectory(Table, &RestartKey, ...)) {
  671. // :
  672. // }
  673. //
  674. // If RestartKey is NULL, the package will start from the least entry in the
  675. // table, otherwise it will start from the last entry returned.
  676. //
  677. // NOTE: This routine does not modify either the structure of the tree
  678. // or the generic table itself. The table must only be acquired
  679. // shared for the duration of this call, and all synchronization
  680. // may optionally be dropped between calls. Enumeration is always
  681. // correctly resumed in the most efficient manner possible via the
  682. // IN OUT parameters provided.
  683. //
  684. // ****** Explain NextFlag. Directory enumeration resumes from a key
  685. // requires more thought. Also need the match pattern and IgnoreCase.
  686. // Should some structure be introduced to carry it all?
  687. //
  688. NTSYSAPI
  689. PVOID
  690. NTAPI
  691. RtlEnumerateGenericTableLikeADirectory (
  692. IN PRTL_AVL_TABLE Table,
  693. IN PRTL_AVL_MATCH_FUNCTION MatchFunction,
  694. IN PVOID MatchData,
  695. IN ULONG NextFlag,
  696. IN OUT PVOID *RestartKey,
  697. IN OUT PULONG DeleteCount,
  698. IN OUT PVOID Buffer
  699. );
  700. //
  701. // The function GetElementGenericTable will return the i'th element
  702. // inserted in the generic table. I = 0 implies the first element,
  703. // I = (RtlNumberGenericTableElements(Table)-1) will return the last element
  704. // inserted into the generic table. The type of I is ULONG. Values
  705. // of I > than (NumberGenericTableElements(Table)-1) will return NULL. If
  706. // an arbitrary element is deleted from the generic table it will cause
  707. // all elements inserted after the deleted element to "move up".
  708. NTSYSAPI
  709. PVOID
  710. NTAPI
  711. RtlGetElementGenericTableAvl (
  712. PRTL_AVL_TABLE Table,
  713. ULONG I
  714. );
  715. //
  716. // The function NumberGenericTableElements returns a ULONG value
  717. // which is the number of generic table elements currently inserted
  718. // in the generic table.
  719. NTSYSAPI
  720. ULONG
  721. NTAPI
  722. RtlNumberGenericTableElementsAvl (
  723. PRTL_AVL_TABLE Table
  724. );
  725. //
  726. // The function IsGenericTableEmpty will return to the caller TRUE if
  727. // the input table is empty (i.e., does not contain any elements) and
  728. // FALSE otherwise.
  729. //
  730. NTSYSAPI
  731. BOOLEAN
  732. NTAPI
  733. RtlIsGenericTableEmptyAvl (
  734. PRTL_AVL_TABLE Table
  735. );
  736. //
  737. // As an aid to allowing existing generic table users to do (in most
  738. // cases) a single-line edit to switch over to Avl table use, we
  739. // have the following defines and inline routine definitions which
  740. // redirect calls and types. Note that the type override (performed
  741. // by #define below) will not work in the unexpected event that someone
  742. // has used a pointer or type specifier in their own #define, since
  743. // #define processing is one pass and does not nest. The __inline
  744. // declarations below do not have this limitation, however.
  745. //
  746. // To switch to using Avl tables, add the following line before your
  747. // includes:
  748. //
  749. // #define RTL_USE_AVL_TABLES 0
  750. //
  751. #ifdef RTL_USE_AVL_TABLES
  752. #undef PRTL_GENERIC_COMPARE_ROUTINE
  753. #undef PRTL_GENERIC_ALLOCATE_ROUTINE
  754. #undef PRTL_GENERIC_FREE_ROUTINE
  755. #undef RTL_GENERIC_TABLE
  756. #undef PRTL_GENERIC_TABLE
  757. #define PRTL_GENERIC_COMPARE_ROUTINE PRTL_AVL_COMPARE_ROUTINE
  758. #define PRTL_GENERIC_ALLOCATE_ROUTINE PRTL_AVL_ALLOCATE_ROUTINE
  759. #define PRTL_GENERIC_FREE_ROUTINE PRTL_AVL_FREE_ROUTINE
  760. #define RTL_GENERIC_TABLE RTL_AVL_TABLE
  761. #define PRTL_GENERIC_TABLE PRTL_AVL_TABLE
  762. #define RtlInitializeGenericTable RtlInitializeGenericTableAvl
  763. #define RtlInsertElementGenericTable RtlInsertElementGenericTableAvl
  764. #define RtlInsertElementGenericTableFull RtlInsertElementGenericTableFullAvl
  765. #define RtlDeleteElementGenericTable RtlDeleteElementGenericTableAvl
  766. #define RtlLookupElementGenericTable RtlLookupElementGenericTableAvl
  767. #define RtlLookupElementGenericTableFull RtlLookupElementGenericTableFullAvl
  768. #define RtlEnumerateGenericTable RtlEnumerateGenericTableAvl
  769. #define RtlEnumerateGenericTableWithoutSplaying RtlEnumerateGenericTableWithoutSplayingAvl
  770. #define RtlGetElementGenericTable RtlGetElementGenericTableAvl
  771. #define RtlNumberGenericTableElements RtlNumberGenericTableElementsAvl
  772. #define RtlIsGenericTableEmpty RtlIsGenericTableEmptyAvl
  773. #endif // RTL_USE_AVL_TABLES
  774. //
  775. // Define the splay links and the associated manipuliation macros and
  776. // routines. Note that the splay_links should be an opaque type.
  777. // Routine are provided to traverse and manipulate the structure.
  778. //
  779. typedef struct _RTL_SPLAY_LINKS {
  780. struct _RTL_SPLAY_LINKS *Parent;
  781. struct _RTL_SPLAY_LINKS *LeftChild;
  782. struct _RTL_SPLAY_LINKS *RightChild;
  783. } RTL_SPLAY_LINKS;
  784. typedef RTL_SPLAY_LINKS *PRTL_SPLAY_LINKS;
  785. //
  786. // The macro procedure InitializeSplayLinks takes as input a pointer to
  787. // splay link and initializes its substructure. All splay link nodes must
  788. // be initialized before they are used in the different splay routines and
  789. // macros.
  790. //
  791. // VOID
  792. // RtlInitializeSplayLinks (
  793. // PRTL_SPLAY_LINKS Links
  794. // );
  795. //
  796. #define RtlInitializeSplayLinks(Links) { \
  797. PRTL_SPLAY_LINKS _SplayLinks; \
  798. _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
  799. _SplayLinks->Parent = _SplayLinks; \
  800. _SplayLinks->LeftChild = NULL; \
  801. _SplayLinks->RightChild = NULL; \
  802. }
  803. //
  804. // The macro function Parent takes as input a pointer to a splay link in a
  805. // tree and returns a pointer to the splay link of the parent of the input
  806. // node. If the input node is the root of the tree the return value is
  807. // equal to the input value.
  808. //
  809. // PRTL_SPLAY_LINKS
  810. // RtlParent (
  811. // PRTL_SPLAY_LINKS Links
  812. // );
  813. //
  814. #define RtlParent(Links) ( \
  815. (PRTL_SPLAY_LINKS)(Links)->Parent \
  816. )
  817. //
  818. // The macro function LeftChild takes as input a pointer to a splay link in
  819. // a tree and returns a pointer to the splay link of the left child of the
  820. // input node. If the left child does not exist, the return value is NULL.
  821. //
  822. // PRTL_SPLAY_LINKS
  823. // RtlLeftChild (
  824. // PRTL_SPLAY_LINKS Links
  825. // );
  826. //
  827. #define RtlLeftChild(Links) ( \
  828. (PRTL_SPLAY_LINKS)(Links)->LeftChild \
  829. )
  830. //
  831. // The macro function RightChild takes as input a pointer to a splay link
  832. // in a tree and returns a pointer to the splay link of the right child of
  833. // the input node. If the right child does not exist, the return value is
  834. // NULL.
  835. //
  836. // PRTL_SPLAY_LINKS
  837. // RtlRightChild (
  838. // PRTL_SPLAY_LINKS Links
  839. // );
  840. //
  841. #define RtlRightChild(Links) ( \
  842. (PRTL_SPLAY_LINKS)(Links)->RightChild \
  843. )
  844. //
  845. // The macro function IsRoot takes as input a pointer to a splay link
  846. // in a tree and returns TRUE if the input node is the root of the tree,
  847. // otherwise it returns FALSE.
  848. //
  849. // BOOLEAN
  850. // RtlIsRoot (
  851. // PRTL_SPLAY_LINKS Links
  852. // );
  853. //
  854. #define RtlIsRoot(Links) ( \
  855. (RtlParent(Links) == (PRTL_SPLAY_LINKS)(Links)) \
  856. )
  857. //
  858. // The macro function IsLeftChild takes as input a pointer to a splay link
  859. // in a tree and returns TRUE if the input node is the left child of its
  860. // parent, otherwise it returns FALSE.
  861. //
  862. // BOOLEAN
  863. // RtlIsLeftChild (
  864. // PRTL_SPLAY_LINKS Links
  865. // );
  866. //
  867. #define RtlIsLeftChild(Links) ( \
  868. (RtlLeftChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)) \
  869. )
  870. //
  871. // The macro function IsRightChild takes as input a pointer to a splay link
  872. // in a tree and returns TRUE if the input node is the right child of its
  873. // parent, otherwise it returns FALSE.
  874. //
  875. // BOOLEAN
  876. // RtlIsRightChild (
  877. // PRTL_SPLAY_LINKS Links
  878. // );
  879. //
  880. #define RtlIsRightChild(Links) ( \
  881. (RtlRightChild(RtlParent(Links)) == (PRTL_SPLAY_LINKS)(Links)) \
  882. )
  883. //
  884. // The macro procedure InsertAsLeftChild takes as input a pointer to a splay
  885. // link in a tree and a pointer to a node not in a tree. It inserts the
  886. // second node as the left child of the first node. The first node must not
  887. // already have a left child, and the second node must not already have a
  888. // parent.
  889. //
  890. // VOID
  891. // RtlInsertAsLeftChild (
  892. // PRTL_SPLAY_LINKS ParentLinks,
  893. // PRTL_SPLAY_LINKS ChildLinks
  894. // );
  895. //
  896. #define RtlInsertAsLeftChild(ParentLinks,ChildLinks) { \
  897. PRTL_SPLAY_LINKS _SplayParent; \
  898. PRTL_SPLAY_LINKS _SplayChild; \
  899. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  900. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  901. _SplayParent->LeftChild = _SplayChild; \
  902. _SplayChild->Parent = _SplayParent; \
  903. }
  904. //
  905. // The macro procedure InsertAsRightChild takes as input a pointer to a splay
  906. // link in a tree and a pointer to a node not in a tree. It inserts the
  907. // second node as the right child of the first node. The first node must not
  908. // already have a right child, and the second node must not already have a
  909. // parent.
  910. //
  911. // VOID
  912. // RtlInsertAsRightChild (
  913. // PRTL_SPLAY_LINKS ParentLinks,
  914. // PRTL_SPLAY_LINKS ChildLinks
  915. // );
  916. //
  917. #define RtlInsertAsRightChild(ParentLinks,ChildLinks) { \
  918. PRTL_SPLAY_LINKS _SplayParent; \
  919. PRTL_SPLAY_LINKS _SplayChild; \
  920. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  921. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  922. _SplayParent->RightChild = _SplayChild; \
  923. _SplayChild->Parent = _SplayParent; \
  924. }
  925. //
  926. // The Splay function takes as input a pointer to a splay link in a tree
  927. // and splays the tree. Its function return value is a pointer to the
  928. // root of the splayed tree.
  929. //
  930. NTSYSAPI
  931. PRTL_SPLAY_LINKS
  932. NTAPI
  933. RtlSplay (
  934. PRTL_SPLAY_LINKS Links
  935. );
  936. //
  937. // The Delete function takes as input a pointer to a splay link in a tree
  938. // and deletes that node from the tree. Its function return value is a
  939. // pointer to the root of the tree. If the tree is now empty, the return
  940. // value is NULL.
  941. //
  942. NTSYSAPI
  943. PRTL_SPLAY_LINKS
  944. NTAPI
  945. RtlDelete (
  946. PRTL_SPLAY_LINKS Links
  947. );
  948. //
  949. // The DeleteNoSplay function takes as input a pointer to a splay link in a tree,
  950. // the caller's pointer to the root of the tree and deletes that node from the
  951. // tree. Upon return the caller's pointer to the root node will correctly point
  952. // at the root of the tree.
  953. //
  954. // It operationally differs from RtlDelete only in that it will not splay the tree.
  955. //
  956. NTSYSAPI
  957. VOID
  958. NTAPI
  959. RtlDeleteNoSplay (
  960. PRTL_SPLAY_LINKS Links,
  961. PRTL_SPLAY_LINKS *Root
  962. );
  963. //
  964. // The SubtreeSuccessor function takes as input a pointer to a splay link
  965. // in a tree and returns a pointer to the successor of the input node of
  966. // the substree rooted at the input node. If there is not a successor, the
  967. // return value is NULL.
  968. //
  969. NTSYSAPI
  970. PRTL_SPLAY_LINKS
  971. NTAPI
  972. RtlSubtreeSuccessor (
  973. PRTL_SPLAY_LINKS Links
  974. );
  975. //
  976. // The SubtreePredecessor function takes as input a pointer to a splay link
  977. // in a tree and returns a pointer to the predecessor of the input node of
  978. // the substree rooted at the input node. If there is not a predecessor,
  979. // the return value is NULL.
  980. //
  981. NTSYSAPI
  982. PRTL_SPLAY_LINKS
  983. NTAPI
  984. RtlSubtreePredecessor (
  985. PRTL_SPLAY_LINKS Links
  986. );
  987. //
  988. // The RealSuccessor function takes as input a pointer to a splay link
  989. // in a tree and returns a pointer to the successor of the input node within
  990. // the entire tree. If there is not a successor, the return value is NULL.
  991. //
  992. NTSYSAPI
  993. PRTL_SPLAY_LINKS
  994. NTAPI
  995. RtlRealSuccessor (
  996. PRTL_SPLAY_LINKS Links
  997. );
  998. //
  999. // The RealPredecessor function takes as input a pointer to a splay link
  1000. // in a tree and returns a pointer to the predecessor of the input node
  1001. // within the entire tree. If there is not a predecessor, the return value
  1002. // is NULL.
  1003. //
  1004. NTSYSAPI
  1005. PRTL_SPLAY_LINKS
  1006. NTAPI
  1007. RtlRealPredecessor (
  1008. PRTL_SPLAY_LINKS Links
  1009. );
  1010. //
  1011. // Define the generic table package. Note a generic table should really
  1012. // be an opaque type. We provide routines to manipulate the structure.
  1013. //
  1014. // A generic table is package for inserting, deleting, and looking up elements
  1015. // in a table (e.g., in a symbol table). To use this package the user
  1016. // defines the structure of the elements stored in the table, provides a
  1017. // comparison function, a memory allocation function, and a memory
  1018. // deallocation function.
  1019. //
  1020. // Note: the user compare function must impose a complete ordering among
  1021. // all of the elements, and the table does not allow for duplicate entries.
  1022. //
  1023. //
  1024. // Do not do the following defines if using Avl
  1025. //
  1026. #ifndef RTL_USE_AVL_TABLES
  1027. //
  1028. // Add an empty typedef so that functions can reference the
  1029. // a pointer to the generic table struct before it is declared.
  1030. //
  1031. struct _RTL_GENERIC_TABLE;
  1032. //
  1033. // The comparison function takes as input pointers to elements containing
  1034. // user defined structures and returns the results of comparing the two
  1035. // elements.
  1036. //
  1037. typedef
  1038. RTL_GENERIC_COMPARE_RESULTS
  1039. (NTAPI *PRTL_GENERIC_COMPARE_ROUTINE) (
  1040. struct _RTL_GENERIC_TABLE *Table,
  1041. PVOID FirstStruct,
  1042. PVOID SecondStruct
  1043. );
  1044. //
  1045. // The allocation function is called by the generic table package whenever
  1046. // it needs to allocate memory for the table.
  1047. //
  1048. typedef
  1049. PVOID
  1050. (NTAPI *PRTL_GENERIC_ALLOCATE_ROUTINE) (
  1051. struct _RTL_GENERIC_TABLE *Table,
  1052. CLONG ByteSize
  1053. );
  1054. //
  1055. // The deallocation function is called by the generic table package whenever
  1056. // it needs to deallocate memory from the table that was allocated by calling
  1057. // the user supplied allocation function.
  1058. //
  1059. typedef
  1060. VOID
  1061. (NTAPI *PRTL_GENERIC_FREE_ROUTINE) (
  1062. struct _RTL_GENERIC_TABLE *Table,
  1063. PVOID Buffer
  1064. );
  1065. //
  1066. // To use the generic table package the user declares a variable of type
  1067. // GENERIC_TABLE and then uses the routines described below to initialize
  1068. // the table and to manipulate the table. Note that the generic table
  1069. // should really be an opaque type.
  1070. //
  1071. typedef struct _RTL_GENERIC_TABLE {
  1072. PRTL_SPLAY_LINKS TableRoot;
  1073. LIST_ENTRY InsertOrderList;
  1074. PLIST_ENTRY OrderedPointer;
  1075. ULONG WhichOrderedElement;
  1076. ULONG NumberGenericTableElements;
  1077. PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine;
  1078. PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine;
  1079. PRTL_GENERIC_FREE_ROUTINE FreeRoutine;
  1080. PVOID TableContext;
  1081. } RTL_GENERIC_TABLE;
  1082. typedef RTL_GENERIC_TABLE *PRTL_GENERIC_TABLE;
  1083. //
  1084. // The procedure InitializeGenericTable takes as input an uninitialized
  1085. // generic table variable and pointers to the three user supplied routines.
  1086. // This must be called for every individual generic table variable before
  1087. // it can be used.
  1088. //
  1089. NTSYSAPI
  1090. VOID
  1091. NTAPI
  1092. RtlInitializeGenericTable (
  1093. PRTL_GENERIC_TABLE Table,
  1094. PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine,
  1095. PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine,
  1096. PRTL_GENERIC_FREE_ROUTINE FreeRoutine,
  1097. PVOID TableContext
  1098. );
  1099. //
  1100. // The function InsertElementGenericTable will insert a new element
  1101. // in a table. It does this by allocating space for the new element
  1102. // (this includes splay links), inserting the element in the table, and
  1103. // then returning to the user a pointer to the new element. If an element
  1104. // with the same key already exists in the table the return value is a pointer
  1105. // to the old element. The optional output parameter NewElement is used
  1106. // to indicate if the element previously existed in the table. Note: the user
  1107. // supplied Buffer is only used for searching the table, upon insertion its
  1108. // contents are copied to the newly created element. This means that
  1109. // pointer to the input buffer will not point to the new element.
  1110. //
  1111. NTSYSAPI
  1112. PVOID
  1113. NTAPI
  1114. RtlInsertElementGenericTable (
  1115. PRTL_GENERIC_TABLE Table,
  1116. PVOID Buffer,
  1117. CLONG BufferSize,
  1118. PBOOLEAN NewElement OPTIONAL
  1119. );
  1120. //
  1121. // The function InsertElementGenericTableFull will insert a new element
  1122. // in a table. It does this by allocating space for the new element
  1123. // (this includes splay links), inserting the element in the table, and
  1124. // then returning to the user a pointer to the new element. If an element
  1125. // with the same key already exists in the table the return value is a pointer
  1126. // to the old element. The optional output parameter NewElement is used
  1127. // to indicate if the element previously existed in the table. Note: the user
  1128. // supplied Buffer is only used for searching the table, upon insertion its
  1129. // contents are copied to the newly created element. This means that
  1130. // pointer to the input buffer will not point to the new element.
  1131. // This routine is passed the NodeOrParent and SearchResult from a
  1132. // previous RtlLookupElementGenericTableFull.
  1133. //
  1134. NTSYSAPI
  1135. PVOID
  1136. NTAPI
  1137. RtlInsertElementGenericTableFull (
  1138. PRTL_GENERIC_TABLE Table,
  1139. PVOID Buffer,
  1140. CLONG BufferSize,
  1141. PBOOLEAN NewElement OPTIONAL,
  1142. PVOID NodeOrParent,
  1143. TABLE_SEARCH_RESULT SearchResult
  1144. );
  1145. //
  1146. // The function DeleteElementGenericTable will find and delete an element
  1147. // from a generic table. If the element is located and deleted the return
  1148. // value is TRUE, otherwise if the element is not located the return value
  1149. // is FALSE. The user supplied input buffer is only used as a key in
  1150. // locating the element in the table.
  1151. //
  1152. NTSYSAPI
  1153. BOOLEAN
  1154. NTAPI
  1155. RtlDeleteElementGenericTable (
  1156. PRTL_GENERIC_TABLE Table,
  1157. PVOID Buffer
  1158. );
  1159. //
  1160. // The function LookupElementGenericTable will find an element in a generic
  1161. // table. If the element is located the return value is a pointer to
  1162. // the user defined structure associated with the element, otherwise if
  1163. // the element is not located the return value is NULL. The user supplied
  1164. // input buffer is only used as a key in locating the element in the table.
  1165. //
  1166. NTSYSAPI
  1167. PVOID
  1168. NTAPI
  1169. RtlLookupElementGenericTable (
  1170. PRTL_GENERIC_TABLE Table,
  1171. PVOID Buffer
  1172. );
  1173. //
  1174. // The function LookupElementGenericTableFull will find an element in a generic
  1175. // table. If the element is located the return value is a pointer to
  1176. // the user defined structure associated with the element. If the element is not
  1177. // located then a pointer to the parent for the insert location is returned. The
  1178. // user must look at the SearchResult value to determine which is being returned.
  1179. // The user can use the SearchResult and parent for a subsequent FullInsertElement
  1180. // call to optimize the insert.
  1181. //
  1182. NTSYSAPI
  1183. PVOID
  1184. NTAPI
  1185. RtlLookupElementGenericTableFull (
  1186. PRTL_GENERIC_TABLE Table,
  1187. PVOID Buffer,
  1188. OUT PVOID *NodeOrParent,
  1189. OUT TABLE_SEARCH_RESULT *SearchResult
  1190. );
  1191. //
  1192. // The function EnumerateGenericTable will return to the caller one-by-one
  1193. // the elements of of a table. The return value is a pointer to the user
  1194. // defined structure associated with the element. The input parameter
  1195. // Restart indicates if the enumeration should start from the beginning
  1196. // or should return the next element. If the are no more new elements to
  1197. // return the return value is NULL. As an example of its use, to enumerate
  1198. // all of the elements in a table the user would write:
  1199. //
  1200. // for (ptr = EnumerateGenericTable(Table, TRUE);
  1201. // ptr != NULL;
  1202. // ptr = EnumerateGenericTable(Table, FALSE)) {
  1203. // :
  1204. // }
  1205. //
  1206. //
  1207. // PLEASE NOTE:
  1208. //
  1209. // If you enumerate a GenericTable using RtlEnumerateGenericTable, you
  1210. // will flatten the table, turning it into a sorted linked list.
  1211. // To enumerate the table without perturbing the splay links, use
  1212. // RtlEnumerateGenericTableWithoutSplaying
  1213. NTSYSAPI
  1214. PVOID
  1215. NTAPI
  1216. RtlEnumerateGenericTable (
  1217. PRTL_GENERIC_TABLE Table,
  1218. BOOLEAN Restart
  1219. );
  1220. //
  1221. // The function EnumerateGenericTableWithoutSplaying will return to the
  1222. // caller one-by-one the elements of of a table. The return value is a
  1223. // pointer to the user defined structure associated with the element.
  1224. // The input parameter RestartKey indicates if the enumeration should
  1225. // start from the beginning or should return the next element. If the
  1226. // are no more new elements to return the return value is NULL. As an
  1227. // example of its use, to enumerate all of the elements in a table the
  1228. // user would write:
  1229. //
  1230. // RestartKey = NULL;
  1231. // for (ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey);
  1232. // ptr != NULL;
  1233. // ptr = EnumerateGenericTableWithoutSplaying(Table, &RestartKey)) {
  1234. // :
  1235. // }
  1236. //
  1237. // If RestartKey is NULL, the package will start from the least entry in the
  1238. // table, otherwise it will start from the last entry returned.
  1239. //
  1240. //
  1241. // Note that unlike RtlEnumerateGenericTable, this routine will NOT perturb
  1242. // the splay order of the tree.
  1243. //
  1244. NTSYSAPI
  1245. PVOID
  1246. NTAPI
  1247. RtlEnumerateGenericTableWithoutSplaying (
  1248. PRTL_GENERIC_TABLE Table,
  1249. PVOID *RestartKey
  1250. );
  1251. //
  1252. // The function GetElementGenericTable will return the i'th element
  1253. // inserted in the generic table. I = 0 implies the first element,
  1254. // I = (RtlNumberGenericTableElements(Table)-1) will return the last element
  1255. // inserted into the generic table. The type of I is ULONG. Values
  1256. // of I > than (NumberGenericTableElements(Table)-1) will return NULL. If
  1257. // an arbitrary element is deleted from the generic table it will cause
  1258. // all elements inserted after the deleted element to "move up".
  1259. NTSYSAPI
  1260. PVOID
  1261. NTAPI
  1262. RtlGetElementGenericTable(
  1263. PRTL_GENERIC_TABLE Table,
  1264. ULONG I
  1265. );
  1266. //
  1267. // The function NumberGenericTableElements returns a ULONG value
  1268. // which is the number of generic table elements currently inserted
  1269. // in the generic table.
  1270. NTSYSAPI
  1271. ULONG
  1272. NTAPI
  1273. RtlNumberGenericTableElements(
  1274. PRTL_GENERIC_TABLE Table
  1275. );
  1276. //
  1277. // The function IsGenericTableEmpty will return to the caller TRUE if
  1278. // the input table is empty (i.e., does not contain any elements) and
  1279. // FALSE otherwise.
  1280. //
  1281. NTSYSAPI
  1282. BOOLEAN
  1283. NTAPI
  1284. RtlIsGenericTableEmpty (
  1285. PRTL_GENERIC_TABLE Table
  1286. );
  1287. #endif // RTL_USE_AVL_TABLES
  1288. // end_ntifs
  1289. //
  1290. // Heap Allocator
  1291. //
  1292. NTSYSAPI
  1293. NTSTATUS
  1294. NTAPI
  1295. RtlInitializeHeapManager(
  1296. VOID
  1297. );
  1298. // begin_ntifs
  1299. typedef NTSTATUS
  1300. (NTAPI * PRTL_HEAP_COMMIT_ROUTINE)(
  1301. IN PVOID Base,
  1302. IN OUT PVOID *CommitAddress,
  1303. IN OUT PSIZE_T CommitSize
  1304. );
  1305. typedef struct _RTL_HEAP_PARAMETERS {
  1306. ULONG Length;
  1307. SIZE_T SegmentReserve;
  1308. SIZE_T SegmentCommit;
  1309. SIZE_T DeCommitFreeBlockThreshold;
  1310. SIZE_T DeCommitTotalFreeThreshold;
  1311. SIZE_T MaximumAllocationSize;
  1312. SIZE_T VirtualMemoryThreshold;
  1313. SIZE_T InitialCommit;
  1314. SIZE_T InitialReserve;
  1315. PRTL_HEAP_COMMIT_ROUTINE CommitRoutine;
  1316. SIZE_T Reserved[ 2 ];
  1317. } RTL_HEAP_PARAMETERS, *PRTL_HEAP_PARAMETERS;
  1318. NTSYSAPI
  1319. PVOID
  1320. NTAPI
  1321. RtlCreateHeap(
  1322. IN ULONG Flags,
  1323. IN PVOID HeapBase OPTIONAL,
  1324. IN SIZE_T ReserveSize OPTIONAL,
  1325. IN SIZE_T CommitSize OPTIONAL,
  1326. IN PVOID Lock OPTIONAL,
  1327. IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL
  1328. );
  1329. #define HEAP_NO_SERIALIZE 0x00000001 // winnt
  1330. #define HEAP_GROWABLE 0x00000002 // winnt
  1331. #define HEAP_GENERATE_EXCEPTIONS 0x00000004 // winnt
  1332. #define HEAP_ZERO_MEMORY 0x00000008 // winnt
  1333. #define HEAP_REALLOC_IN_PLACE_ONLY 0x00000010 // winnt
  1334. #define HEAP_TAIL_CHECKING_ENABLED 0x00000020 // winnt
  1335. #define HEAP_FREE_CHECKING_ENABLED 0x00000040 // winnt
  1336. #define HEAP_DISABLE_COALESCE_ON_FREE 0x00000080 // winnt
  1337. #define HEAP_CREATE_ALIGN_16 0x00010000 // winnt Create heap with 16 byte alignment (obsolete)
  1338. #define HEAP_CREATE_ENABLE_TRACING 0x00020000 // winnt Create heap call tracing enabled (obsolete)
  1339. #define HEAP_SETTABLE_USER_VALUE 0x00000100
  1340. #define HEAP_SETTABLE_USER_FLAG1 0x00000200
  1341. #define HEAP_SETTABLE_USER_FLAG2 0x00000400
  1342. #define HEAP_SETTABLE_USER_FLAG3 0x00000800
  1343. #define HEAP_SETTABLE_USER_FLAGS 0x00000E00
  1344. #define HEAP_CLASS_0 0x00000000 // process heap
  1345. #define HEAP_CLASS_1 0x00001000 // private heap
  1346. #define HEAP_CLASS_2 0x00002000 // Kernel Heap
  1347. #define HEAP_CLASS_3 0x00003000 // GDI heap
  1348. #define HEAP_CLASS_4 0x00004000 // User heap
  1349. #define HEAP_CLASS_5 0x00005000 // Console heap
  1350. #define HEAP_CLASS_6 0x00006000 // User Desktop heap
  1351. #define HEAP_CLASS_7 0x00007000 // Csrss Shared heap
  1352. #define HEAP_CLASS_8 0x00008000 // Csr Port heap
  1353. #define HEAP_CLASS_MASK 0x0000F000
  1354. #define HEAP_MAXIMUM_TAG 0x0FFF // winnt
  1355. #define HEAP_GLOBAL_TAG 0x0800
  1356. #define HEAP_PSEUDO_TAG_FLAG 0x8000 // winnt
  1357. #define HEAP_TAG_SHIFT 18 // winnt
  1358. #define HEAP_MAKE_TAG_FLAGS( b, o ) ((ULONG)((b) + ((o) << 18))) // winnt
  1359. #define HEAP_TAG_MASK (HEAP_MAXIMUM_TAG << HEAP_TAG_SHIFT)
  1360. #define HEAP_CREATE_VALID_MASK (HEAP_NO_SERIALIZE | \
  1361. HEAP_GROWABLE | \
  1362. HEAP_GENERATE_EXCEPTIONS | \
  1363. HEAP_ZERO_MEMORY | \
  1364. HEAP_REALLOC_IN_PLACE_ONLY | \
  1365. HEAP_TAIL_CHECKING_ENABLED | \
  1366. HEAP_FREE_CHECKING_ENABLED | \
  1367. HEAP_DISABLE_COALESCE_ON_FREE | \
  1368. HEAP_CLASS_MASK | \
  1369. HEAP_CREATE_ALIGN_16 | \
  1370. HEAP_CREATE_ENABLE_TRACING)
  1371. NTSYSAPI
  1372. PVOID
  1373. NTAPI
  1374. RtlDestroyHeap(
  1375. IN PVOID HeapHandle
  1376. );
  1377. NTSYSAPI
  1378. PVOID
  1379. NTAPI
  1380. RtlAllocateHeap(
  1381. IN PVOID HeapHandle,
  1382. IN ULONG Flags,
  1383. IN SIZE_T Size
  1384. );
  1385. NTSYSAPI
  1386. BOOLEAN
  1387. NTAPI
  1388. RtlFreeHeap(
  1389. IN PVOID HeapHandle,
  1390. IN ULONG Flags,
  1391. IN PVOID BaseAddress
  1392. );
  1393. // end_ntifs
  1394. NTSYSAPI
  1395. SIZE_T
  1396. NTAPI
  1397. RtlSizeHeap(
  1398. IN PVOID HeapHandle,
  1399. IN ULONG Flags,
  1400. IN PVOID BaseAddress
  1401. );
  1402. NTSYSAPI
  1403. NTSTATUS
  1404. NTAPI
  1405. RtlZeroHeap(
  1406. IN PVOID HeapHandle,
  1407. IN ULONG Flags
  1408. );
  1409. NTSYSAPI
  1410. VOID
  1411. NTAPI
  1412. RtlProtectHeap(
  1413. IN PVOID HeapHandle,
  1414. IN BOOLEAN MakeReadOnly
  1415. );
  1416. //
  1417. // See NTURTL.H for remaining, user mode only heap functions.
  1418. //
  1419. //
  1420. // The types PACQUIRE_LOCK_ROUTINE and PRELEASE_LOCK_ROUTINE are prototypes
  1421. // for routines to acquire and release locks in kernel and user mode.
  1422. //
  1423. typedef
  1424. NTSTATUS
  1425. (NTAPI *PRTL_INITIALIZE_LOCK_ROUTINE) (
  1426. PVOID Lock
  1427. );
  1428. typedef
  1429. NTSTATUS
  1430. (NTAPI *PRTL_ACQUIRE_LOCK_ROUTINE) (
  1431. PVOID Lock
  1432. );
  1433. typedef
  1434. NTSTATUS
  1435. (NTAPI *PRTL_RELEASE_LOCK_ROUTINE) (
  1436. PVOID Lock
  1437. );
  1438. typedef
  1439. NTSTATUS
  1440. (NTAPI *PRTL_DELETE_LOCK_ROUTINE) (
  1441. PVOID Lock
  1442. );
  1443. typedef
  1444. BOOLEAN
  1445. (NTAPI *PRTL_OKAY_TO_LOCK_ROUTINE) (
  1446. IN PVOID Lock
  1447. );
  1448. NTSYSAPI
  1449. ULONG
  1450. NTAPI
  1451. RtlGetNtGlobalFlags(
  1452. VOID
  1453. );
  1454. //
  1455. // Functions to capture a stack back trace
  1456. //
  1457. // begin_ntddk begin_nthal begin_ntifs begin_ntndis
  1458. #if defined (_MSC_VER) && ( _MSC_VER >= 900 )
  1459. PVOID
  1460. _ReturnAddress (
  1461. VOID
  1462. );
  1463. #pragma intrinsic(_ReturnAddress)
  1464. #endif
  1465. #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
  1466. #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
  1467. *CallersAddress = (PVOID)_ReturnAddress(); \
  1468. *CallersCaller = NULL;
  1469. #else
  1470. NTSYSAPI
  1471. VOID
  1472. NTAPI
  1473. RtlGetCallersAddress(
  1474. OUT PVOID *CallersAddress,
  1475. OUT PVOID *CallersCaller
  1476. );
  1477. #endif
  1478. NTSYSAPI
  1479. ULONG
  1480. NTAPI
  1481. RtlWalkFrameChain (
  1482. OUT PVOID *Callers,
  1483. IN ULONG Count,
  1484. IN ULONG Flags
  1485. );
  1486. // end_ntddk end_nthal end_ntifs end_ntndis
  1487. NTSYSAPI
  1488. USHORT
  1489. NTAPI
  1490. RtlLogStackBackTrace(
  1491. VOID
  1492. );
  1493. // begin_winnt
  1494. NTSYSAPI
  1495. VOID
  1496. NTAPI
  1497. RtlCaptureContext (
  1498. OUT PCONTEXT ContextRecord
  1499. );
  1500. // end_winnt
  1501. NTSYSAPI
  1502. USHORT
  1503. NTAPI
  1504. RtlCaptureStackBackTrace(
  1505. IN ULONG FramesToSkip,
  1506. IN ULONG FramesToCapture,
  1507. OUT PVOID *BackTrace,
  1508. OUT PULONG BackTraceHash OPTIONAL
  1509. );
  1510. #define MAX_STACK_DEPTH 32
  1511. typedef struct _RTL_PROCESS_BACKTRACE_INFORMATION {
  1512. PCHAR SymbolicBackTrace; // Not filled in
  1513. ULONG TraceCount;
  1514. USHORT Index;
  1515. USHORT Depth;
  1516. PVOID BackTrace[ MAX_STACK_DEPTH ];
  1517. } RTL_PROCESS_BACKTRACE_INFORMATION, *PRTL_PROCESS_BACKTRACE_INFORMATION;
  1518. typedef struct _RTL_PROCESS_BACKTRACES {
  1519. ULONG CommittedMemory;
  1520. ULONG ReservedMemory;
  1521. ULONG NumberOfBackTraceLookups;
  1522. ULONG NumberOfBackTraces;
  1523. RTL_PROCESS_BACKTRACE_INFORMATION BackTraces[ 1 ];
  1524. } RTL_PROCESS_BACKTRACES, *PRTL_PROCESS_BACKTRACES;
  1525. //
  1526. // Capture stack context
  1527. //
  1528. typedef struct _RTL_STACK_CONTEXT_ENTRY {
  1529. ULONG_PTR Address; // stack address
  1530. ULONG_PTR Data; // stack contents
  1531. } RTL_STACK_CONTEXT_ENTRY, * PRTL_STACK_CONTEXT_ENTRY;
  1532. typedef struct _RTL_STACK_CONTEXT {
  1533. ULONG NumberOfEntries;
  1534. RTL_STACK_CONTEXT_ENTRY Entry[1];
  1535. } RTL_STACK_CONTEXT, * PRTL_STACK_CONTEXT;
  1536. NTSYSAPI
  1537. ULONG
  1538. NTAPI
  1539. RtlCaptureStackContext (
  1540. OUT PULONG_PTR Callers,
  1541. OUT PRTL_STACK_CONTEXT Context,
  1542. IN ULONG Limit
  1543. );
  1544. //
  1545. // Trace database support (User/Kernel mode).
  1546. //
  1547. #define RTL_TRACE_IN_USER_MODE 0x00000001
  1548. #define RTL_TRACE_IN_KERNEL_MODE 0x00000002
  1549. #define RTL_TRACE_USE_NONPAGED_POOL 0x00000004
  1550. #define RTL_TRACE_USE_PAGED_POOL 0x00000008
  1551. //
  1552. // RTL_TRACE_BLOCK
  1553. //
  1554. typedef struct _RTL_TRACE_BLOCK {
  1555. ULONG Magic;
  1556. ULONG Count;
  1557. ULONG Size;
  1558. SIZE_T UserCount;
  1559. SIZE_T UserSize;
  1560. PVOID UserContext;
  1561. struct _RTL_TRACE_BLOCK * Next;
  1562. PVOID * Trace;
  1563. } RTL_TRACE_BLOCK, * PRTL_TRACE_BLOCK;
  1564. //
  1565. // RTL_TRACE_HASH_FUNCTION
  1566. //
  1567. typedef ULONG (* RTL_TRACE_HASH_FUNCTION) (ULONG Count, PVOID * Trace);
  1568. //
  1569. // RTL_TRACE_DATABASE
  1570. //
  1571. typedef struct _RTL_TRACE_DATABASE * PRTL_TRACE_DATABASE;
  1572. //
  1573. // RTL_TRACE_ENUMERATE
  1574. //
  1575. typedef struct _RTL_TRACE_ENUMERATE {
  1576. PRTL_TRACE_DATABASE Database;
  1577. ULONG Index;
  1578. PRTL_TRACE_BLOCK Block;
  1579. } RTL_TRACE_ENUMERATE, * PRTL_TRACE_ENUMERATE;
  1580. //
  1581. // Trace database interfaces
  1582. //
  1583. PRTL_TRACE_DATABASE
  1584. RtlTraceDatabaseCreate (
  1585. IN ULONG Buckets,
  1586. IN SIZE_T MaximumSize OPTIONAL,
  1587. IN ULONG Flags, // OPTIONAL in User mode
  1588. IN ULONG Tag, // OPTIONAL in User mode
  1589. IN RTL_TRACE_HASH_FUNCTION HashFunction OPTIONAL
  1590. );
  1591. BOOLEAN
  1592. RtlTraceDatabaseDestroy (
  1593. IN PRTL_TRACE_DATABASE Database
  1594. );
  1595. BOOLEAN
  1596. RtlTraceDatabaseValidate (
  1597. IN PRTL_TRACE_DATABASE Database
  1598. );
  1599. BOOLEAN
  1600. RtlTraceDatabaseAdd (
  1601. IN PRTL_TRACE_DATABASE Database,
  1602. IN ULONG Count,
  1603. IN PVOID * Trace,
  1604. OUT PRTL_TRACE_BLOCK * TraceBlock OPTIONAL
  1605. );
  1606. BOOLEAN
  1607. RtlTraceDatabaseFind (
  1608. PRTL_TRACE_DATABASE Database,
  1609. IN ULONG Count,
  1610. IN PVOID * Trace,
  1611. OUT PRTL_TRACE_BLOCK * TraceBlock OPTIONAL
  1612. );
  1613. BOOLEAN
  1614. RtlTraceDatabaseEnumerate (
  1615. PRTL_TRACE_DATABASE Database,
  1616. OUT PRTL_TRACE_ENUMERATE Enumerate,
  1617. OUT PRTL_TRACE_BLOCK * TraceBlock
  1618. );
  1619. VOID
  1620. RtlTraceDatabaseLock (
  1621. IN PRTL_TRACE_DATABASE Database
  1622. );
  1623. VOID
  1624. RtlTraceDatabaseUnlock (
  1625. IN PRTL_TRACE_DATABASE Database
  1626. );
  1627. #if defined(_IA64_)
  1628. VOID
  1629. RtlCopyIa64FloatRegisterContext(
  1630. IN PFLOAT128 Destination,
  1631. IN PFLOAT128 Source,
  1632. IN ULONGLONG Length
  1633. );
  1634. VOID
  1635. RtlpCaptureRnats (
  1636. IN OUT PCONTEXT ContextRecord
  1637. );
  1638. #if !defined(MIDL_PASS)
  1639. FORCEINLINE
  1640. ULONGLONG
  1641. RtlpRseShrinkByNumber(
  1642. ULONGLONG Bsp,
  1643. LONGLONG NumReg
  1644. )
  1645. /*++
  1646. Routine Description:
  1647. This function calculates a new bsp by shrinking the current frame
  1648. by a given number.
  1649. Algorithm:
  1650. a new bsp = (bsp - num_registers*8 - ((62 - bsp [8:3] + num_registers)/63)*8)
  1651. (62 - bsp [8:3] + numbers)/63 could be translated to:
  1652. if ((62 - bsp [8:3] + num_registers) >= 63) then 1 extra shrink
  1653. if (((62 - bsp [8:3] + num_registers) - 63) >= 63) then 2 extra shrink
  1654. otherwise 0 bsp shrink
  1655. ((62 - bsp [8:3] + num_register) >= 63) is equal to (num_registers - bsp [8:3] > 0)
  1656. (((62 - bsp [8:3] + num_registers) - 63) >= 63) is equal to (num_registers - bsp [8:3] > 63)
  1657. therefore,
  1658. if (number_registers - bsp [8:3] > 0) then bsp - num_registers*8 - 1*8
  1659. if (number_registers - bsp [8:3] > 63) then bsp - num_registers*8 - 2*8
  1660. otherwise bsp - num_registers*8
  1661. Arguments:
  1662. Bsp - Supplies the BSP value
  1663. NumReg - Supplies the number of register to shrink
  1664. Return Value:
  1665. A new BSP value is returned.
  1666. --*/
  1667. {
  1668. ULONGLONG NewBsp;
  1669. IA64_BSP TempBsp;
  1670. LONGLONG Bsp83;
  1671. TempBsp.ull = Bsp;
  1672. NewBsp = Bsp - (NumReg << 3);
  1673. Bsp83 = (LONGLONG)TempBsp.sb.bsp83;
  1674. if ((NumReg - Bsp83) > 0) {
  1675. NewBsp -= 8;
  1676. }
  1677. if ((NumReg - Bsp83) > 63) {
  1678. NewBsp -= 8;
  1679. }
  1680. return NewBsp;
  1681. }
  1682. FORCEINLINE
  1683. ULONGLONG
  1684. RtlpRseGrowByNumber(
  1685. ULONGLONG Bsp,
  1686. LONGLONG NumReg
  1687. )
  1688. /*++
  1689. Routine Description:
  1690. This function calculates a new BSP by growing the current frame by
  1691. the SOF (Size of Frame) of a given frame maker.
  1692. Algorithm:
  1693. a new bsp = (bsp + (num_registers*8) + ((bsp [8:3] + num_registers)/63)*8)
  1694. (bsp [8:3] + num_registers)/63 could be translated to:
  1695. if bsp [8:3] + num_registers >= 63 then grows 1 extra
  1696. if bsp [8:3] + num_registers >= 126 then grows 2 extra
  1697. otherwise grows 0 extra
  1698. Arguments:
  1699. Bsp - Supplies the BSP value
  1700. NumReg - Supplies the number of register to grow
  1701. Return Value:
  1702. A new BSP value is returned.
  1703. --*/
  1704. {
  1705. ULONGLONG NewBsp;
  1706. IA64_BSP TempBsp;
  1707. LONGLONG Bsp83;
  1708. TempBsp.ull = Bsp;
  1709. NewBsp = Bsp + (NumReg << 3);
  1710. Bsp83 = (LONGLONG)TempBsp.sb.bsp83;
  1711. if ((NumReg + Bsp83) >= 63) {
  1712. NewBsp += 8;
  1713. }
  1714. if ((NumReg + Bsp83) >= 126) {
  1715. NewBsp += 8;
  1716. }
  1717. return NewBsp;
  1718. }
  1719. FORCEINLINE
  1720. ULONGLONG
  1721. RtlpRseShrinkBySOF (
  1722. ULONGLONG BSP,
  1723. ULONGLONG PFS
  1724. )
  1725. {
  1726. IA64_PFS TempPfs;
  1727. TempPfs.ull = PFS;
  1728. return RtlpRseShrinkByNumber(BSP, TempPfs.sb.pfs_sof);
  1729. }
  1730. FORCEINLINE
  1731. ULONGLONG
  1732. RtlpRseShrinkBySOL (
  1733. ULONGLONG BSP,
  1734. ULONGLONG PFS
  1735. )
  1736. {
  1737. IA64_PFS TempPfs;
  1738. TempPfs.ull = PFS;
  1739. return RtlpRseShrinkByNumber(BSP, TempPfs.sb.pfs_sol);
  1740. }
  1741. FORCEINLINE
  1742. ULONGLONG
  1743. RtlpRseGrowBySOF (
  1744. ULONGLONG BSP,
  1745. ULONGLONG PFS
  1746. )
  1747. {
  1748. IA64_PFS TempPfs;
  1749. TempPfs.ull = PFS ;
  1750. return RtlpRseGrowByNumber(BSP, TempPfs.sb.pfs_sof);
  1751. }
  1752. FORCEINLINE
  1753. ULONGLONG
  1754. RtlpRseGrowBySOL (
  1755. ULONGLONG BSP,
  1756. ULONGLONG PFS
  1757. )
  1758. {
  1759. IA64_PFS TempPfs;
  1760. TempPfs.ull = PFS;
  1761. return RtlpRseGrowByNumber(BSP, TempPfs.sb.pfs_sol);
  1762. }
  1763. FORCEINLINE
  1764. ULONGLONG
  1765. RtlpRseRNatCollectOffset(
  1766. ULONGLONG BSP
  1767. )
  1768. {
  1769. IA64_BSP TempBsp;
  1770. TempBsp.ull = BSP;
  1771. return (TempBsp.sb.bsp83);
  1772. }
  1773. FORCEINLINE
  1774. PULONGLONG
  1775. RtlpRseRNatAddress(
  1776. ULONGLONG BSP
  1777. )
  1778. {
  1779. IA64_BSP TempBsp;
  1780. TempBsp.ull = BSP;
  1781. TempBsp.sb.bsp83 = 63;
  1782. return ((PULONGLONG)TempBsp.ull);
  1783. }
  1784. #endif // MIDL_PASS
  1785. #endif // _IA64_
  1786. //
  1787. // Subroutines for dealing with Win32 ATOMs. Used by kernel mode window
  1788. // manager and user mode implementation of Win32 ATOM API calls in KERNEL32
  1789. //
  1790. #define RTL_ATOM_MAXIMUM_INTEGER_ATOM (RTL_ATOM)0xC000
  1791. #define RTL_ATOM_INVALID_ATOM (RTL_ATOM)0x0000
  1792. #define RTL_ATOM_TABLE_DEFAULT_NUMBER_OF_BUCKETS 37
  1793. #define RTL_ATOM_MAXIMUM_NAME_LENGTH 255
  1794. #define RTL_ATOM_PINNED 0x01
  1795. NTSYSAPI
  1796. NTSTATUS
  1797. NTAPI
  1798. RtlInitializeAtomPackage(
  1799. IN ULONG AllocationTag
  1800. );
  1801. NTSYSAPI
  1802. NTSTATUS
  1803. NTAPI
  1804. RtlCreateAtomTable(
  1805. IN ULONG NumberOfBuckets,
  1806. OUT PVOID *AtomTableHandle
  1807. );
  1808. NTSYSAPI
  1809. NTSTATUS
  1810. NTAPI
  1811. RtlDestroyAtomTable(
  1812. IN PVOID AtomTableHandle
  1813. );
  1814. NTSYSAPI
  1815. NTSTATUS
  1816. NTAPI
  1817. RtlEmptyAtomTable(
  1818. IN PVOID AtomTableHandle,
  1819. IN BOOLEAN IncludePinnedAtoms
  1820. );
  1821. NTSYSAPI
  1822. NTSTATUS
  1823. NTAPI
  1824. RtlAddAtomToAtomTable(
  1825. IN PVOID AtomTableHandle,
  1826. IN PWSTR AtomName OPTIONAL,
  1827. IN OUT PRTL_ATOM Atom OPTIONAL
  1828. );
  1829. NTSYSAPI
  1830. NTSTATUS
  1831. NTAPI
  1832. RtlLookupAtomInAtomTable(
  1833. IN PVOID AtomTableHandle,
  1834. IN PWSTR AtomName,
  1835. OUT PRTL_ATOM Atom OPTIONAL
  1836. );
  1837. NTSYSAPI
  1838. NTSTATUS
  1839. NTAPI
  1840. RtlDeleteAtomFromAtomTable(
  1841. IN PVOID AtomTableHandle,
  1842. IN RTL_ATOM Atom
  1843. );
  1844. NTSYSAPI
  1845. NTSTATUS
  1846. NTAPI
  1847. RtlPinAtomInAtomTable(
  1848. IN PVOID AtomTableHandle,
  1849. IN RTL_ATOM Atom
  1850. );
  1851. NTSYSAPI
  1852. NTSTATUS
  1853. NTAPI
  1854. RtlQueryAtomInAtomTable(
  1855. IN PVOID AtomTableHandle,
  1856. IN RTL_ATOM Atom,
  1857. OUT PULONG AtomUsage OPTIONAL,
  1858. OUT PULONG AtomFlags OPTIONAL,
  1859. IN OUT PWSTR AtomName OPTIONAL,
  1860. IN OUT PULONG AtomNameLength OPTIONAL
  1861. );
  1862. NTSYSAPI
  1863. NTSTATUS
  1864. NTAPI
  1865. RtlQueryAtomsInAtomTable(
  1866. IN PVOID AtomTableHandle,
  1867. IN ULONG MaximumNumberOfAtoms,
  1868. OUT PULONG NumberOfAtoms,
  1869. OUT PRTL_ATOM Atoms
  1870. );
  1871. // begin_ntddk begin_wdm begin_nthal
  1872. //
  1873. // Subroutines for dealing with the Registry
  1874. //
  1875. // end_ntddk end_wdm end_nthal
  1876. NTSYSAPI
  1877. BOOLEAN
  1878. NTAPI
  1879. RtlGetNtProductType(
  1880. PNT_PRODUCT_TYPE NtProductType
  1881. );
  1882. NTSYSAPI
  1883. NTSTATUS
  1884. NTAPI
  1885. RtlFormatCurrentUserKeyPath (
  1886. OUT PUNICODE_STRING CurrentUserKeyPath
  1887. );
  1888. NTSYSAPI
  1889. NTSTATUS
  1890. NTAPI
  1891. RtlOpenCurrentUser(
  1892. IN ULONG DesiredAccess,
  1893. OUT PHANDLE CurrentUserKey
  1894. );
  1895. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  1896. typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
  1897. IN PWSTR ValueName,
  1898. IN ULONG ValueType,
  1899. IN PVOID ValueData,
  1900. IN ULONG ValueLength,
  1901. IN PVOID Context,
  1902. IN PVOID EntryContext
  1903. );
  1904. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  1905. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  1906. ULONG Flags;
  1907. PWSTR Name;
  1908. PVOID EntryContext;
  1909. ULONG DefaultType;
  1910. PVOID DefaultData;
  1911. ULONG DefaultLength;
  1912. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  1913. //
  1914. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  1915. // entry is interpreted. A NULL name indicates the end of the table.
  1916. //
  1917. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  1918. // table or until next subkey are value
  1919. // names for that subkey to look at.
  1920. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  1921. // this and all following table entries.
  1922. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  1923. // entry.
  1924. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  1925. // value name, just wants a call out, not
  1926. // an enumeration of all values.
  1927. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  1928. // REG_MULTI_SZ into multiple callouts or
  1929. // to prevent the expansion of environment
  1930. // variable values in REG_EXPAND_SZ
  1931. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  1932. // field points to location to store value.
  1933. // For null terminated strings, EntryContext
  1934. // points to UNICODE_STRING structure that
  1935. // that describes maximum size of buffer.
  1936. // If .Buffer field is NULL then a buffer is
  1937. // allocated.
  1938. //
  1939. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  1940. // are queried.
  1941. NTSYSAPI
  1942. NTSTATUS
  1943. NTAPI
  1944. RtlQueryRegistryValues(
  1945. IN ULONG RelativeTo,
  1946. IN PCWSTR Path,
  1947. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  1948. IN PVOID Context,
  1949. IN PVOID Environment OPTIONAL
  1950. );
  1951. NTSYSAPI
  1952. NTSTATUS
  1953. NTAPI
  1954. RtlWriteRegistryValue(
  1955. IN ULONG RelativeTo,
  1956. IN PCWSTR Path,
  1957. IN PCWSTR ValueName,
  1958. IN ULONG ValueType,
  1959. IN PVOID ValueData,
  1960. IN ULONG ValueLength
  1961. );
  1962. NTSYSAPI
  1963. NTSTATUS
  1964. NTAPI
  1965. RtlDeleteRegistryValue(
  1966. IN ULONG RelativeTo,
  1967. IN PCWSTR Path,
  1968. IN PCWSTR ValueName
  1969. );
  1970. // end_wdm
  1971. NTSYSAPI
  1972. NTSTATUS
  1973. NTAPI
  1974. RtlCreateRegistryKey(
  1975. IN ULONG RelativeTo,
  1976. IN PWSTR Path
  1977. );
  1978. NTSYSAPI
  1979. NTSTATUS
  1980. NTAPI
  1981. RtlCheckRegistryKey(
  1982. IN ULONG RelativeTo,
  1983. IN PWSTR Path
  1984. );
  1985. // begin_wdm
  1986. //
  1987. // The following values for the RelativeTo parameter determine what the
  1988. // Path parameter to RtlQueryRegistryValues is relative to.
  1989. //
  1990. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  1991. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  1992. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  1993. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  1994. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  1995. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  1996. #define RTL_REGISTRY_MAXIMUM 6
  1997. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  1998. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  1999. // end_ntddk end_wdm end_nthal end_ntifs
  2000. //
  2001. // Some simple Rtl routines for random number and
  2002. // hexadecimal conversion
  2003. //
  2004. NTSYSAPI
  2005. ULONG
  2006. NTAPI
  2007. RtlUniform (
  2008. PULONG Seed
  2009. );
  2010. NTSYSAPI // ntifs
  2011. ULONG // ntifs
  2012. NTAPI // ntifs
  2013. RtlRandom ( // ntifs
  2014. PULONG Seed // ntifs
  2015. ); // ntifs
  2016. NTSYSAPI // ntifs
  2017. ULONG // ntifs
  2018. NTAPI // ntifs
  2019. RtlRandomEx ( // ntifs
  2020. PULONG Seed // ntifs
  2021. ); // ntifs
  2022. NTSTATUS
  2023. RtlComputeImportTableHash(
  2024. IN HANDLE hFile,
  2025. IN PCHAR Hash,
  2026. IN ULONG ImportTableHashRevision
  2027. );
  2028. NTSYSAPI
  2029. NTSTATUS
  2030. NTAPI
  2031. RtlIntegerToChar (
  2032. ULONG Value,
  2033. ULONG Base,
  2034. LONG OutputLength,
  2035. PSZ String
  2036. );
  2037. NTSYSAPI
  2038. NTSTATUS
  2039. NTAPI
  2040. RtlIntegerToUnicode (
  2041. IN ULONG Value,
  2042. IN ULONG Base OPTIONAL,
  2043. IN LONG OutputLength,
  2044. OUT PWSTR String
  2045. );
  2046. NTSYSAPI // ntddk ntifs
  2047. NTSTATUS // ntddk ntifs
  2048. NTAPI // ntddk ntifs
  2049. RtlCharToInteger ( // ntddk ntifs
  2050. PCSZ String, // ntddk ntifs
  2051. ULONG Base, // ntddk ntifs
  2052. PULONG Value // ntddk ntifs
  2053. ); // ntddk ntifs
  2054. NTSYSAPI
  2055. NTSTATUS
  2056. NTAPI
  2057. RtlLargeIntegerToChar (
  2058. PLARGE_INTEGER Value,
  2059. ULONG Base OPTIONAL,
  2060. LONG OutputLength,
  2061. PSZ String
  2062. );
  2063. NTSYSAPI
  2064. NTSTATUS
  2065. NTAPI
  2066. RtlLargeIntegerToUnicode (
  2067. IN PLARGE_INTEGER Value,
  2068. IN ULONG Base OPTIONAL,
  2069. IN LONG OutputLength,
  2070. OUT PWSTR String
  2071. );
  2072. // begin_ntosp
  2073. //
  2074. // Some simple Rtl routines for IP address <-> string literal conversion
  2075. //
  2076. struct in_addr;
  2077. struct in6_addr;
  2078. NTSYSAPI
  2079. PSTR
  2080. NTAPI
  2081. RtlIpv4AddressToStringA (
  2082. IN const struct in_addr *Addr,
  2083. OUT PSTR S
  2084. );
  2085. NTSYSAPI
  2086. PSTR
  2087. NTAPI
  2088. RtlIpv6AddressToStringA (
  2089. IN const struct in6_addr *Addr,
  2090. OUT PSTR S
  2091. );
  2092. NTSYSAPI
  2093. NTSTATUS
  2094. NTAPI
  2095. RtlIpv4AddressToStringExA(
  2096. IN const struct in_addr *Address,
  2097. IN USHORT Port,
  2098. OUT PSTR AddressString,
  2099. IN OUT PULONG AddressStringLength
  2100. );
  2101. NTSYSAPI
  2102. NTSTATUS
  2103. NTAPI
  2104. RtlIpv6AddressToStringExA(
  2105. IN const struct in6_addr *Address,
  2106. IN ULONG ScopeId,
  2107. IN USHORT Port,
  2108. OUT PSTR AddressString,
  2109. IN OUT PULONG AddressStringLength
  2110. );
  2111. NTSYSAPI
  2112. PWSTR
  2113. NTAPI
  2114. RtlIpv4AddressToStringW (
  2115. IN const struct in_addr *Addr,
  2116. OUT PWSTR S
  2117. );
  2118. NTSYSAPI
  2119. PWSTR
  2120. NTAPI
  2121. RtlIpv6AddressToStringW (
  2122. IN const struct in6_addr *Addr,
  2123. OUT PWSTR S
  2124. );
  2125. NTSYSAPI
  2126. NTSTATUS
  2127. NTAPI
  2128. RtlIpv4AddressToStringExW(
  2129. IN const struct in_addr *Address,
  2130. IN USHORT Port,
  2131. OUT PWSTR AddressString,
  2132. IN OUT PULONG AddressStringLength
  2133. );
  2134. NTSYSAPI
  2135. NTSTATUS
  2136. NTAPI
  2137. RtlIpv6AddressToStringExW(
  2138. IN const struct in6_addr *Address,
  2139. IN ULONG ScopeId,
  2140. IN USHORT Port,
  2141. OUT PWSTR AddressString,
  2142. IN OUT PULONG AddressStringLength
  2143. );
  2144. NTSYSAPI
  2145. NTSTATUS
  2146. NTAPI
  2147. RtlIpv4StringToAddressA (
  2148. IN PCSTR S,
  2149. IN BOOLEAN Strict,
  2150. OUT PCSTR *Terminator,
  2151. OUT struct in_addr *Addr
  2152. );
  2153. NTSYSAPI
  2154. NTSTATUS
  2155. NTAPI
  2156. RtlIpv6StringToAddressA (
  2157. IN PCSTR S,
  2158. OUT PCSTR *Terminator,
  2159. OUT struct in6_addr *Addr
  2160. );
  2161. NTSYSAPI
  2162. NTSTATUS
  2163. NTAPI
  2164. RtlIpv4StringToAddressExA (
  2165. IN PCSTR AddressString,
  2166. IN BOOLEAN Strict,
  2167. OUT struct in_addr *Address,
  2168. OUT PUSHORT Port
  2169. );
  2170. NTSYSAPI
  2171. NTSTATUS
  2172. NTAPI
  2173. RtlIpv6StringToAddressExA (
  2174. IN PCSTR AddressString,
  2175. OUT struct in6_addr *Address,
  2176. OUT PULONG ScopeId,
  2177. OUT PUSHORT Port
  2178. );
  2179. NTSYSAPI
  2180. NTSTATUS
  2181. NTAPI
  2182. RtlIpv4StringToAddressW (
  2183. IN PCWSTR S,
  2184. IN BOOLEAN Strict,
  2185. OUT LPCWSTR *Terminator,
  2186. OUT struct in_addr *Addr
  2187. );
  2188. NTSYSAPI
  2189. NTSTATUS
  2190. NTAPI
  2191. RtlIpv6StringToAddressW (
  2192. IN PCWSTR S,
  2193. OUT PCWSTR *Terminator,
  2194. OUT struct in6_addr *Addr
  2195. );
  2196. NTSYSAPI
  2197. NTSTATUS
  2198. NTAPI
  2199. RtlIpv4StringToAddressExW (
  2200. IN PCWSTR AddressString,
  2201. IN BOOLEAN Strict,
  2202. OUT struct in_addr *Address,
  2203. OUT PUSHORT Port
  2204. );
  2205. NTSYSAPI
  2206. NTSTATUS
  2207. NTAPI
  2208. RtlIpv6StringToAddressExW (
  2209. IN PCWSTR AddressString,
  2210. OUT struct in6_addr *Address,
  2211. OUT PULONG ScopeId,
  2212. OUT PUSHORT Port
  2213. );
  2214. #ifdef UNICODE
  2215. #define RtlIpv4AddressToString RtlIpv4AddressToStringW
  2216. #define RtlIpv6AddressToString RtlIpv6AddressToStringW
  2217. #define RtlIpv4StringToAddress RtlIpv4StringToAddressW
  2218. #define RtlIpv6StringToAddress RtlIpv6StringToAddressW
  2219. #define RtlIpv6StringToAddressEx RtlIpv6StringToAddressExW
  2220. #define RtlIpv4AddressToStringEx RtlIpv4AddressToStringExW
  2221. #define RtlIpv6AddressToStringEx RtlIpv6AddressToStringExW
  2222. #define RtlIpv4StringToAddressEx RtlIpv4StringToAddressExW
  2223. #else
  2224. #define RtlIpv4AddressToString RtlIpv4AddressToStringA
  2225. #define RtlIpv6AddressToString RtlIpv6AddressToStringA
  2226. #define RtlIpv4StringToAddress RtlIpv4StringToAddressA
  2227. #define RtlIpv6StringToAddress RtlIpv6StringToAddressA
  2228. #define RtlIpv6StringToAddressEx RtlIpv6StringToAddressExA
  2229. #define RtlIpv4AddressToStringEx RtlIpv4AddressToStringExA
  2230. #define RtlIpv6AddressToStringEx RtlIpv6AddressToStringExA
  2231. #define RtlIpv4StringToAddressEx RtlIpv4StringToAddressExA
  2232. #endif // UNICODE
  2233. // end_ntosp
  2234. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  2235. NTSYSAPI
  2236. NTSTATUS
  2237. NTAPI
  2238. RtlIntegerToUnicodeString (
  2239. ULONG Value,
  2240. ULONG Base,
  2241. PUNICODE_STRING String
  2242. );
  2243. NTSYSAPI
  2244. NTSTATUS
  2245. NTAPI
  2246. RtlInt64ToUnicodeString (
  2247. IN ULONGLONG Value,
  2248. IN ULONG Base OPTIONAL,
  2249. IN OUT PUNICODE_STRING String
  2250. );
  2251. #ifdef _WIN64
  2252. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
  2253. #else
  2254. #define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
  2255. #endif
  2256. NTSYSAPI
  2257. NTSTATUS
  2258. NTAPI
  2259. RtlUnicodeStringToInteger (
  2260. PCUNICODE_STRING String,
  2261. ULONG Base,
  2262. PULONG Value
  2263. );
  2264. //
  2265. // String manipulation routines
  2266. //
  2267. #ifdef _NTSYSTEM_
  2268. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  2269. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  2270. #else
  2271. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  2272. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  2273. #endif // _NTSYSTEM_
  2274. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  2275. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  2276. NTSYSAPI
  2277. VOID
  2278. NTAPI
  2279. RtlInitString(
  2280. PSTRING DestinationString,
  2281. PCSZ SourceString
  2282. );
  2283. NTSYSAPI
  2284. VOID
  2285. NTAPI
  2286. RtlInitAnsiString(
  2287. PANSI_STRING DestinationString,
  2288. PCSZ SourceString
  2289. );
  2290. NTSYSAPI
  2291. VOID
  2292. NTAPI
  2293. RtlInitUnicodeString(
  2294. PUNICODE_STRING DestinationString,
  2295. PCWSTR SourceString
  2296. );
  2297. #define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
  2298. ((_ucStr)->Buffer = (_buf), \
  2299. (_ucStr)->Length = 0, \
  2300. (_ucStr)->MaximumLength = (USHORT)(_bufSize))
  2301. // end_ntddk end_wdm
  2302. NTSYSAPI
  2303. NTSTATUS
  2304. NTAPI
  2305. RtlInitUnicodeStringEx(
  2306. PUNICODE_STRING DestinationString,
  2307. PCWSTR SourceString
  2308. );
  2309. NTSYSAPI
  2310. NTSTATUS
  2311. NTAPI
  2312. RtlInitAnsiStringEx(
  2313. OUT PANSI_STRING DestinationString,
  2314. IN PCSZ SourceString OPTIONAL
  2315. );
  2316. NTSYSAPI
  2317. BOOLEAN
  2318. NTAPI
  2319. RtlCreateUnicodeString(
  2320. OUT PUNICODE_STRING DestinationString,
  2321. IN PCWSTR SourceString
  2322. );
  2323. // end_ntifs
  2324. NTSYSAPI
  2325. BOOLEAN
  2326. NTAPI
  2327. RtlEqualDomainName(
  2328. IN PCUNICODE_STRING String1,
  2329. IN PCUNICODE_STRING String2
  2330. );
  2331. NTSYSAPI
  2332. BOOLEAN
  2333. NTAPI
  2334. RtlEqualComputerName(
  2335. IN PCUNICODE_STRING String1,
  2336. IN PCUNICODE_STRING String2
  2337. );
  2338. NTSTATUS
  2339. RtlDnsHostNameToComputerName(
  2340. OUT PUNICODE_STRING ComputerNameString,
  2341. IN PCUNICODE_STRING DnsHostNameString,
  2342. IN BOOLEAN AllocateComputerNameString
  2343. );
  2344. NTSYSAPI
  2345. BOOLEAN
  2346. NTAPI
  2347. RtlCreateUnicodeStringFromAsciiz(
  2348. OUT PUNICODE_STRING DestinationString,
  2349. IN PCSZ SourceString
  2350. );
  2351. // begin_ntddk begin_ntifs
  2352. NTSYSAPI
  2353. VOID
  2354. NTAPI
  2355. RtlCopyString(
  2356. PSTRING DestinationString,
  2357. const STRING * SourceString
  2358. );
  2359. NTSYSAPI
  2360. CHAR
  2361. NTAPI
  2362. RtlUpperChar (
  2363. CHAR Character
  2364. );
  2365. NTSYSAPI
  2366. LONG
  2367. NTAPI
  2368. RtlCompareString(
  2369. const STRING * String1,
  2370. const STRING * String2,
  2371. BOOLEAN CaseInSensitive
  2372. );
  2373. NTSYSAPI
  2374. BOOLEAN
  2375. NTAPI
  2376. RtlEqualString(
  2377. const STRING * String1,
  2378. const STRING * String2,
  2379. BOOLEAN CaseInSensitive
  2380. );
  2381. // end_ntddk end_ntifs
  2382. NTSYSAPI
  2383. BOOLEAN
  2384. NTAPI
  2385. RtlPrefixString(
  2386. const STRING * String1,
  2387. const STRING * String2,
  2388. BOOLEAN CaseInSensitive
  2389. );
  2390. // begin_ntddk begin_ntifs
  2391. NTSYSAPI
  2392. VOID
  2393. NTAPI
  2394. RtlUpperString(
  2395. PSTRING DestinationString,
  2396. const STRING * SourceString
  2397. );
  2398. // end_ntddk end_ntifs
  2399. NTSYSAPI
  2400. NTSTATUS
  2401. NTAPI
  2402. RtlAppendAsciizToString (
  2403. PSTRING Destination,
  2404. PCSZ Source
  2405. );
  2406. // begin_ntifs
  2407. NTSYSAPI
  2408. NTSTATUS
  2409. NTAPI
  2410. RtlAppendStringToString (
  2411. PSTRING Destination,
  2412. const STRING * Source
  2413. );
  2414. // begin_ntddk begin_wdm
  2415. //
  2416. // NLS String functions
  2417. //
  2418. NTSYSAPI
  2419. NTSTATUS
  2420. NTAPI
  2421. RtlAnsiStringToUnicodeString(
  2422. PUNICODE_STRING DestinationString,
  2423. PCANSI_STRING SourceString,
  2424. BOOLEAN AllocateDestinationString
  2425. );
  2426. // end_ntddk end_wdm end_nthal end_ntifs
  2427. NTSYSAPI
  2428. WCHAR
  2429. NTAPI
  2430. RtlAnsiCharToUnicodeChar(
  2431. PUCHAR *SourceCharacter
  2432. );
  2433. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis
  2434. NTSYSAPI
  2435. NTSTATUS
  2436. NTAPI
  2437. RtlUnicodeStringToAnsiString(
  2438. PANSI_STRING DestinationString,
  2439. PCUNICODE_STRING SourceString,
  2440. BOOLEAN AllocateDestinationString
  2441. );
  2442. // end_ntddk end_wdm end_nthal end_ntifs end_ntndis
  2443. NTSYSAPI
  2444. NTSTATUS
  2445. NTAPI
  2446. RtlUpcaseUnicodeStringToAnsiString(
  2447. PANSI_STRING DestinationString,
  2448. PCUNICODE_STRING SourceString,
  2449. BOOLEAN AllocateDestinationString
  2450. );
  2451. // begin_ntifs
  2452. NTSYSAPI
  2453. NTSTATUS
  2454. NTAPI
  2455. RtlOemStringToUnicodeString(
  2456. PUNICODE_STRING DestinationString,
  2457. PCOEM_STRING SourceString,
  2458. BOOLEAN AllocateDestinationString
  2459. );
  2460. NTSYSAPI
  2461. NTSTATUS
  2462. NTAPI
  2463. RtlUnicodeStringToOemString(
  2464. POEM_STRING DestinationString,
  2465. PCUNICODE_STRING SourceString,
  2466. BOOLEAN AllocateDestinationString
  2467. );
  2468. NTSYSAPI
  2469. NTSTATUS
  2470. NTAPI
  2471. RtlUpcaseUnicodeStringToOemString(
  2472. POEM_STRING DestinationString,
  2473. PCUNICODE_STRING SourceString,
  2474. BOOLEAN AllocateDestinationString
  2475. );
  2476. NTSYSAPI
  2477. NTSTATUS
  2478. NTAPI
  2479. RtlOemStringToCountedUnicodeString(
  2480. PUNICODE_STRING DestinationString,
  2481. PCOEM_STRING SourceString,
  2482. BOOLEAN AllocateDestinationString
  2483. );
  2484. NTSYSAPI
  2485. NTSTATUS
  2486. NTAPI
  2487. RtlUnicodeStringToCountedOemString(
  2488. POEM_STRING DestinationString,
  2489. PCUNICODE_STRING SourceString,
  2490. BOOLEAN AllocateDestinationString
  2491. );
  2492. NTSYSAPI
  2493. NTSTATUS
  2494. NTAPI
  2495. RtlUpcaseUnicodeStringToCountedOemString(
  2496. POEM_STRING DestinationString,
  2497. PCUNICODE_STRING SourceString,
  2498. BOOLEAN AllocateDestinationString
  2499. );
  2500. // begin_ntddk begin_wdm begin_ntndis
  2501. NTSYSAPI
  2502. LONG
  2503. NTAPI
  2504. RtlCompareUnicodeString(
  2505. PCUNICODE_STRING String1,
  2506. PCUNICODE_STRING String2,
  2507. BOOLEAN CaseInSensitive
  2508. );
  2509. NTSYSAPI
  2510. BOOLEAN
  2511. NTAPI
  2512. RtlEqualUnicodeString(
  2513. PCUNICODE_STRING String1,
  2514. PCUNICODE_STRING String2,
  2515. BOOLEAN CaseInSensitive
  2516. );
  2517. #define HASH_STRING_ALGORITHM_DEFAULT (0)
  2518. #define HASH_STRING_ALGORITHM_X65599 (1)
  2519. #define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
  2520. NTSYSAPI
  2521. NTSTATUS
  2522. NTAPI
  2523. RtlHashUnicodeString(
  2524. IN const UNICODE_STRING *String,
  2525. IN BOOLEAN CaseInSensitive,
  2526. IN ULONG HashAlgorithm,
  2527. OUT PULONG HashValue
  2528. );
  2529. // end_ntddk end_wdm end_ntndis
  2530. NTSYSAPI
  2531. NTSTATUS
  2532. NTAPI
  2533. RtlValidateUnicodeString(
  2534. IN ULONG Flags,
  2535. IN const UNICODE_STRING *String
  2536. );
  2537. #define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE (0x00000001)
  2538. #define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING (0x00000002)
  2539. NTSYSAPI
  2540. NTSTATUS
  2541. NTAPI
  2542. RtlDuplicateUnicodeString(
  2543. IN ULONG Flags,
  2544. IN const UNICODE_STRING *StringIn,
  2545. OUT UNICODE_STRING *StringOut
  2546. );
  2547. // begin_ntddk begin_ntndis
  2548. NTSYSAPI
  2549. BOOLEAN
  2550. NTAPI
  2551. RtlPrefixUnicodeString(
  2552. IN PCUNICODE_STRING String1,
  2553. IN PCUNICODE_STRING String2,
  2554. IN BOOLEAN CaseInSensitive
  2555. );
  2556. NTSYSAPI
  2557. NTSTATUS
  2558. NTAPI
  2559. RtlUpcaseUnicodeString(
  2560. PUNICODE_STRING DestinationString,
  2561. PCUNICODE_STRING SourceString,
  2562. BOOLEAN AllocateDestinationString
  2563. );
  2564. // end_ntddk end_ntifs end_ntndis
  2565. #define RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END (0x00000001)
  2566. #define RTL_FIND_CHAR_IN_UNICODE_STRING_COMPLEMENT_CHAR_SET (0x00000002)
  2567. #define RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE (0x00000004)
  2568. NTSYSAPI
  2569. NTSTATUS
  2570. NTAPI
  2571. RtlFindCharInUnicodeString(
  2572. IN ULONG Flags,
  2573. IN PCUNICODE_STRING StringToSearch,
  2574. IN PCUNICODE_STRING CharSet,
  2575. OUT USHORT *NonInclusivePrefixLength
  2576. );
  2577. // begin_ntifs
  2578. NTSTATUS
  2579. RtlDowncaseUnicodeString(
  2580. OUT PUNICODE_STRING DestinationString,
  2581. IN PCUNICODE_STRING SourceString,
  2582. IN BOOLEAN AllocateDestinationString
  2583. );
  2584. // end_ntifs
  2585. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis
  2586. NTSYSAPI
  2587. VOID
  2588. NTAPI
  2589. RtlCopyUnicodeString(
  2590. PUNICODE_STRING DestinationString,
  2591. PCUNICODE_STRING SourceString
  2592. );
  2593. NTSYSAPI
  2594. NTSTATUS
  2595. NTAPI
  2596. RtlAppendUnicodeStringToString (
  2597. PUNICODE_STRING Destination,
  2598. PCUNICODE_STRING Source
  2599. );
  2600. NTSYSAPI
  2601. NTSTATUS
  2602. NTAPI
  2603. RtlAppendUnicodeToString (
  2604. PUNICODE_STRING Destination,
  2605. PCWSTR Source
  2606. );
  2607. // end_ntndis end_wdm
  2608. NTSYSAPI
  2609. WCHAR
  2610. NTAPI
  2611. RtlUpcaseUnicodeChar(
  2612. WCHAR SourceCharacter
  2613. );
  2614. NTSYSAPI
  2615. WCHAR
  2616. NTAPI
  2617. RtlDowncaseUnicodeChar(
  2618. WCHAR SourceCharacter
  2619. );
  2620. // begin_wdm
  2621. NTSYSAPI
  2622. VOID
  2623. NTAPI
  2624. RtlFreeUnicodeString(
  2625. PUNICODE_STRING UnicodeString
  2626. );
  2627. NTSYSAPI
  2628. VOID
  2629. NTAPI
  2630. RtlFreeAnsiString(
  2631. PANSI_STRING AnsiString
  2632. );
  2633. // end_ntddk end_wdm end_nthal
  2634. NTSYSAPI
  2635. VOID
  2636. NTAPI
  2637. RtlFreeOemString(
  2638. POEM_STRING OemString
  2639. );
  2640. // begin_wdm
  2641. NTSYSAPI
  2642. ULONG
  2643. NTAPI
  2644. RtlxUnicodeStringToAnsiSize(
  2645. PCUNICODE_STRING UnicodeString
  2646. );
  2647. //
  2648. // NTSYSAPI
  2649. // ULONG
  2650. // NTAPI
  2651. // RtlUnicodeStringToAnsiSize(
  2652. // PUNICODE_STRING UnicodeString
  2653. // );
  2654. //
  2655. #define RtlUnicodeStringToAnsiSize(STRING) ( \
  2656. NLS_MB_CODE_PAGE_TAG ? \
  2657. RtlxUnicodeStringToAnsiSize(STRING) : \
  2658. ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
  2659. )
  2660. // end_wdm
  2661. NTSYSAPI
  2662. ULONG
  2663. NTAPI
  2664. RtlxUnicodeStringToOemSize(
  2665. PCUNICODE_STRING UnicodeString
  2666. );
  2667. //
  2668. // NTSYSAPI
  2669. // ULONG
  2670. // NTAPI
  2671. // RtlUnicodeStringToOemSize(
  2672. // PUNICODE_STRING UnicodeString
  2673. // );
  2674. //
  2675. #define RtlUnicodeStringToOemSize(STRING) ( \
  2676. NLS_MB_OEM_CODE_PAGE_TAG ? \
  2677. RtlxUnicodeStringToOemSize(STRING) : \
  2678. ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
  2679. )
  2680. // end_ntifs
  2681. //
  2682. // ULONG
  2683. // RtlUnicodeStringToCountedOemSize(
  2684. // PUNICODE_STRING UnicodeString
  2685. // );
  2686. //
  2687. #define RtlUnicodeStringToCountedOemSize(STRING) ( \
  2688. (ULONG)(RtlUnicodeStringToOemSize(STRING) - sizeof(ANSI_NULL)) \
  2689. )
  2690. // begin_ntddk begin_wdm begin_ntifs
  2691. NTSYSAPI
  2692. ULONG
  2693. NTAPI
  2694. RtlxAnsiStringToUnicodeSize(
  2695. PCANSI_STRING AnsiString
  2696. );
  2697. //
  2698. // NTSYSAPI
  2699. // ULONG
  2700. // NTAPI
  2701. // RtlAnsiStringToUnicodeSize(
  2702. // PANSI_STRING AnsiString
  2703. // );
  2704. //
  2705. #define RtlAnsiStringToUnicodeSize(STRING) ( \
  2706. NLS_MB_CODE_PAGE_TAG ? \
  2707. RtlxAnsiStringToUnicodeSize(STRING) : \
  2708. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  2709. )
  2710. // end_ntddk end_wdm
  2711. NTSYSAPI
  2712. ULONG
  2713. NTAPI
  2714. RtlxOemStringToUnicodeSize(
  2715. PCOEM_STRING OemString
  2716. );
  2717. //
  2718. // NTSYSAPI
  2719. // ULONG
  2720. // NTAPI
  2721. // RtlOemStringToUnicodeSize(
  2722. // POEM_STRING OemString
  2723. // );
  2724. //
  2725. #define RtlOemStringToUnicodeSize(STRING) ( \
  2726. NLS_MB_OEM_CODE_PAGE_TAG ? \
  2727. RtlxOemStringToUnicodeSize(STRING) : \
  2728. ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
  2729. )
  2730. //
  2731. // ULONG
  2732. // RtlOemStringToCountedUnicodeSize(
  2733. // POEM_STRING OemString
  2734. // );
  2735. //
  2736. #define RtlOemStringToCountedUnicodeSize(STRING) ( \
  2737. (ULONG)(RtlOemStringToUnicodeSize(STRING) - sizeof(UNICODE_NULL)) \
  2738. )
  2739. NTSYSAPI
  2740. NTSTATUS
  2741. NTAPI
  2742. RtlMultiByteToUnicodeN(
  2743. PWSTR UnicodeString,
  2744. ULONG MaxBytesInUnicodeString,
  2745. PULONG BytesInUnicodeString,
  2746. PCSTR MultiByteString,
  2747. ULONG BytesInMultiByteString
  2748. );
  2749. NTSYSAPI
  2750. NTSTATUS
  2751. NTAPI
  2752. RtlMultiByteToUnicodeSize(
  2753. PULONG BytesInUnicodeString,
  2754. PCSTR MultiByteString,
  2755. ULONG BytesInMultiByteString
  2756. );
  2757. NTSYSAPI
  2758. NTSTATUS
  2759. NTAPI
  2760. RtlUnicodeToMultiByteSize(
  2761. PULONG BytesInMultiByteString,
  2762. IN PWSTR UnicodeString,
  2763. ULONG BytesInUnicodeString
  2764. );
  2765. NTSYSAPI
  2766. NTSTATUS
  2767. NTAPI
  2768. RtlUnicodeToMultiByteN(
  2769. PCHAR MultiByteString,
  2770. ULONG MaxBytesInMultiByteString,
  2771. PULONG BytesInMultiByteString,
  2772. PWSTR UnicodeString,
  2773. ULONG BytesInUnicodeString
  2774. );
  2775. NTSYSAPI
  2776. NTSTATUS
  2777. NTAPI
  2778. RtlUpcaseUnicodeToMultiByteN(
  2779. PCHAR MultiByteString,
  2780. ULONG MaxBytesInMultiByteString,
  2781. PULONG BytesInMultiByteString,
  2782. PWSTR UnicodeString,
  2783. ULONG BytesInUnicodeString
  2784. );
  2785. NTSYSAPI
  2786. NTSTATUS
  2787. NTAPI
  2788. RtlOemToUnicodeN(
  2789. PWSTR UnicodeString,
  2790. ULONG MaxBytesInUnicodeString,
  2791. PULONG BytesInUnicodeString,
  2792. IN PCHAR OemString,
  2793. ULONG BytesInOemString
  2794. );
  2795. NTSYSAPI
  2796. NTSTATUS
  2797. NTAPI
  2798. RtlUnicodeToOemN(
  2799. PCHAR OemString,
  2800. ULONG MaxBytesInOemString,
  2801. PULONG BytesInOemString,
  2802. PWSTR UnicodeString,
  2803. ULONG BytesInUnicodeString
  2804. );
  2805. NTSYSAPI
  2806. NTSTATUS
  2807. NTAPI
  2808. RtlUpcaseUnicodeToOemN(
  2809. PCHAR OemString,
  2810. ULONG MaxBytesInOemString,
  2811. PULONG BytesInOemString,
  2812. PWSTR UnicodeString,
  2813. ULONG BytesInUnicodeString
  2814. );
  2815. // end_ntifs
  2816. NTSYSAPI
  2817. NTSTATUS
  2818. NTAPI
  2819. RtlConsoleMultiByteToUnicodeN(
  2820. OUT PWCH UnicodeString,
  2821. IN ULONG MaxBytesInUnicodeString,
  2822. OUT PULONG BytesInUnicodeString OPTIONAL,
  2823. IN PCH MultiByteString,
  2824. IN ULONG BytesInMultiByteString,
  2825. OUT PULONG pdwSpecialChar );
  2826. // begin_winnt
  2827. #define IS_TEXT_UNICODE_ASCII16 0x0001
  2828. #define IS_TEXT_UNICODE_REVERSE_ASCII16 0x0010
  2829. #define IS_TEXT_UNICODE_STATISTICS 0x0002
  2830. #define IS_TEXT_UNICODE_REVERSE_STATISTICS 0x0020
  2831. #define IS_TEXT_UNICODE_CONTROLS 0x0004
  2832. #define IS_TEXT_UNICODE_REVERSE_CONTROLS 0x0040
  2833. #define IS_TEXT_UNICODE_SIGNATURE 0x0008
  2834. #define IS_TEXT_UNICODE_REVERSE_SIGNATURE 0x0080
  2835. #define IS_TEXT_UNICODE_ILLEGAL_CHARS 0x0100
  2836. #define IS_TEXT_UNICODE_ODD_LENGTH 0x0200
  2837. #define IS_TEXT_UNICODE_DBCS_LEADBYTE 0x0400
  2838. #define IS_TEXT_UNICODE_NULL_BYTES 0x1000
  2839. #define IS_TEXT_UNICODE_UNICODE_MASK 0x000F
  2840. #define IS_TEXT_UNICODE_REVERSE_MASK 0x00F0
  2841. #define IS_TEXT_UNICODE_NOT_UNICODE_MASK 0x0F00
  2842. #define IS_TEXT_UNICODE_NOT_ASCII_MASK 0xF000
  2843. // end_winnt
  2844. NTSYSAPI
  2845. BOOLEAN
  2846. NTAPI
  2847. RtlIsTextUnicode(
  2848. IN CONST VOID* Buffer,
  2849. IN ULONG Size,
  2850. IN OUT PULONG Result OPTIONAL
  2851. );
  2852. // begin_ntifs
  2853. typedef
  2854. PVOID
  2855. (NTAPI *PRTL_ALLOCATE_STRING_ROUTINE) (
  2856. SIZE_T NumberOfBytes
  2857. );
  2858. typedef
  2859. VOID
  2860. (NTAPI *PRTL_FREE_STRING_ROUTINE) (
  2861. PVOID Buffer
  2862. );
  2863. extern const PRTL_ALLOCATE_STRING_ROUTINE RtlAllocateStringRoutine;
  2864. extern const PRTL_FREE_STRING_ROUTINE RtlFreeStringRoutine;
  2865. //
  2866. // Defines and Routines for handling GUID's.
  2867. //
  2868. // begin_ntddk begin_wdm begin_nthal
  2869. // begin_ntminiport
  2870. #include <guiddef.h>
  2871. // end_ntminiport
  2872. #ifndef DEFINE_GUIDEX
  2873. #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
  2874. #endif // !defined(DEFINE_GUIDEX)
  2875. #ifndef STATICGUIDOF
  2876. #define STATICGUIDOF(guid) STATIC_##guid
  2877. #endif // !defined(STATICGUIDOF)
  2878. #ifndef __IID_ALIGNED__
  2879. #define __IID_ALIGNED__
  2880. #ifdef __cplusplus
  2881. inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
  2882. {
  2883. return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
  2884. }
  2885. #else // !__cplusplus
  2886. #define IsEqualGUIDAligned(guid1, guid2) \
  2887. ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
  2888. #endif // !__cplusplus
  2889. #endif // !__IID_ALIGNED__
  2890. NTSYSAPI
  2891. NTSTATUS
  2892. NTAPI
  2893. RtlStringFromGUID(
  2894. IN REFGUID Guid,
  2895. OUT PUNICODE_STRING GuidString
  2896. );
  2897. NTSYSAPI
  2898. NTSTATUS
  2899. NTAPI
  2900. RtlGUIDFromString(
  2901. IN PUNICODE_STRING GuidString,
  2902. OUT GUID* Guid
  2903. );
  2904. // end_ntddk end_wdm end_nthal
  2905. //
  2906. // Routine for generating 8.3 names from long names.
  2907. //
  2908. //
  2909. // The context structure is used when generating 8.3 names. The caller must
  2910. // always zero out the structure before starting a new generation sequence
  2911. //
  2912. typedef struct _GENERATE_NAME_CONTEXT {
  2913. //
  2914. // The structure is divided into two strings. The Name, and extension.
  2915. // Each part contains the value that was last inserted in the name.
  2916. // The length values are in terms of wchars and not bytes. We also
  2917. // store the last index value used in the generation collision algorithm.
  2918. //
  2919. USHORT Checksum;
  2920. BOOLEAN ChecksumInserted;
  2921. UCHAR NameLength; // not including extension
  2922. WCHAR NameBuffer[8]; // e.g., "ntoskrnl"
  2923. ULONG ExtensionLength; // including dot
  2924. WCHAR ExtensionBuffer[4]; // e.g., ".exe"
  2925. ULONG LastIndexValue;
  2926. } GENERATE_NAME_CONTEXT;
  2927. typedef GENERATE_NAME_CONTEXT *PGENERATE_NAME_CONTEXT;
  2928. NTSYSAPI
  2929. VOID
  2930. NTAPI
  2931. RtlGenerate8dot3Name (
  2932. IN PUNICODE_STRING Name,
  2933. IN BOOLEAN AllowExtendedCharacters,
  2934. IN OUT PGENERATE_NAME_CONTEXT Context,
  2935. OUT PUNICODE_STRING Name8dot3
  2936. );
  2937. NTSYSAPI
  2938. BOOLEAN
  2939. NTAPI
  2940. RtlIsNameLegalDOS8Dot3 (
  2941. IN PUNICODE_STRING Name,
  2942. IN OUT POEM_STRING OemName OPTIONAL,
  2943. IN OUT PBOOLEAN NameContainsSpaces OPTIONAL
  2944. );
  2945. BOOLEAN
  2946. RtlIsValidOemCharacter (
  2947. IN PWCHAR Char
  2948. );
  2949. // end_ntifs
  2950. //
  2951. // Thread Context manipulation routines.
  2952. //
  2953. NTSYSAPI
  2954. VOID
  2955. NTAPI
  2956. RtlInitializeContext(
  2957. HANDLE Process,
  2958. PCONTEXT Context,
  2959. PVOID Parameter,
  2960. PVOID InitialPc,
  2961. PVOID InitialSp
  2962. );
  2963. NTSYSAPI
  2964. NTSTATUS
  2965. NTAPI
  2966. RtlRemoteCall(
  2967. HANDLE Process,
  2968. HANDLE Thread,
  2969. PVOID CallSite,
  2970. ULONG ArgumentCount,
  2971. PULONG_PTR Arguments,
  2972. BOOLEAN PassContext,
  2973. BOOLEAN AlreadySuspended
  2974. );
  2975. //
  2976. // Process/Thread Environment Block allocation functions.
  2977. //
  2978. NTSYSAPI
  2979. VOID
  2980. NTAPI
  2981. RtlAcquirePebLock(
  2982. VOID
  2983. );
  2984. NTSYSAPI
  2985. VOID
  2986. NTAPI
  2987. RtlReleasePebLock(
  2988. VOID
  2989. );
  2990. NTSYSAPI
  2991. NTSTATUS
  2992. NTAPI
  2993. RtlAllocateFromPeb(
  2994. ULONG Size,
  2995. PVOID *Block
  2996. );
  2997. NTSYSAPI
  2998. NTSTATUS
  2999. NTAPI
  3000. RtlFreeToPeb(
  3001. PVOID Block,
  3002. ULONG Size
  3003. );
  3004. NTSYSAPI
  3005. NTSTATUS
  3006. STDAPIVCALLTYPE
  3007. RtlSetProcessIsCritical(
  3008. IN BOOLEAN NewValue,
  3009. OUT PBOOLEAN OldValue OPTIONAL,
  3010. IN BOOLEAN CheckFlag
  3011. );
  3012. NTSYSAPI
  3013. NTSTATUS
  3014. STDAPIVCALLTYPE
  3015. RtlSetThreadIsCritical(
  3016. IN BOOLEAN NewValue,
  3017. OUT PBOOLEAN OldValue OPTIONAL,
  3018. IN BOOLEAN CheckFlag
  3019. );
  3020. //
  3021. // Environment Variable API calls
  3022. //
  3023. NTSYSAPI
  3024. NTSTATUS
  3025. NTAPI
  3026. RtlCreateEnvironment(
  3027. BOOLEAN CloneCurrentEnvironment,
  3028. PVOID *Environment
  3029. );
  3030. NTSYSAPI
  3031. NTSTATUS
  3032. NTAPI
  3033. RtlDestroyEnvironment(
  3034. PVOID Environment
  3035. );
  3036. NTSYSAPI
  3037. NTSTATUS
  3038. NTAPI
  3039. RtlSetCurrentEnvironment(
  3040. PVOID Environment,
  3041. PVOID *PreviousEnvironment
  3042. );
  3043. NTSYSAPI
  3044. NTSTATUS
  3045. NTAPI
  3046. RtlSetEnvironmentVariable(
  3047. PVOID *Environment,
  3048. PCUNICODE_STRING Name,
  3049. PCUNICODE_STRING Value
  3050. );
  3051. NTSYSAPI
  3052. NTSTATUS
  3053. NTAPI
  3054. RtlQueryEnvironmentVariable_U (
  3055. PVOID Environment,
  3056. PCUNICODE_STRING Name,
  3057. PUNICODE_STRING Value
  3058. );
  3059. NTSYSAPI
  3060. NTSTATUS
  3061. NTAPI
  3062. RtlExpandEnvironmentStrings_U(
  3063. IN PVOID Environment OPTIONAL,
  3064. IN PCUNICODE_STRING Source,
  3065. OUT PUNICODE_STRING Destination,
  3066. OUT PULONG ReturnedLength OPTIONAL
  3067. );
  3068. // begin_ntifs
  3069. //
  3070. // Prefix package types and procedures.
  3071. //
  3072. // Note that the following two record structures should really be opaque
  3073. // to the user of this package. The only information about the two
  3074. // structures available for the user should be the size and alignment
  3075. // of the structures.
  3076. //
  3077. typedef struct _PREFIX_TABLE_ENTRY {
  3078. CSHORT NodeTypeCode;
  3079. CSHORT NameLength;
  3080. struct _PREFIX_TABLE_ENTRY *NextPrefixTree;
  3081. RTL_SPLAY_LINKS Links;
  3082. PSTRING Prefix;
  3083. } PREFIX_TABLE_ENTRY;
  3084. typedef PREFIX_TABLE_ENTRY *PPREFIX_TABLE_ENTRY;
  3085. typedef struct _PREFIX_TABLE {
  3086. CSHORT NodeTypeCode;
  3087. CSHORT NameLength;
  3088. PPREFIX_TABLE_ENTRY NextPrefixTree;
  3089. } PREFIX_TABLE;
  3090. typedef PREFIX_TABLE *PPREFIX_TABLE;
  3091. //
  3092. // The procedure prototypes for the prefix package
  3093. //
  3094. NTSYSAPI
  3095. VOID
  3096. NTAPI
  3097. PfxInitialize (
  3098. PPREFIX_TABLE PrefixTable
  3099. );
  3100. NTSYSAPI
  3101. BOOLEAN
  3102. NTAPI
  3103. PfxInsertPrefix (
  3104. PPREFIX_TABLE PrefixTable,
  3105. PSTRING Prefix,
  3106. PPREFIX_TABLE_ENTRY PrefixTableEntry
  3107. );
  3108. NTSYSAPI
  3109. VOID
  3110. NTAPI
  3111. PfxRemovePrefix (
  3112. PPREFIX_TABLE PrefixTable,
  3113. PPREFIX_TABLE_ENTRY PrefixTableEntry
  3114. );
  3115. NTSYSAPI
  3116. PPREFIX_TABLE_ENTRY
  3117. NTAPI
  3118. PfxFindPrefix (
  3119. PPREFIX_TABLE PrefixTable,
  3120. PSTRING FullName
  3121. );
  3122. //
  3123. // The following definitions are for the unicode version of the prefix
  3124. // package.
  3125. //
  3126. typedef struct _UNICODE_PREFIX_TABLE_ENTRY {
  3127. CSHORT NodeTypeCode;
  3128. CSHORT NameLength;
  3129. struct _UNICODE_PREFIX_TABLE_ENTRY *NextPrefixTree;
  3130. struct _UNICODE_PREFIX_TABLE_ENTRY *CaseMatch;
  3131. RTL_SPLAY_LINKS Links;
  3132. PUNICODE_STRING Prefix;
  3133. } UNICODE_PREFIX_TABLE_ENTRY;
  3134. typedef UNICODE_PREFIX_TABLE_ENTRY *PUNICODE_PREFIX_TABLE_ENTRY;
  3135. typedef struct _UNICODE_PREFIX_TABLE {
  3136. CSHORT NodeTypeCode;
  3137. CSHORT NameLength;
  3138. PUNICODE_PREFIX_TABLE_ENTRY NextPrefixTree;
  3139. PUNICODE_PREFIX_TABLE_ENTRY LastNextEntry;
  3140. } UNICODE_PREFIX_TABLE;
  3141. typedef UNICODE_PREFIX_TABLE *PUNICODE_PREFIX_TABLE;
  3142. NTSYSAPI
  3143. VOID
  3144. NTAPI
  3145. RtlInitializeUnicodePrefix (
  3146. PUNICODE_PREFIX_TABLE PrefixTable
  3147. );
  3148. NTSYSAPI
  3149. BOOLEAN
  3150. NTAPI
  3151. RtlInsertUnicodePrefix (
  3152. PUNICODE_PREFIX_TABLE PrefixTable,
  3153. PUNICODE_STRING Prefix,
  3154. PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
  3155. );
  3156. NTSYSAPI
  3157. VOID
  3158. NTAPI
  3159. RtlRemoveUnicodePrefix (
  3160. PUNICODE_PREFIX_TABLE PrefixTable,
  3161. PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry
  3162. );
  3163. NTSYSAPI
  3164. PUNICODE_PREFIX_TABLE_ENTRY
  3165. NTAPI
  3166. RtlFindUnicodePrefix (
  3167. PUNICODE_PREFIX_TABLE PrefixTable,
  3168. PUNICODE_STRING FullName,
  3169. ULONG CaseInsensitiveIndex
  3170. );
  3171. NTSYSAPI
  3172. PUNICODE_PREFIX_TABLE_ENTRY
  3173. NTAPI
  3174. RtlNextUnicodePrefix (
  3175. PUNICODE_PREFIX_TABLE PrefixTable,
  3176. BOOLEAN Restart
  3177. );
  3178. //
  3179. //
  3180. // Compression package types and procedures.
  3181. //
  3182. #define COMPRESSION_FORMAT_NONE (0x0000) // winnt
  3183. #define COMPRESSION_FORMAT_DEFAULT (0x0001) // winnt
  3184. #define COMPRESSION_FORMAT_LZNT1 (0x0002) // winnt
  3185. #define COMPRESSION_ENGINE_STANDARD (0x0000) // winnt
  3186. #define COMPRESSION_ENGINE_MAXIMUM (0x0100) // winnt
  3187. #define COMPRESSION_ENGINE_HIBER (0x0200) // winnt
  3188. //
  3189. // Compressed Data Information structure. This structure is
  3190. // used to describe the state of a compressed data buffer,
  3191. // whose uncompressed size is known. All compressed chunks
  3192. // described by this structure must be compressed with the
  3193. // same format. On compressed reads, this entire structure
  3194. // is an output, and on compressed writes the entire structure
  3195. // is an input.
  3196. //
  3197. typedef struct _COMPRESSED_DATA_INFO {
  3198. //
  3199. // Code for the compression format (and engine) as
  3200. // defined in ntrtl.h. Note that COMPRESSION_FORMAT_NONE
  3201. // and COMPRESSION_FORMAT_DEFAULT are invalid if
  3202. // any of the described chunks are compressed.
  3203. //
  3204. USHORT CompressionFormatAndEngine;
  3205. //
  3206. // Since chunks and compression units are expected to be
  3207. // powers of 2 in size, we express then log2. So, for
  3208. // example (1 << ChunkShift) == ChunkSizeInBytes. The
  3209. // ClusterShift indicates how much space must be saved
  3210. // to successfully compress a compression unit - each
  3211. // successfully compressed compression unit must occupy
  3212. // at least one cluster less in bytes than an uncompressed
  3213. // compression unit.
  3214. //
  3215. UCHAR CompressionUnitShift;
  3216. UCHAR ChunkShift;
  3217. UCHAR ClusterShift;
  3218. UCHAR Reserved;
  3219. //
  3220. // This is the number of entries in the CompressedChunkSizes
  3221. // array.
  3222. //
  3223. USHORT NumberOfChunks;
  3224. //
  3225. // This is an array of the sizes of all chunks resident
  3226. // in the compressed data buffer. There must be one entry
  3227. // in this array for each chunk possible in the uncompressed
  3228. // buffer size. A size of FSRTL_CHUNK_SIZE indicates the
  3229. // corresponding chunk is uncompressed and occupies exactly
  3230. // that size. A size of 0 indicates that the corresponding
  3231. // chunk contains nothing but binary 0's, and occupies no
  3232. // space in the compressed data. All other sizes must be
  3233. // less than FSRTL_CHUNK_SIZE, and indicate the exact size
  3234. // of the compressed data in bytes.
  3235. //
  3236. ULONG CompressedChunkSizes[ANYSIZE_ARRAY];
  3237. } COMPRESSED_DATA_INFO;
  3238. typedef COMPRESSED_DATA_INFO *PCOMPRESSED_DATA_INFO;
  3239. NTSYSAPI
  3240. NTSTATUS
  3241. NTAPI
  3242. RtlGetCompressionWorkSpaceSize (
  3243. IN USHORT CompressionFormatAndEngine,
  3244. OUT PULONG CompressBufferWorkSpaceSize,
  3245. OUT PULONG CompressFragmentWorkSpaceSize
  3246. );
  3247. NTSYSAPI
  3248. NTSTATUS
  3249. NTAPI
  3250. RtlCompressBuffer (
  3251. IN USHORT CompressionFormatAndEngine,
  3252. IN PUCHAR UncompressedBuffer,
  3253. IN ULONG UncompressedBufferSize,
  3254. OUT PUCHAR CompressedBuffer,
  3255. IN ULONG CompressedBufferSize,
  3256. IN ULONG UncompressedChunkSize,
  3257. OUT PULONG FinalCompressedSize,
  3258. IN PVOID WorkSpace
  3259. );
  3260. NTSYSAPI
  3261. NTSTATUS
  3262. NTAPI
  3263. RtlDecompressBuffer (
  3264. IN USHORT CompressionFormat,
  3265. OUT PUCHAR UncompressedBuffer,
  3266. IN ULONG UncompressedBufferSize,
  3267. IN PUCHAR CompressedBuffer,
  3268. IN ULONG CompressedBufferSize,
  3269. OUT PULONG FinalUncompressedSize
  3270. );
  3271. NTSYSAPI
  3272. NTSTATUS
  3273. NTAPI
  3274. RtlDecompressFragment (
  3275. IN USHORT CompressionFormat,
  3276. OUT PUCHAR UncompressedFragment,
  3277. IN ULONG UncompressedFragmentSize,
  3278. IN PUCHAR CompressedBuffer,
  3279. IN ULONG CompressedBufferSize,
  3280. IN ULONG FragmentOffset,
  3281. OUT PULONG FinalUncompressedSize,
  3282. IN PVOID WorkSpace
  3283. );
  3284. NTSYSAPI
  3285. NTSTATUS
  3286. NTAPI
  3287. RtlDescribeChunk (
  3288. IN USHORT CompressionFormat,
  3289. IN OUT PUCHAR *CompressedBuffer,
  3290. IN PUCHAR EndOfCompressedBufferPlus1,
  3291. OUT PUCHAR *ChunkBuffer,
  3292. OUT PULONG ChunkSize
  3293. );
  3294. NTSYSAPI
  3295. NTSTATUS
  3296. NTAPI
  3297. RtlReserveChunk (
  3298. IN USHORT CompressionFormat,
  3299. IN OUT PUCHAR *CompressedBuffer,
  3300. IN PUCHAR EndOfCompressedBufferPlus1,
  3301. OUT PUCHAR *ChunkBuffer,
  3302. IN ULONG ChunkSize
  3303. );
  3304. NTSYSAPI
  3305. NTSTATUS
  3306. NTAPI
  3307. RtlDecompressChunks (
  3308. OUT PUCHAR UncompressedBuffer,
  3309. IN ULONG UncompressedBufferSize,
  3310. IN PUCHAR CompressedBuffer,
  3311. IN ULONG CompressedBufferSize,
  3312. IN PUCHAR CompressedTail,
  3313. IN ULONG CompressedTailSize,
  3314. IN PCOMPRESSED_DATA_INFO CompressedDataInfo
  3315. );
  3316. NTSYSAPI
  3317. NTSTATUS
  3318. NTAPI
  3319. RtlCompressChunks (
  3320. IN PUCHAR UncompressedBuffer,
  3321. IN ULONG UncompressedBufferSize,
  3322. OUT PUCHAR CompressedBuffer,
  3323. IN ULONG CompressedBufferSize,
  3324. IN OUT PCOMPRESSED_DATA_INFO CompressedDataInfo,
  3325. IN ULONG CompressedDataInfoLength,
  3326. IN PVOID WorkSpace
  3327. );
  3328. // end_ntifs
  3329. //
  3330. // Image loading functions
  3331. //
  3332. #define DOS_MAX_COMPONENT_LENGTH 255
  3333. #define DOS_MAX_PATH_LENGTH (DOS_MAX_COMPONENT_LENGTH + 5 )
  3334. typedef struct _CURDIR {
  3335. UNICODE_STRING DosPath;
  3336. HANDLE Handle;
  3337. } CURDIR, *PCURDIR;
  3338. //
  3339. // Low order 2 bits of handle value used as flag bits.
  3340. //
  3341. #define RTL_USER_PROC_CURDIR_CLOSE 0x00000002
  3342. #define RTL_USER_PROC_CURDIR_INHERIT 0x00000003
  3343. typedef struct _RTL_DRIVE_LETTER_CURDIR {
  3344. USHORT Flags;
  3345. USHORT Length;
  3346. ULONG TimeStamp;
  3347. STRING DosPath;
  3348. } RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
  3349. #define RTL_MAX_DRIVE_LETTERS 32
  3350. #define RTL_DRIVE_LETTER_VALID (USHORT)0x0001
  3351. typedef struct _RTL_USER_PROCESS_PARAMETERS {
  3352. ULONG MaximumLength;
  3353. ULONG Length;
  3354. ULONG Flags;
  3355. ULONG DebugFlags;
  3356. HANDLE ConsoleHandle;
  3357. ULONG ConsoleFlags;
  3358. HANDLE StandardInput;
  3359. HANDLE StandardOutput;
  3360. HANDLE StandardError;
  3361. CURDIR CurrentDirectory; // ProcessParameters
  3362. UNICODE_STRING DllPath; // ProcessParameters
  3363. UNICODE_STRING ImagePathName; // ProcessParameters
  3364. UNICODE_STRING CommandLine; // ProcessParameters
  3365. PVOID Environment; // NtAllocateVirtualMemory
  3366. ULONG StartingX;
  3367. ULONG StartingY;
  3368. ULONG CountX;
  3369. ULONG CountY;
  3370. ULONG CountCharsX;
  3371. ULONG CountCharsY;
  3372. ULONG FillAttribute;
  3373. ULONG WindowFlags;
  3374. ULONG ShowWindowFlags;
  3375. UNICODE_STRING WindowTitle; // ProcessParameters
  3376. UNICODE_STRING DesktopInfo; // ProcessParameters
  3377. UNICODE_STRING ShellInfo; // ProcessParameters
  3378. UNICODE_STRING RuntimeData; // ProcessParameters
  3379. RTL_DRIVE_LETTER_CURDIR CurrentDirectores[ RTL_MAX_DRIVE_LETTERS ];
  3380. } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
  3381. //
  3382. // Possible bit values for Flags field.
  3383. //
  3384. #define RTL_USER_PROC_PARAMS_NORMALIZED 0x00000001
  3385. #define RTL_USER_PROC_PROFILE_USER 0x00000002
  3386. #define RTL_USER_PROC_PROFILE_KERNEL 0x00000004
  3387. #define RTL_USER_PROC_PROFILE_SERVER 0x00000008
  3388. #define RTL_USER_PROC_RESERVE_1MB 0x00000020
  3389. #define RTL_USER_PROC_RESERVE_16MB 0x00000040
  3390. #define RTL_USER_PROC_CASE_SENSITIVE 0x00000080
  3391. #define RTL_USER_PROC_DISABLE_HEAP_DECOMMIT 0x00000100
  3392. #define RTL_USER_PROC_DLL_REDIRECTION_LOCAL 0x00001000
  3393. #define RTL_USER_PROC_APP_MANIFEST_PRESENT 0x00002000
  3394. NTSYSAPI
  3395. NTSTATUS
  3396. NTAPI
  3397. RtlCreateProcessParameters(
  3398. PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
  3399. PUNICODE_STRING ImagePathName,
  3400. PUNICODE_STRING DllPath,
  3401. PUNICODE_STRING CurrentDirectory,
  3402. PUNICODE_STRING CommandLine,
  3403. PVOID Environment,
  3404. PUNICODE_STRING WindowTitle,
  3405. PUNICODE_STRING DesktopInfo,
  3406. PUNICODE_STRING ShellInfo,
  3407. PUNICODE_STRING RuntimeData
  3408. );
  3409. NTSYSAPI
  3410. NTSTATUS
  3411. NTAPI
  3412. RtlDestroyProcessParameters(
  3413. PRTL_USER_PROCESS_PARAMETERS ProcessParameters
  3414. );
  3415. NTSYSAPI
  3416. PRTL_USER_PROCESS_PARAMETERS
  3417. NTAPI
  3418. RtlNormalizeProcessParams(
  3419. PRTL_USER_PROCESS_PARAMETERS ProcessParameters
  3420. );
  3421. NTSYSAPI
  3422. PRTL_USER_PROCESS_PARAMETERS
  3423. NTAPI
  3424. RtlDeNormalizeProcessParams(
  3425. PRTL_USER_PROCESS_PARAMETERS ProcessParameters
  3426. );
  3427. typedef NTSTATUS (*PUSER_PROCESS_START_ROUTINE)(
  3428. PRTL_USER_PROCESS_PARAMETERS ProcessParameters
  3429. );
  3430. typedef NTSTATUS (*PUSER_THREAD_START_ROUTINE)(
  3431. PVOID ThreadParameter
  3432. );
  3433. typedef struct _RTL_USER_PROCESS_INFORMATION {
  3434. ULONG Length;
  3435. HANDLE Process;
  3436. HANDLE Thread;
  3437. CLIENT_ID ClientId;
  3438. SECTION_IMAGE_INFORMATION ImageInformation;
  3439. } RTL_USER_PROCESS_INFORMATION, *PRTL_USER_PROCESS_INFORMATION;
  3440. //
  3441. // This structure is used only by Wow64 processes. The offsets
  3442. // of structure elements should the same as viewed by a native Win64 application.
  3443. //
  3444. typedef struct _RTL_USER_PROCESS_INFORMATION64 {
  3445. ULONG Length;
  3446. LONGLONG Process;
  3447. LONGLONG Thread;
  3448. CLIENT_ID64 ClientId;
  3449. SECTION_IMAGE_INFORMATION64 ImageInformation;
  3450. } RTL_USER_PROCESS_INFORMATION64, *PRTL_USER_PROCESS_INFORMATION64;
  3451. NTSYSAPI
  3452. NTSTATUS
  3453. NTAPI
  3454. RtlCreateUserProcess(
  3455. PUNICODE_STRING NtImagePathName,
  3456. ULONG Attributes,
  3457. PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
  3458. PSECURITY_DESCRIPTOR ProcessSecurityDescriptor,
  3459. PSECURITY_DESCRIPTOR ThreadSecurityDescriptor,
  3460. HANDLE ParentProcess,
  3461. BOOLEAN InheritHandles,
  3462. HANDLE DebugPort,
  3463. HANDLE ExceptionPort,
  3464. PRTL_USER_PROCESS_INFORMATION ProcessInformation
  3465. );
  3466. NTSYSAPI
  3467. NTSTATUS
  3468. NTAPI
  3469. RtlCreateUserThread(
  3470. HANDLE Process,
  3471. PSECURITY_DESCRIPTOR ThreadSecurityDescriptor,
  3472. BOOLEAN CreateSuspended,
  3473. ULONG StackZeroBits,
  3474. SIZE_T MaximumStackSize OPTIONAL,
  3475. SIZE_T InitialStackSize OPTIONAL,
  3476. PUSER_THREAD_START_ROUTINE StartAddress,
  3477. PVOID Parameter,
  3478. PHANDLE Thread,
  3479. PCLIENT_ID ClientId
  3480. );
  3481. DECLSPEC_NORETURN
  3482. NTSYSAPI
  3483. VOID
  3484. NTAPI
  3485. RtlExitUserThread (
  3486. IN NTSTATUS ExitStatus
  3487. );
  3488. NTSYSAPI
  3489. VOID
  3490. NTAPI
  3491. RtlFreeUserThreadStack(
  3492. HANDLE hProcess,
  3493. HANDLE hThread
  3494. );
  3495. NTSYSAPI
  3496. PVOID
  3497. NTAPI
  3498. RtlPcToFileHeader(
  3499. PVOID PcValue,
  3500. PVOID *BaseOfImage
  3501. );
  3502. #define RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK (0x00000001)
  3503. NTSYSAPI
  3504. NTSTATUS
  3505. NTAPI
  3506. RtlImageNtHeaderEx(
  3507. ULONG Flags,
  3508. PVOID Base,
  3509. ULONG64 Size,
  3510. OUT PIMAGE_NT_HEADERS * OutHeaders
  3511. );
  3512. NTSYSAPI
  3513. PIMAGE_NT_HEADERS
  3514. NTAPI
  3515. RtlImageNtHeader(
  3516. PVOID Base
  3517. );
  3518. #define RTL_MEG (1024UL * 1024UL)
  3519. #define RTLP_IMAGE_MAX_DOS_HEADER ( 256UL * RTL_MEG)
  3520. #if !defined(MIDL_PASS)
  3521. __inline
  3522. PIMAGE_NT_HEADERS
  3523. NTAPI
  3524. RtlpImageNtHeader (
  3525. IN PVOID Base
  3526. )
  3527. /*++
  3528. Routine Description:
  3529. This function returns the address of the NT Header.
  3530. Arguments:
  3531. Base - Supplies the base of the image.
  3532. Return Value:
  3533. Returns the address of the NT Header.
  3534. --*/
  3535. {
  3536. PIMAGE_NT_HEADERS NtHeaders = NULL;
  3537. #ifndef _MAC
  3538. if (Base != NULL && Base != (PVOID)-1) {
  3539. __try {
  3540. if ((((PIMAGE_DOS_HEADER)Base)->e_magic == IMAGE_DOS_SIGNATURE) &&
  3541. ((ULONG)((PIMAGE_DOS_HEADER)Base)->e_lfanew < RTLP_IMAGE_MAX_DOS_HEADER)) {
  3542. NtHeaders = (PIMAGE_NT_HEADERS)((PCHAR)Base + ((PIMAGE_DOS_HEADER)Base)->e_lfanew);
  3543. if (NtHeaders->Signature != IMAGE_NT_SIGNATURE) {
  3544. NtHeaders = NULL;
  3545. }
  3546. }
  3547. }
  3548. __except(EXCEPTION_EXECUTE_HANDLER) {
  3549. NtHeaders = NULL;
  3550. }
  3551. }
  3552. #endif //_MAC
  3553. return NtHeaders;
  3554. }
  3555. #endif
  3556. NTSYSAPI
  3557. PVOID
  3558. NTAPI
  3559. RtlAddressInSectionTable (
  3560. IN PIMAGE_NT_HEADERS NtHeaders,
  3561. IN PVOID BaseOfImage,
  3562. IN ULONG VirtualAddress
  3563. );
  3564. NTSYSAPI
  3565. PIMAGE_SECTION_HEADER
  3566. NTAPI
  3567. RtlSectionTableFromVirtualAddress (
  3568. IN PIMAGE_NT_HEADERS NtHeaders,
  3569. IN PVOID BaseOfImage,
  3570. IN ULONG VirtualAddress
  3571. );
  3572. NTSYSAPI
  3573. PVOID
  3574. NTAPI
  3575. RtlImageDirectoryEntryToData(
  3576. PVOID BaseOfImage,
  3577. BOOLEAN MappedAsImage,
  3578. USHORT DirectoryEntry,
  3579. PULONG Size
  3580. );
  3581. #if defined(_WIN64)
  3582. NTSYSAPI
  3583. PVOID
  3584. RtlImageDirectoryEntryToData32 (
  3585. IN PVOID Base,
  3586. IN BOOLEAN MappedAsImage,
  3587. IN USHORT DirectoryEntry,
  3588. OUT PULONG Size
  3589. );
  3590. #else
  3591. #define RtlImageDirectoryEntryToData32 RtlImageDirectoryEntryToData
  3592. #endif
  3593. NTSYSAPI
  3594. PIMAGE_SECTION_HEADER
  3595. NTAPI
  3596. RtlImageRvaToSection(
  3597. IN PIMAGE_NT_HEADERS NtHeaders,
  3598. IN PVOID Base,
  3599. IN ULONG Rva
  3600. );
  3601. NTSYSAPI
  3602. PVOID
  3603. NTAPI
  3604. RtlImageRvaToVa(
  3605. IN PIMAGE_NT_HEADERS NtHeaders,
  3606. IN PVOID Base,
  3607. IN ULONG Rva,
  3608. IN OUT PIMAGE_SECTION_HEADER *LastRvaSection OPTIONAL
  3609. );
  3610. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  3611. //
  3612. // Fast primitives to compare, move, and zero memory
  3613. //
  3614. // begin_winnt begin_ntndis
  3615. NTSYSAPI
  3616. SIZE_T
  3617. NTAPI
  3618. RtlCompareMemory (
  3619. const VOID *Source1,
  3620. const VOID *Source2,
  3621. SIZE_T Length
  3622. );
  3623. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  3624. #if defined(_M_AMD64)
  3625. NTSYSAPI
  3626. VOID
  3627. NTAPI
  3628. RtlCopyMemory (
  3629. VOID UNALIGNED *Destination,
  3630. CONST VOID UNALIGNED *Source,
  3631. SIZE_T Length
  3632. );
  3633. NTSYSAPI
  3634. VOID
  3635. NTAPI
  3636. RtlMoveMemory (
  3637. VOID UNALIGNED *Destination,
  3638. CONST VOID UNALIGNED *Source,
  3639. SIZE_T Length
  3640. );
  3641. NTSYSAPI
  3642. VOID
  3643. NTAPI
  3644. RtlFillMemory (
  3645. VOID UNALIGNED *Destination,
  3646. SIZE_T Length,
  3647. IN UCHAR Fill
  3648. );
  3649. NTSYSAPI
  3650. VOID
  3651. NTAPI
  3652. RtlZeroMemory (
  3653. VOID UNALIGNED *Destination,
  3654. SIZE_T Length
  3655. );
  3656. #else
  3657. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  3658. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  3659. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  3660. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  3661. #endif
  3662. #if !defined(MIDL_PASS)
  3663. FORCEINLINE
  3664. PVOID
  3665. RtlSecureZeroMemory(
  3666. IN PVOID ptr,
  3667. IN SIZE_T cnt
  3668. )
  3669. {
  3670. volatile char *vptr = (volatile char *)ptr;
  3671. while (cnt) {
  3672. *vptr = 0;
  3673. vptr++;
  3674. cnt--;
  3675. }
  3676. return ptr;
  3677. }
  3678. #endif
  3679. // end_ntndis end_winnt
  3680. #define RtlCopyBytes RtlCopyMemory
  3681. #define RtlZeroBytes RtlZeroMemory
  3682. #define RtlFillBytes RtlFillMemory
  3683. #if defined(_M_AMD64)
  3684. NTSYSAPI
  3685. VOID
  3686. NTAPI
  3687. RtlCopyMemoryNonTemporal (
  3688. VOID UNALIGNED *Destination,
  3689. CONST VOID UNALIGNED *Source,
  3690. SIZE_T Length
  3691. );
  3692. #else
  3693. #define RtlCopyMemoryNonTemporal RtlCopyMemory
  3694. #endif
  3695. NTSYSAPI
  3696. VOID
  3697. FASTCALL
  3698. RtlPrefetchMemoryNonTemporal(
  3699. IN PVOID Source,
  3700. IN SIZE_T Length
  3701. );
  3702. // end_ntddk end_wdm end_nthal
  3703. NTSYSAPI
  3704. SIZE_T
  3705. NTAPI
  3706. RtlCompareMemoryUlong (
  3707. PVOID Source,
  3708. SIZE_T Length,
  3709. ULONG Pattern
  3710. );
  3711. #if defined(_M_AMD64)
  3712. #define RtlFillMemoryUlong(Destination, Length, Pattern) \
  3713. __stosd((PULONG)(Destination), Pattern, (Length) / 4)
  3714. #define RtlFillMemoryUlonglong(Destination, Length, Pattern) \
  3715. __stosq((PULONG64)(Destination), Pattern, (Length) / 8)
  3716. #else
  3717. NTSYSAPI
  3718. VOID
  3719. NTAPI
  3720. RtlFillMemoryUlong (
  3721. PVOID Destination,
  3722. SIZE_T Length,
  3723. ULONG Pattern
  3724. );
  3725. NTSYSAPI
  3726. VOID
  3727. NTAPI
  3728. RtlFillMemoryUlonglong (
  3729. PVOID Destination,
  3730. SIZE_T Length,
  3731. ULONGLONG Pattern
  3732. );
  3733. #endif
  3734. // end_ntifs
  3735. //
  3736. // Debugging support functions.
  3737. //
  3738. typedef struct _RTL_PROCESS_LOCK_INFORMATION {
  3739. PVOID Address;
  3740. USHORT Type;
  3741. USHORT CreatorBackTraceIndex;
  3742. HANDLE OwningThread; // from the thread's ClientId->UniqueThread
  3743. LONG LockCount;
  3744. ULONG ContentionCount;
  3745. ULONG EntryCount;
  3746. //
  3747. // The following fields are only valid for Type == RTL_CRITSECT_TYPE
  3748. //
  3749. LONG RecursionCount;
  3750. //
  3751. // The following fields are only valid for Type == RTL_RESOURCE_TYPE
  3752. //
  3753. ULONG NumberOfWaitingShared;
  3754. ULONG NumberOfWaitingExclusive;
  3755. } RTL_PROCESS_LOCK_INFORMATION, *PRTL_PROCESS_LOCK_INFORMATION;
  3756. typedef struct _RTL_PROCESS_LOCKS {
  3757. ULONG NumberOfLocks;
  3758. RTL_PROCESS_LOCK_INFORMATION Locks[ 1 ];
  3759. } RTL_PROCESS_LOCKS, *PRTL_PROCESS_LOCKS;
  3760. #if defined(_AMD64_) || defined(_IA64_)
  3761. #include "pshpck16.h" // CONTEXT is 16-byte aligned on win64
  3762. #endif
  3763. //
  3764. // Exception dispatcher's log of recent exceptions
  3765. //
  3766. #define MAX_EXCEPTION_LOG 10
  3767. #define MAX_EXCEPTION_LOG_DATA_SIZE 5
  3768. #pragma warning(push)
  3769. #pragma warning(disable:4324)
  3770. typedef struct _LAST_EXCEPTION_LOG {
  3771. EXCEPTION_RECORD ExceptionRecord;
  3772. CONTEXT ContextRecord;
  3773. ULONG ControlPc;
  3774. EXCEPTION_DISPOSITION Disposition;
  3775. // On x86 this contains a frame registration record; 4 dwords
  3776. // on RISC machines, it is a RUNTIME_FUNCTION record.
  3777. ULONG HandlerData[MAX_EXCEPTION_LOG_DATA_SIZE];
  3778. } LAST_EXCEPTION_LOG, *PLAST_EXCEPTION_LOG;
  3779. #pragma warning(pop)
  3780. #if defined(_AMD64_) || defined(_IA64_)
  3781. #include "poppack.h"
  3782. #endif
  3783. NTSYSAPI
  3784. VOID
  3785. NTAPI
  3786. RtlInitializeExceptionLog(
  3787. IN ULONG Entries
  3788. );
  3789. NTSYSAPI
  3790. LONG
  3791. NTAPI
  3792. RtlUnhandledExceptionFilter(
  3793. IN struct _EXCEPTION_POINTERS *ExceptionInfo
  3794. );
  3795. NTSYSAPI
  3796. LONG
  3797. NTAPI
  3798. RtlUnhandledExceptionFilter2(
  3799. IN struct _EXCEPTION_POINTERS *ExceptionInfo,
  3800. IN CONST CHAR* Function
  3801. );
  3802. VOID
  3803. NTAPI
  3804. DbgUserBreakPoint(
  3805. VOID
  3806. );
  3807. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis
  3808. //
  3809. // Define kernel debugger print prototypes and macros.
  3810. //
  3811. // N.B. The following function cannot be directly imported because there are
  3812. // a few places in the source tree where this function is redefined.
  3813. //
  3814. VOID
  3815. NTAPI
  3816. DbgBreakPoint(
  3817. VOID
  3818. );
  3819. // end_wdm
  3820. NTSYSAPI
  3821. VOID
  3822. NTAPI
  3823. DbgBreakPointWithStatus(
  3824. IN ULONG Status
  3825. );
  3826. // begin_wdm
  3827. #define DBG_STATUS_CONTROL_C 1
  3828. #define DBG_STATUS_SYSRQ 2
  3829. #define DBG_STATUS_BUGCHECK_FIRST 3
  3830. #define DBG_STATUS_BUGCHECK_SECOND 4
  3831. #define DBG_STATUS_FATAL 5
  3832. #define DBG_STATUS_DEBUG_CONTROL 6
  3833. #define DBG_STATUS_WORKER 7
  3834. #if DBG
  3835. #define KdPrint(_x_) DbgPrint _x_
  3836. // end_wdm
  3837. #define KdPrintEx(_x_) DbgPrintEx _x_
  3838. #define vKdPrintEx(_x_) vDbgPrintEx _x_
  3839. #define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
  3840. // begin_wdm
  3841. #define KdBreakPoint() DbgBreakPoint()
  3842. // end_wdm
  3843. #define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
  3844. // begin_wdm
  3845. #else
  3846. #define KdPrint(_x_)
  3847. // end_wdm
  3848. #define KdPrintEx(_x_)
  3849. #define vKdPrintEx(_x_)
  3850. #define vKdPrintExWithPrefix(_x_)
  3851. // begin_wdm
  3852. #define KdBreakPoint()
  3853. // end_wdm
  3854. #define KdBreakPointWithStatus(s)
  3855. // begin_wdm
  3856. #endif
  3857. #ifndef _DBGNT_
  3858. ULONG
  3859. __cdecl
  3860. DbgPrint(
  3861. PCH Format,
  3862. ...
  3863. );
  3864. // end_wdm
  3865. ULONG
  3866. __cdecl
  3867. DbgPrintEx(
  3868. IN ULONG ComponentId,
  3869. IN ULONG Level,
  3870. IN PCH Format,
  3871. ...
  3872. );
  3873. #ifdef _VA_LIST_DEFINED
  3874. ULONG
  3875. vDbgPrintEx(
  3876. IN ULONG ComponentId,
  3877. IN ULONG Level,
  3878. IN PCH Format,
  3879. va_list arglist
  3880. );
  3881. ULONG
  3882. vDbgPrintExWithPrefix(
  3883. IN PCH Prefix,
  3884. IN ULONG ComponentId,
  3885. IN ULONG Level,
  3886. IN PCH Format,
  3887. va_list arglist
  3888. );
  3889. #endif
  3890. ULONG
  3891. __cdecl
  3892. DbgPrintReturnControlC(
  3893. PCH Format,
  3894. ...
  3895. );
  3896. NTSYSAPI
  3897. NTSTATUS
  3898. DbgQueryDebugFilterState(
  3899. IN ULONG ComponentId,
  3900. IN ULONG Level
  3901. );
  3902. NTSYSAPI
  3903. NTSTATUS
  3904. DbgSetDebugFilterState(
  3905. IN ULONG ComponentId,
  3906. IN ULONG Level,
  3907. IN BOOLEAN State
  3908. );
  3909. // begin_wdm
  3910. #endif // _DBGNT_
  3911. // end_ntddk end_wdm end_nthal end_ntifs end_ntndis
  3912. NTSYSAPI
  3913. ULONG
  3914. NTAPI
  3915. DbgPrompt(
  3916. PCH Prompt,
  3917. PCH Response,
  3918. ULONG MaximumResponseLength
  3919. );
  3920. NTSYSAPI
  3921. VOID
  3922. NTAPI
  3923. DbgLoadImageSymbols(
  3924. PSTRING FileName,
  3925. PVOID ImageBase,
  3926. ULONG_PTR ProcessId
  3927. );
  3928. NTSYSAPI
  3929. VOID
  3930. NTAPI
  3931. DbgUnLoadImageSymbols(
  3932. PSTRING FileName,
  3933. PVOID ImageBase,
  3934. ULONG_PTR ProcessId
  3935. );
  3936. NTSYSAPI
  3937. VOID
  3938. NTAPI
  3939. DbgCommandString(
  3940. PCH Name,
  3941. PCH Command
  3942. );
  3943. // internal only
  3944. VOID
  3945. DebugService2(
  3946. PVOID Arg1,
  3947. PVOID Arg2,
  3948. ULONG Service
  3949. );
  3950. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  3951. //
  3952. // Large integer arithmetic routines.
  3953. //
  3954. //
  3955. // Large integer add - 64-bits + 64-bits -> 64-bits
  3956. //
  3957. #if !defined(MIDL_PASS)
  3958. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3959. __inline
  3960. LARGE_INTEGER
  3961. NTAPI
  3962. RtlLargeIntegerAdd (
  3963. LARGE_INTEGER Addend1,
  3964. LARGE_INTEGER Addend2
  3965. )
  3966. {
  3967. LARGE_INTEGER Sum;
  3968. Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
  3969. return Sum;
  3970. }
  3971. //
  3972. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  3973. //
  3974. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3975. __inline
  3976. LARGE_INTEGER
  3977. NTAPI
  3978. RtlEnlargedIntegerMultiply (
  3979. LONG Multiplicand,
  3980. LONG Multiplier
  3981. )
  3982. {
  3983. LARGE_INTEGER Product;
  3984. Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  3985. return Product;
  3986. }
  3987. //
  3988. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  3989. //
  3990. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  3991. __inline
  3992. LARGE_INTEGER
  3993. NTAPI
  3994. RtlEnlargedUnsignedMultiply (
  3995. ULONG Multiplicand,
  3996. ULONG Multiplier
  3997. )
  3998. {
  3999. LARGE_INTEGER Product;
  4000. Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
  4001. return Product;
  4002. }
  4003. //
  4004. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  4005. //
  4006. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4007. __inline
  4008. ULONG
  4009. NTAPI
  4010. RtlEnlargedUnsignedDivide (
  4011. IN ULARGE_INTEGER Dividend,
  4012. IN ULONG Divisor,
  4013. IN PULONG Remainder OPTIONAL
  4014. )
  4015. {
  4016. ULONG Quotient;
  4017. Quotient = (ULONG)(Dividend.QuadPart / Divisor);
  4018. if (ARGUMENT_PRESENT(Remainder)) {
  4019. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  4020. }
  4021. return Quotient;
  4022. }
  4023. //
  4024. // Large integer negation - -(64-bits)
  4025. //
  4026. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4027. __inline
  4028. LARGE_INTEGER
  4029. NTAPI
  4030. RtlLargeIntegerNegate (
  4031. LARGE_INTEGER Subtrahend
  4032. )
  4033. {
  4034. LARGE_INTEGER Difference;
  4035. Difference.QuadPart = -Subtrahend.QuadPart;
  4036. return Difference;
  4037. }
  4038. //
  4039. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  4040. //
  4041. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4042. __inline
  4043. LARGE_INTEGER
  4044. NTAPI
  4045. RtlLargeIntegerSubtract (
  4046. LARGE_INTEGER Minuend,
  4047. LARGE_INTEGER Subtrahend
  4048. )
  4049. {
  4050. LARGE_INTEGER Difference;
  4051. Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
  4052. return Difference;
  4053. }
  4054. //
  4055. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  4056. //
  4057. #if defined(_AMD64_)
  4058. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4059. __inline
  4060. LARGE_INTEGER
  4061. NTAPI
  4062. RtlExtendedMagicDivide (
  4063. LARGE_INTEGER Dividend,
  4064. LARGE_INTEGER MagicDivisor,
  4065. CCHAR ShiftCount
  4066. )
  4067. {
  4068. LARGE_INTEGER Quotient;
  4069. if (Dividend.QuadPart >= 0) {
  4070. Quotient.QuadPart = UnsignedMultiplyHigh(Dividend.QuadPart,
  4071. (ULONG64)MagicDivisor.QuadPart);
  4072. } else {
  4073. Quotient.QuadPart = UnsignedMultiplyHigh(-Dividend.QuadPart,
  4074. (ULONG64)MagicDivisor.QuadPart);
  4075. }
  4076. Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
  4077. if (Dividend.QuadPart < 0) {
  4078. Quotient.QuadPart = - Quotient.QuadPart;
  4079. }
  4080. return Quotient;
  4081. }
  4082. #endif // defined(_AMD64_)
  4083. #if defined(_X86_) || defined(_IA64_)
  4084. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4085. NTSYSAPI
  4086. LARGE_INTEGER
  4087. NTAPI
  4088. RtlExtendedMagicDivide (
  4089. LARGE_INTEGER Dividend,
  4090. LARGE_INTEGER MagicDivisor,
  4091. CCHAR ShiftCount
  4092. );
  4093. #endif // defined(_X86_) || defined(_IA64_)
  4094. #if defined(_AMD64_) || defined(_IA64_)
  4095. //
  4096. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  4097. //
  4098. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4099. __inline
  4100. LARGE_INTEGER
  4101. NTAPI
  4102. RtlExtendedLargeIntegerDivide (
  4103. LARGE_INTEGER Dividend,
  4104. ULONG Divisor,
  4105. PULONG Remainder OPTIONAL
  4106. )
  4107. {
  4108. LARGE_INTEGER Quotient;
  4109. Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
  4110. if (ARGUMENT_PRESENT(Remainder)) {
  4111. *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
  4112. }
  4113. return Quotient;
  4114. }
  4115. // end_wdm
  4116. //
  4117. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  4118. //
  4119. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4120. __inline
  4121. LARGE_INTEGER
  4122. NTAPI
  4123. RtlLargeIntegerDivide (
  4124. LARGE_INTEGER Dividend,
  4125. LARGE_INTEGER Divisor,
  4126. PLARGE_INTEGER Remainder OPTIONAL
  4127. )
  4128. {
  4129. LARGE_INTEGER Quotient;
  4130. Quotient.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
  4131. if (ARGUMENT_PRESENT(Remainder)) {
  4132. Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
  4133. }
  4134. return Quotient;
  4135. }
  4136. // begin_wdm
  4137. //
  4138. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  4139. //
  4140. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4141. __inline
  4142. LARGE_INTEGER
  4143. NTAPI
  4144. RtlExtendedIntegerMultiply (
  4145. LARGE_INTEGER Multiplicand,
  4146. LONG Multiplier
  4147. )
  4148. {
  4149. LARGE_INTEGER Product;
  4150. Product.QuadPart = Multiplicand.QuadPart * Multiplier;
  4151. return Product;
  4152. }
  4153. #else
  4154. //
  4155. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  4156. //
  4157. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4158. NTSYSAPI
  4159. LARGE_INTEGER
  4160. NTAPI
  4161. RtlExtendedLargeIntegerDivide (
  4162. LARGE_INTEGER Dividend,
  4163. ULONG Divisor,
  4164. PULONG Remainder
  4165. );
  4166. // end_wdm
  4167. //
  4168. // Large Integer divide - 64-bits / 64-bits -> 64-bits
  4169. //
  4170. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4171. NTSYSAPI
  4172. LARGE_INTEGER
  4173. NTAPI
  4174. RtlLargeIntegerDivide (
  4175. LARGE_INTEGER Dividend,
  4176. LARGE_INTEGER Divisor,
  4177. PLARGE_INTEGER Remainder
  4178. );
  4179. // begin_wdm
  4180. //
  4181. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  4182. //
  4183. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4184. NTSYSAPI
  4185. LARGE_INTEGER
  4186. NTAPI
  4187. RtlExtendedIntegerMultiply (
  4188. LARGE_INTEGER Multiplicand,
  4189. LONG Multiplier
  4190. );
  4191. #endif // defined(_AMD64_) || defined(_IA64_)
  4192. //
  4193. // Large integer and - 64-bite & 64-bits -> 64-bits.
  4194. //
  4195. #if PRAGMA_DEPRECATED_DDK
  4196. #pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
  4197. #endif
  4198. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  4199. Result.QuadPart = Source.QuadPart & Mask.QuadPart
  4200. //
  4201. // Convert signed integer to large integer.
  4202. //
  4203. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4204. __inline
  4205. LARGE_INTEGER
  4206. NTAPI
  4207. RtlConvertLongToLargeInteger (
  4208. LONG SignedInteger
  4209. )
  4210. {
  4211. LARGE_INTEGER Result;
  4212. Result.QuadPart = SignedInteger;
  4213. return Result;
  4214. }
  4215. //
  4216. // Convert unsigned integer to large integer.
  4217. //
  4218. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4219. __inline
  4220. LARGE_INTEGER
  4221. NTAPI
  4222. RtlConvertUlongToLargeInteger (
  4223. ULONG UnsignedInteger
  4224. )
  4225. {
  4226. LARGE_INTEGER Result;
  4227. Result.QuadPart = UnsignedInteger;
  4228. return Result;
  4229. }
  4230. //
  4231. // Large integer shift routines.
  4232. //
  4233. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4234. __inline
  4235. LARGE_INTEGER
  4236. NTAPI
  4237. RtlLargeIntegerShiftLeft (
  4238. LARGE_INTEGER LargeInteger,
  4239. CCHAR ShiftCount
  4240. )
  4241. {
  4242. LARGE_INTEGER Result;
  4243. Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
  4244. return Result;
  4245. }
  4246. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4247. __inline
  4248. LARGE_INTEGER
  4249. NTAPI
  4250. RtlLargeIntegerShiftRight (
  4251. LARGE_INTEGER LargeInteger,
  4252. CCHAR ShiftCount
  4253. )
  4254. {
  4255. LARGE_INTEGER Result;
  4256. Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
  4257. return Result;
  4258. }
  4259. DECLSPEC_DEPRECATED_DDK // Use native __int64 math
  4260. __inline
  4261. LARGE_INTEGER
  4262. NTAPI
  4263. RtlLargeIntegerArithmeticShift (
  4264. LARGE_INTEGER LargeInteger,
  4265. CCHAR ShiftCount
  4266. )
  4267. {
  4268. LARGE_INTEGER Result;
  4269. Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
  4270. return Result;
  4271. }
  4272. //
  4273. // Large integer comparison routines.
  4274. //
  4275. #if PRAGMA_DEPRECATED_DDK
  4276. #pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
  4277. #pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
  4278. #pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
  4279. #pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
  4280. #pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
  4281. #pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
  4282. #pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
  4283. #pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
  4284. #pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
  4285. #pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
  4286. #pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
  4287. #pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
  4288. #endif
  4289. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  4290. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  4291. ((X).HighPart > (Y).HighPart) \
  4292. )
  4293. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  4294. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  4295. ((X).HighPart > (Y).HighPart) \
  4296. )
  4297. #define RtlLargeIntegerEqualTo(X,Y) ( \
  4298. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  4299. )
  4300. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  4301. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  4302. )
  4303. #define RtlLargeIntegerLessThan(X,Y) ( \
  4304. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  4305. ((X).HighPart < (Y).HighPart) \
  4306. )
  4307. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  4308. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  4309. ((X).HighPart < (Y).HighPart) \
  4310. )
  4311. #define RtlLargeIntegerGreaterThanZero(X) ( \
  4312. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  4313. ((X).HighPart > 0 ) \
  4314. )
  4315. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  4316. (X).HighPart >= 0 \
  4317. )
  4318. #define RtlLargeIntegerEqualToZero(X) ( \
  4319. !((X).LowPart | (X).HighPart) \
  4320. )
  4321. #define RtlLargeIntegerNotEqualToZero(X) ( \
  4322. ((X).LowPart | (X).HighPart) \
  4323. )
  4324. #define RtlLargeIntegerLessThanZero(X) ( \
  4325. ((X).HighPart < 0) \
  4326. )
  4327. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  4328. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  4329. )
  4330. #endif // !defined(MIDL_PASS)
  4331. //
  4332. // Time conversion routines
  4333. //
  4334. typedef struct _TIME_FIELDS {
  4335. CSHORT Year; // range [1601...]
  4336. CSHORT Month; // range [1..12]
  4337. CSHORT Day; // range [1..31]
  4338. CSHORT Hour; // range [0..23]
  4339. CSHORT Minute; // range [0..59]
  4340. CSHORT Second; // range [0..59]
  4341. CSHORT Milliseconds;// range [0..999]
  4342. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  4343. } TIME_FIELDS;
  4344. typedef TIME_FIELDS *PTIME_FIELDS;
  4345. // end_ntddk end_wdm end_ntifs
  4346. NTSYSAPI
  4347. BOOLEAN
  4348. NTAPI
  4349. RtlCutoverTimeToSystemTime(
  4350. PTIME_FIELDS CutoverTime,
  4351. PLARGE_INTEGER SystemTime,
  4352. PLARGE_INTEGER CurrentSystemTime,
  4353. BOOLEAN ThisYear
  4354. );
  4355. NTSYSAPI
  4356. NTSTATUS
  4357. NTAPI
  4358. RtlSystemTimeToLocalTime (
  4359. IN PLARGE_INTEGER SystemTime,
  4360. OUT PLARGE_INTEGER LocalTime
  4361. );
  4362. NTSYSAPI
  4363. NTSTATUS
  4364. NTAPI
  4365. RtlLocalTimeToSystemTime (
  4366. IN PLARGE_INTEGER LocalTime,
  4367. OUT PLARGE_INTEGER SystemTime
  4368. );
  4369. //
  4370. // A 64 bit Time value -> time field record
  4371. //
  4372. NTSYSAPI
  4373. VOID
  4374. NTAPI
  4375. RtlTimeToElapsedTimeFields (
  4376. IN PLARGE_INTEGER Time,
  4377. OUT PTIME_FIELDS TimeFields
  4378. );
  4379. // begin_ntddk begin_wdm begin_ntifs
  4380. NTSYSAPI
  4381. VOID
  4382. NTAPI
  4383. RtlTimeToTimeFields (
  4384. PLARGE_INTEGER Time,
  4385. PTIME_FIELDS TimeFields
  4386. );
  4387. //
  4388. // A time field record (Weekday ignored) -> 64 bit Time value
  4389. //
  4390. NTSYSAPI
  4391. BOOLEAN
  4392. NTAPI
  4393. RtlTimeFieldsToTime (
  4394. PTIME_FIELDS TimeFields,
  4395. PLARGE_INTEGER Time
  4396. );
  4397. // end_ntddk end_wdm
  4398. //
  4399. // A 64 bit Time value -> Seconds since the start of 1980
  4400. //
  4401. NTSYSAPI
  4402. BOOLEAN
  4403. NTAPI
  4404. RtlTimeToSecondsSince1980 (
  4405. PLARGE_INTEGER Time,
  4406. PULONG ElapsedSeconds
  4407. );
  4408. //
  4409. // Seconds since the start of 1980 -> 64 bit Time value
  4410. //
  4411. NTSYSAPI
  4412. VOID
  4413. NTAPI
  4414. RtlSecondsSince1980ToTime (
  4415. ULONG ElapsedSeconds,
  4416. PLARGE_INTEGER Time
  4417. );
  4418. //
  4419. // A 64 bit Time value -> Seconds since the start of 1970
  4420. //
  4421. NTSYSAPI
  4422. BOOLEAN
  4423. NTAPI
  4424. RtlTimeToSecondsSince1970 (
  4425. PLARGE_INTEGER Time,
  4426. PULONG ElapsedSeconds
  4427. );
  4428. //
  4429. // Seconds since the start of 1970 -> 64 bit Time value
  4430. //
  4431. NTSYSAPI
  4432. VOID
  4433. NTAPI
  4434. RtlSecondsSince1970ToTime (
  4435. ULONG ElapsedSeconds,
  4436. PLARGE_INTEGER Time
  4437. );
  4438. // end_nthal end_ntifs
  4439. //
  4440. // Time Zone Information structure and procedures
  4441. //
  4442. typedef struct _RTL_TIME_ZONE_INFORMATION {
  4443. LONG Bias;
  4444. WCHAR StandardName[ 32 ];
  4445. TIME_FIELDS StandardStart;
  4446. LONG StandardBias;
  4447. WCHAR DaylightName[ 32 ];
  4448. TIME_FIELDS DaylightStart;
  4449. LONG DaylightBias;
  4450. } RTL_TIME_ZONE_INFORMATION, *PRTL_TIME_ZONE_INFORMATION;
  4451. NTSYSAPI
  4452. NTSTATUS
  4453. NTAPI
  4454. RtlQueryTimeZoneInformation(
  4455. OUT PRTL_TIME_ZONE_INFORMATION TimeZoneInformation
  4456. );
  4457. NTSYSAPI
  4458. NTSTATUS
  4459. NTAPI
  4460. RtlSetTimeZoneInformation(
  4461. IN PRTL_TIME_ZONE_INFORMATION TimeZoneInformation
  4462. );
  4463. NTSYSAPI
  4464. NTSTATUS
  4465. NTAPI
  4466. RtlSetActiveTimeBias(
  4467. IN LONG ActiveBias
  4468. );
  4469. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  4470. //
  4471. // The following macros store and retrieve USHORTS and ULONGS from potentially
  4472. // unaligned addresses, avoiding alignment faults. they should probably be
  4473. // rewritten in assembler
  4474. //
  4475. #define SHORT_SIZE (sizeof(USHORT))
  4476. #define SHORT_MASK (SHORT_SIZE - 1)
  4477. #define LONG_SIZE (sizeof(LONG))
  4478. #define LONGLONG_SIZE (sizeof(LONGLONG))
  4479. #define LONG_MASK (LONG_SIZE - 1)
  4480. #define LONGLONG_MASK (LONGLONG_SIZE - 1)
  4481. #define LOWBYTE_MASK 0x00FF
  4482. #define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
  4483. #define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
  4484. #define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
  4485. #define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
  4486. //
  4487. // if MIPS Big Endian, order of bytes is reversed.
  4488. //
  4489. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  4490. #define SHORT_MOST_SIGNIFICANT_BIT 1
  4491. #define LONG_LEAST_SIGNIFICANT_BIT 0
  4492. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  4493. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  4494. #define LONG_MOST_SIGNIFICANT_BIT 3
  4495. //++
  4496. //
  4497. // VOID
  4498. // RtlStoreUshort (
  4499. // PUSHORT ADDRESS
  4500. // USHORT VALUE
  4501. // )
  4502. //
  4503. // Routine Description:
  4504. //
  4505. // This macro stores a USHORT value in at a particular address, avoiding
  4506. // alignment faults.
  4507. //
  4508. // Arguments:
  4509. //
  4510. // ADDRESS - where to store USHORT value
  4511. // VALUE - USHORT to store
  4512. //
  4513. // Return Value:
  4514. //
  4515. // none.
  4516. //
  4517. //--
  4518. #define RtlStoreUshort(ADDRESS,VALUE) \
  4519. if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
  4520. ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  4521. ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  4522. } \
  4523. else { \
  4524. *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
  4525. }
  4526. //++
  4527. //
  4528. // VOID
  4529. // RtlStoreUlong (
  4530. // PULONG ADDRESS
  4531. // ULONG VALUE
  4532. // )
  4533. //
  4534. // Routine Description:
  4535. //
  4536. // This macro stores a ULONG value in at a particular address, avoiding
  4537. // alignment faults.
  4538. //
  4539. // Arguments:
  4540. //
  4541. // ADDRESS - where to store ULONG value
  4542. // VALUE - ULONG to store
  4543. //
  4544. // Return Value:
  4545. //
  4546. // none.
  4547. //
  4548. // Note:
  4549. // Depending on the machine, we might want to call storeushort in the
  4550. // unaligned case.
  4551. //
  4552. //--
  4553. #define RtlStoreUlong(ADDRESS,VALUE) \
  4554. if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
  4555. ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  4556. ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  4557. ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  4558. ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  4559. } \
  4560. else { \
  4561. *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
  4562. }
  4563. //++
  4564. //
  4565. // VOID
  4566. // RtlStoreUlonglong (
  4567. // PULONGLONG ADDRESS
  4568. // ULONG VALUE
  4569. // )
  4570. //
  4571. // Routine Description:
  4572. //
  4573. // This macro stores a ULONGLONG value in at a particular address, avoiding
  4574. // alignment faults.
  4575. //
  4576. // Arguments:
  4577. //
  4578. // ADDRESS - where to store ULONGLONG value
  4579. // VALUE - ULONGLONG to store
  4580. //
  4581. // Return Value:
  4582. //
  4583. // none.
  4584. //
  4585. //--
  4586. #define RtlStoreUlonglong(ADDRESS,VALUE) \
  4587. if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
  4588. RtlStoreUlong((ULONG_PTR)(ADDRESS), \
  4589. (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
  4590. RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
  4591. (ULONGLONG)(VALUE) >> 32); \
  4592. } else { \
  4593. *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
  4594. }
  4595. //++
  4596. //
  4597. // VOID
  4598. // RtlStoreUlongPtr (
  4599. // PULONG_PTR ADDRESS
  4600. // ULONG_PTR VALUE
  4601. // )
  4602. //
  4603. // Routine Description:
  4604. //
  4605. // This macro stores a ULONG_PTR value in at a particular address, avoiding
  4606. // alignment faults.
  4607. //
  4608. // Arguments:
  4609. //
  4610. // ADDRESS - where to store ULONG_PTR value
  4611. // VALUE - ULONG_PTR to store
  4612. //
  4613. // Return Value:
  4614. //
  4615. // none.
  4616. //
  4617. //--
  4618. #ifdef _WIN64
  4619. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  4620. RtlStoreUlonglong(ADDRESS,VALUE)
  4621. #else
  4622. #define RtlStoreUlongPtr(ADDRESS,VALUE) \
  4623. RtlStoreUlong(ADDRESS,VALUE)
  4624. #endif
  4625. //++
  4626. //
  4627. // VOID
  4628. // RtlRetrieveUshort (
  4629. // PUSHORT DESTINATION_ADDRESS
  4630. // PUSHORT SOURCE_ADDRESS
  4631. // )
  4632. //
  4633. // Routine Description:
  4634. //
  4635. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  4636. // alignment faults. The DESTINATION address is assumed to be aligned.
  4637. //
  4638. // Arguments:
  4639. //
  4640. // DESTINATION_ADDRESS - where to store USHORT value
  4641. // SOURCE_ADDRESS - where to retrieve USHORT value from
  4642. //
  4643. // Return Value:
  4644. //
  4645. // none.
  4646. //
  4647. //--
  4648. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  4649. if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
  4650. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  4651. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  4652. } \
  4653. else { \
  4654. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  4655. } \
  4656. //++
  4657. //
  4658. // VOID
  4659. // RtlRetrieveUlong (
  4660. // PULONG DESTINATION_ADDRESS
  4661. // PULONG SOURCE_ADDRESS
  4662. // )
  4663. //
  4664. // Routine Description:
  4665. //
  4666. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  4667. // alignment faults. The DESTINATION address is assumed to be aligned.
  4668. //
  4669. // Arguments:
  4670. //
  4671. // DESTINATION_ADDRESS - where to store ULONG value
  4672. // SOURCE_ADDRESS - where to retrieve ULONG value from
  4673. //
  4674. // Return Value:
  4675. //
  4676. // none.
  4677. //
  4678. // Note:
  4679. // Depending on the machine, we might want to call retrieveushort in the
  4680. // unaligned case.
  4681. //
  4682. //--
  4683. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  4684. if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
  4685. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  4686. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  4687. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  4688. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  4689. } \
  4690. else { \
  4691. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  4692. }
  4693. // end_ntddk end_wdm
  4694. //++
  4695. //
  4696. // PCHAR
  4697. // RtlOffsetToPointer (
  4698. // PVOID Base,
  4699. // ULONG Offset
  4700. // )
  4701. //
  4702. // Routine Description:
  4703. //
  4704. // This macro generates a pointer which points to the byte that is 'Offset'
  4705. // bytes beyond 'Base'. This is useful for referencing fields within
  4706. // self-relative data structures.
  4707. //
  4708. // Arguments:
  4709. //
  4710. // Base - The address of the base of the structure.
  4711. //
  4712. // Offset - An unsigned integer offset of the byte whose address is to
  4713. // be generated.
  4714. //
  4715. // Return Value:
  4716. //
  4717. // A PCHAR pointer to the byte that is 'Offset' bytes beyond 'Base'.
  4718. //
  4719. //
  4720. //--
  4721. #define RtlOffsetToPointer(B,O) ((PCHAR)( ((PCHAR)(B)) + ((ULONG_PTR)(O)) ))
  4722. //++
  4723. //
  4724. // ULONG
  4725. // RtlPointerToOffset (
  4726. // PVOID Base,
  4727. // PVOID Pointer
  4728. // )
  4729. //
  4730. // Routine Description:
  4731. //
  4732. // This macro calculates the offset from Base to Pointer. This is useful
  4733. // for producing self-relative offsets for structures.
  4734. //
  4735. // Arguments:
  4736. //
  4737. // Base - The address of the base of the structure.
  4738. //
  4739. // Pointer - A pointer to a field, presumably within the structure
  4740. // pointed to by Base. This value must be larger than that specified
  4741. // for Base.
  4742. //
  4743. // Return Value:
  4744. //
  4745. // A ULONG offset from Base to Pointer.
  4746. //
  4747. //
  4748. //--
  4749. #define RtlPointerToOffset(B,P) ((ULONG)( ((PCHAR)(P)) - ((PCHAR)(B)) ))
  4750. // end_ntifs
  4751. // begin_ntifs begin_ntddk begin_wdm
  4752. //
  4753. // BitMap routines. The following structure, routines, and macros are
  4754. // for manipulating bitmaps. The user is responsible for allocating a bitmap
  4755. // structure (which is really a header) and a buffer (which must be longword
  4756. // aligned and multiple longwords in size).
  4757. //
  4758. typedef struct _RTL_BITMAP {
  4759. ULONG SizeOfBitMap; // Number of bits in bit map
  4760. PULONG Buffer; // Pointer to the bit map itself
  4761. } RTL_BITMAP;
  4762. typedef RTL_BITMAP *PRTL_BITMAP;
  4763. //
  4764. // The following routine initializes a new bitmap. It does not alter the
  4765. // data currently in the bitmap. This routine must be called before
  4766. // any other bitmap routine/macro.
  4767. //
  4768. NTSYSAPI
  4769. VOID
  4770. NTAPI
  4771. RtlInitializeBitMap (
  4772. PRTL_BITMAP BitMapHeader,
  4773. PULONG BitMapBuffer,
  4774. ULONG SizeOfBitMap
  4775. );
  4776. //
  4777. // The following three routines clear, set, and test the state of a
  4778. // single bit in a bitmap.
  4779. //
  4780. NTSYSAPI
  4781. VOID
  4782. NTAPI
  4783. RtlClearBit (
  4784. PRTL_BITMAP BitMapHeader,
  4785. ULONG BitNumber
  4786. );
  4787. NTSYSAPI
  4788. VOID
  4789. NTAPI
  4790. RtlSetBit (
  4791. PRTL_BITMAP BitMapHeader,
  4792. ULONG BitNumber
  4793. );
  4794. NTSYSAPI
  4795. BOOLEAN
  4796. NTAPI
  4797. RtlTestBit (
  4798. PRTL_BITMAP BitMapHeader,
  4799. ULONG BitNumber
  4800. );
  4801. //
  4802. // The following two routines either clear or set all of the bits
  4803. // in a bitmap.
  4804. //
  4805. NTSYSAPI
  4806. VOID
  4807. NTAPI
  4808. RtlClearAllBits (
  4809. PRTL_BITMAP BitMapHeader
  4810. );
  4811. NTSYSAPI
  4812. VOID
  4813. NTAPI
  4814. RtlSetAllBits (
  4815. PRTL_BITMAP BitMapHeader
  4816. );
  4817. //
  4818. // The following two routines locate a contiguous region of either
  4819. // clear or set bits within the bitmap. The region will be at least
  4820. // as large as the number specified, and the search of the bitmap will
  4821. // begin at the specified hint index (which is a bit index within the
  4822. // bitmap, zero based). The return value is the bit index of the located
  4823. // region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
  4824. // be located
  4825. //
  4826. NTSYSAPI
  4827. ULONG
  4828. NTAPI
  4829. RtlFindClearBits (
  4830. PRTL_BITMAP BitMapHeader,
  4831. ULONG NumberToFind,
  4832. ULONG HintIndex
  4833. );
  4834. NTSYSAPI
  4835. ULONG
  4836. NTAPI
  4837. RtlFindSetBits (
  4838. PRTL_BITMAP BitMapHeader,
  4839. ULONG NumberToFind,
  4840. ULONG HintIndex
  4841. );
  4842. //
  4843. // The following two routines locate a contiguous region of either
  4844. // clear or set bits within the bitmap and either set or clear the bits
  4845. // within the located region. The region will be as large as the number
  4846. // specified, and the search for the region will begin at the specified
  4847. // hint index (which is a bit index within the bitmap, zero based). The
  4848. // return value is the bit index of the located region (zero based) or
  4849. // -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
  4850. // cannot be located then the setting/clearing of the bitmap is not performed.
  4851. //
  4852. NTSYSAPI
  4853. ULONG
  4854. NTAPI
  4855. RtlFindClearBitsAndSet (
  4856. PRTL_BITMAP BitMapHeader,
  4857. ULONG NumberToFind,
  4858. ULONG HintIndex
  4859. );
  4860. NTSYSAPI
  4861. ULONG
  4862. NTAPI
  4863. RtlFindSetBitsAndClear (
  4864. PRTL_BITMAP BitMapHeader,
  4865. ULONG NumberToFind,
  4866. ULONG HintIndex
  4867. );
  4868. //
  4869. // The following two routines clear or set bits within a specified region
  4870. // of the bitmap. The starting index is zero based.
  4871. //
  4872. NTSYSAPI
  4873. VOID
  4874. NTAPI
  4875. RtlClearBits (
  4876. PRTL_BITMAP BitMapHeader,
  4877. ULONG StartingIndex,
  4878. ULONG NumberToClear
  4879. );
  4880. NTSYSAPI
  4881. VOID
  4882. NTAPI
  4883. RtlSetBits (
  4884. PRTL_BITMAP BitMapHeader,
  4885. ULONG StartingIndex,
  4886. ULONG NumberToSet
  4887. );
  4888. //
  4889. // The following routine locates a set of contiguous regions of clear
  4890. // bits within the bitmap. The caller specifies whether to return the
  4891. // longest runs or just the first found lcoated. The following structure is
  4892. // used to denote a contiguous run of bits. The two routines return an array
  4893. // of this structure, one for each run located.
  4894. //
  4895. typedef struct _RTL_BITMAP_RUN {
  4896. ULONG StartingIndex;
  4897. ULONG NumberOfBits;
  4898. } RTL_BITMAP_RUN;
  4899. typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
  4900. NTSYSAPI
  4901. ULONG
  4902. NTAPI
  4903. RtlFindClearRuns (
  4904. PRTL_BITMAP BitMapHeader,
  4905. PRTL_BITMAP_RUN RunArray,
  4906. ULONG SizeOfRunArray,
  4907. BOOLEAN LocateLongestRuns
  4908. );
  4909. //
  4910. // The following routine locates the longest contiguous region of
  4911. // clear bits within the bitmap. The returned starting index value
  4912. // denotes the first contiguous region located satisfying our requirements
  4913. // The return value is the length (in bits) of the longest region found.
  4914. //
  4915. NTSYSAPI
  4916. ULONG
  4917. NTAPI
  4918. RtlFindLongestRunClear (
  4919. PRTL_BITMAP BitMapHeader,
  4920. PULONG StartingIndex
  4921. );
  4922. //
  4923. // The following routine locates the first contiguous region of
  4924. // clear bits within the bitmap. The returned starting index value
  4925. // denotes the first contiguous region located satisfying our requirements
  4926. // The return value is the length (in bits) of the region found.
  4927. //
  4928. NTSYSAPI
  4929. ULONG
  4930. NTAPI
  4931. RtlFindFirstRunClear (
  4932. PRTL_BITMAP BitMapHeader,
  4933. PULONG StartingIndex
  4934. );
  4935. //
  4936. // The following macro returns the value of the bit stored within the
  4937. // bitmap at the specified location. If the bit is set a value of 1 is
  4938. // returned otherwise a value of 0 is returned.
  4939. //
  4940. // ULONG
  4941. // RtlCheckBit (
  4942. // PRTL_BITMAP BitMapHeader,
  4943. // ULONG BitPosition
  4944. // );
  4945. //
  4946. //
  4947. // To implement CheckBit the macro retrieves the longword containing the
  4948. // bit in question, shifts the longword to get the bit in question into the
  4949. // low order bit position and masks out all other bits.
  4950. //
  4951. #define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
  4952. //
  4953. // The following two procedures return to the caller the total number of
  4954. // clear or set bits within the specified bitmap.
  4955. //
  4956. NTSYSAPI
  4957. ULONG
  4958. NTAPI
  4959. RtlNumberOfClearBits (
  4960. PRTL_BITMAP BitMapHeader
  4961. );
  4962. NTSYSAPI
  4963. ULONG
  4964. NTAPI
  4965. RtlNumberOfSetBits (
  4966. PRTL_BITMAP BitMapHeader
  4967. );
  4968. //
  4969. // The following two procedures return to the caller a boolean value
  4970. // indicating if the specified range of bits are all clear or set.
  4971. //
  4972. NTSYSAPI
  4973. BOOLEAN
  4974. NTAPI
  4975. RtlAreBitsClear (
  4976. PRTL_BITMAP BitMapHeader,
  4977. ULONG StartingIndex,
  4978. ULONG Length
  4979. );
  4980. NTSYSAPI
  4981. BOOLEAN
  4982. NTAPI
  4983. RtlAreBitsSet (
  4984. PRTL_BITMAP BitMapHeader,
  4985. ULONG StartingIndex,
  4986. ULONG Length
  4987. );
  4988. NTSYSAPI
  4989. ULONG
  4990. NTAPI
  4991. RtlFindNextForwardRunClear (
  4992. IN PRTL_BITMAP BitMapHeader,
  4993. IN ULONG FromIndex,
  4994. IN PULONG StartingRunIndex
  4995. );
  4996. NTSYSAPI
  4997. ULONG
  4998. NTAPI
  4999. RtlFindLastBackwardRunClear (
  5000. IN PRTL_BITMAP BitMapHeader,
  5001. IN ULONG FromIndex,
  5002. IN PULONG StartingRunIndex
  5003. );
  5004. //
  5005. // The following two procedures return to the caller a value indicating
  5006. // the position within a ULONGLONG of the most or least significant non-zero
  5007. // bit. A value of zero results in a return value of -1.
  5008. //
  5009. NTSYSAPI
  5010. CCHAR
  5011. NTAPI
  5012. RtlFindLeastSignificantBit (
  5013. IN ULONGLONG Set
  5014. );
  5015. NTSYSAPI
  5016. CCHAR
  5017. NTAPI
  5018. RtlFindMostSignificantBit (
  5019. IN ULONGLONG Set
  5020. );
  5021. // end_nthal end_ntifs end_ntddk end_wdm
  5022. // begin_ntifs
  5023. //
  5024. // Security ID RTL routine definitions
  5025. //
  5026. NTSYSAPI
  5027. BOOLEAN
  5028. NTAPI
  5029. RtlValidSid (
  5030. PSID Sid
  5031. );
  5032. NTSYSAPI
  5033. BOOLEAN
  5034. NTAPI
  5035. RtlEqualSid (
  5036. PSID Sid1,
  5037. PSID Sid2
  5038. );
  5039. NTSYSAPI
  5040. BOOLEAN
  5041. NTAPI
  5042. RtlEqualPrefixSid (
  5043. PSID Sid1,
  5044. PSID Sid2
  5045. );
  5046. NTSYSAPI
  5047. ULONG
  5048. NTAPI
  5049. RtlLengthRequiredSid (
  5050. ULONG SubAuthorityCount
  5051. );
  5052. NTSYSAPI
  5053. PVOID
  5054. NTAPI
  5055. RtlFreeSid(
  5056. IN PSID Sid
  5057. );
  5058. NTSYSAPI
  5059. NTSTATUS
  5060. NTAPI
  5061. RtlAllocateAndInitializeSid(
  5062. IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
  5063. IN UCHAR SubAuthorityCount,
  5064. IN ULONG SubAuthority0,
  5065. IN ULONG SubAuthority1,
  5066. IN ULONG SubAuthority2,
  5067. IN ULONG SubAuthority3,
  5068. IN ULONG SubAuthority4,
  5069. IN ULONG SubAuthority5,
  5070. IN ULONG SubAuthority6,
  5071. IN ULONG SubAuthority7,
  5072. OUT PSID *Sid
  5073. );
  5074. NTSYSAPI // ntifs
  5075. NTSTATUS // ntifs
  5076. NTAPI // ntifs
  5077. RtlInitializeSid ( // ntifs
  5078. PSID Sid, // ntifs
  5079. PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, // ntifs
  5080. UCHAR SubAuthorityCount // ntifs
  5081. ); // ntifs
  5082. NTSYSAPI
  5083. PSID_IDENTIFIER_AUTHORITY
  5084. NTAPI
  5085. RtlIdentifierAuthoritySid (
  5086. PSID Sid
  5087. );
  5088. NTSYSAPI // ntifs
  5089. PULONG // ntifs
  5090. NTAPI // ntifs
  5091. RtlSubAuthoritySid ( // ntifs
  5092. PSID Sid, // ntifs
  5093. ULONG SubAuthority // ntifs
  5094. ); // ntifs
  5095. NTSYSAPI
  5096. PUCHAR
  5097. NTAPI
  5098. RtlSubAuthorityCountSid (
  5099. PSID Sid
  5100. );
  5101. // begin_ntifs
  5102. NTSYSAPI
  5103. ULONG
  5104. NTAPI
  5105. RtlLengthSid (
  5106. PSID Sid
  5107. );
  5108. NTSYSAPI
  5109. NTSTATUS
  5110. NTAPI
  5111. RtlCopySid (
  5112. ULONG DestinationSidLength,
  5113. PSID DestinationSid,
  5114. PSID SourceSid
  5115. );
  5116. // end_ntifs
  5117. NTSYSAPI
  5118. NTSTATUS
  5119. NTAPI
  5120. RtlCopySidAndAttributesArray (
  5121. ULONG ArrayLength,
  5122. PSID_AND_ATTRIBUTES Source,
  5123. ULONG TargetSidBufferSize,
  5124. PSID_AND_ATTRIBUTES TargetArrayElement,
  5125. PSID TargetSid,
  5126. PSID *NextTargetSid,
  5127. PULONG RemainingTargetSidSize
  5128. );
  5129. NTSYSAPI
  5130. NTSTATUS
  5131. NTAPI
  5132. RtlLengthSidAsUnicodeString(
  5133. PSID Sid,
  5134. PULONG StringLength
  5135. );
  5136. NTSYSAPI
  5137. NTSTATUS
  5138. NTAPI
  5139. RtlConvertSidToUnicodeString(
  5140. PUNICODE_STRING UnicodeString,
  5141. PSID Sid,
  5142. BOOLEAN AllocateDestinationString
  5143. );
  5144. //
  5145. // LUID RTL routine definitions
  5146. //
  5147. // begin_ntddk begin_ntifs
  5148. //
  5149. // BOOLEAN
  5150. // RtlEqualLuid(
  5151. // PLUID L1,
  5152. // PLUID L2
  5153. // );
  5154. #define RtlEqualLuid(L1, L2) (((L1)->LowPart == (L2)->LowPart) && \
  5155. ((L1)->HighPart == (L2)->HighPart))
  5156. //
  5157. // BOOLEAN
  5158. // RtlIsZeroLuid(
  5159. // PLUID L1
  5160. // );
  5161. //
  5162. #define RtlIsZeroLuid(L1) ((BOOLEAN) (((L1)->LowPart | (L1)->HighPart) == 0))
  5163. #if !defined(MIDL_PASS)
  5164. FORCEINLINE LUID
  5165. NTAPI
  5166. RtlConvertLongToLuid(
  5167. LONG Long
  5168. )
  5169. {
  5170. LUID TempLuid;
  5171. LARGE_INTEGER TempLi;
  5172. TempLi.QuadPart = Long;
  5173. TempLuid.LowPart = TempLi.LowPart;
  5174. TempLuid.HighPart = TempLi.HighPart;
  5175. return(TempLuid);
  5176. }
  5177. FORCEINLINE
  5178. LUID
  5179. NTAPI
  5180. RtlConvertUlongToLuid(
  5181. ULONG Ulong
  5182. )
  5183. {
  5184. LUID TempLuid;
  5185. TempLuid.LowPart = Ulong;
  5186. TempLuid.HighPart = 0;
  5187. return(TempLuid);
  5188. }
  5189. #endif
  5190. // end_ntddk
  5191. NTSYSAPI
  5192. VOID
  5193. NTAPI
  5194. RtlCopyLuid (
  5195. PLUID DestinationLuid,
  5196. PLUID SourceLuid
  5197. );
  5198. // end_ntifs
  5199. NTSYSAPI
  5200. VOID
  5201. NTAPI
  5202. RtlCopyLuidAndAttributesArray (
  5203. ULONG ArrayLength,
  5204. PLUID_AND_ATTRIBUTES Source,
  5205. PLUID_AND_ATTRIBUTES Target
  5206. );
  5207. //
  5208. // ACCESS_MASK RTL routine definitions
  5209. //
  5210. NTSYSAPI
  5211. BOOLEAN
  5212. NTAPI
  5213. RtlAreAllAccessesGranted(
  5214. ACCESS_MASK GrantedAccess,
  5215. ACCESS_MASK DesiredAccess
  5216. );
  5217. NTSYSAPI
  5218. BOOLEAN
  5219. NTAPI
  5220. RtlAreAnyAccessesGranted(
  5221. ACCESS_MASK GrantedAccess,
  5222. ACCESS_MASK DesiredAccess
  5223. );
  5224. // begin_ntddk begin_ntifs
  5225. NTSYSAPI
  5226. VOID
  5227. NTAPI
  5228. RtlMapGenericMask(
  5229. PACCESS_MASK AccessMask,
  5230. PGENERIC_MAPPING GenericMapping
  5231. );
  5232. // end_ntddk end_ntifs
  5233. //
  5234. // ACL RTL routine definitions
  5235. //
  5236. NTSYSAPI
  5237. BOOLEAN
  5238. NTAPI
  5239. RtlValidAcl (
  5240. PACL Acl
  5241. );
  5242. NTSYSAPI // ntifs
  5243. NTSTATUS // ntifs
  5244. NTAPI // ntifs
  5245. RtlCreateAcl ( // ntifs
  5246. PACL Acl, // ntifs
  5247. ULONG AclLength, // ntifs
  5248. ULONG AclRevision // ntifs
  5249. ); // ntifs
  5250. NTSYSAPI
  5251. NTSTATUS
  5252. NTAPI
  5253. RtlQueryInformationAcl (
  5254. PACL Acl,
  5255. PVOID AclInformation,
  5256. ULONG AclInformationLength,
  5257. ACL_INFORMATION_CLASS AclInformationClass
  5258. );
  5259. NTSYSAPI
  5260. NTSTATUS
  5261. NTAPI
  5262. RtlSetInformationAcl (
  5263. PACL Acl,
  5264. PVOID AclInformation,
  5265. ULONG AclInformationLength,
  5266. ACL_INFORMATION_CLASS AclInformationClass
  5267. );
  5268. NTSYSAPI
  5269. NTSTATUS
  5270. NTAPI
  5271. RtlAddAce (
  5272. PACL Acl,
  5273. ULONG AceRevision,
  5274. ULONG StartingAceIndex,
  5275. PVOID AceList,
  5276. ULONG AceListLength
  5277. );
  5278. NTSYSAPI
  5279. NTSTATUS
  5280. NTAPI
  5281. RtlDeleteAce (
  5282. PACL Acl,
  5283. ULONG AceIndex
  5284. );
  5285. // begin_ntifs
  5286. NTSYSAPI
  5287. NTSTATUS
  5288. NTAPI
  5289. RtlGetAce (
  5290. PACL Acl,
  5291. ULONG AceIndex,
  5292. PVOID *Ace
  5293. );
  5294. NTSYSAPI
  5295. NTSTATUS
  5296. NTAPI
  5297. RtlAddAccessAllowedAce (
  5298. PACL Acl,
  5299. ULONG AceRevision,
  5300. ACCESS_MASK AccessMask,
  5301. PSID Sid
  5302. );
  5303. // end_ntifs
  5304. NTSYSAPI
  5305. NTSTATUS
  5306. NTAPI
  5307. RtlAddAccessAllowedAceEx (
  5308. PACL Acl,
  5309. ULONG AceRevision,
  5310. ULONG AceFlags,
  5311. ACCESS_MASK AccessMask,
  5312. PSID Sid
  5313. );
  5314. NTSYSAPI
  5315. NTSTATUS
  5316. NTAPI
  5317. RtlAddAccessDeniedAce (
  5318. PACL Acl,
  5319. ULONG AceRevision,
  5320. ACCESS_MASK AccessMask,
  5321. PSID Sid
  5322. );
  5323. NTSYSAPI
  5324. NTSTATUS
  5325. NTAPI
  5326. RtlAddAccessDeniedAceEx (
  5327. PACL Acl,
  5328. ULONG AceRevision,
  5329. ULONG AceFlags,
  5330. ACCESS_MASK AccessMask,
  5331. PSID Sid
  5332. );
  5333. NTSYSAPI
  5334. NTSTATUS
  5335. NTAPI
  5336. RtlAddAuditAccessAce (
  5337. PACL Acl,
  5338. ULONG AceRevision,
  5339. ACCESS_MASK AccessMask,
  5340. PSID Sid,
  5341. BOOLEAN AuditSuccess,
  5342. BOOLEAN AuditFailure
  5343. );
  5344. NTSYSAPI
  5345. NTSTATUS
  5346. NTAPI
  5347. RtlAddAuditAccessAceEx (
  5348. PACL Acl,
  5349. ULONG AceRevision,
  5350. ULONG AceFlags,
  5351. ACCESS_MASK AccessMask,
  5352. PSID Sid,
  5353. BOOLEAN AuditSuccess,
  5354. BOOLEAN AuditFailure
  5355. );
  5356. NTSYSAPI
  5357. NTSTATUS
  5358. NTAPI
  5359. RtlAddAccessAllowedObjectAce (
  5360. IN OUT PACL Acl,
  5361. IN ULONG AceRevision,
  5362. IN ULONG AceFlags,
  5363. IN ACCESS_MASK AccessMask,
  5364. IN GUID *ObjectTypeGuid OPTIONAL,
  5365. IN GUID *InheritedObjectTypeGuid OPTIONAL,
  5366. IN PSID Sid
  5367. );
  5368. NTSYSAPI
  5369. NTSTATUS
  5370. NTAPI
  5371. RtlAddAccessDeniedObjectAce (
  5372. IN OUT PACL Acl,
  5373. IN ULONG AceRevision,
  5374. IN ULONG AceFlags,
  5375. IN ACCESS_MASK AccessMask,
  5376. IN GUID *ObjectTypeGuid OPTIONAL,
  5377. IN GUID *InheritedObjectTypeGuid OPTIONAL,
  5378. IN PSID Sid
  5379. );
  5380. NTSYSAPI
  5381. NTSTATUS
  5382. NTAPI
  5383. RtlAddAuditAccessObjectAce (
  5384. IN OUT PACL Acl,
  5385. IN ULONG AceRevision,
  5386. IN ULONG AceFlags,
  5387. IN ACCESS_MASK AccessMask,
  5388. IN GUID *ObjectTypeGuid OPTIONAL,
  5389. IN GUID *InheritedObjectTypeGuid OPTIONAL,
  5390. IN PSID Sid,
  5391. BOOLEAN AuditSuccess,
  5392. BOOLEAN AuditFailure
  5393. );
  5394. NTSYSAPI
  5395. BOOLEAN
  5396. NTAPI
  5397. RtlFirstFreeAce (
  5398. PACL Acl,
  5399. PVOID *FirstFree
  5400. );
  5401. NTSYSAPI
  5402. NTSTATUS
  5403. NTAPI
  5404. RtlAddCompoundAce (
  5405. IN PACL Acl,
  5406. IN ULONG AceRevision,
  5407. IN UCHAR AceType,
  5408. IN ACCESS_MASK AccessMask,
  5409. IN PSID ServerSid,
  5410. IN PSID ClientSid
  5411. );
  5412. // begin_wdm begin_ntddk begin_ntifs
  5413. //
  5414. // SecurityDescriptor RTL routine definitions
  5415. //
  5416. NTSYSAPI
  5417. NTSTATUS
  5418. NTAPI
  5419. RtlCreateSecurityDescriptor (
  5420. PSECURITY_DESCRIPTOR SecurityDescriptor,
  5421. ULONG Revision
  5422. );
  5423. // end_wdm end_ntddk
  5424. NTSYSAPI
  5425. NTSTATUS
  5426. NTAPI
  5427. RtlCreateSecurityDescriptorRelative (
  5428. PISECURITY_DESCRIPTOR_RELATIVE SecurityDescriptor,
  5429. ULONG Revision
  5430. );
  5431. // begin_wdm begin_ntddk
  5432. NTSYSAPI
  5433. BOOLEAN
  5434. NTAPI
  5435. RtlValidSecurityDescriptor (
  5436. PSECURITY_DESCRIPTOR SecurityDescriptor
  5437. );
  5438. NTSYSAPI
  5439. ULONG
  5440. NTAPI
  5441. RtlLengthSecurityDescriptor (
  5442. PSECURITY_DESCRIPTOR SecurityDescriptor
  5443. );
  5444. NTSYSAPI
  5445. BOOLEAN
  5446. NTAPI
  5447. RtlValidRelativeSecurityDescriptor (
  5448. IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
  5449. IN ULONG SecurityDescriptorLength,
  5450. IN SECURITY_INFORMATION RequiredInformation
  5451. );
  5452. // end_wdm end_ntddk end_ntifs
  5453. NTSYSAPI
  5454. NTSTATUS
  5455. NTAPI
  5456. RtlGetControlSecurityDescriptor (
  5457. PSECURITY_DESCRIPTOR SecurityDescriptor,
  5458. PSECURITY_DESCRIPTOR_CONTROL Control,
  5459. PULONG Revision
  5460. );
  5461. NTSYSAPI
  5462. NTSTATUS
  5463. NTAPI
  5464. RtlSetControlSecurityDescriptor (
  5465. IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
  5466. IN SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
  5467. IN SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
  5468. );
  5469. NTSYSAPI
  5470. NTSTATUS
  5471. NTAPI
  5472. RtlSetAttributesSecurityDescriptor(
  5473. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  5474. IN SECURITY_DESCRIPTOR_CONTROL Control,
  5475. IN OUT PULONG Revision
  5476. );
  5477. // begin_wdm begin_ntddk begin_ntifs
  5478. NTSYSAPI
  5479. NTSTATUS
  5480. NTAPI
  5481. RtlSetDaclSecurityDescriptor (
  5482. PSECURITY_DESCRIPTOR SecurityDescriptor,
  5483. BOOLEAN DaclPresent,
  5484. PACL Dacl,
  5485. BOOLEAN DaclDefaulted
  5486. );
  5487. // end_wdm end_ntddk
  5488. NTSYSAPI
  5489. NTSTATUS
  5490. NTAPI
  5491. RtlGetDaclSecurityDescriptor (
  5492. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  5493. OUT PBOOLEAN DaclPresent,
  5494. OUT PACL *Dacl,
  5495. OUT PBOOLEAN DaclDefaulted
  5496. );
  5497. // end_ntifs
  5498. NTSYSAPI
  5499. BOOLEAN
  5500. NTAPI
  5501. RtlGetSecurityDescriptorRMControl(
  5502. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  5503. OUT PUCHAR RMControl
  5504. );
  5505. NTSYSAPI
  5506. VOID
  5507. NTAPI
  5508. RtlSetSecurityDescriptorRMControl(
  5509. IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
  5510. IN PUCHAR RMControl OPTIONAL
  5511. );
  5512. NTSYSAPI
  5513. NTSTATUS
  5514. NTAPI
  5515. RtlSetSaclSecurityDescriptor (
  5516. PSECURITY_DESCRIPTOR SecurityDescriptor,
  5517. BOOLEAN SaclPresent,
  5518. PACL Sacl,
  5519. BOOLEAN SaclDefaulted
  5520. );
  5521. NTSYSAPI
  5522. NTSTATUS
  5523. NTAPI
  5524. RtlGetSaclSecurityDescriptor (
  5525. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  5526. OUT PBOOLEAN SaclPresent,
  5527. OUT PACL *Sacl,
  5528. OUT PBOOLEAN SaclDefaulted
  5529. );
  5530. NTSYSAPI // ntifs
  5531. NTSTATUS // ntifs
  5532. NTAPI // ntifs
  5533. RtlSetOwnerSecurityDescriptor ( // ntifs
  5534. PSECURITY_DESCRIPTOR SecurityDescriptor, // ntifs
  5535. PSID Owner, // ntifs
  5536. BOOLEAN OwnerDefaulted // ntifs
  5537. ); // ntifs
  5538. NTSYSAPI // ntifs
  5539. NTSTATUS // ntifs
  5540. NTAPI // ntifs
  5541. RtlGetOwnerSecurityDescriptor ( // ntifs
  5542. IN PSECURITY_DESCRIPTOR SecurityDescriptor, // ntifs
  5543. OUT PSID *Owner, // ntifs
  5544. OUT PBOOLEAN OwnerDefaulted // ntifs
  5545. ); // ntifs
  5546. NTSYSAPI
  5547. NTSTATUS
  5548. NTAPI
  5549. RtlSetGroupSecurityDescriptor (
  5550. PSECURITY_DESCRIPTOR SecurityDescriptor,
  5551. PSID Group,
  5552. BOOLEAN GroupDefaulted
  5553. );
  5554. NTSYSAPI
  5555. NTSTATUS
  5556. NTAPI
  5557. RtlGetGroupSecurityDescriptor (
  5558. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  5559. OUT PSID *Group,
  5560. OUT PBOOLEAN GroupDefaulted
  5561. );
  5562. NTSYSAPI
  5563. NTSTATUS
  5564. NTAPI
  5565. RtlMakeSelfRelativeSD(
  5566. IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
  5567. OUT PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
  5568. OUT PULONG BufferLength
  5569. );
  5570. NTSYSAPI
  5571. NTSTATUS
  5572. NTAPI
  5573. RtlAbsoluteToSelfRelativeSD(
  5574. PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
  5575. PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
  5576. PULONG BufferLength
  5577. );
  5578. NTSYSAPI
  5579. NTSTATUS
  5580. NTAPI
  5581. RtlSelfRelativeToAbsoluteSD(
  5582. PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
  5583. PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
  5584. PULONG AbsoluteSecurityDescriptorSize,
  5585. PACL Dacl,
  5586. PULONG DaclSize,
  5587. PACL Sacl,
  5588. PULONG SaclSize,
  5589. PSID Owner,
  5590. PULONG OwnerSize,
  5591. PSID PrimaryGroup,
  5592. PULONG PrimaryGroupSize
  5593. );
  5594. NTSYSAPI
  5595. NTSTATUS
  5596. NTAPI
  5597. RtlSelfRelativeToAbsoluteSD2(
  5598. PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
  5599. PULONG pBufferSize
  5600. );
  5601. NTSYSAPI
  5602. NTSTATUS
  5603. NTAPI
  5604. RtlNewSecurityGrantedAccess(
  5605. ACCESS_MASK DesiredAccess,
  5606. PPRIVILEGE_SET Privileges,
  5607. PULONG Length,
  5608. HANDLE Token,
  5609. PGENERIC_MAPPING GenericMapping,
  5610. PACCESS_MASK RemainingDesiredAccess
  5611. );
  5612. NTSYSAPI
  5613. NTSTATUS
  5614. NTAPI
  5615. RtlMapSecurityErrorToNtStatus(
  5616. SECURITY_STATUS Error
  5617. );
  5618. NTSYSAPI
  5619. NTSTATUS
  5620. NTAPI
  5621. RtlImpersonateSelf(
  5622. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  5623. );
  5624. NTSYSAPI
  5625. NTSTATUS
  5626. NTAPI
  5627. RtlAdjustPrivilege(
  5628. ULONG Privilege,
  5629. BOOLEAN Enable,
  5630. BOOLEAN Client,
  5631. PBOOLEAN WasEnabled
  5632. );
  5633. NTSYSAPI
  5634. VOID
  5635. NTAPI
  5636. RtlRunEncodeUnicodeString(
  5637. PUCHAR Seed OPTIONAL,
  5638. PUNICODE_STRING String
  5639. );
  5640. NTSYSAPI
  5641. VOID
  5642. NTAPI
  5643. RtlRunDecodeUnicodeString(
  5644. UCHAR Seed,
  5645. PUNICODE_STRING String
  5646. );
  5647. NTSYSAPI
  5648. VOID
  5649. NTAPI
  5650. RtlEraseUnicodeString(
  5651. PUNICODE_STRING String
  5652. );
  5653. //
  5654. // Macro to make a known ACE type ready for applying to a specific object type.
  5655. // This is done by mapping any generic access types, and clearing
  5656. // the special access types field.
  5657. //
  5658. // This routine should only be used on DSA define ACEs.
  5659. //
  5660. // Parameters:
  5661. //
  5662. // Ace - Points to an ACE to be applied. Only ACEs that are not
  5663. // InheritOnly are mapped.
  5664. //
  5665. // Mapping - Points to a generic mapping array for the type of
  5666. // object the ACE is being applied to.
  5667. //
  5668. //
  5669. // Clear invalid bits. Note that ACCESS_SYSTEM_SECURITY is
  5670. // valid in SACLs, but not in DACLs. So, leave it in audit and
  5671. // alarm ACEs, but clear it in access allowed and denied ACEs.
  5672. //
  5673. #define RtlApplyAceToObject(Ace,Mapping) \
  5674. if (!FlagOn((Ace)->AceFlags, INHERIT_ONLY_ACE) ) { \
  5675. RtlApplyGenericMask( Ace, &((PKNOWN_ACE)(Ace))->Mask, Mapping ); \
  5676. }
  5677. // Same as above, but don't modify the mask in the ACE itself.
  5678. #define RtlApplyGenericMask(Ace, Mask, Mapping) { \
  5679. RtlMapGenericMask( (Mask), (Mapping)); \
  5680. \
  5681. if ( (((PKNOWN_ACE)(Ace))->Header.AceType == ACCESS_ALLOWED_ACE_TYPE) || \
  5682. (((PKNOWN_ACE)(Ace))->Header.AceType == ACCESS_DENIED_ACE_TYPE) || \
  5683. (((PKNOWN_ACE)(Ace))->Header.AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE) || \
  5684. (((PKNOWN_ACE)(Ace))->Header.AceType == ACCESS_ALLOWED_OBJECT_ACE_TYPE) || \
  5685. (((PKNOWN_ACE)(Ace))->Header.AceType == ACCESS_DENIED_OBJECT_ACE_TYPE) ) { \
  5686. *(Mask) &= (Mapping)->GenericAll; \
  5687. } else { \
  5688. *(Mask) &= ((Mapping)->GenericAll | \
  5689. ACCESS_SYSTEM_SECURITY); \
  5690. } \
  5691. }
  5692. //
  5693. // Service to get the primary domain name/sid of the local machine
  5694. // Callable only from user mode.
  5695. //
  5696. //NTSYSAPI
  5697. NTSTATUS
  5698. NTAPI
  5699. RtlGetPrimaryDomain(
  5700. IN ULONG SidLength,
  5701. OUT PBOOLEAN PrimaryDomainPresent,
  5702. OUT PUNICODE_STRING PrimaryDomainName,
  5703. OUT PUSHORT RequiredNameLength,
  5704. OUT PSID PrimaryDomainSid OPTIONAL,
  5705. OUT PULONG RequiredSidLength
  5706. );
  5707. //!!!!!!!!!!!!!!! Temporary user mode Registry system services !!!!!!//
  5708. // //
  5709. // These services will be eliminted when BryanWi implements the real //
  5710. // registry object. //
  5711. //
  5712. NTSTATUS //
  5713. RtlpNtOpenKey( //
  5714. PHANDLE KeyHandle, //
  5715. ACCESS_MASK DesiredAccess, //
  5716. POBJECT_ATTRIBUTES ObjectAttributes, //
  5717. ULONG Options //
  5718. ); //
  5719. //
  5720. NTSTATUS //
  5721. RtlpNtCreateKey( //
  5722. PHANDLE KeyHandle, //
  5723. ACCESS_MASK DesiredAccess, //
  5724. POBJECT_ATTRIBUTES ObjectAttributes, //
  5725. ULONG Options, //
  5726. PUNICODE_STRING Provider, //
  5727. PULONG Disposition //
  5728. ); //
  5729. //
  5730. NTSTATUS //
  5731. RtlpNtEnumerateSubKey( //
  5732. HANDLE KeyHandle, //
  5733. PUNICODE_STRING SubKeyName, //
  5734. ULONG Index, //
  5735. PLARGE_INTEGER LastWriteTime //
  5736. ); //
  5737. //
  5738. NTSTATUS //
  5739. RtlpNtQueryValueKey( //
  5740. HANDLE KeyHandle, //
  5741. PULONG KeyValueType, //
  5742. PVOID KeyValue, //
  5743. PULONG KeyValueLength, //
  5744. PLARGE_INTEGER LastWriteTime //
  5745. ); //
  5746. //
  5747. NTSTATUS //
  5748. RtlpNtSetValueKey( //
  5749. HANDLE KeyHandle, //
  5750. ULONG KeyValueType, //
  5751. PVOID KeyValue, //
  5752. ULONG KeyValueLength //
  5753. ); //
  5754. //
  5755. NTSTATUS //
  5756. RtlpNtMakeTemporaryKey( //
  5757. HANDLE KeyHandle //
  5758. ); //
  5759. //
  5760. /////////////////////////////////////////////////////////////////////////
  5761. //
  5762. // Extract the SIDs from a compound ACE.
  5763. //
  5764. #define RtlCompoundAceServerSid( Ace ) ((PSID)&((PKNOWN_COMPOUND_ACE)(Ace))->SidStart)
  5765. #define RtlCompoundAceClientSid( Ace ) ((PSID)(((ULONG_PTR)(&((PKNOWN_COMPOUND_ACE)(Ace))->SidStart))+RtlLengthSid( RtlCompoundAceServerSid((Ace)))))
  5766. // begin_winnt
  5767. typedef struct _MESSAGE_RESOURCE_ENTRY {
  5768. USHORT Length;
  5769. USHORT Flags;
  5770. UCHAR Text[ 1 ];
  5771. } MESSAGE_RESOURCE_ENTRY, *PMESSAGE_RESOURCE_ENTRY;
  5772. #define MESSAGE_RESOURCE_UNICODE 0x0001
  5773. typedef struct _MESSAGE_RESOURCE_BLOCK {
  5774. ULONG LowId;
  5775. ULONG HighId;
  5776. ULONG OffsetToEntries;
  5777. } MESSAGE_RESOURCE_BLOCK, *PMESSAGE_RESOURCE_BLOCK;
  5778. typedef struct _MESSAGE_RESOURCE_DATA {
  5779. ULONG NumberOfBlocks;
  5780. MESSAGE_RESOURCE_BLOCK Blocks[ 1 ];
  5781. } MESSAGE_RESOURCE_DATA, *PMESSAGE_RESOURCE_DATA;
  5782. // end_winnt
  5783. NTSYSAPI
  5784. NTSTATUS
  5785. NTAPI
  5786. RtlFindMessage(
  5787. PVOID DllHandle,
  5788. ULONG MessageTableId,
  5789. ULONG MessageLanguageId,
  5790. ULONG MessageId,
  5791. PMESSAGE_RESOURCE_ENTRY *MessageEntry
  5792. );
  5793. NTSYSAPI
  5794. NTSTATUS
  5795. NTAPI
  5796. RtlFormatMessage(
  5797. IN PWSTR MessageFormat,
  5798. IN ULONG MaximumWidth OPTIONAL,
  5799. IN BOOLEAN IgnoreInserts,
  5800. IN BOOLEAN ArgumentsAreAnsi,
  5801. IN BOOLEAN ArgumentsAreAnArray,
  5802. IN va_list *Arguments,
  5803. OUT PWSTR Buffer,
  5804. IN ULONG Length,
  5805. OUT PULONG ReturnLength OPTIONAL
  5806. );
  5807. //
  5808. // Services providing a simple transaction capability for operations on
  5809. // the registration database.
  5810. //
  5811. typedef enum _RTL_RXACT_OPERATION {
  5812. RtlRXactOperationDelete = 1, // Causes sub-key to be deleted
  5813. RtlRXactOperationSetValue, // Sets sub-key value (creates key(s) if necessary)
  5814. RtlRXactOperationDelAttribute,
  5815. RtlRXactOperationSetAttribute
  5816. } RTL_RXACT_OPERATION, *PRTL_RXACT_OPERATION;
  5817. typedef struct _RTL_RXACT_LOG {
  5818. ULONG OperationCount;
  5819. ULONG LogSize; // Includes sizeof( LOG_HEADER )
  5820. ULONG LogSizeInUse;
  5821. #if defined(_WIN64)
  5822. ULONG Alignment;
  5823. #endif
  5824. // UCHAR LogData[ ANYSIZE_ARRAY ]
  5825. } RTL_RXACT_LOG, *PRTL_RXACT_LOG;
  5826. #ifdef _MAC
  5827. #pragma warning( disable : 4121)
  5828. #endif
  5829. typedef struct _RTL_RXACT_CONTEXT {
  5830. HANDLE RootRegistryKey;
  5831. HANDLE RXactKey;
  5832. BOOLEAN HandlesValid; // Handles found in Log entries are legit
  5833. PRTL_RXACT_LOG RXactLog;
  5834. } RTL_RXACT_CONTEXT, *PRTL_RXACT_CONTEXT;
  5835. #ifdef _MAC
  5836. #pragma warning( default : 4121 )
  5837. #endif
  5838. NTSYSAPI
  5839. NTSTATUS
  5840. NTAPI
  5841. RtlInitializeRXact(
  5842. IN HANDLE RootRegistryKey,
  5843. IN BOOLEAN CommitIfNecessary,
  5844. OUT PRTL_RXACT_CONTEXT *RXactContext
  5845. );
  5846. NTSYSAPI
  5847. NTSTATUS
  5848. NTAPI
  5849. RtlStartRXact(
  5850. IN PRTL_RXACT_CONTEXT RXactContext
  5851. );
  5852. NTSYSAPI
  5853. NTSTATUS
  5854. NTAPI
  5855. RtlAbortRXact(
  5856. IN PRTL_RXACT_CONTEXT RXactContext
  5857. );
  5858. NTSYSAPI
  5859. NTSTATUS
  5860. NTAPI
  5861. RtlAddAttributeActionToRXact(
  5862. IN PRTL_RXACT_CONTEXT RXactContext,
  5863. IN RTL_RXACT_OPERATION Operation,
  5864. IN PUNICODE_STRING SubKeyName,
  5865. IN HANDLE KeyHandle,
  5866. IN PUNICODE_STRING AttributeName,
  5867. IN ULONG NewValueType,
  5868. IN PVOID NewValue,
  5869. IN ULONG NewValueLength
  5870. );
  5871. NTSYSAPI
  5872. NTSTATUS
  5873. NTAPI
  5874. RtlAddActionToRXact(
  5875. IN PRTL_RXACT_CONTEXT RXactContext,
  5876. IN RTL_RXACT_OPERATION Operation,
  5877. IN PUNICODE_STRING SubKeyName,
  5878. IN ULONG NewKeyValueType,
  5879. IN PVOID NewKeyValue OPTIONAL,
  5880. IN ULONG NewKeyValueLength
  5881. );
  5882. NTSYSAPI
  5883. NTSTATUS
  5884. NTAPI
  5885. RtlApplyRXact(
  5886. IN PRTL_RXACT_CONTEXT RXactContext
  5887. );
  5888. NTSYSAPI
  5889. NTSTATUS
  5890. NTAPI
  5891. RtlApplyRXactNoFlush(
  5892. IN PRTL_RXACT_CONTEXT RXactContext
  5893. );
  5894. //
  5895. // Routine for converting NT status codes to DOS/OS|2 equivalents.
  5896. //
  5897. // begin_ntifs
  5898. NTSYSAPI
  5899. ULONG
  5900. NTAPI
  5901. RtlNtStatusToDosError (
  5902. NTSTATUS Status
  5903. );
  5904. NTSYSAPI
  5905. ULONG
  5906. NTAPI
  5907. RtlNtStatusToDosErrorNoTeb (
  5908. NTSTATUS Status
  5909. );
  5910. NTSYSAPI
  5911. NTSTATUS
  5912. NTAPI
  5913. RtlCustomCPToUnicodeN(
  5914. IN PCPTABLEINFO CustomCP,
  5915. OUT PWCH UnicodeString,
  5916. IN ULONG MaxBytesInUnicodeString,
  5917. OUT PULONG BytesInUnicodeString OPTIONAL,
  5918. IN PCH CustomCPString,
  5919. IN ULONG BytesInCustomCPString
  5920. );
  5921. NTSYSAPI
  5922. NTSTATUS
  5923. NTAPI
  5924. RtlUnicodeToCustomCPN(
  5925. IN PCPTABLEINFO CustomCP,
  5926. OUT PCH CustomCPString,
  5927. IN ULONG MaxBytesInCustomCPString,
  5928. OUT PULONG BytesInCustomCPString OPTIONAL,
  5929. IN PWCH UnicodeString,
  5930. IN ULONG BytesInUnicodeString
  5931. );
  5932. NTSYSAPI
  5933. NTSTATUS
  5934. NTAPI
  5935. RtlUpcaseUnicodeToCustomCPN(
  5936. IN PCPTABLEINFO CustomCP,
  5937. OUT PCH CustomCPString,
  5938. IN ULONG MaxBytesInCustomCPString,
  5939. OUT PULONG BytesInCustomCPString OPTIONAL,
  5940. IN PWCH UnicodeString,
  5941. IN ULONG BytesInUnicodeString
  5942. );
  5943. NTSYSAPI
  5944. VOID
  5945. NTAPI
  5946. RtlInitCodePageTable(
  5947. IN PUSHORT TableBase,
  5948. OUT PCPTABLEINFO CodePageTable
  5949. );
  5950. // end_ntifs
  5951. NTSYSAPI
  5952. VOID
  5953. NTAPI
  5954. RtlInitNlsTables(
  5955. IN PUSHORT AnsiNlsBase,
  5956. IN PUSHORT OemNlsBase,
  5957. IN PUSHORT LanguageNlsBase,
  5958. OUT PNLSTABLEINFO TableInfo
  5959. );
  5960. NTSYSAPI
  5961. VOID
  5962. NTAPI
  5963. RtlResetRtlTranslations(
  5964. PNLSTABLEINFO TableInfo
  5965. );
  5966. NTSYSAPI
  5967. VOID
  5968. NTAPI
  5969. RtlGetDefaultCodePage(
  5970. OUT PUSHORT AnsiCodePage,
  5971. OUT PUSHORT OemCodePage
  5972. );
  5973. // begin_ntddk begin_nthal
  5974. //
  5975. // Range list package
  5976. //
  5977. typedef struct _RTL_RANGE {
  5978. //
  5979. // The start of the range
  5980. //
  5981. ULONGLONG Start; // Read only
  5982. //
  5983. // The end of the range
  5984. //
  5985. ULONGLONG End; // Read only
  5986. //
  5987. // Data the user passed in when they created the range
  5988. //
  5989. PVOID UserData; // Read/Write
  5990. //
  5991. // The owner of the range
  5992. //
  5993. PVOID Owner; // Read/Write
  5994. //
  5995. // User defined flags the user specified when they created the range
  5996. //
  5997. UCHAR Attributes; // Read/Write
  5998. //
  5999. // Flags (RTL_RANGE_*)
  6000. //
  6001. UCHAR Flags; // Read only
  6002. } RTL_RANGE, *PRTL_RANGE;
  6003. #define RTL_RANGE_SHARED 0x01
  6004. #define RTL_RANGE_CONFLICT 0x02
  6005. typedef struct _RTL_RANGE_LIST {
  6006. //
  6007. // The list of ranges
  6008. //
  6009. LIST_ENTRY ListHead;
  6010. //
  6011. // These always come in useful
  6012. //
  6013. ULONG Flags; // use RANGE_LIST_FLAG_*
  6014. //
  6015. // The number of entries in the list
  6016. //
  6017. ULONG Count;
  6018. //
  6019. // Every time an add/delete operation is performed on the list this is
  6020. // incremented. It is checked during iteration to ensure that the list
  6021. // hasn't changed between GetFirst/GetNext or GetNext/GetNext calls
  6022. //
  6023. ULONG Stamp;
  6024. } RTL_RANGE_LIST, *PRTL_RANGE_LIST;
  6025. typedef struct _RANGE_LIST_ITERATOR {
  6026. PLIST_ENTRY RangeListHead;
  6027. PLIST_ENTRY MergedHead;
  6028. PVOID Current;
  6029. ULONG Stamp;
  6030. } RTL_RANGE_LIST_ITERATOR, *PRTL_RANGE_LIST_ITERATOR;
  6031. // end_ntddk end_nthal
  6032. VOID
  6033. NTAPI
  6034. RtlInitializeRangeListPackage(
  6035. VOID
  6036. );
  6037. // begin_ntddk begin_nthal
  6038. NTSYSAPI
  6039. VOID
  6040. NTAPI
  6041. RtlInitializeRangeList(
  6042. IN OUT PRTL_RANGE_LIST RangeList
  6043. );
  6044. NTSYSAPI
  6045. VOID
  6046. NTAPI
  6047. RtlFreeRangeList(
  6048. IN PRTL_RANGE_LIST RangeList
  6049. );
  6050. NTSYSAPI
  6051. NTSTATUS
  6052. NTAPI
  6053. RtlCopyRangeList(
  6054. OUT PRTL_RANGE_LIST CopyRangeList,
  6055. IN PRTL_RANGE_LIST RangeList
  6056. );
  6057. #define RTL_RANGE_LIST_ADD_IF_CONFLICT 0x00000001
  6058. #define RTL_RANGE_LIST_ADD_SHARED 0x00000002
  6059. NTSYSAPI
  6060. NTSTATUS
  6061. NTAPI
  6062. RtlAddRange(
  6063. IN OUT PRTL_RANGE_LIST RangeList,
  6064. IN ULONGLONG Start,
  6065. IN ULONGLONG End,
  6066. IN UCHAR Attributes,
  6067. IN ULONG Flags,
  6068. IN PVOID UserData, OPTIONAL
  6069. IN PVOID Owner OPTIONAL
  6070. );
  6071. NTSYSAPI
  6072. NTSTATUS
  6073. NTAPI
  6074. RtlDeleteRange(
  6075. IN OUT PRTL_RANGE_LIST RangeList,
  6076. IN ULONGLONG Start,
  6077. IN ULONGLONG End,
  6078. IN PVOID Owner
  6079. );
  6080. NTSYSAPI
  6081. NTSTATUS
  6082. NTAPI
  6083. RtlDeleteOwnersRanges(
  6084. IN OUT PRTL_RANGE_LIST RangeList,
  6085. IN PVOID Owner
  6086. );
  6087. #define RTL_RANGE_LIST_SHARED_OK 0x00000001
  6088. #define RTL_RANGE_LIST_NULL_CONFLICT_OK 0x00000002
  6089. typedef
  6090. BOOLEAN
  6091. (*PRTL_CONFLICT_RANGE_CALLBACK) (
  6092. IN PVOID Context,
  6093. IN PRTL_RANGE Range
  6094. );
  6095. NTSYSAPI
  6096. NTSTATUS
  6097. NTAPI
  6098. RtlFindRange(
  6099. IN PRTL_RANGE_LIST RangeList,
  6100. IN ULONGLONG Minimum,
  6101. IN ULONGLONG Maximum,
  6102. IN ULONG Length,
  6103. IN ULONG Alignment,
  6104. IN ULONG Flags,
  6105. IN UCHAR AttributeAvailableMask,
  6106. IN PVOID Context OPTIONAL,
  6107. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  6108. OUT PULONGLONG Start
  6109. );
  6110. NTSYSAPI
  6111. NTSTATUS
  6112. NTAPI
  6113. RtlIsRangeAvailable(
  6114. IN PRTL_RANGE_LIST RangeList,
  6115. IN ULONGLONG Start,
  6116. IN ULONGLONG End,
  6117. IN ULONG Flags,
  6118. IN UCHAR AttributeAvailableMask,
  6119. IN PVOID Context OPTIONAL,
  6120. IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
  6121. OUT PBOOLEAN Available
  6122. );
  6123. #define FOR_ALL_RANGES(RangeList, Iterator, Current) \
  6124. for (RtlGetFirstRange((RangeList), (Iterator), &(Current)); \
  6125. (Current) != NULL; \
  6126. RtlGetNextRange((Iterator), &(Current), TRUE) \
  6127. )
  6128. #define FOR_ALL_RANGES_BACKWARDS(RangeList, Iterator, Current) \
  6129. for (RtlGetLastRange((RangeList), (Iterator), &(Current)); \
  6130. (Current) != NULL; \
  6131. RtlGetNextRange((Iterator), &(Current), FALSE) \
  6132. )
  6133. NTSYSAPI
  6134. NTSTATUS
  6135. NTAPI
  6136. RtlGetFirstRange(
  6137. IN PRTL_RANGE_LIST RangeList,
  6138. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  6139. OUT PRTL_RANGE *Range
  6140. );
  6141. NTSYSAPI
  6142. NTSTATUS
  6143. NTAPI
  6144. RtlGetLastRange(
  6145. IN PRTL_RANGE_LIST RangeList,
  6146. OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  6147. OUT PRTL_RANGE *Range
  6148. );
  6149. NTSYSAPI
  6150. NTSTATUS
  6151. NTAPI
  6152. RtlGetNextRange(
  6153. IN OUT PRTL_RANGE_LIST_ITERATOR Iterator,
  6154. OUT PRTL_RANGE *Range,
  6155. IN BOOLEAN MoveForwards
  6156. );
  6157. #define RTL_RANGE_LIST_MERGE_IF_CONFLICT RTL_RANGE_LIST_ADD_IF_CONFLICT
  6158. NTSYSAPI
  6159. NTSTATUS
  6160. NTAPI
  6161. RtlMergeRangeLists(
  6162. OUT PRTL_RANGE_LIST MergedRangeList,
  6163. IN PRTL_RANGE_LIST RangeList1,
  6164. IN PRTL_RANGE_LIST RangeList2,
  6165. IN ULONG Flags
  6166. );
  6167. NTSYSAPI
  6168. NTSTATUS
  6169. NTAPI
  6170. RtlInvertRangeList(
  6171. OUT PRTL_RANGE_LIST InvertedRangeList,
  6172. IN PRTL_RANGE_LIST RangeList
  6173. );
  6174. // end_nthal
  6175. // begin_wdm
  6176. //
  6177. // Byte swap routines. These are used to convert from little-endian to
  6178. // big-endian and vice-versa.
  6179. //
  6180. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  6181. #ifdef __cplusplus
  6182. extern "C" {
  6183. #endif
  6184. unsigned short __cdecl _byteswap_ushort(unsigned short);
  6185. unsigned long __cdecl _byteswap_ulong (unsigned long);
  6186. unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
  6187. #ifdef __cplusplus
  6188. }
  6189. #endif
  6190. #pragma intrinsic(_byteswap_ushort)
  6191. #pragma intrinsic(_byteswap_ulong)
  6192. #pragma intrinsic(_byteswap_uint64)
  6193. #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
  6194. #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
  6195. #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
  6196. #else
  6197. USHORT
  6198. FASTCALL
  6199. RtlUshortByteSwap(
  6200. IN USHORT Source
  6201. );
  6202. ULONG
  6203. FASTCALL
  6204. RtlUlongByteSwap(
  6205. IN ULONG Source
  6206. );
  6207. ULONGLONG
  6208. FASTCALL
  6209. RtlUlonglongByteSwap(
  6210. IN ULONGLONG Source
  6211. );
  6212. #endif
  6213. // end_wdm
  6214. // begin_ntifs
  6215. //
  6216. // Routine for converting from a volume device object to a DOS name.
  6217. //
  6218. NTSYSAPI
  6219. NTSTATUS
  6220. NTAPI
  6221. RtlVolumeDeviceToDosName(
  6222. IN PVOID VolumeDeviceObject,
  6223. OUT PUNICODE_STRING DosName
  6224. );
  6225. // end_ntifs end_ntddk
  6226. // begin_ntifs
  6227. //
  6228. // Routine for verifying or creating the "System Volume Information"
  6229. // folder on NTFS volumes.
  6230. //
  6231. NTSYSAPI
  6232. NTSTATUS
  6233. NTAPI
  6234. RtlCreateSystemVolumeInformationFolder(
  6235. IN PUNICODE_STRING VolumeRootPath
  6236. );
  6237. #define RTL_SYSTEM_VOLUME_INFORMATION_FOLDER L"System Volume Information"
  6238. // end_ntifs
  6239. // begin_winnt begin_ntddk begin_ntifs
  6240. typedef struct _OSVERSIONINFOA {
  6241. ULONG dwOSVersionInfoSize;
  6242. ULONG dwMajorVersion;
  6243. ULONG dwMinorVersion;
  6244. ULONG dwBuildNumber;
  6245. ULONG dwPlatformId;
  6246. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6247. } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
  6248. typedef struct _OSVERSIONINFOW {
  6249. ULONG dwOSVersionInfoSize;
  6250. ULONG dwMajorVersion;
  6251. ULONG dwMinorVersion;
  6252. ULONG dwBuildNumber;
  6253. ULONG dwPlatformId;
  6254. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6255. } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
  6256. #ifdef UNICODE
  6257. typedef OSVERSIONINFOW OSVERSIONINFO;
  6258. typedef POSVERSIONINFOW POSVERSIONINFO;
  6259. typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
  6260. #else
  6261. typedef OSVERSIONINFOA OSVERSIONINFO;
  6262. typedef POSVERSIONINFOA POSVERSIONINFO;
  6263. typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
  6264. #endif // UNICODE
  6265. typedef struct _OSVERSIONINFOEXA {
  6266. ULONG dwOSVersionInfoSize;
  6267. ULONG dwMajorVersion;
  6268. ULONG dwMinorVersion;
  6269. ULONG dwBuildNumber;
  6270. ULONG dwPlatformId;
  6271. CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6272. USHORT wServicePackMajor;
  6273. USHORT wServicePackMinor;
  6274. USHORT wSuiteMask;
  6275. UCHAR wProductType;
  6276. UCHAR wReserved;
  6277. } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
  6278. typedef struct _OSVERSIONINFOEXW {
  6279. ULONG dwOSVersionInfoSize;
  6280. ULONG dwMajorVersion;
  6281. ULONG dwMinorVersion;
  6282. ULONG dwBuildNumber;
  6283. ULONG dwPlatformId;
  6284. WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
  6285. USHORT wServicePackMajor;
  6286. USHORT wServicePackMinor;
  6287. USHORT wSuiteMask;
  6288. UCHAR wProductType;
  6289. UCHAR wReserved;
  6290. } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
  6291. #ifdef UNICODE
  6292. typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
  6293. typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
  6294. typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
  6295. #else
  6296. typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
  6297. typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
  6298. typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
  6299. #endif // UNICODE
  6300. //
  6301. // RtlVerifyVersionInfo() conditions
  6302. //
  6303. #define VER_EQUAL 1
  6304. #define VER_GREATER 2
  6305. #define VER_GREATER_EQUAL 3
  6306. #define VER_LESS 4
  6307. #define VER_LESS_EQUAL 5
  6308. #define VER_AND 6
  6309. #define VER_OR 7
  6310. #define VER_CONDITION_MASK 7
  6311. #define VER_NUM_BITS_PER_CONDITION_MASK 3
  6312. //
  6313. // RtlVerifyVersionInfo() type mask bits
  6314. //
  6315. #define VER_MINORVERSION 0x0000001
  6316. #define VER_MAJORVERSION 0x0000002
  6317. #define VER_BUILDNUMBER 0x0000004
  6318. #define VER_PLATFORMID 0x0000008
  6319. #define VER_SERVICEPACKMINOR 0x0000010
  6320. #define VER_SERVICEPACKMAJOR 0x0000020
  6321. #define VER_SUITENAME 0x0000040
  6322. #define VER_PRODUCT_TYPE 0x0000080
  6323. //
  6324. // RtlVerifyVersionInfo() os product type values
  6325. //
  6326. #define VER_NT_WORKSTATION 0x0000001
  6327. #define VER_NT_DOMAIN_CONTROLLER 0x0000002
  6328. #define VER_NT_SERVER 0x0000003
  6329. //
  6330. // dwPlatformId defines:
  6331. //
  6332. #define VER_PLATFORM_WIN32s 0
  6333. #define VER_PLATFORM_WIN32_WINDOWS 1
  6334. #define VER_PLATFORM_WIN32_NT 2
  6335. //
  6336. //
  6337. // VerifyVersionInfo() macro to set the condition mask
  6338. //
  6339. // For documentation sakes here's the old version of the macro that got
  6340. // changed to call an API
  6341. // #define VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
  6342. //
  6343. #define VER_SET_CONDITION(_m_,_t_,_c_) \
  6344. ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
  6345. ULONGLONG
  6346. NTAPI
  6347. VerSetConditionMask(
  6348. IN ULONGLONG ConditionMask,
  6349. IN ULONG TypeMask,
  6350. IN UCHAR Condition
  6351. );
  6352. //
  6353. // end_winnt
  6354. //
  6355. NTSYSAPI
  6356. NTSTATUS
  6357. RtlGetVersion(
  6358. OUT PRTL_OSVERSIONINFOW lpVersionInformation
  6359. );
  6360. NTSYSAPI
  6361. NTSTATUS
  6362. RtlVerifyVersionInfo(
  6363. IN PRTL_OSVERSIONINFOEXW VersionInfo,
  6364. IN ULONG TypeMask,
  6365. IN ULONGLONG ConditionMask
  6366. );
  6367. //
  6368. // end_ntddk end_ntifs
  6369. //
  6370. typedef
  6371. NTSTATUS
  6372. (*PRTL_SECURE_MEMORY_CACHE_CALLBACK) (
  6373. IN PVOID Addr,
  6374. IN SIZE_T Range
  6375. );
  6376. NTSTATUS
  6377. RtlRegisterSecureMemoryCacheCallback(
  6378. IN PRTL_SECURE_MEMORY_CACHE_CALLBACK CallBack
  6379. );
  6380. BOOLEAN
  6381. RtlFlushSecureMemoryCache(
  6382. PVOID lpAddr,
  6383. SIZE_T size
  6384. );
  6385. ULONG32
  6386. RtlComputeCrc32(
  6387. IN ULONG32 PartialCrc,
  6388. IN PVOID Buffer,
  6389. IN ULONG Length
  6390. );
  6391. PPEB
  6392. RtlGetCurrentPeb (
  6393. VOID
  6394. );
  6395. ULONG
  6396. FASTCALL
  6397. RtlInterlockedSetClearBits (
  6398. IN OUT PULONG Flags,
  6399. IN ULONG sFlag,
  6400. IN ULONG cFlag
  6401. );
  6402. // begin_ntddk begin_ntifs
  6403. //
  6404. // Interlocked bit manipulation interfaces
  6405. //
  6406. #define RtlInterlockedSetBits(Flags, Flag) \
  6407. InterlockedOr((PLONG)(Flags), Flag)
  6408. #define RtlInterlockedAndBits(Flags, Flag) \
  6409. InterlockedAnd((PLONG)(Flags), Flag)
  6410. #define RtlInterlockedClearBits(Flags, Flag) \
  6411. RtlInterlockedAndBits(Flags, ~(Flag))
  6412. #define RtlInterlockedXorBits(Flags, Flag) \
  6413. InterlockedXor(Flags, Flag)
  6414. #define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
  6415. (VOID) RtlInterlockedSetBits(Flags, Flag)
  6416. #define RtlInterlockedAndBitsDiscardReturn(Flags, Flag) \
  6417. (VOID) RtlInterlockedAndBits(Flags, Flag)
  6418. #define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
  6419. RtlInterlockedAndBitsDiscardReturn(Flags, ~(Flag))
  6420. // end_ntddk end_ntifs
  6421. #include "ntrtlstringandbuffer.h"
  6422. #include "ntrtlpath.h"
  6423. NTSTATUS
  6424. NTAPI
  6425. RtlGetLastNtStatus(
  6426. VOID
  6427. );
  6428. NTSYSAPI
  6429. LONG
  6430. NTAPI
  6431. RtlGetLastWin32Error(
  6432. VOID
  6433. );
  6434. NTSYSAPI
  6435. VOID
  6436. NTAPI
  6437. RtlSetLastWin32ErrorAndNtStatusFromNtStatus(
  6438. NTSTATUS Status
  6439. );
  6440. NTSYSAPI
  6441. VOID
  6442. NTAPI
  6443. RtlSetLastWin32Error(
  6444. LONG Win32Error
  6445. );
  6446. //
  6447. // This differs from RtlSetLastWin32Error in that.
  6448. // - it is a different function, so breakpoints on RtlSetLastWin32Error won't fire when you call it
  6449. // - #if DBG, it only writes if the current value is unequal, so data breakpoints won't fire as much
  6450. //
  6451. NTSYSAPI
  6452. VOID
  6453. NTAPI
  6454. RtlRestoreLastWin32Error(
  6455. LONG Win32Error
  6456. );
  6457. //
  6458. // Routines to manipulate boot status data.
  6459. //
  6460. typedef enum {
  6461. RtlBsdItemVersionNumber = 0x00,
  6462. RtlBsdItemProductType,
  6463. RtlBsdItemAabEnabled,
  6464. RtlBsdItemAabTimeout,
  6465. RtlBsdItemBootGood,
  6466. RtlBsdItemBootShutdown,
  6467. RtlBsdItemMax
  6468. } RTL_BSD_ITEM_TYPE, *PRTL_BSD_ITEM_TYPE;
  6469. NTSYSAPI
  6470. NTSTATUS
  6471. NTAPI
  6472. RtlGetSetBootStatusData(
  6473. IN HANDLE Handle,
  6474. IN BOOLEAN Get,
  6475. IN RTL_BSD_ITEM_TYPE DataItem,
  6476. IN PVOID DataBuffer,
  6477. IN ULONG DataBufferLength,
  6478. OUT PULONG ByteRead OPTIONAL
  6479. );
  6480. NTSYSAPI
  6481. NTSTATUS
  6482. NTAPI
  6483. RtlLockBootStatusData(
  6484. OUT PHANDLE BootStatusDataHandle
  6485. );
  6486. NTSYSAPI
  6487. VOID
  6488. NTAPI
  6489. RtlUnlockBootStatusData(
  6490. IN HANDLE BootStatusDataHandle
  6491. );
  6492. NTSYSAPI
  6493. NTSTATUS
  6494. NTAPI
  6495. RtlCreateBootStatusDataFile(
  6496. VOID
  6497. );
  6498. #define RTL_ERRORMODE_FAILCRITICALERRORS (0x0010)
  6499. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  6500. FORCEINLINE
  6501. BOOLEAN
  6502. RtlUnsignedAddWithCarryOut32(
  6503. unsigned __int32 *pc,
  6504. unsigned __int32 a,
  6505. unsigned __int32 b
  6506. )
  6507. {
  6508. unsigned __int32 c;
  6509. c = a + b;
  6510. *pc = c;
  6511. return (c >= a && c >= b) ? 0 : 1;
  6512. }
  6513. FORCEINLINE
  6514. BOOLEAN
  6515. RtlUnsignedAddWithCarryOut64(
  6516. unsigned __int64 *pc,
  6517. unsigned __int64 a,
  6518. unsigned __int64 b
  6519. )
  6520. {
  6521. unsigned __int64 c;
  6522. c = a + b;
  6523. *pc = c;
  6524. return (c >= a && c >= b) ? 0 : 1;
  6525. }
  6526. FORCEINLINE
  6527. BOOLEAN
  6528. RtlSignedAddWithOverflowOut32(
  6529. __int32 *pc,
  6530. __int32 a,
  6531. __int32 b
  6532. )
  6533. {
  6534. __int32 c;
  6535. c = a + b;
  6536. *pc = c;
  6537. //
  6538. // negative + positive -> no overflow
  6539. // positive + negative -> no overflow
  6540. // positive + positive -> overflow if result is not positive
  6541. // negative + negative -> overflow if result is not negative
  6542. //
  6543. // aka -- no overflow if result's sign is the same as either input's sign.
  6544. //
  6545. return (((c < 0) == (a < 0)) || ((c < 0) == (b < 0))) ? 0 : 1;
  6546. }
  6547. FORCEINLINE
  6548. BOOLEAN
  6549. RtlSignedAddWithOverflowOut64(
  6550. __int64 *pc,
  6551. __int64 a,
  6552. __int64 b
  6553. )
  6554. {
  6555. __int64 c;
  6556. c = a + b;
  6557. *pc = c;
  6558. return (((c < 0) == (a < 0)) || ((c < 0) == (b < 0))) ? 0 : 1;
  6559. }
  6560. #define RTLP_ADD_WITH_CARRY_OUT(FunctionName, Type, BaseFunction, BaseType) \
  6561. FORCEINLINE \
  6562. BOOLEAN \
  6563. FunctionName( \
  6564. Type *pc, \
  6565. Type a, \
  6566. Type b \
  6567. ) \
  6568. { \
  6569. return BaseFunction((BaseType*)pc, a, b); \
  6570. }
  6571. #define RTLP_ADD_WITH_OVERFLOW_OUT RTLP_ADD_WITH_CARRY_OUT
  6572. #define RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(FunctionName, Type) \
  6573. RTLP_ADD_WITH_CARRY_OUT(FunctionName, Type, RtlUnsignedAddWithCarryOut32, unsigned __int32)
  6574. #define RTLP_ADD_WITH_CARRY_OUT_UNSIGNED64(FunctionName, Type) \
  6575. RTLP_ADD_WITH_CARRY_OUT(FunctionName, Type, RtlUnsignedAddWithCarryOut64, unsigned __int64)
  6576. #define RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED32(FunctionName, Type) \
  6577. RTLP_ADD_WITH_OVERFLOW_OUT(FunctionName, Type, RtlSignedAddWithOverflowOut32, __int32)
  6578. #define RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED64(FunctionName, Type) \
  6579. RTLP_ADD_WITH_OVERFLOW_OUT(FunctionName, Type, RtlSignedAddWithOverflowOut64, __int64)
  6580. #if !defined(_WIN64)
  6581. #define RTLP_ADD_WITH_CARRY_OUT_UNSIGNED_PTR(FunctionName, Type) RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(FunctionName, Type)
  6582. #define RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED_PTR(FunctionName, Type) RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED32(FunctionName, Type)
  6583. #else
  6584. #define RTLP_ADD_WITH_CARRY_OUT_UNSIGNED_PTR(FunctionName, Type) RTLP_ADD_WITH_CARRY_OUT_UNSIGNED64(FunctionName, Type)
  6585. #define RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED_PTR(FunctionName, Type) RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED64(FunctionName, Type)
  6586. #endif
  6587. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(RtlAddWithCarryOutUint, unsigned int) /* aka UINT */
  6588. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(RtlAddWithCarryOutUint32, UINT32)
  6589. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(RtlAddWithCarryOutUlong, ULONG)
  6590. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(RtlAddWithCarryOutUlong32, ULONG32)
  6591. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(RtlAddWithCarryOutDword, unsigned long) /* aka DWORD */
  6592. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32(RtlAddWithCarryOutDword32, DWORD32)
  6593. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED64(RtlAddWithCarryOutUint64, UINT64)
  6594. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED64(RtlAddWithCarryOutUlong64, ULONG64)
  6595. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED64(RtlAddWithCarryOutDword64, DWORD64)
  6596. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED64(RtlAddWithCarryOutUlonglong, ULONGLONG)
  6597. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED32(RtlAddWithOverflowOutInt, int) /* aka INT */
  6598. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED32(RtlAddWithOverflowOutInt32, INT32)
  6599. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED32(RtlAddWithOverflowOutLong, LONG)
  6600. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED32(RtlAddWithOverflowOutLong32, LONG32)
  6601. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED64(RtlAddWithOverflowOutInt64, INT64)
  6602. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED64(RtlAddWithOverflowOutLong64, LONG64)
  6603. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED64(RtlAddWithOverflowOutLongLong, LONGLONG)
  6604. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED_PTR(RtlAddWithCarryOutUintPtr, UINT_PTR)
  6605. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED_PTR(RtlAddWithCarryOutUlongPtr, ULONG_PTR)
  6606. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED_PTR(RtlAddWithCarryOutDwordPtr, DWORD_PTR)
  6607. RTLP_ADD_WITH_CARRY_OUT_UNSIGNED_PTR(RtlAddWithCarryOutSizet, SIZE_T)
  6608. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED_PTR(RtlAddWithOverflowOutIntPtr, INT_PTR)
  6609. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED_PTR(RtlAddWithOverflowOutLongPtr, LONG_PTR)
  6610. RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED_PTR(RtlAddWithOverflowOutSsizet, SSIZE_T)
  6611. #undef RTLP_ADD_WITH_CARRY_OUT
  6612. #undef RTLP_ADD_WITH_OVERFLOW_OUT
  6613. #undef RTLP_ADD_WITH_CARRY_OUT_UNSIGNED32
  6614. #undef RTLP_ADD_WITH_CARRY_OUT_UNSIGNED64
  6615. #undef RTLP_ADD_WITH_CARRY_OUT_UNSIGNED_PTR
  6616. #undef RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED32
  6617. #undef RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED64
  6618. #undef RTLP_ADD_WITH_OVERFLOW_OUT_SIGNED_PTR
  6619. #endif // !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  6620. //
  6621. // Get information from the correct TEB
  6622. //
  6623. #if defined(BUILD_WOW6432)
  6624. #define RtlIsImpersonating() (NtCurrentTeb64()->IsImpersonating ? TRUE : FALSE)
  6625. #else
  6626. #define RtlIsImpersonating() (NtCurrentTeb()->IsImpersonating ? TRUE : FALSE)
  6627. #endif
  6628. #ifdef __cplusplus
  6629. } // extern "C"
  6630. #endif
  6631. #if defined (_MSC_VER) && ( _MSC_VER >= 800 )
  6632. #if _MSC_VER >= 1200
  6633. #pragma warning(pop)
  6634. #else
  6635. #pragma warning(default:4001)
  6636. #pragma warning(default:4201)
  6637. #pragma warning(default:4214)
  6638. #endif
  6639. #endif
  6640. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis