Subject: Re: Wine & NetBSD?
To: Chuck Silvers <chuq@chuq.com>
From: Bang Jun-Young <bjy@mogua.org>
List: tech-kern
Date: 11/20/2001 16:56:59
On Mon, Nov 19, 2001 at 10:48:00PM -0800, Chuck Silvers wrote:
> why would anything be mapped at 0x800000?

By chance. I should use more reasonable value for it. 

> the only reason that anything will be mapped at 0x800000 is if
> the mapping was created with MAP_FIXED.  so again, if both
> of these mappings really have to be at 0x800000, then
> it won't work without MAP_FIXED either.

If
	addr = wine_anon_mmap(/* arguments, ... */);

returned 0x800000 to addr, any attempt to map something at that
address at later time should fail, but with MAP_FIXED it isn't. 

Let's take a look at another one on NetBSD:

	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.

So that's why using MAP_FIXED mapping is sometimes a bad idea. mmap
manpage says "Use of this option [MAP_FIXED] is discouraged."
(I don't understand why it also says "If the specified address cannot
be used, mmap will fail" even though it returns success for the address
that can't be used as the above)

Jun-Young

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