/* Set an IDT entry. If the entry is part of the current IDT, then also update Xen. */ static void xen_write_idt_entry(gate_desc *dt, int entrynum, const gate_desc *g) { unsigned long p = (unsigned long)&dt[entrynum]; unsigned long start, end; preempt_disable(); start = __get_cpu_var(idt_desc).address; end = start + __get_cpu_var(idt_desc).size + 1; xen_mc_flush(); native_write_idt_entry(dt, entrynum, g); if (p >= start && (p + 8) <= end) { struct trap_info info[2]; info[1].address = 0; if (cvt_gate_to_trap(entrynum, g, &info[0])) if (HYPERVISOR_set_trap_table(info)) BUG(); } preempt_enable(); }
long xen_set_trap_table(trap_info_t *table) { long err; if ((err = HYPERVISOR_set_trap_table(table)) != 0) { /* * X_EFAULT: bad address * X_EPERM: bad selector */ panic("xen_set_trap_table(%p): error %d", (void *)table, -(int)err); } return (err); }
/* Load a new IDT into Xen. In principle this can be per-CPU, so we hold a spinlock to protect the static traps[] array (static because it avoids allocation, and saves stack space). */ static void xen_load_idt(const struct desc_ptr *desc) { static DEFINE_SPINLOCK(lock); static struct trap_info traps[257]; spin_lock(&lock); __get_cpu_var(idt_desc) = *desc; xen_convert_trap_info(desc, traps); xen_mc_flush(); if (HYPERVISOR_set_trap_table(traps)) BUG(); spin_unlock(&lock); }
void trap_fini(void) { HYPERVISOR_set_trap_table(NULL); }
void trap_init(void) { HYPERVISOR_set_trap_table(trap_table); }