valid VMA ranges and mincore()

Bruno Haible bruno at clisp.org
Wed Jun 14 14:15:28 UTC 2006


Hello Konstantin,

> > - Filling in values of -1 into the array could be done more easily by
> >   changing the statements in sys/vm/vm_mmap.c lines 861 and 902.
> I do not agree. It zeroes array not only for holes, but also for (some)
> skipped vm areas.

ok, you understand the code better than I do :-)

> Index: vm_mmap.c
> ===================================================================
> RCS file: /usr/local/arch/ncvs/src/sys/vm/vm_mmap.c,v
> retrieving revision 1.205
> diff -u -r1.205 vm_mmap.c
> --- vm_mmap.c	21 Apr 2006 07:17:25 -0000	1.205
> +++ vm_mmap.c	14 Jun 2006 13:51:20 -0000
> @@ -756,8 +756,10 @@
>  	first_addr = addr = trunc_page((vm_offset_t) uap->addr);
>  	end = addr + (vm_size_t)round_page(uap->len);
>  	map = &td->td_proc->p_vmspace->vm_map;
> -	if (end > vm_map_max(map) || end < addr)
> +	if (end < addr)
>  		return (EINVAL);
> +	if (end > vm_map_max(map))
> +		return (ENOMEM);
>  
>  	/*
>  	 * Address of byte vector
> @@ -770,8 +772,18 @@
>  RestartScan:
>  	timestamp = map->timestamp;
>  
> -	if (!vm_map_lookup_entry(map, addr, &entry))
> -		entry = entry->next;
> +	if (!vm_map_lookup_entry(map, first_addr, &entry)) {
> +		vm_map_unlock_read(map);
> +		return (ENOMEM);
> +	}
> +	for (current = entry;
> +	    (current != &map->header) && (current->end < end);
> +	    current = current->next) {
> +		if (current->end != current->next->start) {
> +			vm_map_unlock_read(map);
> +			return (ENOMEM);
> +		}
> +	}
>  
>  	/*
>  	 * Do this on a map entry basis so that if the pages are not
> 

Looks good to me: This does what Linux, NetBSD, Solaris do. Thanks!

Bruno


More information about the freebsd-hackers mailing list