Alexandre Julliard : ntdll: Determine the mapping type automatically from the WRITECOPY flag.
Alexandre Julliard
julliard at winehq.org
Tue May 13 14:23:46 CDT 2014
Module: wine
Branch: master
Commit: 2cef8dbcc29739278037e6409e0a00a4fa8dc0d4
URL: http://source.winehq.org/git/wine.git/?a=commit;h=2cef8dbcc29739278037e6409e0a00a4fa8dc0d4
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue May 13 12:28:58 2014 +0200
ntdll: Determine the mapping type automatically from the WRITECOPY flag.
---
dlls/ntdll/virtual.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 70dea5a..4819d2d 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -854,10 +854,11 @@ done:
* The csVirtual section must be held by caller.
*/
static NTSTATUS map_file_into_view( struct file_view *view, int fd, size_t start, size_t size,
- off_t offset, unsigned int vprot, int flags, BOOL removable )
+ off_t offset, unsigned int vprot, BOOL removable )
{
void *ptr;
int prot = VIRTUAL_GetUnixProt( vprot | VPROT_COMMITTED /* make sure it is accessible */ );
+ unsigned int flags = MAP_FIXED | ((vprot & VPROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED);
assert( start < view->size );
assert( start + size <= view->size );
@@ -872,7 +873,7 @@ static NTSTATUS map_file_into_view( struct file_view *view, int fd, size_t start
/* only try mmap if media is not removable (or if we require write access) */
if (!removable || (flags & MAP_SHARED))
{
- if (mmap( (char *)view->base + start, size, prot, flags | MAP_FIXED, fd, offset ) != (void *)-1)
+ if (mmap( (char *)view->base + start, size, prot, flags, fd, offset ) != (void *)-1)
goto done;
if ((errno == EPERM) && (prot & PROT_EXEC))
@@ -1094,7 +1095,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
if (!st.st_size) goto error;
header_size = min( header_size, st.st_size );
if (map_file_into_view( view, fd, 0, header_size, 0, VPROT_COMMITTED | VPROT_READ | VPROT_WRITECOPY,
- MAP_PRIVATE, !dup_mapping ) != STATUS_SUCCESS) goto error;
+ !dup_mapping ) != STATUS_SUCCESS) goto error;
dos = (IMAGE_DOS_HEADER *)ptr;
nt = (IMAGE_NT_HEADERS *)(ptr + dos->e_lfanew);
header_end = ptr + ROUND_SIZE( 0, header_size );
@@ -1118,8 +1119,8 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
/* unaligned sections, this happens for native subsystem binaries */
/* in that case Windows simply maps in the whole file */
- if (map_file_into_view( view, fd, 0, total_size, 0, VPROT_COMMITTED | VPROT_READ,
- MAP_PRIVATE, !dup_mapping ) != STATUS_SUCCESS) goto error;
+ if (map_file_into_view( view, fd, 0, total_size, 0, VPROT_COMMITTED | VPROT_READ | VPROT_WRITECOPY,
+ !dup_mapping ) != STATUS_SUCCESS) goto error;
/* check that all sections are loaded at the right offset */
if (nt->OptionalHeader.FileAlignment != nt->OptionalHeader.SectionAlignment) goto error;
@@ -1172,8 +1173,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
sec->PointerToRawData, (int)pos, file_size, map_size,
sec->Characteristics );
if (map_file_into_view( view, shared_fd, sec->VirtualAddress, map_size, pos,
- VPROT_COMMITTED | VPROT_READ | VPROT_WRITE,
- MAP_SHARED, FALSE ) != STATUS_SUCCESS)
+ VPROT_COMMITTED | VPROT_READ | VPROT_WRITE, FALSE ) != STATUS_SUCCESS)
{
ERR_(module)( "Could not map shared section %.8s\n", sec->Name );
goto error;
@@ -1189,8 +1189,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
if (end > base)
map_file_into_view( view, shared_fd, base, end - base,
pos + (base - sec->VirtualAddress),
- VPROT_COMMITTED | VPROT_READ | VPROT_WRITECOPY,
- MAP_PRIVATE, FALSE );
+ VPROT_COMMITTED | VPROT_READ | VPROT_WRITECOPY, FALSE );
}
pos += map_size;
continue;
@@ -1212,7 +1211,7 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
end < file_start ||
map_file_into_view( view, fd, sec->VirtualAddress, file_size, file_start,
VPROT_COMMITTED | VPROT_READ | VPROT_WRITECOPY,
- MAP_PRIVATE, !dup_mapping ) != STATUS_SUCCESS)
+ !dup_mapping ) != STATUS_SUCCESS)
{
ERR_(module)( "Could not map section %.8s, file probably truncated\n", sec->Name );
goto error;
@@ -2627,8 +2626,7 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
TRACE("handle=%p size=%lx offset=%x%08x\n",
handle, size, offset.u.HighPart, offset.u.LowPart );
- res = map_file_into_view( view, unix_handle, 0, size, offset.QuadPart, vprot,
- (vprot & VPROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED, !dup_mapping );
+ res = map_file_into_view( view, unix_handle, 0, size, offset.QuadPart, vprot, !dup_mapping );
if (res == STATUS_SUCCESS)
{
*addr_ptr = view->base;
More information about the wine-cvs
mailing list