WO2016127566A1 - Patch processing method and device - Google Patents

Patch processing method and device Download PDF

Info

Publication number
WO2016127566A1
WO2016127566A1 PCT/CN2015/083913 CN2015083913W WO2016127566A1 WO 2016127566 A1 WO2016127566 A1 WO 2016127566A1 CN 2015083913 W CN2015083913 W CN 2015083913W WO 2016127566 A1 WO2016127566 A1 WO 2016127566A1
Authority
WO
WIPO (PCT)
Prior art keywords
patch
function
patched
instruction
executed
Prior art date
Application number
PCT/CN2015/083913
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 WO2016127566A1 publication Critical patent/WO2016127566A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating

Definitions

  • the present invention relates to the field of communications, and in particular to a patch processing method and apparatus.
  • the hot patch technology is to replace the defective function with the patch function by the function replacement in the process of running the system, that is, jump to the patch function by the jump instruction at the entrance of the complement function, thereby avoiding executing the patched function.
  • the patch function is executed instead to fix the defect. Therefore, the basic problem of the hot patch mechanism can be summarized as:
  • Short jumps can be implemented with a single instruction, and the replacement of a single instruction is atomic, so this will bring great convenience to the implementation of problem 2, greatly simplifying the design of the hot patch mechanism, but short jump
  • the shortcoming is also obvious, that is, the scope of the jump is very limited, especially in large software systems, this shortcoming is more likely to be highlighted, which will result in the address that is far away from the jump can not be reached, resulting in the patch can not be hit, of course, can take special Tips to circumvent this shortcoming of short jumps.
  • the embodiment of the invention provides a patch processing method and device, so as to solve at least the problem of atomicity of the instruction modification process when the long jump instruction mode is adopted in the related art.
  • a patch processing method including: detecting whether a pointer of an instruction to be executed corresponding to each thread in a patched process points to a header of a patched function, wherein the patched process The address used to obtain the patched function and the patch function; when it is detected that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the header of the patched function, the patched function is replaced with The patch function.
  • the pointer of the instruction to be executed is a pointer stored in the program counter PC.
  • replacing the patched function with a patch function includes: modifying an instruction located in a header of the patched function to an instruction for jumping to the patch function, wherein the pointer is modified by a jump instruction
  • the latter patched function is referred to as the first patched function.
  • the method before detecting whether the pointers of the to-be-executed instructions corresponding to the respective threads in the patched process point to the header of the patched function, the method includes: receiving a patch activation request; acquiring a name and a version of the patch file according to the patch activation request; The name and version of the patch file determine that the patched process has not played the same patch corresponding to the patch file; parse the patch file, and obtain the address of the patched function according to the parsing result and the The address of the patch function.
  • the method before detecting whether the pointers of the to-be-executed instructions corresponding to the respective threads in the patched process point to the header of the patched function, the method includes: stopping the running of the respective threads; and executing a command corresponding to the specified thread in the each thread.
  • the pointer points to the head of the patched function
  • the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the header of the corresponding patched function.
  • the first patched function is replaced when the pointer of the to-be-executed instruction corresponding to the all threads meets the following conditions: the all threads
  • the pointers corresponding to the to-be-executed instructions are not directed to the header of the corresponding first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads are not pointed to in any of the patch functions, corresponding to any thread.
  • the call chain before the pointer of the instruction to be executed does not fall within the patch function.
  • replacing the first patched function includes: restoring the jump instruction in the first patched function to an instruction in a header before the patched function is replaced.
  • the method includes: receiving a patch deactivation request.
  • a patch processing apparatus including: a detecting module, configured to detect whether a pointer of an instruction to be executed corresponding to each thread in the patched process points to a header of the patched function, The patched process is used to obtain the address of the patched function and the patch function.
  • the first replacement module is configured to detect that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the patched When the header of the function is used, the patched function is replaced with the patch function.
  • the pointer of the instruction to be executed is a pointer stored in the program counter PC.
  • the first replacement module is further configured to modify an instruction located in a header of the patched function as an instruction for jumping to the patch function, where the modified instruction will be The patched function is called the first patched function.
  • the device further includes: a first receiving module, configured to receive a patch activation request; a first obtaining module, configured to acquire a name and a version of the patch file according to the patch activation request; and a determining module, configured to The name and version of the patch file determine that the patched process has not played the same patch corresponding to the patch file; the second obtaining module is configured to parse the patch file, and obtain the patch according to the parsing result.
  • the address of the function and the address of the patch function is configured to receive a patch activation request.
  • the device further includes: a first running module, configured to stop running the respective threads; and a second running module, configured to point a pointer of the instruction to be executed corresponding to the specified thread in the each thread to the When the header of the function is patched, the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the header of the corresponding patched function.
  • the device further includes: a second replacement module, configured to replace the first patched function when the pointer of the to-be-executed instruction corresponding to the all threads meets the following conditions:
  • the pointers of the to-be-executed instructions are not directed to the corresponding header of the first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads are not pointed to in any of the patch functions, and any thread corresponding to be executed
  • the call chain before the pointer of the instruction does not fall in the patch function.
  • the second replacement module is further configured to restore the jump instruction in the first patched function to an instruction in the header before the patched function is replaced.
  • the apparatus further includes: a second receiving module configured to receive a patch deactivation request.
  • the patched process is an address for obtaining the patched function and the patch function;
  • the patch function is replaced with the patch function.
  • FIG. 1 is a flowchart of a patch processing method according to an embodiment of the present invention.
  • FIG. 2 is a structural block diagram of a patch processing apparatus according to an embodiment of the present invention.
  • FIG. 3 is a structural block diagram (1) of a patch processing apparatus according to an embodiment of the present invention.
  • FIG. 4 is a structural block diagram (2) of a patch processing apparatus according to an embodiment of the present invention.
  • FIG. 5 is a structural block diagram (3) of a patch processing apparatus according to an embodiment of the present invention.
  • FIG. 6 is a structural block diagram (4) of a patch processing apparatus according to an embodiment of the present invention.
  • FIG. 7 is a flow chart of a hot patch message in accordance with an embodiment of the present invention.
  • FIG. 1 is a flowchart of a method for processing a patch according to an embodiment of the present invention. As shown in FIG. 1 , the process includes the following steps:
  • Step S102 detecting whether the pointers of the to-be-executed instructions corresponding to the respective threads in the patched process point to the header of the patched function, wherein the patched process is an address for acquiring the patched function and the patch function;
  • Step S104 when it is detected that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the header of the patched function, the patch function is replaced with a patch function.
  • the pointer to the instruction to be executed is a pointer stored in the program counter PC.
  • step S104 involves replacing the patched function with a patch function.
  • the completion will be The patch function is replaced with a patch function, where the patched function modified by the jump instruction is referred to herein as the first patched function.
  • the patch file is parsed, and the address of the patched function and the address of the patch function are obtained according to the parsing result.
  • the process of replacing the patched function with the patch function further involves a process of deactivation.
  • the first patched function is replaced when the pointer of the instruction to be executed of all the threads satisfies the following conditions:
  • the pointers of the to-be-executed instructions corresponding to all threads do not point to the header of the corresponding first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads do not point to any of the pending functions in any of the patch functions.
  • the call chain before the pointer does not fall in the patch function.
  • the first patched function is replaced.
  • the jump instruction in the first patched function is restored to the instruction in the header before the patched function is replaced.
  • the patch deactivation request is received prior to the replacement of the first patched function.
  • a patch processing device is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments, and has not been described again.
  • the term “module” may implement a combination of software and/or hardware of a predetermined function.
  • the apparatus described in the following embodiments is preferably implemented in software, hardware, or a combination of software and hardware, is also possible and contemplated.
  • the pointer of the instruction to be executed is a pointer stored in the program counter PC.
  • the first replacement module 24 is further configured to modify an instruction located in the header of the patched function as an instruction for jumping to the patch function, wherein the patched function modified by the jump instruction is called It is the first patched function.
  • FIG. 3 is a structural block diagram (1) of a patch processing apparatus according to an embodiment of the present invention.
  • the apparatus further includes: a first receiving module 32 configured to receive a patch activation request; and a first obtaining module 34 configured to Obtaining the name and version of the patch file according to the patch activation request; the determining module 36 is configured to determine that the patched process does not play the same patch corresponding to the patch file according to the name and version of the patch file; and the second obtaining module 38 Set to parse the patch file, and obtain the address of the patched function and the address of the patch function according to the parsing result.
  • FIG. 4 is a structural block diagram (2) of a patch processing apparatus according to an embodiment of the present invention.
  • the apparatus further includes: a first running module 42 configured to stop running the respective threads; and a second running module 44, When the pointer of the instruction to be executed corresponding to the specified thread in the respective threads points to the head of the patched function, the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the corresponding patched function. The head.
  • the second replacement module 52 is further configured to restore the jump instruction in the first patched function to an instruction in the header before the patched function is replaced.
  • FIG. 6 is a structural block diagram (4) of a patch processing apparatus according to an embodiment of the present invention. As shown in FIG. 6, the apparatus further includes: a second receiving module 62 configured to receive a patch deactivation request.
  • each of the above modules may be implemented by software or hardware.
  • the foregoing may be implemented by, but not limited to, the foregoing modules are all located in the same processor; or, the above modules are respectively located.
  • the first processor, the second processor, and the third processor In the first processor, the second processor, and the third processor.
  • This alternative embodiment employs a long jump instruction mode and uses a simple mechanism to guarantee the atomicity of the long jump instruction modification process.
  • this jump mode can jump to any address.
  • the user interaction process receives user patch requests, including patch activation and deactivation requests. After receiving the activation request, it searches for the corresponding patch according to the name and version of the patch file. If not, records the content of the request, that is, the patch name and version, and then distributes the request content as a message. Give the patched process, then wait for the response of the patched process until it times out. If the same patch is patched by the patch process, it will return directly.
  • the patch process After receiving the patch activation message, the patch process unpacks the patch file, verifies the patch header, extracts the patch dynamic library after verification, and then loads the patch dynamic library, locates the patch function and the address of the patched function, and prepares for patch activation. Then, the patch process will send the address of the patch function and the patch function to the patch management process, and the latter completes the final function replacement work.
  • the replacement of the patch function is to modify the first few instructions of the patch function to jump to the corresponding patch function. Since the patch process is static at the moment, there is no execution flow, so the instruction modification process will not be interrupted. Thus, the atomicity of the instruction modification process can be guaranteed. It is through this method of letting the patched process be static to achieve the atomicity of the instruction modification process.
  • the patch deactivation is to restore the original instruction of the patched function.
  • the patched function instruction will be saved for subsequent recovery.
  • the deactivation process is consistent with the activation process, requesting a user interaction process to the patched process, and then to the patch management process.
  • the criteria are more stringent and require that the PCs of all threads in the patch function be satisfied:
  • the patch can be safely uninstalled only if the above three conditions are met, otherwise a fatal error will result.
  • FIG. 7 is a hot patch message flow chart according to an embodiment of the present invention. As shown in FIG. 7, the method includes the following steps:
  • Step 1 The user interaction process receives an activation/deactivation request from the user. After receiving the request, it checks whether the request has been executed according to the existing record information. If not, the request is recorded, and then the request is packaged into a message. Push to the patched process, otherwise return directly.
  • the absolute path name of the patch /home/test.patch and the name of the patched process are sent to the user interaction process.
  • the latter searches the patched process patch list according to the patch name test.patch. Check whether there is a patch with the same name. If it is found, the patch has been played and returned directly. Otherwise, the absolute path /home/test.patch is sent to the patched process.
  • the patch process After receiving the patch activation message, the patch process first opens the absolute path name /home/test.patch of the patch file contained in the activation message.
  • the test.patch file consists of two parts: the patch description part and the patch entity.
  • the patch description part includes information such as the list of patched function names, the list of patch function names, and the number of patch functions.
  • the patch entity is a dynamic library file compiled by the patch code. The two pieces of information are extracted separately, the latter is stored separately in a new file and opened.
  • the patch code is loaded, and then the addresses of the patched function and the patch function are respectively searched, and then the patch function and the patch function are The address list is sent to the patch management process to be activated. If it is deactivated, then it is only necessary to find the patched function list and the patch dynamic library according to the received patch information, and then submit it to the patch management process to activate.
  • Step 3 After the patch management process receives the patch message, if it is an activation message, all the threads in the patch process will be stopped, and it is checked whether the command of the patch function can be replaced at this moment, that is, the PC pointer of all threads is not It falls on the head of any of the complemented functions. If it is possible, the command is modified. Otherwise, the criterion is converged, that is, the operation is continuously performed and judged until the maximum number of runs. If the criterion is converged, the command is modified, otherwise the declaration fails; If it is deactivated, the criteria are first converged, but the criteria are more stringent, as described above.
  • a storage medium is further provided, wherein the software includes the above-mentioned software, including but not limited to: an optical disk, a floppy disk, a hard disk, an erasable memory, and the like.
  • modules or steps of the embodiments of the present invention can be implemented by a general computing device, which can be concentrated on a single computing device or distributed in multiple computing devices. Further, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from The steps shown or described are performed sequentially, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof are fabricated into a single integrated circuit module. Thus, embodiments of the invention are not limited to any specific combination of hardware and software.

Landscapes

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

Abstract

A patch processing method and device. The method comprises: detecting whether all pointers of instructions to be executed corresponding to various threads in a patched process point to the head of a patched function (S102), wherein the patched process is used for acquiring the addresses of the patched function and a patch function; and when it is detected that none of the pointers of the instructions to be executed corresponding to the various threads point to the head of the patched function, replacing the patched function with the patch function (S104).By using the method and the device, the problem in the related art that the atomicity in an instruction modification procedure cannot be effectively solved when a long jump instruction mode is adopted is solved, thereby realizing the effect of ensuring the atomicity of the instruction modification procedure when a long jump instruction mode is adopted.

Description

补丁处理方法及装置Patch processing method and device 技术领域Technical field
本发明涉及通信领域,具体而言,涉及补丁处理方法及装置。The present invention relates to the field of communications, and in particular to a patch processing method and apparatus.
背景技术Background technique
热补丁技术是***在运行的过程中,通过函数替换,将有缺陷的函数替换为补丁函数,即在被补函数入口处通过跳转指令跳转到补丁函数,从而避开执行被补丁函数,转而执行补丁函数,以此达到修补缺陷的目的。所以,热补丁机制的基本问题可以归结为:The hot patch technology is to replace the defective function with the patch function by the function replacement in the process of running the system, that is, jump to the patch function by the jump instruction at the entrance of the complement function, thereby avoiding executing the patched function. The patch function is executed instead to fix the defect. Therefore, the basic problem of the hot patch mechanism can be summarized as:
1)采用什么样的跳转指令,是短跳转还是长跳转;1) What kind of jump instruction is used, whether it is a short jump or a long jump;
2)如何保证指令修改过程的原子性,即修改过程中,被修改指令不可被任何执行流执行,必须等到全部指令修改完成方可。2) How to ensure the atomicity of the instruction modification process, that is, the modified instruction cannot be executed by any execution flow during the modification process, and must wait until all the instruction modification is completed.
二者的核心是问题2)的实现,而问题2)的复杂程度取决于问题1)中跳转方式的选择。The core of both is the implementation of question 2), and the complexity of question 2) depends on the choice of the jump mode in question 1).
短跳转可以用单条指令来实现,而单条指令的替换本身就是原子的,所以这会给问题2的实现带来很大的便利性,大大简化了热补丁机制的设计,但是短跳转的缺点也是显而易见的,那就是跳转的范围很有限,尤其是在大型软件***中,这个缺点更易凸显出来,会导致跳转距离远的地址无法到达,导致补丁打不上,当然可以采取特殊的技巧来规避短跳转的这个缺点。Short jumps can be implemented with a single instruction, and the replacement of a single instruction is atomic, so this will bring great convenience to the implementation of problem 2, greatly simplifying the design of the hot patch mechanism, but short jump The shortcoming is also obvious, that is, the scope of the jump is very limited, especially in large software systems, this shortcoming is more likely to be highlighted, which will result in the address that is far away from the jump can not be reached, resulting in the patch can not be hit, of course, can take special Tips to circumvent this shortcoming of short jumps.
如果采用长跳转指令,那么理论上可以跳转到任意地址,可以从根本上解决短跳转的缺陷,但是长跳转需要多条指令来实现,而多条指令的修改过程如果不加保护,原子性就得不到保障,这是很危险的,很容易破坏代码的一致性。If a long jump instruction is used, then theoretically it is possible to jump to an arbitrary address, which can fundamentally solve the short jump defect, but a long jump requires multiple instructions to implement, and the modification process of multiple instructions is not protected. , atomicity is not guaranteed, it is very dangerous, it is easy to break the consistency of the code.
由此可见,短跳转要着力解决跳转距离的问题,而长跳转则要解决指令修改过程的原子性问题;It can be seen that the short jump should focus on solving the problem of the jump distance, while the long jump should solve the atomic problem of the instruction modification process;
目前出现的大部分热补丁技术采用的都是短跳转,然后使用各种技巧来解决跳转距离的问题。 Most of the hot patching techniques that are currently in use use short jumps and then use various techniques to solve the jump distance problem.
针对相关技术中,采用长跳转指令方式时,不能有效解决指令修改过程的原子性的问题,还未提出有效的解决方案。In the related art, when the long jump instruction mode is adopted, the atomicity of the instruction modification process cannot be effectively solved, and an effective solution has not been proposed.
发明内容Summary of the invention
本发明实施例提供了一种补丁处理方法及装置,以至少解决相关技术中采用长跳转指令方式时,不能有效解决指令修改过程的原子性的问题。The embodiment of the invention provides a patch processing method and device, so as to solve at least the problem of atomicity of the instruction modification process when the long jump instruction mode is adopted in the related art.
根据本发明实施例的一个方面,提供了一种补丁处理方法,包括:检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部,其中,所述被补丁进程为用于获取所述被补丁函数和补丁函数的地址;在检测到所述各个线程所对应待执行指令的指针均未指向所述被补丁函数的头部时,将所述被补丁函数替换为所述补丁函数。According to an aspect of the embodiments of the present invention, a patch processing method is provided, including: detecting whether a pointer of an instruction to be executed corresponding to each thread in a patched process points to a header of a patched function, wherein the patched process The address used to obtain the patched function and the patch function; when it is detected that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the header of the patched function, the patched function is replaced with The patch function.
进一步地,所述待执行指令的指针为存储于程序计数器PC中的指针。Further, the pointer of the instruction to be executed is a pointer stored in the program counter PC.
进一步地,将所述被补丁函数替换为补丁函数包括:将位于所述被补丁函数的头部中的指令修改为用于跳转至所述补丁函数的指令,其中,将经过跳转指令修改后的所述被补丁函数称之为第一被补丁函数。Further, replacing the patched function with a patch function includes: modifying an instruction located in a header of the patched function to an instruction for jumping to the patch function, wherein the pointer is modified by a jump instruction The latter patched function is referred to as the first patched function.
进一步地,检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部之前包括:接收补丁激活请求;根据所述补丁激活请求获取补丁文件的名称及版本;根据所述补丁文件的名称及版本确定所述被补丁进程未打过与所述补丁文件对应的相同的补丁;对所述补丁文件进行解析,并根据解析结果获取所述被补丁函数的地址和所述补丁函数的地址。Further, before detecting whether the pointers of the to-be-executed instructions corresponding to the respective threads in the patched process point to the header of the patched function, the method includes: receiving a patch activation request; acquiring a name and a version of the patch file according to the patch activation request; The name and version of the patch file determine that the patched process has not played the same patch corresponding to the patch file; parse the patch file, and obtain the address of the patched function according to the parsing result and the The address of the patch function.
进一步地,检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部之前包括:停止运行所述各个线程;在所述各个线程中的指定线程所对应待执行指令的指针指向所述被补丁函数的头部时,运行所述指定线程,直至所述指定线程对应的待执行指令的指针未指向对应的被补丁函数的头部。Further, before detecting whether the pointers of the to-be-executed instructions corresponding to the respective threads in the patched process point to the header of the patched function, the method includes: stopping the running of the respective threads; and executing a command corresponding to the specified thread in the each thread. When the pointer points to the head of the patched function, the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the header of the corresponding patched function.
进一步地,将所述被补丁函数替换为所述补丁函数之后包括:在所述全部线程所对应待执行指令的指针满足以下条件时,对所述第一被补丁函数进行替换:所述全部线程所对应待执行指令的指针均未指向对应的所述第一被补丁函数的头部、所述全部线程所对应待执行指令的指针均未指向在任一所述补丁函数中、任一线程所对应待执行指令的指针之前的调用链均未落在所述补丁函数中。 Further, after the patched function is replaced by the patch function, the first patched function is replaced when the pointer of the to-be-executed instruction corresponding to the all threads meets the following conditions: the all threads The pointers corresponding to the to-be-executed instructions are not directed to the header of the corresponding first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads are not pointed to in any of the patch functions, corresponding to any thread. The call chain before the pointer of the instruction to be executed does not fall within the patch function.
进一步地,对所述第一被补丁函数进行替换包括:将所述第一被补丁函数中的跳转指令恢复为未对所述被补丁函数进行替换之前头部中的指令。Further, replacing the first patched function includes: restoring the jump instruction in the first patched function to an instruction in a header before the patched function is replaced.
进一步地,对所述第一被补丁函数进行替换之前包括:接收补丁去激活请求。Further, before the replacing the first patched function, the method includes: receiving a patch deactivation request.
根据本发明实施例的另一个方面,还提供了一种补丁处理装置,包括:检测模块,设置为检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部,其中,所述被补丁进程为用于获取所述被补丁函数和补丁函数的地址;第一替换模块,设置为在检测到所述各个线程所对应待执行指令的指针均未指向所述被补丁函数的头部时,将所述被补丁函数替换为所述补丁函数。According to another aspect of the present invention, a patch processing apparatus is provided, including: a detecting module, configured to detect whether a pointer of an instruction to be executed corresponding to each thread in the patched process points to a header of the patched function, The patched process is used to obtain the address of the patched function and the patch function. The first replacement module is configured to detect that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the patched When the header of the function is used, the patched function is replaced with the patch function.
进一步地,所述待执行指令的指针为存储于程序计数器PC中的指针。Further, the pointer of the instruction to be executed is a pointer stored in the program counter PC.
进一步地,所述第一替换模块还设置为将位于所述被补丁函数的头部中的指令修改为用于跳转至所述补丁函数的指令,其中,将经过跳转指令修改后的所述被补丁函数称之为第一被补丁函数。Further, the first replacement module is further configured to modify an instruction located in a header of the patched function as an instruction for jumping to the patch function, where the modified instruction will be The patched function is called the first patched function.
进一步地,所述装置还包括:第一接收模块,设置为接收补丁激活请求;第一获取模块,设置为根据所述补丁激活请求获取补丁文件的名称及版本;确定模块,设置为根据所述补丁文件的名称及版本确定所述被补丁进程未打过与所述补丁文件对应的相同的补丁;第二获取模块,设置为对所述补丁文件进行解析,并根据解析结果获取所述被补丁函数的地址和所述补丁函数的地址。Further, the device further includes: a first receiving module, configured to receive a patch activation request; a first obtaining module, configured to acquire a name and a version of the patch file according to the patch activation request; and a determining module, configured to The name and version of the patch file determine that the patched process has not played the same patch corresponding to the patch file; the second obtaining module is configured to parse the patch file, and obtain the patch according to the parsing result. The address of the function and the address of the patch function.
进一步地,所述装置还包括:第一运行模块,设置为停止运行所述各个线程;第二运行模块,设置为在所述各个线程中的指定线程所对应待执行指令的指针指向所述被补丁函数的头部时,运行所述指定线程,直至所述指定线程对应的待执行指令的指针未指向对应的被补丁函数的头部。Further, the device further includes: a first running module, configured to stop running the respective threads; and a second running module, configured to point a pointer of the instruction to be executed corresponding to the specified thread in the each thread to the When the header of the function is patched, the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the header of the corresponding patched function.
进一步地,所述装置还包括:第二替换模块,设置为在所述全部线程所对应待执行指令的指针满足以下条件时,对所述第一被补丁函数进行替换:所述全部线程所对应待执行指令的指针均未指向对应的所述第一被补丁函数的头部、所述全部线程所对应待执行指令的指针均未指向在任一所述补丁函数中、任一线程所对应待执行指令的指针之前的调用链均未落在所述补丁函数中。Further, the device further includes: a second replacement module, configured to replace the first patched function when the pointer of the to-be-executed instruction corresponding to the all threads meets the following conditions: The pointers of the to-be-executed instructions are not directed to the corresponding header of the first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads are not pointed to in any of the patch functions, and any thread corresponding to be executed The call chain before the pointer of the instruction does not fall in the patch function.
进一步地,所述第二替换模块还设置为将所述第一被补丁函数中的跳转指令恢复为未对所述被补丁函数进行替换之前头部中的指令。Further, the second replacement module is further configured to restore the jump instruction in the first patched function to an instruction in the header before the patched function is replaced.
进一步地,所述装置还包括:第二接收模块,设置为接收补丁去激活请求。 Further, the apparatus further includes: a second receiving module configured to receive a patch deactivation request.
通过本发明实施例,采用检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部,其中,被补丁进程为用于获取该被补丁函数和补丁函数的地址;在检测到各个线程所对应待执行指令的指针均未指向该被补丁函数的头部时,将被补丁函数替换为补丁函数。解决了相关技术中采用长跳转指令方式时,不能有效解决指令修改过程的原子性的问题,进而实现了采用长跳转指令方式时,保证了指令修改过程的原子性的效果。According to the embodiment of the present invention, whether the pointer of the to-be-executed instruction corresponding to each thread in the patched process is directed to the header of the patched function, wherein the patched process is an address for obtaining the patched function and the patch function; When it is detected that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the header of the patched function, the patch function is replaced with the patch function. When the long jump instruction mode is adopted in the related art, the atomicity of the instruction modification process cannot be effectively solved, and the atomic effect of the instruction modification process is ensured when the long jump instruction mode is adopted.
附图说明DRAWINGS
此处所说明的附图用来提供对本发明实施例的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:The drawings are intended to provide a further understanding of the embodiments of the present invention, and are intended to be a part of the present invention, and the description of the present invention is not intended to limit the invention. In the drawing:
图1是根据本发明实施例的补丁处理方法的流程图;1 is a flowchart of a patch processing method according to an embodiment of the present invention;
图2是根据本发明实施例的补丁处理装置的结构框图;2 is a structural block diagram of a patch processing apparatus according to an embodiment of the present invention;
图3是根据本发明实施例的补丁处理装置的结构框图(一);3 is a structural block diagram (1) of a patch processing apparatus according to an embodiment of the present invention;
图4是根据本发明实施例的补丁处理装置的结构框图(二);4 is a structural block diagram (2) of a patch processing apparatus according to an embodiment of the present invention;
图5是根据本发明实施例的补丁处理装置的结构框图(三);FIG. 5 is a structural block diagram (3) of a patch processing apparatus according to an embodiment of the present invention; FIG.
图6是根据本发明实施例的补丁处理装置的结构框图(四);6 is a structural block diagram (4) of a patch processing apparatus according to an embodiment of the present invention;
图7是根据本发明实施例的热补丁消息流程图。7 is a flow chart of a hot patch message in accordance with an embodiment of the present invention.
具体实施方式detailed description
下文中将参考附图并结合实施例来详细说明本发明。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。The invention will be described in detail below with reference to the drawings in conjunction with the embodiments. It should be noted that the embodiments in the present application and the features in the embodiments may be combined with each other without conflict.
在本实施例中提供了一种补丁处理方法,图1是根据本发明实施例的补丁处理方法的流程图,如图1所示,该流程包括如下步骤:A method for processing a patch is provided in this embodiment. FIG. 1 is a flowchart of a method for processing a patch according to an embodiment of the present invention. As shown in FIG. 1 , the process includes the following steps:
步骤S102,检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部,其中,被补丁进程为用于获取被补丁函数和补丁函数的地址; Step S102, detecting whether the pointers of the to-be-executed instructions corresponding to the respective threads in the patched process point to the header of the patched function, wherein the patched process is an address for acquiring the patched function and the patch function;
步骤S104,在检测到该各个线程所对应待执行指令的指针均未指向该被补丁函数的头部时,将被补丁函数替换为补丁函数。Step S104, when it is detected that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the header of the patched function, the patch function is replaced with a patch function.
通过上述步骤,在确定各个线程所对应待执行指令的指针均未指向该被补丁函数的头部时,才将被补丁函数替换为补丁函数,解决了相关技术中采用长跳转指令方式时,不能有效解决指令修改过程的原子性的问题,进而实现了采用长跳转指令方式时,保证了指令修改过程的原子性的效果。Through the above steps, when it is determined that the pointers of the instructions to be executed corresponding to the respective threads do not point to the head of the patched function, the patched function is replaced with the patch function, and when the long jump instruction mode is adopted in the related art, The problem of atomicity of the instruction modification process cannot be effectively solved, and the effect of atomicity of the instruction modification process is ensured when the long jump instruction mode is adopted.
在一个可选实施例中,上述待执行指令的指针为存储于程序计数器PC中的指针。In an alternative embodiment, the pointer to the instruction to be executed is a pointer stored in the program counter PC.
上述步骤S104中涉及到将被补丁函数替换为补丁函数,在一个可选实施例中,通过将位于被补丁函数的头部中的指令修改为用于跳转至补丁函数的指令,完成将被补丁函数替换为补丁函数,其中,此处将经过跳转指令修改后的被补丁函数称之为第一被补丁函数。The above step S104 involves replacing the patched function with a patch function. In an alternative embodiment, by modifying the instruction located in the header of the patched function to an instruction for jumping to the patch function, the completion will be The patch function is replaced with a patch function, where the patched function modified by the jump instruction is referred to herein as the first patched function.
在一个可选实施例中,检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部之前,接收补丁激活请求,根据补丁激活请求获取补丁文件的名称及版本,根据补丁文件的名称及版本确定被补丁进程未打过与补丁文件对应的相同的补丁,对补丁文件进行解析,并根据解析结果获取被补丁函数的地址和补丁函数的地址。In an optional embodiment, before detecting whether the pointer of the to-be-executed instruction corresponding to each thread in the patched process points to the head of the patched function, receiving a patch activation request, and acquiring the name and version of the patch file according to the patch activation request, According to the name and version of the patch file, it is determined that the patch process has not been patched with the same patch corresponding to the patch file, the patch file is parsed, and the address of the patched function and the address of the patch function are obtained according to the parsing result.
在另一个可选实施例中,检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部之前,停止运行各个线程,在各个线程中的指定线程所对应待执行指令的指针指向被补丁函数的头部时,运行指定线程,直至该指定线程对应的待执行指令的指针未指向对应的被补丁函数的头部。从而保证了指令修改过程是不被中断的,即是具备原子性的。In another optional embodiment, before detecting whether the pointers of the to-be-executed instructions corresponding to the respective threads in the patched process point to the head of the patched function, stopping running each thread, and the specified thread in each thread is to be executed. When the pointer of the instruction points to the head of the patched function, the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the header of the corresponding patched function. This ensures that the instruction modification process is not interrupted, that is, it is atomic.
将该被补丁函数替换为该补丁函数之后还涉及到去激活的过程,在一个可选实施例中,在全部线程所对应待执行指令的指针满足以下条件时,对第一被补丁函数进行替换:全部线程所对应待执行指令的指针均未指向对应的第一被补丁函数的头部、全部线程所对应待执行指令的指针均未指向在任一补丁函数中、任一线程所对应待执行指令的指针之前的调用链均未落在补丁函数中。The process of replacing the patched function with the patch function further involves a process of deactivation. In an optional embodiment, the first patched function is replaced when the pointer of the instruction to be executed of all the threads satisfies the following conditions: The pointers of the to-be-executed instructions corresponding to all threads do not point to the header of the corresponding first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads do not point to any of the pending functions in any of the patch functions. The call chain before the pointer does not fall in the patch function.
关于上述步骤中,对第一被补丁函数进行替换,在一个可选实施例中,将第一被补丁函数中的跳转指令恢复为未对被补丁函数进行替换之前头部中的指令。With respect to the above steps, the first patched function is replaced. In an alternative embodiment, the jump instruction in the first patched function is restored to the instruction in the header before the patched function is replaced.
在一个可选实施例中,对第一被补丁函数进行替换之前,接收补丁去激活请求。 In an alternative embodiment, the patch deactivation request is received prior to the replacement of the first patched function.
在本实施例中还提供了一种补丁处理装置,该装置用于实现上述实施例及优选实施方式,已经进行过说明的不再赘述。如以下所使用的,术语“模块”可以实现预定功能的软件和/或硬件的组合。尽管以下实施例所描述的装置较佳地以软件来实现,但是硬件,或者软件和硬件的组合的实现也是可能并被构想的。In the embodiment, a patch processing device is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments, and has not been described again. As used below, the term "module" may implement a combination of software and/or hardware of a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware, or a combination of software and hardware, is also possible and contemplated.
图2是根据本发明实施例的补丁处理装置的结构框图,如图2所述,该装置包括:检测模块22,设置为检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部,其中,该被补丁进程为用于获取该被补丁函数和补丁函数的地址;第一替换模块24,设置为在检测到该各个线程所对应待执行指令的指针均未指向该被补丁函数的头部时,将该被补丁函数替换为该补丁函数。2 is a structural block diagram of a patch processing apparatus according to an embodiment of the present invention. As shown in FIG. 2, the apparatus includes: a detecting module 22 configured to detect whether pointers of instructions to be executed by respective threads in a patched process point to a header of the patch function, wherein the patched process is an address for obtaining the patched function and the patch function; and the first replacement module 24 is configured to detect that the pointers of the to-be-executed instructions corresponding to the respective threads are not pointed When the header of the function is patched, the patched function is replaced with the patch function.
进一步地,待执行指令的指针为存储于程序计数器PC中的指针。Further, the pointer of the instruction to be executed is a pointer stored in the program counter PC.
进一步地,第一替换模块24还设置为将位于该被补丁函数的头部中的指令修改为用于跳转至该补丁函数的指令,其中,将经过跳转指令修改后的被补丁函数称之为第一被补丁函数。Further, the first replacement module 24 is further configured to modify an instruction located in the header of the patched function as an instruction for jumping to the patch function, wherein the patched function modified by the jump instruction is called It is the first patched function.
图3是根据本发明实施例的补丁处理装置的结构框图(一),如图3所示,装置还包括:第一接收模块32,设置为接收补丁激活请求;第一获取模块34,设置为根据该补丁激活请求获取补丁文件的名称及版本;确定模块36,设置为根据该补丁文件的名称及版本确定该被补丁进程未打过与该补丁文件对应的相同的补丁;第二获取模块38,设置为对该补丁文件进行解析,并根据解析结果获取该被补丁函数的地址和该补丁函数的地址。FIG. 3 is a structural block diagram (1) of a patch processing apparatus according to an embodiment of the present invention. As shown in FIG. 3, the apparatus further includes: a first receiving module 32 configured to receive a patch activation request; and a first obtaining module 34 configured to Obtaining the name and version of the patch file according to the patch activation request; the determining module 36 is configured to determine that the patched process does not play the same patch corresponding to the patch file according to the name and version of the patch file; and the second obtaining module 38 Set to parse the patch file, and obtain the address of the patched function and the address of the patch function according to the parsing result.
图4是根据本发明实施例的补丁处理装置的结构框图(二),如图4所示,该装置还包括:第一运行模块42,设置为停止运行该各个线程;第二运行模块44,设置为在该各个线程中的指定线程所对应待执行指令的指针指向该被补丁函数的头部时,运行该指定线程,直至该指定线程对应的待执行指令的指针未指向对应的被补丁函数的头部。4 is a structural block diagram (2) of a patch processing apparatus according to an embodiment of the present invention. As shown in FIG. 4, the apparatus further includes: a first running module 42 configured to stop running the respective threads; and a second running module 44, When the pointer of the instruction to be executed corresponding to the specified thread in the respective threads points to the head of the patched function, the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the corresponding patched function. The head.
图5是根据本发明实施例的补丁处理装置的结构框图(三),如图5所示,该装置还包括:第二替换模块52,设置为在该全部线程所对应待执行指令的指针满足以下条件时,对该第一被补丁函数进行替换:该全部线程所对应待执行指令的指针均未指向对应的被补丁函数的头部、该全部线程所对应待执行指令的指针均未指向在任一该补丁函数中、任一线程所对应待执行指令的指针之前的调用链均未落在该补丁函数中。 FIG. 5 is a structural block diagram (3) of a patch processing apparatus according to an embodiment of the present invention. As shown in FIG. 5, the apparatus further includes: a second replacement module 52, configured to satisfy a pointer of an instruction to be executed corresponding to all threads. When the following conditions are used, the first patched function is replaced: the pointers of the instructions to be executed corresponding to all the threads do not point to the header of the corresponding patched function, and the pointers of the instructions to be executed corresponding to all the threads do not point to the incumbent In the patch function, the call chain before the pointer of the instruction to be executed by any thread does not fall in the patch function.
进一步地,第二替换模块52还设置为将该第一被补丁函数中的跳转指令恢复为未对该被补丁函数进行替换之前头部中的指令。Further, the second replacement module 52 is further configured to restore the jump instruction in the first patched function to an instruction in the header before the patched function is replaced.
图6是根据本发明实施例的补丁处理装置的结构框图(四),如图6所示,该装置还包括:第二接收模块62,设置为接收补丁去激活请求。FIG. 6 is a structural block diagram (4) of a patch processing apparatus according to an embodiment of the present invention. As shown in FIG. 6, the apparatus further includes: a second receiving module 62 configured to receive a patch deactivation request.
需要说明的是,上述各个模块是可以通过软件或硬件来实现的,对于后者,可以通过以下方式实现,但不限于此:上述各个模块均位于同一处理器中;或者,上述各个模块分别位于第一处理器、第二处理器和第三处理器…中。It should be noted that each of the above modules may be implemented by software or hardware. For the latter, the foregoing may be implemented by, but not limited to, the foregoing modules are all located in the same processor; or, the above modules are respectively located. In the first processor, the second processor, and the third processor.
针对相关技术中存在的上述问题,下面结合可选实施例进行说明,在本可选实施例中结合了上述可选实施例及其可选实施方式。For the above-mentioned problems existing in the related art, the following description will be made in conjunction with an alternative embodiment in which the above-described optional embodiments and alternative embodiments thereof are combined.
本可选实施例采用长跳转指令方式,并且使用一种简单的机制来保障长跳转指令修改过程的原子性。This alternative embodiment employs a long jump instruction mode and uses a simple mechanism to guarantee the atomicity of the long jump instruction modification process.
因为长跳转由多条指令组成,所以修改这些指令势必会牵涉到指令一致性问题,即修改指令的过程可能会被中断,导致指令修改不完整、指令序列不一致,并且随后这些被部分修改的指令被执行,这些前后不一致的指令被执行会导致致命的错误,所以指令修改过程必须是不被中断的,即原子的。本发明使用一种简单实用的机制来保证指令修改过程的原子性。Because long jumps consist of multiple instructions, modifying these instructions is bound to involve instruction consistency problems, that is, the process of modifying instructions may be interrupted, resulting in incomplete instruction modification, inconsistent instruction sequences, and subsequent partial modifications. Instructions are executed, and these inconsistent instructions are executed to cause fatal errors, so the instruction modification process must be uninterrupted, that is, atomic. The present invention uses a simple and practical mechanism to guarantee the atomicity of the instruction modification process.
确定采用长跳转方式,这种跳转方式可以跳转到任何地址。Make sure to use long jump mode, this jump mode can jump to any address.
打补丁过程由三个进程合作完成,用户交互进程、补丁管理进程、被补丁进程。The patching process is completed by three processes, a user interaction process, a patch management process, and a patched process.
用户交互进程接收用户补丁请求,包括补丁的激活、去激活请求。接收到激活请求后,根据补丁文件的名称及版本,查找对应被补丁进程是否已经打过相同的补丁,如果没有,记录本次请求内容,即补丁名称及版本,随后将请求内容以消息形式派发给被补丁进程,接着等待被补丁进程的响应,直至超时。如果被补丁进程打过相同的补丁,那么直接返回。The user interaction process receives user patch requests, including patch activation and deactivation requests. After receiving the activation request, it searches for the corresponding patch according to the name and version of the patch file. If not, records the content of the request, that is, the patch name and version, and then distributes the request content as a message. Give the patched process, then wait for the response of the patched process until it times out. If the same patch is patched by the patch process, it will return directly.
被补丁进程接收到补丁激活消息后,解开补丁文件,验证补丁头,验证无误后提取补丁动态库,然后加载补丁动态库,定位补丁函数和被补丁函数的地址,做好补丁激活的准备工作,然后被补丁进程将被补丁函数与补丁函数的地址发送给补丁管理进程,由后者完成最终的函数替换工作。 After receiving the patch activation message, the patch process unpacks the patch file, verifies the patch header, extracts the patch dynamic library after verification, and then loads the patch dynamic library, locates the patch function and the address of the patched function, and prepares for patch activation. Then, the patch process will send the address of the patch function and the patch function to the patch management process, and the latter completes the final function replacement work.
补丁管理进程收到被补丁进程发送的补丁激活消息后,停住被补丁进程内所有线程,即让被补丁进程处于完全静止的状态,然后判断被补丁进程此刻能否安全地进行函数替换,即判断被补丁进程内各个线程的程序计数器,装载即将执行的指令地址的寄存器(Program Counter,简称为PC)是否落在被补丁函数的头部,如果均没有落在任一被补丁函数的头部,那么可以进行函数替换。After receiving the patch activation message sent by the patching process, the patch management process stops all threads in the patched process, that is, the patched process is in a completely static state, and then determines whether the patched process can safely perform function replacement at this time, that is, Determine whether the program counter of each thread in the patched process loads the register (Program Counter, PC for short) of the instruction address to be executed, if it falls in the head of the patched function, and if it does not fall in the head of any of the patched functions, Then you can perform function substitution.
如果上述测试不满足条件,记录下所有不满足条件的线程,然后让这些线程运行一小段时间,目的是让各个线程的PC指针有机会离开被补丁函数的头部,运行结束后,再次判断这些线程的PC,不满足条件的接着运行,就这样不断运行不满足条件的线程,直到最大运行次数。If the above test does not meet the conditions, record all the threads that do not meet the conditions, and then let these threads run for a short period of time, in order to let the PC pointer of each thread have the opportunity to leave the head of the patched function. After the end of the run, judge these again. The thread's PC, which does not satisfy the condition, then runs the thread that does not satisfy the condition until the maximum number of runs.
到达最大运行次数前,如果已经没有线程不满足条件,即被补丁进程内所有线程已经全部满足打补丁的条件,那么接着进行各个被补丁函数的替换工作;否则,本次补丁激活请求宣告失败。Before the maximum number of runs is reached, if no thread does not satisfy the condition, that is, all threads in the patched process have all met the patching condition, then the replacement of each patched function is performed; otherwise, the patch activation request fails.
被补丁函数的替换,就是将被补丁函数的头几条指令修改成跳转至对应补丁函数的指令,由于此刻被补丁进程是静止的,没有任何执行流,所以指令修改过程不会被打断,从而可以保证指令修改过程的原子性。正是通过这种让被补丁进程静止的方法来达到指令修改过程的原子性。The replacement of the patch function is to modify the first few instructions of the patch function to jump to the corresponding patch function. Since the patch process is static at the moment, there is no execution flow, so the instruction modification process will not be interrupted. Thus, the atomicity of the instruction modification process can be guaranteed. It is through this method of letting the patched process be static to achieve the atomicity of the instruction modification process.
所有被补丁函数的指令修改完成后,启动被补丁进程内所有线程,补丁管理进程将操作结果返回给被补丁进程,被补丁进程接着将操作结果返回给用户交互进程,最终用户交互进程将结果返回给用户,本次补丁激活流程至此全部完成。After all the modified functions of the patch function are modified, all threads in the patched process are started, and the patch management process returns the operation result to the patched process, and the patched process then returns the operation result to the user interaction process, and the final user interaction process returns the result. To the user, the patch activation process is now complete.
补丁去激活就是恢复被补丁函数的原先指令,补丁激活过程中,指令修改时,会将被补丁函数的指令保存起来以便后续恢复。去激活流程与激活流程一致,请求经由用户交互进程到被补丁进程,然后到补丁管理进程。恢复被补丁函数的指令时,判据更加严格,要求被补丁函数内所有线程的PC满足:The patch deactivation is to restore the original instruction of the patched function. During the patch activation process, when the instruction is modified, the patched function instruction will be saved for subsequent recovery. The deactivation process is consistent with the activation process, requesting a user interaction process to the patched process, and then to the patch management process. When restoring the instructions of the patched function, the criteria are more stringent and require that the PCs of all threads in the patch function be satisfied:
1)不落在任一被补丁函数的头几条指令中;1) does not fall into the first few instructions of any patched function;
2)不落在当前要去激活的补丁区域中,即不落在任一补丁函数中;2) does not fall in the patch area that is currently to be activated, that is, does not fall in any patch function;
3)以当前PC为起点往后回溯调用链,要求调用链不穿过补丁区域;3) Backtracking the call chain with the current PC as the starting point, requiring the call chain not to pass through the patch area;
只有满足以上3个条件,才可以安全地卸载补丁,否则会导致致命错误。 The patch can be safely uninstalled only if the above three conditions are met, otherwise a fatal error will result.
本可选实施例提供了一个通用的软件热补丁方法,图7是根据本发明实施例的热补丁消息流程图,如图7所示,包括如下步骤:The optional embodiment provides a general software hot patch method, and FIG. 7 is a hot patch message flow chart according to an embodiment of the present invention. As shown in FIG. 7, the method includes the following steps:
步骤一,用户交互进程接收来自用户的激活/去激活请求,接收到请求后会根据已有的记录信息查看该请求是否已经执行过,如果没有,则会记录该请求,然后将请求打包成消息推送给被补丁进程,否则直接返回。Step 1: The user interaction process receives an activation/deactivation request from the user. After receiving the request, it checks whether the request has been executed according to the existing record information. If not, the request is recorded, and then the request is packaged into a message. Push to the patched process, otherwise return directly.
例如用户请求激活补丁/home/test.patch,会将补丁绝对路径名/home/test.patch及被补丁进程名发给用户交互进程,后者根据补丁名称test.patch搜索被补丁进程补丁列表,检查是否存在相同名称的补丁,如果找到,说明该补丁已经打过,直接返回,否则,将绝对路径/home/test.patch发送给被补丁进程。For example, if the user requests to activate the patch /home/test.patch, the absolute path name of the patch /home/test.patch and the name of the patched process are sent to the user interaction process. The latter searches the patched process patch list according to the patch name test.patch. Check whether there is a patch with the same name. If it is found, the patch has been played and returned directly. Otherwise, the absolute path /home/test.patch is sent to the patched process.
步骤二,被补丁进程接收到补丁消息后,如果是激活消息,就解开补丁包验证补丁的有效性,然后提取补丁包的内容生成补丁动态库,加载该动态库,根据补丁头内容定位补丁函数及被补丁函数的地址,并作记录,以防对同一个函数叠加打补丁,做好这些准备工作后,将补丁函数及被补丁函数打包成消息发送给补丁管理函数,由后者完成真正的补丁激活工作。如果是去激活消息,根据补丁版本信息获取补丁信息,然后向补丁管理进程请求去激活补丁。Step 2: After the patch process receives the patch message, if it is an activation message, unpack the patch package to verify the validity of the patch, and then extract the content of the patch package to generate a patch dynamic library, load the dynamic library, and locate the patch according to the content of the patch header. The address of the function and the patched function, and record, in order to prevent the same function from being superimposed and patched. After doing these preparations, the patch function and the patched function are packaged into a message and sent to the patch management function, and the latter completes the real The patch is activated. If the message is deactivated, the patch information is obtained according to the patch version information, and then the patch management process is requested to deactivate the patch.
收到补丁激活消息,被补丁进程首先打开包含在激活消息中的补丁文件绝对路径名/home/test.patch,test.patch文件由两部分组成:补丁说明部分、补丁实体。补丁说明部分包括被补丁函数名称列表、补丁函数名称列表、补丁函数个数等信息;补丁实体则是由补丁代码编译生成的动态库文件。这两部分信息被分别提取出来,后者单独存放到一个新的文件中并打开,至此,补丁代码加载完毕,然后分别查找被补丁函数与补丁函数的地址,接着将被补丁函数与补丁函数的地址列表发送给补丁管理进程去激活。如果是去激活的话,那么只需根据收到的补丁信息查找被补丁函数列表及补丁动态库,然后提交给补丁管理进程去去激活。After receiving the patch activation message, the patch process first opens the absolute path name /home/test.patch of the patch file contained in the activation message. The test.patch file consists of two parts: the patch description part and the patch entity. The patch description part includes information such as the list of patched function names, the list of patch function names, and the number of patch functions. The patch entity is a dynamic library file compiled by the patch code. The two pieces of information are extracted separately, the latter is stored separately in a new file and opened. At this point, the patch code is loaded, and then the addresses of the patched function and the patch function are respectively searched, and then the patch function and the patch function are The address list is sent to the patch management process to be activated. If it is deactivated, then it is only necessary to find the patched function list and the patch dynamic library according to the received patch information, and then submit it to the patch management process to activate.
步骤三,补丁管理进程收到补丁消息后,如果是激活消息,就将被补丁进程内所有的线程全部停住,检查此刻能否进行被补丁函数的指令替换,即所有线程的PC指针均不落在任一被补函数的头部,如果可以,则进行指令修改,否则,进行判据收敛,即不断进行运行、判断直至最大运行次数,若判据收敛,则进行指令修改,否则宣告失败;如果是去激活,同样首先进行判据收敛,只是判据更为严格,如上文所述。Step 3: After the patch management process receives the patch message, if it is an activation message, all the threads in the patch process will be stopped, and it is checked whether the command of the patch function can be replaced at this moment, that is, the PC pointer of all threads is not It falls on the head of any of the complemented functions. If it is possible, the command is modified. Otherwise, the criterion is converged, that is, the operation is continuously performed and judged until the maximum number of runs. If the criterion is converged, the command is modified, otherwise the declaration fails; If it is deactivated, the criteria are first converged, but the criteria are more stringent, as described above.
综上所述,通过本发明实施例解决了相关技术中采用长跳转指令方式时,不能有效解决指令修改过程的原子性的问题,进而实现了采用长跳转指令方式时,保证了指令修改过程的原子性的效果。 In summary, when the long jump instruction mode is adopted in the related art, the problem of atomicity of the instruction modification process cannot be effectively solved, and the instruction modification is ensured when the long jump instruction mode is adopted. The atomic effect of the process.
在另外一个实施例中,还提供了一种软件,该软件用于执行上述实施例及优选实施方式中描述的技术方案。In another embodiment, software is also provided for performing the technical solutions described in the above embodiments and preferred embodiments.
在另外一个实施例中,还提供了一种存储介质,该存储介质中存储有上述软件,该存储介质包括但不限于:光盘、软盘、硬盘、可擦写存储器等。In another embodiment, a storage medium is further provided, wherein the software includes the above-mentioned software, including but not limited to: an optical disk, a floppy disk, a hard disk, an erasable memory, and the like.
显然,本领域的技术人员应该明白,上述的本发明实施例的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,进一步地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明实施例不限制于任何特定的硬件和软件结合。Obviously, those skilled in the art should understand that the above modules or steps of the embodiments of the present invention can be implemented by a general computing device, which can be concentrated on a single computing device or distributed in multiple computing devices. Further, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from The steps shown or described are performed sequentially, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof are fabricated into a single integrated circuit module. Thus, embodiments of the invention are not limited to any specific combination of hardware and software.
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above description is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.
工业实用性Industrial applicability
上述的本发明实施例,应用于通信领域,解决了相关技术中采用长跳转指令方式时,不能有效解决指令修改过程的原子性的问题,进而实现了采用长跳转指令方式时,保证了指令修改过程的原子性的效果。 The foregoing embodiments of the present invention are applied to the field of communications, and solve the problem that the long jump instruction mode in the related art cannot effectively solve the atomicity of the instruction modification process, thereby realizing the use of the long jump instruction mode. The atomic effect of the instruction modification process.

