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 | 18 ++++++++++++++---- dlls/ntdll/unix/env.c | 2 ++ include/wine/condrv.h | 1 + 3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c index 046eee6147c..e298e940148 100644 --- a/dlls/kernelbase/console.c +++ b/dlls/kernelbase/console.c @@ -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=%x)\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 ); } 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 2d763d0b821..3355d7177b0 100644 --- a/include/wine/condrv.h +++ b/include/wine/condrv.h @@ -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 */