本文介绍了调用invlpg指令时出现段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现tlb刷新功能.对于刷新,我使用INVLPG指令,但不幸的是,它始终会导致分段错误.您能帮我解决这个问题吗?

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?

这是代码:

#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);
}

推荐答案

发生SIGSEGV的原因是INVLPG是特权指令,只能从内核代码中调用.这意味着您不能以这种方式将用户空间页面逐出TLB.但是我写了一个小内核模块,演示了invlpg的用法:如何在x86-64体系结构上使用INVLPG? a>

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?

这篇关于调用invlpg指令时出现段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!