kernelbase: Provide a pseudo console environment for initial CUI processes not tied to a Unix tty.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52771
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52761
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52743
Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Eric Pouech 2022-04-11 15:05:09 +02:00 committed by Alexandre Julliard
parent 95202ea4da
commit eff83cd4e0
3 changed files with 17 additions and 4 deletions

View File

@ -86,6 +86,12 @@ static BOOL console_ioctl( HANDLE handle, DWORD code, void *in_buff, DWORD in_co
IO_STATUS_BLOCK io;
NTSTATUS status;
if (handle == CONSOLE_HANDLE_SHELL_NO_WINDOW)
{
WARN("Incorrect access to Shell-no-window console (ioctl=%lx)\n", code);
SetLastError( ERROR_INVALID_ACCESS );
return FALSE;
}
status = NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io, code, in_buff, in_count,
out_buff, out_count );
switch( status )
@ -621,10 +627,13 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeConsole(void)
{
RtlEnterCriticalSection( &console_section );
NtClose( console_connection );
console_connection = NULL;
if (RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != CONSOLE_HANDLE_SHELL_NO_WINDOW)
{
NtClose( console_connection );
console_connection = NULL;
NtClose( RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle );
NtClose( RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle );
}
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
if (console_flags & CONSOLE_INPUT_HANDLE) NtClose( GetStdHandle( STD_INPUT_HANDLE ));
@ -2303,5 +2312,6 @@ void init_console( void )
if (RtlImageNtHeader( mod )->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
alloc_console( no_window );
}
else if (params->ConsoleHandle) create_console_connection( params->ConsoleHandle );
else if (params->ConsoleHandle && params->ConsoleHandle != CONSOLE_HANDLE_SHELL_NO_WINDOW)
create_console_connection( params->ConsoleHandle );
}

View File

@ -1354,6 +1354,8 @@ static void get_initial_console( RTL_USER_PROCESS_PARAMETERS *params )
params->hStdOutput = (HANDLE)((UINT_PTR)params->hStdOutput | 1);
output_fd = 1;
}
if (!params->ConsoleHandle && main_image_info.SubSystemType == IMAGE_SUBSYSTEM_WINDOWS_CUI)
params->ConsoleHandle = CONSOLE_HANDLE_SHELL_NO_WINDOW;
if (output_fd != -1)
{

View File

@ -191,5 +191,6 @@ struct condrv_ctrl_event
#define CONSOLE_HANDLE_ALLOC LongToHandle(-1)
#define CONSOLE_HANDLE_ALLOC_NO_WINDOW LongToHandle(-2)
#define CONSOLE_HANDLE_SHELL LongToHandle(-3)
#define CONSOLE_HANDLE_SHELL_NO_WINDOW LongToHandle(-4)
#endif /* _INC_CONDRV */