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.

416 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1991 - 2001 Microsoft Corporation
  3. Module Name:
  4. #### ## # ###### ##### ##### ## # ### ## ## ##
  5. ## ### # ## ## ## ## ### # ### ## ## ##
  6. ## #### # ## ## ## ## #### # ## ## ## ## ##
  7. ## # #### ## ##### ##### # #### ## ## ## #######
  8. ## # ### ## ## #### # ### ####### ## ## ##
  9. ## # ## ## ## ## ## # ## ## ## ## ## ## ##
  10. #### # # ## ##### ## ## # # ## ## ##### ## ## ##
  11. Abstract:
  12. This header contains all definitions that are internal
  13. to the watchdog driver.
  14. Author:
  15. Wesley Witt (wesw) 23-Jan-2002
  16. Environment:
  17. Kernel mode only.
  18. Notes:
  19. --*/
  20. extern "C" {
  21. #include <ntosp.h>
  22. #include <zwapi.h>
  23. #include <mountmgr.h>
  24. #include <mountdev.h>
  25. #include <ntddstor.h>
  26. #include <ntdddisk.h>
  27. #include <acpitabl.h>
  28. #include <stdio.h>
  29. #include <eventmsg.h>
  30. }
  31. #pragma warning(error:4101) // Unreferenced local variable
  32. //
  33. // externs
  34. //
  35. extern ULONG ShutdownCountTime;
  36. extern ULONG RunningCountTime;
  37. extern ULONG WdDebugLevel;
  38. extern ULONG OsMajorVersion;
  39. extern ULONG OsMinorVersion;
  40. extern PWATCHDOG_TIMER_RESOURCE_TABLE WdTable;
  41. //
  42. // Memory allocation
  43. ///
  44. #define WD_POOL_TAG 'tpaS'
  45. #ifdef POOL_TAGGING
  46. #ifdef ExAllocatePool
  47. #undef ExAllocatePool
  48. #endif
  49. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,WD_POOL_TAG)
  50. #endif
  51. //
  52. // General purpose macros
  53. //
  54. #define STRING_SZ(_str) (wcslen((PWSTR)_str)*sizeof(WCHAR))
  55. #define ARRAY_SZ(_ary) (sizeof(_ary)/sizeof(_ary[0]))
  56. #define SecToNano(_sec) (LONGLONG)((_sec) * 1000 * 1000 * 10)
  57. #define NanoToSec(_nano) (ULONG)((_nano) / (1000 * 1000 * 10))
  58. #define CLEARBITS(_val,_mask) ((_val) &= ~(_mask))
  59. #define SETBITS(_val,_mask) ((_val) |= (_mask))
  60. #define MIN_TIMEOUT_VALUE (100)
  61. //
  62. // Control Register Bits
  63. //
  64. #define WATCHDOG_CONTROL_TRIGGER 0x80 // Setting this to 1 causes a new countdown to start
  65. #define WATCHDOG_CONTROL_BIOS_JUMPER 0x08 // Is the timer disabled in the BIOS? (0=false,1=true)
  66. #define WATCHDOG_CONTROL_TIMER_MODE 0x04 // Controls what happens when the timer fires (0=reset,1=shutdown)
  67. #define WATCHDOG_CONTROL_FIRED 0x02 // The timer fired causing the last reboot
  68. #define WATCHDOG_CONTROL_ENABLE 0x01 // Starts/stops the timer
  69. typedef struct _SYSTEM_HEALTH_DATA {
  70. ULONG CpuCount;
  71. LONG HealthyCpuRatio;
  72. LONGLONG TickCountPrevious;
  73. LONGLONG ContextSwitchesPrevious;
  74. PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION ProcInfo;
  75. PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION ProcInfoPrev;
  76. ULONG ProcInfoSize;
  77. LONG ContextSwitchRate;
  78. LONG CPUTime;
  79. LONG ContextCpuRatio;
  80. } SYSTEM_HEALTH_DATA, *PSYSTEM_HEALTH_DATA;
  81. typedef struct _DEVICE_EXTENSION {
  82. PDEVICE_OBJECT DeviceObject;
  83. PDRIVER_OBJECT DriverObject;
  84. PDEVICE_OBJECT TargetObject;
  85. PDEVICE_OBJECT Pdo;
  86. LONG IsStarted;
  87. LONG IsRemoved;
  88. IO_REMOVE_LOCK RemoveLock;
  89. KSPIN_LOCK DeviceLock;
  90. KTIMER Timer;
  91. KDPC TimerDpc;
  92. PULONG ControlRegisterAddress;
  93. PULONG CountRegisterAddress;
  94. ULONG MaxCount;
  95. ULONG DpcTimeout;
  96. ULONG Units;
  97. ULONG HardwareTimeout;
  98. SYSTEM_HEALTH_DATA Health;
  99. ULONG WdState;
  100. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  101. //
  102. // Debug Stuff
  103. //
  104. #define WD_DEBUG_ERROR_LEVEL 0x00000001
  105. #define WD_WARNING_LEVEL 0x00000002
  106. #define WD_DEBUG_TRACE_LEVEL 0x00000004
  107. #define WD_DEBUG_INFO_LEVEL 0x00000008
  108. #define WD_DEBUG_IGNORE_LEVEL 0xffffffff
  109. #if DBG
  110. #define DebugPrint(_X_) WdDebugPrint _X_
  111. #else
  112. #define DebugPrint(_X_)
  113. #endif
  114. #define REPORT_ERROR(_msg_,_status_) \
  115. DebugPrint(( WD_DEBUG_ERROR_LEVEL, "%s [0x%08x]: %s @ %d\n", _msg_, _status_, __FILE__, __LINE__ ))
  116. #define ERROR_RETURN(_msg_,_status_) \
  117. { \
  118. REPORT_ERROR(_msg_,_status_); \
  119. __leave; \
  120. }
  121. #if DBG
  122. VOID
  123. WdDebugPrint(
  124. IN ULONG DebugLevel,
  125. IN PSTR DebugMessage,
  126. IN ...
  127. );
  128. PCHAR
  129. PnPMinorFunctionString(
  130. UCHAR MinorFunction
  131. );
  132. PCHAR
  133. IoctlString(
  134. ULONG IoControlCode
  135. );
  136. PCHAR
  137. PowerMinorFunctionString(
  138. UCHAR MinorFunction
  139. );
  140. PCHAR
  141. PowerSystemStateString(
  142. SYSTEM_POWER_STATE State
  143. );
  144. PCHAR
  145. PowerDeviceStateString(
  146. DEVICE_POWER_STATE State
  147. );
  148. PCHAR
  149. PnPMinorFunctionString(
  150. UCHAR MinorFunction
  151. );
  152. #endif
  153. //
  154. // prototypes
  155. //
  156. extern "C" {
  157. NTSTATUS
  158. DriverEntry(
  159. IN PDRIVER_OBJECT DriverObject,
  160. IN PUNICODE_STRING RegistryPath
  161. );
  162. NTSTATUS
  163. WdPnp(
  164. IN PDEVICE_OBJECT DeviceObject,
  165. IN PIRP Irp
  166. );
  167. NTSTATUS
  168. WdAddDevice(
  169. IN PDRIVER_OBJECT DriverObject,
  170. IN OUT PDEVICE_OBJECT PhysicalDeviceObject
  171. );
  172. NTSTATUS
  173. WdPower(
  174. IN PDEVICE_OBJECT DeviceObject,
  175. IN PIRP Irp
  176. );
  177. NTSTATUS
  178. WdShutdown(
  179. IN PDEVICE_OBJECT DeviceObject,
  180. IN PIRP Irp
  181. );
  182. NTSTATUS
  183. WdSystemControl(
  184. IN PDEVICE_OBJECT DeviceObject,
  185. IN PIRP Irp
  186. );
  187. NTSTATUS
  188. WdDefaultDispatch(
  189. IN PDEVICE_OBJECT DeviceObject,
  190. IN PIRP Irp
  191. );
  192. NTSTATUS
  193. WdHandlerFunction(
  194. IN WATCHDOG_HANDLER_ACTION Action,
  195. IN PVOID Context,
  196. IN OUT PULONG DataValue,
  197. IN BOOLEAN NoLocks
  198. );
  199. } // extern "C"
  200. NTSTATUS
  201. WdInitializeSoftwareTimer(
  202. PDEVICE_EXTENSION DeviceExtension
  203. );
  204. //
  205. // util.cpp
  206. //
  207. VOID
  208. PrintDriverVersion(
  209. IN PDRIVER_OBJECT DriverObject
  210. );
  211. NTSTATUS
  212. CallLowerDriverAndWait(
  213. IN PIRP Irp,
  214. IN PDEVICE_OBJECT TargetObject
  215. );
  216. NTSTATUS
  217. CompleteRequest(
  218. PIRP Irp,
  219. NTSTATUS Status,
  220. ULONG_PTR OutputLength
  221. );
  222. NTSTATUS
  223. ForwardRequest(
  224. IN PIRP Irp,
  225. IN PDEVICE_OBJECT TargetObject
  226. );
  227. NTSTATUS
  228. OpenParametersRegistryKey(
  229. IN PUNICODE_STRING RegistryPath,
  230. IN ULONG AccessMode,
  231. OUT PHANDLE RegistryHandle
  232. );
  233. NTSTATUS
  234. CreateParametersRegistryKey(
  235. IN PUNICODE_STRING RegistryPath,
  236. OUT PHANDLE parametersKey
  237. );
  238. NTSTATUS
  239. ReadRegistryValue(
  240. IN PUNICODE_STRING RegistryPath,
  241. IN PWSTR ValueName,
  242. OUT PKEY_VALUE_FULL_INFORMATION *KeyInformation
  243. );
  244. NTSTATUS
  245. WriteRegistryValue(
  246. IN PUNICODE_STRING RegistryPath,
  247. IN PWSTR ValueName,
  248. IN ULONG RegistryType,
  249. IN PVOID RegistryValue,
  250. IN ULONG RegistryValueLength
  251. );
  252. VOID
  253. GetOsVersion(
  254. VOID
  255. );
  256. NTSTATUS
  257. WdInitializeSystemHealth(
  258. PSYSTEM_HEALTH_DATA Health
  259. );
  260. BOOLEAN
  261. WdCheckSystemHealth(
  262. PSYSTEM_HEALTH_DATA Health
  263. );
  264. NTSTATUS
  265. WriteEventLogEntry (
  266. IN PDEVICE_EXTENSION DeviceExtension,
  267. IN ULONG ErrorCode,
  268. IN PVOID InsertionStrings, OPTIONAL
  269. IN ULONG StringCount, OPTIONAL
  270. IN PVOID DumpData, OPTIONAL
  271. IN ULONG DataSize OPTIONAL
  272. );
  273. ULONG
  274. ConvertTimeoutFromMilliseconds(
  275. IN ULONG Units,
  276. IN ULONG UserTimeout
  277. );
  278. ULONG
  279. ConvertTimeoutToMilliseconds(
  280. IN ULONG Units,
  281. IN ULONG NativeTimeout
  282. );
  283. PVOID
  284. WdGetAcpiTable(
  285. IN ULONG Signature
  286. );
  287. VOID
  288. PingWatchdogTimer(
  289. IN PDEVICE_EXTENSION DeviceExtension,
  290. IN BOOLEAN LockResources
  291. );
  292. void
  293. WdHandlerSetTimeoutValue(
  294. IN PDEVICE_EXTENSION DeviceExtension,
  295. IN ULONG Timeout,
  296. IN BOOLEAN PingTimer
  297. );
  298. ULONG
  299. WdHandlerQueryTimeoutValue(
  300. IN PDEVICE_EXTENSION DeviceExtension
  301. );
  302. void
  303. WdHandlerResetTimer(
  304. IN PDEVICE_EXTENSION DeviceExtension
  305. );
  306. void
  307. WdHandlerStopTimer(
  308. IN PDEVICE_EXTENSION DeviceExtension
  309. );
  310. void
  311. WdHandlerStartTimer(
  312. IN PDEVICE_EXTENSION DeviceExtension
  313. );
  314. void
  315. WdHandlerSetTriggerAction(
  316. IN PDEVICE_EXTENSION DeviceExtension,
  317. IN ULONG TriggerAction
  318. );
  319. ULONG
  320. WdHandlerQueryTriggerAction(
  321. IN PDEVICE_EXTENSION DeviceExtension
  322. );
  323. ULONG
  324. WdHandlerQueryState(
  325. IN PDEVICE_EXTENSION DeviceExtension,
  326. IN BOOLEAN QueryFiredFromDevice
  327. );
  328. void
  329. WdHandlerResetFired(
  330. IN PDEVICE_EXTENSION DeviceExtension
  331. );