Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. nbf.h
  5. Abstract:
  6. Private include file for the NBF (NetBIOS Frames Protocol) transport
  7. provider subcomponent of the NTOS project.
  8. Author:
  9. Stephen E. Jones (stevej) 25-Oct-1989
  10. Revision History:
  11. David Beaver (dbeaver) 24-Sep-1990
  12. Remove PDI and PC586-specific support; add NDIS support
  13. --*/
  14. #include <ntddk.h>
  15. #include <windef.h>
  16. #include <nb30.h>
  17. //#include <ntiologc.h>
  18. //#include <ctype.h>
  19. //#include <assert.h>
  20. //#include <stdio.h>
  21. //#include <stdlib.h>
  22. //#include <memory.h>
  23. //#include <nt.h>
  24. //#include <ntrtl.h>
  25. //#include <nturtl.h>
  26. //#include <string.h>
  27. //#include <windows.h>
  28. #ifdef BUILD_FOR_511
  29. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  30. #endif
  31. typedef struct _RTL_SPLAY_LINKS {
  32. struct _RTL_SPLAY_LINKS *Parent;
  33. struct _RTL_SPLAY_LINKS *LeftChild;
  34. struct _RTL_SPLAY_LINKS *RightChild;
  35. } RTL_SPLAY_LINKS;
  36. typedef RTL_SPLAY_LINKS *PRTL_SPLAY_LINKS;
  37. #define RtlInitializeSplayLinks(Links) { \
  38. PRTL_SPLAY_LINKS _SplayLinks; \
  39. _SplayLinks = (PRTL_SPLAY_LINKS)(Links); \
  40. _SplayLinks->Parent = _SplayLinks; \
  41. _SplayLinks->LeftChild = NULL; \
  42. _SplayLinks->RightChild = NULL; \
  43. }
  44. #define RtlLeftChild(Links) ( \
  45. (PRTL_SPLAY_LINKS)(Links)->LeftChild \
  46. )
  47. #define RtlRightChild(Links) ( \
  48. (PRTL_SPLAY_LINKS)(Links)->RightChild \
  49. )
  50. #define RtlInsertAsLeftChild(ParentLinks,ChildLinks) { \
  51. PRTL_SPLAY_LINKS _SplayParent; \
  52. PRTL_SPLAY_LINKS _SplayChild; \
  53. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  54. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  55. _SplayParent->LeftChild = _SplayChild; \
  56. _SplayChild->Parent = _SplayParent; \
  57. }
  58. #define RtlInsertAsRightChild(ParentLinks,ChildLinks) { \
  59. PRTL_SPLAY_LINKS _SplayParent; \
  60. PRTL_SPLAY_LINKS _SplayChild; \
  61. _SplayParent = (PRTL_SPLAY_LINKS)(ParentLinks); \
  62. _SplayChild = (PRTL_SPLAY_LINKS)(ChildLinks); \
  63. _SplayParent->RightChild = _SplayChild; \
  64. _SplayChild->Parent = _SplayParent; \
  65. }
  66. PRTL_SPLAY_LINKS
  67. NTAPI
  68. RtlDelete (
  69. PRTL_SPLAY_LINKS Links
  70. );
  71. #include <tdikrnl.h> // Transport Driver Interface.
  72. #include <ndis.h> // Physical Driver Interface.
  73. #if DEVL
  74. #define STATIC
  75. #else
  76. #define STATIC static
  77. #endif
  78. #include "nbfconst.h" // private NETBEUI constants.
  79. #include "nbfmac.h" // mac-specific definitions
  80. #include "nbfhdrs.h" // private NETBEUI protocol headers.
  81. #include "nbfcnfg.h" // configuration information.
  82. #include "nbftypes.h" // private NETBEUI types.
  83. #include "nbfprocs.h" // private NETBEUI function prototypes.
  84. #ifdef MEMPRINT
  85. #include "memprint.h" // drt's memory debug print
  86. #endif
  87. #if defined(NT_UP) && defined(DRIVERS_UP)
  88. #define NBF_UP 1
  89. #endif
  90. //
  91. // Resource and Mutex Macros
  92. //
  93. //
  94. // We wrap each of these macros using
  95. // Enter,Leave critical region macros
  96. // to disable APCs which might occur
  97. // while we are holding the resource
  98. // resulting in deadlocks in the OS.
  99. //
  100. #define ACQUIRE_RESOURCE_EXCLUSIVE(Resource, Wait) \
  101. KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(Resource, Wait);
  102. #define RELEASE_RESOURCE(Resource) \
  103. ExReleaseResourceLite(Resource); KeLeaveCriticalRegion();
  104. #define ACQUIRE_FAST_MUTEX_UNSAFE(Mutex) \
  105. KeEnterCriticalRegion(); ExAcquireFastMutexUnsafe(Mutex);
  106. #define RELEASE_FAST_MUTEX_UNSAFE(Mutex) \
  107. ExReleaseFastMutexUnsafe(Mutex); KeLeaveCriticalRegion();
  108. #ifndef NBF_LOCKS
  109. #if !defined(NBF_UP)
  110. #define ACQUIRE_SPIN_LOCK(lock,irql) KeAcquireSpinLock(lock,irql)
  111. #define RELEASE_SPIN_LOCK(lock,irql) KeReleaseSpinLock(lock,irql)
  112. #define ACQUIRE_DPC_SPIN_LOCK(lock) KeAcquireSpinLockAtDpcLevel(lock)
  113. #define RELEASE_DPC_SPIN_LOCK(lock) KeReleaseSpinLockFromDpcLevel(lock)
  114. #else // NBF_UP
  115. #define ACQUIRE_SPIN_LOCK(lock,irql) ExAcquireSpinLock(lock,irql)
  116. #define RELEASE_SPIN_LOCK(lock,irql) ExReleaseSpinLock(lock,irql)
  117. #define ACQUIRE_DPC_SPIN_LOCK(lock)
  118. #define RELEASE_DPC_SPIN_LOCK(lock)
  119. #endif
  120. #if DBG
  121. #define ACQUIRE_C_SPIN_LOCK(lock,irql) { \
  122. PTP_CONNECTION _conn = CONTAINING_RECORD(lock,TP_CONNECTION,SpinLock); \
  123. KeAcquireSpinLock(lock,irql); \
  124. _conn->LockAcquired = TRUE; \
  125. strncpy(_conn->LastAcquireFile, strrchr(__FILE__,'\\')+1, 7); \
  126. _conn->LastAcquireLine = __LINE__; \
  127. }
  128. #define RELEASE_C_SPIN_LOCK(lock,irql) { \
  129. PTP_CONNECTION _conn = CONTAINING_RECORD(lock,TP_CONNECTION,SpinLock); \
  130. _conn->LockAcquired = FALSE; \
  131. strncpy(_conn->LastReleaseFile, strrchr(__FILE__,'\\')+1, 7); \
  132. _conn->LastReleaseLine = __LINE__; \
  133. KeReleaseSpinLock(lock,irql); \
  134. }
  135. #define ACQUIRE_DPC_C_SPIN_LOCK(lock) { \
  136. PTP_CONNECTION _conn = CONTAINING_RECORD(lock,TP_CONNECTION,SpinLock); \
  137. KeAcquireSpinLockAtDpcLevel(lock); \
  138. _conn->LockAcquired = TRUE; \
  139. strncpy(_conn->LastAcquireFile, strrchr(__FILE__,'\\')+1, 7); \
  140. _conn->LastAcquireLine = __LINE__; \
  141. }
  142. #define RELEASE_DPC_C_SPIN_LOCK(lock) { \
  143. PTP_CONNECTION _conn = CONTAINING_RECORD(lock,TP_CONNECTION,SpinLock); \
  144. _conn->LockAcquired = FALSE; \
  145. strncpy(_conn->LastReleaseFile, strrchr(__FILE__,'\\')+1, 7); \
  146. _conn->LastReleaseLine = __LINE__; \
  147. KeReleaseSpinLockFromDpcLevel(lock); \
  148. }
  149. #else // DBG
  150. #define ACQUIRE_C_SPIN_LOCK(lock,irql) ACQUIRE_SPIN_LOCK(lock,irql)
  151. #define RELEASE_C_SPIN_LOCK(lock,irql) RELEASE_SPIN_LOCK(lock,irql)
  152. #define ACQUIRE_DPC_C_SPIN_LOCK(lock) ACQUIRE_DPC_SPIN_LOCK(lock)
  153. #define RELEASE_DPC_C_SPIN_LOCK(lock) RELEASE_DPC_SPIN_LOCK(lock)
  154. #endif // DBG
  155. #define ENTER_NBF
  156. #define LEAVE_NBF
  157. #else
  158. VOID
  159. NbfAcquireSpinLock(
  160. IN PKSPIN_LOCK Lock,
  161. OUT PKIRQL OldIrql,
  162. IN PSZ LockName,
  163. IN PSZ FileName,
  164. IN ULONG LineNumber
  165. );
  166. VOID
  167. NbfReleaseSpinLock(
  168. IN PKSPIN_LOCK Lock,
  169. IN KIRQL OldIrql,
  170. IN PSZ LockName,
  171. IN PSZ FileName,
  172. IN ULONG LineNumber
  173. );
  174. #define ACQUIRE_SPIN_LOCK(lock,irql) \
  175. NbfAcquireSpinLock( lock, irql, #lock, __FILE__, __LINE__ )
  176. #define RELEASE_SPIN_LOCK(lock,irql) \
  177. NbfReleaseSpinLock( lock, irql, #lock, __FILE__, __LINE__ )
  178. #define ACQUIRE_DPC_SPIN_LOCK(lock) \
  179. { \
  180. KIRQL OldIrql; \
  181. NbfAcquireSpinLock( lock, &OldIrql, #lock, __FILE__, __LINE__ ); \
  182. }
  183. #define RELEASE_DPC_SPIN_LOCK(lock) \
  184. NbfReleaseSpinLock( lock, DISPATCH_LEVEL, #lock, __FILE__, __LINE__ )
  185. #define ENTER_NBF \
  186. NbfAcquireSpinLock( (PKSPIN_LOCK)NULL, (PKIRQL)NULL, "(Global)", __FILE__, __LINE__ )
  187. #define LEAVE_NBF \
  188. NbfReleaseSpinLock( (PKSPIN_LOCK)NULL, (KIRQL)-1, "(Global)", __FILE__, __LINE__ )
  189. #endif