[轉]关于CR0.WP

关于CR0.WP

我们知道CR0的WP位可以关闭内核写保护。他和页表的R/W位有关。Intel手册中的描述绕来绕去似乎一直没有说到重点。

When the processor is in supervisor mode and the WP flag in register CR0 is clear (its 
state following reset initialization), all pages are both readable and writable (write-
protection is ignored). When the processor is in user mode, it can write only to user-
mode pages that are read/write accessible. User-mode pages which are read/write or 
read-only are readable; supervisor-mode pages are neither readable nor writable 
from user mode. A page-fault exception is generated on any attempt to violate the 
protection rules.
Starting with the P6 family, Intel processors allow user-mode pages to be write-
protected against supervisor-mode access. Setting CR0.WP = 1 enables supervisor-
mode sensitivity to user-mode, write protected pages. Supervisor pages which are 
read-only are not writable from any privilege level (if CR0.WP = 1). This supervisor 
write-protect feature is useful for implementing a “copy-on-write” strategy used by 
some operating systems, such as UNIX*, for task creation (also called forking or 
spawning). When a new task is created, it is possible to copy the entire address space 
of the parent task. This gives the child task a complete, duplicate set of the parent's 
segments and pages. An alternative copy-on-write strategy saves memory space and 
time by mapping the child's segments and pages to the same segments and pages 
used by the parent task. A private copy of a page gets created only when one of the 
tasks writes to the page. By using the WP flag and marking the shared pages as read-
only, the supervisor can detect an attempt to write to a user-level page, and can copy 
the page at that time.

 

经过试验明白了WP位的作用。

WP位是Supervisor的写保护位 (CPL < 3是Supervisor)

当WP = 1时,Supervisor不能写R/W没有置位的页。

WP = 0时,Supervisor可以写任何页。

 

对于User (CPL = 3), 无论WP是什么,都不能写R/W没有置位的页。所以User无论怎么样都是二等公民。

转载于:https://www.cnblogs.com/bittorrent/p/3328238.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值