aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Brown <kbrown@cornell.edu>2024-12-29 18:20:07 -0500
committerKen Brown <kbrown@cornell.edu>2025-01-09 17:51:27 -0500
commitfb8681e4ca9cb4c491a376b2de0e2a06b35890f0 (patch)
tree39f47e24b25d97d5fa14f1ba3283bf6e11c3ad01
parentceda26c9d35b7a53705685e82541fa9b6b9b05ee (diff)
downloadnewlib-fb8681e4ca9cb4c491a376b2de0e2a06b35890f0.zip
newlib-fb8681e4ca9cb4c491a376b2de0e2a06b35890f0.tar.gz
newlib-fb8681e4ca9cb4c491a376b2de0e2a06b35890f0.tar.bz2
Cygwin: mmap_list::try_map: simplify
Save the result of mmap_record::find_unused pages, and then pass that result to the appropriate version of mmap_record::map_pages. Add a new parameter of type off_t to the latter to make this possible, and change its return type from off_t to bool. This saves map_pages from having to call find_unused_pages again. Signed-off-by: Ken Brown <kbrown@cornell.edu>
-rw-r--r--winsup/cygwin/mm/mmap.cc30
1 files changed, 14 insertions, 16 deletions
diff --git a/winsup/cygwin/mm/mmap.cc b/winsup/cygwin/mm/mmap.cc
index 7fc8cb0..501d37b 100644
--- a/winsup/cygwin/mm/mmap.cc
+++ b/winsup/cygwin/mm/mmap.cc
@@ -328,7 +328,7 @@ class mmap_record
bool match (caddr_t addr, SIZE_T len, caddr_t &m_addr, SIZE_T &m_len,
bool &contains);
bool match (caddr_t addr, SIZE_T len, caddr_t &m_addr, SIZE_T &m_len);
- off_t map_pages (SIZE_T len, int new_prot);
+ bool map_pages (SIZE_T len, int new_prot, off_t off);
bool map_pages (caddr_t addr, SIZE_T len, int new_prot);
bool unmap_pages (caddr_t addr, SIZE_T len);
int access (caddr_t address);
@@ -457,21 +457,18 @@ mmap_record::init_page_map (mmap_record &r)
MAP_SET (len);
}
-off_t
-mmap_record::map_pages (SIZE_T len, int new_prot)
+bool
+mmap_record::map_pages (SIZE_T len, int new_prot, off_t off)
{
- /* Used ONLY if this mapping matches into the chunk of another already
- performed mapping in a special case of MAP_ANON|MAP_PRIVATE.
-
- Otherwise it's job is now done by init_page_map(). */
+ /* Used only in a MAP_ANON|MAP_PRIVATE request for len bytes, with
+ MAP_FIXED not given. Moreover, we know when this function is
+ called that this record contains enough unused pages starting at
+ off to satisfy the request. */
DWORD old_prot;
debug_printf ("map_pages (fd=%d, len=%lu, new_prot=%y)", get_fd (), len,
new_prot);
len = PAGE_CNT (len);
- off_t off = find_unused_pages (len);
- if (off == (off_t) -1)
- return (off_t) 0;
if (!noreserve ()
&& !VirtualProtect (get_address () + off * wincap.page_size (),
len * wincap.page_size (),
@@ -479,12 +476,12 @@ mmap_record::map_pages (SIZE_T len, int new_prot)
&old_prot))
{
__seterrno ();
- return (off_t) -1;
+ return false;
}
while (len-- > 0)
MAP_SET (off + len);
- return off * wincap.page_size ();
+ return true;
}
bool
@@ -638,13 +635,14 @@ mmap_list::try_map (void *addr, size_t len, int new_prot, int flags, off_t off)
mapping. */
SIZE_T plen = PAGE_CNT (len);
LIST_FOREACH (rec, &recs, mr_next)
- if (rec->find_unused_pages (plen) != (SIZE_T) -1)
+ if ((off = rec->find_unused_pages (plen)) != (off_t) -1
+ && rec->compatible_flags (flags))
break;
- if (rec && rec->compatible_flags (flags))
+ if (rec)
{
- if ((off = rec->map_pages (len, new_prot)) == (off_t) -1)
+ if (!rec->map_pages (len, new_prot, off))
return (caddr_t) MAP_FAILED;
- return (caddr_t) rec->get_address () + off;
+ return (caddr_t) rec->get_address () + off * wincap.page_size ();
}
}
else if (fixed (flags))