CVS: winex/loader pe_image.c,1.19,1.20

[email protected] 31 Jul 2007 19:48:57 -0000
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/loader pe_image.c,1.19,1.20Update of /var/lib/cvsd/cvsroot/winex/loader
In directory agravaine:/tmp/cvs-serv759/loader

Modified Files:
	pe_image.c 
Log Message:

Trac #60

When importing DLLs in PE_fixup_imports, try to import all the DLLs referenced
by the DLL we are loading, don't just stop at the first failure. If any DLLs
can't load, this will cause PE_fixup_imports to return with failure, AFTER it
attempts to load all the DLLs imported by the DLL being loaded. This appears
to be Windows behavior, and some programs unsconsciously depend on it - A
imports B imports C, and A also imports C. B can load C, but for some reason A
can't. If B doesn't load C when it has the chance, A can't load (find) C. In
case B can't load because it's missing D, and A doesn't really need B, but
does need C, if B fails while trying to load D before loading C, A is stuck
without C, and the program fails, or behaves differently than it would on
Windows.


Index: pe_image.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/loader/pe_image.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- pe_image.c	29 Mar 2007 14:03:19 -0000	1.19
+++ pe_image.c	31 Jul 2007 19:48:55 -0000	1.20
@@ -263,6 +263,7 @@
     unsigned int load_addr	= wm->module;
     int				i,characteristics_detection=1;
     IMAGE_IMPORT_DESCRIPTOR *imports = get_imports(wm->module);
+    int r = 0;
 
     /* first, count the number of imported non-internal modules */
     pe_imp = imports;
@@ -304,7 +305,11 @@
 	wmImp = MODULE_LoadLibraryExA( name, 0, 0 );
 	if (!wmImp) {
 	    ERR_(module)("Module (file) %s (which is needed by %s) not found\n", name, wm->filename);
-	    return 1;
+	    /* We will fail the load, but import all the DLLs we can. */
+	    /* Someone else might need one of the DLLs we import, but */
+	    /* not be able to import it themselves. */
+	    r = 1;
+	    continue;
 	}
         wm->deps[i++] = wmImp;
 
@@ -386,7 +391,7 @@
 	    }
 	}
     }
-    return 0;
+    return r;
 }
 
 /***********************************************************************