/* * 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 #include extern TaskQueue *readyQueue[]; /* 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; pid_t tid = 0; /* After this, anything on the stack is desynchronised */ child->pageDir = clone_dir(); /* Split tasks here */ uintptr_t esp, ebp, eip; eip = (uintptr_t) &&end; asm volatile("mov %%esp, %0" : "=r" (esp)); asm volatile("mov %%ebp, %0" : "=r" (ebp)); child->esp = esp; child->ebp = ebp; child->eip = eip; add_to_queue(readyQueue[child->priority], child); tid = child->tid; put(child); end: return tid; }