Execute RDMSR and WRMSR instructions from C/C++ code

那年仲夏 提交于 2019-11-27 15:25:29

问题


I need to control C-State configuration. Specifically, I'd probably like to execute the following asm code:

__asm
{
    rdmsr
    and eax, 0x00
    or eax, 0x01
    wrmsr
}

Currently, I got this exception on rdmsr line:

Unhandled exception at 0x00e3139e in MessWithCStates.exe: 0xC0000096: Privileged instruction.

How can I (permanently) elevate priviliges of my app so it could execute the code above? I use VS 2010.

NOTE: It is possible without writing a kernel-mode driver. See R/W Everything.


回答1:


Chances are, you are running this code on an x86 processor within Ring 3. You do not have the privileges to execute this command. Period. This is a hardware limitation. The only way to execute that instruction is to go into Ring 0 and chances are, your OS won't let you do that. You will need to write a kernel-mode driver to accomplish this.

Edit: http://faydoc.tripod.com/cpu/rdmsr.htm has more info.



来源:https://stackoverflow.com/questions/5875778/execute-rdmsr-and-wrmsr-instructions-from-c-c-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!