munmap slowness; IsBadReadPtr considered harmful

Corinna Vinschen
Wed Feb 25 10:55:00 GMT 2004

On Feb 24 17:23, Brian Ford wrote:
> On Tue, 24 Feb 2004, Corinna Vinschen wrote:
> > 5.) No one has enough spare time currently.
> >
> Yeah, I hoped that was it.  But, I saw enough activity from you and Chris
> on the cygwin list about, IMHO, less interesting issues, that I wondered.

I must admit that my attention span is somewhat restricted currently.

> > AFAIU VirtualQuery, it returns information about consecutive pages
> > which share the same attributes.  So the length returned must be >=
> > the len parameter or you must check the actual attributes returned
> > by VirtualQuery.
> >
> Um, why must it be >= len?  I agree about checking the attributes, though.

Sorry, I didn't look into your function closely enough.  Scratch my

> I guess it all depends on your interpretation of the following lines from:
>     Addresses in the range [addr,addr+len) are outside the valid range for
> the address space of a process.
> What does that *really* mean, especially in terms of

That's true.  On Linux, calling munmap on an already munmap'd memory
is no problem.  Even more interesting, regardless of the state of the
page allocation, all addresses valid as virtual memory addresses of
a process do not fail with munmap.

Since NOACCESS is used to mark munmapped pages in Cygwin's mmap
implementation, this would mean that munmapping an already munmapped
page would fail on Cygwin when checking for NOACCESS.  Testing reveals
that this is already the case right now so using IsBadReadPtr in this
context is actually wrong.  Oh boy.

I tested your first implementation of that function.  To say it in
simple words, the function only checks if the addresses are in the
valid virtual address space of the process.  I used it in the munmap
context and munmap behaves like on Linux now, only failing for addresses
outside the valid virtual address space of the process.

What I did is this:  I stripped the function to the bare minimum and
put it into, called "check_invalid_virtual_addr".  Also
munmap now calls check_invalid_virtual_addr instead of IsBadReadPtr


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                      
Red Hat, Inc.

More information about the Cygwin-developers mailing list