This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 1.5.21s mmap error

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),
>     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 Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]