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.

210 lines
6.0 KiB

  1. extern "C" {
  2. #include <ntosp.h>
  3. #include <acpitabl.h>
  4. #include <zwapi.h>
  5. #include <stdio.h>
  6. }
  7. #include "ioctl.h"
  8. PWATCHDOG_TIMER_RESOURCE_TABLE WdTable;
  9. PVOID
  10. PciGetAcpiTable(
  11. void
  12. );
  13. NTSTATUS
  14. CompleteRequest(
  15. PIRP Irp,
  16. NTSTATUS Status,
  17. ULONG_PTR Information
  18. )
  19. {
  20. Irp->IoStatus.Information = Information;
  21. Irp->IoStatus.Status = Status;
  22. IoCompleteRequest( Irp, IO_NO_INCREMENT );
  23. return Status;
  24. }
  25. extern "C"
  26. NTSTATUS
  27. SaTestDeviceControl(
  28. IN PDEVICE_OBJECT DeviceObject,
  29. IN PIRP Irp
  30. )
  31. {
  32. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
  33. NTSTATUS Status = STATUS_SUCCESS;
  34. PVOID OutputBuffer;
  35. ULONG OutputBufferLength;
  36. PSYSTEM_WATCHDOG_TIMER_INFORMATION WdTimerInfo;
  37. ULONG ReturnLength;
  38. KIRQL OldIrql;
  39. if (Irp->MdlAddress) {
  40. OutputBuffer = (PVOID) MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority );
  41. if (OutputBuffer == NULL) {
  42. return CompleteRequest( Irp, STATUS_INSUFFICIENT_RESOURCES, 0 );
  43. }
  44. OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
  45. } else {
  46. OutputBuffer = NULL;
  47. OutputBufferLength = 0;
  48. }
  49. switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
  50. case IOCTL_SATEST_GET_ACPI_TABLE:
  51. if (WdTable == NULL) {
  52. return CompleteRequest( Irp, STATUS_INVALID_PARAMETER, 0 );
  53. }
  54. if (OutputBufferLength < sizeof(WATCHDOG_TIMER_RESOURCE_TABLE)) {
  55. return CompleteRequest( Irp, STATUS_INVALID_PARAMETER, 0 );
  56. }
  57. RtlCopyMemory( OutputBuffer, WdTable, sizeof(WATCHDOG_TIMER_RESOURCE_TABLE) );
  58. return CompleteRequest( Irp, STATUS_SUCCESS, OutputBufferLength );
  59. case IOCTL_SATEST_QUERY_WATCHDOG_TIMER_INFORMATION:
  60. if (OutputBufferLength < sizeof(SYSTEM_WATCHDOG_TIMER_INFORMATION)) {
  61. return CompleteRequest( Irp, STATUS_INVALID_PARAMETER, 0 );
  62. }
  63. WdTimerInfo = (PSYSTEM_WATCHDOG_TIMER_INFORMATION)OutputBuffer;
  64. Status = ZwQuerySystemInformation(
  65. SystemWatchdogTimerInformation,
  66. WdTimerInfo,
  67. sizeof(SYSTEM_WATCHDOG_TIMER_INFORMATION),
  68. &ReturnLength
  69. );
  70. if (NT_SUCCESS(Status)) {
  71. return CompleteRequest( Irp, Status, sizeof(SYSTEM_WATCHDOG_TIMER_INFORMATION) );
  72. }
  73. return CompleteRequest( Irp, Status, 0 );
  74. case IOCTL_SATEST_SET_WATCHDOG_TIMER_INFORMATION:
  75. WdTimerInfo = (PSYSTEM_WATCHDOG_TIMER_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
  76. if (IrpSp->Parameters.DeviceIoControl.InputBufferLength != sizeof(SYSTEM_WATCHDOG_TIMER_INFORMATION)) {
  77. return CompleteRequest( Irp, STATUS_INVALID_PARAMETER, 0 );
  78. }
  79. Status = ZwSetSystemInformation(
  80. SystemWatchdogTimerInformation,
  81. WdTimerInfo,
  82. sizeof(SYSTEM_WATCHDOG_TIMER_INFORMATION)
  83. );
  84. if (NT_SUCCESS(Status)) {
  85. return CompleteRequest( Irp, Status, sizeof(SYSTEM_WATCHDOG_TIMER_INFORMATION) );
  86. }
  87. return CompleteRequest( Irp, Status, 0 );
  88. case IOCTL_SATEST_RAISE_IRQL:
  89. KeRaiseIrql( HIGH_LEVEL, &OldIrql );
  90. return CompleteRequest( Irp, Status, 0 );
  91. default:
  92. return CompleteRequest( Irp, STATUS_INVALID_PARAMETER, 0 );
  93. }
  94. return CompleteRequest( Irp, STATUS_SUCCESS, 0 );
  95. }
  96. extern "C"
  97. VOID
  98. SaTestUnload(
  99. IN PDRIVER_OBJECT DriverObject
  100. )
  101. {
  102. PDEVICE_OBJECT currentDevice = DriverObject->DeviceObject;
  103. UNICODE_STRING fullLinkName;
  104. while (currentDevice) {
  105. RtlInitUnicodeString( &fullLinkName, DOSDEVICE_NAME );
  106. IoDeleteSymbolicLink(&fullLinkName);
  107. IoDeleteDevice(currentDevice);
  108. currentDevice = DriverObject->DeviceObject;
  109. }
  110. }
  111. extern "C"
  112. NTSTATUS
  113. SaTestOpenClose(
  114. IN PDEVICE_OBJECT DeviceObject,
  115. IN PIRP Irp
  116. )
  117. {
  118. NTSTATUS status = STATUS_SUCCESS;
  119. Irp->IoStatus.Status = status;
  120. Irp->IoStatus.Information = 0;
  121. status = Irp->IoStatus.Status;
  122. IoCompleteRequest( Irp, 0 );
  123. return status;
  124. }
  125. extern "C"
  126. NTSTATUS
  127. DriverEntry(
  128. IN PDRIVER_OBJECT DriverObject,
  129. IN PUNICODE_STRING RegistryPath
  130. )
  131. {
  132. NTSTATUS status;
  133. UNICODE_STRING DeviceName;
  134. PDEVICE_OBJECT deviceObject;
  135. UNICODE_STRING LinkObject;
  136. WCHAR LinkName[80];
  137. ULONG DeviceSize;
  138. RtlInitUnicodeString( &DeviceName, DEVICE_NAME );
  139. status = IoCreateDevice(
  140. DriverObject,
  141. 0,
  142. &DeviceName,
  143. FILE_DEVICE_NULL,
  144. 0,
  145. FALSE,
  146. &deviceObject
  147. );
  148. if (!NT_SUCCESS( status )) {
  149. return status;
  150. }
  151. LinkName[0] = UNICODE_NULL;
  152. RtlInitUnicodeString( &LinkObject, LinkName );
  153. LinkObject.MaximumLength = sizeof(LinkName);
  154. RtlAppendUnicodeToString( &LinkObject, L"\\DosDevices" );
  155. DeviceSize = sizeof(L"\\Device") - sizeof(UNICODE_NULL);
  156. DeviceName.Buffer += DeviceSize / sizeof(WCHAR);
  157. DeviceName.Length -= (USHORT)DeviceSize;
  158. RtlAppendUnicodeStringToString( &LinkObject, &DeviceName );
  159. DeviceName.Buffer -= DeviceSize / sizeof(WCHAR);
  160. DeviceName.Length += (USHORT)DeviceSize;
  161. status = IoCreateSymbolicLink( &LinkObject, &DeviceName );
  162. if (!NT_SUCCESS(status)) {
  163. IoDeleteDevice( deviceObject );
  164. return status;
  165. }
  166. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SaTestDeviceControl;
  167. DriverObject->MajorFunction[IRP_MJ_CREATE] = SaTestOpenClose;
  168. DriverObject->MajorFunction[IRP_MJ_CLOSE] = SaTestOpenClose;
  169. DriverObject->DriverUnload = SaTestUnload;
  170. WdTable = (PWATCHDOG_TIMER_RESOURCE_TABLE) PciGetAcpiTable();
  171. return STATUS_SUCCESS;
  172. }