ReactOS  0.4.15-dev-341-g17c5fb8
console.c File Reference
#include "consrv.h"
#include <shlobj.h>
#include <alias.h>
#include <history.h>
#include "procinit.h"
#include <debug.h>
Include dependency graph for console.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define NDEBUG
 
#define ConSrvLockConsoleListExclusive()   RtlAcquireResourceExclusive(&ListLock, TRUE)
 
#define ConSrvLockConsoleListShared()   RtlAcquireResourceShared(&ListLock, TRUE)
 
#define ConSrvUnlockConsoleList()   RtlReleaseResource(&ListLock)
 
#define CONSOLE_HANDLES_INCREMENT   2 * 3
 
#define PATH_SEPARATOR   L'\\'
 
#define CONSOLE_VALID_CONTROL_MODES
 

Functions

static NTSTATUS InsertConsole (OUT PHANDLE Handle, IN PCONSRV_CONSOLE Console)
 
static NTSTATUS RemoveConsoleByPointer (IN PCONSRV_CONSOLE Console)
 
static BOOLEAN ConsoleCreateUnicodeString (IN OUT PUNICODE_STRING UniDest, IN PCWSTR Source)
 
static VOID ConsoleFreeUnicodeString (IN PUNICODE_STRING UnicodeString)
 
BOOLEAN NTAPI ConSrvValidateConsole (OUT PCONSRV_CONSOLE *Console, IN HANDLE ConsoleHandle, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
 
NTSTATUS ConSrvGetConsole (IN PCONSOLE_PROCESS_DATA ProcessData, OUT PCONSRV_CONSOLE *Console, IN BOOLEAN LockConsole)
 
VOID ConSrvReleaseConsole (IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
 
VOID NTAPI ConSrvInitConsoleSupport (VOID)
 
NTSTATUS NTAPI ConSrvInitTerminal (IN OUT PTERMINAL Terminal, IN OUT PCONSOLE_STATE_INFO ConsoleInfo, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo, IN HANDLE ConsoleLeaderProcessHandle)
 
NTSTATUS NTAPI ConSrvDeinitTerminal (IN OUT PTERMINAL Terminal)
 
static BOOL LoadShellLinkConsoleInfo (IN OUT PCONSOLE_STATE_INFO ConsoleInfo, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo)
 
NTSTATUS NTAPI ConSrvInitConsole (OUT PHANDLE NewConsoleHandle, OUT PCONSRV_CONSOLE *NewConsole, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo, IN PCSR_PROCESS ConsoleLeaderProcess)
 
VOID NTAPI ConSrvDeleteConsole (PCONSRV_CONSOLE Console)
 
VOID ConioPause (PCONSRV_CONSOLE Console, UCHAR Flags)
 
VOID ConioUnpause (PCONSRV_CONSOLE Console, UCHAR Flags)
 
static NTSTATUS ConSrvInitProcessHandles (IN OUT PCONSOLE_PROCESS_DATA ProcessData, IN PCONSRV_CONSOLE Console, OUT PHANDLE pInputHandle, OUT PHANDLE pOutputHandle, OUT PHANDLE pErrorHandle)
 
NTSTATUS ConSrvAllocateConsole (IN OUT PCONSOLE_PROCESS_DATA ProcessData, OUT PHANDLE pInputHandle, OUT PHANDLE pOutputHandle, OUT PHANDLE pErrorHandle, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo)
 
NTSTATUS ConSrvInheritConsole (IN OUT PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE ConsoleHandle, IN BOOLEAN CreateNewHandleTable, OUT PHANDLE pInputHandle, OUT PHANDLE pOutputHandle, OUT PHANDLE pErrorHandle, IN OUT PCONSOLE_START_INFO ConsoleStartInfo)
 
NTSTATUS ConSrvRemoveConsole (IN OUT PCONSOLE_PROCESS_DATA ProcessData)
 
NTSTATUS ConSrvConsoleCtrlEventTimeout (IN ULONG CtrlEvent, IN PCONSOLE_PROCESS_DATA ProcessData, IN ULONG Timeout)
 
NTSTATUS ConSrvConsoleCtrlEvent (IN ULONG CtrlEvent, IN PCONSOLE_PROCESS_DATA ProcessData)
 
PCONSOLE_PROCESS_DATA NTAPI ConSrvGetConsoleLeaderProcess (IN PCONSRV_CONSOLE Console)
 
NTSTATUS NTAPI ConSrvGetConsoleProcessList (IN PCONSRV_CONSOLE Console, IN OUT PULONG ProcessIdsList, IN ULONG MaxIdListItems, OUT PULONG ProcessIdsTotal)
 
NTSTATUS NTAPI ConSrvConsoleProcessCtrlEvent (IN PCONSRV_CONSOLE Console, IN ULONG ProcessGroupId, IN ULONG CtrlEvent)
 
VOID ConSrvSetProcessFocus (IN PCSR_PROCESS CsrProcess, IN BOOLEAN SetForeground)
 
NTSTATUS NTAPI ConSrvSetConsoleProcessFocus (IN PCONSRV_CONSOLE Console, IN BOOLEAN SetForeground)
 
 CON_API_NOCONSOLE (SrvAllocConsole, CONSOLE_ALLOCCONSOLE, AllocConsoleRequest)
 
 CON_API_NOCONSOLE (SrvAttachConsole, CONSOLE_ATTACHCONSOLE, AttachConsoleRequest)
 
 CON_API_NOCONSOLE (SrvFreeConsole, CONSOLE_FREECONSOLE, FreeConsoleRequest)
 
NTSTATUS NTAPI ConDrvGetConsoleMode (IN PCONSOLE Console, IN PCONSOLE_IO_OBJECT Object, OUT PULONG ConsoleMode)
 
 CON_API (SrvGetConsoleMode, CONSOLE_GETSETCONSOLEMODE, ConsoleModeRequest)
 
NTSTATUS NTAPI ConDrvSetConsoleMode (IN PCONSOLE Console, IN PCONSOLE_IO_OBJECT Object, IN ULONG ConsoleMode)
 
 CON_API (SrvSetConsoleMode, CONSOLE_GETSETCONSOLEMODE, ConsoleModeRequest)
 
 CON_API (SrvGetConsoleTitle, CONSOLE_GETSETCONSOLETITLE, TitleRequest)
 
 CON_API (SrvSetConsoleTitle, CONSOLE_GETSETCONSOLETITLE, TitleRequest)
 
NTSTATUS NTAPI ConDrvGetConsoleCP (IN PCONSOLE Console, OUT PUINT CodePage, IN BOOLEAN OutputCP)
 
 CON_API (SrvGetConsoleCP, CONSOLE_GETINPUTOUTPUTCP, GetConsoleCPRequest)
 
NTSTATUS NTAPI ConDrvSetConsoleCP (IN PCONSOLE Console, IN UINT CodePage, IN BOOLEAN OutputCP)
 
 CON_API (SrvSetConsoleCP, CONSOLE_SETINPUTOUTPUTCP, SetConsoleCPRequest)
 
 CON_API (SrvGetConsoleProcessList, CONSOLE_GETPROCESSLIST, GetProcessListRequest)
 
 CON_API (SrvGenerateConsoleCtrlEvent, CONSOLE_GENERATECTRLEVENT, GenerateCtrlEventRequest)
 
 CON_API (SrvConsoleNotifyLastClose, CONSOLE_NOTIFYLASTCLOSE, NotifyLastCloseRequest)
 
 CON_API (SrvGetConsoleMouseInfo, CONSOLE_GETMOUSEINFO, GetMouseInfoRequest)
 
 CSR_API (SrvSetConsoleKeyShortcuts)
 
 CON_API (SrvGetConsoleKeyboardLayoutName, CONSOLE_GETKBDLAYOUTNAME, GetKbdLayoutNameRequest)
 
 CSR_API (SrvGetConsoleCharType)
 
 CSR_API (SrvSetConsoleLocalEUDC)
 
 CSR_API (SrvSetConsoleCursorMode)
 
 CSR_API (SrvGetConsoleCursorMode)
 
 CSR_API (SrvGetConsoleNlsMode)
 
 CSR_API (SrvSetConsoleNlsMode)
 
 CSR_API (SrvGetConsoleLangId)
 

Variables

static ULONG ConsoleListSize
 
static PCONSRV_CONSOLEConsoleList
 
static RTL_RESOURCE ListLock
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 16 of file console.c.

◆ CONSOLE_HANDLES_INCREMENT

#define CONSOLE_HANDLES_INCREMENT   2 * 3

◆ CONSOLE_VALID_CONTROL_MODES

#define CONSOLE_VALID_CONTROL_MODES
Value:
ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE )
#define ENABLE_EXTENDED_FLAGS
Definition: wincon.h:85
#define ENABLE_QUICK_EDIT_MODE
Definition: wincon.h:84

◆ ConSrvLockConsoleListExclusive

#define ConSrvLockConsoleListExclusive ( )    RtlAcquireResourceExclusive(&ListLock, TRUE)

Definition at line 38 of file console.c.

◆ ConSrvLockConsoleListShared

#define ConSrvLockConsoleListShared ( )    RtlAcquireResourceShared(&ListLock, TRUE)

Definition at line 41 of file console.c.

◆ ConSrvUnlockConsoleList

#define ConSrvUnlockConsoleList ( )    RtlReleaseResource(&ListLock)

Definition at line 44 of file console.c.

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file console.c.

◆ PATH_SEPARATOR

#define PATH_SEPARATOR   L'\\'

Function Documentation

◆ CON_API() [1/11]

CON_API ( SrvGetConsoleMode  ,
CONSOLE_GETSETCONSOLEMODE  ,
ConsoleModeRequest   
)

Definition at line 1660 of file console.c.

1662 {
1663  NTSTATUS Status;
1665  PULONG ConsoleMode = &ConsoleModeRequest->Mode;
1666 
1667  Status = ConSrvGetObject(ProcessData,
1668  ConsoleModeRequest->Handle,
1669  &Object, NULL, GENERIC_READ, TRUE, 0);
1670  if (!NT_SUCCESS(Status))
1671  return Status;
1672 
1673  ASSERT((PCONSOLE)Console == Object->Console);
1674 
1675  /* Get the standard console modes */
1677  if (NT_SUCCESS(Status))
1678  {
1679  /*
1680  * If getting the console modes succeeds, then retrieve
1681  * the extended CONSRV-specific input modes.
1682  */
1683  if (INPUT_BUFFER == Object->Type)
1684  {
1685  if (Console->InsertMode || Console->QuickEdit)
1686  {
1687  /* Windows also adds ENABLE_EXTENDED_FLAGS, even if it's not documented on MSDN */
1688  *ConsoleMode |= ENABLE_EXTENDED_FLAGS;
1689 
1690  if (Console->InsertMode) *ConsoleMode |= ENABLE_INSERT_MODE;
1691  if (Console->QuickEdit ) *ConsoleMode |= ENABLE_QUICK_EDIT_MODE;
1692  }
1693  }
1694  }
1695 
1697  return Status;
1698 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ConDrvGetConsoleMode(IN PCONSOLE Console, IN PCONSOLE_IO_OBJECT Object, OUT PULONG ConsoleMode)
Definition: console.c:323
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
NTSTATUS ConSrvGetObject(IN PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE Handle, OUT PCONSOLE_IO_OBJECT *Object, OUT PVOID *Entry OPTIONAL, IN ULONG Access, IN BOOLEAN LockConsole, IN CONSOLE_IO_OBJECT_TYPE Type)
Definition: handle.c:318
#define ENABLE_INSERT_MODE
Definition: wincon.h:83
#define ENABLE_EXTENDED_FLAGS
Definition: wincon.h:85
unsigned int * PULONG
Definition: retypes.h:1
CConsole Console
VOID ConSrvReleaseObject(IN PCONSOLE_IO_OBJECT Object, IN BOOLEAN IsConsoleLocked)
Definition: handle.c:382
#define ENABLE_QUICK_EDIT_MODE
Definition: wincon.h:84

◆ CON_API() [2/11]

CON_API ( SrvSetConsoleMode  ,
CONSOLE_GETSETCONSOLEMODE  ,
ConsoleModeRequest   
)

Definition at line 1705 of file console.c.

1707 {
1708 #define CONSOLE_VALID_CONTROL_MODES ( ENABLE_EXTENDED_FLAGS | \
1709  ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE )
1710 // NOTE: Vista+ ENABLE_AUTO_POSITION is also a control mode.
1711 
1712  NTSTATUS Status;
1714  ULONG ConsoleMode = ConsoleModeRequest->Mode;
1715 
1716  Status = ConSrvGetObject(ProcessData,
1717  ConsoleModeRequest->Handle,
1718  &Object, NULL, GENERIC_WRITE, TRUE, 0);
1719  if (!NT_SUCCESS(Status))
1720  return Status;
1721 
1722  ASSERT((PCONSOLE)Console == Object->Console);
1723 
1724  /* Set the standard console modes (without the CONSRV-specific input modes) */
1725  ConsoleMode &= ~CONSOLE_VALID_CONTROL_MODES; // Remove CONSRV-specific input modes.
1727  if (NT_SUCCESS(Status))
1728  {
1729  /*
1730  * If setting the console modes succeeds, then set
1731  * the extended CONSRV-specific input modes.
1732  */
1733  if (INPUT_BUFFER == Object->Type)
1734  {
1735  ConsoleMode = ConsoleModeRequest->Mode;
1736 
1737  if (ConsoleMode & CONSOLE_VALID_CONTROL_MODES)
1738  {
1739  /*
1740  * If we use control mode flags without ENABLE_EXTENDED_FLAGS,
1741  * then consider the flags invalid.
1742  */
1743  if ((ConsoleMode & ENABLE_EXTENDED_FLAGS) == 0)
1744  {
1746  }
1747  else
1748  {
1749  Console->InsertMode = !!(ConsoleMode & ENABLE_INSERT_MODE);
1750  Console->QuickEdit = !!(ConsoleMode & ENABLE_QUICK_EDIT_MODE);
1751  }
1752  }
1753  }
1754  }
1755 
1757  return Status;
1758 }
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ConDrvSetConsoleMode(IN PCONSOLE Console, IN PCONSOLE_IO_OBJECT Object, IN ULONG ConsoleMode)
Definition: console.c:356
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CONSOLE_VALID_CONTROL_MODES
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
NTSTATUS ConSrvGetObject(IN PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE Handle, OUT PCONSOLE_IO_OBJECT *Object, OUT PVOID *Entry OPTIONAL, IN ULONG Access, IN BOOLEAN LockConsole, IN CONSOLE_IO_OBJECT_TYPE Type)
Definition: handle.c:318
#define ENABLE_INSERT_MODE
Definition: wincon.h:83
#define ENABLE_EXTENDED_FLAGS
Definition: wincon.h:85
CConsole Console
VOID ConSrvReleaseObject(IN PCONSOLE_IO_OBJECT Object, IN BOOLEAN IsConsoleLocked)
Definition: handle.c:382
unsigned int ULONG
Definition: retypes.h:1
#define ENABLE_QUICK_EDIT_MODE
Definition: wincon.h:84

◆ CON_API() [3/11]

CON_API ( SrvGetConsoleTitle  ,
CONSOLE_GETSETCONSOLETITLE  ,
TitleRequest   
)

Definition at line 1761 of file console.c.

1763 {
1764  ULONG Length;
1765 
1766  if (!CsrValidateMessageBuffer(ApiMessage,
1767  (PVOID)&TitleRequest->Title,
1768  TitleRequest->Length,
1769  sizeof(BYTE)))
1770  {
1771  return STATUS_INVALID_PARAMETER;
1772  }
1773 
1774  /* Copy title of the console to the user title buffer */
1775  if (TitleRequest->Unicode)
1776  {
1777  if (TitleRequest->Length >= sizeof(WCHAR))
1778  {
1779  Length = min(TitleRequest->Length - sizeof(WCHAR), Console->Title.Length);
1780  RtlCopyMemory(TitleRequest->Title, Console->Title.Buffer, Length);
1781  ((PWCHAR)TitleRequest->Title)[Length / sizeof(WCHAR)] = UNICODE_NULL;
1782  TitleRequest->Length = Length;
1783  }
1784  else
1785  {
1786  TitleRequest->Length = Console->Title.Length;
1787  }
1788  }
1789  else
1790  {
1791  if (TitleRequest->Length >= sizeof(CHAR))
1792  {
1793  Length = min(TitleRequest->Length - sizeof(CHAR), Console->Title.Length / sizeof(WCHAR));
1794  Length = WideCharToMultiByte(Console->InputCodePage, 0,
1795  Console->Title.Buffer, Length,
1796  TitleRequest->Title, Length,
1797  NULL, NULL);
1798  ((PCHAR)TitleRequest->Title)[Length] = ANSI_NULL;
1799  TitleRequest->Length = Length;
1800  }
1801  else
1802  {
1803  TitleRequest->Length = Console->Title.Length / sizeof(WCHAR);
1804  }
1805  }
1806 
1807  return STATUS_SUCCESS;
1808 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define WideCharToMultiByte
Definition: compat.h:101
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
char CHAR
Definition: xmlstorage.h:175
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
uint16_t * PWCHAR
Definition: typedefs.h:55
#define UNICODE_NULL
#define ANSI_NULL
smooth NULL
Definition: ftsmooth.c:416
#define PCHAR
Definition: match.c:90
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char BYTE
Definition: xxhash.c:193
#define min(a, b)
Definition: monoChain.cc:55
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [4/11]

CON_API ( SrvSetConsoleTitle  ,
CONSOLE_GETSETCONSOLETITLE  ,
TitleRequest   
)

Definition at line 1811 of file console.c.

1813 {
1814  PWCHAR Buffer;
1815  ULONG Length;
1816 
1817  if (!CsrValidateMessageBuffer(ApiMessage,
1818  (PVOID)&TitleRequest->Title,
1819  TitleRequest->Length,
1820  sizeof(BYTE)))
1821  {
1822  return STATUS_INVALID_PARAMETER;
1823  }
1824 
1825  if (TitleRequest->Unicode)
1826  {
1827  /* Length is in bytes */
1828  Length = TitleRequest->Length;
1829  }
1830  else
1831  {
1832  /* Use the console input CP for the conversion */
1833  Length = MultiByteToWideChar(Console->InputCodePage, 0,
1834  TitleRequest->Title, TitleRequest->Length,
1835  NULL, 0);
1836  /* The returned Length was in number of wchars, convert it in bytes */
1837  Length *= sizeof(WCHAR);
1838  }
1839 
1840  /* Allocate a new buffer to hold the new title (NULL-terminated) */
1842  if (!Buffer)
1843  return STATUS_NO_MEMORY;
1844 
1845  /* Free the old title */
1847 
1848  /* Copy title to console */
1849  Console->Title.Buffer = Buffer;
1850  Console->Title.Length = Length;
1851  Console->Title.MaximumLength = Console->Title.Length + sizeof(WCHAR);
1852 
1853  if (TitleRequest->Unicode)
1854  {
1855  RtlCopyMemory(Console->Title.Buffer, TitleRequest->Title, Console->Title.Length);
1856  }
1857  else
1858  {
1859  MultiByteToWideChar(Console->InputCodePage, 0,
1860  TitleRequest->Title, TitleRequest->Length,
1861  Console->Title.Buffer,
1862  Console->Title.Length / sizeof(WCHAR));
1863  }
1864 
1865  /* NULL-terminate */
1866  Console->Title.Buffer[Console->Title.Length / sizeof(WCHAR)] = UNICODE_NULL;
1867 
1869 
1870  return STATUS_SUCCESS;
1871 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static VOID ConsoleFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
Definition: console.c:234
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
uint16_t * PWCHAR
Definition: typedefs.h:55
#define TermChangeTitle(Console)
Definition: term.h:46
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char BYTE
Definition: xxhash.c:193
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define MultiByteToWideChar
Definition: compat.h:100
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [5/11]

CON_API ( SrvGetConsoleCP  ,
CONSOLE_GETINPUTOUTPUTCP  ,
GetConsoleCPRequest   
)

Definition at line 1878 of file console.c.

1880 {
1881  DPRINT("SrvGetConsoleCP, getting %s Code Page\n",
1882  GetConsoleCPRequest->OutputCP ? "Output" : "Input");
1883 
1885  &GetConsoleCPRequest->CodePage,
1886  GetConsoleCPRequest->OutputCP);
1887 }
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI ConDrvGetConsoleCP(IN PCONSOLE Console, OUT PUINT CodePage, IN BOOLEAN OutputCP)
Definition: console.c:410
CConsole Console

◆ CON_API() [6/11]

CON_API ( SrvSetConsoleCP  ,
CONSOLE_SETINPUTOUTPUTCP  ,
SetConsoleCPRequest   
)

Definition at line 1894 of file console.c.

1896 {
1897  DPRINT("SrvSetConsoleCP, setting %s Code Page\n",
1898  SetConsoleCPRequest->OutputCP ? "Output" : "Input");
1899 
1901  SetConsoleCPRequest->CodePage,
1902  SetConsoleCPRequest->OutputCP);
1903 }
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI ConDrvSetConsoleCP(IN PCONSOLE Console, IN UINT CodePage, IN BOOLEAN OutputCP)
Definition: console.c:423
CConsole Console

◆ CON_API() [7/11]

CON_API ( SrvGetConsoleProcessList  ,
CONSOLE_GETPROCESSLIST  ,
GetProcessListRequest   
)

Definition at line 1906 of file console.c.

1908 {
1909  if (!CsrValidateMessageBuffer(ApiMessage,
1910  (PVOID)&GetProcessListRequest->ProcessIdsList,
1911  GetProcessListRequest->ProcessCount,
1912  sizeof(DWORD)))
1913  {
1914  return STATUS_INVALID_PARAMETER;
1915  }
1916 
1918  GetProcessListRequest->ProcessIdsList,
1919  GetProcessListRequest->ProcessCount,
1920  &GetProcessListRequest->ProcessCount);
1921 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
NTSTATUS NTAPI ConSrvGetConsoleProcessList(IN PCONSRV_CONSOLE Console, IN OUT PULONG ProcessIdsList, IN ULONG MaxIdListItems, OUT PULONG ProcessIdsTotal)
Definition: console.c:1373
unsigned long DWORD
Definition: ntddk_ex.h:95
CConsole Console

◆ CON_API() [8/11]

CON_API ( SrvGenerateConsoleCtrlEvent  ,
CONSOLE_GENERATECTRLEVENT  ,
GenerateCtrlEventRequest   
)

Definition at line 1924 of file console.c.

1926 {
1928  GenerateCtrlEventRequest->ProcessGroupId,
1929  GenerateCtrlEventRequest->CtrlEvent);
1930 }
NTSTATUS NTAPI ConSrvConsoleProcessCtrlEvent(IN PCONSRV_CONSOLE Console, IN ULONG ProcessGroupId, IN ULONG CtrlEvent)
Definition: console.c:1402
CConsole Console

