📄 signal32.c
字号:
" membar #StoreStore\n" " flush %0 + %1" : : "r" (page), "r" (address & (PAGE_SIZE - 1)) : "memory"); } } return;sigill: do_exit(SIGILL);sigsegv: do_exit(SIGSEGV);}/* Setup a Solaris stack frame */static inline voidsetup_svr4_frame32(struct sigaction *sa, unsigned long pc, unsigned long npc, struct pt_regs *regs, int signr, sigset_t *oldset){ svr4_signal_frame_t *sfp; svr4_gregset_t *gr; svr4_siginfo_t *si; svr4_mcontext_t *mc; svr4_gwindows_t *gw; svr4_ucontext_t *uc; svr4_sigset_t setv;#if 0 int window = 0;#endif unsigned psr; int i, err; synchronize_user_stack(); save_and_clear_fpu(); regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; sfp = (svr4_signal_frame_t *) get_sigframe(sa, regs, REGWIN_SZ + SVR4_SF_ALIGNED); if (invalid_frame_pointer (sfp, sizeof (*sfp))){#ifdef DEBUG_SIGNALS printk ("Invalid stack frame\n");#endif do_exit(SIGILL); } /* Start with a clean frame pointer and fill it */ err = clear_user(sfp, sizeof (*sfp)); /* Setup convenience variables */ si = &sfp->si; uc = &sfp->uc; gw = &sfp->gw; mc = &uc->mcontext; gr = &mc->greg; /* FIXME: where am I supposed to put this? * sc->sigc_onstack = old_status; * anyways, it does not look like it is used for anything at all. */ setv.sigbits[0] = oldset->sig[0]; setv.sigbits[1] = (oldset->sig[0] >> 32); if (_NSIG_WORDS >= 2) { setv.sigbits[2] = oldset->sig[1]; setv.sigbits[3] = (oldset->sig[1] >> 32); err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); } else err |= __copy_to_user(&uc->sigmask, &setv, 2 * sizeof(unsigned)); /* Store registers */ if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { regs->tpc &= 0xffffffff; regs->tnpc &= 0xffffffff; } err |= __put_user(regs->tpc, &((*gr) [SVR4_PC])); err |= __put_user(regs->tnpc, &((*gr) [SVR4_NPC])); psr = tstate_to_psr (regs->tstate); if(current->thread.fpsaved[0] & FPRS_FEF) psr |= PSR_EF; err |= __put_user(psr, &((*gr) [SVR4_PSR])); err |= __put_user(regs->y, &((*gr) [SVR4_Y])); /* Copy g [1..7] and o [0..7] registers */ for (i = 0; i < 7; i++) err |= __put_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); for (i = 0; i < 8; i++) err |= __put_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); /* Setup sigaltstack */ err |= __put_user(current->sas_ss_sp, &uc->stack.sp); err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags); err |= __put_user(current->sas_ss_size, &uc->stack.size); /* Save the currently window file: */ /* 1. Link sfp->uc->gwins to our windows */ err |= __put_user((u32)(long)gw, &mc->gwin); /* 2. Number of windows to restore at setcontext (): */ err |= __put_user(current->thread.w_saved, &gw->count); /* 3. Save each valid window * Currently, it makes a copy of the windows from the kernel copy. * David's code for SunOS, makes the copy but keeps the pointer to * the kernel. My version makes the pointer point to a userland * copy of those. Mhm, I wonder if I shouldn't just ignore those * on setcontext and use those that are on the kernel, the signal * handler should not be modyfing those, mhm. * * These windows are just used in case synchronize_user_stack failed * to flush the user windows. */#if 0 for(window = 0; window < current->thread.w_saved; window++) { err |= __put_user((int *) &(gw->win [window]), (int **)gw->winptr +window ); err |= copy_to_user(&gw->win [window], ¤t->thread.reg_window [window], sizeof (svr4_rwindow_t)); err |= __put_user(0, (int *)gw->winptr + window); }#endif /* 4. We just pay attention to the gw->count field on setcontext */ current->thread.w_saved = 0; /* So process is allowed to execute. */ /* Setup the signal information. Solaris expects a bunch of * information to be passed to the signal handler, we don't provide * that much currently, should use siginfo. */ err |= __put_user(signr, &si->siginfo.signo); err |= __put_user(SVR4_SINOINFO, &si->siginfo.code); if (err) goto sigsegv; regs->u_regs[UREG_FP] = (unsigned long) sfp; regs->tpc = (unsigned long) sa->sa_handler; regs->tnpc = (regs->tpc + 4); if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { regs->tpc &= 0xffffffff; regs->tnpc &= 0xffffffff; }#ifdef DEBUG_SIGNALS printk ("Solaris-frame: %x %x\n", (int) regs->tpc, (int) regs->tnpc);#endif /* Arguments passed to signal handler */ if (regs->u_regs [14]){ struct reg_window32 *rw = (struct reg_window32 *) (regs->u_regs [14] & 0x00000000ffffffffUL); err |= __put_user(signr, &rw->ins [0]); err |= __put_user((u64)si, &rw->ins [1]); err |= __put_user((u64)uc, &rw->ins [2]); err |= __put_user((u64)sfp, &rw->ins [6]); /* frame pointer */ if (err) goto sigsegv; regs->u_regs[UREG_I0] = signr; regs->u_regs[UREG_I1] = (u32)(u64) si; regs->u_regs[UREG_I2] = (u32)(u64) uc; } return;sigsegv: do_exit(SIGSEGV);}asmlinkage intsvr4_getcontext(svr4_ucontext_t *uc, struct pt_regs *regs){ svr4_gregset_t *gr; svr4_mcontext_t *mc; svr4_sigset_t setv; int i, err; synchronize_user_stack(); save_and_clear_fpu(); if (current->thread.w_saved){ printk ("Uh oh, w_saved is not zero (%d)\n", (int) current->thread.w_saved); do_exit (SIGSEGV); } err = clear_user(uc, sizeof (*uc)); /* Setup convenience variables */ mc = &uc->mcontext; gr = &mc->greg; setv.sigbits[0] = current->blocked.sig[0]; setv.sigbits[1] = (current->blocked.sig[0] >> 32); if (_NSIG_WORDS >= 2) { setv.sigbits[2] = current->blocked.sig[1]; setv.sigbits[3] = (current->blocked.sig[1] >> 32); err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); } else err |= __copy_to_user(&uc->sigmask, &setv, 2 * sizeof(unsigned)); /* Store registers */ if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { regs->tpc &= 0xffffffff; regs->tnpc &= 0xffffffff; } err |= __put_user(regs->tpc, &uc->mcontext.greg [SVR4_PC]); err |= __put_user(regs->tnpc, &uc->mcontext.greg [SVR4_NPC]);#if 1 err |= __put_user(0, &uc->mcontext.greg [SVR4_PSR]);#else i = tstate_to_psr(regs->tstate) & ~PSR_EF; if (current->thread.fpsaved[0] & FPRS_FEF) i |= PSR_EF; err |= __put_user(i, &uc->mcontext.greg [SVR4_PSR]);#endif err |= __put_user(regs->y, &uc->mcontext.greg [SVR4_Y]); /* Copy g [1..7] and o [0..7] registers */ for (i = 0; i < 7; i++) err |= __put_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); for (i = 0; i < 8; i++) err |= __put_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); /* Setup sigaltstack */ err |= __put_user(current->sas_ss_sp, &uc->stack.sp); err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags); err |= __put_user(current->sas_ss_size, &uc->stack.size); /* The register file is not saved * we have already stuffed all of it with sync_user_stack */ return (err ? -EFAULT : 0);}/* Set the context for a svr4 application, this is Solaris way to sigreturn */asmlinkage int svr4_setcontext(svr4_ucontext_t *c, struct pt_regs *regs){ struct thread_struct *tp = ¤t->thread; svr4_gregset_t *gr; mm_segment_t old_fs; u32 pc, npc, psr; sigset_t set; svr4_sigset_t setv; int i, err; stack_t st; /* Fixme: restore windows, or is this already taken care of in * svr4_setup_frame when sync_user_windows is done? */ flush_user_windows(); if (tp->w_saved){ printk ("Uh oh, w_saved is: 0x%x\n", tp->w_saved); goto sigsegv; } if (((unsigned long) c) & 3){ printk ("Unaligned structure passed\n"); goto sigsegv; } if(!__access_ok((unsigned long)c, sizeof(*c))) { /* Miguel, add nice debugging msg _here_. ;-) */ goto sigsegv; } /* Check for valid PC and nPC */ gr = &c->mcontext.greg; err = __get_user(pc, &((*gr)[SVR4_PC])); err |= __get_user(npc, &((*gr)[SVR4_NPC])); if((pc | npc) & 3) {#ifdef DEBUG_SIGNALS printk ("setcontext, PC or nPC were bogus\n");#endif goto sigsegv; } /* Retrieve information from passed ucontext */ /* note that nPC is ored a 1, this is used to inform entry.S */ /* that we don't want it to mess with our PC and nPC */ err |= copy_from_user (&setv, &c->sigmask, sizeof(svr4_sigset_t)); set.sig[0] = setv.sigbits[0] | (((long)setv.sigbits[1]) << 32); if (_NSIG_WORDS >= 2) set.sig[1] = setv.sigbits[2] | (((long)setv.sigbits[3]) << 32); err |= __get_user((long)st.ss_sp, &c->stack.sp); err |= __get_user(st.ss_flags, &c->stack.flags); err |= __get_user(st.ss_size, &c->stack.size); if (err) goto sigsegv; /* It is more difficult to avoid calling this function than to call it and ignore errors. */ old_fs = get_fs(); set_fs(KERNEL_DS); do_sigaltstack(&st, NULL, regs->u_regs[UREG_I6]); set_fs(old_fs); sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); regs->tpc = pc; regs->tnpc = npc | 1; if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { regs->tpc &= 0xffffffff; regs->tnpc &= 0xffffffff; } err |= __get_user(regs->y, &((*gr) [SVR4_Y])); err |= __get_user(psr, &((*gr) [SVR4_PSR])); regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); regs->tstate |= psr_to_tstate_icc(psr);#if 0 if(psr & PSR_EF) regs->tstate |= TSTATE_PEF;#endif /* Restore g[1..7] and o[0..7] registers */ for (i = 0; i < 7; i++) err |= __get_user(regs->u_regs[UREG_G1+i], (&(*gr)[SVR4_G1])+i); for (i = 0; i < 8; i++) err |= __get_user(regs->u_regs[UREG_I0+i], (&(*gr)[SVR4_O0])+i); if(err) goto sigsegv; return -EINTR;sigsegv: do_exit(SIGSEGV);}static inline void setup_rt_frame32(struct k_sigaction *ka, struct pt_regs *regs, unsigned long signr, sigset_t *oldset, siginfo_t *info){ struct rt_signal_frame32 *sf; int sigframe_size; u32 psr; int i, err; sigset_t32 seta; /* 1. Make sure everything is clean */ synchronize_user_stack(); save_and_clear_fpu(); sigframe_size = RT_ALIGNEDSZ; if (!(current->thread.fpsaved[0] & FPRS_FEF)) sigframe_size -= sizeof(__siginfo_fpu_t); sf = (struct rt_signal_frame32 *)get_sigframe(&ka->sa, regs, sigframe_size); if (invalid_frame_pointer (sf, sigframe_size)) {#ifdef DEBUG_SIGNALS printk("rt_setup_frame32(%s:%d): invalid_frame_pointer(%p, %d)\n", current->comm, current->pid, sf, sigframe_size);#endif goto sigill; } if (current->thread.w_saved != 0) {#ifdef DEBUG_SIGNALS printk ("%s[%d]: Invalid user stack frame for " "signal delivery.\n", current->comm, current->pid);#endif goto sigill; } /* 2. Save the current process state */ if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { regs->tpc &= 0xffffffff; regs->tnpc &= 0xffffffff; } err = put_user(regs->tpc, &sf->regs.pc); err |= __put_user(regs->tnpc, &sf->regs.npc); err |= __put_user(regs->y, &sf->regs.y); psr = tstate_to_psr (regs->tstate); if(current->thread.fpsaved[0] & FPRS_FEF) psr |= PSR_EF; err |= __put_user(psr, &sf->regs.psr); for (i = 0; i < 16; i++) err |= __put_user(regs->u_regs[i], &sf->regs.u_regs[i]); err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size); err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]); for (i = 1; i < 16; i++) err |= __put_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]); if (psr & PSR_EF) { err |= save_fpu_state32(regs, &sf->fpu_state); err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save); } else { err |= __put_user(0, &sf->fpu_save); } /* Update the siginfo structure. */ err |= copy_siginfo_to_user32(&sf->info, info); /* Setup sigaltstack */ err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp); err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags); err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -