Subject: Re: Wine & NetBSD?
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Bang Jun-Young <bjy@mogua.org>
List: tech-kern
Date: 11/20/2001 23:54:13
On Tue, Nov 20, 2001 at 03:32:02AM -0500, der Mouse wrote:
> > 	mmap((void *)0x50000000, 4096, PROT_READ, 0, fd, 0);
> > 	mmap((void *)0x50000000, 4096, PROT_READ, MAP_FIXED, fd, 0);
> > 	mmap((void *)0x50000000, 4096, PROT_READ, 0, fd, 0);
> > 	mmap((void *)0x50000000, 4096, PROT_READ, MAP_FIXED, fd, 0);
> 
> > Here I expected the second and the fourth mmap()'s would fail, since
> > there was a mapping already done at 0x50000000 by the first mmap.
> > Even if the second succeeded, I expected at least the fourth would
> > fail.  The result was that they _all_ succeded.
> 
> mmap(2) - at least on my machines - says, in part,
> 
> A successful
> .Fa mmap
> deletes any previous mapping in the allocated address range.
> 
> This seems to me to be a fairly clear statement that if you mmap
> something on top of something else, the previous mapping is, to the
> extent that it conflicts with the new one, unmapped and replaced.

At first I expected that, but the result shows that mmap(2) doesn't
act like that: the third mmap call returned 0x50001000, not 0x50000000.
If the manpage was right, mmap should zap the previous mapping at
0x50000000.

Jun-Young

-- 
Bang Jun-Young <bjy@mogua.org>