This is the mail archive of the
mailing list for the Cygwin project.
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 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");
> 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
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html