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

📄 signal32.c

📁 这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自测试~但就算用来做参考资料也是非常好的
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * signal32.c: Support 32bit signal syscalls. * * Copyright (C) 2001 IBM * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) * * These routines maintain argument size conversion between 32bit and 64bit * environment. * *      This program is free software; you can redistribute it and/or *      modify it under the terms of the GNU General Public License *      as published by the Free Software Foundation; either version *      2 of the License, or (at your option) any later version. */#include <asm/ptrace.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/fs.h> #include <linux/mm.h> #include <linux/file.h> #include <linux/signal.h>#include <linux/utime.h>#include <linux/resource.h>#include <linux/times.h>#include <linux/utsname.h>#include <linux/timex.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/sem.h>#include <linux/msg.h>#include <linux/shm.h>#include <linux/slab.h>#include <linux/uio.h>#include <linux/nfs_fs.h>#include <linux/smb_fs.h>#include <linux/smb_mount.h>#include <linux/ncp_fs.h>#include <linux/quota.h>#include <linux/module.h>#include <linux/poll.h>#include <linux/personality.h>#include <linux/stat.h>#include <linux/filter.h>#include <asm/types.h>#include <asm/ipc.h>#include <asm/uaccess.h>#include <linux/elf.h>#include <asm/ppc32.h>#include <asm/ppcdebug.h>#include <asm/unistd.h>#include <asm/ucontext.h>#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))/*  * These are the flags in the MSR that the user is allowed to change * by modifying the saved value of the MSR on the stack.  SE and BE * should not be in this list since gdb may want to change these.  I.e, * you should be able to step out of a signal handler to see what * instruction executes next after the signal handler completes. * Alternately, if you stepped into a signal handler, you should be * able to continue 'til the next breakpoint from within the signal * handler, even if the handler returns. */#define MSR_USERCHANGE	(MSR_FE0 | MSR_FE1)struct timespec32 {	s32    tv_sec;	s32    tv_nsec;};struct sigregs32 {    /***********************************************************************/    /* the gp_regs array is 32 bit representation of the pt_regs structure */    /*  that was stored on the kernle stack during the system call that    */    /*  was interrupted for the signal.                                    */    /*                                                                     */    /* Note that the entire pt_regs regs structure will fit in the gp_regs */    /*   structure because the ELF_NREG value is 48 for PPC and the pt_regs*/    /*   structure contains 44 registers                                   */    /*                                                                     */     /***********************************************************************/ 	elf_gregset_t32	gp_regs;	double		fp_regs[ELF_NFPREG];	unsigned int	tramp[2];	/* Programs using the rs6000/xcoff abi can save up to 19 gp regs	   and 18 fp regs below sp before decrementing it. */	int		abigap[56];};struct rt_sigframe_32 {	/* Unused space at start of frame to allow for storing of stack pointers */	unsigned long _unused;	/* This is a 32 bit pointer in user address space 	 *     it is a pointer to the siginfo stucture in the rt stack frame 	 */	u32 pinfo;	/* This is a 32 bit pointer in user address space */	/*     it is a pointer to the user context in the rt stack frame  */	u32 puc;	struct siginfo32  info;	struct ucontext32 uc;};extern asmlinkage long sys_wait4(pid_t pid,unsigned int * stat_addr, int options, struct rusage * ru);/****************************************************************************//*  Start of nonRT signal support                                           *//*                                                                          *//*     sigset_t is 32 bits for non-rt signals                               *//*                                                                          *//*  System Calls                                                            *//*       sigaction                sys32_sigaction                           *//*       sigpending               sys32_sigpending                          *//*       sigprocmask              sys32_sigprocmask                         *//*       sigreturn                sys32_sigreturn                           *//*                                                                          *//*  Note sigsuspend has no special 32 bit routine - uses the 64 bit routine */ /*                                                                          *//*  Other routines                                                          *//*        setup_frame32                                                     *//*                                                                          *//****************************************************************************/asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 *act, struct old_sigaction32 *oact){	struct k_sigaction new_ka, old_ka;	int ret;		PPCDBG(PPCDBG_SYS32, "sys32_sigaction - entered - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);	if (sig < 0)	{		sig = -sig;	}	if (act)	{		old_sigset_t32 mask;		ret = get_user((long)new_ka.sa.sa_handler, &act->sa_handler);		ret |= __get_user((long)new_ka.sa.sa_restorer, &act->sa_restorer);		ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);		ret |= __get_user(mask, &act->sa_mask);		if (ret)			return ret;		PPCDBG(PPCDBG_SIGNAL, "sys32_sigaction flags =%lx  \n", new_ka.sa.sa_flags);		siginitset(&new_ka.sa.sa_mask, mask);	}	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);	if (!ret && oact)	{		ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);		ret |= __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer);		ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);		ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);	}		PPCDBG(PPCDBG_SYS32, "sys32_sigaction - exited - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);	return ret;}extern asmlinkage long sys_sigpending(old_sigset_t *set);asmlinkage long sys32_sigpending(old_sigset_t32 *set){	old_sigset_t s;	int ret;	mm_segment_t old_fs = get_fs();		PPCDBG(PPCDBG_SYS32, "sys32_sigpending - entered - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);			set_fs (KERNEL_DS);	ret = sys_sigpending(&s);	set_fs (old_fs);	if (put_user (s, set)) return -EFAULT;		PPCDBG(PPCDBG_SYS32, "sys32_sigpending - exited - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);	return ret;}extern asmlinkage long sys_sigprocmask(int how, old_sigset_t *set, old_sigset_t *oset);/* Note: it is necessary to treat how as an unsigned int,  * with the corresponding cast to a signed int to insure that the  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */asmlinkage long sys32_sigprocmask(u32 how, old_sigset_t32 *set, old_sigset_t32 *oset){	old_sigset_t s;	int ret;	mm_segment_t old_fs = get_fs();		PPCDBG(PPCDBG_SYS32, "sys32_sigprocmask - entered - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);		if (set && get_user (s, set)) return -EFAULT;	set_fs (KERNEL_DS);	ret = sys_sigprocmask((int)how, set ? &s : NULL, oset ? &s : NULL);	set_fs (old_fs);	if (ret) return ret;	if (oset && put_user (s, oset)) return -EFAULT;		PPCDBG(PPCDBG_SYS32, "sys32_sigprocmask - exited - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);	return 0;}/* * When we have signals to deliver, we set up on the * user stack, going down from the original stack pointer: *	a sigregs struct *	one or more sigcontext structs *	a gap of __SIGNAL_FRAMESIZE32 bytes * * Each of these things must be a multiple of 16 bytes in size. **//* * Do a signal return; undo the signal stack. */long sys32_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,		     unsigned long r6, unsigned long r7, unsigned long r8,		     struct pt_regs *regs){	struct sigcontext32_struct *sc, sigctx;	struct sigregs32 *sr;	int ret;	elf_gregset_t32 saved_regs;  /* an array of ELF_NGREG unsigned ints (32 bits) */	sigset_t set;	unsigned int prevsp;	PPCDBG(PPCDBG_SIGNAL, "sys32_sigreturn - entered - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);	sc = (struct sigcontext32_struct *)(regs->gpr[1] + __SIGNAL_FRAMESIZE32);	if (copy_from_user(&sigctx, sc, sizeof(sigctx)))		goto badframe;	/* Note that PPC32 puts the upper 32 bits of the sigmask in the  */	/*   unused part of the signal stackframe                        */	set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3])<< 32);	sigdelsetmask(&set, ~_BLOCKABLE);	spin_lock_irq(&current->sigmask_lock);	current->blocked = set;	recalc_sigpending(current);	spin_unlock_irq(&current->sigmask_lock);	sc++;			/* Look at next sigcontext */	/* If the next sigcontext is actually the sigregs (frame)  */	/*   - then no more sigcontexts on the user stack          */  	if (sc == (struct sigcontext32_struct*)(u64)sigctx.regs)	{		/* Last stacked signal - restore registers */		sr = (struct sigregs32*)(u64)sigctx.regs;		if (regs->msr & MSR_FP )			giveup_fpu(current);		/* copy the 32 bit register values off the user stack */		/*   into the 32 bit register area                    */		if (copy_from_user(saved_regs, &sr->gp_regs,sizeof(sr->gp_regs)))			goto badframe;		/**********************************************************************/		/* The saved reg structure in the frame is an elf_grepset_t32, it is  */		/*   a 32 bit register save of the registers in the pt_regs structure */		/*   that was stored on the kernel stack during the system call       */		/*   when the system call was interrupted for the signal. Only 32 bits*/		/*   are saved because the sigcontext contains a pointer to the regs  */		/*   and the sig context address is passed as a pointer to the signal */		/*   handler.                                                         */		/*                                                                    */		/* The entries in the elf_grepset have the same index as the elements */		/*   in the pt_regs structure.                                        */		/*                                                                    */		/**********************************************************************/		saved_regs[PT_MSR] = (regs->msr & ~MSR_USERCHANGE)			| (saved_regs[PT_MSR] & MSR_USERCHANGE);		regs->gpr[0] = (u64)(saved_regs[0]) & 0xFFFFFFFF;		regs->gpr[1] = (u64)(saved_regs[1]) & 0xFFFFFFFF;		/**********************************************************************/		/* Register 2 is the kernel toc - should be reset on any calls into   */		/*  the kernel                                                        */		/**********************************************************************/		regs->gpr[2] = (u64)(saved_regs[2]) & 0xFFFFFFFF;		regs->gpr[3] = (u64)(saved_regs[3]) & 0xFFFFFFFF;		regs->gpr[4] = (u64)(saved_regs[4]) & 0xFFFFFFFF;		regs->gpr[5] = (u64)(saved_regs[5]) & 0xFFFFFFFF;		regs->gpr[6] = (u64)(saved_regs[6]) & 0xFFFFFFFF;		regs->gpr[7] = (u64)(saved_regs[7]) & 0xFFFFFFFF;		regs->gpr[8] = (u64)(saved_regs[8]) & 0xFFFFFFFF;		regs->gpr[9] = (u64)(saved_regs[9]) & 0xFFFFFFFF;		regs->gpr[10] = (u64)(saved_regs[10]) & 0xFFFFFFFF;		regs->gpr[11] = (u64)(saved_regs[11]) & 0xFFFFFFFF;		regs->gpr[12] = (u64)(saved_regs[12]) & 0xFFFFFFFF;		regs->gpr[13] = (u64)(saved_regs[13]) & 0xFFFFFFFF;		regs->gpr[14] = (u64)(saved_regs[14]) & 0xFFFFFFFF;		regs->gpr[15] = (u64)(saved_regs[15]) & 0xFFFFFFFF;		regs->gpr[16] = (u64)(saved_regs[16]) & 0xFFFFFFFF;		regs->gpr[17] = (u64)(saved_regs[17]) & 0xFFFFFFFF;		regs->gpr[18] = (u64)(saved_regs[18]) & 0xFFFFFFFF;		regs->gpr[19] = (u64)(saved_regs[19]) & 0xFFFFFFFF;		regs->gpr[20] = (u64)(saved_regs[20]) & 0xFFFFFFFF;		regs->gpr[21] = (u64)(saved_regs[21]) & 0xFFFFFFFF;		regs->gpr[22] = (u64)(saved_regs[22]) & 0xFFFFFFFF;		regs->gpr[23] = (u64)(saved_regs[23]) & 0xFFFFFFFF;		regs->gpr[24] = (u64)(saved_regs[24]) & 0xFFFFFFFF;		regs->gpr[25] = (u64)(saved_regs[25]) & 0xFFFFFFFF;		regs->gpr[26] = (u64)(saved_regs[26]) & 0xFFFFFFFF;		regs->gpr[27] = (u64)(saved_regs[27]) & 0xFFFFFFFF;		regs->gpr[28] = (u64)(saved_regs[28]) & 0xFFFFFFFF;		regs->gpr[29] = (u64)(saved_regs[29]) & 0xFFFFFFFF;		regs->gpr[30] = (u64)(saved_regs[30]) & 0xFFFFFFFF;		regs->gpr[31] = (u64)(saved_regs[31]) & 0xFFFFFFFF;		/****************************************************/		/*  restore the non gpr registers                   */		/****************************************************/		regs->msr = (u64)(saved_regs[PT_MSR]) & 0xFFFFFFFF;		/* Insure that the interrupt mode is 64 bit, during 32 bit execution.		 * (This is necessary because we only saved lower 32 bits of msr.)		 */		regs->msr = regs->msr | MSR_ISF;  /* When this thread is interrupted it should run in 64 bit mode. */		regs->nip = (u64)(saved_regs[PT_NIP]) & 0xFFFFFFFF;		regs->orig_gpr3 = (u64)(saved_regs[PT_ORIG_R3]) & 0xFFFFFFFF; 		regs->ctr = (u64)(saved_regs[PT_CTR]) & 0xFFFFFFFF; 		regs->link = (u64)(saved_regs[PT_LNK]) & 0xFFFFFFFF; 		regs->xer = (u64)(saved_regs[PT_XER]) & 0xFFFFFFFF; 		regs->ccr = (u64)(saved_regs[PT_CCR]) & 0xFFFFFFFF;		/* regs->softe is left unchanged (like the MSR.EE bit) */		/******************************************************/		/* the DAR and the DSISR are only relevant during a   */		/*   data or instruction storage interrupt. The value */		/*   will be set to zero.                             */		/******************************************************/		regs->dar = 0; 		regs->dsisr = 0;		regs->result = (u64)(saved_regs[PT_RESULT]) & 0xFFFFFFFF;		if (copy_from_user(current->thread.fpr, &sr->fp_regs, sizeof(sr->fp_regs)))			goto badframe;		ret = regs->result;	} else {		/* More signals to go */		regs->gpr[1] = (unsigned long)sc - __SIGNAL_FRAMESIZE32;		if (copy_from_user(&sigctx, sc, sizeof(sigctx)))			goto badframe;

⌨️ 快捷键说明

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