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.

400 lines
7.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Module: util.h
  4. //
  5. // Description:
  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. // Constants and Macros
  27. //---------------------------------------------------------------------------
  28. #ifdef DEBUG
  29. #define DEBUG_FLAGS_OBJECT 0x00000001
  30. #define DEBUG_FLAGS_DEVICE 0x00000002
  31. #define DEBUG_FLAGS_FILTER 0x00000004
  32. #define DEBUG_FLAGS_LOGICAL_FILTER 0x00000008
  33. #define DEBUG_FLAGS_PIN 0x00000010
  34. #define DEBUG_FLAGS_INSTANCE 0x00000020
  35. #define DEBUG_FLAGS_GRAPH 0x00000040
  36. #define DEBUG_FLAGS_TOPOLOGY 0x00000080
  37. #define DEBUG_FLAGS_ADDRESS 0x00000100
  38. #define DEBUG_FLAGS_VERBOSE 0x00000200
  39. #define DEBUG_FLAGS_DETAILS 0x00000400
  40. #endif
  41. #define INTERNAL_WILDCARD ((PKSIDENTIFIER)-1)
  42. #define STATUS_DEAD_END ((NTSTATUS)-1)
  43. //---------------------------------------------------------------------------
  44. // Global Data
  45. //---------------------------------------------------------------------------
  46. extern "C" KMUTEX gMutex;
  47. #ifdef DEBUG
  48. extern ULONG ulDebugFlags;
  49. extern ULONG ulDebugNumber;
  50. #endif
  51. //---------------------------------------------------------------------------
  52. // Data structures
  53. //---------------------------------------------------------------------------
  54. typedef struct dataranges {
  55. KSMULTIPLE_ITEM MultipleItem;
  56. KSDATARANGE aDataRanges[1];
  57. } DATARANGES, *PDATARANGES;
  58. typedef struct identifiers {
  59. KSMULTIPLE_ITEM MultipleItem;
  60. KSIDENTIFIER aIdentifiers[1]; // Array of identifiers
  61. } IDENTIFIERS, *PIDENTIFIERS;
  62. typedef class CQueueWorkListData : public CObj
  63. {
  64. public:
  65. void * __cdecl operator new(size_t size)
  66. {
  67. return(ExAllocatePoolWithTag(NonPagedPool, size, 0x41535953));
  68. };
  69. void __cdecl operator delete(void *p)
  70. {
  71. ExFreePool(p);
  72. };
  73. CQueueWorkListData(
  74. NTSTATUS (*Function)(PVOID Reference1, PVOID Reference2),
  75. PVOID Reference1,
  76. PVOID Reference2
  77. );
  78. NTSTATUS
  79. QueueAsyncList(
  80. );
  81. static VOID
  82. AsyncWorker(
  83. IN OUT PVOID pReference
  84. );
  85. #ifdef DEBUG
  86. ENUMFUNC
  87. Dump(
  88. )
  89. {
  90. dprintf("CKPD: %08x PFN %08x R1 %08x R2 %08x\n",
  91. this,
  92. Function,
  93. Reference1,
  94. Reference2);
  95. return (STATUS_CONTINUE);
  96. };
  97. #endif
  98. private:
  99. LIST_ENTRY leNext;
  100. NTSTATUS (*Function)(PVOID, PVOID);
  101. PVOID Reference1;
  102. PVOID Reference2;
  103. DefineSignature(0x444c5751); // QWLD
  104. } QUEUE_WORK_LIST_DATA, *PQUEUE_WORK_LIST_DATA;
  105. //---------------------------------------------------------------------------
  106. typedef NTSTATUS (*UTIL_PFN)(PVOID, PVOID);
  107. //---------------------------------------------------------------------------
  108. // Inline helper functions
  109. //---------------------------------------------------------------------------
  110. __inline int IsEqualGUID(const GUID *lpguid1, const GUID *lpguid2)
  111. {
  112. return !memcmp(lpguid1, lpguid2, sizeof(GUID));
  113. }
  114. __inline VOID GrabMutex()
  115. {
  116. ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
  117. #ifdef DEBUG
  118. LARGE_INTEGER li = {0, 600000000};
  119. NTSTATUS Status;
  120. while(Status = KeWaitForMutexObject(
  121. &gMutex,
  122. Executive,
  123. KernelMode,
  124. FALSE,
  125. &li) == STATUS_TIMEOUT) {
  126. dprintf("SYSAUDIO: possible deadlock - thread %08x\n",
  127. KeGetCurrentThread());
  128. }
  129. #else
  130. KeWaitForMutexObject(&gMutex, Executive, KernelMode, FALSE, NULL);
  131. #endif
  132. }
  133. __inline VOID ReleaseMutex()
  134. {
  135. ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
  136. KeReleaseMutex(&gMutex, FALSE);
  137. }
  138. //---------------------------------------------------------------------------
  139. // Local prototypes
  140. //---------------------------------------------------------------------------
  141. extern "C" {
  142. NTSTATUS
  143. InitializeUtil(
  144. );
  145. VOID
  146. UninitializeUtil(
  147. );
  148. VOID
  149. UninitializeMemory(
  150. );
  151. NTSTATUS
  152. DispatchInvalidDeviceRequest(
  153. IN PDEVICE_OBJECT pdo,
  154. IN PIRP pIrp
  155. );
  156. BOOLEAN
  157. DispatchFastIoDeviceControlFailure(
  158. IN PFILE_OBJECT FileObject,
  159. IN BOOLEAN Wait,
  160. IN PVOID InputBuffer OPTIONAL,
  161. IN ULONG InputBufferLength,
  162. OUT PVOID OutputBuffer OPTIONAL,
  163. IN ULONG OutputBufferLength,
  164. IN ULONG IoControlCode,
  165. OUT PIO_STATUS_BLOCK IoStatus,
  166. IN PDEVICE_OBJECT DeviceObject
  167. );
  168. BOOLEAN
  169. DispatchFastReadFailure(
  170. IN PFILE_OBJECT FileObject,
  171. IN PLARGE_INTEGER FileOffset,
  172. IN ULONG Length,
  173. IN BOOLEAN Wait,
  174. IN ULONG LockKey,
  175. OUT PVOID Buffer,
  176. OUT PIO_STATUS_BLOCK IoStatus,
  177. IN PDEVICE_OBJECT DeviceObject
  178. );
  179. #define DispatchFastWriteFailure DispatchFastReadFailure
  180. CompareDataRange(
  181. PKSDATARANGE pDataRange1,
  182. PKSDATARANGE pDataRange2
  183. );
  184. BOOL
  185. DataIntersectionRange(
  186. PKSDATARANGE pDataRange1,
  187. PKSDATARANGE pDataRange2,
  188. PKSDATARANGE pDataRangeIntersection
  189. );
  190. BOOL
  191. DataIntersectionAudio(
  192. PKSDATARANGE_AUDIO pDataRangeAudio1,
  193. PKSDATARANGE_AUDIO pDataRangeAudio2,
  194. PKSDATARANGE_AUDIO pDataRangeAudioIntersection
  195. );
  196. BOOL
  197. CompareDataRangeExact(
  198. PKSDATARANGE pDataRange1,
  199. PKSDATARANGE pDataRange2
  200. );
  201. BOOL
  202. CompareDataRangeGuids(
  203. PKSDATARANGE pDataRange1,
  204. PKSDATARANGE pDataRange2
  205. );
  206. BOOL
  207. CompareIdentifier(
  208. PKSIDENTIFIER pIdentifier1,
  209. PKSIDENTIFIER pIdentifier2
  210. );
  211. void
  212. ModifyPinConnect(
  213. PKSPIN_CONNECT pPinConnect,
  214. WORD nChannels
  215. );
  216. BOOL
  217. WaveFormatExtensibleToWaveFormat(
  218. PKSPIN_CONNECT pPinConnect
  219. );
  220. NTSTATUS
  221. OpenDevice(
  222. IN PWSTR pwstrDevice,
  223. OUT PHANDLE pHandle
  224. );
  225. NTSTATUS
  226. GetPinProperty(
  227. PFILE_OBJECT pFileObject,
  228. ULONG PropertyId,
  229. ULONG PinId,
  230. ULONG cbProperty,
  231. PVOID pProperty
  232. );
  233. NTSTATUS
  234. PinConnectionProperty(
  235. PFILE_OBJECT pFileObject,
  236. ULONG ulPropertyId,
  237. ULONG ulFlags,
  238. ULONG cbProperty,
  239. PVOID pProperty
  240. );
  241. NTSTATUS
  242. GetPinPropertyEx(
  243. PFILE_OBJECT pFileObject,
  244. ULONG PropertyId,
  245. ULONG PinId,
  246. PVOID *ppProperty
  247. );
  248. NTSTATUS
  249. GetPinProperty2(
  250. PFILE_OBJECT pFileObject,
  251. ULONG ulPropertyId,
  252. ULONG ulPinId,
  253. ULONG cbInput,
  254. PVOID pInputData,
  255. PVOID *ppPropertyOutput
  256. );
  257. NTSTATUS
  258. GetProperty(
  259. PFILE_OBJECT pFileObject,
  260. CONST GUID *pguidPropertySet,
  261. ULONG ulPropertyId,
  262. ULONG cbInput,
  263. PVOID pInputData,
  264. PVOID *ppPropertyOutput
  265. );
  266. NTSTATUS
  267. QueueWorkList(
  268. IN NTSTATUS (*Function)(PVOID Reference1, PVOID Reference2),
  269. IN PVOID Reference1,
  270. IN PVOID Reference2
  271. );
  272. VOID
  273. GetDefaultOrder(
  274. ULONG fulType,
  275. PULONG pulOrder
  276. );
  277. NTSTATUS
  278. SetKsFrameHolding(
  279. PFILE_OBJECT pFileObject
  280. );
  281. //---------------------------------------------------------------------------
  282. #ifdef DEBUG
  283. VOID
  284. DumpPinConnect(
  285. LONG Level,
  286. PKSPIN_CONNECT pPinConnect
  287. );
  288. VOID
  289. DumpDataFormat(
  290. LONG Level,
  291. PKSDATAFORMAT pDataFormat
  292. );
  293. VOID
  294. DumpWaveFormatEx(
  295. LONG Level,
  296. PSZ pszSpecifier,
  297. WAVEFORMATEX *pWaveFormatEx
  298. );
  299. VOID
  300. DumpDataRange(
  301. LONG Level,
  302. PKSDATARANGE_AUDIO pDataRangeAudio
  303. );
  304. VOID
  305. DumpDataRangeAudio(
  306. PKSDATARANGE_AUDIO pDataRangeAudio
  307. );
  308. VOID
  309. DumpfulType(
  310. ULONG fulType
  311. );
  312. ENUMFUNC
  313. DumpListData(
  314. PVOID pData
  315. );
  316. PSZ DbgUnicode2Sz(
  317. PWSTR pwstr
  318. );
  319. PSZ
  320. DbgIdentifier2Sz(
  321. PKSIDENTIFIER pIdentifier
  322. );
  323. PSZ
  324. DbgGuid2Sz(
  325. GUID *pGuid
  326. );
  327. //---------------------------------------------------------------------------
  328. #endif // DEBUG
  329. } // extern "C"
  330. //---------------------------------------------------------------------------
  331. // End of File: util.h
  332. //---------------------------------------------------------------------------