Windows NT 4.0 source code leak
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.

255 lines
9.1 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. nb.h
  5. Abstract:
  6. Private include file for the NB (NetBIOS) component of the NTOS project.
  7. Author:
  8. Colin Watson (ColinW) 13-Mar-1991
  9. Revision History:
  10. --*/
  11. #ifndef _NB_
  12. #define _NB_
  13. #include <ntifs.h>
  14. //#include <ntos.h>
  15. #include <windef.h>
  16. #include <status.h>
  17. #include <tdikrnl.h> // Transport Driver Interface.
  18. #include <nb30.h>
  19. #include <nb30p.h>
  20. #include "nbconst.h" // private NETBEUI constants.
  21. #include "nbtypes.h" // private NETBEUI types.
  22. #include "nbdebug.h" // private NETBEUI debug defines.
  23. #include "nbprocs.h" // private NETBEUI function prototypes.
  24. #ifdef MEMPRINT
  25. #include "memprint.h" // drt's memory debug print
  26. #endif
  27. extern PEPROCESS NbFspProcess;
  28. #if DBG
  29. #define PAGED_DBG 1
  30. #endif
  31. #ifdef PAGED_DBG
  32. #undef PAGED_CODE
  33. #define PAGED_CODE() \
  34. struct { ULONG bogus; } ThisCodeCantBePaged; \
  35. ThisCodeCantBePaged; \
  36. if (KeGetCurrentIrql() > APC_LEVEL) { \
  37. KdPrint(( "NETBIOS: Pageable code called at IRQL %d. File %s, Line %d\n", KeGetCurrentIrql(), __FILE__, __LINE__ )); \
  38. ASSERT(FALSE); \
  39. }
  40. #define PAGED_CODE_CHECK() if (ThisCodeCantBePaged) ;
  41. extern ULONG ThisCodeCantBePaged;
  42. #else
  43. #define PAGED_CODE_CHECK()
  44. #endif
  45. #if PAGED_DBG
  46. #define ACQUIRE_SPIN_LOCK(a, b) { \
  47. PAGED_CODE_CHECK(); \
  48. KeAcquireSpinLock(a, b); \
  49. }
  50. #define RELEASE_SPIN_LOCK(a, b) { \
  51. PAGED_CODE_CHECK(); \
  52. KeReleaseSpinLock(a, b); \
  53. }
  54. #else
  55. #define ACQUIRE_SPIN_LOCK(a, b) KeAcquireSpinLock(a, b)
  56. #define RELEASE_SPIN_LOCK(a, b) KeReleaseSpinLock(a, b)
  57. #endif
  58. //
  59. // Macro for filling in the status for an NCB.
  60. //
  61. #define NCB_COMPLETE( _pdncb, _code ) { \
  62. UCHAR _internal_copy = _code; \
  63. IF_NBDBG (NB_DEBUG_COMPLETE) { \
  64. NbPrint (("%s %d NCB_COMPLETE: %lx, %lx\n" , \
  65. __FILE__, __LINE__, _pdncb, _internal_copy )); \
  66. } \
  67. if (((PDNCB)_pdncb)->ncb_retcode == NRC_PENDING) { \
  68. ((PDNCB)_pdncb)->ncb_retcode = _internal_copy; \
  69. } else { \
  70. IF_NBDBG (NB_DEBUG_NCBS) { \
  71. NbPrint((" Status already set!!!!!!!!\n")); \
  72. IF_NBDBG (NB_DEBUG_NCBSBRK) { \
  73. DbgBreakPoint(); \
  74. } \
  75. } \
  76. } \
  77. IF_NBDBG (NB_DEBUG_NCBS) { \
  78. NbDisplayNcb( (PDNCB)_pdncb ); \
  79. } \
  80. }
  81. //++
  82. //
  83. // VOID
  84. // NbCompleteRequest (
  85. // IN PIRP Irp,
  86. // IN NTSTATUS Status
  87. // );
  88. //
  89. // Routine Description:
  90. //
  91. // This routine is used to complete an IRP with the indicated
  92. // status. It does the necessary raise and lower of IRQL.
  93. //
  94. // Arguments:
  95. //
  96. // Irp - Supplies a pointer to the Irp to complete
  97. //
  98. // Status - Supplies the completion status for the Irp
  99. //
  100. // Return Value:
  101. //
  102. // None.
  103. //
  104. //--
  105. #define NbCompleteRequest(IRP,STATUS) { \
  106. (IRP)->IoStatus.Status = (STATUS); \
  107. IoCompleteRequest( (IRP), IO_NETWORK_INCREMENT ); \
  108. }
  109. //
  110. // Normally the driver wants to prohibit other threads making
  111. // requests (using a resource) and also prevent indication routines
  112. // being called (using a spinlock).
  113. //
  114. // To do this LOCK and UNLOCK are used. IO system calls cannot
  115. // be called with a spinlock held so sometimes the ordering becomes
  116. // LOCK, UNLOCK_SPINLOCK <do IO calls> UNLOCK_RESOURCE.
  117. //
  118. #define LOCK(PFCB, OLDIRQL) { \
  119. IF_NBDBG (NB_DEBUG_LOCKS) { \
  120. NbPrint (("%s %d LOCK: %lx %lx %lx\n" , \
  121. __FILE__, __LINE__, (PFCB) )); \
  122. } \
  123. ExAcquireResourceExclusive( &(PFCB)->Resource, TRUE); \
  124. ACQUIRE_SPIN_LOCK( &(PFCB)->SpinLock, &(OLDIRQL)); \
  125. }
  126. #define LOCK_RESOURCE(PFCB) { \
  127. IF_NBDBG (NB_DEBUG_LOCKS) { \
  128. NbPrint(("%s %d LOCK_RESOURCE: %lx, %lx %lx\n" , \
  129. __FILE__, __LINE__, (PFCB))); \
  130. } \
  131. ExAcquireResourceExclusive( &(PFCB)->Resource, TRUE); \
  132. }
  133. #define LOCK_SPINLOCK(PFCB, OLDIRQL) { \
  134. IF_NBDBG (NB_DEBUG_LOCKS) { \
  135. NbPrint( ("%s %d LOCK_SPINLOCK: %lx %lx %lx\n" , \
  136. __FILE__, __LINE__, (PFCB))); \
  137. } \
  138. ACQUIRE_SPIN_LOCK( &(PFCB)->SpinLock, &(OLDIRQL)); \
  139. }
  140. #define UNLOCK(PFCB, OLDIRQL) { \
  141. UNLOCK_SPINLOCK( PFCB, OLDIRQL ); \
  142. UNLOCK_RESOURCE( PFCB ); \
  143. }
  144. #define UNLOCK_RESOURCE(PFCB) { \
  145. IF_NBDBG (NB_DEBUG_LOCKS) { \
  146. NbPrint( ("%s %d RESOURCE: %lx, %lx %lx\n" , \
  147. __FILE__, __LINE__, pfcb )); \
  148. } \
  149. ExReleaseResource( &(PFCB)->Resource ); \
  150. }
  151. #define UNLOCK_SPINLOCK(PFCB, OLDIRQL) { \
  152. IF_NBDBG (NB_DEBUG_LOCKS) { \
  153. NbPrint( ("%s %d SPINLOCK: %lx, %lx %lx %lx\n" , \
  154. __FILE__, __LINE__, (PFCB), (OLDIRQL))); \
  155. } \
  156. RELEASE_SPIN_LOCK( &(PFCB)->SpinLock, (OLDIRQL) ); \
  157. }
  158. // Assume resource held when modifying CurrentUsers
  159. #define REFERENCE_AB(PAB) { \
  160. (PAB)->CurrentUsers++; \
  161. IF_NBDBG (NB_DEBUG_ADDRESS) { \
  162. NbPrint( ("ReferenceAb %s %d: %lx, NewCount:%lx\n", \
  163. __FILE__, __LINE__, \
  164. PAB, \
  165. (PAB)->CurrentUsers)); \
  166. NbFormattedDump( (PUCHAR)&(PAB)->Name, sizeof(NAME) ); \
  167. } \
  168. }
  169. // Resource must be held before dereferencing the address block
  170. #define DEREFERENCE_AB(PPAB) { \
  171. IF_NBDBG (NB_DEBUG_ADDRESS) { \
  172. NbPrint( ("DereferenceAb %s %d: %lx, OldCount:%lx\n", \
  173. __FILE__, __LINE__, *PPAB, (*PPAB)->CurrentUsers)); \
  174. NbFormattedDump( (PUCHAR)&(*PPAB)->Name, sizeof(NAME) );\
  175. } \
  176. (*PPAB)->CurrentUsers--; \
  177. if ( (*PPAB)->CurrentUsers == 0 ) { \
  178. if ( (*PPAB)->AddressHandle != NULL ) { \
  179. IF_NBDBG (NB_DEBUG_ADDRESS) { \
  180. NbPrint( ("DereferenceAb: Closing: %lx\n", \
  181. (*PPAB)->AddressHandle)); \
  182. } \
  183. NbAddressClose( (*PPAB)->AddressHandle, \
  184. (*PPAB)->AddressObject ); \
  185. (*PPAB)->AddressHandle = NULL; \
  186. } \
  187. (*PPAB)->pLana->AddressCount--; \
  188. ExFreePool( *PPAB ); \
  189. *PPAB = NULL; \
  190. } \
  191. }
  192. //
  193. // The following macros are used to establish the semantics needed
  194. // to do a return from within a try-finally clause. As a rule every
  195. // try clause must end with a label call try_exit. For example,
  196. //
  197. // try {
  198. // :
  199. // :
  200. //
  201. // try_exit: NOTHING;
  202. // } finally {
  203. //
  204. // :
  205. // :
  206. // }
  207. //
  208. // Every return statement executed inside of a try clause should use the
  209. // try_return macro. If the compiler fully supports the try-finally construct
  210. // then the macro should be
  211. //
  212. // #define try_return(S) { return(S); }
  213. //
  214. // If the compiler does not support the try-finally construct then the macro
  215. // should be
  216. //
  217. #define try_return(S) { S; goto try_exit; }
  218. #endif // def _NB_