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.

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