Ignore:
File:
1 edited

Legend:

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

    r98000fb rfc47885  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 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
    3844/** 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. */
     51typedef 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;
    4361
    4462#ifdef KERNEL
     
    4765#include <arch/mm/as.h>
    4866#include <arch/mm/asid.h>
    49 #include <arch/types.h>
     67#include <typedefs.h>
    5068#include <synch/spinlock.h>
    5169#include <synch/mutex.h>
     
    5775 * Defined to be true if user address space and kernel address space shadow each
    5876 * 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
    6887
    6988/** Kernel address space. */
    70 #define FLAG_AS_KERNEL                  (1 << 0)       
     89#define FLAG_AS_KERNEL  (1 << 0)
    7190
    7291/* Address space area attributes. */
    73 #define AS_AREA_ATTR_NONE       0
    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. */
    7594
    7695/** The page fault was not resolved by as_page_fault(). */
    77 #define AS_PF_FAULT             0
     96#define AS_PF_FAULT  0
     97
    7898/** The page fault was resolved by as_page_fault(). */
    79 #define AS_PF_OK                1
     99#define AS_PF_OK  1
     100
    80101/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
    81 #define AS_PF_DEFER             2
     102#define AS_PF_DEFER  2
    82103
    83104/** Address space structure.
     
    87108 * supposed to figure in the list as they are shared by all tasks and
    88109 * set up during system initialization.
     110 *
    89111 */
    90112typedef struct as {
    91113        /** Protected by asidlock. */
    92114        link_t inactive_as_with_asid_link;
     115       
    93116        /**
    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.
    96120         */
    97121        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         *
    102128         */
    103129        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). */
    106132        atomic_t refcount;
    107 
     133       
    108134        mutex_t lock;
    109 
     135       
    110136        /** B+tree of address space areas. */
    111137        btree_t as_area_btree;
     
    113139        /** Non-generic content. */
    114140        as_genarch_t genarch;
    115 
     141       
    116142        /** Architecture specific content. */
    117143        as_arch_t arch;
     
    119145
    120146typedef 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 *);
    125152} as_operations_t;
    126153
     
    128155 * This structure contains information associated with the shared address space
    129156 * area.
     157 *
    130158 */
    131159typedef struct {
    132160        /** This lock must be acquired only when the as_area lock is held. */
    133         mutex_t lock;           
     161        mutex_t lock;
    134162        /** This structure can be deallocated if refcount drops to 0. */
    135163        size_t refcount;
     164       
    136165        /**
    137166         * B+tree containing complete map of anonymous pages of the shared area.
     
    144173        PF_ACCESS_READ,
    145174        PF_ACCESS_WRITE,
    146         PF_ACCESS_EXEC
     175        PF_ACCESS_EXEC,
     176        PF_ACCESS_UNKNOWN
    147177} pf_access_t;
    148178
     
    151181/** Backend data stored in address space area. */
    152182typedef union mem_backend_data {
    153         struct {        /**< elf_backend members */
     183        /** elf_backend members */
     184        struct {
    154185                elf_header_t *elf;
    155186                elf_segment_header_t *segment;
    156187        };
    157         struct {        /**< phys_backend members */
     188       
     189        /** phys_backend members */
     190        struct {
    158191                uintptr_t base;
    159192                size_t frames;
     
    164197 *
    165198 * Each as_area_t structure describes one contiguous area of virtual memory.
     199 *
    166200 */
    167201typedef struct {
    168202        mutex_t lock;
     203       
    169204        /** 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. */
    178214        size_t pages;
     215       
     216        /** Number of resident pages in the area. */
     217        size_t resident;
     218       
    179219        /** Base address of this area. */
    180220        uintptr_t base;
     221       
    181222        /** Map of used space. */
    182223        btree_t used_space;
    183 
     224       
    184225        /**
    185          * If the address space area has been shared, this pointer will
    186          * reference the share info structure.
     226         * If the address space area is shared. this is
     227         * a reference to the share info structure.
    187228         */
    188229        share_info_t *sh_info;
    189 
     230       
    190231        /** Memory backend backing this address space area. */
    191232        struct mem_backend *backend;
    192 
     233       
    193234        /** Data to be used by the backend. */
    194235        mem_backend_data_t backend_data;
     
    197238/** Address space area backend structure. */
    198239typedef 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 *);
    202243} mem_backend_t;
    203244
     
    209250extern void as_init(void);
    210251
    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 
     252extern as_t *as_create(unsigned int);
     253extern void as_destroy(as_t *);
     254extern void as_hold(as_t *);
     255extern void as_release(as_t *);
     256extern void as_switch(as_t *, as_t *);
     257extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
     258
     259extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t,
     260    unsigned int, mem_backend_t *, mem_backend_data_t *);
     261extern int as_area_destroy(as_t *, uintptr_t);
     262extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int);
     263extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t,
     264    unsigned int);
     265extern int as_area_change_flags(as_t *, unsigned int, uintptr_t);
     266
     267extern unsigned int as_area_get_flags(as_area_t *);
     268extern bool as_area_check_access(as_area_t *, pf_access_t);
     269extern size_t as_area_get_size(uintptr_t);
     270extern bool used_space_insert(as_area_t *, uintptr_t, size_t);
     271extern bool used_space_remove(as_area_t *, uintptr_t, size_t);
    231272
    232273/* Interface to be implemented by architectures. */
     274
    233275#ifndef as_constructor_arch
    234 extern int as_constructor_arch(as_t *as, int flags);
     276extern int as_constructor_arch(as_t *, unsigned int);
    235277#endif /* !def as_constructor_arch */
     278
    236279#ifndef as_destructor_arch
    237 extern int as_destructor_arch(as_t *as);
     280extern int as_destructor_arch(as_t *);
    238281#endif /* !def as_destructor_arch */
     282
    239283#ifndef as_create_arch
    240 extern int as_create_arch(as_t *as, int flags);
     284extern int as_create_arch(as_t *, unsigned int);
    241285#endif /* !def as_create_arch */
     286
    242287#ifndef as_install_arch
    243 extern void as_install_arch(as_t *as);
     288extern void as_install_arch(as_t *);
    244289#endif /* !def as_install_arch */
     290
    245291#ifndef as_deinstall_arch
    246 extern void as_deinstall_arch(as_t *as);
     292extern void as_deinstall_arch(as_t *);
    247293#endif /* !def as_deinstall_arch */
    248294
     
    252298extern mem_backend_t phys_backend;
    253299
    254 /** 
     300/**
    255301 * This flags is passed when running the loader, otherwise elf_load()
    256302 * 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
     308extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
    262309
    263310/* 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);
     311extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int);
     312extern sysarg_t sys_as_area_resize(uintptr_t, size_t, unsigned int);
     313extern sysarg_t sys_as_area_change_flags(uintptr_t, unsigned int);
     314extern sysarg_t sys_as_area_destroy(uintptr_t);
    268315
    269316/* Introspection functions. */
    270 extern void as_print(as_t *as);
     317extern void as_get_area_info(as_t *, as_area_info_t **, size_t *);
     318extern void as_print(as_t *);
    271319
    272320#endif /* KERNEL */
Note: See TracChangeset for help on using the changeset viewer.