|
|
1.1 root 1: /*
2: * Copyright (c) 1991 Regents of the University of California.
3: * 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
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: *
1.1.1.2 ! root 36: * from: @(#)vm_user.c 7.3 (Berkeley) 4/21/91
! 37: * vm_user.c,v 1.3 1993/07/17 16:03:18 mycroft Exp
1.1 root 38: *
39: *
40: * Copyright (c) 1987, 1990 Carnegie-Mellon University.
41: * All rights reserved.
42: *
43: * Authors: Avadis Tevanian, Jr., Michael Wayne Young
44: *
45: * Permission to use, copy, modify and distribute this software and
46: * its documentation is hereby granted, provided that both the copyright
47: * notice and this permission notice appear in all copies of the
48: * software, derivative works or modified versions, and any portions
49: * thereof, and that both notices appear in supporting documentation.
50: *
51: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
52: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
53: * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
54: *
55: * Carnegie Mellon requests users of this software to return to
56: *
57: * Software Distribution Coordinator or [email protected]
58: * School of Computer Science
59: * Carnegie Mellon University
60: * Pittsburgh PA 15213-3890
61: *
62: * any improvements or extensions that they make and grant Carnegie the
63: * rights to redistribute these changes.
64: */
65:
66: /*
67: * User-exported virtual memory functions.
68: */
69:
70: #include "param.h"
71: #include "systm.h"
72: #include "proc.h"
73:
74: #include "vm.h"
75: #include "vm_page.h"
76:
77: simple_lock_data_t vm_alloc_lock; /* XXX */
78:
79: #ifdef MACHVMCOMPAT
80: /*
81: * BSD style syscall interfaces to MACH calls
82: * All return MACH return values.
83: */
1.1.1.2 ! root 84: struct svm_allocate_args {
! 85: vm_map_t map;
! 86: vm_offset_t *addr;
! 87: vm_size_t size;
! 88: boolean_t anywhere;
! 89: };
! 90:
1.1 root 91: /* ARGSUSED */
92: svm_allocate(p, uap, retval)
93: struct proc *p;
1.1.1.2 ! root 94: struct svm_allocate_args *uap;
1.1 root 95: int *retval;
96: {
97: vm_offset_t addr;
98: int rv;
99:
100: uap->map = p->p_map; /* XXX */
101:
102: if (copyin((caddr_t)uap->addr, (caddr_t)&addr, sizeof (addr)))
103: rv = KERN_INVALID_ARGUMENT;
104: else
105: rv = vm_allocate(uap->map, &addr, uap->size, uap->anywhere);
106: if (rv == KERN_SUCCESS) {
107: if (copyout((caddr_t)&addr, (caddr_t)uap->addr, sizeof(addr)))
108: rv = KERN_INVALID_ARGUMENT;
109: }
110: return((int)rv);
111: }
112:
1.1.1.2 ! root 113: struct svm_deallocate_args {
! 114: vm_map_t map;
! 115: vm_offset_t addr;
! 116: vm_size_t size;
! 117: };
! 118:
1.1 root 119: /* ARGSUSED */
120: svm_deallocate(p, uap, retval)
121: struct proc *p;
1.1.1.2 ! root 122: struct svm_deallocate_args *uap;
1.1 root 123: int *retval;
124: {
125: int rv;
126:
127: uap->map = p->p_map; /* XXX */
128: rv = vm_deallocate(uap->map, uap->addr, uap->size);
129: return((int)rv);
130: }
131:
1.1.1.2 ! root 132: struct svm_inherit_args {
! 133: vm_map_t map;
! 134: vm_offset_t addr;
! 135: vm_size_t size;
! 136: vm_inherit_t inherit;
! 137: };
! 138:
1.1 root 139: /* ARGSUSED */
140: svm_inherit(p, uap, retval)
141: struct proc *p;
1.1.1.2 ! root 142: struct svm_inherit_args *uap;
1.1 root 143: int *retval;
144: {
145: int rv;
146:
147: uap->map = p->p_map; /* XXX */
148: rv = vm_inherit(uap->map, uap->addr, uap->size, uap->inherit);
149: return((int)rv);
150: }
151:
1.1.1.2 ! root 152: struct svm_protect_args {
! 153: vm_map_t map;
! 154: vm_offset_t addr;
! 155: vm_size_t size;
! 156: boolean_t setmax;
! 157: vm_prot_t prot;
! 158: };
! 159:
1.1 root 160: /* ARGSUSED */
161: svm_protect(p, uap, retval)
162: struct proc *p;
1.1.1.2 ! root 163: struct svm_protect_args *uap;
1.1 root 164: int *retval;
165: {
166: int rv;
167:
168: uap->map = p->p_map; /* XXX */
169: rv = vm_protect(uap->map, uap->addr, uap->size, uap->setmax, uap->prot);
170: return((int)rv);
171: }
172: #endif
173:
174: /*
175: * vm_allocate allocates "zero fill" memory in the specfied
176: * map.
177: */
178: vm_allocate(map, addr, size, anywhere)
179: register vm_map_t map;
180: register vm_offset_t *addr;
181: register vm_size_t size;
182: boolean_t anywhere;
183: {
184: int result;
185:
186: if (map == NULL)
187: return(KERN_INVALID_ARGUMENT);
188: if (size == 0) {
189: *addr = 0;
190: return(KERN_SUCCESS);
191: }
192:
193: if (anywhere)
194: *addr = vm_map_min(map);
195: else
196: *addr = trunc_page(*addr);
197: size = round_page(size);
198:
199: result = vm_map_find(map, NULL, (vm_offset_t) 0, addr,
200: size, anywhere);
201:
202: return(result);
203: }
204:
205: /*
206: * vm_deallocate deallocates the specified range of addresses in the
207: * specified address map.
208: */
209: vm_deallocate(map, start, size)
210: register vm_map_t map;
211: vm_offset_t start;
212: vm_size_t size;
213: {
214: if (map == NULL)
215: return(KERN_INVALID_ARGUMENT);
216:
217: if (size == (vm_offset_t) 0)
218: return(KERN_SUCCESS);
219:
220: return(vm_map_remove(map, trunc_page(start), round_page(start+size)));
221: }
222:
223: /*
224: * vm_inherit sets the inheritence of the specified range in the
225: * specified map.
226: */
227: vm_inherit(map, start, size, new_inheritance)
228: register vm_map_t map;
229: vm_offset_t start;
230: vm_size_t size;
231: vm_inherit_t new_inheritance;
232: {
233: if (map == NULL)
234: return(KERN_INVALID_ARGUMENT);
235:
236: return(vm_map_inherit(map, trunc_page(start), round_page(start+size), new_inheritance));
237: }
238:
239: /*
240: * vm_protect sets the protection of the specified range in the
241: * specified map.
242: */
243:
244: vm_protect(map, start, size, set_maximum, new_protection)
245: register vm_map_t map;
246: vm_offset_t start;
247: vm_size_t size;
248: boolean_t set_maximum;
249: vm_prot_t new_protection;
250: {
251: if (map == NULL)
252: return(KERN_INVALID_ARGUMENT);
253:
254: return(vm_map_protect(map, trunc_page(start), round_page(start+size), new_protection, set_maximum));
255: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.