Commit 4847c1d8 authored by Alexandre Julliard's avatar Alexandre Julliard

server: Set the dynamically relocated flag when relocations are present.

parent 84418169
...@@ -2153,6 +2153,7 @@ static void test_import_resolution(void) ...@@ -2153,6 +2153,7 @@ static void test_import_resolution(void)
} data, *ptr; } data, *ptr;
IMAGE_NT_HEADERS nt, *pnt; IMAGE_NT_HEADERS nt, *pnt;
IMAGE_SECTION_HEADER section; IMAGE_SECTION_HEADER section;
SECTION_IMAGE_INFORMATION image;
int test, tls_index_save, nb_rel; int test, tls_index_save, nb_rel;
#if defined(__i386__) #if defined(__i386__)
static const UCHAR tls_init_code[] = { static const UCHAR tls_init_code[] = {
...@@ -2192,6 +2193,7 @@ static void test_import_resolution(void) ...@@ -2192,6 +2193,7 @@ static void test_import_resolution(void)
#else #else
#define ADD_RELOC(field) data.rel.type_off[nb_rel++] = (IMAGE_REL_BASED_HIGHLOW << 12) + offsetof( struct imports, field ) #define ADD_RELOC(field) data.rel.type_off[nb_rel++] = (IMAGE_REL_BASED_HIGHLOW << 12) + offsetof( struct imports, field )
#endif #endif
winetest_push_context( "%u", test );
nt = nt_header_template; nt = nt_header_template;
nt.FileHeader.NumberOfSections = 1; nt.FileHeader.NumberOfSections = 1;
nt.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER); nt.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
...@@ -2363,6 +2365,11 @@ static void test_import_resolution(void) ...@@ -2363,6 +2365,11 @@ static void test_import_resolution(void)
ok( GetLastError() == ERROR_BAD_EXE_FORMAT, "wrong error %lu\n", GetLastError() ); ok( GetLastError() == ERROR_BAD_EXE_FORMAT, "wrong error %lu\n", GetLastError() );
break; break;
} }
status = pNtQuerySection( mapping, SectionImageInformation, &image, sizeof(image), &size );
ok( !status, "NtQuerySection failed %lx\n", status );
ok( test == 6 ? !image.ImageDynamicallyRelocated : image.ImageDynamicallyRelocated,
"image flags %x\n", image.ImageFlags);
ok( !image.ImageContainsCode, "contains code %x\n", image.ImageContainsCode);
ok( mapping != 0, "CreateFileMappingA failed err %lu\n", GetLastError() ); ok( mapping != 0, "CreateFileMappingA failed err %lu\n", GetLastError() );
/* make sure that the address is not available */ /* make sure that the address is not available */
tmp = VirtualAlloc( (void *)nt.OptionalHeader.ImageBase, 0x10000, tmp = VirtualAlloc( (void *)nt.OptionalHeader.ImageBase, 0x10000,
...@@ -2399,6 +2406,7 @@ static void test_import_resolution(void) ...@@ -2399,6 +2406,7 @@ static void test_import_resolution(void)
break; break;
} }
DeleteFileA( dll_name ); DeleteFileA( dll_name );
winetest_pop_context();
#undef DATA_RVA #undef DATA_RVA
} }
} }
......
...@@ -695,7 +695,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -695,7 +695,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
} opt; } opt;
} nt; } nt;
off_t pos; off_t pos;
int size; int size, has_relocs;
size_t mz_size, clr_va = 0, clr_size = 0; size_t mz_size, clr_va = 0, clr_size = 0;
unsigned int i; unsigned int i;
...@@ -757,10 +757,15 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -757,10 +757,15 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
mapping->image.header_size = nt.opt.hdr32.SizeOfHeaders; mapping->image.header_size = nt.opt.hdr32.SizeOfHeaders;
mapping->image.checksum = nt.opt.hdr32.CheckSum; mapping->image.checksum = nt.opt.hdr32.CheckSum;
mapping->image.image_flags = 0; mapping->image.image_flags = 0;
has_relocs = (nt.opt.hdr32.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_BASERELOC &&
nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress &&
nt.opt.hdr32.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size &&
!(nt.FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED));
if (nt.opt.hdr32.SectionAlignment & page_mask) if (nt.opt.hdr32.SectionAlignment & page_mask)
mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat; mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat;
else if ((nt.opt.hdr32.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) && else if ((nt.opt.hdr32.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) &&
mapping->image.contains_code && !(clr_va && clr_size)) (has_relocs || mapping->image.contains_code) && !(clr_va && clr_size))
mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated; mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated;
break; break;
...@@ -800,10 +805,20 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s ...@@ -800,10 +805,20 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
mapping->image.header_size = nt.opt.hdr64.SizeOfHeaders; mapping->image.header_size = nt.opt.hdr64.SizeOfHeaders;
mapping->image.checksum = nt.opt.hdr64.CheckSum; mapping->image.checksum = nt.opt.hdr64.CheckSum;
mapping->image.image_flags = 0; mapping->image.image_flags = 0;
has_relocs = (nt.opt.hdr64.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_BASERELOC &&
nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress &&
nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size &&
!(nt.FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED));
if (nt.opt.hdr64.SectionAlignment & page_mask) if (nt.opt.hdr64.SectionAlignment & page_mask)
mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat; mapping->image.image_flags |= IMAGE_FLAGS_ImageMappedFlat;
else if (nt.opt.hdr64.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_BASERELOC &&
nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress &&
nt.opt.hdr64.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size &&
!(nt.FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED))
mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated;
else if ((nt.opt.hdr64.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) && else if ((nt.opt.hdr64.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) &&
mapping->image.contains_code && !(clr_va && clr_size)) (has_relocs || mapping->image.contains_code) && !(clr_va && clr_size))
mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated; mapping->image.image_flags |= IMAGE_FLAGS_ImageDynamicallyRelocated;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment