Runtime Patch Redirection for Restart-Free Defect Fixing
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing programs face defects that require correction without suspending operation, affecting performance and efficiency.
Innovation Solution
A patch execution method and apparatus that inserts an exception instruction into a program function, modifying it to a jump instruction to access a patch function without kernel dependence, allowing patching without restarting.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If the program is suspended to fix the defect, then the defect can be corrected, but performance of the program and running efficiency are affected
Solution Approach 1:
The patch function is prepared in advance and stored in a patch area before the program runs. The exception instruction is inserted beforehand to enable future patching without program suspension. This preliminary preparation allows defects to be fixed on-demand without affecting program performance during normal operation.
2Adaptability or versatility
If an exception instruction is inserted to suspend threads, then all threads accessing the original function are suspended, but there is no need to trap into an operating system kernel
Solution Approach 1:
The patent extracts the thread suspension mechanism from the operating system kernel and implements it directly in user space through exception instructions inserted in the program code. This removes dependency on kernel trapping mechanisms and enables patching in environments where kernel access is restricted or unavailable.
Solution Approach 2:
The exception instruction acts as an intermediary mechanism between the patching system and thread execution. Instead of directly interacting with the operating system kernel to suspend threads, the exception instruction serves as a self-contained mediator that suspends threads locally within the program, eliminating kernel dependency.
3Reliability
If the exception instruction is modified to a jump instruction, then threads jump to the patch area to execute the patch function, but the jump distance is limited
Solution Approach 1:
The patent segments the patching process into two parts: a near patch area within jump distance that can be directly accessed, and a far patch area that requires an intermediate trampoline function. This segmentation allows the system to handle both short and long distance patches reliably while managing the limitations of jump instruction distance.
Solution Approach 2:
When the patch area is beyond direct jump distance, the patent introduces a trampoline function as an intermediary. The jump instruction jumps to the trampoline, which then performs another jump to the actual patch area. This intermediary mechanism overcomes the jump distance limitation while maintaining reliable patch execution.
Data Source
Figure 1
Figure 2
Figure 3~4(a)
AI summary
This application provides a patch execution method and apparatus. The method includes: 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. In this way, a defect in a to-be-patched original function in a program can be fixed by using a patch function. In addition, the program can be patched without restarting the program, thereby improving program execution efficiency and patching efficiency.