ntdll: Pass the mapping file access instead of the protection bits to the server.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2017-09-12 11:42:04 +02:00
parent f448be618b
commit 1c8a36a91c
6 changed files with 34 additions and 51 deletions

View File

@ -74,6 +74,17 @@ struct file_view
unsigned int protect; /* protection for all pages at allocation time and SEC_* flags */
};
/* per-page protection flags */
#define VPROT_READ 0x01
#define VPROT_WRITE 0x02
#define VPROT_EXEC 0x04
#define VPROT_WRITECOPY 0x08
#define VPROT_GUARD 0x10
#define VPROT_COMMITTED 0x20
#define VPROT_WRITEWATCH 0x40
/* per-mapping protection flags */
#define VPROT_SYSTEM 0x0200 /* system view (underlying mmap not under our control) */
#define VPROT_VALLOC 0x0400 /* allocated by VirtualAlloc */
/* Conversion from VPROT_* to Win32 flags */
static const BYTE VIRTUAL_Win32Flags[16] =
@ -2632,20 +2643,23 @@ NTSTATUS WINAPI NtCreateSection( HANDLE *handle, ACCESS_MASK access, const OBJEC
ULONG sec_flags, HANDLE file )
{
NTSTATUS ret;
unsigned int vprot;
unsigned int vprot, file_access = 0;
data_size_t len;
struct object_attributes *objattr;
if ((ret = get_vprot_flags( protect, &vprot, sec_flags & SEC_IMAGE ))) return ret;
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
if (vprot & VPROT_READ) file_access |= FILE_READ_DATA;
if (vprot & VPROT_WRITE) file_access |= FILE_WRITE_DATA;
SERVER_START_REQ( create_mapping )
{
req->access = access;
req->flags = sec_flags;
req->file_handle = wine_server_obj_handle( file );
req->file_access = file_access;
req->size = size ? size->QuadPart : 0;
req->protect = vprot;
wine_server_add_data( req, objattr, len );
ret = wine_server_call( req );
*handle = wine_server_ptr_handle( reply->handle );

View File

@ -2174,7 +2174,7 @@ struct create_mapping_request
struct request_header __header;
unsigned int access;
unsigned int flags;
unsigned int protect;
unsigned int file_access;
mem_size_t size;
obj_handle_t file_handle;
/* VARARG(objattr,object_attributes); */
@ -2187,17 +2187,6 @@ struct create_mapping_reply
char __pad_12[4];
};
#define VPROT_READ 0x01
#define VPROT_WRITE 0x02
#define VPROT_EXEC 0x04
#define VPROT_WRITECOPY 0x08
#define VPROT_GUARD 0x10
#define VPROT_COMMITTED 0x20
#define VPROT_WRITEWATCH 0x40
#define VPROT_SYSTEM 0x0200
#define VPROT_VALLOC 0x0400
struct open_mapping_request
@ -2229,10 +2218,10 @@ struct get_mapping_info_reply
struct reply_header __header;
mem_size_t size;
unsigned int flags;
int protect;
obj_handle_t mapping;
obj_handle_t shared_file;
/* VARARG(image,pe_image_info); */
char __pad_28[4];
};
@ -6417,6 +6406,6 @@ union generic_reply
struct terminate_job_reply terminate_job_reply;
};
#define SERVER_PROTOCOL_VERSION 535
#define SERVER_PROTOCOL_VERSION 536
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */

View File

