Initial import, 0.1 + pk 0.2.4-B1
[unix-history] / sys / vm / vm_map.h
CommitLineData
15637ed4
RG
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 * @(#)vm_map.h 7.3 (Berkeley) 4/21/91
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 * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
65 * -------------------- ----- ----------------------
66 * CURRENT PATCH LEVEL: 1 00002
67 * -------------------- ----- ----------------------
68 *
69 * 15 Aug 92 William Jolitz Prevent running out of map entries...
70 */
71
72/*
73 * Virtual memory map module definitions.
74 */
75
76#ifndef _VM_MAP_
77#define _VM_MAP_
78
79/*
80 * Types defined:
81 *
82 * vm_map_t the high-level address map data structure.
83 * vm_map_entry_t an entry in an address map.
84 * vm_map_version_t a timestamp of a map, for use with vm_map_lookup
85 */
86
87/*
88 * Objects which live in maps may be either VM objects, or
89 * another map (called a "sharing map") which denotes read-write
90 * sharing with other maps.
91 */
92
93union vm_map_object {
94 struct vm_object *vm_object; /* object object */
95 struct vm_map *share_map; /* share map */
96 struct vm_map *sub_map; /* belongs to another map */
97};
98
99typedef union vm_map_object vm_map_object_t;
100
101/*
102 * Address map entries consist of start and end addresses,
103 * a VM object (or sharing map) and offset into that object,
104 * and user-exported inheritance and protection information.
105 * Also included is control information for virtual copy operations.
106 */
107struct vm_map_entry {
108 struct vm_map_entry *prev; /* previous entry */
109 struct vm_map_entry *next; /* next entry */
110 vm_offset_t start; /* start address */
111 vm_offset_t end; /* end address */
112 union vm_map_object object; /* object I point to */
113 vm_offset_t offset; /* offset into object */
114 boolean_t is_a_map; /* Is "object" a map? */
115 boolean_t is_sub_map; /* Is "object" a submap? */
116 /* Only in sharing maps: */
117 boolean_t copy_on_write; /* is data copy-on-write */
118 boolean_t needs_copy; /* does object need to be copied */
119 /* Only in task maps: */
120 vm_prot_t protection; /* protection code */
121 vm_prot_t max_protection; /* maximum protection */
122 vm_inherit_t inheritance; /* inheritance */
123 int wired_count; /* can be paged if = 0 */
124};
125
126typedef struct vm_map_entry *vm_map_entry_t;
127
128/*
129 * Maps are doubly-linked lists of map entries, kept sorted
130 * by address. A single hint is provided to start
131 * searches again from the last successful search,
132 * insertion, or removal.
133 */
134struct vm_map {
135 struct pmap * pmap; /* Physical map */
136 lock_data_t lock; /* Lock for map data */
137 struct vm_map_entry header; /* List of entries */
138 int nentries; /* Number of entries */
139 vm_size_t size; /* virtual size */
140 boolean_t is_main_map; /* Am I a main map? */
141 int ref_count; /* Reference count */
142 simple_lock_data_t ref_lock; /* Lock for ref_count field */
143 vm_map_entry_t hint; /* hint for quick lookups */
144 simple_lock_data_t hint_lock; /* lock for hint storage */
145 vm_map_entry_t first_free; /* First free space hint */
146 boolean_t entries_pageable; /* map entries pageable?? */
147 unsigned int timestamp; /* Version number */
148#define min_offset header.start
149#define max_offset header.end
150};
151
152typedef struct vm_map *vm_map_t;
153
154/*
155 * Map versions are used to validate a previous lookup attempt.
156 *
157 * Since lookup operations may involve both a main map and
158 * a sharing map, it is necessary to have a timestamp from each.
159 * [If the main map timestamp has changed, the share_map and
160 * associated timestamp are no longer valid; the map version
161 * does not include a reference for the imbedded share_map.]
162 */
163typedef struct {
164 int main_timestamp;
165 vm_map_t share_map;
166 int share_timestamp;
167} vm_map_version_t;
168
169/*
170 * Macros: vm_map_lock, etc.
171 * Function:
172 * Perform locking on the data portion of a map.
173 */
174
175#define vm_map_lock(map) { lock_write(&(map)->lock); (map)->timestamp++; }
176#define vm_map_unlock(map) lock_write_done(&(map)->lock)
177#define vm_map_lock_read(map) lock_read(&(map)->lock)
178#define vm_map_unlock_read(map) lock_read_done(&(map)->lock)
179
180/*
181 * Exported procedures that operate on vm_map_t.
182 */
183
184void vm_map_init();
185vm_map_t vm_map_create();
186void vm_map_deallocate();
187void vm_map_reference();
188int vm_map_find();
189int vm_map_remove();
190int vm_map_lookup();
191void vm_map_lookup_done();
192int vm_map_protect();
193int vm_map_inherit();
194int vm_map_copy();
195void vm_map_print();
196void vm_map_copy_entry();
197boolean_t vm_map_verify();
198void vm_map_verify_done();
199
200/*
201 * Functions implemented as macros
202 */
203#define vm_map_min(map) ((map)->min_offset)
204#define vm_map_max(map) ((map)->max_offset)
205#define vm_map_pmap(map) ((map)->pmap)
206
207/* XXX: number of kernel maps and entries to statically allocate */
208#define MAX_KMAP 10
209
210#ifdef OMIT
211#define MAX_KMAPENT 500
212#else /* !OMIT*/
213#define MAX_KMAPENT 1000 /* 15 Aug 92*/
214#endif /* !OMIT*/
215
216#endif _VM_MAP_