WO2011116672A1 - Method and apparatus for patching shared code segment - Google Patents

Method and apparatus for patching shared code segment Download PDF

Info

Publication number
WO2011116672A1
WO2011116672A1 PCT/CN2011/071991 CN2011071991W WO2011116672A1 WO 2011116672 A1 WO2011116672 A1 WO 2011116672A1 CN 2011071991 W CN2011071991 W CN 2011071991W WO 2011116672 A1 WO2011116672 A1 WO 2011116672A1
Authority
WO
WIPO (PCT)
Prior art keywords
instruction
vcpu
service
function
patch
Prior art date
Application number
PCT/CN2011/071991
Other languages
French (fr)
Chinese (zh)
Inventor
陈福军
Original Assignee
成都市华为赛门铁克科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 成都市华为赛门铁克科技有限公司 filed Critical 成都市华为赛门铁克科技有限公司
Publication of WO2011116672A1 publication Critical patent/WO2011116672A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

Definitions

  • Patch technology is gaining more and more attention as an upgrade tool.
  • some errors in the software often cause abnormalities or crashes in the system.
  • patch software can be used to upgrade the software in question. In this process, it will not affect the processing of normal business.
  • Errors in the software often exist in one or more functions, and these erroneous primitives are called by other functions. Although it is difficult to find these calling functions, it is easy to find the original function of the error. Therefore, the key operations of patching should focus on the original function of these errors.
  • the process of patching is: when calling the original function of these errors, jump from the wrong original function to the modified function (that is, the patch function), and then return to the calling function after executing the patch function. In this way, the software will never execute the wrong original function, thus completing the modification of the software.
  • the main virtual CPU (VCPU) VCPU sends a synchronization message to all service VCPUs executing the shared code segment, and notifies each service VCPU that the service VCPU needs to perform Patch operation.
  • each service VCPU stops its normal service processing, enters the waiting for patching state, and sends a response message to the primary VCPU to notify itself that it has entered the waiting state.
  • the main VCPU modifies the instructions in the original function that needs to be patched, and then performs the patching operation procedure to enable the service.
  • the VCPU jumps from the original function to the patch function when it executes the original function. After modifying the instructions, to all services The VCPU sends a completion synchronization message to notify all service VCPU that the patch operation has been completed. After receiving the synchronization message for completing the patch operation, all service VCPUs refresh their respective fast instruction buffers to make the modified instructions take effect, and then perform normal service processing. In this solution, although the problem that the main VCPU interacts with the service VCPU during the patch operation is avoided, that is, when the main VCPU modifies the instruction, there is no service VCPU executing to the current modification instruction.
  • the inventors have found that at least the following problems exist in the prior art:
  • the primary VCPU after the primary VCPU sends the patched synchronization message to all service VCPUs, it needs to receive the response message sent by all service VCPUs.
  • the shared code segment can be patched; and all service VCPUs can perform normal service processing only after receiving the synchronization message of the completion patch operation sent by the primary VCPU. Therefore, if the current service of a service VCPU is busy, after receiving the patched synchronization message sent by the primary VCPU, the response message cannot be sent to the primary VCPU in time, causing other service VCPUs and the primary VCPU to enter the waiting for patching. status. As a result, the patch takes effect for a long time, which prevents other services VCPUs from processing services.
  • the embodiment of the present invention provides a method and a device for patching a shared code segment, which is used to solve the defect that the patch is valid for a shared code segment, and the patch takes effect for a long time, which affects the normal processing service of the service VCPU. Patching the shared code segment and making the patch take effect quickly without affecting the normal business processing of the service VCPU.
  • An embodiment of the present invention provides a method for patching a shared code segment, including:
  • the first instruction of the original function is modified to jump to the exception handling instruction, and the original function is a shared function that needs to be patched;
  • the patch function is a function that replaces the original function
  • the embodiment of the present invention provides a method for patching a shared code segment, including: after receiving the first interrupt information sent by the main VCPU, interrupting the current service according to the instruction of the first interrupt information, and refreshing the fast instruction buffer. So that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory, and the original function is a function that needs to be patched;
  • the patch function is found in the patch area according to the first address of the original function.
  • the patch function is a function that replaces the original function; and jumps from the exception processing to the patch function according to a first address of the patch function;
  • An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
  • a first modification module configured to modify, in the shared memory, the first instruction of the original function to jump to an exception processing instruction before the original function is patched, where the original function is a shared function that needs to be patched;
  • An interrupt module configured to: after the first modification module in the shared memory, modify the first instruction of the original function to jump to the exception processing instruction, send a first interrupt message to the service VCPU, where the interrupt information is Used to instruct the service VCPU to interrupt the current service and refresh its own fast instruction buffer;
  • a first patch module configured to: after the first interrupt module sends the first interrupt information to the service VPCU, in the shared memory, modify the first instruction and the second instruction of the original function to Jumping to an instruction of the patch function, so that the service VCPU executing to the original function jumps from the original function to the patch function, and the patch function is a function that replaces the original function;
  • a second interrupt module configured to: after the first patch module in the shared memory, modify the first instruction and the second instruction of the original function to jump to a patch function,
  • the service VPCU sends a second interrupt message.
  • An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
  • a first refreshing module configured to receive the first interrupt information sent by the main VCPU, according to the first An interrupt instruction indicates that the current service is interrupted, and the fast instruction buffer is refreshed, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory, and the original function needs to be patched.
  • a first exception processing module configured to: after the first refresh module refreshes the fast instruction buffer, execute the first instruction to the original function, according to the first instruction of the original function, enter an exception processing, In the exception processing, according to the first address of the original function, the first address of the patch function is found in the patch area, and the patch function is a function that replaces the original function;
  • a first patch function execution module configured to: after the first exception processing module finds the first address of the patch function, jump from the exception processing to the patch function according to a first address of the patch function carried out;
  • a second refreshing module configured to: after the first refreshing module interrupts the current service according to the indication of the first interrupt information, and after refreshing the fast instruction buffer, receive the second interrupt information sent by the primary VCPU, according to the The indication of the second interrupt information, interrupting the current service, refreshing its own fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory
  • a method and a device for patching a shared code segment are performed.
  • the first instruction of the original function is first modified to jump to The exception-handled instruction sends an interrupt message to the service VCPU, causing the service VCPU to immediately flush the fast instruction buffer.
  • the service VCPU after receiving the interrupt information sent by the main CPU, the service VCPU does not need to send a response message to the main VCPU; and after the main CPU sends the interrupt information to the service VCPU, the original function can be patched.
  • the embodiment of the invention enables the patch to take effect quickly.
  • the main VCPU patches the original function
  • the service VCPU executes the original function, it enters the patch function from the exception processing, which ensures that the main VCPU performs the normal patching operation on the original function. Therefore, in the embodiment of the present invention, the method for patching the shared code segment, when the main VCPU patches the original function, does not affect the normal service processing of the service VCPU, and can also execute the service VCPU from the original function to the original function. Jump to the patch function to execute.
  • An embodiment of the present invention provides a method for patching a shared code segment, including:
  • the first instruction of the original function is modified to jump to the exception handling instruction, and the original function is a function that needs to be patched;
  • the service VCPU sends a first patch activation message to each service VCPU, where the first patch activation message is used to indicate
  • the service VCPU refreshes its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory; indicating the last fast instruction of refreshing itself
  • the VCPU of the buffer modifies the first instruction and the second instruction of the original function in the shared memory before refreshing its own fast instruction buffer.
  • An embodiment of the present invention provides a method for patching a shared code segment, including:
  • the service VCPU receives the first patch activation message sent by the primary VCPU.
  • the service VCPU is the last service VCPU that refreshes its own fast instruction buffer
  • the first instruction and the second instruction of the original function are modified in the shared memory to The instruction that jumps to the patch function
  • the original function is a function that needs to be patched
  • the service VCPU refreshes its own fast instruction buffer, and the other VCPUs other than the service VCPU that refreshes its own fast instruction buffer are refreshed by the main VCPU to refresh its own fast instruction buffer.
  • the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
  • An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
  • a third modification module configured to modify, in the shared memory, the first instruction of the original function to jump to an exception processing instruction before the original function is patched, where the original function is a function that needs to be patched;
  • a message sending module configured to: in the shared memory, modify the first command of the original function to jump to the instruction of the exception processing, and send a first patch activation message to each service VCPU, where The first patch activation message is used to indicate that the service VCPU refreshes its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory. ; indicates the last refresh of its own fast instruction buffer
  • the VCPU modifies the first instruction and the second instruction of the original function in the shared memory before refreshing its own fast instruction buffer.
  • An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
  • a first receiving module configured to receive, by the service VCPU, a first patch activation message sent by the primary VCPU, and a determining module, configured to determine whether the service VCPU is the last service VCPU that refreshes its own fast instruction buffer;
  • a second patch module configured to: when the determining module determines that the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the first patch activation message
  • the first instruction and the second instruction of the original function are modified in the shared memory to the instruction that jumps to the patch function, and the original function is a function that needs to be patched;
  • a first refresh notification module configured to refresh the service VCPU after the second patch module modifies the first instruction and the second instruction of the original function into the instruction to jump to the patch function in the shared memory a fast instruction buffer, and through the main VCPU, notify the service VCPU other than the service VCPU that refreshes its own fast instruction buffer to refresh its own fast instruction buffer, so that the service VCPU itself is fast
  • the instruction in the instruction buffer is updated synchronously with the instruction in the shared memory.
  • the main VCPU modifies the first instruction of the original function to jump to the instruction of the exception processing, and sends a patch to the service VCPU.
  • the last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched.
  • the last service VCPU patches the original function
  • the other service VCPU executes the original function
  • the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
  • FIG. 1B is a flowchart of a method for patching a shared code segment according to a first embodiment of the present invention
  • FIG. 1b is a flowchart of a patch execution method for patching a shared code segment according to a first embodiment of the present invention
  • FIG. 3a is a flowchart of a method for patching a shared code segment according to a third embodiment of the present invention
  • FIG. 3b is a signaling interaction diagram of a method for patching a shared code segment according to a third embodiment of the present invention
  • FIG. 1B is a flowchart of a method for patching a shared code segment according to a first embodiment of the present invention
  • FIG. 1b is a flowchart of a patch execution method for patching a shared code segment according to a first embodiment of the present invention
  • FIG. 4a is a flowchart of a method for patching a shared code segment according to a fourth embodiment of the present invention
  • FIG. 4b is a signaling interaction diagram of a method for patching a shared code segment according to a fourth embodiment of the present invention
  • FIG. 5 is a flowchart of a method for patching a shared code segment according to a fifth embodiment of the present invention
  • FIG. 6 is a flowchart of a method for patching a shared code segment according to a sixth embodiment of the present invention
  • FIG. 7b is a flowchart of another method for patching a shared code segment according to a seventh embodiment of the present invention.
  • FIG. 7c is a signal interaction diagram of another method for patching a shared code segment according to a seventh embodiment of the present invention.
  • FIG. 8 is a flowchart of a method for patching a shared code segment according to an eighth embodiment of the present invention
  • FIG. 8b is a signaling interaction diagram of a method for patching a shared code segment according to an eighth embodiment of the present invention
  • FIG. 9 is a schematic structural diagram of an apparatus for patching a shared code segment according to a ninth embodiment of the present invention
  • FIG. 10 is a schematic structural diagram of an apparatus for patching a shared code segment according to a tenth embodiment of the present invention
  • FIG. 11 is a schematic structural diagram of an apparatus for patching a shared code segment according to an eleventh embodiment of the present invention.
  • FIG. 1 ib is another apparatus for patching a shared code segment according to an eleventh embodiment of the present invention.
  • FIG. 12 is a schematic structural diagram of an apparatus for patching a shared code segment according to a twelfth embodiment of the present invention.
  • FIG. 13 is a schematic structural diagram of an apparatus for patching a shared code segment according to a thirteenth embodiment of the present invention
  • FIG. 14 is a schematic structural diagram of an apparatus for patching a shared code segment according to a fourteenth embodiment of the present invention
  • FIG. 15 is a schematic structural diagram of an apparatus for patching a shared code segment according to a fifteenth embodiment of the present invention.
  • FIG. 16 is a schematic structural diagram of an apparatus for patching a shared code segment according to a sixteenth embodiment of the present invention.
  • the VCPU running on the embedded operating system is called the primary VPCU, which is used to manage the common resources of the system and manage and monitor the service VCPU.
  • the service VCPU runs a single-task operating system to perform efficient user data processing.
  • the technical solution is applicable to an asymmetric processor AMP (asymmetnc multi-processing) structure, and a separate operating system must be run on each VCPU.
  • Images running on a VCPU can have exclusive code segments or share code segments.
  • MIPS Microcomputer without interlocked pipeline stages
  • the implementation refers to There is a delay slot when jumping, that is to say, the delay slot is executed first when the actual execution, and then the jump instruction is executed. Therefore, two instructions must be modified at the same time, that is, the empty instruction NOP is used as the delay slot instruction and the jump instruction is modified to implement the patching operation.
  • the two instructions need to be modified to perform the patch operation, in the case of the shared code segment of the multi-core processor, not only the modification of the instruction but also the timing of the modification of the instruction and the immediate effect of the patch need to be considered. Because, in a multi-core processor, multiple VCPUs access the same code segment together. If a VCPU has executed the first instruction and another VCPU is modifying the instruction at this time, the first VCPU instruction is abnormal. Causes the system to crash.
  • the combination of the interrupt and the exception processing, and the combination of the message and the exception processing, respectively enable the patch to take effect quickly, and the normal service processing of each service VCPU is not affected.
  • the first to fourth embodiments are methods for patching shared code segments in a multi-core processor system operation by means of interrupts and exceptions; wherein, the first embodiment and the second The embodiment describes the process of the patching operation from the perspective of the main VCPU.
  • the third embodiment and the fourth embodiment explain the process of the patching operation from the perspective of each service VCPU.
  • the fifth to eighth embodiments are a method for patching a shared code segment in a multi-core processor system operation by means of a combination of a message and an exception; wherein the fifth embodiment and the sixth embodiment are The main VCPU angle illustrates the process of the patching operation, and the seventh embodiment and the eighth embodiment explain the process of the patching operation from the perspective of each service VCPU.
  • the original function in the following embodiment is a function that needs to be patched
  • the patch function is a function that replaces the original function
  • FIG. 1 is a flowchart of a method for patching a shared code segment according to a first embodiment of the present invention.
  • This embodiment illustrates a process of patching operations from the perspective of a main VCPU. As shown in FIG. 1 , this embodiment includes: Step 11: Before patching the original function, modify the first instruction of the original function to jump to the exception handling instruction in the shared memory;
  • the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and the purpose is to perform the original function in the subsequent modification process, if each service VCPU executes the original function, each The service VCPU enters the exception handling according to the instruction that jumps to the exception handling. Among them, the instruction to jump to exception handling can be break.;
  • the original function is a shared function that needs to be patched.
  • Step 12 Send a first interrupt message to each service VCPU.
  • the feature of the interrupt message is that after each service VCPU receives the interrupt message sent by the main VCPU, it That is, the current under execution service is stopped, and the interrupt message is processed.
  • the main VCPU sends the first interrupt information to each service VCPU.
  • the purpose is to instruct each service VCPU to interrupt the current service and immediately refresh its own fast instruction buffer after receiving the first interrupt information. Therefore, the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory. Since the fast instruction buffer access speed is higher than the memory access speed, the business VCPU usually transfers frequently used code segments from the shared memory into its own fast instruction buffer when executing the code segment. When these code segments are used, they are read directly from the fast instruction buffer, thereby increasing the access code speed.
  • a service VCPU receives the first interrupt information, it has transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, and after refreshing its own fast instruction buffer, its fast instruction buffer
  • the first instruction of the original function in the region is updated to the first instruction of the original function in the shared memory, that is, the instruction that jumps to the exception processing.
  • a service VCPU If a service VCPU receives the first interrupt information, it has not transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, and after refreshing its own fast instruction buffer, its fast instruction The instruction in the buffer is still the original instruction.
  • Step 13 In the shared memory, modify the first instruction and the second instruction of the original function to an instruction that jumps to the patch function;
  • the VCPU modifies the first instruction and the second instruction of the original function in the shared memory
  • the VCPUs executing the original function are jumped from the first instruction of the original function to the patch function, thereby realizing the original function.
  • the patch function is a function that replaces the original function.
  • the method for modifying the original function may be: first modify the second instruction of the original function into a delay slot instruction, that is, a NOP; and then modify the first instruction of the original function to an instruction that jumps to the patch function, that is, a JMP patch function. First address.
  • the main VCPU first modifies the first instruction of the original function, then the second instruction of the original function is modified. After the main VCPU changes the first instruction of the original function from the entry of the exception processing instruction to the jump instruction, and has not modified the second instruction of the original function into the delay slot instruction, the execution is performed to the original function first.
  • the service VCPU of the instruction will cause the system to crash because the second instruction is not a delay slot instruction and cannot be jumped to the patch function for execution.
  • the main VCPU is modified first to use the second instruction of the original function as the delay slot instruction, and then the first instruction of the original function is modified as the jump instruction.
  • the business VCPU executes to the original function To the first instruction, since the first instruction of the original function still enters the exception handling instruction (for example, break ), the service VCPU enters the exception processing through the first instruction, and does not continue to execute the second function of the original function. Instructions.
  • this embodiment avoids the effect of the delay slot instruction on patching the shared original function.
  • FIG. 1b is a flowchart of a patch execution in a method for patching a shared code segment according to a first embodiment of the present invention.
  • the service VCPU executes the instruction that jumps to the original function in the calling function
  • the call function jumps to the first function.
  • the instructions begin execution.
  • the service VCPU jumps from the original function to the patch function.
  • the execution reaches the end of the patch function, it returns to the calling function A, and continues to execute the instruction in the calling function A, thereby achieving the purpose of patching the original function.
  • Step 14 Send a second interrupt information to each service VCPU.
  • the second interrupt information is used to indicate the service VCPU, and the current service is interrupted to immediately refresh the respective fast instruction buffers.
  • the instructions in the fast instruction buffer of each service VCPU and the instructions in the shared memory are updated synchronously.
  • a certain service VCPU When the main VCPU modifies the first instruction and the second instruction of the original function in the shared memory, a certain service VCPU has transferred the first instruction and the second instruction of the original function from the shared memory to its own fast instruction.
  • the buffer after refreshing its own fast instruction buffer, will update the first instruction and the second instruction of the original function in its own fast buffer to the first function of the original function modified by the main VCPU.
  • the instruction and the second instruction is
  • the first instruction of the original function is first changed to the instruction that jumps to the exception processing, and is directed to the service VCPU.
  • the interrupt message is sent so that the service VCPU immediately refreshes the fast instruction buffer.
  • the service VCPU after receiving the interrupt information sent by the main CPU, the service VCPU does not need to send a response message to the main VCPU; and after the main CPU sends the interrupt information to the service VCPU, the original function can be patched.
  • the embodiment of the invention enables the patch to take effect quickly.
  • the VCPU performs a normal patching operation on the original function, while avoiding the effect of the delayed instruction on patching the shared original function. Therefore, in the embodiment of the present invention, a method for patching a shared code segment is performed on a primary VCPU pair.
  • the original function is patched, it does not affect the normal business processing of the service VCPU. It also enables the service VCPU executing the original function to jump from the original function to the patch function, without causing service congestion and loss of service data. .
  • FIG. 2 is a flowchart of a method for patching a shared code segment according to a second embodiment of the present invention.
  • the main VCPU has an error in the first instruction and the second instruction of the original function in step 13, and has performed step 14: sending a second interrupt message to each service VCPU.
  • the main VCPU restores the first instruction and the second instruction of the original function to the original original instruction by the method in this embodiment.
  • the embodiment includes:
  • Step 21 Before restoring the first instruction and the second instruction of the original function, modify the first instruction of the original function to jump to the instruction of the exception processing in the shared memory;
  • the instruction to jump to the exception processing can be break.
  • Step 22 Send a third interrupt message to each service VCPU.
  • the third interrupt information is used to instruct each service VCPU to interrupt the current service and immediately refresh its own fast instruction buffer, so that the instructions in the fast instruction buffer of each service VCPU and the instructions in the shared memory are updated synchronously;
  • Step 23 In the shared memory, restore the first instruction and the second instruction of the original function to the instruction before the original function is modified;
  • step 23 the main VCPU restores the first instruction and the second instruction of the original function to the instruction before the original function is patched, that is, the instruction before the original function is modified.
  • Step 24 Send a fourth interrupt information to each service VCPU.
  • the fourth interrupt information is used to indicate the service VCPU, and the current service is interrupted to immediately refresh the respective fast instruction buffers, so that the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory.
  • the main VCPU restores the first instruction and the second instruction of the original function
  • the first instruction of the original function is first modified to jump to the exception processing instruction, and the interrupt information is sent to the service VCPU to enable the service.
  • the VCPU immediately refreshes the fast instruction buffer.
  • the main VCPU restores the first instruction and the second instruction of the original function
  • the service VCPU executes the original function, it jumps to the exception processing finger. Let the exception handling, and then jump from the exception processing to the first address of the patch function, start executing the instructions in the patch function to ensure that the main VCPU restores the original function.
  • FIG. 3 is a flowchart of a method for patching a shared code segment according to a third embodiment of the present invention.
  • FIG. 3b is a signaling interaction diagram of a method for patching a shared code segment according to a third embodiment of the present invention.
  • This embodiment in conjunction with the action of the main VCPU in the embodiment shown in FIG. 1, mainly describes the process of the patching operation from the perspective of the service VCPU. Referring to FIG. 3a and FIG. 3b, this embodiment includes:
  • Step 31 After receiving the first interrupt information sent by the main VCPU, according to the indication of the first interrupt information, interrupting the current service and immediately refreshing the fast instruction buffer;
  • Each service VCPU interrupts the current service, and the purpose of immediately refreshing its own fast instruction buffer is to synchronize the instructions in its own fast instruction buffer with the instructions in the shared memory to ensure instruction and sharing in its own fast instruction buffer.
  • the corresponding instructions in the memory are consistent.
  • Step 32 When the first instruction to the original function is executed, according to the first instruction of the original function, the exception processing is entered;
  • a service VCPU receives the first interrupt information, it has transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, refreshing its own fast instruction buffer, and its fast instruction buffer.
  • the first instruction of the original function is updated to the first instruction of the original function in the shared memory, that is, the instruction that jumps to the exception processing.
  • the second interrupt information sent by the main VCPU has not been received, that is, before the first instruction of the original function is not updated in its own fast instruction buffer, when the service VCPU executes the first instruction, According to the instruction that jumps to the exception processing, the exception processing is entered.
  • a service VCPU receives the first interrupt information, it has not transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, and after refreshing its own fast instruction buffer, its fast instruction buffer The instructions in the zone are still the original instructions.
  • the service VCPU subsequently transfers the first instruction of the original function into the fast buffer, if the second interrupt information sent by the main VCPU has not been received, if the first instruction of the original function is executed, At this time, the first instruction is an instruction that jumps to the exception processing, and the service VCPU enters the exception processing according to the instruction that jumps to the exception processing.
  • Step 33 In the exception handling, according to the first address of the original function to be patched, find the first address of the patch function in the patch area;
  • the patch area stores the first address of the original function, the first address of the patch function, the mapping relationship between the original function and the patch function, and the first two instructions of the original function.
  • Step 34 According to the first address of the patch function, jump from exception processing to execution in the patch function.
  • the service VCPU finds the first address of the corresponding patch function in the patch area according to the first address of the original function. After finding the first address of the corresponding patch function, the return address of the exception processing is modified to the first address of the patch function, and then the exception function is processed into the patch function, and the instruction in the patch function is executed.
  • the service VCPU executes the first instruction of the original function, In the exception handling, the patch function is executed for execution. Thus, not only does it not affect the normal service processing of the service VCPU, but it also enables the service VCPU to execute the middle instruction of the patch function.
  • Step 35 After interrupting the current service according to the indication of the first interrupt information, after refreshing the fast instruction buffer, receiving the second interrupt information sent by the main VCPU, and interrupting the current service to refresh itself quickly according to the indication of the second interrupt information. Instruction buffer.
  • the service VCPU refreshes its own fast instruction buffer, which causes the instructions in the fast instruction buffer of the service VCPU itself to be updated synchronously with the instructions in the shared memory.
  • the service VCPU After interrupting the current service according to the indication of the first interrupt information, after the fast instruction buffer is refreshed, the service VCPU receives the second interrupt information sent by the main VCPU, indicating that the main VCPU has the first two functions of the original function in the shared memory.
  • the instruction is modified. If the first instruction and the second instruction of the original function are stored in the fast instruction buffer of the original function, the first instruction and the first instruction of the original function are refreshed after the fast instruction buffer is refreshed.
  • the two instructions are updated to the modified VCPU instruction, that is, the first is Jump and the second is Nop. After the update, when the service VCPU executes the first instruction to the original function, it jumps directly from the original function to the patch function, thereby implementing the patching operation on the original function.
  • each service VCPU immediately refreshes its respective fast instruction buffer after receiving the first interrupt information sent by the main CPU.
  • the service VCPU executes the first instruction to the original function, and does not receive the second interrupt information sent by the main VCPU, jumps to the exception processing according to the instruction that jumps to the exception processing, and then enters the patch from the exception processing.
  • the patch function is started. Therefore, in the embodiment of the present invention, the method for patching the shared code segment, when the main VCPU patches the original function, does not affect the normal service processing of the service VCPU, and can also execute the service VCPU from the original function to the original function. Jump to the patch function to execute.
  • FIG. 4a is a flowchart of a method for patching a shared code segment according to a fourth embodiment of the present invention.
  • the service VCPU receives the second interrupt information sent by the main VCPU in the embodiment corresponding to FIG. 3a, and may also receive the third middle sent by the main VCPU according to the refresh of the respective fast instruction buffers.
  • FIG. 4b is a signaling interaction diagram of a method for patching a shared code segment according to a fourth embodiment of the present invention.
  • This embodiment in conjunction with the execution flow of the main VCPU in the corresponding embodiment of FIG. 1 and FIG. 2, mainly illustrates the execution flow of the service VCPU after receiving the third interrupt information sent by the main VCPU, from the perspective of the service VCPU. As shown in FIG. 4a and FIG. 4b, this embodiment includes:
  • Step 41 After receiving the third interrupt information sent by the primary VCPU, interrupting the current service to immediately refresh the fast instruction buffer according to the indication of the third interrupt information.
  • the service VCPU receives the third interrupt message sent by the primary VCPU, indicating that the primary VCPU has modified the original function.
  • Each service VCPU immediately refreshes its own fast instruction buffer, so that its instructions in the fast instruction buffer are synchronized with the instructions in the shared memory.
  • Step 42 When executing the first instruction to the original function, according to the first instruction of the original function, enter the exception processing;
  • the main VCPU sends the third interrupt information to each service VCPU, the first instruction and the second instruction of the original function are restored to restore the original first instruction and the second instruction in the original function.
  • the exception processing is entered by the instruction that jumps to the exception processing. Therefore, it does not affect the normal business processing of the service VCPU.
  • Step 43 In the exception processing, according to the first address of the original function to be patched, the first address of the patch function is searched in the patch area; the patch function is a function that replaces the original function;
  • Step 44 According to the first address of the patch function, return from exception processing to execution in the patch function.
  • Step 45 After interrupting the current service according to the instruction of the third interrupt information, after refreshing the fast instruction buffer, receiving the fourth interrupt information sent by the main VCPU, and interrupting the current service to refresh itself quickly according to the indication of the second interrupt information. Instruction buffer.
  • the service VCPU refreshes its own fast instruction buffer, which causes the instructions in the fast instruction buffer of the service VCPU itself to be updated synchronously with the instructions in the shared memory.
  • the service VCPU After interrupting the current service and immediately refreshing its own fast instruction buffer according to the indication of the third interrupt information, the service VCPU receives the fourth interrupt information sent by the primary VCPU.
  • the main VCPU needs to restore the first instruction and the second instruction of the original function before modification, the first instruction of the original function is modified to jump to the exception processing.
  • the instruction then sends a third interrupt message to each service VCPU, causing each VCPU to refresh its respective instruction buffer. After the main VCPU sends the third interrupt message, it starts to enter the first two instructions of the original function. Line recovery operation.
  • the service VCPU executes the first instruction to the original function, it will enter the patch function by jumping to the exception handling instruction.
  • the method for patching the shared code segment when the main VCPU restores the original function, does not affect the normal service processing of the service VCPU, and can also execute the service VCPU from the original function to the original function. Jump to the patch function to execute.
  • FIG. 5 is a flowchart of a method for patching a shared code segment according to a fifth embodiment of the present invention.
  • This embodiment illustrates a process of patching operations from the perspective of a main VCPU.
  • this embodiment includes: Step 51: Before patching the original function, in the shared memory, modify the first instruction of the original function to jump to the exception processing instruction;
  • the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and the purpose is to perform other functions in the subsequent VCPU to modify the original function.
  • the service VCPU enters exception handling according to the instruction that jumps to the director's processing. Among them, the instruction to jump to exception handling can be break.;
  • the original function is a shared function that needs to be patched.
  • Step 52 Send a first patch activation message to each service VCPU.
  • the first patch activation message is used to instruct each service VCPU to refresh its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of each service VCPU itself is updated synchronously with the instruction in the shared memory;
  • the VCPU in the shared memory, modifies the first instruction and the second instruction of the original function.
  • the primary VCPU To determine the last service VCPU that refreshes its own fast instruction buffer, the primary VCPU saves all the service VCPU numbers that need to receive the first patch activation message in the shared memory before sending the first patch activation message.
  • each service VCPU After receiving the patch activation message and refreshing its own fast instruction buffer, each service VCPU records its own VCPU number in the shared memory and checks whether all the service VCPUs except itself have been recorded in the shared memory. The number, if it is, indicates that it is the last business VCPU.
  • the service VCPU does not immediately process the first patch activation message. Instead, after processing the current business, refresh its own fast instruction buffer.
  • the last service VCPU before refreshing its own fast instruction buffer, modifies the first instruction and the second instruction of the original function in the shared memory, that is, the original function is patched. If the service VCPU that modifies the original function instruction is not the last quick refresh command.
  • the service VCPU of the rushing area when the service VCPU modifies the first instruction and the second instruction of the original function in the shared memory, if the other service VCPU that does not refresh its own fast instruction buffer subsequently executes the first function to the original function
  • An instruction or a second instruction may cause an instruction execution error. Therefore, in the embodiment of the present invention, the last VCPU that refreshes its own buffer is used, and the first instruction and the second instruction of the original function are modified.
  • the service VCPU After the service VCPU processes the current service and processes the first patch activation information, that is, after refreshing its own fast instruction buffer, the first instruction of the original function is stored in its own fast instruction buffer, and the instruction is Jump to the instruction of exception handling.
  • the service VCPU executes the instruction in the original function, it enters the exception processing, and then enters the patch function from the exception processing.
  • the embodiment of the present invention is a method for patching a shared code segment.
  • the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and sends the first patch to the service VCPU.
  • the last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched.
  • the last service VCPU patches the original function
  • the other service VCPU executes the original function
  • the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
  • FIG. 6 is a flowchart of a method for patching a shared code segment according to a sixth embodiment of the present invention. After the step 52 of the embodiment corresponding to FIG. 5, if the modification of the original function by the service VCPU of the last fast instruction buffer is incorrect, the instruction of the original function is restored by this embodiment. Specifically, as shown in FIG. 6, the embodiment includes:
  • Step 61 Before restoring the first instruction and the second instruction of the original function, in the shared memory, modify the first instruction of the original function to jump to the instruction of the exception processing;
  • the instruction to jump to exception handling can be break.
  • Step 62 Send a second patch activation message to each service VCPU.
  • the second patch activation message is used to instruct each service VCPU to refresh its own fast instruction buffer, so that the instruction in the fast instruction buffer of each service VCPU itself is updated synchronously with the instruction in the shared memory; and the last refresh of each service VCPU is indicated.
  • the VCPU of its own fast instruction buffer restores the first instruction and the second instruction of the original function to the original instruction in the shared memory.
  • the second patch activation message in this embodiment differs from the first patch activation message in the corresponding implementation column of FIG. 5 in that the second patch activation message indicates the last service VCPU of the fast instruction buffer of its own refresh, in the shared memory. The first instruction and the second instruction of the original function are restored to the original instruction.
  • the main VCPU first modifies the first instruction of the original function to jump to the abnormality. Processing the instruction and sending a second patch activation message to the service VCPU.
  • the service VCPU processes the current service, after refreshing its own fast instruction buffer according to the second patch activation message, if the other service VCPU executes the first instruction of the original function, it jumps to the exception processing instruction, according to the jump to The exception-handled instruction enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the last service VCPU restores the original function, it does not affect the normal service processing of other service VCPUs, and does not cause traffic congestion and loss.
  • FIG. 7a is a flowchart of a method for patching a shared code segment according to a seventh embodiment of the present invention.
  • This embodiment mainly describes a process of patching operations from the perspective of a service VCPU. As shown in FIG. 7a, this embodiment includes :
  • Step 71a The service VCPU receives the first patch activation message sent by the primary VCPU.
  • the purpose of the first VCPU to send the first patch activation message is to enable each service VCPU to refresh its own fast instruction buffer after processing the current service.
  • the refresh can cause the first instruction of the modified original function in the shared memory to be transferred into the fast instruction buffer, thereby
  • the VCPU except the last service VCPU that refreshes its own fast instruction buffer
  • executes the first instruction to the original function it enters the exception handling, and then proceeds from the exception handling into the patch function.
  • Step 72a When the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the instruction of the first patch activation message, the first instruction and the second instruction of the original function are modified in the shared memory to Jump to the instruction of the patch function;
  • Step 73a The service VCPU refreshes its own fast instruction buffer, and the main VCPU notifies the other service VCPUs other than the service VCPU that refreshes its own fast instruction buffer to refresh its own fast instruction buffer.
  • the service VCPU refreshes its own fast instruction buffer, which causes its instructions in the fast instruction buffer to be updated synchronously with the instructions in the shared memory.
  • the embodiment of the present invention is a method for patching a shared code segment.
  • the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and sends a patch activation message to the service VCPU.
  • the service VCPU refreshes the fast instruction buffer after processing the current service.
  • the last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched.
  • the last service VCPU patches the original function
  • the other service VCPU executes the original function
  • the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
  • FIG. 7b is a flowchart of another method for patching a shared code segment according to a seventh embodiment of the present invention
  • FIG. 7c is another method for patching a shared code segment according to a seventh embodiment of the present invention.
  • the process of the patching operation is mainly described from the perspective of the service VCPU, as shown in FIG. 7b and FIG. 7c.
  • the embodiment includes: Step 71: The service VCPU receives the main VCPU. The first patch activation message sent;
  • Step 72 Determine whether it is the last service VCPU that refreshes its own fast instruction buffer.
  • the main VCPU saves in the shared memory before sending the first patch activation message. All service VCPU numbers that need to receive the first patch activation message.
  • Each service VCPU records its own VCPU number in the shared memory before receiving the patch activation message and refreshing its own fast instruction buffer. And according to all the service VCPU numbers that the main VCPU saves in the shared memory, need to receive the first patch activation message, and check whether the number of all service VCPUs other than itself is recorded in the shared memory, and if so, it indicates that it is the last A business VCPU.
  • Step 73 If the service VCPU is processing the current service and confirming that it is not the last VCPU that refreshes its own fast instruction buffer before refreshing its own fast instruction buffer, then step 73 is performed. Step 76, as follows:
  • Step 73 Refresh its own fast instruction buffer
  • Step 74 When executing the first instruction to the original function, according to the instruction of the original function jumping to the exception processing, the exception processing is entered; the first instruction that does not execute the original function indicates that the service is normally processed.
  • Step 75 In the exception processing, according to the first address of the original function to be patched, find the first address of the patch function in the patch area;
  • Step 76 According to the first address of the patch function, return from the exception processing to the execution of the patch function. If the service VCPU is processing the current service and refreshing its own fast instruction buffer before determining that it is the last VCPU to refresh its own fast instruction buffer, then perform steps 77 to 78, as follows:
  • Step 77 Modify the first instruction and the second instruction of the original function into an instruction to jump to the patch function in the shared memory;
  • the last service VCPU that refreshes its own fast instruction buffer the method of modifying the first instruction and the second instruction of the original function may be: first modify the second instruction of the original function into a delay slot instruction, that is, NOP; Modify the first instruction of the original function to the instruction that jumps to the patch function, that is, the first address of the JMP patch function.
  • Step 78 Refresh its own fast instruction buffer, and notify the other VCPUs through the main VCPU to refresh their fast instruction buffer.
  • the fast instruction buffer is used to synchronize the instructions in the fast instruction buffer of each service VCPU itself with the instructions in the shared memory.
  • the embodiment of the present invention is a method for patching a shared code segment.
  • the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and sends a patch activation message to the service VCPU.
  • the service VCPU refreshes the fast instruction buffer after processing the current service.
  • the last service VCPU that refreshes the fast instruction buffer, after patching the original function notifies other service VCPUs to refresh their respective fast instruction buffers.
  • the last service VCPU patches the original function
  • the other service VCPU executes the original function
  • the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function.
  • the normal service processing of other service VCPUs will not cause traffic congestion and loss.
  • FIG. 8a is a flowchart of a method for patching a shared code segment according to an eighth embodiment of the present invention. After the step 72 of the embodiment corresponding to FIG. 7, if the modification of the original function by the service VCPU of the last fast instruction buffer is incorrect, the instruction of the original function is restored by this embodiment.
  • FIG. 8b is a signaling interaction diagram of a method for patching a shared code segment according to an eighth embodiment of the present invention. Specifically, as shown in FIG. 8a and FIG. 8b, this embodiment includes:
  • Step 81 Receive a second patch activation message sent by the primary VCPU.
  • the purpose of sending the second patch activation message to each service VCPU is to enable each service VCPU to refresh itself after processing the current service.
  • the instructions in the fast instruction buffer are used to synchronize the instructions in their own fast instruction buffer with the instructions in the shared memory.
  • the main VCPU first modifies the first instruction to break, and then sends the first instruction to the service VCPU.
  • Two patch activation messages The difference between the second patch activation message and the first patch activation message is that the service VCPU indicating the last refresh of the fast instruction buffer restores the first instruction and the second instruction of the original function to the original function. instruction.
  • Step 82 Determine whether it is the last service VCPU that refreshes its own fast instruction buffer
  • each service VCPU After processing the current service, each service VCPU needs to determine whether it is the last service VCPU that refreshes its own fast instruction buffer before refreshing its own fast instruction buffer to perform different operations according to the first patch activation message. . If it is not the last service VCPU that refreshes its own fast instruction buffer, go to step 83 to step 86:
  • Step 83 Refresh its own fast instruction buffer
  • Step 84 According to the first instruction of the original function, enter exception processing
  • the service VCPU executes the first instruction to the original function, because the instruction in its own fast instruction buffer has been updated synchronously with the shared memory, the first instruction of the original function in its own fast instruction buffer is a jump. Go to the exception handling instructions. Therefore, the service VCPU enters the exception processing from the first instruction of the original function, and executes the exception handler. The first instruction that did not execute the original function indicates that the service is processed normally.
  • Step 85 In the exception handling, according to the first address of the original function to be patched, check in the patch area. Find the first address of the patch function;
  • Step 86 According to the first address of the patch function, return from the exception processing to the patch function. If it is the last service VCPU that refreshes its own fast instruction buffer, perform steps 87 to 88, as follows:
  • Step 87 Restore the first instruction and the second instruction of the original function in the shared memory; the last service VCPU that refreshes its own fast instruction buffer, and the method of modifying the original function first instruction and the second instruction For: first the second instruction of the original function (delay slot instruction, ie
  • NOP restores the second instruction before the modification of the original function, and restores the first instruction of the original function (the instruction that jumps to the exception processing, ie, break) to the first instruction before the modification of the original function.
  • Step 88 Refresh its own fast instruction buffer, and notify the other VCPUs of the service VCPU to refresh their fast instruction buffer through the main VCPU.
  • the fast instruction buffer is used to synchronize the instructions in the fast instruction buffer of each service VCPU itself with the instructions in the shared memory.
  • the main VCPU first modifies the first instruction of the original function to jump to the abnormality. Processing the instruction and sending a second patch activation message to the service VCPU.
  • the service VCPU processes the current service, after refreshing its own fast instruction buffer according to the second patch activation message, if the other service VCPU executes the first instruction of the original function, it jumps to the exception processing instruction, according to the jump to The exception-handled instruction enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the last service VCPU restores the original function, it does not affect the normal service processing of other service VCPUs, and does not cause traffic congestion and loss.
  • the ninth embodiment and the eleventh embodiment are devices for patching the original function in a combination of an interrupt and an abnormality;
  • the twelfth to sixteenth embodiments are a combination of a message and an abnormality Method, a device that patches the original function.
  • FIG. 9 is a schematic structural diagram of an apparatus for patching a shared code segment according to a ninth embodiment of the present invention.
  • the embodiment includes: a first modification module 91, a first interruption module 92, a first patch module 93, and a second interrupt module 94.
  • the first modification module 91 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory before the main VCPU patches the original function; wherein, the original function is a shared function that needs to be patched.
  • the first interrupt module 92 sends the first interrupt message to the service VCPU after the first modification module 91 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory.
  • the first interrupt information is used to instruct each service VCPU to interrupt the current service and immediately refresh its own fast instruction buffer, so that the modified instruction of the first modification module 91 takes effect quickly. Therefore, when the main VCPU patches the original function, each service VCPU is caused to jump to the exception processing according to the first instruction of the original function.
  • the first patch module 93 modifies the first instruction and the second instruction of the original function into an instruction to jump to the patch function in the shared memory.
  • the specific operation of the first patch module 93 may be: first modifying the second instruction of the original function into a delay slot instruction; modifying the first instruction of the original function to an instruction that jumps to the patch function. Because the first patch module 93 changes the first instruction and the second instruction of the original function to the instruction to jump to the patch function in the shared memory, each service VCPU has refreshed according to the instruction of the first interrupt information. Its own fast instruction buffer. Therefore, if each service VCPU executes the original function, it will jump to the exception processing, so that it is not affected by the patching of the original function by the first patch module 93.
  • the second interrupt module 94 sends the second interrupt information to the service VPCU after the first patch module 93 modifies the first instruction and the second instruction of the original function to jump to the patch function in the shared memory.
  • the second interrupt information is used to instruct each service VCPU to interrupt the current service and refresh its own fast instruction buffer, so that the patch function of the original function is decelerated.
  • the first modification module 91 first modifies the first instruction of the original function to jump to the exception processing.
  • the instruction, and instructing the first interrupt module 92 to send an interrupt message to the service VCPU causes the service VCPU to immediately refresh the fast instruction buffer.
  • the service VCPU after receiving the interrupt information sent by the first patch module 93, the service VCPU does not need to send a response message to the main VCPU; and after the first patch module 93 sends the interrupt information to the service VCPU, the original function can be The patching operation is performed. Therefore, the embodiment of the present invention enables the patch to take effect quickly.
  • the device for patching the shared code segment does not affect the normal service processing of the service VCPU when the first patch module 93 patches the original function, and can also perform the service VCPU to the original function. Jump from the original function to the patch function, and will not cause business blocking and business data loss.
  • FIG. 10 is a schematic structural diagram of an apparatus for patching a shared code segment according to a tenth embodiment of the present invention, as shown in FIG.
  • the second interrupt module 94 has sent the second interrupt information to each service VCPU. Then, by using the first recovery module in this embodiment, the first instruction and the second instruction of the original function are restored to the instruction before the original function is modified. details as follows:
  • the first instruction of the original function is modified to Jump to the instruction of exception handling.
  • the third interrupt module 96 sends a third interrupt message to the service VCPU to indicate that the service VCPU interrupts the current Business, refresh its own fast instruction buffer.
  • the first recovery module 97 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory.
  • the fourth interrupt module 98 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory in the first recovery module 97, and then sends the fourth interrupt information to the service VCPU.
  • the current service is interrupted and the respective fast instruction buffers are refreshed, so that the instructions in the fast instruction buffer of the service VCPU itself are updated synchronously with the instructions in the shared memory.
  • the second modification module 95 first modifies the first instruction of the original function to jump to the instruction of the exception processing, and passes the instruction.
  • the third interrupt module 96 sends a third interrupt message to the service VCPU, so that the service VCPU immediately refreshes the fast instruction buffer.
  • the first recovery module 94 When the first recovery module 94 performs the patching operation on the original function, if the service VCPU executes the original function, the patch function is entered from the exception processing. Therefore, in the embodiment, when the first recovery module 97 patches the original function, It does not affect the normal service processing of the service VCPU, and will not cause traffic congestion and data loss.
  • FIG. 11a is a schematic structural diagram of an apparatus for patching a shared code segment according to an eleventh embodiment of the present invention. As shown in FIG. 11a, the embodiment includes: a first refresh module 111, a first exception processing module 112, and a first patch function execution module 113 and a second refresh module 114.
  • the first refresh module 111 interrupts the current service and immediately refreshes the fast instruction buffer according to the instruction of the first interrupt information, so that the instruction in the fast instruction buffer of the service VCPU itself is Synchronous updates to instructions in shared memory.
  • the first exception processing module 112 enters the exception processing according to the instruction of the original function to jump to the exception processing; in the exception processing, the original function that needs to be patched according to the need The first address, find the first address of the patch function in the patch area; the patch function is a function that replaces the original function.
  • the first patch function execution module 113 returns from the exception processing to the first address of the patch function, and executes the patch function.
  • the primary service VCPU After the primary service VCPU sends the first interrupt information to the service VCPU, it performs the operation of patching the original function, and sends the second interrupt information to each service VCPU after the original function is patched. Therefore, the second refreshing module 114 interrupts the current service according to the instruction of the first interrupt information, refreshes the fast instruction buffer, and receives the second interrupt information sent by the main VCPU according to the indication of the second interrupt information. Interrupt the current service and refresh its own fast instruction buffer to synchronize the instructions in the fast instruction buffer of the service VCPU itself with the instructions in the shared memory.
  • the service VCPU can pass the following modules: the third refresh module 115, the second The exception handling module 116, the second patch function execution module 117, and the fourth refresh module 118 process the interaction with the master VPUC without affecting the normal processing of the current service.
  • the third refresh module 115 receives the third interrupt information sent by the main VCPU, and interrupts the current service according to the instruction of the third interrupt information, and refreshes its own fast instruction buffer.
  • the second exception processing module 116 refreshes the fast finger in the third refresh module 115.
  • the fourth refresh module 118 after the third refresh module 115 interrupts the current service according to the instruction of the third interrupt information, and refreshes its own fast instruction buffer, receives an indication of the fourth interrupt information sent by the main VCPU, according to the fourth interrupt information. Instructs to interrupt the current service and refresh its own fast instruction buffer to synchronize the instructions in the fast instruction buffer of the service VCPU itself with the instructions in the shared memory.
  • the first refresh module 111 immediately refreshes the respective fast instruction buffers after receiving the interrupt information sent by the main CPU.
  • the service VCPU executes the first instruction to the original function, and does not receive the second interrupt information sent by the main VCPU, jumps to the exception processing according to the instruction that jumps to the exception processing, and then enters the patch from the exception processing.
  • the patch function is started. Therefore, in this embodiment, when the primary VCPU patches or restores the original function, it does not affect the normal service processing of the service VCPU, and can also cause the service VCPU executing the original function to jump from the original function to the patch function. carried out.
  • FIG. 12 is a schematic structural diagram of an apparatus for patching a shared code segment according to a twelfth embodiment of the present invention. As shown in FIG. 12, the embodiment includes: a third modification module 121 and a first message sending module 122.
  • the third modification module 121 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory.
  • the first message sending module 122 sends the first patch activation message to each service VCPU after the first modification module 121 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory.
  • the first patch activation message is used to instruct each service VCPU to refresh its own fast instruction buffer after processing the current service, so that the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory.
  • the first patch activation message also indicates the last VCPU that refreshes its own fast instruction buffer, and modifies the first instruction and the second instruction of the original function in the shared memory.
  • the first message sending module 122 sends the first patch to the service VCPU. Activate the message to refresh the fast instruction buffer after the service VCPU has processed the current service.
  • the last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched.
  • the last service VCPU patches the original function
  • the other service VCPU executes the original function
  • the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
  • FIG. 13 is a schematic structural diagram of an apparatus for patching a shared code segment according to a thirteenth embodiment of the present invention. As shown in FIG. 13, on the basis of the corresponding embodiment of FIG. 12, the embodiment further includes: a second message sending module 124 and a fourth modifying module 123.
  • the second message sending module 124 of the embodiment may send a second activation patch message to each service VCPU to indicate the last VCPU that refreshes its own fast instruction buffer. Modify one instruction and the second instruction of the original function to the original instruction of the original function.
  • the fourth modification module 123 after the first message sending module sends the first patch activation message to the service VCPU, modify the first instruction of the original function to jump to the abnormal processing instruction in the shared memory.
  • the second message sending module 124 sends the second patch activation message to each service VCPU after the first modification module 123 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory.
  • the activation message is used to instruct each service VCPU to refresh its own fast instruction buffer, so that the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory.
  • the second patch activation message also indicates that the VCPU of the fast instruction buffer of each service VCPU is refreshed by itself, and in the shared memory, the first instruction and the second instruction of the original function are restored to the original function. instruction.
  • the fourth modification module 124 first modifies the first instruction of the original function to jump to the exception processing instruction, and the second message sending module 123 sends the second patch activation to the service VCPU.
  • the service VCPU processes the current service, after refreshing its own fast instruction buffer according to the second patch activation message, if the other service VCPU executes the first instruction of the original function, it jumps to the exception processing instruction, according to the jump to The exception-handled instruction enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the last service VCPU restores the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
  • FIG. 14 is a schematic structural diagram of an apparatus for patching a shared code segment according to a fourteenth embodiment of the present invention. As shown in FIG. 14, the embodiment includes: a first receiving module 141, a second patch module 142, and a first refresh notification module 143 and a determining module 144.
  • the determining module 144 determines.
  • Current Service VCPU is the last service VCPU that refreshes its own fast instruction buffer.
  • the second patch module 142 modifies the first two instructions of the original function in the shared memory according to the indication of the first patch activation message.
  • the first refresh notification module 143 refreshes the fast instruction buffer of the service VCPU after the second patch module modifies the first instruction and the second instruction of the original function into the instruction to jump to the patch function in the shared memory, and
  • the VCPU notifies the other service VCPUs other than the service VCPU that refreshes its own fast instruction buffer by the main VCPU to refresh its own fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself and the instruction in the shared memory Synchronization Update.
  • the embodiment of the present invention is a device for patching a shared code segment.
  • the main VCPU modifies the first instruction of the original function to jump to the instruction of the exception processing, and sends a patch activation message to the service VCPU.
  • the service VCPU refreshes the fast instruction buffer after processing the current service.
  • the last service VCPU that refreshes the fast instruction buffer, after patching the original function notifies other service VCPUs to refresh their respective fast instruction buffers.
  • the last service VCPU patches the original function
  • the other service VCPU executes the original function
  • the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execution
  • Execution The instruction in the function. Therefore, when the second patch module 142 performs the patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
  • FIG. 15 is a block diagram showing the structure of a device for patching a shared code segment according to a fifteenth embodiment of the present invention.
  • the second receiving module 145 receives the second patch activation message sent by the primary VCPU. Time.
  • the judging module 144 judges that the current service VCPU is the last service VCPU that refreshes its own fast instruction buffer.
  • the second recovery module 146 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory after the service VCPU processes the current service according to the indication of the second patch activation message. .
  • the second refresh notification module 147 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory, and refreshes the fast instruction buffer of the service VCPU.
  • the area, and the main VCPU notifies the service VCPU except the service VCPU that refreshes its own fast instruction buffer to refresh its own fast instruction buffer, so that the instruction and sharing in the fast instruction buffer of the service VCPU itself In-memory instructions are updated synchronously.
  • the service VCPU processes the current service and refreshes its own fast instruction buffer according to the second patch activation message
  • the instruction jumps to the exception processing instruction, according to The instruction that jumps to the exception handling enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the second recovery module 146 performs the recovery operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service blocking and loss.
  • FIG. 16 is a diagram of a device for patching a shared code segment according to a sixteenth embodiment of the present invention.
  • the present embodiment further includes: a fifth refresh module 148, a third exception processing module 149, and a third patch function execution module 140, based on the corresponding embodiment of FIG.
  • the fifth refreshing module 148 determines in the determining module 144 that the current service VCPU is not When the service VCPU of the fast instruction buffer of the current service is refreshed, after the current service VCPU processes the current service, the fast instruction buffer of the service VCPU is refreshed according to the indication of the first patch activation message or the second patch activation message. Thereby, the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory.
  • the third exception processing module 149 enters the exception processing according to the instruction of the original function to jump to the exception processing; and in the exception processing, according to the first address of the original function, Find the first address of the patch function in the patch area. After the third exception processing module 149 finds the first address of the patch function, the third patch function execution module 140 jumps from the exception processing to the patch function according to the first address of the patch function.
  • the embodiment of the present invention is a device for patching a shared code segment.
  • the main VCPU modifies the first instruction of the original function to jump to the instruction of the exception processing, and sends a patch activation message to the service VCPU.
  • the service VCPU refreshes the fast instruction buffer after processing the current service.
  • the last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched.
  • the last service VCPU patches the original function
  • the other service VCPU executes the original function
  • the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the second patch module 142 performs the patch operation on the original function, it does not affect the normal service processing of the VCPU of other services, and does not cause service congestion and loss.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a method and a device for patching a shared code segment. The method for patching the shared code segment includes the following steps: before a primitive function is patched, modifying a first instruction of the primitive function into an instruction for jumping to an exception handling in a shared memory, wherein the primitive function is a shared function that needs to be patched; sending a first interrupt message to each service VCPU (virtual CPU), wherein the first interrupt information is used to indicate each service VCPU to interrupt current services and instantly refresh its fast instruction buffer; modifying the first instruction and a second instruction of the primitive function into instructions for jumping to a patching function; and sending a second interrupt information to each service VCPU to indicate each service VCPU to interrupt the current services and instantly refresh its fast instruction buffer. The embodiment of the invention realizes patching the shared code segment and enabling the patch to take effect quickly without interfering with the normal service processing of the service VCPUs.

Description

为共享代码段打补丁的方法及装置 本申请要求于 2010 年 3 月 26 日提交中国专利局、 申请号为 201010138932.4. 发明名称为"为共享代码段打补丁的方法及装置"的中国专 利申请的优先权, 其全部内容通过引用结合在本申请中。 技术领域 本发明实施例涉及计算机技术领域,尤其涉及一种为共享代码段打补丁的 方法及装置。  Method and apparatus for patching shared code segments This application claims to be filed on March 26, 2010, the Chinese Patent Office, Application No. 201010138932.4. The Chinese patent application entitled "Method and Apparatus for Patching Shared Code Segments" Priority is hereby incorporated by reference in its entirety. The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for patching shared code segments.
背景技术 Background technique
补丁技术作为一种升级手段越来越受到关注。 在计算机系统运行过程中, 由于软件存在的某种错误往往会造成系统出现异常或崩溃,为了弥补这样的错 误, 可以采用补丁技术对存在问题的软件进行升级。 在这个过程中, 不会影响 到正常业务的处理。  Patch technology is gaining more and more attention as an upgrade tool. In the process of running a computer system, some errors in the software often cause abnormalities or crashes in the system. To compensate for such errors, patch software can be used to upgrade the software in question. In this process, it will not affect the processing of normal business.
软件中出现错误的地方往往存在于一个或多个函数中 ,这些有错误的原函 数会被其他函数调用。 虽然找到这些调用函数比较困难, 但是 4艮容易找到出错 的原函数。 因此, 打补丁的关键操作应关注于这些出错的原函数上。 打补丁的 过程为:在调用这些错误的原函数时,从错误的原函数跳转到修改后的函数(即 补丁函数)上, 执行完补丁函数后再返回到调用函数。 如此, 软件将永远不会 执行错误的原函数, 从而完成对软件的修改。  Errors in the software often exist in one or more functions, and these erroneous primitives are called by other functions. Although it is difficult to find these calling functions, it is easy to find the original function of the error. Therefore, the key operations of patching should focus on the original function of these errors. The process of patching is: when calling the original function of these errors, jump from the wrong original function to the modified function (that is, the patch function), and then return to the calling function after executing the patch function. In this way, the software will never execute the wrong original function, thus completing the modification of the software.
多核处理器环境下, 现有的对共享代码段进行打补丁的方法中, 主虚拟 CPU ( Virtual CPU, 简称 VCPU ) VCPU向执行共享代码段的所有业务 VCPU发 送同步消息, 通知各业务 VCPU需要进行补丁操作。 各业务 VCPU收到同步消 息后, 停止自己正常的业务处理, 进入等待打补丁状态, 并向主 VCPU发送响 应消息通知自己已进入等待状态。主 VCPU收到所有业务 VCPU的响应消息后, 对需要打补丁的原函数中指令进行修改即进行打补丁操作规程, 以使业务 In the multi-core processor environment, in the existing method of patching the shared code segment, the main virtual CPU (VCPU) VCPU sends a synchronization message to all service VCPUs executing the shared code segment, and notifies each service VCPU that the service VCPU needs to perform Patch operation. After receiving the synchronization message, each service VCPU stops its normal service processing, enters the waiting for patching state, and sends a response message to the primary VCPU to notify itself that it has entered the waiting state. After receiving the response message of all the VCPUs of the service, the main VCPU modifies the instructions in the original function that needs to be patched, and then performs the patching operation procedure to enable the service.
VCPU执行到原函数时从原函数跳转到补丁函数。 修改完指令后, 向所有业务 VCPU发送完成同步消息, 通知所有业务 VCPU补丁操作已经完成。 所有业务 VCPU收到完成补丁操作的同步消息后, 刷新各自的快速指令緩沖区使修改后 的指令生效, 然后进行正常的业务处理。 该方案, 虽然避免了主 VCPU在补丁 操作时, 主 VCPU与业务 VCPU之间相互影响的问题, 即主 VCPU修改指令时, 不会有业务 VCPU执行到当前修改指令处。 The VCPU jumps from the original function to the patch function when it executes the original function. After modifying the instructions, to all services The VCPU sends a completion synchronization message to notify all service VCPU that the patch operation has been completed. After receiving the synchronization message for completing the patch operation, all service VCPUs refresh their respective fast instruction buffers to make the modified instructions take effect, and then perform normal service processing. In this solution, although the problem that the main VCPU interacts with the service VCPU during the patch operation is avoided, that is, when the main VCPU modifies the instruction, there is no service VCPU executing to the current modification instruction.
在实现本发明过程中,发明人发现现有技术中至少存在如下问题: 在现有 方案中, 主 VCPU向所有业务 VCPU发送打补丁的同步消息后, 需要接收到所 有业务 VCPU发送的响应消息, 才能对共享代码段进行打补丁操作; 并且所有 业务 VCPU只有在接收到主 VCPU发送的完成补丁操作的同步消息后, 才能进 行正常的业务处理。 因此, 如果某个业务 VCPU当前的业务很繁忙, 在接收到 主 VCPU发送的打补丁的同步消息后, 无法及时向主 VCPU发送响应消息, 则 会造成其他业务 VCPU和主 VCPU都进入等待打补丁状态。 从而导致补丁生效 时间较长, 使其它业务 VCPU不能正常处理业务。  In the process of implementing the present invention, the inventors have found that at least the following problems exist in the prior art: In the existing solution, after the primary VCPU sends the patched synchronization message to all service VCPUs, it needs to receive the response message sent by all service VCPUs. The shared code segment can be patched; and all service VCPUs can perform normal service processing only after receiving the synchronization message of the completion patch operation sent by the primary VCPU. Therefore, if the current service of a service VCPU is busy, after receiving the patched synchronization message sent by the primary VCPU, the response message cannot be sent to the primary VCPU in time, causing other service VCPUs and the primary VCPU to enter the waiting for patching. status. As a result, the patch takes effect for a long time, which prevents other services VCPUs from processing services.
发明内容 Summary of the invention
本发明实施例提供一种为共享代码段打补丁的方法及装置,用以解决现有 为共享代码段打补丁的方法中, 补丁生效时间较长, 影响业务 VCPU正常处理 业务的缺陷, 实现了在不影响业务 VCPU正常业务处理的情况下, 对共享代码 段进行补丁操作并使补丁快速生效。  The embodiment of the present invention provides a method and a device for patching a shared code segment, which is used to solve the defect that the patch is valid for a shared code segment, and the patch takes effect for a long time, which affects the normal processing service of the service VCPU. Patching the shared code segment and making the patch take effect quickly without affecting the normal business processing of the service VCPU.
本发明实施例提供一种为共享代码段打补丁的方法, 包括:  An embodiment of the present invention provides a method for patching a shared code segment, including:
为原函数打补丁前,在共享内存中,将原函数的第一条指令修改为跳转到 异常处理的指令, 所述原函数为需要打补丁的共享函数;  Before patching the original function, in the shared memory, the first instruction of the original function is modified to jump to the exception handling instruction, and the original function is a shared function that needs to be patched;
向业务 VCPU发送第一中断消息, 所述第一中断信息用于指示所述业务 VCPU中断当前业务, 刷新自身的快速指令緩冲区;  Sending a first interrupt message to the service VCPU, where the first interrupt information is used to indicate that the service VCPU interrupts the current service, and refreshes its own fast instruction buffer;
在所述共享内存中,将所述原函数的第一条指令和第二条指令修改为跳转 到补丁函数的指令, 以使执行到所述原函数的所述业务 VCPU从所述原函数跳 转到所述补丁函数, 所述补丁函数为替换所述原函数的函数;  In the shared memory, modifying the first instruction and the second instruction of the original function into an instruction to jump to the patch function, so that the service VCPU executing the original function is executed from the original function Jumping to the patch function, the patch function is a function that replaces the original function;
向所述业务 VCPU发送第二中断信息, 所述笫二中断信息用于指示所述业 务 VCPU中断当前业务, 刷新自身的快速指令缓冲区。 本发明实施例提供一种为共享代码段打补丁的方法, 包括: 接收到主 VCPU发送的第一中断信息后, 根据所述第一中断信息的指示, 中断当前业务, 刷新快速指令緩冲区, 以使所述业务 VCPU自身的快速指令緩 冲区中指令与所述共享内存中指令同步更新, 所述原函数为需要打补丁的函 数; Sending a second interrupt information to the service VCPU, where the second interrupt information is used to instruct the service VCPU to interrupt the current service and refresh its own fast instruction buffer. The embodiment of the present invention provides a method for patching a shared code segment, including: after receiving the first interrupt information sent by the main VCPU, interrupting the current service according to the instruction of the first interrupt information, and refreshing the fast instruction buffer. So that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory, and the original function is a function that needs to be patched;
执行到原函数的第一条指令时,根据所述原函数的第一条指令, 进入异常 处理, 在所述异常处理中, 根据所述原函数的首地址, 在补丁区查找出补丁函 数的首地址, 所述补丁函数为替换所述原函数的函数; 根据所述补丁函数的首 地址, 从所述异常处理跳转到所述补丁函数中执行;  When the first instruction of the original function is executed, according to the first instruction of the original function, an exception processing is entered, in which the patch function is found in the patch area according to the first address of the original function. a first address, the patch function is a function that replaces the original function; and jumps from the exception processing to the patch function according to a first address of the patch function;
在根据所述第一中断信息的指示, 中断当前业务,刷新快速指令緩冲区之 后, 接收所述主 VCPU发送的第二中断信息;  Receiving, according to the indication of the first interrupt information, interrupting the current service, and after refreshing the fast instruction buffer, receiving the second interrupt information sent by the primary VCPU;
根据所述第二中断信息的指示, 中断当前业务,刷新自身的快速指令緩沖 区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与所述共享内存中指令 同步更新。  And interrupting the current service according to the indication of the second interrupt information, and refreshing the fast instruction buffer area of the service, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
本发明实施例提供一种为共享代码段打补丁的装置, 包括:  An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
第一修改模块, 用于为原函数打补丁前, 在共享内存中, 将原函数的第一 条指令修改为跳转到异常处理的指令, 所述原函数为需要打补丁的共享函数; 第一中断模块, 用于在所述第一修改模块在共享内存中,将原函数的第一 条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送第一中断消息, 所 述中断信息用于指示所述业务 VCPU中断当前业务, 刷新自身的快速指令緩冲 区;  a first modification module, configured to modify, in the shared memory, the first instruction of the original function to jump to an exception processing instruction before the original function is patched, where the original function is a shared function that needs to be patched; An interrupt module, configured to: after the first modification module in the shared memory, modify the first instruction of the original function to jump to the exception processing instruction, send a first interrupt message to the service VCPU, where the interrupt information is Used to instruct the service VCPU to interrupt the current service and refresh its own fast instruction buffer;
第一补丁模块, 用于在所述第一中断模块向所述业务 VPCU发送第一中断 信息后,在所述共享内存中,将所述原函数的第一条指令和第二条指令修改为 跳转到补丁函数的指令, 以使执行到所述原函数的所述业务 VCPU从所述原函 数跳转到所述补丁函数, 所述补丁函数为替换所述原函数的函数;  a first patch module, configured to: after the first interrupt module sends the first interrupt information to the service VPCU, in the shared memory, modify the first instruction and the second instruction of the original function to Jumping to an instruction of the patch function, so that the service VCPU executing to the original function jumps from the original function to the patch function, and the patch function is a function that replaces the original function;
第二中断模块, 用于在所述第一补丁模块在所述共享内存中,将所述原函 数的第一条指令和第二条指令修改为跳转到补丁函数的指令后, 向所述业务 VPCU发送第二中断信息。  a second interrupt module, configured to: after the first patch module in the shared memory, modify the first instruction and the second instruction of the original function to jump to a patch function, The service VPCU sends a second interrupt message.
本发明实施例提供一种为共享代码段打补丁的装置, 包括:  An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
第一刷新模块, 用于接收到主 VCPU发送的第一中断信息后, 根据所述第 一中断信息的指示,中断当前业务,刷新快速指令緩冲区,以使所述业务 VCPU 自身的快速指令緩冲区中指令与所述共享内存中指令同步更新,所述原函数为 需要打补丁的函数; a first refreshing module, configured to receive the first interrupt information sent by the main VCPU, according to the first An interrupt instruction indicates that the current service is interrupted, and the fast instruction buffer is refreshed, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory, and the original function needs to be patched. The function;
第一异常处理模块,用于在所述第一刷新模块刷新快速指令緩冲区后,执 行到原函数的第一条指令时, 根据所述原函数的第一条指令, 进入异常处理, 在所述异常处理中,根据所述原函数的首地址, 在补丁区查找出补丁函数的首 地址, 所述补丁函数为替换所述原函数的函数;  a first exception processing module, configured to: after the first refresh module refreshes the fast instruction buffer, execute the first instruction to the original function, according to the first instruction of the original function, enter an exception processing, In the exception processing, according to the first address of the original function, the first address of the patch function is found in the patch area, and the patch function is a function that replaces the original function;
第一补丁函数执行模块,用于在所述第一异常处理模块查找出所述补丁函 数的首地址后,根据所述补丁函数的首地址,从所述异常处理跳转到所述补丁 函数中执行;  a first patch function execution module, configured to: after the first exception processing module finds the first address of the patch function, jump from the exception processing to the patch function according to a first address of the patch function carried out;
第二刷新模块, 用于在所述第一刷新模块根据所述第一中断信息的指示, 中断当前业务, 刷新快速指令緩沖区之后, 接收所述主 VCPU发送的第二中断 信息, 根据所述第二中断信息的指示, 中断当前业务, 刷新自身的快速指令緩 冲区, 以使所述业务 VCPU自身的快速指令缓冲区中指令与所述共享内存中指 令同步更新  a second refreshing module, configured to: after the first refreshing module interrupts the current service according to the indication of the first interrupt information, and after refreshing the fast instruction buffer, receive the second interrupt information sent by the primary VCPU, according to the The indication of the second interrupt information, interrupting the current service, refreshing its own fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory
本发明实施例为共享代码段打补丁的方法及装置,在多核处理器系统运行 过程中, 在主 VCPU对原函数进行打补丁操作之前, 将原函数的第一条指令先 修改为跳转到异常处理的指令, 并向业务 VCPU发送中断信息, 使业务 VCPU 立即刷新快速指令緩冲区。 由于, 本发明实施例中业务 VCPU接收到主 CPU发 送的中断信息后, 不需要向主 VCPU发送响应消息; 并且主 CPU向业务 VCPU 发送中断信息后, 即可对原函数进行打补丁操作, 因此, 本发明实施例能使补 丁快速生效。 另外, 在主 VCPU对原函数打补丁操作时, 若业务 VCPU执行到 原函数则从异常处理进入补丁函数, 能保证主 VCPU对原函数进行正常的打补 丁操作。 因此本发明实施例为共享代码段打补丁的方法, 在主 VCPU对原函数 打补丁操作时, 不会影响到该业务 VCPU的正常业务处理, 还能使执行到原函 数的业务 VCPU从原函数跳转到补丁函数中执行。  In the embodiment of the present invention, a method and a device for patching a shared code segment are performed. In the running process of the multi-core processor system, before the main VCPU performs a patching operation on the original function, the first instruction of the original function is first modified to jump to The exception-handled instruction sends an interrupt message to the service VCPU, causing the service VCPU to immediately flush the fast instruction buffer. In the embodiment of the present invention, after receiving the interrupt information sent by the main CPU, the service VCPU does not need to send a response message to the main VCPU; and after the main CPU sends the interrupt information to the service VCPU, the original function can be patched. The embodiment of the invention enables the patch to take effect quickly. In addition, when the main VCPU patches the original function, if the service VCPU executes the original function, it enters the patch function from the exception processing, which ensures that the main VCPU performs the normal patching operation on the original function. Therefore, in the embodiment of the present invention, the method for patching the shared code segment, when the main VCPU patches the original function, does not affect the normal service processing of the service VCPU, and can also execute the service VCPU from the original function to the original function. Jump to the patch function to execute.
本发明实施例提供一种为共享代码段打补丁的方法, 包括:  An embodiment of the present invention provides a method for patching a shared code segment, including:
为原函数打补丁前,在共享内存中,将原函数的第一条指令修改为跳转到 异常处理的指令, 所述原函数为需要打补丁的函数;  Before patching the original function, in the shared memory, the first instruction of the original function is modified to jump to the exception handling instruction, and the original function is a function that needs to be patched;
向各业务 VCPU发送第一补丁激活消息, 所述笫一补丁激活消息用于指示 所述业务 VCPU在处理完当前业务后刷新自身的快速指令缓冲区, 以使所述业 务 VCPU自身的快速指令緩沖区中指令与所述共享内存中指令同步更新; 指示 最后一个刷新自身的快速指令緩冲区的 VCPU, 在刷新自身的快速指令緩冲区 之前, 在所述共享内存中修改所述原函数的第一条指令和第二条指令。 Sending a first patch activation message to each service VCPU, where the first patch activation message is used to indicate The service VCPU refreshes its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory; indicating the last fast instruction of refreshing itself The VCPU of the buffer modifies the first instruction and the second instruction of the original function in the shared memory before refreshing its own fast instruction buffer.
本发明实施例提供一种为共享代码段打补丁的方法, 包括:  An embodiment of the present invention provides a method for patching a shared code segment, including:
业务 VCPU接收主 VCPU发送的第一补丁激活消息;  The service VCPU receives the first patch activation message sent by the primary VCPU.
当所述业务 VCPU是最后一个刷新自身的快速指令緩沖区的业务 VCPU 时,根据所述第一补丁激活消息的指示,在共享内存中将原函数的第一条指令 和第二条指令修改为所述跳转到补丁函数的指令,所述原函数为需要打补丁的 函数;  When the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the instruction of the first patch activation message, the first instruction and the second instruction of the original function are modified in the shared memory to The instruction that jumps to the patch function, the original function is a function that needs to be patched;
所述业务 VCPU刷新自身的快速指令緩冲区, 并通过所述主 VCPU通知除 最后一个刷新自身的快速指令缓冲区的业务 VCPU以外的其它业务 VCPU刷新 自身的快速指令緩冲区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与 所述共享内存中指令同步更新。  The service VCPU refreshes its own fast instruction buffer, and the other VCPUs other than the service VCPU that refreshes its own fast instruction buffer are refreshed by the main VCPU to refresh its own fast instruction buffer. The instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
本发明实施例提供一种为共享代码段打补丁的装置, 包括:  An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
第三修改模块, 用于为原函数打补丁前, 在共享内存中, 将原函数的第一 条指令修改为跳转到异常处理的指令, 所述原函数为需要打补丁的函数; 第一消息发送模块,用于所述第三 4 改模块在共享内存中,将原函数的第 一奈指令修改为跳转到异常处理的指令后, 向各业务 VCPU发送第一补丁激活 消息, 所述第一补丁激活消息用于指示所述业务 VCPU在处理完当前业务后刷 新自身的快速指令緩沖区, 以使所述业务 VCPU自身的快速指令緩冲区中指令 与所述共享内存中指令同步更新;指示最后一个刷新自身的快速指令缓冲区的 a third modification module, configured to modify, in the shared memory, the first instruction of the original function to jump to an exception processing instruction before the original function is patched, where the original function is a function that needs to be patched; a message sending module, configured to: in the shared memory, modify the first command of the original function to jump to the instruction of the exception processing, and send a first patch activation message to each service VCPU, where The first patch activation message is used to indicate that the service VCPU refreshes its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory. ; indicates the last refresh of its own fast instruction buffer
VCPU, 在刷新自身的快速指令緩沖区之前, 在共享内存中修改所述原函数的 第一条指令和第二条指令。 The VCPU modifies the first instruction and the second instruction of the original function in the shared memory before refreshing its own fast instruction buffer.
本发明实施例提供一种为共享代码段打补丁的装置, 包括:  An embodiment of the present invention provides an apparatus for patching a shared code segment, including:
第一接收模块, 用于业务 VCPU接收主 VCPU发送的第一补丁激活消息; 判断模块, 用于判断所述业务 VCPU是否是最后一个刷新自身的快速指令 緩沖区的业务 VCPU;  a first receiving module, configured to receive, by the service VCPU, a first patch activation message sent by the primary VCPU, and a determining module, configured to determine whether the service VCPU is the last service VCPU that refreshes its own fast instruction buffer;
第二补丁模块, 用于在所述判断模块判断出所述业务 VCPU是最后一个刷 新自身的快速指令缓冲区的业务 VCPU时, 根据所述第一补丁激活消息的指 示,在共享内存中将原函数的第一条指令和第二条指令修改为所述跳转到补丁 函数的指令, 所述原函数为需要打补丁的函数; a second patch module, configured to: when the determining module determines that the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the first patch activation message The first instruction and the second instruction of the original function are modified in the shared memory to the instruction that jumps to the patch function, and the original function is a function that needs to be patched;
第一刷新通知模块,用于在所述第二补丁模块在共享内存中将原函数的第 一条指令和第二条指令修改为所述跳转到补丁函数的指令后, 刷新所述业务 VCPU的快速指令緩冲区, 并通过所述主 VCPU通知除最后一个刷新自身的快 速指令缓冲区的业务 VCPU以外的其它业务 VCPU刷新自身的快速指令緩冲 区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与所述共享内存中指令 同步更新。  a first refresh notification module, configured to refresh the service VCPU after the second patch module modifies the first instruction and the second instruction of the original function into the instruction to jump to the patch function in the shared memory a fast instruction buffer, and through the main VCPU, notify the service VCPU other than the service VCPU that refreshes its own fast instruction buffer to refresh its own fast instruction buffer, so that the service VCPU itself is fast The instruction in the instruction buffer is updated synchronously with the instruction in the shared memory.
本发明实施例为共享代码段打补丁的方法及装置,在多核处理器系统运行 过程中, 主 VCPU将原函数的第一条指令修改为跳转到异常处理的指令后, 向 业务 VCPU发送补丁激活消息, 使业务 VCPU处理完当前业务后刷新快速指令 緩冲区。 最后一个刷新快速指令缓沖区的业务 VCPU对原函数进行打补丁的操 作后,通知其它业务 VCPU刷新各自的快速指令緩冲区。在最后一个业务 VCPU 对原函数进行打补丁操作时, 其它业务 VCPU若执行到原函数, 则从原函数的 第一条指令则进入异常处理,再从异常处理中跳转到补丁函数的首地址执行补 丁函数中的指令。 从而, 最后一个业务 VCPU对原函数进行补丁操作时, 不影 响其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丟失。  The method and device for patching the shared code segment in the embodiment of the present invention, in the running process of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the instruction of the exception processing, and sends a patch to the service VCPU. Activate the message to refresh the fast instruction buffer after the service VCPU has processed the current service. The last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched. When the last service VCPU patches the original function, if the other service VCPU executes the original function, the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
附图说明 DRAWINGS
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施 例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地, 下面描 述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不 付出创造性劳动性的前提下, 还可以根据这些附图获得其他的附图。  In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief description of the drawings used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description For some embodiments of the present invention, other drawings may be obtained from those skilled in the art without departing from the drawings.
图 la为本发明第一实施例提供的为共享代码段打补丁的方法流程图; 图 lb为本发明第一实施例提供的为共享代码段打补丁的方法中补丁执行 流程图; 图 2为本发明第二实施例提供的为共享代码段打补丁的方法流程图; 图 3a为本发明第三实施例提供的为共享代码段打补丁的方法流程图; 图 3b为本发明笫三实施例提供的为共享代码段打补丁的方法的信令交互 图; FIG. 1B is a flowchart of a method for patching a shared code segment according to a first embodiment of the present invention; FIG. 1b is a flowchart of a patch execution method for patching a shared code segment according to a first embodiment of the present invention; A flowchart of a method for patching a shared code segment according to a second embodiment of the present invention; FIG. 3a is a flowchart of a method for patching a shared code segment according to a third embodiment of the present invention; FIG. 3b is a signaling interaction diagram of a method for patching a shared code segment according to a third embodiment of the present invention; FIG.
图 4a为本发明第四实施例提供的为共享代码段打补丁的方法流程图; 图 4b为本发明第四实施例提供的为共享代码段打补丁的方法的信令交互 图;  4a is a flowchart of a method for patching a shared code segment according to a fourth embodiment of the present invention; FIG. 4b is a signaling interaction diagram of a method for patching a shared code segment according to a fourth embodiment of the present invention;
图 5为本发明第五实施例提供的为共享代码段打补丁的方法流程图; 图 6为本发明第六实施例提供的为共享代码段打补丁的方法流程图; 图 7a 为本发明第七实施例提供的一种为共享代码段打补丁的方法流程 图;  FIG. 5 is a flowchart of a method for patching a shared code segment according to a fifth embodiment of the present invention; FIG. 6 is a flowchart of a method for patching a shared code segment according to a sixth embodiment of the present invention; A flowchart of a method for patching a shared code segment provided by the seventh embodiment;
图 7b为本发明第七实施例提供的另一种为共享代码段打补丁的方法流程 图;  FIG. 7b is a flowchart of another method for patching a shared code segment according to a seventh embodiment of the present invention;
图 7c为本发明第七实施例提供的另一种为共享代码段打补丁的方法的信 令交互图;  FIG. 7c is a signal interaction diagram of another method for patching a shared code segment according to a seventh embodiment of the present invention;
图 8a为本发明第八实施例提供的为共享代码段打补丁的方法流程图; 图 8b为本发明第八实施例提供的为共享代码段打补丁的方法的信令交互 图;  FIG. 8 is a flowchart of a method for patching a shared code segment according to an eighth embodiment of the present invention; FIG. 8b is a signaling interaction diagram of a method for patching a shared code segment according to an eighth embodiment of the present invention;
图 9为本发明第九实施例提供的为共享代码段打补丁的装置结构示意图; 图 10 为本发明第十实施例提供的为共享代码段打补丁的装置结构示意 图;  FIG. 9 is a schematic structural diagram of an apparatus for patching a shared code segment according to a ninth embodiment of the present invention; FIG. 10 is a schematic structural diagram of an apparatus for patching a shared code segment according to a tenth embodiment of the present invention;
图 11a 为本发明第十一实施例提供的一种为共享代码段打补丁的装置结 构示意图;  FIG. 11 is a schematic structural diagram of an apparatus for patching a shared code segment according to an eleventh embodiment of the present invention; FIG.
图 l ib 为本发明第十一实施例提供的另一种为共享代码段打补丁的装置 结构示意图; 图 12为本发明第十二实施例提供的为共享代码段打补丁的装置结构示意 图; FIG. 1 ib is another apparatus for patching a shared code segment according to an eleventh embodiment of the present invention. FIG. 12 is a schematic structural diagram of an apparatus for patching a shared code segment according to a twelfth embodiment of the present invention;
图 13为本发明第十三实施例提供的为共享代码段打补丁的装置结构示意 图; 图 14为本发明笫十四实施例提供的为共享代码段打补丁的装置结构示意 图;  13 is a schematic structural diagram of an apparatus for patching a shared code segment according to a thirteenth embodiment of the present invention; FIG. 14 is a schematic structural diagram of an apparatus for patching a shared code segment according to a fourteenth embodiment of the present invention;
图 15为本发明第十五实施例提供的为共享代码段打补丁的装置结构示意 图;  15 is a schematic structural diagram of an apparatus for patching a shared code segment according to a fifteenth embodiment of the present invention;
图 16为本发明第十六实施例提供的为共享代码段打补丁的装置结构示意 图。  FIG. 16 is a schematic structural diagram of an apparatus for patching a shared code segment according to a sixteenth embodiment of the present invention.
具体实施方式 detailed description
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而不是 全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造 性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。 BRIEF DESCRIPTION OF THE DRAWINGS The technical solutions in the embodiments of the present invention will be described in detail below with reference to the accompanying drawings. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present invention without creative work are within the scope of the present invention.
运行于嵌入式操作系统的 VCPU称为主 VPCU, 用于管理系统的公共资源, 并对业务 VCPU进行管理监控。 业务 VCPU运行单任务的操作系统, 完成高效 的用户数据处理。 本技术方案适用于非对称处理器 AMP(asymmetnc multi-processing)结构, 每一个 VCPU上必须运行单独的操作系统。 在 VCPU上 运行的映像可以独享代码段, 也可以共享代码段。  The VCPU running on the embedded operating system is called the primary VPCU, which is used to manage the common resources of the system and manage and monitor the service VCPU. The service VCPU runs a single-task operating system to perform efficient user data processing. The technical solution is applicable to an asymmetric processor AMP (asymmetnc multi-processing) structure, and a separate operating system must be run on each VCPU. Images running on a VCPU can have exclusive code segments or share code segments.
以 MIPS ( Microcomputer without interlocked pipeline stages )处理器为例, 说明在多核处理器环境下的补丁原理。 由于 MIPS使用了流水线技术, 执行指 令跳转时存在延迟槽,也就是说实际执行时会先执行延迟槽,再执行跳转指令。 所以必须同时修改两条指令,即使用空指令 NOP作为延迟槽指令以及修改跳转 指令, 才能实现打补丁操作。 Take the MIPS (Microcomputer without interlocked pipeline stages) processor as an example to illustrate the patching principle in a multi-core processor environment. Since MIPS uses pipeline technology, the implementation refers to There is a delay slot when jumping, that is to say, the delay slot is executed first when the actual execution, and then the jump instruction is executed. Therefore, two instructions must be modified at the same time, that is, the empty instruction NOP is used as the delay slot instruction and the jump instruction is modified to implement the patching operation.
由于需要修改两条指令才能进行补丁操作,所以在多核处理器的共享代 码段情况下, 不仅需要考虑指令的修改, 而且还需要考虑修改指令的时机以及 补丁立即生效问题。 因为, 在多核处理器中有多个 VCPU共同访问相同的代码 段, 如果某 VCPU已经执行到了第一条指令, 而另外一个 VCPU此时正在修改 指令, 就会造成第一个 VCPU指令异常, 从而造成系统崩溃。  Since the two instructions need to be modified to perform the patch operation, in the case of the shared code segment of the multi-core processor, not only the modification of the instruction but also the timing of the modification of the instruction and the immediate effect of the patch need to be considered. Because, in a multi-core processor, multiple VCPUs access the same code segment together. If a VCPU has executed the first instruction and another VCPU is modifying the instruction at this time, the first VCPU instruction is abnormal. Causes the system to crash.
本发明实施例分别通过将中断与异常处理相结合的方式,以及消息与异常 处理相结合的方式, 使补丁快速生效, 并且不会影响各业务 VCPU的正常业务 处理。 以下实施例中, 第一实施例至第四实施例是, 通过中断与异常相结合的 方式, 在多核处理器系统运行中为共享代码段打补丁的方法; 其中, 第一实施 例与第二实施例从主 VCPU角度说明打补丁操作的过程, 第三实施例与第四实 施例从各业务 VCPU角度说明打补丁操作的过程。 另外, 第五实施例至第八实 施例是,通过消息与异常相结合的方式,在多核处理器系统运行中为共享代码 段打补丁的方法; 其中, 第五实施例与第六实施例从主 VCPU角度说明打补丁 操作的过程, 第七实施例与第八实施例从各业务 VCPU角度说明打补丁操作的 过程。  In the embodiment of the present invention, the combination of the interrupt and the exception processing, and the combination of the message and the exception processing, respectively, enable the patch to take effect quickly, and the normal service processing of each service VCPU is not affected. In the following embodiments, the first to fourth embodiments are methods for patching shared code segments in a multi-core processor system operation by means of interrupts and exceptions; wherein, the first embodiment and the second The embodiment describes the process of the patching operation from the perspective of the main VCPU. The third embodiment and the fourth embodiment explain the process of the patching operation from the perspective of each service VCPU. In addition, the fifth to eighth embodiments are a method for patching a shared code segment in a multi-core processor system operation by means of a combination of a message and an exception; wherein the fifth embodiment and the sixth embodiment are The main VCPU angle illustrates the process of the patching operation, and the seventh embodiment and the eighth embodiment explain the process of the patching operation from the perspective of each service VCPU.
需要说明的是: 以下实施例中的原函数, 即为需要打补丁的函数, 补丁 函数即为替换原函数的函数。  It should be noted that the original function in the following embodiment is a function that needs to be patched, and the patch function is a function that replaces the original function.
图 la为本发明第一实施例提供的为共享代码段打补丁的方法流程图,本实 施例从主 VCPU角度说明打补丁操作的过程, 如图 1所示, 本实施例包括: 步骤 11 : 为原函数打补丁前, 在共享内存中将原函数的第一条指令修改为 跳转到异常处理的指令;  FIG. 1 is a flowchart of a method for patching a shared code segment according to a first embodiment of the present invention. This embodiment illustrates a process of patching operations from the perspective of a main VCPU. As shown in FIG. 1 , this embodiment includes: Step 11: Before patching the original function, modify the first instruction of the original function to jump to the exception handling instruction in the shared memory;
在多核处理器系统运行过程中, 主 VCPU将原函数的第一条指令修改为跳 转到异常处理的指令, 其目的是在后续修改原函数过程中, 若各业务 VCPU执 行到原函数, 各业务 VCPU根据跳转到异常处理的指令进入异常处理。 其中, 跳转到异常处理的指令可为 break.; 原函数为需要打补丁的共享函数。  During the operation of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and the purpose is to perform the original function in the subsequent modification process, if each service VCPU executes the original function, each The service VCPU enters the exception handling according to the instruction that jumps to the exception handling. Among them, the instruction to jump to exception handling can be break.; The original function is a shared function that needs to be patched.
步骤 12: 向各业务 VCPU发送第一中断消息;  Step 12: Send a first interrupt message to each service VCPU.
中断消息的特点是, 各业务 VCPU接收到主 VCPU以送的中断消息后, 立 即停止当前下在执行的业务, 处理中断消息。 主 VCPU向各业务 VCPU发送第 一中断信息, 其目的是指示各业务 VCPU在接收到第一中断信息后, 中断当前 业务立即刷新自身的快速指令緩冲区。从而使各业务 VCPU自身的快速指令緩 冲区中指令与共享内存中指令同步更新。由于快速指令緩冲区的存取速度高于 内存的存取速度, 因此, 业务 VCPU在执行代码段时, 通常会将经常使用的代 码段从共享内存中调入自身的快速指令緩冲区中, 当使用到这些代码段时, 直 接从快速指令緩沖中读取, 从而提高存取代码速度。 The feature of the interrupt message is that after each service VCPU receives the interrupt message sent by the main VCPU, it That is, the current under execution service is stopped, and the interrupt message is processed. The main VCPU sends the first interrupt information to each service VCPU. The purpose is to instruct each service VCPU to interrupt the current service and immediately refresh its own fast instruction buffer after receiving the first interrupt information. Therefore, the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory. Since the fast instruction buffer access speed is higher than the memory access speed, the business VCPU usually transfers frequently used code segments from the shared memory into its own fast instruction buffer when executing the code segment. When these code segments are used, they are read directly from the fast instruction buffer, thereby increasing the access code speed.
若某个业务 VCPU接收到第一中断信息后, 已将原函数的第一条指令从共 享内存中调到自身的快速指令緩冲区,刷新自身的快速指令缓冲区后,其快速 指令緩冲区中该原函数的第一条指令则更新为共享内存中该原函数的第一条 指令, 即跳转到异常处理的指令。  If a service VCPU receives the first interrupt information, it has transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, and after refreshing its own fast instruction buffer, its fast instruction buffer The first instruction of the original function in the region is updated to the first instruction of the original function in the shared memory, that is, the instruction that jumps to the exception processing.
若某个业务 VCPU接收到第一中断信息后, 还没将原函数的第一条指令从 共享内存中调到自身的快速指令緩冲区,刷新自身的快速指令緩冲区后,其快 速指令緩冲区中指令仍为原有指令。  If a service VCPU receives the first interrupt information, it has not transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, and after refreshing its own fast instruction buffer, its fast instruction The instruction in the buffer is still the original instruction.
步骤 13 : 在共享内存中,将原函数的第一条指令和第二条指令修改为跳转 到补丁函数的指令;  Step 13: In the shared memory, modify the first instruction and the second instruction of the original function to an instruction that jumps to the patch function;
修改原函数的第一条指令和第二奈指令, 即为原函数打补丁操作。 主 Modify the first instruction and the second instruction of the original function, that is, patch the original function. the Lord
VCPU在共享内存修改原函数的第一条指令和第二条指令后, 使执行到原函数 的各业务 VCPU, 从原函数的第一条指令跳转到补丁函数中, 从而实现了对原 函数的修改。 其中, 补丁函数为替换原函数的函数。 After the VCPU modifies the first instruction and the second instruction of the original function in the shared memory, the VCPUs executing the original function are jumped from the first instruction of the original function to the patch function, thereby realizing the original function. Modifications. Among them, the patch function is a function that replaces the original function.
修改原函数的方法具体可为: 先将原函数的第二条指令修改为延迟槽指 令, 即 NOP; 再将原函数的第一条指令修改为跳转到补丁函数的指令, 即 JMP 补丁函数首地址。  The method for modifying the original function may be: first modify the second instruction of the original function into a delay slot instruction, that is, a NOP; and then modify the first instruction of the original function to an instruction that jumps to the patch function, that is, a JMP patch function. First address.
若主 VCPU先修改原函数的第一条指令, 后修改原函数的第二条指令。 在 主 VCPU将原函数的第一条指令从进入异常处理指令修改为跳转指令后, 还没 未将原函数第二条指令修改为延迟槽指令的情况下,此时执行到原函数第一条 指令的业务 VCPU, 会因为第二条指令不是延迟槽指令, 无法跳转到补丁函数 中执行, 则会导致系统崩溃。  If the main VCPU first modifies the first instruction of the original function, then the second instruction of the original function is modified. After the main VCPU changes the first instruction of the original function from the entry of the exception processing instruction to the jump instruction, and has not modified the second instruction of the original function into the delay slot instruction, the execution is performed to the original function first. The service VCPU of the instruction will cause the system to crash because the second instruction is not a delay slot instruction and cannot be jumped to the patch function for execution.
因此, 本实施例中先将主 VCPU修改先将原函数的第二条指令为延迟槽指 令, 后修改原函数的第一条指令为跳转指令。 此时若业务 VCPU执行到原函数 到第一条指令, 由于此时原函数的第一条指令还是进入异常处理指令(例如, break ), 业务 VCPU则通过第一条指令进入异常处理, 而不会再继续执行原函 数的第二条指令。从而, 本实施例避免了延迟槽指令对共享原函数打补丁的影 响。 Therefore, in this embodiment, the main VCPU is modified first to use the second instruction of the original function as the delay slot instruction, and then the first instruction of the original function is modified as the jump instruction. At this point, if the business VCPU executes to the original function To the first instruction, since the first instruction of the original function still enters the exception handling instruction (for example, break ), the service VCPU enters the exception processing through the first instruction, and does not continue to execute the second function of the original function. Instructions. Thus, this embodiment avoids the effect of the delay slot instruction on patching the shared original function.
图 lb为本发明第一实施例提供的为共享代码段打补丁的方法中补丁执行 流程图。 如图 lb 所示, 为原函数打完补丁后, 在多核处理器系统运行过程中, 业务 VCPU执行到调用函数中跳转到原函数的指令时, 由调用函数跳转到原函 数的第一条指令开始执行。此时, 由于原函数的第一奈指令为跳转到补丁函数 的指令, 第二条指令为延迟槽指令, 则业务 VCPU从原函数跳转到补丁函数中 执行。 执行到补丁函数的末尾时再返回到调用函数 A中, 继续执行调用函数 A 中的指令, 从而达到了为原函数打补丁的目的。  FIG. 1b is a flowchart of a patch execution in a method for patching a shared code segment according to a first embodiment of the present invention. As shown in Figure lb, after the original function is patched, during the operation of the multi-core processor system, when the service VCPU executes the instruction that jumps to the original function in the calling function, the call function jumps to the first function. The instructions begin execution. At this time, since the first instruction of the original function is an instruction to jump to the patch function, and the second instruction is a delay slot instruction, the service VCPU jumps from the original function to the patch function. When the execution reaches the end of the patch function, it returns to the calling function A, and continues to execute the instruction in the calling function A, thereby achieving the purpose of patching the original function.
步骤 14: 向各业务 VCPU发送第二中断信息;  Step 14: Send a second interrupt information to each service VCPU.
第二中断信息用于指示业务 VCPU, 中断当前业务立即刷新各自的快速指 令缓冲区, 各业务 VCPU自身的快速指令缓冲区中指令与共享内存中指令同步 更新。  The second interrupt information is used to indicate the service VCPU, and the current service is interrupted to immediately refresh the respective fast instruction buffers. The instructions in the fast instruction buffer of each service VCPU and the instructions in the shared memory are updated synchronously.
在主 VCPU在共享内存修改原函数的第一条指令和第二条指令时, 某个业 务 VCPU已将原函数的第一条指令和第二条指令, 从共享内存中调入自身的快 速指令緩冲区,其刷新自身的快速指令緩沖区后, 则会将自身的快速緩冲区中 该原函数的第一条指令和第二条指令, 更新为主 VCPU修改后的原函数的第一 条指令和第二条指令。  When the main VCPU modifies the first instruction and the second instruction of the original function in the shared memory, a certain service VCPU has transferred the first instruction and the second instruction of the original function from the shared memory to its own fast instruction. The buffer, after refreshing its own fast instruction buffer, will update the first instruction and the second instruction of the original function in its own fast buffer to the first function of the original function modified by the main VCPU. The instruction and the second instruction.
本实施例, 在多核处理器系统运行过程中, 在主 VCPU对原函数进行打补 丁操作之前,将原函数的第一条指令先^ ί 改为跳转到异常处理的指令, 并向业 务 VCPU发送中断信息, 使业务 VCPU立即刷新快速指令緩沖区。 由于, 本发 明实施例中业务 VCPU接收到主 CPU发送的中断信息后, 不需要向主 VCPU发 送响应消息; 并且主 CPU向业务 VCPU发送中断信息后, 即可对原函数进行打 补丁操作, 因此, 本发明实施例能使补丁快速生效。 另外, 在主 VCPU对原函 数打补丁操作时, 若业务 VCPU执行到原函数的第一条指令时, 通过上述跳转 到异常处理的指令进入异常处理,再从异常处理进入补丁函数,从而能保证主 In this embodiment, in the running process of the multi-core processor system, before the main VCPU performs the patching operation on the original function, the first instruction of the original function is first changed to the instruction that jumps to the exception processing, and is directed to the service VCPU. The interrupt message is sent so that the service VCPU immediately refreshes the fast instruction buffer. In the embodiment of the present invention, after receiving the interrupt information sent by the main CPU, the service VCPU does not need to send a response message to the main VCPU; and after the main CPU sends the interrupt information to the service VCPU, the original function can be patched. The embodiment of the invention enables the patch to take effect quickly. In addition, when the main VCPU patches the original function, if the service VCPU executes the first instruction to the original function, the instruction that jumps to the exception processing enters the exception processing, and then enters the patch function from the exception processing, thereby enabling Guarantee the Lord
VCPU对原函数进行正常的打补丁操作, 同时避免了延迟指令对为共享原函数 打补丁的影响。 因此本发明实施例为共享代码段打补丁的方法, 在主 VCPU对 原函数打补丁操作时, 不会影响到该业务 VCPU的正常业务处理, 还能使执行 到原函数的业务 VCPU从原函数跳转到补丁函数中执行, 并且不会导致业务阻 塞和业务数据丢失。 The VCPU performs a normal patching operation on the original function, while avoiding the effect of the delayed instruction on patching the shared original function. Therefore, in the embodiment of the present invention, a method for patching a shared code segment is performed on a primary VCPU pair. When the original function is patched, it does not affect the normal business processing of the service VCPU. It also enables the service VCPU executing the original function to jump from the original function to the patch function, without causing service congestion and loss of service data. .
图 2为本发明第二实施例提供的为共享代码段打补丁的方法的流程图。 若 在图 1对应的实施例中, 主 VCPU在步驟 13中对原函数的第一条指令和第二条 指令有误,并已执行过步驟 14: 向各业务 VCPU发送第二中断消息, 则主 VCPU 通过本实施例中方法,将原函数的第一条指令和第二条指令恢复为原函数原有 指令。 在主 VCPU恢复原函数的第一条指令和第二条指令的过程中, 与图 1对 应的实施例方法类似, 不会的影响到各业务 VCPU的正常业务处理, 并且还能 使执行到原函数第一条指令的业务 VCPU, 通过异常处理进入补丁数中执行。 具体地, 如图 2所示, 本实施例包括:  FIG. 2 is a flowchart of a method for patching a shared code segment according to a second embodiment of the present invention. In the embodiment corresponding to FIG. 1, the main VCPU has an error in the first instruction and the second instruction of the original function in step 13, and has performed step 14: sending a second interrupt message to each service VCPU. The main VCPU restores the first instruction and the second instruction of the original function to the original original instruction by the method in this embodiment. In the process of restoring the first instruction and the second instruction of the original function by the main VCPU, the method of the embodiment corresponding to FIG. 1 is similar, which does not affect the normal service processing of each service VCPU, and can also cause execution to the original The service VCPU of the first instruction of the function is executed by the exception processing into the number of patches. Specifically, as shown in FIG. 2, the embodiment includes:
步骤 21 : 恢复原函数的第一条指令和第二条指令前, 在共享内存中将原函 数的第一条指令修改为跳转到异常处理的指令;  Step 21: Before restoring the first instruction and the second instruction of the original function, modify the first instruction of the original function to jump to the instruction of the exception processing in the shared memory;
其中, 跳转到异常处理的指令, 可为 break。  Among them, the instruction to jump to the exception processing can be break.
步骤 22: 向各业务 VCPU发送第三中断消息;  Step 22: Send a third interrupt message to each service VCPU.
第三中断信息用于指示各业务 VCPU, 中断当前业务立即刷新自身的快速 指令缓沖区, 以使各业务 VCPU自身的快速指令缓冲区中指令与共享内存中指 令同步更新;  The third interrupt information is used to instruct each service VCPU to interrupt the current service and immediately refresh its own fast instruction buffer, so that the instructions in the fast instruction buffer of each service VCPU and the instructions in the shared memory are updated synchronously;
步骤 23: 在共享内存中, 将原函数的第一条指令和第二条指令, 恢复成对 原函数修改前的指令;  Step 23: In the shared memory, restore the first instruction and the second instruction of the original function to the instruction before the original function is modified;
在步骤 23中, 主 VCPU将原函数的第一条指令和第二条指令, 恢复成为原 函数打补丁之前的指令, 即对原函数修改前的指令。  In step 23, the main VCPU restores the first instruction and the second instruction of the original function to the instruction before the original function is patched, that is, the instruction before the original function is modified.
步骤 24: 向各业务 VCPU发送第四中断信息;  Step 24: Send a fourth interrupt information to each service VCPU.
第四中断信息用于指示业务 VCPU, 中断当前业务立即刷新各自的快速指 令緩冲区, 以使各业务 VCPU自身的快速指令缓冲区中指令与共享内存中指令 同步更新。  The fourth interrupt information is used to indicate the service VCPU, and the current service is interrupted to immediately refresh the respective fast instruction buffers, so that the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory.
本实施例在主 VCPU恢复原函数的第一条指令和第二条指令之前, 将原函 数的第一条指令先修改为跳转到异常处理的指令, 并向业务 VCPU发送中断信 息, 使业务 VCPU立即刷新快速指令緩冲区。 在主 VCPU恢复原函数的第一条 指令和第二条指令时, 若业务 VCPU执行到原函数则通过跳转到异常处理的指 令进入异常处理,再从异常处理跳转到补丁函数的首地址处, 开始执行补丁函 数中的指令, 以保证主 VCPU对原函数进行恢复操作。 In this embodiment, before the main VCPU restores the first instruction and the second instruction of the original function, the first instruction of the original function is first modified to jump to the exception processing instruction, and the interrupt information is sent to the service VCPU to enable the service. The VCPU immediately refreshes the fast instruction buffer. When the main VCPU restores the first instruction and the second instruction of the original function, if the service VCPU executes the original function, it jumps to the exception processing finger. Let the exception handling, and then jump from the exception processing to the first address of the patch function, start executing the instructions in the patch function to ensure that the main VCPU restores the original function.
图¾为本发明第三实施例提供的为共享代码段打补丁的方法的流程图。图 FIG. 3 is a flowchart of a method for patching a shared code segment according to a third embodiment of the present invention. Figure
3b为本发明第三实施例提供的为共享代码段打补丁的方法的信令交互图。本实 施例结合图 1所示实施例中主 VCPU的动作,主要从业务 VCPU角度说明打补丁 操作的过程。 请参见图 3a和图 3b, 本实施例包括: 3b is a signaling interaction diagram of a method for patching a shared code segment according to a third embodiment of the present invention. This embodiment, in conjunction with the action of the main VCPU in the embodiment shown in FIG. 1, mainly describes the process of the patching operation from the perspective of the service VCPU. Referring to FIG. 3a and FIG. 3b, this embodiment includes:
步驟 31 : 接收到主 VCPU发送的第一中断信息后, 根据第一中断信息的指 示, 中断当前业务立即刷新快速指令緩冲区;  Step 31: After receiving the first interrupt information sent by the main VCPU, according to the indication of the first interrupt information, interrupting the current service and immediately refreshing the fast instruction buffer;
各业务 VCPU中断当前业务, 立即刷新自身快速指令緩冲区的目的是, 使 自身的快速指令緩冲区中指令与共享内存中指令同步更新,以保证自身的快速 指令緩冲区中指令与共享内存中相应指令保持一致。  Each service VCPU interrupts the current service, and the purpose of immediately refreshing its own fast instruction buffer is to synchronize the instructions in its own fast instruction buffer with the instructions in the shared memory to ensure instruction and sharing in its own fast instruction buffer. The corresponding instructions in the memory are consistent.
步骤 32: 执行到原函数的第一条指令时, 根据原函数的第一条指令, 进入 异常处理;  Step 32: When the first instruction to the original function is executed, according to the first instruction of the original function, the exception processing is entered;
若某个业务 VCPU接收到第一中断信息时, 已将原函数的第一条指令从共 享内存中调到自身的快速指令缓冲区,刷新自身的快速指令缓冲区后,其快速 指令緩沖区中该原函数的第一条指令则更新为共享内存中该原函数的第一条 指令, 即跳转到异常处理的指令。 在还没有接收到主 VCPU发送的第二中断信 息时, 即在自身的快速指令緩冲区中该原函数的第一条指令还没有更新之前, 当该业务 VCPU执行到第一条指令时, 根据跳转到异常处理的指令, 进入到异 常处理。  If a service VCPU receives the first interrupt information, it has transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, refreshing its own fast instruction buffer, and its fast instruction buffer. The first instruction of the original function is updated to the first instruction of the original function in the shared memory, that is, the instruction that jumps to the exception processing. When the second interrupt information sent by the main VCPU has not been received, that is, before the first instruction of the original function is not updated in its own fast instruction buffer, when the service VCPU executes the first instruction, According to the instruction that jumps to the exception processing, the exception processing is entered.
若某个业务 VCPU接收到第一中断信息时, 还没将原函数的第一条指令从 共享内存中调到自身的快速指令緩沖区,刷新自身的快速指令缓冲区后,其快 速指令緩冲区中指令仍为原有指令。 当后续该业务 VCPU将该原函数的第一条 指令调入快速緩冲区中, 在还没有接收到主 VCPU发送的第二中断信息时, 若 执行到了该原函数的第一条指令,由于此时第一条指令为跳转到异常处理的指 令, 该业务 VCPU则根据跳转到异常处理的指令进入异常处理。  If a service VCPU receives the first interrupt information, it has not transferred the first instruction of the original function from the shared memory to its own fast instruction buffer, and after refreshing its own fast instruction buffer, its fast instruction buffer The instructions in the zone are still the original instructions. When the service VCPU subsequently transfers the first instruction of the original function into the fast buffer, if the second interrupt information sent by the main VCPU has not been received, if the first instruction of the original function is executed, At this time, the first instruction is an instruction that jumps to the exception processing, and the service VCPU enters the exception processing according to the instruction that jumps to the exception processing.
步骤 33 : 在异常处理中, 根据需要打补丁的原函数的首地址, 在补丁区查 找补丁函数的首地址;  Step 33: In the exception handling, according to the first address of the original function to be patched, find the first address of the patch function in the patch area;
补丁区存储有原函数的首地址、补丁函数的首地址、原函数与补丁函数的 映射关系, 以及原函数的前两条指令等信息。 步骤 34: 根据补丁函数的首地址, 从异常处理跳转到补丁函数中执行。 业务 VCPU根据原函数的首地址在补丁区查找到对应补丁函数的首地址。 查找到对应补丁函数的首地址后,将异常处理的返回地址修改为补丁函数的首 地址, 然后从异常处理进入到补丁函数, 执行补丁函数中指令。 因此, 在业务 VCPU还没有接收到主 VPCU发送的第二中断消息之前,即主 VCPU对原函数的 补丁操作还没生效之前, 若业务 VCPU执行了该原函数的第一条指令, 则会从 异常处理中进入到补丁函数进行执行。 从而不仅没有影响到以业务 VCPU的正 常业务处理, 而且还能使该业务 VCPU执行补丁函数的中指令。 The patch area stores the first address of the original function, the first address of the patch function, the mapping relationship between the original function and the patch function, and the first two instructions of the original function. Step 34: According to the first address of the patch function, jump from exception processing to execution in the patch function. The service VCPU finds the first address of the corresponding patch function in the patch area according to the first address of the original function. After finding the first address of the corresponding patch function, the return address of the exception processing is modified to the first address of the patch function, and then the exception function is processed into the patch function, and the instruction in the patch function is executed. Therefore, before the service VCPU has received the second interrupt message sent by the primary VPCU, that is, before the patch operation of the original function by the primary VCPU has not yet taken effect, if the service VCPU executes the first instruction of the original function, In the exception handling, the patch function is executed for execution. Thus, not only does it not affect the normal service processing of the service VCPU, but it also enables the service VCPU to execute the middle instruction of the patch function.
步骤 35: 在根据第一中断信息的指示, 中断当前业务, 刷新快速指令緩冲 区之后, 接收主 VCPU发送的第二中断信息, 根据第二中断信息的指示, 中断 当前业务立即刷新自身的快速指令緩冲区。  Step 35: After interrupting the current service according to the indication of the first interrupt information, after refreshing the fast instruction buffer, receiving the second interrupt information sent by the main VCPU, and interrupting the current service to refresh itself quickly according to the indication of the second interrupt information. Instruction buffer.
业务 VCPU刷新自身的快速指令緩冲区, 会使业务 VCPU自身的快速指令 緩冲区中指令与共享内存中指令同步更新。  The service VCPU refreshes its own fast instruction buffer, which causes the instructions in the fast instruction buffer of the service VCPU itself to be updated synchronously with the instructions in the shared memory.
在根据第一中断信息的指示, 中断当前业务, 刷新快速指令缓沖区之后, 业务 VCPU接收到主 VCPU发送的第二中断信息时,说明主 VCPU在共享内存中 已对原函数的前两条指令进行了修改,若此时自身的快速指令緩冲区存储有该 原函数的第一条指令和第二条指令, 则刷新快速指令緩冲区后, 该原函数的第 一条指令和第二条指令, 则更新为主 VCPU修改后的指令, 即第一条为 Jump, 第二条为 Nop。 更新后, 在该业务 VCPU执行到该原函数的第一条指令时, 则 从原函数直接跳转到补丁函数中执行, 从而实现了对原函数的打补丁操作。  After interrupting the current service according to the indication of the first interrupt information, after the fast instruction buffer is refreshed, the service VCPU receives the second interrupt information sent by the main VCPU, indicating that the main VCPU has the first two functions of the original function in the shared memory. The instruction is modified. If the first instruction and the second instruction of the original function are stored in the fast instruction buffer of the original function, the first instruction and the first instruction of the original function are refreshed after the fast instruction buffer is refreshed. The two instructions are updated to the modified VCPU instruction, that is, the first is Jump and the second is Nop. After the update, when the service VCPU executes the first instruction to the original function, it jumps directly from the original function to the patch function, thereby implementing the patching operation on the original function.
本实施例, 在多核处理器系统运行过程中, 各业务 VCPU接收到主 CPU发 送的第一中断信息后, 立即刷新各自的快速指令缓冲区。 在业务 VCPU执行到 原函数的第一条指令时, 且没有接收到主 VCPU发送的第二中断信息之前, 根 据跳转到异常处理的指令跳转到异常处理中,然后从异常处理中进入补丁函数 中, 开始执行补丁函数。 因此本发明实施例为共享代码段打补丁的方法, 在主 VCPU对原函数打补丁操作时, 不会影响到该业务 VCPU的正常业务处理, 还 能使执行到原函数的业务 VCPU从原函数跳转到补丁函数中执行。  In this embodiment, during the operation of the multi-core processor system, each service VCPU immediately refreshes its respective fast instruction buffer after receiving the first interrupt information sent by the main CPU. When the service VCPU executes the first instruction to the original function, and does not receive the second interrupt information sent by the main VCPU, jumps to the exception processing according to the instruction that jumps to the exception processing, and then enters the patch from the exception processing. In the function, the patch function is started. Therefore, in the embodiment of the present invention, the method for patching the shared code segment, when the main VCPU patches the original function, does not affect the normal service processing of the service VCPU, and can also execute the service VCPU from the original function to the original function. Jump to the patch function to execute.
图 4a为本发明第四实施例提供的为共享代码段打补丁的方法的流程图。业 务 VCPU在图 3a对应的实施例中接收到主 VCPU发送的第二中断信息, 并根据 对各自的快速指令缓冲区刷新的后, 还有可能会接收到主 VCPU发送的第三中 断信息。图 4b为本发明第四实施例提供的为共享代码段打补丁的方法信令交互 图。 本实施例结合图 1、 图 2对应实施例中主 VCPU的执行流程, 主要从业务 VCPU角度来说明业务 VCPU在接收到主 VCPU发送的第三中断信息后的执行 流程。 如图 4a和图 4b所示, 本实施例包括: 4a is a flowchart of a method for patching a shared code segment according to a fourth embodiment of the present invention. The service VCPU receives the second interrupt information sent by the main VCPU in the embodiment corresponding to FIG. 3a, and may also receive the third middle sent by the main VCPU according to the refresh of the respective fast instruction buffers. Broken information. FIG. 4b is a signaling interaction diagram of a method for patching a shared code segment according to a fourth embodiment of the present invention. This embodiment, in conjunction with the execution flow of the main VCPU in the corresponding embodiment of FIG. 1 and FIG. 2, mainly illustrates the execution flow of the service VCPU after receiving the third interrupt information sent by the main VCPU, from the perspective of the service VCPU. As shown in FIG. 4a and FIG. 4b, this embodiment includes:
步骤 41 :接收主 VCPU发送的第三中断信息后,根据第三中断信息的指示, 中断当前业务立即刷新快速指令緩冲区;  Step 41: After receiving the third interrupt information sent by the primary VCPU, interrupting the current service to immediately refresh the fast instruction buffer according to the indication of the third interrupt information.
业务 VCPU接收到主 VCPU发送的第三中断信息,说明主 VCPU对原函数已 进行了修改。 各业务 VCPU立即刷新自身的快速指令緩冲区, 使自身的快速指 令緩冲区中指令与共享内存中指令同步更新。  The service VCPU receives the third interrupt message sent by the primary VCPU, indicating that the primary VCPU has modified the original function. Each service VCPU immediately refreshes its own fast instruction buffer, so that its instructions in the fast instruction buffer are synchronized with the instructions in the shared memory.
步骤 42: 执行到原函数的第一条指令时, 根据原函数的第一条指令, 进入 异常处理;  Step 42: When executing the first instruction to the original function, according to the first instruction of the original function, enter the exception processing;
主 VCPU向各业务 VCPU发送第三中断信息后, 对原函数的第一条指令和 第二条指令进行恢复操作 ,使其恢复为原函数中原有的第一条指令和第二条指 令。 在此过程中, 与图 3对应的实施例类似, 若此时业务 VCPU执行到原函数 的第一条指令, 则通过跳转到异常处理的指令进入异常处理。 因此, 不会影响 到业务 VCPU的正常业务处理。  After the main VCPU sends the third interrupt information to each service VCPU, the first instruction and the second instruction of the original function are restored to restore the original first instruction and the second instruction in the original function. In this process, similar to the embodiment corresponding to Fig. 3, if the service VCPU executes the first instruction to the original function at this time, the exception processing is entered by the instruction that jumps to the exception processing. Therefore, it does not affect the normal business processing of the service VCPU.
步驟 43: 在异常处理中, 根据需要打补丁的原函数的首地址, 在补丁区查 找补丁函数的首地址; 补丁函数为替换原函数的函数;  Step 43: In the exception processing, according to the first address of the original function to be patched, the first address of the patch function is searched in the patch area; the patch function is a function that replaces the original function;
步骤 44: 根据补丁函数的首地址, 从异常处理返回到补丁函数中执行。 步骤 45: 在根据第三中断信息的指示, 中断当前业务, 刷新快速指令緩冲 区之后, 接收主 VCPU发送的第四中断信息, 根据第二中断信息的指示, 中断 当前业务立即刷新自身的快速指令緩沖区。  Step 44: According to the first address of the patch function, return from exception processing to execution in the patch function. Step 45: After interrupting the current service according to the instruction of the third interrupt information, after refreshing the fast instruction buffer, receiving the fourth interrupt information sent by the main VCPU, and interrupting the current service to refresh itself quickly according to the indication of the second interrupt information. Instruction buffer.
业务 VCPU刷新自身的快速指令緩冲区 , 会使业务 VCPU自身的快速指令 緩冲区中指令与共享内存中指令同步更新。  The service VCPU refreshes its own fast instruction buffer, which causes the instructions in the fast instruction buffer of the service VCPU itself to be updated synchronously with the instructions in the shared memory.
在根据第三中断信息的指示,中断当前业务立即刷新自身的快速指令缓冲 区之后 , 业务 VCPU接收主 VCPU发送的第四中断信息。  After interrupting the current service and immediately refreshing its own fast instruction buffer according to the indication of the third interrupt information, the service VCPU receives the fourth interrupt information sent by the primary VCPU.
本实施例在多核处理器系统运行过程中, 若主 VCPU需要恢复之前对原函 数第一条指令和第二条指令的修改,事先将原函数的第一条指令修改为跳转到 异常处理的指令, 然后向各业务 VCPU发第三中断信息, 使各 VCPU刷新各自 的指令緩冲区。 主 VCPU发送第三中断消息后, 开始对原函数的前两条指令进 行恢复操作, 在此阶段, 若业务 VCPU执行到原函数的第一条指令, 则会通过 跳转到异常处理指令进入补丁函数。因此本发明实施例为共享代码段打补丁的 方法, 在主 VCPU对原函数进行恢复操作时, 不会影响到该业务 VCPU的正常 业务处理, 还能使执行到原函数的业务 VCPU从原函数跳转到补丁函数中执 行。 In this embodiment, during the operation of the multi-core processor system, if the main VCPU needs to restore the first instruction and the second instruction of the original function before modification, the first instruction of the original function is modified to jump to the exception processing. The instruction then sends a third interrupt message to each service VCPU, causing each VCPU to refresh its respective instruction buffer. After the main VCPU sends the third interrupt message, it starts to enter the first two instructions of the original function. Line recovery operation. At this stage, if the service VCPU executes the first instruction to the original function, it will enter the patch function by jumping to the exception handling instruction. Therefore, in the embodiment of the present invention, the method for patching the shared code segment, when the main VCPU restores the original function, does not affect the normal service processing of the service VCPU, and can also execute the service VCPU from the original function to the original function. Jump to the patch function to execute.
图 5为本发明第五实施例提供的为共享代码段打补丁的方法流程图, 本实 施例从主 VCPU角度说明打补丁操作的过程, 如图 5所示 , 本实施例包括: 步骤 51 : 为原函数打补丁前, 在共享内存中, 将原函数的第一条指令修改 为跳转到异常处理的指令;  FIG. 5 is a flowchart of a method for patching a shared code segment according to a fifth embodiment of the present invention. This embodiment illustrates a process of patching operations from the perspective of a main VCPU. As shown in FIG. 5, this embodiment includes: Step 51: Before patching the original function, in the shared memory, modify the first instruction of the original function to jump to the exception processing instruction;
在多核处理器系统运行过程中, 主 VCPU将原函数的第一条指令修改为跳 转到异常处理的指令, 其目的是在后续最后一个 VCPU修改原函数过程中, 若 其它业务 VCPU执行到原函数, 该业务 VCPU根据跳转到导演处理的指令进入 异常处理。 其中, 跳转到异常处理的指令可为 break.; 原函数为需要打补丁的 共享函数。  During the operation of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and the purpose is to perform other functions in the subsequent VCPU to modify the original function. Function, the service VCPU enters exception handling according to the instruction that jumps to the director's processing. Among them, the instruction to jump to exception handling can be break.; The original function is a shared function that needs to be patched.
步骤 52: 向各业务 VCPU发送第一补丁激活消息;  Step 52: Send a first patch activation message to each service VCPU.
第一补丁激活消息用于指示各业务 VCPU在处理完当前业务后刷新自身 的快速指令缓沖区, 以使各业务 VCPU自身的快速指令緩沖区中指令与共享内 存中指令同步更新; 并指示最后一个刷新自身的快速指令緩沖区的业务 The first patch activation message is used to instruct each service VCPU to refresh its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of each service VCPU itself is updated synchronously with the instruction in the shared memory; A service that refreshes its own fast instruction buffer
VCPU, 在共享内存中修改原函数的第一条指令和第二奈指令。 The VCPU, in the shared memory, modifies the first instruction and the second instruction of the original function.
为确定出最后一个刷新自身的快速指令緩冲区的业务 VCPU , 主 VCPU发 送第一补丁激活消息前,会在共享内存中保存需要接收第一补丁激活消息的所 有业务 VCPU编号。 每一个业务 VCPU在接收到补丁激活消息后且刷新自身的 快速指令緩沖区之前, 都会在共享内存中记录自己的 VCPU编号, 并查看共享 内存中是否已记录有除自身之外的所有业务 VCPU的编号, 如果是, 则表明自 己是最后一个业务 VCPU。  To determine the last service VCPU that refreshes its own fast instruction buffer, the primary VCPU saves all the service VCPU numbers that need to receive the first patch activation message in the shared memory before sending the first patch activation message. After receiving the patch activation message and refreshing its own fast instruction buffer, each service VCPU records its own VCPU number in the shared memory and checks whether all the service VCPUs except itself have been recorded in the shared memory. The number, if it is, indicates that it is the last business VCPU.
由于消息的特点, 业务 VCPU接收到主 VCPU发送第一补丁激活消息后, 不立即处理该第一补丁激活消息。 而是在处理完当前业务后,再刷新自身的快 速指令緩冲区。 最后一个业务 VCPU, 在刷新自身的快速指令緩沖区之前, 在 共享内存中修改原函数的第一条指令和第二条指令, 即对原函数进行补丁操 作。 如果修改原函数指令的业务 VCPU不是最后一个刷新瞬自身的快速指令缓 冲区的业务 VCPU, 当该业务 VCPU在共享内存中修改原函数的第一条指令和 第二指令时, 若后续没有刷新自身快速指令緩沖区的其它业务 VCPU此时已执 行到原函数的第一条指令或第二条指令, 则会引起指令执行错误异常 因此, 本发明实施例中采用最后一个刷新自身緩冲区的 VCPU, 修改原函数的第一条 指令和第二条指令。 Due to the characteristics of the message, after receiving the first patch activation message, the service VCPU does not immediately process the first patch activation message. Instead, after processing the current business, refresh its own fast instruction buffer. The last service VCPU, before refreshing its own fast instruction buffer, modifies the first instruction and the second instruction of the original function in the shared memory, that is, the original function is patched. If the service VCPU that modifies the original function instruction is not the last quick refresh command The service VCPU of the rushing area, when the service VCPU modifies the first instruction and the second instruction of the original function in the shared memory, if the other service VCPU that does not refresh its own fast instruction buffer subsequently executes the first function to the original function An instruction or a second instruction may cause an instruction execution error. Therefore, in the embodiment of the present invention, the last VCPU that refreshes its own buffer is used, and the first instruction and the second instruction of the original function are modified.
业务 VCPU处理完当前业务, 对接收到第一补丁激活信息进行处理, 即刷 新自身的快速指令缓冲区后, 自身的快速指令緩沖区中存储有原函数的第一条 指令, 则该条指令为跳转到异常处理的指令。 该业务 VCPU执行到原函数中的 该指令时, 进入异常处理, 再从异常处理中进入补丁函数。  After the service VCPU processes the current service and processes the first patch activation information, that is, after refreshing its own fast instruction buffer, the first instruction of the original function is stored in its own fast instruction buffer, and the instruction is Jump to the instruction of exception handling. When the service VCPU executes the instruction in the original function, it enters the exception processing, and then enters the patch function from the exception processing.
本发明实施例为共享代码段打补丁的方法, 在多核处理器系统运行过程 中, 主 VCPU将原函数的第一条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送第一补丁激活消息, 使业务 VCPU处理完当前业务后刷新快速指令 緩冲区。 最后一个刷新快速指令緩冲区的业务 VCPU对原函数进行打补丁的操 作后,通知其它业务 VCPU刷新各自的快速指令缓冲区。在最后一个业务 VCPU 对原函数进行打补丁操作时, 其它业务 VCPU若执行到原函数, 则从原函数的 第一条指令则进入异常处理,再从异常处理中跳转到补丁函数的首地址执行补 丁函数中的指令。 从而, 最后一个业务 VCPU对原函数进行补丁操作时, 不影 响其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丟失。  The embodiment of the present invention is a method for patching a shared code segment. During the operation of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and sends the first patch to the service VCPU. Activate the message to refresh the fast instruction buffer after the service VCPU has processed the current service. The last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched. When the last service VCPU patches the original function, if the other service VCPU executes the original function, the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
图 6为本发明第六实施例提供的为共享代码段打补丁的方法的流程图。 在 图 5对应的实施例步骤 52之后, 若最后一个刷新自身快速指令緩冲区的业务 VCPU对原函数的修改出现错误, 则通过本实施例对原函数的指令进行恢复。 具体地, 如图 6所示, 本实施例包括:  FIG. 6 is a flowchart of a method for patching a shared code segment according to a sixth embodiment of the present invention. After the step 52 of the embodiment corresponding to FIG. 5, if the modification of the original function by the service VCPU of the last fast instruction buffer is incorrect, the instruction of the original function is restored by this embodiment. Specifically, as shown in FIG. 6, the embodiment includes:
步骤 61 : 恢复原函数的第一条指令和第二第指令前, 在共享内存中, 将原 函数的第一条指令修改为跳转到异常处理的指令;  Step 61: Before restoring the first instruction and the second instruction of the original function, in the shared memory, modify the first instruction of the original function to jump to the instruction of the exception processing;
跳转到异常处理的指令可为 break。  The instruction to jump to exception handling can be break.
步骤 62: 向各业务 VCPU发送第二补丁激活消息;  Step 62: Send a second patch activation message to each service VCPU.
第二补丁激活消息用于指示各业务 VCPU刷新自身的快速指令緩冲区, 以 使各业务 VCPU自身的快速指令緩沖区中指令与共享内存中指令同步更新; 并 指示各业务 VCPU中最后一个刷新自身的快速指令緩冲区的 VCPU, 在共享内 存中, 将原函数的第一条指令和第二条指令恢复为原有指令。 本实施例中的第二补丁激活消息, 与图 5对应实施列中第一补丁激活消息 的区别在于,第二补丁激活消息指示最后一个刷新自身的快速指令緩冲区的业 务 VCPU, 在共享内存中, 将原函数的第一条指令和第二条指令恢复为原有指 令。 The second patch activation message is used to instruct each service VCPU to refresh its own fast instruction buffer, so that the instruction in the fast instruction buffer of each service VCPU itself is updated synchronously with the instruction in the shared memory; and the last refresh of each service VCPU is indicated. The VCPU of its own fast instruction buffer restores the first instruction and the second instruction of the original function to the original instruction in the shared memory. The second patch activation message in this embodiment differs from the first patch activation message in the corresponding implementation column of FIG. 5 in that the second patch activation message indicates the last service VCPU of the fast instruction buffer of its own refresh, in the shared memory. The first instruction and the second instruction of the original function are restored to the original instruction.
本实施例,在多核处理器系统运行过程中, 若对原函数的打补丁操作出现 错误, 需要对原函数的指令恢复时, 主 VCPU先将原函数的第一条指令修改为 跳转到异常处理的指令, 并向业务 VCPU发送第二补丁激活消息。 业务 VCPU 处理完当前业务后,根据第二补丁激活消息刷新自身的快速指令緩冲区后, 若 其它业务 VCPU执行到原函数的第一条指令即跳转到异常处理的指令, 根据跳 转到异常处理的指令进入异常处理,再从异常处理中跳转到补丁函数的首地址 执行补丁函数中的指令。从而,最后一个业务 VCPU对原函数进行恢复操作时, 不影响其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丢失。  In this embodiment, in the running process of the multi-core processor system, if an error occurs in the patching operation of the original function, and the instruction of the original function needs to be restored, the main VCPU first modifies the first instruction of the original function to jump to the abnormality. Processing the instruction and sending a second patch activation message to the service VCPU. After the service VCPU processes the current service, after refreshing its own fast instruction buffer according to the second patch activation message, if the other service VCPU executes the first instruction of the original function, it jumps to the exception processing instruction, according to the jump to The exception-handled instruction enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the last service VCPU restores the original function, it does not affect the normal service processing of other service VCPUs, and does not cause traffic congestion and loss.
图 7a为本发明第七实施例提供的一种为共享代码段打补丁的方法的流程 图, 本实施例主要从业务 VCPU角度说明打补丁操作的过程, 如图 7a所示, 本 实施例包括:  FIG. 7a is a flowchart of a method for patching a shared code segment according to a seventh embodiment of the present invention. This embodiment mainly describes a process of patching operations from the perspective of a service VCPU. As shown in FIG. 7a, this embodiment includes :
步骤 71a: 业务 VCPU接收主 VCPU发送的第一补丁激活消息;  Step 71a: The service VCPU receives the first patch activation message sent by the primary VCPU.
主 VCPU发送第一补丁激活消息的目的是, 使各业务 VCPU处理完当前业 务后, 刷新自身快速指令緩冲区。 当业务 VCPU中的快速指令緩冲区已存储有 原函数的第一条指令,此时刷新可以使共享内存中修改后的原函数的第一条指 令调入快速指令緩冲区, 从而在业务 VCPU (除最后一个刷新自身快速指令緩 冲区的业务 VCPU之外)执行到原函数的第一条指令时, 进入异常处理, 再从 异常处理进入补丁函数中执行。 如此, 在最后一个业务 VCPU对原函数进行打 补丁操作 (将第一条指令修改为 Jump, 第二条指令修改为 Nop ), 不影响其它 业务 VCPU的正常业务处理, 而且还能使执行到原函数的其它业务 VCPU从原 函数跳转到补丁函数中执行。  The purpose of the first VCPU to send the first patch activation message is to enable each service VCPU to refresh its own fast instruction buffer after processing the current service. When the fast instruction buffer in the service VCPU has stored the first instruction of the original function, the refresh can cause the first instruction of the modified original function in the shared memory to be transferred into the fast instruction buffer, thereby When the VCPU (except the last service VCPU that refreshes its own fast instruction buffer) executes the first instruction to the original function, it enters the exception handling, and then proceeds from the exception handling into the patch function. In this way, in the last service VCPU to patch the original function (change the first instruction to Jump, the second instruction to Nop), does not affect the normal business processing of other business VCPU, but also enables execution to the original The other business VCPU of the function jumps from the original function to the patch function.
步骤 72a: 当业务 VCPU是最后一个刷新自身的快速指令緩冲区的业务 VCPU时, 根据第一补丁激活消息的指示, 在共享内存中将原函数的第一条指 令和第二条指令修改为跳转到补丁函数的指令;  Step 72a: When the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the instruction of the first patch activation message, the first instruction and the second instruction of the original function are modified in the shared memory to Jump to the instruction of the patch function;
在业务 VCPU处理完当前业务后, 准备刷新自身的快速指令緩冲区之前, 判断出自身是最后一个刷新自身的快速指令缓冲区的业务 VCPU时。 在共享内 存中将原函数的第一条指令和第二条指令修改为跳转到补丁函数的指令。 步骤 73a: 业务 VCPU刷新自身的快速指令緩冲区, 并通过主 VCPU通知除 最后一个刷新自身的快速指令緩冲区的业务 VCPU以外的其它业务 VCPU刷新 自身的快速指令緩冲区。 After the service VCPU finishes processing the current service, it is determined that it is the last service VCPU that refreshes its own fast instruction buffer before preparing to refresh its own fast instruction buffer. Within the share The first instruction and the second instruction of the original function are modified to execute the instruction that jumps to the patch function. Step 73a: The service VCPU refreshes its own fast instruction buffer, and the main VCPU notifies the other service VCPUs other than the service VCPU that refreshes its own fast instruction buffer to refresh its own fast instruction buffer.
业务 VCPU刷新自身的快速指令緩冲区, 会使自身的快速指令緩冲区中指 令与共享内存中指令同步更新。  The service VCPU refreshes its own fast instruction buffer, which causes its instructions in the fast instruction buffer to be updated synchronously with the instructions in the shared memory.
本发明实施例为共享代码段打补丁的方法, 在多核处理器系统运行过程 中, 主 VCPU将原函数的第一条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送补丁激活消息, 使业务 VCPU处理完当前业务后刷新快速指令緩冲 区。 最后一个刷新快速指令緩沖区的业务 VCPU对原函数进行打补丁的操作 后, 通知其它业务 VCPU刷新各自的快速指令緩冲区。 在最后一个业务 VCPU 对原函数进行打补丁操作时, 其它业务 VCPU若执行到原函数, 则从原函数的 第一条指令则进入异常处理,再从异常处理中跳转到补丁函数的首地址执行补 丁函数中的指令。 从而, 最后一个业务 VCPU对原函数进行补丁操作时, 不影 响其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丢失。  The embodiment of the present invention is a method for patching a shared code segment. During the operation of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and sends a patch activation message to the service VCPU. , the service VCPU refreshes the fast instruction buffer after processing the current service. The last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched. When the last service VCPU patches the original function, if the other service VCPU executes the original function, the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
图 7b为本发明第七实施例提供的另一种为共享代码段打补丁的方法的流 程图,图 7c为本发明笫七实施例提供的另一种为共享代码段打补丁的方法的信 令交互图。 本实施例结合图 5对应实施例中主 VCPU的执行流程, 主要从业务 VCPU角度说明打补丁操作的过程, 如图 7b和图 7c所示, 本实施例包括: 步骤 71 : 业务 VCPU接收主 VCPU发送的第一补丁激活消息;  FIG. 7b is a flowchart of another method for patching a shared code segment according to a seventh embodiment of the present invention, and FIG. 7c is another method for patching a shared code segment according to a seventh embodiment of the present invention. Make an interaction diagram. In this embodiment, the process of the patching operation is mainly described from the perspective of the service VCPU, as shown in FIG. 7b and FIG. 7c. The embodiment includes: Step 71: The service VCPU receives the main VCPU. The first patch activation message sent;
步骤 72: 判断是否为最后一个刷新自身快速指令緩沖区的业务 VCPU; 为确定出最后一个刷新自身的快速指令缓冲区的业务 VCPU, 主 VCPU发 送第一补丁激活消息前,会在共享内存中保存需要接收第一补丁激活消息的所 有业务 VCPU编号。 每一个业务 VCPU在接收到补丁激活消息后且刷新自身的 快速指令緩冲区之前, 都会在共享内存中记录自己的 VCPU编号。 并根据主 VCPU在共享内存中保存的需要接收第一补丁激活消息的所有业务 VCPU编 号, 查看共享内存中是否已记录有除自身之外的所有业务 VCPU的编号, 如果 是, 则表明自己是最后一个业务 VCPU。  Step 72: Determine whether it is the last service VCPU that refreshes its own fast instruction buffer. To determine the last service VCPU that refreshes its own fast instruction buffer, the main VCPU saves in the shared memory before sending the first patch activation message. All service VCPU numbers that need to receive the first patch activation message. Each service VCPU records its own VCPU number in the shared memory before receiving the patch activation message and refreshing its own fast instruction buffer. And according to all the service VCPU numbers that the main VCPU saves in the shared memory, need to receive the first patch activation message, and check whether the number of all service VCPUs other than itself is recorded in the shared memory, and if so, it indicates that it is the last A business VCPU.
若业务 VCPU在处理完当前业务, 并在刷新自身快速指令緩冲区之前, 判 断出自己不是最后一个刷新自身快速指令缓冲区的 VCPU, 则执行步骤 73至步 骤 76, 具体如下: If the service VCPU is processing the current service and confirming that it is not the last VCPU that refreshes its own fast instruction buffer before refreshing its own fast instruction buffer, then step 73 is performed. Step 76, as follows:
步骤 73: 刷新自身快速指令緩沖区;  Step 73: Refresh its own fast instruction buffer;
步骤 74: 在执行到原函数的第一条指令时,根据原函数的跳转到异常处理 的指令, 进入异常处理; 没有执行原函数的第一条指令, 表明正常处理业务。  Step 74: When executing the first instruction to the original function, according to the instruction of the original function jumping to the exception processing, the exception processing is entered; the first instruction that does not execute the original function indicates that the service is normally processed.
步骤 75: 在异常处理中, 根据需要打补丁的原函数的首地址, 在补丁区查 找补丁函数的首地址;  Step 75: In the exception processing, according to the first address of the original function to be patched, find the first address of the patch function in the patch area;
步驟 76: 根据补丁函数的首地址, 从异常处理返回到补丁函数中执行。 若业务 VCPU在处理完当前业务, 并在刷新自身快速指令緩冲区之前, 判 断出自己是最后一个刷新自身快速指令緩冲区的 VCPU, 则执行步骤 77至步骤 78, 具体如下:  Step 76: According to the first address of the patch function, return from the exception processing to the execution of the patch function. If the service VCPU is processing the current service and refreshing its own fast instruction buffer before determining that it is the last VCPU to refresh its own fast instruction buffer, then perform steps 77 to 78, as follows:
步骤 77:在共享内存中将原函数的第一条指令和第二条指令修改为跳转到 补丁函数的指令;  Step 77: Modify the first instruction and the second instruction of the original function into an instruction to jump to the patch function in the shared memory;
最后一个刷新自身的快速指令緩冲区的业务 VCPU, 具体修改原函数第一 条指令和第二指令的方法可为: 先将原函数的第二条指令修改为延迟槽指令, 即 NOP; 再将原函数的第一条指令修改为跳转到补丁函数的指令, 即 JMP补 丁函数首地址。  The last service VCPU that refreshes its own fast instruction buffer, the method of modifying the first instruction and the second instruction of the original function may be: first modify the second instruction of the original function into a delay slot instruction, that is, NOP; Modify the first instruction of the original function to the instruction that jumps to the patch function, that is, the first address of the JMP patch function.
步驟 78:刷新自身的快速指令緩沖区,通过主 VCPU通知其它各业务 VCPU 刷新自身的快速指令緩冲区。  Step 78: Refresh its own fast instruction buffer, and notify the other VCPUs through the main VCPU to refresh their fast instruction buffer.
最后一个刷新自身的快速指令緩冲区的业务 VCPU, 在修改完原函数的第 一条指令和第二条指令, 刷新自身的快速指令緩冲区, 并通过主 VCPU通知其 它各业务 VCPU刷新自身的快速指令緩沖区 , 以使各业务 VCPU自身的快速指 令缓沖区中指令与共享内存中指令同步更新。  The last service VCPU that refreshes its own fast instruction buffer, after modifying the first instruction and the second instruction of the original function, refreshes its own fast instruction buffer, and notifies other service VCPUs to refresh themselves through the main VCPU. The fast instruction buffer is used to synchronize the instructions in the fast instruction buffer of each service VCPU itself with the instructions in the shared memory.
本发明实施例为共享代码段打补丁的方法, 在多核处理器系统运行过程 中, 主 VCPU将原函数的第一条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送补丁激活消息, 使业务 VCPU处理完当前业务后刷新快速指令缓冲 区。 最后一个刷新快速指令緩冲区的业务 VCPU对原函数进行打补丁的操作 后, 通知其它业务 VCPU刷新各自的快速指令缓沖区。 在最后一个业务 VCPU 对原函数进行打补丁操作时, 其它业务 VCPU若执行到原函数, 则从原函数的 第一条指令则进入异常处理,再从异常处理中跳转到补丁函数的首地址执行补 丁函数中的指令。 从而, 最后一个业务 VCPU对原函数进行补丁操作时, 不影 响其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丟失。 The embodiment of the present invention is a method for patching a shared code segment. During the operation of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the exception processing instruction, and sends a patch activation message to the service VCPU. , the service VCPU refreshes the fast instruction buffer after processing the current service. The last service VCPU that refreshes the fast instruction buffer, after patching the original function, notifies other service VCPUs to refresh their respective fast instruction buffers. When the last service VCPU patches the original function, if the other service VCPU executes the original function, the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Thus, when the last service VCPU performs a patch operation on the original function, The normal service processing of other service VCPUs will not cause traffic congestion and loss.
图 8a为本发明第八实施例提供的为共享代码段打补丁的方法的流程图。在 图 7对应的实施例步驟 72之后, 若最后一个刷新自身快速指令緩冲区的业务 VCPU对原函数的修改出现错误, 则通过本实施例对原函数的指令进行恢复。 图 8b为本发明第八实施例提供的为共享代码段打补丁的方法的信令交互图。具 体地, 如图 8a和图 8b所示, 本实施例包括:  FIG. 8a is a flowchart of a method for patching a shared code segment according to an eighth embodiment of the present invention. After the step 72 of the embodiment corresponding to FIG. 7, if the modification of the original function by the service VCPU of the last fast instruction buffer is incorrect, the instruction of the original function is restored by this embodiment. FIG. 8b is a signaling interaction diagram of a method for patching a shared code segment according to an eighth embodiment of the present invention. Specifically, as shown in FIG. 8a and FIG. 8b, this embodiment includes:
步驟 81: 接收主 VCPU发送的第二补丁激活消息;  Step 81: Receive a second patch activation message sent by the primary VCPU.
主 VCPU在共享内存中将原函数的第一条指令修改为跳转到异常处理的 指令后, 向各业务 VCPU发送第二补丁激活消息的目的是, 使各业务 VCPU处 理完当前业务后刷新自身的快速指令緩冲区中指令,以使自身的快速指令緩冲 区中指令与共享内存中指令进行同步更新。  After the main VCPU modifies the first instruction of the original function in the shared memory to jump to the exception processing instruction, the purpose of sending the second patch activation message to each service VCPU is to enable each service VCPU to refresh itself after processing the current service. The instructions in the fast instruction buffer are used to synchronize the instructions in their own fast instruction buffer with the instructions in the shared memory.
与图 7对应实施列相类似, 在对原函数进行打补丁操作, 即同时修改第一 条指令和第二条指令之前, 主 VCPU先将第一条指令修改为 break, 然后向业务 VCPU发送第二补丁激活消息。 第二补丁激活消息与第一补丁激活消息的不同 在于, 指示最后一个刷新快速指令緩冲区的业务 VCPU, 将原函数的第一条指 令和第二条指令, 恢复为对原函数修改前的指令。  Similar to the implementation column of Figure 7, before the original function is patched, that is, before modifying the first instruction and the second instruction, the main VCPU first modifies the first instruction to break, and then sends the first instruction to the service VCPU. Two patch activation messages. The difference between the second patch activation message and the first patch activation message is that the service VCPU indicating the last refresh of the fast instruction buffer restores the first instruction and the second instruction of the original function to the original function. instruction.
步驟 82: 判断自身是否是最后一个刷新自身的快速指令緩沖区的业务 VCPU;  Step 82: Determine whether it is the last service VCPU that refreshes its own fast instruction buffer;
各业务 VCPU在处理当前业务后, 在刷新自身的快速指令緩冲区之前, 需 判断自身是否是最后一个刷新自身的快速指令緩冲区的业务 VCPU, 以根据第 一补丁激活消息进行不同的操作。若不是最后一个刷新自身的快速指令緩冲区 的业务 VCPU, 则执行步驟 83至步驟 86:  After processing the current service, each service VCPU needs to determine whether it is the last service VCPU that refreshes its own fast instruction buffer before refreshing its own fast instruction buffer to perform different operations according to the first patch activation message. . If it is not the last service VCPU that refreshes its own fast instruction buffer, go to step 83 to step 86:
步骤 83: 刷新自身的快速指令緩沖区;  Step 83: Refresh its own fast instruction buffer;
步骤 84: 根据原函数的第一条指令, 进入异常处理;  Step 84: According to the first instruction of the original function, enter exception processing;
业务 VCPU在执行到原函数的第一条指令时, 由于其自身的快速指令缓冲 区中指令已经过与共享内存的同步更新,其自身的快速指令緩冲区中原函数的 第一条指令为跳转到异常处理的指令。 因此, 该业务 VCPU从原函数的第一条 指令进入异常处理, 执行异常处理程序。 没有执行原函数的第一条指令, 表明 正常处理业务。  When the service VCPU executes the first instruction to the original function, because the instruction in its own fast instruction buffer has been updated synchronously with the shared memory, the first instruction of the original function in its own fast instruction buffer is a jump. Go to the exception handling instructions. Therefore, the service VCPU enters the exception processing from the first instruction of the original function, and executes the exception handler. The first instruction that did not execute the original function indicates that the service is processed normally.
步驟 85: 在异常处理中, 根据需要打补丁的原函数的首地址, 在补丁区查 找补丁函数的首地址; Step 85: In the exception handling, according to the first address of the original function to be patched, check in the patch area. Find the first address of the patch function;
步骤 86: 根据补丁函数的首地址, 从异常处理返回到补丁函数中执行; 若是最后一个刷新自身的快速指令緩冲区的业务 VCPU, 则执行步骤 87至 步驟 88, 具体如下:  Step 86: According to the first address of the patch function, return from the exception processing to the patch function. If it is the last service VCPU that refreshes its own fast instruction buffer, perform steps 87 to 88, as follows:
步骤 87: 在共享内存中恢复原函数的第一条指令和第二条指令; 最后一个刷新自身的快速指令緩冲区的业务 VCPU, 具体修改原函数第 -一 条指令和第二指令的方法可为: 先将原函数的第二条指令(延迟槽指令, 即 Step 87: Restore the first instruction and the second instruction of the original function in the shared memory; the last service VCPU that refreshes its own fast instruction buffer, and the method of modifying the original function first instruction and the second instruction For: first the second instruction of the original function (delay slot instruction, ie
NOP )恢复成对原函数修改前的第二条指令, 再将原函数的第一奈指令(跳转 到异常处理的指令, 即 break ) 恢复成对原函数修改前的第一条指令。 NOP) restores the second instruction before the modification of the original function, and restores the first instruction of the original function (the instruction that jumps to the exception processing, ie, break) to the first instruction before the modification of the original function.
步骤 88:刷新自身的快速指令緩冲区,通过主 VCPU通知其它各业务 VCPU 刷新自身的快速指令緩冲区。  Step 88: Refresh its own fast instruction buffer, and notify the other VCPUs of the service VCPU to refresh their fast instruction buffer through the main VCPU.
最后一个刷新自身的快速指令缓沖区的业务 VCPU, 在恢复原函数的第一 条指令和第二条指令后, 刷新自身的快速指令緩冲区, 并通过主 VCPU通知其 它各业务 VCPU刷新自身的快速指令缓冲区, 以使各业务 VCPU自身的快速指 令緩冲区中指令与共享内存中指令同步更新。  The last service VCPU that refreshes its own fast instruction buffer, after restoring the first instruction and the second instruction of the original function, refreshes its own fast instruction buffer, and notifies other service VCPUs to refresh themselves through the main VCPU. The fast instruction buffer is used to synchronize the instructions in the fast instruction buffer of each service VCPU itself with the instructions in the shared memory.
本实施例,在多核处理器系统运行过程中, 若对原函数的打补丁操作出现 错误, 需要对原函数的指令恢复时, 主 VCPU先将原函数的第一条指令修改为 跳转到异常处理的指令, 并向业务 VCPU发送第二补丁激活消息。 业务 VCPU 处理完当前业务后,根据第二补丁激活消息刷新自身的快速指令緩冲区后, 若 其它业务 VCPU执行到原函数的第一条指令即跳转到异常处理的指令, 根据跳 转到异常处理的指令进入异常处理,再从异常处理中跳转到补丁函数的首地址 执行补丁函数中的指令。从而,最后一个业务 VCPU对原函数进行恢复操作时, 不影响其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丢失。  In this embodiment, in the running process of the multi-core processor system, if an error occurs in the patching operation of the original function, and the instruction of the original function needs to be restored, the main VCPU first modifies the first instruction of the original function to jump to the abnormality. Processing the instruction and sending a second patch activation message to the service VCPU. After the service VCPU processes the current service, after refreshing its own fast instruction buffer according to the second patch activation message, if the other service VCPU executes the first instruction of the original function, it jumps to the exception processing instruction, according to the jump to The exception-handled instruction enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the last service VCPU restores the original function, it does not affect the normal service processing of other service VCPUs, and does not cause traffic congestion and loss.
以下是对本发明实施例为共享代码段打补丁的装置的说明。其中, 第九实 施列和第十一实施例是以中断和异常相结合的方式,对原函数进行打补丁的装 置; 第十二实施例至第十六实施例是以消息和异常相结合的方式,对原函数进 行打补丁的装置。  The following is a description of an apparatus for patching a shared code segment in an embodiment of the present invention. Wherein, the ninth embodiment and the eleventh embodiment are devices for patching the original function in a combination of an interrupt and an abnormality; the twelfth to sixteenth embodiments are a combination of a message and an abnormality Method, a device that patches the original function.
图 9为本发明第九实施例为共享代码段打补丁的装置的结构示意图。如图 9 所示, 本实施例包括: 第一修改模块 91、 第一中断模块 92和第一补丁模块 93 以及笫二中断模块 94。 第一修改模块 91在主 VCPU为原函数打补丁前, 在共享内存中, 将原函数 的第一条指令修改为跳转到异常处理的指令; 其中, 原函数为需要打补丁的 共享函数。 第一中断模块 92在第一修改模块 91在共享内存中,将原函数的第一 条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送第一中断消息。 第 一中断信息用于指示各业务 VCPU中断当前业务立即刷新自身的快速指令緩 冲区, 使第一修改模块 91修改后的指令快速生效。 从而, 在主 VCPU为原函数 打补丁时, 使各业务 VCPU根据原函数的第一条指令跳转到异常处理中。 FIG. 9 is a schematic structural diagram of an apparatus for patching a shared code segment according to a ninth embodiment of the present invention. As shown in FIG. 9, the embodiment includes: a first modification module 91, a first interruption module 92, a first patch module 93, and a second interrupt module 94. The first modification module 91 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory before the main VCPU patches the original function; wherein, the original function is a shared function that needs to be patched. The first interrupt module 92 sends the first interrupt message to the service VCPU after the first modification module 91 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory. The first interrupt information is used to instruct each service VCPU to interrupt the current service and immediately refresh its own fast instruction buffer, so that the modified instruction of the first modification module 91 takes effect quickly. Therefore, when the main VCPU patches the original function, each service VCPU is caused to jump to the exception processing according to the first instruction of the original function.
第一补丁模块 93在第一中断模块 92向业务 VPCU发送第一中断信息后, 在 共享内存中,将原函数的第一条指令和第二条指令修改为跳转到补丁函数的指 令。 第一补丁模块 93的具体操作可为: 先将原函数的第二条指令修改为延迟槽 指令; 将原函数的第一条指令修改为跳转到补丁函数的指令。 由于, 第一补丁 模块 93在共享内存中,将原函数的第一条指令和第二条指令修改为跳转到补丁 函数的指令时, 各业务 VCPU已根据第一中断信息的指示, 刷新了自身的快速 指令缓沖区。 因而, 若各业务 VCPU执行到原函数时, 会跳转到异常处理中, 从而不会受到第一补丁模块 93为原函数打补丁的影响。  After the first interrupt module 92 sends the first interrupt information to the service VPCU, the first patch module 93 modifies the first instruction and the second instruction of the original function into an instruction to jump to the patch function in the shared memory. The specific operation of the first patch module 93 may be: first modifying the second instruction of the original function into a delay slot instruction; modifying the first instruction of the original function to an instruction that jumps to the patch function. Because the first patch module 93 changes the first instruction and the second instruction of the original function to the instruction to jump to the patch function in the shared memory, each service VCPU has refreshed according to the instruction of the first interrupt information. Its own fast instruction buffer. Therefore, if each service VCPU executes the original function, it will jump to the exception processing, so that it is not affected by the patching of the original function by the first patch module 93.
第二中断模块 94在第一补丁模块 93在共享内存中,将原函数的第一条指令 和第二条指令修改为跳转到补丁函数的指令后, 向业务 VPCU发送第二中断信 息。 第二中断信息用于指示各业务 VCPU中断当前业务, 刷新自身的快速指令 緩冲区, 从而使原函数打的补丁函数怏速生效。  The second interrupt module 94 sends the second interrupt information to the service VPCU after the first patch module 93 modifies the first instruction and the second instruction of the original function to jump to the patch function in the shared memory. The second interrupt information is used to instruct each service VCPU to interrupt the current service and refresh its own fast instruction buffer, so that the patch function of the original function is decelerated.
本实施例中各模块的工作机理参见图 1对应实施例中的描述, 在此不再赘 述。  For the working mechanism of each module in this embodiment, refer to the description in the corresponding embodiment of FIG. 1, and details are not described herein again.
本实施例,在多核处理器系统运行过程中,在第一补丁模块 93对原函数进 行打补丁操作之前,第一修改模块 91将原函数的第一条指令先修改为跳转到异 常处理的指令, 并指示第一中断模块 92向业务 VCPU发送中断信息, 使业务 VCPU立即刷新快速指令緩冲区。 由于, 本发明实施例中业务 VCPU接收到第 一补丁模块 93发送的中断信息后, 不需要向主 VCPU发送响应消息; 并且第一 补丁模块 93向业务 VCPU发送中断信息后, 即可对原函数进行打补丁操作, 因 此, 本发明实施例能使补丁快速生效。 另外, 在第一补丁模块 93对原函数打补 丁操作时, 若业务 VCPU执行到原函数的第一条指令时, 通过上述跳转到异常 处理的指令进入异常处理,再从异常处理进入补丁函数, 从而能保证第一补丁 模块 93对原函数进行正常的打补丁操作。因此本发明实施例为共享代码段打补 丁的装置, 在第一补丁模块 93对原函数打补丁操作时, 不会影响到该业务 VCPU的正常业务处理, 还能使执行到原函数的业务 VCPU从原函数跳转到补 丁函数中执行, 并且不会导致业务阻塞和业务数据丢失。 In this embodiment, during the operation of the multi-core processor system, before the first patch module 93 performs a patching operation on the original function, the first modification module 91 first modifies the first instruction of the original function to jump to the exception processing. The instruction, and instructing the first interrupt module 92 to send an interrupt message to the service VCPU, causes the service VCPU to immediately refresh the fast instruction buffer. In the embodiment of the present invention, after receiving the interrupt information sent by the first patch module 93, the service VCPU does not need to send a response message to the main VCPU; and after the first patch module 93 sends the interrupt information to the service VCPU, the original function can be The patching operation is performed. Therefore, the embodiment of the present invention enables the patch to take effect quickly. In addition, when the first patch module 93 performs a patching operation on the original function, if the service VCPU executes the first instruction to the original function, the instruction that jumps to the exception processing enters the exception processing, and then enters the patch function from the exception processing. , thus ensuring the first patch Module 93 performs a normal patching operation on the original function. Therefore, in the embodiment of the present invention, the device for patching the shared code segment does not affect the normal service processing of the service VCPU when the first patch module 93 patches the original function, and can also perform the service VCPU to the original function. Jump from the original function to the patch function, and will not cause business blocking and business data loss.
图 10为本发明第十实施例为共享代码段打补丁的装置的结构示意图,如图 10 is a schematic structural diagram of an apparatus for patching a shared code segment according to a tenth embodiment of the present invention, as shown in FIG.
10所示, 在图 9对应实施例的基础上, 还包括: 第二修改模块 95、 第三中断模 块 96、 第一恢复模块 97和第四中断模块 98。 10, based on the corresponding embodiment of FIG. 9, further comprising: a second modification module 95, a third interrupt module 96, a first recovery module 97, and a fourth interrupt module 98.
若第一补丁模块 93对原函数的第一条指令和第二条指令有误,并且在第一 补丁模块 93修改完后, 第二中断模块 94已向各业务 VCPU发送过第二中断信 息, 则通过本实施例中第一恢复模块,将原函数的第一条指令和第二条指令恢 复为对原函数修改前的指令。 具体如下:  If the first patch module 93 has an error in the first instruction and the second instruction of the original function, and after the first patch module 93 is modified, the second interrupt module 94 has sent the second interrupt information to each service VCPU. Then, by using the first recovery module in this embodiment, the first instruction and the second instruction of the original function are restored to the instruction before the original function is modified. details as follows:
第二修改模块 95已向各业务 VCPU发送过第二中断信息后, 并在恢复原函 数的第一条指令和第二条指令前,在共享内存中,将原函数的第一条指令修改 为跳转到异常处理的指令。 第三中断模块 96在第二修改模块 95在共享内存中, 将原函数的第一条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送第 三中断消息, 以指示业务 VCPU中断当前业务, 刷新自身的快速指令緩冲区。 第一恢复模块 97在第三中断模块 96向业务 VCPU发送笫三中断消息后, 在共享 内存中 ,将原函数的第一条指令和第二条指令,恢复成对原函数修改前的指令。 第四中断模块 98在第一恢复模块 97在共享内存中,将原函数的第一条指令和第 二条指令,恢复成对原函数修改前的指令后,向业务 VCPU发送第四中断信息, 以指示业务 VCPU, 中断当前业务立即刷新各自的快速指令緩沖区, 从而使业 务 VCPU自身的快速指令緩冲区中指令与共享内存中指令同步更新。  After the second modification module 95 has sent the second interrupt information to each service VCPU, and before restoring the first instruction and the second instruction of the original function, in the shared memory, the first instruction of the original function is modified to Jump to the instruction of exception handling. After the third modification module 95 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory, the third interrupt module 96 sends a third interrupt message to the service VCPU to indicate that the service VCPU interrupts the current Business, refresh its own fast instruction buffer. After the third interrupt module 96 sends the third interrupt message to the service VCPU, the first recovery module 97 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory. The fourth interrupt module 98 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory in the first recovery module 97, and then sends the fourth interrupt information to the service VCPU. In order to indicate the service VCPU, the current service is interrupted and the respective fast instruction buffers are refreshed, so that the instructions in the fast instruction buffer of the service VCPU itself are updated synchronously with the instructions in the shared memory.
本实施例中各模块的工作机理参见图 2对应实施例中的描述, 在此不再赘 述。  For the working mechanism of each module in this embodiment, refer to the description in the corresponding embodiment of FIG. 2, and details are not described herein again.
本实施例在第一恢复模块 97恢复原函数的第一条指令和第二条指令之前, 第二修改模块 95将原函数的第一条指令先修改为跳转到异常处理的指令,并通 过第三中断模块 96向业务 VCPU发送第三中断信息, 使业务 VCPU立即刷新快 速指令緩冲区。 在第一恢复模块 97恢复原函数的第一条指令和第二条指令时, 若业务 VCPU执行到原函数则通过跳转到异常处理的指令进入异常处理, 再从 异常处理跳转到补丁函数的首地址处, 开始执行补丁函数中的指令, 以保证第 一恢复模块 97对原函数进行修改时。 由于,在第一恢复模块 94对原函数打补丁 操作时, 若业务 VCPU执行到原函数则从异常处理进入补丁函数, 因此本实施 例, 在第一恢复模块 97对原函数打补丁操作时, 不影响业务 VCPU的正常业务 处理, 不会造成业务阻塞和数据丢失。 In this embodiment, before the first recovery module 97 restores the first instruction and the second instruction of the original function, the second modification module 95 first modifies the first instruction of the original function to jump to the instruction of the exception processing, and passes the instruction. The third interrupt module 96 sends a third interrupt message to the service VCPU, so that the service VCPU immediately refreshes the fast instruction buffer. When the first recovery module 97 restores the first instruction and the second instruction of the original function, if the service VCPU executes the original function, the exception processing is performed by jumping to the exception processing instruction, and then the exception processing is jumped to the patch function. At the first address, start executing the instructions in the patch function to ensure that A recovery module 97 modifies the original function. When the first recovery module 94 performs the patching operation on the original function, if the service VCPU executes the original function, the patch function is entered from the exception processing. Therefore, in the embodiment, when the first recovery module 97 patches the original function, It does not affect the normal service processing of the service VCPU, and will not cause traffic congestion and data loss.
图 11 a为本发明第十一实施例为共享代码段打补丁的装置的结构示意图。 如图 11a所示, 本实施例包括: 第一刷新模块 111、 第一异常处理模块 112和第 一补丁函数执行模块 113以及第二刷新模块 114。  11a is a schematic structural diagram of an apparatus for patching a shared code segment according to an eleventh embodiment of the present invention. As shown in FIG. 11a, the embodiment includes: a first refresh module 111, a first exception processing module 112, and a first patch function execution module 113 and a second refresh module 114.
第一刷新模块 111接收到主 VCPU发送的第一中断信息后,根据第一中断信 息的指示, 中断当前业务立即刷新快速指令緩冲区, 以使业务 VCPU自身的快 速指令緩冲区中指令与共享内存中指令同步更新。 后续, 在业务 VCPU执行到 原函数的第一条指令时, 第一异常处理模块 112根据原函数的跳转到异常处理 的指令, 进入异常处理; 在异常处理中, 根据需要打补丁的原函数的首地址, 在补丁区查找补丁函数的首地址; 补丁函数为替换原函数的函数。 第一异常处 理模块 112查找到补丁函数的首地址后,第一补丁函数执行模块 113从异常处理 返回到补丁函数的首地址, 并执行补丁函数。  After receiving the first interrupt information sent by the main VCPU, the first refresh module 111 interrupts the current service and immediately refreshes the fast instruction buffer according to the instruction of the first interrupt information, so that the instruction in the fast instruction buffer of the service VCPU itself is Synchronous updates to instructions in shared memory. Subsequently, when the service VCPU executes the first instruction to the original function, the first exception processing module 112 enters the exception processing according to the instruction of the original function to jump to the exception processing; in the exception processing, the original function that needs to be patched according to the need The first address, find the first address of the patch function in the patch area; the patch function is a function that replaces the original function. After the first exception processing module 112 finds the first address of the patch function, the first patch function execution module 113 returns from the exception processing to the first address of the patch function, and executes the patch function.
由于主业务 VCPU在向业务 VCPU发送第一中断信息后, 会进行为原函数 打补丁的操作, 并在为原函数打补丁之后向各业务 VCPU发送第二中断信息 。 因此, 第二刷新模块 114在第一刷新模块 111根据第一中断信息的指示, 中断当 前业务, 刷新快速指令緩冲区之后, 接收主 VCPU发送的第二中断信息, 根据 第二中断信息的指示, 中断当前业务, 刷新自身的快速指令緩冲区, 以使业务 VCPU自身的快速指令緩冲区中指令与共享内存中指令同步更新。  After the primary service VCPU sends the first interrupt information to the service VCPU, it performs the operation of patching the original function, and sends the second interrupt information to each service VCPU after the original function is patched. Therefore, the second refreshing module 114 interrupts the current service according to the instruction of the first interrupt information, refreshes the fast instruction buffer, and receives the second interrupt information sent by the main VCPU according to the indication of the second interrupt information. Interrupt the current service and refresh its own fast instruction buffer to synchronize the instructions in the fast instruction buffer of the service VCPU itself with the instructions in the shared memory.
上述各模块的工作机理参见图 3a和图 3b对应实施例中的描述,在此不再赘 述。  The working mechanism of each module mentioned above is described in the corresponding embodiment of FIG. 3a and FIG. 3b, and details are not described herein again.
若主 VCPU为原函数打补丁之后, 需要对原函数的第一条指令和第二条指 令进行恢复时,如图 1 lb 所示 ,业务 VCPU可通过以下模块:第三刷新模块 115、 第二异常处理模块 116、 第二补丁函数执行模块 117和第四刷新模块 118 , 处理 与主 VPUC的交互、 并不影响当前业务的正常处理。  If the primary VCPU needs to restore the first instruction and the second instruction of the original function after patching the original function, as shown in FIG. 1 lb, the service VCPU can pass the following modules: the third refresh module 115, the second The exception handling module 116, the second patch function execution module 117, and the fourth refresh module 118 process the interaction with the master VPUC without affecting the normal processing of the current service.
第三刷新模块 115在第二刷新模块 114刷新快速指令緩沖区后, 接收主 VCPU发送的第三中断信息, 根据第三中断信息的指示, 中断当前业务, 刷新 自身的快速指令缓冲区。第二异常处理模块 116在第三刷新模块 115刷新快速指 令緩冲区后, 执行到原函数的第一条指令时, 根据主 VCPU原函数的第一条指 令, 进入异常处理; 在异常处理中, 根据需要打补丁的原函数的首地址, 在补 丁区查找出补丁函数的首地址。 第二补丁函数执行模块 117在第二异常处理模 块 116查找出补丁函数的首地址后, 根据补丁函数的首地址, 从异常处理跳转 到补丁函数中执行。 After the second refresh module 114 refreshes the fast instruction buffer, the third refresh module 115 receives the third interrupt information sent by the main VCPU, and interrupts the current service according to the instruction of the third interrupt information, and refreshes its own fast instruction buffer. The second exception processing module 116 refreshes the fast finger in the third refresh module 115. After the buffer is executed, when the first instruction of the original function is executed, according to the first instruction of the original VCPU original function, the exception processing is entered; in the exception processing, according to the first address of the original function to be patched, in the patch The area finds the first address of the patch function. After the second exception function processing module 117 finds the first address of the patch function, the second patch function execution module 117 jumps from the exception processing to the patch function according to the first address of the patch function.
第四刷新模块 118在第三刷新模块 115根据第三中断信息的指示, 中断当前 业务, 刷新自身的快速指令緩沖区之后, 接收主 VCPU发送的第四中断信息 的指示, 根据第四中断信息的指示, 中断当前业务, 刷新自身的快速指令緩冲 区, 以使业务 VCPU自身的快速指令緩冲区中指令与共享内存中指令同步更 新。  The fourth refresh module 118, after the third refresh module 115 interrupts the current service according to the instruction of the third interrupt information, and refreshes its own fast instruction buffer, receives an indication of the fourth interrupt information sent by the main VCPU, according to the fourth interrupt information. Instructs to interrupt the current service and refresh its own fast instruction buffer to synchronize the instructions in the fast instruction buffer of the service VCPU itself with the instructions in the shared memory.
上述各模块的工作机理参见图 4a和图 4b对应实施例中的描述,在此不再赘 述。  The working mechanism of each of the above modules is described in the corresponding embodiment of FIG. 4a and FIG. 4b, and details are not described herein again.
本实施例,在多核处理器系统运行过程中,第一刷新模块 111接收到主 CPU 发送的中断信息后, 立即刷新各自的快速指令缓冲区。 在业务 VCPU执行到原 函数的第一条指令时, 且没有接收到主 VCPU发送的第二中断信息之前, 根据 跳转到异常处理的指令跳转到异常处理中, 然后从异常处理中进入补丁函数 中, 开始执行补丁函数。 因此本实施例, 在主 VCPU对原函数打补丁操作或恢 复操作时, 不会影响到该业务 VCPU的正常业务处理, 还能使执行到原函数的 业务 VCPU从原函数跳转到补丁函数中执行。  In this embodiment, during the operation of the multi-core processor system, the first refresh module 111 immediately refreshes the respective fast instruction buffers after receiving the interrupt information sent by the main CPU. When the service VCPU executes the first instruction to the original function, and does not receive the second interrupt information sent by the main VCPU, jumps to the exception processing according to the instruction that jumps to the exception processing, and then enters the patch from the exception processing. In the function, the patch function is started. Therefore, in this embodiment, when the primary VCPU patches or restores the original function, it does not affect the normal service processing of the service VCPU, and can also cause the service VCPU executing the original function to jump from the original function to the patch function. carried out.
图 12为本发明第十二实施例为共享代码段打补丁的装置的结构示意图。如 图 12所示, 本实施例包括: 第三修改模块 121和第一消息发送模块 122。  FIG. 12 is a schematic structural diagram of an apparatus for patching a shared code segment according to a twelfth embodiment of the present invention. As shown in FIG. 12, the embodiment includes: a third modification module 121 and a first message sending module 122.
为原函数打补丁前, 第三修改模块 121在共享内存中, 将原函数的第一条 指令修改为跳转到异常处理的指令。第一消息发送模块 122在第三修改模块 121 在共享内存中,将原函数的第一条指令修改为跳转到异常处理的指令后, 向各 业务 VCPU发送第一补丁激活消息。  Before the original function is patched, the third modification module 121 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory. The first message sending module 122 sends the first patch activation message to each service VCPU after the first modification module 121 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory.
第一补丁激活消息用于指示各业务 VCPU在处理完当前业务后刷新自身 的快速指令缓沖区, 以使各业务 VCPU自身的快速指令缓沖区中指令与共享内 存中指令同步更新。第一补丁激活消息还指示最后一个刷新自身的快速指令緩 冲区的 VCPU, 在共享内存中修改原函数的第一条指令和第二条指令。  The first patch activation message is used to instruct each service VCPU to refresh its own fast instruction buffer after processing the current service, so that the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory. The first patch activation message also indicates the last VCPU that refreshes its own fast instruction buffer, and modifies the first instruction and the second instruction of the original function in the shared memory.
本实施例中各模块的工作机理参见图 5对应实施例中的描述, 在此不再赘 述。 For the working mechanism of each module in this embodiment, refer to the description in the corresponding embodiment in FIG. 5, and no longer Said.
本实施例, 在多核处理器系统运行过程中, 第三修改模块 121将原函数的 第一条指令修改为跳转到异常处理的指令后, 第一消息发送模块 122向业务 VCPU发送第一补丁激活消息, 使业务 VCPU处理完当前业务后刷新快速指令 緩沖区。 最后一个刷新快速指令緩沖区的业务 VCPU对原函数进行打补丁的操 作后,通知其它业务 VCPU刷新各自的快速指令緩冲区。在最后一个业务 VCPU 对原函数进行打补丁操作时, 其它业务 VCPU若执行到原函数, 则从原函数的 第一条指令则进入异常处理,再从异常处理中跳转到补丁函数的首地址执行补 丁函数中的指令。 从而, 最后一个业务 VCPU对原函数进行补丁操作时, 不影 响其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丢失。  In this embodiment, after the third modification module 121 modifies the first instruction of the original function to the instruction that jumps to the exception processing, the first message sending module 122 sends the first patch to the service VCPU. Activate the message to refresh the fast instruction buffer after the service VCPU has processed the current service. The last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched. When the last service VCPU patches the original function, if the other service VCPU executes the original function, the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the last service VCPU performs a patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
图 13为本发明第十三实施例为共享代码段打补丁的装置的结构示意图。如 图 13所示, 在图 12对应实施例的基础上, 本实施例还包括: 第二消息发送模块 124和第四修改模块 123。  FIG. 13 is a schematic structural diagram of an apparatus for patching a shared code segment according to a thirteenth embodiment of the present invention. As shown in FIG. 13, on the basis of the corresponding embodiment of FIG. 12, the embodiment further includes: a second message sending module 124 and a fourth modifying module 123.
若最后一个刷新自身快速指令缓沖区的 VCPU, 对原函数的第一条指令和 第二条指令有误, 并且已通知过各业务 VCPU发送再次刷新自身的快速指令缓 冲区。 可通过本实施例第二消息发送模块 124, 向各业务 VCPU发送第二激活 补丁消息, 指示最后一个刷新自身快速指令緩冲区的 VCPU。 将原函数的笫一 条指令和第二条指令修改为原函数原有的指令。  If the last VCPU of its own fast instruction buffer is refreshed, the first instruction and the second instruction of the original function are incorrect, and each service VCPU has been notified to send a fast instruction buffer to refresh itself again. The second message sending module 124 of the embodiment may send a second activation patch message to each service VCPU to indicate the last VCPU that refreshes its own fast instruction buffer. Modify one instruction and the second instruction of the original function to the original instruction of the original function.
具体地, 第四修改模块 123, 在第一消息发送模块向业务 VCPU发送第一 补丁激活消息之后, 在共享内存中,将原函数的第一条指令修改为跳转到异常 处理的指令。 第二消息发送模块 124在第四修改模块 123在共享内存中,将原函 数的第一条指令修改为跳转到异常处理的指令之后, 向各业务 VCPU发送第二 补丁激活消息; 第二补丁激活消息用于指示各业务 VCPU刷新自身的快速指令 緩冲区, 以使各业务 VCPU自身的快速指令緩冲区中指令与共享内存中指令同 步更新。 第二补丁激活消息还指示各业务 VCPU中最后一个刷新自身的快速指 令緩冲区的 VCPU, 在共享内存中, 将原函数的第一条指令和第二条指令恢复 为对原函数修改前的指令。  Specifically, the fourth modification module 123, after the first message sending module sends the first patch activation message to the service VCPU, modify the first instruction of the original function to jump to the abnormal processing instruction in the shared memory. The second message sending module 124 sends the second patch activation message to each service VCPU after the first modification module 123 modifies the first instruction of the original function to jump to the exception processing instruction in the shared memory. The activation message is used to instruct each service VCPU to refresh its own fast instruction buffer, so that the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory. The second patch activation message also indicates that the VCPU of the fast instruction buffer of each service VCPU is refreshed by itself, and in the shared memory, the first instruction and the second instruction of the original function are restored to the original function. instruction.
本实施例中各模块的工作机理参见图 6对应实施例中的描述, 在此不再赘 述。  For the working mechanism of each module in this embodiment, refer to the description in the corresponding embodiment of FIG. 6, and details are not described herein again.
本实施例,在多核处理器系统运行过程中, 若对原函数的打补丁操作出现 错误, 需要对原函数的指令恢复时, 第四修改模块 124先将原函数的第一条指 令修改为跳转到异常处理的指令, 第二消息发送模块 123再向业务 VCPU发送 第二补丁激活消息。 业务 VCPU处理完当前业务后, 根据第二补丁激活消息刷 新自身的快速指令緩冲区后, 若其它业务 VCPU执行到原函数的第一条指令即 跳转到异常处理的指令,根据跳转到异常处理的指令进入异常处理,再从异常 处理中跳转到补丁函数的首地址执行补丁函数中的指令。从而, 最后一个业务 VCPU对原函数进行恢复操作时, 不影响其它业务 VCPU的正常业务处理, 不 会造成业务阻塞和丟失。 In this embodiment, in the running process of the multi-core processor system, if the patching operation of the original function occurs If the instruction of the original function needs to be restored, the fourth modification module 124 first modifies the first instruction of the original function to jump to the exception processing instruction, and the second message sending module 123 sends the second patch activation to the service VCPU. Message. After the service VCPU processes the current service, after refreshing its own fast instruction buffer according to the second patch activation message, if the other service VCPU executes the first instruction of the original function, it jumps to the exception processing instruction, according to the jump to The exception-handled instruction enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the last service VCPU restores the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
图 14为本发明第十四实施例为共享代码段打补丁的装置的结构示意图。如 图 14所示, 本实施例包括: 第一接收模块 141、 第二补丁模块 142和第一刷新通 知模块 143以及判断模块 144。  FIG. 14 is a schematic structural diagram of an apparatus for patching a shared code segment according to a fourteenth embodiment of the present invention. As shown in FIG. 14, the embodiment includes: a first receiving module 141, a second patch module 142, and a first refresh notification module 143 and a determining module 144.
第一接收模块 141接收到主 VCPU发送的第一补丁激活消息后, 判断模块 144判断。 当前业务 VCPU是否是最后一个刷新自身的快速指令緩冲区的业务 VCPU。判断模块 144判断出当前业务 VPCU是最后一个刷新自身的快速指令缓 冲区的业务 VCPU时, 第二补丁模块 142根据第一补丁激活消息的指示, 在共 享内存中修改原函数的前两条指令。 第一刷新通知模块 143在第二补丁模块在 共享内存中将原函数的第一条指令和第二条指令修改为跳转到补丁函数的指 令后, 刷新业务 VCPU的快速指令緩冲区, 并通过主 VCPU通知除最后一个刷 新自身的快速指令緩冲区的业务 VCPU以外的其它业务 VCPU刷新自身的快速 指令緩冲区, 以使业务 VCPU自身的快速指令緩冲区中指令与共享内存中指令 同步更新。  After the first receiving module 141 receives the first patch activation message sent by the primary VCPU, the determining module 144 determines. Current Service VCPU is the last service VCPU that refreshes its own fast instruction buffer. When the determining module 144 determines that the current service VPCU is the last service VCPU that refreshes its own fast command buffer, the second patch module 142 modifies the first two instructions of the original function in the shared memory according to the indication of the first patch activation message. The first refresh notification module 143 refreshes the fast instruction buffer of the service VCPU after the second patch module modifies the first instruction and the second instruction of the original function into the instruction to jump to the patch function in the shared memory, and The VCPU notifies the other service VCPUs other than the service VCPU that refreshes its own fast instruction buffer by the main VCPU to refresh its own fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself and the instruction in the shared memory Synchronization Update.
本实施例中各模块的工作机理参见图 7a和图 7 b对应实施例中的描述, 在 此不再赘述。  For the working mechanism of each module in this embodiment, reference is made to the description in the corresponding embodiment in FIG. 7a and FIG. 7b, and details are not described herein again.
本发明实施例为共享代码段打补丁的装置, 在多核处理器系统运行过程 中, 主 VCPU将原函数的第一条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送补丁激活消息, 使业务 VCPU处理完当前业务后刷新快速指令緩冲 区。 最后一个刷新快速指令缓沖区的业务 VCPU对原函数进行打补丁的操作 后, 通知其它业务 VCPU刷新各自的快速指令緩沖区。 在最后一个业务 VCPU 对原函数进行打补丁操作时, 其它业务 VCPU若执行到原函数, 则从原函数的 第一条指令则进入异常处理,再从异常处理中跳转到补丁函数的首地址执行补 丁函数中的指令。 从而, 第二补丁模块 142对原函数进行补丁操作时, 不影响 其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丟失。 The embodiment of the present invention is a device for patching a shared code segment. During the running of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the instruction of the exception processing, and sends a patch activation message to the service VCPU. , the service VCPU refreshes the fast instruction buffer after processing the current service. The last service VCPU that refreshes the fast instruction buffer, after patching the original function, notifies other service VCPUs to refresh their respective fast instruction buffers. When the last service VCPU patches the original function, if the other service VCPU executes the original function, the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execution The instruction in the function. Therefore, when the second patch module 142 performs the patch operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service congestion and loss.
在上迷方案中, 若第二补丁模块 142对原函数的打补丁操作出现错误, 需 要对原函数的指令恢复时, 为不影响业务 VCPU的正常执行, 主 VCPU先将原 函数的第一条指令修改为跳转到异常处理的指令, 再向业务 VCPU发送第二补 丁激活消息。 第二补丁激活消息指示最后一个业务 VCPU刷新自身的快速指令 緩沖区之前, 对原函数的前两条指令进行恢复操作。 因此, 在图 14对应实施例 的基础上, 图 15对应实施例还包括: 第二接收模块 145和第二恢复模块 146以及 第二刷新通知模块 147。 图 15为本发明第十五实施例为共享代码段打补丁的装 置的结构示意图。  In the above scheme, if the patching operation of the original function by the second patch module 142 is incorrect, and the instruction of the original function needs to be restored, the main VCPU first sets the first function of the original function so as not to affect the normal execution of the service VCPU. The instruction is modified to jump to the exception handling instruction, and then sends a second patch activation message to the service VCPU. The second patch activation message indicates that the last service VCPU resumes the first two instructions of the original function before refreshing its own fast instruction buffer. Therefore, on the basis of the corresponding embodiment of FIG. 14, the corresponding embodiment of FIG. 15 further includes: a second receiving module 145 and a second recovery module 146 and a second refresh notification module 147. Figure 15 is a block diagram showing the structure of a device for patching a shared code segment according to a fifteenth embodiment of the present invention.
当第二补丁模块 142在共享内存中将原函数的第一条指令和第二条指令修 改为跳转到补丁函数的指令后, 第二接收模块 145接收到主 VCPU发送的第二 补丁激活消息时。 判断模块 144判断出当前业务 VCPU是最后一个刷新自身的 快速指令緩冲区的业务 VCPU时。 第二恢复模块 146根据第二补丁激活消息的 指示, 在业务 VCPU处理完当前业务后, 在共享内存中将原函数的第一条指令 和第二条指令, 恢复成对原函数修改前的指令。  After the second patch module 142 modifies the first instruction and the second instruction of the original function into the instruction to jump to the patch function in the shared memory, the second receiving module 145 receives the second patch activation message sent by the primary VCPU. Time. The judging module 144 judges that the current service VCPU is the last service VCPU that refreshes its own fast instruction buffer. The second recovery module 146 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory after the service VCPU processes the current service according to the indication of the second patch activation message. .
第二刷新通知模块 147在第二恢复模块 146将在共享内存中将原函数的第 一条指令和第二条指令, 恢复成对原函数修改前的指令后, 刷新业务 VCPU的 快速指令緩冲区, 并通过主 VCPU通知除最后一个刷新自身的快速指令緩冲区 的业务 VCPU以外的其它业务 VCPU刷新自身的快速指令緩冲区, 以使业务 VCPU自身的快速指令緩冲区中指令与共享内存中指令同步更新。  The second refresh notification module 147 restores the first instruction and the second instruction of the original function to the instruction before the original function modification in the shared memory, and refreshes the fast instruction buffer of the service VCPU. The area, and the main VCPU notifies the service VCPU except the service VCPU that refreshes its own fast instruction buffer to refresh its own fast instruction buffer, so that the instruction and sharing in the fast instruction buffer of the service VCPU itself In-memory instructions are updated synchronously.
本实施例中各模块的工作机理参见图 7a和图 7 b对应实施例中的描述, 在 此不再赘述。  For the working mechanism of each module in this embodiment, reference is made to the description in the corresponding embodiment in FIG. 7a and FIG. 7b, and details are not described herein again.
本实施例中业务 VCPU处理完当前业务, 根据第二补丁激活消息刷新自身 的快速指令緩冲区后, 若有业务 VCPU执行到原函数的第一条指令即跳转到异 常处理的指令,根据跳转到异常处理的指令进入异常处理,再从异常处理中跳 转到补丁函数的首地址执行补丁函数中的指令。 从而, 第二恢复模块 146对原 函数进行恢复操作时, 不影响其它业务 VCPU的正常业务处理, 不会造成业务 阻塞和丟失。  In this embodiment, after the service VCPU processes the current service and refreshes its own fast instruction buffer according to the second patch activation message, if the service VCPU executes the first instruction to the original function, the instruction jumps to the exception processing instruction, according to The instruction that jumps to the exception handling enters the exception handling, and then jumps from the exception handling to the first address of the patch function to execute the instruction in the patch function. Therefore, when the second recovery module 146 performs the recovery operation on the original function, it does not affect the normal service processing of other service VCPUs, and does not cause service blocking and loss.
图 16为本发明第十六实施例提供的为共享代码段打补丁的装置。 如图 16 所示, 在图 14对应实施例的基础上, 本实施例还包括: 第五刷新模块 148、 第 三异常处理模块 149和第三补丁函数执行模块 140。 FIG. 16 is a diagram of a device for patching a shared code segment according to a sixteenth embodiment of the present invention. Figure 16 The present embodiment further includes: a fifth refresh module 148, a third exception processing module 149, and a third patch function execution module 140, based on the corresponding embodiment of FIG.
第一接收模块 141接收到主 VCPU发送的第一补丁激活消息或第二接收模 块 145接收到主 VCPU发送的第二补丁激活消息后, 第五刷新模块 148在判断模 块 144判断出当前业务 VCPU不是最后一个刷新自身的快速指令緩冲区的业务 VCPU时, 在当前业务 VCPU处理完当前业务后, 根据第一补丁激活消息或第 二补丁激活消息的指示, 刷新业务 VCPU的快速指令緩沖区。 从而, 使各业务 VCPU自身的快速指令緩冲区中指令与共享内存中指令同步更新。 在上述业务 VCPU执行到原函数的第一条指令时, 第三异常处理模块 149根据原函数的跳 转到异常处理的指令,进入异常处理;并在异常处理中,根据原函数的首地址, 在补丁区查找补丁函数的首地址。 第三异常处理模块 149查找出补丁函数的首 地址后, 第三补丁函数执行模块 140根据补丁函数的首地址, 从异常处理跳转 到补丁函数中执行。  After the first receiving module 141 receives the first patch activation message sent by the primary VCPU or the second receiving module 145 receives the second patch activation message sent by the primary VCPU, the fifth refreshing module 148 determines in the determining module 144 that the current service VCPU is not When the service VCPU of the fast instruction buffer of the current service is refreshed, after the current service VCPU processes the current service, the fast instruction buffer of the service VCPU is refreshed according to the indication of the first patch activation message or the second patch activation message. Thereby, the instructions in the fast instruction buffer of each service VCPU itself are updated synchronously with the instructions in the shared memory. When the service VCPU executes the first instruction to the original function, the third exception processing module 149 enters the exception processing according to the instruction of the original function to jump to the exception processing; and in the exception processing, according to the first address of the original function, Find the first address of the patch function in the patch area. After the third exception processing module 149 finds the first address of the patch function, the third patch function execution module 140 jumps from the exception processing to the patch function according to the first address of the patch function.
上述各模块的工作机理参见图 7a、图 7b、图 8a和图 8b对应实施例中的描述, 在此不再赘述。  The working mechanism of each of the above modules is described in the corresponding embodiments in FIG. 7a, FIG. 7b, FIG. 8a and FIG. 8b, and details are not described herein again.
本发明实施例为共享代码段打补丁的装置, 在多核处理器系统运行过程 中, 主 VCPU将原函数的第一条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送补丁激活消息, 使业务 VCPU处理完当前业务后刷新快速指令緩沖 区。 最后一个刷新快速指令緩冲区的业务 VCPU对原函数进行打补丁的操作 后, 通知其它业务 VCPU刷新各自的快速指令緩冲区。 在最后一个业务 VCPU 对原函数进行打补丁操作时, 其它业务 VCPU若执行到原函数, 则从原函数的 第一条指令则进入异常处理,再从异常处理中跳转到补丁函数的首地址执行补 丁函数中的指令。 从而, 第二补丁模块 142对原函数进行补丁操作时, 不影响 其它业务 VCPU的正常业务处理, 不会造成业务阻塞和丢失。  The embodiment of the present invention is a device for patching a shared code segment. During the running of the multi-core processor system, the main VCPU modifies the first instruction of the original function to jump to the instruction of the exception processing, and sends a patch activation message to the service VCPU. , the service VCPU refreshes the fast instruction buffer after processing the current service. The last service that refreshes the fast instruction buffer VCPU notifies other services VCPU to refresh their respective fast instruction buffers after the original function is patched. When the last service VCPU patches the original function, if the other service VCPU executes the original function, the first instruction from the original function enters the exception processing, and then jumps from the exception processing to the first address of the patch function. Execute the instructions in the patch function. Therefore, when the second patch module 142 performs the patch operation on the original function, it does not affect the normal service processing of the VCPU of other services, and does not cause service congestion and loss.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到本发明 可借助软件加必需的硬件平台的方式来实现, 当然也可以全部通过硬件来实 施, 但很多情况下前者是更佳的实施方式。基于这样的理解, 本发明的技术方 案对背景技术做出贡献的全部或者部分可以以软件产品的形式体现出来,该计 算机软件产品可以存储在存储介质中, 如 ROM/RAM、 磁碟、 光盘等, 包括若 干指令用以使得一台计算机设备(可以是个人计算机, 服务器, 或者网络设备 等)执行本发明各个实施例或者实施例的某些部分所述的方法。 Through the description of the above embodiments, those skilled in the art can clearly understand that the present invention can be implemented by means of software plus a necessary hardware platform, and of course, all can be implemented by hardware, but in many cases, the former is better. Implementation. Based on such understanding, all or part of the technical solution of the present invention contributing to the background art may be embodied in the form of a software product, which may be stored in a storage medium such as a ROM/RAM, a magnetic disk, an optical disk, or the like. , including a number of instructions to make a computer device (which can be a personal computer, server, or network device) Etc.) Performing the methods described in various embodiments of the invention or in certain portions of the embodiments.
最后应说明的是:以上实施例仅用以说明本发明的技术方案而非对其进行 限制,尽管参照较佳实施例对本发明进行了详细的说明, 本领域的普通技术人 员应当理解: 其依然可以对本发明的技术方案进行修改或者等同替换, 而这些 修改或者等同替换亦不能使修改后的技术方案脱离本发明技术方案的精神和 范围。  It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to be limiting, although the present invention will be described in detail with reference to the preferred embodiments. The technical solutions of the present invention may be modified or equivalently substituted, and the modified technical solutions may not deviate from the spirit and scope of the technical solutions of the present invention.

Claims

权 利 要 求 Rights request
1、 一种为共享代码段打补丁的方法, 其特征在于, 包括: A method for patching a shared code segment, the method comprising:
为原函数打补丁前,在共享内存中,将原函数的第一条指令修改为跳转到 异常处理的指令, 所述原函数为需要打补丁的共享函数;  Before patching the original function, in the shared memory, the first instruction of the original function is modified to jump to the exception handling instruction, and the original function is a shared function that needs to be patched;
向业务 VCPU发送第一中断消息, 所述第一中断信息用于指示所述业务 VCPU中断当前业务, 刷新自身的快速指令缓冲区;  Sending a first interrupt message to the service VCPU, where the first interrupt information is used to indicate that the service VCPU interrupts the current service, and refreshes its own fast instruction buffer;
在所述共享内存中,将所述原函数的第一条指令和第二条指令修改为跳转 到补丁函数的指令, 以使执行到所述原函数的所述业务 VCPU从所述原函数跳 转到所述补丁函数, 所述补丁函数为替换所述原函数的函数;  In the shared memory, modifying the first instruction and the second instruction of the original function into an instruction to jump to the patch function, so that the service VCPU executing the original function is executed from the original function Jumping to the patch function, the patch function is a function that replaces the original function;
向所述业务 VCPU发送第二中断信息, 所迷第二中断信息用于指示所述业 务 VCPU中断当前业务, 刷新自身的快速指令緩冲区。  The second interrupt information is sent to the service VCPU, and the second interrupt information is used to instruct the service VCPU to interrupt the current service and refresh its own fast instruction buffer.
2、 根据权利要求 1所述的为共享代码段打补丁的方法, 其特征在于, 在向 所述业务 VCPU发送第二中断信息之后, 还包括:  2. The method for patching a shared code segment according to claim 1, wherein after the sending the second interrupt information to the service VCPU, the method further includes:
恢复所述原函数的第一条指令和第二条指令前,在所迷共享内存中将所述 原函数的第一条指令修改为跳转到异常处理的指令;  Before restoring the first instruction and the second instruction of the original function, modifying the first instruction of the original function into an instruction that jumps to the exception processing in the shared memory;
向所述业务 VCPU发送第三中断消息, 所述第三中断信息用于指示所述业 务 VCPU中断当前业务, 刷新自身的快速指令緩冲区;  Sending a third interrupt message to the service VCPU, where the third interrupt information is used to instruct the service VCPU to interrupt the current service and refresh its own fast instruction buffer;
在所述共享内存中,将所述原函数的第一条指令和第二奈指令, 恢复成对 所述原函数修改前的指令;  Returning, in the shared memory, the first instruction and the second instruction of the original function to an instruction before modifying the original function;
向所述业务 VCPU发送第四中断信息, 所述第四中断信息用于指示所述业 务 VCPU,中断当前业务立即刷新各自的快速指令緩冲区,以使所述业务 VCPU 自身的快速指令緩冲区中指令与所述共享内存中指令同步更新。  And sending, by the service VCPU, fourth interrupt information, where the fourth interrupt information is used to instruct the service VCPU to interrupt the current service and immediately refresh the respective fast instruction buffers, so that the service VCPU itself has a fast instruction buffer. The instruction in the area is updated synchronously with the instruction in the shared memory.
3、 一种为共享代码段打补丁的方法, 其特征在于, 包括:  3. A method for patching a shared code segment, the method comprising:
接收到主 VCPU发送的第一中断信息后, 根据所述第一中断信息的指示, 中断当前业务, 刷新快速指令緩沖区, 以使所述业务 VCPU自身的快速指令緩 冲区中指令与所述共享内存中指令同步更新, 所述原函数为需要打补丁的函 数;  After receiving the first interrupt information sent by the main VCPU, interrupting the current service according to the instruction of the first interrupt information, and refreshing the fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself is The instruction in the shared memory is synchronously updated, and the original function is a function that needs to be patched;
执行到原函数的第一条指令时,根据所述原函数的第一条指令, 进入异常 处理, 在所述异常处理中, 根据所述原函数的首地址, 在补丁区查找出补丁函 数的首地址, 所述补丁函数为替换所述原函数的函数; 根据所述补丁函数的首 地址, 从所述异常处理跳转到所述补丁函数中执行; When executing the first instruction of the original function, according to the first instruction of the original function, entering an exception processing, in which the patch function is found in the patch area according to the first address of the original function. a first address of the number, the patch function is a function that replaces the original function; and jumps from the exception processing to the patch function according to a first address of the patch function;
在根据所述第一中断信息的指示, 中断当前业务,刷新快速指令緩冲区之 后, 接收所述主 VCPU发送的第二中断信息;  Receiving, according to the indication of the first interrupt information, interrupting the current service, and after refreshing the fast instruction buffer, receiving the second interrupt information sent by the primary VCPU;
根据所述第二中断信息的指示, 中断当前业务,刷新自身的快速指令緩沖 区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与所述共享内存中指令 同步更新。  And interrupting the current service according to the indication of the second interrupt information, and refreshing the fast instruction buffer area of the service, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
4、 根据权利要求 3所述的为共享代码段打补丁的方法, 其特征在于, 在根 据所述第二中断信息的指示,中断当前业务,刷新自身的快速指令緩冲区之后, 还包括:  The method for patching a shared code segment according to claim 3, wherein after interrupting the current service and refreshing the fast instruction buffer according to the indication of the second interrupt information, the method further includes:
接收到所述主 VCPU发送的第三中断信息后 , 根据所述第三中断信息的指 示, 中断当前业务, 刷新自身的快速指令緩冲区, 以使所迷业务 VCPU自身的 快速指令緩冲区中指令与所述共享内存中指令同步更新;  After receiving the third interrupt information sent by the main VCPU, according to the indication of the third interrupt information, interrupting the current service, refreshing its own fast instruction buffer, so that the fast instruction buffer of the service VCPU itself The middle instruction is updated synchronously with the instruction in the shared memory;
执行到所述原函数的第一条指令时, 根据所述主 VCPU所述原函数的第一 条指令, 进入异常处理; 在异常处理中, 根据需要打补丁的原函数的首地址, 在补丁区查找出补丁函数的首地址;根据所述补丁函数的首地址,从所述异常 处理跳转到所述补丁函数中执行;  When the first instruction of the original function is executed, according to the first instruction of the original function of the main VCPU, the exception processing is entered; in the exception processing, according to the first address of the original function to be patched, in the patch The area finds a first address of the patch function; according to the first address of the patch function, jumps from the exception processing to the patch function;
在根据所述第三中断信息的指示, 中断当前业务,刷新自身的快速指令緩 冲区之后, 接收所迷主 VCPU发送的第四中断信息的指示;  Receiving an indication of the fourth interrupt information sent by the host VCPU after interrupting the current service and refreshing the fast command buffer according to the indication of the third interrupt information;
根据所述第四中断信息的指示, 中断当前业务,刷新自身的快速指令緩冲 区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与所述共享内存中指令 同步更新。  And interrupting the current service according to the indication of the fourth interrupt information, and refreshing its own fast instruction buffer area, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
5、 一种为共享代码段打补丁的方法, 其特征在于, 包括:  5. A method for patching a shared code segment, the method comprising:
为原函数打补丁前,在共享内存中,将原函数的第一条指令修改为跳转到 异常处理的指令, 所述原函数为需要打补丁的函数;  Before patching the original function, in the shared memory, the first instruction of the original function is modified to jump to the exception handling instruction, and the original function is a function that needs to be patched;
向各业务 VCPU发送第一补丁激活消息, 所述第一补丁激活消息用于指示 所述业务 VCPU在处理完当前业务后刷新自身的快速指令缓沖区, 以使所述业 务 VCPU自身的快速指令緩沖区中指令与所述共享内存中指令同步更新; 指示 最后一个刷新自身的快速指令緩冲区的 VCPU, 在刷新自身的快速指令緩冲区 之前, 在所述共享内存中修改所述原函数的第一条指令和第二条指令。 Sending a first patch activation message to each service VCPU, where the first patch activation message is used to indicate that the service VCPU refreshes its own fast instruction buffer after processing the current service, so that the service VCPU itself has a fast instruction. The instruction in the buffer is updated synchronously with the instruction in the shared memory; the VCPU indicating the last refresh instruction buffer of its own, modifying the original function in the shared memory before refreshing its own fast instruction buffer The first instruction and the second instruction.
6、 根据权利要求 5所述的为共享代码段打补丁的方法, 其特征在于, 在向 所述业务 VCPU发送第一补丁激活消息之后, 还包括: The method for patching the shared code segment according to claim 5, further comprising: after sending the first patch activation message to the service VCPU,
恢复所述原函数的第一条指令和第二条指令前, 在所述共享内存中,将所 述原函数的第一条指令修改为跳转到异常处理的指令;  Before restoring the first instruction and the second instruction of the original function, modifying, in the shared memory, the first instruction of the original function to jump to an instruction for exception processing;
向所述业务 VCPU发送第二补丁激活消息, 所述第二补丁激活消息用于指 示所述业务 VCPU刷新自身的快速指令緩冲区, 以使所述业务 VCPU自身的快 速指令緩冲区中指令与所述共享内存中指令同步更新; 指示所述业务 VCPU中 最后一个刷新自身的快速指令緩冲区的业务 VCPU, 在刷新自身的快速指令緩 冲区之前,在共享内存中将所述原函数的第一条指令和第二条指令, 恢复成对 所述函数修改前的指令。  Sending a second patch activation message to the service VCPU, where the second patch activation message is used to instruct the service VCPU to refresh its own fast instruction buffer, so that the service VCPU itself has a fast instruction buffer instruction Synchronizing with the instruction in the shared memory; indicating that the service VCPU of the service VCPU last refreshing its own fast instruction buffer, before the refreshing its own fast instruction buffer, the original function in the shared memory The first instruction and the second instruction are restored to the instruction before the function modification.
7、 一种为共享代码段打补丁的方法, 其特征在于, 包括:  7. A method for patching a shared code segment, the method comprising:
业务 VCPU接收主 VCPU发送的第一补丁激活消息;  The service VCPU receives the first patch activation message sent by the primary VCPU.
当所述业务 VCPU是最后一个刷新自身的快速指令緩冲区的业务 VCPU 时,根据所述第一补丁激活消息的指示,在共享内存中将原函数的第一条指令 和第二条指令修改为所述跳转到补丁函数的指令,所述原函数为需要打补丁的 函数;  When the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the instruction of the first patch activation message, the first instruction and the second instruction of the original function are modified in the shared memory. For the instruction to jump to the patch function, the original function is a function that needs to be patched;
所述业务 VCPU刷新自身的快速指令緩沖区, 并通过所述主 VCPU通知除 最后一个刷新自身的快速指令緩冲区的业务 VCPU以外的其它业务 VCPU刷新 自身的快速指令緩冲区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与 所述共享内存中指令同步更新。  The service VCPU refreshes its own fast instruction buffer, and the other VCPUs other than the service VCPU that refreshes its own fast instruction buffer are refreshed by the main VCPU to refresh its own fast instruction buffer. The instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
8、 根据权利要求 7所述的为共享代码段打补丁的方法, 其特征在于, 在共 享内存中将所述原函数的第一条指令和第二条指令修改为所述跳转到补丁函 数的指令之后, 还包括:  8. The method for patching a shared code segment according to claim 7, wherein the first instruction and the second instruction of the original function are modified into the jump to patch function in a shared memory. After the instructions, it also includes:
接收所述主 VCPU发送的第二补丁激活消息;  Receiving a second patch activation message sent by the primary VCPU;
当所述业务 VCPU是最后一个刷新自身的快速指令緩冲区的业务 VCPU 时, 根据所述第二补丁激活消息的指示, 处理完当前业务后, 在所述共享内存 中将所述原函数的第一条指令和第二条指令,恢复成对所述原则函数修改前的 指令;  When the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the indication of the second patch activation message, after processing the current service, the original function is used in the shared memory. The first instruction and the second instruction are restored to the instruction before the modification of the principle function;
所述业务 VCPU刷新自身的快速指令緩冲区, 并通过所述主 VCPU通知所 述除最后一个刷新自身的快速指令缓冲区的业务 VCPU以外的其它业务 VCPU 刷新自身的快速指令緩冲区, 以使所述业务 VCPU自身的快速指令緩冲区中指 令与所述共享内存中指令同步更新。 The service VCPU refreshes its own fast instruction buffer, and notifies the VCPU of the service VCPU other than the service VCPU that refreshes its own fast instruction buffer by the main VCPU. Refreshing its own fast instruction buffer to synchronize the instructions in the fast instruction buffer of the service VCPU itself with the instructions in the shared memory.
9、 权利要求 8所述的为共享代码段打补丁的方法, 其特征在于, 还包括: 当所述业务 VCPU不是最后一个刷新自身的快速指令緩冲区的业务 VCPU 时,根据所述第一补丁激活消息或第二补丁激活消息的指示, 处理完当前业务 后刷新自身的快速指令缓冲区, 以使各业务 VCPU自身的快速指令緩冲区中指 令与共享内存中指令同步更新;  The method for patching a shared code segment according to claim 8, further comprising: when the service VCPU is not the last service VCPU that refreshes its own fast instruction buffer, according to the first The instruction of the patch activation message or the second patch activation message refreshes its own fast instruction buffer after the current service is processed, so that the instruction in the fast instruction buffer of each service VCPU itself is updated synchronously with the instruction in the shared memory;
在执行到所述原函数的第一条指令时, 根据所述原函数的第一条指令, 进 入异常处理; 在异常处理中, 根据所述原函数的首地址, 在补丁区查找出所述 补丁函数的首地址;  When executing the first instruction to the original function, according to the first instruction of the original function, entering an exception processing; in the exception processing, searching for the content in the patch area according to the first address of the original function The first address of the patch function;
根据所述补丁函数的首地址, 从所述异常处理跳转到所述补丁函数中执 行。  According to the first address of the patch function, jump from the exception processing to execution in the patch function.
10、 一种为共享代码段打补丁的装置, 其特征在于, 包括:  10. A device for patching a shared code segment, comprising:
第一修改模块, 用于为原函数打补丁前, 在共享内存中, 将原函数的第一 条指令修改为跳转到异常处理的指令, 所述原函数为需要打补丁的共享函数; 第一中断模块, 用于在所述第一修改模块在共享内存中,将原函数的第一 条指令修改为跳转到异常处理的指令后, 向业务 VCPU发送第一中断消息, 所 述中断信息用于指示所述业务 VCPU中断当前业务, 刷新自身的快速指令緩沖 区;  a first modification module, configured to modify, in the shared memory, the first instruction of the original function to jump to an exception processing instruction before the original function is patched, where the original function is a shared function that needs to be patched; An interrupt module, configured to: after the first modification module in the shared memory, modify the first instruction of the original function to jump to the exception processing instruction, send a first interrupt message to the service VCPU, where the interrupt information is Used to instruct the service VCPU to interrupt the current service and refresh its own fast instruction buffer;
第一补丁模块, 用于在所述第一中断模块向所述业务 VPCU发送第一中断 信息后,在所述共享内存中,将所述原函数的第一条指令和第二条指令修改为 跳转到补丁函数的指令, 以使执行到所述原函数的所述业务 VCPU从所述原函 数跳转到所述补丁函数 , 所述补丁函数为替换所述原函数的函数;  a first patch module, configured to: after the first interrupt module sends the first interrupt information to the service VPCU, in the shared memory, modify the first instruction and the second instruction of the original function to Jumping to an instruction of the patch function, so that the service VCPU executing to the original function jumps from the original function to the patch function, and the patch function is a function that replaces the original function;
第二中断模块, 用于在所述第一补丁模块在所述共享内存中,将所述原函 数的第一条指令和第二条指令修改为跳转到补丁函数的指令后, 向所述业务 VPCU发送第二中断信息。  a second interrupt module, configured to: after the first patch module in the shared memory, modify the first instruction and the second instruction of the original function to jump to a patch function, The service VPCU sends a second interrupt message.
11、根据权利要求 10所述的为共享代码段打补丁的装置, 其特征在于, 还 包括:  The device for patching a shared code segment according to claim 10, further comprising:
第二修改模块, 用于在向所述业务 VCPU发送第二中断信息之后、 恢复所 述原函数的第一条指令和第二条指令前,在共享内存中将原函数的第一条指令 修改为跳转到异常处理的指令; a second modifying module, configured to: after the second interrupt information is sent to the service VCPU, before recovering the first instruction and the second instruction of the original function, the first instruction of the original function is in the shared memory Modified to jump to the exception handling instructions;
第三中断模块, 用于所述第二修改模块在共享内存中,将原函数的第一条 指令修改为跳转到异常处理的指令后, 向所述业务 VCPU发送第三中断消息, 所述第三中断信息用于指示所述业务 VCPU中断当前业务, 刷新自身的快速指 令緩冲区;  a third interrupt module, configured to: in the shared memory, modify the first instruction of the original function to jump to the instruction of the exception processing, and send a third interrupt message to the service VCPU, where The third interrupt information is used to indicate that the service VCPU interrupts the current service and refreshes its own fast instruction buffer.
第一恢复模块, 用于在所述第三中断模块向所述业务 VCPU发送第三中断 消息后, 在所述共享内存中, 将所述原函数的第一条指令和第二条指令, 恢复 成对所迷原函数修改前的指令;  a first recovery module, configured to: after the third interrupt module sends a third interrupt message to the service VCPU, restore the first instruction and the second instruction of the original function in the shared memory The instruction before the modification of the original function in pairs;
第四中断模块, 用于在所述第一恢复模块在所述共享内存中,将所述原函 数的第一条指令和第二条指令, 恢复成对所述原函数修改前的指令后, 向所述 业务 VCPU发送第四中断信息, 所述第四中断信息用于指示所述业务 VCPU, 中断当前业务立即刷新各自的快速指令緩冲区, 以使所迷业务 VCPU自身的快 速指令緩冲区中指令与所述共享内存中指令同步更新。  a fourth interrupt module, configured to: after the first recovery module restores the first instruction and the second instruction of the original function in the shared memory, to an instruction before modifying the original function, Sending a fourth interrupt information to the service VCPU, where the fourth interrupt information is used to instruct the service VCPU to interrupt the current service and immediately refresh the respective fast instruction buffers, so that the fast instruction buffer of the service VCPU itself is buffered. The instruction in the area is updated synchronously with the instruction in the shared memory.
12、 一种为共享代码段打补丁的装置, 其特征在于, 包括:  12. A device for patching a shared code segment, comprising:
第一刷新模块, 用于接收到主 VCPU发送的第一中断信息后, 根据所述第 一中断信息的指示,中断当前业务,刷新快速指令緩冲区,以使所述业务 VCPU 自身的快速指令緩冲区中指令与所述共享内存中指令同步更新,所述原函数为 需要打补丁的函数;  a first refreshing module, configured to: after receiving the first interrupt information sent by the main VCPU, interrupt the current service according to the indication of the first interrupt information, and refresh the fast instruction buffer to enable the fast instruction of the service VCPU itself The instruction in the buffer is updated synchronously with the instruction in the shared memory, and the original function is a function that needs to be patched;
第一异常处理模块,用于在所述第一刷新模块刷新快速指令緩冲区后,执 行到原函数的第一条指令时, 根据所述原函数的第一条指令, 进入异常处理, 在所述异常处理中,根据所述原函数的首地址, 在补丁区查找出补丁函数的首 地址, 所述补丁函数为替换所述原函数的函数;  a first exception processing module, configured to: after the first refresh module refreshes the fast instruction buffer, execute the first instruction to the original function, according to the first instruction of the original function, enter an exception processing, In the exception processing, according to the first address of the original function, the first address of the patch function is found in the patch area, and the patch function is a function that replaces the original function;
第一补丁函数执行模块,用于在所述第一异常处理模块查找出所述补丁函 数的首地址后,根据所述补丁函数的首地址,从所述异常处理跳转到所述补丁 函数中执行;  a first patch function execution module, configured to: after the first exception processing module finds the first address of the patch function, jump from the exception processing to the patch function according to a first address of the patch function carried out;
第二刷新模块, 用于在所述第一刷新模块根据所述第一中断信息的指示, 中断当前业务, 刷新快速指令缓沖区之后, 接收所述主 VCPU发送的第二中断 信息, 根据所述第二中断信息的指示, 中断当前业务, 刷新自身的快速指令緩 冲区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与所述共享内存中指 令同步更新。 a second refreshing module, configured to: after the first refreshing module interrupts the current service according to the indication of the first interrupt information, after receiving the fast instruction buffer, receiving the second interrupt information sent by the primary VCPU, according to the The instruction of the second interrupt information interrupts the current service, and refreshes its own fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
13、根据权利要求 12所述的为共享代码段打补丁的装置, 其特征在于, 还 包括: The device for patching a shared code segment according to claim 12, further comprising:
第三刷新模块, 用于在所述第二刷新模块刷新快速指令緩冲区后,接收到 所述主 VCPU发送的第三中断信息后, 根据所述第三中断信息的指示, 中断当 前业务, 刷新自身的快速指令緩沖区, 以使所述业务 VCPU自身的快速指令緩 冲区中指令与所述共享内存中指令同步更新;  a third refreshing module, configured to: after the second refreshing module refreshes the fast instruction buffer, after receiving the third interrupt information sent by the primary VCPU, interrupting the current service according to the indication of the third interrupt information, Refreshing its own fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory;
第二异常处理模块,用于在所述第三刷新模块刷新快速指令緩冲区后,执 行到所述原函数的第一奈指令时, 根据所述主 VCPU所述原函数的第一条指 令, 进入异常处理; 在异常处理中, 根据需要打补丁的原函数的首地址, 在补 丁区查找出补丁函数的首地址;  a second exception processing module, configured to: when the third refresh module refreshes the fast instruction buffer, execute the first instruction to the original function, according to the first instruction of the original function of the main VCPU , enter exception handling; in exception handling, according to the first address of the original function to be patched, find the first address of the patch function in the patch area;
第二补丁执行模块,用于在所述第二异常处理模块查找出所述补丁函数的 首地址后,根据所迷补丁函数的首地址,从所述异常处理跳转到所述补丁函数 中执行;  a second patch execution module, configured to: after the first exception processing module finds the first address of the patch function, jump from the exception processing to the patch function according to the first address of the patch function ;
第四刷新模块, 用于在所述第三刷新模块根据所述第三中断信息的指示, 中断当前业务, 刷新自身的快速指令緩冲区之后, 接收所述主 VCPU发送的 第四中断信息的指示, 根据所述第四中断信息的指示, 中断当前业务, 刷新自 身的快速指令緩沖区, 以使所述业务 VCPU自身的快速指令緩沖区中指令与所 述共享内存中指令同步更新。  a fourth refreshing module, configured to: after the third refreshing module interrupts the current service according to the indication of the third interrupt information, refreshing the fast instruction buffer of the third refreshing module, and receiving the fourth interrupt information sent by the main VCPU Instructing, according to the indication of the fourth interrupt information, interrupting the current service, and refreshing its own fast instruction buffer, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
14、 一种为共享代码段打补丁的装置, 其特征在于, 包括:  14. A device for patching a shared code segment, comprising:
第三修改模块, 用于为原函数打补丁前, 在共享内存中, 将原函数的第一 条指令修改为跳转到异常处理的指令, 所述原函数为需要打补丁的函数; 第一消息发送模块,用于所述第三 4 改模块在共享内存中,将原函数的第 一条指令修改为跳转到异常处理的指令后, 向各业务 VCPU发送第一补丁激活 消息, 所述第一补丁激活消息用于指示所述业务 VCPU在处理完当前业务后刷 新自身的快速指令緩冲区, 以使所述业务 VCPU自身的快速指令缓冲区中指令 与所述共享内存中指令同步更新;指示最后一个刷新自身的快速指令緩冲区的 VCPU, 在刷新自身的快速指令缓沖区之前, 在共享内存中修改所述原函数的 第一条指令和第二条指令。  a third modification module, configured to modify, in the shared memory, the first instruction of the original function to jump to an exception processing instruction before the original function is patched, where the original function is a function that needs to be patched; a message sending module, configured to: in the shared memory, modify the first instruction of the original function to jump to the instruction of the exception processing, and send a first patch activation message to each service VCPU, where The first patch activation message is used to indicate that the service VCPU refreshes its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory. The VCPU indicating the last refresh instruction buffer of its own, the first instruction and the second instruction of the original function are modified in the shared memory before refreshing its own fast instruction buffer.
15、根据权利要求 14所述的为共享代码段打补丁的装置, 其特征在于, 还 包括: 第四修改模块, 用于在所述第一消息发送模块向所述业务 VCPU发送第 -一 补丁激活消息之后, 在所述共享内存中,将所述原函数的第一条指令修改为跳 转到异常处理的指令; The device for patching a shared code segment according to claim 14, further comprising: a fourth modification module, configured to: after the first message sending module sends a first patch activation message to the service VCPU, modify the first instruction of the original function to a jump in the shared memory An instruction to the exception handling;
第二消息发送模块,用于所述第四修改模块在所述共享内存中,将所述原 函数的第一条指令修改为跳转到异常处理的指令之后, 向所述业务 VCPU发送 第二补丁激活消息, 所述第二补丁激活消息用于指示所述业务 VCPU在处理完 当前业务后刷新自身的快速指令緩沖区, 以使所述业务 VCPU自身的快速指令 緩冲区中指令与所述共享内存中指令同步更新; 指示所述业务 VCPU中最后一 个刷新自身的快速指令緩冲区的业务 VCPU, 在刷新自身的快速指令緩冲区之 前,在共享内存中将所述原函数的第一条指令和第二条指令, 恢复成对所述原 函数修改前的指令。  a second message sending module, configured to: in the shared memory, modify the first instruction of the original function to jump to an instruction of exception processing, and send a second message to the service VCPU a patch activation message, the second patch activation message is used to indicate that the service VCPU refreshes its own fast instruction buffer after processing the current service, so that the instruction in the fast instruction buffer of the service VCPU itself is The instruction in the shared memory is synchronously updated; indicating that the service VCPU of the service VCPU last refreshing its own fast instruction buffer, before refreshing its own fast instruction buffer, the first function of the original function in the shared memory The instruction and the second instruction are restored to the instruction before the modification of the original function.
16、 一种为共享代码段打补丁的装置, 其特征在于, 包括:  16. A device for patching a shared code segment, comprising:
第一接收模块, 用于业务 VCPU接收主 VCPU发送的第一补丁激活消息; 判断模块, 用于判断所述业务 VCPU是否是最后一个刷新自身的快速指令 緩冲区的业务 VCPU;  a first receiving module, configured to receive, by the service VCPU, a first patch activation message sent by the primary VCPU, and a determining module, configured to determine whether the service VCPU is the last service VCPU that refreshes its own fast instruction buffer;
第二补丁模块, 用于在所述判断模块判断出所述业务 VCPU是最后一个刷 新自身的快速指令缓冲区的业务 VCPU时, 根据所述第一补丁激活消息的指 示,在共享内存中将原函数的第一条指令和第二条指令修改为所述跳转到补丁 函数的指令, 所述原函数为需要打补丁的函数;  a second patch module, configured to: when the determining module determines that the service VCPU is the last service VCPU that refreshes its own fast instruction buffer, according to the indication of the first patch activation message, the original The first instruction and the second instruction of the function are modified into the instruction to jump to the patch function, and the original function is a function that needs to be patched;
第一刷新通知模块,用于在所述第二补丁模块在共享内存中将原函数的第 一条指令和第二条指令修改为所述跳转到补丁函数的指令后, 刷新所述业务 a first refresh notification module, configured to refresh the service after the second patch module modifies the first instruction and the second instruction of the original function into the instruction to jump to the patch function in the shared memory
VCPU的快速指令缓冲区, 并通过所述主 VCPU通知除最后一个刷新自身的快 速指令緩冲区的业务 VCPU以外的其它业务 VCPU刷新自身的快速指令緩冲 区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与所述共享内存中指令 同步更新。 a fast instruction buffer of the VCPU, and the other VCPUs other than the service VCPU that refreshes its own fast instruction buffer are notified by the main VCPU to refresh its own fast instruction buffer, so that the service VCPU itself The instructions in the fast instruction buffer are updated synchronously with the instructions in the shared memory.
17、根据权利要求 16所述的为共享代码段打补丁的装置, 其特征在于, 还 包括:  The device for patching a shared code segment according to claim 16, further comprising:
第二接收模块, 用于第一刷新通知模块刷新所述业务 VCPU的快速指令緩 冲区后, 接收所述主 VCPU发送的第二补丁激活消息;  a second receiving module, configured to: after the first refresh notification module refreshes the fast instruction buffer of the service VCPU, receive a second patch activation message sent by the primary VCPU;
笫二恢复模块, 用于在所述判断模块判断出所述业务 VCPU是最后一个刷 新自身的快速指令緩冲区的业务 VCPU时, 根据所述第二补丁激活消息的指 示,处理完当前业务后,在所述共享内存中将所述原函数的第一条指令和第二 条指令, 恢复成对所述原函数修改前的指令; a recovery module, configured to determine, in the determining module, that the service VCPU is the last brush When the service VCPU of the new fast instruction buffer is new, according to the indication of the second patch activation message, after the current service is processed, the first instruction and the second instruction of the original function are in the shared memory. An instruction to restore the instruction before the modification of the original function;
第二刷新通知模块,用于在所述第二恢复模块将在所述共享内存中将所述 原函数的第一条指令和第二条指令, 恢复成对所述原函数修改前的指令后,刷 新所述业务 VCPU的快速指令緩冲区, 并通过所述主 VCPU通知所述除最后一 个刷新自身的快速指令缓冲区的业务 VCPU以外的其它业务 VCPU刷新自身的 快速指令緩冲区, 以使所述业务 VCPU自身的快速指令緩冲区中指令与所述共 享内存中指令同步更新。  a second refresh notification module, configured to: after the second recovery module restores the first instruction and the second instruction of the original function in the shared memory, to an instruction before modifying the original function Refreshing the fast instruction buffer of the service VCPU, and notifying the service VCPU other than the service VCPU that refreshes its own fast instruction buffer by the main VCPU to refresh its fast instruction buffer, The instruction in the fast instruction buffer of the service VCPU itself is updated synchronously with the instruction in the shared memory.
18、 根据权利要求 17所述的为共享代码段打补丁的装置, 其特征在于, 还包括:  18. The apparatus for patching a shared code segment according to claim 17, further comprising:
第五刷新模块, 用于在所述判断模块判断出所述业务 VCPU不是最后一个 刷新自身的快速指令緩冲区的业务 VCPU时, 根据所述第一补丁激活消息或第 二补丁激活消息的指示, 在所述业务 VCPU处理完当前业务后, 刷新所述业务 VCPU的快速指令緩冲区, 以使各业务 VCPU自身的快速指令緩冲区中指令与 共享内存中指令同步更新;  a fifth refreshing module, configured to: when the determining module determines that the service VCPU is not the last service VCPU that refreshes its own fast instruction buffer, according to the indication of the first patch activation message or the second patch activation message After the service VCPU processes the current service, refresh the fast instruction buffer of the service VCPU, so that the instruction in the fast instruction buffer of each service VCPU itself is updated synchronously with the instruction in the shared memory;
第三异常处理模块, 用于在所述第五刷新模块刷新所述业务 VCPU的快速 指令缓沖区后,执行到原函数的第一条指令时,根据所述原函数的第一条指令, 进入异常处理; 在异常处理中, 根据所述原函数的首地址, 在补丁区查找出所 述补丁函数的首地址;  a third exception processing module, configured to: after the fifth refresh module refreshes the fast instruction buffer of the service VCPU, execute the first instruction to the original function, according to the first instruction of the original function, Entering the exception processing; in the exception processing, searching for the first address of the patch function in the patch area according to the first address of the original function;
第三补丁函数执行模块,用于在所述第三异常处理模块查找出所述补丁函 数的首地址后,根据所述补丁函数的首地址,从所述异常处理跳转到所述补丁 函数中执行。  a third patch function execution module, configured to: after the third exception processing module finds the first address of the patch function, jump from the exception processing to the patch function according to the first address of the patch function carried out.
PCT/CN2011/071991 2010-03-26 2011-03-21 Method and apparatus for patching shared code segment WO2011116672A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN2010101389324A CN101794272B (en) 2010-03-26 2010-03-26 Method and device for patching code-sharing section
CN201010138932.4 2010-03-26

