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

3328 lines
90 KiB

  1. /*++ Build Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. nturtl.h
  5. Abstract:
  6. Include file for NT runtime routines that are callable by only
  7. user mode code in various NT subsystems.
  8. Author:
  9. Steve Wood (stevewo) 10-Aug-1989
  10. Environment:
  11. These routines are dynamically linked in the caller's executable and
  12. are callable only from user mode. They make use of Nt system
  13. services.
  14. Revision History:
  15. --*/
  16. #ifndef _NTURTL_
  17. #define _NTURTL_
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if defined (_MSC_VER)
  25. #if ( _MSC_VER >= 800 )
  26. #pragma warning(disable:4514)
  27. #if _MSC_VER >= 1200
  28. #pragma warning(push)
  29. #endif
  30. #pragma warning(disable:4001)
  31. #pragma warning(disable:4201)
  32. #pragma warning(disable:4214)
  33. #endif
  34. #if (_MSC_VER >= 1020)
  35. #pragma once
  36. #endif
  37. #endif
  38. //
  39. // CriticalSection function definitions
  40. //
  41. // begin_winnt
  42. typedef struct _RTL_CRITICAL_SECTION_DEBUG {
  43. USHORT Type;
  44. USHORT CreatorBackTraceIndex;
  45. struct _RTL_CRITICAL_SECTION *CriticalSection;
  46. LIST_ENTRY ProcessLocksList;
  47. ULONG EntryCount;
  48. ULONG ContentionCount;
  49. ULONG Spare[ 2 ];
  50. } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG, RTL_RESOURCE_DEBUG, *PRTL_RESOURCE_DEBUG;
  51. #define RTL_CRITSECT_TYPE 0
  52. #define RTL_RESOURCE_TYPE 1
  53. typedef struct _RTL_CRITICAL_SECTION {
  54. PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
  55. //
  56. // The following three fields control entering and exiting the critical
  57. // section for the resource
  58. //
  59. LONG LockCount;
  60. LONG RecursionCount;
  61. HANDLE OwningThread; // from the thread's ClientId->UniqueThread
  62. HANDLE LockSemaphore;
  63. ULONG_PTR SpinCount; // force size on 64-bit systems when packed
  64. } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
  65. // end_winnt
  66. //
  67. // These are needed for the debugger and WOW64.
  68. //
  69. typedef struct _RTL_CRITICAL_SECTION_DEBUG32 {
  70. USHORT Type;
  71. USHORT CreatorBackTraceIndex;
  72. ULONG CriticalSection;
  73. LIST_ENTRY32 ProcessLocksList;
  74. ULONG EntryCount;
  75. ULONG ContentionCount;
  76. ULONG Spare[ 2 ];
  77. } RTL_CRITICAL_SECTION_DEBUG32, *PRTL_CRITICAL_SECTION_DEBUG32, RTL_RESOURCE_DEBUG32, *PRTL_RESOURCE_DEBUG32;
  78. typedef struct _RTL_CRITICAL_SECTION_DEBUG64 {
  79. USHORT Type;
  80. USHORT CreatorBackTraceIndex;
  81. ULONG64 CriticalSection;
  82. LIST_ENTRY64 ProcessLocksList;
  83. ULONG EntryCount;
  84. ULONG ContentionCount;
  85. ULONG Spare[ 2 ];
  86. } RTL_CRITICAL_SECTION_DEBUG64, *PRTL_CRITICAL_SECTION_DEBUG64, RTL_RESOURCE_DEBUG64, *PRTL_RESOURCE_DEBUG64;
  87. typedef struct _RTL_CRITICAL_SECTION32 {
  88. ULONG DebugInfo;
  89. LONG LockCount;
  90. LONG RecursionCount;
  91. ULONG OwningThread;
  92. ULONG LockSemaphore;
  93. ULONG SpinCount;
  94. } RTL_CRITICAL_SECTION32, *PRTL_CRITICAL_SECTION32;
  95. typedef struct _RTL_CRITICAL_SECTION64 {
  96. ULONG64 DebugInfo;
  97. LONG LockCount;
  98. LONG RecursionCount;
  99. ULONG64 OwningThread;
  100. ULONG64 LockSemaphore;
  101. ULONG64 SpinCount;
  102. } RTL_CRITICAL_SECTION64, *PRTL_CRITICAL_SECTION64;
  103. //
  104. // Shared resource function definitions
  105. //
  106. typedef struct _RTL_RESOURCE {
  107. //
  108. // The following field controls entering and exiting the critical
  109. // section for the resource
  110. //
  111. RTL_CRITICAL_SECTION CriticalSection;
  112. //
  113. // The following four fields indicate the number of both shared or
  114. // exclusive waiters
  115. //
  116. HANDLE SharedSemaphore;
  117. ULONG NumberOfWaitingShared;
  118. HANDLE ExclusiveSemaphore;
  119. ULONG NumberOfWaitingExclusive;
  120. //
  121. // The following indicates the current state of the resource
  122. //
  123. // <0 the resource is acquired for exclusive access with the
  124. // absolute value indicating the number of recursive accesses
  125. // to the resource
  126. //
  127. // 0 the resource is available
  128. //
  129. // >0 the resource is acquired for shared access with the
  130. // value indicating the number of shared accesses to the resource
  131. //
  132. LONG NumberOfActive;
  133. HANDLE ExclusiveOwnerThread;
  134. ULONG Flags; // See RTL_RESOURCE_FLAG_ equates below.
  135. PRTL_RESOURCE_DEBUG DebugInfo;
  136. } RTL_RESOURCE, *PRTL_RESOURCE;
  137. #define RTL_RESOURCE_FLAG_LONG_TERM ((ULONG) 0x00000001)
  138. NTSYSAPI
  139. NTSTATUS
  140. NTAPI
  141. RtlEnterCriticalSection(
  142. PRTL_CRITICAL_SECTION CriticalSection
  143. );
  144. NTSYSAPI
  145. NTSTATUS
  146. NTAPI
  147. RtlLeaveCriticalSection(
  148. PRTL_CRITICAL_SECTION CriticalSection
  149. );
  150. NTSYSAPI
  151. BOOLEAN
  152. NTAPI
  153. RtlTryEnterCriticalSection(
  154. PRTL_CRITICAL_SECTION CriticalSection
  155. );
  156. NTSYSAPI
  157. NTSTATUS
  158. NTAPI
  159. RtlInitializeCriticalSection(
  160. PRTL_CRITICAL_SECTION CriticalSection
  161. );
  162. NTSYSAPI
  163. VOID
  164. NTAPI
  165. RtlEnableEarlyCriticalSectionEventCreation(
  166. VOID
  167. );
  168. NTSYSAPI
  169. NTSTATUS
  170. NTAPI
  171. RtlInitializeCriticalSectionAndSpinCount(
  172. PRTL_CRITICAL_SECTION CriticalSection,
  173. ULONG SpinCount
  174. );
  175. NTSYSAPI
  176. ULONG
  177. NTAPI
  178. RtlSetCriticalSectionSpinCount(
  179. PRTL_CRITICAL_SECTION CriticalSection,
  180. ULONG SpinCount
  181. );
  182. NTSYSAPI
  183. NTSTATUS
  184. NTAPI
  185. RtlDeleteCriticalSection(
  186. PRTL_CRITICAL_SECTION CriticalSection
  187. );
  188. NTSYSAPI
  189. VOID
  190. NTAPI
  191. RtlInitializeResource(
  192. PRTL_RESOURCE Resource
  193. );
  194. NTSYSAPI
  195. BOOLEAN
  196. NTAPI
  197. RtlAcquireResourceShared(
  198. PRTL_RESOURCE Resource,
  199. BOOLEAN Wait
  200. );
  201. NTSYSAPI
  202. BOOLEAN
  203. NTAPI
  204. RtlAcquireResourceExclusive(
  205. PRTL_RESOURCE Resource,
  206. BOOLEAN Wait
  207. );
  208. NTSYSAPI
  209. VOID
  210. NTAPI
  211. RtlReleaseResource(
  212. PRTL_RESOURCE Resource
  213. );
  214. NTSYSAPI
  215. VOID
  216. NTAPI
  217. RtlConvertSharedToExclusive(
  218. PRTL_RESOURCE Resource
  219. );
  220. NTSYSAPI
  221. VOID
  222. NTAPI
  223. RtlConvertExclusiveToShared(
  224. PRTL_RESOURCE Resource
  225. );
  226. NTSYSAPI
  227. VOID
  228. NTAPI
  229. RtlDeleteResource (
  230. PRTL_RESOURCE Resource
  231. );
  232. NTSYSAPI
  233. VOID
  234. NTAPI
  235. RtlCheckForOrphanedCriticalSections(
  236. IN HANDLE hThread
  237. );
  238. NTSYSAPI
  239. VOID
  240. NTAPI
  241. RtlCheckHeldCriticalSections(
  242. IN HANDLE hThread,
  243. IN PRTL_CRITICAL_SECTION const *LocksHeld
  244. );
  245. #define RTL_UNLOAD_EVENT_TRACE_NUMBER 16
  246. typedef struct _RTL_UNLOAD_EVENT_TRACE {
  247. PVOID BaseAddress; // Base address of dll
  248. SIZE_T SizeOfImage; // Size of image
  249. ULONG Sequence; // Sequence number for this event
  250. ULONG TimeDateStamp; // Time and date of image
  251. ULONG CheckSum; // Image checksum
  252. WCHAR ImageName[32]; // Image name
  253. } RTL_UNLOAD_EVENT_TRACE, *PRTL_UNLOAD_EVENT_TRACE;
  254. typedef struct _RTL_UNLOAD_EVENT_TRACE64 {
  255. ULONGLONG BaseAddress; // Base address of dll
  256. ULONGLONG SizeOfImage; // Size of image
  257. ULONG Sequence; // Sequence number for this event
  258. ULONG TimeDateStamp; // Time and date of image
  259. ULONG CheckSum; // Image checksum
  260. WCHAR ImageName[32]; // Image name
  261. } RTL_UNLOAD_EVENT_TRACE64, *PRTL_UNLOAD_EVENT_TRACE64;
  262. typedef struct _RTL_UNLOAD_EVENT_TRACE32 {
  263. ULONG BaseAddress; // Base address of dll
  264. ULONG SizeOfImage; // Size of image
  265. ULONG Sequence; // Sequence number for this event
  266. ULONG TimeDateStamp; // Time and date of image
  267. ULONG CheckSum; // Image checksum
  268. WCHAR ImageName[32]; // Image name
  269. } RTL_UNLOAD_EVENT_TRACE32, *PRTL_UNLOAD_EVENT_TRACE32;
  270. NTSYSAPI
  271. PRTL_UNLOAD_EVENT_TRACE
  272. NTAPI
  273. RtlGetUnloadEventTrace (
  274. VOID
  275. );
  276. //
  277. // Application verifier types needed by provider dlls
  278. //
  279. // begin_winnt
  280. typedef VOID (NTAPI * RTL_VERIFIER_DLL_LOAD_CALLBACK) (
  281. PWSTR DllName,
  282. PVOID DllBase,
  283. SIZE_T DllSize,
  284. PVOID Reserved
  285. );
  286. typedef VOID (NTAPI * RTL_VERIFIER_DLL_UNLOAD_CALLBACK) (
  287. PWSTR DllName,
  288. PVOID DllBase,
  289. SIZE_T DllSize,
  290. PVOID Reserved
  291. );
  292. typedef VOID (NTAPI * RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK) (
  293. PVOID AllocationBase,
  294. SIZE_T AllocationSize
  295. );
  296. typedef struct _RTL_VERIFIER_THUNK_DESCRIPTOR {
  297. PCHAR ThunkName;
  298. PVOID ThunkOldAddress;
  299. PVOID ThunkNewAddress;
  300. } RTL_VERIFIER_THUNK_DESCRIPTOR, *PRTL_VERIFIER_THUNK_DESCRIPTOR;
  301. typedef struct _RTL_VERIFIER_DLL_DESCRIPTOR {
  302. PWCHAR DllName;
  303. ULONG DllFlags;
  304. PVOID DllAddress;
  305. PRTL_VERIFIER_THUNK_DESCRIPTOR DllThunks;
  306. } RTL_VERIFIER_DLL_DESCRIPTOR, *PRTL_VERIFIER_DLL_DESCRIPTOR;
  307. typedef struct _RTL_VERIFIER_PROVIDER_DESCRIPTOR {
  308. //
  309. // Filled by verifier provider DLL
  310. //
  311. ULONG Length;
  312. PRTL_VERIFIER_DLL_DESCRIPTOR ProviderDlls;
  313. RTL_VERIFIER_DLL_LOAD_CALLBACK ProviderDllLoadCallback;
  314. RTL_VERIFIER_DLL_UNLOAD_CALLBACK ProviderDllUnloadCallback;
  315. //
  316. // Filled by verifier engine
  317. //
  318. PWSTR VerifierImage;
  319. ULONG VerifierFlags;
  320. ULONG VerifierDebug;
  321. PVOID RtlpGetStackTraceAddress;
  322. PVOID RtlpDebugPageHeapCreate;
  323. PVOID RtlpDebugPageHeapDestroy;
  324. //
  325. // Filled by verifier provider DLL
  326. //
  327. RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK ProviderNtdllHeapFreeCallback;
  328. } RTL_VERIFIER_PROVIDER_DESCRIPTOR, *PRTL_VERIFIER_PROVIDER_DESCRIPTOR;
  329. //
  330. // Application verifier standard flags
  331. //
  332. #define RTL_VRF_FLG_FULL_PAGE_HEAP 0x00000001
  333. #define RTL_VRF_FLG_RESERVED_DONOTUSE 0x00000002 // old RTL_VRF_FLG_LOCK_CHECKS
  334. #define RTL_VRF_FLG_HANDLE_CHECKS 0x00000004
  335. #define RTL_VRF_FLG_STACK_CHECKS 0x00000008
  336. #define RTL_VRF_FLG_APPCOMPAT_CHECKS 0x00000010
  337. #define RTL_VRF_FLG_TLS_CHECKS 0x00000020
  338. #define RTL_VRF_FLG_DIRTY_STACKS 0x00000040
  339. #define RTL_VRF_FLG_RPC_CHECKS 0x00000080
  340. #define RTL_VRF_FLG_COM_CHECKS 0x00000100
  341. #define RTL_VRF_FLG_DANGEROUS_APIS 0x00000200
  342. #define RTL_VRF_FLG_RACE_CHECKS 0x00000400
  343. #define RTL_VRF_FLG_DEADLOCK_CHECKS 0x00000800
  344. #define RTL_VRF_FLG_FIRST_CHANCE_EXCEPTION_CHECKS 0x00001000
  345. #define RTL_VRF_FLG_VIRTUAL_MEM_CHECKS 0x00002000
  346. #define RTL_VRF_FLG_ENABLE_LOGGING 0x00004000
  347. #define RTL_VRF_FLG_FAST_FILL_HEAP 0x00008000
  348. #define RTL_VRF_FLG_VIRTUAL_SPACE_TRACKING 0x00010000
  349. #define RTL_VRF_FLG_ENABLED_SYSTEM_WIDE 0x00020000
  350. #define RTL_VRF_FLG_MISCELLANEOUS_CHECKS 0x00020000
  351. #define RTL_VRF_FLG_LOCK_CHECKS 0x00040000
  352. //
  353. // Application verifier standard stop codes
  354. //
  355. #define APPLICATION_VERIFIER_INTERNAL_ERROR 0x80000000
  356. #define APPLICATION_VERIFIER_INTERNAL_WARNING 0x40000000
  357. #define APPLICATION_VERIFIER_NO_BREAK 0x20000000
  358. #define APPLICATION_VERIFIER_CONTINUABLE_BREAK 0x10000000
  359. #define APPLICATION_VERIFIER_UNKNOWN_ERROR 0x0001
  360. #define APPLICATION_VERIFIER_ACCESS_VIOLATION 0x0002
  361. #define APPLICATION_VERIFIER_UNSYNCHRONIZED_ACCESS 0x0003
  362. #define APPLICATION_VERIFIER_EXTREME_SIZE_REQUEST 0x0004
  363. #define APPLICATION_VERIFIER_BAD_HEAP_HANDLE 0x0005
  364. #define APPLICATION_VERIFIER_SWITCHED_HEAP_HANDLE 0x0006
  365. #define APPLICATION_VERIFIER_DOUBLE_FREE 0x0007
  366. #define APPLICATION_VERIFIER_CORRUPTED_HEAP_BLOCK 0x0008
  367. #define APPLICATION_VERIFIER_DESTROY_PROCESS_HEAP 0x0009
  368. #define APPLICATION_VERIFIER_UNEXPECTED_EXCEPTION 0x000A
  369. #define APPLICATION_VERIFIER_STACK_OVERFLOW 0x000B
  370. #define APPLICATION_VERIFIER_TERMINATE_THREAD_CALL 0x0100
  371. #define APPLICATION_VERIFIER_INVALID_EXIT_PROCESS_CALL 0x0101
  372. #define APPLICATION_VERIFIER_EXIT_THREAD_OWNS_LOCK 0x0200
  373. #define APPLICATION_VERIFIER_LOCK_IN_UNLOADED_DLL 0x0201
  374. #define APPLICATION_VERIFIER_LOCK_IN_FREED_HEAP 0x0202
  375. #define APPLICATION_VERIFIER_LOCK_DOUBLE_INITIALIZE 0x0203
  376. #define APPLICATION_VERIFIER_LOCK_IN_FREED_MEMORY 0x0204
  377. #define APPLICATION_VERIFIER_LOCK_CORRUPTED 0x0205
  378. #define APPLICATION_VERIFIER_LOCK_INVALID_OWNER 0x0206
  379. #define APPLICATION_VERIFIER_LOCK_INVALID_RECURSION_COUNT 0x0207
  380. #define APPLICATION_VERIFIER_LOCK_INVALID_LOCK_COUNT 0x0208
  381. #define APPLICATION_VERIFIER_LOCK_OVER_RELEASED 0x0209
  382. #define APPLICATION_VERIFIER_LOCK_NOT_INITIALIZED 0x0210
  383. #define APPLICATION_VERIFIER_LOCK_ALREADY_INITIALIZED 0x0211
  384. #define APPLICATION_VERIFIER_INVALID_HANDLE 0x0300
  385. #define APPLICATION_VERIFIER_INVALID_TLS_VALUE 0x0301
  386. #define APPLICATION_VERIFIER_INCORRECT_WAIT_CALL 0x0302
  387. #define APPLICATION_VERIFIER_NULL_HANDLE 0x0303
  388. #define APPLICATION_VERIFIER_WAIT_IN_DLLMAIN 0x0304
  389. #define APPLICATION_VERIFIER_COM_ERROR 0x0400
  390. #define APPLICATION_VERIFIER_COM_API_IN_DLLMAIN 0x0401
  391. #define APPLICATION_VERIFIER_COM_UNHANDLED_EXCEPTION 0x0402
  392. #define APPLICATION_VERIFIER_COM_UNBALANCED_COINIT 0x0403
  393. #define APPLICATION_VERIFIER_COM_UNBALANCED_OLEINIT 0x0404
  394. #define APPLICATION_VERIFIER_COM_UNBALANCED_SWC 0x0405
  395. #define APPLICATION_VERIFIER_COM_NULL_DACL 0x0406
  396. #define APPLICATION_VERIFIER_COM_UNSAFE_IMPERSONATION 0x0407
  397. #define APPLICATION_VERIFIER_COM_SMUGGLED_WRAPPER 0x0408
  398. #define APPLICATION_VERIFIER_COM_SMUGGLED_PROXY 0x0409
  399. #define APPLICATION_VERIFIER_COM_CF_SUCCESS_WITH_NULL 0x040A
  400. #define APPLICATION_VERIFIER_COM_GCO_SUCCESS_WITH_NULL 0x040B
  401. #define APPLICATION_VERIFIER_COM_OBJECT_IN_FREED_MEMORY 0x040C
  402. #define APPLICATION_VERIFIER_COM_OBJECT_IN_UNLOADED_DLL 0x040D
  403. #define APPLICATION_VERIFIER_COM_VTBL_IN_FREED_MEMORY 0x040E
  404. #define APPLICATION_VERIFIER_COM_VTBL_IN_UNLOADED_DLL 0x040F
  405. #define APPLICATION_VERIFIER_COM_HOLDING_LOCKS_ON_CALL 0x0410
  406. #define APPLICATION_VERIFIER_RPC_ERROR 0x0500
  407. #define APPLICATION_VERIFIER_INVALID_FREEMEM 0x0600
  408. #define APPLICATION_VERIFIER_INVALID_ALLOCMEM 0x0601
  409. #define APPLICATION_VERIFIER_INVALID_MAPVIEW 0x0602
  410. #define APPLICATION_VERIFIER_PROBE_INVALID_ADDRESS 0x0603
  411. #define APPLICATION_VERIFIER_PROBE_FREE_MEM 0x0604
  412. #define APPLICATION_VERIFIER_PROBE_GUARD_PAGE 0x0605
  413. #define APPLICATION_VERIFIER_PROBE_NULL 0x0606
  414. #define APPLICATION_VERIFIER_PROBE_INVALID_START_OR_SIZE 0x0607
  415. #define VERIFIER_STOP(Code, Msg, P1, S1, P2, S2, P3, S3, P4, S4) { \
  416. RtlApplicationVerifierStop ((Code), \
  417. (Msg), \
  418. (ULONG_PTR)(P1),(S1), \
  419. (ULONG_PTR)(P2),(S2), \
  420. (ULONG_PTR)(P3),(S3), \
  421. (ULONG_PTR)(P4),(S4)); \
  422. }
  423. VOID
  424. NTAPI
  425. RtlApplicationVerifierStop (
  426. ULONG_PTR Code,
  427. PCHAR Message,
  428. ULONG_PTR Param1, PCHAR Description1,
  429. ULONG_PTR Param2, PCHAR Description2,
  430. ULONG_PTR Param3, PCHAR Description3,
  431. ULONG_PTR Param4, PCHAR Description4
  432. );
  433. // end_winnt
  434. //
  435. // VectoredExceptionHandler Stuff
  436. //
  437. // begin_winnt
  438. typedef LONG (NTAPI *PVECTORED_EXCEPTION_HANDLER)(
  439. struct _EXCEPTION_POINTERS *ExceptionInfo
  440. );
  441. // end_winnt
  442. NTSYSAPI
  443. BOOLEAN
  444. NTAPI
  445. RtlCallVectoredExceptionHandlers(
  446. IN PEXCEPTION_RECORD ExceptionRecord,
  447. IN PCONTEXT ContextRecord
  448. );
  449. NTSYSAPI
  450. PVOID
  451. NTAPI
  452. RtlAddVectoredExceptionHandler(
  453. IN ULONG FirstHandler,
  454. IN PVECTORED_EXCEPTION_HANDLER VectoredHandler
  455. );
  456. NTSYSAPI
  457. ULONG
  458. NTAPI
  459. RtlRemoveVectoredExceptionHandler(
  460. IN PVOID VectoredHandlerHandle
  461. );
  462. //
  463. // Current Directory Stuff
  464. //
  465. typedef struct _RTLP_CURDIR_REF *PRTLP_CURDIR_REF;
  466. typedef struct _RTL_RELATIVE_NAME_U {
  467. UNICODE_STRING RelativeName;
  468. HANDLE ContainingDirectory;
  469. PRTLP_CURDIR_REF CurDirRef;
  470. } RTL_RELATIVE_NAME_U, *PRTL_RELATIVE_NAME_U;
  471. typedef enum _RTL_PATH_TYPE {
  472. RtlPathTypeUnknown, // 0
  473. RtlPathTypeUncAbsolute, // 1
  474. RtlPathTypeDriveAbsolute, // 2
  475. RtlPathTypeDriveRelative, // 3
  476. RtlPathTypeRooted, // 4
  477. RtlPathTypeRelative, // 5
  478. RtlPathTypeLocalDevice, // 6
  479. RtlPathTypeRootLocalDevice // 7
  480. } RTL_PATH_TYPE;
  481. NTSYSAPI
  482. RTL_PATH_TYPE
  483. NTAPI
  484. RtlDetermineDosPathNameType_U(
  485. PCWSTR DosFileName
  486. );
  487. RTL_PATH_TYPE
  488. NTAPI
  489. RtlDetermineDosPathNameType_Ustr(
  490. IN PCUNICODE_STRING String
  491. );
  492. NTSYSAPI
  493. ULONG
  494. NTAPI
  495. RtlIsDosDeviceName_U(
  496. PCWSTR DosFileName
  497. );
  498. NTSYSAPI
  499. ULONG
  500. NTAPI
  501. RtlGetFullPathName_U(
  502. PCWSTR lpFileName,
  503. ULONG nBufferLength,
  504. PWSTR lpBuffer,
  505. PWSTR *lpFilePart
  506. );
  507. NTSYSAPI
  508. NTSTATUS
  509. NTAPI
  510. RtlGetFullPathName_UstrEx(
  511. PCUNICODE_STRING FileName,
  512. PUNICODE_STRING StaticString,
  513. PUNICODE_STRING DynamicString,
  514. PUNICODE_STRING *StringUsed,
  515. SIZE_T *FilePartPrefixCch OPTIONAL,
  516. PBOOLEAN NameInvalid,
  517. RTL_PATH_TYPE *InputPathType,
  518. OUT SIZE_T *BytesRequired OPTIONAL
  519. );
  520. NTSYSAPI
  521. ULONG
  522. NTAPI
  523. RtlGetCurrentDirectory_U(
  524. ULONG nBufferLength,
  525. PWSTR lpBuffer
  526. );
  527. NTSYSAPI
  528. NTSTATUS
  529. NTAPI
  530. RtlSetCurrentDirectory_U(
  531. IN PCUNICODE_STRING PathName
  532. );
  533. NTSYSAPI
  534. ULONG
  535. NTAPI
  536. RtlGetLongestNtPathLength( VOID );
  537. NTSYSAPI
  538. BOOLEAN
  539. NTAPI
  540. RtlDosPathNameToNtPathName_U(
  541. PCWSTR DosFileName,
  542. PUNICODE_STRING NtFileName,
  543. PWSTR *FilePart OPTIONAL,
  544. PVOID Reserved // Must be NULL
  545. );
  546. NTSYSAPI
  547. BOOLEAN
  548. NTAPI
  549. RtlDosPathNameToRelativeNtPathName_U(
  550. PCWSTR DosFileName,
  551. PUNICODE_STRING NtFileName,
  552. PWSTR *FilePart OPTIONAL,
  553. PRTL_RELATIVE_NAME_U RelativeName OPTIONAL
  554. );
  555. NTSYSAPI
  556. VOID
  557. NTAPI
  558. RtlReleaseRelativeName(
  559. IN PRTL_RELATIVE_NAME_U RelativeName
  560. );
  561. NTSYSAPI
  562. ULONG
  563. NTAPI
  564. RtlDosSearchPath_U(
  565. IN PCWSTR lpPath,
  566. IN PCWSTR lpFileName,
  567. IN PCWSTR lpExtension,
  568. ULONG nBufferLength,
  569. PWSTR lpBuffer,
  570. PWSTR *lpFilePart
  571. );
  572. #define RTL_DOS_SEARCH_PATH_FLAG_APPLY_ISOLATION_REDIRECTION (0x00000001)
  573. // Flags to preserve Win32 SearchPathW() semantics in the ntdll implementation:
  574. #define RTL_DOS_SEARCH_PATH_FLAG_DISALLOW_DOT_RELATIVE_PATH_SEARCH (0x00000002)
  575. #define RTL_DOS_SEARCH_PATH_FLAG_APPLY_DEFAULT_EXTENSION_WHEN_NOT_RELATIVE_PATH_EVEN_IF_FILE_HAS_EXTENSION (0x00000004)
  576. NTSYSAPI
  577. NTSTATUS
  578. NTAPI
  579. RtlDosSearchPath_Ustr(
  580. IN ULONG Flags,
  581. IN PCUNICODE_STRING Path,
  582. IN PCUNICODE_STRING FileName,
  583. IN PCUNICODE_STRING DefaultExtension OPTIONAL,
  584. OUT PUNICODE_STRING StaticString OPTIONAL,
  585. OUT PUNICODE_STRING DynamicString OPTIONAL,
  586. OUT PCUNICODE_STRING *FullFileNameOut OPTIONAL,
  587. OUT SIZE_T *FilePartPrefixCch OPTIONAL,
  588. OUT SIZE_T *BytesRequired OPTIONAL
  589. );
  590. NTSYSAPI
  591. BOOLEAN
  592. NTAPI
  593. RtlDoesFileExists_U(
  594. PCWSTR FileName
  595. );
  596. // input flags
  597. #define RTL_DOS_APPLY_FILE_REDIRECTION_USTR_FLAG_RESPECT_DOT_LOCAL (1)
  598. // output flags
  599. #define RTL_DOS_APPLY_FILE_REDIRECTION_USTR_OUTFLAG_DOT_LOCAL_REDIRECT (1)
  600. #define RTL_DOS_APPLY_FILE_REDIRECTION_USTR_OUTFLAG_ACTCTX_REDIRECT (2)
  601. NTSYSAPI
  602. NTSTATUS
  603. NTAPI
  604. RtlDosApplyFileIsolationRedirection_Ustr(
  605. IN ULONG Flags,
  606. IN PCUNICODE_STRING FileName,
  607. IN PCUNICODE_STRING DefaultExtension OPTIONAL,
  608. IN PUNICODE_STRING PreAllocatedString OPTIONAL,
  609. OUT PUNICODE_STRING DynamicallyAllocatedString OPTIONAL,
  610. OUT PUNICODE_STRING *FullPath OPTIONAL,
  611. OUT ULONG * OutFlags,
  612. OUT SIZE_T *FilePartPrefixCch OPTIONAL,
  613. OUT SIZE_T *BytesRequired OPTIONAL
  614. );
  615. NTSYSAPI
  616. NTSTATUS
  617. NTAPI
  618. RtlComputePrivatizedDllName_U(
  619. IN PCUNICODE_STRING DllName,
  620. IN OUT PUNICODE_STRING NewDllNameUnderImageDir,
  621. IN OUT PUNICODE_STRING NewDllNameUnderLocalDir
  622. );
  623. NTSYSAPI
  624. NTSTATUS
  625. NTAPI
  626. RtlInitializeProfile (
  627. BOOLEAN KernelToo
  628. );
  629. NTSYSAPI
  630. NTSTATUS
  631. NTAPI
  632. RtlStartProfile (
  633. VOID
  634. );
  635. NTSYSAPI
  636. NTSTATUS
  637. NTAPI
  638. RtlStopProfile (
  639. VOID
  640. );
  641. NTSYSAPI
  642. NTSTATUS
  643. NTAPI
  644. RtlAnalyzeProfile (
  645. VOID
  646. );
  647. //
  648. // User mode only security Rtl routines
  649. //
  650. //
  651. // Structure to hold information about an ACE to be created
  652. //
  653. #ifdef _MAC
  654. #pragma warning( disable : 4121)
  655. #endif
  656. typedef struct {
  657. UCHAR AceType;
  658. UCHAR InheritFlags;
  659. UCHAR AceFlags;
  660. ACCESS_MASK Mask;
  661. PSID *Sid;
  662. } RTL_ACE_DATA, *PRTL_ACE_DATA;
  663. #ifdef _MAC
  664. #pragma warning( default : 4121 )
  665. #endif
  666. NTSYSAPI
  667. NTSTATUS
  668. NTAPI
  669. RtlNewSecurityObject(
  670. PSECURITY_DESCRIPTOR ParentDescriptor,
  671. PSECURITY_DESCRIPTOR CreatorDescriptor,
  672. PSECURITY_DESCRIPTOR * NewDescriptor,
  673. BOOLEAN IsDirectoryObject,
  674. HANDLE Token,
  675. PGENERIC_MAPPING GenericMapping
  676. );
  677. NTSYSAPI
  678. NTSTATUS
  679. NTAPI
  680. RtlNewSecurityObjectEx (
  681. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  682. IN PSECURITY_DESCRIPTOR CreatorDescriptor OPTIONAL,
  683. OUT PSECURITY_DESCRIPTOR * NewDescriptor,
  684. IN GUID *ObjectType OPTIONAL,
  685. IN BOOLEAN IsDirectoryObject,
  686. IN ULONG AutoInheritFlags,
  687. IN HANDLE Token,
  688. IN PGENERIC_MAPPING GenericMapping
  689. );
  690. NTSYSAPI
  691. NTSTATUS
  692. NTAPI
  693. RtlNewSecurityObjectWithMultipleInheritance (
  694. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  695. IN PSECURITY_DESCRIPTOR CreatorDescriptor OPTIONAL,
  696. OUT PSECURITY_DESCRIPTOR * NewDescriptor,
  697. IN GUID **pObjectType OPTIONAL,
  698. IN ULONG GuidCount,
  699. IN BOOLEAN IsDirectoryObject,
  700. IN ULONG AutoInheritFlags,
  701. IN HANDLE Token,
  702. IN PGENERIC_MAPPING GenericMapping
  703. );
  704. // Values for AutoInheritFlags
  705. // begin_winnt
  706. #define SEF_DACL_AUTO_INHERIT 0x01
  707. #define SEF_SACL_AUTO_INHERIT 0x02
  708. #define SEF_DEFAULT_DESCRIPTOR_FOR_OBJECT 0x04
  709. #define SEF_AVOID_PRIVILEGE_CHECK 0x08
  710. #define SEF_AVOID_OWNER_CHECK 0x10
  711. #define SEF_DEFAULT_OWNER_FROM_PARENT 0x20
  712. #define SEF_DEFAULT_GROUP_FROM_PARENT 0x40
  713. // end_winnt
  714. NTSTATUS
  715. NTAPI
  716. RtlConvertToAutoInheritSecurityObject(
  717. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  718. IN PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,
  719. OUT PSECURITY_DESCRIPTOR *NewSecurityDescriptor,
  720. IN GUID *ObjectType OPTIONAL,
  721. IN BOOLEAN IsDirectoryObject,
  722. IN PGENERIC_MAPPING GenericMapping
  723. );
  724. NTSYSAPI
  725. NTSTATUS
  726. NTAPI
  727. RtlSetSecurityObject (
  728. SECURITY_INFORMATION SecurityInformation,
  729. PSECURITY_DESCRIPTOR ModificationDescriptor,
  730. PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  731. PGENERIC_MAPPING GenericMapping,
  732. HANDLE Token
  733. );
  734. NTSYSAPI
  735. NTSTATUS
  736. NTAPI
  737. RtlSetSecurityObjectEx (
  738. IN SECURITY_INFORMATION SecurityInformation,
  739. IN PSECURITY_DESCRIPTOR ModificationDescriptor,
  740. IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
  741. IN ULONG AutoInheritFlags,
  742. IN PGENERIC_MAPPING GenericMapping,
  743. IN HANDLE Token OPTIONAL
  744. );
  745. NTSYSAPI
  746. NTSTATUS
  747. NTAPI
  748. RtlQuerySecurityObject (
  749. PSECURITY_DESCRIPTOR ObjectDescriptor,
  750. SECURITY_INFORMATION SecurityInformation,
  751. PSECURITY_DESCRIPTOR ResultantDescriptor,
  752. ULONG DescriptorLength,
  753. PULONG ReturnLength
  754. );
  755. NTSYSAPI
  756. NTSTATUS
  757. NTAPI
  758. RtlDeleteSecurityObject (
  759. PSECURITY_DESCRIPTOR * ObjectDescriptor
  760. );
  761. NTSYSAPI
  762. NTSTATUS
  763. NTAPI
  764. RtlNewInstanceSecurityObject(
  765. BOOLEAN ParentDescriptorChanged,
  766. BOOLEAN CreatorDescriptorChanged,
  767. PLUID OldClientTokenModifiedId,
  768. PLUID NewClientTokenModifiedId,
  769. PSECURITY_DESCRIPTOR ParentDescriptor,
  770. PSECURITY_DESCRIPTOR CreatorDescriptor,
  771. PSECURITY_DESCRIPTOR * NewDescriptor,
  772. BOOLEAN IsDirectoryObject,
  773. HANDLE Token,
  774. PGENERIC_MAPPING GenericMapping
  775. );
  776. NTSYSAPI
  777. NTSTATUS
  778. NTAPI
  779. RtlCopySecurityDescriptor(
  780. PSECURITY_DESCRIPTOR InputSecurityDescriptor,
  781. PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
  782. );
  783. //
  784. // list canonicalization
  785. //
  786. NTSYSAPI
  787. NTSTATUS
  788. NTAPI
  789. RtlConvertUiListToApiList(
  790. PUNICODE_STRING UiList OPTIONAL,
  791. PUNICODE_STRING ApiList,
  792. BOOLEAN BlankIsDelimiter
  793. );
  794. NTSYSAPI
  795. NTSTATUS
  796. NTAPI
  797. RtlCreateAndSetSD(
  798. IN PRTL_ACE_DATA AceData,
  799. IN ULONG AceCount,
  800. IN PSID OwnerSid OPTIONAL,
  801. IN PSID GroupSid OPTIONAL,
  802. OUT PSECURITY_DESCRIPTOR *NewDescriptor
  803. );
  804. NTSYSAPI
  805. NTSTATUS
  806. NTAPI
  807. RtlCreateUserSecurityObject(
  808. IN PRTL_ACE_DATA AceData,
  809. IN ULONG AceCount,
  810. IN PSID OwnerSid,
  811. IN PSID GroupSid,
  812. IN BOOLEAN IsDirectoryObject,
  813. IN PGENERIC_MAPPING GenericMapping,
  814. OUT PSECURITY_DESCRIPTOR *NewDescriptor
  815. );
  816. NTSYSAPI
  817. NTSTATUS
  818. NTAPI
  819. RtlDefaultNpAcl(
  820. OUT PACL * pAcl
  821. );
  822. //
  823. // Per-Thread Curdir Support
  824. //
  825. typedef struct _RTL_PERTHREAD_CURDIR {
  826. PRTL_DRIVE_LETTER_CURDIR CurrentDirectories;
  827. PUNICODE_STRING ImageName;
  828. PVOID Environment;
  829. } RTL_PERTHREAD_CURDIR, *PRTL_PERTHREAD_CURDIR;
  830. #define RtlAssociatePerThreadCurdir(BLOCK,CURRENTDIRECTORIES,IMAGENAME,ENVIRONMENT)\
  831. (BLOCK)->CurrentDirectories = (CURRENTDIRECTORIES); \
  832. (BLOCK)->ImageName = (IMAGENAME); \
  833. (BLOCK)->Environment = (ENVIRONMENT); \
  834. NtCurrentTeb()->NtTib.SubSystemTib = (PVOID)(BLOCK) \
  835. #define RtlDisAssociatePerThreadCurdir() \
  836. NtCurrentTeb()->NtTib.SubSystemTib = NULL;
  837. #define RtlGetPerThreadCurdir() \
  838. ((PRTL_PERTHREAD_CURDIR)(NtCurrentTeb()->NtTib.SubSystemTib))
  839. //
  840. // See NTRTL.H for heap functions availble to both kernel and user mode code.
  841. //
  842. #define RtlProcessHeap() (NtCurrentPeb()->ProcessHeap)
  843. NTSYSAPI
  844. BOOLEAN
  845. NTAPI
  846. RtlLockHeap(
  847. IN PVOID HeapHandle
  848. );
  849. NTSYSAPI
  850. BOOLEAN
  851. NTAPI
  852. RtlUnlockHeap(
  853. IN PVOID HeapHandle
  854. );
  855. NTSYSAPI
  856. PVOID
  857. NTAPI
  858. RtlReAllocateHeap(
  859. IN PVOID HeapHandle,
  860. IN ULONG Flags,
  861. IN PVOID BaseAddress,
  862. IN SIZE_T Size
  863. );
  864. NTSYSAPI
  865. BOOLEAN
  866. NTAPI
  867. RtlGetUserInfoHeap(
  868. IN PVOID HeapHandle,
  869. IN ULONG Flags,
  870. IN PVOID BaseAddress,
  871. OUT PVOID *UserValue OPTIONAL,
  872. OUT PULONG UserFlags OPTIONAL
  873. );
  874. NTSYSAPI
  875. BOOLEAN
  876. NTAPI
  877. RtlSetUserValueHeap(
  878. IN PVOID HeapHandle,
  879. IN ULONG Flags,
  880. IN PVOID BaseAddress,
  881. IN PVOID UserValue
  882. );
  883. NTSYSAPI
  884. BOOLEAN
  885. NTAPI
  886. RtlSetUserFlagsHeap(
  887. IN PVOID HeapHandle,
  888. IN ULONG Flags,
  889. IN PVOID BaseAddress,
  890. IN ULONG UserFlagsReset,
  891. IN ULONG UserFlagsSet
  892. );
  893. typedef struct _RTL_HEAP_TAG_INFO {
  894. ULONG NumberOfAllocations;
  895. ULONG NumberOfFrees;
  896. SIZE_T BytesAllocated;
  897. } RTL_HEAP_TAG_INFO, *PRTL_HEAP_TAG_INFO;
  898. NTSYSAPI
  899. ULONG
  900. NTAPI
  901. RtlCreateTagHeap(
  902. IN PVOID HeapHandle,
  903. IN ULONG Flags,
  904. IN PWSTR TagPrefix OPTIONAL,
  905. IN PWSTR TagNames
  906. );
  907. #define RTL_HEAP_MAKE_TAG HEAP_MAKE_TAG_FLAGS
  908. NTSYSAPI
  909. PWSTR
  910. NTAPI
  911. RtlQueryTagHeap(
  912. IN PVOID HeapHandle,
  913. IN ULONG Flags,
  914. IN USHORT TagIndex,
  915. IN BOOLEAN ResetCounters,
  916. OUT PRTL_HEAP_TAG_INFO TagInfo OPTIONAL
  917. );
  918. NTSYSAPI
  919. NTSTATUS
  920. NTAPI
  921. RtlExtendHeap(
  922. IN PVOID HeapHandle,
  923. IN ULONG Flags,
  924. IN PVOID Base,
  925. IN SIZE_T Size
  926. );
  927. NTSYSAPI
  928. SIZE_T
  929. NTAPI
  930. RtlCompactHeap(
  931. IN PVOID HeapHandle,
  932. IN ULONG Flags
  933. );
  934. NTSYSAPI
  935. BOOLEAN
  936. NTAPI
  937. RtlValidateHeap(
  938. IN PVOID HeapHandle,
  939. IN ULONG Flags,
  940. IN PVOID BaseAddress
  941. );
  942. NTSYSAPI
  943. BOOLEAN
  944. NTAPI
  945. RtlValidateProcessHeaps( VOID );
  946. NTSYSAPI
  947. ULONG
  948. NTAPI
  949. RtlGetProcessHeaps(
  950. ULONG NumberOfHeaps,
  951. PVOID *ProcessHeaps
  952. );
  953. typedef
  954. NTSTATUS (NTAPI * PRTL_ENUM_HEAPS_ROUTINE)(
  955. PVOID HeapHandle,
  956. PVOID Parameter
  957. );
  958. NTSYSAPI
  959. NTSTATUS
  960. NTAPI
  961. RtlEnumProcessHeaps(
  962. PRTL_ENUM_HEAPS_ROUTINE EnumRoutine,
  963. PVOID Parameter
  964. );
  965. typedef struct _RTL_HEAP_USAGE_ENTRY {
  966. struct _RTL_HEAP_USAGE_ENTRY *Next;
  967. PVOID Address;
  968. SIZE_T Size;
  969. USHORT AllocatorBackTraceIndex;
  970. USHORT TagIndex;
  971. } RTL_HEAP_USAGE_ENTRY, *PRTL_HEAP_USAGE_ENTRY;
  972. typedef struct _RTL_HEAP_USAGE {
  973. ULONG Length;
  974. SIZE_T BytesAllocated;
  975. SIZE_T BytesCommitted;
  976. SIZE_T BytesReserved;
  977. SIZE_T BytesReservedMaximum;
  978. PRTL_HEAP_USAGE_ENTRY Entries;
  979. PRTL_HEAP_USAGE_ENTRY AddedEntries;
  980. PRTL_HEAP_USAGE_ENTRY RemovedEntries;
  981. ULONG_PTR Reserved[ 8 ];
  982. } RTL_HEAP_USAGE, *PRTL_HEAP_USAGE;
  983. #define HEAP_USAGE_ALLOCATED_BLOCKS HEAP_REALLOC_IN_PLACE_ONLY
  984. #define HEAP_USAGE_FREE_BUFFER HEAP_ZERO_MEMORY
  985. NTSYSAPI
  986. NTSTATUS
  987. NTAPI
  988. RtlUsageHeap(
  989. IN PVOID HeapHandle,
  990. IN ULONG Flags,
  991. IN OUT PRTL_HEAP_USAGE Usage
  992. );
  993. typedef struct _RTL_HEAP_WALK_ENTRY {
  994. PVOID DataAddress;
  995. SIZE_T DataSize;
  996. UCHAR OverheadBytes;
  997. UCHAR SegmentIndex;
  998. USHORT Flags;
  999. union {
  1000. struct {
  1001. SIZE_T Settable;
  1002. USHORT TagIndex;
  1003. USHORT AllocatorBackTraceIndex;
  1004. ULONG Reserved[ 2 ];
  1005. } Block;
  1006. struct {
  1007. ULONG CommittedSize;
  1008. ULONG UnCommittedSize;
  1009. PVOID FirstEntry;
  1010. PVOID LastEntry;
  1011. } Segment;
  1012. };
  1013. } RTL_HEAP_WALK_ENTRY, *PRTL_HEAP_WALK_ENTRY;
  1014. NTSYSAPI
  1015. NTSTATUS
  1016. NTAPI
  1017. RtlWalkHeap(
  1018. IN PVOID HeapHandle,
  1019. IN OUT PRTL_HEAP_WALK_ENTRY Entry
  1020. );
  1021. typedef struct _RTL_HEAP_ENTRY {
  1022. SIZE_T Size;
  1023. USHORT Flags;
  1024. USHORT AllocatorBackTraceIndex;
  1025. union {
  1026. struct {
  1027. SIZE_T Settable;
  1028. ULONG Tag;
  1029. } s1; // All other heap entries
  1030. struct {
  1031. SIZE_T CommittedSize;
  1032. PVOID FirstBlock;
  1033. } s2; // RTL_SEGMENT
  1034. } u;
  1035. } RTL_HEAP_ENTRY, *PRTL_HEAP_ENTRY;
  1036. #define RTL_HEAP_BUSY (USHORT)0x0001
  1037. #define RTL_HEAP_SEGMENT (USHORT)0x0002
  1038. #define RTL_HEAP_SETTABLE_VALUE (USHORT)0x0010
  1039. #define RTL_HEAP_SETTABLE_FLAG1 (USHORT)0x0020
  1040. #define RTL_HEAP_SETTABLE_FLAG2 (USHORT)0x0040
  1041. #define RTL_HEAP_SETTABLE_FLAG3 (USHORT)0x0080
  1042. #define RTL_HEAP_SETTABLE_FLAGS (USHORT)0x00E0
  1043. #define RTL_HEAP_UNCOMMITTED_RANGE (USHORT)0x0100
  1044. #define RTL_HEAP_PROTECTED_ENTRY (USHORT)0x0200
  1045. typedef struct _RTL_HEAP_TAG {
  1046. ULONG NumberOfAllocations;
  1047. ULONG NumberOfFrees;
  1048. SIZE_T BytesAllocated;
  1049. USHORT TagIndex;
  1050. USHORT CreatorBackTraceIndex;
  1051. WCHAR TagName[ 24 ];
  1052. } RTL_HEAP_TAG, *PRTL_HEAP_TAG;
  1053. typedef struct _RTL_HEAP_INFORMATION {
  1054. PVOID BaseAddress;
  1055. ULONG Flags;
  1056. USHORT EntryOverhead;
  1057. USHORT CreatorBackTraceIndex;
  1058. SIZE_T BytesAllocated;
  1059. SIZE_T BytesCommitted;
  1060. ULONG NumberOfTags;
  1061. ULONG NumberOfEntries;
  1062. ULONG NumberOfPseudoTags;
  1063. ULONG PseudoTagGranularity;
  1064. ULONG Reserved[ 5 ];
  1065. PRTL_HEAP_TAG Tags;
  1066. PRTL_HEAP_ENTRY Entries;
  1067. } RTL_HEAP_INFORMATION, *PRTL_HEAP_INFORMATION;
  1068. typedef struct _RTL_PROCESS_HEAPS {
  1069. ULONG NumberOfHeaps;
  1070. RTL_HEAP_INFORMATION Heaps[ 1 ];
  1071. } RTL_PROCESS_HEAPS, *PRTL_PROCESS_HEAPS;
  1072. //
  1073. // Heap Information APIs & data definitions
  1074. //
  1075. // begin_winnt
  1076. typedef enum _HEAP_INFORMATION_CLASS {
  1077. HeapCompatibilityInformation
  1078. } HEAP_INFORMATION_CLASS;
  1079. NTSTATUS
  1080. NTAPI
  1081. RtlSetHeapInformation (
  1082. IN PVOID HeapHandle,
  1083. IN HEAP_INFORMATION_CLASS HeapInformationClass,
  1084. IN PVOID HeapInformation OPTIONAL,
  1085. IN SIZE_T HeapInformationLength OPTIONAL
  1086. );
  1087. NTSTATUS
  1088. NTAPI
  1089. RtlQueryHeapInformation (
  1090. IN PVOID HeapHandle,
  1091. IN HEAP_INFORMATION_CLASS HeapInformationClass,
  1092. OUT PVOID HeapInformation OPTIONAL,
  1093. IN SIZE_T HeapInformationLength OPTIONAL,
  1094. OUT PSIZE_T ReturnLength OPTIONAL
  1095. );
  1096. //
  1097. // Multiple alloc-free APIS
  1098. //
  1099. ULONG
  1100. NTAPI
  1101. RtlMultipleAllocateHeap (
  1102. IN PVOID HeapHandle,
  1103. IN ULONG Flags,
  1104. IN SIZE_T Size,
  1105. IN ULONG Count,
  1106. OUT PVOID * Array
  1107. );
  1108. ULONG
  1109. NTAPI
  1110. RtlMultipleFreeHeap (
  1111. IN PVOID HeapHandle,
  1112. IN ULONG Flags,
  1113. IN ULONG Count,
  1114. OUT PVOID * Array
  1115. );
  1116. // end_winnt
  1117. //
  1118. // Debugging support
  1119. //
  1120. typedef struct _RTL_DEBUG_INFORMATION {
  1121. HANDLE SectionHandleClient;
  1122. PVOID ViewBaseClient;
  1123. PVOID ViewBaseTarget;
  1124. ULONG_PTR ViewBaseDelta;
  1125. HANDLE EventPairClient;
  1126. HANDLE EventPairTarget;
  1127. HANDLE TargetProcessId;
  1128. HANDLE TargetThreadHandle;
  1129. ULONG Flags;
  1130. SIZE_T OffsetFree;
  1131. SIZE_T CommitSize;
  1132. SIZE_T ViewSize;
  1133. PRTL_PROCESS_MODULES Modules;
  1134. PRTL_PROCESS_BACKTRACES BackTraces;
  1135. PRTL_PROCESS_HEAPS Heaps;
  1136. PRTL_PROCESS_LOCKS Locks;
  1137. PVOID SpecificHeap;
  1138. HANDLE TargetProcessHandle;
  1139. PVOID Reserved[ 6 ];
  1140. } RTL_DEBUG_INFORMATION, *PRTL_DEBUG_INFORMATION;
  1141. NTSYSAPI
  1142. PRTL_DEBUG_INFORMATION
  1143. NTAPI
  1144. RtlCreateQueryDebugBuffer(
  1145. IN ULONG MaximumCommit OPTIONAL,
  1146. IN BOOLEAN UseEventPair
  1147. );
  1148. NTSYSAPI
  1149. NTSTATUS
  1150. NTAPI
  1151. RtlDestroyQueryDebugBuffer(
  1152. IN PRTL_DEBUG_INFORMATION Buffer
  1153. );
  1154. NTSYSAPI
  1155. NTSTATUS
  1156. NTAPI
  1157. RtlQueryProcessDebugInformation(
  1158. IN HANDLE UniqueProcessId,
  1159. IN ULONG Flags,
  1160. IN OUT PRTL_DEBUG_INFORMATION Buffer
  1161. );
  1162. #define RTL_QUERY_PROCESS_MODULES 0x00000001
  1163. #define RTL_QUERY_PROCESS_BACKTRACES 0x00000002
  1164. #define RTL_QUERY_PROCESS_HEAP_SUMMARY 0x00000004
  1165. #define RTL_QUERY_PROCESS_HEAP_TAGS 0x00000008
  1166. #define RTL_QUERY_PROCESS_HEAP_ENTRIES 0x00000010
  1167. #define RTL_QUERY_PROCESS_LOCKS 0x00000020
  1168. #define RTL_QUERY_PROCESS_MODULES32 0x00000040
  1169. #define RTL_QUERY_PROCESS_NONINVASIVE 0x80000000
  1170. NTSTATUS
  1171. NTAPI
  1172. RtlQueryProcessModuleInformation(
  1173. IN HANDLE hProcess OPTIONAL,
  1174. IN ULONG Flags,
  1175. IN OUT PRTL_DEBUG_INFORMATION Buffer
  1176. );
  1177. NTSYSAPI
  1178. NTSTATUS
  1179. NTAPI
  1180. RtlQueryProcessBackTraceInformation(
  1181. IN OUT PRTL_DEBUG_INFORMATION Buffer
  1182. );
  1183. NTSYSAPI
  1184. NTSTATUS
  1185. NTAPI
  1186. RtlQueryProcessHeapInformation(
  1187. IN OUT PRTL_DEBUG_INFORMATION Buffer
  1188. );
  1189. NTSYSAPI
  1190. NTSTATUS
  1191. NTAPI
  1192. RtlQueryProcessLockInformation(
  1193. IN OUT PRTL_DEBUG_INFORMATION Buffer
  1194. );
  1195. //
  1196. // Routines for manipulating user mode handle tables. Used for Atoms
  1197. // and Local/Global memory allocations.
  1198. //
  1199. typedef struct _RTL_HANDLE_TABLE_ENTRY {
  1200. union {
  1201. ULONG Flags; // Allocated entries have low bit set
  1202. struct _RTL_HANDLE_TABLE_ENTRY *NextFree; // Free entries use this word for free list
  1203. };
  1204. } RTL_HANDLE_TABLE_ENTRY, *PRTL_HANDLE_TABLE_ENTRY;
  1205. #define RTL_HANDLE_ALLOCATED (USHORT)0x0001
  1206. typedef struct _RTL_HANDLE_TABLE {
  1207. ULONG MaximumNumberOfHandles;
  1208. ULONG SizeOfHandleTableEntry;
  1209. ULONG Reserved[ 2 ];
  1210. PRTL_HANDLE_TABLE_ENTRY FreeHandles;
  1211. PRTL_HANDLE_TABLE_ENTRY CommittedHandles;
  1212. PRTL_HANDLE_TABLE_ENTRY UnCommittedHandles;
  1213. PRTL_HANDLE_TABLE_ENTRY MaxReservedHandles;
  1214. } RTL_HANDLE_TABLE, *PRTL_HANDLE_TABLE;
  1215. NTSYSAPI
  1216. void
  1217. NTAPI
  1218. RtlInitializeHandleTable(
  1219. IN ULONG MaximumNumberOfHandles,
  1220. IN ULONG SizeOfHandleTableEntry,
  1221. OUT PRTL_HANDLE_TABLE HandleTable
  1222. );
  1223. NTSYSAPI
  1224. NTSTATUS
  1225. NTAPI
  1226. RtlDestroyHandleTable(
  1227. IN OUT PRTL_HANDLE_TABLE HandleTable
  1228. );
  1229. NTSYSAPI
  1230. PRTL_HANDLE_TABLE_ENTRY
  1231. NTAPI
  1232. RtlAllocateHandle(
  1233. IN PRTL_HANDLE_TABLE HandleTable,
  1234. OUT PULONG HandleIndex OPTIONAL
  1235. );
  1236. NTSYSAPI
  1237. BOOLEAN
  1238. NTAPI
  1239. RtlFreeHandle(
  1240. IN PRTL_HANDLE_TABLE HandleTable,
  1241. IN PRTL_HANDLE_TABLE_ENTRY Handle
  1242. );
  1243. NTSYSAPI
  1244. BOOLEAN
  1245. NTAPI
  1246. RtlIsValidHandle(
  1247. IN PRTL_HANDLE_TABLE HandleTable,
  1248. IN PRTL_HANDLE_TABLE_ENTRY Handle
  1249. );
  1250. NTSYSAPI
  1251. BOOLEAN
  1252. NTAPI
  1253. RtlIsValidIndexHandle(
  1254. IN PRTL_HANDLE_TABLE HandleTable,
  1255. IN ULONG HandleIndex,
  1256. OUT PRTL_HANDLE_TABLE_ENTRY *Handle
  1257. );
  1258. //
  1259. // Routines for thread pool.
  1260. //
  1261. #define WT_EXECUTEDEFAULT 0x00000000 // winnt
  1262. #define WT_EXECUTEINIOTHREAD 0x00000001 // winnt
  1263. #define WT_EXECUTEINUITHREAD 0x00000002 // winnt
  1264. #define WT_EXECUTEINWAITTHREAD 0x00000004 // winnt
  1265. #define WT_EXECUTEONLYONCE 0x00000008 // winnt
  1266. #define WT_EXECUTEINTIMERTHREAD 0x00000020 // winnt
  1267. #define WT_EXECUTELONGFUNCTION 0x00000010 // winnt
  1268. #define WT_EXECUTEINPERSISTENTIOTHREAD 0x00000040 // winnt
  1269. #define WT_EXECUTEINPERSISTENTTHREAD 0x00000080 // winnt
  1270. #define WT_TRANSFER_IMPERSONATION 0x00000100 // winnt
  1271. #define WT_SET_MAX_THREADPOOL_THREADS(Flags, Limit) ((Flags) |= (Limit)<<16) // winnt
  1272. typedef VOID (NTAPI * WAITORTIMERCALLBACKFUNC) (PVOID, BOOLEAN ); // winnt
  1273. typedef VOID (NTAPI * WORKERCALLBACKFUNC) (PVOID ); // winnt
  1274. typedef VOID (NTAPI * APC_CALLBACK_FUNCTION) (NTSTATUS, PVOID, PVOID); // winnt
  1275. typedef NTSTATUS (NTAPI RTLP_START_THREAD)(
  1276. PUSER_THREAD_START_ROUTINE,
  1277. PVOID,
  1278. HANDLE *);
  1279. typedef NTSTATUS (NTAPI RTLP_EXIT_THREAD)(
  1280. NTSTATUS );
  1281. typedef RTLP_START_THREAD * PRTLP_START_THREAD ;
  1282. typedef RTLP_EXIT_THREAD * PRTLP_EXIT_THREAD ;
  1283. NTSTATUS
  1284. NTAPI
  1285. RtlSetThreadPoolStartFunc(
  1286. PRTLP_START_THREAD StartFunc,
  1287. PRTLP_EXIT_THREAD ExitFunc
  1288. );
  1289. NTSYSAPI
  1290. NTSTATUS
  1291. NTAPI
  1292. RtlRegisterWait (
  1293. OUT PHANDLE WaitHandle,
  1294. IN HANDLE Handle,
  1295. IN WAITORTIMERCALLBACKFUNC Function,
  1296. IN PVOID Context,
  1297. IN ULONG Milliseconds,
  1298. IN ULONG Flags
  1299. ) ;
  1300. NTSYSAPI
  1301. NTSTATUS
  1302. NTAPI
  1303. RtlDeregisterWait(
  1304. IN HANDLE WaitHandle
  1305. ) ;
  1306. NTSYSAPI
  1307. NTSTATUS
  1308. NTAPI
  1309. RtlDeregisterWaitEx(
  1310. IN HANDLE WaitHandle,
  1311. IN HANDLE Event
  1312. ) ;
  1313. NTSYSAPI
  1314. NTSTATUS
  1315. NTAPI
  1316. RtlQueueWorkItem(
  1317. IN WORKERCALLBACKFUNC Function,
  1318. IN PVOID Context,
  1319. IN ULONG Flags
  1320. ) ;
  1321. NTSTATUS
  1322. NTAPI
  1323. RtlSetIoCompletionCallback (
  1324. IN HANDLE FileHandle,
  1325. IN APC_CALLBACK_FUNCTION CompletionProc,
  1326. IN ULONG Flags
  1327. ) ;
  1328. NTSYSAPI
  1329. NTSTATUS
  1330. NTAPI
  1331. RtlCreateTimerQueue(
  1332. OUT PHANDLE TimerQueueHandle
  1333. ) ;
  1334. NTSYSAPI
  1335. NTSTATUS
  1336. NTAPI
  1337. RtlCreateTimer(
  1338. IN HANDLE TimerQueueHandle,
  1339. OUT HANDLE *Handle,
  1340. IN WAITORTIMERCALLBACKFUNC Function,
  1341. IN PVOID Context,
  1342. IN ULONG DueTime,
  1343. IN ULONG Period,
  1344. IN ULONG Flags
  1345. ) ;
  1346. NTSYSAPI
  1347. NTSTATUS
  1348. NTAPI
  1349. RtlUpdateTimer(
  1350. IN HANDLE TimerQueueHandle,
  1351. IN HANDLE TimerHandle,
  1352. IN ULONG DueTime,
  1353. IN ULONG Period
  1354. ) ;
  1355. NTSYSAPI
  1356. NTSTATUS
  1357. NTAPI
  1358. RtlDeleteTimer(
  1359. IN HANDLE TimerQueueHandle,
  1360. IN HANDLE TimerToCancel,
  1361. IN HANDLE Event
  1362. ) ;
  1363. NTSYSAPI
  1364. NTSTATUS
  1365. NTAPI
  1366. RtlDeleteTimerQueue(
  1367. IN HANDLE TimerQueueHandle
  1368. ) ;
  1369. NTSYSAPI
  1370. NTSTATUS
  1371. NTAPI
  1372. RtlDeleteTimerQueueEx(
  1373. IN HANDLE TimerQueueHandle,
  1374. IN HANDLE Event
  1375. ) ;
  1376. BOOLEAN
  1377. RtlDllShutdownInProgress (
  1378. VOID
  1379. );
  1380. //--------OBSOLETE FUNCTIONS: DONT USE----------//
  1381. VOID
  1382. RtlDebugPrintTimes (
  1383. VOID
  1384. );
  1385. NTSYSAPI
  1386. NTSTATUS
  1387. NTAPI
  1388. RtlCancelTimer(
  1389. IN HANDLE TimerQueueHandle,
  1390. IN HANDLE TimerToCancel
  1391. ) ;
  1392. NTSYSAPI
  1393. NTSTATUS
  1394. NTAPI
  1395. RtlSetTimer(
  1396. IN HANDLE TimerQueueHandle,
  1397. OUT HANDLE *Handle,
  1398. IN WAITORTIMERCALLBACKFUNC Function,
  1399. IN PVOID Context,
  1400. IN ULONG DueTime,
  1401. IN ULONG Period,
  1402. IN ULONG Flags
  1403. ) ;
  1404. //todo:delete below: dont use the below flag. will be deleted
  1405. #define WT_EXECUTEINLONGTHREAD 0x00000010 // winnt
  1406. #define WT_EXECUTEDELETEWAIT 0x00000008 // winnt
  1407. //------end OBSOLUTE FUNCTIONS: DONT USE--------//
  1408. #if (defined(RTL_DECLARE_IMALLOC) && RTL_DECLARE_IMALLOC) \
  1409. || (defined(RTL_DECLARE_STREAMS) && RTL_DECLARE_STREAMS \
  1410. && defined(RTL_DECLARE_MEMORY_STREAM) && RTL_DECLARE_MEMORY_STREAM)
  1411. // Introducing the struct before the typedef works better if the
  1412. // header is enclosed in a C++ namespace.
  1413. struct IMallocVtbl; typedef struct IMallocVtbl IMallocVtbl;
  1414. #if defined(interface) // it's defined in objbase.h
  1415. interface IMalloc; typedef interface IMalloc IMalloc;
  1416. #else
  1417. struct IMalloc; typedef struct IMalloc IMalloc;
  1418. #endif
  1419. #endif
  1420. #if defined(RTL_DECLARE_IMALLOC) && RTL_DECLARE_IMALLOC
  1421. //
  1422. // IMalloc over an RtlHeap
  1423. //
  1424. struct _RTL_IMALLOC;
  1425. typedef struct _RTL_IMALLOC {
  1426. ULONG ReferenceCount;
  1427. ULONG Flags;
  1428. VOID (STDMETHODCALLTYPE* FinalRelease)(struct _RTL_HEAP_IMALLOC*);
  1429. HANDLE Heap;
  1430. ULONG HeapFlags;
  1431. } RTL_IMALLOC, *PRTL_IMALLOC;
  1432. //
  1433. // Don't use NTSYSAPI directly so you can more easily
  1434. // statically link to these functions, independently
  1435. // of how you link to the rest of ntdll.
  1436. //
  1437. #if !defined(RTL_IMALLOC_API)
  1438. #define RTL_IMALLOC_API NTSYSAPI
  1439. #endif
  1440. RTL_IMALLOC_API
  1441. HRESULT
  1442. STDMETHODCALLTYPE
  1443. RtlAllocHeapIMalloc(
  1444. PRTL_HEAP_IMALLOC HeapIMalloc
  1445. );
  1446. RTL_IMALLOC_API
  1447. PVOID
  1448. STDMETHODCALLTYPE
  1449. RtlReallocIMalloc(
  1450. PRTL_IMALLOC Malloc,
  1451. PVOID BlockOfMemory,
  1452. ULONG NumberOfBytes
  1453. );
  1454. RTL_IMALLOC_API
  1455. VOID
  1456. STDMETHODCALLTYPE
  1457. RtlFreeIMalloc(
  1458. PRTL_IMALLOC Malloc,
  1459. PVOID BlockOfMemory
  1460. );
  1461. RTL_IMALLOC_API
  1462. ULONG
  1463. STDMETHODCALLTYPE
  1464. RtlGetSizeIMalloc(
  1465. PRTL_IMALLOC Malloc,
  1466. PVOID BlockOfMemory
  1467. );
  1468. RTL_IMALLOC_API
  1469. BOOL
  1470. STDMETHODCALLTYPE
  1471. RtlDidAllocIMalloc(
  1472. PRTL_IMALLOC Malloc,
  1473. PVOID BlockOfMemory
  1474. );
  1475. RTL_IMALLOC_API
  1476. VOID
  1477. STDMETHODCALLTYPE
  1478. RtlMinimizeIMalloc(
  1479. PRTL_IMALLOC Malloc
  1480. );
  1481. RTL_IMALLOC_API
  1482. PRTL_IMALLOC
  1483. STDMETHODCALLTYPE
  1484. RtlProcessIMalloc(
  1485. VOID
  1486. );
  1487. #endif // RTL_DECLARE_MALLOC
  1488. #if defined(RTL_DECLARE_STREAMS) && RTL_DECLARE_STREAMS
  1489. // Introducing the structs before the typedefs works better if the
  1490. // header is enclosed in a C++ namespace.
  1491. struct tagSTATSTG; typedef struct tagSTATSTG STATSTG;
  1492. struct IStreamVtbl; typedef struct IStreamVtbl IStreamVtbl;
  1493. #if defined(interface) // it's defined in objbase.h
  1494. interface IStream; typedef interface IStream IStream;
  1495. #else
  1496. struct IStream; typedef struct IStream IStream;
  1497. #endif
  1498. #if defined(RTL_DECLARE_FILE_STREAM) && RTL_DECLARE_FILE_STREAM
  1499. //
  1500. // IStream over an NT File handle (not yet adapted for C++)
  1501. //
  1502. struct _RTL_FILE_STREAM;
  1503. typedef struct _RTL_FILE_STREAM
  1504. {
  1505. LONG ReferenceCount;
  1506. ULONG Flags;
  1507. VOID (STDMETHODCALLTYPE* FinalRelease)(struct _RTL_FILE_STREAM*);
  1508. HANDLE FileHandle;
  1509. } RTL_FILE_STREAM, *PRTL_FILE_STREAM;
  1510. //
  1511. // Don't use NTSYSAPI directly so you can more easily
  1512. // statically link to these functions, independently
  1513. // of how you link to the rest of ntdll.
  1514. //
  1515. #if !defined(RTL_FILE_STREAM_API)
  1516. #define RTL_FILE_STREAM_API NTSYSAPI
  1517. #endif
  1518. RTL_FILE_STREAM_API
  1519. HRESULT
  1520. STDMETHODCALLTYPE
  1521. RtlInitFileStream(
  1522. PRTL_FILE_STREAM FileStream
  1523. );
  1524. RTL_FILE_STREAM_API
  1525. HRESULT
  1526. STDMETHODCALLTYPE
  1527. RtlCloseFileStream(
  1528. PRTL_FILE_STREAM FileStream
  1529. );
  1530. RTL_FILE_STREAM_API
  1531. ULONG
  1532. STDMETHODCALLTYPE
  1533. RtlAddRefFileStream(
  1534. PRTL_FILE_STREAM FileStream
  1535. );
  1536. RTL_FILE_STREAM_API
  1537. ULONG
  1538. STDMETHODCALLTYPE
  1539. RtlReleaseFileStream(
  1540. PRTL_FILE_STREAM FileStream
  1541. );
  1542. RTL_FILE_STREAM_API
  1543. HRESULT
  1544. STDMETHODCALLTYPE
  1545. RtlQueryFileStreamInterface(
  1546. IStream* Functions,
  1547. PRTL_FILE_STREAM Data,
  1548. const IID* Interface,
  1549. PVOID* Object
  1550. );
  1551. RTL_FILE_STREAM_API
  1552. HRESULT
  1553. STDMETHODCALLTYPE
  1554. RtlReadFileStream(
  1555. PRTL_FILE_STREAM FileStream,
  1556. PVOID Buffer,
  1557. ULONG BytesToRead,
  1558. ULONG* BytesRead
  1559. );
  1560. RTL_FILE_STREAM_API
  1561. HRESULT
  1562. STDMETHODCALLTYPE
  1563. RtlWriteFileStream(
  1564. PRTL_FILE_STREAM FileStream,
  1565. const VOID* Buffer,
  1566. ULONG BytesToWrite,
  1567. ULONG* BytesWritten
  1568. );
  1569. RTL_FILE_STREAM_API
  1570. HRESULT
  1571. STDMETHODCALLTYPE
  1572. RtlSeekFileStream(
  1573. PRTL_FILE_STREAM FileStream,
  1574. LARGE_INTEGER Distance,
  1575. ULONG Origin,
  1576. ULARGE_INTEGER* NewPosition
  1577. );
  1578. /* returns E_NOTIMPL */
  1579. RTL_FILE_STREAM_API
  1580. HRESULT
  1581. STDMETHODCALLTYPE
  1582. RtlSetFileStreamSize(
  1583. PRTL_FILE_STREAM FileStream,
  1584. ULARGE_INTEGER NewSize
  1585. );
  1586. /* returns E_NOTIMPL */
  1587. RTL_FILE_STREAM_API
  1588. HRESULT
  1589. STDMETHODCALLTYPE
  1590. RtlCopyFileStreamTo(
  1591. PRTL_FILE_STREAM FileStream,
  1592. IStream* AnotherStream,
  1593. ULARGE_INTEGER NumberOfBytesToCopy,
  1594. ULARGE_INTEGER* NumberOfBytesRead,
  1595. ULARGE_INTEGER* NumberOfBytesWritten
  1596. );
  1597. /* returns E_NOTIMPL */
  1598. RTL_FILE_STREAM_API
  1599. HRESULT
  1600. STDMETHODCALLTYPE
  1601. RtlCommitFileStream(
  1602. PRTL_FILE_STREAM FileStream,
  1603. ULONG Flags
  1604. );
  1605. /* returns E_NOTIMPL */
  1606. RTL_FILE_STREAM_API
  1607. HRESULT
  1608. STDMETHODCALLTYPE
  1609. RtlRevertFileStream(
  1610. PRTL_FILE_STREAM FileStream
  1611. );
  1612. /* returns E_NOTIMPL */
  1613. RTL_FILE_STREAM_API
  1614. HRESULT
  1615. STDMETHODCALLTYPE
  1616. RtlLockFileStreamRegion(
  1617. PRTL_FILE_STREAM FileStream,
  1618. ULARGE_INTEGER Offset,
  1619. ULARGE_INTEGER NumberOfBytes,
  1620. ULONG LockType
  1621. );
  1622. /* returns E_NOTIMPL */
  1623. RTL_FILE_STREAM_API
  1624. HRESULT
  1625. STDMETHODCALLTYPE
  1626. RtlUnlockFileStreamRegion(
  1627. PRTL_FILE_STREAM FileStream,
  1628. ULARGE_INTEGER Offset,
  1629. ULARGE_INTEGER NumberOfBytes,
  1630. ULONG LockType
  1631. );
  1632. /* returns E_NOTIMPL */
  1633. RTL_FILE_STREAM_API
  1634. HRESULT
  1635. STDMETHODCALLTYPE
  1636. RtlStatFileStream(
  1637. PRTL_FILE_STREAM FileStream,
  1638. STATSTG* StatusInformation,
  1639. ULONG Flags
  1640. );
  1641. /* returns E_NOTIMPL */
  1642. RTL_FILE_STREAM_API
  1643. HRESULT
  1644. STDMETHODCALLTYPE
  1645. RtlCloneFileStream(
  1646. PRTL_FILE_STREAM FileStream,
  1647. IStream** NewStream
  1648. );
  1649. #endif // RTL_DECLARE_FILE_STREAM
  1650. //
  1651. // functions for implementing a readable IStream over a block of memory
  1652. // (writable/growable in the future)
  1653. //
  1654. #if defined(RTL_DECLARE_MEMORY_STREAM) && RTL_DECLARE_MEMORY_STREAM
  1655. struct _RTL_MEMORY_STREAM_DATA;
  1656. struct _RTL_MEMORY_STREAM_WITH_VTABLE;
  1657. struct _RTL_OUT_OF_PROCESS_MEMORY_STREAM_DATA;
  1658. struct _RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE;
  1659. //
  1660. // Don't use NTSYSAPI directly so you can more easily
  1661. // statically link to these functions, independently
  1662. // of how you link to the rest of ntdll.
  1663. //
  1664. #if !defined(RTL_MEMORY_STREAM_API)
  1665. #define RTL_MEMORY_STREAM_API NTSYSAPI
  1666. #endif
  1667. typedef struct _RTL_MEMORY_STREAM_DATA {
  1668. #define RTLP_MEMORY_STREAM_DATA_PREFIX \
  1669. LONG ReferenceCount; \
  1670. ULONG Flags; \
  1671. PUCHAR Current; \
  1672. PUCHAR Begin; \
  1673. PUCHAR End
  1674. RTLP_MEMORY_STREAM_DATA_PREFIX;
  1675. VOID (STDMETHODCALLTYPE* FinalRelease)(struct _RTL_MEMORY_STREAM_WITH_VTABLE*);
  1676. IMalloc* ReservedForMalloc;
  1677. } RTL_MEMORY_STREAM_DATA, *PRTL_MEMORY_STREAM_DATA;
  1678. typedef struct _RTL_MEMORY_STREAM_WITH_VTABLE {
  1679. const IStreamVtbl* StreamVTable;
  1680. RTL_MEMORY_STREAM_DATA Data;
  1681. } RTL_MEMORY_STREAM_WITH_VTABLE, *PRTL_MEMORY_STREAM_WITH_VTABLE;
  1682. typedef struct _RTL_OUT_OF_PROCESS_MEMORY_STREAM_DATA {
  1683. RTLP_MEMORY_STREAM_DATA_PREFIX;
  1684. VOID (STDMETHODCALLTYPE* FinalRelease)(struct _RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE*);
  1685. HANDLE Process;
  1686. } RTL_OUT_OF_PROCESS_MEMORY_STREAM_DATA, *PRTL_OUT_OF_PROCESS_MEMORY_STREAM_DATA;
  1687. typedef struct _RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE {
  1688. const IStreamVtbl* StreamVTable;
  1689. RTL_OUT_OF_PROCESS_MEMORY_STREAM_DATA Data;
  1690. } RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE, *PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE;
  1691. //
  1692. // These macros generate function pointer types that match the IStream member functions,
  1693. // but IStream* is replaced by "T". As well, an identifier is placed within the type
  1694. // appropriately for defining a typedef or a struct member or a variable.
  1695. // They are used so that a vtable can be somewhat typesafely initialized.
  1696. // This way, if you fill out the vtable in the wrong order, you will like get a compile
  1697. // error (other than were function signatures coincide).
  1698. // Also, you don't have to cast the this pointer in your implementations of member functions.
  1699. //
  1700. // You should define a set of macros like this for any COM interface you implement in C.
  1701. //
  1702. #define RTLP_STREAM_NOTHING /* nothing */
  1703. #define PRTL_QUERYINTERFACE_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, const IID* riid, VOID** ppvObject)
  1704. #define PRTL_ADDREF_STREAM2(T, Name) ULONG (STDMETHODCALLTYPE* Name)(T* This)
  1705. #define PRTL_RELEASE_STREAM2(T, Name) ULONG (STDMETHODCALLTYPE* Name)(T* This)
  1706. #define PRTL_READ_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, VOID* pv, ULONG cb, ULONG* pcbRead)
  1707. #define PRTL_WRITE_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, const VOID* pv, ULONG cb, ULONG* pcbWritten)
  1708. #define PRTL_SEEK_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
  1709. #define PRTL_SET_STREAM_SIZE2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, ULARGE_INTEGER libNewSize)
  1710. #define PRTL_COPY_STREAM_TO2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
  1711. #define PRTL_COMMIT_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, DWORD grfCommitFlags)
  1712. #define PRTL_REVERT_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This)
  1713. #define PRTL_LOCK_STREAM_REGION2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  1714. #define PRTL_UNLOCK_STREAM_REGION2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  1715. #define PRTL_STAT_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, STATSTG* pstatstg, DWORD grfStatFlag)
  1716. #define PRTL_CLONE_STREAM2(T, Name) HRESULT (STDMETHODCALLTYPE* Name)(T* This, IStream** ppstm)
  1717. //
  1718. // These macros are like the previous set, but they do not place a name in the
  1719. // type. They are appropriate for casting function pointers.
  1720. // They are used like so:
  1721. // #define RtlOperateOnDerivedFoo (PRTL_OPERATOR_INTERFACE2(RTL_DERIVED_FOO)RtlOperateOnBaseFoo)
  1722. //
  1723. // You should define a set of macros like this for any COM interface you implement in C.
  1724. //
  1725. #define PRTL_QUERYINTERFACE_STREAM1(T) PRTL_QUERYINTERFACE_STREAM2(T, RTLP_STREAM_NOTHING)
  1726. #define PRTL_ADDREF_STREAM1(T) PRTL_ADDREF_STREAM2(T, RTLP_STREAM_NOTHING)
  1727. #define PRTL_RELEASE_STREAM1(T) PRTL_RELEASE_STREAM2(T, RTLP_STREAM_NOTHING)
  1728. #define PRTL_READ_STREAM1(T) PRTL_READ_STREAM2(T, RTLP_STREAM_NOTHING)
  1729. #define PRTL_WRITE_STREAM1(T) PRTL_WRITE_STREAM2(T, RTLP_STREAM_NOTHING)
  1730. #define PRTL_SEEK_STREAM1(T) PRTL_SEEK_STREAM2(T, RTLP_STREAM_NOTHING)
  1731. #define PRTL_SET_STREAM_SIZE1(T) PRTL_SET_STREAM_SIZE2(T, RTLP_STREAM_NOTHING)
  1732. #define PRTL_COPY_STREAM_TO1(T) PRTL_COPY_STREAM_TO2(T, RTLP_STREAM_NOTHING)
  1733. #define PRTL_COMMIT_STREAM1(T) PRTL_COMMIT_STREAM2(T, RTLP_STREAM_NOTHING)
  1734. #define PRTL_REVERT_STREAM1(T) PRTL_REVERT_STREAM2(T, RTLP_STREAM_NOTHING)
  1735. #define PRTL_LOCK_STREAM_REGION1(T) PRTL_LOCK_STREAM_REGION2(T, RTLP_STREAM_NOTHING)
  1736. #define PRTL_UNLOCK_STREAM_REGION1(T) PRTL_UNLOCK_STREAM_REGION2(T, RTLP_STREAM_NOTHING)
  1737. #define PRTL_STAT_STREAM1(T) PRTL_STAT_STREAM2(T, RTLP_STREAM_NOTHING)
  1738. #define PRTL_CLONE_STREAM1(T) PRTL_CLONE_STREAM2(T, RTLP_STREAM_NOTHING)
  1739. //
  1740. // This "template" lets you fill out a VTable
  1741. // with some type safety. Then cast the address of the vtable.
  1742. // Midl ought to provide something like this..
  1743. //
  1744. // You should define a macro like this for any COM interface you implement in C.
  1745. //
  1746. #define RTL_STREAM_VTABLE_TEMPLATE(T) \
  1747. struct \
  1748. { \
  1749. PRTL_QUERYINTERFACE_STREAM2(T, QueryInterface); \
  1750. PRTL_ADDREF_STREAM2(T, AddRef); \
  1751. PRTL_RELEASE_STREAM2(T, Release); \
  1752. PRTL_READ_STREAM2(T, Read); \
  1753. PRTL_WRITE_STREAM2(T, Write); \
  1754. PRTL_SEEK_STREAM2(T, Seek); \
  1755. PRTL_SET_STREAM_SIZE2(T, SetSize); \
  1756. PRTL_COPY_STREAM_TO2(T, CopyTo); \
  1757. PRTL_COMMIT_STREAM2(T, Commit); \
  1758. PRTL_REVERT_STREAM2(T, Revert); \
  1759. PRTL_LOCK_STREAM_REGION2(T, LockRegion); \
  1760. PRTL_UNLOCK_STREAM_REGION2(T, UnlockRegion); \
  1761. PRTL_STAT_STREAM2(T, Stat); \
  1762. PRTL_CLONE_STREAM2(T, Clone); \
  1763. }
  1764. RTL_MEMORY_STREAM_API
  1765. VOID
  1766. STDMETHODCALLTYPE
  1767. RtlInitMemoryStream(
  1768. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream
  1769. );
  1770. RTL_MEMORY_STREAM_API
  1771. VOID
  1772. STDMETHODCALLTYPE
  1773. RtlInitOutOfProcessMemoryStream(
  1774. PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE MemoryStream
  1775. );
  1776. RTL_MEMORY_STREAM_API
  1777. VOID
  1778. STDMETHODCALLTYPE
  1779. RtlFinalReleaseOutOfProcessMemoryStream(
  1780. PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE MemoryStream
  1781. );
  1782. RTL_MEMORY_STREAM_API
  1783. ULONG
  1784. STDMETHODCALLTYPE
  1785. RtlAddRefMemoryStream(
  1786. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream
  1787. );
  1788. #define RtlAddRefOutOfProcessMemoryStream \
  1789. ((PRTL_ADDREF_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlAddRefMemoryStream)
  1790. RTL_MEMORY_STREAM_API
  1791. ULONG
  1792. STDMETHODCALLTYPE
  1793. RtlReleaseMemoryStream(
  1794. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream
  1795. );
  1796. #define RtlReleaseOutOfProcessMemoryStream \
  1797. ((PRTL_RELEASE_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlReleaseMemoryStream)
  1798. RTL_MEMORY_STREAM_API
  1799. HRESULT
  1800. STDMETHODCALLTYPE
  1801. RtlQueryInterfaceMemoryStream(
  1802. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1803. const IID* Interface,
  1804. PVOID* Object
  1805. );
  1806. #define RtlQueryInterfaceOutOfProcessMemoryStream \
  1807. ((PRTL_QUERYINTERFACE_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlQueryInterfaceMemoryStream)
  1808. RTL_MEMORY_STREAM_API
  1809. HRESULT
  1810. STDMETHODCALLTYPE
  1811. RtlReadMemoryStream(
  1812. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1813. PVOID Buffer,
  1814. ULONG BytesToRead,
  1815. ULONG* BytesRead
  1816. );
  1817. RTL_MEMORY_STREAM_API
  1818. HRESULT
  1819. STDMETHODCALLTYPE
  1820. RtlReadOutOfProcessMemoryStream(
  1821. PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1822. PVOID Buffer,
  1823. ULONG BytesToRead,
  1824. ULONG* BytesRead
  1825. );
  1826. // E_NOTIMPL
  1827. RTL_MEMORY_STREAM_API
  1828. HRESULT
  1829. STDMETHODCALLTYPE
  1830. RtlWriteMemoryStream(
  1831. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1832. const VOID* Buffer,
  1833. ULONG BytesToWrite,
  1834. ULONG* BytesWritten
  1835. );
  1836. #define RtlWriteOutOfProcessMemoryStream \
  1837. ((PRTL_WRITE_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlWriteMemoryStream)
  1838. RTL_MEMORY_STREAM_API
  1839. HRESULT
  1840. STDMETHODCALLTYPE
  1841. RtlSeekMemoryStream(
  1842. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1843. LARGE_INTEGER Distance,
  1844. ULONG Origin,
  1845. ULARGE_INTEGER* NewPosition
  1846. );
  1847. #define RtlSeekOutOfProcessMemoryStream \
  1848. ((PRTL_SEEK_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlSeekMemoryStream)
  1849. // E_NOTIMPL
  1850. RTL_MEMORY_STREAM_API
  1851. HRESULT
  1852. STDMETHODCALLTYPE
  1853. RtlSetMemoryStreamSize(
  1854. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1855. ULARGE_INTEGER NewSize
  1856. );
  1857. #define RtlSetOutOfProcessMemoryStreamSize \
  1858. ((PRTL_SET_STREAM_SIZE1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlSetMemoryStreamSize)
  1859. RTL_MEMORY_STREAM_API
  1860. HRESULT
  1861. STDMETHODCALLTYPE
  1862. RtlCopyMemoryStreamTo(
  1863. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1864. IStream* AnotherStream,
  1865. ULARGE_INTEGER NumberOfBytesToCopy,
  1866. ULARGE_INTEGER* NumberOfBytesRead,
  1867. ULARGE_INTEGER* NumberOfBytesWritten
  1868. );
  1869. // E_NOTIMPL
  1870. RTL_MEMORY_STREAM_API
  1871. HRESULT
  1872. STDMETHODCALLTYPE
  1873. RtlCopyOutOfProcessMemoryStreamTo(
  1874. PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1875. IStream* AnotherStream,
  1876. ULARGE_INTEGER NumberOfBytesToCopy,
  1877. ULARGE_INTEGER* NumberOfBytesRead,
  1878. ULARGE_INTEGER* NumberOfBytesWritten
  1879. );
  1880. // E_NOTIMPL
  1881. RTL_MEMORY_STREAM_API
  1882. HRESULT
  1883. STDMETHODCALLTYPE
  1884. RtlCommitMemoryStream(
  1885. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1886. ULONG Flags
  1887. );
  1888. #define RtlCommitOutOfProcessMemoryStream \
  1889. ((PRTL_COMMIT_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlCommitMemoryStream)
  1890. // E_NOTIMPL
  1891. RTL_MEMORY_STREAM_API
  1892. HRESULT
  1893. STDMETHODCALLTYPE
  1894. RtlRevertMemoryStream(
  1895. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream
  1896. );
  1897. #define RtlRevertOutOfProcessMemoryStream \
  1898. ((PRTL_REVERT_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlRevertMemoryStream)
  1899. // E_NOTIMPL
  1900. RTL_MEMORY_STREAM_API
  1901. HRESULT
  1902. STDMETHODCALLTYPE
  1903. RtlLockMemoryStreamRegion(
  1904. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1905. ULARGE_INTEGER Offset,
  1906. ULARGE_INTEGER NumberOfBytes,
  1907. ULONG LockType
  1908. );
  1909. #define RtlLockOutOfProcessMemoryStreamRegion \
  1910. ((PRTL_LOCK_STREAM_REGION1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlLockMemoryStreamRegion)
  1911. // E_NOTIMPL
  1912. RTL_MEMORY_STREAM_API
  1913. HRESULT
  1914. STDMETHODCALLTYPE
  1915. RtlUnlockMemoryStreamRegion(
  1916. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1917. ULARGE_INTEGER Offset,
  1918. ULARGE_INTEGER NumberOfBytes,
  1919. ULONG LockType
  1920. );
  1921. #define RtlUnlockOutOfProcessMemoryStreamRegion \
  1922. ((PRTL_UNLOCK_STREAM_REGION1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlUnlockMemoryStreamRegion)
  1923. // E_NOTIMPL
  1924. RTL_MEMORY_STREAM_API
  1925. HRESULT
  1926. STDMETHODCALLTYPE
  1927. RtlStatMemoryStream(
  1928. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1929. STATSTG* StatusInformation,
  1930. ULONG Flags
  1931. );
  1932. #define RtlStatOutOfProcessMemoryStream \
  1933. ((PRTL_STAT_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlStatMemoryStream)
  1934. // E_NOTIMPL
  1935. RTL_MEMORY_STREAM_API
  1936. HRESULT
  1937. STDMETHODCALLTYPE
  1938. RtlCloneMemoryStream(
  1939. PRTL_MEMORY_STREAM_WITH_VTABLE MemoryStream,
  1940. IStream** NewStream
  1941. );
  1942. #define RtlCloneOutOfProcessMemoryStream \
  1943. ((PRTL_CLONE_STREAM1(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE))RtlCloneMemoryStream)
  1944. #if defined(__cplusplus) && !defined(CINTERFACE)
  1945. #if !defined(interface)
  1946. //
  1947. // we need #define interface struct
  1948. //
  1949. #include "objbase.h"
  1950. #endif
  1951. #ifdef COM_NO_WINDOWS_H
  1952. #include "objidl.h"
  1953. #else
  1954. #define COM_NO_WINDOWS_H
  1955. #include "objidl.h"
  1956. #undef COM_NO_WINDOWS_H
  1957. #endif
  1958. class DECLSPEC_NOVTABLE CRtlMemoryStream : public IStream
  1959. {
  1960. protected:
  1961. operator PRTL_MEMORY_STREAM_WITH_VTABLE()
  1962. {
  1963. return reinterpret_cast<PRTL_MEMORY_STREAM_WITH_VTABLE>(this);
  1964. }
  1965. RTL_MEMORY_STREAM_DATA Data;
  1966. public:
  1967. /* This conflicts with DECLSPEC_NOVTABLE
  1968. static VOID STDMETHODCALLTYPE FinalReleaseGlue(PRTL_MEMORY_STREAM_WITH_VTABLE This)
  1969. {
  1970. return reinterpret_cast<CRtlMemoryStream*>(This)->FinalRelease();
  1971. }
  1972. virtual VOID STDMETHODCALLTYPE FinalRelease() { }
  1973. */
  1974. CRtlMemoryStream()
  1975. {
  1976. RtlInitMemoryStream(*this);
  1977. //Data.FinalRelease = FinalReleaseGlue;
  1978. }
  1979. ULONG STDMETHODCALLTYPE AddRef()
  1980. {
  1981. return RtlAddRefMemoryStream(*this);
  1982. }
  1983. ULONG STDMETHODCALLTYPE ReleaseRef()
  1984. {
  1985. return RtlReleaseMemoryStream(*this);
  1986. }
  1987. HRESULT STDMETHODCALLTYPE QueryInterface(
  1988. const IID& Interface,
  1989. PVOID* Object
  1990. )
  1991. {
  1992. return RtlQueryInterfaceMemoryStream(*this, &Interface, Object);
  1993. }
  1994. HRESULT STDMETHODCALLTYPE Read(
  1995. PVOID Buffer,
  1996. ULONG BytesToRead,
  1997. ULONG* BytesRead
  1998. )
  1999. {
  2000. return RtlReadMemoryStream(*this, Buffer, BytesToRead, BytesRead);
  2001. }
  2002. HRESULT STDMETHODCALLTYPE Write(
  2003. const VOID* Buffer,
  2004. ULONG BytesToWrite,
  2005. ULONG* BytesWritten
  2006. )
  2007. {
  2008. return RtlWriteMemoryStream(*this, Buffer, BytesToWrite, BytesWritten);
  2009. }
  2010. HRESULT STDMETHODCALLTYPE Seek(
  2011. LARGE_INTEGER Distance,
  2012. ULONG Origin,
  2013. ULARGE_INTEGER* NewPosition
  2014. )
  2015. {
  2016. return RtlSeekMemoryStream(*this, Distance, Origin, NewPosition);
  2017. }
  2018. HRESULT STDMETHODCALLTYPE SetSize(
  2019. ULARGE_INTEGER NewSize
  2020. )
  2021. {
  2022. return RtlSetMemoryStreamSize(*this, NewSize);
  2023. }
  2024. HRESULT STDMETHODCALLTYPE CopyTo(
  2025. IStream* AnotherStream,
  2026. ULARGE_INTEGER NumberOfBytesToCopy,
  2027. ULARGE_INTEGER* NumberOfBytesRead,
  2028. ULARGE_INTEGER* NumberOfBytesWritten
  2029. )
  2030. {
  2031. return RtlCopyMemoryStreamTo(
  2032. *this,
  2033. AnotherStream,
  2034. NumberOfBytesToCopy,
  2035. NumberOfBytesRead,
  2036. NumberOfBytesWritten);
  2037. }
  2038. HRESULT STDMETHODCALLTYPE Commit(
  2039. ULONG Flags
  2040. )
  2041. {
  2042. return RtlCommitMemoryStream(*this, Flags);
  2043. }
  2044. HRESULT STDMETHODCALLTYPE Revert()
  2045. {
  2046. return RtlRevertMemoryStream(*this);
  2047. }
  2048. HRESULT STDMETHODCALLTYPE LockRegion(
  2049. ULARGE_INTEGER Offset,
  2050. ULARGE_INTEGER NumberOfBytes,
  2051. ULONG LockType
  2052. )
  2053. {
  2054. return RtlLockMemoryStreamRegion(*this, Offset, NumberOfBytes, LockType);
  2055. }
  2056. HRESULT STDMETHODCALLTYPE UnlockRegion(
  2057. ULARGE_INTEGER Offset,
  2058. ULARGE_INTEGER NumberOfBytes,
  2059. ULONG LockType
  2060. )
  2061. {
  2062. return RtlUnlockMemoryStreamRegion(*this, Offset, NumberOfBytes, LockType);
  2063. }
  2064. HRESULT STDMETHODCALLTYPE Stat(
  2065. STATSTG* StatusInformation,
  2066. ULONG Flags
  2067. )
  2068. {
  2069. return RtlStatMemoryStream(*this, StatusInformation, Flags);
  2070. }
  2071. HRESULT STDMETHODCALLTYPE Clone(
  2072. IStream** NewStream
  2073. )
  2074. {
  2075. return RtlCloneMemoryStream(*this, NewStream);
  2076. }
  2077. private:
  2078. // can't do this outside the class because Data is not public
  2079. static void CompileTimeAssert() {
  2080. C_ASSERT(FIELD_OFFSET(RTL_MEMORY_STREAM_WITH_VTABLE, Data) == FIELD_OFFSET(CRtlMemoryStream, Data));
  2081. }
  2082. };
  2083. C_ASSERT(sizeof(RTL_MEMORY_STREAM_WITH_VTABLE) == sizeof(CRtlMemoryStream));
  2084. class DECLSPEC_NOVTABLE CRtlOutOfProcessMemoryStream : public IStream
  2085. {
  2086. protected:
  2087. operator PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE()
  2088. {
  2089. return reinterpret_cast<PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE>(this);
  2090. }
  2091. RTL_OUT_OF_PROCESS_MEMORY_STREAM_DATA Data;
  2092. public:
  2093. /* This conflicts with DECLSPEC_NOVTABLE
  2094. static VOID STDMETHODCALLTYPE FinalReleaseGlue(PRTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE This)
  2095. {
  2096. return reinterpret_cast<CRtlOutOfProcessMemoryStream*>(This)->FinalRelease();
  2097. }
  2098. virtual VOID STDMETHODCALLTYPE FinalRelease() { }
  2099. */
  2100. CRtlOutOfProcessMemoryStream()
  2101. {
  2102. RtlInitOutOfProcessMemoryStream(*this);
  2103. //Data.FinalRelease = FinalReleaseGlue;
  2104. }
  2105. ULONG STDMETHODCALLTYPE AddRef()
  2106. {
  2107. return RtlAddRefOutOfProcessMemoryStream(*this);
  2108. }
  2109. ULONG STDMETHODCALLTYPE ReleaseRef()
  2110. {
  2111. return RtlReleaseOutOfProcessMemoryStream(*this);
  2112. }
  2113. HRESULT STDMETHODCALLTYPE QueryInterface(
  2114. const IID& Interface,
  2115. PVOID* Object
  2116. )
  2117. {
  2118. return RtlQueryInterfaceOutOfProcessMemoryStream(*this, &Interface, Object);
  2119. }
  2120. HRESULT STDMETHODCALLTYPE Read(
  2121. PVOID Buffer,
  2122. ULONG BytesToRead,
  2123. ULONG* BytesRead
  2124. )
  2125. {
  2126. return RtlReadOutOfProcessMemoryStream(*this, Buffer, BytesToRead, BytesRead);
  2127. }
  2128. HRESULT STDMETHODCALLTYPE Write(
  2129. const VOID* Buffer,
  2130. ULONG BytesToWrite,
  2131. ULONG* BytesWritten
  2132. )
  2133. {
  2134. return RtlWriteOutOfProcessMemoryStream(*this, Buffer, BytesToWrite, BytesWritten);
  2135. }
  2136. HRESULT STDMETHODCALLTYPE Seek(
  2137. LARGE_INTEGER Distance,
  2138. ULONG Origin,
  2139. ULARGE_INTEGER* NewPosition
  2140. )
  2141. {
  2142. return RtlSeekOutOfProcessMemoryStream(*this, Distance, Origin, NewPosition);
  2143. }
  2144. HRESULT STDMETHODCALLTYPE SetSize(
  2145. ULARGE_INTEGER NewSize
  2146. )
  2147. {
  2148. return RtlSetOutOfProcessMemoryStreamSize(*this, NewSize);
  2149. }
  2150. HRESULT STDMETHODCALLTYPE CopyTo(
  2151. IStream* AnotherStream,
  2152. ULARGE_INTEGER NumberOfBytesToCopy,
  2153. ULARGE_INTEGER* NumberOfBytesRead,
  2154. ULARGE_INTEGER* NumberOfBytesWritten
  2155. )
  2156. {
  2157. return RtlCopyOutOfProcessMemoryStreamTo(
  2158. *this,
  2159. AnotherStream,
  2160. NumberOfBytesToCopy,
  2161. NumberOfBytesRead,
  2162. NumberOfBytesWritten);
  2163. }
  2164. HRESULT STDMETHODCALLTYPE Commit(
  2165. ULONG Flags
  2166. )
  2167. {
  2168. return RtlCommitOutOfProcessMemoryStream(*this, Flags);
  2169. }
  2170. HRESULT STDMETHODCALLTYPE Revert()
  2171. {
  2172. return RtlRevertOutOfProcessMemoryStream(*this);
  2173. }
  2174. HRESULT STDMETHODCALLTYPE LockRegion(
  2175. ULARGE_INTEGER Offset,
  2176. ULARGE_INTEGER NumberOfBytes,
  2177. ULONG LockType
  2178. )
  2179. {
  2180. return RtlLockOutOfProcessMemoryStreamRegion(*this, Offset, NumberOfBytes, LockType);
  2181. }
  2182. HRESULT STDMETHODCALLTYPE UnlockRegion(
  2183. ULARGE_INTEGER Offset,
  2184. ULARGE_INTEGER NumberOfBytes,
  2185. ULONG LockType
  2186. )
  2187. {
  2188. return RtlUnlockOutOfProcessMemoryStreamRegion(*this, Offset, NumberOfBytes, LockType);
  2189. }
  2190. HRESULT STDMETHODCALLTYPE Stat(
  2191. STATSTG* StatusInformation,
  2192. ULONG Flags
  2193. )
  2194. {
  2195. return RtlStatOutOfProcessMemoryStream(*this, StatusInformation, Flags);
  2196. }
  2197. HRESULT STDMETHODCALLTYPE Clone(
  2198. IStream** NewStream
  2199. )
  2200. {
  2201. return RtlCloneOutOfProcessMemoryStream(*this, NewStream);
  2202. }
  2203. private:
  2204. // can't do this outside the class because Data is not public
  2205. static void CompileTimeAssert() {
  2206. C_ASSERT(FIELD_OFFSET(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE, Data) == FIELD_OFFSET(CRtlOutOfProcessMemoryStream, Data));
  2207. }
  2208. };
  2209. C_ASSERT(sizeof(RTL_OUT_OF_PROCESS_MEMORY_STREAM_WITH_VTABLE) == sizeof(CRtlOutOfProcessMemoryStream));
  2210. #endif // __cplusplus
  2211. #endif // RTL_DECLARE_MEMORY_STREAM
  2212. #endif // RTL_DECLARE_STREAMS
  2213. #define RTL_CLOSE_HANDLE(handle_) ((handle_) != NULL ? NtClose(handle_) : STATUS_SUCCESS)
  2214. #define RTL_UNMAP_VIEW_OF_SECTION2(process_, base_) ((base_) != NULL ? NtUnmapViewOfSection((process_), (base_)) : STATUS_SUCCESS)
  2215. #define RTL_UNMAP_VIEW_OF_SECTION1(base_) (RTL_UNMAP_VIEW_OF_SECTION2(NtCurrentProcess(), (base_)))
  2216. #if defined(__cplusplus) && !defined(CINTERFACE)
  2217. #define RTL_RELEASE(punk_) do { if ((punk_) != NULL) { (punk_)->Release(); (punk_) = NULL; } } while(0)
  2218. #else
  2219. #define RTL_RELEASE(punk_) do { if ((punk_) != NULL) { (punk_)->lpVtbl->Release(punk_); (punk_) = NULL; } } while(0)
  2220. #endif
  2221. //
  2222. // Activation context management functions
  2223. //
  2224. //
  2225. // Data structures are visible both in ntrtl and Win32 APIs, so their
  2226. // definitions are factored out into a separate header file.
  2227. //
  2228. #define ACTCTX_PROCESS_DEFAULT ((void*)NULL)
  2229. //
  2230. // If you activate this activation context handle,
  2231. // all activation context queries fail and searches
  2232. // drop back to pre-activation context behavior, like
  2233. // searching PATH for .dlls.
  2234. //
  2235. // This constant works at the Win32 and Rtl level, but
  2236. // is intended only for Shell clients, so is kept out of winnt.h
  2237. //
  2238. #define ACTCTX_EMPTY ((void*)(LONG_PTR)-3)
  2239. //
  2240. // NULL can also mean ACTCTX_SYSTEM_DEFAULT. We are between decisions
  2241. // on NULL plus a flag, magic numbers and/or static instances. I generally
  2242. // favor public magic numbers internally mapped to static instances, but
  2243. // I was pushed toward flags to start.
  2244. //
  2245. #define ACTCTX_SYSTEM_DEFAULT ((void*)(LONG_PTR)-4)
  2246. //
  2247. // Reserve a small range of values, 0 through -7.
  2248. // (Note that NtCurrentProcess() == -1, NtCurrentThread() == -2, so I avoided
  2249. // those, though this macro picks them up.)
  2250. //
  2251. // We subtract one instead of comparing against NULL seperately to avoid
  2252. // evaluating the macro parameter more than once.
  2253. //
  2254. #define IS_SPECIAL_ACTCTX(x) (((((LONG_PTR)(x)) - 1) | 7) == -1)
  2255. typedef struct _ACTIVATION_CONTEXT *PACTIVATION_CONTEXT;
  2256. typedef const struct _ACTIVATION_CONTEXT *PCACTIVATION_CONTEXT;
  2257. #define INVALID_ACTIVATION_CONTEXT ((PACTIVATION_CONTEXT) ((LONG_PTR) -1))
  2258. // begin_winnt
  2259. typedef enum _ACTIVATION_CONTEXT_INFO_CLASS {
  2260. ActivationContextBasicInformation = 1,
  2261. ActivationContextDetailedInformation = 2,
  2262. AssemblyDetailedInformationInActivationContext = 3,
  2263. FileInformationInAssemblyOfAssemblyInActivationContext = 4,
  2264. MaxActivationContextInfoClass,
  2265. //
  2266. // compatibility with old names
  2267. //
  2268. AssemblyDetailedInformationInActivationContxt = 3,
  2269. FileInformationInAssemblyOfAssemblyInActivationContxt = 4
  2270. } ACTIVATION_CONTEXT_INFO_CLASS;
  2271. #define ACTIVATIONCONTEXTINFOCLASS ACTIVATION_CONTEXT_INFO_CLASS
  2272. // end_winnt
  2273. #define RTL_QUERY_INFORMATION_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT (0x00000001)
  2274. #define RTL_QUERY_INFORMATION_ACTIVATION_CONTEXT_FLAG_ACTIVATION_CONTEXT_IS_MODULE (0x00000002)
  2275. #define RTL_QUERY_INFORMATION_ACTIVATION_CONTEXT_FLAG_ACTIVATION_CONTEXT_IS_ADDRESS (0x00000004)
  2276. #define RTL_QUERY_INFORMATION_ACTIVATION_CONTEXT_FLAG_NO_ADDREF (0x80000000)
  2277. // begin_winnt
  2278. typedef struct _ACTIVATION_CONTEXT_QUERY_INDEX {
  2279. ULONG ulAssemblyIndex;
  2280. ULONG ulFileIndexInAssembly;
  2281. } ACTIVATION_CONTEXT_QUERY_INDEX, * PACTIVATION_CONTEXT_QUERY_INDEX;
  2282. typedef const struct _ACTIVATION_CONTEXT_QUERY_INDEX * PCACTIVATION_CONTEXT_QUERY_INDEX;
  2283. // end_winnt
  2284. NTSYSAPI
  2285. NTSTATUS
  2286. NTAPI
  2287. RtlQueryInformationActivationContext(
  2288. IN ULONG Flags,
  2289. IN PCACTIVATION_CONTEXT ActivationContext,
  2290. IN PVOID SubInstanceIndex,
  2291. IN ACTIVATION_CONTEXT_INFO_CLASS ActivationContextInformationClass,
  2292. OUT PVOID ActivationContextInformation,
  2293. IN SIZE_T ActivationContextInformationLength,
  2294. OUT PSIZE_T ReturnLength OPTIONAL
  2295. );
  2296. NTSYSAPI
  2297. NTSTATUS
  2298. NTAPI
  2299. RtlQueryInformationActiveActivationContext(
  2300. IN ACTIVATION_CONTEXT_INFO_CLASS ActivationContextInformationClass,
  2301. OUT PVOID ActivationContextInformation,
  2302. IN SIZE_T ActivationContextInformationLength,
  2303. OUT PSIZE_T ReturnLength OPTIONAL
  2304. );
  2305. #define FIND_ACTIVATION_CONTEXT_SECTION_OUTFLAG_FOUND_IN_PROCESS_DEFAULT (0x00000001)
  2306. #define FIND_ACTIVATION_CONTEXT_SECTION_OUTFLAG_FOUND_IN_SYSTEM_DEFAULT (0x00000002)
  2307. #if !defined(RC_INVOKED) /* RC complains about long symbols in #ifs */
  2308. #if !defined(ACTIVATION_CONTEXT_BASIC_INFORMATION_DEFINED)
  2309. typedef struct _ACTIVATION_CONTEXT_BASIC_INFORMATION {
  2310. union {
  2311. struct _ACTIVATION_CONTEXT *ActivationContext;
  2312. HANDLE hActCtx; // for compatibility with windows.h/winbase.h clients
  2313. };
  2314. union {
  2315. ULONG Flags;
  2316. ULONG dwFlags; // for compatibility with windows.h/winbase.h clients
  2317. };
  2318. } ACTIVATION_CONTEXT_BASIC_INFORMATION, *PACTIVATION_CONTEXT_BASIC_INFORMATION;
  2319. typedef const struct _ACTIVATION_CONTEXT_BASIC_INFORMATION *PCACTIVATION_CONTEXT_BASIC_INFORMATION;
  2320. #define ACTIVATION_CONTEXT_BASIC_INFORMATION_DEFINED 1
  2321. #endif // !defined(ACTIVATION_CONTEXT_BASIC_INFORMATION_DEFINED)
  2322. #endif
  2323. // begin_winnt
  2324. #define ACTIVATION_CONTEXT_PATH_TYPE_NONE (1)
  2325. #define ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE (2)
  2326. #define ACTIVATION_CONTEXT_PATH_TYPE_URL (3)
  2327. #define ACTIVATION_CONTEXT_PATH_TYPE_ASSEMBLYREF (4)
  2328. typedef struct _ASSEMBLY_FILE_DETAILED_INFORMATION {
  2329. ULONG ulFlags;
  2330. ULONG ulFilenameLength;
  2331. ULONG ulPathLength;
  2332. PCWSTR lpFileName;
  2333. PCWSTR lpFilePath;
  2334. } ASSEMBLY_FILE_DETAILED_INFORMATION, *PASSEMBLY_FILE_DETAILED_INFORMATION;
  2335. typedef const ASSEMBLY_FILE_DETAILED_INFORMATION *PCASSEMBLY_FILE_DETAILED_INFORMATION;
  2336. //
  2337. // compatibility with old names
  2338. // The new names use "file" consistently.
  2339. //
  2340. #define _ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION _ASSEMBLY_FILE_DETAILED_INFORMATION
  2341. #define ASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION ASSEMBLY_FILE_DETAILED_INFORMATION
  2342. #define PASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION PASSEMBLY_FILE_DETAILED_INFORMATION
  2343. #define PCASSEMBLY_DLL_REDIRECTION_DETAILED_INFORMATION PCASSEMBLY_FILE_DETAILED_INFORMATION
  2344. typedef struct _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION {
  2345. ULONG ulFlags;
  2346. ULONG ulEncodedAssemblyIdentityLength; // in bytes
  2347. ULONG ulManifestPathType; // ACTIVATION_CONTEXT_PATH_TYPE_*
  2348. ULONG ulManifestPathLength; // in bytes
  2349. LARGE_INTEGER liManifestLastWriteTime; // FILETIME
  2350. ULONG ulPolicyPathType; // ACTIVATION_CONTEXT_PATH_TYPE_*
  2351. ULONG ulPolicyPathLength; // in bytes
  2352. LARGE_INTEGER liPolicyLastWriteTime; // FILETIME
  2353. ULONG ulMetadataSatelliteRosterIndex;
  2354. ULONG ulManifestVersionMajor; // 1
  2355. ULONG ulManifestVersionMinor; // 0
  2356. ULONG ulPolicyVersionMajor; // 0
  2357. ULONG ulPolicyVersionMinor; // 0
  2358. ULONG ulAssemblyDirectoryNameLength; // in bytes
  2359. PCWSTR lpAssemblyEncodedAssemblyIdentity;
  2360. PCWSTR lpAssemblyManifestPath;
  2361. PCWSTR lpAssemblyPolicyPath;
  2362. PCWSTR lpAssemblyDirectoryName;
  2363. ULONG ulFileCount;
  2364. } ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION, * PACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION;
  2365. typedef const struct _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION * PCACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION ;
  2366. typedef struct _ACTIVATION_CONTEXT_DETAILED_INFORMATION {
  2367. ULONG dwFlags;
  2368. ULONG ulFormatVersion;
  2369. ULONG ulAssemblyCount;
  2370. ULONG ulRootManifestPathType;
  2371. ULONG ulRootManifestPathChars;
  2372. ULONG ulRootConfigurationPathType;
  2373. ULONG ulRootConfigurationPathChars;
  2374. ULONG ulAppDirPathType;
  2375. ULONG ulAppDirPathChars;
  2376. PCWSTR lpRootManifestPath;
  2377. PCWSTR lpRootConfigurationPath;
  2378. PCWSTR lpAppDirPath;
  2379. } ACTIVATION_CONTEXT_DETAILED_INFORMATION, *PACTIVATION_CONTEXT_DETAILED_INFORMATION;
  2380. typedef const struct _ACTIVATION_CONTEXT_DETAILED_INFORMATION *PCACTIVATION_CONTEXT_DETAILED_INFORMATION;
  2381. // end_winnt
  2382. typedef struct _FINDFIRSTACTIVATIONCONTEXTSECTION {
  2383. ULONG Size;
  2384. ULONG Flags;
  2385. const GUID *ExtensionGuid;
  2386. ULONG Id;
  2387. ULONG Depth;
  2388. ULONG OutFlags;
  2389. } FINDFIRSTACTIVATIONCONTEXTSECTION, *PFINDFIRSTACTIVATIONCONTEXTSECTION;
  2390. typedef const FINDFIRSTACTIVATIONCONTEXTSECTION * PCFINDFIRSTACTIVATIONCONTEXTSECTION;
  2391. #define ACTIVATION_CONTEXT_NOTIFICATION_DESTROY (1)
  2392. #define ACTIVATION_CONTEXT_NOTIFICATION_ZOMBIFY (2)
  2393. #define ACTIVATION_CONTEXT_NOTIFICATION_USED (3)
  2394. typedef
  2395. VOID (NTAPI * PACTIVATION_CONTEXT_NOTIFY_ROUTINE)(
  2396. IN ULONG NotificationType,
  2397. IN PACTIVATION_CONTEXT ActivationContext,
  2398. IN const VOID *ActivationContextData,
  2399. IN PVOID NotificationContext,
  2400. IN PVOID NotificationData,
  2401. IN OUT PBOOLEAN DisableThisNotification
  2402. );
  2403. NTSYSAPI
  2404. NTSTATUS
  2405. NTAPI
  2406. RtlCreateActivationContext(
  2407. IN ULONG Flags,
  2408. IN const struct _ACTIVATION_CONTEXT_DATA * ActivationContextData,
  2409. IN ULONG ExtraBytes OPTIONAL,
  2410. IN PACTIVATION_CONTEXT_NOTIFY_ROUTINE NotificationRoutine OPTIONAL,
  2411. IN PVOID NotificationContext OPTIONAL,
  2412. OUT PACTIVATION_CONTEXT *ActivationContext
  2413. );
  2414. NTSYSAPI
  2415. VOID
  2416. NTAPI
  2417. RtlAddRefActivationContext(
  2418. IN PACTIVATION_CONTEXT AppCtx
  2419. );
  2420. NTSYSAPI
  2421. VOID
  2422. NTAPI
  2423. RtlReleaseActivationContext(
  2424. IN PACTIVATION_CONTEXT AppCtx
  2425. );
  2426. NTSYSAPI
  2427. NTSTATUS
  2428. NTAPI
  2429. RtlZombifyActivationContext(
  2430. IN PACTIVATION_CONTEXT ActivationContext
  2431. );
  2432. NTSYSAPI
  2433. NTSTATUS
  2434. NTAPI
  2435. RtlGetActiveActivationContext(
  2436. OUT PACTIVATION_CONTEXT *ActivationContext
  2437. );
  2438. NTSYSAPI
  2439. BOOLEAN
  2440. NTAPI
  2441. RtlIsActivationContextActive(
  2442. IN PACTIVATION_CONTEXT ActivationContext
  2443. );
  2444. typedef struct _ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_BEGINNING {
  2445. IN VOID const * Data; // pointer to activation context data
  2446. IN ULONG AssemblyRosterIndex;
  2447. OUT PVOID ResolutionContext;
  2448. OUT UNICODE_STRING Root; // Root path - a default buffer is passed in; if
  2449. // it is not large enough, callback must allocate
  2450. // a string using the RtlAllocateStringRoutine
  2451. // function pointer.
  2452. OUT BOOLEAN KnownRoot; // default is FALSE; set to TRUE if you were able to
  2453. // resolve the storage root immediately. this is
  2454. // how to handle things like run-from-source where
  2455. // the assembly is on read-only removable media like
  2456. // a CD-ROM. If you set it to TRUE, the _SUCCESSFUL
  2457. // vs. _UNSUCCESSFUL callbacks are not made.
  2458. OUT SIZE_T RootCount; // Caller may set to ((SIZE_T) -1) and use the
  2459. // .NoMoreEntries BOOLEAN in the callback to stop enumeration
  2460. OUT BOOLEAN CancelResolution; // set to true if you want to stop the resolution
  2461. } ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_BEGINNING;
  2462. typedef struct _ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_GET_ROOT {
  2463. IN PVOID ResolutionContext;
  2464. IN SIZE_T RootIndex;
  2465. OUT BOOLEAN CancelResolution; // set to true if you want to stop the resolution with STATUS_CANCELLED
  2466. OUT BOOLEAN NoMoreEntries; // set to TRUE if you have no more roots to return.
  2467. OUT UNICODE_STRING Root; // If for some reason you want to skip this index; set .Length to zero
  2468. } ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_GET_ROOT;
  2469. typedef struct _ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_SUCCESSFUL {
  2470. IN PVOID ResolutionContext;
  2471. IN ULONG RootIndexUsed;
  2472. } ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_SUCCESSFUL;
  2473. typedef struct _ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_ENDING {
  2474. IN PVOID ResolutionContext;
  2475. } ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_ENDING;
  2476. typedef union _ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA {
  2477. ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_BEGINNING ResolutionBeginning;
  2478. ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_GET_ROOT GetRoot;
  2479. ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_SUCCESSFUL ResolutionSuccessful;
  2480. ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA_RESOLUTION_ENDING ResolutionEnding;
  2481. } ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA, *PASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA;
  2482. #define ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_REASON_RESOLUTION_BEGINNING (1)
  2483. #define ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_REASON_GET_ROOT (2)
  2484. #define ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_REASON_RESOLUTION_SUCCESSFUL (3)
  2485. #define ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_REASON_RESOLUTION_ENDING (4)
  2486. typedef
  2487. VOID (NTAPI * PASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_ROUTINE)(
  2488. IN ULONG CallbackReason,
  2489. IN OUT PASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA CallbackData,
  2490. IN PVOID CallbackContext
  2491. );
  2492. NTSYSAPI
  2493. NTSTATUS
  2494. NTAPI
  2495. RtlResolveAssemblyStorageMapEntry(
  2496. IN ULONG Flags,
  2497. IN PACTIVATION_CONTEXT ActivationContext,
  2498. IN ULONG AssemblyRosterIndex,
  2499. IN PASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_ROUTINE Callback,
  2500. IN PVOID CallbackContext
  2501. );
  2502. #define RTL_GET_ASSEMBLY_STORAGE_ROOT_FLAG_ACTIVATION_CONTEXT_USE_PROCESS_DEFAULT (0x00000001)
  2503. #define RTL_GET_ASSEMBLY_STORAGE_ROOT_FLAG_ACTIVATION_CONTEXT_USE_SYSTEM_DEFAULT (0x00000002)
  2504. NTSYSAPI
  2505. NTSTATUS
  2506. NTAPI
  2507. RtlGetAssemblyStorageRoot(
  2508. IN ULONG Flags,
  2509. IN PACTIVATION_CONTEXT ActivationContext,
  2510. IN ULONG AssemblyRosterIndex,
  2511. OUT PCUNICODE_STRING *AssemblyStorageRoot,
  2512. IN PASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_ROUTINE Callback,
  2513. IN PVOID CallbackContext
  2514. );
  2515. #define ACTIVATION_CONTEXT_SECTION_KEYED_DATA_FLAG_FOUND_IN_PROCESS_DEFAULT (0x00000001)
  2516. #define ACTIVATION_CONTEXT_SECTION_KEYED_DATA_FLAG_FOUND_IN_SYSTEM_DEFAULT (0x00000002)
  2517. typedef struct _ACTIVATION_CONTEXT_SECTION_KEYED_DATA_2600 {
  2518. ULONG Size;
  2519. ULONG DataFormatVersion;
  2520. PVOID Data;
  2521. ULONG Length;
  2522. PVOID SectionGlobalData;
  2523. ULONG SectionGlobalDataLength;
  2524. PVOID SectionBase;
  2525. ULONG SectionTotalLength;
  2526. PACTIVATION_CONTEXT ActivationContext;
  2527. ULONG AssemblyRosterIndex;
  2528. ULONG Flags;
  2529. } ACTIVATION_CONTEXT_SECTION_KEYED_DATA_2600, *PACTIVATION_CONTEXT_SECTION_KEYED_DATA_2600;
  2530. typedef const ACTIVATION_CONTEXT_SECTION_KEYED_DATA_2600 *PCACTIVATION_CONTEXT_SECTION_KEYED_DATA_2600;
  2531. typedef struct _ACTIVATION_CONTEXT_SECTION_KEYED_DATA_ASSEMBLY_METADATA {
  2532. struct _ACTIVATION_CONTEXT_DATA_ASSEMBLY_INFORMATION * Information;
  2533. PVOID SectionBase;
  2534. ULONG SectionLength;
  2535. PVOID SectionGlobalDataBase;
  2536. ULONG SectionGlobalDataLength;
  2537. } ACTIVATION_CONTEXT_SECTION_KEYED_DATA_ASSEMBLY_METADATA, *PACTIVATION_CONTEXT_SECTION_KEYED_DATA_ASSEMBLY_METADATA;
  2538. typedef const ACTIVATION_CONTEXT_SECTION_KEYED_DATA_ASSEMBLY_METADATA *PCACTIVATION_CONTEXT_SECTION_KEYED_DATA_ASSEMBLY_METADATA;
  2539. typedef struct _ACTIVATION_CONTEXT_SECTION_KEYED_DATA {
  2540. ULONG Size;
  2541. ULONG DataFormatVersion;
  2542. PVOID Data;
  2543. ULONG Length;
  2544. PVOID SectionGlobalData;
  2545. ULONG SectionGlobalDataLength;
  2546. PVOID SectionBase;
  2547. ULONG SectionTotalLength;
  2548. PACTIVATION_CONTEXT ActivationContext;
  2549. ULONG AssemblyRosterIndex;
  2550. ULONG Flags;
  2551. // 2600 stops here
  2552. ACTIVATION_CONTEXT_SECTION_KEYED_DATA_ASSEMBLY_METADATA AssemblyMetadata;
  2553. } ACTIVATION_CONTEXT_SECTION_KEYED_DATA, *PACTIVATION_CONTEXT_SECTION_KEYED_DATA;
  2554. typedef const ACTIVATION_CONTEXT_SECTION_KEYED_DATA * PCACTIVATION_CONTEXT_SECTION_KEYED_DATA;
  2555. //
  2556. // Flags for the RtlFindActivationContextSection*() APIs
  2557. //
  2558. #define FIND_ACTIVATION_CONTEXT_SECTION_KEY_RETURN_ACTIVATION_CONTEXT (0x00000001)
  2559. #define FIND_ACTIVATION_CONTEXT_SECTION_KEY_RETURN_FLAGS (0x00000002)
  2560. #define FIND_ACTIVATION_CONTEXT_SECTION_KEY_RETURN_ASSEMBLY_METADATA (0x00000004)
  2561. NTSYSAPI
  2562. NTSTATUS
  2563. NTAPI
  2564. RtlFindActivationContextSectionString(
  2565. IN ULONG Flags,
  2566. IN const GUID *ExtensionGuid OPTIONAL,
  2567. IN ULONG SectionId,
  2568. IN PCUNICODE_STRING StringToFind,
  2569. IN OUT PACTIVATION_CONTEXT_SECTION_KEYED_DATA ReturnedData
  2570. );
  2571. NTSYSAPI
  2572. NTSTATUS
  2573. NTAPI
  2574. RtlFindActivationContextSectionGuid(
  2575. IN ULONG Flags,
  2576. IN const GUID *ExtensionGuid OPTIONAL,
  2577. IN ULONG SectionId,
  2578. IN const GUID *GuidToFind,
  2579. IN OUT PACTIVATION_CONTEXT_SECTION_KEYED_DATA ReturnedData
  2580. );
  2581. #define ACTIVATION_CONTEXT_ASSEMBLY_DATA_IS_ROOT_ASSEMBLY (0x00000001)
  2582. typedef struct _ACTIVATION_CONTEXT_ASSEMBLY_DATA {
  2583. ULONG Size;
  2584. ULONG Flags;
  2585. const WCHAR *AssemblyName;
  2586. ULONG AssemblyNameLength; // in bytes
  2587. ULONG HashAlgorithm;
  2588. ULONG PseudoKey;
  2589. } ACTIVATION_CONTEXT_ASSEMBLY_DATA, *PACTIVATION_CONTEXT_ASSEMBLY_DATA;
  2590. typedef const ACTIVATION_CONTEXT_ASSEMBLY_DATA *PCACTIVATION_CONTEXT_ASSEMBLY_DATA;
  2591. NTSYSAPI
  2592. NTSTATUS
  2593. NTAPI
  2594. RtlGetActivationContextAssemblyData(
  2595. IN PCACTIVATION_CONTEXT ActivationContext,
  2596. IN ULONG AssemblyRosterIndex, // note that valid indices are [1 .. AssemblyCount] inclusive
  2597. IN OUT PACTIVATION_CONTEXT_ASSEMBLY_DATA Data
  2598. );
  2599. NTSYSAPI
  2600. NTSTATUS
  2601. NTAPI
  2602. RtlGetActivationContextAssemblyCount(
  2603. IN PCACTIVATION_CONTEXT ActivationContext,
  2604. OUT ULONG *AssemblyCount
  2605. );
  2606. NTSYSAPI
  2607. VOID
  2608. NTAPI
  2609. RtlFreeThreadActivationContextStack(
  2610. VOID
  2611. );
  2612. NTSYSAPI
  2613. NTSTATUS
  2614. NTAPI
  2615. RtlFindFirstActivationContextSection(
  2616. IN OUT PFINDFIRSTACTIVATIONCONTEXTSECTION Context,
  2617. OUT PVOID *Section,
  2618. OUT ULONG *Length,
  2619. OUT PACTIVATION_CONTEXT *ActivationContext OPTIONAL
  2620. );
  2621. NTSYSAPI
  2622. NTSTATUS
  2623. NTAPI
  2624. RtlFindNextActivationContextSection(
  2625. IN OUT PFINDFIRSTACTIVATIONCONTEXTSECTION Context,
  2626. OUT PVOID *Section,
  2627. OUT ULONG *Length,
  2628. OUT PACTIVATION_CONTEXT *ActivationContext OPTIONAL
  2629. );
  2630. NTSYSAPI
  2631. VOID
  2632. NTAPI
  2633. RtlEndFindActivationContextSection(
  2634. IN PFINDFIRSTACTIVATIONCONTEXTSECTION Context
  2635. );
  2636. NTSYSAPI
  2637. NTSTATUS
  2638. NTAPI
  2639. RtlGetActivationContextStack(
  2640. PVOID *Stack
  2641. );
  2642. //
  2643. // RTL_ACTIVATION_CONTEXT_STACK_FRAME
  2644. //
  2645. #define RTL_ACTIVATION_CONTEXT_STACK_FRAME_FLAG_RELEASE_ON_DEACTIVATION (0x00000001)
  2646. #define RTL_ACTIVATION_CONTEXT_STACK_FRAME_FLAG_NO_DEACTIVATE (0x00000002)
  2647. #define RTL_ACTIVATION_CONTEXT_STACK_FRAME_FLAG_ON_FREE_LIST (0x00000004)
  2648. #define RTL_ACTIVATION_CONTEXT_STACK_FRAME_FLAG_HEAP_ALLOCATED (0x00000008)
  2649. #define RTL_ACTIVATION_CONTEXT_STACK_FRAME_FLAG_NOT_REALLY_ACTIVATED (0x00000010)
  2650. #define RTL_ACTIVATION_CONTEXT_STACK_FRAME_FLAG_ACTIVATED (0x00000020)
  2651. #define RTL_ACTIVATION_CONTEXT_STACK_FRAME_FLAG_DEACTIVATED (0x00000040)
  2652. typedef struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME {
  2653. struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME *Previous;
  2654. PACTIVATION_CONTEXT ActivationContext;
  2655. ULONG Flags;
  2656. } RTL_ACTIVATION_CONTEXT_STACK_FRAME, *PRTL_ACTIVATION_CONTEXT_STACK_FRAME;
  2657. typedef const struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME *PCRTL_ACTIVATION_CONTEXT_STACK_FRAME;
  2658. #define RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER (1)
  2659. typedef struct _RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_BASIC {
  2660. SIZE_T Size;
  2661. ULONG Format;
  2662. RTL_ACTIVATION_CONTEXT_STACK_FRAME Frame;
  2663. } RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_BASIC, *PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_BASIC;
  2664. typedef struct _RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED {
  2665. SIZE_T Size;
  2666. ULONG Format;
  2667. RTL_ACTIVATION_CONTEXT_STACK_FRAME Frame;
  2668. PVOID Extra1;
  2669. PVOID Extra2;
  2670. PVOID Extra3;
  2671. PVOID Extra4;
  2672. } RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED, *PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED;
  2673. // Maybe this should be conditionalized, but we have enough trouble debugging FRE builds that
  2674. // we'll use extended stacks always. -mgrier 1/4/2002
  2675. typedef RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME;
  2676. typedef PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME;
  2677. #define INVALID_ACTIVATION_CONTEXT_ACTIVATION_COOKIE ((ULONG_PTR) 0)
  2678. NTSYSAPI
  2679. NTSTATUS
  2680. NTAPI
  2681. RtlActivateActivationContext(
  2682. IN ULONG Flags,
  2683. IN PACTIVATION_CONTEXT ActivationContext,
  2684. OUT ULONG_PTR *Cookie
  2685. );
  2686. #define RTL_ACTIVATE_ACTIVATION_CONTEXT_EX_FLAG_RELEASE_ON_STACK_DEALLOCATION (0x00000001)
  2687. NTSYSAPI
  2688. NTSTATUS
  2689. NTAPI
  2690. RtlActivateActivationContextEx(
  2691. IN ULONG Flags,
  2692. IN PTEB Teb,
  2693. IN PACTIVATION_CONTEXT ActivationContext,
  2694. OUT PULONG_PTR Cookie
  2695. );
  2696. #define RTL_DEACTIVATE_ACTIVATION_CONTEXT_FLAG_FORCE_EARLY_DEACTIVATION (0x00000001)
  2697. NTSYSAPI
  2698. VOID
  2699. NTAPI
  2700. RtlDeactivateActivationContext(
  2701. IN ULONG Flags,
  2702. IN ULONG_PTR Cookie
  2703. );
  2704. NTSYSAPI
  2705. VOID
  2706. FASTCALL
  2707. RtlActivateActivationContextUnsafeFast(
  2708. IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME Frame,
  2709. IN PACTIVATION_CONTEXT ActivationContext
  2710. );
  2711. NTSYSAPI
  2712. VOID
  2713. FASTCALL
  2714. RtlDeactivateActivationContextUnsafeFast(
  2715. IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME Frame
  2716. );
  2717. NTSYSAPI
  2718. VOID
  2719. NTAPI
  2720. RtlPushFrame(
  2721. IN PTEB_ACTIVE_FRAME Frame
  2722. );
  2723. NTSYSAPI
  2724. VOID
  2725. NTAPI
  2726. RtlPopFrame(
  2727. IN PTEB_ACTIVE_FRAME Frame
  2728. );
  2729. NTSYSAPI
  2730. PTEB_ACTIVE_FRAME
  2731. NTAPI
  2732. RtlGetFrame(
  2733. VOID
  2734. );
  2735. NTSYSAPI
  2736. NTSTATUS
  2737. NTAPI
  2738. RtlGetNativeSystemInformation(
  2739. IN ULONG SystemInformationClass,
  2740. IN PVOID NativeSystemInformation,
  2741. IN ULONG InformationLength,
  2742. OUT PULONG ReturnLength OPTIONAL
  2743. );
  2744. NTSTATUS
  2745. RtlQueueApcWow64Thread(
  2746. IN HANDLE ThreadHandle,
  2747. IN PPS_APC_ROUTINE ApcRoutine,
  2748. IN PVOID ApcArgument1,
  2749. IN PVOID ApcArgument2,
  2750. IN PVOID ApcArgument3
  2751. );
  2752. NTSTATUS
  2753. RtlWow64EnableFsRedirection (
  2754. IN BOOLEAN Wow64FsEnableRedirection
  2755. );
  2756. //++
  2757. //
  2758. // ULONG
  2759. // RtlGetCurrentProcessId(
  2760. // VOID
  2761. // );
  2762. //
  2763. //--
  2764. #define RtlGetCurrentProcessId() (HandleToUlong(NtCurrentTeb()->ClientId.UniqueProcess))
  2765. //++
  2766. //
  2767. // ULONG
  2768. // RtlGetCurrentThreadId(
  2769. // VOID
  2770. // );
  2771. //
  2772. //--
  2773. #define RtlGetCurrentThreadId() (HandleToUlong(NtCurrentTeb()->ClientId.UniqueThread))
  2774. typedef BOOLEAN
  2775. (NTAPI *
  2776. PRTL_IS_THREAD_WITHIN_LOADER_CALLOUT)(
  2777. VOID
  2778. );
  2779. BOOLEAN
  2780. NTAPI
  2781. RtlIsThreadWithinLoaderCallout (
  2782. VOID
  2783. );
  2784. typedef LONG
  2785. (NTAPI *
  2786. PRTL_READ_MAPPED_MEMORY_EXCEPTION_FILTER)(
  2787. IN PEXCEPTION_POINTERS ExceptionPointer,
  2788. IN PNTSTATUS ExceptionCode
  2789. );
  2790. LONG
  2791. NTAPI
  2792. RtlReadMappedMemoryExceptionFilter(
  2793. IN PEXCEPTION_POINTERS ExceptionPointer,
  2794. IN PNTSTATUS ExceptionCode
  2795. );
  2796. //
  2797. // Per-thread errormode accessor routines
  2798. //
  2799. // RTL_ERRORMODE_FAILCRITICALERRORS is defined in ntrtl.w
  2800. #define RTL_ERRORMODE_NOGPFAULTERRORBOX (0x0020)
  2801. #define RTL_ERRORMODE_NOOPENFILEERRORBOX (0x0040)
  2802. ULONG
  2803. NTAPI
  2804. RtlGetThreadErrorMode(
  2805. VOID
  2806. );
  2807. NTSTATUS
  2808. NTAPI
  2809. RtlSetThreadErrorMode(
  2810. IN ULONG NewMode,
  2811. OUT PULONG OldMode OPTIONAL
  2812. );
  2813. NTSTATUS
  2814. NTAPI
  2815. RtlSetEnvironmentStrings(
  2816. IN PWCHAR NewEnvironment,
  2817. IN SIZE_T NewEnvironmentSize
  2818. );
  2819. #if defined (_MSC_VER) && ( _MSC_VER >= 800 )
  2820. #if _MSC_VER >= 1200
  2821. #pragma warning(pop)
  2822. #else
  2823. #pragma warning(default:4001)
  2824. #pragma warning(default:4201)
  2825. #pragma warning(default:4214)
  2826. #endif
  2827. #endif
  2828. #ifdef __cplusplus
  2829. } // extern "C"
  2830. #endif
  2831. #endif // _NTURTL_