What is the point of mincore() in reserve_area() in libs/wine/mmap.c?

Albert Lee trisk at opensolaris.org
Tue May 4 19:20:55 CDT 2010

On Tue, 04 May 2010 10:22:44 -0600, Charles Davis
<cdavis at mymail.mines.edu> wrote:
> On 5/4/10 10:17 AM, Johann "Myrkraverk" Oskarsson wrote:
>> Hi all,
>> In the Solaris/BSD implementation of reserve_area() in libs/wine/mmap.c
>> there is
>>         for (i = 0; i < size; i += pagesize)
>>             if (mincore( (caddr_t)addr + i, pagesize, &vec ) != -1)
>>             break;
>> &vec is never used again in that function.  What is the point of
>> mincore() ?
> It's trying to see if the address is valid. From the manpage:
>      Upon successful completion, a value of 0 is returned.  Otherwise,
>      a value of -1 is returned and errno is set to indicate the error.
>      [EINVAL]           addr is not a valid address for user mode.
>      [EFAULT]           an error occurred trying to copy to the output
>                         character array vec.
> vec is to make sure it failed because the address was invalid, not
> because it couldn't write the flags out.
> Chip

It's a clever, though stop-the-world expensive way to determine which
areas of the address space already have mappings present so MAP_FIXED can
be used without accidentally clobbering another mapping. The strategy
probably should be revisited for OpenSolaris since mmap now accepts an
address hint.


More information about the wine-devel mailing list