Added patch to fix implementation of ntdll.MapViewOfSection.

This commit is contained in:
Sebastian Lackner 2015-08-11 07:15:21 +02:00
parent 03a15069bc
commit c97628a0e5
5 changed files with 276 additions and 36 deletions

View File

@ -39,9 +39,10 @@ Wine. All those differences are also documented on the
Included bug fixes and improvements
-----------------------------------
**Bug fixes and features included in the next upcoming release [3]:**
**Bug fixes and features included in the next upcoming release [4]:**
* Catch invalid memory accesses in imagehlp.CheckSumMappedFile
* Fix implementation of ntdll.MapViewOfSection
* Implement vcomp locking functions ([Wine Bug #26688](https://bugs.winehq.org/show_bug.cgi?id=26688))
* Properly implement imagehlp.ImageLoad and ImageUnload

1
debian/changelog vendored
View File

@ -1,6 +1,7 @@
wine-staging (1.7.50) UNRELEASED; urgency=low
* Add patch to implement remaining OpenMP locking functions.
* Added various patches for imagehlp cleanup (fixes Wine Staging Bug #502).
* Added patch to fix implementation of ntdll.MapViewOfSection.
-- Sebastian Lackner <sebastian@fds-team.de> Tue, 11 Aug 2015 06:12:14 +0200
wine-staging (1.7.49) unstable; urgency=low

View File

@ -0,0 +1,213 @@
From 804fe2821fb2e925df294f44f00a357fcdad384c Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Tue, 11 Aug 2015 07:03:49 +0200
Subject: ntdll: Separate image relocation from NtMapViewOfSection.
---
dlls/kernel32/tests/loader.c | 10 ------
dlls/ntdll/loader.c | 84 +++++++++++++++++++++++++++++++++++++++++++-
dlls/ntdll/virtual.c | 44 +----------------------
3 files changed, 84 insertions(+), 54 deletions(-)
diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c
index 89feeb9..25b7b08 100644
--- a/dlls/kernel32/tests/loader.c
+++ b/dlls/kernel32/tests/loader.c
@@ -799,15 +799,6 @@ static void test_image_mapping(const char *dll_name, DWORD scn_page_access, BOOL
size = 0;
status = pNtMapViewOfSection(hmap, GetCurrentProcess(), &addr2, 0, 0, &offset,
&size, 1 /* ViewShare */, 0, PAGE_READONLY);
- /* FIXME: remove once Wine is fixed */
- if (status != STATUS_IMAGE_NOT_AT_BASE)
- {
- todo_wine {
- ok(status == STATUS_IMAGE_NOT_AT_BASE, "expected STATUS_IMAGE_NOT_AT_BASE, got %x\n", status);
- ok(addr2 != 0, "mapped address should be valid\n");
- }
- goto wine_is_broken;
- }
ok(status == STATUS_IMAGE_NOT_AT_BASE, "expected STATUS_IMAGE_NOT_AT_BASE, got %x\n", status);
ok(addr2 != 0, "mapped address should be valid\n");
ok(addr2 != addr1, "mapped addresses should be different\n");
@@ -861,7 +852,6 @@ static void test_image_mapping(const char *dll_name, DWORD scn_page_access, BOOL
ok(ret, "FreeLibrary error %d\n", GetLastError());
}
-wine_is_broken:
status = pNtUnmapViewOfSection(GetCurrentProcess(), addr1);
ok(status == STATUS_SUCCESS, "NtUnmapViewOfSection error %x\n", status);
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index fb7b171..493e444 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -1656,6 +1656,79 @@ static void set_security_cookie( void *module, SIZE_T len )
}
}
+static NTSTATUS perform_relocations( void *module )
+{
+ IMAGE_NT_HEADERS *nt;
+ char *base;
+ IMAGE_BASE_RELOCATION *rel, *end;
+ const IMAGE_DATA_DIRECTORY *relocs;
+ const IMAGE_SECTION_HEADER *sec;
+ INT_PTR delta;
+ SIZE_T total_size;
+ ULONG protect_old[96], i;
+
+ nt = RtlImageNtHeader( module );
+ base = (char *)nt->OptionalHeader.ImageBase;
+
+ assert( module != base );
+
+ if (!(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && NtCurrentTeb()->Peb->ImageBaseAddress)
+ return STATUS_SUCCESS;
+
+ relocs = &nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
+
+ if ((nt->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) ||
+ !relocs->VirtualAddress || !relocs->Size)
+ {
+ WARN( "Need to relocate module from %p to %p, but there are no relocation records\n",
+ base, module );
+ return STATUS_CONFLICTING_ADDRESSES;
+ }
+
+ if (nt->FileHeader.NumberOfSections > sizeof(protect_old)/sizeof(protect_old[0]))
+ return STATUS_INVALID_IMAGE_FORMAT;
+
+ sec = (const IMAGE_SECTION_HEADER *)((const char *)&nt->OptionalHeader +
+ nt->FileHeader.SizeOfOptionalHeader);
+ for (i = 0; i < nt->FileHeader.NumberOfSections; i++)
+ {
+ void *addr = get_rva( module, sec[i].VirtualAddress );
+ total_size = sec[i].SizeOfRawData;
+ NtProtectVirtualMemory( NtCurrentProcess(), &addr,
+ &total_size, PAGE_READWRITE, &protect_old[i] );
+ }
+
+ total_size = nt->OptionalHeader.SizeOfImage;
+ TRACE( "relocating from %p-%p to %p-%p\n",
+ base, base + total_size, module, (char *)module + total_size );
+
+ rel = get_rva( module, relocs->VirtualAddress );
+ end = get_rva( module, relocs->VirtualAddress + relocs->Size );
+ delta = (char *)module - base;
+
+ while (rel < end - 1 && rel->SizeOfBlock)
+ {
+ if (rel->VirtualAddress >= total_size)
+ {
+ WARN( "invalid address %p in relocation %p\n", (char *)module + rel->VirtualAddress, rel );
+ return STATUS_ACCESS_VIOLATION;
+ }
+ rel = LdrProcessRelocationBlock( (char *)module + rel->VirtualAddress,
+ (rel->SizeOfBlock - sizeof(*rel)) / sizeof(USHORT),
+ (USHORT *)(rel + 1), delta );
+ if (!rel) return STATUS_INVALID_IMAGE_FORMAT;
+ }
+
+ for (i = 0; i < nt->FileHeader.NumberOfSections; i++)
+ {
+ void *addr = get_rva( module, sec[i].VirtualAddress );
+ total_size = sec[i].SizeOfRawData;
+ NtProtectVirtualMemory( NtCurrentProcess(), &addr,
+ &total_size, protect_old[i], NULL );
+ }
+
+ return STATUS_SUCCESS;
+}
/******************************************************************************
* load_native_dll (internal)
@@ -1681,7 +1754,16 @@ static NTSTATUS load_native_dll( LPCWSTR load_path, LPCWSTR name, HANDLE file,
module = NULL;
status = NtMapViewOfSection( mapping, NtCurrentProcess(),
&module, 0, 0, &size, &len, ViewShare, 0, PAGE_EXECUTE_READ );
- if (status < 0) goto done;
+
+ /* perform base relocation, if necessary */
+
+ if (status == STATUS_IMAGE_NOT_AT_BASE)
+ status = perform_relocations( module );
+ if (status != STATUS_SUCCESS)
+ {
+ if (module) NtUnmapViewOfSection( NtCurrentProcess(), module );
+ goto done;
+ }
/* create the MODREF */
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index fe17518..4d4bc3b 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1073,7 +1073,6 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
struct stat st;
struct file_view *view = NULL;
char *ptr, *header_end, *header_start;
- INT_PTR delta = 0;
/* zero-map the whole range */
@@ -1236,47 +1235,6 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
}
}
-
- /* perform base relocation, if necessary */
-
- if (ptr != base &&
- ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) ||
- !NtCurrentTeb()->Peb->ImageBaseAddress) )
- {
- IMAGE_BASE_RELOCATION *rel, *end;
- const IMAGE_DATA_DIRECTORY *relocs;
-
- if (nt->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)
- {
- WARN_(module)( "Need to relocate module from %p to %p, but there are no relocation records\n",
- base, ptr );
- status = STATUS_CONFLICTING_ADDRESSES;
- goto error;
- }
-
- TRACE_(module)( "relocating from %p-%p to %p-%p\n",
- base, base + total_size, ptr, ptr + total_size );
-
- relocs = &nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
- rel = (IMAGE_BASE_RELOCATION *)(ptr + relocs->VirtualAddress);
- end = (IMAGE_BASE_RELOCATION *)(ptr + relocs->VirtualAddress + relocs->Size);
- delta = ptr - base;
-
- while (rel < end - 1 && rel->SizeOfBlock)
- {
- if (rel->VirtualAddress >= total_size)
- {
- WARN_(module)( "invalid address %p in relocation %p\n", ptr + rel->VirtualAddress, rel );
- status = STATUS_ACCESS_VIOLATION;
- goto error;
- }
- rel = LdrProcessRelocationBlock( ptr + rel->VirtualAddress,
- (rel->SizeOfBlock - sizeof(*rel)) / sizeof(USHORT),
- (USHORT *)(rel + 1), delta );
- if (!rel) goto error;
- }
- }
-
/* set the image protections */
VIRTUAL_SetProt( view, ptr, ROUND_SIZE( 0, header_size ), VPROT_COMMITTED | VPROT_READ );
@@ -1313,7 +1271,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
*addr_ptr = ptr;
#ifdef VALGRIND_LOAD_PDB_DEBUGINFO
- VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, delta);
+ VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, ptr - base);
#endif
if (ptr != base) return STATUS_IMAGE_NOT_AT_BASE;
return STATUS_SUCCESS;
--
2.5.0

