OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [kernel/] [signal.c] - Diff between revs 1622 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1622 Rev 1765
/*
/*
 *  linux/arch/arm/kernel/signal.c
 *  linux/arch/arm/kernel/signal.c
 *
 *
 *  Copyright (C) 1995, 1996 Russell King
 *  Copyright (C) 1995, 1996 Russell King
 */
 */
 
 
#include <linux/sched.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/mm.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/signal.h>
#include <linux/signal.h>
#include <linux/errno.h>
#include <linux/errno.h>
#include <linux/wait.h>
#include <linux/wait.h>
#include <linux/ptrace.h>
#include <linux/ptrace.h>
#include <linux/unistd.h>
#include <linux/unistd.h>
 
 
#include <asm/segment.h>
#include <asm/segment.h>
#include <asm/pgtable.h>
#include <asm/pgtable.h>
 
 
#define _S(nr) (1<<((nr)-1))
#define _S(nr) (1<<((nr)-1))
 
 
#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
 
 
#define SWI_SYS_SIGRETURN 0xef900077
#define SWI_SYS_SIGRETURN 0xef900077
 
 
asmlinkage int sys_waitpid(pid_t pid,unsigned long * stat_addr, int options);
asmlinkage int sys_waitpid(pid_t pid,unsigned long * stat_addr, int options);
asmlinkage int do_signal(unsigned long oldmask, struct pt_regs * regs);
asmlinkage int do_signal(unsigned long oldmask, struct pt_regs * regs);
extern int ptrace_cancel_bpt (struct task_struct *);
extern int ptrace_cancel_bpt (struct task_struct *);
extern int ptrace_set_bpt (struct task_struct *);
extern int ptrace_set_bpt (struct task_struct *);
 
 
/*
/*
 * atomically swap in the new signal mask, and wait for a signal.
 * atomically swap in the new signal mask, and wait for a signal.
 */
 */
asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, unsigned long set)
asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, unsigned long set)
{
{
    unsigned long mask;
    unsigned long mask;
    struct pt_regs * regs;
    struct pt_regs * regs;
    __asm__("mov\t%0,r9\n\t": "=r" (regs));
    __asm__("mov\t%0,r9\n\t": "=r" (regs));
 
 
    mask = current->blocked;
    mask = current->blocked;
    current->blocked = set & _BLOCKABLE;
    current->blocked = set & _BLOCKABLE;
    regs->ARM_r0 = -EINTR;
    regs->ARM_r0 = -EINTR;
 
 
    while (1) {
    while (1) {
        current->state = TASK_INTERRUPTIBLE;
        current->state = TASK_INTERRUPTIBLE;
        schedule();
        schedule();
        if (do_signal(mask,regs))
        if (do_signal(mask,regs))
            return regs->ARM_r0;
            return regs->ARM_r0;
    }
    }
}
}
 
 
/*
/*
 * This sets regs->esp even though we don't actually use sigstacks yet..
 * This sets regs->esp even though we don't actually use sigstacks yet..
 */
 */
asmlinkage int sys_sigreturn(unsigned long __unused)
asmlinkage int sys_sigreturn(unsigned long __unused)
{
{
    struct pt_regs *regs;
    struct pt_regs *regs;
    struct sigcontext_struct context;
    struct sigcontext_struct context;
    void *frame;
    void *frame;
 
 
    __asm__ ("mov\t%0, r9\n\t": "=r" (regs));
    __asm__ ("mov\t%0, r9\n\t": "=r" (regs));
 
 
    frame = (void *)regs->ARM_sp;
    frame = (void *)regs->ARM_sp;
 
 
    if (verify_area(VERIFY_READ,frame,sizeof(context))) {
    if (verify_area(VERIFY_READ,frame,sizeof(context))) {
        printk("*** Bad stack frame\n");
        printk("*** Bad stack frame\n");
        goto badframe;
        goto badframe;
    }
    }
 
 
    memcpy_fromfs(&context,frame,sizeof(context));
    memcpy_fromfs(&context,frame,sizeof(context));
 
 
    if (context.magic!=0x4B534154) {
    if (context.magic!=0x4B534154) {
        printk("Bad stack identifier\n");
        printk("Bad stack identifier\n");
        goto badframe;
        goto badframe;
    }
    }
 
 
    *regs = context.reg;
    *regs = context.reg;
 
 
    current->blocked = context.oldmask & _BLOCKABLE;
    current->blocked = context.oldmask & _BLOCKABLE;
 
 
    if (!valid_user_regs(regs))
    if (!valid_user_regs(regs))
        goto badframe;
        goto badframe;
 
 
    /* send SIGTRAP if we're single-stepping */
    /* send SIGTRAP if we're single-stepping */
    if (ptrace_cancel_bpt (current))
    if (ptrace_cancel_bpt (current))
        send_sig (SIGTRAP, current, 1);
        send_sig (SIGTRAP, current, 1);
 
 
    return regs->ARM_r0;
    return regs->ARM_r0;
badframe:
badframe:
    do_exit(SIGSEGV);
    do_exit(SIGSEGV);
    return 0;
    return 0;
}
}
 
 
/*
/*
 * Set up a signal frame...
 * Set up a signal frame...
 */
 */
