Expanding on Alexey:
When some interrupts happen (but not others), they automatically push a 4 byte error code to the stack. Page fault is one of them.
This error code contains extra information about the interrupt.
Intel Manual Volume 3 System Programming Guide - 325384-056US September 2015 Table 6-1. "Protected-Mode Exceptions and Interrupts" column "Error Code" tells us exactly which interrupts push the error code, and which do not.
38.9.2.2 "Page Fault Error Codes" explains what the error means.
So you will need either:
pop %eax
/* Do something with %eax */
iret
Or if you want to ignore the error code:
add $4, %esp
iret
For a minimal example, see this page handler and try commenting out the pop
.
Compare the above with a Division error exception which does not need to pop the stack.
Note that if you do simply int $14
, no extra byte gets pushed: this only happens on the actual exception.
A neat way to deal with this is to push a dummy error code 0
on the stack for the interrupts that don't do this to make things uniform. James Molloy's tutorial does exactly that.
The Linux kernel 4.2 seems to do something similar. Under arch/x86/entry/entry64.S it models interrupts with has_error_code
:
trace_idtentry page_fault do_page_fault has_error_code=1
and then uses it on the same file as:
.ifeq \has_error_code
pushq $-1 /* ORIG_RAX: no syscall to restart */
.endif
which does the push when has_error_code=0
.
Related question: Do I have to pop the error code pushed to stack by certain exceptions before returning from the interrupt handler?