Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 340311
b: refs/heads/master
c: 7147e21
h: refs/heads/master
i:
  340309: d515b91
  340307: f60e450
  340303: 3bbd355
v: v3
  • Loading branch information
Al Viro committed Oct 23, 2012
1 parent c65a767 commit 8bfdb4b
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 199 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1ffbed7220331dabc04dee6d3c520b5b022b9245
refs/heads/master: 7147e215480323bb2617fcebf585c447188ff760
2 changes: 0 additions & 2 deletions trunk/arch/score/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ config SCORE
select GENERIC_CLOCKEVENTS
select HAVE_MOD_ARCH_SPECIFIC
select MODULES_USE_ELF_REL
select GENERIC_KERNEL_THREAD
select GENERIC_KERNEL_EXECVE

choice
prompt "System type"
Expand Down
1 change: 1 addition & 0 deletions trunk/arch/score/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct task_struct;
*/
extern void (*cpu_wait)(void);

extern long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
extern unsigned long thread_saved_pc(struct task_struct *tsk);
extern void start_thread(struct pt_regs *regs,
unsigned long pc, unsigned long sp);
Expand Down
1 change: 1 addition & 0 deletions trunk/arch/score/include/asm/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _ASM_SCORE_SYSCALLS_H

asmlinkage long score_clone(struct pt_regs *regs);
asmlinkage long score_execve(struct pt_regs *regs);
asmlinkage long score_sigaltstack(struct pt_regs *regs);
asmlinkage long score_rt_sigreturn(struct pt_regs *regs);

Expand Down
1 change: 0 additions & 1 deletion trunk/arch/score/include/asm/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
#define __ARCH_WANT_SYSCALL_NO_FLAGS
#define __ARCH_WANT_SYSCALL_OFF_T
#define __ARCH_WANT_SYSCALL_DEPRECATED
#define __ARCH_WANT_SYS_EXECVE

#include <asm-generic/unistd.h>
12 changes: 5 additions & 7 deletions trunk/arch/score/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ need_resched:
nop
#endif

ENTRY(ret_from_kernel_thread)
bl schedule_tail # r4=struct task_struct *prev
nop
mv r4, r13
brl r12
j syscall_exit

ENTRY(ret_from_fork)
bl schedule_tail # r4=struct task_struct *prev

Expand Down Expand Up @@ -487,6 +480,11 @@ illegal_syscall:
sw r9, [r0, PT_R7]
j syscall_return

ENTRY(sys_execve)
mv r4, r0
la r8, score_execve
br r8

ENTRY(sys_clone)
mv r4, r0
la r8, score_clone
Expand Down
55 changes: 41 additions & 14 deletions trunk/arch/score/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ void __noreturn cpu_idle(void)
}

void ret_from_fork(void);
void ret_from_kernel_thread(void);

void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
{
Expand All @@ -87,27 +86,29 @@ void flush_thread(void) {}
* set up the kernel stack and exception frames for a new process
*/
int copy_thread(unsigned long clone_flags, unsigned long usp,
unsigned long arg,
unsigned long unused,
struct task_struct *p, struct pt_regs *regs)
{
struct thread_info *ti = task_thread_info(p);
struct pt_regs *childregs = task_pt_regs(p);

p->thread.reg0 = (unsigned long) childregs;
if (unlikely(!regs)) {
memset(childregs, 0, sizeof(struct pt_regs));
p->thread->reg12 = usp;
p->thread->reg13 = arg;
p->thread.reg3 = (unsigned long) ret_from_kernel_thread;
p->set_child_tid = NULL;
p->clear_child_tid = NULL;

*childregs = *regs;
childregs->regs[7] = 0; /* Clear error flag */
childregs->regs[4] = 0; /* Child gets zero as return value */
regs->regs[4] = p->pid;

if (childregs->cp0_psr & 0x8) { /* test kernel fork or user fork */
childregs->regs[0] = usp; /* user fork */
} else {
*childregs = *regs;
childregs->regs[7] = 0; /* Clear error flag */
childregs->regs[4] = 0; /* Child gets zero as return value */
childregs->regs[0] = usp; /* user fork */
regs->regs[4] = p->pid; /* WTF? */
p->thread.reg3 = (unsigned long) ret_from_fork;
childregs->regs[28] = (unsigned long) ti; /* kernel fork */
childregs->regs[0] = (unsigned long) childregs;
}

p->thread.reg0 = (unsigned long) childregs;
p->thread.reg3 = (unsigned long) ret_from_fork;
p->thread.cp0_psr = 0;

return 0;
Expand All @@ -119,6 +120,32 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)
return 1;
}

static void __noreturn
kernel_thread_helper(void *unused0, int (*fn)(void *),
void *arg, void *unused1)
{
do_exit(fn(arg));
}

/*
* Create a kernel thread.
*/
long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
struct pt_regs regs;

memset(&regs, 0, sizeof(regs));

regs.regs[6] = (unsigned long) arg;
regs.regs[5] = (unsigned long) fn;
regs.cp0_epc = (unsigned long) kernel_thread_helper;
regs.cp0_psr = (regs.cp0_psr & ~(0x1|0x4|0x8)) | \
((regs.cp0_psr & 0x3) << 2);

return do_fork(flags | CLONE_VM | CLONE_UNTRACED, \
0, &regs, 0, NULL, NULL);
}