Claims (16)

  1. 一种补丁处理方法,包括:A patch processing method includes:
    检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部,其中,所述被补丁进程为用于获取所述被补丁函数和补丁函数的地址;Detecting whether the pointer of the to-be-executed instruction corresponding to each thread in the patched process points to the header of the patched function, where the patched process is an address for acquiring the patched function and the patch function;
    在检测到所述各个线程所对应待执行指令的指针均未指向所述被补丁函数的头部时,将所述被补丁函数替换为所述补丁函数。When it is detected that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the header of the patched function, the patched function is replaced with the patch function.
  2. 根据权利要求1所述的方法,其中,所述待执行指令的指针为存储于程序计数器PC中的指针。The method of claim 1, wherein the pointer of the instruction to be executed is a pointer stored in the program counter PC.
  3. 根据权利要求1所述的方法,其中,将所述被补丁函数替换为补丁函数包括:The method of claim 1 wherein replacing the patched function with a patch function comprises:
    将位于所述被补丁函数的头部中的指令修改为用于跳转至所述补丁函数的指令,其中,将经过跳转指令修改后的所述被补丁函数称之为第一被补丁函数。Modifying an instruction located in the header of the patched function to an instruction for jumping to the patch function, wherein the patched function modified by the jump instruction is referred to as a first patched function .
  4. 根据权利要求1所述的方法,其中,检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部之前包括:The method according to claim 1, wherein detecting whether the pointer of the instruction to be executed corresponding to each thread in the patched process points to the header of the patched function includes:
    接收补丁激活请求;Receiving a patch activation request;
    根据所述补丁激活请求获取补丁文件的名称及版本;Obtaining the name and version of the patch file according to the patch activation request;
    根据所述补丁文件的名称及版本确定所述被补丁进程未打过与所述补丁文件对应的相同的补丁;Determining, according to the name and version of the patch file, that the patched process has not played the same patch corresponding to the patch file;
    对所述补丁文件进行解析,并根据解析结果获取所述被补丁函数的地址和所述补丁函数的地址。Parsing the patch file, and obtaining an address of the patched function and an address of the patch function according to the parsing result.
  5. 根据权利要求1所述的方法,其中,检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部之前包括:The method according to claim 1, wherein detecting whether the pointer of the instruction to be executed corresponding to each thread in the patched process points to the header of the patched function includes:
    停止运行所述各个线程;Stop running the respective threads;
    在所述各个线程中的指定线程所对应待执行指令的指针指向所述被补丁函数的头部时,运行所述指定线程,直至所述指定线程对应的待执行指令的指针未指向对应的被补丁函数的头部。 When the pointer of the instruction to be executed corresponding to the specified thread in the respective threads points to the head of the patched function, the specified thread is run until the pointer of the instruction to be executed corresponding to the specified thread does not point to the corresponding The head of the patch function.
  6. 根据权利要求3所述的方法,其中,将所述被补丁函数替换为所述补丁函数之后包括:The method of claim 3, wherein replacing the patched function with the patch function comprises:
    在全部线程所对应待执行指令的指针满足以下条件时,对所述第一被补丁函数进行替换:The first patched function is replaced when the pointer of the instruction to be executed corresponding to all the threads satisfies the following conditions:
    所述全部线程所对应待执行指令的指针均未指向对应的所述第一被补丁函数的头部、所述全部线程所对应待执行指令的指针均未指向在任一所述补丁函数中、任一线程所对应待执行指令的指针之前的调用链均未落在所述补丁函数中。The pointers of the to-be-executed instructions corresponding to all the threads do not point to the header of the corresponding first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads do not point to any of the patch functions. The call chain before the pointer corresponding to the instruction to be executed by a thread does not fall in the patch function.
  7. 根据权利要求6所述的方法,其中,对所述第一被补丁函数进行替换包括:The method of claim 6 wherein replacing the first patched function comprises:
    将所述第一被补丁函数中的跳转指令恢复为未对所述被补丁函数进行替换之前头部中的指令。The jump instruction in the first patched function is restored to an instruction in the header before the patched function is replaced.
  8. 根据权利要求6所述的方法,其中,对所述第一被补丁函数进行替换之前包括:The method of claim 6 wherein the replacing the first patched function comprises:
    接收补丁去激活请求。Receive a patch to deactivate the request.
  9. 一种补丁处理装置,包括:A patch processing device includes:
    检测模块,设置为检测被补丁进程中各个线程所对应待执行指令的指针是否均指向被补丁函数的头部,其中,所述被补丁进程为用于获取所述被补丁函数和补丁函数的地址;The detecting module is configured to detect whether the pointer of the to-be-executed instruction corresponding to each thread in the patched process points to a header of the patched function, where the patched process is an address used to obtain the patched function and the patch function. ;
    第一替换模块,设置为在检测到所述各个线程所对应待执行指令的指针均未指向所述被补丁函数的头部时,将所述被补丁函数替换为所述补丁函数。The first replacement module is configured to replace the patched function with the patch function when detecting that the pointers of the to-be-executed instructions corresponding to the respective threads do not point to the header of the patched function.
  10. 根据权利要求9所述的装置,其中,所述待执行指令的指针为存储于程序计数器PC中的指针。The apparatus of claim 9, wherein the pointer of the instruction to be executed is a pointer stored in the program counter PC.
  11. 根据权利要求9所述的装置,其中,所述第一替换模块还设置为将位于所述被补丁函数的头部中的指令修改为用于跳转至所述补丁函数的指令,其中,将经过跳转指令修改后的所述被补丁函数称之为第一被补丁函数。The apparatus of claim 9, wherein the first replacement module is further configured to modify an instruction located in a header of the patched function as an instruction to jump to the patch function, wherein The patched function modified by the jump instruction is referred to as a first patched function.
  12. 根据权利要求9所述的装置,其中,所述装置还包括:The apparatus of claim 9 wherein said apparatus further comprises:
    第一接收模块,设置为接收补丁激活请求;a first receiving module, configured to receive a patch activation request;
    第一获取模块,设置为根据所述补丁激活请求获取补丁文件的名称及版本; a first obtaining module, configured to obtain a name and a version of the patch file according to the patch activation request;
    确定模块,设置为根据所述补丁文件的名称及版本确定所述被补丁进程未打过与所述补丁文件对应的相同的补丁;a determining module, configured to determine, according to the name and version of the patch file, that the patched process has not played the same patch corresponding to the patch file;
    第二获取模块,设置为对所述补丁文件进行解析,并根据解析结果获取所述被补丁函数的地址和所述补丁函数的地址。The second obtaining module is configured to parse the patch file, and obtain an address of the patched function and an address of the patch function according to the parsing result.
  13. 根据权利要求9所述的装置,其中,所述装置还包括:The apparatus of claim 9 wherein said apparatus further comprises:
    第一运行模块,设置为停止运行所述各个线程;a first running module, configured to stop running the respective threads;
    第二运行模块,设置为在所述各个线程中的指定线程所对应待执行指令的指针指向所述被补丁函数的头部时,运行所述指定线程,直至所述指定线程对应的待执行指令的指针未指向对应的被补丁函数的头部。a second running module, configured to: when a pointer of the instruction to be executed corresponding to the specified thread in the each thread points to a header of the patched function, run the specified thread until the instruction to be executed corresponding to the specified thread The pointer does not point to the header of the corresponding patched function.
  14. 根据权利要求11所述的装置,其中,所述装置还包括:The apparatus of claim 11 wherein said apparatus further comprises:
    第二替换模块,设置为在全部线程所对应待执行指令的指针满足以下条件时,对所述第一被补丁函数进行替换:The second replacement module is configured to replace the first patched function when the pointer of the instruction to be executed corresponding to all the threads satisfies the following conditions:
    所述全部线程所对应待执行指令的指针均未指向对应的所述第一被补丁函数的头部、所述全部线程所对应待执行指令的指针均未指向在任一所述补丁函数中、任一线程所对应待执行指令的指针之前的调用链均未落在所述补丁函数中。The pointers of the to-be-executed instructions corresponding to all the threads do not point to the header of the corresponding first patched function, and the pointers of the to-be-executed instructions corresponding to all the threads do not point to any of the patch functions. The call chain before the pointer corresponding to the instruction to be executed by a thread does not fall in the patch function.
  15. 根据权利要求14所述的装置,其中,所述第二替换模块还设置为将所述第一被补丁函数中的跳转指令恢复为未对所述被补丁函数进行替换之前头部中的指令。The apparatus of claim 14, wherein the second replacement module is further configured to restore the jump instruction in the first patched function to an instruction in the header before the patched function is replaced .
  16. 根据权利要求14所述的装置,其中,所述装置还包括:The apparatus of claim 14 wherein said apparatus further comprises:
    第二接收模块,设置为接收补丁去激活请求。 The second receiving module is configured to receive a patch deactivation request.
