// linux/kernerl/fork.c:2866 /* * Ok, this is the main fork-routine. * * It copies the process, and if successful kick-starts * it and waits for it to finish using the VM if required. * * args->exit_signal is expected to be checked for sanity by the caller. */ pid_tkernel_clone(struct kernel_clone_args *args);
/*linux/arch/x86/entry/entry_64.S:225*/ SYM_CODE_START(ret_from_fork_asm) /* * This is the start of the kernel stack; even through there's a * register set at the top, the regset isn't necessarily coherent * (consider kthreads) and one cannot unwind further. * * This ensures stack unwinds of kernel threads terminate in a known * good state. */ UNWIND_HINT_END_OF_STACK ANNOTATE_NOENDBR // copy_thread CALL_DEPTH_ACCOUNT
/* * Set the stack state to what is expected for the target function * -- at this point the register set should be a valid user set * and unwind should work normally. */ UNWIND_HINT_REGS jmp swapgs_restore_regs_and_return_to_usermode SYM_CODE_END(ret_from_fork_asm)
/* Is this a kernel thread? */ if (unlikely(fn)) { fn(fn_arg); /* * A kernel thread is allowed to return here after successfully * calling kernel_execve(). Exit to userspace to complete the * execve() syscall. */ regs->ax = 0; }