Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does hardware and compiler deal with an x86 instruction that crosses into a non-executable page?

Unlike (most) RISC arch, x86 instructions have variable length. The start/end of an instruction doesn't have to aligned. If the compiler doesn't one instruction could be just lying across the page margin.

Assume that if the first byte of an instruction is at the last byte of a page, which is marked as executable. The rest bytes of the instruction are at the second page, which is marked as non-executable.

In such case, what will happen in the CPU when the execution reaches this instruction?

Does compiler need to care such cases?

like image 619
wuxb Avatar asked Jul 12 '11 05:07

wuxb


1 Answers

Hardware will (should, haven't tested) generate a GPF.

Compiler shouldn't care.

like image 171
ninjalj Avatar answered Oct 09 '22 13:10

ninjalj