Publications (1)

Publication Number Publication Date
WO2011116672A1 true WO2011116672A1 (en) 2011-09-29

Family

ID=42586976

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/071991 WO2011116672A1 (en) 2010-03-26 2011-03-21 Method and apparatus for patching shared code segment

Country Status (2)

Country Link
CN (1) CN101794272B (en)
WO (1) WO2011116672A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102508681A (en) * 2011-11-09 2012-06-20 华为数字技术有限公司 Method and system for patching without interrupting service in multi-core system
GB2519386A (en) * 2013-08-07 2015-04-22 Cambridge Silicon Radio Ltd Patching of programmable memory

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101794272B (en) * 2010-03-26 2012-07-25 成都市华为赛门铁克科技有限公司 Method and device for patching code-sharing section
CN104424037B (en) * 2013-08-29 2018-12-14 中兴通讯股份有限公司 A kind of method and device of dynamic patch function
CN110262838A (en) * 2019-06-14 2019-09-20 深圳乐信软件技术有限公司 A kind of processing method of program crashing, device, terminal and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5414848A (en) * 1993-04-01 1995-05-09 Intel Corporation Method and apparatus for sharing a common routine stored in a single virtual machine with other virtual machines operating in a preemptive muli-tasking computer system
US20030140082A1 (en) * 2002-01-23 2003-07-24 Nec Corporation Patch processing system and method
CN101482834A (en) * 2009-01-20 2009-07-15 华为技术有限公司 On-line patch activation method, communication device and system
CN101561764A (en) * 2009-05-18 2009-10-21 华为技术有限公司 Patching method and patching device under multi-core environment
CN101794272A (en) * 2010-03-26 2010-08-04 成都市华为赛门铁克科技有限公司 Method and device for patching code-sharing section

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5414848A (en) * 1993-04-01 1995-05-09 Intel Corporation Method and apparatus for sharing a common routine stored in a single virtual machine with other virtual machines operating in a preemptive muli-tasking computer system
US20030140082A1 (en) * 2002-01-23 2003-07-24 Nec Corporation Patch processing system and method
CN101482834A (en) * 2009-01-20 2009-07-15 华为技术有限公司 On-line patch activation method, communication device and system
CN101561764A (en) * 2009-05-18 2009-10-21 华为技术有限公司 Patching method and patching device under multi-core environment
CN101794272A (en) * 2010-03-26 2010-08-04 成都市华为赛门铁克科技有限公司 Method and device for patching code-sharing section

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102508681A (en) * 2011-11-09 2012-06-20 华为数字技术有限公司 Method and system for patching without interrupting service in multi-core system
GB2519386A (en) * 2013-08-07 2015-04-22 Cambridge Silicon Radio Ltd Patching of programmable memory
US10453534B2 (en) 2013-08-07 2019-10-22 Qualcomm Technologies International, Ltd. Patching of programmable memory

