Added preliminary support for execve(). Updates to clone, fork, exit, task handling.

It turned out we used one version of kmalloc for malloc() and another for kfree()!
Now fixed.
Added parent-child relationship to tasks. Need to polish handling CLONE_PARENT and THREAD.
This commit is contained in:
Bahadir Balban
2008-11-19 12:59:52 +02:00
parent d182b5b35a
commit 46937eab88
39 changed files with 502 additions and 1192 deletions

28
tasks/mm0/include/boot.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef __BOOT_H__
#define __BOOT_H__
#include <vm_area.h>
#include <task.h>
/* Structures to use when sending new task information to vfs */
struct task_data {
unsigned long tid;
unsigned long utcb_address;
};
struct task_data_head {
unsigned long total;
struct task_data tdata[];
};
int boottask_setup_regions(struct vm_file *file, struct tcb *task,
unsigned long task_start, unsigned long task_end);
int boottask_mmap_regions(struct tcb *task, struct vm_file *file);
struct tcb *boottask_exec(struct vm_file *f, unsigned long task_region_start,
unsigned long task_region_end, struct task_ids *ids);
int vfs_send_task_data(struct tcb *vfs);
#endif /* __BOOT_H__ */

18
tasks/mm0/include/exec.h Normal file
View File

@@ -0,0 +1,18 @@
/*
* Definitions for executables
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __EXEC_H__
#define __EXEC_H__
/*
* This presents extra executable file information that is
* not present in the tcb, in a generic format.
*/
struct exec_file_desc {
unsigned long text_offset; /* File offset of text section */
unsigned long data_offset; /* File offset of data section */
};
#endif /* __EXEC_H__ */

15
tasks/mm0/include/exit.h Normal file
View File

@@ -0,0 +1,15 @@
/*
* Definitions for do_exit() flags
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __EXIT_H__
#define __EXIT_H__
#define EXIT_THREAD_DESTROY (1 << 0)
#define EXIT_UNMAP_ALL_SPACE (1 << 1)
void do_exit(struct tcb *task, unsigned int flags, int status);
#endif /* __EXIT_H__ */

View File

@@ -0,0 +1,35 @@
/*
* Definitions for ELF program headers
* Based on Portable Formats Specification v1.1
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __ELFPRG_H__
#define __ELFPRG_H__
#include <l4/types.h>
struct elf_program_header {
u32 p_type; /* Type of segment */
u32 p_offset; /* Segment file offset */
u32 p_vaddr; /* Virtual start address */
u32 p_paddr; /* Physical start address */
u32 p_filesz; /* Size in stored file */
u32 p_memsz; /* Size in memory image */
u32 p_flags; /* Segment attributes */
u32 p_align; /* Alignment requirement */
} __attribute__((__packed__));
/* Program segment type definitions */
#define PT_NULL 0
#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7FFFFFFF
#endif /* __ELFPRG_H__ */

View File

@@ -3,6 +3,7 @@
#include <stddef.h>
#include <string.h>
#include <stdio.h>
void *kmalloc(size_t size);
void kfree(void *blk);

View File

@@ -1,15 +0,0 @@
#ifndef __MM0_PROC__
#define __MM0_PROC__
#include <vm_area.h>
struct proc_vm_objects {
struct vm_object *stack; /* ZI, RO: devzero, RW: private */
struct vm_object *env; /* NON-ZI, RO: private, RW: private */
struct vm_object *data; /* NON-ZI, RO: shared, RW: private */
struct vm_object *bss; /* ZI, RO: devzero, RW: private */
};
int task_setup_vm_objects(struct tcb *t);
#endif

View File

@@ -14,6 +14,7 @@
#include <l4lib/utcb.h>
#include <lib/addr.h>
#include <l4/api/kip.h>
#include <exec.h>
#define __TASKNAME__ __PAGERNAME__
@@ -31,7 +32,8 @@
#define TCB_SHARED_VM (1 << 0)
#define TCB_SHARED_FILES (1 << 1)
#define TCB_SHARED_FS (1 << 2)
#define TCB_SAME_GROUP (1 << 3)
#define TCB_SHARED_TGROUP (1 << 3)
#define TCB_SHARED_PARENT (1 << 4)
struct vm_file;
@@ -57,6 +59,14 @@ struct tcb {
/* Task list */
struct list_head list;
/* Fields for parent-child relations */
struct list_head child_ref; /* Child ref in parent's list */
struct list_head children; /* List of children */
struct tcb *parent; /* Parent task */
/* Task creation flags */
unsigned int clone_flags;
/* Name of the task */
char name[16];
@@ -66,13 +76,14 @@ struct tcb {
int tgid;
/* Related task ids */
unsigned int pagerid; /* Task's pager */
unsigned int pagerid; /* Task's pager */
/* Task's main address space region, usually USER_AREA_START/END */
unsigned long start;
unsigned long end;
/* Page aligned program segment marks, ends exclusive as usual */
unsigned long entry;
unsigned long text_start;
unsigned long text_end;
unsigned long data_start;
@@ -102,17 +113,6 @@ struct tcb {
struct task_fd_head *files;
};
/* Structures to use when sending new task information to vfs */
struct task_data {
unsigned long tid;
unsigned long utcb_address;
};
struct task_data_head {
unsigned long total;
struct task_data tdata[];
};
struct tcb_head {
struct list_head list;
int total; /* Total threads */
@@ -121,20 +121,16 @@ struct tcb_head {
struct tcb *find_task(int tid);
void global_add_task(struct tcb *task);
void global_remove_task(struct tcb *task);
int send_task_data(struct tcb *requester);
void task_map_prefault_utcb(struct tcb *mapper, struct tcb *owner);
int task_mmap_regions(struct tcb *task, struct vm_file *file);
int task_setup_regions(struct vm_file *file, struct tcb *task,
unsigned long task_start, unsigned long task_end);
int task_mmap_segments(struct tcb *task, struct vm_file *file, struct exec_file_desc *efd);
int task_setup_registers(struct tcb *task, unsigned int pc,
unsigned int sp, l4id_t pager);
struct tcb *tcb_alloc_init(unsigned int flags);
int tcb_destroy(struct tcb *task);
struct tcb *task_exec(struct vm_file *f, unsigned long task_region_start,
unsigned long task_region_end, struct task_ids *ids);
int task_start(struct tcb *task, struct task_ids *ids);
int task_start(struct tcb *task);
int copy_tcb(struct tcb *to, struct tcb *from, unsigned int flags);
int task_release_vmas(struct task_vma_head *vma_head);
int task_prefault_regions(struct tcb *task, struct vm_file *f);
struct tcb *task_create(struct tcb *orig,
struct task_ids *ids,
unsigned int ctrl_flags,

View File

@@ -225,6 +225,7 @@ struct vm_object *vm_object_create(void);
struct vm_file *vm_file_create(void);
int vm_file_delete(struct vm_file *f);
int vm_object_delete(struct vm_object *vmo);
void vm_file_put(struct vm_file *f);
/* Printing objects, files */
void vm_object_print(struct vm_object *vmo);
@@ -235,6 +236,9 @@ void vm_print_files(struct list_head *file_list);
int prefault_page(struct tcb *task, unsigned long address,
unsigned int vmflags);
struct page *page_init(struct page *page);
struct page *find_page(struct vm_object *vmo, unsigned long page_offset);
void *pager_map_page(struct vm_file *f, unsigned long page_offset);
void pager_unmap_page(void *vaddr);
/* To get currently mapped page of a virtual address on a task */
struct page *task_virt_to_page(struct tcb *t, unsigned long virtual);