[PATCH 1/2] loader: always ensure that WINELOADER is defined

Eric Pouech eric.pouech at gmail.com
Tue Nov 23 12:12:32 CST 2021


when:
- Wine is installed in a (configure:d) directory
- running wine directly from <confdir>/bin/wine(64)
  (without setting any WINE specific env variables)
- dbghelp cannot find back the loader/wine(64) file

consequences:
- dbghelp cannot get back to the ELF information, hence
  (on a live target) doesn't report the already loaded ELF modules
  (only the PE ones are listed)

dbghelp searches:
- WINELOADER env var (but it isn't set in that case)
- LD_LIBRARY_PATH (isn't changed, and even if it would,
  it would point to <confdir>/lib directory)
- WINEDLLDIR<NN>, but again could point to <confdir>/lib
  directory, not the bin one

wine-staging has a solution by forcing dbghelp to search @bindir@ as well

this patch proposes an alternate approach: the wine loader sets WINELOADER
if it isn't already set by the calling environment

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 loader/main.c |   20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/loader/main.c b/loader/main.c
index 242ff15accd..c5e0fdf68b2 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -41,18 +41,12 @@ extern char **environ;
 /* the preloader will set this variable */
 const struct wine_preload_info *wine_main_preload_info = NULL;
 
-/* canonicalize path and return its directory name */
-static char *realpath_dirname( const char *name )
+/* remove filename from an (absolute) path */
+static void remove_filename( char *fullpath )
 {
-    char *p, *fullpath = realpath( name, NULL );
-
-    if (fullpath)
-    {
-        p = strrchr( fullpath, '/' );
-        if (p == fullpath) p++;
-        if (p) *p = 0;
-    }
-    return fullpath;
+    char *p = strrchr( fullpath, '/' );
+    if (p == fullpath) p++;
+    if (p) *p = 0;
 }
 
 /* if string ends with tail, remove it */
@@ -141,8 +135,10 @@ static void *load_ntdll( char *argv0 )
     char *path, *p;
     void *handle = NULL;
 
-    if (self && ((path = realpath_dirname( self ))))
+    if (self && (path = realpath( self, NULL )))
     {
+        setenv( "WINELOADER", path, 0 );
+        remove_filename( path );
         if ((p = remove_tail( path, "/loader" )))
         {
             handle = try_dlopen( p, "dlls/ntdll/ntdll.so" );




More information about the wine-devel mailing list