BarryServer : Git

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

// Related

Nucleus

Barry Object Lists + replacing Task Queues 4d3c382 (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>

extern ObjectList *readyQueue[];

/* Clone a task */
pid_t
clone(int flags)
{
	uintptr_t ints = irq_disable();

	Task *parent = current, *child = new(&taskType), *tmp;
	pid_t tid = 0;

	/* After this, anything on the stack is desynchronised */
	child->pageDir = clone_dir();

	/* Split tasks here */
	child->eip = (uintptr_t) &&end;
	asm volatile("mov %%esp, %0" : "=r" (child->esp));
	asm volatile("mov %%ebp, %0" : "=r" (child->ebp));
	add(readyQueue[child->priority], child);
	tid = child->tid;
	put(child);
end:
	irq_restore(ints);
	return tid;
}