delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/07/12/16:22:31

X-Spam-Check-By: sourceware.org
Date: Wed, 12 Jul 2006 22:22:15 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: 1.5.21s mmap error
Message-ID: <20060712202215.GS8759@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <Pine DOT CYG DOT 4 DOT 58 DOT 0607121030410 DOT 3792 AT PC1163-8460-XP DOT flightsafety DOT com> <20060712165900 DOT GQ8759 AT calimero DOT vinschen DOT de> <Pine DOT CYG DOT 4 DOT 58 DOT 0607121318080 DOT 2284 AT PC1163-8460-XP DOT flightsafety DOT com>
Mime-Version: 1.0
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 AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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

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/

- Raw text -


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