Revised task initialisation, revising mmap yet.

This commit is contained in:
Bahadir Balban
2008-03-06 20:55:46 +00:00
parent 5681f3d1cb
commit 783904574d
12 changed files with 589 additions and 308 deletions

View File

@@ -19,6 +19,7 @@
struct initdata {
struct bootdesc *bootdesc;
struct page_bitmap page_map;
struct list_head boot_file_list;
};
extern struct initdata initdata;

View File

@@ -16,17 +16,11 @@ struct membank {
struct page *page_array;
};
extern struct membank membank[];
extern struct vm_file *swap_file;
void init_mm_descriptors(struct page_bitmap *page_map,
struct bootdesc *bootdesc, struct membank *membank);
void init_physmem(struct initdata *initdata, struct membank *membank);
void init_devzero(void);
struct vm_file *get_devzero(void);
void *get_zero_page(void);
void put_zero_page(void);
int do_mmap(struct vm_file *mapfile, unsigned long f_offset, struct tcb *t,
unsigned long map_address, unsigned int flags, unsigned int pages);

View File

@@ -16,7 +16,13 @@
#define __TASKNAME__ __PAGERNAME__
#define TASK_OFILES_MAX 32
#define TASK_FILES_MAX 32
/* POSIX minimum is 4Kb */
#define DEFAULT_ENV_SIZE SZ_16KB
#define DEFAULT_STACK_SIZE SZ_16KB
#define DEFAULT_UTCB_SIZE PAGE_SIZE
struct vm_file;
@@ -26,13 +32,6 @@ struct file_descriptor {
struct vm_file *vmfile;
};
struct proc_files {
struct vm_file *stackfile; /* ZI, private, devzero, then autogenerated */
struct vm_file *envfile; /* NON-ZI, private, autogenerated, then autogenerated */
struct vm_file *datafile; /* NON-ZI, private, real file, then autogenerated */
struct vm_file *bssfile; /* ZI private, devzero, then autogenerated */
};
/* Stores all task information that can be kept in userspace. */
struct tcb {
/* Task list */
@@ -67,22 +66,17 @@ struct tcb {
/* UTCB address */
unsigned long utcb_address;
/* Task's private files */
struct proc_files proc_files;
/* Virtual memory areas */
struct list_head vm_area_list;
/* File descriptors for this task */
struct file_descriptor fd[TASK_OFILES_MAX];
struct file_descriptor fd[TASK_FILES_MAX];
};
struct tcb *find_task(int tid);
struct initdata;
void init_pm(struct initdata *initdata);
int start_init_tasks(struct initdata *initdata);
void dump_tasks(void);
void send_task_data(l4id_t requester);

View File

@@ -22,15 +22,14 @@
#define VM_PROT_MASK (VM_READ | VM_WRITE | VM_EXEC)
/* Shared copy of a file */
#define VMA_SHARED (1 << 3)
#define VMA_SHARED (1 << 4)
/* VMA that's not file-backed, always maps devzero as VMA_COW */
#define VMA_ANONYMOUS (1 << 4)
#define VMA_ANONYMOUS (1 << 5)
/* Private copy of a file */
#define VMA_PRIVATE (1 << 5)
#define VMA_PRIVATE (1 << 6)
/* Copy-on-write semantics */
#define VMA_COW (1 << 6)
/* A vm object that is a shadow of another */
#define VMOBJ_SHADOW (1 << 7)
#define VMA_COW (1 << 7)
#define VMA_FIXED (1 << 8)
struct page {
int count; /* Refcount */
@@ -60,8 +59,8 @@ struct fault_data {
};
struct vm_pager_ops {
int (*page_in)(struct vm_object *vm_obj, unsigned long f_offset);
int (*page_out)(struct vm_object *vm_obj, unsigned long f_offset);
int (*page_in)(struct vm_object *vm_obj, unsigned long pfn_offset);
int (*page_out)(struct vm_object *vm_obj, unsigned long pfn_offset);
};
/* Describes the pager task that handles a vm_area. */
@@ -69,14 +68,27 @@ struct vm_pager {
struct vm_pager_ops ops; /* The ops the pager does on area */
};
/* Defines the type of file. A device file? Regular file? One used at boot? */
enum VM_FILE_TYPE {
VM_FILE_DEVZERO = 0,
VM_FILE_REGULAR,
VM_FILE_BOOTFILE,
};
/* Defines the type of object. A file? Just a standalone object? */
enum VM_OBJ_TYPE {
VM_OBJ_SHADOW = 1, /* Anonymous pages, swap_pager, no vm_file */
VM_OBJ_VNODE, /* VFS file pages, vnode_pager, has vm_file */
VM_OBJ_DEVICE /* Device pages, device_pager, has vm_file */
VM_OBJ_SHADOW = 1, /* Anonymous pages, swap_pager */
VM_OBJ_FILE, /* VFS file and device pages */
};
/* TODO:
* How to distinguish different devices handling page faults ???
* A possible answer:
*
* If they are not mmap'ed, this is handled by the vfs calling that file's
* specific operations (e.g. even calling the device process). If they're
* mmap'ed, they adhere to a standard mmap_device structure kept in
* vm_file->priv_data. This is used by the device pager to map those pages.
*/
/*
@@ -94,24 +106,29 @@ struct vm_object {
struct vm_object *orig_obj; /* Original object that this one shadows */
unsigned int type; /* Defines the type of the object */
struct list_head list; /* List of all vm objects in memory */
struct list_head page_cache; /* List of in-memory pages */
struct vm_pager *pager; /* The pager for this object */
struct vm_pager *pager; /* The pager for this object */
struct list_head page_cache; /* List of in-memory pages */
};
/* In memory representation of either a vfs file, a device. */
struct vm_file {
unsigned long vnum;
unsigned long length;
unsigned int type;
struct list_head list;
struct vm_object vm_obj;
void *priv_data; /* Device pagers use to access device info */
};
/* To create per-vma vm_object lists */
struct vma_obj_list {
struct vma_obj_link {
struct list_head list;
struct vm_object *obj;
}
#define vm_object_to_file(obj) \
(struct vm_file *)container_of(obj, struct vm_file, vm_obj)
/*
* Describes a virtually contiguous chunk of memory region in a task. It covers
* a unique virtual address area within its task, meaning that it does not
@@ -119,9 +136,9 @@ struct vma_obj_list {
* file or various other resources. This is managed by the region's pager.
*
* COW: Upon copy-on-write, each copy-on-write instance creates a shadow of the
* original vma which supersedes the original vma with its copied modified pages.
* This creates a stack of shadow vmas, where the top vma's copy of pages
* supersede the ones lower in the stack.
* original vm object which supersedes the original vm object with its copied
* modified pages. This creates a stack of shadow vm objects, where the top
* object's copy of pages supersede the ones lower in the stack.
*/
struct vm_area {
struct list_head list; /* Per-task vma list */
@@ -148,10 +165,17 @@ static inline struct vm_area *find_vma(unsigned long addr,
int insert_page_olist(struct page *this, struct vm_object *vm_obj);
/* Pagers */
extern struct vm_pager default_file_pager;
extern struct vm_pager boot_file_pager;
extern struct vm_pager swap_pager;
extern struct vm_pager file_pager;
extern struct vm_pager bootfile_pager;
extern struct vm_pager devzero_pager;
/* vm object and vm file lists */
extern struct list_head vm_object_list;
extern struct list_head vm_file_list;
/* vm file and object initialisation */
struct vm_file *vm_file_alloc_init(void);
struct vm_object *vm_object_alloc_init(void);
/* Main page fault entry point */
void page_fault_handler(l4id_t tid, fault_kdata_t *fkdata);