关键词不能为空

当前您在: 主页 > 英语 >

fault.c

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-13 11:10
tags:

-

2021年2月13日发(作者:描写)


/*


* linux/arch/i386/mm/fault.c


*


* Copyright (C) 1995 Linus Torvalds


*/



#include


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include




#include


#include


#include


#include



extern void die(const char *,struct pt_regs *,long);



/*


/* For unblank_screen() */


* Ugly, ugly, but the goto's result in better assembly..


*/


int __verify_write(const void * addr, unsigned long size)


{














good_area:















for (;;) {


survive:






{





int fault = handle_mm_fault(current->mm, vma, start, 1);


if (!fault)



goto bad_area;


if (!(vma->vm_flags & VM_WRITE))



size--;


size += start & ~PAGE_MASK;


size >>= PAGE_SHIFT;


start &= PAGE_MASK;


goto bad_area;


vma = find_vma(current->mm, start);


if (!vma)



goto bad_area;


if (!size)



return 1;


struct vm_area_struct * vma;


unsigned long start = (unsigned long) addr;


if (vma->vm_start > start)



goto check_stack;

































}




}


if (fault < 0)



goto out_of_memory;


if (!size)



size--;


start += PAGE_SIZE;


if (start < vma->vm_end)



continue;


break;


vma = vma->vm_next;


if (!vma || vma->vm_start != start)



goto bad_area;


if (!(vma->vm_flags & VM_WRITE))



goto bad_area;;


return 1;


check_stack:







bad_area:




out_of_memory:





if (current->pid == 1) {




current->policy |= SCHED_YIELD;


schedule();


return 0;


if (!(vma->vm_flags & VM_GROWSDOWN))



goto bad_area;


if (expand_stack(vma, start) == 0)



goto good_area;





}




}


goto survive;


goto bad_area;


extern spinlock_t timerlist_lock;



/*


* Unlock any spinlocks which will prevent us from getting the


* message out (timerlist_lock is acquired through the


* console unblank code)


*/


void bust_spinlocks(int yes)


{





spin_lock_init(&timerlist_lock);


if (yes) {



oops_in_progress = 1;


#ifdef CONFIG_SMP



#endif




} else {



int loglevel_save = console_loglevel;



global_irq_lock = 0;


/* Many serial drivers do __global_cli() */


#ifdef CONFIG_VT



#endif












oops_in_progress = 0;


/*


* OK, the message is on the console. Now we call printk()


* without oops_in_progress set so that printk will give klogd


* a poke. Hold onto your hats...



unblank_screen();




*/



/* NMI oopser may have shut




console_loglevel = 15;


the console up */





}





}


printk(


console_loglevel = loglevel_save;


void do_BUG(const char *file, int line)//


输出错误信息



{




}



asmlinkage void do_invalid_op(struct pt_regs *, unsigned long);


extern unsigned long idt;



/*


* This routine handles page faults. It determines the address,


* and the problem, and then passes it off to one of the appropriate


* routines.


*


* error_code:


*


*


*


*/


asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long


error_code)//regs


存放着异常发生时


cpu


寄存器的值



bit 0 == 0 means no page found, 1 means protection fault


bit 1 == 0 means read, 1 means write


bit 2 == 0 means kernel, 1 means user-mode


bust_spinlocks(1);


