Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 Date: Fri, 25 Feb 2005 13:00:45 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: mmap and MAP_FIXED Message-ID: <20050225120045.GO18314@cygbert.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <421E60A0 DOT 8000102 AT stambulchik DOT net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <421E60A0.8000102@stambulchik.net> User-Agent: Mutt/1.4.2i On Feb 25 01:17, Evgeny Stambulchik wrote: > Hello, > > There is something strange about mmap(addr, ..., MAP_FIXED) under > Cygwin. For a reason, it always fails if addr is not on a 16xPAGE_SIZE > boundary. Here is a short demo: > > #include > #include > #include > #include > #include > #include > > #define NRUNS 20 > #define CHUNK_SIZE 4096 > #define START_ADDR 0x640000 > > int main(void) > { > unsigned int i, pagesize, prot, flags; > void *addr, *maddr; > > pagesize = getpagesize(); > prot = PROT_READ | PROT_WRITE | PROT_EXEC; > flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; > > for (i = 0; i < NRUNS; i++) { > addr = (void *) START_ADDR + pagesize*i; > maddr = mmap(addr, CHUNK_SIZE, prot, flags, 0, 0); > if (maddr != MAP_FAILED) { > fprintf(stderr, "OK: %p -> %p\n", addr, maddr); > } else { > fprintf(stderr, "FAIL: %p (%s)\n", addr, strerror(errno)); > } > } > exit(0); > } > > And the output is: > > OK: 0x640000 -> 0x640000 Pure coincidence. You shouldn't just use some arbitrary address and use MAP_FIXED with it, otherwise you're making invaild assumptions about the memory layout of your machine/os/application. The reason that MAP_FAILED only works on 64K boundaries so far is, that I didn't handle this case. Usually there are not many good reasons to use MAP_FIXED. However, I've checked in a patch which tries to handle MAP_FIXED on 4K boundaries, but only in the anonymous case. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader mailto: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/