简体   繁体   中英

Root Has Segfault Executing RDMSR Assembly Code

I would like to read msr 0x19a (IA32_CLOCK_MODULATIOn) directly from C code WITH root privilege. However, I get the following segfault error.

a.out[27843] general protection ip:40053b sp:7fffefc38020 error:0 in a.out[400000+1000]

Does anyone know whether this way of calling rdmsr is a viable option?

Thanks in advance!

#include <stdio.h>
#define __init

typedef unsigned uint32_t;
static int __init test3_init(void)
{
     uint32_t hi,lo;
     hi=0x0; lo=0x0;
     asm volatile("mov $0x19a,%ecx");
     asm volatile("rdmsr":"=a"(lo),"=d"(hi));
     printf("exit_readmsr: hi=%08x lo=%08x\n",hi,lo);
     return 0;
 }

 int main(void)
 {                                          
      return test3_init();                      
 }

BTW, the code is extract from this answer.

该指令必须在特权级别0执行。换句话说,您必须在内核内部。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM