[PATCH v3 07/10] ntdll: Add top_down parameter to virtual_map_section and map_image
Rémi Bernon
rbernon at codeweavers.com
Tue Jun 18 11:39:31 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 next 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 | 2 +-
dlls/ntdll/virtual.c | 16 ++++++++--------
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 3f422a9c0be..5e5758f3f8b 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -2134,7 +2134,7 @@ static NTSTATUS open_dll_file( UNICODE_STRING *nt_name, WINE_MODREF **pwm,
NtUnmapViewOfSection( NtCurrentProcess(), *module );
*module = NULL;
}
- status = virtual_map_section( mapping, module, 0, 0, NULL, &len,
+ status = virtual_map_section( mapping, module, 0, 0, 0, NULL, &len,
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..67393b6ba69 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -170,7 +170,7 @@ extern NTSTATUS nt_to_unix_file_name_attr( const OBJECT_ATTRIBUTES *attr, ANSI_S
/* virtual memory */
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,
+extern NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, int top_down, 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;
extern void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info ) DECLSPEC_HIDDEN;
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index cf3e597ab2f..88ea958ccf5 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1370,7 +1370,7 @@ static NTSTATUS map_pe_header( void *ptr, size_t size, int fd, BOOL *removable )
*
* Map an executable (PE format) image into memory.
*/
-static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, SIZE_T zero_bits,
+static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, int top_down, SIZE_T zero_bits,
pe_image_info_t *image_info, int shared_fd, BOOL removable, PVOID *addr_ptr )
{
IMAGE_DOS_HEADER *dos;
@@ -1402,12 +1402,12 @@ static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, SIZE_T z
if (base >= (char *)address_space_start) /* make sure the DOS area remains free */
status = map_view_aligned( &view, base, total_size,
SEC_IMAGE | SEC_FILE | VPROT_COMMITTED | VPROT_READ | VPROT_EXEC | VPROT_WRITECOPY,
- FALSE, zero_bits, 0 );
+ top_down, zero_bits, 0 );
if (status != STATUS_SUCCESS)
status = map_view_aligned( &view, NULL, total_size,
SEC_IMAGE | SEC_FILE | VPROT_COMMITTED | VPROT_READ | VPROT_EXEC | VPROT_WRITECOPY,
- FALSE, zero_bits, 0 );
+ top_down, zero_bits, 0 );
if (status != STATUS_SUCCESS) goto error;
@@ -1622,7 +1622,7 @@ static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, SIZE_T z
*
* Map a file section into memory.
*/
-NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG zero_bits, SIZE_T commit_size,
+NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, int top_down, ULONG zero_bits, SIZE_T commit_size,
const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG protect,
pe_image_info_t *image_info )
{
@@ -1684,14 +1684,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, zero_bits, image_info,
+ res = map_image( handle, access, unix_handle, top_down, zero_bits, image_info,
shared_fd, needs_close, addr_ptr );
if (shared_needs_close) close( shared_fd );
close_handle( shared_file );
}
else
{
- res = map_image( handle, access, unix_handle, zero_bits, image_info,
+ res = map_image( handle, access, unix_handle, top_down, zero_bits, image_info,
-1, needs_close, addr_ptr );
}
if (needs_close) close( unix_handle );
@@ -1729,7 +1729,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_aligned( &view, *addr_ptr, size, vprot, FALSE, zero_bits, 0 );
+ res = map_view_aligned( &view, *addr_ptr, size, vprot, top_down, zero_bits, 0 );
if (res)
{
server_leave_uninterrupted_section( &csVirtual, &sigset );
@@ -3170,7 +3170,7 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
return result.map_view.status;
}
- return virtual_map_section( handle, addr_ptr, zero_bits, commit_size,
+ return virtual_map_section( handle, addr_ptr, alloc_type & MEM_TOP_DOWN, zero_bits, commit_size,
offset_ptr, size_ptr, protect, &image_info );
}
--
2.20.1
More information about the wine-devel
mailing list