page对保护的作用
昨天看了些page的东西,开眼界了。赶紧总结记下来,可别忘了。
Page Hardware Protection Scheme:
在页表项中的后12位,具体可看intel documentation,这里只说比较酷的跟用户有关的几个位。
User/Supervisor ------ When this flag is 0, the page can be addressed only when the CPL is less than 3 (this means, for Linux, when the processor is in Kernel Mode). When the flag is 1, the page can always be addressed.
Read/Write ----- If the Read/Write flag of a Page Directory or Page Table entry is equal to
0, the corresponding Page Table or page can only be read; otherwise it can be read and
written.
这里便想起了,
1 以前写的程序,会对read-only data 进行写操作,便会产生segmentation fault.这里估计就是把read-only data放到了一个read-only page里面了。
2 还有如果对数组a[100]不断的进行写操作,也许当到index=1000时候,才会报segmentation fault。这是因为之前还是一直在read-write page里面操作,后来出了这个page了。(要么这个page不允许写,要么这个page的内存还没有申请,所以page fault了。)