From 995d706909e7917a9d8f63d4266902ddc97897ce Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Sat, 8 Jun 2013 13:13:40 +0000 Subject: [PATCH] Make sys_mlock() function just a wrapper around vm_mlock() function that does all the job. Reviewed by: kib, jilles Sponsored by: Nginx, Inc. --- sys/vm/vm_extern.h | 1 + sys/vm/vm_mmap.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sys/vm/vm_extern.h b/sys/vm/vm_extern.h index 74a9b394d89c..4a2dc04a9f07 100644 --- a/sys/vm/vm_extern.h +++ b/sys/vm/vm_extern.h @@ -90,5 +90,6 @@ struct sf_buf *vm_imgact_map_page(vm_object_t object, vm_ooffset_t offset); void vm_imgact_unmap_page(struct sf_buf *sf); void vm_thread_dispose(struct thread *td); int vm_thread_new(struct thread *td, int pages); +int vm_mlock(struct proc *, struct ucred *, const void *, size_t); #endif /* _KERNEL */ #endif /* !_VM_EXTERN_H_ */ diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index bf9f5f98cbf4..c7e22c3f96f6 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -1036,18 +1036,24 @@ sys_mlock(td, uap) struct thread *td; struct mlock_args *uap; { - struct proc *proc; + + return (vm_mlock(td->td_proc, td->td_ucred, uap->addr, uap->len)); +} + +int +vm_mlock(struct proc *proc, struct ucred *cred, const void *addr0, size_t len) +{ vm_offset_t addr, end, last, start; vm_size_t npages, size; vm_map_t map; unsigned long nsize; int error; - error = priv_check(td, PRIV_VM_MLOCK); + error = priv_check_cred(cred, PRIV_VM_MLOCK, 0); if (error) return (error); - addr = (vm_offset_t)uap->addr; - size = uap->len; + addr = (vm_offset_t)addr0; + size = len; last = addr + size; start = trunc_page(addr); end = round_page(last); @@ -1056,7 +1062,6 @@ sys_mlock(td, uap) npages = atop(end - start); if (npages > vm_page_max_wired) return (ENOMEM); - proc = td->td_proc; map = &proc->p_vmspace->vm_map; PROC_LOCK(proc); nsize = ptoa(npages + pmap_wired_count(map->pmap));