* mmap.cc (mmap): Move setting the access after evaluating fd.

Remove useless comment.  Explain copy-on-write problem of 9x
        more detailed.  Don't set access to FILE_MAP_COPY on 9x only
        when anonymous mapping is requested.
        (fhandler_disk_file::mmap): Remove useless device check.
        Add debug output.
This commit is contained in:
Corinna Vinschen 2001-09-27 22:39:50 +00:00
parent c814d12f04
commit f4f30cf140
2 changed files with 26 additions and 24 deletions

View File

@ -1,3 +1,12 @@
Sat Sep 28 00:34:00 2001 Corinna Vinschen <corinna@vinschen.de>
* mmap.cc (mmap): Move setting the access after evaluating fd.
Remove useless comment. Explain copy-on-write problem of 9x
more detailed. Don't set access to FILE_MAP_COPY on 9x only
when anonymous mapping is requested.
(fhandler_disk_file::mmap): Remove useless device check.
Add debug output.
Fri Sep 27 07:35:00 2001 Robert Collins <rbtcollins@hotmail.com> Fri Sep 27 07:35:00 2001 Robert Collins <rbtcollins@hotmail.com>
* Makefile.in: Only stamp winver_stamp on success. * Makefile.in: Only stamp winver_stamp on success.

View File

@ -422,30 +422,8 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
return MAP_FAILED; return MAP_FAILED;
} }
DWORD access = (prot & PROT_WRITE) ? FILE_MAP_WRITE : FILE_MAP_READ;
/* copy-on-write doesn't work correctly on 9x. To have at least read
access we use *READ mapping on 9x when appropriate. It will still
fail when needing write access, though. */
if ((flags & MAP_PRIVATE) && (wincap.has_working_copy_on_write ()
|| (prot & ~PROT_READ)))
access = FILE_MAP_COPY;
SetResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap"); SetResourceLock(LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
#if 0
/* Windows 95 does not have fixed addresses */
/*
* CV: This assumption isn't correct. See Microsoft Platform SDK, Memory,
* description of call `MapViewOfFileEx'.
*/
if ((!wincap.is_winnt ()) && (flags & MAP_FIXED))
{
set_errno (EINVAL);
syscall_printf ("-1 = mmap(): win95 and MAP_FIXED");
return MAP_FAILED;
}
#endif
if (mmapped_areas == NULL) if (mmapped_areas == NULL)
{ {
/* First mmap call, create STL map */ /* First mmap call, create STL map */
@ -516,6 +494,21 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
} }
} }
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
access and don't use named file mapping.
copy-on-write doesn't also work properly on 9x with real files.
While the changes are not propagated to the file, they are
visible to other processes sharing the same file mapping object.
Workaround: Don't use named file mapping. That should work since
sharing file mappings only works reliable using named
file mapping on 9x.
*/
if ((flags & MAP_PRIVATE)
&& (wincap.has_working_copy_on_write () || fd != -1))
access = FILE_MAP_COPY;
h = fh->mmap (&base, gran_len, access, flags, gran_off); h = fh->mmap (&base, gran_len, access, flags, gran_off);
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
@ -748,7 +741,6 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access,
objects between processes by name. What a mess... */ objects between processes by name. What a mess... */
if (wincap.share_mmaps_only_by_name () if (wincap.share_mmaps_only_by_name ()
&& get_handle () != INVALID_HANDLE_VALUE && get_handle () != INVALID_HANDLE_VALUE
&& get_device () == FH_DISK
&& !(access & FILE_MAP_COPY)) && !(access & FILE_MAP_COPY))
{ {
/* Grrr, the whole stuff is just needed to try to get a reliable /* Grrr, the whole stuff is just needed to try to get a reliable
@ -759,6 +751,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access,
for (int i = strlen (namebuf) - 1; i >= 0; --i) for (int i = strlen (namebuf) - 1; i >= 0; --i)
namebuf[i] = cyg_tolower (namebuf [i]); namebuf[i] = cyg_tolower (namebuf [i]);
debug_printf ("named sharing");
if (!(h = OpenFileMapping (access, TRUE, namebuf))) if (!(h = OpenFileMapping (access, TRUE, namebuf)))
h = CreateFileMapping (get_handle(), &sec_none, protect, 0, 0, namebuf); h = CreateFileMapping (get_handle(), &sec_none, protect, 0, 0, namebuf);
} }
@ -775,7 +768,7 @@ fhandler_disk_file::mmap (caddr_t *addr, size_t len, DWORD access,
void *base = MapViewOfFileEx (h, access, 0, off, len, void *base = MapViewOfFileEx (h, access, 0, off, len,
(flags & MAP_FIXED) ? *addr : NULL); (flags & MAP_FIXED) ? *addr : NULL);
debug_printf ("%x = MapViewOfFileEx (h:%x, access:%x, 0, off:%d, len:%d, addr:%x)", base, h, access, off, len, (flags & MAP_FIXED) ? *addr : NULL);
if (!base || ((flags & MAP_FIXED) && base != *addr)) if (!base || ((flags & MAP_FIXED) && base != *addr))
{ {
if (!base) if (!base)