Dig into IRQL

1. Introduction

-------------------------------------------------------------------------------------------------------------------
Interrupt Request Level (IRQL), is a software concept that provided by Windows, which supports an ability that management and hidden the detail of the low-level complexity of interrupt.

However, as a kernel enthusiast, security researcher, it is necessaryfor understanding what it hides?? how does it worsk?


This article are going to provide a simplest explanation for the IRQL.


2. Exception v.s. Trap v.s. Interrupt from processor perspectives

-------------------------------------------------------------------------------------------------------------------
There are so many differences between these stuff, however, they share the only characteristic is that they also are delivered by Interrupt Descriptor Table (IDT).

Exception and Trap is officially document in Intel SDM , which fixed in IDT from interrupt vector from 0 to  20 (include trap, exception.)

Exception is synchronous with instruction stream, and which is as same as interrupt, it will disable IF flag in RFLAG register.

Trap is synchronous event with instruction stream, and it will not disable IF flag in RFLAG register.

Interrupt is asynchronous, which is always fired by the external component, and delivered by LAPIC for each logical process (core)

3. Exception v.s. Trap v.s. Interrupt from kernel perspectives

-------------------------------------------------------------------------------------------------------------------
This is the main point of this article, windows kernel treats interrupt (interrupt vector 32 to 255) different from the exception and trap.

In Windows 7 x64, it always dispatch its interrupt by nt!KiInterruptDispatch, it always manipulate CR8 register before real interrupt dispatching , in Intel 64 Architecture CR8 should be mapped to APIC Task Priority Register (TPR), as shown Figure[1], In older windows, it will call a hal!HalBeginSystemInterrupt and hal!HalEndSystemInterrupt.

Figure[1]

Figure[2] 
As shown in Figure[1] , CR8 register is filled by byte ptr [rsi+5Dh], which is a IRQL stored in interrupt object (see Figure[2]) , initialized by IoConnectInterrupt function. it is significantly important for the interruptibility.

After the instruction, TPR Register is reflected also, and it could be call the interrupt callback with the expected IRQL (it should be same as the device IRQ)

TPR register will be compared when an external interrupt comes, if interrupt comes, and the priority (IRQ) is not greater TPR, it cannot be fired instantly, but pending interrupt state. That's why IRQL can be affect the interruption progress.

Figure[3]


However Exception dispatching is not affect IRQL, when the exception occurred, IRQL will not be change, but the maskable interrupt is still be block.



Comments

Popular posts from this blog

Android Kernel Development - Kernel compilation and Hello World

How does Nested-Virtualization works?

Understanding ACPI and Device Tree