Towards adding sys_clone()

Stopped working on self_spawn() - going to finish clone() syscall first.
Arch-specific clone() library call that does ipc() and cloned child setup.
- Need to finish thread_create() that satisfy clone() necessities. i.e. setting up its stack.
  Question: Does the pager (and thus the microkernel) have to explicitly set SP_USR?
  Once the call is known to be successful, the library could set it.
This commit is contained in:
Bahadir Balban
2008-09-11 16:56:41 +03:00
parent fc51512438
commit af03975dc1
6 changed files with 230 additions and 35 deletions

View File

@@ -63,8 +63,11 @@ int do_fork(struct tcb *parent)
* Create a new L4 thread with parent's page tables
* kernel stack and kernel-side tcb copied
*/
child = task_create(parent, &ids, THREAD_CREATE_COPYSPC,
TCB_NO_SHARING);
if (IS_ERR(child = task_create(parent, &ids, THREAD_CREATE_COPYSPC,
TCB_NO_SHARING))) {
l4_ipc_return((int)child);
return 0;
}
/* Create new utcb for child since it can't use its parent's */
child->utcb = utcb_vaddr_new();
@@ -110,3 +113,66 @@ int sys_fork(l4id_t sender)
return do_fork(parent);
}
int sys_clone(l4id_t sender, void *child_stack, unsigned int flags)
{
struct task_ids ids;
struct vm_file *utcb_shm;
struct tcb *parent, *child;
unsigned long stack, stack_size;
BUG_ON(!(parent = find_task(sender)));
ids.tid = TASK_ID_INVALID;
ids.spid = parent->spid;
ids.tgid = parent->tgid;
if (IS_ERR(child = task_create(parent, &ids, THREAD_CREATE_SAMESPC,
TCB_SHARED_VM | TCB_SHARED_FILES))) {
l4_ipc_return((int)child);
return 0;
}
/* Allocate a unique utcb address for child */
child->utcb = utcb_vaddr_new();
/*
* Create the utcb shared memory segment
* available for child to shmat()
*/
if (IS_ERR(utcb_shm = shm_new((key_t)child->utcb,
__pfn(DEFAULT_UTCB_SIZE)))) {
l4_ipc_return((int)utcb_shm);
return 0;
}
/* Map and prefault child's utcb to vfs task */
task_map_prefault_utcb(find_task(VFS_TID), child);
/* Set up child stack marks with given stack argument */
child->stack_end = (unsigned long)child_stack;
child->stack_start = 0;
/* We can now notify vfs 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);
/* Return back to parent */
l4_ipc_return(child->tid);
return 0;
}