Function Header Hot Patching Without Program Suspension
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods to fix defects in programs require suspension, affecting performance and efficiency.
Innovation Solution
A patch execution method that inserts an exception instruction into a function header, modifying it to a jump instruction to access a patch function without restarting the program, allowing threads to be suspended and redirected without kernel dependency.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If the program is suspended to fix the defect, then the defect can be corrected, but the performance and running efficiency of the program are affected
Solution Approach 1:
The patch function is prepared in advance and stored in the patch area before the defect needs to be fixed. The exception instruction is inserted beforehand to enable future redirection. When the defect needs correction, the patch is already ready and can be activated without suspending the running program, thus maintaining execution efficiency while ensuring defect correction.
2Reliability
If the program is restarted to apply the patch, then the defect can be fixed, but the running efficiency and execution efficiency are reduced
Solution Approach 1:
An intermediate mechanism is introduced: the exception instruction acts as a mediator between the original function and the patch function. When activated, this instruction redirects control flow to the patch area without requiring program restart. This intermediary mechanism enables hot-patching, fixing defects while avoiding the time loss associated with restarting the program.
3Ease of operation
If an exception instruction is inserted into the function header, then threads can be suspended and redirected to the patch function, but the complexity of the patching process increases
Solution Approach 1:
The exception handling mechanism is extracted from the normal execution flow and placed in a dedicated patch area. The exception instruction is inserted only at the function header entry point, separating the patching logic from the main program code. This extraction simplifies the overall structure by concentrating patching functionality in a specific location, making the process more manageable despite the added capability.
4Adaptability or versatility
If the patch function is stored in the patch area with different address, then the original function can be modified, but the address mapping and jump instruction generation become more complex
Solution Approach 1:
The manual address mapping process is replaced with automated calculation. The system automatically computes the offset between the original function address and the patch function address, and generates the appropriate jump instruction with the correct target address. This substitution of automated computation for manual address management reduces the complexity of address mapping while maintaining the ability to modify functions at different addresses.
Data Source
AI summary
A patch execution method is provided, including: obtaining a first patch function, and storing the first patch function in a patch area, where the first patch function is used to modify a first original function in a program, an address of the first original function is a first address, and an address of the first patch function is a second address; inserting an exception instruction before a first instruction in the first original function, where the exception instruction is used by a thread to suspend execution of an instruction in the first original function after execution advances to the exception instruction; and modifying the exception instruction to a jump instruction based on the first address and the second address, where the jump instruction is used by the thread to jump to the patch area when the first original function is accessed, to execute an instruction in the first patch function.