PCT/CN2015/083913 2015-02-12 2015-07-13 Patch processing method and device WO2016127566A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510076617.6A CN105988798B (en) 2015-02-12 2015-02-12 Patch processing method and device
CN201510076617.6 2015-02-12

Publications (1)

Publication Number Publication Date
WO2016127566A1 true WO2016127566A1 (en) 2016-08-18

Family

ID=56614077

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/083913 WO2016127566A1 (en) 2015-02-12 2015-07-13 Patch processing method and device

Country Status (2)

Country Link
CN (1) CN105988798B (en)
WO (1) WO2016127566A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107870777A (en) * 2016-09-23 2018-04-03 中兴通讯股份有限公司 A kind of hot patch implementation method and device, terminal

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107341110B (en) * 2017-07-11 2020-01-07 浪潮软件集团有限公司 Tool for modifying and affecting range of software test positioning patch and implementation method
CN107357622B (en) * 2017-07-17 2020-09-22 迈普通信技术股份有限公司 Hot patch implementation method and communication equipment
CN110457151B (en) * 2019-07-10 2022-01-28 五八有限公司 Thermal restoration method and device and readable storage medium
CN112988182A (en) 2019-12-13 2021-06-18 中兴通讯股份有限公司 LINUX kernel hot patch implementation method, electronic device and computer readable medium
CN111694594B (en) * 2020-05-18 2023-03-03 成都盛芯微科技有限公司 Patch control method and system
CN111949290B (en) * 2020-07-14 2022-10-14 锐捷网络股份有限公司 Hot patch management method and device, electronic equipment and storage medium
CN118295708A (en) * 2023-01-04 2024-07-05 中兴通讯股份有限公司 Hot patch processing method and device under ARM architecture, storage medium and electronic device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101799763A (en) * 2009-02-10 2010-08-11 华为技术有限公司 Method, device and system for patching kernel on line
CN102467394A (en) * 2010-11-12 2012-05-23 中兴通讯股份有限公司 Method and system for realizing multi-core hot patching
US8468516B1 (en) * 2008-12-19 2013-06-18 Juniper Networks, Inc. Creating hot patches for embedded systems
CN103885808A (en) * 2014-04-08 2014-06-25 北京奇虎科技有限公司 Hotfix processing method and device

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6691308B1 (en) * 1999-12-30 2004-02-10 Stmicroelectronics, Inc. Method and apparatus for changing microcode to be executed in a processor
CN100445952C (en) * 2007-01-26 2008-12-24 上海华为技术有限公司 Software version update method and device in communication equipment
US20090007096A1 (en) * 2007-06-28 2009-01-01 Microsoft Corporation Secure Software Deployments
CN103744709B (en) * 2014-01-23 2017-02-15 华为技术有限公司 patch loading method and device
CN104125101B (en) * 2014-08-12 2017-10-10 烽火通信科技股份有限公司 The method that communication system network element uses the affiliated business single-deck of hot patch batch upgrade

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8468516B1 (en) * 2008-12-19 2013-06-18 Juniper Networks, Inc. Creating hot patches for embedded systems
CN101799763A (en) * 2009-02-10 2010-08-11 华为技术有限公司 Method, device and system for patching kernel on line
CN102467394A (en) * 2010-11-12 2012-05-23 中兴通讯股份有限公司 Method and system for realizing multi-core hot patching
CN103885808A (en) * 2014-04-08 2014-06-25 北京奇虎科技有限公司 Hotfix processing method and device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
LEI, ZHENYU: "Research and Implementation of Online Thermal Upgrading of Embedded Network Equipment", CHINA MASTER'S THESES FULL-TEXT DATABASE, 15 September 2014 (2014-09-15) *
SUN, SHENGFANG: "Research and Implementation of Hotfix to Embedded Linux Operating System Kernel", CHWA MASTER' S THESES FULL-TEXT DATABASE, 15 April 2011 (2011-04-15), pages 42 - 49 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107870777A (en) * 2016-09-23 2018-04-03 中兴通讯股份有限公司 A kind of hot patch implementation method and device, terminal