unsigned long thread_saved_pc(struct task_struct *tsk)
{
return task_pt_regs(tsk)->cp0_epc;
Expand Down
54 changes: 54 additions & 0 deletions trunk/arch/score/kernel/sys_score.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,57 @@ score_vfork(struct pt_regs *regs)
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
regs->regs[0], regs, 0, NULL, NULL);
}

/*
* sys_execve() executes a new program.
* This is called indirectly via a small wrapper
*/
asmlinkage long
score_execve(struct pt_regs *regs)
{
int error;
struct filename *filename;

filename = getname((char __user*)regs->regs[4]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;

error = do_execve(filename->name,
(const char __user *const __user *)regs->regs[5],
(const char __user *const __user *)regs->regs[6],
regs);

putname(filename);
return error;
}

/*
* Do a system call from kernel instead of calling sys_execve so we
* end up with proper pt_regs.
*/
asmlinkage
int kernel_execve(const char *filename,
const char *const argv[],
const char *const envp[])
{
register unsigned long __r4 asm("r4") = (unsigned long) filename;
register unsigned long __r5 asm("r5") = (unsigned long) argv;
register unsigned long __r6 asm("r6") = (unsigned long) envp;
register unsigned long __r7 asm("r7");

__asm__ __volatile__ (" \n"
"ldi r27, %5 \n"
"syscall \n"
"mv %0, r4 \n"
"mv %1, r7 \n"
: "=&r" (__r4), "=r" (__r7)
: "r" (__r4), "r" (__r5), "r" (__r6), "i" (__NR_execve)
: "r8", "r9", "r10", "r11", "r22", "r23", "r24", "r25",
"r26", "r27", "memory");

if (__r7 == 0)
return __r4;

return -__r4;
}
2 changes: 2 additions & 0 deletions trunk/arch/sh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ config SUPERH
select GENERIC_STRNLEN_USER
select HAVE_MOD_ARCH_SPECIFIC if DWARF_UNWINDER
select MODULES_USE_ELF_RELA
select GENERIC_KERNEL_THREAD
select GENERIC_KERNEL_EXECVE
help
The SuperH is a RISC processor targeted for use in embedded systems
and consumer electronics; it was also used in the Sega Dreamcast
Expand Down
5 changes: 0 additions & 5 deletions trunk/arch/sh/include/asm/processor_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_pc, unsigned lo
/* Free all resources held by a thread. */
extern void release_thread(struct task_struct *);

/*
* create a kernel thread without removing it from tasklists
*/
extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);

/* Copy and release all segment info associated with a VM */
#define copy_segments(p, mm) do { } while(0)
#define release_segments(mm) do { } while(0)
Expand Down
5 changes: 0 additions & 5 deletions trunk/arch/sh/include/asm/processor_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ struct mm_struct;

/* Free all resources held by a thread. */
extern void release_thread(struct task_struct *);
/*
* create a kernel thread without removing it from tasklists
*/
extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);


/* Copy and release all segment info associated with a VM */
#define copy_segments(p, mm) do { } while (0)
Expand Down
3 changes: 2 additions & 1 deletion trunk/arch/sh/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ obj-y := debugtraps.o dma-nommu.o dumpstack.o \
machvec.o nmi_debug.o process.o \
process_$(BITS).o ptrace.o ptrace_$(BITS).o \
reboot.o return_address.o \
setup.o signal_$(BITS).o sys_sh.o sys_sh$(BITS).o \
setup.o signal_$(BITS).o sys_sh.o \
syscalls_$(BITS).o time.o topology.o traps.o \
traps_$(BITS).o unwinder.o

