mem_size_t size; /* mapping size */
int protect; /* protection flags */
struct fd *fd; /* fd for mapped file */
- struct file *file; /* file mapped */
int header_size; /* size of headers (for PE image mapping) */
client_ptr_t base; /* default base addr (for PE image mapping) */
struct ranges *committed; /* list of committed ranges in this mapping */
return 0;
}
+/* create a temp file for anonymous mappings */
+static int create_temp_file( file_pos_t size )
+{
+ char tmpfn[16];
+ int fd;
+
+ sprintf( tmpfn, "anonmap.XXXXXX" ); /* create it in the server directory */
+ fd = mkstemps( tmpfn, 0 );
+ if (fd != -1)
+ {
+ if (!grow_file( fd, size ))
+ {
+ close( fd );
+ fd = -1;
+ }
+ unlink( tmpfn );
+ }
+ else file_set_error();
+ return fd;
+}
+
/* find the shared PE mapping for a given mapping */
static struct file *get_shared_file( struct mapping *mapping )
{
/* create a temp file for the mapping */
- if (!(mapping->shared_file = create_temp_file( FILE_GENERIC_READ|FILE_GENERIC_WRITE ))) return 0;
- if ((shared_fd = get_file_unix_fd( mapping->shared_file )) == -1) goto error;
- if (!grow_file( shared_fd, total_size )) goto error;
+ if ((shared_fd = create_temp_file( total_size )) == -1) return 0;
+ if (!(mapping->shared_file = create_file_for_fd( shared_fd, FILE_GENERIC_READ|FILE_GENERIC_WRITE, 0 )))
+ return 0;
if (!(buffer = malloc( max_size ))) goto error;
mapping->header_size = 0;
mapping->base = 0;
mapping->fd = NULL;
- mapping->file = NULL;
mapping->shared_file = NULL;
mapping->committed = NULL;
if (handle)
{
+ unsigned int mapping_access = FILE_MAPPING_ACCESS;
+
if (!(protect & VPROT_COMMITTED))
{
set_error( STATUS_INVALID_PARAMETER );
}
if (!(file = get_file_obj( current->process, handle, access ))) goto error;
fd = get_obj_fd( (struct object *)file );
- mapping->fd = dup_fd_object( fd );
+
+ /* file sharing rules for mappings are different so we use magic the access rights */
+ if (protect & VPROT_IMAGE) mapping_access |= FILE_MAPPING_IMAGE;
+ else if (protect & VPROT_WRITE) mapping_access |= FILE_MAPPING_WRITE;
+ mapping->fd = dup_fd_object( fd, mapping_access,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ FILE_SYNCHRONOUS_IO_NONALERT );
release_object( file );
release_object( fd );
if (!mapping->fd) goto error;
mapping->committed->count = 0;
mapping->committed->max = 8;
}
- if (!(mapping->file = create_temp_file( access ))) goto error;
- mapping->fd = get_obj_fd( (struct object *)mapping->file );
- if ((unix_fd = get_unix_fd( mapping->fd )) == -1) goto error;
- if (!grow_file( unix_fd, size )) goto error;
+ if ((unix_fd = create_temp_file( size )) == -1) goto error;
+ if (!(mapping->fd = create_anonymous_fd( &mapping_fd_ops, unix_fd, &mapping->obj,
+ FILE_SYNCHRONOUS_IO_NONALERT ))) goto error;
+ allow_fd_caching( mapping->fd );
}
mapping->size = (size + page_mask) & ~((mem_size_t)page_mask);
mapping->protect = protect;
{
struct mapping *mapping = (struct mapping *)obj;
assert( obj->ops == &mapping_ops );
- if (mapping->file) release_object( mapping->file );
if (mapping->fd) release_object( mapping->fd );
if (mapping->shared_file)
{