View File

@ -0,0 +1,2 @@
Fixes: Fix implementation of ntdll.MapViewOfSection
Depends: ntdll-Security_Cookie

View File

@ -173,6 +173,7 @@ patch_enable_all ()
enable_ntdll_Hide_Wine_Exports="$1"
enable_ntdll_Junction_Points="$1"
enable_ntdll_Loader_Machine_Type="$1"
enable_ntdll_NtMapViewOfSection="$1"
enable_ntdll_NtQueryEaFile="$1"
enable_ntdll_NtQuerySection="$1"
enable_ntdll_NtSetLdtEntries="$1"
@ -603,6 +604,9 @@ patch_enable ()
ntdll-Loader_Machine_Type)
enable_ntdll_Loader_Machine_Type="$2"
;;
ntdll-NtMapViewOfSection)
enable_ntdll_NtMapViewOfSection="$2"
;;
ntdll-NtQueryEaFile)
enable_ntdll_NtQueryEaFile="$2"
;;
@ -1753,6 +1757,13 @@ if test "$enable_ntdll_WriteWatches" -eq 1; then
enable_ws2_32_WriteWatches=1
fi
if test "$enable_ntdll_NtMapViewOfSection" -eq 1; then
if test "$enable_ntdll_Security_Cookie" -gt 1; then
abort "Patchset ntdll-Security_Cookie disabled, but ntdll-NtMapViewOfSection depends on that."
fi
enable_ntdll_Security_Cookie=1
fi
if test "$enable_ntdll_Junction_Points" -eq 1; then
if test "$enable_ntdll_Fix_Free" -gt 1; then
abort "Patchset ntdll-Fix_Free disabled, but ntdll-Junction_Points depends on that."
@ -3752,6 +3763,33 @@ if test "$enable_ntdll_Junction_Points" -eq 1; then
) >> "$patchlist"
fi
# Patchset ntdll-Security_Cookie
# |
# | This patchset fixes the following Wine bugs:
# | * [#39040] Move cookie initialization code from memory management to loader
# |
# | Modified files:
# | * dlls/ntdll/loader.c, dlls/ntdll/virtual.c
# |
if test "$enable_ntdll_Security_Cookie" -eq 1; then
patch_apply ntdll-Security_Cookie/0001-ntdll-Move-cookie-initialization-code-from-memory-ma.patch
(
echo '+ { "Sebastian Lackner", "ntdll: Move cookie initialization code from memory management to loader.", 1 },';
) >> "$patchlist"
fi
# Patchset ntdll-NtMapViewOfSection
# |
# | Modified files:
# | * dlls/kernel32/tests/loader.c, dlls/ntdll/loader.c, dlls/ntdll/virtual.c
# |
if test "$enable_ntdll_NtMapViewOfSection" -eq 1; then
patch_apply ntdll-NtMapViewOfSection/0001-ntdll-Separate-image-relocation-from-NtMapViewOfSect.patch
(
echo '+ { "Dmitry Timoshkov", "ntdll: Separate image relocation from NtMapViewOfSection.", 1 },';
) >> "$patchlist"
fi
# Patchset ntdll-NtQuerySection
# |
# | This patchset fixes the following Wine bugs:
@ -3818,21 +3856,6 @@ if test "$enable_ntdll_RtlIpStringToAddress" -eq 1; then
) >> "$patchlist"
fi
# Patchset ntdll-Security_Cookie
# |
# | This patchset fixes the following Wine bugs:
# | * [#39040] Move cookie initialization code from memory management to loader
# |
# | Modified files:
# | * dlls/ntdll/loader.c, dlls/ntdll/virtual.c
# |
if test "$enable_ntdll_Security_Cookie" -eq 1; then
patch_apply ntdll-Security_Cookie/0001-ntdll-Move-cookie-initialization-code-from-memory-ma.patch
(
echo '+ { "Sebastian Lackner", "ntdll: Move cookie initialization code from memory management to loader.", 1 },';
) >> "$patchlist"
fi
# Patchset ntdll-ThreadTime
# |
# | This patchset fixes the following Wine bugs:
@ -5059,6 +5082,18 @@ if test "$enable_wined3d_CSMT_Helper" -eq 1; then
) >> "$patchlist"
fi
# Patchset wined3d-MESA_GPU_Info
# |
# | Modified files:
# | * dlls/wined3d/directx.c, dlls/wined3d/wined3d_gl.h, dlls/winex11.drv/opengl.c, include/wine/wgl_driver.h
# |
if test "$enable_wined3d_MESA_GPU_Info" -eq 1; then
patch_apply wined3d-MESA_GPU_Info/0001-wined3d-Use-pci-and-memory-information-from-MESA-if-.patch
(
echo '+ { "Michael Müller", "wined3d: Use pci and memory information from MESA if possible.", 2 },';
) >> "$patchlist"
fi
# Patchset wined3d-Multisampling
# |
# | This patchset fixes the following Wine bugs:
@ -5131,21 +5166,6 @@ if test "$enable_wined3d_resource_check_usage" -eq 1; then
) >> "$patchlist"
fi
# Patchset wined3d-Geforce_425M
# |
# | This patchset fixes the following Wine bugs:
# | * [#35054] Add wined3d detection for GeForce GT 425M
# |
# | Modified files:
# | * dlls/wined3d/directx.c, dlls/wined3d/wined3d_private.h
# |
if test "$enable_wined3d_Geforce_425M" -eq 1; then
patch_apply wined3d-Geforce_425M/0001-wined3d-Add-detection-for-NVIDIA-GeForce-425M.patch
(
echo '+ { "Jarkko Korpi", "wined3d: Add detection for NVIDIA GeForce 425M.", 1 },';
) >> "$patchlist"
fi
# Patchset wined3d-wined3d_swapchain_present
# |
# | Modified files:
@ -5158,15 +5178,18 @@ if test "$enable_wined3d_wined3d_swapchain_present" -eq 1; then
) >> "$patchlist"
fi
# Patchset wined3d-MESA_GPU_Info
# Patchset wined3d-Geforce_425M
# |
# | This patchset fixes the following Wine bugs:
# | * [#35054] Add wined3d detection for GeForce GT 425M
# |
# | Modified files:
# | * dlls/wined3d/directx.c, dlls/wined3d/wined3d_gl.h, dlls/winex11.drv/opengl.c, include/wine/wgl_driver.h
# | * dlls/wined3d/directx.c, dlls/wined3d/wined3d_private.h
# |
if test "$enable_wined3d_MESA_GPU_Info" -eq 1; then
patch_apply wined3d-MESA_GPU_Info/0001-wined3d-Use-pci-and-memory-information-from-MESA-if-.patch
if test "$enable_wined3d_Geforce_425M" -eq 1; then
patch_apply wined3d-Geforce_425M/0001-wined3d-Add-detection-for-NVIDIA-GeForce-425M.patch
(
echo '+ { "Michael Müller", "wined3d: Use pci and memory information from MESA if possible.", 2 },';
echo '+ { "Jarkko Korpi", "wined3d: Add detection for NVIDIA GeForce 425M.", 1 },';
) >> "$patchlist"
fi