[PATCH v2 5/8] ntdll: Clarify NtMapViewOfSection zero_bits parameter semantic
Rémi Bernon
rbernon at codeweavers.com
Fri Jun 14 08:11:14 CDT 2019
See 00451d5edf9a13fd8f414a0d06869e38cf66b754
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/ntdll/tests/virtual.c | 1 -
dlls/ntdll/virtual.c | 34 ++++++++++++++++++----------------
2 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/dlls/ntdll/tests/virtual.c b/dlls/ntdll/tests/virtual.c
index c02dbd88a54..8693194ae84 100644
--- a/dlls/ntdll/tests/virtual.c
+++ b/dlls/ntdll/tests/virtual.c
@@ -272,7 +272,6 @@ static void test_MapViewOfSection(void)
}
else
{
- todo_wine
ok(status == STATUS_SUCCESS || status == STATUS_NO_MEMORY,
"NtMapViewOfSection returned %08x\n", status);
if (status == STATUS_SUCCESS)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 86377af0a8c..3c978b266d8 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -409,12 +409,12 @@ static struct file_view *VIRTUAL_FindView( const void *addr, size_t size )
/***********************************************************************
* get_mask
*/
-static inline UINT_PTR get_mask( ULONG zero_bits )
+static inline UINT_PTR get_mask( ULONG alignment )
{
- if (!zero_bits) return 0xffff; /* allocations are aligned to 64K by default */
- if (zero_bits < page_shift) zero_bits = page_shift;
- if (zero_bits > 21) return 0;
- return (1 << zero_bits) - 1;
+ if (!alignment) return 0xffff; /* allocations are aligned to 64K by default */
+ if (alignment < page_shift) alignment = page_shift;
+ if (alignment > 21) return 0;
+ return (1 << alignment) - 1;
}
@@ -1361,7 +1361,8 @@ 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 mask,
- pe_image_info_t *image_info, int shared_fd, BOOL removable, PVOID *addr_ptr )
+ pe_image_info_t *image_info, int shared_fd, BOOL removable,
+ PVOID *addr_ptr, SIZE_T zero_bits )
{
IMAGE_DOS_HEADER *dos;
IMAGE_NT_HEADERS *nt;
@@ -1391,11 +1392,11 @@ static NTSTATUS map_image( HANDLE hmapping, ACCESS_MASK access, int fd, SIZE_T m
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, 0 );
+ 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, 0 );
+ VPROT_COMMITTED | VPROT_READ | VPROT_EXEC | VPROT_WRITECOPY, zero_bits );
if (status != STATUS_SUCCESS) goto error;
@@ -1617,7 +1618,7 @@ NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, ULONG zero_bits, S
NTSTATUS res;
mem_size_t full_size;
ACCESS_MASK access;
- SIZE_T size, mask = get_mask( zero_bits );
+ SIZE_T size, mask = get_mask( 0 );
int unix_handle = -1, needs_close;
unsigned int vprot, sec_flags;
struct file_view *view;
@@ -1673,13 +1674,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 );
+ shared_fd, needs_close, addr_ptr, zero_bits );
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 );
+ res = map_image( handle, access, unix_handle, mask, image_info,
+ -1, needs_close, addr_ptr, zero_bits );
}
if (needs_close) close( unix_handle );
if (res >= 0) *size_ptr = image_info->map_size;
@@ -1716,7 +1718,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, 0 );
+ res = map_view( &view, *addr_ptr, size, mask, FALSE, vprot, zero_bits );
if (res)
{
server_leave_uninterrupted_section( &csVirtual, &sigset );
@@ -3098,7 +3100,7 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
SECTION_INHERIT inherit, ULONG alloc_type, ULONG protect )
{
NTSTATUS res;
- SIZE_T mask = get_mask( zero_bits );
+ SIZE_T mask = get_mask( 0 );
pe_image_info_t image_info;
LARGE_INTEGER offset;
@@ -3108,9 +3110,9 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
handle, process, *addr_ptr, offset.u.HighPart, offset.u.LowPart, *size_ptr, protect );
/* Check parameters */
-
- if ((*addr_ptr && zero_bits) || !mask)
- return STATUS_INVALID_PARAMETER_4;
+ if (*addr_ptr && zero_bits) return STATUS_INVALID_PARAMETER_4;
+ if (zero_bits > 21 && zero_bits < 32) return STATUS_INVALID_PARAMETER_4;
+ if (!is_win64 && !is_wow64 && zero_bits >= 32) return STATUS_INVALID_PARAMETER_4;
#ifndef _WIN64
if (!is_wow64 && (alloc_type & AT_ROUND_TO_PAGE))
--
2.20.1
More information about the wine-devel
mailing list