diff options
Diffstat (limited to 'winsup/cygwin/mmap.cc')
-rw-r--r-- | winsup/cygwin/mmap.cc | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index d7eed339362..88b98523339 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -49,8 +49,6 @@ details. */ /* 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 @@ -983,6 +981,8 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off) 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; @@ -992,7 +992,6 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off) 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"); @@ -1078,12 +1077,13 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off) set_errno (EACCES); goto out; } - fh_disk_file.set_io_handle (h); - fh_disk_file.set_access (fh->get_access () | GENERIC_WRITE); + fh_disk_file = new (alloca (sizeof *fh_disk_file)) fhandler_disk_file; path_conv pc; pc.set_name (fh->get_win32_name (), ""); - fh_disk_file.set_name (pc); - fh = &fh_disk_file; + fh_disk_file->set_name (pc); + fh_disk_file->set_io_handle (h); + fh_disk_file->set_access (fh->get_access () | GENERIC_WRITE); + fh = fh_disk_file; } /* On NT you can't create mappings with PAGE_EXECUTE protection if @@ -1096,9 +1096,13 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off) OPEN_EXISTING, 0, NULL); if (h != INVALID_HANDLE_VALUE) { - 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; + path_conv pc; + pc.set_name (fh->get_win32_name (), ""); + fh_disk_file->set_name (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) { @@ -1294,8 +1298,8 @@ out: ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap"); - if (fh_disk_file.get_handle ()) - CloseHandle (fh_disk_file.get_handle ()); + if (fh_disk_file) + CloseHandle (fh_disk_file->get_handle ()); syscall_printf ("%p = mmap() ", ret); return ret; |