Should I leave the error code on the stack for exceptions that put the error code there?
As already mentioned, you should do the following:
pop %eax /* Do something with %eax */ iret
Or if you want to ignore the error code:
add $4, %esp iret
If you do not, iret interprets the error code as a new CS, and you will probably get general protection, as indicated in: Why does iret from the page error handler generate interrupt 13 (general protection error) and error code 0x18?
The minimal work with the handler of this page that I created to illustrate this. Try commenting on pop and see how it explodes.
Compare the above with a split error exception that should not cause the stack.
Please note that if you just int $14 , an extra byte will not be pressed: this only happens with the actual exception.
Intel Programming Guide Volume Guide 3 - 325384-056US September 2015 Table 6-1. The "Protected mode excluded and interrupted modes" column "Error code" contains a list of interrupts that cause the error code or not.
38.9.2.2 "Page Error Error Codes" explains what the error means.
The best way to deal with this is to introduce a dummy error code 0 on the stack for interrupts that do not do this to make things the same. The James Molloy tutorial does just that .
The Linux 4.2 kernel seems to do something similar. In 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 in the same file as:
.ifeq \has_error_code pushq $-1 /* ORIG_RAX: no syscall to restart */ .endif
which clicks when has_error_code=0 .
Ciro Santilli ๅ
ๅญ ้ฒ ๅฎช ๅ
ญๅ ไบไปถ ๆณ่ฝฎๅ
source share