Alexandre Julliard : server: Implement the ImageContainsCode flag for image mappings.

Alexandre Julliard julliard at winehq.org
Tue Jan 30 14:38:14 CST 2018


Module: wine
Branch: master
Commit: 0810e6a68827a864bd9062c63094f5ad072b2697
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0810e6a68827a864bd9062c63094f5ad072b2697

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Jan 30 11:03:09 2018 +0100

server: Implement the ImageContainsCode flag for image mappings.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/tests/loader.c | 13 ++++++-------
 server/mapping.c             | 12 ++++++++++--
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c
index 38175da..bd23a1c 100644
--- a/dlls/kernel32/tests/loader.c
+++ b/dlls/kernel32/tests/loader.c
@@ -49,6 +49,7 @@ struct PROCESS_BASIC_INFORMATION_PRIVATE
 static LONG *child_failures;
 static WORD cb_count;
 static DWORD page_size;
+static BOOL is_win64 = sizeof(void *) > sizeof(int);
 static BOOL is_wow64;
 
 static NTSTATUS (WINAPI *pNtCreateSection)(HANDLE *, ACCESS_MASK, const OBJECT_ATTRIBUTES *,
@@ -267,8 +268,8 @@ static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HE
     status = pNtQuerySection( mapping, SectionImageInformation, &image, sizeof(image), &info_size );
     ok( !status, "%u: NtQuerySection failed err %x\n", id, status );
     ok( info_size == sizeof(image), "%u: NtQuerySection wrong size %lu\n", id, info_size );
-    if (nt_header->OptionalHeader.Magic == (sizeof(void *) > sizeof(int) ? IMAGE_NT_OPTIONAL_HDR64_MAGIC
-                                                                         : IMAGE_NT_OPTIONAL_HDR32_MAGIC))
+    if (nt_header->OptionalHeader.Magic == (is_win64 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC
+                                                     : IMAGE_NT_OPTIONAL_HDR32_MAGIC))
     {
         max_stack = nt_header->OptionalHeader.SizeOfStackReserve;
         commit_stack = nt_header->OptionalHeader.SizeOfStackCommit;
@@ -327,13 +328,11 @@ static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HE
     ok( image.CheckSum == nt_header->OptionalHeader.CheckSum, "%u: CheckSum wrong %08x / %08x\n", id,
         image.CheckSum, nt_header->OptionalHeader.CheckSum );
     if (nt_header->OptionalHeader.SizeOfCode || nt_header->OptionalHeader.AddressOfEntryPoint)
-        todo_wine
         ok( image.ImageContainsCode == TRUE, "%u: ImageContainsCode wrong %u\n", id,
             image.ImageContainsCode );
     else if ((nt_header->OptionalHeader.SectionAlignment % page_size) ||
              (nt_header->FileHeader.NumberOfSections == 1 &&
               (section.Characteristics & IMAGE_SCN_MEM_EXECUTE)))
-        todo_wine
         ok( image.ImageContainsCode == TRUE || broken(!image.ImageContainsCode), /* <= win8 */
             "%u: ImageContainsCode wrong %u\n", id, image.ImageContainsCode );
     else
@@ -416,8 +415,8 @@ static NTSTATUS map_image_section( const IMAGE_NT_HEADERS *nt_header, int line )
             info.Size.u.HighPart, info.Size.u.LowPart, file_size );
         has_code = query_image_section( line, dll_name, nt_header );
         /* test loading dll of wrong 32/64 bitness */
-        if (nt_header->OptionalHeader.Magic == (sizeof(void *) > sizeof(int) ? IMAGE_NT_OPTIONAL_HDR32_MAGIC
-                                                                             : IMAGE_NT_OPTIONAL_HDR64_MAGIC))
+        if (nt_header->OptionalHeader.Magic == (is_win64 ? IMAGE_NT_OPTIONAL_HDR32_MAGIC
+                                                         : IMAGE_NT_OPTIONAL_HDR64_MAGIC))
         {
             SetLastError( 0xdeadbeef );
             mod = LoadLibraryExA( dll_name, 0, DONT_RESOLVE_DLL_REFERENCES );
@@ -425,7 +424,7 @@ static NTSTATUS map_image_section( const IMAGE_NT_HEADERS *nt_header, int line )
             {
                 ok( mod != NULL, "%u: loading failed err %u\n", line, GetLastError() );
             }
-            else todo_wine_if (is_wow64)
+            else todo_wine_if (is_win64 || is_wow64)
             {
                 ok( !mod, "%u: loading succeeded\n", line );
                 ok( GetLastError() == ERROR_BAD_EXE_FORMAT, "%u: wrong error %u\n", line, GetLastError() );
diff --git a/server/mapping.c b/server/mapping.c
index b86ac9a..d863d08 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -539,7 +539,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
     } nt;
     off_t pos;
     int size;
-    unsigned int cpu_mask = get_supported_cpu_mask();
+    unsigned int i, cpu_mask = get_supported_cpu_mask();
 
     /* load the headers */
 
@@ -587,6 +587,9 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
         mapping->image.subsystem_low  = nt.opt.hdr32.MinorSubsystemVersion;
         mapping->image.subsystem_high = nt.opt.hdr32.MajorSubsystemVersion;
         mapping->image.dll_charact    = nt.opt.hdr32.DllCharacteristics;
+        mapping->image.contains_code  = (nt.opt.hdr32.SizeOfCode ||
+                                         nt.opt.hdr32.AddressOfEntryPoint ||
+                                         nt.opt.hdr32.SectionAlignment & page_mask);
         mapping->image.loader_flags   = nt.opt.hdr32.LoaderFlags;
         mapping->image.header_size    = nt.opt.hdr32.SizeOfHeaders;
         mapping->image.checksum       = nt.opt.hdr32.CheckSum;
@@ -614,6 +617,9 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
         mapping->image.subsystem_low  = nt.opt.hdr64.MinorSubsystemVersion;
         mapping->image.subsystem_high = nt.opt.hdr64.MajorSubsystemVersion;
         mapping->image.dll_charact    = nt.opt.hdr64.DllCharacteristics;
+        mapping->image.contains_code  = (nt.opt.hdr64.SizeOfCode ||
+                                         nt.opt.hdr64.AddressOfEntryPoint ||
+                                         nt.opt.hdr64.SectionAlignment & page_mask);
         mapping->image.loader_flags   = nt.opt.hdr64.LoaderFlags;
         mapping->image.header_size    = nt.opt.hdr64.SizeOfHeaders;
         mapping->image.checksum       = nt.opt.hdr64.CheckSum;
@@ -627,7 +633,6 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
     mapping->image.machine       = nt.FileHeader.Machine;
     mapping->image.zerobits      = 0; /* FIXME */
     mapping->image.gp            = 0; /* FIXME */
-    mapping->image.contains_code = 0; /* FIXME */
     mapping->image.image_flags   = 0; /* FIXME */
     mapping->image.file_size     = file_size;
 
@@ -642,6 +647,9 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
     if (!(sec = malloc( size ))) goto error;
     if (pread( unix_fd, sec, size, pos ) != size) goto error;
 
+    for (i = 0; i < nt.FileHeader.NumberOfSections && !mapping->image.contains_code; i++)
+        if (sec[i].Characteristics & IMAGE_SCN_MEM_EXECUTE) mapping->image.contains_code = 1;
+
     if (!build_shared_mapping( mapping, unix_fd, sec, nt.FileHeader.NumberOfSections )) goto error;
 
     free( sec );




More information about the wine-cvs mailing list