ntdll: Map the PE header up to the specified size, and clear the rest of the page.

This commit is contained in:
Alexandre Julliard 2006-12-13 13:06:12 +01:00
parent 64b2ca2573
commit 3dc21d387b
3 changed files with 8 additions and 11 deletions

View File

@ -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);
}

View File

@ -974,11 +974,12 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
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,7 +1068,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
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",
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 hmapping, int fd, char *base, SIZE_T total_siz
/* 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++)
{

View File

@ -243,11 +243,11 @@ static int get_image_params( struct mapping *mapping )
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 );