Changes in kernel/generic/include/mm/as.h [fc47885:98000fb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/mm/as.h
rfc47885 r98000fb 1 1 /* 2 * Copyright (c) 20 10Jakub Jermar2 * Copyright (c) 2001-2004 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 36 36 #define KERN_AS_H_ 37 37 38 #ifdef KERNEL39 #include <typedefs.h>40 #else41 #include <sys/types.h>42 #endif43 44 38 /** Address space area flags. */ 45 #define AS_AREA_READ 1 46 #define AS_AREA_WRITE 2 47 #define AS_AREA_EXEC 4 48 #define AS_AREA_CACHEABLE 8 49 50 /** Address space area info exported to userspace. */ 51 typedef struct { 52 /** Starting address */ 53 uintptr_t start_addr; 54 55 /** Area size */ 56 size_t size; 57 58 /** Area flags */ 59 unsigned int flags; 60 } as_area_info_t; 39 #define AS_AREA_READ 1 40 #define AS_AREA_WRITE 2 41 #define AS_AREA_EXEC 4 42 #define AS_AREA_CACHEABLE 8 61 43 62 44 #ifdef KERNEL … … 65 47 #include <arch/mm/as.h> 66 48 #include <arch/mm/asid.h> 67 #include < typedefs.h>49 #include <arch/types.h> 68 50 #include <synch/spinlock.h> 69 51 #include <synch/mutex.h> … … 75 57 * Defined to be true if user address space and kernel address space shadow each 76 58 * other. 77 * 78 */ 79 #define KERNEL_ADDRESS_SPACE_SHADOWED KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 80 81 #define KERNEL_ADDRESS_SPACE_START KERNEL_ADDRESS_SPACE_START_ARCH 82 #define KERNEL_ADDRESS_SPACE_END KERNEL_ADDRESS_SPACE_END_ARCH 83 #define USER_ADDRESS_SPACE_START USER_ADDRESS_SPACE_START_ARCH 84 #define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH 85 86 #define USTACK_ADDRESS USTACK_ADDRESS_ARCH 59 */ 60 #define KERNEL_ADDRESS_SPACE_SHADOWED KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 61 62 #define KERNEL_ADDRESS_SPACE_START KERNEL_ADDRESS_SPACE_START_ARCH 63 #define KERNEL_ADDRESS_SPACE_END KERNEL_ADDRESS_SPACE_END_ARCH 64 #define USER_ADDRESS_SPACE_START USER_ADDRESS_SPACE_START_ARCH 65 #define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH 66 67 #define USTACK_ADDRESS USTACK_ADDRESS_ARCH 87 68 88 69 /** Kernel address space. */ 89 #define FLAG_AS_KERNEL (1 << 0)70 #define FLAG_AS_KERNEL (1 << 0) 90 71 91 72 /* Address space area attributes. */ 92 #define AS_AREA_ATTR_NONE 93 #define AS_AREA_ATTR_PARTIAL 1/**< Not fully initialized area. */73 #define AS_AREA_ATTR_NONE 0 74 #define AS_AREA_ATTR_PARTIAL 1 /**< Not fully initialized area. */ 94 75 95 76 /** The page fault was not resolved by as_page_fault(). */ 96 #define AS_PF_FAULT 0 97 77 #define AS_PF_FAULT 0 98 78 /** The page fault was resolved by as_page_fault(). */ 99 #define AS_PF_OK 1 100 79 #define AS_PF_OK 1 101 80 /** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */ 102 #define AS_PF_DEFER 81 #define AS_PF_DEFER 2 103 82 104 83 /** Address space structure. … … 108 87 * supposed to figure in the list as they are shared by all tasks and 109 88 * set up during system initialization. 110 *111 89 */ 112 90 typedef struct as { 113 91 /** Protected by asidlock. */ 114 92 link_t inactive_as_with_asid_link; 115 116 /** 117 * Number of processors on which this 118 * address space is active. Protected by 119 * asidlock. 93 /** 94 * Number of processors on wich is this address space active. 95 * Protected by asidlock. 120 96 */ 121 97 size_t cpu_refcount; 122 123 /** Address space identifier. 124 * 125 * Constant on architectures that do not 126 * support ASIDs. Protected by asidlock. 127 * 98 /** 99 * Address space identifier. 100 * Constant on architectures that do not support ASIDs. 101 * Protected by asidlock. 128 102 */ 129 103 asid_t asid; 130 131 /** Number of references (i.e .tasks that reference this as). */104 105 /** Number of references (i.e tasks that reference this as). */ 132 106 atomic_t refcount; 133 107 134 108 mutex_t lock; 135 109 136 110 /** B+tree of address space areas. */ 137 111 btree_t as_area_btree; … … 139 113 /** Non-generic content. */ 140 114 as_genarch_t genarch; 141 115 142 116 /** Architecture specific content. */ 143 117 as_arch_t arch; … … 145 119 146 120 typedef struct { 147 pte_t *(* page_table_create)(unsigned int); 148 void (* page_table_destroy)(pte_t *); 149 void (* page_table_lock)(as_t *, bool); 150 void (* page_table_unlock)(as_t *, bool); 151 bool (* page_table_locked)(as_t *); 121 pte_t *(* page_table_create)(int flags); 122 void (* page_table_destroy)(pte_t *page_table); 123 void (* page_table_lock)(as_t *as, bool lock); 124 void (* page_table_unlock)(as_t *as, bool unlock); 152 125 } as_operations_t; 153 126 … … 155 128 * This structure contains information associated with the shared address space 156 129 * area. 157 *158 130 */ 159 131 typedef struct { 160 132 /** This lock must be acquired only when the as_area lock is held. */ 161 mutex_t lock; 133 mutex_t lock; 162 134 /** This structure can be deallocated if refcount drops to 0. */ 163 135 size_t refcount; 164 165 136 /** 166 137 * B+tree containing complete map of anonymous pages of the shared area. … … 173 144 PF_ACCESS_READ, 174 145 PF_ACCESS_WRITE, 175 PF_ACCESS_EXEC, 176 PF_ACCESS_UNKNOWN 146 PF_ACCESS_EXEC 177 147 } pf_access_t; 178 148 … … 181 151 /** Backend data stored in address space area. */ 182 152 typedef union mem_backend_data { 183 /** elf_backend members */ 184 struct { 153 struct { /**< elf_backend members */ 185 154 elf_header_t *elf; 186 155 elf_segment_header_t *segment; 187 156 }; 188 189 /** phys_backend members */ 190 struct { 157 struct { /**< phys_backend members */ 191 158 uintptr_t base; 192 159 size_t frames; … … 197 164 * 198 165 * Each as_area_t structure describes one contiguous area of virtual memory. 199 *200 166 */ 201 167 typedef struct { 202 168 mutex_t lock; 203 204 169 /** Containing address space. */ 205 as_t *as; 206 207 /** Memory flags. */ 208 unsigned int flags; 209 210 /** Address space area attributes. */ 211 unsigned int attributes; 212 213 /** Number of pages in the area. */ 170 as_t *as; 171 /** 172 * Flags related to the memory represented by the address space area. 173 */ 174 int flags; 175 /** Attributes related to the address space area itself. */ 176 int attributes; 177 /** Size of this area in multiples of PAGE_SIZE. */ 214 178 size_t pages; 215 216 /** Number of resident pages in the area. */217 size_t resident;218 219 179 /** Base address of this area. */ 220 180 uintptr_t base; 221 222 181 /** Map of used space. */ 223 182 btree_t used_space; 224 225 /** 226 * If the address space area is shared. this is227 * a reference tothe share info structure.183 184 /** 185 * If the address space area has been shared, this pointer will 186 * reference the share info structure. 228 187 */ 229 188 share_info_t *sh_info; 230 189 231 190 /** Memory backend backing this address space area. */ 232 191 struct mem_backend *backend; 233 192 234 193 /** Data to be used by the backend. */ 235 194 mem_backend_data_t backend_data; … … 238 197 /** Address space area backend structure. */ 239 198 typedef struct mem_backend { 240 int (* page_fault)(as_area_t * , uintptr_t, pf_access_t);241 void (* frame_free)(as_area_t * , uintptr_t, uintptr_t);242 void (* share)(as_area_t * );199 int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access); 200 void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame); 201 void (* share)(as_area_t *area); 243 202 } mem_backend_t; 244 203 … … 250 209 extern void as_init(void); 251 210 252 extern as_t *as_create( unsigned int);253 extern void as_destroy(as_t * );254 extern void as_ hold(as_t *);255 extern void as_release(as_t *);256 extern void as_switch(as_t *, as_t *); 257 extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);258 259 extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t, 260 unsigned int, mem_backend_t *, mem_backend_data_t *); 261 extern int as_area_ destroy(as_t *, uintptr_t);262 extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int); 263 extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t, 264 unsigned int);265 extern int as_area_change_flags(as_t *, unsigned int, uintptr_t); 266 267 extern unsigned int as_area_get_flags(as_area_t *);268 extern bool as_area_check_access(as_area_t *, pf_access_t);269 extern size_t as_area_get_size(uintptr_t);270 extern bool used_space_insert(as_area_t *, uintptr_t, size_t);271 extern bool used_space_remove(as_area_t *, uintptr_t, size_t); 211 extern as_t *as_create(int flags); 212 extern void as_destroy(as_t *as); 213 extern void as_switch(as_t *old_as, as_t *new_as); 214 extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate); 215 216 extern as_area_t *as_area_create(as_t *as, int flags, size_t size, 217 uintptr_t base, int attrs, mem_backend_t *backend, 218 mem_backend_data_t *backend_data); 219 extern int as_area_destroy(as_t *as, uintptr_t address); 220 extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags); 221 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size, 222 as_t *dst_as, uintptr_t dst_base, int dst_flags_mask); 223 extern int as_area_change_flags(as_t *as, int flags, uintptr_t address); 224 225 extern int as_area_get_flags(as_area_t *area); 226 extern bool as_area_check_access(as_area_t *area, pf_access_t access); 227 extern size_t as_area_get_size(uintptr_t base); 228 extern int used_space_insert(as_area_t *a, uintptr_t page, size_t count); 229 extern int used_space_remove(as_area_t *a, uintptr_t page, size_t count); 230 272 231 273 232 /* Interface to be implemented by architectures. */ 274 275 233 #ifndef as_constructor_arch 276 extern int as_constructor_arch(as_t * , unsigned int);234 extern int as_constructor_arch(as_t *as, int flags); 277 235 #endif /* !def as_constructor_arch */ 278 279 236 #ifndef as_destructor_arch 280 extern int as_destructor_arch(as_t * );237 extern int as_destructor_arch(as_t *as); 281 238 #endif /* !def as_destructor_arch */ 282 283 239 #ifndef as_create_arch 284 extern int as_create_arch(as_t * , unsigned int);240 extern int as_create_arch(as_t *as, int flags); 285 241 #endif /* !def as_create_arch */ 286 287 242 #ifndef as_install_arch 288 extern void as_install_arch(as_t * );243 extern void as_install_arch(as_t *as); 289 244 #endif /* !def as_install_arch */ 290 291 245 #ifndef as_deinstall_arch 292 extern void as_deinstall_arch(as_t * );246 extern void as_deinstall_arch(as_t *as); 293 247 #endif /* !def as_deinstall_arch */ 294 248 … … 298 252 extern mem_backend_t phys_backend; 299 253 300 /** 254 /** 301 255 * This flags is passed when running the loader, otherwise elf_load() 302 256 * would return with a EE_LOADER error code. 303 * 304 */ 305 #define ELD_F_NONE 0 306 #define ELD_F_LOADER 1 307 308 extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int); 257 */ 258 #define ELD_F_NONE 0 259 #define ELD_F_LOADER 1 260 261 extern unsigned int elf_load(elf_header_t *header, as_t *as, int flags); 309 262 310 263 /* Address space area related syscalls. */ 311 extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int);312 extern sysarg_t sys_as_area_resize(uintptr_t, size_t, unsigned int);313 extern sysarg_t sys_as_area_change_flags(uintptr_t, unsigned int);314 extern sysarg_t sys_as_area_destroy(uintptr_t);264 extern unative_t sys_as_area_create(uintptr_t address, size_t size, int flags); 265 extern unative_t sys_as_area_resize(uintptr_t address, size_t size, int flags); 266 extern unative_t sys_as_area_change_flags(uintptr_t address, int flags); 267 extern unative_t sys_as_area_destroy(uintptr_t address); 315 268 316 269 /* Introspection functions. */ 317 extern void as_get_area_info(as_t *, as_area_info_t **, size_t *); 318 extern void as_print(as_t *); 270 extern void as_print(as_t *as); 319 271 320 272 #endif /* KERNEL */
Note:
See TracChangeset
for help on using the changeset viewer.