kernelbase: Create console connection in init_console.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-09-16 20:39:01 +02:00 committed by Alexandre Julliard
parent 7364a4b075
commit 74192f7a56
2 changed files with 22 additions and 4 deletions

View File

@ -54,6 +54,7 @@ static CRITICAL_SECTION_DEBUG critsect_debug =
};
static CRITICAL_SECTION console_section = { &critsect_debug, -1, 0, 0, 0, 0 };
static HANDLE console_connection;
static HANDLE console_wait_event;
static unsigned int console_flags;
@ -208,6 +209,21 @@ static HANDLE create_console_reference( HANDLE root )
return set_ntstatus( status ) ? handle : NULL;
}
static BOOL create_console_connection( HANDLE root )
{
OBJECT_ATTRIBUTES attr = {sizeof(attr)};
UNICODE_STRING string;
IO_STATUS_BLOCK iosb;
NTSTATUS status;
RtlInitUnicodeString( &string, root ? L"Connection" : L"\\Device\\ConDrv\\Connection" );
attr.RootDirectory = root;
attr.ObjectName = &string;
status = NtCreateFile( &console_connection, FILE_WRITE_PROPERTIES | FILE_READ_PROPERTIES | SYNCHRONIZE, &attr,
&iosb, NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0 );
return set_ntstatus( status );
}
static BOOL init_console_std_handles(void)
{
HANDLE std_out = NULL, std_err = NULL, handle;
@ -568,6 +584,9 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeConsole(void)
RtlEnterCriticalSection( &console_section );
NtClose( console_connection );
console_connection = NULL;
NtClose( RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle );
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
@ -1734,6 +1753,7 @@ void init_console( void )
if (RtlImageNtHeader( mod )->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
AllocConsole();
}
else if (params->ConsoleHandle) create_console_connection( params->ConsoleHandle );
RtlAddVectoredExceptionHandler( FALSE, handle_ctrl_c );
}

View File

@ -799,14 +799,12 @@ obj_handle_t inherit_console( struct thread *parent_thread, obj_handle_t handle,
{
struct console_input *console = NULL;
if (handle && !(console = (struct console_input *)get_handle_obj( current->process, handle, 0,
&console_input_ops )))
return 0;
if (handle) return duplicate_handle( current->process, handle, process, 0, 0, DUP_HANDLE_SAME_ACCESS );
/* if parent is a renderer, then attach current process to its console
* a bit hacky....
*/
if (!console && hconin && parent_thread)
if (hconin && parent_thread)
{
/* FIXME: should we check some access rights ? */
if (!(console = (struct console_input *)get_handle_obj( parent_thread->process, hconin,