Jacek Caban : kernelbase: Create console connection in init_console.

Alexandre Julliard julliard at winehq.org
Wed Sep 16 15:37:33 CDT 2020


Module: wine
Branch: master
Commit: 74192f7a56c319c1a9cadb67a3dd3305c965292d
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=74192f7a56c319c1a9cadb67a3dd3305c965292d

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 16 20:39:01 2020 +0200

kernelbase: Create console connection in init_console.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernelbase/console.c | 20 ++++++++++++++++++++
 server/console.c          |  6 ++----
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/dlls/kernelbase/console.c b/dlls/kernelbase/console.c
index f4dd06ae2d..eff63a29a1 100644
--- a/dlls/kernelbase/console.c
+++ b/dlls/kernelbase/console.c
@@ -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 );
 }
diff --git a/server/console.c b/server/console.c
index 108371080e..50698a727f 100644
--- a/server/console.c
+++ b/server/console.c
@@ -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,




More information about the wine-cvs mailing list