Source code of Windows XP (NT5)
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.

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