Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2005-03-01 14:51:29 +0300
committerCorinna Vinschen <corinna@vinschen.de>2005-03-01 14:51:29 +0300
commit4717214c201b6d54b7c58d1fedf6e88c5336f55c (patch)
treea744789ae843e8d73f7a0c2f78ba8862bca80104 /winsup/cygwin/mmap.cc
parent93c60b6d6a34653d966a90f2bdb4fd6e28ed0a76 (diff)
* fhandler_clipboard.cc (fhandler_dev_clipboard::write): Never set
errno to 0. (fhandler_dev_clipboard::read): Ditto. * fhandler_windows.cc (fhandler_windows::read): Ditto. * scandir.cc (scandir): Ditto. * syscalls.cc (_fstat64_r): Ditto. (_fstat_r): Ditto. (_stat64_r): Ditto. (_stat_r): Ditto. * mmap.cc (mmap64): Fix /dev/zero mapping.
Diffstat (limited to 'winsup/cygwin/mmap.cc')
-rw-r--r--winsup/cygwin/mmap.cc79
1 files changed, 42 insertions, 37 deletions
diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc
index 36db16ce6..9a34ba4d2 100644
--- a/winsup/cygwin/mmap.cc
+++ b/winsup/cygwin/mmap.cc
@@ -538,24 +538,9 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
if (flags & MAP_ANONYMOUS)
fd = -1;
- /* 9x only: If MAP_FIXED is requested on a non-granularity boundary,
- change request so that this looks like a request with offset
- addr % granularity. */
- if (wincap.share_mmaps_only_by_name () && fd == -1 && (flags & MAP_FIXED)
- && ((DWORD)addr % granularity) && !off)
- off = (DWORD)addr % granularity;
- /* Map always in multipliers of `granularity'-sized chunks.
- Not necessary for anonymous maps on NT. */
- _off64_t gran_off = off;
- DWORD gran_len = len;
- if (wincap.share_mmaps_only_by_name () || fd != -1)
- {
- gran_off = off & ~(granularity - 1);
- gran_len = howmany (off + len, granularity) * granularity - gran_off;
- }
-
fhandler_base *fh;
+ /* Get fhandler and convert /dev/zero mapping to MAP_ANONYMOUS mapping. */
if (fd != -1)
{
/* Ensure that fd is open */
@@ -567,27 +552,8 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
return MAP_FAILED;
}
fh = cfd;
- if (fh->get_device () == FH_FS)
- {
- DWORD high;
- DWORD low = GetFileSize (fh->get_handle (), &high);
- _off64_t fsiz = ((_off64_t)high << 32) + low;
- /* Don't allow mappings beginning beyond EOF since Windows can't
- handle that POSIX like. FIXME: Still looking for a good idea
- to allow that nevertheless. */
- if (gran_off >= fsiz)
- {
- set_errno (ENXIO);
- ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
- "mmap");
- return MAP_FAILED;
- }
- fsiz -= gran_off;
- if (gran_len > fsiz)
- gran_len = fsiz;
- }
- else if (fh->get_device () == FH_ZERO)
- {
+ if (fh->get_device () == FH_ZERO)
+ {
/* mmap /dev/zero is like MAP_ANONYMOUS. */
fd = -1;
flags |= MAP_ANONYMOUS;
@@ -599,6 +565,45 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
fh = &fh_paging_file;
}
+ /* 9x only: If MAP_FIXED is requested on a non-granularity boundary,
+ change request so that this looks like a request with offset
+ addr % granularity. */
+ if (wincap.share_mmaps_only_by_name () && fd == -1 && (flags & MAP_FIXED)
+ && ((DWORD)addr % granularity) && !off)
+ off = (DWORD)addr % granularity;
+ /* Map always in multipliers of `granularity'-sized chunks.
+ Not necessary for anonymous maps on NT. */
+ _off64_t gran_off = off;
+ DWORD gran_len = len;
+ if (wincap.share_mmaps_only_by_name () || fd != -1)
+ {
+ gran_off = off & ~(granularity - 1);
+ gran_len = howmany (off + len, granularity) * granularity - gran_off;
+ }
+
+ /* File mappings needs some extra care. */
+ if (fd != -1 && fh->get_device () == FH_FS)
+ {
+ DWORD high;
+ DWORD low = GetFileSize (fh->get_handle (), &high);
+ _off64_t fsiz = ((_off64_t)high << 32) + low;
+ /* Don't allow mappings beginning beyond EOF since Windows can't
+ handle that POSIX like. FIXME: Still looking for a good idea
+ to allow that nevertheless. */
+ if (gran_off >= fsiz)
+ {
+ set_errno (ENXIO);
+ ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
+ "mmap");
+ return MAP_FAILED;
+ }
+ /* Don't map beyond EOF. Windows would change the file to the
+ new length otherwise, in contrast to POSIX. */
+ fsiz -= gran_off;
+ if (gran_len > fsiz)
+ gran_len = fsiz;
+ }
+
DWORD access = (prot & PROT_WRITE) ? FILE_MAP_WRITE : FILE_MAP_READ;
/* copy-on-write doesn't work at all on 9x using anonymous maps.
Workaround: Anonymous mappings always use normal READ or WRITE