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 Message-ID: <421E60A0.8000102@stambulchik.net> Date: Fri, 25 Feb 2005 01:17:52 +0200 From: Evgeny Stambulchik User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: mmap and MAP_FIXED Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 FAIL: 0x641000 (Permission denied) FAIL: 0x642000 (Permission denied) FAIL: 0x643000 (Permission denied) FAIL: 0x644000 (Permission denied) FAIL: 0x645000 (Permission denied) FAIL: 0x646000 (Permission denied) FAIL: 0x647000 (Permission denied) FAIL: 0x648000 (Permission denied) FAIL: 0x649000 (Permission denied) FAIL: 0x64a000 (Permission denied) FAIL: 0x64b000 (Permission denied) FAIL: 0x64c000 (Permission denied) FAIL: 0x64d000 (Permission denied) FAIL: 0x64e000 (Permission denied) FAIL: 0x64f000 (Permission denied) OK: 0x650000 -> 0x650000 FAIL: 0x651000 (Permission denied) FAIL: 0x652000 (Permission denied) FAIL: 0x653000 (Permission denied) On the other hand, if 'MAP_FIXED' is removed, mmap() happily uses the address hint in all cases: OK: 0x640000 -> 0x640000 OK: 0x641000 -> 0x641000 OK: 0x642000 -> 0x642000 OK: 0x643000 -> 0x643000 OK: 0x644000 -> 0x644000 OK: 0x645000 -> 0x645000 OK: 0x646000 -> 0x646000 OK: 0x647000 -> 0x647000 OK: 0x648000 -> 0x648000 OK: 0x649000 -> 0x649000 OK: 0x64a000 -> 0x64a000 OK: 0x64b000 -> 0x64b000 OK: 0x64c000 -> 0x64c000 OK: 0x64d000 -> 0x64d000 OK: 0x64e000 -> 0x64e000 OK: 0x64f000 -> 0x64f000 OK: 0x650000 -> 0x650000 OK: 0x651000 -> 0x651000 OK: 0x652000 -> 0x652000 OK: 0x653000 -> 0x653000 Any insight? Regards, Evgeny -- 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/