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.

212 lines
6.1 KiB

  1. #include "precomp.h" // Precompiled header
  2. /****************************************************************************************
  3. * *
  4. * Module: SPX_INIT.C *
  5. * *
  6. * Creation: 27th September 1998 *
  7. * *
  8. * Author: Paul Smith *
  9. * *
  10. * Version: 1.0.0 *
  11. * *
  12. * Description: This module contains the code that load the driver. *
  13. * *
  14. ****************************************************************************************/
  15. #define FILE_ID SPX_INIT_C // File ID for Event Logging see SPX_DEFS.H for values.
  16. // Function Prototypes
  17. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath);
  18. // End function prototypes.
  19. // Paging..
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text(INIT, DriverEntry)
  22. #pragma alloc_text(PAGE, DriverUnload)
  23. #endif
  24. // Gloabal Driver Data
  25. UNICODE_STRING SavedRegistryPath;
  26. #if DBG
  27. ULONG SpxDebugLevel = 0; // Debug level for checked build
  28. #endif
  29. //////////////////////////////////////////////////////////////////////////////////////////
  30. // DriverEntry - Load first and initialises entry points. //
  31. //////////////////////////////////////////////////////////////////////////////////////////
  32. /*
  33. Routine Description:
  34. The entry point that the system point calls to initialize
  35. any driver.
  36. Arguments:
  37. DriverObject - Just what it says, really of little use
  38. to the driver itself, it is something that the IO system
  39. cares more about.
  40. RegistryPath - points to the entry for this driver
  41. in the current control set of the registry.
  42. Return Value:
  43. STATUS_SUCCESS
  44. */
  45. NTSTATUS
  46. DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
  47. {
  48. // Holds status information return by various OS and driver initialization routines.
  49. NTSTATUS status;
  50. // We use this to query into the registry as to whether we should break at driver entry.
  51. RTL_QUERY_REGISTRY_TABLE paramTable[3];
  52. ULONG zero = 0;
  53. ULONG debugLevel = 0;
  54. ULONG shouldBreak = 0;
  55. PWCHAR path = NULL;
  56. PAGED_CODE(); // Macro in checked build to assert if pagable code is run at or above dispatch IRQL
  57. #if DBG
  58. DbgPrint( "%s: In DriverEntry\n", PRODUCT_NAME);
  59. #endif
  60. // Store Registry Path
  61. SavedRegistryPath.MaximumLength = RegistryPath->MaximumLength;
  62. SavedRegistryPath.Length = RegistryPath->Length;
  63. SavedRegistryPath.Buffer = SpxAllocateMem(PagedPool, SavedRegistryPath.MaximumLength);
  64. if(SavedRegistryPath.Buffer)
  65. {
  66. RtlMoveMemory(SavedRegistryPath.Buffer, RegistryPath->Buffer, RegistryPath->Length);
  67. RtlZeroMemory(&paramTable[0], sizeof(paramTable));
  68. paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
  69. paramTable[0].Name = L"BreakOnEntry";
  70. paramTable[0].EntryContext = &shouldBreak;
  71. paramTable[0].DefaultType = REG_DWORD;
  72. paramTable[0].DefaultData = &zero;
  73. paramTable[0].DefaultLength = sizeof(ULONG);
  74. paramTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
  75. paramTable[1].Name = L"DebugLevel";
  76. paramTable[1].EntryContext = &debugLevel;
  77. paramTable[1].DefaultType = REG_DWORD;
  78. paramTable[1].DefaultData = &zero;
  79. paramTable[1].DefaultLength = sizeof(ULONG);
  80. if(!SPX_SUCCESS(status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL,
  81. RegistryPath->Buffer, &paramTable[0],
  82. NULL, NULL)))
  83. {
  84. shouldBreak = 0;
  85. debugLevel = 0;
  86. }
  87. }
  88. else
  89. status = STATUS_INSUFFICIENT_RESOURCES;
  90. #if DBG
  91. SpxDebugLevel = debugLevel;
  92. // SpxDebugLevel = (ULONG)-1; // Prints all debug messages
  93. // shouldBreak = 1; // HARD CODED BREAKPOINT WITH CHECKED BUILD !!!
  94. #endif
  95. if(shouldBreak)
  96. {
  97. DbgBreakPoint(); // Break Debugger.
  98. }
  99. if(SPX_SUCCESS(status))
  100. {
  101. // Initialize the Driver Object with driver's entry points
  102. DriverObject->DriverUnload = DriverUnload;
  103. DriverObject->DriverExtension->AddDevice = Spx_AddDevice;
  104. DriverObject->MajorFunction[IRP_MJ_PNP] = Spx_DispatchPnp;
  105. DriverObject->MajorFunction[IRP_MJ_POWER] = Spx_DispatchPower;
  106. DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = Spx_Flush;
  107. DriverObject->MajorFunction[IRP_MJ_WRITE] = Spx_Write;
  108. DriverObject->MajorFunction[IRP_MJ_READ] = Spx_Read;
  109. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Spx_IoControl;
  110. DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = Spx_InternalIoControl;
  111. DriverObject->MajorFunction[IRP_MJ_CREATE] = Spx_CreateOpen;
  112. DriverObject->MajorFunction[IRP_MJ_CLOSE] = Spx_Close;
  113. DriverObject->MajorFunction[IRP_MJ_CLEANUP] = Spx_Cleanup;
  114. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = Spx_QueryInformationFile;
  115. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = Spx_SetInformationFile;
  116. #ifdef WMI_SUPPORT
  117. DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = Spx_DispatchSystemControl;
  118. #endif
  119. }
  120. else
  121. {
  122. // Free
  123. if(SavedRegistryPath.Buffer)
  124. {
  125. SpxFreeMem(SavedRegistryPath.Buffer);
  126. SavedRegistryPath.Buffer = NULL;
  127. }
  128. }
  129. return(status);
  130. } // DriverEntry
  131. //////////////////////////////////////////////////////////////////////////////////////////
  132. // DriverUnload - Called as driver unloads.
  133. //////////////////////////////////////////////////////////////////////////////////////////
  134. VOID
  135. DriverUnload(IN PDRIVER_OBJECT pDriverObject)
  136. /*++
  137. Routine Description:
  138. This routine cleans up all of the resources allocated in DriverEntry.
  139. Arguments:
  140. pDriverObject - Pointer to the driver object controling all of the
  141. devices.
  142. Return Value:
  143. None.
  144. --*/
  145. {
  146. PAGED_CODE();
  147. SpxDbgMsg(SPX_TRACE_CALLS, ("%s: Entering DriverUnload\n", PRODUCT_NAME));
  148. // All Device Objects must have been deleted by now.
  149. ASSERT (pDriverObject->DeviceObject == NULL);
  150. // Free
  151. if(SavedRegistryPath.Buffer)
  152. {
  153. SpxFreeMem(SavedRegistryPath.Buffer);
  154. SavedRegistryPath.Buffer = NULL;
  155. }
  156. return;
  157. }
  158. // End of SPX_INIT.C