Deleted Added
sdiff udiff text old ( 217192 ) new ( 220373 )
full compact
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 43 unchanged lines hidden (view full) ---

52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
57 */
58
59#include <sys/cdefs.h>
60__FBSDID("$FreeBSD: head/sys/vm/vm_glue.c 217192 2011-01-09 12:50:44Z kib $");
61
62#include "opt_vm.h"
63#include "opt_kstack_pages.h"
64#include "opt_kstack_max_pages.h"
65
66#include <sys/param.h>
67#include <sys/systm.h>
68#include <sys/limits.h>
69#include <sys/lock.h>
70#include <sys/mutex.h>
71#include <sys/proc.h>
72#include <sys/resourcevar.h>
73#include <sys/sched.h>
74#include <sys/sf_buf.h>
75#include <sys/shm.h>
76#include <sys/vmmeter.h>
77#include <sys/sx.h>
78#include <sys/sysctl.h>
79

--- 97 unchanged lines hidden (view full) ---

177 vm_map_unlock_read(map);
178 return (rv == TRUE);
179}
180
181int
182vslock(void *addr, size_t len)
183{
184 vm_offset_t end, last, start;
185 vm_size_t npages;
186 int error;
187
188 last = (vm_offset_t)addr + len;
189 start = trunc_page((vm_offset_t)addr);
190 end = round_page(last);
191 if (last < (vm_offset_t)addr || end < (vm_offset_t)addr)
192 return (EINVAL);
193 npages = atop(end - start);
194 if (npages > vm_page_max_wired)
195 return (ENOMEM);
196 PROC_LOCK(curproc);
197 if (ptoa(npages +
198 pmap_wired_count(vm_map_pmap(&curproc->p_vmspace->vm_map))) >
199 lim_cur(curproc, RLIMIT_MEMLOCK)) {
200 PROC_UNLOCK(curproc);
201 return (ENOMEM);
202 }
203 PROC_UNLOCK(curproc);
204#if 0
205 /*
206 * XXX - not yet
207 *
208 * The limit for transient usage of wired pages should be
209 * larger than for "permanent" wired pages (mlock()).
210 *
211 * Also, the sysctl code, which is the only present user
212 * of vslock(), does a hard loop on EAGAIN.
213 */
214 if (npages + cnt.v_wire_count > vm_page_max_wired)
215 return (EAGAIN);
216#endif
217 error = vm_map_wire(&curproc->p_vmspace->vm_map, start, end,
218 VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
219 /*
220 * Return EFAULT on error to match copy{in,out}() behaviour
221 * rather than returning ENOMEM like mlock() would.
222 */
223 return (error == KERN_SUCCESS ? 0 : EFAULT);
224}
225
226void
227vsunlock(void *addr, size_t len)
228{
229
230 /* Rely on the parameter sanity checks performed by vslock(). */
231 (void)vm_map_unwire(&curproc->p_vmspace->vm_map,
232 trunc_page((vm_offset_t)addr), round_page((vm_offset_t)addr + len),
233 VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
234}
235
236/*
237 * Pin the page contained within the given object at the given offset. If the
238 * page is not resident, allocate and load it using the given object's pager.
239 * Return the pinned page if successful; otherwise, return NULL.
240 */
241static vm_page_t

--- 825 unchanged lines hidden ---