static void setup_frame(struct sigaction * sa, unsigned long ** fp, unsigned long eip,
static void setup_frame(struct sigaction * sa, unsigned long ** fp, unsigned long eip,
        struct pt_regs * regs, int signr, unsigned long oldmask)
        struct pt_regs * regs, int signr, unsigned long oldmask)
{
{
    unsigned long * frame;
    unsigned long * frame;
    struct sigcontext_struct context;
    struct sigcontext_struct context;
 
 
    frame = (unsigned long *)(((int)(*fp)) - sizeof(context) - 4);
    frame = (unsigned long *)(((int)(*fp)) - sizeof(context) - 4);
 
 
    if (verify_area (VERIFY_WRITE, frame, sizeof(context)))
    if (verify_area (VERIFY_WRITE, frame, sizeof(context)))
        do_exit (SIGSEGV);
        do_exit (SIGSEGV);
 
 
    context.magic       = 0x4B534154; /* Signature */
    context.magic       = 0x4B534154; /* Signature */
    context.reg         = *regs;
    context.reg         = *regs;
    context.reg.ARM_sp  = (unsigned long)*fp;
    context.reg.ARM_sp  = (unsigned long)*fp;
    context.reg.ARM_pc  = eip;
    context.reg.ARM_pc  = eip;
 
 
    context.trap_no     = current->tss.trap_no;
    context.trap_no     = current->tss.trap_no;
    context.error_code  = current->tss.error_code;
    context.error_code  = current->tss.error_code;
    context.oldmask     = oldmask;
    context.oldmask     = oldmask;
 
 
    memcpy_tofs (frame, &context, sizeof(context));
    memcpy_tofs (frame, &context, sizeof(context));
    put_user (SWI_SYS_SIGRETURN, frame + sizeof (context)/4);
    put_user (SWI_SYS_SIGRETURN, frame + sizeof (context)/4);
    /*
    /*
     * Ensure that the SWI instruction is flushed out of D-cache
     * Ensure that the SWI instruction is flushed out of D-cache
     */
     */
    __flush_entry_to_ram(frame + sizeof (context)/4);
    __flush_entry_to_ram(frame + sizeof (context)/4);
 
 
    *fp = frame;
    *fp = frame;
    if (current->exec_domain && current->exec_domain->signal_invmap)
    if (current->exec_domain && current->exec_domain->signal_invmap)
        regs->ARM_r0 = current->exec_domain->signal_invmap[signr];
        regs->ARM_r0 = current->exec_domain->signal_invmap[signr];
    else
    else
        regs->ARM_r0 = signr;
        regs->ARM_r0 = signr;
    regs->ARM_lr = ((unsigned long)frame) + sizeof (context);
    regs->ARM_lr = ((unsigned long)frame) + sizeof (context);
    if (!valid_user_regs(&context.reg))
    if (!valid_user_regs(&context.reg))
        goto badframe;
        goto badframe;
 
 
    return;
    return;
 
 
badframe:
badframe:
    do_exit(SIGSEGV);
    do_exit(SIGSEGV);
}
}
 
 
/*
/*
 * Note that 'init' is a special process: it doesn't get signals it doesn't
 * Note that 'init' is a special process: it doesn't get signals it doesn't
 * want to handle. Thus you cannot kill init even with a SIGKILL even by
 * want to handle. Thus you cannot kill init even with a SIGKILL even by
 * mistake.
 * mistake.
 *
 *
 * Note that we go through the signals twice: once to check the signals that
 * Note that we go through the signals twice: once to check the signals that
 * the kernel can handle, and then we build all the user-level signal handling
 * the kernel can handle, and then we build all the user-level signal handling
 * stack-frames in one go after that.
 * stack-frames in one go after that.
 */
 */
