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.

629 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. D:\nt\private\ntos\tdi\rawwan\core\macros.h
  5. Abstract:
  6. Macros for the NullTrans module. Adapted from ATMARP Client.
  7. Revision History:
  8. Who When What
  9. -------- -------- ----
  10. arvindm 05-07-97 created
  11. Notes:
  12. --*/
  13. #ifndef __RWAN_MACROS_H_INCLUDED
  14. #define __RWAN_MACROS_H_INCLUDED
  15. #ifndef MAX
  16. /*++
  17. OPAQUE
  18. MAX(
  19. IN OPAQUE Fred,
  20. IN OPAQUE Shred
  21. )
  22. --*/
  23. #define MAX(Fred, Shred) (((Fred) > (Shred)) ? (Fred) : (Shred))
  24. #endif // MAX
  25. #ifndef MIN
  26. /*++
  27. OPAQUE
  28. MIN(
  29. IN OPAQUE Fred,
  30. IN OPAQUE Shred
  31. )
  32. --*/
  33. #define MIN(Fred, Shred) (((Fred) < (Shred)) ? (Fred) : (Shred))
  34. #endif // MIN
  35. /*++
  36. VOID
  37. RWAN_SET_FLAG(
  38. IN ULONG Flags,
  39. IN ULONG Mask,
  40. IN ULONG Val
  41. )
  42. --*/
  43. #define RWAN_SET_FLAG(Flags, Mask, Val) \
  44. (Flags) = ((Flags) & ~(Mask)) | (Val)
  45. /*++
  46. BOOLEAN
  47. RWAN_IS_FLAG_SET(
  48. IN ULONG Flags,
  49. IN ULONG Mask,
  50. IN ULONG Val
  51. )
  52. --*/
  53. #define RWAN_IS_FLAG_SET(Flags, Mask, Val) \
  54. (((Flags) & (Mask)) == (Val))
  55. #define RWAN_SET_BIT(_Flags, _Bit) \
  56. (_Flags) = (_Flags) | (_Bit);
  57. #define RWAN_RESET_BIT(_Flags, _Bit) \
  58. (_Flags) &= ~(_Bit);
  59. #define RWAN_IS_BIT_SET(_Flags, _Bit) \
  60. (((_Flags) & (_Bit)) != 0)
  61. /*++
  62. VOID
  63. RWAN_INIT_EVENT_STRUCT(
  64. IN RWAN_EVENT *pEvent
  65. )
  66. --*/
  67. #define RWAN_INIT_EVENT_STRUCT(pEvent) NdisInitializeEvent(&((pEvent)->Event))
  68. /*++
  69. NDIS_STATUS
  70. RWAN_WAIT_ON_EVENT_STRUCT(
  71. IN RWAN_EVENT *pEvent
  72. )
  73. --*/
  74. #define RWAN_WAIT_ON_EVENT_STRUCT(pEvent) \
  75. (NdisWaitEvent(&((pEvent)->Event), 0), (pEvent)->Status)
  76. /*++
  77. VOID
  78. RWAN_SIGNAL_EVENT_STRUCT(
  79. IN RWAN_EVENT *pEvent,
  80. IN UINT Status
  81. )
  82. --*/
  83. #define RWAN_SIGNAL_EVENT_STRUCT(pEvent, _Status) \
  84. { (pEvent)->Status = _Status; NdisSetEvent(&((pEvent)->Event)); }
  85. /*++
  86. VOID
  87. RWAN_FREE_EVENT_STRUCT(
  88. IN RWAN_EVENT *pEvent
  89. )
  90. --*/
  91. #define RWAN_FREE_EVENT_STRUCT(pEvent) // Nothing to be done here
  92. /*++
  93. VOID
  94. RWAN_INIT_LOCK(
  95. IN PNDIS_SPIN_LOCK pLock
  96. )
  97. --*/
  98. #if DBG_SPIN_LOCK
  99. #define RWAN_INIT_LOCK(pLock) \
  100. RWanAllocateSpinLock(pLock, _FILENUMBER, __LINE__)
  101. #else
  102. #define RWAN_INIT_LOCK(pLock) \
  103. NdisAllocateSpinLock(pLock)
  104. #endif // DBG_SPIN_LOCK
  105. /*++
  106. VOID
  107. RWAN_ACQUIRE_LOCK(
  108. IN PNDIS_SPIN_LOCK pLock
  109. )
  110. --*/
  111. #if DBG_SPIN_LOCK
  112. #define RWAN_ACQUIRE_LOCK(pLock) \
  113. RWanAcquireSpinLock(pLock, _FILENUMBER, __LINE__)
  114. #else
  115. #define RWAN_ACQUIRE_LOCK(pLock) \
  116. NdisAcquireSpinLock(pLock)
  117. #endif // DBG_SPIN_LOCK
  118. /*++
  119. VOID
  120. RWAN_ACQUIRE_LOCK_DPC(
  121. IN PNDIS_SPIN_LOCK pLock
  122. )
  123. --*/
  124. #if DBG_SPIN_LOCK
  125. #define RWAN_ACQUIRE_LOCK_DPC(pLock) \
  126. RWanAcquireSpinLock(pLock, _FILENUMBER, __LINE__)
  127. #else
  128. #define RWAN_ACQUIRE_LOCK_DPC(pLock) \
  129. NdisDprAcquireSpinLock(pLock)
  130. #endif // DBG_SPIN_LOCK
  131. /*++
  132. VOID
  133. RWAN_RELEASE_LOCK(
  134. IN PNDIS_SPIN_LOCK pLock
  135. )
  136. --*/
  137. #if DBG_SPIN_LOCK
  138. #define RWAN_RELEASE_LOCK(pLock) \
  139. RWanReleaseSpinLock(pLock, _FILENUMBER, __LINE__)
  140. #else
  141. #define RWAN_RELEASE_LOCK(pLock) \
  142. NdisReleaseSpinLock(pLock)
  143. #endif // DBG_SPIN_LOCK
  144. /*++
  145. VOID
  146. RWAN_RELEASE_LOCK_DPC(
  147. IN PNDIS_SPIN_LOCK pLock
  148. )
  149. --*/
  150. #if DBG_SPIN_LOCK
  151. #define RWAN_RELEASE_LOCK_DPC(pLock) \
  152. RWanReleaseSpinLock(pLock, _FILENUMBER, __LINE__)
  153. #else
  154. #define RWAN_RELEASE_LOCK_DPC(pLock) \
  155. NdisDprReleaseSpinLock(pLock)
  156. #endif // DBG_SPIN_LOCK
  157. /*++
  158. VOID
  159. RWAN_FREE_LOCK(
  160. IN PNDIS_SPIN_LOCK pLock
  161. )
  162. --*/
  163. #define RWAN_FREE_LOCK(pLock) \
  164. NdisFreeSpinLock(pLock)
  165. //
  166. // Macros for operating the Global lock:
  167. //
  168. #define RWAN_INIT_GLOBAL_LOCK() \
  169. RWAN_INIT_LOCK(&((pRWanGlobal)->GlobalLock))
  170. #define RWAN_ACQUIRE_GLOBAL_LOCK() \
  171. RWAN_ACQUIRE_LOCK(&((pRWanGlobal)->GlobalLock))
  172. #define RWAN_RELEASE_GLOBAL_LOCK() \
  173. RWAN_RELEASE_LOCK(&((pRWanGlobal)->GlobalLock))
  174. #define RWAN_FREE_GLOBAL_LOCK() \
  175. RWAN_FREE_LOCK(&((pRWanGlobal)->GlobalLock))
  176. //
  177. // Macros for operating the Address List lock:
  178. //
  179. #define RWAN_INIT_ADDRESS_LIST_LOCK() \
  180. RWAN_INIT_LOCK(&((pRWanGlobal)->AddressListLock))
  181. #define RWAN_ACQUIRE_ADDRESS_LIST_LOCK() \
  182. RWAN_ACQUIRE_LOCK(&((pRWanGlobal)->AddressListLock))
  183. #define RWAN_RELEASE_ADDRESS_LIST_LOCK() \
  184. RWAN_RELEASE_LOCK(&((pRWanGlobal)->AddressListLock))
  185. #define RWAN_FREE_ADDRESS_LIST_LOCK() \
  186. RWAN_FREE_LOCK(&((pRWanGlobal)->AddressListLock))
  187. //
  188. // Macros for operating the Connection Table lock:
  189. //
  190. #define RWAN_INIT_CONN_TABLE_LOCK() \
  191. RWAN_INIT_LOCK(&((pRWanGlobal)->ConnTableLock))
  192. #define RWAN_ACQUIRE_CONN_TABLE_LOCK() \
  193. RWAN_ACQUIRE_LOCK(&((pRWanGlobal)->ConnTableLock))
  194. #define RWAN_RELEASE_CONN_TABLE_LOCK() \
  195. RWAN_RELEASE_LOCK(&((pRWanGlobal)->ConnTableLock))
  196. #define RWAN_FREE_CONN_TABLE_LOCK() \
  197. RWAN_FREE_LOCK(&((pRWanGlobal)->ConnTableLock))
  198. //
  199. // Macros for operating Connection object locks:
  200. //
  201. #define RWAN_INIT_CONN_LOCK(pConnObj) \
  202. RWAN_INIT_LOCK(&(pConnObj)->Lock)
  203. #define RWAN_ACQUIRE_CONN_LOCK(pConnObj) \
  204. RWAN_ACQUIRE_LOCK(&(pConnObj)->Lock)
  205. #define RWAN_ACQUIRE_CONN_LOCK_DPC(pConnObj) \
  206. RWAN_ACQUIRE_LOCK_DPC(&(pConnObj)->Lock)
  207. #define RWAN_RELEASE_CONN_LOCK(pConnObj) \
  208. RWAN_RELEASE_LOCK(&(pConnObj)->Lock)
  209. #define RWAN_RELEASE_CONN_LOCK_DPC(pConnObj) \
  210. RWAN_RELEASE_LOCK_DPC(&(pConnObj)->Lock)
  211. #define RWAN_FREE_CONN_LOCK(pConnObj) \
  212. RWAN_FREE_CONN_LOCK(&(pConnObj)->Lock)
  213. //
  214. // Macros for operating Address object locks:
  215. //
  216. #define RWAN_INIT_ADDRESS_LOCK(pAddrObj) \
  217. RWAN_INIT_LOCK(&(pAddrObj)->Lock)
  218. #define RWAN_ACQUIRE_ADDRESS_LOCK(pAddrObj) \
  219. RWAN_ACQUIRE_LOCK(&(pAddrObj)->Lock)
  220. #define RWAN_ACQUIRE_ADDRESS_LOCK_DPC(pAddrObj) \
  221. RWAN_ACQUIRE_LOCK_DPC(&(pAddrObj)->Lock)
  222. #define RWAN_RELEASE_ADDRESS_LOCK(pAddrObj) \
  223. RWAN_RELEASE_LOCK(&(pAddrObj)->Lock)
  224. #define RWAN_RELEASE_ADDRESS_LOCK_DPC(pAddrObj) \
  225. RWAN_RELEASE_LOCK_DPC(&(pAddrObj)->Lock)
  226. #define RWAN_FREE_ADDRESS_LOCK(pAddrObj) \
  227. RWAN_FREE_ADDRESS_LOCK(&(pAddrObj)->Lock)
  228. //
  229. // Macros for operating AF locks:
  230. //
  231. #define RWAN_INIT_AF_LOCK(pAfBlk) \
  232. RWAN_INIT_LOCK(&(pAfBlk)->Lock)
  233. #define RWAN_ACQUIRE_AF_LOCK(pAfBlk) \
  234. RWAN_ACQUIRE_LOCK(&(pAfBlk)->Lock)
  235. #define RWAN_ACQUIRE_AF_LOCK_DPC(pAfBlk) \
  236. RWAN_ACQUIRE_LOCK_DPC(&(pAfBlk)->Lock)
  237. #define RWAN_RELEASE_AF_LOCK(pAfBlk) \
  238. RWAN_RELEASE_LOCK(&(pAfBlk)->Lock)
  239. #define RWAN_RELEASE_AF_LOCK_DPC(pAfBlk) \
  240. RWAN_RELEASE_LOCK_DPC(&(pAfBlk)->Lock)
  241. #define RWAN_FREE_AF_LOCK(pAfBlk) \
  242. RWAN_FREE_AF_LOCK(&(pAfBlk)->Lock)
  243. //
  244. // Macros for operating Adapter locks:
  245. //
  246. #define RWAN_INIT_ADAPTER_LOCK(pAdptr) \
  247. RWAN_INIT_LOCK(&(pAdptr)->Lock)
  248. #define RWAN_ACQUIRE_ADAPTER_LOCK(pAdptr) \
  249. RWAN_ACQUIRE_LOCK(&(pAdptr)->Lock)
  250. #define RWAN_ACQUIRE_ADAPTER_LOCK_DPC(pAdptr) \
  251. RWAN_ACQUIRE_LOCK_DPC(&(pAdptr)->Lock)
  252. #define RWAN_RELEASE_ADAPTER_LOCK(pAdptr) \
  253. RWAN_RELEASE_LOCK(&(pAdptr)->Lock)
  254. #define RWAN_RELEASE_ADAPTER_LOCK_DPC(pAdptr) \
  255. RWAN_RELEASE_LOCK_DPC(&(pAdptr)->Lock)
  256. #define RWAN_FREE_ADAPTER_LOCK(pAdptr) \
  257. RWAN_FREE_ADAPTER_LOCK(&(pAdptr)->Lock)
  258. /*++
  259. VOID
  260. RWAN_ALLOC_MEM(
  261. IN POPAQUE pVar,
  262. IN OPAQUE StructureType,
  263. IN ULONG SizeOfStructure
  264. )
  265. --*/
  266. #if DBG
  267. #define RWAN_ALLOC_MEM(pVar, StructureType, SizeOfStructure) \
  268. pVar = (StructureType *)RWanAuditAllocMem( \
  269. (PVOID)(&(pVar)), \
  270. (ULONG)(SizeOfStructure), \
  271. _FILENUMBER, \
  272. __LINE__ \
  273. );
  274. #else
  275. #define RWAN_ALLOC_MEM(pVar, StructureType, SizeOfStructure) \
  276. NdisAllocateMemoryWithTag((PVOID *)(&pVar), (ULONG)(SizeOfStructure), (ULONG)'naWR');
  277. #endif // DBG
  278. /*++
  279. VOID
  280. RWAN_FREE_MEM(
  281. IN POPAQUE pMem
  282. )
  283. --*/
  284. #if DBG
  285. #define RWAN_FREE_MEM(pMem) RWanAuditFreeMem((PVOID)(pMem));
  286. #else
  287. #define RWAN_FREE_MEM(pMem) NdisFreeMemory((PVOID)(pMem), 0, 0);
  288. #endif // DBG
  289. /*++
  290. VOID
  291. RWAN_SET_MEM(
  292. IN POPAQUE pMem,
  293. IN UCHAR bValue,
  294. IN ULONG NumberOfBytes
  295. )
  296. --*/
  297. #define RWAN_SET_MEM(pMem, bValue, NumberOfBytes) \
  298. RtlFillMemory((PVOID)(pMem), (ULONG)(NumberOfBytes), (UCHAR)(bValue));
  299. /*++
  300. VOID
  301. RWAN_ZERO_MEM(
  302. IN POPAQUE pMem,
  303. IN ULONG NumberOfBytes
  304. )
  305. --*/
  306. #define RWAN_ZERO_MEM(pMem, NumberOfBytes) \
  307. RtlZeroMemory((PVOID)pMem, (ULONG)(NumberOfBytes));
  308. /*++
  309. VOID
  310. RWAN_COPY_MEM(
  311. IN POPAQUE pDst,
  312. IN POPAQUE pSrc,
  313. IN ULONG NumberOfBytes
  314. )
  315. --*/
  316. #define RWAN_COPY_MEM(pDst, pSrc, NumberOfBytes) \
  317. NdisMoveMemory((PVOID)(pDst), (PVOID)(pSrc), NumberOfBytes);
  318. /*++
  319. BOOLEAN
  320. RWAN_EQUAL_MEM(
  321. IN POPAQUE pMem1,
  322. IN POPAQUE pMem2,
  323. IN ULONG Length
  324. )
  325. --*/
  326. #define RWAN_EQUAL_MEM(_pMem1, _pMem2, _Length) \
  327. (RtlCompareMemory((PVOID)(_pMem1), (PVOID)(_pMem2), (ULONG)(_Length)) == (_Length))
  328. /*++
  329. VOID
  330. RWAN_SET_NEXT_PACKET(
  331. IN PNDIS_PACKET pNdisPacket,
  332. IN PNDIS_PACKET pNextPacket
  333. )
  334. --*/
  335. #define RWAN_SET_NEXT_PACKET(pPkt, pNext) \
  336. *((PNDIS_PACKET *)((pPkt)->MiniportReserved)) = (pNext);
  337. /*++
  338. PNDIS_PACKET
  339. RWAN_GET_NEXT_PACKET(
  340. IN PNDIS_PACKET pNdisPacket
  341. )
  342. --*/
  343. #define RWAN_GET_NEXT_PACKET(pPkt) \
  344. (*((PNDIS_PACKET *)((pPkt)->MiniportReserved)))
  345. //
  346. // Doubly linked list manipulation definitions and macros.
  347. //
  348. #define RWAN_INIT_LIST(_pListHead) \
  349. InitializeListHead(_pListHead)
  350. #define RWAN_IS_LIST_EMPTY(_pListHead) \
  351. IsListEmpty(_pListHead)
  352. #define RWAN_INSERT_HEAD_LIST(_pListHead, _pEntry) \
  353. InsertHeadList((_pListHead), (_pEntry))
  354. #define RWAN_INSERT_TAIL_LIST(_pListHead, _pEntry) \
  355. InsertTailList((_pListHead), (_pEntry))
  356. #define RWAN_DELETE_FROM_LIST(_pEntry) \
  357. RemoveEntryList(_pEntry)
  358. /*++
  359. ULONG
  360. ROUND_UP(
  361. IN ULONG Val
  362. )
  363. Round up a value so that it becomes a multiple of 4.
  364. --*/
  365. #define ROUND_UP(Val) (((Val) + 3) & ~0x3)
  366. /*++
  367. VOID
  368. RWAN_ADVANCE_RCV_REQ_BUFFER(
  369. IN PRWAN_RECEIVE_REQUEST pRcvReq
  370. )
  371. --*/
  372. #define RWAN_ADVANCE_RCV_REQ_BUFFER(_pRcvReq) \
  373. { \
  374. PNDIS_BUFFER _pNextBuffer; \
  375. NdisGetNextBuffer((_pRcvReq)->pBuffer, &(_pNextBuffer)); \
  376. (_pRcvReq)->pBuffer = _pNextBuffer; \
  377. if (_pNextBuffer != NULL) \
  378. { \
  379. NdisQueryBuffer( \
  380. (_pNextBuffer), \
  381. &(_pRcvReq)->pWriteData, \
  382. &(_pRcvReq)->BytesLeftInBuffer \
  383. ); \
  384. \
  385. if (((_pRcvReq)->BytesLeftInBuffer > (_pRcvReq)->AvailableBufferLength)) \
  386. { \
  387. (_pRcvReq)->BytesLeftInBuffer = (_pRcvReq)->AvailableBufferLength; \
  388. } \
  389. } \
  390. else \
  391. { \
  392. (_pRcvReq)->BytesLeftInBuffer = 0; \
  393. (_pRcvReq)->pWriteData = NULL; \
  394. } \
  395. }
  396. /*++
  397. VOID
  398. RWAN_ADVANCE_RCV_IND_BUFFER(
  399. IN PRWAN_RECEIVE_INDICATION pRcvInd
  400. )
  401. --*/
  402. #define RWAN_ADVANCE_RCV_IND_BUFFER(_pRcvInd) \
  403. { \
  404. PNDIS_BUFFER _pNextBuffer; \
  405. NdisGetNextBuffer((_pRcvInd)->pBuffer, &(_pNextBuffer)); \
  406. (_pRcvInd)->pBuffer = _pNextBuffer; \
  407. if (_pNextBuffer != NULL) \
  408. { \
  409. NdisQueryBuffer( \
  410. (_pNextBuffer), \
  411. &(_pRcvInd)->pReadData, \
  412. &(_pRcvInd)->BytesLeftInBuffer \
  413. ); \
  414. } \
  415. else \
  416. { \
  417. (_pRcvInd)->BytesLeftInBuffer = 0; \
  418. (_pRcvInd)->pReadData = NULL; \
  419. } \
  420. }
  421. /*++
  422. VOID
  423. RWAN_SET_DELETE_NOTIFY(
  424. IN PRWAN_DELETE_NOTIFY pNotifyObject,
  425. IN PCOMPLETE_RTN pDeleteRtn,
  426. IN PVOID DeleteContext
  427. )
  428. --*/
  429. #define RWAN_SET_DELETE_NOTIFY(_pNotifyObj, _pDeleteRtn, _DeleteContext) \
  430. { \
  431. (_pNotifyObj)->pDeleteRtn = (_pDeleteRtn); \
  432. (_pNotifyObj)->DeleteContext = (_DeleteContext); \
  433. }
  434. /*++
  435. PRWAN_SEND_REQUEST
  436. RWAN_SEND_REQUEST_FROM_PACKET(
  437. IN PNDIS_PACKET pNdisPacket
  438. )
  439. --*/
  440. #define RWAN_SEND_REQUEST_FROM_PACKET(_pNdisPacket) \
  441. (PRWAN_SEND_REQUEST)((_pNdisPacket)->ProtocolReserved)
  442. #if DBG
  443. #define RWAN_LINK_CONNECTION_TO_VC(_pConn, _pVc) \
  444. { \
  445. (_pConn)->NdisConnection.pNdisVc = _pVc; \
  446. (_pConn)->pNdisVcSave = _pVc; \
  447. (_pVc)->pConnObject = (_pConn); \
  448. }
  449. #else
  450. #define RWAN_LINK_CONNECTION_TO_VC(_pConn, _pVc) \
  451. { \
  452. (_pConn)->NdisConnection.pNdisVc = _pVc; \
  453. (_pConn)->pNdisVcSave = _pVc; \
  454. (_pVc)->pConnObject = (_pConn); \
  455. }
  456. #endif // DBG
  457. #define RWAN_UNLINK_CONNECTION_AND_VC(_pConn, _pVc) \
  458. { \
  459. (_pConn)->NdisConnection.pNdisVc = NULL_PRWAN_NDIS_VC;\
  460. (_pVc)->pConnObject = NULL_PRWAN_TDI_CONNECTION; \
  461. }
  462. /*++
  463. VOID
  464. RWAN_SET_VC_CALL_PARAMS(
  465. IN PRWAN_NDIS_VC pVc,
  466. IN PCO_CALL_PARAMETERS pCallParameters
  467. )
  468. --*/
  469. #define RWAN_SET_VC_CALL_PARAMS(_pVc, _pCallParameters) \
  470. { \
  471. if ((_pCallParameters != NULL) && \
  472. (_pCallParameters->CallMgrParameters != NULL)) \
  473. { \
  474. _pVc->MaxSendSize = _pCallParameters->CallMgrParameters->Transmit.MaxSduSize; \
  475. } \
  476. if (gHackSendSize) \
  477. { \
  478. _pVc->MaxSendSize = gHackSendSize; \
  479. } \
  480. /* DbgPrint("RWan: set vc %x: maxsendsize to %d\n", _pVc, _pVc->MaxSendSize); */ \
  481. }
  482. #define RWAN_SET_VC_EVENT(_pVc, _Flags) ((_pVc)->Flags) |= (_Flags);
  483. #if STATS
  484. #define INCR_STAT(_pSt) InterlockedIncrement(_pSt);
  485. #define ADD_STAT(_pSt, Incr) *(_pSt) += Incr;
  486. #endif // STATS
  487. #endif // __RWAN_MACROS_H_INCLUDED