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

📄 process.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	al = (regs->regs[35]) & 0xffffffff;	bh = (regs->regs[36]) >> 32;	bl = (regs->regs[36]) & 0xffffffff;	ch = (regs->regs[37]) >> 32;	cl = (regs->regs[37]) & 0xffffffff;	printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[38]) >> 32;	al = (regs->regs[38]) & 0xffffffff;	bh = (regs->regs[39]) >> 32;	bl = (regs->regs[39]) & 0xffffffff;	ch = (regs->regs[40]) >> 32;	cl = (regs->regs[40]) & 0xffffffff;	printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[41]) >> 32;	al = (regs->regs[41]) & 0xffffffff;	bh = (regs->regs[42]) >> 32;	bl = (regs->regs[42]) & 0xffffffff;	ch = (regs->regs[43]) >> 32;	cl = (regs->regs[43]) & 0xffffffff;	printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[44]) >> 32;	al = (regs->regs[44]) & 0xffffffff;	bh = (regs->regs[45]) >> 32;	bl = (regs->regs[45]) & 0xffffffff;	ch = (regs->regs[46]) >> 32;	cl = (regs->regs[46]) & 0xffffffff;	printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[47]) >> 32;	al = (regs->regs[47]) & 0xffffffff;	bh = (regs->regs[48]) >> 32;	bl = (regs->regs[48]) & 0xffffffff;	ch = (regs->regs[49]) >> 32;	cl = (regs->regs[49]) & 0xffffffff;	printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[50]) >> 32;	al = (regs->regs[50]) & 0xffffffff;	bh = (regs->regs[51]) >> 32;	bl = (regs->regs[51]) & 0xffffffff;	ch = (regs->regs[52]) >> 32;	cl = (regs->regs[52]) & 0xffffffff;	printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[53]) >> 32;	al = (regs->regs[53]) & 0xffffffff;	bh = (regs->regs[54]) >> 32;	bl = (regs->regs[54]) & 0xffffffff;	ch = (regs->regs[55]) >> 32;	cl = (regs->regs[55]) & 0xffffffff;	printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[56]) >> 32;	al = (regs->regs[56]) & 0xffffffff;	bh = (regs->regs[57]) >> 32;	bl = (regs->regs[57]) & 0xffffffff;	ch = (regs->regs[58]) >> 32;	cl = (regs->regs[58]) & 0xffffffff;	printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[59]) >> 32;	al = (regs->regs[59]) & 0xffffffff;	bh = (regs->regs[60]) >> 32;	bl = (regs->regs[60]) & 0xffffffff;	ch = (regs->regs[61]) >> 32;	cl = (regs->regs[61]) & 0xffffffff;	printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->regs[62]) >> 32;	al = (regs->regs[62]) & 0xffffffff;	bh = (regs->tregs[0]) >> 32;	bl = (regs->tregs[0]) & 0xffffffff;	ch = (regs->tregs[1]) >> 32;	cl = (regs->tregs[1]) & 0xffffffff;	printk("R62 : %08Lx%08Lx T0  : %08Lx%08Lx T1  : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->tregs[2]) >> 32;	al = (regs->tregs[2]) & 0xffffffff;	bh = (regs->tregs[3]) >> 32;	bl = (regs->tregs[3]) & 0xffffffff;	ch = (regs->tregs[4]) >> 32;	cl = (regs->tregs[4]) & 0xffffffff;	printk("T2  : %08Lx%08Lx T3  : %08Lx%08Lx T4  : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	ah = (regs->tregs[5]) >> 32;	al = (regs->tregs[5]) & 0xffffffff;	bh = (regs->tregs[6]) >> 32;	bl = (regs->tregs[6]) & 0xffffffff;	ch = (regs->tregs[7]) >> 32;	cl = (regs->tregs[7]) & 0xffffffff;	printk("T5  : %08Lx%08Lx T6  : %08Lx%08Lx T7  : %08Lx%08Lx\n",	       ah, al, bh, bl, ch, cl);	/*	 * If we're in kernel mode, dump the stack too..	 */	if (!user_mode(regs)) {		extern void show_task(unsigned long *sp);		unsigned long sp = regs->regs[15] & 0xffffffff;		show_task((unsigned long *)sp);	}}struct task_struct * alloc_task_struct(void){	/* Get task descriptor pages */	return (struct task_struct *)		__get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE));}void free_task_struct(struct task_struct *p){	free_pages((unsigned long) p, get_order(THREAD_SIZE));}/* * Create a kernel thread *//* * 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. */int arch_kernel_thread(int (*fn)(void *), void * arg, unsigned long flags){	/* A bit less processor dependent than older sh ... */	unsigned int reply;static __inline__ _syscall2(int,clone,unsigned long,flags,unsigned long,newsp)static __inline__ _syscall1(int,exit,int,ret)	reply = clone(flags | CLONE_VM, 0);	if (!reply) {		/* Child */		reply = exit(fn(arg));	}	return reply;}/* * Free current thread data structures etc.. */void exit_thread(void){	/* See arch/sparc/kernel/process.c for the precedent for doing this -- RPC.		   The SH-5 FPU save/restore approach relies on last_task_used_math	   pointing to a live task_struct.  When another task tries to use the	   FPU for the 1st time, the FPUDIS trap handling (see	   arch/sh64/kernel/fpu.c) will save the existing FPU state to the	   FP regs field within last_task_used_math before re-loading the new	   task's FPU state (or initialising it if the FPU has been used	   before).  So if last_task_used_math is stale, and its page has already been	   re-allocated for another use, the consequences are rather grim. Unless we	   null it here, there is no other path through which it would get safely	   nulled. */#ifndef CONFIG_NOFPU_SUPPORT	if (last_task_used_math == current) {		last_task_used_math = NULL;	}#endif}void flush_thread(void){	/* As far as I can tell, this function isn't actually called from anywhere.	   So why does it have a non-null body for most architectures?? -- RPC */	/* Look closer, this is used in fs/exec.c by flush_old_exec() which is	   used by binfmt_elf and friends to remove leftover traces of the	   previously running executable. -- PFM */#ifndef CONFIG_NOFPU_SUPPORT	if (last_task_used_math == current) {		last_task_used_math = NULL;	}#endif	/* if we are a kernel thread, about to change to user thread,         * update kreg          */	if(current->thread.kregs==&fake_swapper_regs) {          current->thread.kregs=              ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);	}}void release_thread(struct task_struct *dead_task){	/* do nothing */}/* Fill in the fpu structure for a core dump.. */int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu){#ifndef CONFIG_NOFPU_SUPPORT	int fpvalid;	struct task_struct *tsk = current;	fpvalid = tsk->used_math;	if (fpvalid) {		if (current == last_task_used_math) {			grab_fpu();			fpsave(&tsk->thread.fpu.hard);			release_fpu();			last_task_used_math = 0;			regs->sr |= SR_FD;		}				memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));	}	return fpvalid;#else	return 0; /* Task didn't use the fpu at all. */#endif}asmlinkage void ret_from_fork(void);int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,		unsigned long unused,		struct task_struct *p, struct pt_regs *regs){	struct pt_regs *childregs;	unsigned long long se;			/* Sign extension */#ifndef CONFIG_NOFPU_SUPPORT	if(last_task_used_math == current) {				grab_fpu();		fpsave(&current->thread.fpu.hard);		release_fpu();		last_task_used_math = NULL;		regs->sr |= SR_FD;	}#endif	childregs = ((struct pt_regs *)(THREAD_SIZE + (unsigned long) p)) - 1;	*childregs = *regs;	if (user_mode(regs)) {		childregs->regs[15] = usp;		p->thread.kregs = childregs;	} else {		childregs->regs[15] = (unsigned long)p+THREAD_SIZE;		p->thread.kregs = &fake_swapper_regs;	}	childregs->regs[9] = 0; /* Set return value for child */	childregs->sr |= SR_FD; /* Invalidate FPU flag */	p->thread.sp = (unsigned long) childregs;	p->thread.pc = (unsigned long) ret_from_fork;	/*	 * Sign extend the edited stack.         * Note that thread.pc and thread.pc will stay	 * 32-bit wide and context switch must take care	 * of NEFF sign extension.	 */      	se = childregs->regs[15];	se = (se & NEFF_SIGN) ? (se | NEFF_MASK) : se;	childregs->regs[15] = se;	return 0;}/* * fill in the user structure for a core dump.. */void dump_thread(struct pt_regs * regs, struct user * dump){	dump->magic = CMAGIC;	dump->start_code = current->mm->start_code;	dump->start_data  = current->mm->start_data;	dump->start_stack = regs->regs[15] & ~(PAGE_SIZE - 1);	dump->u_tsize = (current->mm->end_code - dump->start_code) >> PAGE_SHIFT;	dump->u_dsize = (current->mm->brk + (PAGE_SIZE-1) - dump->start_data) >> PAGE_SHIFT;	dump->u_ssize = (current->mm->start_stack - dump->start_stack +			 PAGE_SIZE - 1) >> PAGE_SHIFT;	/* Debug registers will come here. */	dump->regs = *regs;	dump->u_fpvalid = dump_fpu(regs, &dump->fpu);}/* *	switch_to(x,y) should switch tasks from x to y. * */struct task_struct * __switch_to(struct task_struct *prev, struct task_struct *next){	/*	 * Restore the kernel mode register	 *   	KCR0 =  __c17	 */	asm volatile("putcon	%0, " __c17 "\n"		     : /* no output */		     :"r" (next));	return prev;}asmlinkage int sys_fork(unsigned long r2, unsigned long r3,			unsigned long r4, unsigned long r5,			unsigned long r6, unsigned long r7,			struct pt_regs *pregs){	return do_fork(SIGCHLD, pregs->regs[15], pregs,0);}asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,			 unsigned long r4, unsigned long r5,			 unsigned long r6, unsigned long r7,			 struct pt_regs *pregs){	if (!newsp)		newsp = pregs->regs[15];	return do_fork(clone_flags, newsp, pregs,0);}/* * This is trivial, and on the face of it looks like it * could equally well be done in user mode. * * Not so, for quite unobvious reasons - register pressure. * In user mode vfork() cannot have a stack frame, and if * done by calling the "clone()" system call directly, you * do not have enough call-clobbered registers to hold all * the information you need. */asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,			 unsigned long r4, unsigned long r5,			 unsigned long r6, unsigned long r7,			 struct pt_regs *pregs){	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs,0);}/* * sys_execve() executes a new program. */asmlinkage int sys_execve(char *ufilename, char **uargv,			  char **uenvp, unsigned long r5,			  unsigned long r6, unsigned long r7,			  struct pt_regs *pregs){	int error;	char *filename;	lock_kernel();	filename = getname(ufilename);	error = PTR_ERR(filename);	if (IS_ERR(filename))		goto out;	error = do_execve(filename, uargv, uenvp, pregs);	if (error == 0)		current->ptrace &= ~PT_DTRACE;	putname(filename);out:	unlock_kernel();	return error;}/* * These bracket the sleeping functions.. */extern void scheduling_functions_start_here(void);extern void scheduling_functions_end_here(void);extern void interruptible_sleep_on(wait_queue_head_t *q);#define first_sched	((unsigned long) scheduling_functions_start_here)#define mid_sched	((unsigned long) interruptible_sleep_on)#define last_sched	((unsigned long) scheduling_functions_end_here)unsigned long get_wchan(struct task_struct *p){	unsigned long schedule_frame;	unsigned long pc;	if (!p || p == current || p->state == TASK_RUNNING)		return 0;	/*	 * The same comment as on the Alpha applies here, too ...	 */	pc = thread_saved_pc(&p->thread);	if (pc >= first_sched && pc < last_sched) {		schedule_frame = (long) p->thread.sp;		/* Should we unwind schedule_timeout() ? */		if (pc < mid_sched)			/* according to disasm:			**     48 bytes in case of RH toolchain		        */			schedule_frame += 48;					/*		** Unwind schedule(). According to disasm:		**    72 bytes in case of RH toolchain		** plus 304 bytes of switch_to additional frame.		*/		schedule_frame += 72 + 304;#ifdef CS_SAVE_ALL		schedule_frame += 256;#endif		/*		 * schedule_frame now according to SLEEP_ON_VAR.	 	 * Bad thing is that we have no trace of the waiting		 * address (the classical WCHAN). SLEEP_ON_VAR should		 * have saved q. From the linked list only we can't get		 * the object and first parameter is not saved on stack		 * by the ABI. The best we can tell is who called the		 * *sleep_on* by returning LINK, which is saved at		 * offset 64 on all flavours.		 */		return (unsigned long)((unsigned long *)schedule_frame)[16];	}	return pc;}/* Provide a /proc/asids file that lists out the   ASIDs currently associated with the processes.  (If the DM.PC register is   examined through the debug link, this shows ASID + PC.  To make use of this,   the PID->ASID relationship needs to be known.  This is primarily for   debugging.)   */#if defined(CONFIG_SH64_PROC_ASIDS)#include <linux/init.h>#include <linux/proc_fs.h>static intasids_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data){	int len=0;	struct task_struct *p;	read_lock(&tasklist_lock);	for_each_task(p) {		int pid = p->pid;		struct mm_struct *mm;		if (!pid) continue;		mm = p->mm;		if (mm) {			unsigned long asid, context;			context = mm->context;			asid = (context & 0xff);			len += sprintf(buf+len, "%5d : %02x\n", pid, asid);		} else {			len += sprintf(buf+len, "%5d : (none)\n", pid);		}	}	read_unlock(&tasklist_lock);	*eof = 1;	return len;}static int __init register_proc_asids(void){  create_proc_read_entry("asids", 0, NULL, asids_proc_info, NULL);  return 0;}__initcall(register_proc_asids);#endif

⌨️ 快捷键说明

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