Re: mmap and MAP_FIXED
On Feb 25 16:18, Corinna Vinschen wrote: On Feb 25 06:35, Eric Blake wrote: While you are at it, POSIX requires an update to underlying file's ctime sometime between mmap(... MAP_SHARED, PROT_WRITE ...) and the corresponding munmap() or msync() if the mapped region was written to. If Windows correctly updates mtime on a mapped file, then one possible way to do this might be: when munmap()ing, if mtime is newer than ctime (but less than or equal to now), adjust ctime to match mtime. Well... no, not now. [...] I'm sorry, but it looks like that won't work at all. I've just tested how the filetime behaves when changing the mapped area of a file mapped MAP_SHARED. Windows does change the file, but it does not change mtime. 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/
Re: mmap and MAP_FIXED
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
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
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 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 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/
Re: mmap and MAP_FIXED
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Corinna Vinschen on 2/25/2005 5:00 AM: 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. While you are at it, POSIX requires an update to underlying file's ctime sometime between mmap(... MAP_SHARED, PROT_WRITE ...) and the corresponding munmap() or msync() if the mapped region was written to. If Windows correctly updates mtime on a mapped file, then one possible way to do this might be: when munmap()ing, if mtime is newer than ctime (but less than or equal to now), adjust ctime to match mtime. - -- Life is short - so eat dessert first! Eric Blake [EMAIL PROTECTED] -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.0 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCHymH84KuGfSFAYARAjlKAJ4gmCNi638o+KZGuc0w+O9fOlrm1wCfZVdt /ELwbzRBKloMYluTFzu2O84= =uhzz -END PGP SIGNATURE- -- 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
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
On Feb 25 06:35, Eric Blake wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Corinna Vinschen on 2/25/2005 5:00 AM: 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. While you are at it, POSIX requires an update to underlying file's ctime sometime between mmap(... MAP_SHARED, PROT_WRITE ...) and the corresponding munmap() or msync() if the mapped region was written to. If Windows correctly updates mtime on a mapped file, then one possible way to do this might be: when munmap()ing, if mtime is newer than ctime (but less than or equal to now), adjust ctime to match mtime. Well... no, not now. That's more tricky than you think. If you have an open mmap to a file, there's not necessarily also an open file descriptor available. This is perfectly fine: fd = open (foo, O_RDWR); addr = mmap (NULL, getpagesize (), PROT_WRITE, MAP_SHARED, fd, 0); close (fd); *addr = 'x'; munmap (addr, getpagesize ()); The problem is that right now the mmap records don't keep track of the file name, nor do they keep a file handle open since that was never necessary for the mmap/munmap functionality. Adding this just for the sake of setting st_ctime makes the code rather more complicated than it already is. I have to think about this a while. 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/
mmap and MAP_FIXED
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 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/
Re: mmap and MAP_FIXED
On Fri, Feb 25, 2005 at 01:17:52AM +0200, Evgeny Stambulchik wrote: 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: See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/mapviewoffileex.asp Pay particular attention to the description of lpBaseAddress. cgf -- 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
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/
Re: mmap and MAP_FIXED
Evgeny Stambulchik wrote: 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 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. */ Also, the Linux man page for mmap pretty much sums it up as follows: The mmap function asks to map length bytes starting at offset offset from the file (or other object) specified by the file descriptor fd into memory, preferably at address start. This latter address is a hint only, and is usually specified as 0. The actual place where the object is mapped is returned by mmap. ... MAP_FIXED Do not select a different address than the one specified. If the specified address cannot be used, mmap will fail. If MAP_FIXED is speci- fied, start must be a multiple of the pagesize. Use of this option is discouraged. Sean -- 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/
Strange max. mapping address for mmap() with MAP_FIXED
Hi, Is there any reason why the maximum address value I can use for mapping shared memory is 0x9ff. If I go beyond that (f.i. 0xa00) I get Value too large for defined data type. I call mmap(address, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, filehandle, 0). I'm using the latest release of Cygwin supplemented with the snapshot of Oct. 26 (cygcheck output attached). regards, Martin. -- -- Martin J.N. Corino | Remedy IT Expertise BV Leeghwaterstraat 25 | 2811 DT HP Reeuwijk| The Netherlands tel: +31 (182) 39 33 39 | fax: +31 (182) 39 59 35 World Wide Web: http://www.remedy.nl -- Cygwin Configuration Diagnostics Current System Time: Tue Nov 02 14:32:48 2004 Windows XP Professional Ver 5.1 Build 2600 Service Pack 1 Path: C:\cygwin\usr\local\bin C:\cygwin\bin C:\cygwin\bin C:\cygwin\usr\X11R6\bin c:\Perl\bin\ c:\WINDOWS\system32 c:\WINDOWS c:\WINDOWS\System32\Wbem c:\Program Files\ATI Technologies\ATI Control Panel c:\Program Files\TortoiseCVS Output from C:\cygwin\bin\id.exe (nontsec) UID: 1003(martin) GID: 513(None) 513(None) Output from C:\cygwin\bin\id.exe (ntsec) UID: 1003(martin)GID: 513(None) 0(root) 513(None)544(Administrators) 545(Users) 1005(Debugger Users) SysDir: C:\WINDOWS\System32 WinDir: C:\WINDOWS HOME = `C:\cygwin\home\martin' MAKE_MODE = `unix' PWD = `/home/martin' USER = `martin' ALLUSERSPROFILE = `C:\Documents and Settings\All Users' APPDATA = `C:\Documents and Settings\martin\Application Data' CLIENTNAME = `Console' COMMONPROGRAMFILES = `C:\Program Files\Common Files' COMPUTERNAME = `FARAMIR' COMSPEC = `C:\WINDOWS\system32\cmd.exe' CVS_RSH = `/bin/ssh' HOMEDRIVE = `C:' HOMEPATH = `\Documents and Settings\martin' HOSTNAME = `faramir' INFOPATH = `/usr/local/info:/usr/info:/usr/share/info:/usr/autotool/devel/info:/usr/autotool/stable/info:' LOGONSERVER = `\\FARAMIR' MANPATH = `/usr/local/man:/usr/man:/usr/share/man:/usr/autotool/devel/man::/usr/ssl/man' NUMBER_OF_PROCESSORS = `1' OLDPWD = `/cygdrive/c/ACE/Cygwin/ACE_wrappers/tests/log' OS = `Windows_NT' PATHEXT = `.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH' PRINTER = `' PROCESSOR_ARCHITECTURE = `x86' PROCESSOR_IDENTIFIER = `x86 Family 15 Model 14 Stepping 0, AuthenticAMD' PROCESSOR_LEVEL = `15' PROCESSOR_REVISION = `0e00' PROGRAMFILES = `C:\Program Files' PROMPT = `$P$G' PS1 = `\[\033]0;\w\007 [EMAIL PROTECTED] \[\033[33m\w\033[0m\] $ ' SESSIONNAME = `RDP-Tcp#1' SHLVL = `1' SYSTEMDRIVE = `C:' SYSTEMROOT = `C:\WINDOWS' TEMP = `C:\DOCUME~1\martin\LOCALS~1\Temp' TERM = `cygwin' TMP = `C:\DOCUME~1\martin\LOCALS~1\Temp' USERDOMAIN = `FARAMIR' USERNAME = `martin' USERPROFILE = `C:\Documents and Settings\martin' VS71COMNTOOLS = `C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\' WINDIR = `C:\WINDOWS' _ = `/usr/bin/cygcheck' POSIXLY_CORRECT = `1' HKEY_CURRENT_USER\Software\Cygnus Solutions HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2 HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\Program Options HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2 (default) = `/cygdrive' cygdrive flags = 0x0022 HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/ (default) = `C:\cygwin' flags = 0x000a HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/bin (default) = `C:\cygwin/bin' flags = 0x000a HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/lib (default) = `C:\cygwin/lib' flags = 0x000a HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\Program Options a: fd N/AN/A c: hd NTFS 80003Mb 13% CP CS UN PA FC C:\cygwin / system binmode C:\cygwin/bin /usr/bin system binmode C:\cygwin/lib /usr/lib system binmode . /cygdrive system binmode,cygdrive Found: C:\cygwin\bin\awk.exe Found: C:\cygwin\bin\bash.exe Found: C:\cygwin\bin\cat.exe Found: C:\cygwin\bin\cp.exe Found: C:\cygwin\bin\cpp.exe Found: C:\cygwin\bin\find.exe Found: C:\cygwin\bin\gcc.exe Found: C:\cygwin\bin\gdb.exe Found: C:\cygwin\bin\grep.exe Found: C:\cygwin\bin\ld.exe Found: C:\cygwin\bin\ls.exe Found: C:\cygwin\bin\make.exe Found: C:\cygwin\bin\mv.exe Found: C:\cygwin\bin\rm.exe Found: C:\cygwin\bin\sed.exe Found: C:\cygwin\bin\sh.exe Found: C:\cygwin\bin\tar.exe 55k 2004/09/14 C:\cygwin\bin\cygbz2-1.dll - os=4.0 img=1.0 sys=4.0 cygbz2-1.dll v0.0 ts=2004/9/14 6:16 18k 2004/07/06 C:\cygwin\bin\cygcharset-1.dll - os=4.0 img=1.0 sys=4.0