xref: /386bsd/usr/src/kernel/include/vm_map.h (revision a2142627)
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  *
36  *	$Id: vm_map.h,v 1.2 93/02/04 20:15:43 bill Exp Locker: bill $
37  *
38  *
39  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
40  * All rights reserved.
41  *
42  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
43  *
44  * Permission to use, copy, modify and distribute this software and
45  * its documentation is hereby granted, provided that both the copyright
46  * notice and this permission notice appear in all copies of the
47  * software, derivative works or modified versions, and any portions
48  * thereof, and that both notices appear in supporting documentation.
49  *
50  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53  *
54  * Carnegie Mellon requests users of this software to return to
55  *
56  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
57  *  School of Computer Science
58  *  Carnegie Mellon University
59  *  Pittsburgh PA 15213-3890
60  *
61  * any improvements or extensions that they make and grant Carnegie the
62  * rights to redistribute these changes.
63  */
64 
65 /*
66  *	Virtual memory map module definitions.
67  */
68 
69 #ifndef	_VM_MAP_
70 #define	_VM_MAP_
71 
72 /*
73  *	Types defined:
74  *
75  *	vm_map_t		the high-level address map data structure.
76  *	vm_map_entry_t		an entry in an address map.
77  *	vm_map_version_t	a timestamp of a map, for use with vm_map_lookup
78  */
79 
80 /*
81  *	Objects which live in maps may be either VM objects, or
82  *	another map (called a "sharing map") which denotes read-write
83  *	sharing with other maps.
84  */
85 
86 union vm_map_object {
87 	struct vm_object	*vm_object;	/* object object */
88 	struct vm_map		*share_map;	/* share map */
89 	struct vm_map		*sub_map;	/* belongs to another map */
90 };
91 
92 typedef union vm_map_object	vm_map_object_t;
93 
94 /*
95  *	Address map entries consist of start and end addresses,
96  *	a VM object (or sharing map) and offset into that object,
97  *	and user-exported inheritance and protection information.
98  *	Also included is control information for virtual copy operations.
99  */
100 struct vm_map_entry {
101 	struct vm_map_entry	*prev;		/* previous entry */
102 	struct vm_map_entry	*next;		/* next entry */
103 	vm_offset_t		start;		/* start address */
104 	vm_offset_t		end;		/* end address */
105 	union vm_map_object	object;		/* object I point to */
106 	vm_offset_t		offset;		/* offset into object */
107 	unsigned int
108 				is_a_map:1,	/* Is "object" a map? */
109 				is_sub_map:1,	/* Is "object" a submap? */
110 		/* Only in sharing maps: */
111 				copy_on_write:1,/* is data copy-on-write */
112 				needs_copy:1,	/* does object need to be copied */
113 		/* Only in task maps: */
114 				canwire:1;	/* wire on fault */
115 	vm_prot_t		protection;	/* protection code */
116 	vm_prot_t		max_protection;	/* maximum protection */
117 	vm_inherit_t		inheritance;	/* inheritance */
118 	int			wired_count;	/* can be paged if = 0 */
119 };
120 
121 typedef struct vm_map_entry	*vm_map_entry_t;
122 
123 /*
124  *	Maps are doubly-linked lists of map entries, kept sorted
125  *	by address.  A single hint is provided to start
126  *	searches again from the last successful search,
127  *	insertion, or removal.
128  */
129 struct vm_map {
130 	struct pmap *		pmap;		/* Physical map */
131 	lock_data_t		lock;		/* Lock for map data */
132 	struct vm_map_entry	header;		/* List of entries */
133 	int			nentries;	/* Number of entries */
134 	vm_size_t		size;		/* virtual size */
135 	boolean_t		is_main_map;	/* Am I a main map? */
136 	int			ref_count;	/* Reference count */
137 	vm_map_entry_t		hint;		/* hint for quick lookups */
138 	vm_map_entry_t		first_free;	/* First free space hint */
139 	boolean_t		entries_pageable; /* map entries pageable?? */
140 	unsigned int		timestamp;	/* Version number */
141 #define	min_offset		header.start
142 #define max_offset		header.end
143 };
144 
145 typedef	struct vm_map	*vm_map_t;
146 
147 /*
148  *	Map versions are used to validate a previous lookup attempt.
149  *
150  *	Since lookup operations may involve both a main map and
151  *	a sharing map, it is necessary to have a timestamp from each.
152  *	[If the main map timestamp has changed, the share_map and
153  *	associated timestamp are no longer valid; the map version
154  *	does not include a reference for the imbedded share_map.]
155  */
156 typedef struct {
157 	int		main_timestamp;
158 	vm_map_t	share_map;
159 	int		share_timestamp;
160 } vm_map_version_t;
161 
162 /*
163  *	Macros:		vm_map_lock, etc.
164  *	Function:
165  *		Perform locking on the data portion of a map.
166  */
167 
168 #define		vm_map_lock(map)	{ lock_write(&(map)->lock); (map)->timestamp++; }
169 #define		vm_map_unlock(map)	lock_write_done(&(map)->lock)
170 #define		vm_map_lock_read(map)	lock_read(&(map)->lock)
171 #define		vm_map_unlock_read(map)	lock_read_done(&(map)->lock)
172 
173 /*
174  *	Exported procedures that operate on vm_map_t.
175  */
176 
177 void	vm_map_startup(void);
178 vm_map_t
179 	vm_map_create(pmap_t pmap, vm_offset_t min, vm_offset_t max,
180 		boolean_t pageable);
181 void	vm_map_init(struct vm_map *map, vm_offset_t min, vm_offset_t max,
182 		boolean_t pageable);
183 void	vm_map_reference(vm_map_t map);
184 void	vm_map_deallocate(vm_map_t map);
185 int	vm_map_find(vm_map_t map, vm_offset_t *addr, vm_size_t length);
186 int	vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end,
187 		vm_prot_t new_prot, boolean_t set_max);
188 int	vm_map_inherit(vm_map_t map, vm_offset_t start, vm_offset_t end,
189 		vm_inherit_t new_inheritance);
190 int	vm_map_pageable(vm_map_t map, vm_offset_t start, vm_offset_t end,
191 		boolean_t new_pageable);
192 int	vm_map_remove(vm_map_t map, vm_offset_t start, vm_offset_t end);
193 boolean_t
194 	vm_map_check_protection(vm_map_t map, vm_offset_t start,
195 		vm_offset_t end, vm_prot_t protection);
196 int	vm_map_copy(vm_map_t dst_map, vm_map_t src_map, vm_offset_t dst_addr,
197 		vm_size_t len, vm_offset_t src_addr, boolean_t dst_alloc,
198 		boolean_t src_destroy);
199 int	vm_map_lookup(vm_map_t *var_map, vm_offset_t vaddr,
200 		vm_prot_t fault_type, vm_map_entry_t *out_entry,
201 		vm_object_t *object, vm_offset_t *offset, vm_prot_t *out_prot,
202 		boolean_t *wired, boolean_t *single_use);
203 void	vm_map_lookup_done(vm_map_t map, vm_map_entry_t entry);
204 void	vm_map_simplify(vm_map_t map, vm_offset_t start);
205 
206 /*  "internal" routines currently used externally (vm_kern,vm_mmap): */
207 int	vm_map_submap(vm_map_t map, vm_offset_t start, vm_offset_t end,
208 		vm_map_t submap);
209 void	vm_map_delete(vm_map_t map, vm_offset_t start, vm_offset_t end);
210 int	vm_map_insert(vm_map_t map, vm_object_t object, vm_offset_t offset,
211 		vm_offset_t start, vm_offset_t end);
212 boolean_t
213 	vm_map_lookup_entry(vm_map_t map, vm_offset_t address,
214 		vm_map_entry_t *entry);
215 
216 void vm_map_print(vm_map_t map, boolean_t full);
217 
218 /*
219  *	Functions implemented as macros
220  */
221 #define		vm_map_min(map)		((map)->min_offset)
222 #define		vm_map_max(map)		((map)->max_offset)
223 #define		vm_map_pmap(map)	((map)->pmap)
224 
225 /* XXX: number of kernel maps and entries to statically allocate */
226 #define MAX_KMAP	10
227 #define	MAX_KMAPENT	500
228 
229 #endif	_VM_MAP_
230