mirror of
https://github.com/drasko/codezero.git
synced 2026-11-25 10:23:54 +01:00
Changes towards adding clone/fork
new file: src/clone.c
This commit is contained in:
Executable
+57
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user