[PATCH] Problems with Cygwin mmap/munmap (mmap.cc)
Tue Nov 28 19:44:00 GMT 2000
On Tue, Nov 28, 2000 at 02:12:37PM -0500, Kelley Cook wrote:
> loc = mmap (NULL, 1048576, PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> munmap (loc + 786432, 262144)
> munmap (loc, 524288)
> and still have a valid 256K map @ loc+524288.
> This fails under cygwin since munmap is a thunk into the Win32's API
> UnmapViewOfFile which does not take a length parameter and therefore always
> frees the amount allocated on the call to MapViewOfFile/MapViewOfFileEx.
> So under Cygwin, the first munmap call would fail and the second one
> frees the entire range. The first causes a memory leak and the second
> will likely later lead to a segfault.
Aha, this tells me how to write a suitable autoconf test for the buggy
version. The test program I had wasn't thorough enough.
> FWIW, it doesn't attempt to emulate another *nix mmap/munmap possibility,
> which is using one munmap with a double length to unmap two consecutive
> mmapped regions. I personally don't think this is a good idea, so I
> just ignored that case. The munmap call properly fails with EINVAL if it
> is attempted which at least will let the programmer know that it is
Whether it's a good idea is arguable, but GCC uses this behavior too.
If cygwin doesn't support it that will be another memory leak (though
not a segfault). Note it also assumes munmap cannot fail, which I
happen to think is a reasonable stance for resource deallocation
I might point out that we only want these things for mmap of anonymous
memory. If Cygwin used VirtualAlloc instead of CreateFileMapping with
an invalid handle to implement anonymous mmap, then both behaviors
would be implementable easily. (I don't know if this would interfere
with cygwin's brk() implementation, though.)
Want to unsubscribe from this list?
Send a message to email@example.com
More information about the Cygwin