X-Spam-Check-By: sourceware.org Date: Wed, 12 Jul 2006 22:22:15 +0200 From: Corinna Vinschen 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: <20060712165900 DOT GQ8759 AT calimero DOT vinschen DOT de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2i Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , 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 > #include > #include > #include > #include > #include > > > 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/