Ignore:
File:
1 edited

Legend:

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

    rc15b374 r0321109  
    4343
    4444/** 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
     45#define AS_AREA_READ            1
     46#define AS_AREA_WRITE           2
     47#define AS_AREA_EXEC            4
     48#define AS_AREA_CACHEABLE       8
    4949
    5050/** Address space area info exported to userspace. */
     
    5252        /** Starting address */
    5353        uintptr_t start_addr;
    54        
     54
    5555        /** Area size */
    5656        size_t size;
    57        
     57
    5858        /** Area flags */
    59         unsigned int flags;
     59        int flags;
    6060} as_area_info_t;
    6161
     
    7575 * Defined to be true if user address space and kernel address space shadow each
    7676 * 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
     77 */
     78#define KERNEL_ADDRESS_SPACE_SHADOWED   KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
     79
     80#define KERNEL_ADDRESS_SPACE_START      KERNEL_ADDRESS_SPACE_START_ARCH
     81#define KERNEL_ADDRESS_SPACE_END        KERNEL_ADDRESS_SPACE_END_ARCH
     82#define USER_ADDRESS_SPACE_START        USER_ADDRESS_SPACE_START_ARCH
     83#define USER_ADDRESS_SPACE_END          USER_ADDRESS_SPACE_END_ARCH
     84
     85#define USTACK_ADDRESS                  USTACK_ADDRESS_ARCH
    8786
    8887/** Kernel address space. */
    89 #define FLAG_AS_KERNEL  (1 << 0)
     88#define FLAG_AS_KERNEL                  (1 << 0)       
    9089
    9190/* Address space area attributes. */
    92 #define AS_AREA_ATTR_NONE     0
    93 #define AS_AREA_ATTR_PARTIAL  1  /**< Not fully initialized area. */
     91#define AS_AREA_ATTR_NONE       0
     92#define AS_AREA_ATTR_PARTIAL    1       /**< Not fully initialized area. */
    9493
    9594/** The page fault was not resolved by as_page_fault(). */
    96 #define AS_PF_FAULT  0
    97 
     95#define AS_PF_FAULT             0
    9896/** The page fault was resolved by as_page_fault(). */
    99 #define AS_PF_OK  1
    100 
     97#define AS_PF_OK                1
    10198/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
    102 #define AS_PF_DEFER  2
     99#define AS_PF_DEFER             2
    103100
    104101/** Address space structure.
     
    108105 * supposed to figure in the list as they are shared by all tasks and
    109106 * set up during system initialization.
    110  *
    111107 */
    112108typedef struct as {
    113109        /** Protected by asidlock. */
    114110        link_t inactive_as_with_asid_link;
    115        
    116111        /**
    117112         * Number of processors on wich is this address space active.
     
    119114         */
    120115        size_t cpu_refcount;
    121        
    122116        /**
    123117         * Address space identifier.
     
    126120         */
    127121        asid_t asid;
    128        
     122
    129123        /** Number of references (i.e tasks that reference this as). */
    130124        atomic_t refcount;
    131        
     125
    132126        mutex_t lock;
    133        
     127
    134128        /** B+tree of address space areas. */
    135129        btree_t as_area_btree;
     
    137131        /** Non-generic content. */
    138132        as_genarch_t genarch;
    139        
     133
    140134        /** Architecture specific content. */
    141135        as_arch_t arch;
     
    143137
    144138typedef struct {
    145         pte_t *(* page_table_create)(unsigned int);
    146         void (* page_table_destroy)(pte_t *);
    147         void (* page_table_lock)(as_t *, bool);
    148         void (* page_table_unlock)(as_t *, bool);
    149         bool (* page_table_locked)(as_t *);
     139        pte_t *(* page_table_create)(int flags);
     140        void (* page_table_destroy)(pte_t *page_table);
     141        void (* page_table_lock)(as_t *as, bool lock);
     142        void (* page_table_unlock)(as_t *as, bool unlock);
    150143} as_operations_t;
    151144
     
    153146 * This structure contains information associated with the shared address space
    154147 * area.
    155  *
    156148 */
    157149typedef struct {
    158150        /** This lock must be acquired only when the as_area lock is held. */
    159         mutex_t lock;
     151        mutex_t lock;           
    160152        /** This structure can be deallocated if refcount drops to 0. */
    161153        size_t refcount;
    162        
    163154        /**
    164155         * B+tree containing complete map of anonymous pages of the shared area.
     
    171162        PF_ACCESS_READ,
    172163        PF_ACCESS_WRITE,
    173         PF_ACCESS_EXEC,
    174         PF_ACCESS_UNKNOWN
     164        PF_ACCESS_EXEC
    175165} pf_access_t;
    176166
     
    179169/** Backend data stored in address space area. */
    180170typedef union mem_backend_data {
    181         /** elf_backend members */
    182         struct {
     171        struct {        /**< elf_backend members */
    183172                elf_header_t *elf;
    184173                elf_segment_header_t *segment;
    185174        };
    186        
    187         /** phys_backend members */
    188         struct {
     175        struct {        /**< phys_backend members */
    189176                uintptr_t base;
    190177                size_t frames;
     
    195182 *
    196183 * Each as_area_t structure describes one contiguous area of virtual memory.
    197  *
    198184 */
    199185typedef struct {
    200186        mutex_t lock;
    201187        /** Containing address space. */
    202         as_t *as;
    203        
     188        as_t *as;               
    204189        /**
    205190         * Flags related to the memory represented by the address space area.
    206191         */
    207         unsigned int flags;
    208        
     192        int flags;
    209193        /** Attributes related to the address space area itself. */
    210         unsigned int attributes;
     194        int attributes;
    211195        /** Size of this area in multiples of PAGE_SIZE. */
    212196        size_t pages;
     
    215199        /** Map of used space. */
    216200        btree_t used_space;
    217        
     201
    218202        /**
    219203         * If the address space area has been shared, this pointer will
     
    221205         */
    222206        share_info_t *sh_info;
    223        
     207
    224208        /** Memory backend backing this address space area. */
    225209        struct mem_backend *backend;
    226        
     210
    227211        /** Data to be used by the backend. */
    228212        mem_backend_data_t backend_data;
     
    231215/** Address space area backend structure. */
    232216typedef struct mem_backend {
    233         int (* page_fault)(as_area_t *, uintptr_t, pf_access_t);
    234         void (* frame_free)(as_area_t *, uintptr_t, uintptr_t);
    235         void (* share)(as_area_t *);
     217        int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access);
     218        void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame);
     219        void (* share)(as_area_t *area);
    236220} mem_backend_t;
    237221
     
    243227extern void as_init(void);
    244228
    245 extern as_t *as_create(unsigned int);
     229extern as_t *as_create(int);
    246230extern void as_destroy(as_t *);
    247231extern void as_hold(as_t *);
     
    250234extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
    251235
    252 extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t,
    253     unsigned int, mem_backend_t *, mem_backend_data_t *);
     236extern as_area_t *as_area_create(as_t *, int, size_t, uintptr_t, int,
     237    mem_backend_t *, mem_backend_data_t *);
    254238extern int as_area_destroy(as_t *, uintptr_t);
    255 extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int);
    256 extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t,
    257     unsigned int);
    258 extern int as_area_change_flags(as_t *, unsigned int, uintptr_t);
    259 
    260 extern unsigned int as_area_get_flags(as_area_t *);
     239extern int as_area_resize(as_t *, uintptr_t, size_t, int);
     240extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t, int);
     241extern int as_area_change_flags(as_t *, int, uintptr_t);
     242
     243extern int as_area_get_flags(as_area_t *);
    261244extern bool as_area_check_access(as_area_t *, pf_access_t);
    262245extern size_t as_area_get_size(uintptr_t);
     
    266249
    267250/* Interface to be implemented by architectures. */
    268 
    269251#ifndef as_constructor_arch
    270 extern int as_constructor_arch(as_t *, unsigned int);
     252extern int as_constructor_arch(as_t *, int);
    271253#endif /* !def as_constructor_arch */
    272 
    273254#ifndef as_destructor_arch
    274255extern int as_destructor_arch(as_t *);
    275256#endif /* !def as_destructor_arch */
    276 
    277257#ifndef as_create_arch
    278 extern int as_create_arch(as_t *, unsigned int);
     258extern int as_create_arch(as_t *, int);
    279259#endif /* !def as_create_arch */
    280 
    281260#ifndef as_install_arch
    282261extern void as_install_arch(as_t *);
    283262#endif /* !def as_install_arch */
    284 
    285263#ifndef as_deinstall_arch
    286264extern void as_deinstall_arch(as_t *);
     
    292270extern mem_backend_t phys_backend;
    293271
    294 /**
     272/** 
    295273 * This flags is passed when running the loader, otherwise elf_load()
    296274 * would return with a EE_LOADER error code.
    297  *
    298  */
    299 #define ELD_F_NONE    0
    300 #define ELD_F_LOADER  1
    301 
    302 extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
     275 */
     276#define ELD_F_NONE      0
     277#define ELD_F_LOADER    1
     278
     279extern unsigned int elf_load(elf_header_t *, as_t *, int);
    303280
    304281/* Address space area related syscalls. */
    305 extern unative_t sys_as_area_create(uintptr_t, size_t, unsigned int);
    306 extern unative_t sys_as_area_resize(uintptr_t, size_t, unsigned int);
    307 extern unative_t sys_as_area_change_flags(uintptr_t, unsigned int);
     282extern unative_t sys_as_area_create(uintptr_t, size_t, int);
     283extern unative_t sys_as_area_resize(uintptr_t, size_t, int);
     284extern unative_t sys_as_area_change_flags(uintptr_t, int);
    308285extern unative_t sys_as_area_destroy(uintptr_t);
    309286
Note: See TracChangeset for help on using the changeset viewer.