Changeset da1bafb in mainline for kernel/generic/include/mm/as.h


Ignore:
Timestamp:
2010-05-24T18:57:31Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

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

    r666f492 rda1bafb  
    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         int flags;
     59        unsigned 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 #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
     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
    8687
    8788/** Kernel address space. */
    88 #define FLAG_AS_KERNEL                  (1 << 0)       
     89#define FLAG_AS_KERNEL  (1 << 0)
    8990
    9091/* Address space area attributes. */
    91 #define AS_AREA_ATTR_NONE       0
    92 #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. */
    9394
    9495/** The page fault was not resolved by as_page_fault(). */
    95 #define AS_PF_FAULT             0
     96#define AS_PF_FAULT  0
     97
    9698/** The page fault was resolved by as_page_fault(). */
    97 #define AS_PF_OK                1
     99#define AS_PF_OK  1
     100
    98101/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
    99 #define AS_PF_DEFER             2
     102#define AS_PF_DEFER  2
    100103
    101104/** Address space structure.
     
    105108 * supposed to figure in the list as they are shared by all tasks and
    106109 * set up during system initialization.
     110 *
    107111 */
    108112typedef struct as {
    109113        /** Protected by asidlock. */
    110114        link_t inactive_as_with_asid_link;
     115       
    111116        /**
    112117         * Number of processors on wich is this address space active.
     
    114119         */
    115120        size_t cpu_refcount;
     121       
    116122        /**
    117123         * Address space identifier.
     
    120126         */
    121127        asid_t asid;
    122 
     128       
    123129        /** Number of references (i.e tasks that reference this as). */
    124130        atomic_t refcount;
    125 
     131       
    126132        mutex_t lock;
    127 
     133       
    128134        /** B+tree of address space areas. */
    129135        btree_t as_area_btree;
     
    131137        /** Non-generic content. */
    132138        as_genarch_t genarch;
    133 
     139       
    134140        /** Architecture specific content. */
    135141        as_arch_t arch;
     
    137143
    138144typedef struct {
    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);
     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);
    143149} as_operations_t;
    144150
     
    146152 * This structure contains information associated with the shared address space
    147153 * area.
     154 *
    148155 */
    149156typedef struct {
    150157        /** This lock must be acquired only when the as_area lock is held. */
    151         mutex_t lock;           
     158        mutex_t lock;
    152159        /** This structure can be deallocated if refcount drops to 0. */
    153160        size_t refcount;
     161       
    154162        /**
    155163         * B+tree containing complete map of anonymous pages of the shared area.
     
    169177/** Backend data stored in address space area. */
    170178typedef union mem_backend_data {
    171         struct {        /**< elf_backend members */
     179        /** elf_backend members */
     180        struct {
    172181                elf_header_t *elf;
    173182                elf_segment_header_t *segment;
    174183        };
    175         struct {        /**< phys_backend members */
     184       
     185        /** phys_backend members */
     186        struct {
    176187                uintptr_t base;
    177188                size_t frames;
     
    182193 *
    183194 * Each as_area_t structure describes one contiguous area of virtual memory.
     195 *
    184196 */
    185197typedef struct {
    186198        mutex_t lock;
    187199        /** Containing address space. */
    188         as_t *as;               
     200        as_t *as;
     201       
    189202        /**
    190203         * Flags related to the memory represented by the address space area.
    191204         */
    192         int flags;
     205        unsigned int flags;
     206       
    193207        /** Attributes related to the address space area itself. */
    194         int attributes;
     208        unsigned int attributes;
    195209        /** Size of this area in multiples of PAGE_SIZE. */
    196210        size_t pages;
     
    199213        /** Map of used space. */
    200214        btree_t used_space;
    201 
     215       
    202216        /**
    203217         * If the address space area has been shared, this pointer will
     
    205219         */
    206220        share_info_t *sh_info;
    207 
     221       
    208222        /** Memory backend backing this address space area. */
    209223        struct mem_backend *backend;
    210 
     224       
    211225        /** Data to be used by the backend. */
    212226        mem_backend_data_t backend_data;
     
    215229/** Address space area backend structure. */
    216230typedef struct mem_backend {
    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);
     231        int (* page_fault)(as_area_t *, uintptr_t, pf_access_t);
     232        void (* frame_free)(as_area_t *, uintptr_t, uintptr_t);
     233        void (* share)(as_area_t *);
    220234} mem_backend_t;
    221235
     
    227241extern void as_init(void);
    228242
    229 extern as_t *as_create(int);
     243extern as_t *as_create(unsigned int);
    230244extern void as_destroy(as_t *);
    231245extern void as_hold(as_t *);
     
    234248extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
    235249
    236 extern as_area_t *as_area_create(as_t *, int, size_t, uintptr_t, int,
    237     mem_backend_t *, mem_backend_data_t *);
     250extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t,
     251    unsigned int, mem_backend_t *, mem_backend_data_t *);
    238252extern int as_area_destroy(as_t *, uintptr_t);
    239 extern int as_area_resize(as_t *, uintptr_t, size_t, int);
    240 extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t, int);
    241 extern int as_area_change_flags(as_t *, int, uintptr_t);
    242 
    243 extern int as_area_get_flags(as_area_t *);
     253extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int);
     254extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t,
     255    unsigned int);
     256extern int as_area_change_flags(as_t *, unsigned int, uintptr_t);
     257
     258extern unsigned int as_area_get_flags(as_area_t *);
    244259extern bool as_area_check_access(as_area_t *, pf_access_t);
    245260extern size_t as_area_get_size(uintptr_t);
     
    249264
    250265/* Interface to be implemented by architectures. */
     266
    251267#ifndef as_constructor_arch
    252 extern int as_constructor_arch(as_t *, int);
     268extern int as_constructor_arch(as_t *, unsigned int);
    253269#endif /* !def as_constructor_arch */
     270
    254271#ifndef as_destructor_arch
    255272extern int as_destructor_arch(as_t *);
    256273#endif /* !def as_destructor_arch */
     274
    257275#ifndef as_create_arch
    258 extern int as_create_arch(as_t *, int);
     276extern int as_create_arch(as_t *, unsigned int);
    259277#endif /* !def as_create_arch */
     278
    260279#ifndef as_install_arch
    261280extern void as_install_arch(as_t *);
    262281#endif /* !def as_install_arch */
     282
    263283#ifndef as_deinstall_arch
    264284extern void as_deinstall_arch(as_t *);
     
    270290extern mem_backend_t phys_backend;
    271291
    272 /** 
     292/**
    273293 * This flags is passed when running the loader, otherwise elf_load()
    274294 * would return with a EE_LOADER error code.
    275  */
    276 #define ELD_F_NONE      0
    277 #define ELD_F_LOADER    1
    278 
    279 extern unsigned int elf_load(elf_header_t *, as_t *, int);
     295 *
     296 */
     297#define ELD_F_NONE    0
     298#define ELD_F_LOADER  1
     299
     300extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
    280301
    281302/* Address space area related syscalls. */
    282 extern unative_t sys_as_area_create(uintptr_t, size_t, int);
    283 extern unative_t sys_as_area_resize(uintptr_t, size_t, int);
    284 extern unative_t sys_as_area_change_flags(uintptr_t, int);
     303extern unative_t sys_as_area_create(uintptr_t, size_t, unsigned int);
     304extern unative_t sys_as_area_resize(uintptr_t, size_t, unsigned int);
     305extern unative_t sys_as_area_change_flags(uintptr_t, unsigned int);
    285306extern unative_t sys_as_area_destroy(uintptr_t);
    286307
Note: See TracChangeset for help on using the changeset viewer.