From 9d900a9956b77812db5159ce834a8ea7cc89b279 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Wed, 14 Oct 2009 15:21:33 +0300 Subject: [PATCH] Cleanup to execve functions --- conts/posix/mm0/mm/clone.c | 51 ++++++++++++------------- conts/posix/mm0/mm/execve.c | 75 ++++++++++++++++++++----------------- 2 files changed, 65 insertions(+), 61 deletions(-) diff --git a/conts/posix/mm0/mm/clone.c b/conts/posix/mm0/mm/clone.c index afeead6..61b001f 100644 --- a/conts/posix/mm0/mm/clone.c +++ b/conts/posix/mm0/mm/clone.c @@ -35,7 +35,8 @@ int sys_fork(struct tcb *parent) * Create a new L4 thread with parent's page tables * kernel stack and kernel-side tcb copied */ - if (IS_ERR(child = task_create(parent, &ids, THREAD_COPY_SPACE, + if (IS_ERR(child = task_create(parent, &ids, + THREAD_COPY_SPACE, TCB_NO_SHARING))) return (int)child; @@ -45,19 +46,14 @@ int sys_fork(struct tcb *parent) /* Set child's new utcb address set by task_create() */ BUG_ON(!child->utcb_address); - exregs_set_utcb(&exregs, child->utcb_address); + exregs_set_utcb(&exregs, + child->utcb_address); /* Do the actual exregs call to c0 */ - if ((err = l4_exchange_registers(&exregs, child->tid)) < 0) + if ((err = l4_exchange_registers(&exregs, + child->tid)) < 0) BUG(); - /* Create and prefault a shared page for child and map it to vfs task */ - //shpage_map_to_task(child, find_task(VFS_TID), - // SHPAGE_NEW_ADDRESS | SHPAGE_NEW_SHM | - // SHPAGE_PREFAULT); - - // printf("Mapped 0x%p to vfs as utcb of %d\n", child->utcb, child->tid); - /* Add child to global task list */ global_add_task(child); @@ -68,24 +64,27 @@ int sys_fork(struct tcb *parent) return child->tid; } -int do_clone(struct tcb *parent, unsigned long child_stack, unsigned int flags) +int do_clone(struct tcb *parent, + unsigned long child_stack, + unsigned int flags) { struct exregs_data exregs; struct task_ids ids; struct tcb *child; int err; - //ids.tid = TASK_ID_INVALID; - //ids.spid = parent->spid; - - - /* Determine whether the cloned thread is in parent's thread group */ + /* + * Determine whether the cloned + * thread is in parent's thread group + */ if (flags & TCB_SHARED_TGROUP) ids.tgid = parent->tgid; else ids.tgid = TASK_ID_INVALID; - if (IS_ERR(child = task_create(parent, &ids, THREAD_SAME_SPACE, flags))) + if (IS_ERR(child = task_create(parent, &ids, + THREAD_SAME_SPACE, + flags))) return (int)child; /* Set up child stack marks with given stack argument */ @@ -103,20 +102,14 @@ int do_clone(struct tcb *parent, unsigned long child_stack, unsigned int flags) exregs_set_utcb(&exregs, child->utcb_address); /* Do the actual exregs call to c0 */ - if ((err = l4_exchange_registers(&exregs, child->tid)) < 0) + if ((err = l4_exchange_registers(&exregs, + child->tid)) < 0) BUG(); - /* Create and prefault a shared page for child and map it to vfs task */ - //shpage_map_to_task(child, find_task(VFS_TID), - // SHPAGE_NEW_ADDRESS | SHPAGE_NEW_SHM | - // SHPAGE_PREFAULT); - /* We can now notify vfs about forked process */ - /* Add child to global task list */ global_add_task(child); /* Start cloned child. */ - // printf("%s/%s: Starting cloned child.\n", __TASKNAME__, __FUNCTION__); l4_thread_control(THREAD_RUN, &ids); /* Return child tid to parent */ @@ -124,7 +117,9 @@ int do_clone(struct tcb *parent, unsigned long child_stack, unsigned int flags) } -int sys_clone(struct tcb *parent, void *child_stack, unsigned int clone_flags) +int sys_clone(struct tcb *parent, + void *child_stack, + unsigned int clone_flags) { unsigned int flags = 0; @@ -142,6 +137,8 @@ int sys_clone(struct tcb *parent, void *child_stack, unsigned int clone_flags) if (clone_flags & CLONE_PARENT) flags |= TCB_SHARED_PARENT; - return do_clone(parent, (unsigned long)child_stack, flags); + return do_clone(parent, + (unsigned long)child_stack, + flags); } diff --git a/conts/posix/mm0/mm/execve.c b/conts/posix/mm0/mm/execve.c index 770823d..99642cb 100644 --- a/conts/posix/mm0/mm/execve.c +++ b/conts/posix/mm0/mm/execve.c @@ -27,7 +27,8 @@ * Probes and parses the low-level executable file format and creates a * generic execution description that can be used to run the task. */ -int task_setup_from_executable(struct vm_file *vmfile, struct tcb *task, +int task_setup_from_executable(struct vm_file *vmfile, + struct tcb *task, struct exec_file_desc *efd) { memset(efd, 0, sizeof(*efd)); @@ -82,8 +83,13 @@ int init_execve(char *filepath) return (int)new_task; } - /* Fill and validate tcb memory segment markers from executable file */ - if ((err = task_setup_from_executable(vmfile, new_task, &efd)) < 0) { + /* + * Fill and validate tcb memory + * segment markers from executable file + */ + if ((err = task_setup_from_executable(vmfile, + new_task, + &efd)) < 0) { sys_close(self, fd); kfree(new_task); return err; @@ -113,7 +119,28 @@ int init_execve(char *filepath) } -int do_execve(struct tcb *sender, char *filename, struct args_struct *args, +/* + * TODO: + * + * Dynamic Linking. + * See if an interpreter (dynamic linker) is needed + * Find the interpreter executable file, if needed + * Map all dynamic linker file segments + * (should not clash with original executable + * Set up registers to run dynamic linker (exchange_registers()) + * Run the interpreter + * + * The interpreter will: + * - Need some initial info (dyn sym tables) at a certain location + * - Find necessary shared library files in userspace + * (will use open/read). + * - Map them into process address space via mmap() + * - Reinitialise references to symbols in the shared libraries + * - Jump to the entry point of main executable. + */ + +int do_execve(struct tcb *sender, char *filename, + struct args_struct *args, struct args_struct *env) { struct vm_file *vmfile; @@ -135,8 +162,13 @@ int do_execve(struct tcb *sender, char *filename, struct args_struct *args, return (int)new_task; } - /* Fill and validate tcb memory segment markers from executable file */ - if ((err = task_setup_from_executable(vmfile, new_task, &efd)) < 0) { + /* + * Fill and validate tcb memory + * segment markers from executable file + */ + if ((err = task_setup_from_executable(vmfile, + new_task, + &efd)) < 0) { sys_close(self, fd); kfree(new_task); return err; @@ -154,7 +186,9 @@ int do_execve(struct tcb *sender, char *filename, struct args_struct *args, BUG_ON(!(tgleader = find_task(sender->tgid))); /* Destroy all children threads. */ - list_foreach_struct(thread, &tgleader->children, child_ref) + list_foreach_struct(thread, + &tgleader->children, + child_ref) do_exit(thread, 0); } else { /* Otherwise group leader is same as sender */ @@ -191,33 +225,6 @@ int do_execve(struct tcb *sender, char *filename, struct args_struct *args, /* Start the task */ task_start(new_task); -#if 0 -TODO: -Dynamic Linking. - - /* See if an interpreter (dynamic linker) is needed */ - - /* Find the interpreter executable file, if needed */ - - /* - * Map all dynamic linker file segments - * (should not clash with original executable - */ - - /* Set up registers to run dynamic linker (exchange_registers()) */ - - /* Run the interpreter */ - - /* - * The interpreter will: - * - Need some initial info (dyn sym tables) at a certain location - * - Find necessary shared library files in userspace - * (will use open/read). - * - Map them into process address space via mmap() - * - Reinitialise references to symbols in the shared libraries - * - Jump to the entry point of main executable. - */ -#endif return 0; }