Page 1 of 1

How to find if an interrupt generated by the program or not?

Posted: Wed Sep 20, 2017 10:24 am
by Coconut9
Is there an fast way to find if an interrupt has been generated by the program, the cpu or the LOCAL APIC?
I thought to "pop" the first stack value and test if the point that the value points (program EIP) is equal to 0xCD (int instruction in binary).
Do there exist also a way to block code that runs on ring 3 execute the specific interrupt (if do to generate #GP)?

Re: How to find if an interrupt generated by the program or

Posted: Wed Sep 20, 2017 12:36 pm
by Korona
If you're using the local APIC, you can check its ISR register to see if the interrupt is hardware generated. You can also do that for the legacy PIC, however it is not advisable to do so, as reads from the PIC need to go through the system bus and chipset and are much slower than reads from the APIC.

Checking the instruction is not sound as an hardware IRQ might trigger at an "int" instruction boundary.

The IDT has bits that determine the privilege level that is require to invoke each vector using the "int" instruction. The CPU itself only generates faults (i.e. vector number < 32).