HelenOS sources
#ifndef KERN_AS_H_
#define KERN_AS_H_
#include <typedefs.h>
#include <abi/mm/as.h>
#include <arch/mm/page.h>
#include <arch/mm/as.h>
#include <arch/mm/asid.h>
#include <arch/istate.h>
#include <synch/spinlock.h>
#include <synch/mutex.h>
#include <adt/list.h>
#include <adt/odict.h>
#include <lib/elf.h>
#include <arch.h>
#include <lib/refcount.h>
#define AS CURRENT->as
#define KERNEL_ADDRESS_SPACE_SHADOWED KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
#define KERNEL_SEPARATE_PTL0 KERNEL_SEPARATE_PTL0_ARCH
#define KERNEL_ADDRESS_SPACE_START KERNEL_ADDRESS_SPACE_START_ARCH
#define KERNEL_ADDRESS_SPACE_END KERNEL_ADDRESS_SPACE_END_ARCH
#define USER_ADDRESS_SPACE_START USER_ADDRESS_SPACE_START_ARCH
#define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH
#define FLAG_AS_KERNEL (1 << 0)
#define AS_AREA_ATTR_NONE 0
#define AS_AREA_ATTR_PARTIAL 1
#define AS_PF_OK 0
#define AS_PF_DEFER 1
#define AS_PF_FAULT 2
#define AS_PF_SILENT 3
typedef struct as {
link_t inactive_as_with_asid_link;
size_t cpu_refcount;
asid_t asid;
atomic_refcount_t refcount;
mutex_t lock;
odict_t as_areas;
as_genarch_t genarch;
as_arch_t arch;
} as_t;
typedef struct {
pte_t *(*page_table_create)(unsigned int);
void (*page_table_destroy)(pte_t *);
void (*page_table_lock)(as_t *, bool);
void (*page_table_unlock)(as_t *, bool);
bool (*page_table_locked)(as_t *);
} as_operations_t;
typedef struct {
struct as_pagemap *pagemap;
odlink_t lpagemap;
uintptr_t vaddr;
uintptr_t frame;
} as_page_mapping_t;
typedef struct as_pagemap {
odict_t map;
} as_pagemap_t;
typedef struct {
struct used_space *used_space;
odlink_t lused_space;
uintptr_t page;
size_t count;
} used_space_ival_t;
typedef struct used_space {
odict_t ivals;
size_t pages;
} used_space_t;
typedef struct {
mutex_t lock;
size_t refcount;
bool shared;
as_pagemap_t pagemap;
struct mem_backend *backend;
void *backend_shared_data;
} share_info_t;
typedef enum {
PF_ACCESS_READ,
PF_ACCESS_WRITE,
PF_ACCESS_EXEC,
PF_ACCESS_UNKNOWN
} pf_access_t;
struct mem_backend;
typedef union mem_backend_data {
struct {
};
struct {
uintptr_t elf_base;
elf_header_t *elf;
elf_segment_header_t *segment;
};
struct {
uintptr_t base;
size_t frames;
bool anonymous;
struct parea *parea;
};
struct {
as_area_pager_info_t pager_info;
};
} mem_backend_data_t;
typedef struct {
mutex_t lock;
as_t *as;
odlink_t las_areas;
unsigned int flags;
unsigned int attributes;
size_t pages;
uintptr_t base;
used_space_t used_space;
share_info_t *sh_info;
struct mem_backend *backend;
mem_backend_data_t backend_data;
} as_area_t;
typedef struct mem_backend {
bool (*create)(as_area_t *);
bool (*resize)(as_area_t *, size_t);
void (*share)(as_area_t *);
void (*destroy)(as_area_t *);
bool (*is_resizable)(as_area_t *);
bool (*is_shareable)(as_area_t *);
int (*page_fault)(as_area_t *, uintptr_t, pf_access_t);
void (*frame_free)(as_area_t *, uintptr_t, uintptr_t);
bool (*create_shared_data)(as_area_t *);
void (*destroy_shared_data)(void *);
} mem_backend_t;
extern as_t *AS_KERNEL;
extern const as_operations_t *as_operations;
extern list_t inactive_as_with_asid_list;
extern void as_init(void);
extern as_t *as_create(unsigned int);
extern void as_hold(as_t *);
extern void as_release(as_t *);
extern void as_switch(as_t *, as_t *);
extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
extern as_area_t *as_area_create(as_t *, unsigned int, size_t, unsigned int,
mem_backend_t *, mem_backend_data_t *, uintptr_t *, uintptr_t);
extern errno_t as_area_destroy(as_t *, uintptr_t);
extern errno_t as_area_resize(as_t *, uintptr_t, size_t, unsigned int);
extern errno_t as_area_share(as_t *, uintptr_t, size_t, as_t *, unsigned int,
uintptr_t *, uintptr_t);
extern errno_t as_area_change_flags(as_t *, unsigned int, uintptr_t);
extern as_area_t *as_area_first(as_t *);
extern as_area_t *as_area_next(as_area_t *);
extern void as_pagemap_initialize(as_pagemap_t *);
extern void as_pagemap_finalize(as_pagemap_t *);
extern as_page_mapping_t *as_pagemap_first(as_pagemap_t *);
extern as_page_mapping_t *as_pagemap_next(as_page_mapping_t *);
extern errno_t as_pagemap_find(as_pagemap_t *, uintptr_t, uintptr_t *);
extern void as_pagemap_insert(as_pagemap_t *, uintptr_t, uintptr_t);
extern void as_pagemap_remove(as_page_mapping_t *);
extern unsigned int as_area_get_flags(as_area_t *);
extern bool as_area_check_access(as_area_t *, pf_access_t);
extern size_t as_area_get_size(uintptr_t);
extern used_space_ival_t *used_space_first(used_space_t *);
extern used_space_ival_t *used_space_next(used_space_ival_t *);
extern used_space_ival_t *used_space_find_gteq(used_space_t *, uintptr_t);
extern bool used_space_insert(used_space_t *, uintptr_t, size_t);
#ifndef as_constructor_arch
extern errno_t as_constructor_arch(as_t *, unsigned int);
#endif
#ifndef as_destructor_arch
extern int as_destructor_arch(as_t *);
#endif
#ifndef as_create_arch
extern errno_t as_create_arch(as_t *, unsigned int);
#endif
#ifndef as_install_arch
extern void as_install_arch(as_t *);
#endif
#ifndef as_deinstall_arch
extern void as_deinstall_arch(as_t *);
#endif
extern mem_backend_t anon_backend;
extern mem_backend_t elf_backend;
extern mem_backend_t phys_backend;
extern mem_backend_t user_backend;
extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int, uintptr_t,
uspace_ptr_as_area_pager_info_t);
extern sys_errno_t sys_as_area_resize(uintptr_t, size_t, unsigned int);
extern sys_errno_t sys_as_area_change_flags(uintptr_t, unsigned int);
extern sys_errno_t sys_as_area_get_info(uintptr_t, uspace_ptr_as_area_info_t);
extern sys_errno_t sys_as_area_destroy(uintptr_t);
extern as_area_info_t *as_get_area_info(as_t *, size_t *);
extern void as_print(as_t *);
#endif
HelenOS homepage, sources at GitHub