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.

516 lines
12 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. proc.h
  5. Abstract:
  6. This module contains routine prototypes for UL.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Revision History:
  10. --*/
  11. #ifndef _PROC_H_
  12. #define _PROC_H_
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. //
  17. // Device driver entry routine from INIT.C.
  18. //
  19. EXTERN_C
  20. NTSTATUS
  21. DriverEntry(
  22. IN PDRIVER_OBJECT DriverObject,
  23. IN PUNICODE_STRING RegistryPath
  24. );
  25. //
  26. // IRP handlers from various modules.
  27. //
  28. NTSTATUS
  29. UlCleanup(
  30. IN PDEVICE_OBJECT DeviceObject,
  31. IN PIRP Irp
  32. );
  33. NTSTATUS
  34. UlClose(
  35. IN PDEVICE_OBJECT DeviceObject,
  36. IN PIRP Irp
  37. );
  38. NTSTATUS
  39. UlCreate(
  40. IN PDEVICE_OBJECT DeviceObject,
  41. IN PIRP Irp
  42. );
  43. NTSTATUS
  44. UlDeviceControl (
  45. IN PDEVICE_OBJECT DeviceObject,
  46. IN PIRP Irp
  47. );
  48. //
  49. // Fast IO handler from DEVCTRL.C.
  50. //
  51. BOOLEAN
  52. UlFastDeviceControl(
  53. IN PFILE_OBJECT FileObject,
  54. IN BOOLEAN Wait,
  55. IN PVOID InputBuffer OPTIONAL,
  56. IN ULONG InputBufferLength,
  57. OUT PVOID OutputBuffer OPTIONAL,
  58. IN ULONG OutputBufferLength,
  59. IN ULONG IoControlCode,
  60. OUT PIO_STATUS_BLOCK IoStatus,
  61. IN PDEVICE_OBJECT DeviceObject
  62. );
  63. //
  64. // Global data initialization/termination from DATA.C.
  65. //
  66. NTSTATUS
  67. UlInitializeData(
  68. PUL_CONFIG pConfig
  69. );
  70. VOID
  71. UlTerminateData(
  72. VOID
  73. );
  74. //
  75. // Utility functions from MISC.C.
  76. //
  77. NTSTATUS
  78. UlOpenRegistry(
  79. IN PUNICODE_STRING BaseName,
  80. OUT PHANDLE ParametersHandle
  81. );
  82. LONG
  83. UlReadLongParameter(
  84. IN HANDLE ParametersHandle,
  85. IN PWCHAR ValueName,
  86. IN LONG DefaultValue
  87. );
  88. LONGLONG
  89. UlReadLongLongParameter(
  90. IN HANDLE ParametersHandle,
  91. IN PWCHAR ValueName,
  92. IN LONGLONG DefaultValue
  93. );
  94. NTSTATUS
  95. UlReadGenericParameter(
  96. IN HANDLE ParametersHandle,
  97. IN PWCHAR ValueName,
  98. OUT PKEY_VALUE_PARTIAL_INFORMATION * Value
  99. );
  100. VOID
  101. UlBuildDeviceControlIrp(
  102. IN OUT PIRP Irp,
  103. IN ULONG IoControlCode,
  104. IN PVOID InputBuffer OPTIONAL,
  105. IN ULONG InputBufferLength,
  106. IN PVOID OutputBuffer OPTIONAL,
  107. IN ULONG OutputBufferLength,
  108. IN PMDL MdlAddress,
  109. IN PFILE_OBJECT FileObject,
  110. IN PDEVICE_OBJECT DeviceObject,
  111. IN PIO_STATUS_BLOCK IoStatusBlock,
  112. IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  113. IN PVOID CompletionContext,
  114. IN PETHREAD TargetThread OPTIONAL
  115. );
  116. PSTR
  117. UlULongLongToAscii(
  118. IN PSTR String,
  119. IN ULONGLONG Value
  120. );
  121. NTSTATUS
  122. _RtlIntegerToUnicode(
  123. IN ULONG Integer,
  124. IN ULONG Base OPTIONAL,
  125. IN LONG BufferLength,
  126. OUT PWSTR pBuffer
  127. );
  128. NTSTATUS
  129. UlAnsiToULongLong(
  130. PUCHAR pString,
  131. ULONG Base,
  132. PULONGLONG pValue
  133. );
  134. NTSTATUS
  135. UlUnicodeToULongLong(
  136. PWCHAR pString,
  137. ULONG Base,
  138. PULONGLONG pValue
  139. );
  140. NTSTATUS
  141. UlIssueDeviceControl(
  142. IN PUX_TDI_OBJECT pTdiObject,
  143. IN PVOID pIrpParameters,
  144. IN ULONG IrpParametersLength,
  145. IN PVOID pMdlBuffer OPTIONAL,
  146. IN ULONG MdlBufferLength OPTIONAL,
  147. IN UCHAR MinorFunction
  148. );
  149. NTSTATUS
  150. UlInvokeCompletionRoutine(
  151. IN NTSTATUS Status,
  152. IN ULONG_PTR Information,
  153. IN PUL_COMPLETION_ROUTINE pCompletionRoutine,
  154. IN PVOID pCompletionContext
  155. );
  156. //
  157. // Initialize a TA_IP_ADDRESS structure.
  158. //
  159. #define UlInitializeIpTransportAddress( ta, ipaddr, port ) \
  160. do { \
  161. RtlZeroMemory( (ta), sizeof(*(ta)) ); \
  162. (ta)->TAAddressCount = 1; \
  163. (ta)->Address[0].AddressLength = sizeof(TDI_ADDRESS_IP); \
  164. (ta)->Address[0].AddressType = TDI_ADDRESS_TYPE_IP; \
  165. (ta)->Address[0].Address[0].in_addr = SWAP_LONG( (ipaddr) ); \
  166. (ta)->Address[0].Address[0].sin_port = SWAP_SHORT( (port) ); \
  167. } while (FALSE)
  168. //
  169. // The following definitions are used to generate meaningful blue bugcheck
  170. // screens. On a bugcheck the file system can output 4 ulongs of useful
  171. // information. The first ulong will have encoded in it a source file id
  172. // (in the high word) and the line number of the bugcheck (in the low word).
  173. // The other values can be whatever the caller of the bugcheck routine deems
  174. // necessary.
  175. //
  176. // Each individual file that calls bugcheck needs to have defined at the
  177. // start of the file a constant called BugCheckFileId with one of the
  178. // UL_BUG_CHECK_ values defined below and then use UlBugCheck to bugcheck
  179. // the system.
  180. //
  181. #define UL_BUG_CHECK_CLOSE (0x00010000)
  182. #define UL_BUG_CHECK_CREATE (0x00020000)
  183. #define UL_BUG_CHECK_DEBUG (0x00030000)
  184. #define UL_BUG_CHECK_DEVCTRL (0x00040000)
  185. #define UL_BUG_CHECK_INIT (0x00050000)
  186. #define UL_BUG_CHECK_IOCTL (0x00060000)
  187. #define UL_BUG_CHECK_MISC (0x00070000)
  188. #define UL_BUG_CHECK_ULDATA (0x00080000)
  189. #define UlBugCheck(A,B,C) \
  190. KeBugCheckEx( \
  191. UL_INTERNAL_ERROR, \
  192. BugCheckFileId | __LINE__, \
  193. (A), \
  194. (B), \
  195. (C) \
  196. )
  197. //
  198. // IRP context manipulators.
  199. //
  200. #define UlPplAllocateIrpContext() \
  201. (PUL_IRP_CONTEXT)(PplAllocate( \
  202. g_pUlNonpagedData->IrpContextLookaside \
  203. ))
  204. #define UlPplFreeIrpContext( pContext ) \
  205. PplFree( \
  206. g_pUlNonpagedData->IrpContextLookaside, \
  207. (pContext) \
  208. )
  209. PVOID
  210. UlAllocateIrpContextPool(
  211. IN POOL_TYPE PoolType,
  212. IN SIZE_T ByteLength,
  213. IN ULONG Tag
  214. );
  215. VOID
  216. UlFreeIrpContextPool(
  217. IN PVOID pBuffer
  218. );
  219. //
  220. // Buffer allocators.
  221. //
  222. #define UlPplAllocateReceiveBuffer() \
  223. (PUL_RECEIVE_BUFFER)(PplAllocate( \
  224. g_pUlNonpagedData->ReceiveBufferLookaside \
  225. ))
  226. #define UlPplFreeReceiveBuffer( pBuffer ) \
  227. PplFree( \
  228. g_pUlNonpagedData->ReceiveBufferLookaside, \
  229. (pBuffer) \
  230. )
  231. PVOID
  232. UlAllocateReceiveBufferPool(
  233. IN POOL_TYPE PoolType,
  234. IN SIZE_T ByteLength,
  235. IN ULONG Tag
  236. );
  237. VOID
  238. UlFreeReceiveBufferPool(
  239. IN PVOID pBuffer
  240. );
  241. //
  242. // Request buffer allocators.
  243. //
  244. #define UlPplAllocateRequestBuffer() \
  245. (PUL_REQUEST_BUFFER)(PplAllocate( \
  246. g_pUlNonpagedData->RequestBufferLookaside \
  247. ))
  248. #define UlPplFreeRequestBuffer( pBuffer ) \
  249. PplFree( \
  250. g_pUlNonpagedData->RequestBufferLookaside, \
  251. (pBuffer) \
  252. )
  253. PVOID
  254. UlAllocateRequestBufferPool(
  255. IN POOL_TYPE PoolType,
  256. IN SIZE_T ByteLength,
  257. IN ULONG Tag
  258. );
  259. VOID
  260. UlFreeRequestBufferPool(
  261. IN PVOID pBuffer
  262. );
  263. //
  264. // Internal request buffer allocators.
  265. //
  266. #define UlPplAllocateInternalRequest() \
  267. (PUL_INTERNAL_REQUEST)(PplAllocate( \
  268. g_pUlNonpagedData->InternalRequestLookaside \
  269. ))
  270. #define UlPplFreeInternalRequest( pBuffer ) \
  271. PplFree( \
  272. g_pUlNonpagedData->InternalRequestLookaside, \
  273. (pBuffer) \
  274. )
  275. PVOID
  276. UlAllocateInternalRequestPool(
  277. IN POOL_TYPE PoolType,
  278. IN SIZE_T ByteLength,
  279. IN ULONG Tag
  280. );
  281. VOID
  282. UlFreeInternalRequestPool(
  283. IN PVOID pBuffer
  284. );
  285. //
  286. // Chunk tracker allocators.
  287. //
  288. #define UlPplAllocateChunkTracker() \
  289. (PUL_CHUNK_TRACKER)(PplAllocate( \
  290. g_pUlNonpagedData->ChunkTrackerLookaside \
  291. ))
  292. #define UlPplFreeChunkTracker( pBuffer ) \
  293. PplFree( \
  294. g_pUlNonpagedData->ChunkTrackerLookaside, \
  295. (pBuffer) \
  296. )
  297. PVOID
  298. UlAllocateChunkTrackerPool(
  299. IN POOL_TYPE PoolType,
  300. IN SIZE_T ByteLength,
  301. IN ULONG Tag
  302. );
  303. VOID
  304. UlFreeChunkTrackerPool(
  305. IN PVOID pBuffer
  306. );
  307. //
  308. // Full tracker allocators.
  309. //
  310. #define UlPplAllocateFullTracker() \
  311. (PUL_FULL_TRACKER)(PplAllocate( \
  312. g_pUlNonpagedData->FullTrackerLookaside \
  313. ))
  314. #define UlPplFreeFullTracker( pBuffer ) \
  315. PplFree( \
  316. g_pUlNonpagedData->FullTrackerLookaside, \
  317. (pBuffer) \
  318. )
  319. PVOID
  320. UlAllocateFullTrackerPool(
  321. IN POOL_TYPE PoolType,
  322. IN SIZE_T ByteLength,
  323. IN ULONG Tag
  324. );
  325. VOID
  326. UlFreeFullTrackerPool(
  327. IN PVOID pBuffer
  328. );
  329. //
  330. // Internal response buffer allocators.
  331. //
  332. #define UlPplAllocateResponseBuffer() \
  333. (PUL_INTERNAL_RESPONSE)(PplAllocate( \
  334. g_pUlNonpagedData->ResponseBufferLookaside \
  335. ))
  336. #define UlPplFreeResponseBuffer( pBuffer ) \
  337. PplFree( \
  338. g_pUlNonpagedData->ResponseBufferLookaside, \
  339. (pBuffer) \
  340. )
  341. PVOID
  342. UlAllocateResponseBufferPool(
  343. IN POOL_TYPE PoolType,
  344. IN SIZE_T ByteLength,
  345. IN ULONG Tag
  346. );
  347. VOID
  348. UlFreeResponseBufferPool(
  349. IN PVOID pBuffer
  350. );
  351. //
  352. // Log buffer allocators.
  353. //
  354. __inline
  355. PUL_LOG_FILE_BUFFER
  356. FASTCALL
  357. UlPplAllocateLogBuffer(
  358. VOID
  359. )
  360. {
  361. PUL_LOG_FILE_BUFFER pBuffer;
  362. PAGED_CODE();
  363. pBuffer = (PUL_LOG_FILE_BUFFER)
  364. PplAllocate(
  365. g_pUlNonpagedData->LogBufferLookaside
  366. );
  367. if (pBuffer)
  368. {
  369. ASSERT(pBuffer->Signature == MAKE_FREE_TAG(UL_LOG_FILE_BUFFER_POOL_TAG));
  370. pBuffer->Signature = UL_LOG_FILE_BUFFER_POOL_TAG;
  371. }
  372. return pBuffer;
  373. }
  374. __inline
  375. VOID
  376. FASTCALL
  377. UlPplFreeLogBuffer(
  378. IN PUL_LOG_FILE_BUFFER pBuffer
  379. )
  380. {
  381. PAGED_CODE();
  382. IS_VALID_LOG_FILE_BUFFER(pBuffer);
  383. pBuffer->BufferUsed = 0;
  384. pBuffer->Signature = MAKE_FREE_TAG(UL_LOG_FILE_BUFFER_POOL_TAG);
  385. PplFree(
  386. g_pUlNonpagedData->LogBufferLookaside,
  387. pBuffer
  388. );
  389. }
  390. PVOID
  391. UlAllocateLogBufferPool(
  392. IN POOL_TYPE PoolType,
  393. IN SIZE_T ByteLength,
  394. IN ULONG Tag
  395. );
  396. VOID
  397. UlFreeLogBufferPool(
  398. IN PVOID pBuffer
  399. );
  400. //
  401. // Trivial macro that should probably be in ntos\inc\io.h.
  402. //
  403. #define UlUnmarkIrpPending( Irp ) ( \
  404. IoGetCurrentIrpStackLocation( (Irp) )->Control &= ~SL_PENDING_RETURNED )
  405. #ifdef __cplusplus
  406. }; // extern "C"
  407. #endif
  408. #endif // _PROC_H_