◆ CON_API() [9/11]

CON_API ( SrvConsoleNotifyLastClose  ,
CONSOLE_NOTIFYLASTCLOSE  ,
NotifyLastCloseRequest   
)

Definition at line 1933 of file console.c.

1935 {
1936  /* Only one process is allowed to be registered for last close notification */
1937  if (Console->NotifyLastClose)
1938  return STATUS_ACCESS_DENIED;
1939 
1940  Console->NotifyLastClose = TRUE;
1941  Console->NotifiedLastCloseProcess = ProcessData;
1942  return STATUS_SUCCESS;
1943 }
#define TRUE
Definition: types.h:120
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [10/11]

CON_API ( SrvGetConsoleMouseInfo  ,
CONSOLE_GETMOUSEINFO  ,
GetMouseInfoRequest   
)

Definition at line 1946 of file console.c.

1948 {
1949  /* Just retrieve the number of buttons of the mouse attached to this console */
1950  GetMouseInfoRequest->NumButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);
1951  return STATUS_SUCCESS;
1952 }
#define SM_CMOUSEBUTTONS
Definition: winuser.h:996
int WINAPI GetSystemMetrics(_In_ int)
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API() [11/11]

CON_API ( SrvGetConsoleKeyboardLayoutName  ,
CONSOLE_GETKBDLAYOUTNAME  ,
GetKbdLayoutNameRequest   
)

Definition at line 1962 of file console.c.

1964 {
1965  /* Retrieve the keyboard layout name of the system */
1966  if (GetKbdLayoutNameRequest->Ansi)
1967  GetKeyboardLayoutNameA((PCHAR)GetKbdLayoutNameRequest->LayoutBuffer);
1968  else
1969  GetKeyboardLayoutNameW((PWCHAR)GetKbdLayoutNameRequest->LayoutBuffer);
1970 
1971  return STATUS_SUCCESS;
1972 }
signed char * PCHAR
Definition: retypes.h:7
BOOL WINAPI GetKeyboardLayoutNameW(_Out_writes_(KL_NAMELENGTH) LPWSTR)
BOOL WINAPI GetKeyboardLayoutNameA(_Out_writes_(KL_NAMELENGTH) LPSTR)
uint16_t * PWCHAR
Definition: typedefs.h:55
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API_NOCONSOLE() [1/3]

CON_API_NOCONSOLE ( SrvAllocConsole  ,
CONSOLE_ALLOCCONSOLE  ,
AllocConsoleRequest   
)

Definition at line 1483 of file console.c.

