Thread-Local Variable Patching Without Process Suspension
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods for fixing defects in processes often require suspension, which affects performance and running speed.
Innovation Solution
A patch execution method that invokes thread-local variables in processes and dynamic libraries by using a Global Offset Table (GOT) to update offsets and module IDs, allowing for defect fixes without suspending the process.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If the process is suspended to fix the defect, then the defect can be corrected, but the performance and running speed of the process are affected
Solution Approach 1:
The patch file is prepared in advance with a GOT structure containing offset and module ID fields. The offset is pre-calculated based on the thread-local variable's position in the dynamic library, and the module ID is pre-set to identify the target dynamic library. This preliminary preparation enables the patch to be applied without suspending the process, as all necessary information is already in place for immediate execution.
2Reliability
If the process is suspended to apply the patch, then the defect can be fixed, but the process execution time is increased
Solution Approach 1:
The GOT (Global Offset Table) serves as an intermediary structure between the patch file and the thread-local variable in the dynamic library. The GOT contains the offset and module ID that mediate the connection, allowing the patch to locate and modify the thread-local variable without direct process suspension. This intermediary mechanism enables seamless patch application during process execution.
3Device complexity
If the patch file directly references the thread-local variable, then the patch can be simple, but it cannot locate variables in dynamic libraries with changing addresses
Solution Approach 1:
The patch file's GOT is segmented into distinct fields: the offset field and the module ID field. This segmentation allows each field to serve a specific function - the offset locates the variable within the dynamic library's address space, while the module ID identifies the target dynamic library. This structured segmentation enables the patch to adapt to dynamic libraries with changing addresses while maintaining a manageable patch structure.
Solution Approach 2:
The GOT uses changeable parameters (offset and module ID) that can be updated based on the dynamic library's loading address. When the dynamic library is loaded at a different address, the offset parameter is recalculated to reflect the new position of the thread-local variable, while the module ID parameter identifies the library. This parameter-based approach allows the patch to adapt to address changes without requiring a complete patch redesign.
Data Source
Figure 1
Figure 2
Figure 3A
AI summary
This application provides a patch execution method and apparatus. The method includes: obtaining a patch file, where the patch file is used to fix a defect in a first process, and a first thread-local variable is referenced in the patch file; creating a GOT in the patch file, where the GOT includes a first entry and a second entry; learning that an offset of the first thread-local variable is a first offset and a module ID of a module in which the first thread-local variable is located is a first ID; updating the first offset and the first ID to the GOT to obtain an updated patch file; running the updated patch file and obtaining an address of the first thread-local variable by using a first function, where the first function obtains the address of the first thread-local variable through the first offset and the first ID in the GOT; and invoking the first thread-local variable through the address of the first thread-local variable. Through this method, the patch file can invoke a thread-local variable in a process and a thread-local variable in a dynamic library.