should improve situation for various bug reports
https://bugs.winehq.org/show_bug.cgi?id=52771 https://bugs.winehq.org/show_bug.cgi?id=52761 https://bugs.winehq.org/show_bug.cgi?id=52743 Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/kernelbase/console.c | 23 +++++++++++++++++++---- dlls/ntdll/unix/env.c | 2 ++ include/wine/condrv.h | 1 + server/process.c | 4 ++-- 4 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c index 046eee6147c..eddfa5f271e 100644 --- a/dlls/kernelbase/console.c +++ b/dlls/kernelbase/console.c @@ -86,6 +86,17 @@ 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) + { + static unsigned once; + if (!once) + { + FIXME("Incorrect access to Shell-no-window console\n"); + once = TRUE; + } + 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 +632,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 +2317,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 ); } diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 64117e70abe..2ead6c1fcc3 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -1684,6 +1684,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) { diff --git a/include/wine/condrv.h b/include/wine/condrv.h index 452ce552da1..94afb1d49c4 100644 --- a/include/wine/condrv.h +++ b/include/wine/condrv.h @@ -191,5 +191,6 @@ struct condrv_ctrl_event #define CONSOLE_HANDLE_ALLOC UlongToHandle(1) #define CONSOLE_HANDLE_ALLOC_NO_WINDOW UlongToHandle(2) #define CONSOLE_HANDLE_SHELL UlongToHandle(3) +#define CONSOLE_HANDLE_SHELL_NO_WINDOW UlongToHandle(5)
#endif /* _INC_CONDRV */ diff --git a/server/process.c b/server/process.c index 65e2aa70de2..d36ef463d60 100644 --- a/server/process.c +++ b/server/process.c @@ -1333,8 +1333,8 @@ DECL_HANDLER(new_process) /* connect to the window station */ connect_process_winstation( process, parent_thread, parent );
- /* set the process console */ - if (info->data->console > 3) + /* set the process console (caring also for CONSOLE_HANDLE_* values) */ + if (info->data->console > 5 || info->data->console == 4) info->data->console = duplicate_handle( parent, info->data->console, process, 0, 0, DUPLICATE_SAME_ACCESS );