1485 {
1487  CONSOLE_INIT_INFO ConsoleInitInfo;
1488 
1489  if (ProcessData->ConsoleHandle != NULL)
1490  {
1491  DPRINT1("Process already has a console\n");
1492  return STATUS_ACCESS_DENIED;
1493  }
1494 
1495  if ( !CsrValidateMessageBuffer(ApiMessage,
1496  (PVOID*)&AllocConsoleRequest->ConsoleStartInfo,
1497  1,
1498  sizeof(CONSOLE_START_INFO)) ||
1499  !CsrValidateMessageBuffer(ApiMessage,
1500  (PVOID*)&AllocConsoleRequest->ConsoleTitle,
1501  AllocConsoleRequest->TitleLength,
1502  sizeof(BYTE)) ||
1503  !CsrValidateMessageBuffer(ApiMessage,
1504  (PVOID*)&AllocConsoleRequest->Desktop,
1505  AllocConsoleRequest->DesktopLength,
1506  sizeof(BYTE)) ||
1507  !CsrValidateMessageBuffer(ApiMessage,
1508  (PVOID*)&AllocConsoleRequest->CurDir,
1509  AllocConsoleRequest->CurDirLength,
1510  sizeof(BYTE)) ||
1511  !CsrValidateMessageBuffer(ApiMessage,
1512  (PVOID*)&AllocConsoleRequest->AppName,
1513  AllocConsoleRequest->AppNameLength,
1514  sizeof(BYTE)) )
1515  {
1516  return STATUS_INVALID_PARAMETER;
1517  }
1518 
1519  /* Initialize the console initialization info structure */
1520  ConsoleInitInfo.ConsoleStartInfo = AllocConsoleRequest->ConsoleStartInfo;
1521  ConsoleInitInfo.IsWindowVisible = TRUE; // The console window is always visible.
1522  ConsoleInitInfo.TitleLength = AllocConsoleRequest->TitleLength;
1523  ConsoleInitInfo.ConsoleTitle = AllocConsoleRequest->ConsoleTitle;
1524  ConsoleInitInfo.DesktopLength = AllocConsoleRequest->DesktopLength;
1525  ConsoleInitInfo.Desktop = AllocConsoleRequest->Desktop;
1526  ConsoleInitInfo.AppNameLength = AllocConsoleRequest->AppNameLength;
1527  ConsoleInitInfo.AppName = AllocConsoleRequest->AppName;
1528  ConsoleInitInfo.CurDirLength = AllocConsoleRequest->CurDirLength;
1529  ConsoleInitInfo.CurDir = AllocConsoleRequest->CurDir;
1530 
1531  /* Initialize a new Console owned by the Console Leader Process */
1532  Status = ConSrvAllocateConsole(ProcessData,
1533  &AllocConsoleRequest->ConsoleStartInfo->InputHandle,
1534  &AllocConsoleRequest->ConsoleStartInfo->OutputHandle,
1535  &AllocConsoleRequest->ConsoleStartInfo->ErrorHandle,
1536  &ConsoleInitInfo);
1537  if (!NT_SUCCESS(Status))
1538  {
1539  DPRINT1("Console allocation failed\n");
1540  return Status;
1541  }
1542 
1543  /* Set the Property-Dialog and Control-Dispatcher handlers */
1544  ProcessData->PropRoutine = AllocConsoleRequest->PropRoutine;
1545  ProcessData->CtrlRoutine = AllocConsoleRequest->CtrlRoutine;
1546 
1547  return STATUS_SUCCESS;
1548 }
PWCHAR Desktop
Definition: console.h:19
PCONSOLE_START_INFO ConsoleStartInfo
Definition: console.h:13
#define TRUE
Definition: types.h:120
ULONG CurDirLength
Definition: console.h:22
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
ULONG AppNameLength
Definition: console.h:20
PWCHAR AppName
Definition: console.h:21
ULONG TitleLength
Definition: console.h:16
smooth NULL
Definition: ftsmooth.c:416
PWCHAR ConsoleTitle
Definition: console.h:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
unsigned char BYTE
Definition: xxhash.c:193
ULONG DesktopLength
Definition: console.h:18
Status
Definition: gdiplustypes.h:24
BOOLEAN IsWindowVisible
Definition: console.h:14
#define DPRINT1
Definition: precomp.h:8
NTSTATUS ConSrvAllocateConsole(IN OUT PCONSOLE_PROCESS_DATA ProcessData, OUT PHANDLE pInputHandle, OUT PHANDLE pOutputHandle, OUT PHANDLE pErrorHandle, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo)
Definition: console.c:968
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CON_API_NOCONSOLE() [2/3]

CON_API_NOCONSOLE ( SrvAttachConsole  ,
CONSOLE_ATTACHCONSOLE  ,
AttachConsoleRequest   
)

Definition at line 1551 of file console.c.

1553 {
1555  PCSR_PROCESS SourceProcess = NULL; // The parent process.
1556  PCSR_PROCESS TargetProcess = CsrGetClientThread()->Process; // Ourselves.
1557  HANDLE ProcessId = ULongToHandle(AttachConsoleRequest->ProcessId);
1558  PCONSOLE_PROCESS_DATA SourceProcessData, TargetProcessData;
1559 
1560  TargetProcessData = ConsoleGetPerProcessData(TargetProcess);
1561 
1562  if (TargetProcessData->ConsoleHandle != NULL)
1563  {
1564  DPRINT1("Process already has a console\n");
1565  return STATUS_ACCESS_DENIED;
1566  }
1567 
1568  if (!CsrValidateMessageBuffer(ApiMessage,
1569  (PVOID*)&AttachConsoleRequest->ConsoleStartInfo,
1570  1,
1571  sizeof(CONSOLE_START_INFO)))
1572  {
1573  return STATUS_INVALID_PARAMETER;
1574  }
1575 
1576  /* Check whether we try to attach to the parent's console */
1578  {
1579  PROCESS_BASIC_INFORMATION ProcessInfo;
1580  ULONG Length = sizeof(ProcessInfo);
1581 
1582  /* Get the real parent's PID */
1583 
1586  &ProcessInfo,
1587  Length, &Length);
1588  if (!NT_SUCCESS(Status))
1589  {
1590  DPRINT1("SrvAttachConsole - Cannot retrieve basic process info, Status = 0x%08lx\n", Status);
1591  return Status;
1592  }
1593 
1595  }
1596 
1597  /* Lock the source process via its PID */
1598  Status = CsrLockProcessByClientId(ProcessId, &SourceProcess);
1599  if (!NT_SUCCESS(Status)) return Status;
1600 
1601  SourceProcessData = ConsoleGetPerProcessData(SourceProcess);
1602 
1603  if (SourceProcessData->ConsoleHandle == NULL)
1604  {
1606  goto Quit;
1607  }
1608 
1609  /*
1610  * Inherit the console from the parent,
1611  * if any, otherwise return an error.
1612  */
1613  Status = ConSrvInheritConsole(TargetProcessData,
1614  SourceProcessData->ConsoleHandle,
1615  TRUE,
1616  &AttachConsoleRequest->ConsoleStartInfo->InputHandle,
1617  &AttachConsoleRequest->ConsoleStartInfo->OutputHandle,
1618  &AttachConsoleRequest->ConsoleStartInfo->ErrorHandle,
1619  AttachConsoleRequest->ConsoleStartInfo);
1620  if (!NT_SUCCESS(Status))
1621  {
1622  DPRINT1("Console inheritance failed\n");
1623  goto Quit;
1624  }
1625 
1626  /* Set the Property-Dialog and Control-Dispatcher handlers */
1627  TargetProcessData->PropRoutine = AttachConsoleRequest->PropRoutine;
1628  TargetProcessData->CtrlRoutine = AttachConsoleRequest->CtrlRoutine;
1629 
1631 
1632 Quit:
1633  /* Unlock the "source" process and exit */
1634  CsrUnlockProcess(SourceProcess);
1635  return Status;
1636 }
HANDLE ConsoleHandle
Definition: consrv.h:45
#define ULongToHandle(h)
Definition: basetsd.h:81
#define CsrGetClientThread()
Definition: csrsrv.h:77
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LPTHREAD_START_ROUTINE CtrlRoutine
Definition: consrv.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
HANDLE ProcessHandle
Definition: csrsrv.h:46
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL)
ULONG_PTR InheritedFromUniqueProcessId
Definition: pstypes.h:340
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ConsoleGetPerProcessData(Process)
Definition: consrv.h:37
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
LPTHREAD_START_ROUTINE PropRoutine
Definition: consrv.h:53
Status
Definition: gdiplustypes.h:24
#define ATTACH_PARENT_PROCESS
Definition: wincon.h:21
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS ConSrvInheritConsole(IN OUT PCONSOLE_PROCESS_DATA ProcessData, IN HANDLE ConsoleHandle, IN BOOLEAN CreateNewHandleTable, OUT PHANDLE pInputHandle, OUT PHANDLE pOutputHandle, OUT PHANDLE pErrorHandle, IN OUT PCONSOLE_START_INFO ConsoleStartInfo)
Definition: console.c:1096
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1409

◆ CON_API_NOCONSOLE() [3/3]

CON_API_NOCONSOLE ( SrvFreeConsole  ,
CONSOLE_FREECONSOLE  ,
FreeConsoleRequest   
)

Definition at line 1639 of file console.c.

1641 {
1642  /*
1643  * If this process doesn't have a console handle, bail out immediately.
1644  * Also the passed console handle should be the same as the process' one.
1645  */
1646  if ((FreeConsoleRequest->ConsoleHandle == NULL) ||
1647  (FreeConsoleRequest->ConsoleHandle != ProcessData->ConsoleHandle))
1648  {
1649  return STATUS_INVALID_HANDLE; // STATUS_ACCESS_DENIED;
1650  }
1651 
1652  return ConSrvRemoveConsole(ProcessData);
1653 }
NTSTATUS ConSrvRemoveConsole(IN OUT PCONSOLE_PROCESS_DATA ProcessData)
Definition: console.c:1227
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
smooth NULL
Definition: ftsmooth.c:416

◆ ConDrvGetConsoleCP()

NTSTATUS NTAPI ConDrvGetConsoleCP ( IN PCONSOLE  Console,
OUT PUINT  CodePage,
IN BOOLEAN  OutputCP 
)

Definition at line 410 of file console.c.

