[X86] Support 'interrupt' attribute for x86


[X86] Support 'interrupt' attribute for x86
This attribute may be attached to a function definition and instructs the backend to generate appropriate function entry/exit code so that
it can be used directly as an interrupt handler.
The IRET instruction, instead of the RET instruction, is used to return from interrupt or exception handlers. All registers, except for the EFLAGS register which is restored by the IRET instruction, are preserved by the compiler.
Any interruptible-without-stack-switch code must be compiled with -mno-red-zone since interrupt handlers can and will, because of the hardware design, touch
the red zone.

interrupt handler must be declared with a mandatory pointer argument:
struct interrupt_frame;

attribute ((interrupt))
void f (struct interrupt_frame *frame) {


and user must properly define the structure the pointer pointing to.

exception handler:

The exception handler is very similar to the interrupt handler with a different mandatory function signature:
#ifdef x86_64
typedef unsigned long long int uword_t;
typedef unsigned int uword_t;

struct interrupt_frame;

attribute ((interrupt))
void f (struct interrupt_frame *frame, uword_t error_code) {


and compiler pops the error code off stack before the IRET instruction.

The exception handler should only be used for exceptions which push an error code and all other exceptions must use the interrupt handler.
The system will crash if the wrong handler is used.
Differential Revision: http://reviews.llvm.org/D15709


ABataevJan 14 2016, 8:06 PM
Differential Revision
D15709: [X86] Support 'interrupt' attribute for x86
rL257866: [tsan] Store the pointer to ThreadState in TLS slot on Android.