[x86_64] code patching atomicity
Commit a49d8ab6 added a naive code patching mechanism to the JIT compiler - it simply rewrites the code array. This is problematic as it leaves the instruction in an incoherent state before the instruction is completely overwritten.
One solution to this is to patch the first byte as INT3
. The compiler then patches the rest bytes before it patches the first byte into expected instruction. If the patching is happening, and the instruction gets executed, it triggers a INT3
trap, and the execution will trap into signal handler with SIGSEGV
. The signal handler will check if current instruction is INT3
(0xCD
); if so, it sets back the program counter, and re-execute the instruction. Thus the execution will not proceed unless the patching is finished.
Once I start implementing a signal handler for Zebu, I will implement this.