X-Spam-Check-By: sourceware.org
Date: Wed, 12 Jul 2006 22:22:15 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: 1.5.21s mmap error
Message-ID: <20060712202215.GS8759@calimero.vinschen.de>
Reply-To: cygwin@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
References: <Pine.CYG.4.58.0607121030410.3792@PC1163-8460-XP.flightsafety.com> <20060712165900.GQ8759@calimero.vinschen.de> <Pine.CYG.4.58.0607121318080.2284@PC1163-8460-XP.flightsafety.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <Pine.CYG.4.58.0607121318080.2284@PC1163-8460-XP.flightsafety.com>
User-Agent: Mutt/1.4.2i
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On Jul 12 13:43, Brian Ford wrote:
> On Wed, 12 Jul 2006, Corinna Vinschen wrote:
> > On Jul 12 10:48, Brian Ford wrote:
> > > This is just a heads up for now as I plan to try and produce an STC
> > > with cygcheck output later today or tomorrow as time allows.  But, just in
> > > case it rings any bells...
> >
> > Does it work with 1.5.20?
> 
> No, nor 1.5.19.

The problem results from introducing MAP_NORESERVE in 1.5.19.  That's
the reason the same code works on 1.5.18.  Your code simply defines
MAP_NORESERVE to 0 under 1.5.18.

The message you see is from a call to VirtualProtect, which must not be
called on reserved pages (which is MEM_RESERVE'd, which is, funny
enough, the Windows define equivalent to Linux' MAP_NORESERVE).  I fixed
that in CVS.

> #include <sys/mman.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <unistd.h>
> 
> 
> int
> main(void)
> {
>     int   fd, virt_size;
>     void *addr;
> 
>     fd = -1;
> 
>     addr      = NULL;
>     virt_size = 0x18000000;
>     addr = mmap(addr, virt_size, (PROT_READ|PROT_WRITE),
> 		(MAP_NORESERVE|MAP_PRIVATE|MAP_ANON), fd, 0);
>     if (addr == MAP_FAILED)
>     {
> 	perror("mapping VM scratch space");
> 	close(fd);
> 	return -1;
>     }
> 
>     *(volatile char *)addr;

      ^^^^^^^^^^^^^^^^^^^^^^^
This is a bug in your application.  You can't rely on being able to
access memory mmap'ed with MAP_NORESERVE.  This might succeed on Linux,
but it's not guaranteed.  It certainly doesn't work this way on Cygwin.
Call something like `mprotect (addr, virt_size, PROT_READ|PROT_WRITE)'
before accessing the mmap'ed memory.


Thanks for the testcase,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

