Rewritten self-patching

The self patching routine has been rewritten in a more secure way.
The final test on kernel 3.5.0-23 have been passed.
The code has been cleaned up a while, and we have started writing
some correctness tests.