idt_table undefined! warning when compiling kernel

2019-04-15 03:39发布

问题:

I'm trying to use gate_desc *idt_table in a kernel module. The set_trap_gate() function defined in desc.h uses this pointer. In desc.h is also a definition : extern gate_desc idt_table[].

I tried different things:

  • use idt_table in my module without definition or affectation
  • affect idt_table with my (valid) idt_table address I get either an id_table undefined warning during compilation or incomplete type for idt_table.

  • creating a new var named for instance gate_desc *it = (gate_desc *)@; And copy the set_trap_gate, set_gate, write_idt_entry, pack_gate functions from sched.h to my module file (renaming them, and using it instead of idt_table). This compiles fine but when inserting my module I get an unknown symbol in module (ret -1) error. (there is no reference in my module to idt_table, and the functions I use from sched do use my variable).

I tried to see where in the files included by sched.h was defined idt_table, but couldn't find it!

Does someone know how I could use, the idt_table pointer from sched.h (affecting it with the corrct address) or create a new pointer?

回答1:

Theoretically, you could implement a non-init-section set_trap_gate() via:

void set_trap_gate(int n, void *addr)
{
    struct { uint16_t lim; struct desc_struct *idt_table; }
        __attribute__((packed)) idt;
    __asm__ ("sidt %0" : : "m"(idt) : "memory");
    _set_gate(idt.idt_table + n, 15, 0, addr);
}

But that'd be CPU-local, i.e. it's not guaranteed to modify any other IDT but the one of the CPU it's running on. Also, it might fall foul of writeprotected memory.

What exactly is it you're trying to achieve ?