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.

542 lines
16 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. server.h
  5. Abstract:
  6. This module contains the internal structures and definitions used
  7. by the console server.
  8. Author:
  9. Therese Stowell (thereses) 12-Nov-1990
  10. Revision History:
  11. --*/
  12. #ifndef _SERVER_H_
  13. #define _SERVER_H_
  14. //
  15. // This message is used to notify the input thread that a console window should
  16. // go away.
  17. //
  18. typedef struct _CONSOLE_SHARE_ACCESS {
  19. ULONG OpenCount;
  20. ULONG Readers;
  21. ULONG Writers;
  22. ULONG SharedRead;
  23. ULONG SharedWrite;
  24. } CONSOLE_SHARE_ACCESS, *PCONSOLE_SHARE_ACCESS;
  25. #include "input.h"
  26. #include "output.h"
  27. #if defined(FE_IME)
  28. #include "conime.h"
  29. #include "convarea.h"
  30. #endif
  31. typedef struct _CONSOLE_PROCESS_HANDLE {
  32. LIST_ENTRY ListLink;
  33. HANDLE ProcessHandle;
  34. PCSR_PROCESS Process;
  35. ULONG TerminateCount;
  36. LPTHREAD_START_ROUTINE CtrlRoutine;
  37. LPTHREAD_START_ROUTINE PropRoutine;
  38. } CONSOLE_PROCESS_HANDLE, *PCONSOLE_PROCESS_HANDLE;
  39. typedef struct _INPUT_THREAD_INFO {
  40. HANDLE ThreadHandle;
  41. DWORD ThreadId;
  42. HDESK Desktop;
  43. HWINSTA WindowStation;
  44. ULONG WindowCount;
  45. #if defined(FE_IME)
  46. HWND hWndConsoleIME;
  47. #endif
  48. } INPUT_THREAD_INFO, *PINPUT_THREAD_INFO;
  49. typedef struct _INPUT_THREAD_INIT_INFO {
  50. HANDLE ThreadHandle;
  51. HANDLE InitCompleteEventHandle;
  52. HDESK DesktopHandle;
  53. HWINSTA WinstaHandle;
  54. NTSTATUS InitStatus;
  55. } INPUT_THREAD_INIT_INFO, *PINPUT_THREAD_INIT_INFO;
  56. typedef struct _CONSOLE_MSG {
  57. LIST_ENTRY ListLink;
  58. UINT Message;
  59. WPARAM wParam;
  60. LPARAM lParam;
  61. } CONSOLE_MSG, *PCONSOLE_MSG;
  62. typedef struct _CONSOLE_THREAD_MSG {
  63. CONSOLE_MSG;
  64. DWORD dwThreadId;
  65. } CONSOLE_THREAD_MSG, *PCONSOLE_THREAD_MSG;
  66. // Flags flags
  67. #define CONSOLE_IS_ICONIC 0x00000001
  68. #define CONSOLE_OUTPUT_SUSPENDED 0x00000002
  69. #define CONSOLE_HAS_FOCUS 0x00000004
  70. #define CONSOLE_IGNORE_NEXT_MOUSE_INPUT 0x00000008
  71. #define CONSOLE_SELECTING 0x00000010
  72. #define CONSOLE_SCROLLING 0x00000020
  73. #define CONSOLE_DISABLE_CLOSE 0x00000040
  74. #define CONSOLE_NOTIFY_LAST_CLOSE 0x00000080
  75. #define CONSOLE_NO_WINDOW 0x00000100
  76. #define CONSOLE_VDM_REGISTERED 0x00000200
  77. #define CONSOLE_UPDATING_SCROLL_BARS 0x00000400
  78. #define CONSOLE_QUICK_EDIT_MODE 0x00000800
  79. #define CONSOLE_TERMINATING 0x00001000
  80. #define CONSOLE_CONNECTED_TO_EMULATOR 0x00002000
  81. #define CONSOLE_FULLSCREEN_NOPAINT 0x00004000
  82. #define CONSOLE_SHUTTING_DOWN 0x00008000
  83. #define CONSOLE_AUTO_POSITION 0x00010000
  84. #define CONSOLE_IGNORE_NEXT_KEYUP 0x00020000
  85. #define CONSOLE_WOW_REGISTERED 0x00040000
  86. #define CONSOLE_USE_PRIVATE_FLAGS 0x00080000
  87. #define CONSOLE_HISTORY_NODUP 0x00100000
  88. #define CONSOLE_SCROLLBAR_TRACKING 0x00200000
  89. #define CONSOLE_IN_DESTRUCTION 0x00400000
  90. #define CONSOLE_SETTING_WINDOW_SIZE 0x00800000
  91. #define CONSOLE_DEFAULT_BUFFER_SIZE 0x01000000
  92. #define CONSOLE_VDM_HIDDEN_WINDOW 0x02000000
  93. #if defined(FE_SB)
  94. #define CONSOLE_OS2_REGISTERED 0x20000000
  95. #define CONSOLE_OS2_OEM_FORMAT 0x40000000
  96. #if defined(FE_IME)
  97. #define CONSOLE_JUST_VDM_UNREGISTERED 0x80000000
  98. #endif // FE_IME
  99. #endif
  100. #define CONSOLE_SUSPENDED (CONSOLE_OUTPUT_SUSPENDED)
  101. #if DBG
  102. typedef struct _CONSOLE_REF_NODE
  103. {
  104. struct _CONSOLE_REF_NODE *pNext;
  105. PVOID pStackTrace[8];
  106. BOOL bRef;
  107. } CONSOLE_REF_NODE, *PCONSOLE_REF_NODE;
  108. #endif
  109. typedef struct _CONSOLE_INFORMATION {
  110. CRITICAL_SECTION ConsoleLock; // serialize input and output using this
  111. ULONG RefCount;
  112. ULONG WaitCount;
  113. INPUT_INFORMATION InputBuffer;
  114. PSCREEN_INFORMATION CurrentScreenBuffer;
  115. PSCREEN_INFORMATION ScreenBuffers; // singly linked list
  116. HWINSTA hWinSta; // server handle to windowstation
  117. HDESK hDesk; // server handle to desktop
  118. HWND hWnd;
  119. HKL hklActive; // keyboard layout for this console window
  120. HDC hDC; // server side hDC
  121. HMENU hMenu; // handle to system menu
  122. HMENU hHeirMenu; // handle to menu we append to system menu
  123. HPALETTE hSysPalette;
  124. RECT WindowRect;
  125. DWORD ResizeFlags;
  126. LIST_ENTRY OutputQueue;
  127. HANDLE InitEvents[NUMBER_OF_INITIALIZATION_EVENTS];
  128. HANDLE ClientThreadHandle;
  129. LIST_ENTRY ProcessHandleList;
  130. LIST_ENTRY CommandHistoryList;
  131. LIST_ENTRY ExeAliasList;
  132. SHORT NumCommandHistories;
  133. SHORT MaxCommandHistories;
  134. SHORT CommandHistorySize;
  135. USHORT OriginalTitleLength;
  136. USHORT TitleLength;
  137. LPWSTR OriginalTitle;
  138. LPWSTR Title;
  139. DWORD dwHotKey;
  140. HICON hIcon;
  141. HICON hSmIcon;
  142. INT iIconId;
  143. WORD LastAttributes;
  144. BYTE ReserveKeys; // keys reserved by app (i.e. ctrl-esc)
  145. DWORD Flags;
  146. // if a wait has been satisfied, the pointer to the wait queue is stored
  147. // here.
  148. PLIST_ENTRY WaitQueue;
  149. // the following fields are used for selection
  150. DWORD SelectionFlags;
  151. SMALL_RECT SelectionRect;
  152. COORD SelectionAnchor;
  153. COORD TextCursorPosition; // current position on screen (in screen buffer coords).
  154. ULONG TextCursorSize;
  155. BOOLEAN TextCursorVisible; // whether cursor is visible (set by user)
  156. BOOLEAN InsertMode; // used by command line editing
  157. // following fields are used when window is created
  158. WORD wShowWindow;
  159. int dwWindowOriginX;
  160. int dwWindowOriginY;
  161. WORD FullScreenFlags;
  162. WORD PopupCount;
  163. // following fields are used for the VDM
  164. HANDLE VDMStartHardwareEvent;
  165. HANDLE VDMEndHardwareEvent;
  166. HANDLE VDMErrorHardwareEvent;
  167. HANDLE VDMProcessHandle;
  168. HANDLE VDMProcessId;
  169. HANDLE VDMBufferSectionHandle;
  170. PCHAR_INFO VDMBuffer;
  171. PCHAR_INFO VDMBufferClient;
  172. COORD VDMBufferSize;
  173. HANDLE StateSectionHandle; // used for get/sethardwarestate
  174. PVOID StateBuffer;
  175. PVOID StateBufferClient;
  176. DWORD StateLength;
  177. // the following fields are used for ansi-unicode translation
  178. UINT CP;
  179. UINT OutputCP;
  180. //
  181. // these two fields are used while getting the icon from the
  182. // program manager via DDE.
  183. //
  184. HWND hWndProgMan;
  185. BOOL bIconInit;
  186. HANDLE ConsoleHandle;
  187. ULONG CtrlFlags; // indicates outstanding ctrl requests
  188. ULONG LimitingProcessId;
  189. HANDLE TerminationEvent;
  190. SHORT VerticalClientToWindow;
  191. SHORT HorizontalClientToWindow;
  192. COLORREF ColorTable[ 16 ];
  193. HANDLE hProcessLastNotifyClose; // process handle of last-close-notify
  194. HANDLE ProcessIdLastNotifyClose; // process unique id of last-close-notify
  195. HWND hWndProperties;
  196. PINPUT_THREAD_INFO InputThreadInfo; // console thread info
  197. LIST_ENTRY MessageQueue;
  198. #if defined(FE_SB)
  199. CPINFO CPInfo;
  200. CPINFO OutputCPInfo;
  201. DWORD ReadConInpNumBytesUnicode;
  202. DWORD ReadConInpNumBytesTemp;
  203. DWORD WriteConOutNumBytesUnicode;
  204. DWORD WriteConOutNumBytesTemp;
  205. PVOID lpCookedReadData; // Same as PCOOKED_READ_DATA
  206. PVOID EudcInformation; // Same as PEUDC_INFORMATION
  207. PVOID FontCacheInformation; // Same as PFONT_CACHE_INFORMATION
  208. #if defined(FE_IME)
  209. CONSOLE_IME_INFORMATION ConsoleIme;
  210. #endif // FE_IME
  211. HDC FonthDC; // Double colored DBCS hDC
  212. HBITMAP hBitmap;
  213. #if defined(i386)
  214. SMALL_RECT Os2SavedWindowRect;
  215. #endif
  216. BOOLEAN fVDMVideoMode; // FALSE : VGA Format
  217. // TRUE : Common LVB Format
  218. BOOLEAN fIsDBCSCP;
  219. BOOLEAN fIsDBCSOutputCP;
  220. #endif
  221. /*
  222. * Instrumentation for Windows Bug 499641.
  223. */
  224. #if DBG
  225. PVOID ConnectStack[16];
  226. PVOID DisconnectStack[16];
  227. PCONSOLE_REF_NODE pRefNodes;
  228. #endif
  229. HANDLE UnlockConsoleOwningThread;
  230. DWORD UnlockConsoleSkipCount;
  231. } CONSOLE_INFORMATION, *PCONSOLE_INFORMATION;
  232. //
  233. // CtrlFlags definitions
  234. //
  235. #define CONSOLE_CTRL_C_FLAG 1
  236. #define CONSOLE_CTRL_BREAK_FLAG 2
  237. #define CONSOLE_CTRL_CLOSE_FLAG 4
  238. #define CONSOLE_FORCE_SHUTDOWN_FLAG 8
  239. #define CONSOLE_CTRL_LOGOFF_FLAG 16
  240. #define CONSOLE_CTRL_SHUTDOWN_FLAG 32
  241. #define ADD_SCROLL_BARS_X 0x1
  242. #define REMOVE_SCROLL_BARS_X 0x2
  243. #define ADD_SCROLL_BARS_Y 0x4
  244. #define REMOVE_SCROLL_BARS_Y 0x8
  245. #define RESIZE_SCROLL_BARS 0x10
  246. #define SCROLL_BAR_CHANGE (ADD_SCROLL_BARS_X | REMOVE_SCROLL_BARS_X | ADD_SCROLL_BARS_Y | REMOVE_SCROLL_BARS_Y | RESIZE_SCROLL_BARS)
  247. #define BORDER_CHANGE 0x20
  248. #define SCREEN_BUFFER_CHANGE 0x40
  249. #define CONSOLE_INITIAL_IO_HANDLES 3
  250. #define CONSOLE_IO_HANDLE_INCREMENT 3
  251. #define CONSOLE_FREE_HANDLE 0
  252. //#define CONSOLE_INPUT_HANDLE 1
  253. //#define CONSOLE_OUTPUT_HANDLE 2
  254. #define CONSOLE_GRAPHICS_OUTPUT_HANDLE 4
  255. #define CONSOLE_INHERITABLE 8
  256. #define CONSOLE_ANY_HANDLE ((ULONG)(-1))
  257. //
  258. // input handle flags
  259. //
  260. #define HANDLE_CLOSING 1
  261. #define HANDLE_INPUT_PENDING 2
  262. #define HANDLE_MULTI_LINE_INPUT 4
  263. typedef struct _HANDLE_DATA {
  264. ULONG HandleType;
  265. ACCESS_MASK Access;
  266. ULONG ShareAccess;
  267. union {
  268. PSCREEN_INFORMATION ScreenBuffer;
  269. PINPUT_INFORMATION InputBuffer;
  270. } Buffer;
  271. PINPUT_READ_HANDLE_DATA InputReadData; // used only by input reads
  272. } HANDLE_DATA, *PHANDLE_DATA;
  273. typedef struct _CONSOLE_PER_PROCESS_DATA {
  274. HANDLE ConsoleHandle;
  275. HANDLE_DATA HandleTable[CONSOLE_INITIAL_IO_HANDLES];
  276. ULONG HandleTableSize;
  277. PHANDLE_DATA HandleTablePtr;
  278. BOOLEAN ConsoleApp;
  279. BOOLEAN RootProcess;
  280. DWORD ParentProcessId;
  281. #if defined(FE_IME)
  282. HDESK hDesk;
  283. HWINSTA hWinSta;
  284. #endif
  285. } CONSOLE_PER_PROCESS_DATA, *PCONSOLE_PER_PROCESS_DATA;
  286. #define CONSOLE_INITIAL_CONSOLES 10
  287. #define CONSOLE_CONSOLE_HANDLE_INCREMENT 5
  288. #define CONSOLE_HANDLE_ALLOCATED 1
  289. #define INDEX_TO_HANDLE(INDEX) ((HANDLE)(((ULONG_PTR)INDEX << 2) | CONSOLE_HANDLE_SIGNATURE))
  290. #define HANDLE_TO_INDEX(CONHANDLE) ((HANDLE)((ULONG_PTR)CONHANDLE >> 2))
  291. #define INPUT_MODES (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT)
  292. #define OUTPUT_MODES (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT)
  293. #define PRIVATE_MODES (ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE | ENABLE_PRIVATE_FLAGS)
  294. #define CURSOR_PERCENTAGE_TO_TOP_SCAN_LINE(FONTSIZE,PERCENTAGE) ((FONTSIZE) - ((FONTSIZE) * (PERCENTAGE) / 100))
  295. #define ConsoleLocked(CONSOLEPTR) (((CONSOLEPTR)->ConsoleLock.OwningThread) == NtCurrentTeb()->ClientId.UniqueThread)
  296. #define CONSOLE_STATUS_WAIT ((NTSTATUS)0xC0030001L)
  297. #define CONSOLE_STATUS_READ_COMPLETE ((NTSTATUS)0xC0030002L)
  298. #define CONSOLE_STATUS_WAIT_NO_BLOCK ((NTSTATUS)0xC0030003L)
  299. #define CM_CREATE_CONSOLE_WINDOW (WM_USER+0)
  300. #define CM_DESTROY_WINDOW (WM_USER+1)
  301. #define CM_SET_WINDOW_SIZE (WM_USER+2)
  302. #define CM_BEEP (WM_USER+3)
  303. #define CM_UPDATE_SCROLL_BARS (WM_USER+4)
  304. #define CM_UPDATE_TITLE (WM_USER+5)
  305. //
  306. // CM_MODE_TRANSITION is hard-coded to WM_USER+6 in kernel\winmgr.c
  307. //
  308. #define CM_MODE_TRANSITION (WM_USER+6)
  309. #define CM_CONSOLE_SHUTDOWN (WM_USER+7)
  310. #define CM_HIDE_WINDOW (WM_USER+8)
  311. #if defined(FE_IME)
  312. #define CM_CONIME_CREATE (WM_USER+9)
  313. #define CM_SET_CONSOLEIME_WINDOW (WM_USER+10)
  314. #define CM_WAIT_CONIME_PROCESS (WM_USER+11)
  315. #define CM_SET_IME_CODEPAGE (WM_USER+12)
  316. #define CM_SET_NLSMODE (WM_USER+13)
  317. #define CM_GET_NLSMODE (WM_USER+14)
  318. #define CM_CONIME_KL_ACTIVATE (WM_USER+15)
  319. #endif
  320. #define CM_CONSOLE_MSG (WM_USER+16)
  321. #define CM_CONSOLE_INPUT_THREAD_MSG (WM_USER+17)
  322. #define CONSOLE_CLIENTTHREADHANDLE(pcsrthread) ((pcsrthread)->ThreadHandle)
  323. #define CONSOLE_CLIENTPROCESSHANDLE() \
  324. ((CSR_SERVER_QUERYCLIENTTHREAD())->Process->ProcessHandle)
  325. #define CONSOLE_CLIENTPROCESSID() \
  326. ((CSR_SERVER_QUERYCLIENTTHREAD())->Process->ClientId.UniqueProcess)
  327. #define CONSOLE_FROMPROCESSPROCESSHANDLE(pcsrprocess) \
  328. ((pcsrprocess)->ProcessHandle)
  329. #define CONSOLE_FROMPROCESSPERPROCESSDATA(pcsrprocess) \
  330. ((pcsrprocess)->ServerDllPerProcessData[CONSRV_SERVERDLL_INDEX])
  331. #define CONSOLE_FROMTHREADPERPROCESSDATA(pcsrthread) \
  332. CONSOLE_FROMPROCESSPERPROCESSDATA((pcsrthread)->Process)
  333. #define CONSOLE_PERPROCESSDATA() \
  334. CONSOLE_FROMTHREADPERPROCESSDATA(CSR_SERVER_QUERYCLIENTTHREAD())
  335. #define CONSOLE_GETCONSOLEAPP() (((PCONSOLE_PER_PROCESS_DATA)CONSOLE_PERPROCESSDATA())->ConsoleApp)
  336. #define CONSOLE_GETCONSOLEAPPFROMPROCESSDATA(PROCESSDATA) ((PROCESSDATA)->ConsoleApp)
  337. #define CONSOLE_SETCONSOLEAPP(VALUE) (((PCONSOLE_PER_PROCESS_DATA)CONSOLE_PERPROCESSDATA())->ConsoleApp = VALUE)
  338. #define CONSOLE_SETCONSOLEAPPFROMPROCESSDATA(PROCESSDATA,VALUE) ((PROCESSDATA)->ConsoleApp = VALUE)
  339. #define CONSOLE_GETCONSOLEHANDLE() (((PCONSOLE_PER_PROCESS_DATA)CONSOLE_PERPROCESSDATA())->ConsoleHandle)
  340. #define CONSOLE_SETCONSOLEHANDLE(VALUE) (((PCONSOLE_PER_PROCESS_DATA)CONSOLE_PERPROCESSDATA())->ConsoleHandle = VALUE)
  341. #define CONSOLE_GETCONSOLEHANDLEFROMPROCESSDATA(PROCESSDATA) ((PROCESSDATA)->ConsoleHandle)
  342. #define CONSOLE_SETCONSOLEHANDLEFROMPROCESSDATA(PROCESSDATA,VALUE) ((PROCESSDATA)->ConsoleHandle = VALUE)
  343. #endif
  344. //
  345. // registry information structure
  346. //
  347. typedef struct _CONSOLE_REGISTRY_INFO {
  348. COORD ScreenBufferSize;
  349. COORD WindowSize;
  350. COORD WindowOrigin;
  351. COORD FontSize;
  352. UINT FontFamily;
  353. UINT FontWeight;
  354. WCHAR FaceName[LF_FACESIZE];
  355. UINT CursorSize;
  356. BOOL FullScreen;
  357. BOOL QuickEdit;
  358. BOOL InsertMode;
  359. BOOL AutoPosition;
  360. CHAR_INFO ScreenFill;
  361. CHAR_INFO PopupFill;
  362. UINT HistoryBufferSize;
  363. UINT NumberOfHistoryBuffers;
  364. BOOL HistoryNoDup;
  365. COLORREF ColorTable[ 16 ];
  366. LONGLONG LastWriteTime;
  367. #if defined(FE_SB) // scotthsu
  368. DWORD CodePage;
  369. #endif
  370. } CONSOLE_REGISTRY_INFO, *PCONSOLE_REGISTRY_INFO;
  371. //
  372. // window class
  373. //
  374. #define CONSOLE_WINDOW_CLASS (L"ConsoleWindowClass")
  375. #define CONSOLE_MAX_APP_SHORTCUTS 1
  376. //
  377. // this structure is used to store relevant information from the
  378. // console for ctrl processing so we can do it without holding the
  379. // console lock.
  380. //
  381. typedef struct _CONSOLE_PROCESS_TERMINATION_RECORD {
  382. HANDLE ProcessHandle;
  383. ULONG TerminateCount;
  384. BOOL bDebugee;
  385. LPTHREAD_START_ROUTINE CtrlRoutine;
  386. } CONSOLE_PROCESS_TERMINATION_RECORD, *PCONSOLE_PROCESS_TERMINATION_RECORD;
  387. //
  388. // this value is used to determine the size of stack buffers for
  389. // strings. it should be long enough to contain the width of a
  390. // normal screen buffer.
  391. //
  392. #define STACK_BUFFER_SIZE 132
  393. //
  394. // link information
  395. //
  396. #define LINK_PROP_MAIN_SIG 0x00000001
  397. #define LINK_PROP_NT_CONSOLE_SIG 0x00000002
  398. #if 0 // no one currently uses this...
  399. typedef struct {
  400. WCHAR pszLinkName[ MAX_PATH ];
  401. WCHAR pszName[ MAX_PATH ];
  402. WCHAR pszRelPath[ MAX_PATH ];
  403. WCHAR pszWorkingDir[ MAX_PATH ];
  404. WCHAR pszArgs[ MAX_PATH ];
  405. WCHAR pszIconLocation[ MAX_PATH ];
  406. int iIcon;
  407. int iShowCmd;
  408. int wHotKey;
  409. } LNKPROPMAIN, * LPLNKPROPMAIN;
  410. #endif
  411. #ifndef _USERKDX_ /* debugging extensions */
  412. typedef struct {
  413. WCHAR pszName[ MAX_PATH ];
  414. WCHAR pszIconLocation[ MAX_PATH ];
  415. UINT uIcon;
  416. UINT uShowCmd;
  417. UINT uHotKey;
  418. NT_CONSOLE_PROPS console_props;
  419. #ifdef FE_SB
  420. NT_FE_CONSOLE_PROPS fe_console_props;
  421. #endif
  422. } LNKPROPNTCONSOLE, *LPLNKPROPNTCONSOLE;
  423. #endif
  424. #ifndef _USERKDX_ /* debugging extensions */
  425. typedef struct {
  426. LPWSTR pszCurFile; // current file from IPersistFile
  427. LPWSTR pszRelSource; // overrides pszCurFile in relative tracking
  428. LPWSTR pszName; // title on short volumes
  429. LPWSTR pszRelPath;
  430. LPWSTR pszWorkingDir;
  431. LPWSTR pszArgs;
  432. LPWSTR pszIconLocation;
  433. LPSTR pExtraData; // extra data to preserve for future compatibility
  434. SHELL_LINK_DATA sld;
  435. } CShellLink;
  436. #endif