BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / db9a0c170420002cff8cade7e3e598ac9d6fb25a / task / clone.c

// Related

Nucleus

Barry Multitasking support db9a0c1 (3 years, 3 months ago)
/*
 * This file contains the clone() function/system call.  It creates a new task,
 * and copies most of the attributes from the parent task into it.
 */

#include <sys/types.h>
#include <nucleus/task.h>

/* Read the EIP */
static uintptr_t
read_eip(void)
{
	uintptr_t eip;
	asm volatile("movl 4(%%ebp), %0" : "=r" (eip));
	return eip;
}

/* Clone a task */
pid_t
clone(int flags)
{
	Task *parent = current, *child = new(&taskType), *tmp;

	child->pageDir = clone_dir();

	parent->next = child;
	child->next = parent;

	/* Split tasks here */
	uintptr_t esp, ebp, eip;
	eip = read_eip();
	if (current == parent) {
		asm volatile("mov %%esp, %0" : "=r" (esp));
		asm volatile("mov %%ebp, %0" : "=r" (ebp));
		child->esp = esp;
		child->ebp = ebp;
		child->eip = eip;
		return child->tid;
	}
	return 0;
}