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.

1121 lines
23 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntamd64.w
  5. Abstract:
  6. User mode visible AMD64 specific structures and constants.
  7. Author:
  8. David N. Cutler (davec) 4-May-2000
  9. Revision History:
  10. --*/
  11. #ifndef _NTAMD64_
  12. #define _NTAMD64_
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. // begin_ntddk begin_wdm begin_nthal begin_winnt begin_ntminiport begin_wx86
  20. #if defined(_AMD64_)
  21. // end_ntddk end_wdm end_nthal end_winnt end_ntminiport end_wx86
  22. //
  23. // ?? Values put in ExceptionRecord.ExceptionInformation[0]
  24. // ?? First parameter is always in ExceptionInformation[1],
  25. // ?? Second parameter is always in ExceptionInformation[2]
  26. //
  27. #define BREAKPOINT_BREAK 0
  28. #define BREAKPOINT_PRINT 1
  29. #define BREAKPOINT_PROMPT 2
  30. #define BREAKPOINT_LOAD_SYMBOLS 3
  31. #define BREAKPOINT_UNLOAD_SYMBOLS 4
  32. #define BREAKPOINT_COMMAND_STRING 5
  33. //
  34. // Define AMD64 specific control space.
  35. //
  36. typedef enum _DEBUG_CONTROL_SPACE_ITEM {
  37. DEBUG_CONTROL_SPACE_PCR,
  38. DEBUG_CONTROL_SPACE_PRCB,
  39. DEBUG_CONTROL_SPACE_KSPECIAL,
  40. DEBUG_CONTROL_SPACE_THREAD,
  41. DEBUG_CONTROL_SPACE_MAXIMUM
  42. } DEBUG_CONTROL_SPACE_ITEM;
  43. //
  44. // Define Address of User Shared Data.
  45. //
  46. #define MM_SHARED_USER_DATA_VA 0x7FFE0000
  47. #define USER_SHARED_DATA ((KUSER_SHARED_DATA * const)MM_SHARED_USER_DATA_VA)
  48. //
  49. // Define address of the WOW64 reserved compatibility area.
  50. //
  51. #define WOW64_COMPATIBILITY_AREA_ADDRESS (MM_SHARED_USER_DATA_VA - 0x1000000)
  52. //
  53. // Define address of the system-wide csrss shared section.
  54. //
  55. #define CSR_SYSTEM_SHARED_ADDRESS (WOW64_COMPATIBILITY_AREA_ADDRESS)
  56. // begin_winnt begin_ntddk begin_wdm begin_nthal begin_ntndis begin_ntosp
  57. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  58. //
  59. // Define bit test intrinsics.
  60. //
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. #define BitTest _bittest
  65. #define BitTestAndComplement _bittestandcomplement
  66. #define BitTestAndSet _bittestandset
  67. #define BitTestAndReset _bittestandreset
  68. #define InterlockedBitTestAndSet _interlockedbittestandset
  69. #define InterlockedBitTestAndReset _interlockedbittestandreset
  70. #define BitTest64 _bittest64
  71. #define BitTestAndComplement64 _bittestandcomplement64
  72. #define BitTestAndSet64 _bittestandset64
  73. #define BitTestAndReset64 _bittestandreset64
  74. #define InterlockedBitTestAndSet64 _interlockedbittestandset64
  75. #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
  76. BOOLEAN
  77. _bittest (
  78. IN LONG *Base,
  79. IN LONG Offset
  80. );
  81. BOOLEAN
  82. _bittestandcomplement (
  83. IN LONG *Base,
  84. IN LONG Offset
  85. );
  86. BOOLEAN
  87. _bittestandset (
  88. IN LONG *Base,
  89. IN LONG Offset
  90. );
  91. BOOLEAN
  92. _bittestandreset (
  93. IN LONG *Base,
  94. IN LONG Offset
  95. );
  96. BOOLEAN
  97. _interlockedbittestandset (
  98. IN LONG *Base,
  99. IN LONG Offset
  100. );
  101. BOOLEAN
  102. _interlockedbittestandreset (
  103. IN LONG *Base,
  104. IN LONG Offset
  105. );
  106. BOOLEAN
  107. _bittest64 (
  108. IN LONG64 *Base,
  109. IN LONG64 Offset
  110. );
  111. BOOLEAN
  112. _bittestandcomplement64 (
  113. IN LONG64 *Base,
  114. IN LONG64 Offset
  115. );
  116. BOOLEAN
  117. _bittestandset64 (
  118. IN LONG64 *Base,
  119. IN LONG64 Offset
  120. );
  121. BOOLEAN
  122. _bittestandreset64 (
  123. IN LONG64 *Base,
  124. IN LONG64 Offset
  125. );
  126. BOOLEAN
  127. _interlockedbittestandset64 (
  128. IN LONG64 *Base,
  129. IN LONG64 Offset
  130. );
  131. BOOLEAN
  132. _interlockedbittestandreset64 (
  133. IN LONG64 *Base,
  134. IN LONG64 Offset
  135. );
  136. #pragma intrinsic(_bittest)
  137. #pragma intrinsic(_bittestandcomplement)
  138. #pragma intrinsic(_bittestandset)
  139. #pragma intrinsic(_bittestandreset)
  140. #pragma intrinsic(_interlockedbittestandset)
  141. #pragma intrinsic(_interlockedbittestandreset)
  142. #pragma intrinsic(_bittest64)
  143. #pragma intrinsic(_bittestandcomplement64)
  144. #pragma intrinsic(_bittestandset64)
  145. #pragma intrinsic(_bittestandreset64)
  146. #pragma intrinsic(_interlockedbittestandset64)
  147. #pragma intrinsic(_interlockedbittestandreset64)
  148. //
  149. // Define bit scan intrinsics.
  150. //
  151. #define BitScanForward _BitScanForward
  152. #define BitScanReverse _BitScanReverse
  153. #define BitScanForward64 _BitScanForward64
  154. #define BitScanReverse64 _BitScanReverse64
  155. BOOLEAN
  156. _BitScanForward (
  157. OUT ULONG *Index,
  158. IN ULONG Mask
  159. );
  160. BOOLEAN
  161. _BitScanReverse (
  162. OUT ULONG *Index,
  163. IN ULONG Mask
  164. );
  165. BOOLEAN
  166. _BitScanForward64 (
  167. OUT ULONG *Index,
  168. IN ULONG64 Mask
  169. );
  170. BOOLEAN
  171. _BitScanReverse64 (
  172. OUT ULONG *Index,
  173. IN ULONG64 Mask
  174. );
  175. #pragma intrinsic(_BitScanForward)
  176. #pragma intrinsic(_BitScanReverse)
  177. #pragma intrinsic(_BitScanForward64)
  178. #pragma intrinsic(_BitScanReverse64)
  179. //
  180. // Define function to flush a cache line.
  181. //
  182. #define CacheLineFlush(Address) _mm_clflush(Address)
  183. VOID
  184. _mm_clflush (
  185. PVOID Address
  186. );
  187. #pragma intrinsic(_mm_clflush)
  188. //
  189. // Define memory fence intrinsics
  190. //
  191. #define LoadFence _mm_lfence
  192. #define MemoryFence _mm_mfence
  193. #define StoreFence _mm_sfence
  194. VOID
  195. _mm_lfence (
  196. VOID
  197. );
  198. VOID
  199. _mm_mfence (
  200. VOID
  201. );
  202. VOID
  203. _mm_sfence (
  204. VOID
  205. );
  206. void
  207. _mm_prefetch(
  208. CHAR CONST *a,
  209. int sel
  210. );
  211. /* constants for use with _mm_prefetch */
  212. #define _MM_HINT_T0 1
  213. #define _MM_HINT_T1 2
  214. #define _MM_HINT_T2 3
  215. #define _MM_HINT_NTA 0
  216. #pragma intrinsic(_mm_prefetch)
  217. #pragma intrinsic(_mm_lfence)
  218. #pragma intrinsic(_mm_mfence)
  219. #pragma intrinsic(_mm_sfence)
  220. #define YieldProcessor()
  221. #define MemoryBarrier _mm_mfence
  222. #define PreFetchCacheLine(l, a) _mm_prefetch((CHAR CONST *) a, l)
  223. //
  224. // PreFetchCacheLine level defines.
  225. //
  226. #define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
  227. #define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
  228. //
  229. // Define function to get the caller's EFLAGs value.
  230. //
  231. #define GetCallersEflags() __getcallerseflags()
  232. unsigned __int32
  233. __getcallerseflags (
  234. VOID
  235. );
  236. #pragma intrinsic(__getcallerseflags)
  237. //
  238. // Define function to read the value of the time stamp counter
  239. //
  240. #define ReadTimeStampCounter() __rdtsc()
  241. ULONG64
  242. __rdtsc (
  243. VOID
  244. );
  245. #pragma intrinsic(__rdtsc)
  246. //
  247. // Define functions to move strings as bytes, words, dwords, and qwords.
  248. //
  249. VOID
  250. __movsb (
  251. IN PUCHAR Destination,
  252. IN PUCHAR Source,
  253. IN SIZE_T Count
  254. );
  255. VOID
  256. __movsw (
  257. IN PUSHORT Destination,
  258. IN PUSHORT Source,
  259. IN SIZE_T Count
  260. );
  261. VOID
  262. __movsd (
  263. IN PULONG Destination,
  264. IN PULONG Source,
  265. IN SIZE_T Count
  266. );
  267. VOID
  268. __movsq (
  269. IN PULONGLONG Destination,
  270. IN PULONGLONG Source,
  271. IN SIZE_T Count
  272. );
  273. #pragma intrinsic(__movsb)
  274. #pragma intrinsic(__movsw)
  275. #pragma intrinsic(__movsd)
  276. #pragma intrinsic(__movsq)
  277. //
  278. // Define functions to store strings as bytes, words, dwords, and qwords.
  279. //
  280. VOID
  281. __stosb (
  282. IN PUCHAR Destination,
  283. IN UCHAR Value,
  284. IN SIZE_T Count
  285. );
  286. VOID
  287. __stosw (
  288. IN PUSHORT Destination,
  289. IN USHORT Value,
  290. IN SIZE_T Count
  291. );
  292. VOID
  293. __stosd (
  294. IN PULONG Destination,
  295. IN ULONG Value,
  296. IN SIZE_T Count
  297. );
  298. VOID
  299. __stosq (
  300. IN PULONG64 Destination,
  301. IN ULONG64 Value,
  302. IN SIZE_T Count
  303. );
  304. #pragma intrinsic(__stosb)
  305. #pragma intrinsic(__stosw)
  306. #pragma intrinsic(__stosd)
  307. #pragma intrinsic(__stosq)
  308. //
  309. // Define functions to capture the high 64-bits of a 128-bit multiply.
  310. //
  311. #define MultiplyHigh __mulh
  312. #define UnsignedMultiplyHigh __umulh
  313. LONGLONG
  314. MultiplyHigh (
  315. IN LONGLONG Multiplier,
  316. IN LONGLONG Multiplicand
  317. );
  318. ULONGLONG
  319. UnsignedMultiplyHigh (
  320. IN ULONGLONG Multiplier,
  321. IN ULONGLONG Multiplicand
  322. );
  323. #pragma intrinsic(__mulh)
  324. #pragma intrinsic(__umulh)
  325. //
  326. // Define functions to read and write the uer TEB and the system PCR/PRCB.
  327. //
  328. UCHAR
  329. __readgsbyte (
  330. IN ULONG Offset
  331. );
  332. USHORT
  333. __readgsword (
  334. IN ULONG Offset
  335. );
  336. ULONG
  337. __readgsdword (
  338. IN ULONG Offset
  339. );
  340. ULONG64
  341. __readgsqword (
  342. IN ULONG Offset
  343. );
  344. VOID
  345. __writegsbyte (
  346. IN ULONG Offset,
  347. IN UCHAR Data
  348. );
  349. VOID
  350. __writegsword (
  351. IN ULONG Offset,
  352. IN USHORT Data
  353. );
  354. VOID
  355. __writegsdword (
  356. IN ULONG Offset,
  357. IN ULONG Data
  358. );
  359. VOID
  360. __writegsqword (
  361. IN ULONG Offset,
  362. IN ULONG64 Data
  363. );
  364. #pragma intrinsic(__readgsbyte)
  365. #pragma intrinsic(__readgsword)
  366. #pragma intrinsic(__readgsdword)
  367. #pragma intrinsic(__readgsqword)
  368. #pragma intrinsic(__writegsbyte)
  369. #pragma intrinsic(__writegsword)
  370. #pragma intrinsic(__writegsdword)
  371. #pragma intrinsic(__writegsqword)
  372. #ifdef __cplusplus
  373. }
  374. #endif
  375. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  376. // end_winnt end_ntddk end_wdm end_nthal end_ntndis end_ntosp
  377. // begin_ntddk begin_nthal
  378. //
  379. // Size of kernel mode stack.
  380. //
  381. #define KERNEL_STACK_SIZE 0x6000
  382. //
  383. // Define size of large kernel mode stack for callbacks.
  384. //
  385. #define KERNEL_LARGE_STACK_SIZE 0xf000
  386. //
  387. // Define number of pages to initialize in a large kernel stack.
  388. //
  389. #define KERNEL_LARGE_STACK_COMMIT 0x5000
  390. //
  391. // Define the size of the stack used for processing an MCA exception.
  392. //
  393. #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
  394. // end_ntddk end_nthal
  395. #define DOUBLE_FAULT_STACK_SIZE 0x2000
  396. // begin_nthal
  397. //
  398. // Define stack alignment and rounding values.
  399. //
  400. #define STACK_ALIGN (16UI64)
  401. #define STACK_ROUND (STACK_ALIGN - 1)
  402. //
  403. // Define constants for system IDTs
  404. //
  405. #define MAXIMUM_IDTVECTOR 0xff
  406. #define MAXIMUM_PRIMARY_VECTOR 0xff
  407. #define PRIMARY_VECTOR_BASE 0x30 // 0-2f are AMD64 trap vectors
  408. // begin_winnt begin_ntddk begin_wx86
  409. //
  410. // The following flags control the contents of the CONTEXT structure.
  411. //
  412. #if !defined(RC_INVOKED)
  413. #define CONTEXT_AMD64 0x100000
  414. // end_wx86
  415. #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
  416. #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
  417. #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
  418. #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
  419. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
  420. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
  421. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
  422. // begin_wx86
  423. #endif // !defined(RC_INVOKED)
  424. //
  425. // Define initial MxCsr control.
  426. //
  427. #define INITIAL_MXCSR 0x1f80 // initial MXCSR value
  428. //
  429. // Define 128-bit 16-byte aligned xmm register type.
  430. //
  431. typedef struct DECLSPEC_ALIGN(16) _M128 {
  432. ULONGLONG Low;
  433. LONGLONG High;
  434. } M128, *PM128;
  435. //
  436. // Format of data for fnsave/frstor instructions.
  437. //
  438. // This structure is used to store the legacy floating point state.
  439. //
  440. typedef struct _LEGACY_SAVE_AREA {
  441. USHORT ControlWord;
  442. USHORT Reserved0;
  443. USHORT StatusWord;
  444. USHORT Reserved1;
  445. USHORT TagWord;
  446. USHORT Reserved2;
  447. ULONG ErrorOffset;
  448. USHORT ErrorSelector;
  449. USHORT ErrorOpcode;
  450. ULONG DataOffset;
  451. USHORT DataSelector;
  452. USHORT Reserved3;
  453. UCHAR FloatRegisters[8 * 10];
  454. } LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
  455. #define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
  456. //
  457. // Context Frame
  458. //
  459. // This frame has a several purposes: 1) it is used as an argument to
  460. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  461. // and 3) it is used in the user level thread creation routines.
  462. //
  463. //
  464. // The flags field within this record controls the contents of a CONTEXT
  465. // record.
  466. //
  467. // If the context record is used as an input parameter, then for each
  468. // portion of the context record controlled by a flag whose value is
  469. // set, it is assumed that that portion of the context record contains
  470. // valid context. If the context record is being used to modify a threads
  471. // context, then only that portion of the threads context is modified.
  472. //
  473. // If the context record is used as an output parameter to capture the
  474. // context of a thread, then only those portions of the thread's context
  475. // corresponding to set flags will be returned.
  476. //
  477. // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
  478. //
  479. // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
  480. //
  481. // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
  482. //
  483. // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
  484. //
  485. // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
  486. // Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
  487. //
  488. typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
  489. //
  490. // Register parameter home addresses.
  491. //
  492. ULONG64 P1Home;
  493. ULONG64 P2Home;
  494. ULONG64 P3Home;
  495. ULONG64 P4Home;
  496. ULONG64 P5Home;
  497. ULONG64 P6Home;
  498. //
  499. // Control flags.
  500. //
  501. ULONG ContextFlags;
  502. ULONG MxCsr;
  503. //
  504. // Segment Registers and processor flags.
  505. //
  506. USHORT SegCs;
  507. USHORT SegDs;
  508. USHORT SegEs;
  509. USHORT SegFs;
  510. USHORT SegGs;
  511. USHORT SegSs;
  512. ULONG EFlags;
  513. //
  514. // Debug registers
  515. //
  516. ULONG64 Dr0;
  517. ULONG64 Dr1;
  518. ULONG64 Dr2;
  519. ULONG64 Dr3;
  520. ULONG64 Dr6;
  521. ULONG64 Dr7;
  522. //
  523. // Integer registers.
  524. //
  525. ULONG64 Rax;
  526. ULONG64 Rcx;
  527. ULONG64 Rdx;
  528. ULONG64 Rbx;
  529. ULONG64 Rsp;
  530. ULONG64 Rbp;
  531. ULONG64 Rsi;
  532. ULONG64 Rdi;
  533. ULONG64 R8;
  534. ULONG64 R9;
  535. ULONG64 R10;
  536. ULONG64 R11;
  537. ULONG64 R12;
  538. ULONG64 R13;
  539. ULONG64 R14;
  540. ULONG64 R15;
  541. //
  542. // Program counter.
  543. //
  544. ULONG64 Rip;
  545. //
  546. // MMX/floating point state.
  547. //
  548. M128 Xmm0;
  549. M128 Xmm1;
  550. M128 Xmm2;
  551. M128 Xmm3;
  552. M128 Xmm4;
  553. M128 Xmm5;
  554. M128 Xmm6;
  555. M128 Xmm7;
  556. M128 Xmm8;
  557. M128 Xmm9;
  558. M128 Xmm10;
  559. M128 Xmm11;
  560. M128 Xmm12;
  561. M128 Xmm13;
  562. M128 Xmm14;
  563. M128 Xmm15;
  564. //
  565. // Legacy floating point state.
  566. //
  567. LEGACY_SAVE_AREA FltSave;
  568. ULONG Fill;
  569. //
  570. // Special debug control registers.
  571. //
  572. ULONG64 DebugControl;
  573. ULONG64 LastBranchToRip;
  574. ULONG64 LastBranchFromRip;
  575. ULONG64 LastExceptionToRip;
  576. ULONG64 LastExceptionFromRip;
  577. ULONG64 Fill1;
  578. } CONTEXT, *PCONTEXT;
  579. // end_ntddk end_nthal end_winnt end_wx86
  580. #define CONTEXT_TO_PROGRAM_COUNTER(Context) ((Context)->Rip)
  581. #define PROGRAM_COUNTER_TO_CONTEXT(Context, ProgramCounter) \
  582. ((Context)->Rip = (ProgramCounter))
  583. #define CONTEXT_ALIGN STACK_ALIGN
  584. #define CONTEXT_LENGTH ((sizeof(CONTEXT) + STACK_ROUND) & ~STACK_ROUND)
  585. //
  586. // Nonvolatile context pointer record.
  587. //
  588. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  589. union {
  590. PM128 FloatingContext[16];
  591. struct {
  592. PM128 Xmm0;
  593. PM128 Xmm1;
  594. PM128 Xmm2;
  595. PM128 Xmm3;
  596. PM128 Xmm4;
  597. PM128 Xmm5;
  598. PM128 Xmm6;
  599. PM128 Xmm7;
  600. PM128 Xmm8;
  601. PM128 Xmm9;
  602. PM128 Xmm10;
  603. PM128 Xmm11;
  604. PM128 Xmm12;
  605. PM128 Xmm13;
  606. PM128 Xmm14;
  607. PM128 Xmm15;
  608. };
  609. };
  610. union {
  611. PULONG64 IntegerContext[16];
  612. struct {
  613. PULONG64 Rax;
  614. PULONG64 Rcx;
  615. PULONG64 Rdx;
  616. PULONG64 Rbx;
  617. PULONG64 Rsp;
  618. PULONG64 Rbp;
  619. PULONG64 Rsi;
  620. PULONG64 Rdi;
  621. PULONG64 R8;
  622. PULONG64 R9;
  623. PULONG64 R10;
  624. PULONG64 R11;
  625. PULONG64 R12;
  626. PULONG64 R13;
  627. PULONG64 R14;
  628. PULONG64 R15;
  629. };
  630. };
  631. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  632. // begin_wx86 begin_nthal
  633. //
  634. // GDT selector numbers.
  635. //
  636. // N.B. There is code in context swap that "cleanses" the user segment
  637. // registers ds, es, fs, and gs. If these values are changed or
  638. // added to, then it is very likely the code in context swap will
  639. // have to be change.
  640. //
  641. #define KGDT64_NULL (0 * 16) // NULL descriptor
  642. #define KGDT64_R0_CODE (1 * 16) // kernel mode 64-bit code
  643. #define KGDT64_R0_DATA (1 * 16) + 8 // kernel mode 64-bit data (stack)
  644. #define KGDT64_R3_CMCODE (2 * 16) // user mode 32-bit code
  645. #define KGDT64_R3_DATA (2 * 16) + 8 // user mode 32-bit data
  646. #define KGDT64_R3_CODE (3 * 16) // user mode 64-bit code
  647. #define KGDT64_SYS_TSS (4 * 16) // kernel mode system task state
  648. #define KGDT64_R3_CMTEB (5 * 16) // user mode 32-bit TEB
  649. #define KGDT64_LAST (6 * 16)
  650. #define KGDT_NUMBER KGDT_LAST
  651. // end_wx86 end_nthal
  652. // begin_ntddk begin_wdm begin_nthal
  653. #endif // _AMD64_
  654. // end_ntddk end_wdm end_nthal
  655. //
  656. // Define AMD64 exception handling structures and function prototypes.
  657. //
  658. // Define unwind operation codes.
  659. //
  660. typedef enum _UNWIND_OP_CODES {
  661. UWOP_PUSH_NONVOL = 0,
  662. UWOP_ALLOC_LARGE,
  663. UWOP_ALLOC_SMALL,
  664. UWOP_SET_FPREG,
  665. UWOP_SAVE_NONVOL,
  666. UWOP_SAVE_NONVOL_FAR,
  667. UWOP_SAVE_XMM,
  668. UWOP_SAVE_XMM_FAR,
  669. UWOP_SAVE_XMM128,
  670. UWOP_SAVE_XMM128_FAR,
  671. UWOP_PUSH_MACHFRAME
  672. } UNWIND_OP_CODES, *PUNWIND_OP_CODES;
  673. //
  674. // Define unwind code structure.
  675. //
  676. typedef union _UNWIND_CODE {
  677. struct {
  678. UCHAR CodeOffset;
  679. UCHAR UnwindOp : 4;
  680. UCHAR OpInfo : 4;
  681. };
  682. USHORT FrameOffset;
  683. } UNWIND_CODE, *PUNWIND_CODE;
  684. //
  685. // Define unwind information flags.
  686. //
  687. #define UNW_FLAG_NHANDLER 0x0
  688. #define UNW_FLAG_EHANDLER 0x1
  689. #define UNW_FLAG_UHANDLER 0x2
  690. #define UNW_FLAG_CHAININFO 0x4
  691. //
  692. // Define unwind information structure.
  693. //
  694. typedef struct _UNWIND_INFO {
  695. UCHAR Version : 3;
  696. UCHAR Flags : 5;
  697. UCHAR SizeOfProlog;
  698. UCHAR CountOfCodes;
  699. UCHAR FrameRegister : 4;
  700. UCHAR FrameOffset : 4;
  701. UNWIND_CODE UnwindCode[1];
  702. //
  703. // The unwind codes are followed by an optional DWORD aligned field that
  704. // contains the exception handler address or the address of chained unwind
  705. // information. If an exception handler address is specified, then it is
  706. // followed by the language specified exception handler data.
  707. //
  708. // union {
  709. // ULONG ExceptionHandler;
  710. // ULONG FunctionEntry;
  711. // };
  712. //
  713. // ULONG ExceptionData[];
  714. //
  715. } UNWIND_INFO, *PUNWIND_INFO;
  716. // begin_winnt
  717. //
  718. // Define function table entry - a function table entry is generated for
  719. // each frame function.
  720. //
  721. typedef struct _RUNTIME_FUNCTION {
  722. ULONG BeginAddress;
  723. ULONG EndAddress;
  724. ULONG UnwindData;
  725. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  726. // end_winnt
  727. //
  728. // Scope table structure definition.
  729. //
  730. typedef struct _SCOPE_TABLE {
  731. ULONG Count;
  732. struct
  733. {
  734. ULONG BeginAddress;
  735. ULONG EndAddress;
  736. ULONG HandlerAddress;
  737. ULONG JumpTarget;
  738. } ScopeRecord[1];
  739. } SCOPE_TABLE, *PSCOPE_TABLE;
  740. // begin_winnt
  741. //
  742. // Define dynamic function table entry.
  743. //
  744. typedef
  745. PRUNTIME_FUNCTION
  746. (*PGET_RUNTIME_FUNCTION_CALLBACK) (
  747. IN ULONG64 ControlPc,
  748. IN PVOID Context
  749. );
  750. // end_winnt
  751. typedef enum _FUNCTION_TABLE_TYPE {
  752. RF_SORTED,
  753. RF_UNSORTED,
  754. RF_CALLBACK
  755. } FUNCTION_TABLE_TYPE;
  756. typedef struct _DYNAMIC_FUNCTION_TABLE {
  757. LIST_ENTRY ListEntry;
  758. PRUNTIME_FUNCTION FunctionTable;
  759. LARGE_INTEGER TimeStamp;
  760. ULONG64 MinimumAddress;
  761. ULONG64 MaximumAddress;
  762. ULONG64 BaseAddress;
  763. PGET_RUNTIME_FUNCTION_CALLBACK Callback;
  764. PVOID Context;
  765. PWSTR OutOfProcessCallbackDll;
  766. FUNCTION_TABLE_TYPE Type;
  767. ULONG EntryCount;
  768. } DYNAMIC_FUNCTION_TABLE, *PDYNAMIC_FUNCTION_TABLE;
  769. // begin_winnt
  770. typedef
  771. NTSTATUS
  772. (*POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK) (
  773. IN HANDLE Process,
  774. IN PVOID TableAddress,
  775. OUT PULONG Entries,
  776. OUT PRUNTIME_FUNCTION* Functions
  777. );
  778. #define OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME \
  779. "OutOfProcessFunctionTableCallback"
  780. // end_winnt
  781. //
  782. // Define unwind history table structure.
  783. //
  784. #define UNWIND_HISTORY_TABLE_SIZE 12
  785. typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
  786. ULONG64 ImageBase;
  787. PRUNTIME_FUNCTION FunctionEntry;
  788. } UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
  789. #define UNWIND_HISTORY_TABLE_NONE 0
  790. #define UNWIND_HISTORY_TABLE_GLOBAL 1
  791. #define UNWIND_HISTORY_TABLE_LOCAL 2
  792. typedef struct _UNWIND_HISTORY_TABLE {
  793. ULONG Count;
  794. UCHAR Search;
  795. ULONG64 LowAddress;
  796. ULONG64 HighAddress;
  797. UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
  798. } UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
  799. //
  800. // Define exception dispatch context structure.
  801. //
  802. typedef struct _DISPATCHER_CONTEXT {
  803. ULONG64 ControlPc;
  804. ULONG64 ImageBase;
  805. PRUNTIME_FUNCTION FunctionEntry;
  806. ULONG64 EstablisherFrame;
  807. ULONG64 TargetIp;
  808. PCONTEXT ContextRecord;
  809. PEXCEPTION_ROUTINE LanguageHandler;
  810. PVOID HandlerData;
  811. PUNWIND_HISTORY_TABLE HistoryTable;
  812. } DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
  813. // begin_winnt
  814. //
  815. // Define runtime exception handling prototypes.
  816. //
  817. VOID
  818. RtlRestoreContext (
  819. IN PCONTEXT ContextRecord,
  820. IN struct _EXCEPTION_RECORD *ExceptionRecord OPTIONAL
  821. );
  822. // end_winnt
  823. VOID
  824. RtlInitializeHistoryTable (
  825. VOID
  826. );
  827. PRUNTIME_FUNCTION
  828. RtlLookupFunctionEntry (
  829. IN ULONG64 ControlPc,
  830. OUT PULONG64 ImageBase,
  831. IN OUT PUNWIND_HISTORY_TABLE HistoryTable OPTIONAL
  832. );
  833. PRUNTIME_FUNCTION
  834. RtlLookupFunctionTable (
  835. IN PVOID ControlPc,
  836. OUT PVOID *ImageBase,
  837. OUT PULONG SizeOfTable
  838. );
  839. PLIST_ENTRY
  840. RtlGetFunctionTableListHead (
  841. VOID
  842. );
  843. #if defined(_AMD64_)
  844. // begin_winnt
  845. BOOLEAN
  846. RtlAddFunctionTable (
  847. IN PRUNTIME_FUNCTION FunctionTable,
  848. IN ULONG EntryCount,
  849. IN ULONG64 BaseAddress
  850. );
  851. BOOLEAN
  852. RtlInstallFunctionTableCallback (
  853. IN ULONG64 TableIdentifier,
  854. IN ULONG64 BaseAddress,
  855. IN ULONG Length,
  856. IN PGET_RUNTIME_FUNCTION_CALLBACK Callback,
  857. IN PVOID Context,
  858. IN PCWSTR OutOfProcessCallbackDll OPTIONAL
  859. );
  860. BOOLEAN
  861. RtlDeleteFunctionTable (
  862. IN PRUNTIME_FUNCTION FunctionTable
  863. );
  864. #endif // _AMD64_
  865. // end_winnt
  866. PEXCEPTION_ROUTINE
  867. RtlVirtualUnwind (
  868. IN ULONG HandlerType,
  869. IN ULONG64 ImageBase,
  870. IN ULONG64 ControlPc,
  871. IN PRUNTIME_FUNCTION FunctionEntry,
  872. IN OUT PCONTEXT ContextRecord,
  873. OUT PVOID *HandlerData,
  874. OUT PULONG64 EstablisherFrame,
  875. IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL
  876. );
  877. //
  878. // Define exception filter and termination handler function types.
  879. //
  880. typedef
  881. LONG
  882. (*PEXCEPTION_FILTER) (
  883. struct _EXCEPTION_POINTERS *ExceptionPointers,
  884. PVOID EstablisherFrame
  885. );
  886. typedef
  887. VOID
  888. (*PTERMINATION_HANDLER) (
  889. BOOLEAN AbnormalTermination,
  890. PVOID EstablisherFrame
  891. );
  892. //
  893. // Additional information supplied in QuerySectionInformation for images.
  894. //
  895. #define SECTION_ADDITIONAL_INFO_USED 0
  896. #ifdef __cplusplus
  897. }
  898. #endif
  899. #endif // _NTAMD64_