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.

313 lines
7.4 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. // Abstract:
  12. //
  13. // General include file for definitions we want everywhere.
  14. //
  15. #ifndef OSCFG_INCLUDED
  16. #define OSCFG_INCLUDED
  17. //
  18. // We want to cast pointer l-values for use with the += operator.
  19. //
  20. #pragma warning(disable:4213) // cast on l-value
  21. #pragma warning(disable:4152) // function/data pointer conversion in expression
  22. #pragma warning(disable:4200) // zero-sized array in struct/union
  23. //
  24. // We often use int rather than BOOLEAN since the assembly is often more
  25. // efficient.
  26. //
  27. #pragma warning(disable:4244) // conversion from 'int' to 'BOOLEAN'
  28. //
  29. // Temporarily disable 4127 which is hit by PAGED_CODE(), KeQueryTickCount(),
  30. // etc.
  31. //
  32. #pragma warning(disable:4127) // conditional expression is constant
  33. #if defined (_WIN64)
  34. #define MAX_CACHE_LINE_SIZE 128
  35. #else
  36. #define MAX_CACHE_LINE_SIZE 64
  37. #endif
  38. #define CACHE_ALIGN __declspec(align(MAX_CACHE_LINE_SIZE))
  39. //
  40. // Common types.
  41. //
  42. typedef unsigned long ulong;
  43. typedef unsigned short ushort;
  44. typedef unsigned char uchar;
  45. typedef unsigned int uint;
  46. //
  47. // Network byte-order is big-endian.
  48. // NT runs in little-endian mode on all supported architectures.
  49. //
  50. __inline ushort
  51. net_short(ushort x)
  52. {
  53. return (((x & 0xff) << 8) | ((x & 0xff00) >> 8));
  54. }
  55. __inline ulong
  56. net_long(ulong x)
  57. {
  58. return (((x & 0xffL) << 24) | ((x & 0xff00L) << 8) |
  59. ((x & 0xff0000L) >> 8) | ((x &0xff000000L) >> 24));
  60. }
  61. //
  62. // Find the highest power of two that is greater
  63. // than or equal to the Value.
  64. //
  65. __inline ulong
  66. ComputeLargerOrEqualPowerOfTwo(
  67. ulong Value
  68. )
  69. {
  70. ulong Temp;
  71. for (Temp = 1; Temp < Value; Temp <<= 1);
  72. return Temp;
  73. }
  74. //
  75. // Helpfull macros.
  76. //
  77. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  78. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  79. //
  80. // NT specific definitions.
  81. //
  82. #include <ntosp.h>
  83. #include <zwapi.h>
  84. #define BEGIN_INIT
  85. #define END_INIT
  86. #include <ndis.h>
  87. //
  88. // Used to report an error from an API that we've called.
  89. // For example, ExAllocatePool failed.
  90. //
  91. #define DPFLTR_NTOS_ERROR DPFLTR_INFO_LEVEL
  92. //
  93. // Used to report an error in an incoming packet.
  94. // For example, a malformed packet header.
  95. //
  96. #define DPFLTR_BAD_PACKET DPFLTR_WARNING_LEVEL
  97. //
  98. // Used to report an error in a user's system call or ioctl.
  99. // For example, an illegal argument.
  100. //
  101. #define DPFLTR_USER_ERROR DPFLTR_WARNING_LEVEL
  102. //
  103. // Used to report an internal error.
  104. // For example, RouteToDestination failed.
  105. //
  106. #define DPFLTR_INTERNAL_ERROR DPFLTR_WARNING_LEVEL
  107. //
  108. // Used to report an internal unusual occurrence.
  109. // For example, a rare race happened.
  110. //
  111. #define DPFLTR_INFO_RARE DPFLTR_INFO_LEVEL
  112. //
  113. // Used to report routine but unusual occurrences,
  114. // which often indicate network configuration problem or packet loss.
  115. // For example, fragmentation reassembly timeout.
  116. //
  117. #define DPFLTR_NET_ERROR DPFLTR_TRACE_LEVEL
  118. //
  119. // Used to report routine state changes,
  120. // which do not happen too frequently.
  121. // For example, creating/deleting an interface or address.
  122. //
  123. #define DPFLTR_INFO_STATE DPFLTR_INFO_LEVEL
  124. //
  125. // Used under IPSEC_DEBUG.
  126. //
  127. #define DPFLTR_INFO_IPSEC DPFLTR_INFO_LEVEL
  128. //
  129. // Used under IF_TCPDBG.
  130. //
  131. #define DPFLTR_INFO_TCPDBG DPFLTR_INFO_LEVEL
  132. //
  133. // NdisGetFirstBufferFromPacket is bad in two ways:
  134. // It uses MmGetMdlVirtualAddress instead of MmGetSystemAddressForMdlSafe.
  135. // It scans over all the buffers adding up the total length,
  136. // even if you don't want it.
  137. //
  138. __inline PNDIS_BUFFER
  139. NdisFirstBuffer(PNDIS_PACKET Packet)
  140. {
  141. return Packet->Private.Head;
  142. }
  143. //
  144. // Use the function versions of these Ndis APIs,
  145. // so that we are immune to changes in internal NDIS structures.
  146. //
  147. #undef NdisRequest
  148. VOID
  149. NdisRequest(
  150. OUT PNDIS_STATUS Status,
  151. IN NDIS_HANDLE NdisBindingHandle,
  152. IN PNDIS_REQUEST NdisRequest
  153. );
  154. #undef NdisSend
  155. VOID
  156. NdisSend(
  157. OUT PNDIS_STATUS Status,
  158. IN NDIS_HANDLE NdisBindingHandle,
  159. IN PNDIS_PACKET Packet
  160. );
  161. #undef NdisTransferData
  162. VOID
  163. NdisTransferData(
  164. OUT PNDIS_STATUS Status,
  165. IN NDIS_HANDLE NdisBindingHandle,
  166. IN NDIS_HANDLE MacReceiveContext,
  167. IN UINT ByteOffset,
  168. IN UINT BytesToTransfer,
  169. IN OUT PNDIS_PACKET Packet,
  170. OUT PUINT BytesTransferred
  171. );
  172. #ifdef _X86_
  173. //
  174. // The Whistler build environment renames
  175. // ExInterlockedPopEntrySList and
  176. // ExInterlockedPushEntrySList to remove the Ex.
  177. // Whistler ntoskrnl.exe exposes both entry points,
  178. // Win2k ntoskrnl.exe only has the Ex entrypoints.
  179. // We use the older entrypoints so that we run on Win2k.
  180. //
  181. #undef ExInterlockedPopEntrySList
  182. NTKERNELAPI
  183. PSLIST_ENTRY
  184. FASTCALL
  185. ExInterlockedPopEntrySList (
  186. IN PSLIST_HEADER ListHead,
  187. IN PKSPIN_LOCK Lock
  188. );
  189. #undef ExInterlockedPushEntrySList
  190. NTKERNELAPI
  191. PSLIST_ENTRY
  192. FASTCALL
  193. ExInterlockedPushEntrySList (
  194. IN PSLIST_HEADER ListHead,
  195. IN PSLIST_ENTRY ListEntry,
  196. IN PKSPIN_LOCK Lock
  197. );
  198. #endif // _X86_
  199. //
  200. // Support for tagging memory allocations.
  201. //
  202. #define IP6_TAG '6vPI'
  203. #ifdef POOL_TAGGING
  204. #ifdef ExAllocatePool
  205. #undef ExAllocatePool
  206. #endif
  207. #define ExAllocatePool(type, size) ExAllocatePoolWithTag(type, size, IP6_TAG)
  208. #endif // POOL_TAGGING
  209. #if DBG
  210. //
  211. // Support for debug event log.
  212. //
  213. // The debug event log allows for "real time" logging of events
  214. // in a circular queue kept in non-pageable memory. Each event consists
  215. // of an id number and a arbitrary 32 bit value. The LogDebugEvent
  216. // function adds a 64 bit timestamp to the event and adds it to the log.
  217. //
  218. // DEBUG_LOG_SIZE must be a power of 2 for wrap around to work properly.
  219. #define DEBUG_LOG_SIZE (8 * 1024) // Number of debug log entries.
  220. struct DebugLogEntry {
  221. LARGE_INTEGER Time; // When.
  222. uint Event; // What.
  223. int Arg; // How/Who/Where/Why?
  224. };
  225. void LogDebugEvent(uint Event, int Arg);
  226. #else
  227. #define LogDebugEvent(Event, Arg)
  228. #endif // DBG
  229. #ifndef COUNTING_MALLOC
  230. #define COUNTING_MALLOC DBG
  231. #endif
  232. #if COUNTING_MALLOC
  233. #if defined(ExFreePool)
  234. #undef ExFreePool
  235. #endif
  236. #define ExAllocatePoolWithTag(poolType, size, tag) CountingExAllocatePoolWithTag((poolType),(size),(tag), __FILE__, __LINE__)
  237. #define ExFreePool(p) CountingExFreePool((p))
  238. VOID *
  239. CountingExAllocatePoolWithTag(
  240. IN POOL_TYPE PoolType,
  241. IN ULONG NumberOfBytes,
  242. IN ULONG Tag,
  243. IN PCHAR File,
  244. IN ULONG Line);
  245. VOID
  246. CountingExFreePool(
  247. PVOID p);
  248. VOID
  249. InitCountingMalloc(void);
  250. VOID
  251. DumpCountingMallocStats(void);
  252. VOID
  253. UnloadCountingMalloc(void);
  254. #endif // COUNTING_MALLOC
  255. #endif // OSCFG_INCLUDED