Alexandre Julliard : ntdll: Map the PE header up to the specified
size, and clear the rest of the page.
Alexandre Julliard
julliard at wine.codeweavers.com
Wed Dec 13 10:03:50 CST 2006
Module: wine
Branch: master
Commit: 3dc21d387ba3506275a775ba79663ecf88e794a9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=3dc21d387ba3506275a775ba79663ecf88e794a9
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Dec 13 13:06:12 2006 +0100
ntdll: Map the PE header up to the specified size, and clear the rest of the page.
---
dlls/kernel32/tests/loader.c | 6 ------
dlls/ntdll/virtual.c | 9 ++++++---
server/mapping.c | 4 ++--
3 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c
index 48771ba..7ae70f3 100644
--- a/dlls/kernel32/tests/loader.c
+++ b/dlls/kernel32/tests/loader.c
@@ -360,12 +360,6 @@ START_TEST(loader)
start = (const char *)hlib + nt_header.OptionalHeader.SizeOfHeaders;
size = ALIGN_SIZE((ULONG_PTR)start, si.dwPageSize) - (ULONG_PTR)start;
- /* remove next 'if' and todo_wine once Wine is fixed */
- if (nt_header.OptionalHeader.SizeOfHeaders < nt_header.OptionalHeader.FileAlignment)
- {
-todo_wine ok(!memcmp(start, filler, size), "%d: header alignment is not cleared\n", i);
- }
- else
ok(!memcmp(start, filler, size), "%d: header alignment is not cleared\n", i);
}
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 2b1ff24..ff16adc 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -974,11 +974,12 @@ static NTSTATUS map_image( HANDLE hmappi
status = STATUS_INVALID_IMAGE_FORMAT; /* generic error */
if (!st.st_size) goto error;
header_size = min( header_size, st.st_size );
- if (map_file_into_view( view, fd, 0, header_size, 0, VPROT_COMMITTED | VPROT_READ,
+ if (map_file_into_view( view, fd, 0, header_size, 0, VPROT_COMMITTED | VPROT_READ | VPROT_WRITECOPY,
removable ) != STATUS_SUCCESS) goto error;
dos = (IMAGE_DOS_HEADER *)ptr;
nt = (IMAGE_NT_HEADERS *)(ptr + dos->e_lfanew);
header_end = ptr + ROUND_SIZE( 0, header_size );
+ memset( ptr + header_size, 0, header_end - (ptr + header_size) );
if ((char *)(nt + 1) > header_end) goto error;
sec = (IMAGE_SECTION_HEADER*)((char*)&nt->OptionalHeader+nt->FileHeader.SizeOfOptionalHeader);
if ((char *)(sec + nt->FileHeader.NumberOfSections) > header_end) goto error;
@@ -1067,8 +1068,8 @@ static NTSTATUS map_image( HANDLE hmappi
end = sec->VirtualAddress + ROUND_SIZE( sec->VirtualAddress, map_size );
if (sec->VirtualAddress > total_size || end > total_size || end < sec->VirtualAddress)
{
- ERR_(module)( "Section %.8s too large (%x+%lx/%lx)\n",
- sec->Name, sec->VirtualAddress, map_size, total_size );
+ WARN_(module)( "Section %.8s too large (%x+%lx/%lx)\n",
+ sec->Name, sec->VirtualAddress, map_size, total_size );
goto error;
}
@@ -1166,6 +1167,8 @@ static NTSTATUS map_image( HANDLE hmappi
/* set the image protections */
+ VIRTUAL_SetProt( view, ptr, ROUND_SIZE( 0, header_size ), VPROT_COMMITTED | VPROT_READ );
+
sec = (IMAGE_SECTION_HEADER*)((char *)&nt->OptionalHeader+nt->FileHeader.SizeOfOptionalHeader);
for (i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++)
{
diff --git a/server/mapping.c b/server/mapping.c
index d526e75..052ea41 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -243,11 +243,11 @@ static int get_image_params( struct mapp
mapping->size = ROUND_SIZE( nt.OptionalHeader.SizeOfImage );
mapping->base = (void *)nt.OptionalHeader.ImageBase;
- mapping->header_size = pos + size;
+ mapping->header_size = max( pos + size, nt.OptionalHeader.SizeOfHeaders );
mapping->protect = VPROT_IMAGE;
/* sanity check */
- if (mapping->header_size > mapping->size) goto error;
+ if (pos + size > mapping->size) goto error;
free( sec );
release_object( fd );
More information about the wine-cvs
mailing list