This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: problems with mprotect()
- From: Corinna Vinschen <corinna-cygwin at cygwin dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 24 Sep 2002 16:41:30 +0200
- Subject: Re: problems with mprotect()
- References: <20020924022122.38538.qmail@web20422.mail.yahoo.com>
- Reply-to: cygwin at cygwin dot com
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/