Hot patch implementation method and device and electronic equipment
By creating tasks in a non-preemptive kernel environment to obtain CPU usage rights, skip security detection and directly perform hot patch installation or uninstallation, it solves the problem of hot patch installation or uninstallation failure in mainstream technologies, improves success rate and optimizes multi-core CPU processing efficiency.
Patent Information
- Application Number
- CN202410928725.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-11-01
AI Technical Summary
Mainstream hot patch technology has a high failure rate for patch installation or uninstallation due to over-detection in non-preemptive kernel environments, especially when the basic function calls the delay function periodically, it cannot pass security detection, resulting in installation or uninstallation failure.
In a non-preemptive kernel environment, by creating tasks to obtain CPU usage rights, skipping function security detection, directly performing instruction replacement to install or uninstall hot patches, and ensuring that the patch function ends and cleanses relevant files after running.
Without reducing security, the installation and uninstallation success rate of hot patches is improved, time-consuming, and the instruction replacement process of each core is optimized through inter-core communication in multi-core CPU scenarios.
Smart Images

Figure CN118885200A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method, device and electronic device for implementing a hot patch. Background Art
[0002] With the continuous development of computer software technology, software and hardware promote each other, driving the entire industry towards high reliability; however, there are inevitably more or less bugs in the software coding process. When the version cannot be upgraded, the bug can generally only be fixed through patches. However, high-reliability devices usually do not allow the device to be restarted during the patch upgrade process, so hot patch technology is required. The device does not need to be restarted during the hot patch installation process.
[0003] However, mainstream hot patch solutions will perform full security checks to ensure that patch installation and uninstallation are safe. For example, the device will be shut down and the function usage will be deduced thread by thread for detection to ensure that the basic function to be repaired is not used, thereby ensuring the safety of patch loading. A similar shutdown detection method is also required during the uninstallation phase.
[0004] However, mainstream hot patching solutions can easily lead to patch installation or uninstallation failures due to excessive detection. For example, the basic function to be repaired periodically calls the delay function, which causes it to be unable to complete the operation for a long time. This will cause the full security detection to fail and the patch cannot be installed. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method, device and electronic device for implementing a hot patch, so as to improve the success rate of installing and uninstalling the hot patch without reducing security in the scenario of a non-preemptive kernel.
[0006] The specific technical solutions are as follows:
[0007] In a first aspect of the present application, a method for implementing a hot patch is provided, the method comprising:
[0008] In the operating environment of the non-preemptive kernel, a first task is created; the first task is used to install a hot patch after obtaining the right to use the CPU.
[0009] Optional, when the CPU is a multi-core CPU,
[0010] The creating of the first task comprises: creating the first task in a first core of the CPU, and instructing to create a second task in each second core of the CPU;
[0011] The second task is used to: after obtaining the right to use the second core, notify the first core;
[0012] The first task is specifically used to install a hot patch after obtaining the right to use the first core and confirming that the second tasks have obtained the right to use the second core.
[0013] Optionally, the installing the hotfix includes:
[0014] A hot patch program is run to modify a function entry instruction of a target base function into a jump instruction for jumping to the patch function.
[0015] Optionally, the method further includes:
[0016] Creating a third task; the third task is used to run a hot patch uninstallation program after obtaining the right to use the CPU to restore the jump instruction to the function entry instruction of the target basic function;
[0017] A function detection is performed on the patch function, and after a detection result of the function detection indicates that the patch function has finished running, patch files related to the patch function are cleaned up.
[0018] Optional, when the CPU is a multi-core CPU,
[0019] The creating of the third task comprises:
[0020] Creating the third task in the first core of the CPU, and instructing to create a fourth task in each second core of the CPU;
[0021] The fourth task is used to: after obtaining the right to use the second core, notify the first core;
[0022] The third task is specifically used for: after obtaining the right to use the first core and confirming that the fourth task has obtained the right to use the second core, running the hot patch uninstaller to restore the jump instruction to the function entry instruction of the target basic function; performing function detection on the patch function, and after the detection result of the function detection indicates that the patch function has ended running, cleaning up the patch files related to the patch function.
[0023] Optionally, the performing function detection on the patch function includes:
[0024] Function detection is performed on the patch function at a first detection frequency until the detection result indicates that the patch function has finished running, or a maximum number of detections is reached; wherein the first detection frequency is negatively correlated with the number of function detections.
[0025] In a second aspect of the present application, a device for implementing a hot patch is provided, the device comprising:
[0026] The first creation module is used to create a first task in the operating environment of the non-preemptive kernel; the first task is used to install a hot patch after obtaining the right to use the CPU.
[0027] Optional, when the CPU is a multi-core CPU,
[0028] The first creation module is specifically used to: create the first task in the first core of the CPU, and instruct the creation of the second task in each second core of the CPU; the second task is used to: notify the first core after obtaining the right to use the second core; the first task is specifically used to: install the hot patch after obtaining the right to use the first core and confirming that the second tasks have obtained the right to use the second core.
[0029] Optionally, the first task is specifically used to: after obtaining the right to use the CPU, run the hot patch program to modify the function entry instruction of the target basic function into a jump instruction for jumping to the patch function.
[0030] Optionally, the device further comprises:
[0031] The second creation module is used to create a third task; the third task is used to run a hot patch uninstallation program after obtaining the right to use the CPU to restore the jump instruction to the function entry instruction of the target basic function;
[0032] The execution module is used to execute function detection for the patch function, and clean up the patch files related to the patch function after the detection result of the function detection indicates that the patch function has finished running.
[0033] Optionally, when the CPU is a multi-core CPU, the second creation module is specifically used to: create the third task in the first core of the CPU, and instruct to create a fourth task in each second core of the CPU; the fourth task is used to: after obtaining the right to use the second core, notify the first core; the third task is specifically used to: after obtaining the right to use the first core and confirming that the fourth tasks have obtained the right to use the second core, run the hot patch uninstallation program to restore the jump instruction to the function entry instruction of the target basic function;
[0034] The execution module is used to execute function detection for the patch function, and clean up the patch files related to the patch function after the detection result of the function detection indicates that the patch function has finished running.
[0035] Optionally, the execution module is specifically used to: perform function detection on the patch function at a first detection frequency until the detection result indicates that the patch function has ended running, or a maximum number of detection times is reached; wherein the first detection frequency is negatively correlated with the number of function detection times.
[0036] The third aspect of the present application provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; the memory is used to store computer programs; the processor is used to implement any of the above-mentioned steps of the hot patch implementation method when executing the program stored in the memory.
[0037] According to a fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements any of the above-mentioned steps of the hot patch implementation method.
[0038] In a fifth aspect of the present application, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned methods for implementing the hot patch.
[0039] Beneficial effects of the embodiments of the present application:
[0040] By using the implementation method of the hot patch provided in the embodiment of the present application, a first task is created in the operating environment of a non-preemptive kernel, and the first task is used to implement the installation of the hot patch. When the first task obtains the right to use the CPU, that is, the CPU switches from executing the previous task to executing the first task, the CPU can complete the installation of the hot patch during the execution of the first task, that is, implement the instruction replacement of the function entry instruction. This process does not require function security detection, thereby improving the success rate of hot patch installation without reducing security.
[0041] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0043] Figure 1 A flow chart of a method for implementing a hot patch provided in an embodiment of the present application;
[0044] Figure 2A flowchart of a method for implementing hot patching in a multi-core CPU scenario provided in an embodiment of the present application;
[0045] Figure 3 Another flowchart of a method for implementing a hot patch provided in an embodiment of the present application;
[0046] Figure 4 Another flowchart of a method for implementing hot patching in a multi-core CPU scenario provided in an embodiment of the present application;
[0047] Figure 5 A schematic diagram of a structure of a device for implementing a hot patch provided in an embodiment of the present application;
[0048] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.
[0050] To facilitate understanding, the relevant technologies and technical problems existing in the relevant technologies are first introduced.
[0051] At present, mainstream hot patch solutions will perform function security detection to ensure the safety of patch installation and uninstallation. For example, the device will be shut down and the function usage will be deduced thread by thread for detection to ensure that instruction replacement can be performed to ensure the safety of patch loading. In the uninstallation stage, a similar shutdown detection method is also required.
[0052] However, excessive detection can easily lead to patch installation or uninstallation failure. For example, after installing a hot patch, the newly installed patch function periodically calls the sleep function to sleep. When the system is shut down for function safety detection, the patch function is likely to be in the process of calling sleep. Calling sleep means that the jump instructions used to jump to the patch function are frequently used. If these instructions are in the call stack, they cannot be modified. In this case, the function safety detection fails and the uninstallation process cannot continue. Correspondingly, during the patch installation phase, if the basic function keeps calling sleep, it means that the function entry instructions of the basic function are frequently used. If these instructions are in the call stack, they cannot be modified. It can be seen that there is a high probability of failure during security detection, which manifests as a failure of patch installation.
[0053] It can be seen that the mainstream hot patch implementation solution has a high failure rate in patch installation and uninstallation because the pre-function security check is not easy to pass.
[0054] In order to solve the above technical problems, the embodiments of the present application provide a method, device and electronic device for implementing a hot patch, see Figure 1 , is a flow chart of a method for implementing a hot patch provided in an embodiment of the present application, the method comprising the following steps:
[0055] S101: creating a first task in a non-preemptive kernel running environment; the first task is used to install a hot patch after obtaining the right to use the CPU.
[0056] First, the non-preemptive kernel is introduced. Operating systems are divided into two categories: preemptive kernel and non-preemptive kernel.
[0057] A non-preemptive kernel means that a high-priority task cannot terminate a low-priority task running in the kernel and preempt the CPU. Once a task is in the kernel state, it will continue to run until it is completed or exits the kernel unless the task voluntarily gives up the CPU.
[0058] A preemptive kernel means that when a task is in kernel space and a higher priority task appears, if the current kernel allows preemption, the current task can be suspended and the higher priority task can be executed.
[0059] Those skilled in the art will understand that the kernel mentioned above refers to the operating system. Kernel is the most basic and core part of the operating system, and is mainly responsible for managing system resources. Multi-core CPUs will also be mentioned below. The core of a multi-core CPU is another concept. For an introduction to the core in a multi-core CPU, see below.
[0060] The scenario adapted by the embodiments of the present application is a non-preemptive kernel. Based on the characteristics of the non-preemptive kernel, an implementation method for improving the success rate of hot patch installation and uninstallation is provided.
[0061] From the code level, installing a hot patch is essentially an instruction replacement, which replaces the basic version of the CPU instruction at the function entry with a CPU jump instruction to jump to the modified function, i.e., the patch function. In this process, as long as the atomicity of the instruction replacement is guaranteed, unnecessary function reference relationship detection can be avoided, thereby increasing the success rate of patch installation.
[0062] Specifically, for the operating environment of a non-preemptive kernel, if the CPU is actively given up, and the task switching interface must be called, that is, the CPU switches from executing task A to executing task B. Assuming that task B is used to execute the task of hot patch installation, then after task B obtains the right to use the CPU, the function entry instruction must have been executed, that is, the function entry instruction must not be in the call stack at this time, so the replacement of the execution instruction at this time must be safe. It can be seen that this process saves function security detection, which not only saves the time of hot patch installation, but also improves the installation success rate.
[0063] The implementation method of the hot patch provided in the embodiment of the present application is specifically applied to electronic devices, such as a PC (Personal Computer) or a mobile terminal running a specific operating system. The hot patch is usually installed to repair vulnerabilities or bugs in the operating system.
[0064] As an example, the specific implementation process of hot patch installation includes: the user learns about the hot patch through email or other means, and downloads the patch file from the software supplier's website to the electronic device. The electronic device runs the patch file. Since the code of the operating system needs to be changed, the patch file runs in the kernel state. The electronic device running the patch file is equivalent to the electronic device creating a first task running in the kernel state. In the operating environment of the non-preemptive kernel, the electronic device can run the patch file, which means that the CPU switches from executing the previous task to executing the current task for running the patch file. As mentioned above, it must be safe to perform instruction replacement at this time. Therefore, in the process of running the patch file, the execution instruction is replaced, and the function entry instruction of the basic function is replaced with a jump instruction for jumping to the patch function, and the installation of the hot patch can be completed.
[0065] Based on the above analysis, the implementation method of the hot patch provided by the embodiment of the present application is adopted, and the first task is created in the operating environment of the non-preemptive kernel, and the first task is used to implement the installation of the hot patch. Since the non-preemptive kernel must have called the task switching interface if it can actively give up the CPU, when the first task obtains the right to use the CPU, that is, the CPU switches from executing the previous task to executing the first task, the task switching interface must have been called. Since there is a sequential relationship between the execution of the task switching interface and the function entry instruction, it indicates that the function entry instruction must have been executed at present, that is, the function entry instruction will not be in the call stack at this time, so it is safe to replace the execution instruction at this time. And the first task is the task for installing the hot patch. The CPU can complete the installation of the hot patch during the execution of the first task, that is, the function entry instruction is replaced by a replacement instruction that jumps to the patch function. This process does not require function security detection, thereby saving the time-consuming installation of the hot patch and improving the installation success rate without reducing security.
[0066] In one embodiment of the present application, when the CPU is a multi-core CPU, a first task is created, which specifically includes: creating a first task in the first core of the CPU, and instructing the creation of a second task in each second core of the CPU; the second task is used to: notify the first core after obtaining the right to use the second core; the first task is specifically used to: install a hot patch after obtaining the right to use the first core and confirming that the second tasks have obtained the right to use the second core.
[0067] A CPU with two or more cores is called a multi-core CPU. Each core of a multi-core CPU can read and execute program instructions independently, which improves the execution speed of the program and supports parallel computing.
[0068] In the scenario of a multi-core CPU, before installing a hot patch, it is necessary to ensure that for each CPU core, the function entry instructions of the basic function to be repaired are not in the execution state, that is, the function entry instructions are not in the call stack. In an embodiment of the present application, creating a first task specifically includes: creating a first task in the first core of the CPU, and instructing to create a second task in each second core of the CPU. Among them, the first core can be any one of the CPU cores, or the CPU main core. Correspondingly, the second core is the other core of the multiple cores of the CPU except the first core, and the second core can be multiple.
[0069] For the second task created in the second core, since the operating environment still belongs to a non-preemptive kernel, after the second task obtains the right to use the CPU, based on the same reason as in the above embodiment, the function entry instruction of the basic function to be repaired will definitely not be in the state of being executed. The second task is designed to send a notification message to the first core through inter-core communication after starting to run. Therefore, the second core executes the second task, that is, sends a notification to the first core to inform the second task that it has obtained the right to use the second core.
[0070] Similarly, after obtaining the right to use the CPU core, the second tasks in other second cores all send notifications to the first core.
[0071] After obtaining the right to use the first core, the first task in the first core waits for notifications initiated by other cores. After confirming that the second tasks in all second cores have obtained the right to use the CPU core, it can be confirmed that for each CPU core, the function entry instructions of the basic function to be repaired are not in the executed state. At this time, instruction replacement can be performed, and the step of installing the hot patch can be executed.
[0072] The specific implementation process of executing and installing the hot patch is the same as that of the single-core CPU. Please refer to the following for details and will not be repeated here.
[0073] See also Figure 2 , is a flow chart of a method for implementing hot patching in a multi-core CPU scenario provided in an embodiment of the present application, including:
[0074] S201: Create a first task in a first core.
[0075] S202: Create a second task in the second core.
[0076] S203: After obtaining the right to use the second core, the second task notifies the first core.
[0077] S204: After the first task confirms that each second task has obtained the right to use the corresponding second core, the first task executes the code instruction for installing the hot patch in the first task.
[0078] S205: After the first task executes the code instruction for installing the hot patch, it notifies each second core and exits the task.
[0079] S206: The second task exits the task after receiving the notification.
[0080] It can be seen that in the operating environment of a non-preemptive kernel, for a multi-core CPU, after the first task or the second task of a CPU core obtains the right to use the core, it can be confirmed that the function entry instruction of the basic function to be repaired will definitely not be in the state of being executed in the core. Therefore, when the first core confirms that the second task of each second core has obtained the right to use the core, the hot patch can be installed. This process saves the function security detection for each CPU core. Under the premise of ensuring the safety of instruction replacement, it not only saves the time of hot patch installation, but also improves the installation success rate.
[0081] From the code level, the essence of installing a hot patch is to replace instructions. In one embodiment of the present application, the steps of installing a hot patch are specifically: by running the hot patch program, the function entry instruction of the target basic function to be repaired is modified to a jump instruction for jumping to the patch function.
[0082] In the specific implementation, the staff writes the patch function in the source file, compiles it into a target file, and uses a patch creation tool to generate a patch file. The staff can use the relevant patch tool to load the patch file into the system address space where the basic function to be repaired runs. When the patch is activated and takes effect, the first instruction of the basic function is modified to an unconditional jump instruction to jump to the patch function.
[0083] The staff can also verify the validity of the patch file through the above method. After the verification is passed, the patch file can be published to the website of the software vendor, and the user can also be notified of the news about the hot patch.
[0084] It should be noted that since this solution is only aimed at the special operating environment of the non-preemptive kernel, the pre-detection of installing the hot patch is omitted, and there is no limitation on the implementation process such as how to release the hot patch and how to load the hot patch through related tools. For details, please refer to the relevant technology.
[0085] See also Figure 3 , which is another flow chart of the implementation method of the hot patch provided in the embodiment of the present application, such as Figure 3 As shown, after executing S101, the process further includes:
[0086] Step S301: creating a third task; the third task is used to run the hot patch uninstallation program after obtaining the right to use the CPU to restore the jump instruction to the function entry instruction of the target basic function;
[0087] Step S302: performing function detection on the patch function, and after the detection result of the function detection indicates that the patch function has finished running, cleaning up the patch files related to the patch function.
[0088] Those skilled in the art will understand that uninstalling a hotfix is not a must-do step and is only performed when necessary. For example, if there is a bug in the patch function, it is necessary to roll back to the basic function first. In other words, after installing the hotfix, uninstalling the hotfix is only performed when it is necessary. Figure 3 The steps S301-S302 are shown.
[0089] Specifically, when the hot patch needs to be uninstalled, a third task is created in the operating environment of the non-preemptive kernel. The third task is used to replace instructions after obtaining the right to use the CPU.
[0090] As an example, a user learns about the hot patch through email or other means, and downloads a patch uninstall file from the software supplier's website to an electronic device. When the electronic device runs the patch uninstall file, since the operating system code needs to be changed, the patch uninstall file runs in the kernel state. The electronic device running the patch uninstall file is equivalent to the electronic device creating a third task running in the kernel state. In the operating environment of the non-preemptive kernel, the electronic device can run the patch uninstall file, which means that the CPU switches from executing the previous task to executing the task currently used to run the patch uninstall file. As described above, it must be safe to perform instruction replacement at this time. Therefore, in the process of running the patch uninstall file, the execution instruction is replaced, and the jump instruction used to jump to the patch function is rolled back to the function entry instruction of the base function.
[0091] For the same reason as in the hot patch installation phase, in a non-preemptive kernel operating environment, when the third task obtains the right to use the CPU, it indicates that the jump instruction used to jump to the patch function must not be in an executed state, and the instruction can be rolled back directly. This is different from the solution of first performing a security check and then rolling back in the related art. For the solution of first performing a security check and then rolling back, in certain scenarios, the instruction replacement phase has a high probability of failure. For example, the patch function periodically calls a delay or sleep function, resulting in a long period of inability to terminate the operation. The solution of first performing a security check and then rolling back adopted in the related art will make it difficult to pass the security check, resulting in a high failure rate for patch uninstallation.
[0092] In the embodiment of the present application, for the operating environment of the non-preemptive kernel, if the CPU is actively given up, and the task switching interface must be called, that is, the CPU switches from executing the previous task to executing the next task. Assuming that the next task is used to execute instruction rollback, then after the next task obtains the right to use the CPU, the jump instruction used to jump to the patch function must have been executed, that is, the jump instruction must not be in the state of being executed, and it must be safe to execute instruction rollback at this time. It can be seen that this process omits the function security detection, which not only saves the time of patch uninstallation but also improves the success rate of uninstallation.
[0093] Specifically, executing instruction rollback is: restoring the jump instruction to the function entry instruction of the target basic function. Thus, when executing the target basic function, the original function is executed instead of jumping to the patch function through the jump instruction.
[0094] To uninstall a hot patch, not only does it require instruction rollback, but it also requires the patch files associated with the patch function to be deleted. However, if the patch function is in the state of being executed, the patch file cannot be deleted. Therefore, after executing the instruction rollback, a function detection is performed for the patch function.
[0095] Since the function entry instruction has been rolled back to before the patch was installed, for a patch function with a faster execution speed, after the current life cycle ends, the next call to the function will start executing the basic version of the function. However, for a patch function with a slower execution speed, or a dormant patch function is called, function detection is required to detect whether the patch function is in the state of being executed. After ensuring that the patch function is executed, the patch file is uninstalled.
[0096] Function detection can be performed on a thread basis, one thread at a time or multiple threads at the same time. Specifically, the call stack of each thread is derived to detect whether the function in the call stack is executing the patch function. If all threads do not execute the patch function, the cleanup action of the patch file can be performed.
[0097] In particular, for a patch function that has called a dormant state, after it exits dormancy, since the function entry instruction has rolled back to the initial version, when it is executed again, the basic function will be executed instead of the patch function. Therefore, for a patch function that has called a dormant state, as long as it waits for it to exit dormancy, the patch file can be cleaned up.
[0098] It can be seen that in the embodiment of the present application, when it is necessary to uninstall the hot patch, a third task is created in the operating environment of the non-preemptive kernel. When the third task obtains the right to use the CPU, it means that the CPU must have called the task switching interface, and the jump instruction located at the function entry position for jumping to the patch function must have been executed and is not in an executed state. Therefore, the instruction can be directly rolled back, and the jump instruction can be restored to the function entry instruction of the target basic function. Then, it is detected whether the patch function has been executed, and the patch file is cleaned up after the execution is completed. Thanks to the method of rolling back the instruction first and then detecting, it provides an opportunity for patch uninstallation that calls the dormant patch function, and it also has a very effective performance in ensuring the uninstallation success rate for functions that are called too frequently.
[0099] In one embodiment of the present application, when the CPU is a multi-core CPU, creating a third task may specifically include: creating a third task in the first core of the CPU, and instructing the creation of a fourth task in each second core of the CPU; the fourth task is used to: after obtaining the right to use the second core, notify the first core; the third task is specifically used to: after obtaining the right to use the first core and confirming that the fourth task has obtained the right to use the second core, run the hot patch uninstaller to restore the jump instruction to the function entry instruction of the target basic function; perform function detection on the patch function, and after the detection result of the function detection indicates that the patch function has ended running, clean up the patch files related to the patch function.
[0100] See also Figure 4 Another flowchart of a method for implementing hot patching in a multi-core CPU scenario provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, after executing S201-S206, if the hot patch file needs to be uninstalled, execute S401-S405:
[0101] S401: creating a third task in the first core;
[0102] S402: creating a fourth task in the second core;
[0103] S403: After the fourth task obtains the right to use the second core, it notifies the first core;
[0104] S404: After the third task confirms that each fourth task has obtained the right to use the corresponding second core, the hot patch uninstaller is run to restore the jump instruction to the function entry instruction of the target basic function.
[0105] S405: Execute function detection for the patch function, and after the detection result of the function detection indicates that the patch function has finished running, clean up the patch files related to the patch function.
[0106] Specifically, in a multi-core CPU scenario, before uninstalling the hot patch, it is necessary to ensure that for each CPU core, the jump instructions for jumping to the patch function are not in the execution state, that is, these instructions are not in the call stack. In an embodiment of the present application, creating the third task specifically includes: creating the third task in the first core of the CPU, and instructing the creation of the fourth task in each second core of the CPU.
[0107] Among them, for the fourth task created in the second core, since the operating environment still belongs to a non-preemptive kernel, after the fourth task obtains the right to use the CPU, based on the same reasons as in the above embodiment, the jump instruction used to jump to the patch function is not in an execution state. Once the second core executes the fourth task, it can send a notification to the first core to inform the fourth task that it has obtained the right to use the second core.
[0108] Similarly, after obtaining the right to use the CPU core, the fourth tasks in other second cores all send notifications to the first core.
[0109] After obtaining the right to use the first core, the third task in the first core waits for notifications initiated by other cores. After confirming that all fourth tasks in the second cores have obtained the right to use the CPU core, it can be confirmed that for each CPU core, the jump instructions used to jump to the patch function are not in the execution state. At this time, instruction replacement can be performed, that is, the jump instructions are restored to the function entry instructions of the target basic function.
[0110] After executing the instruction replacement, the first core continues to perform function detection on the patch function, and after the detection result of the function detection indicates that the patch function has finished running, the patch file related to the patch function is cleaned up.
[0111] As an example, the first core instructs each second core to perform function detection for the patch function through inter-core communication. When the first core confirms that all CPU cores including itself have performed function detection for the patch function and the detection result indicates that the patch function has ended running, the patch files related to the patch function are cleaned up.
[0112] It can be seen that in a multi-core CPU scenario, after the third task or the fourth task of the CPU core obtains the right to use the core, it can be confirmed that the jump instruction used to jump to the patch function will not be in the state of being executed in the core, so that when the first core confirms that the fourth task of each second core has obtained the right to use the core, the instruction rollback can be executed, that is, the jump instruction is restored to the function entry instruction of the target basic function. This process eliminates the need for function security detection for each CPU core. On the premise of ensuring the safety of instruction replacement, it not only saves the time of hot patch uninstallation, but also improves the success rate of uninstallation. The function detection performed after the instruction rollback can ensure that the patch function is not in the state of being executed in each core when cleaning the patch file. Thanks to the method of first rolling back the instruction and then performing the function detection adopted in the embodiment of the present application, it provides an opportunity for patch uninstallation that calls the dormant patch function, and it also has a very effective performance in ensuring the success rate of uninstallation for functions that are called too frequently.
[0113] In one embodiment of the present application, performing function detection on a patch function may specifically include:
[0114] Function detection is performed on the patch function at a first detection frequency until the detection result indicates that the patch function has finished running, or a maximum detection number is reached; wherein the first detection frequency is negatively correlated with the number of function detections.
[0115] Specifically, the first detection frequency can be set to be dynamic. When the function detection is performed at the beginning, the interval between two detections can be small, that is, the first detection frequency is high. If the patch function cannot be executed after multiple function detections, it means that the patch function is likely to call a sleep or delay function such as sleep. At this time, the detection frequency can be reduced.
[0116] As an example, for the first 10 function detections, the interval between each detection is 0.5s; after 10 times, the interval is 1s; after 20 times, the interval is 2s, and so on, until the preset upper limit of function detection times is reached. If this upper limit is reached, the system exits and prompts that the uninstallation failed.
[0117] It can be seen that by setting a dynamic detection frequency, and the detection frequency is negatively correlated with the number of function detections, gradient delay unloading is achieved. For patch functions that execute faster, a faster detection frequency at the beginning can ensure that the patch function is detected as soon as possible. For functions that execute slower or call sleep or delay, the detection frequency is gradually reduced as the number of detections increases, avoiding more invalid detections and saving computing resources.
[0118] See also Figure 5 The embodiment of the present application also provides a device for implementing a hot patch, including:
[0119] The first creation module 501 is used to create a first task in the operating environment of the non-preemptive kernel; the first task is used to install a hot patch after obtaining the right to use the CPU.
[0120] Using the hot patch implementation device provided by the embodiment of the present application, a first task is created in the operating environment of a non-preemptive kernel, and the first task is used to implement the installation of the hot patch. When the first task obtains the right to use the CPU, that is, the CPU switches from executing the previous task to executing the first task, the CPU can complete the installation of the hot patch during the execution of the first task, that is, implement the instruction replacement of the function entry instruction. This process does not require function security detection, thereby improving the success rate of hot patch installation without reducing security.
[0121] In one embodiment of the present application, when the CPU is a multi-core CPU,
[0122] The first creation module is specifically used to: create a first task in the first core of the CPU, and instruct the creation of a second task in each second core of the CPU; the second task is used to: notify the first core after obtaining the right to use the second core; the first task is specifically used to: install a hot patch after obtaining the right to use the first core and confirming that the second tasks have obtained the right to use the second core.
[0123] It can be seen that in the operating environment of a non-preemptive kernel, for a multi-core CPU, after the first task or the second task of a CPU core obtains the right to use the core, it can be confirmed that the function entry instruction of the basic function to be repaired will definitely not be in the state of being executed in the core. Therefore, when the first core confirms that the second task of each second core has obtained the right to use the core, the hot patch can be installed. This process saves the function security detection for each CPU core. Under the premise of ensuring the safety of instruction replacement, it not only saves the time of hot patch installation, but also improves the installation success rate.
[0124] In one embodiment of the present application, the first task is specifically used to: after obtaining the right to use the CPU, run the hot patch program to modify the function entry instruction of the target basic function into a jump instruction for jumping to the patch function.
[0125] In one embodiment of the present application, the device further includes:
[0126] The second creation module is used to create a third task; the third task is used to run a hot patch uninstallation program after obtaining the right to use the CPU to restore the jump instruction to the function entry instruction of the target basic function;
[0127] The execution module is used to execute function detection for the patch function, and clean up the patch files related to the patch function after the detection result of the function detection indicates that the patch function has finished running.
[0128] In the embodiment of the present application, when it is necessary to uninstall the hot patch, a third task is created in the operating environment of a non-preemptive kernel. When the third task obtains the right to use the CPU, it means that the CPU must have called the task switching interface, and the jump instruction located at the function entry position for jumping to the patch function must have been executed and is not in an executed state. Therefore, the instruction can be directly rolled back, and the jump instruction can be restored to the function entry instruction of the target basic function. Then, it is detected whether the patch function has been executed, and the patch file is cleaned up after the execution is completed. Thanks to the method of rolling back the instruction first and then detecting, it provides an opportunity for patch uninstallation that calls the dormant patch function, and it also has a very effective performance in ensuring the uninstallation success rate for functions that are called too frequently.
[0129] In one embodiment of the present application, when the CPU is a multi-core CPU, the second creation module is specifically used to: create the third task in the first core of the CPU, and instruct to create a fourth task in each second core of the CPU; the fourth task is used to: after obtaining the right to use the second core, notify the first core; the third task is specifically used to: after obtaining the right to use the first core and confirming that the fourth tasks have obtained the right to use the second core, run the hot patch uninstallation program to restore the jump instruction to the function entry instruction of the target basic function;
[0130] It can be seen that in a multi-core CPU scenario, after the third task or the fourth task of the CPU core obtains the right to use the core, it can be confirmed that the jump instruction used to jump to the patch function will not be in the state of being executed in the core, so that when the first core confirms that the fourth task of each second core has obtained the right to use the core, the instruction rollback can be executed, that is, the jump instruction is restored to the function entry instruction of the target basic function. This process eliminates the need for function security detection for each CPU core. On the premise of ensuring the safety of instruction replacement, it not only saves the time of hot patch uninstallation, but also improves the success rate of uninstallation. The function detection performed after the instruction rollback can ensure that the patch function is not in the state of being executed in each core when cleaning the patch file. Thanks to the method of first rolling back the instruction and then performing the function detection adopted in the embodiment of the present application, it provides an opportunity for patch uninstallation that calls the dormant patch function, and it also has a very effective performance in ensuring the success rate of uninstallation for functions that are called too frequently.
[0131] In one embodiment of the present application, the execution module is specifically used to: perform function detection on the patch function at a first detection frequency until the detection result indicates that the patch function has ended running, or the maximum number of detections is reached; wherein the first detection frequency is negatively correlated with the number of function detections.
[0132] It can be seen that by setting a dynamic detection frequency, and the detection frequency is negatively correlated with the number of function detections, gradient delay unloading is achieved. For patch functions that execute faster, a faster detection frequency at the beginning can ensure that the patch function is detected as soon as possible. For functions that execute slower or call sleep or delay, the detection frequency is gradually reduced as the number of detections increases, avoiding more invalid detections and saving computing resources.
[0133] The present application also provides an electronic device, such as Figure 6 As shown, it includes a processor 601 , a communication interface 602 , a memory 603 and a communication bus 604 , wherein the processor 601 , the communication interface 602 , and the memory 603 communicate with each other via the communication bus 604 .
[0134] Memory 603, used for storing computer programs;
[0135] The processor 601 is used to execute the program stored in the memory 603 to implement the following steps:
[0136] In the running environment of the non-preemptive kernel, create a first task;
[0137] The first task is used to install a hotfix after obtaining the right to use the CPU.
[0138] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0139] The communication interface is used for communication between the above electronic device and other devices.
[0140] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0141] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0142] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned hot patch implementation methods are implemented.
[0143] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes any method for implementing the hotfix in the above embodiments.
[0144] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0145] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0146] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0147] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for implementing a hot patch, characterized in that: The method comprises: In the running environment of the non-preemptive kernel, create a first task; The first task is used to install a hotfix after obtaining the right to use the CPU.
2. The method according to claim 1, characterized in that When the CPU is a multi-core CPU, The creating of the first task comprises: creating the first task in a first core of the CPU, and instructing to create a second task in each second core of the CPU; The second task is used to: after obtaining the right to use the second core, notify the first core; The first task is specifically used to install a hot patch after obtaining the right to use the first core and confirming that the second tasks have obtained the right to use the second core.
3. The method according to claim 1 or 2, characterized in that: The first task is specifically used to: after obtaining the right to use the CPU, run the hot patch program to modify the function entry instruction of the target basic function into a jump instruction for jumping to the patch function.
4. The method according to claim 3, characterized in that The method further comprises: Creating a third task; the third task is used to run a hot patch uninstallation program after obtaining the right to use the CPU to restore the jump instruction to the function entry instruction of the target basic function; A function detection is performed on the patch function, and after a detection result of the function detection indicates that the patch function has finished running, patch files related to the patch function are cleaned up.
5. The method according to claim 4, characterized in that When the CPU is a multi-core CPU, The creating of the third task comprises: Creating the third task in the first core of the CPU, and instructing to create a fourth task in each second core of the CPU; The fourth task is used to: after obtaining the right to use the second core, notify the first core; The third task is specifically used for: after obtaining the right to use the first core and confirming that the fourth task has obtained the right to use the second core, running the hot patch uninstaller to restore the jump instruction to the function entry instruction of the target basic function; performing function detection on the patch function, and after the detection result of the function detection indicates that the patch function has ended running, cleaning up the patch files related to the patch function.
6. The method according to claim 4 or 5, characterized in that: The performing of function detection for the patch function includes: Function detection is performed on the patch function at a first detection frequency until the detection result indicates that the patch function has finished running, or a maximum number of detections is reached; wherein the first detection frequency is negatively correlated with the number of function detections.
7. A device for implementing a hot patch, characterized in that: The device comprises: The first creation module is used to create a first task in the operating environment of the non-preemptive kernel; the first task is used to install a hot patch after obtaining the right to use the CPU.
8. The device according to claim 7, characterized in that When the CPU is a multi-core CPU, The first creation module is specifically used to: create the first task in the first core of the CPU, and instruct the creation of the second task in each second core of the CPU; the second task is used to: notify the first core after obtaining the right to use the second core; the first task is specifically used to: install the hot patch after obtaining the right to use the first core and confirming that the second tasks have obtained the right to use the second core.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 6 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 6 are implemented.