Also Published As

Publication number Publication date
CN105988798A (en) 2016-10-05
CN105988798B (en) 2020-07-31

Similar Documents

Publication Publication Date Title
WO2016127566A1 (en) Patch processing method and device
US10824404B2 (en) Methods and systems for uploading a program based on a target network platform
Leesatapornwongsa et al. TaxDC: A taxonomy of non-deterministic concurrency bugs in datacenter distributed systems
US7958497B1 (en) State synchronization in recording and replaying computer programs
US7673181B1 (en) Detecting race conditions in computer programs
US9292416B2 (en) Software development kit testing
US10067858B2 (en) Cloud-based software testing
US9519495B2 (en) Timed API rules for runtime verification
US20180329807A1 (en) Focus area integration test heuristics
US9684587B2 (en) Test creation with execution
US8813079B1 (en) Thread management to prevent race conditions in computer programs
CN107479980B (en) Method and equipment for detecting deadlock in application
US20140109058A1 (en) Test language interpreter
US20180173612A1 (en) Debugging method
US8276021B2 (en) Concurrency test effectiveness via mutation testing and dynamic lock elision
US10725889B2 (en) Testing multi-threaded applications
Gotovos et al. Test-driven development of concurrent programs using concuerror
US20180322029A1 (en) Method and apparatus for automatic cross-system program debugging
US20130067439A1 (en) Injecting faults into program for testing
Pina et al. Tedsuto: A general framework for testing dynamic software updates
US10387294B2 (en) Altering a test
WO2012080262A1 (en) Software error code injection
Dong et al. Concurrency-related flaky test detection in android apps
US8972784B2 (en) Method and device for testing a system comprising at least a plurality of software units that can be executed simultaneously
US9218273B2 (en) Automatic generation of a resource reconfiguring test

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: 15881727

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: 15881727

Country of ref document: EP

Kind code of ref document: A1