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