This is the mail archive of the
mailing list for the Cygwin project.
mmap(MAP_FIXED) vs mprotect
- From: Ryan Johnson <ryan dot johnson at cs dot utoronto dot ca>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Wed, 24 Apr 2013 08:03:17 -0400
- Subject: mmap(MAP_FIXED) vs mprotect
I'm trying to port a linux program that uses mmap to implement a
growable array; the ideas is to mmap(PROT_NONE, MAP_NORESERVE) a chunk
of address space (corresponding to the maximum array size) and then call
mmap(PROT_READ|PROT_WRITE, MAP_FIXED) to allocate actual memory in the
"blank" region. This works well in Linux but fails with EINVAL in cygwin.
My code aligns all sizes up to 2MB boundaries, so it's not a 64kB
boundary problem. My code reports the failing call as:
22 Invalid argument addr=0xffdb0000, sz=2097152
A peek in /proc/self/maps confirms that the address is correct:
FFDB0000-FFFB0000 ===p 00000000 0000:0000 0
Oddly, trying to map in blank pages in with mprotect succeeds on cygwin
but fails with ENOMEM on linux...
Am I missing something here, or is this just a place where different
behavior between the two platforms is a fact of life? Which version is
the posixly "correct" way to reserve a chunk of address space and later
back it with actual memory?
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple