Alexandre Julliard : ntdll: Move the console handle initialization to the Unix library.

Alexandre Julliard julliard at winehq.org
Mon Jun 29 14:59:20 CDT 2020


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Jun 29 10:39:27 2020 +0200

ntdll: Move the console handle initialization to the Unix library.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/env.c               | 10 ++--------
 dlls/ntdll/unix/env.c          | 15 +++++++++++++++
 dlls/ntdll/unix/loader.c       |  1 +
 dlls/ntdll/unix/unix_private.h |  1 +
 dlls/ntdll/unixlib.h           |  4 +++-
 5 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c
index a72fc6943d..a68ef5786e 100644
--- a/dlls/ntdll/env.c
+++ b/dlls/ntdll/env.c
@@ -1286,14 +1286,8 @@ void init_user_process_params( SIZE_T data_size )
         RtlFreeUnicodeString( &cmdline );
         RtlReleasePath( load_path );
 
-        if (isatty(0) || isatty(1) || isatty(2))
-            params->ConsoleHandle = (HANDLE)2; /* see kernel32/kernel_private.h */
-        if (!isatty(0))
-            wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE,  OBJ_INHERIT, &params->hStdInput );
-        if (!isatty(1))
-            wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, &params->hStdOutput );
-        if (!isatty(2))
-            wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, &params->hStdError );
+        unix_funcs->get_initial_console( &params->ConsoleHandle, &params->hStdInput,
+                                         &params->hStdOutput, &params->hStdError );
         params->wShowWindow = 1; /* SW_SHOWNORMAL */
 
         run_wineboot( &params->Environment );
diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c
index 7bf57a228f..1ffe45ea3b 100644
--- a/dlls/ntdll/unix/env.c
+++ b/dlls/ntdll/unix/env.c
@@ -954,6 +954,21 @@ NTSTATUS CDECL get_dynamic_environment( WCHAR *env, SIZE_T *size )
 }
 
 
+/*************************************************************************
+ *		get_initial_console
+ *
+ * Return the initial console handles.
+ */
+void CDECL get_initial_console( HANDLE *handle, HANDLE *std_in, HANDLE *std_out, HANDLE *std_err )
+{
+    *handle = *std_in = *std_out = *std_err = 0;
+    if (isatty(0) || isatty(1) || isatty(2)) *handle = (HANDLE)2; /* see kernel32/kernel_private.h */
+    if (!isatty(0)) server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE,  OBJ_INHERIT, std_in );
+    if (!isatty(1)) server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, std_out );
+    if (!isatty(2)) server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, std_err );
+}
+
+
 /*************************************************************************
  *		get_initial_directory
  *
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index be71498343..892ff10c35 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -1491,6 +1491,7 @@ static struct unix_funcs unix_funcs =
     ntdll_tan,
     get_initial_environment,
     get_dynamic_environment,
+    get_initial_console,
     get_initial_directory,
     get_unix_codepage,
     get_locales,
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index fe63606ed8..d6a15d5f7b 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -99,6 +99,7 @@ int  CDECL mmap_enum_reserved_areas( int (CDECL *enum_func)(void *base, SIZE_T s
 extern NTSTATUS CDECL get_initial_environment( WCHAR **wargv[], WCHAR *env, SIZE_T *size ) DECLSPEC_HIDDEN;
 extern NTSTATUS CDECL get_dynamic_environment( WCHAR *env, SIZE_T *size ) DECLSPEC_HIDDEN;
 extern void CDECL get_initial_directory( UNICODE_STRING *dir ) DECLSPEC_HIDDEN;
+extern void CDECL get_initial_console( HANDLE *handle, HANDLE *std_in, HANDLE *std_out, HANDLE *std_err ) DECLSPEC_HIDDEN;
 extern void CDECL get_unix_codepage( CPTABLEINFO *table ) DECLSPEC_HIDDEN;
 extern void CDECL get_locales( WCHAR *sys, WCHAR *user ) DECLSPEC_HIDDEN;
 extern NTSTATUS CDECL virtual_map_section( HANDLE handle, PVOID *addr_ptr, unsigned short zero_bits_64, SIZE_T commit_size,
diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h
index cec36b58c0..88010b695e 100644
--- a/dlls/ntdll/unixlib.h
+++ b/dlls/ntdll/unixlib.h
@@ -29,7 +29,7 @@ struct msghdr;
 struct _DISPATCHER_CONTEXT;
 
 /* increment this when you change the function table */
-#define NTDLL_UNIXLIB_VERSION 64
+#define NTDLL_UNIXLIB_VERSION 65
 
 struct unix_funcs
 {
@@ -300,6 +300,8 @@ struct unix_funcs
     /* environment functions */
     NTSTATUS      (CDECL *get_initial_environment)( WCHAR **wargv[], WCHAR *env, SIZE_T *size );
     NTSTATUS      (CDECL *get_dynamic_environment)( WCHAR *env, SIZE_T *size );
+    void          (CDECL *get_initial_console)( HANDLE *handle, HANDLE *std_in,
+                                                HANDLE *std_out, HANDLE *std_err );
     void          (CDECL *get_initial_directory)( UNICODE_STRING *dir );
     void          (CDECL *get_unix_codepage)( CPTABLEINFO *table );
     void          (CDECL *get_locales)( WCHAR *sys, WCHAR *user );




More information about the wine-cvs mailing list