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 <stdio.h> > #include <stdlib.h> > #include <unistd.h> > #include <errno.h> > #include <string.h> > #include <sys/mman.h> > > #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@cygwin.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/