Also Published As

Publication number Publication date
CN101794272B (en) 2012-07-25
CN101794272A (en) 2010-08-04

Similar Documents

Publication Publication Date Title
US9489230B1 (en) Handling of virtual machine migration while performing clustering operations
JP4468426B2 (en) High availability system and execution state control method
US10628273B2 (en) Node system, server apparatus, scaling control method, and program
JP4585463B2 (en) Program for functioning virtual computer system
US9329958B2 (en) Efficient incremental checkpointing of virtual devices
US9588844B2 (en) Checkpointing systems and methods using data forwarding
US8893122B2 (en) Virtual computer system and a method of controlling a virtual computer system on movement of a virtual computer
US7467322B2 (en) Failover method in a cluster computer system
JPH09259098A (en) Decentralized memory type multiprocessor system and fault recovery method
JP2006072591A (en) Virtual computer control method
WO2011116672A1 (en) Method and apparatus for patching shared code segment
US10379931B2 (en) Computer system
WO2016033755A1 (en) Task handling apparatus and method, and electronic device
CN103885857A (en) Virtual machine fault-tolerant method and device
US20120030504A1 (en) High reliability computer system and its configuration method
JP5287974B2 (en) Arithmetic processing system, resynchronization method, and farm program
JP5436422B2 (en) High integrity and high availability computer processing module
Scales et al. The design and evaluation of a practical system for fault-tolerant virtual machines
CN116257276B (en) Virtual host machine user back-end upgrading method supporting virtualized hardware acceleration
JP2018077594A (en) Virtual machine management device, system, virtual machine movement method, and program
JP5605279B2 (en) Inter-process synchronization method
US10871908B2 (en) Storage bypass driver operation in a highly available computer system
JP4193754B2 (en) Data duplication method and program
CN112380070A (en) Virtual machine fault-tolerant system and fault-tolerant method thereof
JPH0831044B2 (en) Interrupt processing completion monitoring method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11758782

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11758782

Country of ref document: EP

Kind code of ref document: A1