@@ -266,18 +266,22 @@ alpha_vfork(void)
266266int
267267copy_thread (unsigned long clone_flags , unsigned long usp ,
268268 unsigned long arg ,
269- struct task_struct * p , struct pt_regs * regs )
269+ struct task_struct * p , struct pt_regs * wontuse )
270270{
271271 extern void ret_from_fork (void );
272272 extern void ret_from_kernel_thread (void );
273273
274274 struct thread_info * childti = task_thread_info (p );
275275 struct pt_regs * childregs = task_pt_regs (p );
276+ struct pt_regs * regs = current_pt_regs ();
276277 struct switch_stack * childstack , * stack ;
277278 unsigned long settls ;
278279
279280 childstack = ((struct switch_stack * ) childregs ) - 1 ;
280- if (unlikely (!regs )) {
281+ childti -> pcb .ksp = (unsigned long ) childstack ;
282+ childti -> pcb .flags = 1 ; /* set FEN, clear everything else */
283+
284+ if (unlikely (p -> flags & PF_KTHREAD )) {
281285 /* kernel thread */
282286 memset (childstack , 0 ,
283287 sizeof (struct switch_stack ) + sizeof (struct pt_regs ));
@@ -286,35 +290,24 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
286290 childstack -> r10 = arg ;
287291 childregs -> hae = alpha_mv .hae_cache ,
288292 childti -> pcb .usp = 0 ;
289- childti -> pcb .ksp = (unsigned long ) childstack ;
290- childti -> pcb .flags = 1 ; /* set FEN, clear everything else */
291293 return 0 ;
292294 }
295+ /* Note: if CLONE_SETTLS is not set, then we must inherit the
296+ value from the parent, which will have been set by the block
297+ copy in dup_task_struct. This is non-intuitive, but is
298+ required for proper operation in the case of a threaded
299+ application calling fork. */
300+ if (clone_flags & CLONE_SETTLS )
301+ childti -> pcb .unique = regs -> r20 ;
302+ childti -> pcb .usp = usp ?: rdusp ();
293303 * childregs = * regs ;
294- settls = regs -> r20 ;
295304 childregs -> r0 = 0 ;
296305 childregs -> r19 = 0 ;
297306 childregs -> r20 = 1 ; /* OSF/1 has some strange fork() semantics. */
298307 regs -> r20 = 0 ;
299308 stack = ((struct switch_stack * ) regs ) - 1 ;
300309 * childstack = * stack ;
301310 childstack -> r26 = (unsigned long ) ret_from_fork ;
302- childti -> pcb .usp = usp ?: rdusp ();
303- childti -> pcb .ksp = (unsigned long ) childstack ;
304- childti -> pcb .flags = 1 ; /* set FEN, clear everything else */
305-
306- /* Set a new TLS for the child thread? Peek back into the
307- syscall arguments that we saved on syscall entry. Oops,
308- except we'd have clobbered it with the parent/child set
309- of r20. Read the saved copy. */
310- /* Note: if CLONE_SETTLS is not set, then we must inherit the
311- value from the parent, which will have been set by the block
312- copy in dup_task_struct. This is non-intuitive, but is
313- required for proper operation in the case of a threaded
314- application calling fork. */
315- if (clone_flags & CLONE_SETTLS )
316- childti -> pcb .unique = settls ;
317-
318311 return 0 ;
319312}
320313
0 commit comments