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.

261 lines
5.8 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. NTSTATUS
  19. DriverEntry(
  20. IN PDRIVER_OBJECT DriverObject,
  21. IN PUNICODE_STRING RegistryPath
  22. );
  23. VOID
  24. IrCommUnload(
  25. IN PDRIVER_OBJECT DriverObject
  26. );
  27. NTSTATUS
  28. UnHandledDispatch(
  29. PDEVICE_OBJECT DeviceObject,
  30. PIRP Irp
  31. );
  32. #pragma alloc_text(INIT,DriverEntry)
  33. #pragma alloc_text(PAGE,IrCommUnload)
  34. NTSTATUS
  35. DriverEntry(
  36. IN PDRIVER_OBJECT DriverObject,
  37. IN PUNICODE_STRING RegistryPath
  38. )
  39. /*++
  40. Routine Description:
  41. The entry point that the system point calls to initialize
  42. any driver.
  43. Arguments:
  44. DriverObject - Just what it says, really of little use
  45. to the driver itself, it is something that the IO system
  46. cares more about.
  47. PathToRegistry - points to the entry for this driver
  48. in the current control set of the registry.
  49. Return Value:
  50. STATUS_SUCCESS if we could initialize a single device,
  51. otherwise STATUS_NO_SUCH_DEVICE.
  52. --*/
  53. {
  54. //
  55. // We use this to query into the registry as to whether we
  56. // should break at driver entry.
  57. //
  58. UNICODE_STRING DriverEntryRegPath;
  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. FREE_POOL(DriverEntryRegPath.Buffer);
  151. return STATUS_SUCCESS;
  152. }
  153. #if DBG
  154. NTSTATUS
  155. UnHandledDispatch(
  156. PDEVICE_OBJECT DeviceObject,
  157. PIRP Irp
  158. )
  159. {
  160. NTSTATUS Status=STATUS_NOT_SUPPORTED;
  161. PIO_STACK_LOCATION IrpSp=IoGetCurrentIrpStackLocation(Irp);
  162. D_ERROR(DbgPrint("IRCOMM: Unhandled irp mj %x\n",IrpSp->MajorFunction);)
  163. Irp->IoStatus.Status=Status;
  164. Irp->IoStatus.Information=0;
  165. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  166. return Status;
  167. }
  168. #endif
  169. VOID
  170. IrCommUnload(
  171. IN PDRIVER_OBJECT DriverObject
  172. )
  173. {
  174. D_PNP(DbgPrint("IRCOMM: UnLoad\n");)
  175. return;
  176. }