server: Store the section flags separately from the protection.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2016-07-26 14:20:02 +09:00
parent c622b461bb
commit 1ddc636051
7 changed files with 54 additions and 41 deletions

View File

@ -2477,20 +2477,13 @@ NTSTATUS WINAPI NtCreateSection( HANDLE *handle, ACCESS_MASK access, const OBJEC
data_size_t len; data_size_t len;
struct object_attributes *objattr; struct object_attributes *objattr;
/* Check parameters */
if ((ret = get_vprot_flags( protect, &vprot, sec_flags & SEC_IMAGE ))) return ret; if ((ret = get_vprot_flags( protect, &vprot, sec_flags & SEC_IMAGE ))) return ret;
if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret; if ((ret = alloc_object_attributes( attr, &objattr, &len ))) return ret;
if (!(sec_flags & SEC_RESERVE)) vprot |= VPROT_COMMITTED;
if (sec_flags & SEC_NOCACHE) vprot |= VPROT_NOCACHE;
if (sec_flags & SEC_IMAGE) vprot |= VPROT_IMAGE;
/* Create the server object */
SERVER_START_REQ( create_mapping ) SERVER_START_REQ( create_mapping )
{ {
req->access = access; req->access = access;
req->flags = sec_flags;
req->file_handle = wine_server_obj_handle( file ); req->file_handle = wine_server_obj_handle( file );
req->size = size ? size->QuadPart : 0; req->size = size ? size->QuadPart : 0;
req->protect = vprot; req->protect = vprot;
@ -2543,7 +2536,7 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
ACCESS_MASK access; ACCESS_MASK access;
SIZE_T size, mask = get_mask( zero_bits ); SIZE_T size, mask = get_mask( zero_bits );
int unix_handle = -1, needs_close; int unix_handle = -1, needs_close;
unsigned int map_vprot, vprot; unsigned int map_vprot, vprot, sec_flags;
void *base; void *base;
struct file_view *view; struct file_view *view;
DWORD header_size; DWORD header_size;
@ -2624,6 +2617,7 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
req->access = access; req->access = access;
res = wine_server_call( req ); res = wine_server_call( req );
map_vprot = reply->protect; map_vprot = reply->protect;
sec_flags = reply->flags;
base = wine_server_get_ptr( reply->base ); base = wine_server_get_ptr( reply->base );
full_size = reply->size; full_size = reply->size;
header_size = reply->header_size; header_size = reply->header_size;
@ -2634,9 +2628,13 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
SERVER_END_REQ; SERVER_END_REQ;
if (res) return res; if (res) return res;
if (!(sec_flags & SEC_RESERVE)) map_vprot |= VPROT_COMMITTED;
if (sec_flags & SEC_NOCACHE) map_vprot |= VPROT_NOCACHE;
if (sec_flags & SEC_IMAGE) map_vprot |= VPROT_IMAGE;
if ((res = server_get_unix_fd( handle, 0, &unix_handle, &needs_close, NULL, NULL ))) goto done; if ((res = server_get_unix_fd( handle, 0, &unix_handle, &needs_close, NULL, NULL ))) goto done;
if (map_vprot & VPROT_IMAGE) if (sec_flags & SEC_IMAGE)
{ {
size = full_size; size = full_size;
if (size != full_size) /* truncated */ if (size != full_size) /* truncated */
@ -2689,7 +2687,7 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
server_enter_uninterrupted_section( &csVirtual, &sigset ); server_enter_uninterrupted_section( &csVirtual, &sigset );
get_vprot_flags( protect, &vprot, map_vprot & VPROT_IMAGE ); get_vprot_flags( protect, &vprot, sec_flags & SEC_IMAGE );
vprot |= (map_vprot & VPROT_COMMITTED); vprot |= (map_vprot & VPROT_COMMITTED);
res = map_view( &view, *addr_ptr, size, mask, FALSE, vprot ); res = map_view( &view, *addr_ptr, size, mask, FALSE, vprot );
if (res) if (res)

View File

@ -2129,8 +2129,8 @@ struct create_mapping_request
{ {
struct request_header __header; struct request_header __header;
unsigned int access; unsigned int access;
unsigned int flags;
unsigned int protect; unsigned int protect;
char __pad_20[4];
mem_size_t size; mem_size_t size;
obj_handle_t file_handle; obj_handle_t file_handle;
/* VARARG(objattr,object_attributes); */ /* VARARG(objattr,object_attributes); */
@ -2187,11 +2187,13 @@ struct get_mapping_info_reply
{ {
struct reply_header __header; struct reply_header __header;
mem_size_t size; mem_size_t size;
unsigned int flags;
int protect; int protect;
int header_size;
client_ptr_t base; client_ptr_t base;
int header_size;
obj_handle_t mapping; obj_handle_t mapping;
obj_handle_t shared_file; obj_handle_t shared_file;
char __pad_44[4];
}; };
@ -6221,6 +6223,6 @@ union generic_reply
struct terminate_job_reply terminate_job_reply; struct terminate_job_reply terminate_job_reply;
}; };
#define SERVER_PROTOCOL_VERSION 504 #define SERVER_PROTOCOL_VERSION 505
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */ #endif /* __WINE_WINE_SERVER_PROTOCOL_H */

View File

@ -728,10 +728,13 @@ typedef struct _MEMORY_BASIC_INFORMATION
#define SEC_FILE 0x00800000 #define SEC_FILE 0x00800000
#define SEC_IMAGE 0x01000000 #define SEC_IMAGE 0x01000000
#define SEC_PROTECTED_IMAGE 0x02000000
#define SEC_RESERVE 0x04000000 #define SEC_RESERVE 0x04000000
#define SEC_COMMIT 0x08000000 #define SEC_COMMIT 0x08000000
#define SEC_NOCACHE 0x10000000 #define SEC_NOCACHE 0x10000000
#define SEC_WRITECOMBINE 0x40000000
#define SEC_LARGE_PAGES 0x80000000 #define SEC_LARGE_PAGES 0x80000000
#define SEC_IMAGE_NO_EXECUTE (SEC_IMAGE | SEC_NOCACHE)
#define MEM_IMAGE SEC_IMAGE #define MEM_IMAGE SEC_IMAGE
#define WRITE_WATCH_FLAG_RESET 0x00000001 #define WRITE_WATCH_FLAG_RESET 0x00000001

View File

@ -59,6 +59,7 @@ struct mapping
{ {
struct object obj; /* object header */ struct object obj; /* object header */
mem_size_t size; /* mapping size */ mem_size_t size; /* mapping size */
unsigned int flags; /* SEC_* flags */
int protect; /* protection flags */ int protect; /* protection flags */
struct fd *fd; /* fd for mapped file */ struct fd *fd; /* fd for mapped file */
enum cpu_type cpu; /* client CPU (for PE image mapping) */ enum cpu_type cpu; /* client CPU (for PE image mapping) */
@ -372,7 +373,7 @@ static int build_shared_mapping( struct mapping *mapping, int fd,
} }
/* retrieve the mapping parameters for an executable (PE) image */ /* retrieve the mapping parameters for an executable (PE) image */
static unsigned int get_image_params( struct mapping *mapping, int unix_fd, int protect ) static unsigned int get_image_params( struct mapping *mapping, int unix_fd )
{ {
IMAGE_DOS_HEADER dos; IMAGE_DOS_HEADER dos;
IMAGE_SECTION_HEADER *sec = NULL; IMAGE_SECTION_HEADER *sec = NULL;
@ -461,7 +462,6 @@ static unsigned int get_image_params( struct mapping *mapping, int unix_fd, int
if (mapping->shared_file) list_add_head( &shared_list, &mapping->shared_entry ); if (mapping->shared_file) list_add_head( &shared_list, &mapping->shared_entry );
mapping->protect = protect;
free( sec ); free( sec );
return 0; return 0;
@ -471,7 +471,7 @@ static unsigned int get_image_params( struct mapping *mapping, int unix_fd, int
} }
static struct object *create_mapping( struct object *root, const struct unicode_str *name, static struct object *create_mapping( struct object *root, const struct unicode_str *name,
unsigned int attr, mem_size_t size, int protect, unsigned int attr, mem_size_t size, unsigned int flags, int protect,
obj_handle_t handle, const struct security_descriptor *sd ) obj_handle_t handle, const struct security_descriptor *sd )
{ {
struct mapping *mapping; struct mapping *mapping;
@ -490,6 +490,8 @@ static struct object *create_mapping( struct object *root, const struct unicode_
mapping->header_size = 0; mapping->header_size = 0;
mapping->base = 0; mapping->base = 0;
mapping->flags = flags & (SEC_IMAGE | SEC_NOCACHE | SEC_WRITECOMBINE | SEC_LARGE_PAGES);
mapping->protect = protect;
mapping->fd = NULL; mapping->fd = NULL;
mapping->shared_file = NULL; mapping->shared_file = NULL;
mapping->committed = NULL; mapping->committed = NULL;
@ -502,7 +504,7 @@ static struct object *create_mapping( struct object *root, const struct unicode_
const unsigned int sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; const unsigned int sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
unsigned int mapping_access = FILE_MAPPING_ACCESS; unsigned int mapping_access = FILE_MAPPING_ACCESS;
if (!(protect & VPROT_COMMITTED)) if (flags & SEC_RESERVE)
{ {
set_error( STATUS_INVALID_PARAMETER ); set_error( STATUS_INVALID_PARAMETER );
goto error; goto error;
@ -511,9 +513,10 @@ static struct object *create_mapping( struct object *root, const struct unicode_
fd = get_obj_fd( (struct object *)file ); fd = get_obj_fd( (struct object *)file );
/* file sharing rules for mappings are different so we use magic the access rights */ /* file sharing rules for mappings are different so we use magic the access rights */
if (protect & VPROT_IMAGE) mapping_access |= FILE_MAPPING_IMAGE; if (flags & SEC_IMAGE) mapping_access |= FILE_MAPPING_IMAGE;
else if (protect & VPROT_WRITE) mapping_access |= FILE_MAPPING_WRITE; else if (protect & VPROT_WRITE) mapping_access |= FILE_MAPPING_WRITE;
mapping->flags |= SEC_FILE;
if (!(mapping->fd = get_fd_object_for_mapping( fd, mapping_access, sharing ))) if (!(mapping->fd = get_fd_object_for_mapping( fd, mapping_access, sharing )))
{ {
mapping->fd = dup_fd_object( fd, mapping_access, sharing, FILE_SYNCHRONOUS_IO_NONALERT ); mapping->fd = dup_fd_object( fd, mapping_access, sharing, FILE_SYNCHRONOUS_IO_NONALERT );
@ -524,9 +527,9 @@ static struct object *create_mapping( struct object *root, const struct unicode_
if (!mapping->fd) goto error; if (!mapping->fd) goto error;
if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error; if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
if (protect & VPROT_IMAGE) if (flags & SEC_IMAGE)
{ {
unsigned int err = get_image_params( mapping, unix_fd, protect ); unsigned int err = get_image_params( mapping, unix_fd );
if (!err) return &mapping->obj; if (!err) return &mapping->obj;
set_error( err ); set_error( err );
goto error; goto error;
@ -548,12 +551,13 @@ static struct object *create_mapping( struct object *root, const struct unicode_
} }
else /* Anonymous mapping (no associated file) */ else /* Anonymous mapping (no associated file) */
{ {
if (!size || (protect & VPROT_IMAGE)) if (!size || (flags & SEC_IMAGE))
{ {
set_error( STATUS_INVALID_PARAMETER ); set_error( STATUS_INVALID_PARAMETER );
goto error; goto error;
} }
if (!(protect & VPROT_COMMITTED)) mapping->flags |= flags & (SEC_COMMIT | SEC_RESERVE);
if (flags & SEC_RESERVE)
{ {
if (!(mapping->committed = mem_alloc( offsetof(struct ranges, ranges[8]) ))) goto error; if (!(mapping->committed = mem_alloc( offsetof(struct ranges, ranges[8]) ))) goto error;
mapping->committed->count = 0; mapping->committed->count = 0;
@ -565,7 +569,6 @@ static struct object *create_mapping( struct object *root, const struct unicode_
allow_fd_caching( mapping->fd ); allow_fd_caching( mapping->fd );
} }
mapping->size = (size + page_mask) & ~((mem_size_t)page_mask); mapping->size = (size + page_mask) & ~((mem_size_t)page_mask);
mapping->protect = protect;
return &mapping->obj; return &mapping->obj;
error: error:
@ -601,10 +604,10 @@ static void mapping_dump( struct object *obj, int verbose )
{ {
struct mapping *mapping = (struct mapping *)obj; struct mapping *mapping = (struct mapping *)obj;
assert( obj->ops == &mapping_ops ); assert( obj->ops == &mapping_ops );
fprintf( stderr, "Mapping size=%08x%08x prot=%08x fd=%p header_size=%08x base=%08lx " fprintf( stderr, "Mapping size=%08x%08x flags=%08x prot=%08x fd=%p header_size=%08x base=%08lx "
"shared_file=%p\n", "shared_file=%p\n",
(unsigned int)(mapping->size >> 32), (unsigned int)mapping->size, (unsigned int)(mapping->size >> 32), (unsigned int)mapping->size,
mapping->protect, mapping->fd, mapping->header_size, mapping->flags, mapping->protect, mapping->fd, mapping->header_size,
(unsigned long)mapping->base, mapping->shared_file ); (unsigned long)mapping->base, mapping->shared_file );
} }
@ -665,7 +668,7 @@ DECL_HANDLER(create_mapping)
if (!objattr) return; if (!objattr) return;
if ((obj = create_mapping( root, &name, objattr->attributes, if ((obj = create_mapping( root, &name, objattr->attributes,
req->size, req->protect, req->file_handle, sd ))) req->size, req->flags, req->protect, req->file_handle, sd )))
{ {
if (get_error() == STATUS_OBJECT_NAME_EXISTS) if (get_error() == STATUS_OBJECT_NAME_EXISTS)
reply->handle = alloc_handle( current->process, obj, req->access, objattr->attributes ); reply->handle = alloc_handle( current->process, obj, req->access, objattr->attributes );
@ -695,18 +698,19 @@ DECL_HANDLER(get_mapping_info)
if (!(mapping = get_mapping_obj( current->process, req->handle, req->access ))) return; if (!(mapping = get_mapping_obj( current->process, req->handle, req->access ))) return;
if ((mapping->protect & VPROT_IMAGE) && mapping->cpu != current->process->cpu) reply->size = mapping->size;
reply->flags = mapping->flags;
reply->protect = mapping->protect;
reply->header_size = mapping->header_size;
reply->base = mapping->base;
if ((mapping->flags & SEC_IMAGE) && mapping->cpu != current->process->cpu)
{ {
set_error( STATUS_INVALID_IMAGE_FORMAT ); set_error( STATUS_INVALID_IMAGE_FORMAT );
release_object( mapping ); release_object( mapping );
return; return;
} }
reply->size = mapping->size;
reply->protect = mapping->protect;
reply->header_size = mapping->header_size;
reply->base = mapping->base;
reply->shared_file = 0;
if ((fd = get_obj_fd( &mapping->obj ))) if ((fd = get_obj_fd( &mapping->obj )))
{ {
if (!is_fd_removable(fd)) reply->mapping = alloc_handle( current->process, mapping, 0, 0 ); if (!is_fd_removable(fd)) reply->mapping = alloc_handle( current->process, mapping, 0, 0 );

View File

@ -1651,6 +1651,7 @@ enum char_info_mode
/* Create a file mapping */ /* Create a file mapping */
@REQ(create_mapping) @REQ(create_mapping)
unsigned int access; /* wanted access rights */ unsigned int access; /* wanted access rights */
unsigned int flags; /* SEC_* flags */
unsigned int protect; /* protection flags (see below) */ unsigned int protect; /* protection flags (see below) */
mem_size_t size; /* mapping size */ mem_size_t size; /* mapping size */
obj_handle_t file_handle; /* file handle */ obj_handle_t file_handle; /* file handle */
@ -1691,9 +1692,10 @@ enum char_info_mode
unsigned int access; /* wanted access rights */ unsigned int access; /* wanted access rights */
@REPLY @REPLY
mem_size_t size; /* mapping size */ mem_size_t size; /* mapping size */
unsigned int flags; /* SEC_* flags */
int protect; /* protection flags */ int protect; /* protection flags */
int header_size; /* header size (for VPROT_IMAGE mapping) */
client_ptr_t base; /* default base addr (for VPROT_IMAGE mapping) */ client_ptr_t base; /* default base addr (for VPROT_IMAGE mapping) */
int header_size; /* header size (for VPROT_IMAGE mapping) */
obj_handle_t mapping; /* duplicate mapping handle unless removable */ obj_handle_t mapping; /* duplicate mapping handle unless removable */
obj_handle_t shared_file; /* shared mapping file handle */ obj_handle_t shared_file; /* shared mapping file handle */
@END @END

View File

@ -1211,7 +1211,8 @@ C_ASSERT( FIELD_OFFSET(struct read_change_request, handle) == 12 );
C_ASSERT( sizeof(struct read_change_request) == 16 ); C_ASSERT( sizeof(struct read_change_request) == 16 );
C_ASSERT( sizeof(struct read_change_reply) == 8 ); 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, access) == 12 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, protect) == 16 ); 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, size) == 24 ); C_ASSERT( FIELD_OFFSET(struct create_mapping_request, size) == 24 );
C_ASSERT( FIELD_OFFSET(struct create_mapping_request, file_handle) == 32 ); C_ASSERT( FIELD_OFFSET(struct create_mapping_request, file_handle) == 32 );
C_ASSERT( sizeof(struct create_mapping_request) == 40 ); C_ASSERT( sizeof(struct create_mapping_request) == 40 );
@ -1227,12 +1228,13 @@ C_ASSERT( FIELD_OFFSET(struct get_mapping_info_request, handle) == 12 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_request, access) == 16 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_info_request, access) == 16 );
C_ASSERT( sizeof(struct get_mapping_info_request) == 24 ); 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, size) == 8 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, protect) == 16 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, flags) == 16 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, header_size) == 20 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, protect) == 20 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, base) == 24 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, base) == 24 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, mapping) == 32 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, header_size) == 32 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, shared_file) == 36 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, mapping) == 36 );
C_ASSERT( sizeof(struct get_mapping_info_reply) == 40 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_info_reply, shared_file) == 40 );
C_ASSERT( sizeof(struct get_mapping_info_reply) == 48 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_committed_range_request, handle) == 12 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_committed_range_request, handle) == 12 );
C_ASSERT( FIELD_OFFSET(struct get_mapping_committed_range_request, offset) == 16 ); C_ASSERT( FIELD_OFFSET(struct get_mapping_committed_range_request, offset) == 16 );
C_ASSERT( sizeof(struct get_mapping_committed_range_request) == 24 ); C_ASSERT( sizeof(struct get_mapping_committed_range_request) == 24 );

View File

@ -2144,6 +2144,7 @@ static void dump_read_change_reply( const struct read_change_reply *req )
static void dump_create_mapping_request( const struct create_mapping_request *req ) static void dump_create_mapping_request( const struct create_mapping_request *req )
{ {
fprintf( stderr, " access=%08x", req->access ); fprintf( stderr, " access=%08x", req->access );
fprintf( stderr, ", flags=%08x", req->flags );
fprintf( stderr, ", protect=%08x", req->protect ); fprintf( stderr, ", protect=%08x", req->protect );
dump_uint64( ", size=", &req->size ); dump_uint64( ", size=", &req->size );
fprintf( stderr, ", file_handle=%04x", req->file_handle ); fprintf( stderr, ", file_handle=%04x", req->file_handle );
@ -2177,9 +2178,10 @@ static void dump_get_mapping_info_request( const struct get_mapping_info_request
static void dump_get_mapping_info_reply( const struct get_mapping_info_reply *req ) static void dump_get_mapping_info_reply( const struct get_mapping_info_reply *req )
{ {
dump_uint64( " size=", &req->size ); dump_uint64( " size=", &req->size );
fprintf( stderr, ", flags=%08x", req->flags );
fprintf( stderr, ", protect=%d", req->protect ); fprintf( stderr, ", protect=%d", req->protect );
fprintf( stderr, ", header_size=%d", req->header_size );
dump_uint64( ", base=", &req->base ); dump_uint64( ", base=", &req->base );
fprintf( stderr, ", header_size=%d", req->header_size );
fprintf( stderr, ", mapping=%04x", req->mapping ); fprintf( stderr, ", mapping=%04x", req->mapping );
fprintf( stderr, ", shared_file=%04x", req->shared_file ); fprintf( stderr, ", shared_file=%04x", req->shared_file );
} }