首页 > 解决方案 > Linux 更改 IDT,如何读取偏移量?

问题描述

我正在尝试编辑 linex 内核以更改 IDT,因此我编写了以下帮助功能:

#include <asm/desc.h>

unsigned long my_get_gate_offset(gate_desc *gate) {
    unsigned long res = 0;
    return result;
}

res下面的方式怎么填写?

低 16 位应该得到offset_low,中间 16offset_middle位和高 32 位得到offset_high如何在 C 中完成?

加上我怎样才能到达offset_lowoffset_middleoffset_high?它们被声明为gate_structnot ingate_desc

标签: clinuxlinux-kerneloperating-systemoffset

解决方案


已经有一个功能gate_offset可以完全满足您的要求:

static inline unsigned long gate_offset(const gate_desc *g)
{
#ifdef CONFIG_X86_64
    return g->offset_low | ((unsigned long)g->offset_middle << 16) |
        ((unsigned long) g->offset_high << 32);
#else
    return g->offset_low | ((unsigned long)g->offset_middle << 16);
#endif
}

推荐阅读