X-Spam-Check-By: sourceware.org Date: Mon, 28 Nov 2005 12:55:05 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: mmap() on 64K aligned address fails Message-ID: <20051128115505.GG2999@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <20051126180331 DOT GI5074 AT bouh DOT residence DOT ens-lyon DOT fr> <20051126214701 DOT GW5074 AT bouh DOT residence DOT ens-lyon DOT fr> <20051127130652 DOT GT2999 AT calimero DOT vinschen DOT de> <20051127222246 DOT GJ5150 AT bouh DOT residence DOT ens-lyon DOT fr> <20051128115109 DOT GF2999 AT calimero DOT vinschen DOT de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051128115109.GF2999@calimero.vinschen.de> 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 Nov 28 12:51, Corinna Vinschen wrote: > On Nov 27 16:47, Ren? Berber wrote: > > Samuel Thibault wrote: > > [snip] > > > Memmapping to malloced memory could very well be forbidden. Why would > > > one want to do this? > > > > As I said before, the test is one that comes with gcc-4.0.2, it fails only on > > Windows as far as I know. To answer your question: is just a test, it should > > work with some Windows related tweaking but it's just a test. > > > > Besides, what other memory is there available that a process has under its > > control? Yes, I know, mmap() should be used w/o MAP_FIXED and let the OS choose > > where to map, but the interesting part of this test is to use MAP_FIXED. > > The problem is that the application using MAP_FIXED has no idea if the > address it's using is *allowed*. There might be already a mapping > active, maybe just the application's code is mapped at that point, or > the address is generally invalid for shared memory usage. > > Many mmap tests make such invalid assumptions about the memory. Just > because they are part of gcc doesn't make them right. The only blessed > usage of MAP_FIXED is if the application knows that the memory address > is valid. One way to do this is to establish a non-FIXED mmap first, > like this: > > #include > #include > #include > #include > > int > main () > { > int pages = 10; > void *addr, *addr2; > > addr = mmap (NULL, 2 * pages * getpagesize(), PROT_READ|PROT_WRITE, > MAP_SHARED|MAP_ANONYMOUS, -1, 0); > if (addr == MAP_FAILED) > fprintf (stderr, "Gargl\n"); > else > { > munmap (addr, pages * getpagesize()); > addr2 = mmap (addr, pages * getpagesize(), PROT_READ|PROT_WRITE, > MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, -1, 0); > if (addr2 == MAP_FAILED) > fprintf (stderr, "Frtzl\n"); > else if (addr2 != addr) > fprintf (stderr, "Urgl\n"); > else > fprintf (stderr, "Haha\n"); > } > return 0; > } Btw., the above test won't work on Cygwin 1.5.18 due to a incorrect test in Cygwin's mmap implementation. This will be fixed in 1.5.19. For a start, mmap/munmap the whole page area instead just the half of it. That should work. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat, Inc. -- 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/