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.

372 lines
15 KiB

  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 <netpnp.h>
  21. #include "nbconst.h" // private NETBEUI constants.
  22. #include "nbtypes.h" // private NETBEUI types.
  23. #include "nbdebug.h" // private NETBEUI debug defines.
  24. #include "nbprocs.h" // private NETBEUI function prototypes.
  25. #ifdef MEMPRINT
  26. #include "memprint.h" // drt's memory debug print
  27. #endif
  28. extern PEPROCESS NbFspProcess;
  29. extern ULONG g_ulMaxLana;
  30. extern LANA_ENUM g_leLanaEnum;
  31. extern PUNICODE_STRING g_pusActiveDeviceList;
  32. extern HANDLE g_hBindHandle;
  33. extern UNICODE_STRING g_usRegistryPath;
  34. extern LIST_ENTRY g_leFCBList;
  35. extern ERESOURCE g_erGlobalLock;
  36. #if DBG
  37. #define PAGED_DBG 1
  38. #endif
  39. #ifdef PAGED_DBG
  40. #undef PAGED_CODE
  41. #define PAGED_CODE() \
  42. struct { ULONG bogus; } ThisCodeCantBePaged; \
  43. ThisCodeCantBePaged; \
  44. if (KeGetCurrentIrql() > APC_LEVEL) { \
  45. KdPrint(( "NETBIOS: Pageable code called at IRQL %d. File %s, Line %d\n", KeGetCurrentIrql(), __FILE__, __LINE__ )); \
  46. ASSERT(FALSE); \
  47. }
  48. #define PAGED_CODE_CHECK() if (ThisCodeCantBePaged) ;
  49. extern ULONG ThisCodeCantBePaged;
  50. #else
  51. #define PAGED_CODE_CHECK()
  52. #endif
  53. #if PAGED_DBG
  54. #define ACQUIRE_SPIN_LOCK(a, b) { \
  55. PAGED_CODE_CHECK(); \
  56. KeAcquireSpinLock(a, b); \
  57. }
  58. #define RELEASE_SPIN_LOCK(a, b) { \
  59. PAGED_CODE_CHECK(); \
  60. KeReleaseSpinLock(a, b); \
  61. }
  62. #else
  63. #define ACQUIRE_SPIN_LOCK(a, b) KeAcquireSpinLock(a, b)
  64. #define RELEASE_SPIN_LOCK(a, b) KeReleaseSpinLock(a, b)
  65. #endif
  66. //
  67. // Macro for filling in the status for an NCB.
  68. //
  69. #define NCB_COMPLETE( _pdncb, _code ) { \
  70. UCHAR _internal_copy = _code; \
  71. IF_NBDBG (NB_DEBUG_COMPLETE) { \
  72. NbPrint (("%s %d NCB_COMPLETE: %lx, %lx\n" , \
  73. __FILE__, __LINE__, _pdncb, _internal_copy )); \
  74. } \
  75. if (((PDNCB)_pdncb)->ncb_retcode == NRC_PENDING) { \
  76. ((PDNCB)_pdncb)->ncb_retcode = _internal_copy; \
  77. } else { \
  78. IF_NBDBG (NB_DEBUG_NCBS) { \
  79. NbPrint((" Status already set!!!!!!!!\n")); \
  80. IF_NBDBG (NB_DEBUG_NCBSBRK) { \
  81. DbgBreakPoint(); \
  82. } \
  83. } \
  84. } \
  85. IF_NBDBG (NB_DEBUG_NCBS) { \
  86. NbDisplayNcb( (PDNCB)_pdncb ); \
  87. } \
  88. IF_NBDBG (NB_DEBUG_COMPLETE) \
  89. { \
  90. if ( ( (_code) == NRC_BRIDGE ) || \
  91. ( (_code) == NRC_ENVNOTDEF ) ) \
  92. { \
  93. DbgPrint("\n[NETBIOS]: NCB_COMPLETE : File %s," \
  94. " line %d\n", __FILE__, __LINE__); \
  95. DbgPrint("LANA %x, Command %x ", \
  96. ((PDNCB)_pdncb)->ncb_lana_num, \
  97. ((PDNCB)_pdncb)->ncb_command ); \
  98. DbgPrint("Return %x, Cmplt %x\n", \
  99. ((PDNCB)_pdncb)->ncb_retcode, \
  100. ((PDNCB)_pdncb)->ncb_cmd_cplt ); \
  101. NbFormattedDump( ((PDNCB)_pdncb)->ncb_name, 16 ); \
  102. NbFormattedDump( ((PDNCB)_pdncb)->ncb_callname, 16 ); \
  103. } \
  104. else if ( ( ( (_code) == NRC_DUPNAME ) || \
  105. ( (_code) == NRC_INUSE ) ) && \
  106. ( ((PDNCB)_pdncb)-> ncb_command != NCBADDGRNAME ) ) \
  107. { \
  108. DbgPrint("\n[NETBIOS]: NCB_COMPLETE : DUPNAME : File %s," \
  109. "line %d\n", __FILE__, __LINE__); \
  110. DbgPrint("LANA %x, Command %x ", \
  111. ((PDNCB)_pdncb)->ncb_lana_num, \
  112. ((PDNCB)_pdncb)->ncb_command ); \
  113. DbgPrint("Return %x, Cmplt %x\n", \
  114. ((PDNCB)_pdncb)->ncb_retcode, \
  115. ((PDNCB)_pdncb)->ncb_cmd_cplt ); \
  116. NbFormattedDump( ((PDNCB)_pdncb)->ncb_name, 16 ); \
  117. if ( ((PDNCB)_pdncb)->ncb_name[15] == 0x3) \
  118. { \
  119. DbgPrint("Messenger Name, dup ok\n"); \
  120. } \
  121. else \
  122. { \
  123. IF_NBDBG(NB_DEBUG_NCBSBRK) DbgBreakPoint(); \
  124. } \
  125. } \
  126. } \
  127. }
  128. //++
  129. //
  130. // VOID
  131. // NbCompleteRequest (
  132. // IN PIRP Irp,
  133. // IN NTSTATUS Status
  134. // );
  135. //
  136. // Routine Description:
  137. //
  138. // This routine is used to complete an IRP with the indicated
  139. // status. It does the necessary raise and lower of IRQL.
  140. //
  141. // Arguments:
  142. //
  143. // Irp - Supplies a pointer to the Irp to complete
  144. //
  145. // Status - Supplies the completion status for the Irp
  146. //
  147. // Return Value:
  148. //
  149. // None.
  150. //
  151. //--
  152. #define NbCompleteRequest(IRP,STATUS) { \
  153. (IRP)->IoStatus.Status = (STATUS); \
  154. IoCompleteRequest( (IRP), IO_NETWORK_INCREMENT ); \
  155. }
  156. #if defined(_WIN64)
  157. #define NbCheckAndCompleteIrp32(Irp) \
  158. { \
  159. if (IoIs32bitProcess(Irp) == TRUE) \
  160. { \
  161. NbCompleteIrp32(Irp); \
  162. } \
  163. }
  164. #else
  165. #define NbCheckAndCompleteIrp32(Irp)
  166. #endif
  167. //
  168. // Normally the driver wants to prohibit other threads making
  169. // requests (using a resource) and also prevent indication routines
  170. // being called (using a spinlock).
  171. //
  172. // To do this LOCK and UNLOCK are used. IO system calls cannot
  173. // be called with a spinlock held so sometimes the ordering becomes
  174. // LOCK, UNLOCK_SPINLOCK <do IO calls> UNLOCK_RESOURCE.
  175. //
  176. #define LOCK(PFCB, OLDIRQL) { \
  177. IF_NBDBG (NB_DEBUG_LOCKS) { \
  178. NbPrint (("%s %d LOCK: %lx %lx %lx\n" , \
  179. __FILE__, __LINE__, (PFCB) )); \
  180. } \
  181. KeEnterCriticalRegion(); \
  182. ExAcquireResourceExclusiveLite( &(PFCB)->Resource, TRUE); \
  183. ACQUIRE_SPIN_LOCK( &(PFCB)->SpinLock, &(OLDIRQL)); \
  184. }
  185. #define LOCK_RESOURCE(PFCB) { \
  186. IF_NBDBG (NB_DEBUG_LOCKS) { \
  187. NbPrint(("%s %d LOCK_RESOURCE: %lx, %lx %lx\n" , \
  188. __FILE__, __LINE__, (PFCB))); \
  189. } \
  190. KeEnterCriticalRegion(); \
  191. ExAcquireResourceExclusiveLite( &(PFCB)->Resource, TRUE); \
  192. }
  193. #define LOCK_GLOBAL() { \
  194. IF_NBDBG (NB_DEBUG_LOCKS) { \
  195. NbPrint(("%s %d LOCK_GLOBAL: %lx, %lx\n" , \
  196. __FILE__, __LINE__)); \
  197. } \
  198. KeEnterCriticalRegion(); \
  199. ExAcquireResourceExclusiveLite( &g_erGlobalLock, TRUE); \
  200. }
  201. #define LOCK_STOP() { \
  202. IF_NBDBG (NB_DEBUG_LOCKS) { \
  203. NbPrint(("%s %d LOCK_STOP: %lx, %lx\n" , \
  204. __FILE__, __LINE__)); \
  205. } \
  206. KeEnterCriticalRegion(); \
  207. ExAcquireResourceExclusiveLite( &g_erStopLock, TRUE); \
  208. }
  209. #define LOCK_SPINLOCK(PFCB, OLDIRQL) { \
  210. IF_NBDBG (NB_DEBUG_LOCKS) { \
  211. NbPrint( ("%s %d LOCK_SPINLOCK: %lx %lx %lx\n" , \
  212. __FILE__, __LINE__, (PFCB))); \
  213. } \
  214. ACQUIRE_SPIN_LOCK( &(PFCB)->SpinLock, &(OLDIRQL)); \
  215. }
  216. #define UNLOCK(PFCB, OLDIRQL) { \
  217. UNLOCK_SPINLOCK( PFCB, OLDIRQL ); \
  218. UNLOCK_RESOURCE( PFCB ); \
  219. }
  220. #define UNLOCK_GLOBAL() { \
  221. IF_NBDBG (NB_DEBUG_LOCKS) { \
  222. NbPrint(("%s %d UNLOCK_GLOBAL: %lx, %lx\n" , \
  223. __FILE__, __LINE__)); \
  224. } \
  225. ExReleaseResourceLite( &g_erGlobalLock ); \
  226. KeLeaveCriticalRegion(); \
  227. }
  228. #define UNLOCK_STOP() { \
  229. IF_NBDBG (NB_DEBUG_LOCKS) { \
  230. NbPrint(("%s %d UNLOCK_STOP: %lx, %lx\n" , \
  231. __FILE__, __LINE__)); \
  232. } \
  233. ExReleaseResourceLite( &g_erStopLock ); \
  234. KeLeaveCriticalRegion(); \
  235. }
  236. #define UNLOCK_RESOURCE(PFCB) { \
  237. IF_NBDBG (NB_DEBUG_LOCKS) { \
  238. NbPrint( ("%s %d RESOURCE: %lx, %lx %lx\n" , \
  239. __FILE__, __LINE__, (PFCB) )); \
  240. } \
  241. ExReleaseResourceLite( &(PFCB)->Resource ); \
  242. KeLeaveCriticalRegion(); \
  243. }
  244. #define UNLOCK_SPINLOCK(PFCB, OLDIRQL) { \
  245. IF_NBDBG (NB_DEBUG_LOCKS) { \
  246. NbPrint( ("%s %d SPINLOCK: %lx, %lx %lx %lx\n" , \
  247. __FILE__, __LINE__, (PFCB), (OLDIRQL))); \
  248. } \
  249. RELEASE_SPIN_LOCK( &(PFCB)->SpinLock, (OLDIRQL) ); \
  250. }
  251. // Assume resource held when modifying CurrentUsers
  252. #define REFERENCE_AB(PAB) { \
  253. (PAB)->CurrentUsers++; \
  254. IF_NBDBG (NB_DEBUG_ADDRESS) { \
  255. NbPrint( ("ReferenceAb %s %d: %lx, NewCount:%lx\n", \
  256. __FILE__, __LINE__, \
  257. PAB, \
  258. (PAB)->CurrentUsers)); \
  259. NbFormattedDump( (PUCHAR)&(PAB)->Name, sizeof(NAME) ); \
  260. } \
  261. }
  262. // Resource must be held before dereferencing the address block
  263. #define DEREFERENCE_AB(PPAB) { \
  264. IF_NBDBG (NB_DEBUG_ADDRESS) { \
  265. NbPrint( ("DereferenceAb %s %d: %lx, OldCount:%lx\n", \
  266. __FILE__, __LINE__, *PPAB, (*PPAB)->CurrentUsers)); \
  267. NbFormattedDump( (PUCHAR)&(*PPAB)->Name, sizeof(NAME) );\
  268. } \
  269. (*PPAB)->CurrentUsers--; \
  270. if ( (*PPAB)->CurrentUsers == 0 ) { \
  271. if ( (*PPAB)->AddressHandle != NULL ) { \
  272. IF_NBDBG (NB_DEBUG_ADDRESS) { \
  273. NbPrint( ("DereferenceAb: Closing: %lx\n", \
  274. (*PPAB)->AddressHandle)); \
  275. } \
  276. NbAddressClose( (*PPAB)->AddressHandle, \
  277. (*PPAB)->AddressObject ); \
  278. (*PPAB)->AddressHandle = NULL; \
  279. } \
  280. (*PPAB)->pLana->AddressCount--; \
  281. ExFreePool( *PPAB ); \
  282. *PPAB = NULL; \
  283. } \
  284. }
  285. //
  286. // The following macros are used to establish the semantics needed
  287. // to do a return from within a try-finally clause. As a rule every
  288. // try clause must end with a label call try_exit. For example,
  289. //
  290. // try {
  291. // :
  292. // :
  293. //
  294. // try_exit: NOTHING;
  295. // } finally {
  296. //
  297. // :
  298. // :
  299. // }
  300. //
  301. // Every return statement executed inside of a try clause should use the
  302. // try_return macro. If the compiler fully supports the try-finally construct
  303. // then the macro should be
  304. //
  305. // #define try_return(S) { return(S); }
  306. //
  307. // If the compiler does not support the try-finally construct then the macro
  308. // should be
  309. //
  310. #define try_return(S) { S; goto try_exit; }
  311. #define NETBIOS_STOPPING 1
  312. #define NETBIOS_RUNNING 2;
  313. #endif // def _NB_