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>2007-01-09 14:18:57 +0300
committerCorinna Vinschen <corinna@vinschen.de>2007-01-09 14:18:57 +0300
commitd5b45d2f386d6131fcef8c634acc9dfec70d9903 (patch)
treeb0cc96b080a214d9bb8c37b506ee0d95a1d361ae /winsup/cygwin/mmap.cc
parentd234d96e670281f9900d884a83c43e7a41c4d5ad (diff)
* mmap.cc: Do bookkeeping in 4K pages, rather than in 64K chunks.
Diffstat (limited to 'winsup/cygwin/mmap.cc')
-rw-r--r--winsup/cygwin/mmap.cc40
1 files changed, 22 insertions, 18 deletions
diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc
index 31bac5869..14a09b5bd 100644
--- a/winsup/cygwin/mmap.cc
+++ b/winsup/cygwin/mmap.cc
@@ -1,7 +1,7 @@
/* mmap.cc
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
- 2006 Red Hat, Inc.
+ 2006, 2007 Red Hat, Inc.
This file is part of Cygwin.
@@ -36,7 +36,9 @@ details. */
expect to be able to access this part the same way as the file pages. */
#define __PROT_FILLER 0x4000000
-#define PAGE_CNT(bytes) howmany((bytes),getpagesize())
+/* Stick with 4K pages for bookkeeping, otherwise we just get confused
+ when trying to do file mappings with trailing filler pages correctly. */
+#define PAGE_CNT(bytes) howmany((bytes),getsystempagesize())
#define PGBITS (sizeof (DWORD)*8)
#define MAPSIZE(pages) howmany ((pages), PGBITS)
@@ -602,8 +604,9 @@ mmap_record::map_pages (_off64_t off, DWORD len)
if ((off = find_unused_pages (len)) == (DWORD)-1)
return 0L;
if (!noreserve ()
- && !VirtualProtect (get_address () + off * getpagesize (),
- len * getpagesize (), gen_protect (), &old_prot))
+ && !VirtualProtect (get_address () + off * getsystempagesize (),
+ len * getsystempagesize (), gen_protect (),
+ &old_prot))
{
__seterrno ();
return (_off64_t)-1;
@@ -611,7 +614,7 @@ mmap_record::map_pages (_off64_t off, DWORD len)
while (len-- > 0)
MAP_SET (off + len);
- return off * getpagesize ();
+ return off * getsystempagesize ();
}
bool
@@ -620,7 +623,7 @@ mmap_record::map_pages (caddr_t addr, DWORD len)
debug_printf ("map_pages (addr=%x, len=%u)", addr, len);
DWORD old_prot;
DWORD off = addr - get_address ();
- off /= getpagesize ();
+ off /= getsystempagesize ();
len = PAGE_CNT (len);
/* First check if the area is unused right now. */
for (DWORD l = 0; l < len; ++l)
@@ -630,8 +633,9 @@ mmap_record::map_pages (caddr_t addr, DWORD len)
return false;
}
if (!noreserve ()
- && !VirtualProtect (get_address () + off * getpagesize (),
- len * getpagesize (), gen_protect (), &old_prot))
+ && !VirtualProtect (get_address () + off * getsystempagesize (),
+ len * getsystempagesize (), gen_protect (),
+ &old_prot))
{
__seterrno ();
return false;
@@ -646,16 +650,15 @@ mmap_record::unmap_pages (caddr_t addr, DWORD len)
{
DWORD old_prot;
DWORD off = addr - get_address ();
- off /= getpagesize ();
- len = PAGE_CNT (len);
if (noreserve ()
- && !VirtualFree (get_address () + off * getpagesize (),
- len * getpagesize (), MEM_DECOMMIT))
+ && !VirtualFree (get_address () + off, len, MEM_DECOMMIT))
debug_printf ("VirtualFree in unmap_pages () failed, %E");
- else if (!VirtualProtect (get_address () + off * getpagesize (),
- len * getpagesize (), PAGE_NOACCESS, &old_prot))
+ else if (!VirtualProtect (get_address () + off, len, PAGE_NOACCESS,
+ &old_prot))
debug_printf ("VirtualProtect in unmap_pages () failed, %E");
+ off /= getsystempagesize ();
+ len = PAGE_CNT (len);
for (; len-- > 0; ++off)
MAP_CLR (off);
/* Return TRUE if all pages are free'd which may result in unmapping
@@ -671,7 +674,7 @@ mmap_record::access (caddr_t address)
{
if (address < get_address () || address >= get_address () + get_len ())
return 0;
- DWORD off = (address - get_address ()) / getpagesize ();
+ DWORD off = (address - get_address ()) / getsystempagesize ();
return MAP_ISSET (off);
}
@@ -740,8 +743,9 @@ list::search_record (_off64_t off, DWORD len)
{
for (int i = 0; i < nrecs; ++i)
if (off >= recs[i].get_offset ()
- && off + len <= recs[i].get_offset ()
- + (PAGE_CNT (recs[i].get_len ()) * getpagesize ()))
+ && off + len
+ <= recs[i].get_offset ()
+ + (PAGE_CNT (recs[i].get_len ()) * getsystempagesize ()))
return recs + i;
}
return NULL;
@@ -761,7 +765,7 @@ list::search_record (caddr_t addr, DWORD len, caddr_t &m_addr, DWORD &m_len,
if (recs[i].filler ())
high += recs[i].get_len ();
else
- high += (PAGE_CNT (recs[i].get_len ()) * getpagesize ());
+ high += (PAGE_CNT (recs[i].get_len ()) * getsystempagesize ());
high = (addr + len < high) ? addr + len : high;
if (low < high)
{