From 4ffdb45550e2a11da9edad782238368c62e92d17 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Wed, 27 Aug 2008 22:27:53 +0300 Subject: [PATCH] Fixed 2 more fork issues Added setting of spsr for the new task. Added newly created task into mm0's global task list. --- include/l4/api/syscall.h | 2 ++ src/api/syscall.c | 10 ++++++++++ src/api/thread.c | 14 +++++++++----- tasks/fs0/src/task.c | 1 + tasks/mm0/include/task.h | 1 + tasks/mm0/src/clone.c | 4 ++++ tasks/mm0/src/task.c | 9 +++++++-- 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/l4/api/syscall.h b/include/l4/api/syscall.h index 87a7c73..1167d68 100644 --- a/include/l4/api/syscall.h +++ b/include/l4/api/syscall.h @@ -26,6 +26,8 @@ #define syscalls_end_offset sys_time_offset #define SYSCALLS_TOTAL ((syscalls_end_offset >> 2) + 1) +void print_syscall_context(struct ktcb *t); + int sys_ipc(struct syscall_context *); int sys_thread_switch(struct syscall_context *); int sys_thread_control(struct syscall_context *); diff --git a/src/api/syscall.c b/src/api/syscall.c index d45678e..b25df95 100644 --- a/src/api/syscall.c +++ b/src/api/syscall.c @@ -17,6 +17,16 @@ #include INC_API(syscall.h) #include INC_ARCH(exception.h) +void print_syscall_context(struct ktcb *t) +{ + syscall_context_t *r = t->syscall_regs; + + printk("Thread id: %d registers: 0x%x, 0x%x, 0x%x, 0x%x, " + "0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", + t->tid, r->spsr, r->r0, r->r1, r->r2, r->r3, r->r4, + r->r5, r->r6, r->r7, r->r8, r->sp_usr, r->lr_usr); +} + int sys_exchange_registers(syscall_context_t *regs) { struct ktcb *task; diff --git a/src/api/thread.c b/src/api/thread.c index 921599f..70f0635 100644 --- a/src/api/thread.c +++ b/src/api/thread.c @@ -6,6 +6,7 @@ #include #include INC_API(syscall.h) #include +#include #include #include #include @@ -61,6 +62,7 @@ int thread_start(struct task_ids *ids) return -EINVAL; } + extern unsigned int return_from_syscall; /* @@ -107,12 +109,14 @@ int arch_setup_new_thread(struct ktcb *new, struct ktcb *orig) new->syscall_regs->r0 = 0; /* - * Set up the stack pointer and program counter so that next time - * the new thread schedules, it executes the end part of the system - * call exception where the previous context is restored. + * Set up the stack pointer, saved program status register and program + * counter so that next time the new thread schedules, it executes the + * end part of the system call exception where the previous context is + * restored. */ - new->context.sp = (unsigned long)new + syscall_context_offset; - new->context.pc = (unsigned long)return_from_syscall; + new->context.sp = (unsigned long)new->syscall_regs; + new->context.pc = (unsigned long)&return_from_syscall; + new->context.spsr = (unsigned long)orig->context.spsr; /* Copy other relevant fields from original ktcb */ new->pagerid = orig->pagerid; diff --git a/tasks/fs0/src/task.c b/tasks/fs0/src/task.c index 28bd0a0..453c354 100644 --- a/tasks/fs0/src/task.c +++ b/tasks/fs0/src/task.c @@ -121,6 +121,7 @@ int pager_notify_fork(l4id_t sender, l4id_t parid, memcpy(child->fd, parent->fd, TASK_FILES_MAX * sizeof(int)); l4_ipc_return(0); + printf("%s/%s: Exiting...\n", __TASKNAME__, __FUNCTION__); return 0; } diff --git a/tasks/mm0/include/task.h b/tasks/mm0/include/task.h index c3c866f..9431d85 100644 --- a/tasks/mm0/include/task.h +++ b/tasks/mm0/include/task.h @@ -94,6 +94,7 @@ struct task_data_head { }; struct tcb *find_task(int tid); +void task_add_global(struct tcb *t); struct initdata; void init_pm(struct initdata *initdata); diff --git a/tasks/mm0/src/clone.c b/tasks/mm0/src/clone.c index cd255ae..3a978d7 100755 --- a/tasks/mm0/src/clone.c +++ b/tasks/mm0/src/clone.c @@ -158,6 +158,10 @@ int do_fork(struct tcb *parent) /* Notify fs0 about forked process */ vfs_notify_fork(child, parent); + /* Add child to global task list */ + task_add_global(child); + + printf("%s/%s: Starting forked child.\n", __TASKNAME__, __FUNCTION__); /* Start forked child. */ l4_thread_control(THREAD_RUN, &ids); diff --git a/tasks/mm0/src/task.c b/tasks/mm0/src/task.c index 4ad3a73..95e9c35 100644 --- a/tasks/mm0/src/task.c +++ b/tasks/mm0/src/task.c @@ -43,6 +43,12 @@ void print_tasks(void) } } +void task_add_global(struct tcb *task) +{ + list_add_tail(&task->list, &tcb_head.list); + tcb_head.total++; +} + struct tcb *find_task(int tid) { struct tcb *t; @@ -276,8 +282,7 @@ int task_exec(struct vm_file *f, unsigned long task_region_start, return err; /* Add the task to the global task list */ - list_add_tail(&task->list, &tcb_head.list); - tcb_head.total++; + task_add_global(task); /* Add the file to global vm lists */ list_del_init(&f->list);