2007-09-18 Corinna Vinschen <corinna@vinschen.de>
+ * mmap.cc (fh_disk_file): Delete as global static variable and...
+ (mmap64): ...define as local pointer to make mmap thread-safe.
+ Accommodate throughout. Only initialize fh_disk_file after file could
+ be opened with GENERIC_EXECUTE access. Call fstat_by_handle instead of
+ fstat to avoid overhead.
+
+2007-09-18 Corinna Vinschen <corinna@vinschen.de>
+
* security.cc (set_file_sd): Open file with FILE_OPEN_FOR_BACKUP_INTENT
too.
/* Used for anonymous mappings. */
static fhandler_dev_zero fh_anonymous;
-/* Used for reopening a disk file when necessary. */
-static fhandler_disk_file fh_disk_file;
/* Small helpers to avoid having lots of flag bit tests in the code. */
static inline bool
caddr_t ret = (caddr_t) MAP_FAILED;
fhandler_base *fh = NULL;
+ fhandler_disk_file *fh_disk_file = NULL; /* Used for reopening a disk file
+ when necessary. */
list *map_list = NULL;
size_t orig_len = 0;
caddr_t base = NULL;
fh_anonymous.set_io_handle (INVALID_HANDLE_VALUE);
fh_anonymous.set_access (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
- fh_disk_file.set_io_handle (NULL);
SetResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
| FILE_OPEN_FOR_BACKUP_INTENT);
if (NT_SUCCESS (status))
{
- fh_disk_file.set_io_handle (h);
- fh_disk_file.set_access (fh->get_access () | GENERIC_EXECUTE);
- fh = &fh_disk_file;
+ fh_disk_file = new (alloca (sizeof *fh_disk_file)) fhandler_disk_file;
+ fh_disk_file->set_name (fh->pc);
+ fh_disk_file->set_io_handle (h);
+ fh_disk_file->set_access (fh->get_access () | GENERIC_EXECUTE);
+ fh = fh_disk_file;
}
else if (prot & PROT_EXEC)
{
goto out;
}
- if (fh->fstat (&st))
+ if (fh->fstat_by_handle (&st))
{
__seterrno ();
goto out;
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
- if (fh_disk_file.get_handle ())
- NtClose (fh_disk_file.get_handle ());
+ if (fh_disk_file)
+ NtClose (fh_disk_file->get_handle ());
syscall_printf ("%p = mmap() ", ret);
return ret;