Skip to content

Commit

Permalink
cris: switch to generic fork/vfork/clone
Browse files Browse the repository at this point in the history
same braindamage as on s390 - the first two arguments of clone(2) in the
wrong order.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Nov 29, 2012
1 parent 584271b commit 27d892f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 60 deletions.
1 change: 1 addition & 0 deletions arch/cris/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ config CRIS
select MODULES_USE_ELF_RELA
select GENERIC_KERNEL_THREAD
select GENERIC_KERNEL_EXECVE
select CLONE_BACKWARDS2

config HZ
int
Expand Down
32 changes: 4 additions & 28 deletions arch/cris/arch-v10/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <arch/svinto.h>
#include <linux/init.h>
#include <arch/system.h>
#include <asm/ptrace.h>
#include <linux/ptrace.h>

#ifdef CONFIG_ETRAX_GPIO
void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
Expand Down Expand Up @@ -95,7 +95,7 @@ asmlinkage void ret_from_kernel_thread(void);

int copy_thread(unsigned long clone_flags, unsigned long usp,
unsigned long arg,
struct task_struct *p, struct pt_regs *regs)
struct task_struct *p, struct pt_regs *unused)
{
struct pt_regs *childregs = task_pt_regs(p);
struct switch_stack *swstack = ((struct switch_stack *)childregs) - 1;
Expand All @@ -115,7 +115,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
p->thread.usp = 0;
return 0;
}
*childregs = *regs; /* struct copy of pt_regs */
*childregs = *current_pt_regs(); /* struct copy of pt_regs */

childregs->r10 = 0; /* child returns 0 after a fork/clone */

Expand All @@ -129,7 +129,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,

/* fix the user-mode stackpointer */

p->thread.usp = usp;
p->thread.usp = usp ?: rdusp();

/* and the kernel-mode one */

Expand All @@ -143,30 +143,6 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
return 0;
}

asmlinkage int sys_fork(void)
{
return do_fork(SIGCHLD, rdusp(), current_pt_regs(), 0, NULL, NULL);
}

/* if newusp is 0, we just grab the old usp */
/* FIXME: Is parent_tid/child_tid really third/fourth argument? Update lib? */
asmlinkage int sys_clone(unsigned long newusp, unsigned long flags,
int* parent_tid, int* child_tid)
{
if (!newusp)
newusp = rdusp();
return do_fork(flags, newusp, current_pt_regs(), 0, parent_tid, child_tid);
}

/* vfork is a system call in i386 because of register-pressure - maybe
* we can remove it and handle it in libc but we put it here until then.
*/

asmlinkage int sys_vfork(void)
{
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), current_pt_regs(), 0, NULL, NULL);
}

unsigned long get_wchan(struct task_struct *p)
{
#if 0
Expand Down
37 changes: 5 additions & 32 deletions arch/cris/arch-v32/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <hwregs/reg_map.h>
#include <hwregs/timer_defs.h>
#include <hwregs/intr_vect_defs.h>
#include <asm/ptrace.h>
#include <linux/ptrace.h>

extern void stop_watchdog(void);

Expand Down Expand Up @@ -110,7 +110,7 @@ extern asmlinkage void ret_from_kernel_thread(void);
int
copy_thread(unsigned long clone_flags, unsigned long usp,
unsigned long arg,
struct task_struct *p, struct pt_regs *regs)
struct task_struct *p, struct pt_regs *unused)
{
struct pt_regs *childregs = task_pt_regs(p);
struct switch_stack *swstack = ((struct switch_stack *) childregs) - 1;
Expand All @@ -131,14 +131,14 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
p->thread.usp = 0;
return 0;
}
*childregs = *regs; /* Struct copy of pt_regs. */
*childregs = *current_pt_regs(); /* Struct copy of pt_regs. */
childregs->r10 = 0; /* Child returns 0 after a fork/clone. */

/* Set a new TLS ?
* The TLS is in $mof because it is the 5th argument to sys_clone.
*/
if (p->mm && (clone_flags & CLONE_SETTLS)) {
task_thread_info(p)->tls = regs->mof;
task_thread_info(p)->tls = childregs->mof;
}

/* Put the switch stack right below the pt_regs. */
Expand All @@ -153,39 +153,12 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
swstack->return_ip = (unsigned long) ret_from_fork;

/* Fix the user-mode and kernel-mode stackpointer. */
p->thread.usp = usp;
p->thread.usp = usp ?: rdusp();
p->thread.ksp = (unsigned long) swstack;

return 0;
}

asmlinkage int
sys_fork(void)
{
return do_fork(SIGCHLD, rdusp(), current_pt_regs(), 0, NULL, NULL);
}

/* FIXME: Is parent_tid/child_tid really third/fourth argument? Update lib? */
asmlinkage int
sys_clone(unsigned long newusp, unsigned long flags, int *parent_tid, int *child_tid,
unsigned long tls)
{
if (!newusp)
newusp = rdusp();

return do_fork(flags, newusp, current_pt_regs(), 0, parent_tid, child_tid);
}

/*
* vfork is a system call in i386 because of register-pressure - maybe
* we can remove it and handle it in libc but we put it here until then.
*/
asmlinkage int
sys_vfork(void)
{
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), current_pt_regs(), 0, NULL, NULL);
}

unsigned long
get_wchan(struct task_struct *p)
{
Expand Down
3 changes: 3 additions & 0 deletions arch/cris/include/asm/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@
#define __ARCH_WANT_SYS_RT_SIGACTION
#define __ARCH_WANT_SYS_RT_SIGSUSPEND
#define __ARCH_WANT_SYS_EXECVE
#define __ARCH_WANT_SYS_FORK
#define __ARCH_WANT_SYS_VFORK
#define __ARCH_WANT_SYS_CLONE

/*
* "Conditional" syscalls
Expand Down

0 comments on commit 27d892f

Please sign in to comment.