problems with mprotect()
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue Sep 24 07:48:00 GMT 2002
On Mon, Sep 23, 2002 at 07:21:22PM -0700, Anonymous wrote:
> Hi, I'm having segfaults with the following piece of code (working from
> WinXP SP1 using latest Cygwin release):
>
> char * AllocBoundedArray(int size)
> {
> int pgSize = getpagesize();
> char *ptr = new char[pgSize * 2 + size];
> // before
> mprotect(ptr, pgSize, 0);
> // after
> mprotect(ptr + pgSize + size, pgSize, 0);
> return ptr + pgSize;
> }
The code expects that a new or malloc returns the memory on a
page boundary. That's incorrect. It's virtually certain that
it protects memory to NOACCESS which isn't owned by the above
new(). Whatever this is, it's non-portable.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Developer mailto:cygwin@cygwin.com
Red Hat, Inc.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list