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.

2309 lines
59 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. afdprocs.h
  5. Abstract:
  6. This module contains routine prototypes for AFD.
  7. Author:
  8. David Treadwell (davidtr) 21-Feb-1992
  9. Revision History:
  10. --*/
  11. #ifndef _AFDPROCS_
  12. #define _AFDPROCS_
  13. NTSTATUS
  14. DriverEntry (
  15. IN PDRIVER_OBJECT DriverObject,
  16. IN PUNICODE_STRING RegistryPath
  17. );
  18. NTSTATUS
  19. FASTCALL
  20. AfdAccept (
  21. IN PIRP Irp,
  22. IN PIO_STACK_LOCATION IrpSp
  23. );
  24. NTSTATUS
  25. FASTCALL
  26. AfdSuperAccept (
  27. IN PIRP Irp,
  28. IN PIO_STACK_LOCATION IrpSp
  29. );
  30. NTSTATUS
  31. FASTCALL
  32. AfdDeferAccept (
  33. IN PIRP Irp,
  34. IN PIO_STACK_LOCATION IrpSp
  35. );
  36. NTSTATUS
  37. AfdRestartSuperAccept (
  38. IN PDEVICE_OBJECT DeviceObject,
  39. IN PIRP Irp,
  40. IN PVOID Context
  41. );
  42. VOID
  43. AfdCancelSuperAccept (
  44. IN PDEVICE_OBJECT DeviceObject,
  45. IN PIRP Irp
  46. );
  47. VOID
  48. AfdCleanupSuperAccept (
  49. IN PIRP Irp,
  50. IN NTSTATUS Status
  51. );
  52. BOOLEAN
  53. AfdServiceSuperAccept (
  54. IN PAFD_ENDPOINT Endpoint,
  55. IN PAFD_CONNECTION Connection,
  56. IN PAFD_LOCK_QUEUE_HANDLE LockHandle,
  57. OUT PLIST_ENTRY AcceptIrpList
  58. );
  59. NTSTATUS
  60. AfdAcceptCore (
  61. IN PIRP AcceptIrp,
  62. IN PAFD_ENDPOINT AcceptEndpoint,
  63. IN PAFD_CONNECTION Connection
  64. );
  65. NTSTATUS
  66. AfdSetupAcceptEndpoint (
  67. PAFD_ENDPOINT ListenEndpoint,
  68. PAFD_ENDPOINT AcceptEndpoint,
  69. PAFD_CONNECTION Connection
  70. );
  71. VOID
  72. AfdRestartSuperAcceptListen (
  73. IN PIRP Irp,
  74. IN PAFD_CONNECTION Connection
  75. );
  76. NTSTATUS
  77. AfdRestartDelayedSuperAccept (
  78. IN PDEVICE_OBJECT DeviceObject,
  79. IN PIRP Irp,
  80. IN PVOID Context
  81. );
  82. PMDL
  83. AfdAdvanceMdlChain(
  84. IN PMDL Mdl,
  85. IN ULONG Offset
  86. );
  87. #ifdef _WIN64
  88. NTSTATUS
  89. AfdAllocateMdlChain32(
  90. IN PIRP Irp,
  91. IN LPWSABUF32 BufferArray,
  92. IN ULONG BufferCount,
  93. IN LOCK_OPERATION Operation,
  94. OUT PULONG TotalByteCount
  95. );
  96. #endif
  97. NTSTATUS
  98. AfdAllocateMdlChain(
  99. IN PIRP Irp,
  100. IN LPWSABUF BufferArray,
  101. IN ULONG BufferCount,
  102. IN LOCK_OPERATION Operation,
  103. OUT PULONG TotalByteCount
  104. );
  105. BOOLEAN
  106. AfdAreTransportAddressesEqual (
  107. IN PTRANSPORT_ADDRESS EndpointAddress,
  108. IN ULONG EndpointAddressLength,
  109. IN PTRANSPORT_ADDRESS RequestAddress,
  110. IN ULONG RequestAddressLength,
  111. IN BOOLEAN HonorWildcardIpPortInEndpointAddress
  112. );
  113. NTSTATUS
  114. AfdBeginAbort (
  115. IN PAFD_CONNECTION Connection
  116. );
  117. NTSTATUS
  118. AfdBeginDisconnect (
  119. IN PAFD_ENDPOINT Endpoint,
  120. IN PLARGE_INTEGER Timeout OPTIONAL,
  121. OUT PIRP *DisconnectIrp OPTIONAL
  122. );
  123. NTSTATUS
  124. FASTCALL
  125. AfdBind (
  126. IN PIRP Irp,
  127. IN PIO_STACK_LOCATION IrpSp
  128. );
  129. ULONG
  130. AfdCalcBufferArrayByteLength(
  131. IN LPWSABUF BufferArray,
  132. IN ULONG BufferCount
  133. );
  134. VOID
  135. AfdCancelReceiveDatagram (
  136. IN PDEVICE_OBJECT DeviceObject,
  137. IN PIRP Irp
  138. );
  139. NTSTATUS
  140. FASTCALL
  141. AfdCleanup (
  142. IN PIRP Irp,
  143. IN PIO_STACK_LOCATION IrpSp
  144. );
  145. NTSTATUS
  146. FASTCALL
  147. AfdClose (
  148. IN PIRP Irp,
  149. IN PIO_STACK_LOCATION IrpSp
  150. );
  151. VOID
  152. AfdCompleteIrpList (
  153. IN PLIST_ENTRY IrpListHead,
  154. IN PAFD_ENDPOINT Endpoint,
  155. IN NTSTATUS Status,
  156. IN PAFD_IRP_CLEANUP_ROUTINE CleanupRoutine OPTIONAL
  157. );
  158. VOID
  159. AfdCompleteClosePendedTransmit (
  160. IN PVOID Context
  161. );
  162. NTSTATUS
  163. FASTCALL
  164. AfdConnect (
  165. IN PIRP Irp,
  166. IN PIO_STACK_LOCATION IrpSp
  167. );
  168. NTSTATUS
  169. FASTCALL
  170. AfdJoinLeaf (
  171. IN PIRP Irp,
  172. IN PIO_STACK_LOCATION IrpSp
  173. );
  174. NTSTATUS
  175. FASTCALL
  176. AfdSuperConnect (
  177. IN PIRP Irp,
  178. IN PIO_STACK_LOCATION IrpSp
  179. );
  180. NTSTATUS
  181. AfdConnectEventHandler (
  182. IN PVOID TdiEventContext,
  183. IN int RemoteAddressLength,
  184. IN PVOID RemoteAddress,
  185. IN int UserDataLength,
  186. IN PVOID UserData,
  187. IN int OptionsLength,
  188. IN PVOID Options,
  189. OUT CONNECTION_CONTEXT *ConnectionContext,
  190. OUT PIRP *AcceptIrp
  191. );
  192. #ifdef _WIN64
  193. ULONG
  194. AfdComputeCMSGLength32 (
  195. PVOID ControlBuffer,
  196. ULONG ControlLength
  197. );
  198. VOID
  199. AfdCopyCMSGBuffer32 (
  200. PVOID Dst,
  201. PVOID ControlBuffer,
  202. ULONG CopyLength
  203. );
  204. #endif //_WIN64
  205. ULONG
  206. AfdCopyBufferArrayToBuffer(
  207. IN PVOID Destination,
  208. IN ULONG DestinationLength,
  209. IN LPWSABUF BufferArray,
  210. IN ULONG BufferCount
  211. );
  212. ULONG
  213. AfdCopyBufferToBufferArray(
  214. IN LPWSABUF BufferArray,
  215. IN ULONG Offset,
  216. IN ULONG BufferCount,
  217. IN PVOID Source,
  218. IN ULONG SourceLength
  219. );
  220. ULONG
  221. AfdCopyMdlChainToBufferArray(
  222. IN LPWSABUF BufferArray,
  223. IN ULONG BufferOffset,
  224. IN ULONG BufferCount,
  225. IN PMDL Source,
  226. IN ULONG SourceOffset,
  227. IN ULONG SourceLength
  228. );
  229. NTSTATUS
  230. AfdCopyMdlChainToMdlChain (
  231. PMDL Destination,
  232. ULONG DestinationOffset,
  233. PMDL Source,
  234. ULONG SourceOffset,
  235. ULONG SourceLength,
  236. PULONG BytesCopied
  237. );
  238. NTSTATUS
  239. AfdCopyMdlChainToBufferAvoidMapping(
  240. IN PMDL SourceMdl,
  241. IN ULONG SourceOffset,
  242. IN ULONG SourceLength,
  243. IN PUCHAR Buffer,
  244. IN ULONG BufferSize
  245. );
  246. NTSTATUS
  247. AfdMapMdlChain (
  248. PMDL MdlChain
  249. );
  250. NTSTATUS
  251. FASTCALL
  252. AfdCreate (
  253. IN PIRP Irp,
  254. IN PIO_STACK_LOCATION IrpSp
  255. );
  256. NTSTATUS
  257. AfdDelayedAcceptListen (
  258. PAFD_ENDPOINT Endpoint,
  259. PAFD_CONNECTION Connection
  260. );
  261. VOID
  262. AfdDestroyMdlChain (
  263. IN PIRP Irp
  264. );
  265. NTSTATUS
  266. AfdDisconnectEventHandler (
  267. IN PVOID TdiEventContext,
  268. IN CONNECTION_CONTEXT ConnectionContext,
  269. IN int DisconnectDataLength,
  270. IN PVOID DisconnectData,
  271. IN int DisconnectInformationLength,
  272. IN PVOID DisconnectInformation,
  273. IN ULONG DisconnectFlags
  274. );
  275. NTSTATUS
  276. AfdDispatch (
  277. IN PDEVICE_OBJECT DeviceObject,
  278. IN PIRP Irp
  279. );
  280. NTSTATUS
  281. AfdDispatchDeviceControl (
  282. IN PDEVICE_OBJECT DeviceObject,
  283. IN PIRP Irp
  284. );
  285. NTSTATUS
  286. FASTCALL
  287. AfdDispatchImmediateIrp(
  288. IN PIRP Irp,
  289. IN PIO_STACK_LOCATION IrpSp
  290. );
  291. NTSTATUS
  292. AfdEnumNetworkEvents (
  293. IN PFILE_OBJECT FileObject,
  294. IN ULONG IoctlCode,
  295. IN KPROCESSOR_MODE RequestorMode,
  296. IN PVOID InputBuffer,
  297. IN ULONG InputBufferLength,
  298. IN PVOID OutputBuffer,
  299. IN ULONG OutputBufferLength,
  300. OUT PULONG_PTR Information
  301. );
  302. NTSTATUS
  303. AfdErrorEventHandler (
  304. IN PVOID TdiEventContext,
  305. IN NTSTATUS Status
  306. );
  307. NTSTATUS
  308. AfdErrorExEventHandler (
  309. IN PVOID TdiEventContext,
  310. IN NTSTATUS Status,
  311. IN PVOID Context
  312. );
  313. NTSTATUS
  314. AfdEventSelect (
  315. IN PFILE_OBJECT FileObject,
  316. IN ULONG IoctlCode,
  317. IN KPROCESSOR_MODE RequestorMode,
  318. IN PVOID InputBuffer,
  319. IN ULONG InputBufferLength,
  320. IN PVOID OutputBuffer,
  321. IN ULONG OutputBufferLength,
  322. OUT PULONG_PTR Information
  323. );
  324. LONG
  325. AfdExceptionFilter(
  326. #if DBG
  327. IN PCHAR SourceFile,
  328. IN LONG LineNumber,
  329. #endif
  330. IN PEXCEPTION_POINTERS ExceptionPointers,
  331. OUT PNTSTATUS ExceptionCode OPTIONAL
  332. );
  333. BOOLEAN
  334. AfdFastTransmitFile (
  335. IN PAFD_ENDPOINT endpoint,
  336. IN PAFD_TRANSMIT_FILE_INFO transmitInfo,
  337. OUT PIO_STATUS_BLOCK IoStatus
  338. );
  339. VOID
  340. AfdFreeConnectDataBuffers (
  341. IN PAFD_CONNECT_DATA_BUFFERS ConnectDataBuffers
  342. );
  343. VOID
  344. AfdFreeQueuedConnections (
  345. IN PAFD_ENDPOINT Endpoint
  346. );
  347. NTSTATUS
  348. FASTCALL
  349. AfdGetAddress (
  350. IN PIRP Irp,
  351. IN PIO_STACK_LOCATION IrpSp
  352. );
  353. NTSTATUS
  354. AfdGetRemoteAddress (
  355. IN PFILE_OBJECT FileObject,
  356. IN ULONG IoctlCode,
  357. IN KPROCESSOR_MODE RequestorMode,
  358. IN PVOID InputBuffer,
  359. IN ULONG InputBufferLength,
  360. IN PVOID OutputBuffer,
  361. IN ULONG OutputBufferLength,
  362. OUT PULONG_PTR Information
  363. );
  364. NTSTATUS
  365. AfdGetContext (
  366. IN PFILE_OBJECT FileObject,
  367. IN ULONG IoctlCode,
  368. IN KPROCESSOR_MODE RequestorMode,
  369. IN PVOID InputBuffer,
  370. IN ULONG InputBufferLength,
  371. IN PVOID OutputBuffer,
  372. IN ULONG OutputBufferLength,
  373. OUT PULONG_PTR Information
  374. );
  375. NTSTATUS
  376. AfdGetInformation (
  377. IN PFILE_OBJECT FileObject,
  378. IN ULONG IoctlCode,
  379. IN KPROCESSOR_MODE RequestorMode,
  380. IN PVOID InputBuffer,
  381. IN ULONG InputBufferLength,
  382. IN PVOID OutputBuffer,
  383. IN ULONG OutputBufferLength,
  384. OUT PULONG_PTR Information
  385. );
  386. NTSTATUS
  387. AfdGetTransportInfo (
  388. IN PUNICODE_STRING TransportDeviceName,
  389. IN OUT PAFD_TRANSPORT_INFO *TransportInfo
  390. );
  391. NTSTATUS
  392. AfdQueryProviderInfo (
  393. IN PUNICODE_STRING TransportDeviceName,
  394. #ifdef _AFD_VARIABLE_STACK_
  395. OUT CCHAR *StackSize OPTIONAL,
  396. #endif //_AFD_VARIABLE_STACK_
  397. OUT PTDI_PROVIDER_INFO ProviderInfo
  398. );
  399. VOID
  400. AfdIndicateEventSelectEvent (
  401. IN PAFD_ENDPOINT Endpoint,
  402. IN ULONG PollEventMask,
  403. IN NTSTATUS Status
  404. );
  405. VOID
  406. AfdIndicatePollEventReal (
  407. IN PAFD_ENDPOINT Endpoint,
  408. IN ULONG PollEventMask,
  409. IN NTSTATUS Status
  410. );
  411. #define AfdIndicatePollEvent(_e,_m,_s) \
  412. ((_e)->PollCalled ? (AfdIndicatePollEventReal((_e),(_m),(_s)), TRUE) : FALSE)
  413. VOID
  414. AfdInitiateListenBacklogReplenish (
  415. IN PAFD_ENDPOINT Endpoint
  416. );
  417. VOID
  418. AfdInitializeData (
  419. VOID
  420. );
  421. NTSTATUS
  422. AfdIssueDeviceControl (
  423. IN PFILE_OBJECT FileObject,
  424. IN PVOID IrpParameters,
  425. IN ULONG IrpParametersLength,
  426. IN PVOID MdlBuffer,
  427. IN ULONG MdlBufferLength,
  428. IN UCHAR MinorFunction
  429. );
  430. VOID
  431. AfdIncrementLockCount (
  432. VOID
  433. );
  434. VOID
  435. AfdDecrementLockCount (
  436. VOID
  437. );
  438. VOID
  439. AfdInsertNewEndpointInList (
  440. IN PAFD_ENDPOINT Endpoint
  441. );
  442. VOID
  443. AfdRemoveEndpointFromList (
  444. IN PAFD_ENDPOINT Endpoint
  445. );
  446. PVOID
  447. AfdLockEndpointContext (
  448. PAFD_ENDPOINT Endpoint
  449. );
  450. VOID
  451. AfdUnlockEndpointContext (
  452. PAFD_ENDPOINT Endpoint,
  453. PVOID Context
  454. );
  455. NTSTATUS
  456. AfdPartialDisconnect (
  457. IN PFILE_OBJECT FileObject,
  458. IN ULONG IoctlCode,
  459. IN KPROCESSOR_MODE RequestorMode,
  460. IN PVOID InputBuffer,
  461. IN ULONG InputBufferLength,
  462. IN PVOID OutputBuffer,
  463. IN ULONG OutputBufferLength,
  464. OUT PULONG_PTR Information
  465. );
  466. NTSTATUS
  467. FASTCALL
  468. AfdPoll (
  469. IN PIRP Irp,
  470. IN PIO_STACK_LOCATION IrpSp
  471. );
  472. VOID
  473. AfdQueueWorkItem (
  474. IN PWORKER_THREAD_ROUTINE AfdWorkerRoutine,
  475. IN PAFD_WORK_ITEM AfdWorkItem
  476. );
  477. PAFD_WORK_ITEM
  478. AfdGetWorkerByRoutine (
  479. PWORKER_THREAD_ROUTINE Routine
  480. );
  481. NTSTATUS
  482. AfdQueryHandles (
  483. IN PFILE_OBJECT FileObject,
  484. IN ULONG IoctlCode,
  485. IN KPROCESSOR_MODE RequestorMode,
  486. IN PVOID InputBuffer,
  487. IN ULONG InputBufferLength,
  488. IN PVOID OutputBuffer,
  489. IN ULONG OutputBufferLength,
  490. OUT PULONG_PTR Information
  491. );
  492. NTSTATUS
  493. AfdQueryReceiveInformation (
  494. IN PFILE_OBJECT FileObject,
  495. IN ULONG IoctlCode,
  496. IN KPROCESSOR_MODE RequestorMode,
  497. IN PVOID InputBuffer,
  498. IN ULONG InputBufferLength,
  499. IN PVOID OutputBuffer,
  500. IN ULONG OutputBufferLength,
  501. OUT PULONG_PTR Information
  502. );
  503. NTSTATUS
  504. AfdSetContext (
  505. IN PFILE_OBJECT FileObject,
  506. IN ULONG IoctlCode,
  507. IN KPROCESSOR_MODE RequestorMode,
  508. IN PVOID InputBuffer,
  509. IN ULONG InputBufferLength,
  510. IN PVOID OutputBuffer,
  511. IN ULONG OutputBufferLength,
  512. OUT PULONG_PTR Information
  513. );
  514. NTSTATUS
  515. AfdSetEventHandler (
  516. IN PFILE_OBJECT FileObject,
  517. IN ULONG EventType,
  518. IN PVOID EventHandler,
  519. IN PVOID EventContext
  520. );
  521. NTSTATUS
  522. AfdSetInLineMode (
  523. IN PAFD_CONNECTION Connection,
  524. IN BOOLEAN InLine
  525. );
  526. NTSTATUS
  527. AfdUnbind (
  528. IN PAFD_ENDPOINT Endpoint
  529. );
  530. NTSTATUS
  531. FASTCALL
  532. AfdReceive (
  533. IN PIRP Irp,
  534. IN PIO_STACK_LOCATION IrpSp
  535. );
  536. NTSTATUS
  537. AfdBReceive (
  538. IN PIRP Irp,
  539. IN PIO_STACK_LOCATION IrpSp,
  540. IN ULONG RecvFlags,
  541. IN ULONG AfdFlags,
  542. IN ULONG RecvLength
  543. );
  544. NTSTATUS
  545. FASTCALL
  546. AfdReceiveDatagram (
  547. IN PIRP Irp,
  548. IN PIO_STACK_LOCATION IrpSp
  549. );
  550. NTSTATUS
  551. AfdSetupReceiveDatagramIrp (
  552. IN PIRP Irp,
  553. IN PVOID DatagramBuffer OPTIONAL,
  554. IN ULONG DatagramLength,
  555. IN PVOID OptionsBuffer OPTIONAL,
  556. IN ULONG OptionsLength,
  557. IN PVOID SourceAddress OPTIONAL,
  558. IN ULONG SourceAddressLength,
  559. IN ULONG TdiFlags
  560. );
  561. BOOLEAN
  562. AfdCleanupReceiveDatagramIrp(
  563. IN PIRP Irp
  564. );
  565. BOOLEAN
  566. AfdCleanupSendIrp (
  567. PIRP Irp
  568. );
  569. NTSTATUS
  570. AfdReceiveEventHandler (
  571. IN PVOID TdiEventContext,
  572. IN CONNECTION_CONTEXT ConnectionContext,
  573. IN ULONG ReceiveFlags,
  574. IN ULONG BytesIndicated,
  575. IN ULONG BytesAvailable,
  576. OUT ULONG *BytesTaken,
  577. IN PVOID Tsdu,
  578. OUT PIRP *IoRequestPacket
  579. );
  580. NTSTATUS
  581. AfdBChainedReceiveEventHandler(
  582. IN PVOID TdiEventContext,
  583. IN CONNECTION_CONTEXT ConnectionContext,
  584. IN ULONG ReceiveFlags,
  585. IN ULONG ReceiveLength,
  586. IN ULONG StartingOffset,
  587. IN PMDL Tsdu,
  588. IN PVOID TsduDescriptor
  589. );
  590. NTSTATUS
  591. AfdBReceiveEventHandler (
  592. IN PVOID TdiEventContext,
  593. IN CONNECTION_CONTEXT ConnectionContext,
  594. IN ULONG ReceiveFlags,
  595. IN ULONG BytesIndicated,
  596. IN ULONG BytesAvailable,
  597. OUT ULONG *BytesTaken,
  598. IN PVOID Tsdu,
  599. OUT PIRP *IoRequestPacket
  600. );
  601. NTSTATUS
  602. AfdReceiveDatagramEventHandler (
  603. IN PVOID TdiEventContext,
  604. IN int SourceAddressLength,
  605. IN PVOID SourceAddress,
  606. IN int OptionsLength,
  607. IN PVOID Options,
  608. IN ULONG ReceiveDatagramFlags,
  609. IN ULONG BytesIndicated,
  610. IN ULONG BytesAvailable,
  611. OUT ULONG *BytesTaken,
  612. IN PVOID Tsdu,
  613. OUT PIRP *IoRequestPacket
  614. );
  615. NTSTATUS
  616. AfdReceiveExpeditedEventHandler (
  617. IN PVOID TdiEventContext,
  618. IN CONNECTION_CONTEXT ConnectionContext,
  619. IN ULONG ReceiveFlags,
  620. IN ULONG BytesIndicated,
  621. IN ULONG BytesAvailable,
  622. OUT ULONG *BytesTaken,
  623. IN PVOID Tsdu,
  624. OUT PIRP *IoRequestPacket
  625. );
  626. NTSTATUS
  627. AfdBReceiveExpeditedEventHandler (
  628. IN PVOID TdiEventContext,
  629. IN CONNECTION_CONTEXT ConnectionContext,
  630. IN ULONG ReceiveFlags,
  631. IN ULONG BytesIndicated,
  632. IN ULONG BytesAvailable,
  633. OUT ULONG *BytesTaken,
  634. IN PVOID Tsdu,
  635. OUT PIRP *IoRequestPacket
  636. );
  637. NTSTATUS
  638. AfdRestartBufferReceive (
  639. IN PDEVICE_OBJECT DeviceObject,
  640. IN PIRP Irp,
  641. IN PVOID Context
  642. );
  643. NTSTATUS
  644. AfdRestartAbort (
  645. IN PDEVICE_OBJECT DeviceObject,
  646. IN PIRP Irp,
  647. IN PVOID Context
  648. );
  649. NTSTATUS
  650. FASTCALL
  651. AfdSend (
  652. IN PIRP Irp,
  653. IN PIO_STACK_LOCATION IrpSp
  654. );
  655. NTSTATUS
  656. FASTCALL
  657. AfdSendDatagram (
  658. IN PIRP Irp,
  659. IN PIO_STACK_LOCATION IrpSp
  660. );
  661. NTSTATUS
  662. AfdSendPossibleEventHandler (
  663. IN PVOID TdiEventContext,
  664. IN PVOID ConnectionContext,
  665. IN ULONG BytesAvailable
  666. );
  667. NTSTATUS
  668. AfdRestartBufferSend (
  669. IN PDEVICE_OBJECT DeviceObject,
  670. IN PIRP Irp,
  671. IN PVOID Context
  672. );
  673. VOID
  674. AfdProcessBufferSend (
  675. IN PAFD_CONNECTION Connection,
  676. IN PIRP Irp
  677. );
  678. NTSTATUS
  679. AfdSetInformation (
  680. IN PFILE_OBJECT FileObject,
  681. IN ULONG IoctlCode,
  682. IN KPROCESSOR_MODE RequestorMode,
  683. IN PVOID InputBuffer,
  684. IN ULONG InputBufferLength,
  685. IN PVOID OutputBuffer,
  686. IN ULONG OutputBufferLength,
  687. OUT PULONG_PTR Information
  688. );
  689. NTSTATUS
  690. AfdGetSecurity (
  691. IN PAFD_ENDPOINT Endpoint,
  692. IN SECURITY_INFORMATION SecurityInformation,
  693. IN ULONG BufferLength,
  694. OUT PVOID Buffer,
  695. OUT PSIZE_T DataLength
  696. );
  697. NTSTATUS
  698. AfdSetSecurity (
  699. IN PAFD_ENDPOINT Endpoint,
  700. IN SECURITY_INFORMATION SecurityInformation,
  701. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  702. );
  703. BOOLEAN
  704. AfdShouldSendBlock (
  705. IN PAFD_ENDPOINT Endpoint,
  706. IN PAFD_CONNECTION Connection,
  707. IN ULONG SendLength
  708. );
  709. NTSTATUS
  710. AfdStartListen (
  711. IN PFILE_OBJECT FileObject,
  712. IN ULONG IoctlCode,
  713. IN KPROCESSOR_MODE RequestorMode,
  714. IN PVOID InputBuffer,
  715. IN ULONG InputBufferLength,
  716. IN PVOID OutputBuffer,
  717. IN ULONG OutputBufferLength,
  718. OUT PULONG_PTR Information
  719. );
  720. NTSTATUS
  721. FASTCALL
  722. AfdTransmitFile (
  723. IN PIRP Irp,
  724. IN PIO_STACK_LOCATION IrpSp
  725. );
  726. NTSTATUS
  727. FASTCALL
  728. AfdWaitForListen (
  729. IN PIRP Irp,
  730. IN PIO_STACK_LOCATION IrpSp
  731. );
  732. NTSTATUS
  733. FASTCALL
  734. AfdSetQos (
  735. IN PIRP Irp,
  736. IN PIO_STACK_LOCATION IrpSp
  737. );
  738. NTSTATUS
  739. FASTCALL
  740. AfdGetQos (
  741. IN PIRP Irp,
  742. IN PIO_STACK_LOCATION IrpSp
  743. );
  744. NTSTATUS
  745. FASTCALL
  746. AfdNoOperation (
  747. IN PIRP Irp,
  748. IN PIO_STACK_LOCATION IrpSp
  749. );
  750. NTSTATUS
  751. FASTCALL
  752. AfdValidateGroup (
  753. IN PIRP Irp,
  754. IN PIO_STACK_LOCATION IrpSp
  755. );
  756. NTSTATUS
  757. AfdGetUnacceptedConnectData (
  758. IN PFILE_OBJECT FileObject,
  759. IN ULONG IoctlCode,
  760. IN KPROCESSOR_MODE RequestorMode,
  761. IN PVOID InputBuffer,
  762. IN ULONG InputBufferLength,
  763. IN PVOID OutputBuffer,
  764. IN ULONG OutputBufferLength,
  765. OUT PULONG_PTR Information
  766. );
  767. #define AfdReferenceEventObjectByHandle(Handle, AccessMode, Object) \
  768. ObReferenceObjectByHandle( \
  769. (Handle), \
  770. EVENT_MODIFY_STATE, \
  771. *(POBJECT_TYPE *)ExEventObjectType, \
  772. (AccessMode), \
  773. (Object), \
  774. NULL \
  775. )
  776. //
  777. // Endpoint handling routines.
  778. //
  779. NTSTATUS
  780. AfdAllocateEndpoint (
  781. OUT PAFD_ENDPOINT * NewEndpoint,
  782. IN PUNICODE_STRING TransportDeviceName,
  783. IN LONG GroupID
  784. );
  785. #if REFERENCE_DEBUG
  786. VOID
  787. AfdReferenceEndpoint (
  788. IN PAFD_ENDPOINT Endpoint,
  789. IN LONG LocationId,
  790. IN ULONG Param
  791. );
  792. BOOLEAN
  793. AfdCheckAndReferenceEndpoint (
  794. IN PAFD_ENDPOINT Endpoint,
  795. IN LONG LocationId,
  796. IN ULONG Param
  797. );
  798. VOID
  799. AfdDereferenceEndpoint (
  800. IN PAFD_ENDPOINT Endpoint,
  801. IN LONG LocationId,
  802. IN ULONG Param
  803. );
  804. VOID
  805. AfdUpdateEndpoint (
  806. IN PAFD_ENDPOINT Endpoint,
  807. IN LONG LocationId,
  808. IN ULONG Param
  809. );
  810. #define REFERENCE_ENDPOINT(_e) { \
  811. static LONG _arl; \
  812. AfdReferenceEndpoint((_e),AFD_GET_ARL(__FILE__"(%d)+"),__LINE__); \
  813. }
  814. #define REFERENCE_ENDPOINT2(_e,_s,_p) { \
  815. static LONG _arl; \
  816. AfdReferenceEndpoint((_e),AFD_GET_ARL(_s"+"),(_p)); \
  817. }
  818. #define CHECK_REFERENCE_ENDPOINT(_e,_r) { \
  819. static LONG _arl; \
  820. _r = AfdCheckAndReferenceEndpoint((_e),AFD_GET_ARL(__FILE__"(%d)*"),\
  821. __LINE__); \
  822. }
  823. #define DEREFERENCE_ENDPOINT(_e) { \
  824. static LONG _arl; \
  825. AfdDereferenceEndpoint((_e),AFD_GET_ARL(__FILE__"(%d)-"),__LINE__); \
  826. }
  827. #define DEREFERENCE_ENDPOINT2(_e,_s,_p) { \
  828. static LONG _arl; \
  829. AfdDereferenceEndpoint((_e),AFD_GET_ARL(_s"-"),(_p)); \
  830. }
  831. #define UPDATE_ENDPOINT(_e) { \
  832. static LONG _arl; \
  833. AfdUpdateEndpoint((_e),AFD_GET_ARL(__FILE__"(%d)="),__LINE__); \
  834. }
  835. #define UPDATE_ENDPOINT2(_e,_s,_p) { \
  836. static LONG _arl; \
  837. AfdUpdateEndpoint((_e),AFD_GET_ARL(_s"="),(_p)); \
  838. }
  839. #else
  840. BOOLEAN
  841. AfdCheckAndReferenceEndpoint (
  842. IN PAFD_ENDPOINT Endpoint
  843. );
  844. VOID
  845. AfdDereferenceEndpoint (
  846. IN PAFD_ENDPOINT Endpoint
  847. );
  848. #define REFERENCE_ENDPOINT(_e) (VOID)InterlockedIncrement( (PLONG)&(_e)->ReferenceCount )
  849. #define REFERENCE_ENDPOINT2(_e,_s,_p) InterlockedIncrement( (PLONG)&(_e)->ReferenceCount )
  850. #define CHECK_REFERENCE_ENDPOINT(_e,_r) _r=AfdCheckAndReferenceEndpoint((_e))
  851. #define DEREFERENCE_ENDPOINT(_e) AfdDereferenceEndpoint((_e))
  852. #define DEREFERENCE_ENDPOINT2(_e,_s,_p) AfdDereferenceEndpoint((_e))
  853. #define UPDATE_ENDPOINT(_e)
  854. #define UPDATE_ENDPOINT2(_e,_s,_p)
  855. #endif
  856. VOID
  857. AfdRefreshEndpoint (
  858. IN PAFD_ENDPOINT Endpoint
  859. );
  860. //
  861. // Connection handling routines.
  862. //
  863. VOID
  864. AfdAbortConnection (
  865. IN PAFD_CONNECTION Connection
  866. );
  867. NTSTATUS
  868. AfdAddFreeConnection (
  869. IN PAFD_ENDPOINT Endpoint
  870. );
  871. PAFD_CONNECTION
  872. AfdAllocateConnection (
  873. VOID
  874. );
  875. NTSTATUS
  876. AfdCreateConnection (
  877. IN PAFD_TRANSPORT_INFO TransportInfo,
  878. IN HANDLE AddressHandle OPTIONAL,
  879. IN BOOLEAN TdiBufferring,
  880. IN LOGICAL InLine,
  881. IN PEPROCESS ProcessToCharge,
  882. OUT PAFD_CONNECTION *Connection
  883. );
  884. PAFD_CONNECTION
  885. AfdGetFreeConnection (
  886. IN PAFD_ENDPOINT Endpoint,
  887. OUT PIRP *Irp
  888. );
  889. PAFD_CONNECTION
  890. AfdGetReturnedConnection (
  891. IN PAFD_ENDPOINT Endpoint,
  892. IN LONG Sequence
  893. );
  894. PAFD_CONNECTION
  895. AfdFindReturnedConnection(
  896. IN PAFD_ENDPOINT Endpoint,
  897. IN LONG Sequence
  898. );
  899. PAFD_CONNECTION
  900. AfdGetUnacceptedConnection (
  901. IN PAFD_ENDPOINT Endpoint
  902. );
  903. PAFD_CONNECTION
  904. AfdGetConnectionReferenceFromEndpoint (
  905. PAFD_ENDPOINT Endpoint
  906. );
  907. #if REFERENCE_DEBUG
  908. VOID
  909. AfdReferenceConnection (
  910. IN PAFD_CONNECTION Connection,
  911. IN LONG LocationId,
  912. IN ULONG Param
  913. );
  914. BOOLEAN
  915. AfdCheckAndReferenceConnection (
  916. PAFD_CONNECTION Connection,
  917. IN LONG LocationId,
  918. IN ULONG Param
  919. );
  920. VOID
  921. AfdDereferenceConnection (
  922. IN PAFD_CONNECTION Connection,
  923. IN LONG LocationId,
  924. IN ULONG Param
  925. );
  926. #define REFERENCE_CONNECTION(_c) { \
  927. static LONG _arl; \
  928. AfdReferenceConnection((_c),AFD_GET_ARL(__FILE__"(%d)+"),__LINE__); \
  929. }
  930. #define REFERENCE_CONNECTION2(_c,_s,_p) { \
  931. static LONG _arl; \
  932. AfdReferenceConnection((_c),AFD_GET_ARL(_s"+"),(_p)); \
  933. }
  934. #define CHECK_REFERENCE_CONNECTION(_c,_r) { \
  935. static LONG _arl; \
  936. _r=AfdCheckAndReferenceConnection((_c),AFD_GET_ARL(__FILE__"(%d)*"),\
  937. __LINE__); \
  938. }
  939. #define CHECK_REFERENCE_CONNECTION2(_c,_s,_p,_r) { \
  940. static LONG _arl; \
  941. _r = AfdCheckAndReferenceConnection((_c),AFD_GET_ARL(_s"*"),(_p)); \
  942. }
  943. #define DEREFERENCE_CONNECTION(_c) { \
  944. static LONG _arl; \
  945. AfdDereferenceConnection((_c),AFD_GET_ARL(__FILE__"(%d)-"),__LINE__);\
  946. }
  947. #define DEREFERENCE_CONNECTION2(_c,_s,_p) { \
  948. static LONG _arl; \
  949. AfdDereferenceConnection((_c),AFD_GET_ARL(_s"-"),(_p)); \
  950. }
  951. VOID
  952. AfdUpdateConnectionTrack (
  953. IN PAFD_CONNECTION Connection,
  954. IN LONG LocationId,
  955. IN ULONG Param
  956. );
  957. #define UPDATE_CONN(_c) \
  958. if( (_c) != NULL ) { \
  959. static LONG _arl; \
  960. AfdUpdateConnectionTrack( \
  961. (_c), \
  962. AFD_GET_ARL(__FILE__"(%d)="), \
  963. __LINE__ \
  964. ); \
  965. } else
  966. #define UPDATE_CONN2(_c,_s,_p) \
  967. if( (_c) != NULL ) { \
  968. static LONG _arl; \
  969. AfdUpdateConnectionTrack((_c),AFD_GET_ARL(_s"="),(_p)); \
  970. } else
  971. #else
  972. VOID
  973. AfdCloseConnection (
  974. IN PAFD_CONNECTION Connection
  975. );
  976. BOOLEAN
  977. AfdCheckAndReferenceConnection (
  978. PAFD_CONNECTION Connection
  979. );
  980. #define REFERENCE_CONNECTION(_c) (VOID)InterlockedIncrement( (PLONG)&(_c)->ReferenceCount )
  981. #define REFERENCE_CONNECTION2(_c,_s,_p) (VOID)InterlockedIncrement( (PLONG)&(_c)->ReferenceCount )
  982. #define CHECK_REFERENCE_CONNECTION(_c,_r) _r=AfdCheckAndReferenceConnection((_c))
  983. #define CHECK_REFERENCE_CONNECTION2(_c,_s,_p,_r) _r=AfdCheckAndReferenceConnection((_c))
  984. #define DEREFERENCE_CONNECTION(_c) \
  985. if (InterlockedDecrement((PLONG)&(_c)->ReferenceCount)==0) { \
  986. AfdCloseConnection (_c); \
  987. } \
  988. #define DEREFERENCE_CONNECTION2(_c,_s,_p) \
  989. if (InterlockedDecrement((PLONG)&(_c)->ReferenceCount)==0) { \
  990. AfdCloseConnection (_c); \
  991. } \
  992. #define UPDATE_CONN(_c)
  993. #define UPDATE_CONN2(_c,_s,_p)
  994. #endif
  995. VOID
  996. AfdAddConnectedReference (
  997. IN PAFD_CONNECTION Connection
  998. );
  999. VOID
  1000. AfdDeleteConnectedReference (
  1001. IN PAFD_CONNECTION Connection,
  1002. IN BOOLEAN EndpointLockHeld
  1003. );
  1004. //
  1005. // Routines to handle fast IO.
  1006. //
  1007. BOOLEAN
  1008. AfdFastIoRead (
  1009. IN struct _FILE_OBJECT *FileObject,
  1010. IN PLARGE_INTEGER FileOffset,
  1011. IN ULONG Length,
  1012. IN BOOLEAN Wait,
  1013. IN ULONG LockKey,
  1014. OUT PVOID Buffer,
  1015. OUT PIO_STATUS_BLOCK IoStatus,
  1016. IN struct _DEVICE_OBJECT *DeviceObject
  1017. );
  1018. BOOLEAN
  1019. AfdFastIoWrite (
  1020. IN struct _FILE_OBJECT *FileObject,
  1021. IN PLARGE_INTEGER FileOffset,
  1022. IN ULONG Length,
  1023. IN BOOLEAN Wait,
  1024. IN ULONG LockKey,
  1025. IN PVOID Buffer,
  1026. OUT PIO_STATUS_BLOCK IoStatus,
  1027. IN struct _DEVICE_OBJECT *DeviceObject
  1028. );
  1029. BOOLEAN
  1030. AfdFastIoDeviceControl (
  1031. IN struct _FILE_OBJECT *FileObject,
  1032. IN BOOLEAN Wait,
  1033. IN PVOID InputBuffer OPTIONAL,
  1034. IN ULONG InputBufferLength,
  1035. OUT PVOID OutputBuffer OPTIONAL,
  1036. IN ULONG OutputBufferLength,
  1037. IN ULONG IoControlCode,
  1038. OUT PIO_STATUS_BLOCK IoStatus,
  1039. IN struct _DEVICE_OBJECT *DeviceObject
  1040. );
  1041. //
  1042. // Routines to handle getting and setting connect data.
  1043. //
  1044. NTSTATUS
  1045. AfdGetConnectData (
  1046. IN PFILE_OBJECT FileObject,
  1047. IN ULONG IoctlCode,
  1048. IN KPROCESSOR_MODE RequestorMode,
  1049. IN PVOID InputBuffer,
  1050. IN ULONG InputBufferLength,
  1051. IN PVOID OutputBuffer,
  1052. IN ULONG OutputBufferLength,
  1053. OUT PULONG_PTR Information
  1054. );
  1055. NTSTATUS
  1056. AfdSetConnectData (
  1057. IN PFILE_OBJECT FileObject,
  1058. IN ULONG IoctlCode,
  1059. IN KPROCESSOR_MODE RequestorMode,
  1060. IN PVOID InputBuffer,
  1061. IN ULONG InputBufferLength,
  1062. IN PVOID OutputBuffer,
  1063. IN ULONG OutputBufferLength,
  1064. OUT PULONG_PTR Information
  1065. );
  1066. NTSTATUS
  1067. AfdSaveReceivedConnectData (
  1068. IN OUT PAFD_CONNECT_DATA_BUFFERS * DataBuffers,
  1069. IN ULONG IoControlCode,
  1070. IN PVOID Buffer,
  1071. IN ULONG BufferLength
  1072. );
  1073. //
  1074. // Buffer management routines.
  1075. //
  1076. PVOID
  1077. AfdAllocateBuffer (
  1078. IN POOL_TYPE PoolType,
  1079. IN SIZE_T NumberOfBytes,
  1080. IN ULONG Tag
  1081. );
  1082. PVOID
  1083. AfdAllocateBufferTag (
  1084. IN POOL_TYPE PoolType,
  1085. IN SIZE_T NumberOfBytes,
  1086. IN ULONG Tag
  1087. );
  1088. VOID
  1089. NTAPI
  1090. AfdFreeBufferTag(
  1091. IN PVOID AfdBufferTag
  1092. );
  1093. PVOID
  1094. AfdAllocateRemoteAddress (
  1095. IN POOL_TYPE PoolType,
  1096. IN SIZE_T NumberOfBytes,
  1097. IN ULONG Tag
  1098. );
  1099. VOID
  1100. NTAPI
  1101. AfdFreeRemoteAddress(
  1102. IN PVOID AfdBufferTag
  1103. );
  1104. #define AFDB_RAISE_ON_FAILURE ((ULONG_PTR)1)
  1105. PAFD_BUFFER_TAG
  1106. AfdGetBufferTag (
  1107. IN ULONG AddressSize,
  1108. IN PEPROCESS Process
  1109. );
  1110. #define AfdGetBufferTagRaiseOnFailure(_as,_pr) \
  1111. AfdGetBufferTag((_as),((PEPROCESS)((ULONG_PTR)(_pr)|AFDB_RAISE_ON_FAILURE)))
  1112. ULONG
  1113. AfdCalculateBufferSize (
  1114. IN ULONG BufferDataSize,
  1115. IN ULONG AddressSize,
  1116. IN CCHAR StackSize
  1117. );
  1118. PAFD_BUFFER
  1119. FASTCALL
  1120. AfdGetBufferFast (
  1121. IN ULONG BufferDataSize,
  1122. IN ULONG AddressSize,
  1123. IN PEPROCESS Process
  1124. );
  1125. #ifdef _AFD_VARIABLE_STACK_
  1126. PAFD_BUFFER
  1127. FASTCALL
  1128. AfdGetBufferWithMaxStackSize (
  1129. IN ULONG BufferDataSize,
  1130. IN ULONG AddressSize,
  1131. IN PEPROCESS Process
  1132. );
  1133. #define AfdGetBuffer(_e,_ds,_as,_pr) \
  1134. (((_e)->TransportInfo->GetBuffer)(_ds,_as,_pr))
  1135. #else // _AFD_VARIABLE_STACK_
  1136. #define AfdGetBuffer(_e,_ds,_as,_pr) AfdGetBufferFast(_ds,_as,_pr)
  1137. #endif // _AFD_VARIABLE_STACK_
  1138. #define AfdGetBufferRaiseOnFailure(_e,_ds,_as,_pr) \
  1139. AfdGetBuffer(_e,_ds,_as,((PEPROCESS)((ULONG_PTR)(_pr)|AFDB_RAISE_ON_FAILURE)))
  1140. VOID
  1141. AfdReturnBuffer (
  1142. IN PAFD_BUFFER_HEADER AfdBufferHeader,
  1143. IN PEPROCESS Process
  1144. );
  1145. VOID
  1146. NTAPI
  1147. AfdFreeBuffer(
  1148. IN PVOID AfdBuffer
  1149. );
  1150. VOID
  1151. AfdInitializeBufferManager (
  1152. VOID
  1153. );
  1154. //
  1155. // Group ID managment routines.
  1156. //
  1157. BOOLEAN
  1158. AfdInitializeGroup(
  1159. VOID
  1160. );
  1161. VOID
  1162. AfdTerminateGroup(
  1163. VOID
  1164. );
  1165. BOOLEAN
  1166. AfdReferenceGroup(
  1167. IN LONG Group,
  1168. OUT PAFD_GROUP_TYPE GroupType
  1169. );
  1170. BOOLEAN
  1171. AfdDereferenceGroup(
  1172. IN LONG Group
  1173. );
  1174. BOOLEAN
  1175. AfdGetGroup(
  1176. IN OUT PLONG Group,
  1177. OUT PAFD_GROUP_TYPE GroupType
  1178. );
  1179. BOOLEAN
  1180. AfdCancelIrp (
  1181. IN PIRP Irp
  1182. );
  1183. // PnP and PM routines
  1184. NTSTATUS
  1185. FASTCALL
  1186. AfdPnpPower (
  1187. IN PIRP Irp,
  1188. IN PIO_STACK_LOCATION IrpSp
  1189. );
  1190. NTSTATUS
  1191. AfdRoutingInterfaceQuery (
  1192. IN PFILE_OBJECT FileObject,
  1193. IN ULONG IoctlCode,
  1194. IN KPROCESSOR_MODE RequestorMode,
  1195. IN PVOID InputBuffer,
  1196. IN ULONG InputBufferLength,
  1197. IN PVOID OutputBuffer,
  1198. IN ULONG OutputBufferLength,
  1199. OUT PULONG_PTR Information
  1200. );
  1201. NTSTATUS
  1202. FASTCALL
  1203. AfdRoutingInterfaceChange (
  1204. IN PIRP Irp,
  1205. IN PIO_STACK_LOCATION IrpSp
  1206. );
  1207. NTSTATUS
  1208. AfdAddressListQuery (
  1209. IN PFILE_OBJECT FileObject,
  1210. IN ULONG IoctlCode,
  1211. IN KPROCESSOR_MODE RequestorMode,
  1212. IN PVOID InputBuffer,
  1213. IN ULONG InputBufferLength,
  1214. IN PVOID OutputBuffer,
  1215. IN ULONG OutputBufferLength,
  1216. OUT PULONG_PTR Information
  1217. );
  1218. NTSTATUS
  1219. FASTCALL
  1220. AfdAddressListChange (
  1221. IN PIRP Irp,
  1222. IN PIO_STACK_LOCATION IrpSp
  1223. );
  1224. VOID
  1225. AfdDeregisterPnPHandlers (
  1226. PVOID Param
  1227. );
  1228. VOID
  1229. AfdCleanupRoutingChange (
  1230. IN PAFD_ENDPOINT Endpoint
  1231. );
  1232. NTSTATUS
  1233. FASTCALL
  1234. AfdDoTransportIoctl (
  1235. IN PIRP Irp,
  1236. IN PIO_STACK_LOCATION IrpSp
  1237. );
  1238. BOOLEAN
  1239. AfdLRRepostReceive (
  1240. PAFD_LR_LIST_ITEM ListEntry
  1241. );
  1242. VOID
  1243. AfdLRListAddItem (
  1244. PAFD_LR_LIST_ITEM Item,
  1245. PAFD_LR_LIST_ROUTINE Routine
  1246. );
  1247. VOID
  1248. AfdCheckLookasideLists (
  1249. IN PKDPC Dpc,
  1250. IN PVOID DeferredContext,
  1251. IN PVOID SystemArgument1,
  1252. IN PVOID SystemArgument2
  1253. );
  1254. #ifdef _AFD_VARIABLE_STACK_
  1255. VOID
  1256. AfdFixTransportEntryPointsForBigStackSize (
  1257. IN OUT PAFD_TRANSPORT_INFO TransportInfo,
  1258. IN CCHAR StackSize
  1259. );
  1260. NTSTATUS
  1261. FASTCALL
  1262. AfdCallDriverStackIncrease (
  1263. IN PDEVICE_OBJECT DeviceObject,
  1264. IN OUT PIRP Irp
  1265. );
  1266. PIRP
  1267. AfdGetStackIncreaseIrpAndRecordIt (
  1268. IN PAFD_ENDPOINT Endpoint,
  1269. IN PDEVICE_OBJECT DeviceObject,
  1270. IN OUT PIRP Irp
  1271. #if DBG
  1272. ,
  1273. IN PCHAR File,
  1274. IN ULONG Line
  1275. #endif
  1276. );
  1277. #endif //_AFD_VARIABLE_STACK_
  1278. PAFD_TPACKETS_INFO_INTERNAL
  1279. FASTCALL
  1280. AfdGetTpInfoFast (
  1281. ULONG ElementCount
  1282. );
  1283. #ifdef _AFD_VARIABLE_STACK_
  1284. #define AfdGetTpInfo(_e,_c) \
  1285. (((_e)->TransportInfo->GetTpInfo)(_c))
  1286. PAFD_TPACKETS_INFO_INTERNAL
  1287. FASTCALL
  1288. AfdGetTpInfoWithMaxStackSize (
  1289. ULONG ElementCount
  1290. );
  1291. #else //_AFD_VARIABLE_STACK_
  1292. #define AfdGetTpInfo(_e,_c) AfdGetTpInfoFast(_c)
  1293. #endif //_AFD_VARIABLE_STACK_
  1294. ULONG
  1295. AfdComputeTpInfoSize (
  1296. ULONG ElementCount,
  1297. CCHAR IrpStackCount
  1298. );
  1299. NTSTATUS
  1300. FASTCALL
  1301. AfdTransmitPackets (
  1302. IN PIRP Irp,
  1303. IN PIO_STACK_LOCATION IrpSp
  1304. );
  1305. NTSTATUS
  1306. FASTCALL
  1307. AfdSuperDisconnect (
  1308. IN PIRP Irp,
  1309. IN PIO_STACK_LOCATION IrpSp
  1310. );
  1311. VOID
  1312. AfdCompleteClosePendedTPackets (
  1313. PAFD_ENDPOINT Endpoint
  1314. );
  1315. BOOLEAN
  1316. AfdEnqueueTpSendIrp (
  1317. PAFD_ENDPOINT Endpoint,
  1318. PIRP SendIrp,
  1319. BOOLEAN AfdIrp
  1320. );
  1321. PVOID
  1322. AfdAllocateTpInfo (
  1323. IN POOL_TYPE PoolType,
  1324. IN SIZE_T NumberOfBytes,
  1325. IN ULONG Tag
  1326. );
  1327. VOID
  1328. NTAPI
  1329. AfdFreeTpInfo (
  1330. PVOID TpInfo
  1331. );
  1332. //
  1333. // SAN prototypes
  1334. //
  1335. NTSTATUS
  1336. AfdServiceWaitForListen (
  1337. PIRP Irp,
  1338. PAFD_CONNECTION Connection,
  1339. PAFD_LOCK_QUEUE_HANDLE LockHandle
  1340. );
  1341. VOID
  1342. AfdSanCancelAccept (
  1343. IN PDEVICE_OBJECT DeviceObject,
  1344. IN PIRP Irp
  1345. );
  1346. NTSTATUS
  1347. AfdSanAcceptCore (
  1348. PIRP AcceptIrp,
  1349. PFILE_OBJECT AcceptFileObject,
  1350. PAFD_CONNECTION Connection,
  1351. PAFD_LOCK_QUEUE_HANDLE LockHandle
  1352. );
  1353. NTSTATUS
  1354. AfdSanCreateHelper (
  1355. PIRP Irp,
  1356. PFILE_FULL_EA_INFORMATION EaBuffer,
  1357. PAFD_ENDPOINT *Endpoint
  1358. );
  1359. VOID
  1360. AfdSanHelperCleanup (
  1361. PAFD_ENDPOINT SanHlprEndpoint
  1362. );
  1363. VOID
  1364. AfdSanCleanupHelper (
  1365. PAFD_ENDPOINT Endpoint
  1366. );
  1367. VOID
  1368. AfdSanCleanupEndpoint (
  1369. PAFD_ENDPOINT Endpoint
  1370. );
  1371. NTSTATUS
  1372. AfdSanFastCementEndpoint (
  1373. IN PFILE_OBJECT FileObject,
  1374. IN ULONG IoctlCode,
  1375. IN KPROCESSOR_MODE RequestorMode,
  1376. IN PVOID InputBuffer,
  1377. IN ULONG InputBufferLength,
  1378. IN PVOID OutputBuffer,
  1379. IN ULONG OutputBufferLength,
  1380. OUT PULONG_PTR Information
  1381. );
  1382. NTSTATUS
  1383. AfdSanFastSetEvents (
  1384. IN PFILE_OBJECT FileObject,
  1385. IN ULONG IoctlCode,
  1386. IN KPROCESSOR_MODE RequestorMode,
  1387. IN PVOID InputBuffer,
  1388. IN ULONG InputBufferLength,
  1389. IN PVOID OutputBuffer,
  1390. IN ULONG OutputBufferLength,
  1391. OUT PULONG_PTR Information
  1392. );
  1393. NTSTATUS
  1394. AfdSanFastResetEvents (
  1395. IN PFILE_OBJECT FileObject,
  1396. IN ULONG IoctlCode,
  1397. IN KPROCESSOR_MODE RequestorMode,
  1398. IN PVOID InputBuffer,
  1399. IN ULONG InputBufferLength,
  1400. IN PVOID OutputBuffer,
  1401. IN ULONG OutputBufferLength,
  1402. OUT PULONG_PTR Information
  1403. );
  1404. NTSTATUS
  1405. FASTCALL
  1406. AfdSanConnectHandler (
  1407. PIRP Irp,
  1408. PIO_STACK_LOCATION IrpSp
  1409. );
  1410. NTSTATUS
  1411. AfdSanFastCompleteAccept (
  1412. IN PFILE_OBJECT FileObject,
  1413. IN ULONG IoctlCode,
  1414. IN KPROCESSOR_MODE RequestorMode,
  1415. IN PVOID InputBuffer,
  1416. IN ULONG InputBufferLength,
  1417. IN PVOID OutputBuffer,
  1418. IN ULONG OutputBufferLength,
  1419. OUT PULONG_PTR Information
  1420. );
  1421. NTSTATUS
  1422. FASTCALL
  1423. AfdSanRedirectRequest (
  1424. PIRP Irp,
  1425. PIO_STACK_LOCATION IrpSp
  1426. );
  1427. NTSTATUS
  1428. AfdSanFastCompleteRequest (
  1429. IN PFILE_OBJECT FileObject,
  1430. IN ULONG IoctlCode,
  1431. IN KPROCESSOR_MODE RequestorMode,
  1432. IN PVOID InputBuffer,
  1433. IN ULONG InputBufferLength,
  1434. IN PVOID OutputBuffer,
  1435. IN ULONG OutputBufferLength,
  1436. OUT PULONG_PTR Information
  1437. );
  1438. NTSTATUS
  1439. AfdSanFastCompleteIo (
  1440. IN PFILE_OBJECT FileObject,
  1441. IN ULONG IoctlCode,
  1442. IN KPROCESSOR_MODE RequestorMode,
  1443. IN PVOID InputBuffer,
  1444. IN ULONG InputBufferLength,
  1445. IN PVOID OutputBuffer,
  1446. IN ULONG OutputBufferLength,
  1447. OUT PULONG_PTR Information
  1448. );
  1449. NTSTATUS
  1450. AfdSanFastRefreshEndpoint (
  1451. IN PFILE_OBJECT FileObject,
  1452. IN ULONG IoctlCode,
  1453. IN KPROCESSOR_MODE RequestorMode,
  1454. IN PVOID InputBuffer,
  1455. IN ULONG InputBufferLength,
  1456. IN PVOID OutputBuffer,
  1457. IN ULONG OutputBufferLength,
  1458. OUT PULONG_PTR Information
  1459. );
  1460. NTSTATUS
  1461. AfdSanFastGetPhysicalAddr (
  1462. IN PFILE_OBJECT FileObject,
  1463. IN ULONG IoctlCode,
  1464. IN KPROCESSOR_MODE RequestorMode,
  1465. IN PVOID InputBuffer,
  1466. IN ULONG InputBufferLength,
  1467. IN PVOID OutputBuffer,
  1468. IN ULONG OutputBufferLength,
  1469. OUT PULONG_PTR Information
  1470. );
  1471. NTSTATUS
  1472. AfdSanPollBegin (
  1473. PAFD_ENDPOINT Endpoint,
  1474. ULONG EventMask
  1475. );
  1476. VOID
  1477. AfdSanPollEnd (
  1478. PAFD_ENDPOINT Endpoint,
  1479. ULONG EventMask
  1480. );
  1481. VOID
  1482. AfdSanPollUpdate (
  1483. PAFD_ENDPOINT Endpoint,
  1484. ULONG EventMask
  1485. );
  1486. NTSTATUS
  1487. AfdSanPollMerge (
  1488. PAFD_ENDPOINT Endpoint,
  1489. PAFD_SWITCH_CONTEXT Context
  1490. );
  1491. NTSTATUS
  1492. AfdSanFastTransferCtx (
  1493. IN PFILE_OBJECT FileObject,
  1494. IN ULONG IoctlCode,
  1495. IN KPROCESSOR_MODE RequestorMode,
  1496. IN PVOID InputBuffer,
  1497. IN ULONG InputBufferLength,
  1498. IN PVOID OutputBuffer,
  1499. IN ULONG OutputBufferLength,
  1500. OUT PULONG_PTR Information
  1501. );
  1502. NTSTATUS
  1503. AfdSanFastGetServicePid (
  1504. IN PFILE_OBJECT FileObject,
  1505. IN ULONG IoctlCode,
  1506. IN KPROCESSOR_MODE RequestorMode,
  1507. IN PVOID InputBuffer,
  1508. IN ULONG InputBufferLength,
  1509. IN PVOID OutputBuffer,
  1510. IN ULONG OutputBufferLength,
  1511. OUT PULONG_PTR Information
  1512. );
  1513. NTSTATUS
  1514. AfdSanFastSetServiceProcess (
  1515. IN PFILE_OBJECT FileObject,
  1516. IN ULONG IoctlCode,
  1517. IN KPROCESSOR_MODE RequestorMode,
  1518. IN PVOID InputBuffer,
  1519. IN ULONG InputBufferLength,
  1520. IN PVOID OutputBuffer,
  1521. IN ULONG OutputBufferLength,
  1522. OUT PULONG_PTR Information
  1523. );
  1524. NTSTATUS
  1525. AfdSanFastProviderChange (
  1526. IN PFILE_OBJECT FileObject,
  1527. IN ULONG IoctlCode,
  1528. IN KPROCESSOR_MODE RequestorMode,
  1529. IN PVOID InputBuffer,
  1530. IN ULONG InputBufferLength,
  1531. IN PVOID OutputBuffer,
  1532. IN ULONG OutputBufferLength,
  1533. OUT PULONG_PTR Information
  1534. );
  1535. NTSTATUS
  1536. FASTCALL
  1537. AfdSanAddrListChange (
  1538. PIRP Irp,
  1539. PIO_STACK_LOCATION IrpSp
  1540. );
  1541. NTSTATUS
  1542. FASTCALL
  1543. AfdSanAcquireContext (
  1544. PIRP Irp,
  1545. PIO_STACK_LOCATION IrpSp
  1546. );
  1547. BOOLEAN
  1548. AfdSanFastUnlockAll (
  1549. IN PFILE_OBJECT FileObject,
  1550. IN PEPROCESS Process,
  1551. OUT PIO_STATUS_BLOCK IoStatus,
  1552. IN PDEVICE_OBJECT DeviceObject
  1553. );
  1554. VOID
  1555. AfdSanReleaseConnection (
  1556. PAFD_ENDPOINT ListenEndpoint,
  1557. PAFD_CONNECTION Connection,
  1558. BOOLEAN CheckBacklog
  1559. );
  1560. VOID
  1561. AfdSanAbortConnection (
  1562. PAFD_CONNECTION Connection
  1563. );
  1564. NTSTATUS
  1565. AfdSanRestartRequestProcessing (
  1566. PAFD_ENDPOINT Endpoint,
  1567. NTSTATUS Status
  1568. );
  1569. NTSTATUS
  1570. AfdValidateStatus (
  1571. NTSTATUS Status
  1572. );
  1573. //
  1574. // Check if datagram part of the union is valid
  1575. //
  1576. #define IS_DGRAM_ENDPOINT(endp) \
  1577. ((endp)->Type==AfdBlockTypeDatagram)
  1578. //
  1579. // Check if Vc part of the union is valid
  1580. //
  1581. #define IS_VC_ENDPOINT(endp) \
  1582. ( ((endp)->Type==AfdBlockTypeEndpoint) || \
  1583. ((endp)->Type==AfdBlockTypeVcConnecting) || \
  1584. ((endp)->Type==AfdBlockTypeVcListening) || \
  1585. ((endp)->Type==AfdBlockTypeVcBoth) )
  1586. #define IS_SAN_ENDPOINT(endp) \
  1587. ((endp)->Type==AfdBlockTypeSanEndpoint)
  1588. #define IS_SAN_HELPER(endp) \
  1589. ((endp)->Type==AfdBlockTypeSanHelper)
  1590. #define IS_MESSAGE_ENDPOINT(endp) \
  1591. ((endp)->afdMessageMode)
  1592. #define IS_RAW_ENDPOINT(endp) \
  1593. ((endp)->afdRaw)
  1594. #define IS_CROOT_ENDPOINT(endp) \
  1595. ((endp)->afdMultipoint && (endp)->afdC_Root)
  1596. #define IS_DELAYED_ACCEPTANCE_ENDPOINT(endp) \
  1597. ((endp)->DelayedAcceptance)
  1598. #define IS_TDI_MESSAGE_MODE(endp) \
  1599. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_MESSAGE_MODE)!=0))
  1600. #define IS_TDI_BUFFERRING(endp) \
  1601. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_INTERNAL_BUFFERING)!=0))
  1602. #define IS_TDI_EXPEDITED(endp) \
  1603. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_EXPEDITED_DATA)!=0))
  1604. #define IS_TDI_ORDERLY_RELEASE(endp) \
  1605. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_ORDERLY_RELEASE)!=0))
  1606. #define IS_TDI_DGRAM_CONNECTION(endp) \
  1607. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_DGRAM_CONNECTION)!=0))
  1608. #define IS_TDI_FORCE_ACCESS_CHECK(endp) \
  1609. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_FORCE_ACCESS_CHECK)!=0))
  1610. #define IS_TDI_DELAYED_ACCEPTANCE(endp) \
  1611. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_DELAYED_ACCEPTANCE)!=0))
  1612. #ifdef TDI_SERVICE_ADDRESS_SECURITY
  1613. #define IS_TDI_ADDRESS_SECURITY(endp) \
  1614. ((BOOLEAN)(((endp)->TdiServiceFlags&TDI_SERVICE_ADDRESS_SECURITY)!=0))
  1615. #else
  1616. #define IS_TDI_ADDRESS_SECURITY(endp) \
  1617. FALSE
  1618. #endif
  1619. #define IS_DATA_ON_CONNECTION_B(conn) \
  1620. ((conn)->Common.Bufferring.ReceiveBytesIndicated.QuadPart > \
  1621. ((conn)->Common.Bufferring.ReceiveBytesTaken.QuadPart + \
  1622. (conn)->Common.Bufferring.ReceiveBytesOutstanding.QuadPart )\
  1623. || \
  1624. (conn)->VcZeroByteReceiveIndicated)
  1625. #define IS_EXPEDITED_DATA_ON_CONNECTION_B(conn) \
  1626. ((conn)->Common.Bufferring.ReceiveExpeditedBytesIndicated.QuadPart > \
  1627. ((conn)->Common.Bufferring.ReceiveExpeditedBytesTaken.QuadPart + \
  1628. (conn)->Common.Bufferring.ReceiveExpeditedBytesOutstanding.QuadPart) )
  1629. #define IS_DATA_ON_CONNECTION_NB(conn) \
  1630. ( (conn)->VcBufferredReceiveCount != 0 )
  1631. #define IS_EXPEDITED_DATA_ON_CONNECTION_NB(conn) \
  1632. ( (conn)->VcBufferredExpeditedCount != 0 )
  1633. #define IS_DATA_ON_CONNECTION(conn) \
  1634. ((conn)->TdiBufferring ? \
  1635. IS_DATA_ON_CONNECTION_B(conn) : \
  1636. IS_DATA_ON_CONNECTION_NB(conn) )
  1637. #define IS_EXPEDITED_DATA_ON_CONNECTION(conn) \
  1638. ((conn)->TdiBufferring ? \
  1639. IS_EXPEDITED_DATA_ON_CONNECTION_B(conn) : \
  1640. IS_EXPEDITED_DATA_ON_CONNECTION_NB(conn) )
  1641. #define ARE_DATAGRAMS_ON_ENDPOINT(endp) \
  1642. ( (endp)->DgBufferredReceiveCount != 0 )
  1643. #define AFD_START_STATE_CHANGE(endp,newState) \
  1644. (InterlockedCompareExchange( \
  1645. &(endp)->StateChangeInProgress, \
  1646. newState, \
  1647. 0)==0)
  1648. #if DBG
  1649. #define AFD_END_STATE_CHANGE(endp) \
  1650. ASSERT (InterlockedExchange(&(endp)->StateChangeInProgress,0)!=0)
  1651. #else
  1652. //
  1653. // Do interlocked to have a memory barrier (on both x86 and IA64)
  1654. //
  1655. #define AFD_END_STATE_CHANGE(endp) \
  1656. InterlockedExchange(&(endp)->StateChangeInProgress,0)
  1657. #endif
  1658. LOGICAL
  1659. FORCEINLINE
  1660. AfdPreventStateChange (
  1661. PAFD_ENDPOINT Endpoint
  1662. )
  1663. {
  1664. LONG state;
  1665. do {
  1666. state = Endpoint->StateChangeInProgress;
  1667. }
  1668. while (state<=0 &&
  1669. InterlockedCompareExchange (
  1670. &Endpoint->StateChangeInProgress,
  1671. state-1,
  1672. state)!=state);
  1673. return (state<=0);
  1674. }
  1675. #define AFD_PREVENT_STATE_CHANGE(endp) AfdPreventStateChange(endp)
  1676. #if DBG
  1677. #define AFD_REALLOW_STATE_CHANGE(endp) \
  1678. ASSERT (InterlockedIncrement(&(endp)->StateChangeInProgress)<=0)
  1679. #else
  1680. #define AFD_REALLOW_STATE_CHANGE(endp) \
  1681. InterlockedIncrement(&(endp)->StateChangeInProgress)
  1682. #endif
  1683. #define AFD_ALLOCATE_REMOTE_ADDRESS(_l) \
  1684. (((ULONG)(_l)<=AfdStandardAddressLength) \
  1685. ? ExAllocateFromNPagedLookasideList( \
  1686. &AfdLookasideLists->RemoteAddrList )\
  1687. : AFD_ALLOCATE_POOL(NonPagedPool, \
  1688. (_l), AFD_REMOTE_ADDRESS_POOL_TAG) \
  1689. )
  1690. #define AFD_RETURN_REMOTE_ADDRESS(_a,_l) \
  1691. (((ULONG)(_l)<=AfdStandardAddressLength) \
  1692. ? ExFreeToNPagedLookasideList( \
  1693. &AfdLookasideLists->RemoteAddrList, \
  1694. (_a)) \
  1695. : AFD_FREE_POOL((_a), AFD_REMOTE_ADDRESS_POOL_TAG) \
  1696. )
  1697. #if DBG
  1698. LONG
  1699. AfdApcExceptionFilter(
  1700. PEXCEPTION_POINTERS ExceptionPointers,
  1701. PCHAR SourceFile,
  1702. LONG LineNumber
  1703. );
  1704. #endif
  1705. //
  1706. // Debug statistic manipulators. On checked builds these macros update
  1707. // their corresponding statistic counter. On retail builds, these macros
  1708. // evaluate to nothing.
  1709. //
  1710. #if AFD_KEEP_STATS
  1711. #define AfdRecordPoolQuotaCharged( b ) \
  1712. ExInterlockedAddLargeStatistic( \
  1713. &AfdQuotaStats.Charged, \
  1714. (b) \
  1715. )
  1716. #define AfdRecordPoolQuotaReturned( b ) \
  1717. ExInterlockedAddLargeStatistic( \
  1718. &AfdQuotaStats.Returned, \
  1719. (b) \
  1720. )
  1721. #define AfdRecordAddrOpened() InterlockedIncrement( &AfdHandleStats.AddrOpened )
  1722. #define AfdRecordAddrClosed() InterlockedIncrement( &AfdHandleStats.AddrClosed )
  1723. #define AfdRecordAddrRef() InterlockedIncrement( &AfdHandleStats.AddrRef )
  1724. #define AfdRecordAddrDeref() InterlockedIncrement( &AfdHandleStats.AddrDeref )
  1725. #define AfdRecordConnOpened() InterlockedIncrement( &AfdHandleStats.ConnOpened )
  1726. #define AfdRecordConnClosed() InterlockedIncrement( &AfdHandleStats.ConnClosed )
  1727. #define AfdRecordConnRef() InterlockedIncrement( &AfdHandleStats.ConnRef )
  1728. #define AfdRecordConnDeref() InterlockedIncrement( &AfdHandleStats.ConnDeref )
  1729. #define AfdRecordFileRef() InterlockedIncrement( &AfdHandleStats.FileRef )
  1730. #define AfdRecordFileDeref() InterlockedIncrement( &AfdHandleStats.FileDeref )
  1731. #define AfdRecordAfdWorkItemsQueued() InterlockedIncrement( &AfdQueueStats.AfdWorkItemsQueued )
  1732. #define AfdRecordExWorkItemsQueued() InterlockedIncrement( &AfdQueueStats.ExWorkItemsQueued )
  1733. #define AfdRecordWorkerEnter() InterlockedIncrement( &AfdQueueStats.WorkerEnter )
  1734. #define AfdRecordWorkerLeave() InterlockedIncrement( &AfdQueueStats.WorkerLeave )
  1735. #define AfdRecordAfdWorkItemsProcessed() InterlockedIncrement( &AfdQueueStats.AfdWorkItemsProcessed )
  1736. #define AfdRecordAfdWorkerThread(t) \
  1737. if( 1 ) { \
  1738. ASSERT( AfdQueueStats.AfdWorkerThread == NULL || \
  1739. (t) == NULL ); \
  1740. AfdQueueStats.AfdWorkerThread = (t); \
  1741. } else
  1742. #define AfdRecordConnectedReferencesAdded() InterlockedIncrement( &AfdConnectionStats.ConnectedReferencesAdded )
  1743. #define AfdRecordConnectedReferencesDeleted() InterlockedIncrement( &AfdConnectionStats.ConnectedReferencesDeleted )
  1744. #define AfdRecordGracefulDisconnectsInitiated() InterlockedIncrement( &AfdConnectionStats.GracefulDisconnectsInitiated )
  1745. #define AfdRecordGracefulDisconnectsCompleted() InterlockedIncrement( &AfdConnectionStats.GracefulDisconnectsCompleted )
  1746. #define AfdRecordGracefulDisconnectIndications() InterlockedIncrement( &AfdConnectionStats.GracefulDisconnectIndications )
  1747. #define AfdRecordAbortiveDisconnectsInitiated() InterlockedIncrement( &AfdConnectionStats.AbortiveDisconnectsInitiated )
  1748. #define AfdRecordAbortiveDisconnectsCompleted() InterlockedIncrement( &AfdConnectionStats.AbortiveDisconnectsCompleted )
  1749. #define AfdRecordAbortiveDisconnectIndications() InterlockedIncrement( &AfdConnectionStats.AbortiveDisconnectIndications )
  1750. #define AfdRecordConnectionIndications() InterlockedIncrement( &AfdConnectionStats.ConnectionIndications )
  1751. #define AfdRecordConnectionsDropped() InterlockedIncrement( &AfdConnectionStats.ConnectionsDropped )
  1752. #define AfdRecordConnectionsAccepted() InterlockedIncrement( &AfdConnectionStats.ConnectionsAccepted )
  1753. #define AfdRecordConnectionsPreaccepted() InterlockedIncrement( &AfdConnectionStats.ConnectionsPreaccepted )
  1754. #define AfdRecordConnectionsReused() InterlockedIncrement( &AfdConnectionStats.ConnectionsReused )
  1755. #define AfdRecordEndpointsReused() InterlockedIncrement( &AfdConnectionStats.EndpointsReused )
  1756. #else // !AFD_KEEP_STATS
  1757. #define AfdRecordPoolQuotaCharged(b)
  1758. #define AfdRecordPoolQuotaReturned(b)
  1759. #define AfdRecordAddrOpened()
  1760. #define AfdRecordAddrClosed()
  1761. #define AfdRecordAddrRef()
  1762. #define AfdRecordAddrDeref()
  1763. #define AfdRecordConnOpened()
  1764. #define AfdRecordConnClosed()
  1765. #define AfdRecordConnRef()
  1766. #define AfdRecordConnDeref()
  1767. #define AfdRecordFileRef()
  1768. #define AfdRecordFileDeref()
  1769. #define AfdRecordAfdWorkItemsQueued()
  1770. #define AfdRecordExWorkItemsQueued()
  1771. #define AfdRecordWorkerEnter()
  1772. #define AfdRecordWorkerLeave()
  1773. #define AfdRecordAfdWorkItemsProcessed()
  1774. #define AfdRecordAfdWorkerThread(t)
  1775. #define AfdRecordConnectedReferencesAdded()
  1776. #define AfdRecordConnectedReferencesDeleted()
  1777. #define AfdRecordGracefulDisconnectsInitiated()
  1778. #define AfdRecordGracefulDisconnectsCompleted()
  1779. #define AfdRecordGracefulDisconnectIndications()
  1780. #define AfdRecordAbortiveDisconnectsInitiated()
  1781. #define AfdRecordAbortiveDisconnectsCompleted()
  1782. #define AfdRecordAbortiveDisconnectIndications()
  1783. #define AfdRecordConnectionIndications()
  1784. #define AfdRecordConnectionsDropped()
  1785. #define AfdRecordConnectionsAccepted()
  1786. #define AfdRecordConnectionsPreaccepted()
  1787. #define AfdRecordConnectionsReused()
  1788. #define AfdRecordEndpointsReused()
  1789. #endif // if AFD_KEEP_STATS
  1790. #if DBG
  1791. #define AFD_ALLOCATE_POOL(a,b,t) AfdAllocatePool( a,b,t,__FILE__,__LINE__,FALSE,LowPoolPriority )
  1792. #define AFD_ALLOCATE_POOL_WITH_QUOTA(a,b,t) AfdAllocatePool( (a)|POOL_RAISE_IF_ALLOCATION_FAILURE,b,t,__FILE__,__LINE__,TRUE,LowPoolPriority )
  1793. #define AFD_ALLOCATE_POOL_PRIORITY(a,b,t,p) AfdAllocatePool( a,b,t,__FILE__,__LINE__,FALSE,p )
  1794. PVOID
  1795. AfdAllocatePool (
  1796. IN POOL_TYPE PoolType,
  1797. IN SIZE_T NumberOfBytes,
  1798. IN ULONG Tag,
  1799. IN PCHAR FileName,
  1800. IN ULONG LineNumber,
  1801. IN BOOLEAN WithQuota,
  1802. IN EX_POOL_PRIORITY Priority
  1803. );
  1804. #define AFD_FREE_POOL(a,t) AfdFreePool(a,t)
  1805. VOID
  1806. AfdFreePool (
  1807. IN PVOID Pointer,
  1808. IN ULONG Tag
  1809. );
  1810. BOOLEAN
  1811. AfdRecordOutstandingIrpDebug (
  1812. IN PAFD_ENDPOINT Endpoint,
  1813. IN PDEVICE_OBJECT DeviceObject,
  1814. IN PIRP Irp,
  1815. IN PCHAR FileName,
  1816. IN ULONG LineNumber
  1817. );
  1818. #define AfdRecordOutstandingIrp(a,b,c) \
  1819. AfdRecordOutstandingIrpDebug(a,b,c,__FILE__,__LINE__)
  1820. #ifdef _AFD_VARIABLE_STACK_
  1821. #define AfdIoCallDriver(_e,_d,_i) \
  1822. (AfdRecordOutstandingIrp(_e,_d,_i) \
  1823. ? ((_e)->TransportInfo->CallDriver)(_d,_i) \
  1824. : STATUS_INSUFFICIENT_RESOURCES \
  1825. )
  1826. #define AfdCheckStackSizeAndRecordOutstandingIrp(_e,_d,_i) \
  1827. ( ((_i)->CurrentLocation>(_d)->StackSize) \
  1828. ? (AfdRecordOutstandingIrp(_e,_d,_i) ? (_i) : (PIRP)NULL) \
  1829. : AfdGetStackIncreaseIrpAndRecordIt(_e,_d,_i,__FILE__,__LINE__) \
  1830. )
  1831. #else // _AFD_VARIABLE_STACK_
  1832. #define AfdIoCallDriver(_e,_d,_i) \
  1833. (AfdRecordOutstandingIrp(_e,_d,_i) \
  1834. ? IoCallDriver(_d,_i) \
  1835. : STATUS_INSUFFICIENT_RESOURCES \
  1836. )
  1837. #endif // _AFD_VARIABLE_STACK_
  1838. #define AfdCompleteOutstandingIrp(_e,_i) \
  1839. AfdCompleteOutstandingIrpDebug(_e,_i)
  1840. VOID
  1841. AfdCompleteOutstandingIrpDebug (
  1842. IN PAFD_ENDPOINT Endpoint,
  1843. IN PIRP Irp
  1844. );
  1845. #ifdef AFDDBG_QUOTA
  1846. VOID
  1847. AfdRecordQuotaHistory(
  1848. IN PEPROCESS Process,
  1849. IN LONG Bytes,
  1850. IN PSZ Type,
  1851. IN PVOID Block
  1852. );
  1853. #else
  1854. #define AfdRecordQuotaHistory(a,b,c,d)
  1855. #endif
  1856. extern ULONG AfdLocksAcquired;
  1857. //
  1858. // Queued spinlock wrappers - perform basic validation
  1859. //
  1860. #define AfdAcquireSpinLock(a,b) \
  1861. ASSERT(AfdLoaded); (b)->SpinLock=(a); KeAcquireInStackQueuedSpinLock(&(a)->ActualSpinLock,&((b)->LockHandle)); AfdLocksAcquired++
  1862. #define AfdReleaseSpinLock(a,b) \
  1863. AfdLocksAcquired--; ASSERT ((b)->SpinLock==(a)); ASSERT( AfdLoaded ); KeReleaseInStackQueuedSpinLock(&((b)->LockHandle));
  1864. #define AfdAcquireSpinLockAtDpcLevel(a,b) \
  1865. ASSERT( AfdLoaded ); (b)->SpinLock=(a); KeAcquireInStackQueuedSpinLockAtDpcLevel(&(a)->ActualSpinLock,&((b)->LockHandle)); AfdLocksAcquired++
  1866. #define AfdReleaseSpinLockFromDpcLevel(a,b) \
  1867. AfdLocksAcquired--; ASSERT ((b)->SpinLock==(a)); ASSERT( AfdLoaded ); KeReleaseInStackQueuedSpinLockFromDpcLevel(&((b)->LockHandle))
  1868. #define AfdInitializeSpinLock(a) \
  1869. KeInitializeSpinLock(&(a)->ActualSpinLock)
  1870. //
  1871. // Define our own assert so that we can actually catch assertion failures
  1872. // when running a checked AFD on a free kernel.
  1873. //
  1874. VOID
  1875. AfdAssert(
  1876. PVOID FailedAssertion,
  1877. PVOID FileName,
  1878. ULONG LineNumber,
  1879. PCHAR Message
  1880. );
  1881. #undef ASSERT
  1882. #define ASSERT( exp ) \
  1883. if (!(exp)) \
  1884. AfdAssert( #exp, __FILE__, __LINE__, NULL )
  1885. #undef ASSERTMSG
  1886. #define ASSERTMSG( msg, exp ) \
  1887. if (!(exp)) \
  1888. AfdAssert( #exp, __FILE__, __LINE__, msg )
  1889. #define AFD_EXCEPTION_FILTER_NO_STATUS() \
  1890. AfdExceptionFilter( \
  1891. (LPSTR)__FILE__, \
  1892. (LONG)__LINE__, \
  1893. GetExceptionInformation(), \
  1894. NULL \
  1895. )
  1896. #define AFD_EXCEPTION_FILTER(_s) \
  1897. AfdExceptionFilter( \
  1898. (LPSTR)__FILE__, \
  1899. (LONG)__LINE__, \
  1900. GetExceptionInformation(), \
  1901. &_s \
  1902. )
  1903. #else // !DBG
  1904. #define AFD_ALLOCATE_POOL(a,b,t) ExAllocatePoolWithTagPriority(a,b,t,LowPoolPriority)
  1905. #define AFD_ALLOCATE_POOL_WITH_QUOTA(a,b,t) ExAllocatePoolWithQuotaTag((a)|POOL_RAISE_IF_ALLOCATION_FAILURE,b,t)
  1906. #define AFD_ALLOCATE_POOL_PRIORITY(a,b,t,p) ExAllocatePoolWithTagPriority(a,b,t,p)
  1907. #define AFD_FREE_POOL(a,t) MyFreePoolWithTag(a,t)
  1908. #define AfdRecordOutstandingIrp(_e,_d,_i) \
  1909. (InterlockedIncrement(&((_e)->OutstandingIrpCount)), TRUE)
  1910. #ifdef _AFD_VARIABLE_STACK_
  1911. #define AfdIoCallDriver(_e,_d,_i) \
  1912. (AfdRecordOutstandingIrp(_e,_d,_i), ((_e)->TransportInfo->CallDriver) (_d,_i))
  1913. #define AfdCheckStackSizeAndRecordOutstandingIrp(_e,_d,_i) \
  1914. ( ((_i)->CurrentLocation>(_d)->StackSize) \
  1915. ? (InterlockedIncrement(&((_e)->OutstandingIrpCount)),_i) \
  1916. : AfdGetStackIncreaseIrpAndRecordIt(_e,_d,_i) \
  1917. )
  1918. #else // _AFD_VARIABLE_STACK_
  1919. #define AfdIoCallDriver(_e,_d,_i) \
  1920. (AfdRecordOutstandingIrp(_e,_d,_i), IoCallDriver (_d,_i))
  1921. #endif
  1922. #define AfdCompleteOutstandingIrp(_e,_i) \
  1923. InterlockedDecrement(&((_e)->OutstandingIrpCount))
  1924. #define AfdRecordQuotaHistory(a,b,c,d)
  1925. #define AfdAcquireSpinLock(a,b) KeAcquireInStackQueuedSpinLock(&(a)->ActualSpinLock,(b))
  1926. #define AfdReleaseSpinLock(a,b) KeReleaseInStackQueuedSpinLock((b))
  1927. #define AfdAcquireSpinLockAtDpcLevel(a,b) KeAcquireInStackQueuedSpinLockAtDpcLevel(&(a)->ActualSpinLock,(b))
  1928. #define AfdReleaseSpinLockFromDpcLevel(a,b) KeReleaseInStackQueuedSpinLockFromDpcLevel((b))
  1929. #define AfdInitializeSpinLock(a) \
  1930. KeInitializeSpinLock(&(a)->ActualSpinLock)
  1931. #define AFD_EXCEPTION_FILTER_NO_STATUS() \
  1932. EXCEPTION_EXECUTE_HANDLER
  1933. #define AFD_EXCEPTION_FILTER(_s) \
  1934. AfdExceptionFilter( \
  1935. GetExceptionInformation(), \
  1936. &_s \
  1937. )
  1938. #endif // def DBG
  1939. #if DBG || REFERENCE_DEBUG
  1940. VOID
  1941. AfdInitializeDebugData(
  1942. VOID
  1943. );
  1944. VOID
  1945. AfdFreeDebugData (
  1946. VOID
  1947. );
  1948. #endif
  1949. #endif // ndef _AFDPROCS_