Alexandre Julliard : kernel32: Move Unix environment initialization to ntdll.
Alexandre Julliard
julliard at winehq.org
Tue Oct 22 16:57:00 CDT 2019
Module: wine
Branch: master
Commit: a511057f7e27ebac54fbe43e2ed4f394cae5bef2
URL: https://source.winehq.org/git/wine.git/?a=commit;h=a511057f7e27ebac54fbe43e2ed4f394cae5bef2
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Oct 22 10:04:51 2019 +0200
kernel32: Move Unix environment initialization to ntdll.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/kernel32/process.c | 58 +--------------------------------------
dlls/ntdll/env.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 57 deletions(-)
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 1f71a848a3..d03d147d95 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -66,13 +66,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(process);
WINE_DECLARE_DEBUG_CHANNEL(relay);
-#ifdef __APPLE__
-extern char **__wine_get_main_environment(void);
-#else
-extern char **__wine_main_environ;
-static char **__wine_get_main_environment(void) { return __wine_main_environ; }
-#endif
-
typedef struct
{
LPSTR lpEnvAddress;
@@ -455,52 +448,6 @@ static BOOL find_exe_file( const WCHAR *name, WCHAR *buffer, int buflen, HANDLE
}
-/***********************************************************************
- * build_initial_environment
- *
- * Build the Win32 environment from the Unix environment
- */
-static BOOL build_initial_environment(void)
-{
- SIZE_T size = 1;
- char **e;
- WCHAR *p, *endptr;
- void *ptr;
- char **env = __wine_get_main_environment();
-
- /* Compute the total size of the Unix environment */
- for (e = env; *e; e++)
- {
- if (is_special_env_var( *e )) continue;
- size += MultiByteToWideChar( CP_UNIXCP, 0, *e, -1, NULL, 0 );
- }
- size *= sizeof(WCHAR);
-
- if (!(ptr = RtlAllocateHeap( GetProcessHeap(), 0, size ))) return FALSE;
- NtCurrentTeb()->Peb->ProcessParameters->Environment = p = ptr;
- endptr = p + size / sizeof(WCHAR);
-
- /* And fill it with the Unix environment */
- for (e = env; *e; e++)
- {
- char *str = *e;
-
- /* skip Unix special variables and use the Wine variants instead */
- if (!strncmp( str, "WINE", 4 ))
- {
- if (is_special_env_var( str + 4 )) str += 4;
- else if (!strncmp( str, "WINEPRELOADRESERVE=", 19 )) continue; /* skip it */
- }
- else if (is_special_env_var( str )) continue; /* skip it */
-
- MultiByteToWideChar( CP_UNIXCP, 0, str, -1, p, endptr - p );
- p += strlenW(p) + 1;
- }
- *p = 0;
- return TRUE;
-}
-
-
/***********************************************************************
* set_registry_variables
*
@@ -1255,11 +1202,8 @@ void * CDECL __wine_kernel_init(void)
LOCALE_Init();
- if (!params->Environment)
+ if (!peb->ProcessParameters->WindowTitle.Buffer)
{
- /* Copy the parent environment */
- if (!build_initial_environment()) exit(1);
-
/* convert old configuration to new format */
convert_old_config();
diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c
index 7b5f370083..64bd9b15a3 100644
--- a/dlls/ntdll/env.c
+++ b/dlls/ntdll/env.c
@@ -35,6 +35,7 @@
#define WIN32_NO_STATUS
#include "windef.h"
#include "winternl.h"
+#include "wine/library.h"
#include "wine/unicode.h"
#include "wine/debug.h"
#include "ntdll_misc.h"
@@ -55,6 +56,76 @@ static inline SIZE_T get_env_length( const WCHAR *env )
return end + 1 - env;
}
+#ifdef __APPLE__
+extern char **__wine_get_main_environment(void);
+#else
+extern char **__wine_main_environ;
+static char **__wine_get_main_environment(void) { return __wine_main_environ; }
+#endif
+
+
+/***********************************************************************
+ * is_special_env_var
+ *
+ * Check if an environment variable needs to be handled specially when
+ * passed through the Unix environment (i.e. prefixed with "WINE").
+ */
+static inline BOOL is_special_env_var( const char *var )
+{
+ return (!strncmp( var, "PATH=", sizeof("PATH=")-1 ) ||
+ !strncmp( var, "PWD=", sizeof("PWD=")-1 ) ||
+ !strncmp( var, "HOME=", sizeof("HOME=")-1 ) ||
+ !strncmp( var, "TEMP=", sizeof("TEMP=")-1 ) ||
+ !strncmp( var, "TMP=", sizeof("TMP=")-1 ) ||
+ !strncmp( var, "QT_", sizeof("QT_")-1 ) ||
+ !strncmp( var, "VK_", sizeof("VK_")-1 ));
+}
+
+
+/***********************************************************************
+ * build_initial_environment
+ *
+ * Build the Win32 environment from the Unix environment
+ */
+static WCHAR *build_initial_environment( char **env )
+{
+ SIZE_T size = 1;
+ char **e;
+ WCHAR *p, *ptr;
+
+ /* compute the total size of the Unix environment */
+
+ for (e = env; *e; e++)
+ {
+ if (is_special_env_var( *e )) continue;
+ size += ntdll_umbstowcs( 0, *e, strlen(*e) + 1, NULL, 0 );
+ }
+
+ if (!(ptr = RtlAllocateHeap( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return NULL;
+ p = ptr;
+
+ /* and fill it with the Unix environment */
+
+ for (e = env; *e; e++)
+ {
+ char *str = *e;
+
+ /* skip Unix special variables and use the Wine variants instead */
+ if (!strncmp( str, "WINE", 4 ))
+ {
+ if (is_special_env_var( str + 4 )) str += 4;
+ else if (!strncmp( str, "WINEPRELOADRESERVE=", 19 )) continue; /* skip it */
+ }
+ else if (is_special_env_var( str )) continue; /* skip it */
+
+ ntdll_umbstowcs( 0, str, strlen(str) + 1, p, size - (p - ptr) );
+ p += strlenW(p) + 1;
+ }
+ *p = 0;
+ return ptr;
+}
+
+
/***********************************************************************
* get_current_directory
*
@@ -644,6 +715,7 @@ void init_user_process_params( SIZE_T data_size )
return;
NtCurrentTeb()->Peb->ProcessParameters = params;
+ params->Environment = build_initial_environment( __wine_get_main_environment() );
get_current_directory( ¶ms->CurrentDirectory.DosPath );
if (isatty(0) || isatty(1) || isatty(2))
More information about the wine-cvs
mailing list