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.

261 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. initunlo.c
  5. Abstract:
  6. This module contains the code that is very specific to initialization
  7. and unload operations in the irenum driver
  8. Author:
  9. Brian Lieuallen, 7-13-2000
  10. Environment:
  11. Kernel mode
  12. Revision History :
  13. --*/
  14. #include "internal.h"
  15. ULONG DebugFlags;
  16. ULONG DebugMemoryTag='oCrI';
  17. PVOID PagedCodeSectionHandle;
  18. UNICODE_STRING DriverEntryRegPath;
  19. NTSTATUS
  20. DriverEntry(
  21. IN PDRIVER_OBJECT DriverObject,
  22. IN PUNICODE_STRING RegistryPath
  23. );
  24. VOID
  25. IrCommUnload(
  26. IN PDRIVER_OBJECT DriverObject
  27. );
  28. NTSTATUS
  29. UnHandledDispatch(
  30. PDEVICE_OBJECT DeviceObject,
  31. PIRP Irp
  32. );
  33. #pragma alloc_text(INIT,DriverEntry)
  34. #pragma alloc_text(PAGE,IrCommUnload)
  35. NTSTATUS
  36. DriverEntry(
  37. IN PDRIVER_OBJECT DriverObject,
  38. IN PUNICODE_STRING RegistryPath
  39. )
  40. /*++
  41. Routine Description:
  42. The entry point that the system point calls to initialize
  43. any driver.
  44. Arguments:
  45. DriverObject - Just what it says, really of little use
  46. to the driver itself, it is something that the IO system
  47. cares more about.
  48. PathToRegistry - points to the entry for this driver
  49. in the current control set of the registry.
  50. Return Value:
  51. STATUS_SUCCESS if we could initialize a single device,
  52. otherwise STATUS_NO_SUCH_DEVICE.
  53. --*/
  54. {
  55. //
  56. // We use this to query into the registry as to whether we
  57. // should break at driver entry.
  58. //
  59. RTL_QUERY_REGISTRY_TABLE paramTable[4];
  60. ULONG zero = 0;
  61. ULONG debugLevel = 0;
  62. ULONG debugFlags = 0;
  63. ULONG shouldBreak = 0;
  64. D_PNP(DbgPrint("IRCOMM: DriverEntry\n");)
  65. DriverEntryRegPath.Length=RegistryPath->Length;
  66. DriverEntryRegPath.MaximumLength=DriverEntryRegPath.Length+sizeof(WCHAR);
  67. DriverEntryRegPath.Buffer=ALLOCATE_PAGED_POOL(DriverEntryRegPath.MaximumLength);
  68. if (DriverEntryRegPath.Buffer == NULL) {
  69. return STATUS_INSUFFICIENT_RESOURCES;
  70. }
  71. RtlCopyMemory(
  72. DriverEntryRegPath.Buffer,
  73. RegistryPath->Buffer,
  74. RegistryPath->Length
  75. );
  76. //
  77. // NULL terminate the string
  78. //
  79. DriverEntryRegPath.Buffer[RegistryPath->Length/sizeof(WCHAR)]=L'\0';
  80. //
  81. // Since the registry path parameter is a "counted" UNICODE string, it
  82. // might not be zero terminated. For a very short time allocate memory
  83. // to hold the registry path zero terminated so that we can use it to
  84. // delve into the registry.
  85. //
  86. RtlZeroMemory(
  87. &paramTable[0],
  88. sizeof(paramTable)
  89. );
  90. paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
  91. paramTable[0].Name = L"BreakOnEntry";
  92. paramTable[0].EntryContext = &shouldBreak;
  93. paramTable[0].DefaultType = REG_DWORD;
  94. paramTable[0].DefaultData = &zero;
  95. paramTable[0].DefaultLength = sizeof(ULONG);
  96. paramTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
  97. paramTable[1].Name = L"DebugFlags";
  98. paramTable[1].EntryContext = &debugFlags;
  99. paramTable[1].DefaultType = REG_DWORD;
  100. paramTable[1].DefaultData = &zero;
  101. paramTable[1].DefaultLength = sizeof(ULONG);
  102. if (!NT_SUCCESS(RtlQueryRegistryValues(
  103. RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL,
  104. DriverEntryRegPath.Buffer,
  105. &paramTable[0],
  106. NULL,
  107. NULL
  108. ))) {
  109. shouldBreak = 0;
  110. }
  111. #if DBG
  112. DebugFlags=debugFlags;
  113. #endif
  114. if (shouldBreak) {
  115. DbgBreakPoint();
  116. }
  117. //
  118. // pnp driver entry point
  119. //
  120. DriverObject->DriverExtension->AddDevice = IrCommAddDevice;
  121. //
  122. // Initialize the Driver Object with driver's entry points
  123. //
  124. DriverObject->DriverUnload = IrCommUnload;
  125. #if DBG
  126. {
  127. ULONG i;
  128. for (i=0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
  129. DriverObject->MajorFunction[i]=UnHandledDispatch;
  130. }
  131. }
  132. #endif
  133. DriverObject->MajorFunction[IRP_MJ_PNP] = IrCommPnP;
  134. DriverObject->MajorFunction[IRP_MJ_POWER] = IrCommPower;
  135. DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = IrCommWmi;
  136. DriverObject->MajorFunction[IRP_MJ_CREATE] = IrCommCreate;
  137. DriverObject->MajorFunction[IRP_MJ_CLOSE] = IrCommClose;
  138. DriverObject->MajorFunction[IRP_MJ_WRITE] = IrCommWrite;
  139. DriverObject->MajorFunction[IRP_MJ_READ] = IrCommRead;
  140. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IrCommDeviceControl;
  141. DriverObject->MajorFunction[IRP_MJ_CLEANUP] = IrCommCleanup;
  142. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = IrCommQueryInformation;
  143. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = IrCommQueryInformation;
  144. //
  145. // lock and unlock here so we can get a handle to the section
  146. // so future calls will be faster
  147. //
  148. PagedCodeSectionHandle=MmLockPagableCodeSection(IrCommUnload);
  149. MmUnlockPagableImageSection(PagedCodeSectionHandle);
  150. return STATUS_SUCCESS;
  151. }
  152. #if DBG
  153. NTSTATUS
  154. UnHandledDispatch(
  155. PDEVICE_OBJECT DeviceObject,
  156. PIRP Irp
  157. )
  158. {
  159. NTSTATUS Status=STATUS_NOT_SUPPORTED;
  160. PIO_STACK_LOCATION IrpSp=IoGetCurrentIrpStackLocation(Irp);
  161. D_ERROR(DbgPrint("IRCOMM: Unhandled irp mj %x\n",IrpSp->MajorFunction);)
  162. Irp->IoStatus.Status=Status;
  163. Irp->IoStatus.Information=0;
  164. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  165. return Status;
  166. }
  167. #endif
  168. VOID
  169. IrCommUnload(
  170. IN PDRIVER_OBJECT DriverObject
  171. )
  172. {
  173. D_PNP(DbgPrint("IRCOMM: UnLoad\n");)
  174. FREE_POOL(DriverEntryRegPath.Buffer);
  175. return;
  176. }