@ -60,7 +60,6 @@ struct mapping
struct object obj; /* object header */
mem_size_t size; /* mapping size */
unsigned int flags; /* SEC_* flags */
int protect; /* protection flags */
struct fd *fd; /* fd for mapped file */
enum cpu_type cpu; /* client CPU (for PE image mapping) */
pe_image_info_t image; /* image info (for PE image mapping) */
@ -520,13 +519,13 @@ static unsigned int get_mapping_flags( obj_handle_t handle, unsigned int flags )
static struct object *create_mapping( struct object *root, const struct unicode_str *name,
unsigned int attr, mem_size_t size, unsigned int flags, int protect,
obj_handle_t handle, const struct security_descriptor *sd )
unsigned int attr, mem_size_t size, unsigned int flags,
obj_handle_t handle, unsigned int file_access,
const struct security_descriptor *sd )
{
struct mapping *mapping;
struct file *file;
struct fd *fd;
int access = 0;
int unix_fd;
struct stat st;
@ -538,27 +537,23 @@ static struct object *create_mapping( struct object *root, const struct unicode_
return &mapping->obj; /* Nothing else to do */
mapping->size = size;
mapping->protect = protect;
mapping->fd = NULL;
mapping->shared_file = NULL;
mapping->committed = NULL;
if (!(mapping->flags = get_mapping_flags( handle, flags ))) goto error;
if (protect & VPROT_READ) access |= FILE_READ_DATA;
if (protect & VPROT_WRITE) access |= FILE_WRITE_DATA;
if (handle)
{
const unsigned int sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
unsigned int mapping_access = FILE_MAPPING_ACCESS;
if (!(file = get_file_obj( current->process, handle, access ))) goto error;
if (!(file = get_file_obj( current->process, handle, file_access ))) goto error;
fd = get_obj_fd( (struct object *)file );
/* file sharing rules for mappings are different so we use magic the access rights */
if (flags & SEC_IMAGE) mapping_access |= FILE_MAPPING_IMAGE;
else if (protect & VPROT_WRITE) mapping_access |= FILE_MAPPING_WRITE;
else if (file_access & FILE_WRITE_DATA) mapping_access |= FILE_MAPPING_WRITE;
if (!(mapping->fd = get_fd_object_for_mapping( fd, mapping_access, sharing )))
{
@ -592,7 +587,7 @@ static struct object *create_mapping( struct object *root, const struct unicode_
}
else if (st.st_size < mapping->size)
{
if (!(access & FILE_WRITE_DATA))
if (!(file_access & FILE_WRITE_DATA))
{
set_error( STATUS_SECTION_TOO_BIG );
goto error;
@ -654,9 +649,9 @@ static void mapping_dump( struct object *obj, int verbose )
{
struct mapping *mapping = (struct mapping *)obj;
assert( obj->ops == &mapping_ops );
fprintf( stderr, "Mapping size=%08x%08x flags=%08x prot=%08x fd=%p shared_file=%p\n",
fprintf( stderr, "Mapping size=%08x%08x flags=%08x fd=%p shared_file=%p\n",
(unsigned int)(mapping->size >> 32), (unsigned int)mapping->size,
mapping->flags, mapping->protect, mapping->fd, mapping->shared_file );
mapping->flags, mapping->fd, mapping->shared_file );
}
static struct object_type *mapping_get_type( struct object *obj )
@ -715,8 +710,8 @@ DECL_HANDLER(create_mapping)
if (!objattr) return;
if ((obj = create_mapping( root, &name, objattr->attributes,
req->size, req->flags, req->protect, req->file_handle, sd )))
if ((obj = create_mapping( root, &name, objattr->attributes, req->size, req->flags,
req->file_handle, req->file_access, sd )))
{
if (get_error() == STATUS_OBJECT_NAME_EXISTS)
reply->handle = alloc_handle( current->process, obj, req->access, objattr->attributes );
@ -748,7 +743,6 @@ DECL_HANDLER(get_mapping_info)
reply->size = mapping->size;
reply->flags = mapping->flags;
reply->protect = mapping->protect;
if (mapping->flags & SEC_IMAGE)
set_reply_data( &mapping->image, min( sizeof(mapping->image), get_reply_max_size() ));

View File

@ -1691,24 +1691,13 @@ enum char_info_mode
@REQ(create_mapping)
unsigned int access; /* wanted access rights */
unsigned int flags; /* SEC_* flags */
unsigned int protect; /* protection flags (see below) */
unsigned int file_access; /* file access rights */
mem_size_t size; /* mapping size */
obj_handle_t file_handle; /* file handle */
VARARG(objattr,object_attributes); /* object attributes */
@REPLY
obj_handle_t handle; /* handle to the mapping */
@END
/* per-page protection flags */
#define VPROT_READ 0x01
#define VPROT_WRITE 0x02
#define VPROT_EXEC 0x04
#define VPROT_WRITECOPY 0x08
#define VPROT_GUARD 0x10
#define VPROT_COMMITTED 0x20
#define VPROT_WRITEWATCH 0x40
/* per-mapping protection flags */
#define VPROT_SYSTEM 0x0200 /* system view (underlying mmap not under our control) */
#define VPROT_VALLOC 0x0400 /* allocated by VirtualAlloc */
/* Open a mapping */
@ -1729,7 +1718,6 @@ enum char_info_mode
@REPLY
mem_size_t size; /* mapping size */
unsigned int flags; /* SEC_* flags */
int protect; /* protection flags */
obj_handle_t mapping; /* duplicate mapping handle unless removable */
obj_handle_t shared_file; /* shared mapping file handle */
VARARG(image,pe_image_info);/* image info for SEC_IMAGE mappings */

View File

@ -1244,7 +1244,7 @@ C_ASSERT( sizeof(struct read_change_request) == 16 );
C_ASSERT( sizeof(struct read_change_reply) == 8 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, access) == 12 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, flags) == 16 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, protect) == 20 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, file_access) == 20 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, size) == 24 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, file_handle) == 32 );
C_ASSERT( sizeof(struct create_mapping_request) == 40 );
@ -1261,9 +1261,8 @@ C_ASSERT( FIELD_OFFSET(struct get_mapping_info_request, access) == 16 );
C_ASSERT( sizeof(struct get_mapping_info_request) == 24 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, size) == 8 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, flags) == 16 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, protect) == 20 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, mapping) == 24 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, shared_file) == 28 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, mapping) == 20 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, shared_file) == 24 );
C_ASSERT( sizeof(struct get_mapping_info_reply) == 32 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_committed_range_request, handle) == 12 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_committed_range_request, offset) == 16 );

View File

@ -2199,7 +2199,7 @@ static void dump_create_mapping_request( const struct create_mapping_request *re
{
fprintf( stderr, " access=%08x", req->access );
fprintf( stderr, ", flags=%08x", req->flags );
fprintf( stderr, ", protect=%08x", req->protect );
fprintf( stderr, ", file_access=%08x", req->file_access );
dump_uint64( ", size=", &req->size );
fprintf( stderr, ", file_handle=%04x", req->file_handle );
dump_varargs_object_attributes( ", objattr=", cur_size );
@ -2233,7 +2233,6 @@ static void dump_get_mapping_info_reply( const struct get_mapping_info_reply *re
{
dump_uint64( " size=", &req->size );
fprintf( stderr, ", flags=%08x", req->flags );
fprintf( stderr, ", protect=%d", req->protect );
fprintf( stderr, ", mapping=%04x", req->mapping );
fprintf( stderr, ", shared_file=%04x", req->shared_file );
dump_varargs_pe_image_info( ", image=", cur_size );