Friday, July 23, 2010

Generating SIGILL and Performance Improvements

This post is about two weeks late. I'll come to what I did in that period in a later post.

Until now the patching phase involved replacing the instruction to be patched with an instruction which generated a SIGTRAP. This is neither desirable nor practical for three reasons:
  • The entire mono code-base essentially becomes un-debuggable; a user generated SIGTRAP completely throws GDB off the guard, even when not explicitly using breakpoints.
  • The soft-debugger will (probably) be switching to generating a SIGTRAP instead of a SIGSEGV soon. This will become very difficult if safe points continue to use SIGTRAP.
  • The current solution is a gross, ugly hack.
A better idea was, as Kumpera pointed out, to insert code that generates a SIGILL. This can be done with the two byte instruction sequence 0x0F 0x04 (or any of the other possible invalid byte sequences).

A few trivial details, like inserting a NOP after single byte instructions which may be a safe point (which, on AMD64, is only RET) had to be taken care of.

Independently of changing the SIGTRAP to a SIGILL, I made some basic improvements in my code, the result being a small (~ 3 %) improvement in Pystones.

I've forked the mono repository on GitHub (http://github.com/sanjoy/mono) which now hosts most of my (stable) work. - I should be able to get my work done at a much faster pace now. Hopefully this will get me some public review too.