xref: /freebsd/sys/vm/vm_map.h (revision 61afd5bb22d787b0641523e7b9b95c964d669bd5)
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
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  *	from: @(#)vm_map.h	8.3 (Berkeley) 3/15/94
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  * $Id: vm_map.h,v 1.18 1996/12/14 17:54:16 dyson Exp $
65  */
66 
67 /*
68  *	Virtual memory map module definitions.
69  */
70 
71 #ifndef	_VM_MAP_
72 #define	_VM_MAP_
73 
74 /*
75  *	Types defined:
76  *
77  *	vm_map_t		the high-level address map data structure.
78  *	vm_map_entry_t		an entry in an address map.
79  *	vm_map_version_t	a timestamp of a map, for use with vm_map_lookup
80  */
81 
82 /*
83  *	Objects which live in maps may be either VM objects, or
84  *	another map (called a "sharing map") which denotes read-write
85  *	sharing with other maps.
86  */
87 
88 union vm_map_object {
89 	struct vm_object *vm_object;	/* object object */
90 	struct vm_map *share_map;	/* share map */
91 	struct vm_map *sub_map;		/* belongs to another map */
92 };
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_ooffset_t offset;		/* offset into object */
107 	u_char is_a_map:1,		/* Is "object" a map? */
108 	 is_sub_map:1,			/* Is "object" a submap? */
109 	 copy_on_write:1,		/* is data copy-on-write */
110 	 needs_copy:1,			/* does object need to be copied */
111 	 nofault:1,			/* should never fault */
112 	 user_wired:1;			/* wired by user */
113 	/* Only in task maps: */
114 	vm_prot_t protection;		/* protection code */
115 	vm_prot_t max_protection;	/* maximum protection */
116 	vm_inherit_t inheritance;	/* inheritance */
117 	int wired_count;		/* can be paged if = 0 */
118 };
119 
120 /*
121  *	Maps are doubly-linked lists of map entries, kept sorted
122  *	by address.  A single hint is provided to start
123  *	searches again from the last successful search,
124  *	insertion, or removal.
125  */
126 struct vm_map {
127 	struct pmap *pmap;		/* Physical map */
128 	lock_data_t lock;		/* Lock for map data */
129 	struct vm_map_entry header;	/* List of entries */
130 	int nentries;			/* Number of entries */
131 	vm_size_t size;			/* virtual size */
132 	boolean_t is_main_map;		/* Am I a main map? */
133 	int ref_count;			/* Reference count */
134 	vm_map_entry_t hint;		/* hint for quick lookups */
135 	vm_map_entry_t first_free;	/* First free space hint */
136 	boolean_t entries_pageable;	/* map entries pageable?? */
137 	unsigned int timestamp;		/* Version number */
138 #define	min_offset		header.start
139 #define max_offset		header.end
140 };
141 
142 /*
143  * Shareable process virtual address space.
144  * May eventually be merged with vm_map.
145  * Several fields are temporary (text, data stuff).
146  */
147 struct vmspace {
148 	struct vm_map vm_map;	/* VM address map */
149 	struct pmap vm_pmap;	/* private physical map */
150 	int vm_refcnt;		/* number of references */
151 	caddr_t vm_shm;		/* SYS5 shared memory private data XXX */
152 	vm_object_t vm_upages_obj;	/* UPAGES object */
153 /* we copy from vm_startcopy to the end of the structure on fork */
154 #define vm_startcopy vm_rssize
155 	segsz_t vm_rssize;	/* current resident set size in pages */
156 	segsz_t vm_swrss;	/* resident set size before last swap */
157 	segsz_t vm_tsize;	/* text size (pages) XXX */
158 	segsz_t vm_dsize;	/* data size (pages) XXX */
159 	segsz_t vm_ssize;	/* stack size (pages) */
160 	caddr_t vm_taddr;	/* user virtual address of text XXX */
161 	caddr_t vm_daddr;	/* user virtual address of data XXX */
162 	caddr_t vm_maxsaddr;	/* user VA at max stack growth */
163 	caddr_t vm_minsaddr;	/* user VA at max stack growth */
164 };
165 
166 
167 /*
168  *	Map versions are used to validate a previous lookup attempt.
169  *
170  *	Since lookup operations may involve both a main map and
171  *	a sharing map, it is necessary to have a timestamp from each.
172  *	[If the main map timestamp has changed, the share_map and
173  *	associated timestamp are no longer valid; the map version
174  *	does not include a reference for the embedded share_map.]
175  */
176 typedef struct {
177 	int main_timestamp;
178 	vm_map_t share_map;
179 	int share_timestamp;
180 } vm_map_version_t;
181 
182 /*
183  *	Macros:		vm_map_lock, etc.
184  *	Function:
185  *		Perform locking on the data portion of a map.
186  */
187 
188 #define	vm_map_lock(map) { \
189 	lock_write(&(map)->lock); \
190 	(map)->timestamp++; \
191 }
192 #define	vm_map_unlock(map)	lock_write_done(&(map)->lock)
193 #define	vm_map_lock_read(map)	lock_read(&(map)->lock)
194 #define	vm_map_unlock_read(map)	lock_read_done(&(map)->lock)
195 
196 /*
197  *	Functions implemented as macros
198  */
199 #define		vm_map_min(map)		((map)->min_offset)
200 #define		vm_map_max(map)		((map)->max_offset)
201 #define		vm_map_pmap(map)	((map)->pmap)
202 
203 /* XXX: number of kernel maps and entries to statically allocate */
204 #define MAX_KMAP	10
205 #define	MAX_KMAPENT	128
206 
207 /*
208  * Copy-on-write flags for vm_map operations
209  */
210 #define MAP_COPY_NEEDED 0x1
211 #define MAP_COPY_ON_WRITE 0x2
212 #define MAP_NOFAULT 0x4
213 
214 /*
215  * vm_fault option flags
216  */
217 #define VM_FAULT_NORMAL 0
218 #define VM_FAULT_CHANGE_WIRING 1
219 #define VM_FAULT_USER_WIRE 2
220 
221 #ifdef KERNEL
222 extern vm_offset_t kentry_data;
223 extern vm_size_t kentry_data_size;
224 
225 boolean_t vm_map_check_protection __P((vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t));
226 int vm_map_copy __P((vm_map_t, vm_map_t, vm_offset_t, vm_size_t, vm_offset_t, boolean_t, boolean_t));
227 struct pmap;
228 vm_map_t vm_map_create __P((struct pmap *, vm_offset_t, vm_offset_t, boolean_t));
229 void vm_map_deallocate __P((vm_map_t));
230 int vm_map_delete __P((vm_map_t, vm_offset_t, vm_offset_t));
231 int vm_map_find __P((vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, boolean_t, vm_prot_t, vm_prot_t, int));
232 int vm_map_findspace __P((vm_map_t, vm_offset_t, vm_size_t, vm_offset_t *));
233 int vm_map_inherit __P((vm_map_t, vm_offset_t, vm_offset_t, vm_inherit_t));
234 void vm_map_init __P((struct vm_map *, vm_offset_t, vm_offset_t, boolean_t));
235 int vm_map_insert __P((vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t, vm_offset_t, vm_prot_t, vm_prot_t, int));
236 int vm_map_lookup __P((vm_map_t *, vm_offset_t, vm_prot_t, vm_map_entry_t *, vm_object_t *,
237     vm_pindex_t *, vm_prot_t *, boolean_t *, boolean_t *));
238 void vm_map_lookup_done __P((vm_map_t, vm_map_entry_t));
239 boolean_t vm_map_lookup_entry __P((vm_map_t, vm_offset_t, vm_map_entry_t *));
240 int vm_map_pageable __P((vm_map_t, vm_offset_t, vm_offset_t, boolean_t));
241 int vm_map_user_pageable __P((vm_map_t, vm_offset_t, vm_offset_t, boolean_t));
242 int vm_map_clean __P((vm_map_t, vm_offset_t, vm_offset_t, boolean_t, boolean_t));
243 int vm_map_protect __P((vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t, boolean_t));
244 void vm_map_reference __P((vm_map_t));
245 int vm_map_remove __P((vm_map_t, vm_offset_t, vm_offset_t));
246 void vm_map_simplify __P((vm_map_t, vm_offset_t));
247 void vm_map_startup __P((void));
248 int vm_map_submap __P((vm_map_t, vm_offset_t, vm_offset_t, vm_map_t));
249 void vm_map_madvise __P((vm_map_t, pmap_t, vm_offset_t, vm_offset_t, int));
250 void vm_map_simplify_entry __P((vm_map_t, vm_map_entry_t));
251 
252 #endif
253 #endif				/* _VM_MAP_ */
254