delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/09/23/22:21:32

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <20020924022122.38538.qmail@web20422.mail.yahoo.com>
Date: Mon, 23 Sep 2002 19:21:22 -0700 (PDT)
From: Anonymous <tironsi AT yahoo DOT com>
Subject: problems with mprotect()
To: cygwin AT cygwin DOT com
MIME-Version: 1.0

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;
}

In gdb I get the following message when I do a print ptr before and
after the mprotect() line:
// before
$1 = 0xa012818 ""
// after
$2 = 0xa012818 <Address 0xa012818 out of bounds>
also pgSize = 4096 and size = 16384
and I get a seg fault after the return statement
The code works fine on this same machine under linux.

I don't really understand how the code works (I just traced my seg
fault here) as I am a C++ newbie, so forgive me if I have missed something.

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019