/* * 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 /* 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; }