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.

301 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. ntdd.c
  5. Abstract:
  6. This module contains support for standard NT driver initialization.
  7. This module is intended to be included in each WD/TD/PD on a Hydra
  8. system.
  9. Author:
  10. Revision History:
  11. --*/
  12. /*
  13. * Includes
  14. */
  15. #include <ntddk.h>
  16. #include <ntddvdeo.h>
  17. #include <ntddkbd.h>
  18. #include <ntddmou.h>
  19. #include <ntddbeep.h>
  20. #include <winstaw.h>
  21. #include <icadd.h>
  22. #include <sdapi.h>
  23. #include <td.h>
  24. #define DEVICE_NAME_PREFIX L"\\Device\\"
  25. //
  26. // Global data
  27. //
  28. PDEVICE_OBJECT DrvDeviceObject;
  29. //
  30. // External references
  31. //
  32. // This is the name of the WD/TD/PD module we are initializing as.
  33. extern PWCHAR ModuleName;
  34. // This is the stack driver module entry point defined in ntos\citrix\inc\sdapi.h
  35. NTSTATUS
  36. _stdcall
  37. ModuleEntry(
  38. IN OUT PSDCONTEXT pSdContext,
  39. IN BOOLEAN bLoad
  40. );
  41. //
  42. // Forward refrences
  43. //
  44. VOID DrvUnload( PDRIVER_OBJECT );
  45. NTSTATUS
  46. DrvDispatch(
  47. IN PDEVICE_OBJECT DeviceObject,
  48. IN PIRP Irp
  49. );
  50. NTSTATUS
  51. DriverEntry(
  52. IN PDRIVER_OBJECT DriverObject,
  53. IN PUNICODE_STRING RegistryPath
  54. )
  55. /*++
  56. Routine Description:
  57. Standard NT driver entry routine.
  58. Arguments:
  59. DriverObject - NT passed driver object
  60. RegistryPath - Path to driver specific registry entry
  61. Return Value:
  62. NTSTATUS code.
  63. Environment:
  64. Kernel mode, DDK
  65. --*/
  66. {
  67. ULONG i;
  68. NTSTATUS Status;
  69. UNICODE_STRING DeviceName;
  70. PWCHAR NameBuffer;
  71. ULONG NameSize;
  72. PAGED_CODE( );
  73. NameSize = sizeof(DEVICE_NAME_PREFIX) + sizeof(WCHAR);
  74. NameSize += (wcslen(ModuleName) * sizeof(WCHAR));
  75. NameBuffer = IcaStackAllocatePool( NonPagedPool, NameSize );
  76. if( NameBuffer == NULL ) {
  77. return( STATUS_INSUFFICIENT_RESOURCES );
  78. }
  79. wcscpy( NameBuffer, DEVICE_NAME_PREFIX );
  80. wcscat( NameBuffer, ModuleName );
  81. RtlInitUnicodeString( &DeviceName, NameBuffer );
  82. Status = IoCreateDevice(
  83. DriverObject,
  84. 0, // No DeviceExtension
  85. &DeviceName,
  86. FILE_DEVICE_TERMSRV,
  87. 0,
  88. FALSE,
  89. &DrvDeviceObject
  90. );
  91. if( !NT_SUCCESS(Status) ) {
  92. #if DBG
  93. DbgPrint("TD DriverEntry: Could not create Device %wZ, Status 0x%x\n",&DeviceName,Status);
  94. DbgBreakPoint();
  95. #endif
  96. IcaStackFreePool( NameBuffer );
  97. return( Status );
  98. }
  99. DriverObject->DriverUnload = DrvUnload;
  100. DriverObject->FastIoDispatch = NULL;
  101. for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
  102. DriverObject->MajorFunction[i] = DrvDispatch;
  103. }
  104. DrvDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
  105. IcaStackFreePool( NameBuffer );
  106. return( Status );
  107. }
  108. VOID
  109. DrvUnload(
  110. IN PDRIVER_OBJECT DriverObject
  111. )
  112. /*++
  113. Routine Description:
  114. Driver unload routine.
  115. Arguments:
  116. DriverObject - Driver object being unloaded.
  117. Return Value:
  118. None.
  119. Environment:
  120. Kernel mode, DDK
  121. --*/
  122. {
  123. PAGED_CODE( );
  124. IoDeleteDevice( DrvDeviceObject );
  125. return;
  126. }
  127. NTSTATUS
  128. DrvDispatch(
  129. IN PDEVICE_OBJECT DeviceObject,
  130. IN PIRP Irp
  131. )
  132. /*++
  133. Routine Description:
  134. This is the dispatch routine for the driver.
  135. Arguments:
  136. DeviceObject - Pointer to device object for target device
  137. Irp - Pointer to I/O request packet
  138. Return Value:
  139. NTSTATUS -- Indicates whether the request was successfully queued.
  140. Environment:
  141. Kernel mode, DDK
  142. --*/
  143. {
  144. PIO_STACK_LOCATION irpSp;
  145. KIRQL saveIrql;
  146. NTSTATUS Status;
  147. PSD_MODULE_INIT pmi;
  148. DeviceObject; // prevent compiler warnings
  149. irpSp = IoGetCurrentIrpStackLocation( Irp );
  150. switch ( irpSp->MajorFunction ) {
  151. case IRP_MJ_CREATE:
  152. if( Irp->RequestorMode != KernelMode ) {
  153. Status = STATUS_ACCESS_DENIED;
  154. Irp->IoStatus.Status = Status;
  155. IoCompleteRequest( Irp, 0 );
  156. return( Status );
  157. }
  158. Status = STATUS_SUCCESS;
  159. Irp->IoStatus.Status = Status;
  160. IoCompleteRequest( Irp, 0 );
  161. return Status;
  162. case IRP_MJ_INTERNAL_DEVICE_CONTROL:
  163. if( Irp->RequestorMode != KernelMode ) {
  164. Status = STATUS_NOT_IMPLEMENTED;
  165. Irp->IoStatus.Status = Status;
  166. IoCompleteRequest( Irp, 0 );
  167. return( Status );
  168. }
  169. if( irpSp->Parameters.DeviceIoControl.IoControlCode !=
  170. IOCTL_SD_MODULE_INIT ) {
  171. Status = STATUS_NOT_IMPLEMENTED;
  172. Irp->IoStatus.Status = Status;
  173. IoCompleteRequest( Irp, 0 );
  174. return( Status );
  175. }
  176. if( irpSp->Parameters.DeviceIoControl.OutputBufferLength <
  177. sizeof(SD_MODULE_INIT) ) {
  178. Status = STATUS_BUFFER_TOO_SMALL;
  179. Irp->IoStatus.Status = Status;
  180. IoCompleteRequest( Irp, 0 );
  181. return( Status );
  182. }
  183. // Return the SD module entry point.
  184. pmi = (PSD_MODULE_INIT)Irp->UserBuffer;
  185. pmi->SdLoadProc = ModuleEntry;
  186. Status = STATUS_SUCCESS;
  187. Irp->IoStatus.Information = sizeof(SD_MODULE_INIT);
  188. Irp->IoStatus.Status = Status;
  189. IoCompleteRequest( Irp, 0 );
  190. return Status;
  191. case IRP_MJ_CLEANUP:
  192. Status = STATUS_SUCCESS;
  193. Irp->IoStatus.Status = Status;
  194. IoCompleteRequest( Irp, 0 );
  195. return Status;
  196. case IRP_MJ_CLOSE:
  197. Status = STATUS_SUCCESS;
  198. Irp->IoStatus.Status = Status;
  199. IoCompleteRequest( Irp, 0 );
  200. return Status;
  201. default:
  202. Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
  203. IoCompleteRequest( Irp, 0 );
  204. return STATUS_NOT_IMPLEMENTED;
  205. }
  206. }