进程创建时线程栈处理

这个函数是跟体系结构相关的。

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

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值