Module: wine Branch: master Commit: 3e0c90e4c700d79124c6a7a14050799baa531879 URL: https://source.winehq.org/git/wine.git/?a=commit;h=3e0c90e4c700d79124c6a7a14...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Apr 27 12:35:19 2020 +0200
ntdll: Avoid using wine_get_build/data_dir() from libwine.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/Makefile.in | 7 +++++ dlls/ntdll/env.c | 4 +-- dlls/ntdll/loader.c | 2 +- dlls/ntdll/locale.c | 3 --- dlls/ntdll/ntdll_misc.h | 3 +++ dlls/ntdll/process.c | 2 +- dlls/ntdll/server.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++-- dlls/ntdll/thread.c | 1 + 8 files changed, 83 insertions(+), 9 deletions(-)
diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index a67809a6c2..7971ef98cf 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -56,3 +56,10 @@ C_SRCS = \ wcstring.c
RC_SRCS = version.rc + +server_EXTRADEFS = \ + -DBINDIR="${bindir}" \ + -DDLLDIR="${dlldir}" \ + -DBIN_TO_DLLDIR="`$(MAKEDEP) -R ${bindir} ${dlldir}`" \ + -DDLL_TO_BINDIR="`$(MAKEDEP) -R ${dlldir} ${bindir}`" \ + -DBIN_TO_DATADIR="`$(MAKEDEP) -R ${bindir} ${datadir}/wine`" diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index ff0c8fbe90..eabebbcc28 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -408,9 +408,9 @@ static void set_wow64_environment( WCHAR **env )
/* set the Wine paths */
- set_wine_path_variable( env, winedatadirW, wine_get_data_dir() ); + set_wine_path_variable( env, winedatadirW, data_dir ); set_wine_path_variable( env, winehomedirW, home ); - set_wine_path_variable( env, winebuilddirW, wine_get_build_dir() ); + set_wine_path_variable( env, winebuilddirW, build_dir ); set_wine_path_variable( env, wineconfigdirW, config_dir ); for (i = 0; (p = wine_dll_enum_load_path( i )); i++) { diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 38c893e3eb..4d69e33b09 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2715,7 +2715,7 @@ static NTSTATUS find_builtin_dll( const WCHAR *name, WINE_MODREF **pwm, void **module, pe_image_info_t *image_info, struct stat *st, char **so_name ) { - const char *path, *build_dir = wine_get_build_dir(); + const char *path; unsigned int i, pos, len, namelen, maxlen = 0; char *ptr, *file; NTSTATUS status = STATUS_DLL_NOT_FOUND; diff --git a/dlls/ntdll/locale.c b/dlls/ntdll/locale.c index a28f5d0f58..0d0c1194d2 100644 --- a/dlls/ntdll/locale.c +++ b/dlls/ntdll/locale.c @@ -39,7 +39,6 @@ #include "winbase.h" #include "winnls.h" #include "ntdll_misc.h" -#include "wine/library.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(nls); @@ -758,8 +757,6 @@ static const struct { const char *name; UINT cp; } charset_names[] =
static void load_unix_cptable( unsigned int cp ) { - const char *build_dir = wine_get_build_dir(); - const char *data_dir = wine_get_data_dir(); const char *dir = build_dir ? build_dir : data_dir; struct stat st; char *name; diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 11ff0d7bb3..fc12bf47ef 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -96,6 +96,7 @@ extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN; extern void init_unix_codepage(void) DECLSPEC_HIDDEN; extern void init_locale( HMODULE module ) DECLSPEC_HIDDEN; extern void init_user_process_params( SIZE_T data_size ) DECLSPEC_HIDDEN; +extern void init_paths(void) DECLSPEC_HIDDEN; extern char **build_envp( const WCHAR *envW ) DECLSPEC_HIDDEN; extern NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status ) DECLSPEC_HIDDEN;
@@ -104,6 +105,8 @@ extern char **__wine_main_argv; extern WCHAR **__wine_main_wargv;
/* server support */ +extern const char *build_dir DECLSPEC_HIDDEN; +extern const char *data_dir DECLSPEC_HIDDEN; extern const char *config_dir DECLSPEC_HIDDEN; extern timeout_t server_start_time DECLSPEC_HIDDEN; extern unsigned int server_cpus DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index 28aa671f47..d2a3421ac5 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -1008,7 +1008,7 @@ static const char *get_alternate_loader( char **ret_env )
*ret_env = NULL;
- if (wine_get_build_dir()) loader = is_win64 ? "loader/wine" : "loader/wine64"; + if (build_dir) loader = is_win64 ? "loader/wine" : "loader/wine64";
if (loader_env) { diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c index d15ece3f4e..429a41c397 100644 --- a/dlls/ntdll/server.c +++ b/dlls/ntdll/server.c @@ -113,8 +113,11 @@ static const enum cpu_type client_cpu = CPU_ARM64; #error Unsupported CPU #endif
+const char *build_dir = NULL; +const char *data_dir = NULL; const char *config_dir = NULL; static const char *server_dir; +static const char *bin_dir;
unsigned int server_cpus = 0; BOOL is_wow64 = FALSE; @@ -177,6 +180,35 @@ static void fatal_perror( const char *err, ... ) exit(1); }
+/* canonicalize path and return its directory name */ +static char *realpath_dirname( const char *name ) +{ + char *p, *fullpath = realpath( name, NULL ); + + if (fullpath) + { + p = strrchr( fullpath, '/' ); + if (p == fullpath) p++; + if (p) *p = 0; + } + return fullpath; +} + +/* if string ends with tail, remove it */ +static char *remove_tail( const char *str, const char *tail ) +{ + size_t len = strlen( str ); + size_t tail_len = strlen( tail ); + char *ret; + + if (len < tail_len) return NULL; + if (strcmp( str + len - tail_len, tail )) return NULL; + ret = malloc( len - tail_len + 1 ); + memcpy( ret, str, len - tail_len ); + ret[len - tail_len] = 0; + return ret; +} + /* build a path from the specified dir and name */ static char *build_path( const char *dir, const char *name ) { @@ -1279,6 +1311,42 @@ static const char *init_config_dir(void) }
+/*********************************************************************** + * init_paths + */ +void init_paths(void) +{ + const char *dll_dir = NULL; + +#ifdef HAVE_DLADDR + Dl_info info; + + if (dladdr( init_paths, &info ) && info.dli_fname[0] == '/') + dll_dir = realpath_dirname( info.dli_fname ); +#endif + +#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) + bin_dir = realpath_dirname( "/proc/self/exe" ); +#elif defined (__FreeBSD__) || defined(__DragonFly__) + bin_dir = realpath_dirname( "/proc/curproc/file" ); +#else + bin_dir = realpath_dirname( __wine_main_argv[0] ); +#endif + + if (dll_dir) build_dir = remove_tail( dll_dir, "/dlls/ntdll" ); + else if (bin_dir) build_dir = remove_tail( bin_dir, "/loader" ); + + if (!build_dir) + { + if (!bin_dir) bin_dir = dll_dir ? build_path( dll_dir, DLL_TO_BINDIR ) : BINDIR; + else if (!dll_dir) dll_dir = build_path( bin_dir, BIN_TO_DLLDIR ); + data_dir = build_path( bin_dir, BIN_TO_DATADIR ); + } + + config_dir = init_config_dir(); +} + + /*********************************************************************** * setup_config_dir * @@ -1524,8 +1592,6 @@ void server_init_process(void) obj_handle_t version; const char *env_socket = getenv( "WINESERVERSOCKET" );
- config_dir = init_config_dir(); - server_pid = -1; if (env_socket) { diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index e27b3a0c6d..73b5c9ebca 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -299,6 +299,7 @@ TEB *thread_init(void) signal_init_thread( teb ); virtual_init_threading(); debug_init(); + init_paths(); set_process_name( __wine_main_argc, __wine_main_argv );
/* initialize time values in user_shared_data */