Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/mm/as.h

    rfc47885 r98000fb  
    11/*
    2  * Copyright (c) 2010 Jakub Jermar
     2 * Copyright (c) 2001-2004 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    3636#define KERN_AS_H_
    3737
    38 #ifdef KERNEL
    39         #include <typedefs.h>
    40 #else
    41         #include <sys/types.h>
    42 #endif
    43 
    4438/** 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
    6143
    6244#ifdef KERNEL
     
    6547#include <arch/mm/as.h>
    6648#include <arch/mm/asid.h>
    67 #include <typedefs.h>
     49#include <arch/types.h>
    6850#include <synch/spinlock.h>
    6951#include <synch/mutex.h>
     
    7557 * Defined to be true if user address space and kernel address space shadow each
    7658 * 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
    8768
    8869/** Kernel address space. */
    89 #define FLAG_AS_KERNEL  (1 << 0)
     70#define FLAG_AS_KERNEL                  (1 << 0)       
    9071
    9172/* Address space area attributes. */
    92 #define AS_AREA_ATTR_NONE     0
    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. */
    9475
    9576/** The page fault was not resolved by as_page_fault(). */
    96 #define AS_PF_FAULT  0
    97 
     77#define AS_PF_FAULT             0
    9878/** The page fault was resolved by as_page_fault(). */
    99 #define AS_PF_OK  1
    100 
     79#define AS_PF_OK                1
    10180/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
    102 #define AS_PF_DEFER  2
     81#define AS_PF_DEFER             2
    10382
    10483/** Address space structure.
     
    10887 * supposed to figure in the list as they are shared by all tasks and
    10988 * set up during system initialization.
    110  *
    11189 */
    11290typedef struct as {
    11391        /** Protected by asidlock. */
    11492        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.
    12096         */
    12197        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.
    128102         */
    129103        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). */
    132106        atomic_t refcount;
    133        
     107
    134108        mutex_t lock;
    135        
     109
    136110        /** B+tree of address space areas. */
    137111        btree_t as_area_btree;
     
    139113        /** Non-generic content. */
    140114        as_genarch_t genarch;
    141        
     115
    142116        /** Architecture specific content. */
    143117        as_arch_t arch;
     
    145119
    146120typedef 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);
    152125} as_operations_t;
    153126
     
    155128 * This structure contains information associated with the shared address space
    156129 * area.
    157  *
    158130 */
    159131typedef struct {
    160132        /** This lock must be acquired only when the as_area lock is held. */
    161         mutex_t lock;
     133        mutex_t lock;           
    162134        /** This structure can be deallocated if refcount drops to 0. */
    163135        size_t refcount;
    164        
    165136        /**
    166137         * B+tree containing complete map of anonymous pages of the shared area.
     
    173144        PF_ACCESS_READ,
    174145        PF_ACCESS_WRITE,
    175         PF_ACCESS_EXEC,
    176         PF_ACCESS_UNKNOWN
     146        PF_ACCESS_EXEC
    177147} pf_access_t;
    178148
     
    181151/** Backend data stored in address space area. */
    182152typedef union mem_backend_data {
    183         /** elf_backend members */
    184         struct {
     153        struct {        /**< elf_backend members */
    185154                elf_header_t *elf;
    186155                elf_segment_header_t *segment;
    187156        };
    188        
    189         /** phys_backend members */
    190         struct {
     157        struct {        /**< phys_backend members */
    191158                uintptr_t base;
    192159                size_t frames;
     
    197164 *
    198165 * Each as_area_t structure describes one contiguous area of virtual memory.
    199  *
    200166 */
    201167typedef struct {
    202168        mutex_t lock;
    203        
    204169        /** 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. */
    214178        size_t pages;
    215        
    216         /** Number of resident pages in the area. */
    217         size_t resident;
    218        
    219179        /** Base address of this area. */
    220180        uintptr_t base;
    221        
    222181        /** Map of used space. */
    223182        btree_t used_space;
    224        
    225         /**
    226          * If the address space area is shared. this is
    227          * a reference to the share info structure.
     183
     184        /**
     185         * If the address space area has been shared, this pointer will
     186         * reference the share info structure.
    228187         */
    229188        share_info_t *sh_info;
    230        
     189
    231190        /** Memory backend backing this address space area. */
    232191        struct mem_backend *backend;
    233        
     192
    234193        /** Data to be used by the backend. */
    235194        mem_backend_data_t backend_data;
     
    238197/** Address space area backend structure. */
    239198typedef 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);
    243202} mem_backend_t;
    244203
     
    250209extern void as_init(void);
    251210
    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);
     211extern as_t *as_create(int flags);
     212extern void as_destroy(as_t *as);
     213extern void as_switch(as_t *old_as, as_t *new_as);
     214extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate);
     215
     216extern 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);
     219extern int as_area_destroy(as_t *as, uintptr_t address);       
     220extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags);
     221int 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);
     223extern int as_area_change_flags(as_t *as, int flags, uintptr_t address);
     224
     225extern int as_area_get_flags(as_area_t *area);
     226extern bool as_area_check_access(as_area_t *area, pf_access_t access);
     227extern size_t as_area_get_size(uintptr_t base);
     228extern int used_space_insert(as_area_t *a, uintptr_t page, size_t count);
     229extern int used_space_remove(as_area_t *a, uintptr_t page, size_t count);
     230
    272231
    273232/* Interface to be implemented by architectures. */
    274 
    275233#ifndef as_constructor_arch
    276 extern int as_constructor_arch(as_t *, unsigned int);
     234extern int as_constructor_arch(as_t *as, int flags);
    277235#endif /* !def as_constructor_arch */
    278 
    279236#ifndef as_destructor_arch
    280 extern int as_destructor_arch(as_t *);
     237extern int as_destructor_arch(as_t *as);
    281238#endif /* !def as_destructor_arch */
    282 
    283239#ifndef as_create_arch
    284 extern int as_create_arch(as_t *, unsigned int);
     240extern int as_create_arch(as_t *as, int flags);
    285241#endif /* !def as_create_arch */
    286 
    287242#ifndef as_install_arch
    288 extern void as_install_arch(as_t *);
     243extern void as_install_arch(as_t *as);
    289244#endif /* !def as_install_arch */
    290 
    291245#ifndef as_deinstall_arch
    292 extern void as_deinstall_arch(as_t *);
     246extern void as_deinstall_arch(as_t *as);
    293247#endif /* !def as_deinstall_arch */
    294248
     
    298252extern mem_backend_t phys_backend;
    299253
    300 /**
     254/** 
    301255 * This flags is passed when running the loader, otherwise elf_load()
    302256 * 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
     261extern unsigned int elf_load(elf_header_t *header, as_t *as, int flags);
    309262
    310263/* 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);
     264extern unative_t sys_as_area_create(uintptr_t address, size_t size, int flags);
     265extern unative_t sys_as_area_resize(uintptr_t address, size_t size, int flags);
     266extern unative_t sys_as_area_change_flags(uintptr_t address, int flags);
     267extern unative_t sys_as_area_destroy(uintptr_t address);
    315268
    316269/* Introspection functions. */
    317 extern void as_get_area_info(as_t *, as_area_info_t **, size_t *);
    318 extern void as_print(as_t *);
     270extern void as_print(as_t *as);
    319271
    320272#endif /* KERNEL */
Note: See TracChangeset for help on using the changeset viewer.