Re: mmap and MAP_FIXED

2005-02-27 Thread Evgeny Stambulchik
Tried cygwin1-20050225.dll. Things seem to work fine now.
Thanks, Corinna!
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/


Re: mmap and MAP_FIXED

2005-02-25 Thread Evgeny Stambulchik
Corinna Vinschen wrote:
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.
I know. It was just a test code to demo this 64K strangeness. In 
reality, I use addresses which have been previously returned by mmap 
(without MAP_FIXED).

The reason that MAP_FAILED only works on 64K boundaries so far is,
that I didn't handle this case.
I expected something like this ;-)
Usually there are not many good reasons to use MAP_FIXED.
I know. Those good ones are memory debuggers/custom allocators. Quoting 
POSIX (http://www.opengroup.org/onlinepubs/009695399/functions/mmap.html):
"On the other hand, if the program specifies a fixed address mapping 
(which requires some implementation knowledge to determine a suitable 
address, if the function is supported at all), then the program is 
presumed to be successfully managing its own address space and should be 
trusted when it asks to map over existing data structures."

Which is exactly my case. I'm talking about libundo, which manages 
memory snapshotting: ftp://plasma-gate.weizmann.ac.il/pub/libundo/.

However, I've checked in a patch which
tries to handle MAP_FIXED on 4K boundaries, but only in the anonymous
case.
Great! I'll give it a try once a new cygdll snapshot build is available.
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/


Re: mmap and MAP_FIXED

2005-02-25 Thread Evgeny Stambulchik
Sean Daley wrote:
Read the description to lpBaseAddress again and then read the
following comment from
cygwin's mmap code:
/* If a non-zero address is given, try mapping using the given address first.
   If it fails and flags is not MAP_FIXED, try again with NULL address. */
I did. Now may I ask you in exchange to re-read my previous posts?
Again, it's a mistery to me why e.g. mmap(0x641000,...), although not 
forced to, does return the _suggested_ 0x641000 _exactly_, whereas 
mmap(0x641000,..., MAP_FIXED) fails?!

Also, the Linux man page for mmap pretty much sums it up as follows:
mmap on Linux works flawlessly with MAP_FIXED, according to the POSIX 
requirements - i.e., as far as the address is on the page boundary. In 
cygwin, it's not the case; instead, alignment to the "granularity" of 
the mem allocations is needed. BTW, can I get this value from the Cygwin 
API or need to query Win32 directly?

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/


Re: mmap and MAP_FIXED

2005-02-24 Thread Evgeny Stambulchik
Christopher Faylor wrote:
See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/mapviewoffileex.asp
Pay particular attention to the description of lpBaseAddress.
Thanks! It doesn't explain, though, how mmap manages to avoid this 64k 
restriction when MAP_FIXED is NOT set (and why the same trick, whatever 
it is, can't be used with MAP_FIXED)?

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/


mmap and MAP_FIXED

2005-02-24 Thread Evgeny Stambulchik
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  0x64
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:   0x64 -> 0x64
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:   0x65 -> 0x65
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:   0x64 -> 0x64
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:   0x65 -> 0x65
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/