A patch processing method, apparatus, and computer device
By loading patch functions in shared memory space and using a dependency function skip list, the problem of memory waste when multiple processes share dynamic libraries is solved, and efficient memory utilization is achieved.
Patent Information
- Application Number
- CN202210714252.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-22
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2042-06-22
AI Technical Summary
When multiple processes share the same dynamic library, the existing patching method requires each process to load the same patch function into its own memory space, resulting in a waste of memory space.
The patch function is loaded into the shared memory space, and calls to each process are implemented through a dependency function skip list. Only a small dependency function skip list is loaded in each process to avoid repeated loading.
It reduces memory usage, avoids memory waste, and improves memory utilization efficiency.
Smart Images

Figure CN117311770B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a patch processing method, apparatus, and computer equipment. Background Technology
[0002] Currently, multiple processes within the same operating system (OS) can use the same dynamic libraries, such as... Figure 1 As shown, libcom.so represents a dynamic library. Dynamic libraries are loaded dynamically when an application starts, typically running during system runtime. Therefore, different processes and other applications can directly use them, and the same dynamic library can be shared by multiple processes and applications. Only one copy of a dynamic library exists in the system, saving memory and improving system performance. When multiple processes use the same dynamic library, the operating system maps the code segments of the used dynamic library to the same block of physical memory to save physical memory.
[0003] Software patches are small programs released to fix vulnerabilities exposed during the use of large software systems, or they can be small programs added to add new business functions. A diagram illustrating online hot patching technology can be shown below. Figure 2 As shown, if the original function A (funcA) in process 1 needs to be patched, the patch unit A (pFuncA) in the patch package can be loaded into the memory space of process 1, and the header instruction of funcA can be modified into a jump instruction (such as jump pFuncA) so that when process 1 needs to execute funcA, it can jump to pFuncA and execute it according to the jump instruction.
[0004] Under current patching methods, if different processes involve the same patch function, each process needs to load the patch function into its own memory space. For example, if different processes use the same dynamic library, and some functions in that dynamic library need patching, each process needs to load the patch function into its own memory space. This results in a large amount of memory space being used to store the same patch function, leading to a waste of memory. Summary of the Invention
[0005] This application provides a patch processing method, apparatus, and computer device to reduce the memory space occupied by patch functions and avoid memory waste.
[0006] In a first aspect, this application provides a patch processing method, comprising: loading a patch package into the external storage hard disk of a target device, the patch package including the code of one or more patch functions and a jump list of dependent functions corresponding to a target patch function, wherein the target patch function is any one of the one or more patch functions; loading the code of the target patch function and the jump list of dependent functions corresponding to the target patch function required by a first process into the memory space of the first process, wherein the memory space occupied by the code of the target patch function is a shared memory space; obtaining the logical memory address of the dependent function of the target patch function in the memory space of the first process, and modifying the jump address corresponding to the dependent function in the jump list of the dependent function corresponding to the target patch function according to the obtained logical memory address, so that when it is necessary to execute the dependent function on which the target patch function depends, a jump is made to the jump list of dependent functions, and a jump is made to the location of the code of the dependent function according to the jump address; setting a jump instruction in the original function code in the memory space of the first process, so that when it is necessary to execute the original function code, a jump is made to execute the target patch function, wherein the original function is the function to be replaced by the target patch function.
[0007] In the above method, when loading the target patch function, it is loaded into the shared memory space, providing a basis for other processes to access the target patch function. Furthermore, the patch function typically contains dependent functions. If a jump instruction is added to the dependent function of the patch function based on the logical memory address of the dependent function in the first process, then although the target patch function is loaded into the shared memory space, other processes cannot call the target patch function because the jump address of the dependent function is the logical memory address of the first process, and the logical memory address of the dependent function in the second process is not necessarily the same as that in the first process. To solve this problem, the above embodiments of this application introduce a dependent function skip list. The target patch function is loaded into the shared memory space, while the dependent function skip list is loaded into the memory space of each process. Based on the logical memory address of the dependent function in each process, the jump address in the dependent function skip list of that process is modified, so that when it is necessary to execute the dependent function that the target patch function depends on, a jump to the dependent function skip list is made, and the jump to the location of the code of the dependent function is made according to the jump address in the dependent function skip list. According to the above method, when multiple processes involve the same patch function, the patch function only needs to be loaded into the shared memory space once. There is no need for each process to load the patch function into its own memory space separately. Each process only needs to load a small dependency function skip list to call the target patch function, thereby saving memory space.
[0008] In one possible implementation, the offsets of the target patch function's code and the dependent function skip list in the memory space of the first process are the same as their offsets in the patch package. The offsets of the target patch function and the dependent function skip list in the patch package can be determined when the patch package is generated. Therefore, jump instructions can be added to the target patch function based on these offsets during patch package generation, so that when a dependent function of the target patch function needs to be executed, a jump to the dependent function skip list is performed. During loading, the offsets of the target patch function and the dependent function skip list in the logical memory of the first process are made the same as their offsets in the patch package, thus enabling a successful jump to the dependent function skip list loaded in the first process's memory.
[0009] In one possible implementation, loading the code of the target patch function required by the first process and the corresponding jump list of dependent functions into the memory space of the first process includes: determining whether the code of the target patch function is loaded in the physical memory of the target device; if it is determined that the code of the target patch function is not loaded in the physical memory, loading the code of the target patch function into the physical memory of the target device; mapping the physical memory address occupied by the code of the target patch function to the memory space of the first process; and loading the corresponding jump list of dependent functions into the memory space of the first process. A device is configured with physical memory; however, physical memory addresses are usually not visible to the application layer, and the addresses in the program code are usually logical memory addresses for each process. When loading the target patch function and the dependent function skip list, the target device can first load them into physical memory, and then map the physical memory address to the memory space of the first process. That is, the physical memory address where the target patch function is located is mapped to the logical memory address of the first process, and the dependent function skip list is loaded according to the logical memory address of the first process. This ensures that the position offset of the target patch function and the dependent function skip list in the logical memory of the first process is the same as the position offset in the patch package.
[0010] In one possible implementation, the memory space occupied by the dependency function skip list is the exclusive memory space of the first process. Since the jump addresses in the dependency function skip list are the logical memory addresses of the dependent functions in the first process, and cannot be called by other processes, the dependency function skip list can be loaded into the exclusive memory space of the first process.
[0011] In one possible implementation, the method further includes: mapping the physical memory address occupied by the code of the target patch function to the memory space of the second process; loading the jump list of dependent functions corresponding to the target patch function into the memory space of the second process, wherein the offset of the target patch function and the jump list of dependent functions in the memory space of the second process is the same as the offset of the target patch function and the jump list of dependent functions in the memory space of the first process; obtaining the logical memory address of the dependent function of the target patch function in the memory space of the second process, and modifying the jump address corresponding to the dependent function in the memory space of the second process according to the obtained logical memory address, so that when the second process needs to execute the dependent function on which the patch function depends, it jumps to the jump list of dependent functions in the second process, and jumps to the location of the code of the dependent function in the second process according to the jump address in the jump list of dependent functions in the second process; setting a jump instruction in the original function code in the memory space of the second process, wherein the jump address corresponding to the jump instruction is the logical memory address occupied by the code of the target patch function in the second process. Because the target patch function is loaded into the shared memory space, it is easy for other processes to call the target patch function. When a second process also needs to call the target patch function, the physical memory address where the target patch function is located can be mapped to the logical memory address of the second process. The jump table of dependent functions is loaded according to the logical memory address of the first process, and the jump address in the jump table of dependent functions is modified according to the logical memory address of the dependent functions in the second process. This allows the second process to also call the target patch function and run it normally.
[0012] In one possible implementation, the patch package further includes information about the dynamic libraries to which the one or more patch functions are applicable; loading the code of the target patch function required by the first process and the corresponding dependency function skip list into the memory space of the first process includes: matching the dynamic libraries already loaded by the first process with the information about the dynamic libraries to which the patch functions are applicable, and loading the code of the successfully matched target patch functions and the corresponding dependency function skip list into the memory space of the first process. The patch package may contain multiple patch functions, and different patch functions may be to which different dynamic libraries are applicable. Therefore, information about the dynamic libraries to which the patch functions are applicable can be added to the patch package. When loading a patch function, the dynamic library corresponding to the patch function is first checked for a match with the dynamic libraries loaded by the process. If a match is found, the patch function is then loaded to avoid loading unusable patch functions.
[0013] Secondly, this application provides a patch processing apparatus, the apparatus comprising: a loading module, configured to load a patch package into the external storage of a target device, the patch package including the code of one or more patch functions and a jump list of dependent functions corresponding to the target patch function, the target patch function being any one of the one or more patch functions; loading the code of the target patch function required by a first process and the jump list of dependent functions corresponding to the target patch function into the memory space of the first process, the memory space occupied by the code of the target patch function being shared memory space; a modification module, configured to obtain the logical memory address of the dependent function of the target patch function in the memory space of the first process, and modify the jump address corresponding to the dependent function in the jump list of the dependent function corresponding to the target patch function according to the obtained logical memory address, so that when the dependent function on which the target patch function depends needs to be executed, a jump to the jump list of dependent functions is made, and a jump to the location of the code of the dependent function is made according to the jump address; and a setting module, configured to set a jump instruction in the original function code in the memory space of the first process, so that when the original function code needs to be executed, a jump to the target patch function is made, the original function being the function to be replaced by the target patch function.
[0014] In one possible implementation, the offset of the target patch function's code and the dependent function skip list in the memory space of the first process is the same as the offset of the target patch function's code and the dependent function skip list in the patch package.
[0015] In one possible implementation, when loading the code of the target patch function required by the first process and the corresponding skip list of dependent functions into the memory space of the first process, the loading module is specifically configured to: determine whether the code of the target patch function is loaded in the physical memory of the target device; if it is determined that the code of the target patch function is not loaded in the physical memory, load the code of the target patch function into the physical memory of the target device; map the physical memory address occupied by the code of the target patch function to the memory space of the first process; and load the corresponding skip list of dependent functions into the memory space of the first process.
[0016] In one possible implementation, the memory space occupied by the dependent function skip list is the memory space exclusively occupied by the first process.
[0017] In one possible implementation, the loading module is further configured to: map the physical memory address occupied by the code of the target patch function to the memory space of the second process; load the jump list of dependent functions corresponding to the target patch function into the memory space of the second process, wherein the offset of the target patch function and the jump list of dependent functions in the memory space of the second process is the same as the offset of the target patch function and the jump list of dependent functions in the memory space of the first process; the modification module is further configured to: obtain the logical memory address of the dependent function of the target patch function in the memory space of the second process, and modify the jump address corresponding to the dependent function in the memory space of the second process according to the obtained logical memory address, so that when the second process needs to execute the dependent function on which the patch function depends, it jumps to the jump list of dependent functions in the second process, and jumps to the location of the code of the dependent function in the second process according to the jump address in the jump list of dependent functions in the second process; the setting module is further configured to: set a jump instruction in the original function code in the memory space of the second process, wherein the jump address corresponding to the jump instruction is the logical memory address occupied by the code of the target patch function in the second process.
[0018] In one possible implementation, the patch package further includes information about the dynamic libraries to which the one or more patch functions are applicable; the loading module, when loading the code of the target patch function required by the first process and the corresponding dependency function skip list into the memory space of the first process, is specifically used to: match the dynamic libraries already loaded by the first process with the information of the dynamic libraries to which the patch functions are applicable, and load the code of the successfully matched target patch function and the corresponding dependency function skip list into the memory space of the first process.
[0019] Thirdly, embodiments of this application provide a computer device, the computer device including a memory and a processor; the memory stores a computer program; the processor is used to call the computer program stored in the memory to execute the method as described in the first aspect and any implementation thereof.
[0020] Fourthly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method as described in the first aspect and any implementation thereof.
[0021] Fifthly, embodiments of this application provide a computer program product containing instructions that, when run on a computer, cause the methods described in the first aspect and any implementation thereof to be executed.
[0022] For the technical effects that can be achieved by any possible implementation method in any of the second to fifth aspects mentioned above, please refer to the description of the technical effects that can be achieved by the corresponding implementation scheme in the first aspect mentioned above. Repeated parts will not be discussed. Attached Figure Description
[0023] Figure 1 A schematic diagram of a dynamic library provided for an embodiment of this application;
[0024] Figure 2 This is a schematic diagram of the online hot-patching technology provided in an embodiment of this application;
[0025] Figure 3 This is a schematic diagram of dependency function jumps provided in the embodiments of this application;
[0026] Figure 4 This is a schematic diagram of multi-process patch processing provided in an embodiment of this application;
[0027] Figure 5 This is a schematic diagram of multi-process dependency function jumps provided in an embodiment of this application;
[0028] Figure 6 A flowchart illustrating a patch processing method provided in an embodiment of this application;
[0029] Figure 7a and Figure 7b This is a schematic diagram illustrating the loading of the target patch function provided in an embodiment of this application;
[0030] Figure 8 A flowchart illustrating another patch processing method provided in an embodiment of this application;
[0031] Figure 9 This is a schematic diagram illustrating the patch unit generation process provided in an embodiment of this application;
[0032] Figure 10 This is a schematic diagram of a patch package provided in an embodiment of this application;
[0033] Figure 11 This is a schematic diagram of the patch processing device provided in an embodiment of this application;
[0034] Figure 12 This is a schematic diagram of the computer device structure provided in an embodiment of this application. Detailed Implementation
[0035] exist Figure 2 In the patch loading example shown, firstly, patch unit A (pFuncA) from the patch package needs to be loaded into the logical memory space of process 1. This logical memory space is exclusively used by process 1, meaning that other processes cannot access or call pFuncA loaded by process 1.
[0036] Next, the jump addresses of dependent functions in patch unit A need to be modified. Function dependency represents the dependence of the value of one attribute or set of attributes on the value of another attribute or set of attributes; therefore, a dependent function represents the function that is depended upon. For example, when funcA executes its function, it needs to call funcC. funcA can call the already loaded funcC, that is, it jumps to the location of funcC based on the address of the already loaded funcC to execute the function of funcC, without having to add the addition function code in the program code of funcA, which reduces programming complexity and saves memory space. If the vulnerability of funcA is patched, then pFuncA usually also needs to call funcC. However, the jump address of funcC cannot be predicted when pFuncA is generated. It needs to be modified in pFuncA after pFuncA is loaded in process 1, based on the logical memory address of funcC in process 1, such as... Figure 3 As shown.
[0037] Finally, the starting address of the original function (i.e., funcA) in process 1 is modified so that when funcA needs to be executed, the jump is made to pFuncA.
[0038] Figure 2 This example only illustrates the patch loading method for a single process. When multiple processes involve the same patch function, according to the current patch handling method, each process needs to load its required patch function into its own memory space, even if the patch function has already been loaded by other processes. For example... Figure 3 As shown, processes 1 and 2 use the same dynamic library, which includes function A (funcA) and function B (funcB). Both funcA and funcB require vulnerability patching. Therefore, patch unit A (pFuncA) and patch unit B (pFuncB) from the patch package need to be loaded into the memory space of process 1. Figure 4 pFuncA1 and pFuncB1 in process 2 also need to be loaded into the memory space of process 2, that is... Figure 4 pFuncA2 and pFuncB2 in the example.
[0039] The reason why processes 1 and 2 need to load patch functions pFuncA and pFuncB separately is due to address space layout randomization (ASLR). ASLR helps overcome certain types of buffer overflow attacks by placing the cardinality, libraries, heap, and stack at arbitrary random locations within the process's address space, making it difficult for attackers to predict the memory address of the next instruction. However, address randomization results in the same dependent functions having different logical memory addresses in different processes. Because the logical memory addresses of dependent functions differ across processes, different processes cannot share patch functions, requiring each process to load them individually. Figure 5 As shown, pFuncA needs to call funcC. In process 1, the logical memory address of funcC is 0x8003f4e, while in process 2, the logical memory address of funcC is 0x8006de0. Therefore, the jump address of funcC in pFuncA is different in process 1 and process 2, which makes it impossible for process 1 and process 2 to share pFuncA.
[0040] Therefore, according to the current patching method, a large amount of memory space will be used to store the same patch functions, resulting in a serious waste of memory space.
[0041] To address the aforementioned issues, this application provides a patch processing method that reduces the memory footprint of patch functions and avoids memory waste. This method can be executed by a patch manager installed on the target device. The patch manager is an application running on the target device that implements the patch processing method provided in this application.
[0042] See Figure 6 This is a flowchart illustrating the patch processing method provided in an embodiment of this application. Figure 6 This article uses the Patch Manager to illustrate how to perform patch processing, for example. Figure 6 As shown, the method may include the following steps:
[0043] Step 601: The patch manager loads the patch package into the external storage of the target device. The patch package includes the code for one or more patch functions and a skip list of dependent functions corresponding to the target patch function. The target patch function is any one of the one or more patch functions.
[0044] For example, after receiving a user's instruction to load a patch, the patch manager might request a patch package from a server and load the obtained patch package into the target device's external storage. The obtained patch package can be a compressed file; correspondingly, the patch manager can also decompress the compressed file and load the decompressed patch functions and dependency function skip lists into the target device's external storage.
[0045] A patch package may include several patch functions, which represent the functionalities of the original functions after modification. Patch functions typically contain dependent functions. For patch functions with dependent functions, this embodiment configures a corresponding dependency function skip list to store the jump addresses of the dependent functions. In some embodiments, a patch function and its corresponding dependency function skip list can be referred to as a patch unit; that is, a patch package includes several patch units.
[0046] In step 601 above, the jump address in the jump table of the dependent function corresponding to the loaded target patch function is empty; or it is a preset address that is filled in. This preset address is not the exact address of the dependent function, but an address that needs to be modified.
[0047] In addition, patch packages may also include patch version number information, patch description information, etc. The patch description information describes the patch unit, such as: the name of the dynamic library to which the patch unit applies, the summary value of the dynamic library to which the patch unit applies, the priority of the patch unit, the offset of the patch unit within this package, the length of the patch unit, and the name of the patch unit.
[0048] External storage refers to storage devices other than the computer's internal memory and central processing unit (CPU) cache. This type of storage generally retains data even after power is off. In contrast, internal memory (RAM) is directly connected to the CPU, has a smaller storage capacity but higher speed, and is used to store the instructions and data of currently running programs, directly exchanging information with the CPU. External storage can include hard drives, NAND flash memory, and compressed flash memory cards (CF cards), etc.
[0049] Step 602: The patch manager loads the code of the target patch function required by the first process and the corresponding dependent function skip list into the memory space of the first process. The memory space occupied by the code of the target patch function is a shared memory space.
[0050] Each process uses different functions. Even if the first process uses the same dynamic library as other processes, the first process may not use every function in that dynamic library, and other processes may not use every function in that dynamic library either. Therefore, not all the patch functions included in the patch package are necessarily needed by the first process. When loading patch functions for the first process, the target patch functions required by the first process and their corresponding dependent function skip lists are loaded into the first process's memory space.
[0051] After loading the target patch function code into the memory space of the first process, the memory space occupied by the target patch function code can be set to shared, or loaded into a memory space that is already configured as shared. The reason for loading the target patch function code into shared memory space is to facilitate its calling by other processes. If it were loaded into the exclusive memory space of the first process, other processes would not be able to call it and would have to load it separately for each process.
[0052] Optionally, when performing step 602 above, the patch manager can first determine whether the code of the target patch function required by the first process has been loaded into the physical memory of the target device. If it is determined that the code of the target patch function required by the first process has not been loaded into the physical memory, the code of the target patch function required by the first process and the corresponding dependent function skip list are loaded into the memory space of the first process. If it is determined that the code of the target patch function required by the first process has already been loaded into the physical memory, then there is no need to load the code of the target patch function into the physical memory again to avoid duplicate loading and wasting memory space; in this case, the patch processing method for the first process can be referred to the patch processing method for the second process later.
[0053] In one possible implementation, when the patch manager loads the code of the target patch function into the memory space of the first process, it can first load the code of the target patch function into the physical memory of the target device, such as... Figure 7a As shown; then the physical memory address occupied by the code of the target patch function is mapped to the memory space of the first process, and the skip list of the dependent functions corresponding to the target patch function is loaded into the memory space of the first process, as shown. Figure 7b As shown.
[0054] The target device is configured with physical memory, i.e., the hardware device of internal memory. However, physical memory addresses are usually not visible to the application layer. The addresses in the program code are usually logical memory addresses of each process, that is, addresses in the logical memory space of the process where the application resides. When the processor executes the application, it maps the logical memory addresses in the application to physical memory addresses for addressing. When loading the target patch function and the skip list of dependent functions, the target device can be instructed to load them into physical memory first, and then map the physical memory addresses to the memory space of the first process. That is, the physical memory address where the target patch function is located is mapped to the logical memory address of the first process.
[0055] Step 603: The patch manager obtains the logical memory address of the dependent function of the target patch function in the first process memory space, and modifies the jump address of the dependent function in the jump table of the dependent function corresponding to the target patch function based on the obtained logical memory address.
[0056] The patch function modifies the original function, and may not require modification of dependent functions; calling already loaded dependent functions may suffice. Therefore, the patch manager can obtain the logical memory address of the dependent function in the first process's memory space and modify the corresponding jump address in the dependent function's jump table based on that address. For example, in... Figure 7b In the example shown, the logical memory address of the dependent function deps.func of the target patch function pFuncA in process 1 is 0x8003fed. Therefore, the jump address in the jump table pFuncA.rela of the dependent function is modified to 0x8003fed.
[0057] Alternatively, the dependent function may also need to be modified, that is, the patch package also contains the patch function of the dependent function. In this case, the patch function of the dependent function will also be loaded into the memory space of the first process in step 602 above. Then, in step 603, the patch manager can obtain the logical memory address of the patch function corresponding to the dependent function in the memory space of the first process, and modify the jump address corresponding to the dependent function in the dependent function jump table according to the address.
[0058] A patch function may involve multiple dependent functions. Correspondingly, the jump table of the dependent functions of the patch function records multiple jump addresses, and each jump address corresponds to a dependent function.
[0059] In addition, before performing step 603 above, the patch manager needs to identify the dependent functions involved in the target patch function. Optionally, the patch manager can identify dependent functions based on instructions in the target patch function code. For example, the "call deps.func" instruction is often used when calling dependent functions, and the patch manager can identify dependent functions by recognizing the "call deps.func" instruction.
[0060] By executing step 603 above, when the target patch function needs to be executed, the system jumps to the dependency function jump table and, based on the jump address in the dependency function jump table, jumps to the location of the dependency function's code.
[0061] Step 604: The patch manager sets jump instructions in the original function code in the memory space of the first process.
[0062] After the patch manager loads the target patch function and its corresponding dependent function skip list, it can set a jump instruction at the starting address of the original function code replaced by the target patch function, pointing to the location of the target patch function, so that the target patch function is executed when the original function code needs to be executed.
[0063] In the above method, when loading the target patch function, it is loaded into the shared memory space, providing a basis for other processes to access the target patch function. Furthermore, the patch function typically contains dependent functions. If a jump instruction is added to the dependent function of the patch function based on the logical memory address of the dependent function in the first process, then although the target patch function is loaded into the shared memory space, other processes cannot call the target patch function because the jump address of the dependent function is the logical memory address of the first process, and the logical memory address of the dependent function in the second process is not necessarily the same as that in the first process. To solve this problem, the above embodiments of this application introduce a dependent function skip list. The target patch function is loaded into the shared memory space, while the dependent function skip list is loaded into the memory space of each process. Based on the logical memory address of the dependent function in each process, the jump address in the dependent function skip list of that process is modified, so that when it is necessary to execute the dependent function that the target patch function depends on, a jump to the dependent function skip list is made, and the jump to the location of the code of the dependent function is made according to the jump address in the dependent function skip list. According to the above method, when multiple processes involve the same patch function, the patch function only needs to be loaded into the shared memory space once. There is no need for each process to load the patch function into its own memory space separately. Each process only needs to load a small dependency function skip list to call the target patch function, thereby saving memory space.
[0064] To ensure a smooth jump to the dependency function skip list when executing the dependent functions in the target patch function, the patch manager can ensure that the offsets of the target patch function's code and its dependency function skip list in the first process's memory space are the same as their offsets in the patch package when loading the target patch function and its corresponding dependency function skip list. For example, if pFuncA has a length of 0x300, and its corresponding dependency function skip list (pFuncA.rela tbl) immediately follows pFuncA in the patch package, then the offset of pFuncA and pFuncA.rela tbl in the patch package is 0x301. Therefore, when loading pFuncA and pFuncA.rela tbl into the first process's memory space, if the starting address of pFuncA in the first process's memory space is 0x8000, then the starting address of pFuncA.rela tbl in the first process's memory space will be 0x8301.
[0065] The offsets of the target patch function and the dependent function skip list within the patch package can be determined when the patch package is generated. Therefore, jump instructions can be added to the target patch function based on these offsets during patch package generation, so that when a dependent function that the target patch function depends on needs to be executed, the jump will be directed to the dependent function skip list. During loading, the offsets of the target patch function and the dependent function skip list in the logical memory of the first process are made the same as their offsets in the patch package, thus enabling a successful jump to the dependent function skip list loaded in the memory of the first process.
[0066] The memory space occupied by the dependency function skip list can be the exclusive memory space of the first process. Since the jump addresses in the dependency function skip list are the logical memory addresses of the dependent functions in the first process, other processes cannot call them. Therefore, the dependency function skip list can be loaded into the exclusive memory space of the first process.
[0067] As mentioned earlier, the patch package may also include information about the dynamic libraries to which the patch functions are applicable. For example, patch function A is applicable to dynamic library 1, and patch function B is applicable to dynamic library 2. When the patch package includes information about the dynamic libraries to which the patch functions are applicable, before executing step 602 above, the patch manager can first match the dynamic libraries already loaded by the first process with the information about the dynamic libraries to which the patch functions are applicable, and load the code of the target patch functions and their corresponding dependency function skip lists into the memory space of the first process. For example, if the first process has already loaded dynamic library 1 and dynamic library 2, the patch manager matches the identifiers of dynamic library 1 and dynamic library 2 with the information about the dynamic libraries to which the patch functions are applicable in the patch package, determining that patch functions A and B are applicable to dynamic library 1 and dynamic library 2 respectively, while patch function C is not applicable to either dynamic library 1 or dynamic library 2; then patch functions A and B are the target patch functions, and the patch manager then loads patch functions A and B and their corresponding dependency function skip lists into the memory space of the first process.
[0068] A patch package can contain multiple patch functions, and different patch functions may be compatible with different dynamic libraries. Therefore, information about the dynamic libraries that the patch functions are compatible with can be added to the patch package. When loading a patch function, the dynamic library corresponding to the patch function is first checked to see if it matches the dynamic library loaded by the process. If they match, the patch function is then loaded to avoid loading unusable patch functions.
[0069] The patch processing method provided in this application aims to avoid the same patch function being loaded repeatedly in the memory of different processes. Therefore, when the target patch function has already been loaded by the first process, and the second process also needs to use the target patch function, the following method can be adopted: Figure 8 The processing method shown:
[0070] Step 801: The patch processor determines that the target patch function required by the second process has been loaded into physical memory.
[0071] When the patch processor loads the target patch function required for the second process, it can first determine whether the code of the target patch function required by the second process has been loaded in the physical memory of the target device. At this time, the patch processor will find that the code of the target patch function has been loaded, that is, the code of the target patch function has been loaded in the physical memory during the patch processing of the first process.
[0072] Step 802: The patch processor maps the physical memory address occupied by the code of the target patch function to the memory space of the second process.
[0073] When the patch processor performs the uplink step, it can first obtain the physical memory address occupied by the code of the target patch function that has already been loaded, and then map the physical memory address to the memory space of the second process. That is, it maps the physical memory address where the target patch function is located to the logical memory address of the second process.
[0074] Step 803: The patch processor loads the jump list of dependent functions corresponding to the target patch function into the memory space of the second process, and the position offset of the target patch function and the jump list of dependent functions in the memory space of the second process is the same as the position offset of the target patch function and the jump list of dependent functions in the memory space of the first process.
[0075] As mentioned earlier, because the jump addresses of the dependent functions placed in the dependency function jump table are the logical memory addresses of the dependent functions in each process, and the logical memory addresses of dependent functions may not be the same in different processes, different processes cannot share the dependency function jump table. Even if the first process has already loaded the target patch function and its corresponding dependency function jump table, the second process still needs to load the dependency function jump table corresponding to the target patch function again.
[0076] Although it is still necessary to load the jump table of the dependent functions corresponding to the target patch function into the memory space of the second process, the memory occupied by the jump table is very small because it is only used to store the jump address of the dependent function. Compared with reloading the target patch function, it can significantly reduce the memory space occupied.
[0077] In this embodiment, the target patch function first jumps to the dependent function skip list, and then jumps from the dependent function skip list to the dependent function. The jump instruction to the dependent function skip list can be based on the position offset between the target patch function and the dependent function skip list. This ensures that when executing a dependent function within the target patch function, the jump is first performed to the location of the dependent function skip list based on the position offset, and then the jump proceeds to the dependent function. Jumping to the dependent function skip list based on the position offset also facilitates calls to the target patch function from other processes. When the patch manager loads the second process, it ensures that the position offset of the target patch function and the dependent function skip list in the second process's memory space is the same as the position offset of the target patch function and the dependent function skip list in the first process's memory space. Because the position offsets are the same, the loaded target patch function can be called, and the jump to the dependent function skip list in the second process can be successfully executed.
[0078] Step 804: The patch processor obtains the logical memory address of the dependent function of the target patch function in the memory space of the second process, and modifies the jump address corresponding to the dependent function in the memory space of the second process based on the obtained logical memory address.
[0079] The purpose of the above steps is to enable the second process to jump to the dependency function jump table in the second process when the second process needs to execute the dependency function on which the patch function depends, and to jump to the location of the code of the dependency function in the second process according to the jump address in the dependency function jump table in the second process.
[0080] The patch function modifies the original function. If no modification is needed to the dependent function, the loaded dependent function can be called. In this case, the patch manager can obtain the logical memory address of the dependent function in the memory space of the second process and modify the jump address corresponding to the dependent function in the jump table according to the logical memory address of the dependent function in the memory space of the second process.
[0081] If the dependent functions are also modified, then the patch package will also contain the patch functions for the dependent functions. In this case, the patch functions for the dependent functions will also be loaded into the memory space (shared memory space) of the first process along with the target patch function. Then the patch manager can obtain the physical memory address of the patch function corresponding to the dependent function and map the physical memory address to the memory space of the second process. Then, based on the logical memory address of the patch function corresponding to the dependent function in the memory space of the second process, the jump address corresponding to the dependent function in the jump table of the dependent function is modified.
[0082] Step 805: The patch processor sets a jump instruction in the original function code in the memory space of the second process. The jump address corresponding to the jump instruction is the logical memory address occupied by the code of the target patch function in the second process.
[0083] Because the patch processor loads the target patch function into the shared memory space when loading it for the first process, the second process can also call the target patch function. After the patch manager loads the jump list of the dependent functions corresponding to the target patch function into the second process's memory space, it sets a jump instruction at the starting address of the original function code in the second process's memory space. This jump instruction points to the logical memory address occupied by the target patch function in the second process, so that the second process can jump to execute the target patch function when it needs to execute the original function code.
[0084] To complement the above-described patch processing method, this application also provides a patch generation method for generating patch packages applicable to the aforementioned patch processing method. This patch generation method can be executed by a patch generator, which can be an application running on a service provider's device, used to generate patches for content requiring patching, thereby providing the patches to the user.
[0085] The main functions of the patch generator include compiling the code of the patch file, i.e. the patch function code mentioned above, generating a jump list of dependency functions, and packaging the patch units into a patch package.
[0086] Specifically, the patch generator can use a compiler, such as the GNU compiler collection (GCC), to compile the obtained patch function source code into a patch file, which contains code segments. If the patch function has dependent functions, references to the dependent functions can be made using "call deps.func" or other directives.
[0087] After compiling the code for the patch file, the patch generator can identify the dependent functions within the patch function through dependency function reference instructions. It then generates a jump list of dependent functions corresponding to the patch function and modifies the dependency function reference instructions in the patch file code to reference the jump list itself, effectively jumping to the location in the jump list. At this point, the jump addresses in the jump list are either empty or filled with preset addresses. These preset addresses are not the exact addresses of the dependent functions but are addresses to be modified.
[0088] For a patch function that does not contain dependent functions, the patch file obtained after its compilation can be called a patch unit; for a patch function that contains dependent functions, the patch file obtained after its compilation and the corresponding skip list of dependent functions can be called a patch unit.
[0089] Finally, the patch generator packages one or more generated patch units into a patch package. When generating the patch package, version information and descriptions of each patch unit can also be included.
[0090] Figure 9 An exemplary schematic diagram of the patch unit generation process is provided, such as... Figure 9As shown, the obtained source code of the patch function pFuncA.c is input into the compiler, generating the patch file pFuncA.text. By identifying the dependency function reference instruction, it is determined that the patch function pFuncA contains a dependency function deps.func1, and a dependency function skip list pFuncA.rela tbl is generated for the patch function pFuncA. This dependency function skip list pFuncA.rela tbl is used to store the jump address deps.func1 addr entry for the dependency function deps.func1, but at this time, the jump address of the dependency function deps.func1 is empty. The reference to the dependent function deps.func1 in the patch function pFuncA is modified to a reference to the jump address deps.func1 addr entry of the dependent function deps.func1 in the dependent function jump table pFuncA.rela tbl. The diagram assumes that the address of the reference instruction to the dependent function deps.func1 in the patch function pFuncA is offset by 0x20 from the address of the dependent function jump address deps.func1 addr entry in the dependent function jump table pFuncA.rela tbl.
[0091] A patch file pFuncA.text and a dependent function skip list pFuncA.rela tbl constitute a patch unit.
[0092] After generating multiple patch units, the patch package generated by the patch manager can be like this: Figure 10 As shown, the patch package includes version number information (version_id), patch description information (patch_des_tbl), and several patch units. These patch units can include patch unit A (pFuncA.text and pFuncA.rela tbl), patch unit B (pFuncB.text and pFuncB.rela tbl), etc. The patch description information (patch_des_tbl) can include the name of the dynamic library to which the patch unit applies (target), the digest value of the dynamic library to which the patch unit applies (target_diggest), the priority of the patch unit (priority), the offset of the patch unit within this package (offset), the length of the patch unit (length), and the name of the patch unit (name), etc.
[0093] Based on the same technical concept, this application also provides a patch processing apparatus. This apparatus is used to implement the functions of the control node in the above method embodiments. The apparatus may include modules / units that execute any possible implementation of the above method embodiments; these modules / units may be implemented in hardware or by hardware executing corresponding software.
[0094] For example, the device can be as follows Figure 11 As shown, it includes: a loading module 1101, a modification module 1102, and a setting module 1103.
[0095] Specifically, the loading module 1101 is used to load a patch package into the external storage of the target device. The patch package includes the code of one or more patch functions and a jump list of dependent functions corresponding to the target patch function. The target patch function is any one of the one or more patch functions. The code of the target patch function required by the first process and the jump list of dependent functions corresponding to the target patch function are loaded into the memory space of the first process. The memory space occupied by the code of the target patch function is a shared memory space.
[0096] The modification module 1102 is used to obtain the logical memory address of the dependent function of the target patch function in the memory space of the first process, and modify the jump address of the dependent function in the jump table of the dependent function corresponding to the target patch function according to the obtained logical memory address, so that when the dependent function of the target patch function needs to be executed, the jump is made to the jump table of the dependent function, and the jump is made to the location of the code of the dependent function according to the jump address.
[0097] The setting module 1103 is used to set a jump instruction in the original function code in the memory space of the first process, so that when the original function code needs to be executed, the target patch function is executed, and the original function is the function that needs to be replaced by the target patch function.
[0098] In one possible implementation, the offset of the target patch function's code and the dependent function skip list in the memory space of the first process is the same as the offset of the target patch function's code and the dependent function skip list in the patch package.
[0099] In one possible implementation, the loading module 1101, when loading the code of the target patch function required by the first process and the corresponding jump list of dependent functions into the memory space of the first process, is specifically configured to: determine whether the code of the target patch function is loaded in the physical memory of the target device; if it is determined that the code of the target patch function is not loaded in the physical memory, load the code of the target patch function into the physical memory of the target device; map the physical memory address occupied by the code of the target patch function to the memory space of the first process; and load the corresponding jump list of dependent functions into the memory space of the first process.
[0100] In one possible implementation, the memory space occupied by the dependent function skip list is the memory space exclusively occupied by the first process.
[0101] In one possible implementation, the loading module 1101 is further configured to: map the physical memory address occupied by the code of the target patch function to the memory space of the second process; load the dependent function skip list corresponding to the target patch function into the memory space of the second process, wherein the position offset of the target patch function and the dependent function skip list in the memory space of the second process is the same as the position offset of the target patch function and the dependent function skip list in the memory space of the first process.
[0102] The modification module 1102 is further configured to: obtain the logical memory address of the dependent function of the target patch function in the memory space of the second process, and modify the jump address corresponding to the dependent function in the memory space of the second process according to the obtained logical memory address, so that when the second process needs to execute the dependent function on which the patch function depends, it jumps to the dependent function jump table in the second process, and jumps to the location of the code of the dependent function in the second process according to the jump address in the dependent function jump table in the second process.
[0103] The setting module 1103 is further configured to: set a jump instruction in the original function code in the memory space of the second process, wherein the jump address corresponding to the jump instruction is the logical memory address occupied by the code of the target patch function in the second process.
[0104] In one possible implementation, the patch package further includes information about the dynamic libraries to which the one or more patch functions are applicable; the loading module 1101, when loading the code of the target patch function required by the first process and the corresponding dependency function skip list into the memory space of the first process, is specifically used to: match the dynamic libraries already loaded by the first process with the information about the dynamic libraries to which the patch functions are applicable, and load the code of the successfully matched target patch function and the corresponding dependency function skip list into the memory space of the first process.
[0105] Based on the same technical concept, this application also provides a computer device for implementing the functions of the control node in the above method embodiments. The computer device includes, as described above... Figure 12 The processor 1201 shown is accompanied by a memory 1202 connected to the processor 1201. Furthermore, the computer device may also include a communication interface 1203 and a communication bus 1204.
[0106] Processor 1201 can be a general-purpose processor, a microprocessor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or one or more integrated circuits used to control the execution of the program in this application. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
[0107] Memory 1202 is used to store program instructions and / or data so that processor 1201 can call the instructions and / or data stored in memory 1202 to implement the aforementioned functions of processor 1201. Memory 1202 can be read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, electrically erasable programmable read-only memory (EEPROM), or any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. Memory 1202 can exist independently, such as off-chip memory, and is connected to processor 1201 via communication bus 1204. Memory 1202 can also be integrated with processor 1201. Memory 1202 can include internal memory and external memory (such as hard disk).
[0108] The communication interface 1203 is used to communicate with other devices, such as PCI bus interfaces, network cards, radio access networks (RAN), wireless local area networks (WLAN), etc.
[0109] The communication bus 1204 may include a path for transmitting information between the aforementioned components.
[0110] For example, processor 1201 may invoke instructions in memory 1202 to perform the following steps:
[0111] A patch package is loaded into the external storage of the target device. The patch package includes the code of one or more patch functions and a jump list of dependent functions corresponding to the target patch function. The target patch function is any one of the one or more patch functions. The code of the target patch function and the jump list of dependent functions corresponding to the target patch function required by the first process are loaded into the memory space of the first process. The memory space occupied by the code of the target patch function is a shared memory space. The logical memory addresses of the dependent functions of the target patch function in the memory space of the first process are obtained. Based on the obtained logical memory addresses, the jump addresses corresponding to the dependent functions in the jump list of the dependent functions of the target patch function are modified so that when it is necessary to execute the dependent functions that the target patch function depends on, the jump is made to the jump list of dependent functions, and the jump is made to the location of the code of the dependent function according to the jump address. A jump instruction is set in the original function code in the memory space of the first process so that when it is necessary to execute the original function code, the jump is made to execute the target patch function. The original function is the function that needs to be replaced by the target patch function.
[0112] In one possible implementation, the offset of the target patch function's code and the dependent function skip list in the memory space of the first process is the same as the offset of the target patch function's code and the dependent function skip list in the patch package.
[0113] In one possible implementation, when the processor 1201 loads the code of the target patch function required by the first process and the corresponding skip list of dependent functions into the memory space of the first process, it specifically performs the following:
[0114] Determine whether the code of the target patch function is loaded in the physical memory of the target device; if it is determined that the code of the target patch function is not loaded in the physical memory, load the code of the target patch function into the physical memory of the target device; map the physical memory address occupied by the code of the target patch function to the memory space of the first process; load the skip list of dependent functions corresponding to the target patch function into the memory space of the first process.
[0115] In one possible implementation, the memory space occupied by the dependent function skip list is the memory space exclusively occupied by the first process.
[0116] In one possible implementation, the processor 1201 is further configured to: map the physical memory address occupied by the code of the target patch function to the memory space of the second process; load the jump list of dependent functions corresponding to the target patch function into the memory space of the second process, wherein the offset of the target patch function and the jump list of dependent functions in the memory space of the second process is the same as the offset of the target patch function and the jump list of dependent functions in the memory space of the first process; obtain the logical memory address of the dependent function of the target patch function in the memory space of the second process, and modify the jump address corresponding to the dependent function in the memory space of the second process according to the obtained logical memory address, so that when the second process needs to execute the dependent function on which the patch function depends, it jumps to the jump list of dependent functions in the second process, and jumps to the location of the code of the dependent function in the second process according to the jump address in the jump list of dependent functions in the second process; set a jump instruction in the original function code in the memory space of the second process, wherein the jump address corresponding to the jump instruction is the logical memory address occupied by the code of the target patch function in the second process.
[0117] In one possible implementation, the patch package further includes information about the dynamic libraries to which the one or more patch functions are applicable; when the processor 1201 loads the code of the target patch function required by the first process and the corresponding dependent function skip list into the memory space of the first process, it is specifically used for:
[0118] The dynamic libraries already loaded in the first process are matched with the information of the dynamic libraries applicable to the patch functions. The code of the target patch function that is successfully matched and the skip list of the dependent functions corresponding to the target patch function are loaded into the memory space of the first process.
[0119] Based on the same technical concept, embodiments of this application also provide a computer-readable storage medium storing computer-readable instructions, which, when executed on a computer, cause the above-described method embodiments to be performed.
[0120] Based on the same technical concept, this application also provides a computer program product containing instructions that, when run on a computer, cause the above-described method embodiments to be executed.
[0121] It should be understood that in the description of this application, terms such as "first" and "second" are used only for distinguishing purposes and should not be construed as indicating or implying relative importance or order. References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in still other embodiments" appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0122] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0123] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0124] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0125] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0126] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0127] Obviously, those skilled in the art can make various modifications and variations to the embodiments of this application without departing from the spirit and scope of the embodiments of this application. Therefore, if these modifications and variations to the embodiments of this application fall within the scope of the claims of this application and their equivalents, this application also intends to include these modifications and variations.
Claims
1. A patch processing method, characterized in that, The method includes: Load the patch package into the external storage of the target device. The patch package includes the code of one or more patch functions and a skip list of dependent functions corresponding to the target patch function. The target patch function is any one of the one or more patch functions. The code of the target patch function required by the first process and the corresponding skip list of dependent functions are loaded into the memory space of the first process. The memory space occupied by the code of the target patch function is a shared memory space. Obtain the logical memory address of the dependent function of the target patch function in the memory space of the first process, and modify the jump address of the dependent function in the jump table of the dependent function corresponding to the target patch function according to the obtained logical memory address, so that when the dependent function of the target patch function needs to be executed, the jump is made to the jump table of the dependent function, and the jump is made to the location of the code of the dependent function according to the jump address; A jump instruction is set in the original function code in the memory space of the first process so that when the original function code needs to be executed, the execution jumps to the target patch function, where the original function is the function that needs to be replaced by the target patch function.
2. The method according to claim 1, characterized in that, The offset of the target patch function's code and the dependent function's skip list in the memory space of the first process is the same as the offset of the target patch function's code and the dependent function's skip list in the patch package.
3. The method according to claim 1 or 2, characterized in that, The step of loading the code of the target patch function required by the first process and the corresponding skip list of dependent functions into the memory space of the first process includes: Determine whether the code for the target patch function is loaded into the physical memory of the target device; If it is determined that the code for the target patch function has not been loaded, the code for the target patch function will be loaded into the physical memory of the target device. Map the physical memory address occupied by the code of the target patch function to the memory space of the first process; The skip list of dependent functions corresponding to the target patch function is loaded into the memory space of the first process.
4. The method according to any one of claims 1-3, characterized in that, The memory space occupied by the dependent function skip list is the exclusive memory space of the first process.
5. The method according to any one of claims 1-4, characterized in that, The method further includes: Map the physical memory address occupied by the code of the target patch function to the memory space of the second process; The skip list of dependent functions corresponding to the target patch function is loaded into the memory space of the second process. The position offset of the target patch function and the skip list of dependent functions in the memory space of the second process is the same as the position offset of the target patch function and the skip list of dependent functions in the memory space of the first process. Obtain the logical memory address of the dependent function of the target patch function in the memory space of the second process, and modify the jump address corresponding to the dependent function in the memory space of the second process according to the obtained logical memory address, so that when the second process needs to execute the dependent function on which the patch function depends, it jumps to the dependent function jump table in the second process, and jumps to the location of the code of the dependent function in the second process according to the jump address in the dependent function jump table in the second process; A jump instruction is set in the original function code in the memory space of the second process. The jump address corresponding to the jump instruction is the logical memory address occupied by the code of the target patch function in the second process.
6. The method according to any one of claims 1-5, characterized in that, The patch package also includes information about the dynamic libraries to which the one or more patch functions are applicable; The step of loading the code of the target patch function required by the first process and the corresponding skip list of dependent functions into the memory space of the first process includes: The dynamic libraries already loaded in the first process are matched with the information of the dynamic libraries applicable to the patch functions. The code of the target patch function that is successfully matched and the skip list of the dependent functions corresponding to the target patch function are loaded into the memory space of the first process.
7. A patch processing apparatus, characterized in that, The device includes: A loading module is used to load a patch package into the external storage of the target device. The patch package includes the code of one or more patch functions and a skip list of dependent functions corresponding to the target patch function. The target patch function is any one of the one or more patch functions. The code of the target patch function and the skip list of dependent functions corresponding to the target patch function required by the first process are loaded into the memory space of the first process. The memory space occupied by the code of the target patch function is a shared memory space. The modification module is used to obtain the logical memory address of the dependent function of the target patch function in the memory space of the first process, and modify the jump address of the dependent function in the jump table of the dependent function corresponding to the target patch function according to the obtained logical memory address, so that when the dependent function of the target patch function needs to be executed, the jump is made to the jump table of the dependent function, and the jump is made to the location of the code of the dependent function according to the jump address; The setting module is used to set a jump instruction in the original function code in the memory space of the first process, so that when the original function code needs to be executed, the execution jumps to the target patch function, where the original function is the function that needs to be replaced by the target patch function.
8. The apparatus according to claim 7, characterized in that, The offset of the target patch function's code and the dependent function's skip list in the memory space of the first process is the same as the offset of the target patch function's code and the dependent function's skip list in the patch package.
9. The apparatus according to claim 7 or 8, characterized in that, The loading module, when loading the code of the target patch function required by the first process and the corresponding skip list of dependent functions into the memory space of the first process, is specifically used for: Determine whether the code for the target patch function is loaded into the physical memory of the target device; If it is determined that the code for the target patch function has not been loaded, the code for the target patch function will be loaded into the physical memory of the target device. Map the physical memory address occupied by the code of the target patch function to the memory space of the first process; The skip list of dependent functions corresponding to the target patch function is loaded into the memory space of the first process.
10. The apparatus according to any one of claims 7-9, characterized in that, The memory space occupied by the dependent function skip list is the exclusive memory space of the first process.
11. The apparatus according to any one of claims 7-10, characterized in that, The loading module is further configured to: map the physical memory address occupied by the code of the target patch function to the memory space of the second process; load the dependent function skip list corresponding to the target patch function into the memory space of the second process, wherein the position offset of the target patch function and the dependent function skip list in the memory space of the second process is the same as the position offset of the target patch function and the dependent function skip list in the memory space of the first process; The modification module is further configured to: obtain the logical memory address of the dependent function of the target patch function in the memory space of the second process, and modify the jump address corresponding to the dependent function in the memory space of the second process according to the obtained logical memory address, so that when the second process needs to execute the dependent function on which the patch function depends, it jumps to the dependent function jump table in the second process, and jumps to the location of the code of the dependent function in the second process according to the jump address in the dependent function jump table in the second process; The setting module is further configured to: set a jump instruction in the original function code in the memory space of the second process, wherein the jump address corresponding to the jump instruction is the logical memory address occupied by the code of the target patch function in the second process.
12. The apparatus according to any one of claims 7-11, characterized in that, The patch package also includes information about the dynamic libraries to which the one or more patch functions are applicable; The loading module, when loading the code of the target patch function required by the first process and the corresponding skip list of dependent functions into the memory space of the first process, is specifically used for: The dynamic libraries already loaded in the first process are matched with the information of the dynamic libraries applicable to the patch functions. The code of the target patch function that is successfully matched and the skip list of the dependent functions corresponding to the target patch function are loaded into the memory space of the first process.
13. A computer device, characterized in that, The computer device includes a memory and a processor; The memory stores computer programs; The processor is used to invoke a computer program stored in the memory to perform the method according to any one of claims 1-6.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1-6.
Citation Information
Patent Citations
Hot patch processing method and device
CN113918244A
Patch loading method, network element, and computer-readable storage medium
WO2021259109A1