Segfault when invlpg instruction is called

 ̄綄美尐妖づ 提交于 2019-12-12 21:40:28

问题


I am trying to implement tlb flush function. For flushing I use INVLPG instruction, but unfortunately it always cause segmentation fault. Could you help me with this issue?

Here is the code:

#include "stdlib.h"

inline void tlb_flush_entry(int *m) 
{
    asm volatile ("invlpg %0"::"m"(*m):"memory");
}

int main(int argc, char **argv)
{
    int *memory = (int *)malloc(100);
    tlb_flush_entry(memory);
}

回答1:


The SIGSEGV happens because INVLPG is a privileged instruction and can only be called out of kernel code. This means you can't evict a userspace page out of the TLB that way. However I wrote a litte kernel module demonstrating the usage of invlpg: How to use INVLPG on x86-64 architecture?



来源:https://stackoverflow.com/questions/13253498/segfault-when-invlpg-instruction-is-called

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