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.

384 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. sac.h
  5. Abstract:
  6. This is the local header file for SAC. It includes all other
  7. necessary header files for this driver.
  8. Author:
  9. Sean Selitrennikoff (v-seans) - Jan 11, 1999
  10. Revision History:
  11. --*/
  12. #ifndef _SACP_
  13. #define _SACP_
  14. #pragma warning(disable:4214) // bit field types other than int
  15. #pragma warning(disable:4201) // nameless struct/union
  16. #pragma warning(disable:4127) // condition expression is constant
  17. #pragma warning(disable:4115) // named type definition in parentheses
  18. #pragma warning(disable:4206) // translation unit empty
  19. #pragma warning(disable:4706) // assignment within conditional
  20. #pragma warning(disable:4324) // structure was padded
  21. #pragma warning(disable:4328) // greater alignment than needed
  22. #include <stdio.h>
  23. #include <ntosp.h>
  24. #include <zwapi.h>
  25. #include <hdlsblk.h>
  26. #include <hdlsterm.h>
  27. #include "sacmsg.h"
  28. #ifndef max
  29. #define max(a,b) (((a) > (b)) ? (a) : (b))
  30. #endif
  31. #ifndef min
  32. #define min(a,b) (((a) < (b)) ? (a) : (b))
  33. #endif
  34. //
  35. // Debug spew control
  36. //
  37. #if DBG
  38. extern ULONG SACDebug;
  39. #define SAC_DEBUG_FUNC_TRACE 0x0001
  40. #define SAC_DEBUG_FAILS 0x0004
  41. #define SAC_DEBUG_RECEIVE 0x0008
  42. #define SAC_DEBUG_FUNC_TRACE_LOUD 0x2000 // Warning! This could get loud!
  43. #define SAC_DEBUG_MEM 0x1000 // Warning! This could get loud!
  44. #define IF_SAC_DEBUG(x, y) if ((x) & SACDebug) { y; }
  45. #else
  46. #define IF_SAC_DEBUG(x, y)
  47. #endif
  48. //
  49. // Device name
  50. //
  51. #define SAC_DEVICE_NAME L"\\Device\\SAC"
  52. #define SAC_DOSDEVICE_NAME L"\\DosDevices\\SAC"
  53. //
  54. // Commands
  55. //
  56. #define HELP1_COMMAND_STRING "?"
  57. #define HELP2_COMMAND_STRING "help"
  58. #define CRASH_COMMAND_STRING "crashdump"
  59. #define DUMP_COMMAND_STRING "d"
  60. #define FULLINFO_COMMAND_STRING "f"
  61. #define SETIP_COMMAND_STRING "i"
  62. #define INFORMATION_COMMAND_STRING "id"
  63. #define KILL_COMMAND_STRING "k"
  64. #define LOWER_COMMAND_STRING "l"
  65. #define LIMIT_COMMAND_STRING "m"
  66. #define PAGING_COMMAND_STRING "p"
  67. #define RAISE_COMMAND_STRING "r"
  68. #define REBOOT_COMMAND_STRING "restart"
  69. #define TIME_COMMAND_STRING "s"
  70. #define SHUTDOWN_COMMAND_STRING "shutdown"
  71. #define TLIST_COMMAND_STRING "t"
  72. //
  73. // Device port - a random number :-)
  74. //
  75. #define SAC_PORT_NUMBER 385
  76. //
  77. // Memory tags
  78. //
  79. #define ALLOC_POOL_TAG ((ULONG)'ApcR')
  80. #define FREE_POOL_TAG ((ULONG)'FpcR')
  81. #define INITIAL_POOL_TAG ((ULONG)'IpcR')
  82. #define IRP_POOL_TAG ((ULONG)'JpcR')
  83. #define SECURITY_POOL_TAG ((ULONG)'SpcR')
  84. #define GENERAL_POOL_TAG ((ULONG)'GpcR')
  85. //
  86. // Global data
  87. //
  88. extern BOOLEAN GlobalDataInitialized;
  89. extern BOOLEAN GlobalPagingNeeded;
  90. extern BOOLEAN IoctlSubmitted;
  91. extern LONG ProcessingType;
  92. extern HANDLE SACEventHandle;
  93. extern PKEVENT SACEvent;
  94. extern LONG Attempts;
  95. extern PWSTR MachineInformationBuffer;
  96. extern char* GlobalBuffer;
  97. extern ULONG GlobalBufferSize;
  98. extern PUCHAR Utf8ConversionBuffer;
  99. #define MEMORY_INCREMENT 0x1000
  100. #define DEFAULT_IRP_STACK_SIZE 16
  101. #define DEFAULT_PRIORITY_BOOST 2
  102. #define SAC_SUBMIT_IOCTL 1
  103. #define SAC_PROCESS_INPUT 2
  104. #define SAC_NO_OP 0
  105. #define SAC_RETRY_GAP 10
  106. //
  107. // Context for each device created
  108. //
  109. typedef struct _SAC_DEVICE_CONTEXT {
  110. PDEVICE_OBJECT DeviceObject; // back pointer to the device object.
  111. BOOLEAN InitializedAndReady; // Is this device ready to go?
  112. BOOLEAN Processing; // Is something being processed on this device?
  113. BOOLEAN UnloadDeferred; // Should whoever is processing deal with an unload when done?
  114. CCHAR PriorityBoost; // boost to priority for completions.
  115. PKPROCESS SystemProcess; // context for grabbing handles
  116. PSECURITY_DESCRIPTOR AdminSecurityDescriptor;
  117. KSPIN_LOCK SpinLock; // Used to lock this data structure for access.
  118. KEVENT UnloadEvent; // Used to signal the thread trying to unload to continue processing.
  119. KEVENT ProcessEvent; // Used to signal worker thread to process the next request.
  120. HANDLE ThreadHandle; // Handle for the worker thread.
  121. KTIMER Timer; // Used to poll for user input.
  122. KDPC Dpc; // Used with the above timer.
  123. } SAC_DEVICE_CONTEXT, * PSAC_DEVICE_CONTEXT;
  124. //
  125. // Memory management routines
  126. //
  127. #define ALLOCATE_POOL(b,t) MyAllocatePool( b, t, __FILE__, __LINE__ )
  128. #define FREE_POOL(b) MyFreePool( b )
  129. BOOLEAN
  130. InitializeMemoryManagement(
  131. VOID
  132. );
  133. VOID
  134. FreeMemoryManagement(
  135. VOID
  136. );
  137. PVOID
  138. MyAllocatePool(
  139. IN SIZE_T NumberOfBytes,
  140. IN ULONG Tag,
  141. IN PCHAR FileName,
  142. IN ULONG LineNumber
  143. );
  144. VOID
  145. MyFreePool(
  146. IN PVOID Pointer
  147. );
  148. //
  149. // Initialization routines.
  150. //
  151. BOOLEAN
  152. InitializeGlobalData(
  153. IN PUNICODE_STRING RegistryPath,
  154. IN PDRIVER_OBJECT DriverObject
  155. );
  156. VOID
  157. FreeGlobalData(
  158. VOID
  159. );
  160. BOOLEAN
  161. InitializeDeviceData(
  162. PDEVICE_OBJECT DeviceObject
  163. );
  164. VOID
  165. FreeDeviceData(
  166. PDEVICE_OBJECT DeviceContext
  167. );
  168. //
  169. // Dispatch routines
  170. //
  171. NTSTATUS
  172. Dispatch(
  173. IN PDEVICE_OBJECT DeviceObject,
  174. IN PIRP Irp
  175. );
  176. NTSTATUS
  177. DispatchDeviceControl(
  178. IN PDEVICE_OBJECT DeviceObject,
  179. IN PIRP Irp
  180. );
  181. NTSTATUS
  182. DispatchShutdownControl(
  183. IN PDEVICE_OBJECT DeviceObject,
  184. IN PIRP Irp
  185. );
  186. VOID
  187. UnloadHandler(
  188. IN PDRIVER_OBJECT DriverObject
  189. );
  190. NTSTATUS
  191. DispatchSend(
  192. IN PSAC_DEVICE_CONTEXT DeviceContext
  193. );
  194. VOID
  195. DoDeferred(
  196. IN PSAC_DEVICE_CONTEXT DeviceContext
  197. );
  198. VOID
  199. TimerDpcRoutine(
  200. IN struct _KDPC *Dpc,
  201. IN PVOID DeferredContext,
  202. IN PVOID SystemArgument1,
  203. IN PVOID SystemArgument2
  204. );
  205. //
  206. // Worker thread routines.
  207. //
  208. VOID
  209. WorkerProcessEvents(
  210. IN PSAC_DEVICE_CONTEXT DeviceContext
  211. );
  212. //
  213. // Routines in cmd.c
  214. //
  215. VOID
  216. DoHelpCommand(
  217. VOID
  218. );
  219. VOID
  220. DoKillCommand(
  221. PUCHAR InputLine
  222. );
  223. VOID
  224. DoLowerPriorityCommand(
  225. PUCHAR InputLine
  226. );
  227. VOID
  228. DoRaisePriorityCommand(
  229. PUCHAR InputLine
  230. );
  231. VOID
  232. DoLimitMemoryCommand(
  233. PUCHAR InputLine
  234. );
  235. VOID
  236. DoSetTimeCommand(
  237. PUCHAR InputLine
  238. );
  239. VOID
  240. DoSetIpAddressCommand(
  241. PUCHAR InputLine
  242. );
  243. VOID
  244. DoRebootCommand(
  245. BOOLEAN Reboot
  246. );
  247. VOID
  248. DoCrashCommand(
  249. VOID
  250. );
  251. VOID
  252. DoFullInfoCommand(
  253. VOID
  254. );
  255. VOID
  256. DoPagingCommand(
  257. VOID
  258. );
  259. VOID
  260. DoTlistCommand(
  261. VOID
  262. );
  263. VOID
  264. SubmitIPIoRequest(
  265. );
  266. VOID
  267. CancelIPIoRequest(
  268. );
  269. VOID
  270. DoMachineInformationCommand(
  271. VOID
  272. );
  273. //
  274. // routines in util.c
  275. //
  276. NTSTATUS
  277. PreloadGlobalMessageTable(
  278. PVOID ImageHandle
  279. );
  280. NTSTATUS
  281. TearDownGlobalMessageTable(
  282. VOID
  283. );
  284. PCWSTR
  285. GetMessage(
  286. ULONG MessageId
  287. );
  288. BOOLEAN
  289. SacPutSimpleMessage(
  290. ULONG MessageId
  291. );
  292. BOOLEAN
  293. SacPutUnicodeString(
  294. PCWSTR String
  295. );
  296. VOID
  297. SacPutString(
  298. PUCHAR String
  299. );
  300. VOID
  301. InitializeMachineInformation(
  302. VOID
  303. );
  304. #endif // ndef _SACP_