ntdll: Do not perform base relocation if an image is not a DLL. Take 2

Dmitry Timoshkov dmitry at codeweavers.com
Thu Jan 17 07:05:25 CST 2008


Hello,

this patch fixes the problem reported in the bug 11170. It appears that
LoadLibrary in Windows doesn't attempt to relocate .exe files.

Alexandre noticed that previous version of the patch may break relocation of
the main exe. This version addresses that. However, this appears to be not
compatible with what Windows (does not) do: in order to force a relocation
of main under XP I set its base address to match the ntdll.dll (0x7c900000),
and XP just refused to load the exe with an error message "The system cannot
execute the specified program." But we may need to relocate main exe due to
environment limitations (some native .so file may be mapped at that address).

Changelog:
    ntdll: Do not perform base relocation if an image is not a DLL.
---
 dlls/ntdll/virtual.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index cbd524a..1c44d49 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1147,14 +1147,16 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
 
     /* perform base relocation, if necessary */
 
-    if (ptr != base)
+    if (ptr != base &&
+        ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) ||
+          !NtCurrentTeb()->Peb->ImageBaseAddress) )
     {
         const IMAGE_DATA_DIRECTORY *relocs;
 
         relocs = &nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
         if (nt->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)
         {
-            WARN( "Need to relocate module from addr %lx, but there are no relocation records\n",
+            WARN_(module)( "Need to relocate module from addr %lx, but there are no relocation records\n",
                   (ULONG_PTR)nt->OptionalHeader.ImageBase );
             status = STATUS_CONFLICTING_ADDRESSES;
             goto error;
@@ -1165,7 +1167,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
          *        Some DLLs really check the MSB of the module handle :-/
          */
         if ((nt->OptionalHeader.ImageBase & 0x80000000) && !((ULONG_PTR)base & 0x80000000))
-            ERR( "Forced to relocate system DLL (base > 2GB). This is not good.\n" );
+            ERR_(module)( "Forced to relocate system DLL (base > 2GB). This is not good.\n" );
 
         if (!do_relocations( ptr, relocs, ptr - base, total_size ))
         {
-- 
1.5.3.8






More information about the wine-patches mailing list