diff --git a/lib/libc/sys/mincore.2 b/lib/libc/sys/mincore.2 index 25ad07628fd..75e74a4f3f6 100644 --- a/lib/libc/sys/mincore.2 +++ b/lib/libc/sys/mincore.2 @@ -92,12 +92,12 @@ The .Fn mincore system call will fail if: .Bl -tag -width Er -.It Bq Er EINVAL +.It Bq Er ENOMEM The virtual address range specified by the .Fa addr and .Fa len -arguments is not valid. +arguments is not fully mapped. .It Bq Er EFAULT The .Fa vec diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 5965d4a3116..244877e8db9 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -757,7 +757,7 @@ mincore(td, uap) 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) - return (EINVAL); + return (ENOMEM); /* * Address of byte vector @@ -770,8 +770,10 @@ mincore(td, uap) RestartScan: timestamp = map->timestamp; - if (!vm_map_lookup_entry(map, addr, &entry)) - entry = entry->next; + if (!vm_map_lookup_entry(map, addr, &entry)) { + vm_map_unlock_read(map); + return (ENOMEM); + } /* * Do this on a map entry basis so that if the pages are not @@ -783,6 +785,16 @@ RestartScan: (current != &map->header) && (current->start < end); current = current->next) { + /* + * check for contiguity + */ + if (current->end < end && + (entry->next == &map->header || + current->next->start > current->end)) { + vm_map_unlock_read(map); + return (ENOMEM); + } + /* * ignore submaps (for now) or null objects */