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.

616 lines
16 KiB

  1. /************************************************************************
  2. * *
  3. * winternl.h -- This module defines the internal NT APIs and data *
  4. * structures that are intended for the use only by internal core *
  5. * Windows components. These APIs and data structures may change *
  6. * at any time. *
  7. * *
  8. * These APIs and data structures are subject to changes from one *
  9. * Windows release to another Windows release. To maintain the *
  10. * compatiblity of your application, avoid using these APIs and *
  11. * data structures. *
  12. * *
  13. * The appropriate mechanism for accessing the functions defined in *
  14. * this header is to use LoadLibrary() for ntdll.dll and *
  15. * GetProcAddress() for the particular function. By using this *
  16. * approach, your application will be more resilient to changes *
  17. * for these functions between Windows releases. If a function *
  18. * prototype does change, then GetProcAddress() for that function *
  19. * might detect the change and fail the function call, which your *
  20. * application will be able to detect. GetProcAddress() may not *
  21. * be able to detect all signature changes, thus avoid using these *
  22. * internal functions. Instead, your application should use the *
  23. * appropriate Win32 function that provides equivalent or similiar *
  24. * functionality. *
  25. * *
  26. * Copyright (c) Microsoft Corp. All rights reserved. *
  27. * *
  28. ************************************************************************/
  29. #ifndef _WINTERNL_
  30. #define _WINTERNL_
  31. #if (_WIN32_WINNT >= 0x0500)
  32. #include <windef.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. //
  37. // The PEB and TEB structures are subject to changes between Windows
  38. // releases, thus the fields offsets may change as well as the Reserved
  39. // fields. The Reserved fields are reserved for use only by the Windows
  40. // operating systems. Do not assume a maximum size for the structures.
  41. //
  42. //
  43. // Instead of using the BeingDebugged field, use the Win32 APIs
  44. // IsDebuggerPresent, CheckRemoteDebuggerPresent
  45. // Instead of using the SessionId field, use the Win32 APIs
  46. // GetCurrentProcessId and ProcessIdToSessionId
  47. // Sample x86 assembly code that gets the SessionId (subject to change
  48. // between Windows releases, use the Win32 APIs to make your application
  49. // resilient to changes)
  50. // mov eax,fs:[00000018]
  51. // mov eax,[eax+0x30]
  52. // mov eax,[eax+0x1d4]
  53. //
  54. typedef struct _PEB {
  55. BYTE Reserved1[2];
  56. BYTE BeingDebugged;
  57. BYTE Reserved2[229];
  58. PVOID Reserved3[59];
  59. ULONG SessionId;
  60. } PEB, *PPEB;
  61. //
  62. // Instead of using the Tls fields, use the Win32 TLS APIs
  63. // TlsAlloc, TlsGetValue, TlsSetValue, TlsFree
  64. //
  65. // Instead of using the ReservedForOle field, use the COM API
  66. // CoGetContextToken
  67. //
  68. typedef struct _TEB {
  69. BYTE Reserved1[1952];
  70. PVOID Reserved2[412];
  71. PVOID TlsSlots[64];
  72. BYTE Reserved3[8];
  73. PVOID Reserved4[26];
  74. PVOID ReservedForOle; // Windows 2000 only
  75. PVOID Reserved5[4];
  76. PVOID TlsExpansionSlots;
  77. } TEB;
  78. typedef TEB *PTEB;
  79. //
  80. // These data structures and type definitions are needed for compilation and
  81. // use of the internal Windows APIs defined in this header.
  82. //
  83. typedef LONG NTSTATUS;
  84. typedef CONST char *PCSZ;
  85. typedef struct _STRING {
  86. USHORT Length;
  87. USHORT MaximumLength;
  88. PCHAR Buffer;
  89. } STRING;
  90. typedef STRING *PSTRING;
  91. typedef STRING ANSI_STRING;
  92. typedef PSTRING PANSI_STRING;
  93. typedef PSTRING PCANSI_STRING;
  94. typedef STRING OEM_STRING;
  95. typedef PSTRING POEM_STRING;
  96. typedef CONST STRING* PCOEM_STRING;
  97. typedef struct _UNICODE_STRING {
  98. USHORT Length;
  99. USHORT MaximumLength;
  100. PWSTR Buffer;
  101. } UNICODE_STRING;
  102. typedef UNICODE_STRING *PUNICODE_STRING;
  103. typedef const UNICODE_STRING *PCUNICODE_STRING;
  104. typedef struct _OBJECT_ATTRIBUTES {
  105. ULONG Length;
  106. HANDLE RootDirectory;
  107. PUNICODE_STRING ObjectName;
  108. ULONG Attributes;
  109. PVOID SecurityDescriptor;
  110. PVOID SecurityQualityOfService;
  111. } OBJECT_ATTRIBUTES;
  112. typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
  113. typedef struct _IO_STATUS_BLOCK {
  114. union {
  115. NTSTATUS Status;
  116. PVOID Pointer;
  117. };
  118. ULONG_PTR Information;
  119. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  120. typedef
  121. VOID
  122. (NTAPI *PIO_APC_ROUTINE) (
  123. IN PVOID ApcContext,
  124. IN PIO_STATUS_BLOCK IoStatusBlock,
  125. IN ULONG Reserved
  126. );
  127. #if defined(_M_IA64)
  128. typedef struct _FRAME_POINTERS {
  129. ULONGLONG MemoryStackFp;
  130. ULONGLONG BackingStoreFp;
  131. } FRAME_POINTERS, *PFRAME_POINTERS;
  132. #define UNWIND_HISTORY_TABLE_SIZE 12
  133. typedef struct _RUNTIME_FUNCTION {
  134. ULONG BeginAddress;
  135. ULONG EndAddress;
  136. ULONG UnwindInfoAddress;
  137. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  138. typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
  139. ULONG64 ImageBase;
  140. ULONG64 Gp;
  141. PRUNTIME_FUNCTION FunctionEntry;
  142. } UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
  143. typedef struct _UNWIND_HISTORY_TABLE {
  144. ULONG Count;
  145. UCHAR Search;
  146. ULONG64 LowAddress;
  147. ULONG64 HighAddress;
  148. UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
  149. } UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
  150. #endif // _M_IA64
  151. typedef struct _PROCESS_BASIC_INFORMATION {
  152. PVOID Reserved1;
  153. PPEB PebBaseAddress;
  154. PVOID Reserved2[2];
  155. ULONG_PTR UniqueProcessId;
  156. PVOID Reserved3;
  157. } PROCESS_BASIC_INFORMATION;
  158. typedef PROCESS_BASIC_INFORMATION *PPROCESS_BASIC_INFORMATION;
  159. typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
  160. LARGE_INTEGER IdleTime;
  161. LARGE_INTEGER KernelTime;
  162. LARGE_INTEGER UserTime;
  163. LARGE_INTEGER Reserved1[2];
  164. ULONG Reserved2;
  165. } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
  166. typedef struct _SYSTEM_PROCESS_INFORMATION {
  167. ULONG NextEntryOffset;
  168. BYTE Reserved1[52];
  169. PVOID Reserved2[3];
  170. HANDLE UniqueProcessId;
  171. PVOID Reserved3;
  172. ULONG HandleCount;
  173. BYTE Reserved4[4];
  174. PVOID Reserved5[11];
  175. SIZE_T PeakPagefileUsage;
  176. SIZE_T PrivatePageCount;
  177. LARGE_INTEGER Reserved6[6];
  178. } SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION;
  179. typedef struct _SYSTEM_REGISTRY_QUOTA_INFORMATION {
  180. ULONG RegistryQuotaAllowed;
  181. ULONG RegistryQuotaUsed;
  182. PVOID Reserved1;
  183. } SYSTEM_REGISTRY_QUOTA_INFORMATION, *PSYSTEM_REGISTRY_QUOTA_INFORMATION;
  184. typedef struct _SYSTEM_BASIC_INFORMATION {
  185. BYTE Reserved1[24];
  186. PVOID Reserved2[4];
  187. CCHAR NumberOfProcessors;
  188. } SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
  189. typedef struct _SYSTEM_TIMEOFDAY_INFORMATION {
  190. BYTE Reserved1[48];
  191. } SYSTEM_TIMEOFDAY_INFORMATION, *PSYSTEM_TIMEOFDAY_INFORMATION;
  192. typedef struct _SYSTEM_PERFORMANCE_INFORMATION {
  193. BYTE Reserved1[312];
  194. } SYSTEM_PERFORMANCE_INFORMATION, *PSYSTEM_PERFORMANCE_INFORMATION;
  195. typedef struct _SYSTEM_EXCEPTION_INFORMATION {
  196. BYTE Reserved1[16];
  197. } SYSTEM_EXCEPTION_INFORMATION, *PSYSTEM_EXCEPTION_INFORMATION;
  198. typedef struct _SYSTEM_LOOKASIDE_INFORMATION {
  199. BYTE Reserved1[32];
  200. } SYSTEM_LOOKASIDE_INFORMATION, *PSYSTEM_LOOKASIDE_INFORMATION;
  201. typedef struct _SYSTEM_INTERRUPT_INFORMATION {
  202. BYTE Reserved1[24];
  203. } SYSTEM_INTERRUPT_INFORMATION, *PSYSTEM_INTERRUPT_INFORMATION;
  204. typedef enum _FILE_INFORMATION_CLASS {
  205. FileDirectoryInformation = 1
  206. } FILE_INFORMATION_CLASS;
  207. typedef enum _PROCESSINFOCLASS {
  208. ProcessBasicInformation = 0,
  209. ProcessWow64Information = 26
  210. } PROCESSINFOCLASS;
  211. typedef enum _THREADINFOCLASS {
  212. ThreadIsIoPending = 16
  213. } THREADINFOCLASS;
  214. typedef enum _SYSTEM_INFORMATION_CLASS {
  215. SystemBasicInformation = 0,
  216. SystemPerformanceInformation = 2,
  217. SystemTimeOfDayInformation = 3,
  218. SystemProcessInformation = 5,
  219. SystemProcessorPerformanceInformation = 8,
  220. SystemInterruptInformation = 23,
  221. SystemExceptionInformation = 33,
  222. SystemRegistryQuotaInformation = 37,
  223. SystemLookasideInformation = 45
  224. } SYSTEM_INFORMATION_CLASS;
  225. #if (_WIN32_WINNT >= 0x0501)
  226. //
  227. // use the WTS API instead
  228. // WTSGetActiveConsoleSessionId
  229. // The active console id is cached as a volatile ULONG in a constant
  230. // memory location. This x86 memory location is subject to changes between
  231. // Windows releases. Use the WTS API to make your application resilient to
  232. // changes.
  233. //
  234. #define INTERNAL_TS_ACTIVE_CONSOLE_ID ( *((volatile ULONG*)(0x7ffe02d8)) )
  235. #endif // (_WIN32_WINNT >= 0x0501)
  236. //
  237. // These functions are intended for use by internal core Windows components
  238. // since these functions may change between Windows releases.
  239. //
  240. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  241. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  242. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  243. //
  244. // use the Win32 API instead
  245. // CloseHandle
  246. //
  247. NTSTATUS
  248. NtClose (
  249. IN HANDLE Handle
  250. );
  251. //
  252. // use the Win32 API instead
  253. // CreateFile
  254. //
  255. NTSTATUS
  256. NtCreateFile (
  257. OUT PHANDLE FileHandle,
  258. IN ACCESS_MASK DesiredAccess,
  259. IN POBJECT_ATTRIBUTES ObjectAttributes,
  260. OUT PIO_STATUS_BLOCK IoStatusBlock,
  261. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  262. IN ULONG FileAttributes,
  263. IN ULONG ShareAccess,
  264. IN ULONG CreateDisposition,
  265. IN ULONG CreateOptions,
  266. IN PVOID EaBuffer OPTIONAL,
  267. IN ULONG EaLength
  268. );
  269. //
  270. // use the Win32 API instead
  271. // CreateFile
  272. //
  273. NTSTATUS
  274. NtOpenFile (
  275. OUT PHANDLE FileHandle,
  276. IN ACCESS_MASK DesiredAccess,
  277. IN POBJECT_ATTRIBUTES ObjectAttributes,
  278. OUT PIO_STATUS_BLOCK IoStatusBlock,
  279. IN ULONG ShareAccess,
  280. IN ULONG OpenOptions
  281. );
  282. //
  283. // use the Win32 API instead
  284. // DeviceIoControl
  285. //
  286. NTSTATUS
  287. NtDeviceIoControlFile (
  288. IN HANDLE FileHandle,
  289. IN HANDLE Event OPTIONAL,
  290. IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
  291. IN PVOID ApcContext OPTIONAL,
  292. OUT PIO_STATUS_BLOCK IoStatusBlock,
  293. IN ULONG IoControlCode,
  294. IN PVOID InputBuffer OPTIONAL,
  295. IN ULONG InputBufferLength,
  296. OUT PVOID OutputBuffer OPTIONAL,
  297. IN ULONG OutputBufferLength
  298. );
  299. //
  300. // use the Win32 API instead
  301. // WaitForSingleObjectEx
  302. //
  303. NTSTATUS
  304. NtWaitForSingleObject (
  305. IN HANDLE Handle,
  306. IN BOOLEAN Alertable,
  307. IN PLARGE_INTEGER Timeout OPTIONAL
  308. );
  309. //
  310. // use the Win32 API instead
  311. // CheckNameLegalDOS8Dot3
  312. //
  313. BOOLEAN
  314. RtlIsNameLegalDOS8Dot3 (
  315. IN PUNICODE_STRING Name,
  316. IN OUT POEM_STRING OemName OPTIONAL,
  317. IN OUT PBOOLEAN NameContainsSpaces OPTIONAL
  318. );
  319. //
  320. // This function might be needed for some of the internal Windows functions,
  321. // defined in this header file.
  322. //
  323. ULONG
  324. RtlNtStatusToDosError (
  325. NTSTATUS Status
  326. );
  327. //
  328. // use the Win32 APIs instead
  329. // GetProcessHandleCount
  330. // GetProcessId
  331. //
  332. NTSTATUS
  333. NtQueryInformationProcess (
  334. IN HANDLE ProcessHandle,
  335. IN PROCESSINFOCLASS ProcessInformationClass,
  336. OUT PVOID ProcessInformation,
  337. IN ULONG ProcessInformationLength,
  338. OUT PULONG ReturnLength OPTIONAL
  339. );
  340. //
  341. // use the Win32 API instead
  342. // GetThreadIOPendingFlag
  343. //
  344. NTSTATUS
  345. NtQueryInformationThread (
  346. IN HANDLE ThreadHandle,
  347. IN THREADINFOCLASS ThreadInformationClass,
  348. OUT PVOID ThreadInformation,
  349. IN ULONG ThreadInformationLength,
  350. OUT PULONG ReturnLength OPTIONAL
  351. );
  352. //
  353. // use the Win32 APIs instead
  354. // GetSystemRegistryQuota
  355. // GetSystemTimes
  356. // use the CryptoAPIs instead for generating random data
  357. // CryptGenRandom
  358. //
  359. NTSTATUS
  360. NtQuerySystemInformation (
  361. IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
  362. OUT PVOID SystemInformation,
  363. IN ULONG SystemInformationLength,
  364. OUT PULONG ReturnLength OPTIONAL
  365. );
  366. //
  367. // use the Win32 API instead
  368. // GetSystemTimeAsFileTime
  369. //
  370. NTSTATUS
  371. NtQuerySystemTime (
  372. OUT PLARGE_INTEGER SystemTime
  373. );
  374. //
  375. // use the Win32 API instead
  376. // LocalFileTimeToFileTime
  377. //
  378. NTSTATUS
  379. RtlLocalTimeToSystemTime (
  380. IN PLARGE_INTEGER LocalTime,
  381. OUT PLARGE_INTEGER SystemTime
  382. );
  383. //
  384. // use the Win32 API instead
  385. // SystemTimeToFileTime to convert to FILETIME structures
  386. // copy the resulting FILETIME structures to ULARGE_INTEGER structures
  387. // perform the calculation
  388. //
  389. BOOLEAN
  390. RtlTimeToSecondsSince1970 (
  391. PLARGE_INTEGER Time,
  392. PULONG ElapsedSeconds
  393. );
  394. //
  395. // These APIs might be need for some of the internal Windows functions,
  396. // defined in this header file.
  397. //
  398. VOID
  399. RtlFreeAnsiString (
  400. PANSI_STRING AnsiString
  401. );
  402. VOID
  403. RtlFreeUnicodeString (
  404. PUNICODE_STRING UnicodeString
  405. );
  406. VOID
  407. RtlFreeOemString(
  408. POEM_STRING OemString
  409. );
  410. VOID
  411. RtlInitString (
  412. PSTRING DestinationString,
  413. PCSZ SourceString
  414. );
  415. VOID
  416. RtlInitAnsiString (
  417. PANSI_STRING DestinationString,
  418. PCSZ SourceString
  419. );
  420. VOID
  421. RtlInitUnicodeString (
  422. PUNICODE_STRING DestinationString,
  423. PCWSTR SourceString
  424. );
  425. NTSTATUS
  426. RtlAnsiStringToUnicodeString (
  427. PUNICODE_STRING DestinationString,
  428. PCANSI_STRING SourceString,
  429. BOOLEAN AllocateDestinationString
  430. );
  431. NTSTATUS
  432. RtlUnicodeStringToAnsiString (
  433. PANSI_STRING DestinationString,
  434. PCUNICODE_STRING SourceString,
  435. BOOLEAN AllocateDestinationString
  436. );
  437. NTSTATUS
  438. RtlUnicodeStringToOemString(
  439. POEM_STRING DestinationString,
  440. PCUNICODE_STRING SourceString,
  441. BOOLEAN AllocateDestinationString
  442. );
  443. //
  444. // Use the Win32 API instead
  445. // WideCharToMultiByte
  446. // set CodePage to CP_ACP
  447. // set cbMultiByte to 0
  448. //
  449. NTSTATUS
  450. RtlUnicodeToMultiByteSize(
  451. PULONG BytesInMultiByteString,
  452. IN PWSTR UnicodeString,
  453. ULONG BytesInUnicodeString
  454. );
  455. //
  456. // Use the C runtime function instead
  457. // strtol
  458. //
  459. NTSTATUS
  460. RtlCharToInteger (
  461. PCSZ String,
  462. ULONG Base,
  463. PULONG Value
  464. );
  465. //
  466. // use the Win32 API instead
  467. // ConvertSidToStringSid
  468. //
  469. NTSTATUS
  470. RtlConvertSidToUnicodeString (
  471. PUNICODE_STRING UnicodeString,
  472. PSID Sid,
  473. BOOLEAN AllocateDestinationString
  474. );
  475. //
  476. // use the CryptoAPIs instead
  477. // CryptGenRandom
  478. //
  479. ULONG
  480. RtlUniform (
  481. PULONG Seed
  482. );
  483. //
  484. // Use the default built-in system exception handling instead of these
  485. // functions
  486. //
  487. VOID
  488. RtlUnwind (
  489. IN PVOID TargetFrame OPTIONAL,
  490. IN PVOID TargetIp OPTIONAL,
  491. IN PEXCEPTION_RECORD ExceptionRecord OPTIONAL,
  492. IN PVOID ReturnValue
  493. );
  494. #if defined(_M_IA64)
  495. VOID
  496. RtlUnwind2 (
  497. IN FRAME_POINTERS TargetFrame OPTIONAL,
  498. IN PVOID TargetIp OPTIONAL,
  499. IN PEXCEPTION_RECORD ExceptionRecord OPTIONAL,
  500. IN PVOID ReturnValue,
  501. IN PCONTEXT ContextRecord
  502. );
  503. VOID
  504. RtlUnwindEx (
  505. IN FRAME_POINTERS TargetFrame OPTIONAL,
  506. IN PVOID TargetIp OPTIONAL,
  507. IN PEXCEPTION_RECORD ExceptionRecord OPTIONAL,
  508. IN PVOID ReturnValue,
  509. IN PCONTEXT ContextRecord,
  510. IN PUNWIND_HISTORY_TABLE HistoryTable OPTIONAL
  511. );
  512. #endif // _M_IA64
  513. #define LOGONID_CURRENT ((ULONG)-1)
  514. #define SERVERNAME_CURRENT ((HANDLE)NULL)
  515. typedef enum _WINSTATIONINFOCLASS {
  516. WinStationInformation = 8
  517. } WINSTATIONINFOCLASS;
  518. typedef struct _WINSTATIONINFORMATIONW {
  519. BYTE Reserved2[70];
  520. ULONG LogonId;
  521. BYTE Reserved3[1140];
  522. } WINSTATIONINFORMATIONW, * PWINSTATIONINFORMATIONW;
  523. //
  524. // this function is implemented in winsta.dll (you need to loadlibrary to call this function)
  525. // this internal function retrives the LogonId (also called SessionId) for the current process
  526. // You should avoid using this function as it can change. you can retrieve the same information
  527. // Using public api WTSQuerySessionInformation. Pass WTSSessionId as the WTSInfoClass parameter
  528. //
  529. typedef BOOLEAN (WINAPI * PWINSTATIONQUERYINFORMATIONW)(
  530. HANDLE, ULONG, WINSTATIONINFOCLASS, PVOID, ULONG, PULONG );
  531. #ifdef __cplusplus
  532. }
  533. #endif
  534. #endif // (_WIN32_WINNT >= 0x0500)
  535. #endif // _WINTERNL_