Unnecessary limitation on munmap?

Ken Brown kbrown@cornell.edu
Sun Dec 22 15:54:10 GMT 2024


On 12/22/2024 4:17 AM, Corinna Vinschen wrote:
> The point was that a pagesize of 4K is wrong from the POSIX point of
> view.  I was pretty stubborn in understanding this myself, and it
> took quite some time until I caved in and produced the aforementioned
> patch back in 2005.
> 
> The reason (or rather, one example) is that you can't do this:
> 
>    fd = open ("file1", O_RDONLY);
> 
>    addr1 = mmap (NULL, 4096, PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>    addr2 = mmap (addr1 + 4096, 4096, PROT_READ, MAP_PRIVATE, fd, 0);
> 
> This fails on Windows because the allocation granularity is 64K.  So
> even though the mapping at addr1 is (supposedly) only one pagesize of 4K
> in size...
> 
> - the entire region [addr1,addr1+64K[ is now blocked for other mappings,
>    and
> 
> - a mapping can only start at an address % 64K, so the "addr1+4096"
>    expression doesn't work on Windows, because the mapping can only
>    start at the next (or any other) 64K boundary.
> 
> Multiple assumptions around file mappings differ between Windows
> and POSIX, and the most sane way to emulate POSIX on Windows in this
> respect is to define the POSIX pagesize as the Windows allocation
> granularity.
Thanks for explaining.  It makes sense now.

Ken


More information about the Cygwin-developers mailing list