⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signal.c

📁 microwindows移植到S3C44B0的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  linux/arch/m68k/kernel/signal.c * *  Copyright (C) 1991, 1992  Linus Torvalds * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file COPYING in the main directory of this archive * for more details. *//* * Linux/m68k support by Hamish Macdonald * * 68060 fixes by Jesper Skov * * 1997-12-01  Modified for POSIX.1b signals by Andreas Schwab * * mathemu support by Roman Zippel *  (Note: fpstate in the signal context is completly ignored for the emulator *         and the internal floating point format is put on stack) *//* * ++roman (07/09/96): implemented signal stacks (specially for tosemu on * Atari :-) Current limitation: Only one sigstack can be active at one time. * If a second signal with SA_ONSTACK set arrives while working on a sigstack, * SA_ONSTACK is ignored. This behaviour avoids lots of trouble with nested * signal handlers! */#include <linux/sched.h>#include <linux/mm.h>#include <linux/kernel.h>#include <linux/signal.h>#include <linux/errno.h>#include <linux/wait.h>#include <linux/ptrace.h>#include <linux/unistd.h>#include <linux/stddef.h>#include <linux/highuid.h>#include <linux/personality.h>#include <asm/setup.h>#include <asm/uaccess.h>#include <asm/pgtable.h>#include <asm/traps.h>#include <asm/ucontext.h>#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))asmlinkage long sys_wait4(pid_t pid, unsigned int * stat_addr, int options,			struct rusage * ru);asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs);#ifndef CONFIG_UCLINUXconst int frame_extra_sizes[16] = {  0,  -1, /* sizeof(((struct frame *)0)->un.fmt1), */  sizeof(((struct frame *)0)->un.fmt2),  sizeof(((struct frame *)0)->un.fmt3),  sizeof(((struct frame *)0)->un.fmt4),  -1, /* sizeof(((struct frame *)0)->un.fmt5), */  -1, /* sizeof(((struct frame *)0)->un.fmt6), */  sizeof(((struct frame *)0)->un.fmt7),  -1, /* sizeof(((struct frame *)0)->un.fmt8), */  sizeof(((struct frame *)0)->un.fmt9),  sizeof(((struct frame *)0)->un.fmta),  sizeof(((struct frame *)0)->un.fmtb),  -1, /* sizeof(((struct frame *)0)->un.fmtc), */  -1, /* sizeof(((struct frame *)0)->un.fmtd), */  -1, /* sizeof(((struct frame *)0)->un.fmte), */  -1, /* sizeof(((struct frame *)0)->un.fmtf), */};#endif/* * Atomically swap in the new signal mask, and wait for a signal. */asmlinkage int do_sigsuspend(struct pt_regs *regs){	old_sigset_t mask = regs->d3;	sigset_t saveset;	mask &= _BLOCKABLE;	saveset = current->blocked;	siginitset(&current->blocked, mask);	recalc_sigpending(current);	regs->d0 = -EINTR;	while (1) {		current->state = TASK_INTERRUPTIBLE;		schedule();		if (do_signal(&saveset, regs))			return -EINTR;	}}asmlinkage intdo_rt_sigsuspend(struct pt_regs *regs){	sigset_t *unewset = (sigset_t *)regs->d1;	size_t sigsetsize = (size_t)regs->d2;	sigset_t saveset, newset;	/* XXX: Don't preclude handling different sized sigset_t's.  */	if (sigsetsize != sizeof(sigset_t))		return -EINVAL;	if (copy_from_user(&newset, unewset, sizeof(newset)))		return -EFAULT;	sigdelsetmask(&newset, ~_BLOCKABLE);	saveset = current->blocked;	current->blocked = newset;	recalc_sigpending(current);	regs->d0 = -EINTR;	while (1) {		current->state = TASK_INTERRUPTIBLE;		schedule();		if (do_signal(&saveset, regs))			return -EINTR;	}}asmlinkage int sys_sigaction(int sig, const struct old_sigaction *act,	      struct old_sigaction *oact){	struct k_sigaction new_ka, old_ka;	int ret;	if (act) {		old_sigset_t mask;		if (verify_area(VERIFY_READ, act, sizeof(*act)) ||		    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||		    __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))			return -EFAULT;		__get_user(new_ka.sa.sa_flags, &act->sa_flags);		__get_user(mask, &act->sa_mask);		siginitset(&new_ka.sa.sa_mask, mask);	}	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);	if (!ret && oact) {		if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||		    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||		    __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))			return -EFAULT;		__put_user(old_ka.sa.sa_flags, &oact->sa_flags);		__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);	}	return ret;}asmlinkage intsys_sigaltstack(const stack_t *uss, stack_t *uoss){	return do_sigaltstack(uss, uoss, rdusp());}/* * Do a signal return; undo the signal stack. * * Keep the return code on the stack quadword aligned! * That makes the cache flush below easier. */struct sigframe{	char *pretcode;	int sig;	int code;	struct sigcontext *psc;	char retcode[8];	unsigned long extramask[_NSIG_WORDS-1];	struct sigcontext sc;};struct rt_sigframe{	char *pretcode;	int sig;	struct siginfo *pinfo;	void *puc;	char retcode[8];	struct siginfo info;	struct ucontext uc;};int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from){	if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))		return -EFAULT;	if (from->si_code < 0)		return __copy_to_user(to, from, sizeof(siginfo_t));	else {		int err;		/* If you change siginfo_t structure, please be sure		   this code is fixed accordingly.		   It should never copy any pad contained in the structure		   to avoid security leaks, but must copy the generic		   3 ints plus the relevant union member.  */		err = __put_user(from->si_signo, &to->si_signo);		err |= __put_user(from->si_errno, &to->si_errno);		err |= __put_user((short)from->si_code, &to->si_code);		/* First 32bits of unions are always present.  */		err |= __put_user(from->si_pid, &to->si_pid);		switch (from->si_code >> 16) {		case __SI_FAULT >> 16:			break;		case __SI_CHLD >> 16:			err |= __put_user(from->si_utime, &to->si_utime);			err |= __put_user(from->si_stime, &to->si_stime);			err |= __put_user(from->si_status, &to->si_status);		default:			err |= __put_user(from->si_uid, &to->si_uid);			break;		/* case __SI_RT: This is not generated by the kernel as of now.  */		}		return err;	}}#ifndef NO_FPUstatic unsigned char fpu_version = 0;	/* version number of fpu, set by setup_frame */static inline int restore_fpu_state(struct sigcontext *sc){	int err = 1;	if (FPU_IS_EMU) {	    /* restore registers */	    memcpy(current->thread.fpcntl, sc->sc_fpcntl, 12);	    memcpy(current->thread.fp, sc->sc_fpregs, 24);	    return 0;	}	if (CPU_IS_060 ? sc->sc_fpstate[2] : sc->sc_fpstate[0]) {	    /* Verify the frame format.  */	    if (!CPU_IS_060 && (sc->sc_fpstate[0] != fpu_version))		goto out;	    if (CPU_IS_020_OR_030) {		if (m68k_fputype & FPU_68881 &&		    !(sc->sc_fpstate[1] == 0x18 || sc->sc_fpstate[1] == 0xb4))		    goto out;		if (m68k_fputype & FPU_68882 &&		    !(sc->sc_fpstate[1] == 0x38 || sc->sc_fpstate[1] == 0xd4))		    goto out;	    } else if (CPU_IS_040) {		if (!(sc->sc_fpstate[1] == 0x00 ||                      sc->sc_fpstate[1] == 0x28 ||                      sc->sc_fpstate[1] == 0x60))		    goto out;	    } else if (CPU_IS_060) {		if (!(sc->sc_fpstate[3] == 0x00 ||                      sc->sc_fpstate[3] == 0x60 ||		      sc->sc_fpstate[3] == 0xe0))		    goto out;	    } else		goto out;	    __asm__ volatile (".chip 68k/68881\n\t"			      "fmovemx %0,%/fp0-%/fp1\n\t"			      "fmoveml %1,%/fpcr/%/fpsr/%/fpiar\n\t"			      ".chip 68k"			      : /* no outputs */			      : "m" (*sc->sc_fpregs), "m" (*sc->sc_fpcntl));	}	__asm__ volatile (".chip 68k/68881\n\t"			  "frestore %0\n\t"			  ".chip 68k" : : "m" (*sc->sc_fpstate));	err = 0;out:	return err;}#define FPCONTEXT_SIZE	216#define uc_fpstate	uc_filler[0]#define uc_formatvec	uc_filler[FPCONTEXT_SIZE/4]#define uc_extra	uc_filler[FPCONTEXT_SIZE/4+1]static inline int rt_restore_fpu_state(struct ucontext *uc){	unsigned char fpstate[FPCONTEXT_SIZE];	int context_size = CPU_IS_060 ? 8 : 0;	fpregset_t fpregs;	int err = 1;	if (FPU_IS_EMU) {		/* restore fpu control register */		if (__copy_from_user(current->thread.fpcntl,				&uc->uc_mcontext.fpregs.f_pcr, 12))			goto out;		/* restore all other fpu register */		if (__copy_from_user(current->thread.fp,				uc->uc_mcontext.fpregs.f_fpregs, 96))			goto out;		return 0;	}	if (__get_user(*(long *)fpstate, (long *)&uc->uc_fpstate))		goto out;	if (CPU_IS_060 ? fpstate[2] : fpstate[0]) {		if (!CPU_IS_060)			context_size = fpstate[1];		/* Verify the frame format.  */		if (!CPU_IS_060 && (fpstate[0] != fpu_version))			goto out;		if (CPU_IS_020_OR_030) {			if (m68k_fputype & FPU_68881 &&			    !(context_size == 0x18 || context_size == 0xb4))				goto out;			if (m68k_fputype & FPU_68882 &&			    !(context_size == 0x38 || context_size == 0xd4))				goto out;		} else if (CPU_IS_040) {			if (!(context_size == 0x00 ||			      context_size == 0x28 ||			      context_size == 0x60))				goto out;		} else if (CPU_IS_060) {			if (!(fpstate[3] == 0x00 ||			      fpstate[3] == 0x60 ||			      fpstate[3] == 0xe0))				goto out;		} else			goto out;		if (__copy_from_user(&fpregs, &uc->uc_mcontext.fpregs,				     sizeof(fpregs)))			goto out;		__asm__ volatile (".chip 68k/68881\n\t"				  "fmovemx %0,%/fp0-%/fp7\n\t"				  "fmoveml %1,%/fpcr/%/fpsr/%/fpiar\n\t"				  ".chip 68k"				  : /* no outputs */				  : "m" (*fpregs.f_fpregs),				    "m" (fpregs.f_pcr));	}	if (context_size &&	    __copy_from_user(fpstate + 4, (long *)&uc->uc_fpstate + 1,			     context_size))		goto out;	__asm__ volatile (".chip 68k/68881\n\t"			  "frestore %0\n\t"			  ".chip 68k" : : "m" (*fpstate));	err = 0;out:	return err;}#endifstatic inline intrestore_sigcontext(struct pt_regs *regs, struct sigcontext *usc, void *fp,		   int *pd0){#ifndef CONFIG_UCLINUX	int fsize;#endif	int formatvec;	struct sigcontext context;	int err = 0;	/* get previous context */	if (copy_from_user(&context, usc, sizeof(context)))		goto badframe;		/* restore passed registers */	regs->d1 = context.sc_d1;	regs->a0 = context.sc_a0;	regs->a1 = context.sc_a1;	regs->sr = (regs->sr & 0xff00) | (context.sc_sr & 0xff);	regs->pc = context.sc_pc;	regs->orig_d0 = -1;		/* disable syscall checks */	wrusp(context.sc_usp);	formatvec = context.sc_formatvec;	regs->format = formatvec >> 12;	regs->vector = formatvec & 0xfff;#ifndef NO_FPU	err = restore_fpu_state(&context);#endif#ifndef CONFIG_UCLINUX /* has no extra crap */	fsize = frame_extra_sizes[regs->format];	if (fsize < 0) {		/*		 * user process trying to return with weird frame format		 */#if DEBUG		printk("user process returning with weird frame format\n");#endif		goto badframe;	}	/* OK.	Make room on the supervisor stack for the extra junk,	 * if necessary.	 */	if (fsize) {		struct switch_stack *sw = (struct switch_stack *)regs - 1;		regs->d0 = context.sc_d0;#define frame_offset (sizeof(struct pt_regs)+sizeof(struct switch_stack))		__asm__ __volatile__			("   movel %0,%/a0\n\t"			 "   subl %1,%/a0\n\t"     /* make room on stack */			 "   movel %/a0,%/sp\n\t"  /* set stack pointer */			 /* move switch_stack and pt_regs */			 "1: movel %0@+,%/a0@+\n\t"			 "   dbra %2,1b\n\t"			 "   lea %/sp@(%c3),%/a0\n\t" /* add offset of fmt */			 "   lsrl  #2,%1\n\t"			 "   subql #1,%1\n\t"			 "2: movesl %4@+,%2\n\t"			 "3: movel %2,%/a0@+\n\t"			 "   dbra %1,2b\n\t"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -