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.

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