@@ -240,27 +240,35 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
240240 struct pt_regs * childregs = task_pt_regs (p );
241241 unsigned long tls = p -> thread .tp_value ;
242242
243- * childregs = * regs ;
244- childregs -> regs [0 ] = 0 ;
243+ memset (& p -> thread .cpu_context , 0 , sizeof (struct cpu_context ));
245244
246- if (is_compat_thread (task_thread_info (p )))
247- childregs -> compat_sp = stack_start ;
248- else {
245+ if (likely (regs )) {
246+ * childregs = * regs ;
247+ childregs -> regs [0 ] = 0 ;
248+ if (is_compat_thread (task_thread_info (p ))) {
249+ childregs -> compat_sp = stack_start ;
250+ } else {
251+ /*
252+ * Read the current TLS pointer from tpidr_el0 as it may be
253+ * out-of-sync with the saved value.
254+ */
255+ asm("mrs %0, tpidr_el0" : "=r" (tls ));
256+ childregs -> sp = stack_start ;
257+ }
249258 /*
250- * Read the current TLS pointer from tpidr_el0 as it may be
251- * out-of-sync with the saved value .
259+ * If a TLS pointer was passed to clone (4th argument), use it
260+ * for the new thread .
252261 */
253- asm("mrs %0, tpidr_el0" : "=r" (tls ));
254- childregs -> sp = stack_start ;
262+ if (clone_flags & CLONE_SETTLS )
263+ tls = regs -> regs [3 ];
264+ } else {
265+ memset (childregs , 0 , sizeof (struct pt_regs ));
266+ childregs -> pstate = PSR_MODE_EL1h ;
267+ p -> thread .cpu_context .x19 = stack_start ;
268+ p -> thread .cpu_context .x20 = stk_sz ;
255269 }
256-
257- memset (& p -> thread .cpu_context , 0 , sizeof (struct cpu_context ));
258- p -> thread .cpu_context .sp = (unsigned long )childregs ;
259270 p -> thread .cpu_context .pc = (unsigned long )ret_from_fork ;
260-
261- /* If a TLS pointer was passed to clone, use that for the new thread. */
262- if (clone_flags & CLONE_SETTLS )
263- tls = regs -> regs [3 ];
271+ p -> thread .cpu_context .sp = (unsigned long )childregs ;
264272 p -> thread .tp_value = tls ;
265273
266274 ptrace_hw_copy_thread (p );
@@ -327,43 +335,6 @@ int dump_fpu (struct pt_regs *regs, struct user_fp *fp)
327335}
328336EXPORT_SYMBOL (dump_fpu );
329337
330- /*
331- * Shuffle the argument into the correct register before calling the
332- * thread function. x1 is the thread argument, x2 is the pointer to
333- * the thread function, and x3 points to the exit function.
334- */
335- extern void kernel_thread_helper (void );
336- asm( ".section .text\n"
337- " .align\n"
338- " .type kernel_thread_helper, #function\n"
339- "kernel_thread_helper:\n"
340- " mov x0, x1\n"
341- " mov x30, x3\n"
342- " br x2\n"
343- " .size kernel_thread_helper, . - kernel_thread_helper\n"
344- " .previous" );
345-
346- #define kernel_thread_exit do_exit
347-
348- /*
349- * Create a kernel thread.
350- */
351- pid_t kernel_thread (int (* fn )(void * ), void * arg , unsigned long flags )
352- {
353- struct pt_regs regs ;
354-
355- memset (& regs , 0 , sizeof (regs ));
356-
357- regs .regs [1 ] = (unsigned long )arg ;
358- regs .regs [2 ] = (unsigned long )fn ;
359- regs .regs [3 ] = (unsigned long )kernel_thread_exit ;
360- regs .pc = (unsigned long )kernel_thread_helper ;
361- regs .pstate = PSR_MODE_EL1h ;
362-
363- return do_fork (flags |CLONE_VM |CLONE_UNTRACED , 0 , & regs , 0 , NULL , NULL );
364- }
365- EXPORT_SYMBOL (kernel_thread );
366-
367338unsigned long get_wchan (struct task_struct * p )
368339{
369340 struct stackframe frame ;
0 commit comments