Changes in kernel/generic/include/mm/as.h [98000fb:fc47885] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/mm/as.h
r98000fb rfc47885 1 1 /* 2 * Copyright (c) 20 01-2004Jakub Jermar2 * Copyright (c) 2010 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 36 36 #define KERN_AS_H_ 37 37 38 #ifdef KERNEL 39 #include <typedefs.h> 40 #else 41 #include <sys/types.h> 42 #endif 43 38 44 /** Address space area flags. */ 39 #define AS_AREA_READ 1 40 #define AS_AREA_WRITE 2 41 #define AS_AREA_EXEC 4 42 #define AS_AREA_CACHEABLE 8 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; 43 61 44 62 #ifdef KERNEL … … 47 65 #include <arch/mm/as.h> 48 66 #include <arch/mm/asid.h> 49 #include < arch/types.h>67 #include <typedefs.h> 50 68 #include <synch/spinlock.h> 51 69 #include <synch/mutex.h> … … 57 75 * Defined to be true if user address space and kernel address space shadow each 58 76 * other. 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 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 68 87 69 88 /** Kernel address space. */ 70 #define FLAG_AS_KERNEL (1 << 0)89 #define FLAG_AS_KERNEL (1 << 0) 71 90 72 91 /* Address space area attributes. */ 73 #define AS_AREA_ATTR_NONE 74 #define AS_AREA_ATTR_PARTIAL 1/**< Not fully initialized area. */92 #define AS_AREA_ATTR_NONE 0 93 #define AS_AREA_ATTR_PARTIAL 1 /**< Not fully initialized area. */ 75 94 76 95 /** The page fault was not resolved by as_page_fault(). */ 77 #define AS_PF_FAULT 0 96 #define AS_PF_FAULT 0 97 78 98 /** The page fault was resolved by as_page_fault(). */ 79 #define AS_PF_OK 1 99 #define AS_PF_OK 1 100 80 101 /** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */ 81 #define AS_PF_DEFER 102 #define AS_PF_DEFER 2 82 103 83 104 /** Address space structure. … … 87 108 * supposed to figure in the list as they are shared by all tasks and 88 109 * set up during system initialization. 110 * 89 111 */ 90 112 typedef struct as { 91 113 /** Protected by asidlock. */ 92 114 link_t inactive_as_with_asid_link; 115 93 116 /** 94 * Number of processors on wich is this address space active. 95 * Protected by asidlock. 117 * Number of processors on which this 118 * address space is active. Protected by 119 * asidlock. 96 120 */ 97 121 size_t cpu_refcount; 98 /** 99 * Address space identifier. 100 * Constant on architectures that do not support ASIDs. 101 * Protected by asidlock. 122 123 /** Address space identifier. 124 * 125 * Constant on architectures that do not 126 * support ASIDs. Protected by asidlock. 127 * 102 128 */ 103 129 asid_t asid; 104 105 /** Number of references (i.e tasks that reference this as). */130 131 /** Number of references (i.e. tasks that reference this as). */ 106 132 atomic_t refcount; 107 133 108 134 mutex_t lock; 109 135 110 136 /** B+tree of address space areas. */ 111 137 btree_t as_area_btree; … … 113 139 /** Non-generic content. */ 114 140 as_genarch_t genarch; 115 141 116 142 /** Architecture specific content. */ 117 143 as_arch_t arch; … … 119 145 120 146 typedef struct { 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); 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 *); 125 152 } as_operations_t; 126 153 … … 128 155 * This structure contains information associated with the shared address space 129 156 * area. 157 * 130 158 */ 131 159 typedef struct { 132 160 /** This lock must be acquired only when the as_area lock is held. */ 133 mutex_t lock; 161 mutex_t lock; 134 162 /** This structure can be deallocated if refcount drops to 0. */ 135 163 size_t refcount; 164 136 165 /** 137 166 * B+tree containing complete map of anonymous pages of the shared area. … … 144 173 PF_ACCESS_READ, 145 174 PF_ACCESS_WRITE, 146 PF_ACCESS_EXEC 175 PF_ACCESS_EXEC, 176 PF_ACCESS_UNKNOWN 147 177 } pf_access_t; 148 178 … … 151 181 /** Backend data stored in address space area. */ 152 182 typedef union mem_backend_data { 153 struct { /**< elf_backend members */ 183 /** elf_backend members */ 184 struct { 154 185 elf_header_t *elf; 155 186 elf_segment_header_t *segment; 156 187 }; 157 struct { /**< phys_backend members */ 188 189 /** phys_backend members */ 190 struct { 158 191 uintptr_t base; 159 192 size_t frames; … … 164 197 * 165 198 * Each as_area_t structure describes one contiguous area of virtual memory. 199 * 166 200 */ 167 201 typedef struct { 168 202 mutex_t lock; 203 169 204 /** Containing address space. */ 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. */ 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. */ 178 214 size_t pages; 215 216 /** Number of resident pages in the area. */ 217 size_t resident; 218 179 219 /** Base address of this area. */ 180 220 uintptr_t base; 221 181 222 /** Map of used space. */ 182 223 btree_t used_space; 183 224 184 225 /** 185 * If the address space area has been shared, this pointer will186 * referencethe share info structure.226 * If the address space area is shared. this is 227 * a reference to the share info structure. 187 228 */ 188 229 share_info_t *sh_info; 189 230 190 231 /** Memory backend backing this address space area. */ 191 232 struct mem_backend *backend; 192 233 193 234 /** Data to be used by the backend. */ 194 235 mem_backend_data_t backend_data; … … 197 238 /** Address space area backend structure. */ 198 239 typedef struct mem_backend { 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);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 *); 202 243 } mem_backend_t; 203 244 … … 209 250 extern void as_init(void); 210 251 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 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); 231 272 232 273 /* Interface to be implemented by architectures. */ 274 233 275 #ifndef as_constructor_arch 234 extern int as_constructor_arch(as_t * as, int flags);276 extern int as_constructor_arch(as_t *, unsigned int); 235 277 #endif /* !def as_constructor_arch */ 278 236 279 #ifndef as_destructor_arch 237 extern int as_destructor_arch(as_t * as);280 extern int as_destructor_arch(as_t *); 238 281 #endif /* !def as_destructor_arch */ 282 239 283 #ifndef as_create_arch 240 extern int as_create_arch(as_t * as, int flags);284 extern int as_create_arch(as_t *, unsigned int); 241 285 #endif /* !def as_create_arch */ 286 242 287 #ifndef as_install_arch 243 extern void as_install_arch(as_t * as);288 extern void as_install_arch(as_t *); 244 289 #endif /* !def as_install_arch */ 290 245 291 #ifndef as_deinstall_arch 246 extern void as_deinstall_arch(as_t * as);292 extern void as_deinstall_arch(as_t *); 247 293 #endif /* !def as_deinstall_arch */ 248 294 … … 252 298 extern mem_backend_t phys_backend; 253 299 254 /** 300 /** 255 301 * This flags is passed when running the loader, otherwise elf_load() 256 302 * would return with a EE_LOADER error code. 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); 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); 262 309 263 310 /* Address space area related syscalls. */ 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);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); 268 315 269 316 /* Introspection functions. */ 270 extern void as_print(as_t *as); 317 extern void as_get_area_info(as_t *, as_area_info_t **, size_t *); 318 extern void as_print(as_t *); 271 319 272 320 #endif /* KERNEL */
Note:
See TracChangeset
for help on using the changeset viewer.