413 {
414  if (Console == NULL || CodePage == NULL)
416 
417  *CodePage = (OutputCP ? Console->OutputCodePage : Console->InputCodePage);
418 
419  return STATUS_SUCCESS;
420 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConDrvGetConsoleMode()

NTSTATUS NTAPI ConDrvGetConsoleMode ( IN PCONSOLE  Console,
IN PCONSOLE_IO_OBJECT  Object,
OUT PULONG  ConsoleMode 
)

Definition at line 323 of file console.c.

326 {
328 
329  if (Console == NULL || Object == NULL || ConsoleMode == NULL)
331 
332  /* Validity check */
333  ASSERT(Console == Object->Console);
334 
335  /*** FIXME: */ *ConsoleMode = 0; /***/
336 
337  if (INPUT_BUFFER == Object->Type)
338  {
340  *ConsoleMode = InputBuffer->Mode;
341  }
342  else if (TEXTMODE_BUFFER == Object->Type || GRAPHICS_BUFFER == Object->Type)
343  {
345  *ConsoleMode = Buffer->Mode;
346  }
347  else
348  {
350  }
351 
352  return Status;
353 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
CHAR InputBuffer[80]
Definition: conmgr.c:33
struct _CONSOLE_INPUT_BUFFER * PCONSOLE_INPUT_BUFFER
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConDrvSetConsoleCP()

NTSTATUS NTAPI ConDrvSetConsoleCP ( IN PCONSOLE  Console,
IN UINT  CodePage,
IN BOOLEAN  OutputCP 
)

Definition at line 423 of file console.c.

426 {
427  if (Console == NULL || !IsValidCodePage(CodePage))
429 
430  if (OutputCP)
431  {
432  Console->OutputCodePage = CodePage;
433  Console->IsCJK = IsCJKCodePage(CodePage);
434  }
435  else
436  {
437  Console->InputCodePage = CodePage;
438  }
439 
440  return STATUS_SUCCESS;
441 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define IsCJKCodePage(CodePage)
Definition: font.h:23
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI IsValidCodePage(UINT CodePage)
Definition: nls.c:1479
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConDrvSetConsoleMode()

NTSTATUS NTAPI ConDrvSetConsoleMode ( IN PCONSOLE  Console,
IN PCONSOLE_IO_OBJECT  Object,
IN ULONG  ConsoleMode 
)

Definition at line 356 of file console.c.

359 {
360 #define CONSOLE_VALID_INPUT_MODES ( ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | \
361  ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT | \
362  ENABLE_MOUSE_INPUT )
363 #define CONSOLE_VALID_OUTPUT_MODES ( ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT )
364 
366 
367  if (Console == NULL || Object == NULL)
369 
370  /* Validity check */
371  ASSERT(Console == Object->Console);
372 
373  if (INPUT_BUFFER == Object->Type)
374  {
376 
377  /* Only the presence of valid mode flags is allowed */
378  if (ConsoleMode & ~CONSOLE_VALID_INPUT_MODES)
379  {
381  }
382  else
383  {
384  InputBuffer->Mode = (ConsoleMode & CONSOLE_VALID_INPUT_MODES);
385  }
386  }
387  else if (TEXTMODE_BUFFER == Object->Type || GRAPHICS_BUFFER == Object->Type)
388  {
390 
391  /* Only the presence of valid mode flags is allowed */
392  if (ConsoleMode & ~CONSOLE_VALID_OUTPUT_MODES)
393  {
395  }
396  else
397  {
398  Buffer->Mode = (ConsoleMode & CONSOLE_VALID_OUTPUT_MODES);
399  }
400  }
401  else
402  {
404  }
405 
406  return Status;
407 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
CHAR InputBuffer[80]
Definition: conmgr.c:33
struct _CONSOLE_INPUT_BUFFER * PCONSOLE_INPUT_BUFFER
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define CONSOLE_VALID_INPUT_MODES
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
CConsole Console
#define CONSOLE_VALID_OUTPUT_MODES
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConioPause()

VOID ConioPause ( PCONSRV_CONSOLE  Console,
UCHAR  Flags 
)

Definition at line 859 of file console.c.

860 {
861  Console->PauseFlags |= Flags;
863 }
VOID NTAPI ConDrvPause(PCONSOLE Console)
Definition: console.c:303
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
CConsole Console

Referenced by OnScroll(), PreprocessInput(), and UpdateSelection().

◆ ConioUnpause()

VOID ConioUnpause ( PCONSRV_CONSOLE  Console,
UCHAR  Flags 
)

Definition at line 866 of file console.c.

867 {
868  Console->PauseFlags &= ~Flags;
869 
870  // if ((Console->PauseFlags & (PAUSED_FROM_KEYBOARD | PAUSED_FROM_SCROLLBAR | PAUSED_FROM_SELECTION)) == 0)
871  if (Console->PauseFlags == 0)
872  {
874 
875  CsrNotifyWait(&Console->WriteWaitQueue,
876  TRUE,
877  NULL,
878  NULL);
879  if (!IsListEmpty(&Console->WriteWaitQueue))
880  {
881  CsrDereferenceWait(&Console->WriteWaitQueue);
882  }
883  }
884 }
#define TRUE
Definition: types.h:120
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
BOOLEAN NTAPI CsrNotifyWait(IN PLIST_ENTRY WaitList, IN BOOLEAN NotifyAll, IN PVOID WaitArgument1, IN PVOID WaitArgument2)
Definition: wait.c:388
VOID NTAPI ConDrvUnpause(PCONSOLE Console)
Definition: console.c:313
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CsrDereferenceWait(IN PLIST_ENTRY WaitList)
Definition: wait.c:266
CConsole Console

Referenced by OnScroll(), PreprocessInput(), and UpdateSelection().

◆ ConsoleCreateUnicodeString()

static BOOLEAN ConsoleCreateUnicodeString ( IN OUT PUNICODE_STRING  UniDest,
IN PCWSTR  Source 
)
static

Definition at line 216 of file console.c.

218 {
219  SIZE_T Size = (wcslen(Source) + 1) * sizeof(WCHAR);
220  if (Size > MAXUSHORT) return FALSE;
221 
222  UniDest->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Size);
223  if (UniDest->Buffer == NULL) return FALSE;
224 
225  RtlCopyMemory(UniDest->Buffer, Source, Size);
226  UniDest->MaximumLength = (USHORT)Size;
227  UniDest->Length = (USHORT)Size - sizeof(WCHAR);
228 
229  return TRUE;
230 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned short USHORT
Definition: pedump.c:61
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define MAXUSHORT
Definition: typedefs.h:82
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by ConSrvInitConsole().

◆ ConsoleFreeUnicodeString()

static VOID ConsoleFreeUnicodeString ( IN PUNICODE_STRING  UnicodeString)
static

Definition at line 234 of file console.c.

235 {
236  if (UnicodeString->Buffer)
237  {
240  }
241 }
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by CON_API(), and ConSrvDeleteConsole().

◆ ConSrvAllocateConsole()

NTSTATUS ConSrvAllocateConsole ( IN OUT PCONSOLE_PROCESS_DATA  ProcessData,
OUT PHANDLE  pInputHandle,
OUT PHANDLE  pOutputHandle,
OUT PHANDLE  pErrorHandle,
IN OUT PCONSOLE_INIT_INFO  ConsoleInitInfo 
)

Definition at line 968 of file console.c.

974 {
976  HANDLE ConsoleHandle;
978 
979  /*
980  * We are about to create a new console. However when ConSrvNewProcess()
981  * was called, we didn't know that we wanted to create a new console and
982  * therefore, we by default inherited the handle table from our parent
983  * process. It's only now that we notice that in fact we do not need
984  * them, because we've created a new console and thus we must use it.
985  *
986  * Therefore, free the handle table so that we can recreate
987  * a new one later on.
988  */
989  ConSrvFreeHandlesTable(ProcessData);
990 
991  /* Initialize a new Console owned by this process */
992  Status = ConSrvInitConsole(&ConsoleHandle,
993  &Console,
994  ConsoleInitInfo,
995  ProcessData->Process);
996  if (!NT_SUCCESS(Status))
997  {
998  DPRINT1("Console initialization failed\n");
999  return Status;
1000  }
1001 
1002  /* Assign the new console handle */
1003  ProcessData->ConsoleHandle = ConsoleHandle;
1004 
1005  /* Initialize the process handles */
1006  Status = ConSrvInitProcessHandles(ProcessData,
1007  Console,
1008  pInputHandle,
1009  pOutputHandle,
1010  pErrorHandle);
1011  if (!NT_SUCCESS(Status))
1012  {
1013  DPRINT1("Failed to initialize the process handles\n");
1015  ProcessData->ConsoleHandle = NULL;
1016  return Status;
1017  }
1018 
1019  /* Duplicate the Initialization Events */
1021  Console->InitEvents[INIT_SUCCESS],
1022  ProcessData->Process->ProcessHandle,
1023  &ConsoleInitInfo->ConsoleStartInfo->InitEvents[INIT_SUCCESS],
1024  EVENT_ALL_ACCESS, 0, 0);
1025  if (!NT_SUCCESS(Status))
1026  {
1027  DPRINT1("NtDuplicateObject(InitEvents[INIT_SUCCESS]) failed: %lu\n", Status);
1028  ConSrvFreeHandlesTable(ProcessData);
1030  ProcessData->ConsoleHandle = NULL;
1031  return Status;
1032  }
1033 
1035  Console->InitEvents[INIT_FAILURE],
1036  ProcessData->Process->ProcessHandle,
1037  &ConsoleInitInfo->ConsoleStartInfo->InitEvents[INIT_FAILURE],
1038  EVENT_ALL_ACCESS, 0, 0);
1039  if (!NT_SUCCESS(Status))
1040  {
1041  DPRINT1("NtDuplicateObject(InitEvents[INIT_FAILURE]) failed: %lu\n", Status);
1042  NtDuplicateObject(ProcessData->Process->ProcessHandle,
1043  ConsoleInitInfo->ConsoleStartInfo->InitEvents[INIT_SUCCESS],
1044  NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1045  ConSrvFreeHandlesTable(ProcessData);
1047  ProcessData->ConsoleHandle = NULL;
1048  return Status;
1049  }
1050 
1051  /* Duplicate the Input Event */
1053  Console->InputBuffer.ActiveEvent,
1054  ProcessData->Process->ProcessHandle,
1055  &ConsoleInitInfo->ConsoleStartInfo->InputWaitHandle,
1056  EVENT_ALL_ACCESS, 0, 0);
1057  if (!NT_SUCCESS(Status))
1058  {
1059  DPRINT1("NtDuplicateObject(InputWaitHandle) failed: %lu\n", Status);
1060  NtDuplicateObject(ProcessData->Process->ProcessHandle,
1061  ConsoleInitInfo->ConsoleStartInfo->InitEvents[INIT_FAILURE],
1062  NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1063  NtDuplicateObject(ProcessData->Process->ProcessHandle,
1064  ConsoleInitInfo->ConsoleStartInfo->InitEvents[INIT_SUCCESS],
1065  NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1066  ConSrvFreeHandlesTable(ProcessData);
1068  ProcessData->ConsoleHandle = NULL;
1069  return Status;
1070  }
1071 
1072  /* Mark the process as having a console */
1073  ProcessData->ConsoleApp = TRUE;
1074  ProcessData->Process->Flags |= CsrProcessIsConsoleApp;
1075 
1076  /* Return the console handle to the caller */
1077  ConsoleInitInfo->ConsoleStartInfo->ConsoleHandle = ProcessData->ConsoleHandle;
1078 
1079  /*
1080  * Insert the process into the processes list of the console,
1081  * and set its foreground priority.
1082  */
1083  InsertHeadList(&Console->ProcessList, &ProcessData->ConsoleLink);
1084  ConSrvSetProcessFocus(ProcessData->Process, Console->HasFocus);
1085 
1086  /* Add a reference count because the process is tied to the console */
1087  _InterlockedIncrement(&Console->ReferenceCount);
1088 
1089  /* Update the internal info of the terminal */
1091 
1092  return STATUS_SUCCESS;
1093 }
#define DUPLICATE_CLOSE_SOURCE
#define TRUE
Definition: types.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
VOID ConSrvFreeHandlesTable(IN PCONSOLE_PROCESS_DATA ProcessData)
Definition: handle.c:172
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI ConSrvInitConsole(OUT PHANDLE NewConsoleHandle, OUT PCONSRV_CONSOLE *NewConsole, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo, IN PCSR_PROCESS ConsoleLeaderProcess)
Definition: console.c:532
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
static NTSTATUS ConSrvInitProcessHandles(IN OUT PCONSOLE_PROCESS_DATA ProcessData, IN PCONSRV_CONSOLE Console, OUT PHANDLE pInputHandle, OUT PHANDLE pOutputHandle, OUT PHANDLE pErrorHandle)
Definition: console.c:890
VOID NTAPI ConSrvDeleteConsole(PCONSRV_CONSOLE Console)
Definition: console.c:822
CConsole Console
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3407
#define TermRefreshInternalInfo(Console)
Definition: term.h:44
return STATUS_SUCCESS
Definition: btrfs.c:3014
VOID ConSrvSetProcessFocus(IN PCSR_PROCESS CsrProcess, IN BOOLEAN SetForeground)
Definition: console.c:1440

Referenced by CON_API_NOCONSOLE(), and ConSrvConnect().

◆ ConSrvConsoleCtrlEvent()

NTSTATUS ConSrvConsoleCtrlEvent ( IN ULONG  CtrlEvent,
IN PCONSOLE_PROCESS_DATA  ProcessData 
)

Definition at line 1356 of file console.c.

1358 {
1359  return ConSrvConsoleCtrlEventTimeout(CtrlEvent, ProcessData, 0);
1360 }
NTSTATUS ConSrvConsoleCtrlEventTimeout(IN ULONG CtrlEvent, IN PCONSOLE_PROCESS_DATA ProcessData, IN ULONG Timeout)
Definition: console.c:1305

Referenced by ConSrvConsoleProcessCtrlEvent(), and ConSrvRemoveConsole().

◆ ConSrvConsoleCtrlEventTimeout()

NTSTATUS ConSrvConsoleCtrlEventTimeout ( IN ULONG  CtrlEvent,
IN PCONSOLE_PROCESS_DATA  ProcessData,
IN ULONG  Timeout 
)

Definition at line 1305 of file console.c.

1308 {
1310 
1311  DPRINT("ConSrvConsoleCtrlEventTimeout Parent ProcessId = %x\n", ProcessData->Process->ClientId.UniqueProcess);
1312 
1313  /*
1314  * Be sure we effectively have a control routine. It resides in kernel32.dll (client).
1315  */
1316  if (ProcessData->CtrlRoutine == NULL) return Status;
1317 
1318  _SEH2_TRY
1319  {
1320  HANDLE Thread = NULL;
1321 
1322  _SEH2_TRY
1323  {
1324  Thread = CreateRemoteThread(ProcessData->Process->ProcessHandle, NULL, 0,
1325  ProcessData->CtrlRoutine,
1326  UlongToPtr(CtrlEvent), 0, NULL);
1327  if (NULL == Thread)
1328  {
1330  DPRINT1("Failed thread creation, Status = 0x%08lx\n", Status);
1331  }
1332  else
1333  {
1334  DPRINT("ProcessData->CtrlRoutine remote thread creation succeeded, ProcessId = %x, Process = 0x%p\n",
1335  ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
1337  }
1338  }
1340  {
1342  }
1343  _SEH2_END;
1344  }
1346  {
1348  DPRINT1("ConSrvConsoleCtrlEventTimeout - Caught an exception, Status = 0x%08lx\n", Status);
1349  }
1350  _SEH2_END;
1351 
1352  return Status;
1353 }
#define CloseHandle
Definition: compat.h:407
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_TRY
Definition: create.c:4250
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define UlongToPtr(u)
Definition: config.h:106
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
NTSYSAPI NTSTATUS WINAPI RtlGetLastNtStatus(void)
Definition: error.c:114
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
static ULONG Timeout
Definition: ping.c:61
_SEH2_FINALLY
Definition: create.c:4395
#define DPRINT1
Definition: precomp.h:8
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:3014
HANDLE WINAPI CreateRemoteThread(IN HANDLE hProcess, IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:158

Referenced by ConSrvConsoleCtrlEvent(), and NotifyConsoleProcessForShutdown().

◆ ConSrvConsoleProcessCtrlEvent()

NTSTATUS NTAPI ConSrvConsoleProcessCtrlEvent ( IN PCONSRV_CONSOLE  Console,
IN ULONG  ProcessGroupId,
IN ULONG  CtrlEvent 
)

Definition at line 1402 of file console.c.

1405 {
1407  PLIST_ENTRY current_entry;
1409 
1410  /* If the console is already being destroyed, just return */
1412  return STATUS_UNSUCCESSFUL;
1413 
1414  /*
1415  * Loop through the process list, from the most recent process
1416  * (the active one) to the oldest one (the first created, i.e.
1417  * the console leader process), and for each, send an event
1418  * (new processes are inserted at the head of the console process list).
1419  */
1420  current_entry = Console->ProcessList.Flink;
1421  while (current_entry != &Console->ProcessList)
1422  {
1423  current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
1424  current_entry = current_entry->Flink;
1425 
1426  /*
1427  * Only processes belonging to the same process group are signaled.
1428  * If the process group ID is zero, then all the processes are signaled.
1429  */
1430  if (ProcessGroupId == 0 || current->Process->ProcessGroupId == ProcessGroupId)
1431  {
1432  Status = ConSrvConsoleCtrlEvent(CtrlEvent, current);
1433  }
1434  }
1435 
1436  return Status;
1437 }
BOOLEAN NTAPI ConDrvValidateConsoleState(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
Definition: console.c:24
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent, IN PCONSOLE_PROCESS_DATA ProcessData)
Definition: console.c:1356
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: typedefs.h:118
Status
Definition: gdiplustypes.h:24
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014
struct task_struct * current
Definition: linux.c:32

Referenced by CON_API(), ConioProcessInputEvent(), and OnClose().

◆ ConSrvDeinitTerminal()

NTSTATUS NTAPI ConSrvDeinitTerminal ( IN OUT PTERMINAL  Terminal)

Definition at line 237 of file terminal.c.

238 {
240  PFRONTEND FrontEnd = Terminal->Context;
241 
242  /* Reset the ConSrv terminal */
243  Terminal->Context = NULL;
244  Terminal->Vtbl = NULL;
245 
246  /* Unload the frontend */
247  if (FrontEnd != NULL)
248  {
249  Status = ConSrvUnloadFrontEnd(FrontEnd);
250  ConsoleFreeHeap(FrontEnd);
251  }
252 
253  return Status;
254 }
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS ConSrvUnloadFrontEnd(IN PFRONTEND FrontEnd)
Definition: terminal.c:193
smooth NULL
Definition: ftsmooth.c:416
PVOID Context
Definition: conio_winsrv.h:102
Status
Definition: gdiplustypes.h:24
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConSrvInitConsole().

◆ ConSrvDeleteConsole()

VOID NTAPI ConSrvDeleteConsole ( PCONSRV_CONSOLE  Console)

Definition at line 822 of file console.c.

823 {
824  DPRINT("ConSrvDeleteConsole\n");
825 
826  // FIXME: Send a terminate message to all the processes owning this console.
827  // NOTE: In principle there should be none, because such processes would
828  // have a reference to the console and thus this function would not have
829  // been called in the first place.
830 
831  /* Remove the console from the list */
833 
834  /* Destroy the Initialization Events */
835  NtClose(Console->InitEvents[INIT_FAILURE]);
836  NtClose(Console->InitEvents[INIT_SUCCESS]);
837 
838  /* Clean the Input Line Discipline */
839  if (Console->LineBuffer) ConsoleFreeHeap(Console->LineBuffer);
840 
841  /* Clean aliases and history */
844 
845  /* Free the console title */
846  ConsoleFreeUnicodeString(&Console->OriginalTitle);
848 
849  /* Now, call the driver. ConDrvDetachTerminal is called on-demand. */
851 
852  /* Deinit the ConSrv terminal */
853  // FIXME!!
854  // ConSrvDeinitTerminal(&Terminal);
855 }
VOID IntDeleteAllAliases(PCONSRV_CONSOLE Console)
Definition: alias.c:428
VOID HistoryDeleteBuffers(PCONSRV_CONSOLE Console)
Definition: history.c:357
static VOID ConsoleFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
Definition: console.c:234
static NTSTATUS RemoveConsoleByPointer(IN PCONSRV_CONSOLE Console)
Definition: console.c:168
VOID NTAPI ConDrvDeleteConsole(IN PCONSOLE Console)
Definition: console.c:217
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15

Referenced by ConSrvAllocateConsole(), and ConSrvReleaseConsole().

◆ ConSrvGetConsole()

NTSTATUS ConSrvGetConsole ( IN PCONSOLE_PROCESS_DATA  ProcessData,
OUT PCONSRV_CONSOLE Console,
IN BOOLEAN  LockConsole 
)

Definition at line 291 of file console.c.

294 {
296  PCONSRV_CONSOLE GrabConsole;
297 
298  // if (Console == NULL) return STATUS_INVALID_PARAMETER;
299  ASSERT(Console);
300  *Console = NULL;
301 
302  if (ConSrvValidateConsole(&GrabConsole,
303  ProcessData->ConsoleHandle,
305  LockConsole))
306  {
307  _InterlockedIncrement(&GrabConsole->ReferenceCount);
308  *Console = GrabConsole;
310  }
311 
312  return Status;
313 }
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN NTAPI ConSrvValidateConsole(OUT PCONSRV_CONSOLE *Console, IN HANDLE ConsoleHandle, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:247
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API_NOCONSOLE(), and GetThreadConsoleDesktop().

◆ ConSrvGetConsoleLeaderProcess()

PCONSOLE_PROCESS_DATA NTAPI ConSrvGetConsoleLeaderProcess ( IN PCONSRV_CONSOLE  Console)

Definition at line 1363 of file console.c.

1364 {
1365  if (Console == NULL) return NULL;
1366 
1367  return CONTAINING_RECORD(Console->ProcessList.Blink,
1369  ConsoleLink);
1370 }
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
CConsole Console

Referenced by ConSrvRemoveConsole(), GuiApplyUserSettings(), GuiConsoleShowConsoleProperties(), and SetConWndConsoleLeaderCID().

◆ ConSrvGetConsoleProcessList()

NTSTATUS NTAPI ConSrvGetConsoleProcessList ( IN PCONSRV_CONSOLE  Console,
IN OUT PULONG  ProcessIdsList,
IN ULONG  MaxIdListItems,
OUT PULONG  ProcessIdsTotal 
)

Definition at line 1373 of file console.c.

1377 {
1379  PLIST_ENTRY current_entry;
1380 
1381  if (Console == NULL || ProcessIdsList == NULL || ProcessIdsTotal == NULL)
1382  return STATUS_INVALID_PARAMETER;
1383 
1384  *ProcessIdsTotal = 0;
1385 
1386  for (current_entry = Console->ProcessList.Flink;
1387  current_entry != &Console->ProcessList;
1388  current_entry = current_entry->Flink)
1389  {
1390  current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
1391  if (++(*ProcessIdsTotal) <= MaxIdListItems)
1392  {
1393  *ProcessIdsList++ = HandleToUlong(current->Process->ClientId.UniqueProcess);
1394  }
1395  }
1396 
1397  return STATUS_SUCCESS;
1398 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define HandleToUlong(h)
Definition: basetsd.h:79
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
Definition: typedefs.h:118
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014
struct task_struct * current
Definition: linux.c:32

Referenced by CON_API().

◆ ConSrvInheritConsole()

NTSTATUS ConSrvInheritConsole ( IN OUT PCONSOLE_PROCESS_DATA  ProcessData,
IN HANDLE  ConsoleHandle,
IN BOOLEAN  CreateNewHandleTable,
OUT PHANDLE  pInputHandle,
OUT PHANDLE  pOutputHandle,
OUT PHANDLE  pErrorHandle,
IN OUT PCONSOLE_START_INFO  ConsoleStartInfo 
)

Definition at line 1096 of file console.c.

1104 {
1107 
1108  /* Validate and lock the console */
1110  ConsoleHandle,
1112  {
1113  // FIXME: Find another status code
1114  return STATUS_UNSUCCESSFUL;
1115  }
1116 
1117  /* Inherit the console */
1118  ProcessData->ConsoleHandle = ConsoleHandle;
1119 
1120  if (CreateNewHandleTable)
1121  {
1122  /*
1123  * We are about to create a new console. However when ConSrvNewProcess()
1124  * was called, we didn't know that we wanted to create a new console and
1125  * therefore, we by default inherited the handle table from our parent
1126  * process. It's only now that we notice that in fact we do not need
1127  * them, because we've created a new console and thus we must use it.
1128  *
1129  * Therefore, free the handle table so that we can recreate
1130  * a new one later on.
1131  */
1132  ConSrvFreeHandlesTable(ProcessData);
1133 
1134  /* Initialize the process handles */
1135  Status = ConSrvInitProcessHandles(ProcessData,
1136  Console,
1137  pInputHandle,
1138  pOutputHandle,
1139  pErrorHandle);
1140  if (!NT_SUCCESS(Status))
1141  {
1142  DPRINT1("Failed to initialize the process handles\n");
1143  ProcessData->ConsoleHandle = NULL;
1144  goto Quit;
1145  }
1146  }
1147 
1148  /* Duplicate the Initialization Events */
1150  Console->InitEvents[INIT_SUCCESS],
1151  ProcessData->Process->ProcessHandle,
1152  &ConsoleStartInfo->InitEvents[INIT_SUCCESS],
1153  EVENT_ALL_ACCESS, 0, 0);
1154  if (!NT_SUCCESS(Status))
1155  {
1156  DPRINT1("NtDuplicateObject(InitEvents[INIT_SUCCESS]) failed: %lu\n", Status);
1157  ConSrvFreeHandlesTable(ProcessData);
1158  ProcessData->ConsoleHandle = NULL;
1159  goto Quit;
1160  }
1161 
1163  Console->InitEvents[INIT_FAILURE],
1164  ProcessData->Process->ProcessHandle,
1165  &ConsoleStartInfo->InitEvents[INIT_FAILURE],
1166  EVENT_ALL_ACCESS, 0, 0);
1167  if (!NT_SUCCESS(Status))
1168  {
1169  DPRINT1("NtDuplicateObject(InitEvents[INIT_FAILURE]) failed: %lu\n", Status);
1170  NtDuplicateObject(ProcessData->Process->ProcessHandle,
1171  ConsoleStartInfo->InitEvents[INIT_SUCCESS],
1172  NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1173  ConSrvFreeHandlesTable(ProcessData);
1174  ProcessData->ConsoleHandle = NULL;
1175  goto Quit;
1176  }
1177 
1178  /* Duplicate the Input Event */
1180  Console->InputBuffer.ActiveEvent,
1181  ProcessData->Process->ProcessHandle,
1182  &ConsoleStartInfo->InputWaitHandle,
1183  EVENT_ALL_ACCESS, 0, 0);
1184  if (!NT_SUCCESS(Status))
1185  {
1186  DPRINT1("NtDuplicateObject(InputWaitHandle) failed: %lu\n", Status);
1187  NtDuplicateObject(ProcessData->Process->ProcessHandle,
1188  ConsoleStartInfo->InitEvents[INIT_FAILURE],
1189  NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1190  NtDuplicateObject(ProcessData->Process->ProcessHandle,
1191  ConsoleStartInfo->InitEvents[INIT_SUCCESS],
1192  NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1193  ConSrvFreeHandlesTable(ProcessData); // NOTE: Always free the handle table.
1194  ProcessData->ConsoleHandle = NULL;
1195  goto Quit;
1196  }
1197 
1198  /* Mark the process as having a console */
1199  ProcessData->ConsoleApp = TRUE;
1200  ProcessData->Process->Flags |= CsrProcessIsConsoleApp;
1201 
1202  /* Return the console handle to the caller */
1203  ConsoleStartInfo->ConsoleHandle = ProcessData->ConsoleHandle;
1204 
1205  /*
1206  * Insert the process into the processes list of the console,
1207  * and set its foreground priority.
1208  */
1209  InsertHeadList(&Console->ProcessList, &ProcessData->ConsoleLink);
1210  ConSrvSetProcessFocus(ProcessData->Process, Console->HasFocus);
1211 
1212  /* Add a reference count because the process is tied to the console */
1213  _InterlockedIncrement(&Console->ReferenceCount);
1214 
1215  /* Update the internal info of the terminal */
1217 
1219 
1220 Quit:
1221  /* Unlock the console and return */
1222  LeaveCriticalSection(&Console->Lock);
1223  return Status;
1224 }
#define DUPLICATE_CLOSE_SOURCE
#define TRUE
Definition: types.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
VOID ConSrvFreeHandlesTable(IN PCONSOLE_PROCESS_DATA ProcessData)
Definition: handle.c:172
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
BOOLEAN NTAPI ConSrvValidateConsole(OUT PCONSRV_CONSOLE *Console, IN HANDLE ConsoleHandle, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:247
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
static NTSTATUS ConSrvInitProcessHandles(IN OUT PCONSOLE_PROCESS_DATA ProcessData, IN PCONSRV_CONSOLE Console, OUT PHANDLE pInputHandle, OUT PHANDLE pOutputHandle, OUT PHANDLE pErrorHandle)
Definition: console.c:890
CConsole Console
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3407
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define TermRefreshInternalInfo(Console)
Definition: term.h:44
return STATUS_SUCCESS
Definition: btrfs.c:3014
VOID ConSrvSetProcessFocus(IN PCSR_PROCESS CsrProcess, IN BOOLEAN SetForeground)
Definition: console.c:1440

Referenced by CON_API_NOCONSOLE(), and ConSrvConnect().

◆ ConSrvInitConsole()

NTSTATUS NTAPI ConSrvInitConsole ( OUT PHANDLE  NewConsoleHandle,
OUT PCONSRV_CONSOLE NewConsole,
IN OUT PCONSOLE_INIT_INFO  ConsoleInitInfo,
IN PCSR_PROCESS  ConsoleLeaderProcess 
)

Definition at line 532 of file console.c.

536 {
538  HANDLE ConsoleHandle;
540 
541  BYTE ConsoleInfoBuffer[sizeof(CONSOLE_STATE_INFO) + MAX_PATH * sizeof(WCHAR)]; // CONSRV console information
543  CONSOLE_INFO DrvConsoleInfo; // Console information for CONDRV
544 
545  SIZE_T Length = 0;
546 
547  TERMINAL Terminal; /* The ConSrv terminal for this console */
548 
549  if (NewConsole == NULL || ConsoleInitInfo == NULL)
551 
552  *NewConsole = NULL;
553 
554  DPRINT("Initialization of console '%S' for process '%S' on desktop '%S'\n",
555  ConsoleInitInfo->ConsoleTitle ? ConsoleInitInfo->ConsoleTitle : L"n/a",
556  ConsoleInitInfo->AppName ? ConsoleInitInfo->AppName : L"n/a",
557  ConsoleInitInfo->Desktop ? ConsoleInitInfo->Desktop : L"n/a");
558 
559  /*
560  * Load the console settings
561  */
562  RtlZeroMemory(ConsoleInfo, sizeof(ConsoleInfoBuffer));
563  ConsoleInfo->cbSize = sizeof(ConsoleInfoBuffer);
564 
565  /* 1. Get the title of the console (initialize ConsoleInfo->ConsoleTitle) */
566  Length = min(ConsoleInitInfo->TitleLength,
567  (ConsoleInfo->cbSize - FIELD_OFFSET(CONSOLE_STATE_INFO, ConsoleTitle) - sizeof(UNICODE_NULL)) / sizeof(WCHAR));
568  wcsncpy(ConsoleInfo->ConsoleTitle, ConsoleInitInfo->ConsoleTitle, Length);
569  ConsoleInfo->ConsoleTitle[Length] = UNICODE_NULL; // NULL-terminate it.
570 
571  /* 2. Impersonate the caller in order to retrieve settings in its context */
574 
575  /* 3. Load the default settings */
577 
578  /*
579  * 4. Load per-application terminal settings.
580  *
581  * Check whether the process creating the console was launched via
582  * a shell-link. ConsoleInfo->ConsoleTitle may be updated with the
583  * name of the shortcut, and ConsoleStartInfo->Icon[Path|Index] too.
584  */
585  // if (ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) // FIXME!! (for icon loading)
586  {
587  if (!LoadShellLinkConsoleInfo(ConsoleInfo, ConsoleInitInfo))
588  {
589  ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags &= ~STARTF_TITLEISLINKNAME;
590  }
591  }
592 
593  /*
594  * 5. Load the remaining console settings via the registry.
595  */
596  if ((ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) == 0)
597  {
598  /*
599  * Either we weren't created by an app launched via a shell-link,
600  * or we failed to load shell-link console properties.
601  * Therefore, load the console infos for the application from the registry.
602  */
604 
605  /*
606  * Now, update them with the properties the user might gave to us
607  * via the STARTUPINFO structure before calling CreateProcess
608  * (and which was transmitted via the ConsoleStartInfo structure).
609  * We therefore overwrite the values read in the registry.
610  */
611  if (ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_USEFILLATTRIBUTE)
612  {
613  ConsoleInfo->ScreenAttributes = (USHORT)ConsoleInitInfo->ConsoleStartInfo->wFillAttribute;
614  }
615  if (ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_USECOUNTCHARS)
616  {
617  ConsoleInfo->ScreenBufferSize = ConsoleInitInfo->ConsoleStartInfo->dwScreenBufferSize;
618  }
619  if (ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_USESIZE)
620  {
621  ConsoleInfo->WindowSize = ConsoleInitInfo->ConsoleStartInfo->dwWindowSize;
622  }
623 
624 #if 0
625  /*
626  * Now, update them with the properties the user might gave to us
627  * via the STARTUPINFO structure before calling CreateProcess
628  * (and which was transmitted via the ConsoleStartInfo structure).
629  * We therefore overwrite the values read in the registry.
630  */
631  if (ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_USEPOSITION)
632  {
633  ConsoleInfo->AutoPosition = FALSE;
634  ConsoleInfo->WindowPosition.x = ConsoleInitInfo->ConsoleStartInfo->dwWindowOrigin.X;
635  ConsoleInfo->WindowPosition.y = ConsoleInitInfo->ConsoleStartInfo->dwWindowOrigin.Y;
636  }
637  if (ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_RUNFULLSCREEN)
638  {
639  ConsoleInfo->FullScreen = TRUE;
640  }
641 #endif
642  }
643 
644  /* 6. Revert impersonation */
645  CsrRevertToSelf();
646 
647  /* Set-up the code page */
648  ConsoleInfo->CodePage = GetOEMCP();
649 
650  /*
651  * Initialize the ConSrv terminal and give it a chance to load
652  * its own settings and override the console settings.
653  */
654  Status = ConSrvInitTerminal(&Terminal,
655  ConsoleInfo,
656  ConsoleInitInfo,
657  ConsoleLeaderProcess->ProcessHandle);
658  if (!NT_SUCCESS(Status))
659  {
660  DPRINT1("CONSRV: Failed to initialize a terminal, Status = 0x%08lx\n", Status);
661  return Status;
662  }
663  DPRINT("CONSRV: Terminal initialized\n");
664 
665  /* Initialize a new console via the driver */
666  // DrvConsoleInfo.InputBufferSize = 0;
667  DrvConsoleInfo.ScreenBufferSize = ConsoleInfo->ScreenBufferSize;
668  DrvConsoleInfo.ConsoleSize = ConsoleInfo->WindowSize;
669  DrvConsoleInfo.CursorSize = ConsoleInfo->CursorSize;
670  // DrvConsoleInfo.CursorBlinkOn = ConsoleInfo->CursorBlinkOn;
671  DrvConsoleInfo.ScreenAttrib = ConsoleInfo->ScreenAttributes;
672  DrvConsoleInfo.PopupAttrib = ConsoleInfo->PopupAttributes;
673  DrvConsoleInfo.CodePage = ConsoleInfo->CodePage;
674 
675  /*
676  * Allocate a new console
677  */
679  if (Console == NULL)
680  {
681  DPRINT1("Not enough memory for console creation.\n");
682  ConSrvDeinitTerminal(&Terminal);
683  return STATUS_NO_MEMORY;
684  }
685 
686  Status = ConDrvInitConsole((PCONSOLE)Console, &DrvConsoleInfo);
687  if (!NT_SUCCESS(Status))
688  {
689  DPRINT1("Creating a new console failed, Status = 0x%08lx\n", Status);
691  ConSrvDeinitTerminal(&Terminal);
692  return Status;
693  }
694 
695  DPRINT("Console initialized\n");
696 
697  /*** Register ConSrv features ***/
698 
699  /* Initialize the console title */
700 #if 0
701  WCHAR DefaultTitle[128];
702 #endif
703  ConsoleCreateUnicodeString(&Console->OriginalTitle, ConsoleInfo->ConsoleTitle);
704 #if 0
705  if (ConsoleInfo->ConsoleTitle[0] == UNICODE_NULL)
706  {
707  if (LoadStringW(ConSrvDllInstance, IDS_CONSOLE_TITLE, DefaultTitle, sizeof(DefaultTitle) / sizeof(DefaultTitle[0])))
708  {
709  ConsoleCreateUnicodeString(&Console->Title, DefaultTitle);
710  }
711  else
712  {
713  ConsoleCreateUnicodeString(&Console->Title, L"ReactOS Console");
714  }
715  }
716  else
717  {
718 #endif
719  ConsoleCreateUnicodeString(&Console->Title, ConsoleInfo->ConsoleTitle);
720 #if 0
721  }
722 #endif
723 
724  /* Initialize process support */
725  // InitProcessSupport(Console);
726  InitializeListHead(&Console->ProcessList);
727  Console->NotifiedLastCloseProcess = NULL;
728  Console->NotifyLastClose = FALSE;
729  Console->HasFocus = FALSE;
730 
731  /* Initialize pausing support */
732  Console->PauseFlags = 0;
733  InitializeListHead(&Console->ReadWaitQueue);
734  InitializeListHead(&Console->WriteWaitQueue);
735 
736  /* Initialize the alias and history buffers */
737  // InitAliasesHistory(Console);
738  Console->Aliases = NULL;
739  InitializeListHead(&Console->HistoryBuffers);
740  Console->NumberOfHistoryBuffers = 0;
741  Console->MaxNumberOfHistoryBuffers = ConsoleInfo->NumberOfHistoryBuffers;
742  Console->HistoryBufferSize = ConsoleInfo->HistoryBufferSize;
743  Console->HistoryNoDup = ConsoleInfo->HistoryNoDup;
744 
745  /* Initialize the Input Line Discipline */
746  // InitLineInput(Console);
747  Console->LineBuffer = NULL;
748  Console->LinePos = Console->LineMaxSize = Console->LineSize = 0;
749  Console->LineComplete = Console->LineUpPressed = FALSE;
750  // LineWakeupMask
751  Console->LineInsertToggle =
752  Console->InsertMode = ConsoleInfo->InsertMode;
753  Console->QuickEdit = ConsoleInfo->QuickEdit;
754 
755  /* Popup windows */
756  InitializeListHead(&Console->PopupWindows);
757 
758  /* Colour table */
759  RtlCopyMemory(Console->Colors, ConsoleInfo->ColorTable,
760  sizeof(ConsoleInfo->ColorTable));
761 
762  /* Create the Initialization Events */
765  if (!NT_SUCCESS(Status))
766  {
767  DPRINT1("NtCreateEvent(InitEvents[INIT_SUCCESS]) failed: %lu\n", Status);
769  ConSrvDeinitTerminal(&Terminal);
770  return Status;
771  }
774  if (!NT_SUCCESS(Status))
775  {
776  DPRINT1("NtCreateEvent(InitEvents[INIT_FAILURE]) failed: %lu\n", Status);
777  NtClose(Console->InitEvents[INIT_SUCCESS]);
779  ConSrvDeinitTerminal(&Terminal);
780  return Status;
781  }
782 
783  /*
784  * Attach the ConSrv terminal to the console.
785  * This call makes a copy of our local Terminal variable.
786  */
788  if (!NT_SUCCESS(Status))
789  {
790  DPRINT1("Failed to register terminal to the given console, Status = 0x%08lx\n", Status);
791  NtClose(Console->InitEvents[INIT_FAILURE]);
792  NtClose(Console->InitEvents[INIT_SUCCESS]);
794  ConSrvDeinitTerminal(&Terminal);
795  return Status;
796  }
797  DPRINT("Terminal attached\n");
798 
799  /* All went right, so add the console to the list */
800 #if 0
801  Status = ConDrvInsertConsole((PCONSOLE)Console);
802  if (!NT_SUCCESS(Status))
803  {
804  /* Fail */
806  return Status;
807  }
808 #endif
809  Status = InsertConsole(&ConsoleHandle, Console);
810 
811  // FIXME! We do not support at all asynchronous console creation!
812  NtSetEvent(Console->InitEvents[INIT_SUCCESS], NULL);
813  // NtSetEvent(Console->InitEvents[INIT_FAILURE], NULL);
814 
815  /* Return the newly created console to the caller and a success code too */
816  *NewConsoleHandle = ConsoleHandle;
817  *NewConsole = Console;
818  return STATUS_SUCCESS;
819 }
VOID ConCfgGetDefaultSettings(IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
Definition: settings.c:491
#define STARTF_RUNFULLSCREEN
Definition: winbase.h:477
COORD ConsoleSize
Definition: conio.h:183
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IDS_CONSOLE_TITLE
Definition: resource.h:10
#define STATUS_BAD_IMPERSONATION_LEVEL
Definition: ntstatus.h:387
COORD ScreenBufferSize
Definition: conio.h:182
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _CONSOLE_STATE_INFO CONSOLE_STATE_INFO
LONG NTSTATUS
Definition: precomp.h:26
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
BOOLEAN NTAPI CsrRevertToSelf(VOID)
Definition: procsup.c:1056
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
#define STARTF_USEFILLATTRIBUTE
Definition: winbase.h:476
#define STARTF_USEPOSITION
Definition: winbase.h:474
USHORT PopupAttrib
Definition: conio.h:190
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
static BOOLEAN ConsoleCreateUnicodeString(IN OUT PUNICODE_STRING UniDest, IN PCWSTR Source)
Definition: console.c:216
NTSTATUS NTAPI ConSrvInitTerminal(IN OUT PTERMINAL Terminal, IN OUT PCONSOLE_STATE_INFO ConsoleInfo, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo, IN HANDLE ConsoleLeaderProcessHandle)
Definition: terminal.c:204
VOID NTAPI ConDrvDeleteConsole(IN PCONSOLE Console)
Definition: console.c:217
static NTSTATUS InsertConsole(OUT PHANDLE Handle, IN PCONSRV_CONSOLE Console)
Definition: console.c:72
#define UNICODE_NULL
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
ULONG CodePage
Definition: conio.h:192
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
struct _CONSOLE_STATE_INFO * PCONSOLE_STATE_INFO
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:458
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:26
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI ConDrvAttachTerminal(IN PCONSOLE Console, IN PTERMINAL Terminal)
Definition: console.c:159
unsigned char BYTE
Definition: xxhash.c:193
BOOLEAN ConCfgReadUserSettings(IN OUT PCONSOLE_STATE_INFO ConsoleInfo, IN BOOLEAN DefaultSettings)
Definition: settings.c:167
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
USHORT ScreenAttrib
Definition: conio.h:189
#define STARTF_USECOUNTCHARS
Definition: winbase.h:475
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define min(a, b)
Definition: monoChain.cc:55
#define STARTF_USESIZE
Definition: winbase.h:473
ULONG CursorSize
Definition: conio.h:185
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
HINSTANCE ConSrvDllInstance
Definition: init.c:21
BOOLEAN NTAPI CsrImpersonateClient(IN PCSR_THREAD CsrThread)
Definition: procsup.c:931
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:3014
static BOOL LoadShellLinkConsoleInfo(IN OUT PCONSOLE_STATE_INFO ConsoleInfo, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo)
Definition: console.c:370
NTSTATUS NTAPI ConSrvDeinitTerminal(IN OUT PTERMINAL Terminal)
Definition: terminal.c:237
UINT WINAPI GetOEMCP(VOID)
Definition: nls.c:2195
NTSTATUS NTAPI ConDrvInitConsole(IN OUT PCONSOLE Console, IN PCONSOLE_INFO ConsoleInfo)
Definition: console.c:69

Referenced by ConSrvAllocateConsole().

◆ ConSrvInitConsoleSupport()

VOID NTAPI ConSrvInitConsoleSupport ( VOID  )

Definition at line 347 of file console.c.

348 {
349  DPRINT("CONSRV: ConSrvInitConsoleSupport()\n");
350 
351  /* Initialize the console list and its lock */
352  ConsoleListSize = 0;
353  ConsoleList = NULL;
354  // InitializeListHead(&ConDrvConsoleList);
356 
357  /* Should call LoadKeyboardLayout */
358 }
static PCONSRV_CONSOLE * ConsoleList
Definition: console.c:34
static ULONG ConsoleListSize
Definition: console.c:33
static RTL_RESOURCE ListLock
Definition: console.c:36
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)

Referenced by CSR_SERVER_DLL_INIT().

◆ ConSrvInitProcessHandles()

static NTSTATUS ConSrvInitProcessHandles ( IN OUT PCONSOLE_PROCESS_DATA  ProcessData,
IN PCONSRV_CONSOLE  Console,
OUT PHANDLE  pInputHandle,
OUT PHANDLE  pOutputHandle,
OUT PHANDLE  pErrorHandle 
)
static

Definition at line 890 of file console.c.

896 {
900  ErrorHandle = INVALID_HANDLE_VALUE;
901 
902  /*
903  * Initialize the process handles. Use temporary variables to store
904  * the handles values in such a way that, if we fail, we don't
905  * return to the caller invalid handle values.
906  *
907  * Insert the IO handles.
908  */
909 
910  RtlEnterCriticalSection(&ProcessData->HandleTableLock);
911 
912  /* Insert the Input handle */
913  Status = ConSrvInsertObject(ProcessData,
914  &InputHandle,
915  &Console->InputBuffer.Header,
917  TRUE,
919  if (!NT_SUCCESS(Status))
920  {
921  DPRINT1("Failed to insert the input handle\n");
922  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
923  ConSrvFreeHandlesTable(ProcessData);
924  return Status;
925  }
926 
927  /* Insert the Output handle */
928  Status = ConSrvInsertObject(ProcessData,
929  &OutputHandle,
930  &Console->ActiveBuffer->Header,
932  TRUE,
934  if (!NT_SUCCESS(Status))
935  {
936  DPRINT1("Failed to insert the output handle\n");
937  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
938  ConSrvFreeHandlesTable(ProcessData);
939  return Status;
940  }
941 
942  /* Insert the Error handle */
943  Status = ConSrvInsertObject(ProcessData,
944  &ErrorHandle,
945  &Console->ActiveBuffer->Header,
947  TRUE,
949  if (!NT_SUCCESS(Status))
950  {
951  DPRINT1("Failed to insert the error handle\n");
952  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
953  ConSrvFreeHandlesTable(ProcessData);
954  return Status;
955  }
956 
957  RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
958 
959  /* Return the newly created handles */
960  *pInputHandle = InputHandle;
961  *pOutputHandle = OutputHandle;
962  *pErrorHandle = ErrorHandle;
963 
964  return STATUS_SUCCESS;
965 }
#define TRUE
Definition: types.h:120
HANDLE OutputHandle
Definition: apc.c:8
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
VOID ConSrvFreeHandlesTable(IN PCONSOLE_PROCESS_DATA ProcessData)
Definition: handle.c:172
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define GENERIC_WRITE
Definition: nt_native.h:90
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
HANDLE InputHandle
Definition: apc.c:9
CConsole Console
#define DPRINT1
Definition: precomp.h:8
NTSTATUS ConSrvInsertObject(IN PCONSOLE_PROCESS_DATA ProcessData, OUT PHANDLE Handle, IN PCONSOLE_IO_OBJECT Object, IN ULONG Access, IN BOOLEAN Inheritable, IN ULONG ShareMode)
Definition: handle.c:227
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConSrvAllocateConsole(), and ConSrvInheritConsole().

◆ ConSrvInitTerminal()

NTSTATUS NTAPI ConSrvInitTerminal ( IN OUT PTERMINAL  Terminal,
IN OUT PCONSOLE_STATE_INFO  ConsoleInfo,
IN OUT PCONSOLE_INIT_INFO  ConsoleInitInfo,
IN HANDLE  ConsoleLeaderProcessHandle 
)

Definition at line 204 of file terminal.c.

208 {
210  PFRONTEND FrontEnd;
211 
212  /* Load a suitable frontend for the ConSrv terminal */
213  FrontEnd = ConsoleAllocHeap(HEAP_ZERO_MEMORY, sizeof(*FrontEnd));
214  if (!FrontEnd) return STATUS_NO_MEMORY;
215 
216  Status = ConSrvLoadFrontEnd(FrontEnd,
217  ConsoleInfo,
218  ConsoleInitInfo,
219  ConsoleLeaderProcessHandle);
220  if (!NT_SUCCESS(Status))
221  {
222  DPRINT1("CONSRV: Failed to initialize a frontend, Status = 0x%08lx\n", Status);
223  ConsoleFreeHeap(FrontEnd);
224  return Status;
225  }
226  DPRINT("CONSRV: Frontend initialized\n");
227 
228  /* Initialize the ConSrv terminal */
229  Terminal->Vtbl = &ConSrvTermVtbl;
230  // Terminal->Console will be initialized by ConDrvAttachTerminal
231  Terminal->Context = FrontEnd; /* We store the frontend pointer in the terminal private context */
232 
233  return STATUS_SUCCESS;
234 }
LONG NTSTATUS
Definition: precomp.h:26
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static TERMINAL_VTBL ConSrvTermVtbl
Definition: terminal.c:201
static NTSTATUS ConSrvLoadFrontEnd(IN OUT PFRONTEND FrontEnd, IN OUT PCONSOLE_STATE_INFO ConsoleInfo, IN OUT PCONSOLE_INIT_INFO ConsoleInitInfo, IN HANDLE ConsoleLeaderProcessHandle)
Definition: terminal.c:154
Status
Definition: gdiplustypes.h:24
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConSrvInitConsole().

◆ ConSrvReleaseConsole()

VOID ConSrvReleaseConsole ( IN PCONSRV_CONSOLE  Console,
IN BOOLEAN  IsConsoleLocked 
)

Definition at line 316 of file console.c.

318 {
319  LONG RefCount = 0;
320 
321  if (!Console) return;
322  // if (Console->ReferenceCount == 0) return; // This shouldn't happen
323  ASSERT(Console->ReferenceCount > 0);
324 
325  /* The console must be locked */
326  // ASSERT(Console_locked);
327 
328  /*
329  * Decrement the reference count. Save the new value too,
330  * because Console->ReferenceCount might be modified after
331  * the console gets unlocked but before we check whether we
332  * can destroy it.
333  */
334  RefCount = _InterlockedDecrement(&Console->ReferenceCount);
335 
336  /* Unlock the console if needed */
337  if (IsConsoleLocked) LeaveCriticalSection(&Console->Lock);
338 
339  /* Delete the console if needed */
340  if (RefCount <= 0) ConSrvDeleteConsole(Console);
341 }
long LONG
Definition: pedump.c:60
long __cdecl _InterlockedDecrement(_Interlocked_operand_ long volatile *_Addend)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI ConSrvDeleteConsole(PCONSRV_CONSOLE Console)
Definition: console.c:822
CConsole Console
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by CON_API_NOCONSOLE(), ConSrvReleaseObject(), ConSrvRemoveConsole(), and GetThreadConsoleDesktop().

◆ ConSrvRemoveConsole()

NTSTATUS ConSrvRemoveConsole ( IN OUT PCONSOLE_PROCESS_DATA  ProcessData)

Definition at line 1227 of file console.c.

1229 {
1231  PCONSOLE_PROCESS_DATA ConsoleLeaderProcess;
1232 
1233  DPRINT("ConSrvRemoveConsole\n");
1234 
1235  /* Mark the process as not having a console anymore */
1236  ProcessData->ConsoleApp = FALSE;
1237  ProcessData->Process->Flags &= ~CsrProcessIsConsoleApp;
1238 
1239  /* Validate and lock the console */
1241  ProcessData->ConsoleHandle,
1243  {
1244  // FIXME: Find another status code
1245  return STATUS_UNSUCCESSFUL;
1246  }
1247 
1248  DPRINT("ConSrvRemoveConsole - Locking OK\n");
1249 
1250  /* Retrieve the console leader process */
1251  ConsoleLeaderProcess = ConSrvGetConsoleLeaderProcess(Console);
1252 
1253  /* Close all console handles and free the handle table */
1254  ConSrvFreeHandlesTable(ProcessData);
1255 
1256  /* Detach the process from the console */
1257  ProcessData->ConsoleHandle = NULL;
1258 
1259  /* Remove the process from the console's list of processes */
1260  RemoveEntryList(&ProcessData->ConsoleLink);
1261 
1262  /* Check whether the console should send a last close notification */
1263  if (Console->NotifyLastClose)
1264  {
1265  /* If we are removing the process which wants the last close notification... */
1266  if (ProcessData == Console->NotifiedLastCloseProcess)
1267  {
1268  /* ... just reset the flag and the pointer... */
1269  Console->NotifyLastClose = FALSE;
1270  Console->NotifiedLastCloseProcess = NULL;
1271  }
1272  /*
1273  * ... otherwise, if we are removing the console leader process
1274  * (that cannot be the process wanting the notification, because
1275  * the previous case already dealt with it)...
1276  */
1277  else if (ProcessData == ConsoleLeaderProcess)
1278  {
1279  /*
1280  * ... reset the flag first (so that we avoid multiple notifications)
1281  * and then send the last close notification.
1282  */
1283  Console->NotifyLastClose = FALSE;
1284  ConSrvConsoleCtrlEvent(CTRL_LAST_CLOSE_EVENT, Console->NotifiedLastCloseProcess);
1285 
1286  /* Only now, reset the pointer */
1287  Console->NotifiedLastCloseProcess = NULL;
1288  }
1289  }
1290 
1291  /* Update the internal info of the terminal */
1293 
1294  /* Release the console */
1295  DPRINT("ConSrvRemoveConsole - Decrement Console->ReferenceCount = %lu\n", Console->ReferenceCount);
1297 
1298  return STATUS_SUCCESS;
1299 }
PCONSOLE_PROCESS_DATA NTAPI ConSrvGetConsoleLeaderProcess(IN PCONSRV_CONSOLE Console)
Definition: console.c:1363
#define TRUE
Definition: types.h:120
NTSTATUS ConSrvConsoleCtrlEvent(IN ULONG CtrlEvent, IN PCONSOLE_PROCESS_DATA ProcessData)
Definition: console.c:1356
VOID ConSrvReleaseConsole(IN PCONSRV_CONSOLE Console, IN BOOLEAN IsConsoleLocked)
Definition: console.c:316
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
VOID ConSrvFreeHandlesTable(IN PCONSOLE_PROCESS_DATA ProcessData)
Definition: handle.c:172
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
BOOLEAN NTAPI ConSrvValidateConsole(OUT PCONSRV_CONSOLE *Console, IN HANDLE ConsoleHandle, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:247
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CTRL_LAST_CLOSE_EVENT
Definition: wincon.h:71
CConsole Console
#define TermRefreshInternalInfo(Console)
Definition: term.h:44
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API_NOCONSOLE(), and ConSrvDisconnect().

◆ ConSrvSetConsoleProcessFocus()

NTSTATUS NTAPI ConSrvSetConsoleProcessFocus ( IN PCONSRV_CONSOLE  Console,
IN BOOLEAN  SetForeground 
)

Definition at line 1453 of file console.c.

1455 {
1456  PLIST_ENTRY current_entry;
1458 
1459  /* If the console is already being destroyed, just return */
1461  return STATUS_UNSUCCESSFUL;
1462 
1463  /*
1464  * Loop through the process list, from the most recent process
1465  * to the oldest one, and for each, set its foreground priority.
1466  */
1467  current_entry = Console->ProcessList.Flink;
1468  while (current_entry != &Console->ProcessList)
1469  {
1470  current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
1471  current_entry = current_entry->Flink;
1472 
1473  ConSrvSetProcessFocus(current->Process, SetForeground);
1474  }
1475 
1476  return STATUS_SUCCESS;
1477 }
BOOLEAN NTAPI ConDrvValidateConsoleState(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
Definition: console.c:24
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: typedefs.h:118
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014
struct task_struct * current
Definition: linux.c:32
VOID ConSrvSetProcessFocus(IN PCSR_PROCESS CsrProcess, IN BOOLEAN SetForeground)
Definition: console.c:1440

Referenced by OnFocus().

◆ ConSrvSetProcessFocus()

VOID ConSrvSetProcessFocus ( IN PCSR_PROCESS  CsrProcess,
IN BOOLEAN  SetForeground 
)

Definition at line 1440 of file console.c.

1442 {
1443  // FIXME: Call NtUserSetInformationProcess (currently unimplemented!)
1444  // for setting Win32 foreground/background flags.
1445 
1446  if (SetForeground)
1448  else
1450 }
PKPROCESS CsrProcess
Definition: videoprt.c:37
VOID NTAPI CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1137
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1106

Referenced by ConSrvAllocateConsole(), ConSrvInheritConsole(), and ConSrvSetConsoleProcessFocus().

◆ ConSrvValidateConsole()

BOOLEAN NTAPI ConSrvValidateConsole ( OUT PCONSRV_CONSOLE Console,
IN HANDLE  ConsoleHandle,
IN CONSOLE_STATE  ExpectedState,
IN BOOLEAN  LockConsole 
)

Definition at line 247 of file console.c.

251 {
252  BOOLEAN RetVal = FALSE;
253  PCONSRV_CONSOLE ValidatedConsole;
254 
255  BOOLEAN ValidHandle = ((HandleToULong(ConsoleHandle) & 0x3) == 0x3);
256  ULONG Index = HandleToULong(ConsoleHandle) >> 2;
257 
258  if (!ValidHandle) return FALSE;
259 
260  if (!Console) return FALSE;
261  *Console = NULL;
262 
263  /*
264  * Forbid creation or deletion of consoles when
265  * checking for the existence of a console.
266  */
268 
269  if (Index >= ConsoleListSize ||
270  (ValidatedConsole = ConsoleList[Index]) == NULL)
271  {
272  /* Unlock the console list and return */
274  return FALSE;
275  }
276 
277  ValidatedConsole = ConsoleList[Index];
278 
279  /* Unlock the console list */
281 
282  RetVal = ConDrvValidateConsoleUnsafe((PCONSOLE)ValidatedConsole,
283  ExpectedState,
284  LockConsole);
285  if (RetVal) *Console = ValidatedConsole;
286 
287  return RetVal;
288 }
static PCONSRV_CONSOLE * ConsoleList
Definition: console.c:34
static ULONG ConsoleListSize
Definition: console.c:33
#define HandleToULong(h)
Definition: basetsd.h:95
#define ConSrvLockConsoleListShared()
Definition: console.c:41
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static const UCHAR Index[8]
Definition: usbohci.c:18
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:36
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
#define ConSrvUnlockConsoleList()
Definition: console.c:44

Referenced by ConSrvGetConsole(), ConSrvInheritConsole(), ConSrvNewProcess(), and ConSrvRemoveConsole().

◆ CSR_API() [1/8]

CSR_API ( SrvSetConsoleKeyShortcuts  )

Definition at line 1955 of file console.c.

1956 {
1957  DPRINT1("%s not yet implemented\n", __FUNCTION__);
1958  return STATUS_NOT_IMPLEMENTED;
1959 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [2/8]

CSR_API ( SrvGetConsoleCharType  )

Definition at line 1975 of file console.c.

1976 {
1977  DPRINT1("%s not yet implemented\n", __FUNCTION__);
1978  return STATUS_NOT_IMPLEMENTED;
1979 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [3/8]

CSR_API ( SrvSetConsoleLocalEUDC  )

Definition at line 1982 of file console.c.

1983 {
1984  DPRINT1("%s not yet implemented\n", __FUNCTION__);
1985  return STATUS_NOT_IMPLEMENTED;
1986 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [4/8]

CSR_API ( SrvSetConsoleCursorMode  )

Definition at line 1989 of file console.c.

1990 {
1991  DPRINT1("%s not yet implemented\n", __FUNCTION__);
1992  return STATUS_NOT_IMPLEMENTED;
1993 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [5/8]

CSR_API ( SrvGetConsoleCursorMode  )

Definition at line 1996 of file console.c.

1997 {
1998  DPRINT1("%s not yet implemented\n", __FUNCTION__);
1999  return STATUS_NOT_IMPLEMENTED;
2000 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [6/8]

CSR_API ( SrvGetConsoleNlsMode  )

Definition at line 2003 of file console.c.

2004 {
2005  DPRINT1("%s not yet implemented\n", __FUNCTION__);
2006  return STATUS_NOT_IMPLEMENTED;
2007 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [7/8]

CSR_API ( SrvSetConsoleNlsMode  )

Definition at line 2010 of file console.c.

2011 {
2012  DPRINT1("%s not yet implemented\n", __FUNCTION__);
2013  return STATUS_NOT_IMPLEMENTED;
2014 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ CSR_API() [8/8]

CSR_API ( SrvGetConsoleLangId  )

Definition at line 2017 of file console.c.

2018 {
2019  DPRINT1("%s not yet implemented\n", __FUNCTION__);
2020  return STATUS_NOT_IMPLEMENTED;
2021 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:112

◆ InsertConsole()

static NTSTATUS InsertConsole ( OUT PHANDLE  Handle,
IN PCONSRV_CONSOLE  Console 
)
static

Definition at line 72 of file console.c.

75 {
76 #define CONSOLE_HANDLES_INCREMENT 2 * 3
77 
79  ULONG i = 0;
80  PCONSRV_CONSOLE* Block;
81 
82  ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
83  (ConsoleList != NULL && ConsoleListSize != 0) );
84 
85  /* All went right, so add the console to the list */
87  DPRINT("Insert in the list\n");
88 
89  if (ConsoleList)
90  {
91  for (i = 0; i < ConsoleListSize; i++)
92  {
93  if (ConsoleList[i] == NULL) break;
94  }
95  }
96 
97  if (i >= ConsoleListSize)
98  {
99  DPRINT("Creation of a new handles table\n");
100  /* Allocate a new handles table */
102  (ConsoleListSize +
104  if (Block == NULL)
105  {
107  goto Quit;
108  }
109 
110  /* If we previously had a handles table, free it and use the new one */
111  if (ConsoleList)
112  {
113  /* Copy the handles from the old table to the new one */
114  RtlCopyMemory(Block,
115  ConsoleList,
116  ConsoleListSize * sizeof(PCONSRV_CONSOLE));
118  }
119  ConsoleList = Block;
121  }
122 
123  ConsoleList[i] = Console;
124  *Handle = ULongToHandle((i << 2) | 0x3);
125 
126 Quit:
127  /* Unlock the console list and return status */
129  return Status;
130 }
static PCONSRV_CONSOLE * ConsoleList
Definition: console.c:34
static ULONG ConsoleListSize
Definition: console.c:33
#define ConSrvLockConsoleListExclusive()
Definition: console.c:38
#define ULongToHandle(h)
Definition: basetsd.h:81
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
#define CONSOLE_HANDLES_INCREMENT
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
unsigned int ULONG
Definition: retypes.h:1
#define ConSrvUnlockConsoleList()
Definition: console.c:44
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConSrvInitConsole().

◆ LoadShellLinkConsoleInfo()

static BOOL LoadShellLinkConsoleInfo ( IN OUT PCONSOLE_STATE_INFO  ConsoleInfo,
IN OUT PCONSOLE_INIT_INFO  ConsoleInitInfo 
)
static

Definition at line 370 of file console.c.

372 {
373 #define PATH_SEPARATOR L'\\'
374 
375  BOOL RetVal = FALSE;
376  HRESULT hRes = S_OK;
377  SIZE_T Length = 0;
378  LPWSTR LinkName = NULL;
379  LPWSTR IconPath = NULL;
380  WCHAR Buffer[MAX_PATH + 1];
381 
382  ConsoleInitInfo->ConsoleStartInfo->IconIndex = 0;
383 
384  if ((ConsoleInitInfo->ConsoleStartInfo->dwStartupFlags & STARTF_TITLEISLINKNAME) == 0)
385  {
386  // return FALSE; // FIXME!! (for icon loading)
387  RetVal = TRUE;
388  goto Finish;
389  }
390 
391  /* 1- Find the last path separator if any */
392  LinkName = wcsrchr(ConsoleInfo->ConsoleTitle, PATH_SEPARATOR);
393  if (LinkName == NULL)
394  LinkName = ConsoleInfo->ConsoleTitle;
395  else
396  ++LinkName; // Skip the path separator
397 
398  /* 2- Check for the link extension. The name ".lnk" is considered invalid. */
399  Length = wcslen(LinkName);
400  if ( (Length <= 4) || (wcsicmp(LinkName + (Length - 4), L".lnk") != 0) )
401  return FALSE;
402 
403  /* 3- It may be a link. Try to retrieve some properties */
404  hRes = CoInitialize(NULL);
405  if (SUCCEEDED(hRes))
406  {
407  /* Get a pointer to the IShellLink interface */
408  IShellLinkW* pshl = NULL;
409  hRes = CoCreateInstance(&CLSID_ShellLink,
410  NULL,
411  CLSCTX_INPROC_SERVER,
412  &IID_IShellLinkW,
413  (LPVOID*)&pshl);
414  if (SUCCEEDED(hRes))
415  {
416  /* Get a pointer to the IPersistFile interface */
417  IPersistFile* ppf = NULL;
418  hRes = IPersistFile_QueryInterface(pshl, &IID_IPersistFile, (LPVOID*)&ppf);
419  if (SUCCEEDED(hRes))
420  {
421  /* Load the shortcut */
422  hRes = IPersistFile_Load(ppf, ConsoleInfo->ConsoleTitle, STGM_READ);
423  if (SUCCEEDED(hRes))
424  {
425  /*
426  * Finally we can get the properties !
427  * Update the old ones if needed.
428  */
429  INT ShowCmd = 0;
430  // WORD HotKey = 0;
431 
432  /* Reset the name of the console with the name of the shortcut */
433  Length = min(/*Length*/ Length - 4, // 4 == len(".lnk")
434  (ConsoleInfo->cbSize - FIELD_OFFSET(CONSOLE_STATE_INFO, ConsoleTitle) - sizeof(UNICODE_NULL)) / sizeof(WCHAR));
435  wcsncpy(ConsoleInfo->ConsoleTitle, LinkName, Length);
436  ConsoleInfo->ConsoleTitle[Length] = UNICODE_NULL;
437 
438  /* Get the window showing command */
439  hRes = IShellLinkW_GetShowCmd(pshl, &ShowCmd);
440  if (SUCCEEDED(hRes)) ConsoleInitInfo->ConsoleStartInfo->wShowWindow = (WORD)ShowCmd;
441 
442  /* Get the hotkey */
443  // hRes = pshl->GetHotkey(&ShowCmd);
444  // if (SUCCEEDED(hRes)) ConsoleInitInfo->ConsoleStartInfo->HotKey = HotKey;
445 
446  /* Get the icon location, if any */
447  hRes = IShellLinkW_GetIconLocation(pshl,
448  Buffer,
449  sizeof(Buffer)/sizeof(Buffer[0]) - 1, // == MAX_PATH
450  &ConsoleInitInfo->ConsoleStartInfo->IconIndex);
451  if (!SUCCEEDED(hRes))
452  {
453  ConsoleInitInfo->ConsoleStartInfo->IconIndex = 0;
454  }
455  else
456  {
457  IconPath = Buffer;
458  }
459 
460  // FIXME: Since we still don't load console properties from the shortcut,
461  // return false. When this will be done, we will return true instead.
462  RetVal = TRUE; // FALSE;
463  }
464  IPersistFile_Release(ppf);
465  }
466  IShellLinkW_Release(pshl);
467  }
468  }
469  CoUninitialize();
470 
471 Finish:
472 
473  if (RetVal)
474  {
475  /* Get the associated icon, if any */
476  if (IconPath == NULL)
477  {
478  // Question: How to retrieve the full path name
479  // of the app we are going to run??
480  Length = RtlDosSearchPath_U(ConsoleInitInfo->CurDir,
481  ConsoleInitInfo->AppName,
482  NULL,
483  sizeof(Buffer),
484  Buffer,
485  NULL);
486  if (Length > 0 && Length < sizeof(Buffer))
487  IconPath = Buffer;
488  else
489  IconPath = ConsoleInitInfo->AppName;
490 
491  // ConsoleInitInfo->ConsoleStartInfo->IconIndex = 0;
492  }
493  DPRINT("IconPath = '%S' ; IconIndex = %lu\n",
494  IconPath, ConsoleInitInfo->ConsoleStartInfo->IconIndex);
495  if (IconPath && *IconPath)
496  {
497  HICON hIcon = NULL, hIconSm = NULL;
498  /*
499  * FIXME!! Because of a strange bug we have in PrivateExtractIconExW
500  * (see r65683 for more details), we cannot use this API to extract
501  * at the same time the large and small icons from the app.
502  * Instead we just use PrivateExtractIconsW.
503  *
504  PrivateExtractIconExW(IconPath,
505  ConsoleInitInfo->ConsoleStartInfo->IconIndex,
506  &hIcon,
507  &hIconSm,
508  1);
509  */
511  ConsoleInitInfo->ConsoleStartInfo->IconIndex,
512  32, 32,
515  ConsoleInitInfo->ConsoleStartInfo->IconIndex,
516  16, 16,
518 
519  DPRINT("hIcon = 0x%p ; hIconSm = 0x%p\n", hIcon, hIconSm);
520  if (hIcon != NULL) ConsoleInitInfo->ConsoleStartInfo->hIcon = hIcon;
521  if (hIconSm != NULL) ConsoleInitInfo->ConsoleStartInfo->hIconSm = hIconSm;
522  }
523  }
524 
525  // FIXME: See the previous FIXME above.
526  RetVal = FALSE;
527 
528  return RetVal;
529 }
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
int32_t INT
Definition: typedefs.h:57
NTSYSAPI ULONG NTAPI RtlDosSearchPath_U(_In_ PCWSTR Path, _In_ PCWSTR FileName, _In_ PCWSTR Extension, _In_ ULONG BufferSize, _Out_ PWSTR Buffer, _Out_ PWSTR *PartName)
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
Definition: bufpool.h:45
#define STGM_READ
Definition: objbase.h:916
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI PrivateExtractIconsW(_In_reads_(MAX_PATH) LPCWSTR szFileName, _In_ int nIconIndex, _In_ int cxIcon, _In_ int cyIcon, _Out_writes_opt_(nIcons) HICON *phicon, _Out_writes_opt_(nIcons) UINT *piconid, _In_ UINT nIcons, _In_ UINT flags)
unsigned short WORD
Definition: ntddk_ex.h:93
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
#define wcsicmp
Definition: string.h:1152
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define S_OK
Definition: intsafe.h:59
#define PATH_SEPARATOR
#define LR_COPYFROMRESOURCE
Definition: winuser.h:1089
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
HICON hIcon
Definition: msconfig.c:44
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define min(a, b)
Definition: monoChain.cc:55
static const WCHAR IconPath[]
Definition: install.c:51
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
const GUID IID_IPersistFile
HICON hIconSm
Definition: msconfig.c:44
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by ConSrvInitConsole().

◆ RemoveConsoleByPointer()

static NTSTATUS RemoveConsoleByPointer ( IN PCONSRV_CONSOLE  Console)
static

Definition at line 168 of file console.c.

169 {
170  ULONG i = 0;
171 
172  if (!Console) return STATUS_INVALID_PARAMETER;
173 
174  ASSERT( (ConsoleList == NULL && ConsoleListSize == 0) ||
175  (ConsoleList != NULL && ConsoleListSize != 0) );
176 
177  /* Remove the console from the list */
179 
180  if (ConsoleList)
181  {
182  for (i = 0; i < ConsoleListSize; i++)
183  {
184  if (ConsoleList[i] == Console) ConsoleList[i] = NULL;
185  }
186  }
187 
188  /* Unlock the console list and return */
190  return STATUS_SUCCESS;
191 }
static PCONSRV_CONSOLE * ConsoleList
Definition: console.c:34
static ULONG ConsoleListSize
Definition: console.c:33
#define ConSrvLockConsoleListExclusive()
Definition: console.c:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
#define ConSrvUnlockConsoleList()
Definition: console.c:44
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by ConSrvDeleteConsole().

Variable Documentation

◆ ConsoleList

PCONSRV_CONSOLE* ConsoleList
static

◆ ConsoleListSize

ULONG ConsoleListSize
static

◆ ListLock

RTL_RESOURCE ListLock
static

Definition at line 36 of file console.c.

Referenced by ConSrvInitConsoleSupport().