Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.3 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // APC.H - Asynchronous Procedure Call Interface File for Ring 3
  4. //
  5. //-----------------------------------------------------------------------
  6. //
  7. // Author: Mike Toutonghi
  8. // Copyright: 1993 Microsoft
  9. //
  10. //-----------------------------------------------------------------------
  11. // File Description:
  12. // Provides an interface to both USER and KERNEL level APCs under
  13. // Chicago. This file must be kept in sync with APC.INC
  14. //
  15. //-----------------------------------------------------------------------
  16. // Revision History:
  17. // 2/26/93 - created (miketout)
  18. //
  19. //-----------------------------------------------------------------------
  20. #ifdef WOW32_EXTENSIONS
  21. #define AssertSignature(x)
  22. #else // WOW32_EXTENSIONS
  23. #ifdef DEBUG
  24. #define AssertCreate(x, p) ((p)->x##_dwSignature = x##_SIGNATURE)
  25. #define AssertDestroy(x, p) ((p)->x##_dwSignature = 0x44414544)
  26. #define AssertSignature(x) ULONG x##_dwSignature;
  27. #define AssertP(x, p) Assert((p)->x##_dwSignature == x##_SIGNATURE)
  28. #else
  29. #define AssertCreate(x, p)
  30. #define AssertDestroy(x, p)
  31. #define AssertSignature(x)
  32. #define AssertP(x, p)
  33. #endif
  34. #endif // else WOW32_EXTENSIONS
  35. //---------------------------------------------------------------------
  36. // SUPPORT STRUCTURES
  37. //---------------------------------------------------------------------
  38. typedef void (APIENTRY *PAPCFUNC)( DWORD dwParam );
  39. #ifndef PUAPC
  40. typedef struct _userapcrec *PUAPC;
  41. typedef struct _kernelapcrec *PKAPC;
  42. #endif
  43. //
  44. // Structure for a sync APC. Sync APCs are APCs which are
  45. // queueable at interrupt or event time, and synchronize
  46. // a function with the Win32 synchronization objects.
  47. //
  48. // By using a sync APC, interrupt service routines can signal
  49. // Win32 events, decrement semaphores, queue APCs, and set timers.
  50. //
  51. typedef struct _syncapcrec {
  52. PUAPC sar_nextapc; // next APC in list
  53. DWORD sar_dwparam1; // first parameter
  54. DWORD sar_dwparam2; // second parameter for APC
  55. PAPCFUNC sar_apcaddr; // function to invoke
  56. DWORD sar_dwparam3; // third parameter
  57. AssertSignature(SYNCAPCREC)
  58. } SYNCAPCREC;
  59. #define SYNCAPCREC_SIGNATURE 0x20524153
  60. //
  61. // Structure for a user APC
  62. //
  63. typedef struct _userapcrec {
  64. PUAPC uar_nextapc; // next APC in list
  65. DWORD uar_apcstate; // state (APC_DELIVERED)
  66. DWORD uar_dwparam; // parameter for APC
  67. PAPCFUNC uar_apcaddr; // function to invoke
  68. PAPCFUNC uar_apcR0rundown; // call if can't deliver APC
  69. AssertSignature(USERAPCREC)
  70. } USERAPCREC;
  71. #define USERAPCREC_SIGNATURE 0x20524155
  72. // APC state flags
  73. #define APC_DELIVERED 0 // bit set when an APC is delivered
  74. #define APC_DELIVERED_MASK (1 << APC_DELIVERED)
  75. #define APC_FLAG_LAST 0 // last flag
  76. //
  77. // Structure for a kernel APC
  78. //
  79. typedef struct _kernelapcrec {
  80. PKAPC kar_nextapc; // next kernel APC in list
  81. DWORD kar_dwparam; // kernel APC parameter
  82. PAPCFUNC kar_apcaddr; // APC function
  83. PAPCFUNC kar_event; // used if an event is queued for APC
  84. DWORD kar_savedeax; // saved eax for parameter
  85. DWORD kar_savedeip; // eip for same reason as above
  86. WORD kar_savedcs; // saved ring 3 cs to return w/o stk
  87. WORD kar_apcstate; // state (KAR_FLAG...)
  88. AssertSignature(KERNELAPCREC)
  89. } KERNELAPCREC;
  90. #define KERNELAPCREC_SIGNATURE 0x2052414b
  91. // KERNEL APC specific flags
  92. #define KAR_FLAG_BUSY 0
  93. #define KAR_FLAG_BUSY_MASK (1 << KAR_FLAG_BUSY)
  94. #define KAR_FLAG_STATIC (KAR_FLAG_BUSY+1)
  95. #define KAR_FLAG_STATIC_MASK (1 << KAR_FLAG_STATIC)
  96. #define KAR_FLAG_CALLBACK (KAR_FLAG_STATIC+1)
  97. #define KAR_FLAG_CALLBACK_MASK (1 << KAR_FLAG_CALLBACK)
  98. //
  99. // Terminate Process Info structure for local reboot init dialog
  100. //
  101. typedef struct tpi_s {
  102. struct tpi_s *tpi_ptpiNext;
  103. void *tpi_hwnd;
  104. struct _pdb *tpi_ppdb;
  105. struct _tdb *tpi_ptdb;
  106. DWORD tpi_flags;
  107. int tpi_nIndex;
  108. AssertSignature(TPI)
  109. } TPI;
  110. typedef TPI *PTPI;
  111. #define TPI_SIGNATURE 0x20495054
  112. #define TPIF_HUNG 0x00000001
  113. #define TPIF_PROCESSNAME 0x00000002
  114. //
  115. // TerminateThread parameter packet. Allocated at ring 3, passed to
  116. // VxDTerminateThread.
  117. //
  118. typedef struct termdata_s {
  119. struct _tdb *term_ptdb; // thread to terminate
  120. DWORD term_ptcbAPC; // thread to receive user APC
  121. DWORD term_pfnAPC; // user APC function address
  122. DWORD term_hAPC; // handle of kernel APC
  123. DWORD term_htimeout; // handle of time out when nuking
  124. DWORD term_pfrinfo; // force/restore crsts info pointer
  125. AssertSignature(TERMDATA)
  126. } TERMDATA;
  127. typedef TERMDATA *PTERMDATA;
  128. #define TERMDATA_SIGNATURE 0x4d524554
  129. typedef union tpiterm_u {
  130. TERMDATA tpiterm_term;
  131. TPI tpiterm_tpi;
  132. } TPITERM;
  133. //
  134. // Parameter packet used to start a ring 0 thread
  135. //
  136. typedef struct _kernthreadstartdata {
  137. DWORD StartAddress; // start address in ring 3
  138. DWORD dwThreadParam; // parameter for ring 3 startup function
  139. DWORD dwKTStackSize; // ring 3 stack size
  140. DWORD dwCreationFlags; // thread creation flags
  141. DWORD pRing3Event; // set after thread is created
  142. DWORD dwThreadID; // handle for new thread or NULL
  143. DWORD dwErrorCode; // error code if error
  144. } KERNTHREADSTARTDATA;
  145. //
  146. // Parameter packet used to start a ring 0 thread
  147. //
  148. typedef struct _r0startdata {
  149. DWORD R0StartAddress; // start address in ring 0
  150. DWORD dwR0ThreadParam; // parameter for ring 0 startup function
  151. DWORD dwR3StackSize; // ring 3 stack size
  152. DWORD pRing0Event; // set after thread is created
  153. DWORD R0FailCallBack; // or invoke this callback on failure
  154. DWORD dwRing3ThreadID; // ID for thread
  155. DWORD dwRing0ThreadID; // same for ring 0
  156. } R0THREADSTARTDATA;
  157. // include the TDBX structure
  158. #include <tdbx.h>
  159. #ifndef WOW32_EXTENSIONS
  160. typedef VOID (KERNENTRY *PFN_KERNEL_APC)(PVOID);
  161. typedef VOID (KERNENTRY *PFN_USER_APC)(PVOID);
  162. DWORD __cdecl VWIN32_QueueKernelAPC(PFN_KERNEL_APC, DWORD, LPVOID, DWORD);
  163. DWORD __cdecl VWIN32_QueueUserApc(PFN_USER_APC, DWORD, LPVOID);
  164. DWORD __cdecl VWIN32_QueueUserApcEx(PFN_USER_APC, DWORD, LPVOID, LPVOID);
  165. // Queue the kernel or user APC to the kernel services thread.
  166. #define APC_KERNEL_SERVICE_THREAD ((LPVOID)0xFFFFFFFF)
  167. DWORD __cdecl FreeAPCList();
  168. DWORD CancelKernelAPC();
  169. DWORD CancelSuspendAPC();
  170. DWORD __stdcall SuspendAPCHandler(DWORD);
  171. #endif // ndef WOW32_EXTENSIONS