A system and method for dynamically patching code. In one embodiment, a method
includes intercepting original program instructions during execution of the program
using a software interface, determining whether associated instructions have been
cached in a code cache of the software interface and, if so, executing the cached
instructions from the code cache, if associated instructions have not been cached,
determining if the original program instructions require unavailable hardware functionality,
and dynamically replacing the original program instructions with replacement instructions
that do not require unavailable hardware functionality if it is determined that
the original program instructions require unavailable hardware functionality, the
dynamic replacing including fetching replacing instructions, storing the replacement
instructions in the code cache, and executing the replacement instructions from
the code cache.