Revert to the original vslock() and vsunlock() API with the following

exceptions:
	Retain the recently added vslock() error return.

	The type of the len argument should be size_t, not u_int.

Suggested by:	bde
This commit is contained in:
truckman 2004-03-15 06:42:40 +00:00
parent 4a8aedf7cf
commit b7a6af3cc9
3 changed files with 28 additions and 39 deletions

View File

@ -1000,8 +1000,7 @@ kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
error = sysctl_root(0, name, namelen, &req);
if (req.lock == REQ_WIRED)
vsunlock(req.td, (vm_offset_t)req.oldptr,
(vm_size_t)req.wiredlen);
vsunlock(req.oldptr, req.wiredlen);
SYSCTL_UNLOCK();
@ -1103,8 +1102,7 @@ sysctl_wire_old_buffer(struct sysctl_req *req, size_t len)
ret = 0;
if (req->lock == REQ_LOCKED && req->oldptr &&
req->oldfunc == sysctl_old_user) {
ret = vslock(req->td, (vm_offset_t)req->oldptr,
(vm_size_t)wiredlen);
ret = vslock(req->oldptr, wiredlen);
if (ret == 0) {
req->lock = REQ_WIRED;
req->wiredlen = wiredlen;
@ -1320,8 +1318,7 @@ userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
req = req2;
if (req.lock == REQ_WIRED)
vsunlock(req.td, (vm_offset_t)req.oldptr,
(vm_size_t)req.wiredlen);
vsunlock(req.oldptr, req.wiredlen);
SYSCTL_UNLOCK();

View File

@ -86,8 +86,8 @@ void vmspace_unshare(struct proc *);
void vmspace_free(struct vmspace *);
void vmspace_exitfree(struct proc *);
void vnode_pager_setsize(struct vnode *, vm_ooffset_t);
int vslock(struct thread *, vm_offset_t, vm_size_t);
int vsunlock(struct thread *, vm_offset_t, vm_size_t);
int vslock(void *, size_t);
void vsunlock(void *, size_t);
void vm_object_print(/* db_expr_t */ long, boolean_t, /* db_expr_t */ long,
char *);
int vm_fault_quick(caddr_t v, int prot);

View File

@ -187,17 +187,15 @@ useracc(addr, len, rw)
* MPSAFE
*/
int
vslock(td, addr, size)
struct thread *td;
vm_offset_t addr;
vm_size_t size;
vslock(addr, len)
void *addr;
size_t len;
{
vm_offset_t start, end;
struct proc *proc = td->td_proc;
int error, npages;
start = trunc_page(addr);
end = round_page(addr + size);
start = trunc_page((vm_offset_t)addr);
end = round_page((vm_offset_t)addr + len);
/* disable wrap around */
if (end <= start)
@ -208,13 +206,13 @@ vslock(td, addr, size)
if (npages > vm_page_max_wired)
return (ENOMEM);
PROC_LOCK(proc);
if (npages + pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map)) >
atop(lim_cur(proc, RLIMIT_MEMLOCK))) {
PROC_UNLOCK(proc);
PROC_LOCK(curproc);
if (npages + pmap_wired_count(vm_map_pmap(&curproc->p_vmspace->vm_map)) >
atop(lim_cur(curproc, RLIMIT_MEMLOCK))) {
PROC_UNLOCK(curproc);
return (ENOMEM);
}
PROC_UNLOCK(proc);
PROC_UNLOCK(curproc);
#if 0
/*
@ -230,35 +228,29 @@ vslock(td, addr, size)
return (EAGAIN);
#endif
error = vm_map_wire(&proc->p_vmspace->vm_map, start, end,
error = vm_map_wire(&curproc->p_vmspace->vm_map, start, end,
VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES);
/* EINVAL is probably a better error to return than ENOMEM */
return (error == KERN_SUCCESS ? 0 : EINVAL);
/*
* Return EFAULT on error to match copy{in,out}() behaviour
* rather than returning ENOMEM like mlock() would.
*/
return (error == KERN_SUCCESS ? 0 : EFAULT);
}
/*
* MPSAFE
*/
int
vsunlock(td, addr, size)
struct thread *td;
vm_offset_t addr;
vm_size_t size;
void
vsunlock(addr, len)
void *addr;
size_t len;
{
vm_offset_t start, end;
int error;
start = trunc_page(addr);
end = round_page(addr + size);
/* disable wrap around */
if (end <= start)
return (EINVAL);
error = vm_map_unwire(&td->td_proc->p_vmspace->vm_map, start, end,
/* Rely on the parameter sanity checks performed by vslock(). */
(void)vm_map_unwire(&curproc->p_vmspace->vm_map,
trunc_page((vm_offset_t)addr), round_page((vm_offset_t)addr + len),
VM_MAP_WIRE_SYSTEM|VM_MAP_WIRE_NOHOLES);
return (error == KERN_SUCCESS ? 0 : EINVAL);
}
/*