asmlinkage int do_signal(unsigned long oldmask, struct pt_regs * regs)
asmlinkage int do_signal(unsigned long oldmask, struct pt_regs * regs)
{
{
        unsigned long orig_signal;
        unsigned long orig_signal;
        unsigned long mask = ~current->blocked;
        unsigned long mask = ~current->blocked;
        unsigned long handler_signal = 0;
        unsigned long handler_signal = 0;
        unsigned long *frame = NULL;
        unsigned long *frame = NULL;
        unsigned long eip = 0;
        unsigned long eip = 0;
        unsigned long signr;
        unsigned long signr;
        struct sigaction * sa;
        struct sigaction * sa;
        unsigned long *pcinstr = (unsigned long *)(instruction_pointer(regs)-4);
        unsigned long *pcinstr = (unsigned long *)(instruction_pointer(regs)-4);
        int swiinstr = 0, single_stepping;
        int swiinstr = 0, single_stepping;
 
 
        single_stepping = ptrace_cancel_bpt (current);
        single_stepping = ptrace_cancel_bpt (current);
 
 
        if (verify_area(VERIFY_READ, pcinstr, 4) == 0 &&
        if (verify_area(VERIFY_READ, pcinstr, 4) == 0 &&
            (get_user(pcinstr) & 0x0f000000) == 0x0f000000)
            (get_user(pcinstr) & 0x0f000000) == 0x0f000000)
                swiinstr = 1;
                swiinstr = 1;
 
 
        while ((signr = current->signal & mask)) {
        while ((signr = current->signal & mask)) {
                orig_signal = current->signal;
                orig_signal = current->signal;
                eip = signr;
                eip = signr;
                for (signr = 0; signr < 32; signr++)
                for (signr = 0; signr < 32; signr++)
 
 
                if (eip & (1 << signr)) {
                if (eip & (1 << signr)) {
                        current->signal &= ~(1 << signr);
                        current->signal &= ~(1 << signr);
                        break;
                        break;
                }
                }
                sa = current->sig->action + signr;
                sa = current->sig->action + signr;
                signr++;
                signr++;
 
 
                if ((current->flags & PF_PTRACED) && signr != SIGKILL) {
                if ((current->flags & PF_PTRACED) && signr != SIGKILL) {
                        current->exit_code = signr;
                        current->exit_code = signr;
                        current->state = TASK_STOPPED;
                        current->state = TASK_STOPPED;
                        notify_parent(current, SIGCHLD);
                        notify_parent(current, SIGCHLD);
                        schedule();
                        schedule();
                        single_stepping |= ptrace_cancel_bpt (current);
                        single_stepping |= ptrace_cancel_bpt (current);
 
 
                        if (!(signr = current->exit_code))
                        if (!(signr = current->exit_code))
                                continue;
                                continue;
 
 
                        current->exit_code = 0;
                        current->exit_code = 0;
 
 
                        if (signr == SIGSTOP)
                        if (signr == SIGSTOP)
                                continue;
                                continue;
 
 
                        if (_S(signr) & current->blocked) {
                        if (_S(signr) & current->blocked) {
                                current->signal |= _S(signr);
                                current->signal |= _S(signr);
                                continue;
                                continue;
                        }
                        }
                        sa = current->sig->action + signr - 1;
                        sa = current->sig->action + signr - 1;
                }
                }
                if (sa->sa_handler == SIG_IGN) {
                if (sa->sa_handler == SIG_IGN) {
                        if (signr != SIGCHLD)
                        if (signr != SIGCHLD)
                                continue;
                                continue;
                        /* check for SIGCHLD: it's special */
                        /* check for SIGCHLD: it's special */
                        while (sys_waitpid(-1,NULL,WNOHANG) > 0)
                        while (sys_waitpid(-1,NULL,WNOHANG) > 0)
                                /* nothing */;
                                /* nothing */;
                        continue;
                        continue;
                }
                }
                if (sa->sa_handler == SIG_DFL) {
                if (sa->sa_handler == SIG_DFL) {
                        if (current->pid == 1)
                        if (current->pid == 1)
                                continue;
                                continue;
 
 
                        switch (signr) {
                        switch (signr) {
                        case SIGCONT: case SIGCHLD: case SIGWINCH:
                        case SIGCONT: case SIGCHLD: case SIGWINCH:
                                continue;
                                continue;
 
 
                        case SIGTSTP: case SIGTTIN: case SIGTTOU:
                        case SIGTSTP: case SIGTTIN: case SIGTTOU:
                                if (is_orphaned_pgrp (current->pgrp))
                                if (is_orphaned_pgrp (current->pgrp))
                                        continue;
                                        continue;
 
 
                        case SIGSTOP:
                        case SIGSTOP:
                                if (current->flags & PF_PTRACED)
                                if (current->flags & PF_PTRACED)
                                        continue;
                                        continue;
 
 
                                current->state = TASK_STOPPED;
                                current->state = TASK_STOPPED;
                                current->exit_code = signr;
                                current->exit_code = signr;
                                if (!(current->p_pptr->sig->action[SIGCHLD-1].sa_flags &
                                if (!(current->p_pptr->sig->action[SIGCHLD-1].sa_flags &
                                    SA_NOCLDSTOP))
                                    SA_NOCLDSTOP))
                                        notify_parent(current, SIGCHLD);
                                        notify_parent(current, SIGCHLD);
                                schedule();
                                schedule();
                                single_stepping |= ptrace_cancel_bpt (current);
                                single_stepping |= ptrace_cancel_bpt (current);
                                continue;
                                continue;
 
 
                        case SIGBUS:  case SIGQUIT: case SIGILL:
                        case SIGBUS:  case SIGQUIT: case SIGILL:
                        case SIGTRAP: case SIGIOT:  case SIGFPE:
                        case SIGTRAP: case SIGIOT:  case SIGFPE:
                        case SIGSEGV:
                        case SIGSEGV:
                                if (current->binfmt && current->binfmt->core_dump) {
                                if (current->binfmt && current->binfmt->core_dump) {
                                        if (current->binfmt->core_dump(signr, regs))
                                        if (current->binfmt->core_dump(signr, regs))
                                                signr |= 0x80;
                                                signr |= 0x80;
                                }
                                }
                                /* fall through */
                                /* fall through */
                        default:
                        default:
                                current->signal |= _S(signr & 0x7f);
                                current->signal |= _S(signr & 0x7f);
                                do_exit(signr);
                                do_exit(signr);
                        }
                        }
                }
                }
                /*
                /*
                 * OK, we're invoking a handler
                 * OK, we're invoking a handler
                 */
                 */
                if (swiinstr && (regs->ARM_r0 == -ERESTARTNOHAND ||
                if (swiinstr && (regs->ARM_r0 == -ERESTARTNOHAND ||
                            (regs->ARM_r0 == -ERESTARTSYS && !(sa->sa_flags & SA_RESTART))))
                            (regs->ARM_r0 == -ERESTARTSYS && !(sa->sa_flags & SA_RESTART))))
                        regs->ARM_r0 = -EINTR;
                        regs->ARM_r0 = -EINTR;
                handler_signal |= 1 << (signr-1);
                handler_signal |= 1 << (signr-1);
                mask &= ~sa->sa_mask;
                mask &= ~sa->sa_mask;
        }
        }
 
 
        if (swiinstr &&
        if (swiinstr &&
            (regs->ARM_r0 == -ERESTARTNOHAND ||
            (regs->ARM_r0 == -ERESTARTNOHAND ||
             regs->ARM_r0 == -ERESTARTSYS ||
             regs->ARM_r0 == -ERESTARTSYS ||
             regs->ARM_r0 == -ERESTARTNOINTR)) {
             regs->ARM_r0 == -ERESTARTNOINTR)) {
                regs->ARM_r0 = regs->ARM_ORIG_r0;
                regs->ARM_r0 = regs->ARM_ORIG_r0;
                regs->ARM_pc -= 4;
                regs->ARM_pc -= 4;
        }
        }
 
 
        if (!handler_signal) {          /* no handler will be called - return 0 */
        if (!handler_signal) {          /* no handler will be called - return 0 */
                if (single_stepping)
                if (single_stepping)
                        ptrace_set_bpt (current);
                        ptrace_set_bpt (current);
                return 0;
                return 0;
        }
        }
 
 
        eip = regs->ARM_pc;
        eip = regs->ARM_pc;
        frame = (unsigned long *) regs->ARM_sp;
        frame = (unsigned long *) regs->ARM_sp;
        signr = 1;
        signr = 1;
        sa = current->sig->action;
        sa = current->sig->action;
        for (mask = 1 ; mask ; sa++,signr++,mask += mask) {
        for (mask = 1 ; mask ; sa++,signr++,mask += mask) {
                if (mask > handler_signal)
                if (mask > handler_signal)
                        break;
                        break;
                if (!(mask & handler_signal))
                if (!(mask & handler_signal))
                        continue;
                        continue;
                setup_frame(sa,&frame,eip,regs,signr,oldmask);
                setup_frame(sa,&frame,eip,regs,signr,oldmask);
                eip = (unsigned long) sa->sa_handler;
                eip = (unsigned long) sa->sa_handler;
                if (sa->sa_flags & SA_ONESHOT)
                if (sa->sa_flags & SA_ONESHOT)
                        sa->sa_handler = NULL;
                        sa->sa_handler = NULL;
/* force a supervisor-mode page-in of the signal handler to reduce races */
/* force a supervisor-mode page-in of the signal handler to reduce races */
                        current->blocked |= sa->sa_mask;
                        current->blocked |= sa->sa_mask;
                        oldmask |= sa->sa_mask;
                        oldmask |= sa->sa_mask;
        }
        }
        regs->ARM_sp = (unsigned long) frame;
        regs->ARM_sp = (unsigned long) frame;
        regs->ARM_pc = eip;             /* "return" to the first handler */
        regs->ARM_pc = eip;             /* "return" to the first handler */
        current->tss.trap_no = current->tss.error_code = 0;
        current->tss.trap_no = current->tss.error_code = 0;
        if (single_stepping)
        if (single_stepping)
                ptrace_set_bpt (current);
                ptrace_set_bpt (current);
        return 1;
        return 1;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.