Expand All @@ -25,6 +25,7 @@ obj-y += iomap.o
obj-$(CONFIG_HAS_IOPORT) += ioport.o
endif

obj-$(CONFIG_SUPERH32) += sys_sh32.o
obj-y += cpu/
obj-$(CONFIG_VSYSCALL) += vsyscall/
obj-$(CONFIG_SMP) += smp.o
Expand Down
19 changes: 19 additions & 0 deletions trunk/arch/sh/kernel/cpu/sh5/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,25 @@ ret_from_fork:
pta ret_from_syscall, tr0
blink tr0, ZERO

.global ret_from_kernel_thread
ret_from_kernel_thread:

movi schedule_tail,r5
ori r5, 1, r5
ptabs r5, tr0
blink tr0, LINK

ld.q SP, FRAME_R(2), r2
ld.q SP, FRAME_R(3), r3
ptabs r3, tr0
blink tr0, LINK

ld.q SP, FRAME_S(FSPC), r2
addi r2, 4, r2 /* Move PC, being pre-execution event */
st.q SP, FRAME_S(FSPC), r2
pta ret_from_syscall, tr0
blink tr0, ZERO

syscall_allowed:
/* Use LINK to deflect the exit point, default is syscall_ret */
pta syscall_ret, tr0
Expand Down
13 changes: 13 additions & 0 deletions trunk/arch/sh/kernel/entry-common.S
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@ ret_from_fork:
mov r0, r4
bra syscall_exit
nop

.align 2
.globl ret_from_kernel_thread
ret_from_kernel_thread:
mov.l 1f, r8
jsr @r8
mov r0, r4
mov.l @(OFF_R5,r15), r5 ! fn
jsr @r5
mov.l @(OFF_R4,r15), r4 ! arg
bra syscall_exit
nop

.align 2
1: .long schedule_tail

Expand Down
64 changes: 19 additions & 45 deletions trunk/arch/sh/kernel/process_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,6 @@ void show_regs(struct pt_regs * regs)
show_code(regs);
}

/*
* Create a kernel thread
*/
__noreturn void kernel_thread_helper(void *arg, int (*fn)(void *))
{
do_exit(fn(arg));
}

/* Don't use this in BL=1(cli). Or else, CPU resets! */
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
struct pt_regs regs;
int pid;

memset(&regs, 0, sizeof(regs));
regs.regs[4] = (unsigned long)arg;
regs.regs[5] = (unsigned long)fn;

regs.pc = (unsigned long)kernel_thread_helper;
regs.sr = SR_MD;
#if defined(CONFIG_SH_FPU)
regs.sr |= SR_FD;
#endif

/* Ok, create the new process.. */
pid = do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
&regs, 0, NULL, NULL);

return pid;
}
EXPORT_SYMBOL(kernel_thread);

void start_thread(struct pt_regs *regs, unsigned long new_pc,
unsigned long new_sp)
{
Expand Down Expand Up @@ -157,9 +125,10 @@ 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 thread_info *ti = task_thread_info(p);
Expand All @@ -177,29 +146,34 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
}
#endif

childregs = task_pt_regs(p);
*childregs = *regs;
memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));

if (user_mode(regs)) {
childregs->regs[15] = usp;
ti->addr_limit = USER_DS;
} else {
childregs->regs[15] = (unsigned long)childregs;
childregs = task_pt_regs(p);
p->thread.sp = (unsigned long) childregs;
if (unlikely(p->flags & PF_KTHREAD)) {
memset(childregs, 0, sizeof(struct pt_regs));
p->thread.pc = (unsigned long) ret_from_kernel_thread;
childregs->regs[4] = arg;
childregs->regs[5] = usp;
childregs->sr = SR_MD;
#if defined(CONFIG_SH_FPU)
childregs->sr |= SR_FD;
#endif
ti->addr_limit = KERNEL_DS;
ti->status &= ~TS_USEDFPU;
p->fpu_counter = 0;
return 0;
}
*childregs = *regs;

childregs->regs[15] = usp;
ti->addr_limit = USER_DS;

if (clone_flags & CLONE_SETTLS)
childregs->gbr = childregs->regs[0];

childregs->regs[0] = 0; /* Set return value for child */

p->thread.sp = (unsigned long) childregs;
p->thread.pc = (unsigned long) ret_from_fork;

memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));

return 0;
}

Expand Down
Loading

0 comments on commit 8bfdb4b

Please sign in to comment.