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.

186 lines
5.1 KiB

  1. /*************************************************************************
  2. * icadata.c
  3. *
  4. * This module declares global data for Termdd
  5. *
  6. * Copyright (C) 1997-1999 Microsoft Corp.
  7. *************************************************************************/
  8. /*
  9. * Includes
  10. */
  11. #include <precomp.h>
  12. #pragma hdrstop
  13. PDEVICE_OBJECT IcaDeviceObject;
  14. PDEVICE_OBJECT MouDeviceObject = NULL;
  15. PDEVICE_OBJECT KbdDeviceObject = NULL;
  16. BOOLEAN PortDriverInitialized;
  17. KSPIN_LOCK IcaSpinLock;
  18. KSPIN_LOCK IcaTraceSpinLock;
  19. KSPIN_LOCK IcaStackListSpinLock;
  20. PERESOURCE IcaReconnectResource;
  21. PERESOURCE IcaTraceResource;
  22. PERESOURCE IcaSdLoadResource;
  23. LIST_ENTRY IcaSdLoadListHead;
  24. LIST_ENTRY IcaTdHandleList;
  25. LIST_ENTRY IcaFreeOutBufHead[NumOutBufPools];
  26. LIST_ENTRY IcaStackListHead;
  27. ULONG IcaTotalNumOfStacks;
  28. PLIST_ENTRY IcaNextStack;
  29. PKEVENT pIcaKeepAliveEvent;
  30. PKTHREAD pKeepAliveThreadObject;
  31. HANDLE g_TermServProcessID=NULL;
  32. unsigned MaxOutBufMdlOverhead;
  33. // Used by OutBuf alloc code to map a bit range from the alloc size
  34. // (requested alloc size + header sizes) into a particular buffer pool.
  35. // We use a 512-byte granularity, but alloc sizes that are various multiples
  36. // of 512 bytes, to correspond with various protocol typical allocation sizes.
  37. const unsigned char OutBufPoolMapping[1 << NumAllocSigBits] =
  38. {
  39. // Index Binary AllocRange Pool PoolAllocSize
  40. 0, // 0 0000 0..511 0 1024
  41. 0, // 1 0001 512..1023 0 1024
  42. 1, // 2 0010 1024..1535 1 1536
  43. 2, // 3 0011 1536..2047 2 2048
  44. 3, // 4 0100 2048..2559 3 2560
  45. 4, // 5 0101 2560..3071 4 8192
  46. 4, // 6 0110 3072..3583 4 8192
  47. 4, // 7 0111 3584..4095 4 8192
  48. 4, // 8 1000 4096..4607 4 8192
  49. 4, // 9 1001 4608..5119 4 8192
  50. 4, // 10 1010 5120..5631 4 8192
  51. 4, // 11 1011 5632..6143 4 8192
  52. 4, // 12 1100 6144..6655 4 8192
  53. 4, // 13 1101 6656..7167 4 8192
  54. 4, // 14 1110 7168..7679 4 8192
  55. 4, // 15 1111 7680..8191 4 8192
  56. };
  57. // After mapping we have a pool number and need to know the size to alloc.
  58. const unsigned OutBufPoolAllocSizes[NumOutBufPools] =
  59. {
  60. 1024, 1536, 2048, 2560, 8192
  61. };
  62. FAST_IO_DISPATCH IcaFastIoDispatch;
  63. PEPROCESS IcaSystemProcess;
  64. CCHAR IcaIrpStackSize = ICA_DEFAULT_IRP_STACK_SIZE;
  65. CCHAR IcaPriorityBoost = ICA_DEFAULT_PRIORITY_BOOST;
  66. TERMSRV_SYSTEM_PARAMS SysParams =
  67. {
  68. DEFAULT_MOUSE_THROTTLE_SIZE,
  69. DEFAULT_KEYBOARD_THROTTLE_SIZE,
  70. };
  71. #ifdef notdef
  72. FAST_IO_DISPATCH IcaFastIoDispatch =
  73. {
  74. 11, // SizeOfFastIoDispatch
  75. NULL, // FastIoCheckIfPossible
  76. IcaFastIoRead, // FastIoRead
  77. IcaFastIoWrite, // FastIoWrite
  78. NULL, // FastIoQueryBasicInfo
  79. NULL, // FastIoQueryStandardInfo
  80. NULL, // FastIoLock
  81. NULL, // FastIoUnlockSingle
  82. NULL, // FastIoUnlockAll
  83. NULL, // FastIoUnlockAllByKey
  84. IcaFastIoDeviceControl // FastIoDeviceControl
  85. };
  86. #endif
  87. #if DBG
  88. ULONG IcaLocksAcquired = 0;
  89. #endif
  90. BOOLEAN
  91. IcaInitializeData (
  92. VOID
  93. )
  94. {
  95. int i, j;
  96. PAGED_CODE( );
  97. #if DBG
  98. IcaInitializeDebugData( );
  99. #endif
  100. //
  101. // Initialize global lists.
  102. //
  103. InitializeListHead( &IcaSdLoadListHead );
  104. InitializeListHead( &IcaStackListHead );
  105. IcaTotalNumOfStacks = 0;
  106. IcaNextStack = &IcaStackListHead;
  107. pKeepAliveThreadObject = NULL;
  108. for ( i = 0; i < NumOutBufPools; i++ )
  109. InitializeListHead( &IcaFreeOutBufHead[i] );
  110. //
  111. // Initialize global spin locks and resources used by ICA.
  112. //
  113. KeInitializeSpinLock( &IcaSpinLock );
  114. KeInitializeSpinLock( &IcaTraceSpinLock );
  115. KeInitializeSpinLock( &IcaStackListSpinLock );
  116. IcaInitializeHandleTable();
  117. IcaReconnectResource = ICA_ALLOCATE_POOL( NonPagedPool, sizeof(*IcaReconnectResource) );
  118. if ( IcaReconnectResource == NULL ) {
  119. return FALSE;
  120. }
  121. ExInitializeResourceLite( IcaReconnectResource );
  122. IcaSdLoadResource = ICA_ALLOCATE_POOL( NonPagedPool, sizeof(*IcaSdLoadResource) );
  123. if ( IcaSdLoadResource == NULL ) {
  124. return FALSE;
  125. }
  126. ExInitializeResourceLite( IcaSdLoadResource );
  127. IcaTraceResource = ICA_ALLOCATE_POOL( NonPagedPool, sizeof(*IcaTraceResource) );
  128. if ( IcaTraceResource == NULL ) {
  129. return FALSE;
  130. }
  131. ExInitializeResourceLite( IcaTraceResource );
  132. pIcaKeepAliveEvent = ICA_ALLOCATE_POOL(NonPagedPool, sizeof(KEVENT));
  133. if ( pIcaKeepAliveEvent != NULL ) {
  134. KeInitializeEvent(pIcaKeepAliveEvent, NotificationEvent, FALSE);
  135. }
  136. else {
  137. return FALSE;
  138. }
  139. // Used by OutBuf alloc code for determining max overhead of OutBuf info
  140. // for the default max size allocation.
  141. MaxOutBufMdlOverhead = (unsigned)MmSizeOfMdl((PVOID)(PAGE_SIZE - 1),
  142. MaxOutBufAlloc);
  143. return TRUE;
  144. }