sh: switch to generic kernel_thread()/kernel_execve()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
@@ -284,39 +284,6 @@ void show_regs(struct pt_regs *regs)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a kernel thread
|
||||
*/
|
||||
__noreturn void kernel_thread_helper(void *arg, int (*fn)(void *))
|
||||
{
|
||||
do_exit(fn(arg));
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the mechanism for creating a new kernel thread.
|
||||
*
|
||||
* NOTE! Only a kernel-only process(ie the swapper or direct descendants
|
||||
* who haven't done an "execve()") should use this: it will work within
|
||||
* a system call from a "real" process, but the process memory space will
|
||||
* not be freed until both the parent and the child have exited.
|
||||
*/
|
||||
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
|
||||
{
|
||||
struct pt_regs regs;
|
||||
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.regs[2] = (unsigned long)arg;
|
||||
regs.regs[3] = (unsigned long)fn;
|
||||
|
||||
regs.pc = (unsigned long)kernel_thread_helper;
|
||||
regs.sr = (1 << 30);
|
||||
|
||||
/* Ok, create the new process.. */
|
||||
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
|
||||
®s, 0, NULL, NULL);
|
||||
}
|
||||
EXPORT_SYMBOL(kernel_thread);
|
||||
|
||||
/*
|
||||
* Free current thread data structures etc..
|
||||
*/
|
||||
@@ -401,15 +368,17 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
|
||||
EXPORT_SYMBOL(dump_fpu);
|
||||
|
||||
asmlinkage void ret_from_fork(void);
|
||||
asmlinkage void ret_from_kernel_thread(void);
|
||||
|
||||
int copy_thread(unsigned long clone_flags, unsigned long usp,
|
||||
unsigned long unused,
|
||||
unsigned long arg,
|
||||
struct task_struct *p, struct pt_regs *regs)
|
||||
{
|
||||
struct pt_regs *childregs;
|
||||
|
||||
#ifdef CONFIG_SH_FPU
|
||||
if(last_task_used_math == current) {
|
||||
/* can't happen for a kernel thread */
|
||||
if (last_task_used_math == current) {
|
||||
enable_fpu();
|
||||
save_fpu(current);
|
||||
disable_fpu();
|
||||
@@ -419,7 +388,17 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
|
||||
#endif
|
||||
/* Copy from sh version */
|
||||
childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
|
||||
p->thread.sp = (unsigned long) childregs;
|
||||
|
||||
if (unlikely(p->flags & PF_KTHREAD)) {
|
||||
memset(childregs, 0, sizeof(struct pt_regs));
|
||||
childregs->regs[2] = (unsigned long)arg;
|
||||
childregs->regs[3] = (unsigned long)fn;
|
||||
childregs->sr = (1 << 30); /* not user_mode */
|
||||
childregs->sr |= SR_FD; /* Invalidate FPU flag */
|
||||
p->thread.pc = (unsigned long) ret_from_kernel_thread;
|
||||
return 0;
|
||||
}
|
||||
*childregs = *regs;
|
||||
|
||||
/*
|
||||
@@ -428,19 +407,12 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
|
||||
* 32-bit wide and context switch must take care
|
||||
* of NEFF sign extension.
|
||||
*/
|
||||
if (user_mode(regs)) {
|
||||
childregs->regs[15] = neff_sign_extend(usp);
|
||||
p->thread.uregs = childregs;
|
||||
} else {
|
||||
childregs->regs[15] =
|
||||
neff_sign_extend((unsigned long)task_stack_page(p) +
|
||||
THREAD_SIZE);
|
||||
}
|
||||
childregs->regs[15] = neff_sign_extend(usp);
|
||||
p->thread.uregs = childregs;
|
||||
|
||||
childregs->regs[9] = 0; /* Set return value for child */
|
||||
childregs->sr |= SR_FD; /* Invalidate FPU flag */
|
||||
|
||||
p->thread.sp = (unsigned long) childregs;
|
||||
p->thread.pc = (unsigned long) ret_from_fork;
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user