···266266int267267copy_thread(unsigned long clone_flags, unsigned long usp,268268 unsigned long arg,269269- struct task_struct * p, struct pt_regs * regs)269269+ struct task_struct *p, struct pt_regs *wontuse)270270{271271 extern void ret_from_fork(void);272272 extern void ret_from_kernel_thread(void);273273274274 struct thread_info *childti = task_thread_info(p);275275 struct pt_regs *childregs = task_pt_regs(p);276276+ struct pt_regs *regs = current_pt_regs();276277 struct switch_stack *childstack, *stack;277278 unsigned long settls;278279279280 childstack = ((struct switch_stack *) childregs) - 1;280280- if (unlikely(!regs)) {281281+ childti->pcb.ksp = (unsigned long) childstack;282282+ childti->pcb.flags = 1; /* set FEN, clear everything else */283283+284284+ if (unlikely(p->flags & PF_KTHREAD)) {281285 /* kernel thread */282286 memset(childstack, 0,283287 sizeof(struct switch_stack) + sizeof(struct pt_regs));···290286 childstack->r10 = arg;291287 childregs->hae = alpha_mv.hae_cache,292288 childti->pcb.usp = 0;293293- childti->pcb.ksp = (unsigned long) childstack;294294- childti->pcb.flags = 1; /* set FEN, clear everything else */295289 return 0;296290 }291291+ /* Note: if CLONE_SETTLS is not set, then we must inherit the292292+ value from the parent, which will have been set by the block293293+ copy in dup_task_struct. This is non-intuitive, but is294294+ required for proper operation in the case of a threaded295295+ application calling fork. */296296+ if (clone_flags & CLONE_SETTLS)297297+ childti->pcb.unique = regs->r20;298298+ childti->pcb.usp = usp ?: rdusp();297299 *childregs = *regs;298298- settls = regs->r20;299300 childregs->r0 = 0;300301 childregs->r19 = 0;301302 childregs->r20 = 1; /* OSF/1 has some strange fork() semantics. */···308299 stack = ((struct switch_stack *) regs) - 1;309300 *childstack = *stack;310301 childstack->r26 = (unsigned long) ret_from_fork;311311- childti->pcb.usp = usp ?: rdusp();312312- childti->pcb.ksp = (unsigned long) childstack;313313- childti->pcb.flags = 1; /* set FEN, clear everything else */314314-315315- /* Set a new TLS for the child thread? Peek back into the316316- syscall arguments that we saved on syscall entry. Oops,317317- except we'd have clobbered it with the parent/child set318318- of r20. Read the saved copy. */319319- /* Note: if CLONE_SETTLS is not set, then we must inherit the320320- value from the parent, which will have been set by the block321321- copy in dup_task_struct. This is non-intuitive, but is322322- required for proper operation in the case of a threaded323323- application calling fork. */324324- if (clone_flags & CLONE_SETTLS)325325- childti->pcb.unique = settls;326326-327302 return 0;328303}329304