[PATCH v2 6/8] ntdll: Add alloc_type parameter to virtual_map_section and map_image

Rémi Bernon rbernon at codeweavers.com
Fri Jun 14 08:11:15 CDT 2019


NtMapViewOfSection also accepts the MEM_TOP_DOWN parameter that can
be used in combination with zero_bits to map memory on the highest
possible address.

This is useful for the subsequent patches so we can consistently fail
zero_bits tests.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/ntdll/loader.c     |  2 +-
 dlls/ntdll/ntdll_misc.h |  4 ++--
 dlls/ntdll/virtual.c    | 25 ++++++++++++++-----------
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 3f422a9c0be..487b752b499 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -2135,7 +2135,7 @@ static NTSTATUS open_dll_file( UNICODE_STRING *nt_name, WINE_MODREF **pwm,
             *module = NULL;
         }
         status = virtual_map_section( mapping, module, 0, 0, NULL, &len,
-                                      PAGE_EXECUTE_READ, image_info );
+                                      0, PAGE_EXECUTE_READ, image_info );
         if (status == STATUS_IMAGE_NOT_AT_BASE) status = STATUS_SUCCESS;
         NtClose( mapping );
     }
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index f8c377e6010..73e35435e72 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -171,8 +171,8 @@ extern NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, ANSI_S
 extern NTSTATUS virtual_alloc_aligned( PVOID *ret, ULONG zero_bits, SIZE_T *size_ptr,
                                        ULONG type, ULONG protect, ULONG alignment ) DECLSPEC_HIDDEN;
 extern NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG zero_bits, SIZE_T commit_size,
-                                     const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG protect,
-                                     pe_image_info_t *image_info ) DECLSPEC_HIDDEN;
+                                     const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG alloc_type,
+                                     ULONG protect, pe_image_info_t *image_info ) DECLSPEC_HIDDEN;
 extern void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info ) DECLSPEC_HIDDEN;
 extern NTSTATUS virtual_create_builtin_view( void *base ) DECLSPEC_HIDDEN;
 extern NTSTATUS virtual_alloc_thread_stack( TEB *teb, SIZE_T reserve_size,
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 3c978b266d8..29a7c96c599 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1362,7 +1362,7 @@ static NTSTATUS map_pe_header( void *ptr, size_t size, int fd, BOOL *removable )
  */
 static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, SIZE_T mask,
                            pe_image_info_t *image_info, int shared_fd, BOOL removable,
-                           PVOID *addr_ptr, SIZE_T zero_bits )
+                           PVOID *addr_ptr, SIZE_T zero_bits, ULONG alloc_type )
 {
     IMAGE_DOS_HEADER *dos;
     IMAGE_NT_HEADERS *nt;
@@ -1391,12 +1391,14 @@ static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, SIZE_T m
     server_enter_uninterrupted_section( &csVirtual, &sigset );
 
     if (base >= (char *)address_space_start)  /* make sure the DOS area remains free */
-        status = map_view( &view, base, total_size, mask, FALSE, SEC_IMAGE | SEC_FILE |
-                           VPROT_COMMITTED | VPROT_READ | VPROT_EXEC | VPROT_WRITECOPY, zero_bits );
+        status = map_view( &view, base, total_size, mask, alloc_type & MEM_TOP_DOWN,
+                           SEC_IMAGE | SEC_FILE | VPROT_COMMITTED | VPROT_READ | VPROT_EXEC | VPROT_WRITECOPY,
+                           zero_bits );
 
     if (status != STATUS_SUCCESS)
-        status = map_view( &view, NULL, total_size, mask, FALSE, SEC_IMAGE | SEC_FILE |
-                           VPROT_COMMITTED | VPROT_READ | VPROT_EXEC | VPROT_WRITECOPY, zero_bits );
+        status = map_view( &view, NULL, total_size, mask, alloc_type & MEM_TOP_DOWN,
+                           SEC_IMAGE | SEC_FILE | VPROT_COMMITTED | VPROT_READ | VPROT_EXEC | VPROT_WRITECOPY,
+                           zero_bits );
 
     if (status != STATUS_SUCCESS) goto error;
 
@@ -1612,8 +1614,8 @@ static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, SIZE_T m
  * Map a file section into memory.
  */
 NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG zero_bits, SIZE_T commit_size,
-                              const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG protect,
-                              pe_image_info_t *image_info )
+                              const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG alloc_type,
+                              ULONG protect, pe_image_info_t *image_info )
 {
     NTSTATUS res;
     mem_size_t full_size;
@@ -1674,14 +1676,14 @@ NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG zero_bits, S
             if ((res = server_get_unix_fd( shared_file, FILE_READ_DATA|FILE_WRITE_DATA,
                                            &shared_fd, &shared_needs_close, NULL, NULL ))) goto done;
             res = map_image( handle, access, unix_handle, mask, image_info,
-                             shared_fd, needs_close, addr_ptr, zero_bits );
+                             shared_fd, needs_close, addr_ptr, zero_bits, alloc_type );
             if (shared_needs_close) close( shared_fd );
             close_handle( shared_file );
         }
         else
         {
             res = map_image( handle, access, unix_handle, mask, image_info,
-                             -1, needs_close, addr_ptr, zero_bits );
+                             -1, needs_close, addr_ptr, zero_bits, alloc_type );
         }
         if (needs_close) close( unix_handle );
         if (res >= 0) *size_ptr = image_info->map_size;
@@ -1718,7 +1720,7 @@ NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG zero_bits, S
     get_vprot_flags( protect, &vprot, sec_flags & SEC_IMAGE );
     vprot |= sec_flags;
     if (!(sec_flags & SEC_RESERVE)) vprot |= VPROT_COMMITTED;
-    res = map_view( &view, *addr_ptr, size, mask, FALSE, vprot, zero_bits );
+    res = map_view( &view, *addr_ptr, size, mask, alloc_type & MEM_TOP_DOWN, vprot, zero_bits );
     if (res)
     {
         server_leave_uninterrupted_section( &csVirtual, &sigset );
@@ -3152,7 +3154,8 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
     }
 
     return virtual_map_section( handle, addr_ptr, zero_bits, commit_size,
-                                offset_ptr, size_ptr, protect, &image_info );
+                                offset_ptr, size_ptr, alloc_type, protect,
+                                &image_info );
 }
 
 
-- 
2.20.1




More information about the wine-devel mailing list