@@ -166,21 +166,18 @@ void show_regs(struct pt_regs *regs)
166166 */
167167int kernel_thread (int (* fn )(void * ), void * arg , unsigned long flags )
168168{
169- struct pt_regs regs ;
169+ struct pt_regs regs = {
170+ .a0 = (unsigned long ) fn ;
171+ .d0 = (unsigned long ) arg ;
172+ };
170173
171- memset (& regs , 0 , sizeof (regs ));
172-
173- regs .a2 = (unsigned long ) fn ;
174- regs .d2 = (unsigned long ) arg ;
175- regs .pc = (unsigned long ) kernel_thread_helper ;
176174 local_save_flags (regs .epsw );
177175 regs .epsw |= EPSW_IE | EPSW_IM_7 ;
178176
179177 /* Ok, create the new process.. */
180178 return do_fork (flags | CLONE_VM | CLONE_UNTRACED , 0 , & regs , 0 ,
181179 NULL , NULL );
182180}
183- EXPORT_SYMBOL (kernel_thread );
184181
185182/*
186183 * free current thread data structures etc..
@@ -227,49 +224,36 @@ int copy_thread(unsigned long clone_flags,
227224 struct task_struct * p , struct pt_regs * kregs )
228225{
229226 struct thread_info * ti = task_thread_info (p );
230- struct pt_regs * c_uregs , * c_kregs , * uregs ;
227+ struct pt_regs * c_regs ;
231228 unsigned long c_ksp ;
232229
233- uregs = current -> thread .uregs ;
234-
235230 c_ksp = (unsigned long ) task_stack_page (p ) + THREAD_SIZE ;
236231
237232 /* allocate the userspace exception frame and set it up */
238233 c_ksp -= sizeof (struct pt_regs );
239- c_uregs = (struct pt_regs * ) c_ksp ;
234+ c_regs = (struct pt_regs * ) c_ksp ;
240235
241- p -> thread .uregs = c_uregs ;
242- * c_uregs = * uregs ;
243- c_uregs -> sp = c_usp ;
244- c_uregs -> epsw &= ~EPSW_FE ; /* my FPU */
236+ p -> thread .uregs = c_regs ;
237+ * c_regs = * kregs ;
238+ c_regs -> sp = c_usp ;
239+ c_regs -> epsw &= ~EPSW_FE ; /* my FPU */
245240
246241 c_ksp -= 12 ; /* allocate function call ABI slack */
247242
248243 /* the new TLS pointer is passed in as arg #5 to sys_clone() */
249244 if (clone_flags & CLONE_SETTLS )
250- c_uregs -> e2 = current_frame ()-> d3 ;
251-
252- /* set up the return kernel frame if called from kernel_thread() */
253- c_kregs = c_uregs ;
254- if (kregs != uregs ) {
255- c_ksp -= sizeof (struct pt_regs );
256- c_kregs = (struct pt_regs * ) c_ksp ;
257- * c_kregs = * kregs ;
258- c_kregs -> sp = c_usp ;
259- c_kregs -> next = c_uregs ;
260- #ifdef CONFIG_MN10300_CURRENT_IN_E2
261- c_kregs -> e2 = (unsigned long ) p ; /* current */
262- #endif
245+ c_regs -> e2 = current_frame ()-> d3 ;
263246
264- c_ksp -= 12 ; /* allocate function call ABI slack */
265- }
247+ if (unlikely (!user_mode (kregs )))
248+ p -> thread .pc = (unsigned long ) ret_from_kernel_thread ;
249+ else
250+ p -> thread .pc = (unsigned long ) ret_from_fork ;
266251
267252 /* set up things up so the scheduler can start the new task */
268- ti -> frame = c_kregs ;
269- p -> thread .a3 = (unsigned long ) c_kregs ;
253+ ti -> frame = c_regs ;
254+ p -> thread .a3 = (unsigned long ) c_regs ;
270255 p -> thread .sp = c_ksp ;
271- p -> thread .pc = (unsigned long ) ret_from_fork ;
272- p -> thread .wchan = (unsigned long ) ret_from_fork ;
256+ p -> thread .wchan = p -> thread .pc ;
273257 p -> thread .usp = c_usp ;
274258
275259 return 0 ;
0 commit comments