📄 process.c
字号:
if (t->flags & SPARC_FLAG_PERFCTR) { t->user_cntd0 = t->user_cntd1 = NULL; t->pcr_reg = 0; t->flags &= ~(SPARC_FLAG_PERFCTR); write_pcr(0); }}void flush_thread(void){ struct thread_struct *t = ¤t->thread; if (t->flags & SPARC_FLAG_ABI_PENDING) t->flags ^= (SPARC_FLAG_ABI_PENDING | SPARC_FLAG_32BIT); if (current->mm) { unsigned long pgd_cache = 0UL; if (t->flags & SPARC_FLAG_32BIT) { struct mm_struct *mm = current->mm; pgd_t *pgd0 = &mm->pgd[0]; if (pgd_none(*pgd0)) { pmd_t *page = pmd_alloc_one_fast(NULL, 0); if (!page) page = pmd_alloc_one(NULL, 0); pgd_set(pgd0, page); } pgd_cache = pgd_val(*pgd0) << 11UL; } __asm__ __volatile__("stxa %0, [%1] %2\n\t" "membar #Sync" : /* no outputs */ : "r" (pgd_cache), "r" (TSB_REG), "i" (ASI_DMMU)); } t->w_saved = 0; /* Turn off performance counters if on. */ if (t->flags & SPARC_FLAG_PERFCTR) { t->user_cntd0 = t->user_cntd1 = NULL; t->pcr_reg = 0; t->flags &= ~(SPARC_FLAG_PERFCTR); write_pcr(0); } /* Clear FPU register state. */ t->fpsaved[0] = 0; if (t->current_ds.seg != ASI_AIUS) set_fs(USER_DS); /* Init new signal delivery disposition. */ t->flags &= ~SPARC_FLAG_NEWSIGNALS;}/* It's a bit more tricky when 64-bit tasks are involved... */static unsigned long clone_stackframe(unsigned long csp, unsigned long psp){ unsigned long fp, distance, rval; if (!(current->thread.flags & SPARC_FLAG_32BIT)) { csp += STACK_BIAS; psp += STACK_BIAS; __get_user(fp, &(((struct reg_window *)psp)->ins[6])); fp += STACK_BIAS; } else __get_user(fp, &(((struct reg_window32 *)psp)->ins[6])); /* Now 8-byte align the stack as this is mandatory in the * Sparc ABI due to how register windows work. This hides * the restriction from thread libraries etc. -DaveM */ csp &= ~7UL; distance = fp - psp; rval = (csp - distance); if (copy_in_user(rval, psp, distance)) rval = 0; else if (current->thread.flags & SPARC_FLAG_32BIT) { if (put_user(((u32)csp), &(((struct reg_window32 *)rval)->ins[6]))) rval = 0; } else { if (put_user(((u64)csp - STACK_BIAS), &(((struct reg_window *)rval)->ins[6]))) rval = 0; else rval = rval - STACK_BIAS; } return rval;}/* Standard stuff. */static inline void shift_window_buffer(int first_win, int last_win, struct thread_struct *t){ int i; for (i = first_win; i < last_win; i++) { t->rwbuf_stkptrs[i] = t->rwbuf_stkptrs[i+1]; memcpy(&t->reg_window[i], &t->reg_window[i+1], sizeof(struct reg_window)); }}void synchronize_user_stack(void){ struct thread_struct *t = ¤t->thread; unsigned long window; flush_user_windows(); if ((window = t->w_saved) != 0) { int winsize = REGWIN_SZ; int bias = 0; if (t->flags & SPARC_FLAG_32BIT) winsize = REGWIN32_SZ; else bias = STACK_BIAS; window -= 1; do { unsigned long sp = (t->rwbuf_stkptrs[window] + bias); struct reg_window *rwin = &t->reg_window[window]; if (!copy_to_user((char *)sp, rwin, winsize)) { shift_window_buffer(window, t->w_saved - 1, t); t->w_saved--; } } while (window--); }}void fault_in_user_windows(void){ struct thread_struct *t = ¤t->thread; unsigned long window; int winsize = REGWIN_SZ; int bias = 0; if (t->flags & SPARC_FLAG_32BIT) winsize = REGWIN32_SZ; else bias = STACK_BIAS; flush_user_windows(); window = t->w_saved; if (window != 0) { window -= 1; do { unsigned long sp = (t->rwbuf_stkptrs[window] + bias); struct reg_window *rwin = &t->reg_window[window]; if (copy_to_user((char *)sp, rwin, winsize)) goto barf; } while (window--); } t->w_saved = 0; return;barf: t->w_saved = window + 1; do_exit(SIGILL);}/* Copy a Sparc thread. The fork() return value conventions * under SunOS are nothing short of bletcherous: * Parent --> %o0 == childs pid, %o1 == 0 * Child --> %o0 == parents pid, %o1 == 1 */int copy_thread(int nr, unsigned long clone_flags, unsigned long sp, unsigned long unused, struct task_struct *p, struct pt_regs *regs){ struct thread_struct *t = &p->thread; char *child_trap_frame;#ifdef CONFIG_DEBUG_SPINLOCK t->smp_lock_count = 0; t->smp_lock_pc = 0;#endif /* Calculate offset to stack_frame & pt_regs */ child_trap_frame = ((char *)p) + (THREAD_SIZE - (TRACEREG_SZ+REGWIN_SZ)); memcpy(child_trap_frame, (((struct reg_window *)regs)-1), (TRACEREG_SZ+REGWIN_SZ)); t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS; t->flags |= SPARC_FLAG_NEWCHILD; t->kregs = (struct pt_regs *)(child_trap_frame+sizeof(struct reg_window)); t->cwp = (regs->tstate + 1) & TSTATE_CWP; t->fpsaved[0] = 0; if (regs->tstate & TSTATE_PRIV) { /* Special case, if we are spawning a kernel thread from * a userspace task (via KMOD, NFS, or similar) we must * disable performance counters in the child because the * address space and protection realm are changing. */ if (t->flags & SPARC_FLAG_PERFCTR) { t->user_cntd0 = t->user_cntd1 = NULL; t->pcr_reg = 0; t->flags &= ~(SPARC_FLAG_PERFCTR); } t->kregs->u_regs[UREG_FP] = p->thread.ksp; t->current_ds = KERNEL_DS; flush_register_windows(); memcpy((void *)(t->ksp + STACK_BIAS), (void *)(regs->u_regs[UREG_FP] + STACK_BIAS), sizeof(struct reg_window)); t->kregs->u_regs[UREG_G6] = (unsigned long) p; } else { if (t->flags & SPARC_FLAG_32BIT) { sp &= 0x00000000ffffffffUL; regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL; } t->kregs->u_regs[UREG_FP] = sp; t->current_ds = USER_DS; if (sp != regs->u_regs[UREG_FP]) { unsigned long csp; csp = clone_stackframe(sp, regs->u_regs[UREG_FP]); if (!csp) return -EFAULT; t->kregs->u_regs[UREG_FP] = csp; } if (t->utraps) t->utraps[0]++; } /* Set the return value for the child. */ t->kregs->u_regs[UREG_I0] = current->pid; t->kregs->u_regs[UREG_I1] = 1; /* Set the second return value for the parent. */ regs->u_regs[UREG_I1] = 0; return 0;}/* * This is the mechanism for creating a new kernel thread. * * NOTE! Only a kernel-only process(ie the swapper or direct descendants * who haven't done an "execve()") should use this: it will work within * a system call from a "real" process, but the process memory space will * not be free'd until both the parent and the child have exited. */pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags){ long retval; /* If the parent runs before fn(arg) is called by the child, * the input registers of this function can be clobbered. * So we stash 'fn' and 'arg' into global registers which * will not be modified by the parent. */ __asm__ __volatile("mov %4, %%g2\n\t" /* Save FN into global */ "mov %5, %%g3\n\t" /* Save ARG into global */ "mov %1, %%g1\n\t" /* Clone syscall nr. */ "mov %2, %%o0\n\t" /* Clone flags. */ "mov 0, %%o1\n\t" /* usp arg == 0 */ "t 0x6d\n\t" /* Linux/Sparc clone(). */ "brz,a,pn %%o1, 1f\n\t" /* Parent, just return. */ " mov %%o0, %0\n\t" "jmpl %%g2, %%o7\n\t" /* Call the function. */ " mov %%g3, %%o0\n\t" /* Set arg in delay. */ "mov %3, %%g1\n\t" "t 0x6d\n\t" /* Linux/Sparc exit(). */ /* Notreached by child. */ "1:" : "=r" (retval) : "i" (__NR_clone), "r" (flags | CLONE_VM), "i" (__NR_exit), "r" (fn), "r" (arg) : "g1", "g2", "g3", "o0", "o1", "memory", "cc"); return retval;}/* * fill in the user structure for a core dump.. */void dump_thread(struct pt_regs * regs, struct user * dump){#if 1 /* Only should be used for SunOS and ancient a.out * SparcLinux binaries... Fixme some day when bored. * But for now at least plug the security hole :-) */ memset(dump, 0, sizeof(struct user));#else unsigned long first_stack_page; dump->magic = SUNOS_CORE_MAGIC; dump->len = sizeof(struct user); dump->regs.psr = regs->psr; dump->regs.pc = regs->pc; dump->regs.npc = regs->npc; dump->regs.y = regs->y; /* fuck me plenty */ memcpy(&dump->regs.regs[0], ®s->u_regs[1], (sizeof(unsigned long) * 15)); dump->u_tsize = (((unsigned long) current->mm->end_code) - ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1); dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))); dump->u_dsize -= dump->u_tsize; dump->u_dsize &= ~(PAGE_SIZE - 1); first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1)); dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1); memcpy(&dump->fpu.fpstatus.fregs.regs[0], ¤t->thread.float_regs[0], (sizeof(unsigned long) * 32)); dump->fpu.fpstatus.fsr = current->thread.fsr; dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;#endif }typedef struct { union { unsigned int pr_regs[32]; unsigned long pr_dregs[16]; } pr_fr; unsigned int __unused; unsigned int pr_fsr; unsigned char pr_qcnt; unsigned char pr_q_entrysize; unsigned char pr_en; unsigned int pr_q[64];} elf_fpregset_t32;/* * fill in the fpu structure for a core dump. */int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs){ unsigned long *kfpregs = (unsigned long *)(((char *)current) + AOFF_task_fpregs); unsigned long fprs = current->thread.fpsaved[0]; if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) { elf_fpregset_t32 *fpregs32 = (elf_fpregset_t32 *)fpregs; if (fprs & FPRS_DL) memcpy(&fpregs32->pr_fr.pr_regs[0], kfpregs, sizeof(unsigned int) * 32); else memset(&fpregs32->pr_fr.pr_regs[0], 0, sizeof(unsigned int) * 32); fpregs32->pr_qcnt = 0; fpregs32->pr_q_entrysize = 8; memset(&fpregs32->pr_q[0], 0, (sizeof(unsigned int) * 64)); if (fprs & FPRS_FEF) { fpregs32->pr_fsr = (unsigned int) current->thread.xfsr[0]; fpregs32->pr_en = 1; } else { fpregs32->pr_fsr = 0; fpregs32->pr_en = 0; } } else { if(fprs & FPRS_DL) memcpy(&fpregs->pr_regs[0], kfpregs, sizeof(unsigned int) * 32); else memset(&fpregs->pr_regs[0], 0, sizeof(unsigned int) * 32); if(fprs & FPRS_DU) memcpy(&fpregs->pr_regs[16], kfpregs+16, sizeof(unsigned int) * 32); else memset(&fpregs->pr_regs[16], 0, sizeof(unsigned int) * 32); if(fprs & FPRS_FEF) { fpregs->pr_fsr = current->thread.xfsr[0]; fpregs->pr_gsr = current->thread.gsr[0]; } else { fpregs->pr_fsr = fpregs->pr_gsr = 0; } fpregs->pr_fprs = fprs; } return 1;}/* * sparc_execve() executes a new program after the asm stub has set * things up for us. This should basically do what I want it to. */asmlinkage int sparc_execve(struct pt_regs *regs){ int error, base = 0; char *filename; /* User register window flush is done by entry.S */ /* Check for indirect call. */ if (regs->u_regs[UREG_G1] == 0) base = 1; filename = getname((char *)regs->u_regs[base + UREG_I0]); error = PTR_ERR(filename); if (IS_ERR(filename)) goto out; error = do_execve(filename, (char **) regs->u_regs[base + UREG_I1], (char **) regs->u_regs[base + UREG_I2], regs); putname(filename); if (!error) { fprs_write(0); current->thread.xfsr[0] = 0; current->thread.fpsaved[0] = 0; regs->tstate &= ~TSTATE_PEF; }out: return error;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -