This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: munmap slowness; IsBadReadPtr considered harmful


On Feb 23 18:04, Brian Ford wrote:
> Ok, no response.  That means either:
> 
> 1.) No one knows an alternative way to do the check.
> 2.) No one cares that munmap has this overhead.
> 3.) No one believes me, or they can't reproduce the problem.
> 4.) No one likes me :( ...

5.) No one has enough spare time currently.

> Ok, now back on topic :).
> 
> FWIW, the following replacement for IsBadReadPtr appears to have the
> same functionality without the associated page fault overhead.
> 
> static inline bool
> is_addr_valid (void *addr, size_t len)
> {
>   MEMORY_BASIC_INFORMATION mbuf;
>   void *end;
> 
>   for (end = (char *) addr + len; addr < end;
>        addr = (char *) addr + mbuf.RegionSize)
>     {
>       if (!VirtualQuery (addr, &mbuf, sizeof mbuf))
>         {
>           syscall_printf ("VirtualQuery (addr %x) %E", addr);
>           return false;
>         }
>     }
> 
>   return true;
> }
> 
> So, any comments about the function above, where to put it, or what to
> name it?

IMHO, the name's ok.  It could perhaps get its place in miscfuncs.cc.

> I see in the archives that the IsBadXPtr vs. VirtualQuery debate has
> happened before in different contexts.  It seams to me that VirtualQuery
> wins here hands down, though.

Did you check on 9x and NT?  Is that really correctly implemented?
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.  One possible attribute would be PAGE_NOACCESS. 
In that case you would return true, even though the pages are not
accessible, right?

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]