当前位置: 首页 > 图灵资讯 > 技术篇> 进程创建时线程栈处理

进程创建时线程栈处理

来源:图灵教育
时间:2023-05-30 09:32:42

该函数与系统结构有关。

asmlinkage void ret_from_fork(void) asm("ret_from_fork");int copy_thread(unsigned long clone_flags, unsigned long stack_start,  unsigned long stk_sz, struct task_struct *p){ struct pt_regs *childregs = task_pt_regs(p); memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context)); if (likely(!(p->flags & PF_KTHREAD))) {  *childregs = *current_pt_regs();  childregs->regs[0] = 0;  /*   * Read the current TLS pointer from tpidr_el0 as it may be   * out-of-sync with the saved value.   */  *task_user_tls(p) = read_sysreg(tpidr_el0);  if (stack_start) {   if (is_compat_thread(task_thread_info(p)))    childregs->compat_sp = stack_start;   else    childregs->sp = stack_start;  }  /*   * If a TLS pointer was passed to clone (4th argument), use it   * for the new thread.   */  if (clone_flags & CLONE_SETTLS)   p->thread.tp_value = childregs->regs[3]; } else {  memset(childregs, 0, sizeof(struct pt_regs));  childregs->pstate = PSR_MODE_EL1h;  if (IS_ENABLED(CONFIG_ARM64_UAO) &&      cpus_have_cap(ARM64_HAS_UAO))   childregs->pstate |= PSR_UAO_BIT;  p->thread.cpu_context.x19 = stack_start;  p->thread.cpu_context.x20 = stk_sz; } p->thread.cpu_context.pc = (unsigned long)ret_from_fork; p->thread.cpu_context.sp = (unsigned long)childregs; ptrace_hw_copy_thread(p); return 0;}