printk(


//error_code


是异常发生时,


cpu


的控制单元自动压栈给函数的,只有前三 位有意义,



0


位被清零,异常是由访 问一个不在内存中的页引起的,否则是由保护性失效引起


的。



//


保护性失效,第一位,为


0


,由读访问或执行访问引起的,否则异常是由写访问引起


< p>


//


第二位被清零,系统处于内核态,否则处于 用户态



{













/* get the address */


__asm__(


把引起缺页的页地址 存放在


struct task_struct *tsk;


struct mm_struct *mm;


struct vm_area_struct * vma;


unsigned long address;


unsigned long page;


unsigned long fixup;


int write;


siginfo_t info;


address


局部变量中













/*


* We fault-in kernel-space virtual memory on- demand. The


tsk = current;


/* It's safe to allow irq's after cr2 has been saved */


//


恢复中断


,CR2


中的值已经得到了保存



if (regs->eflags & X86_EFLAGS_IF)



local_irq_enable();














* 'reference' page table is init_.


*


* NOTE! We MUST NOT take any locks for this case. We may


* be in an interrupt or a critical region, and should


* only copy the information from the master page table,


* nothing more.


*


* This verifies that the fault happens in kernel space


* (error_code & 4) == 0, and that the fault was not a


* protection error (error_code & 1) == 0.


*/


if (address >= TASK_SIZE && !(error_code & 5))//




错误发生在内核空间




内核空间的写


/


读地址错误













/*


* If we're in an interrupt or have no user


* context, we must not take the fault..


*/


if (in_interrupt() || !mm)//


判断异常发生时


cpu


是否正在处理中断或是执行内


mm = tsk->mm;


_code = SEGV_MAPERR;//


地址没有映射到对象




goto vmalloc_fault;//


转至内核非连续空间的异常处理



核态线程







down_read(&mm-> mmap_sem);//


获取读写信号量




goto no_context;



vma = find_vma(mm, address) ;//


检查当前进程的线性区,验证该地址是否在


进程的地址空 间中








if (!vma)//


若没有这样的


VMA


,说明异常地址是在进程地 址堆栈的上方


,


非法




goto bad_area;


if (vma->vm_start <= address)//

< br>如果地址在


vma





goto good_area;


if (!(vma->vm_flags & VM_GROWSDOWN))//V M_GROWSDOWN:


向下增长


,



有栈才有这样的属性


.


不属于栈而 且又落在空洞中


,


非法

















/*


* Ok, we have a good vm_area for this memory access, so


* we can handle it..


*/


good_area:




_code = SEGV_ACCERR;//


对映射的对象没有权限



write = 0;



goto bad_area;


if (error_code & 4)//

< br>异常发生在用户态,检查


address


是否小于


regs->esp


{










}


if (expand_stack(vma, address))//


扩大栈空间




goto bad_area;


/*


* accessing the stack below %esp is always a bug.


* The


* pusha) doing post-decrement on the stack and that


* doesn't show up until later..


*/


if (address + 32 < regs->esp)



goto bad_area;

-


-


-


-


-


-


-


-



本文更新与2021-02-13 11:10,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/649660.html

fault.c的相关文章

  • 余华爱情经典语录,余华爱情句子

    余华的经典语录——余华《第七天》40、我不怕死,一点都不怕,只怕再也不能看见你——余华《第七天》4可是我再也没遇到一个像福贵这样令我难忘的人了,对自己的经历如此清楚,

    语文
  • 心情低落的图片压抑,心情低落的图片发朋友圈

    心情压抑的图片(心太累没人理解的说说带图片)1、有时候很想找个人倾诉一下,却又不知从何说起,最终是什么也不说,只想快点睡过去,告诉自己,明天就好了。有时候,突然会觉得

    语文
  • 经典古训100句图片大全,古训名言警句

    古代经典励志名言100句译:好的药物味苦但对治病有利;忠言劝诫的话听起来不顺耳却对人的行为有利。3良言一句三冬暖,恶语伤人六月寒。喷泉的高度不会超过它的源头;一个人的事

    语文
  • 关于青春奋斗的名人名言鲁迅,关于青年奋斗的名言鲁迅

    鲁迅名言名句大全励志1、世上本没有路,走的人多了自然便成了路。下面是我整理的鲁迅先生的名言名句大全,希望对你有所帮助!当生存时,还是将遭践踏,将遭删刈,直至于死亡而

    语文
  • 三国群英单机版手游礼包码,三国群英手机单机版攻略

    三国群英传7五神兽洞有什么用那是多一个武将技能。青龙飞升召唤出东方的守护兽,神兽之一的青龙。玄武怒流召唤出北方的守护兽,神兽之一的玄武。白虎傲啸召唤出西方的守护兽,

    语文
  • 不收费的情感挽回专家电话,情感挽回免费咨询

    免费的情感挽回机构(揭秘情感挽回机构骗局)1、牛牛(化名)向上海市公安局金山分局报案,称自己为了挽回与女友的感情,被一家名为“实花教育咨询”的情感咨询机构诈骗4万余元。

    语文