On-the-fly patching of executable code includes placing a block of
modified instructions in memory, identifying a block of code to be
patched, storing instructions to be patched from the block of code to be
patched in a storage location, change the instructions to be patched to
mark instructions, and adding a jump to the block of modified
instructions in the block of code. Prior to the placing and the
identifying steps, a write flag for a page in memory where the block of
code to be patched is located is set to allow writes, and interrupts are
masked. The instructions are replaced in reverse order. The mark
instructions are the same length, in bytes, as the instructions to be
patched. The modified instructions include a resolver to determine a
number of instructions of the block of code to be patched that had
already been executed.