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.

176 lines
4.0 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-2000 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. #ifndef OSCFG_INCLUDED
  7. #define OSCFG_INCLUDED
  8. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  9. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  10. // My binary compatible definition for compiling an Millennium tcpip.sys
  11. #if MILLEN
  12. #include "wdm.h"
  13. #define KdPrintEx(_x_)
  14. #else // MILLEN
  15. #include <ntosp.h>
  16. #include <zwapi.h>
  17. #endif // !MILLEN
  18. #define BEGIN_INIT
  19. #define END_INIT
  20. #if defined (_WIN64)
  21. #define MAX_CACHE_LINE_SIZE 128
  22. #else
  23. #define MAX_CACHE_LINE_SIZE 64
  24. #endif
  25. #define CACHE_ALIGN __declspec(align(MAX_CACHE_LINE_SIZE))
  26. typedef struct CACHE_ALIGN _CACHE_LINE_KSPIN_LOCK {
  27. KSPIN_LOCK Lock;
  28. } CACHE_LINE_KSPIN_LOCK;
  29. C_ASSERT(sizeof(CACHE_LINE_KSPIN_LOCK) % MAX_CACHE_LINE_SIZE == 0);
  30. C_ASSERT(__alignof(CACHE_LINE_KSPIN_LOCK) == MAX_CACHE_LINE_SIZE);
  31. typedef struct CACHE_ALIGN _CACHE_LINE_SLIST_HEADER {
  32. SLIST_HEADER SListHead;
  33. } CACHE_LINE_SLIST_HEADER;
  34. C_ASSERT(sizeof(CACHE_LINE_SLIST_HEADER) % MAX_CACHE_LINE_SIZE == 0);
  35. C_ASSERT(__alignof(CACHE_LINE_SLIST_HEADER) == MAX_CACHE_LINE_SIZE);
  36. typedef struct CACHE_ALIGN _CACHE_LINE_ULONG {
  37. ULONG Value;
  38. } CACHE_LINE_ULONG;
  39. C_ASSERT(sizeof(CACHE_LINE_ULONG) % MAX_CACHE_LINE_SIZE == 0);
  40. C_ASSERT(__alignof(CACHE_LINE_ULONG) == MAX_CACHE_LINE_SIZE);
  41. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  42. #define net_short(_x) _byteswap_ushort((USHORT)(_x))
  43. #define net_long(_x) _byteswap_ulong(_x)
  44. #else
  45. __inline
  46. USHORT
  47. FASTCALL
  48. net_short(
  49. ULONG NaturalData)
  50. {
  51. USHORT ShortData = (USHORT)NaturalData;
  52. return (ShortData << 8) | (ShortData >> 8);
  53. }
  54. // if x is aabbccdd (where aa, bb, cc, dd are hex bytes)
  55. // we want net_long(x) to be ddccbbaa. A small and fast way to do this is
  56. // to first byteswap it to get bbaaddcc and then swap high and low words.
  57. //
  58. __inline
  59. ULONG
  60. FASTCALL
  61. net_long(
  62. ULONG NaturalData)
  63. {
  64. ULONG ByteSwapped;
  65. ByteSwapped = ((NaturalData & 0x00ff00ff) << 8) |
  66. ((NaturalData & 0xff00ff00) >> 8);
  67. return (ByteSwapped << 16) | (ByteSwapped >> 16);
  68. }
  69. #endif
  70. #pragma warning(push)
  71. #pragma warning(disable:4244) // conversion from 'int' to 'BOOLEAN'
  72. __inline
  73. BOOLEAN
  74. IsPowerOfTwo(
  75. ULONG Value
  76. )
  77. {
  78. return (Value & (Value - 1)) == 0;
  79. }
  80. #pragma warning(pop)
  81. // Find the highest power of two that is greater
  82. // than or equal to the Value.
  83. //
  84. __inline
  85. ULONG
  86. ComputeLargerOrEqualPowerOfTwo(
  87. ULONG Value
  88. )
  89. {
  90. ULONG Temp;
  91. for (Temp = 1; Temp < Value; Temp <<= 1);
  92. return Temp;
  93. }
  94. // Find the highest power of two, in the form of its shift, that is greater
  95. // than or equal to the Value.
  96. //
  97. __inline
  98. ULONG
  99. ComputeShiftForLargerOrEqualPowerOfTwo(
  100. ULONG Value
  101. )
  102. {
  103. ULONG Shift;
  104. ULONG Temp;
  105. for (Temp = 1, Shift = 0; Temp < Value; Temp <<= 1, Shift++);
  106. return Shift;
  107. }
  108. __inline
  109. VOID
  110. FASTCALL
  111. CTEGetLockAtIrql (
  112. IN PKSPIN_LOCK SpinLock,
  113. IN KIRQL OrigIrql,
  114. OUT PKIRQL OldIrql)
  115. {
  116. #if !MILLEN
  117. if (DISPATCH_LEVEL == OrigIrql) {
  118. ASSERT(DISPATCH_LEVEL == KeGetCurrentIrql());
  119. ExAcquireSpinLockAtDpcLevel(SpinLock);
  120. *OldIrql = DISPATCH_LEVEL;
  121. } else {
  122. ExAcquireSpinLock(SpinLock, OldIrql);
  123. }
  124. #else
  125. *OldIrql = 0;
  126. #endif
  127. }
  128. __inline
  129. VOID
  130. FASTCALL
  131. CTEFreeLockAtIrql (
  132. IN PKSPIN_LOCK SpinLock,
  133. IN KIRQL OrigIrql,
  134. IN KIRQL NewIrql)
  135. {
  136. #if !MILLEN
  137. if (DISPATCH_LEVEL == OrigIrql) {
  138. ASSERT(DISPATCH_LEVEL == NewIrql);
  139. ASSERT(DISPATCH_LEVEL == KeGetCurrentIrql());
  140. ExReleaseSpinLockFromDpcLevel(SpinLock);
  141. } else {
  142. ExReleaseSpinLock(SpinLock, NewIrql);
  143. }
  144. #endif
  145. }
  146. #endif // OSCFG_INCLUDED