From d434ad4b40f63833d2fb29c2a8112a84dcee65c9 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Tue, 5 Aug 2008 16:56:55 +0300 Subject: [PATCH] Changes towards adding clone/fork new file: src/clone.c --- tasks/mm0/src/clone.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 tasks/mm0/src/clone.c diff --git a/tasks/mm0/src/clone.c b/tasks/mm0/src/clone.c new file mode 100755 index 0000000..7f1f8bf --- /dev/null +++ b/tasks/mm0/src/clone.c @@ -0,0 +1,57 @@ +/* + * Forking and cloning threads, processes + * + * Copyright (C) 2008 Bahadir Balban + */ + + +int copy_tcb(struct tcb *p, struct tcb *c) +{ + /* Copy program segments, file descriptors, vm areas */ +} + +/* + * Sets all r/w shadow objects as read-only for the process + * so that copy-on-write incidents cause read faults. + */ +int vm_freeze_shadows(struct tcb *t) +{ + /* Make all shadows read-only */ + + /* + * Make all writeable shadow entries + * in the page table as read-only + */ +} + +int do_fork(struct tcb *parent) +{ + struct tcb *child; + + /* Create a new L4 thread with new space */ + l4_thread_create(parent); + + /* Create a new local tcb */ + child = tcb_alloc_init(); + + /* Make all parent shadows read only */ + vm_freeze_shadows(parent); + + /* Copy parent tcb to child */ + copy_tcb(struct tcb *parent, struct tcb *child); + + /* FIXME: Copy parent page tables to child ??? */ + /* FIXME: Copy parent register values to child ??? */ + + /* Notify fs0 about forked process */ + vfs_send_fork(parent, child); + + /* Start forked child */ + l4_thread_start(child); + + /* Return back to parent */ + l4_ipc_return(0); + + return 0; +} +