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.

188 lines
5.4 KiB

  1. /***************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Dot4Usb.sys - Lower Filter Driver for Dot4.sys for USB connected
  5. IEEE 1284.4 devices.
  6. File Name:
  7. Util.c
  8. Abstract:
  9. Misc. Utility functions
  10. Environment:
  11. Kernel mode only
  12. Notes:
  13. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  14. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  16. PURPOSE.
  17. Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
  18. Revision History:
  19. 01/18/2000 : created
  20. ToDo in this file:
  21. - code review and doc
  22. - code review w/Joby
  23. Author(s):
  24. Joby Lafky (JobyL)
  25. Doug Fritz (DFritz)
  26. ****************************************************************************/
  27. #include "pch.h"
  28. /************************************************************************/
  29. /* DispatchPassThrough */
  30. /************************************************************************/
  31. //
  32. // Routine Description:
  33. //
  34. // Default dispatch routine for IRP_MJ_xxx that we don't explicitly
  35. // handle. Pass the request down to the device object below us.
  36. //
  37. // Arguments:
  38. //
  39. // DevObj - pointer to Device Object that is the target of the request
  40. // Irp - pointer to request
  41. //
  42. // Return Value:
  43. //
  44. // NTSTATUS
  45. //
  46. // Log:
  47. // 2000-05-03 Code Reviewed - TomGreen, JobyL, DFritz
  48. //
  49. /************************************************************************/
  50. NTSTATUS
  51. DispatchPassThrough(
  52. IN PDEVICE_OBJECT DevObj,
  53. IN PIRP Irp
  54. )
  55. {
  56. PDEVICE_EXTENSION devExt = DevObj->DeviceExtension;
  57. NTSTATUS status = IoAcquireRemoveLock( &devExt->RemoveLock, Irp );
  58. if( NT_SUCCESS(status) ) {
  59. // RemoveLock acquired, continue with request
  60. IoSkipCurrentIrpStackLocation( Irp );
  61. status = IoCallDriver( devExt->LowerDevObj, Irp );
  62. IoReleaseRemoveLock( &devExt->RemoveLock, Irp );
  63. } else {
  64. // unable to acquire RemoveLock - FAIL request
  65. Irp->IoStatus.Status = status;
  66. IoCompleteRequest( Irp, IO_NO_INCREMENT );
  67. }
  68. return status;
  69. }
  70. /************************************************************************/
  71. /* CallLowerDriverSync */
  72. /************************************************************************/
  73. //
  74. // Routine Description:
  75. //
  76. // Call the driver below us synchronously. When this routine returns
  77. // the calling routine once again owns the IRP.
  78. //
  79. // This routine acquires and holds a RemoveLock against the IRP
  80. // while the IRP is in the possession of drivers below us.
  81. //
  82. // Arguments:
  83. //
  84. // DevObj - pointer to Device Object that is issuing the request
  85. // Irp - pointer to request
  86. //
  87. // Return Value:
  88. //
  89. // NTSTATUS
  90. //
  91. /************************************************************************/
  92. NTSTATUS
  93. CallLowerDriverSync(
  94. IN PDEVICE_OBJECT DevObj,
  95. IN PIRP Irp
  96. )
  97. {
  98. PDEVICE_EXTENSION devExt = DevObj->DeviceExtension;
  99. NTSTATUS status = IoAcquireRemoveLock( &devExt->RemoveLock, Irp );
  100. if( NT_SUCCESS(status) ) {
  101. KEVENT event;
  102. KeInitializeEvent( &event, NotificationEvent, FALSE );
  103. IoSetCompletionRoutine( Irp, CallLowerDriverSyncCompletion, &event, TRUE, TRUE, TRUE );
  104. status = IoCallDriver( devExt->LowerDevObj, Irp );
  105. if( STATUS_PENDING == status ) {
  106. KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL );
  107. status = Irp->IoStatus.Status;
  108. }
  109. IoReleaseRemoveLock( &devExt->RemoveLock, Irp );
  110. } else {
  111. TR_FAIL(("util::CallLowerDriverSync - Couldn't aquire RemoveLock"));
  112. }
  113. return status;
  114. }
  115. /************************************************************************/
  116. /* CallLowerDriverSyncCompletion */
  117. /************************************************************************/
  118. //
  119. // Routine Description:
  120. //
  121. // This is the completion routine for CallLowerDriverSync() that
  122. // simply signals the event and stops the IRP completion from
  123. // unwinding so that CallLowerDriverSync() can regain ownership
  124. // of the IRP.
  125. //
  126. // Arguments:
  127. //
  128. // DevObjOrNULL - Usually, this is this driver's device object.
  129. // However, if this driver created the IRP, then
  130. // there is no stack location in the IRP for this
  131. // driver; so the kernel has no place to store the
  132. // device object; ** so devObj will be NULL in
  133. // this case **.
  134. // Irp - pointer to request
  135. //
  136. // Return Value:
  137. //
  138. // NTSTATUS
  139. //
  140. /************************************************************************/
  141. NTSTATUS
  142. CallLowerDriverSyncCompletion(
  143. IN PDEVICE_OBJECT DevObjOrNULL,
  144. IN PIRP Irp,
  145. IN PVOID Context
  146. )
  147. {
  148. PKEVENT event = Context;
  149. UNREFERENCED_PARAMETER( DevObjOrNULL );
  150. UNREFERENCED_PARAMETER( Irp );
  151. KeSetEvent(event, 0, FALSE);
  152. return STATUS_MORE_PROCESSING_REQUIRED;
  153. }
  154.