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

📄 process.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
			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 = ((unsigned long) 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));	}	set_thread_wsaved(0);	/* Turn off performance counters if on. */	if (test_and_clear_thread_flag(TIF_PERFCTR)) {		t->user_cntd0 = t->user_cntd1 = NULL;		t->pcr_reg = 0;		write_pcr(0);	}	/* Clear FPU register state. */	t->fpsaved[0] = 0;		if (get_thread_current_ds() != ASI_AIUS)		set_fs(USER_DS);	/* Init new signal delivery disposition. */	clear_thread_flag(TIF_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 (!(test_thread_flag(TIF_32BIT))) {		csp += STACK_BIAS;		psp += STACK_BIAS;		__get_user(fp, &(((struct reg_window __user *)psp)->ins[6]));		fp += STACK_BIAS;	} else		__get_user(fp, &(((struct reg_window32 __user *)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((void __user *) rval, (void __user *) psp, distance))		rval = 0;	else if (test_thread_flag(TIF_32BIT)) {		if (put_user(((u32)csp),			     &(((struct reg_window32 __user *)rval)->ins[6])))			rval = 0;	} else {		if (put_user(((u64)csp - STACK_BIAS),			     &(((struct reg_window __user *)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_info *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_info *t = current_thread_info();	unsigned long window;	flush_user_windows();	if ((window = get_thread_wsaved()) != 0) {		int winsize = sizeof(struct reg_window);		int bias = 0;		if (test_thread_flag(TIF_32BIT))			winsize = sizeof(struct reg_window32);		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 __user *)sp, rwin, winsize)) {				shift_window_buffer(window, get_thread_wsaved() - 1, t);				set_thread_wsaved(get_thread_wsaved() - 1);			}		} while (window--);	}}void fault_in_user_windows(void){	struct thread_info *t = current_thread_info();	unsigned long window;	int winsize = sizeof(struct reg_window);	int bias = 0;	if (test_thread_flag(TIF_32BIT))		winsize = sizeof(struct reg_window32);	else		bias = STACK_BIAS;	flush_user_windows();	window = get_thread_wsaved();	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 __user *)sp, rwin, winsize))				goto barf;		} while (window--);	}	set_thread_wsaved(0);	return;barf:	set_thread_wsaved(window + 1);	do_exit(SIGILL);}asmlinkage long sparc_do_fork(unsigned long clone_flags,			      unsigned long stack_start,			      struct pt_regs *regs,			      unsigned long stack_size){	int __user *parent_tid_ptr, *child_tid_ptr;	clone_flags &= ~CLONE_IDLETASK;#ifdef CONFIG_COMPAT	if (test_thread_flag(TIF_32BIT)) {		parent_tid_ptr = compat_ptr(regs->u_regs[UREG_I2]);		child_tid_ptr = compat_ptr(regs->u_regs[UREG_I4]);	} else#endif	{		parent_tid_ptr = (int __user *) regs->u_regs[UREG_I2];		child_tid_ptr = (int __user *) regs->u_regs[UREG_I4];	}	return do_fork(clone_flags, stack_start,		       regs, stack_size,		       parent_tid_ptr, child_tid_ptr);}/* 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_info *t = p->thread_info;	char *child_trap_frame;#ifdef CONFIG_DEBUG_SPINLOCK	p->thread.smp_lock_count = 0;	p->thread.smp_lock_pc = 0;#endif	p->set_child_tid = p->clear_child_tid = NULL;	/* Calculate offset to stack_frame & pt_regs */	child_trap_frame = ((char *)t) + (THREAD_SIZE - (TRACEREG_SZ+STACKFRAME_SZ));	memcpy(child_trap_frame, (((struct sparc_stackf *)regs)-1), (TRACEREG_SZ+STACKFRAME_SZ));	t->flags = (t->flags & ~((0xffUL << TI_FLAG_CWP_SHIFT) | (0xffUL << TI_FLAG_CURRENT_DS_SHIFT))) |		_TIF_NEWCHILD |		(((regs->tstate + 1) & TSTATE_CWP) << TI_FLAG_CWP_SHIFT);	t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS;	t->kregs = (struct pt_regs *)(child_trap_frame+sizeof(struct sparc_stackf));	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 & _TIF_PERFCTR) {			t->user_cntd0 = t->user_cntd1 = NULL;			t->pcr_reg = 0;			t->flags &= ~_TIF_PERFCTR;		}		t->kregs->u_regs[UREG_FP] = t->ksp;		t->flags |= ((long)ASI_P << TI_FLAG_CURRENT_DS_SHIFT);		flush_register_windows();		memcpy((void *)(t->ksp + STACK_BIAS),		       (void *)(regs->u_regs[UREG_FP] + STACK_BIAS),		       sizeof(struct sparc_stackf));		t->kregs->u_regs[UREG_G6] = (unsigned long) t;		t->kregs->u_regs[UREG_G4] = (unsigned long) t->task;	} else {		if (t->flags & _TIF_32BIT) {			sp &= 0x00000000ffffffffUL;			regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;		}		t->kregs->u_regs[UREG_FP] = sp;		t->flags |= ((long)ASI_AIUS << TI_FLAG_CURRENT_DS_SHIFT);		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;	if (clone_flags & CLONE_SETTLS)		t->kregs->u_regs[UREG_G7] = regs->u_regs[UREG_I3];	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 | CLONE_UNTRACED),			     "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){	/* Only should be used for SunOS and ancient a.out	 * SparcLinux binaries...  Not worth implementing.	 */	memset(dump, 0, sizeof(struct user));}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 = current_thread_info()->fpregs;	unsigned long fprs = current_thread_info()->fpsaved[0];	if (test_thread_flag(TIF_32BIT)) {		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_info()->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_info()->xfsr[0];			fpregs->pr_gsr = current_thread_info()->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 __user *)regs->u_regs[base + UREG_I0]);	error = PTR_ERR(filename);	if (IS_ERR(filename))		goto out;	error = do_execve(filename,			  (char __user * __user *)			  regs->u_regs[base + UREG_I1],			  (char __user * __user *)			  regs->u_regs[base + UREG_I2], regs);	putname(filename);	if (!error) {		fprs_write(0);		current_thread_info()->xfsr[0] = 0;		current_thread_info()->fpsaved[0] = 0;		regs->tstate &= ~TSTATE_PEF;		current->ptrace &= ~PT_DTRACE;	}out:	return error;}unsigned long get_wchan(struct task_struct *task){	unsigned long pc, fp, bias = 0;	unsigned long thread_info_base;	struct reg_window *rw;        unsigned long ret = 0;	int count = 0; 	if (!task || task == current ||            task->state == TASK_RUNNING)		goto out;	thread_info_base = (unsigned long) task->thread_info;	bias = STACK_BIAS;	fp = task->thread_info->ksp + bias;	do {		/* Bogus frame pointer? */		if (fp < (thread_info_base + sizeof(struct thread_info)) ||		    fp >= (thread_info_base + THREAD_SIZE))			break;		rw = (struct reg_window *) fp;		pc = rw->ins[7];		if (!in_sched_functions(pc)) {			ret = pc;			goto out;		}		fp = rw->ins[6] + bias;	} while (++count < 16);out:	return ret;}

⌨️ 快捷键说明

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