1 /* 2 * Copyright (c) 1985, Avadis Tevanian, Jr., Michael Wayne Young 3 * Copyright (c) 1987 Carnegie-Mellon University 4 * Copyright (c) 1991 Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * The Mach Operating System project at Carnegie-Mellon University. 9 * 10 * The CMU software License Agreement specifies the terms and conditions 11 * for use and redistribution. 12 * 13 * @(#)vm_map.h 7.1 (Berkeley) 12/05/90 14 */ 15 16 /* 17 * Virtual memory map module definitions. 18 */ 19 20 #ifndef _VM_MAP_ 21 #define _VM_MAP_ 22 23 #ifdef KERNEL 24 #include "types.h" 25 #include "lock.h" 26 #include "../vm/pmap.h" 27 #include "../vm/vm_prot.h" 28 #include "../vm/vm_inherit.h" 29 #include "../vm/vm_object.h" 30 #else 31 #include <sys/types.h> 32 #include <sys/lock.h> 33 #include <vm/pmap.h> 34 #include <vm/vm_prot.h> 35 #include <vm/vm_inherit.h> 36 #include <vm/vm_object.h> 37 #endif 38 39 /* 40 * Types defined: 41 * 42 * vm_map_t the high-level address map data structure. 43 * vm_map_entry_t an entry in an address map. 44 * vm_map_version_t a timestamp of a map, for use with vm_map_lookup 45 */ 46 47 /* 48 * Objects which live in maps may be either VM objects, or 49 * another map (called a "sharing map") which denotes read-write 50 * sharing with other maps. 51 */ 52 53 union vm_map_object { 54 struct vm_object *vm_object; /* object object */ 55 struct vm_map *share_map; /* share map */ 56 struct vm_map *sub_map; /* belongs to another map */ 57 }; 58 59 typedef union vm_map_object vm_map_object_t; 60 61 /* 62 * Address map entries consist of start and end addresses, 63 * a VM object (or sharing map) and offset into that object, 64 * and user-exported inheritance and protection information. 65 * Also included is control information for virtual copy operations. 66 */ 67 struct vm_map_entry { 68 struct vm_map_entry *prev; /* previous entry */ 69 struct vm_map_entry *next; /* next entry */ 70 vm_offset_t start; /* start address */ 71 vm_offset_t end; /* end address */ 72 union vm_map_object object; /* object I point to */ 73 vm_offset_t offset; /* offset into object */ 74 boolean_t is_a_map; /* Is "object" a map? */ 75 boolean_t is_sub_map; /* Is "object" a submap? */ 76 /* Only in sharing maps: */ 77 boolean_t copy_on_write; /* is data copy-on-write */ 78 boolean_t needs_copy; /* does object need to be copied */ 79 /* Only in task maps: */ 80 vm_prot_t protection; /* protection code */ 81 vm_prot_t max_protection; /* maximum protection */ 82 vm_inherit_t inheritance; /* inheritance */ 83 int wired_count; /* can be paged if = 0 */ 84 }; 85 86 typedef struct vm_map_entry *vm_map_entry_t; 87 88 #define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0) 89 90 /* 91 * Maps are doubly-linked lists of map entries, kept sorted 92 * by address. A single hint is provided to start 93 * searches again from the last successful search, 94 * insertion, or removal. 95 */ 96 struct vm_map { 97 lock_data_t lock; /* Lock for map data */ 98 struct vm_map_entry header; /* List of entries */ 99 int nentries; /* Number of entries */ 100 pmap_t pmap; /* Physical map */ 101 vm_size_t size; /* virtual size */ 102 boolean_t is_main_map; /* Am I a main map? */ 103 int ref_count; /* Reference count */ 104 simple_lock_data_t ref_lock; /* Lock for ref_count field */ 105 vm_map_entry_t hint; /* hint for quick lookups */ 106 simple_lock_data_t hint_lock; /* lock for hint storage */ 107 vm_map_entry_t first_free; /* First free space hint */ 108 boolean_t entries_pageable; /* map entries pageable?? */ 109 unsigned int timestamp; /* Version number */ 110 #define min_offset header.start 111 #define max_offset header.end 112 }; 113 114 typedef struct vm_map *vm_map_t; 115 116 #define VM_MAP_NULL ((vm_map_t) 0) 117 118 /* 119 * Map versions are used to validate a previous lookup attempt. 120 * 121 * Since lookup operations may involve both a main map and 122 * a sharing map, it is necessary to have a timestamp from each. 123 * [If the main map timestamp has changed, the share_map and 124 * associated timestamp are no longer valid; the map version 125 * does not include a reference for the imbedded share_map.] 126 */ 127 typedef struct { 128 int main_timestamp; 129 vm_map_t share_map; 130 int share_timestamp; 131 } vm_map_version_t; 132 133 /* 134 * Macros: vm_map_lock, etc. 135 * Function: 136 * Perform locking on the data portion of a map. 137 */ 138 139 #define vm_map_lock(map) { lock_write(&(map)->lock); (map)->timestamp++; } 140 #define vm_map_unlock(map) lock_write_done(&(map)->lock) 141 #define vm_map_lock_read(map) lock_read(&(map)->lock) 142 #define vm_map_unlock_read(map) lock_read_done(&(map)->lock) 143 144 /* 145 * Exported procedures that operate on vm_map_t. 146 */ 147 148 void vm_map_init(); 149 vm_map_t vm_map_create(); 150 void vm_map_deallocate(); 151 void vm_map_reference(); 152 int vm_map_find(); 153 int vm_map_remove(); 154 int vm_map_lookup(); 155 void vm_map_lookup_done(); 156 int vm_map_protect(); 157 int vm_map_inherit(); 158 int vm_map_copy(); 159 vm_map_t vm_map_fork(); 160 void vm_map_print(); 161 void vm_map_copy_entry(); 162 boolean_t vm_map_verify(); 163 void vm_map_verify_done(); 164 165 /* 166 * Functions implemented as macros 167 */ 168 #define vm_map_min(map) ((map)->min_offset) 169 #define vm_map_max(map) ((map)->max_offset) 170 #define vm_map_pmap(map) ((map)->pmap) 171 172 /* XXX: number of kernel maps and entries to statically allocate */ 173 #define MAX_KMAP 10 174 #define MAX_KMAPENT 500 175 176 #endif _VM_MAP_ 177