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.

516 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. data.cxx
  5. Abstract:
  6. This module contains global data for UL.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text( INIT, UlInitializeData )
  14. #pragma alloc_text( PAGE, UlTerminateData )
  15. #endif // ALLOC_PRAGMA
  16. //
  17. // The number of processors in the system.
  18. //
  19. CLONG g_UlNumberOfProcessors = 1;
  20. ULONGLONG g_UlThreadAffinityMask = 1;
  21. //
  22. // The largest cache line size the system
  23. //
  24. ULONG g_UlCacheLineSize = 0;
  25. ULONG g_UlCacheLineBits = 0; // see init.cxx
  26. //
  27. // Our nonpaged data.
  28. //
  29. PUL_NONPAGED_DATA g_pUlNonpagedData = NULL;
  30. //
  31. // A pointer to the system process.
  32. //
  33. PKPROCESS g_pUlSystemProcess = NULL;
  34. //
  35. // Our device objects and their container.
  36. //
  37. HANDLE g_UlDirectoryObject = NULL;
  38. PDEVICE_OBJECT g_pUlControlDeviceObject = NULL;
  39. PDEVICE_OBJECT g_pUlFilterDeviceObject = NULL;
  40. PDEVICE_OBJECT g_pUlAppPoolDeviceObject = NULL;
  41. //
  42. // Cached Date header string.
  43. //
  44. LARGE_INTEGER g_UlSystemTime;
  45. UCHAR g_UlDateString[DATE_HDR_LENGTH+1];
  46. ULONG g_UlDateStringLength;
  47. //
  48. // Various pieces of configuration information, with default values.
  49. //
  50. CCHAR g_UlPriorityBoost = DEFAULT_PRIORITY_BOOST;
  51. CCHAR g_UlIrpStackSize = DEFAULT_IRP_STACK_SIZE;
  52. USHORT g_UlMinIdleConnections = DEFAULT_MIN_IDLE_CONNECTIONS;
  53. USHORT g_UlMaxIdleConnections = DEFAULT_MAX_IDLE_CONNECTIONS;
  54. ULONG g_UlReceiveBufferSize = DEFAULT_RCV_BUFFER_SIZE;
  55. ULONG g_UlMaxRequestBytes = DEFAULT_MAX_REQUEST_BYTES;
  56. BOOLEAN g_UlEnableConnectionReuse = DEFAULT_ENABLE_CONNECTION_REUSE;
  57. BOOLEAN g_UlEnableNagling = DEFAULT_ENABLE_NAGLING;
  58. BOOLEAN g_UlEnableThreadAffinity = DEFAULT_ENABLE_THREAD_AFFINITY;
  59. ULONG g_UlMaxUrlLength = DEFAULT_MAX_URL_LENGTH;
  60. ULONG g_UlMaxFieldLength = DEFAULT_MAX_FIELD_LENGTH;
  61. USHORT g_UlDebugLogTimerCycle = DEFAULT_DEBUG_LOGTIMER_CYCLE;
  62. USHORT g_UlDebugLogBufferPeriod = DEFAULT_DEBUG_LOG_BUFFER_PERIOD;
  63. ULONG g_UlLogBufferSize = DEFAULT_LOG_BUFFER_SIZE;
  64. BOOLEAN g_UlEnableNonUTF8 = DEFAULT_ENABLE_NON_UTF8_URL;
  65. BOOLEAN g_UlEnableDBCS = DEFAULT_ENABLE_DBCS_URL;
  66. BOOLEAN g_UlFavorDBCS = DEFAULT_FAVOR_DBCS_URL;
  67. USHORT g_UlMaxInternalUrlLength = DEFAULT_MAX_INTERNAL_URL_LENGTH;
  68. ULONG g_UlResponseBufferSize = DEFAULT_RESP_BUFFER_SIZE;
  69. ULONG g_UlMaxBufferedBytes = DEFAULT_MAX_BUFFERED_BYTES;
  70. ULONG g_UlMaxCopyThreshold = DEFAULT_MAX_COPY_THRESHOLD;
  71. ULONG g_UlMaxSendBufferedBytes = DEFAULT_MAX_SEND_BUFFERED_BYTES;
  72. ULONG g_UlMaxWorkQueueDepth = DEFAULT_MAX_WORK_QUEUE_DEPTH;
  73. ULONG g_UlMinWorkDequeueDepth = DEFAULT_MIN_WORK_DEQUEUE_DEPTH;
  74. ULONG g_UlOpaqueIdTableSize = DEFAULT_OPAQUE_ID_TABLE_SIZE;
  75. //
  76. // The following are generated during initialization.
  77. //
  78. ULONG g_UlMaxVariableHeaderSize = 0;
  79. ULONG g_UlMaxFixedHeaderSize = 0;
  80. ULONG g_UlFixedHeadersMdlLength = 0;
  81. ULONG g_UlVariableHeadersMdlLength = 0;
  82. ULONG g_UlContentMdlLength = 0;
  83. ULONG g_UlChunkTrackerSize = 0;
  84. ULONG g_UlFullTrackerSize = 0;
  85. //
  86. // Make life easier for the debugger extension.
  87. //
  88. #if DBG
  89. ULONG g_UlCheckedBuild = TRUE;
  90. #else
  91. ULONG g_UlCheckedBuild = FALSE;
  92. #endif
  93. //
  94. // Debug stuff.
  95. //
  96. #if DBG
  97. ULONG g_UlDebug = DEFAULT_DEBUG_FLAGS;
  98. ULONG g_UlBreakOnError = DEFAULT_BREAK_ON_ERROR;
  99. ULONG g_UlVerboseErrors = DEFAULT_VERBOSE_ERRORS;
  100. UL_DEBUG_STATISTICS_INFO g_UlDebugStats = { 0 };
  101. #endif // DBG
  102. #if REFERENCE_DEBUG
  103. PTRACE_LOG g_pMondoGlobalTraceLog = NULL;
  104. PTRACE_LOG g_pTdiTraceLog = NULL;
  105. PTRACE_LOG g_pHttpRequestTraceLog = NULL;
  106. PTRACE_LOG g_pHttpConnectionTraceLog = NULL;
  107. PTRACE_LOG g_pHttpResponseTraceLog = NULL;
  108. PTRACE_LOG g_pAppPoolTraceLog = NULL;
  109. PTRACE_LOG g_pConfigGroupTraceLog = NULL;
  110. PTRACE_LOG g_pThreadTraceLog = NULL;
  111. PTRACE_LOG g_pFilterTraceLog = NULL;
  112. PTRACE_LOG g_pIrpTraceLog = NULL;
  113. PTRACE_LOG g_pTimeTraceLog = NULL;
  114. PTRACE_LOG g_pReplenishTraceLog = NULL;
  115. PTRACE_LOG g_pFilterQueueTraceLog = NULL;
  116. PTRACE_LOG g_pMdlTraceLog = NULL;
  117. PTRACE_LOG g_pSiteCounterTraceLog = NULL;
  118. PTRACE_LOG g_pConnectionCountTraceLog = NULL;
  119. PTRACE_LOG g_pConfigGroupInfoTraceLog = NULL;
  120. PTRACE_LOG g_pChunkTrackerTraceLog = NULL;
  121. PTRACE_LOG g_pWorkItemTraceLog = NULL;
  122. #endif // REFERENCE_DEBUG
  123. //
  124. // Public functions.
  125. //
  126. /***************************************************************************++
  127. Routine Description:
  128. Performs global data initialization.
  129. Return Value:
  130. NTSTATUS - Completion status.
  131. --***************************************************************************/
  132. NTSTATUS
  133. UlInitializeData(
  134. PUL_CONFIG pConfig
  135. )
  136. {
  137. //
  138. // Sanity check.
  139. //
  140. PAGED_CODE();
  141. //
  142. // Initialize the nonpaged data.
  143. //
  144. g_pUlNonpagedData = UL_ALLOCATE_STRUCT(
  145. NonPagedPool,
  146. UL_NONPAGED_DATA,
  147. UL_NONPAGED_DATA_POOL_TAG
  148. );
  149. if (g_pUlNonpagedData == NULL )
  150. {
  151. return STATUS_INSUFFICIENT_RESOURCES;
  152. }
  153. RtlZeroMemory(g_pUlNonpagedData, sizeof(*g_pUlNonpagedData));
  154. #if DBG
  155. //
  156. // Initialize any debug-specific data.
  157. //
  158. UlDbgInitializeDebugData( );
  159. #endif // DBG
  160. //
  161. // Initialize the maximum variable header size.
  162. //
  163. g_UlMaxVariableHeaderSize = UlComputeMaxVariableHeaderSize();
  164. g_UlMaxVariableHeaderSize = ALIGN_UP(g_UlMaxVariableHeaderSize, PVOID);
  165. g_UlMaxFixedHeaderSize = DEFAULT_MAX_FIXED_HEADER_SIZE;
  166. //
  167. // Initialize the maximum cache Mdl length.
  168. //
  169. ASSERT( g_UlMaxFixedHeaderSize <= MAX_BYTES_BUFFERED );
  170. ASSERT( g_UlMaxVariableHeaderSize <= MAX_BYTES_BUFFERED );
  171. ASSERT( g_UlMaxCopyThreshold <= MAX_BYTES_BUFFERED );
  172. //
  173. // MDL Length for FixedHeaders or UserBuffer.
  174. //
  175. g_UlFixedHeadersMdlLength = (ULONG)
  176. MmSizeOfMdl(
  177. (PVOID)(PAGE_SIZE - 1),
  178. MAX_BYTES_BUFFERED
  179. );
  180. g_UlFixedHeadersMdlLength = ALIGN_UP(g_UlFixedHeadersMdlLength, PVOID);
  181. //
  182. // MDL Length for VariableHeaders or FixedHeaders + VariablesHeaders +
  183. // CopiedBuffer.
  184. //
  185. g_UlVariableHeadersMdlLength = (ULONG)
  186. MmSizeOfMdl(
  187. (PVOID)(PAGE_SIZE - 1),
  188. g_UlMaxFixedHeaderSize +
  189. g_UlMaxVariableHeaderSize +
  190. g_UlMaxCopyThreshold
  191. );
  192. g_UlVariableHeadersMdlLength = ALIGN_UP(g_UlVariableHeadersMdlLength, PVOID);
  193. //
  194. // MDL Length for Content.
  195. //
  196. g_UlContentMdlLength = (ULONG)
  197. MmSizeOfMdl(
  198. (PVOID)(PAGE_SIZE - 1),
  199. pConfig->UriConfig.MaxUriBytes
  200. );
  201. g_UlContentMdlLength = ALIGN_UP(g_UlContentMdlLength, PVOID);
  202. //
  203. // Initialize chunk and cache tracker size.
  204. //
  205. g_UlChunkTrackerSize =
  206. ALIGN_UP(sizeof(UL_CHUNK_TRACKER), PVOID) +
  207. 2 * ALIGN_UP(IoSizeOfIrp(DEFAULT_MAX_IRP_STACK_SIZE), PVOID) +
  208. g_UlMaxVariableHeaderSize;
  209. g_UlFullTrackerSize =
  210. ALIGN_UP(sizeof(UL_FULL_TRACKER), PVOID) +
  211. ALIGN_UP(IoSizeOfIrp(DEFAULT_MAX_IRP_STACK_SIZE), PVOID) +
  212. g_UlMaxFixedHeaderSize +
  213. g_UlMaxVariableHeaderSize +
  214. g_UlMaxCopyThreshold +
  215. g_UlFixedHeadersMdlLength +
  216. g_UlVariableHeadersMdlLength +
  217. g_UlContentMdlLength;
  218. g_UlFullTrackerSize = ALIGN_UP(g_UlFullTrackerSize, PVOID);
  219. //
  220. // Initialize the lookaside lists.
  221. //
  222. g_pUlNonpagedData->IrpContextLookaside =
  223. PplCreatePool(
  224. &UlAllocateIrpContextPool, // Allocate
  225. &UlFreeIrpContextPool, // Free
  226. 0, // Flags
  227. sizeof(UL_IRP_CONTEXT), // Size
  228. UL_IRP_CONTEXT_POOL_TAG, // Tag
  229. pConfig->IrpContextLookasideDepth // Depth
  230. );
  231. if (!g_pUlNonpagedData->IrpContextLookaside)
  232. {
  233. return STATUS_INSUFFICIENT_RESOURCES;
  234. }
  235. g_pUlNonpagedData->ReceiveBufferLookaside =
  236. PplCreatePool(
  237. &UlAllocateReceiveBufferPool, // Allocate
  238. &UlFreeReceiveBufferPool, // Free
  239. 0, // Flags
  240. sizeof(UL_RECEIVE_BUFFER), // Size
  241. UL_RCV_BUFFER_POOL_TAG, // Tag
  242. pConfig->ReceiveBufferLookasideDepth // Depth
  243. );
  244. if (!g_pUlNonpagedData->ReceiveBufferLookaside)
  245. {
  246. return STATUS_INSUFFICIENT_RESOURCES;
  247. }
  248. g_pUlNonpagedData->ResponseBufferLookaside =
  249. PplCreatePool(
  250. &UlAllocateResponseBufferPool, // Allocate
  251. &UlFreeResponseBufferPool, // Free
  252. 0, // Flags
  253. g_UlResponseBufferSize, // Size
  254. UL_INTERNAL_RESPONSE_POOL_TAG, // Tag
  255. pConfig->ResponseBufferLookasideDepth // Depth
  256. );
  257. if (!g_pUlNonpagedData->ResponseBufferLookaside)
  258. {
  259. return STATUS_INSUFFICIENT_RESOURCES;
  260. }
  261. g_pUlNonpagedData->ResourceLookaside =
  262. PplCreatePool(
  263. &UlResourceAllocatePool, // Allocate
  264. &UlResourceFreePool, // Free
  265. 0, // Flags
  266. sizeof(UL_NONPAGED_RESOURCE), // Size
  267. UL_NONPAGED_RESOURCE_POOL_TAG, // Tag
  268. pConfig->ResourceLookasideDepth // Depth
  269. );
  270. if (!g_pUlNonpagedData->ResourceLookaside)
  271. {
  272. return STATUS_INSUFFICIENT_RESOURCES;
  273. }
  274. g_pUlNonpagedData->RequestBufferLookaside =
  275. PplCreatePool(
  276. &UlAllocateRequestBufferPool, // Allocate
  277. &UlFreeRequestBufferPool, // Free
  278. 0, // Flags
  279. DEFAULT_MAX_REQUEST_BUFFER_SIZE, // Size
  280. UL_REQUEST_BUFFER_POOL_TAG, // Tag
  281. pConfig->RequestBufferLookasideDepth // Depth
  282. );
  283. if (!g_pUlNonpagedData->RequestBufferLookaside)
  284. {
  285. return STATUS_INSUFFICIENT_RESOURCES;
  286. }
  287. g_pUlNonpagedData->InternalRequestLookaside =
  288. PplCreatePool(
  289. &UlAllocateInternalRequestPool, // Allocate
  290. &UlFreeInternalRequestPool, // Free
  291. 0, // Flags
  292. sizeof(UL_INTERNAL_REQUEST), // Size
  293. UL_INTERNAL_REQUEST_POOL_TAG, // Tag
  294. pConfig->InternalRequestLookasideDepth // Depth
  295. );
  296. if (!g_pUlNonpagedData->InternalRequestLookaside)
  297. {
  298. return STATUS_INSUFFICIENT_RESOURCES;
  299. }
  300. g_pUlNonpagedData->ChunkTrackerLookaside =
  301. PplCreatePool(
  302. &UlAllocateChunkTrackerPool, // Allocate
  303. &UlFreeChunkTrackerPool, // Free
  304. 0, // Flags
  305. g_UlChunkTrackerSize, // Size
  306. UL_CHUNK_TRACKER_POOL_TAG, // Tag
  307. pConfig->SendTrackerLookasideDepth // Depth
  308. );
  309. if (!g_pUlNonpagedData->ChunkTrackerLookaside)
  310. {
  311. return STATUS_INSUFFICIENT_RESOURCES;
  312. }
  313. g_pUlNonpagedData->FullTrackerLookaside =
  314. PplCreatePool(
  315. &UlAllocateFullTrackerPool, // Allocate
  316. &UlFreeFullTrackerPool, // Free
  317. 0, // Flags
  318. g_UlFullTrackerSize, // Size
  319. UL_FULL_TRACKER_POOL_TAG, // Tag
  320. pConfig->SendTrackerLookasideDepth // Depth
  321. );
  322. if (!g_pUlNonpagedData->FullTrackerLookaside)
  323. {
  324. return STATUS_INSUFFICIENT_RESOURCES;
  325. }
  326. g_pUlNonpagedData->LogBufferLookaside =
  327. PplCreatePool(
  328. &UlAllocateLogBufferPool, // Allocate
  329. &UlFreeLogBufferPool, // Free
  330. 0, // Flags
  331. sizeof(UL_LOG_FILE_BUFFER), // Size
  332. UL_LOG_FILE_BUFFER_POOL_TAG, // Tag
  333. pConfig->LogBufferLookasideDepth // Depth
  334. );
  335. if (!g_pUlNonpagedData->LogBufferLookaside)
  336. {
  337. return STATUS_INSUFFICIENT_RESOURCES;
  338. }
  339. return STATUS_SUCCESS;
  340. } // UlInitializeData
  341. /***************************************************************************++
  342. Routine Description:
  343. Performs global data termination.
  344. --***************************************************************************/
  345. VOID
  346. UlTerminateData(
  347. VOID
  348. )
  349. {
  350. //
  351. // Sanity check.
  352. //
  353. PAGED_CODE();
  354. if (g_pUlNonpagedData != NULL)
  355. {
  356. //
  357. // Kill the lookaside lists.
  358. //
  359. if (g_pUlNonpagedData->IrpContextLookaside)
  360. {
  361. PplDestroyPool( g_pUlNonpagedData->IrpContextLookaside );
  362. }
  363. if (g_pUlNonpagedData->ReceiveBufferLookaside)
  364. {
  365. PplDestroyPool( g_pUlNonpagedData->ReceiveBufferLookaside );
  366. }
  367. if (g_pUlNonpagedData->ResourceLookaside)
  368. {
  369. PplDestroyPool( g_pUlNonpagedData->ResourceLookaside );
  370. }
  371. if (g_pUlNonpagedData->RequestBufferLookaside)
  372. {
  373. PplDestroyPool( g_pUlNonpagedData->RequestBufferLookaside );
  374. }
  375. if (g_pUlNonpagedData->InternalRequestLookaside)
  376. {
  377. PplDestroyPool( g_pUlNonpagedData->InternalRequestLookaside );
  378. }
  379. if (g_pUlNonpagedData->ChunkTrackerLookaside)
  380. {
  381. PplDestroyPool( g_pUlNonpagedData->ChunkTrackerLookaside );
  382. }
  383. if (g_pUlNonpagedData->FullTrackerLookaside)
  384. {
  385. PplDestroyPool( g_pUlNonpagedData->FullTrackerLookaside );
  386. }
  387. if (g_pUlNonpagedData->ResponseBufferLookaside)
  388. {
  389. PplDestroyPool( g_pUlNonpagedData->ResponseBufferLookaside );
  390. }
  391. if (g_pUlNonpagedData->LogBufferLookaside)
  392. {
  393. PplDestroyPool( g_pUlNonpagedData->LogBufferLookaside );
  394. }
  395. //
  396. // Free the nonpaged data.
  397. //
  398. UL_FREE_POOL( g_pUlNonpagedData, UL_NONPAGED_DATA_POOL_TAG );
  399. }
  400. } // UlTerminateData