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.

175 lines
4.2 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Module: ins.h
  4. //
  5. // Description: KS Instance base class definition
  6. //
  7. //
  8. //@@BEGIN_MSINTERNAL
  9. // Development Team:
  10. // Mike McLaughlin
  11. //
  12. // History: Date Author Comment
  13. //
  14. //@@END_MSINTERNAL
  15. //---------------------------------------------------------------------------
  16. //
  17. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  18. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  19. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  20. // PURPOSE.
  21. //
  22. // Copyright (c) 1996-1999 Microsoft Corporation. All Rights Reserved.
  23. //
  24. //---------------------------------------------------------------------------
  25. //---------------------------------------------------------------------------
  26. // Globals
  27. //---------------------------------------------------------------------------
  28. extern "C" const KSDISPATCH_TABLE DispatchTable;
  29. //---------------------------------------------------------------------------
  30. // Classes
  31. //---------------------------------------------------------------------------
  32. typedef class CInstance
  33. {
  34. friend class ListDoubleField<CInstance>;
  35. public:
  36. CInstance(
  37. IN PPARENT_INSTANCE pParentInstance
  38. );
  39. ~CInstance(
  40. );
  41. static NTSTATUS
  42. DispatchClose(
  43. IN PDEVICE_OBJECT pDeviceObject,
  44. IN PIRP pIrp
  45. );
  46. static NTSTATUS
  47. DispatchForwardIrp(
  48. IN PDEVICE_OBJECT pDeviceObject,
  49. IN PIRP pIrp
  50. );
  51. VOID
  52. Invalidate(
  53. );
  54. PFILE_OBJECT
  55. GetNextFileObject(
  56. )
  57. {
  58. return(pNextFileObject);
  59. };
  60. PPIN_INSTANCE
  61. GetParentInstance( // inline body in pins.h
  62. );
  63. NTSTATUS
  64. SetNextFileObject(
  65. HANDLE handle
  66. )
  67. {
  68. //
  69. // SECURITY NOTE:
  70. // This call is OK because the handle comes always from a trusted
  71. // source.
  72. //
  73. return(ObReferenceObjectByHandle(
  74. handle,
  75. GENERIC_READ | GENERIC_WRITE,
  76. NULL,
  77. KernelMode,
  78. (PVOID*)&pNextFileObject,
  79. NULL));
  80. };
  81. NTSTATUS
  82. DispatchCreate(
  83. IN PIRP pIrp,
  84. IN UTIL_PFN pfnDispatchCreate,
  85. IN OUT PVOID pReference,
  86. IN ULONG cCreateItems = 0,
  87. IN PKSOBJECT_CREATE_ITEM pCreateItems = NULL,
  88. IN const KSDISPATCH_TABLE *pDispatchTable = &DispatchTable
  89. );
  90. VOID GrabInstanceMutex()
  91. {
  92. ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
  93. AssertStatus(
  94. KeWaitForMutexObject(pMutex, Executive, KernelMode, FALSE, NULL));
  95. };
  96. VOID ReleaseInstanceMutex()
  97. {
  98. ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
  99. KeReleaseMutex(pMutex, FALSE);
  100. };
  101. private:
  102. VOID
  103. AddList(
  104. CListDouble *pld
  105. )
  106. {
  107. ldiNext.AddList(pld);
  108. };
  109. VOID
  110. RemoveList(
  111. )
  112. {
  113. ldiNext.RemoveList();
  114. };
  115. //
  116. // This pointer to the dispatch table is used in the common
  117. // dispatch routines to route the IRP to the appropriate
  118. // handlers. This structure is referenced by the device driver
  119. // with IoGetCurrentIrpStackLocation( pIrp ) -> FsContext
  120. //
  121. PVOID pObjectHeader;
  122. PFILE_OBJECT pParentFileObject;
  123. PDEVICE_OBJECT pNextDeviceObject;
  124. PPARENT_INSTANCE pParentInstance;
  125. PFILE_OBJECT pNextFileObject;
  126. CLIST_DOUBLE_ITEM ldiNext;
  127. KMUTEX *pMutex;
  128. public:
  129. DefineSignature(0x534e4943); // CINS
  130. } INSTANCE, *PINSTANCE;
  131. //---------------------------------------------------------------------------
  132. typedef ListDoubleField<INSTANCE> LIST_INSTANCE, *PLIST_INSTANCE;
  133. //---------------------------------------------------------------------------
  134. typedef class CParentInstance
  135. {
  136. friend class CInstance;
  137. public:
  138. VOID
  139. Invalidate(
  140. );
  141. BOOL
  142. IsChildInstance(
  143. )
  144. {
  145. return(lstChildInstance.IsLstEmpty());
  146. };
  147. LIST_INSTANCE lstChildInstance;
  148. DefineSignature(0x52415043); // CPAR
  149. } PARENT_INSTANCE, *PPARENT_INSTANCE;
  150. //---------------------------------------------------------------------------