Multithreaded function processing method, device and electronic device

By setting jump codes in the code segment information, the problem that API Hook technology cannot realize the normal operation of pile function calls and API interfaces under multi-threading is solved, and the normal operation of pile function calls and API interfaces in a multi-threading environment is realized.

CN114942849BActive Publication Date: 2025-03-21SUZHOU ZHITU TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210713173.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-22
Publication Date
2025-03-21
Estimated Expiration
2042-06-22

AI Technical Summary

Technical Problem

The existing API Hook technology cannot simultaneously implement the call of pile functions and the normal operation of the API interface under multiple threads, resulting in other threads being unable to enter pile functions when the API interface is restored.

Method used

By setting the first code to jump to the entry address of the pile function and the second code to jump to the target function corresponding to the application program interface in the code segment information, the multiple threads may call the application program interface based on the first entry address of the first code to cause the multiple threads to jump to the pile function, and at least one thread calls the application program interface at the second entry address of the pile function to cause the multiple threads to jump to the target function.

Benefits of technology

The calling of pile functions and the normal operation of the API interface are implemented under multiple threads, ensuring that multiple threads can call the application program interface and jump to the pile function, and jump to the target function in the pile function.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114942849B_ABST
    Figure CN114942849B_ABST
Patent Text Reader

Abstract

The present invention provides a multi-threaded function processing method, device and electronic device. Wherein, the method is applied to a terminal device, and the method comprises: obtaining code segment information of an application program interface; setting a first code that jumps to a pile function entry address and a second code that jumps to a target function corresponding to the application program interface in the code segment information; wherein the first entry address of the first code and the second entry address of the second code are different; multiple threads call the application program interface based on the first entry address so that multiple threads jump to the pile function; at least one thread calls the application program interface at the second entry address in the pile function so that multiple threads jump to the target function. In this way, multiple threads can call the application program interface to jump to the pile function respectively, and jump to the target function in the pile function, and realize the calling of the pile function and the normal operation of the API interface simultaneously under multi-threading.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of application program interface, and in particular to a multi-threaded function processing method, device and electronic device. Background Art

[0002] In some development scenarios, if developers or testers want to add some temporary functions to the Application Programming Interface (API) for debugging, such as printing logs or function names, but do not want to change the functions in the API.

[0003] In a single thread, developers or testers only need to use API Hook technology (a technology for changing the execution results of an API) to implement this function. However, in a multi-threaded scenario, there is a calling bug in the implementation of this function: if you want to call the original API again in the stub function, you need to restore the API interface when calling the original API interface, and then call the API interface. Here comes an unsolvable problem: when the API interface is restored, if other threads call the API interface, the expectation of the other threads is to enter the stub function first and then call the API. However, in this scenario, the other threads will directly call the original API and will not enter the stub function.

[0004] Therefore, the existing API Hook technology cannot realize the calling of the stub function and the normal operation of the API interface simultaneously under multi-threading. Summary of the invention

[0005] In view of this, the object of the present invention is to provide a kind of multithreaded function processing method, device and electronic device, to realize the calling of pile function and the normal operation of API interface simultaneously under multithreading.

[0006] In the first aspect, an embodiment of the present invention provides a multi-threaded function processing method, which is applied to a terminal device, and the method includes: obtaining code segment information of an application program interface; setting a first code that jumps to an entry address of a pile function and a second code that jumps to a target function corresponding to the application program interface in the code segment information; wherein the first entry address of the first code and the second entry address of the second code are different; multiple threads call the application program interface based on the first entry address so that the multiple threads jump to the pile function; at least one thread calls the application program interface at the second entry address in the pile function so that the multiple threads jump to the target function.

[0007] In a preferred embodiment of the present application, the above-mentioned code segment information comprises assembly code; the above-mentioned step of being set in the code segment information to jump to the first code of the pile function entry address and to jump to the second code of the target function corresponding to the application program interface comprises: the target position in the code segment information is set to jump to the first code of the pile function entry address; The second code of the target function corresponding to the application program interface is set in the assembly code.

[0008] In a preferred embodiment of the present application, the above-mentioned target location in the code segment information is set to the step of the first code that jumps to the pile function entry address, comprising: determining the target location in the code segment information based on the operating system information of the terminal device; The original code of the target location in the code segment information is replaced with the first code that jumps to the pile function entry address.

[0009] In a preferred embodiment of the present application, the above-mentioned original code represents the code for jumping to the target function corresponding to the application interface; the above-mentioned step of setting the second code for jumping to the target function corresponding to the application interface in the assembly code includes: saving the original code of the target position in the code segment information; and setting the original code as the second code in the assembly code.

[0010] In a preferred embodiment of the present application, the above-mentioned multiple threads call an application program interface based on the first entry address, so that the multiple threads jump to the step of the pile function, comprising: multiple threads call the application program interface respectively; multiple threads call the first code of the application program interface from the first entry address, so that the multiple threads jump to the pile function.

[0011] In the preferred embodiment of the application, the second entry address calling application program interface in the pile function of above-mentioned at least one thread is so that multiple threads jump to the step of target function, comprising: at least one thread calls second code of application program interface from the second entry address in the pile function, so that multiple threads jump to the target function.

[0012] In a preferred embodiment of the present application, the above-mentioned code segment information includes an empty function code; the above-mentioned step of setting the second code for jumping to the target function corresponding to the application interface in the code segment information includes: setting the second code for jumping to the target function corresponding to the application interface in the empty function code.

[0013] In a second aspect, an embodiment of the present invention also provides a multi-threaded function processing device, which is applied to a terminal device, and the device includes: a code segment information acquisition module, which is used to obtain the code segment information of an application program interface; a code segment information setting module, which is used to set a first code that jumps to an entry address of a pile function and a second code that jumps to a target function corresponding to the application program interface in the code segment information; wherein the first entry address of the first code and the second entry address of the second code are different; a pile function jump module, which is used for multiple threads to call the application program interface based on the first entry address so that the multiple threads jump to the pile function; and a target function jump module, which is used for at least one thread to call the application program interface at the second entry address in the pile function so that the multiple threads jump to the target function.

[0014] In a third aspect, an embodiment of the present invention further provides an electronic device, including a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the above-mentioned multi-threaded function processing method.

[0015] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned multi-threaded function processing method.

[0016] The embodiments of the present invention bring the following beneficial effects:

[0017] A kind of multithreaded function processing method, device and electronic device that the embodiment of the present invention provides, in code segment information, the first code that jumps to pile function entry address and the second code that jumps to the target function corresponding to application program interface are set, multiple threads can call application program interface based on the first entry address of the first code, so that multiple threads jump to pile function, at least one thread can also call application program interface at the second entry address in pile function, so that multiple threads jump to target function. In this mode, multiple threads can call application program interface respectively to jump to pile function, and jump to target function in pile function, realize the calling of pile function and the normal operation of API interface simultaneously under multithreading.

[0018] Other features and advantages of the present disclosure will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present disclosure.

[0019] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 A flowchart of a multi-threaded function processing method provided by an embodiment of the present invention;

[0022] Figure 2 A flowchart of another multi-threaded function processing method provided by an embodiment of the present invention;

[0023] Figure 3 A schematic diagram of code segment information of an application program interface provided by an embodiment of the present invention;

[0024] Figure 4 A schematic diagram of the structure of a multi-threaded function processing device provided by an embodiment of the present invention;

[0025] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0027] In some development scenarios, developers or testers may want to add some temporary functions to the API interface for debugging, such as printing logs or function names, but do not want to change the functions in the API interface.

[0028] At present, under single thread, R&D personnel or testers only need to use API Hook technology (a technology for changing API execution result) to realize this function. But under multithreaded scenario, there is a calling Bug in this function implementation: if you want to call the original API again in the pile function, then you need to restore the API interface when calling the original API interface, and then call the API interface. Here, an unsolvable problem has just occurred: when the API interface is restored, if there are other threads calling the API interface, the expectation realized by these other threads is to enter the pile function first and then call the API. However, these other threads will directly call the original API in this scenario, and will not enter the pile function.

[0029] Therefore, existing API Hook technology cannot realize the calling of pile function and the normal operation of API interface under multithreading simultaneously.Based on this, a kind of multithreaded function processing method, device and electronic device provided by an embodiment of the present invention are specifically related to a kind of multithreaded function packaging method based on API Hook.

[0030] To facilitate understanding of this embodiment, a multi-threaded function processing method disclosed in an embodiment of the present invention is first introduced in detail.

[0031] Embodiment 1:

[0032] The embodiment of the present invention provides a multi-threaded function processing method, which is applied to a terminal device. The terminal device of this embodiment can be a computer, a mobile phone, a tablet computer, or other device capable of human-computer interaction. Figure 1 A flowchart of a multi-threaded function processing method is shown, and the multi-threaded function processing method includes the following steps:

[0033] Step S102, obtaining code segment information of the application program interface.

[0034] An application programming interface is a set of definitions, procedures and protocols that enable mutual communication between computer software through an API interface. The code segment information of the application programming interface includes some pre-defined functions, the purpose of which is to provide applications and developers with the ability to access a set of routines based on certain software or hardware without having to access the source code or understand the details of the internal working mechanism.

[0035] Step S104, setting a first code that jumps to the stub function entry address and a second code that jumps to the target function corresponding to the application program interface in the code segment information; wherein the first entry address of the first code is different from the second entry address of the second code.

[0036] The first code and the second code can be set in the code segment information. Wherein, the first entry address of the first code is different from the second entry address of the second code, and the pile function entry address can be jumped to by the first code, and the target function corresponding to the application program interface can be jumped to by the second code.

[0037] A stub function, also known as stub code, is a code used to replace certain codes. For example, if a product function or a test function calls an unwritten function, a stub function can be written to replace the called function. Stub code is also used to achieve test isolation.

[0038] The bottom-up approach is adopted for development. The bottom-level code is developed and tested first to avoid writing stub code. The advantages of using stub functions are: reducing the workload; when testing the upper-level function, it is also an indirect test of the lower-level function; when the lower-level function is modified, the callback function can be used to confirm whether the modification causes an error in the upper-level function.

[0039] The pile function of the present embodiment is used to substitute the code that is used to jump to the target function corresponding to the application program interface in the code segment information.Wherein, the above-mentioned code that is used to jump to the target function corresponding to the application program interface can be identical with the second code, but different from the position of the second code in the code segment information.

[0040] Step S106: the multiple threads call the application program interface based on the first entry address, so that the multiple threads jump to the stub function.

[0041] The thread can call the application program interface and jump to the pile function through the first entry address of the first code, thereby realizing the function of the pile function.

[0042] Step S108: at least one thread calls an application program interface at a second entry address in the stub function, so that multiple threads jump to the target function.

[0043] In pile function, can call application program interface, jump to the target function corresponding to application program interface by the second entry address of the second code, thereby realize the function of target function.Therefore, can realize that part thread jumps to pile function in multiple threads, part thread jumps to target function, realizes the calling of pile function and the normal operation of API interface simultaneously under multithreading.

[0044] A kind of multithreaded function processing method that the embodiment of the present invention provides, in code segment information, the first code that jumps to pile function entry address and the second code that jumps to the target function corresponding to application program interface are set, multiple threads can call application program interface based on the first entry address of the first code, so that multiple threads jump to pile function, at least one thread can also call application program interface at the second entry address in pile function, so that multiple threads jump to target function. In this mode, multiple threads can call application program interface respectively to jump to pile function, and jump to target function in pile function, realize the calling of pile function and the normal operation of API interface simultaneously under multithreading.

[0045] Embodiment 2:

[0046] This embodiment provides another multi-threaded function processing method, which is implemented on the basis of the above embodiment. Figure 2 Another multi-threaded function processing method is shown in the flowchart, and the multi-threaded function processing method includes the following steps:

[0047] Step S202, obtaining code segment information of the application program interface.

[0048] The method provided in this embodiment can be applied to the Mockcpp framework, which is a mock framework for C / C++. The Mockcpp framework can specify (or simulate) the behavior of a function, verify input parameters, set output parameters, and specify the return value of a function. Figure 3 A schematic diagram of code segment information of an application program interface is shown, where the code segment information includes a first code and a second code.

[0049] Step S204, setting the first code that jumps to the stub function entry address at the target location in the code segment information.

[0050] The method provided in step S204 involves the content of API Hook. The implementation method of API Hook is to replace the code segment information of the API interface. For example, specifically, the target position in the code segment information can be determined based on the operating system information of the terminal device; the original code of the target position in the code segment information is replaced with the first code that jumps to the stub function entry address.

[0051] The operating system of terminal equipment can be X64, X86 or ARM64, and 14 bytes or 4 bytes (i.e. target location, difference is the operating system information of operating system) at the front of code segment information can be replaced with the first code that jumps to pile function entry address.

[0052] At this point, a simple API Hook has been implemented. However, if you want to call the original API interface in the stub function, you need to restore the original 14 or 4 bytes of code segment information in the stub function and then call it.

[0053] In a single-threaded environment, this implementation will not cause any problems. However, in a multi-threaded environment, there may be a situation where the thread calls the API but does not enter the stub function. In order to cope with the above scenario, the API interface cannot be repaired in the stub function and the front information of the API interface needs to be kept unchanged as the jump instruction.

[0054] Step S206, setting a second code in the assembly code for jumping to the target function corresponding to the application program interface.

[0055] The code segment information includes assembly code. In order not to affect the original API interface function implementation and to accommodate the implementation in multi-threaded scenarios, a portion of assembly code that does not affect the API function can be added at the beginning of the API interface. This portion of assembly code is added to reserve space for subsequent changes. While adding the assembly code, a second entry address can be generated, i.e., a new entry address of the API interface.

[0056] Assembly language is any low-level language used in electronic computers, microprocessors, microcontrollers or other programmable devices, also known as symbolic language. In assembly language, mnemonics are used instead of the opcodes of machine instructions, and address symbols or labels are used instead of the addresses of instructions or operands. In different devices, assembly language corresponds to different machine language instruction sets, which are converted into machine instructions through the assembly process.

[0057] Specifically, the original code at the target location in the code segment information may be saved; and the original code may be set as the second code in the assembly code.

[0058] The original code of the target position represents the code for jumping to the target function corresponding to the application program interface. Before replacing the original code of the target position with the first code, the added original code of the target position can be saved. After the first code is replaced, the pre-stored original code of the target position is copied at the assembly code.

[0059] In addition, the code segment information of this embodiment may include an empty function code, and a second code that jumps to a target function corresponding to the application program interface may be set in the empty function code.

[0060] Can create an empty function of reserved space in the code segment information, the content of the original API interface is copied into this empty function. When the subsequent pile function is called for the API interface, directly call this empty function interface. In the above-mentioned implementation of utilizing the empty function, if there is a call for other functions inside the API interface, the above-mentioned implementation of utilizing the empty function may be a call of a relative address, so the corresponding value of the relative address needs to be recalculated in the process of copying the content of the original API interface.

[0061] Step S208: the multiple threads call the application program interface based on the first entry address, so that the multiple threads jump to the stub function.

[0062] Specifically, the multiple threads call the application program interface respectively; the multiple threads call the first code of the application program interface from the first entry address, so that the multiple threads jump to the stub function.

[0063] The plurality of threads may include at least one first thread that wants to call the first code and jump to the stub function, and / or at least one second thread that wants to call the second code and jump to the target function.

[0064] The first thread and the second thread can both call the first code of the application program interface through the first entry address, so that the multiple threads jump to the stub function.

[0065] Step S210: at least one thread calls an application program interface at a second entry address in the stub function, so that multiple threads jump to the target function.

[0066] The second code can call an application program interface at a second entry address in the stub function to enable multiple threads to jump to the target function.

[0067] Therefore, in this way, the API can be called from the first entry address, and the target function corresponding to the original API interface can be called from the second entry address in the stub function, thereby realizing function development in a multi-threaded scenario.

[0068] The above method provided by the embodiment of the present invention provides a processing method for an API interface in a multi-threaded scenario, a recovery method for an API interface in a multi-threaded scenario, and a calling method for a stub function.

[0069] Specifically, in a multi-threaded scenario, a macro statement can be added to the API interface to reserve space for subsequent assembly operations. Adding a macro statement means modifying the original API content, but the newly added assembly will not change or affect the normal operation of the API interface, and also realizes the function of the technology development, that is, hooking the API interface and calling its original interface in multi-threaded scenarios.

[0070] Wherein, no matter it is simple function interface or the method that the present embodiment of class member function interface provides can realize the calling of pile function and the normal operation of API interface simultaneously under multithreading.But there is a condition for class member function, that is, there can not be the calling for class member variable inside the class member function.

[0071] For example, the existing API interface can be as follows:

[0072]

[0073] If you want to implement the above API interface normally and call the stub function once before the original interface is implemented, you need to do the following:

[0074]

[0075] First, you can write a stub function that you want to implement. The code shown here is just a print function. In addition to the print function, you can add some stub functions that you want to implement. More scenarios can be used in the test process, so this part may be printing logs or preprocessing incoming data.

[0076] It can be seen that below the print function is a function pointer call, which is different from the general pointer call in that it is modified to func1+START_INDEX, which is the new API interface. The following are the changes that need to be made to the new API interface based on the original API:

[0077]

[0078] Compared with the original API interface, we can see that the new API interface adds an ADDASM. This is a macro containing assembly language, which reserves a space of (START_INDEX) size at the beginning of the interface. If you want to jump from the original API interface to the stub function, you need to change the first 14 bytes of the API to a jump instruction. Then the instruction to read the parameters at the beginning of the function will be overwritten, and you may need to store it first and then overwrite it to the reserved assembly space. Then there will be two interfaces: one is the original API interface, which is now a jump instruction (jump to the stub function); the other is the new API interface, which is func1+START_INDEX in this example, and its interface corresponds to the original complete API.

[0079] Embodiment three:

[0080] Corresponding to the above method embodiment, the embodiment of the present invention provides a multi-threaded function processing device, which is applied to a terminal device, see Figure 4A schematic diagram of the structure of a multi-threaded function processing device is shown, and the multi-threaded function processing device includes:

[0081] A code segment information acquisition module 41 is used to acquire code segment information of an application program interface;

[0082] Code segment information is provided with module 42, is used for setting the first code that jumps to pile function entry address and the second code that jumps to target function corresponding to application program interface in code segment information; Wherein, the first entry address of the first code is different from the second entry address of the second code;

[0083] Stub function jump module 43, is used for multiple threads to call application program interface based on the first entry address, so that multiple threads jump to the stub function;

[0084] The target function jump module 44 is used for at least one thread to call the application program interface at the second entry address in the stub function, so that multiple threads jump to the target function.

[0085] A kind of multithreaded function processing device that the embodiment of the present invention provides, in code segment information, the first code that jumps to the pile function entry address and the second code that jumps to the target function corresponding to the application program interface are set, multiple threads can call the application program interface based on the first entry address of the first code, so that multiple threads jump to the pile function, at least one thread can also call the application program interface at the second entry address in the pile function, so that multiple threads jump to the target function. In this mode, multiple threads can call the application program interface respectively to jump to the pile function, and jump to the target function in the pile function, realize the calling of the pile function and the normal operation of the API interface simultaneously under multithreading.

[0086] The code segment information includes assembly code; the code segment information setting module is used to set the first code that jumps to the pile function entry address at the target position in the code segment information; and set the second code that jumps to the target function corresponding to the application program interface in the assembly code.

[0087] The code segment information setting module is used to determine the target position in the code segment information based on the operating system information of the terminal device; and replace the original code of the target position in the code segment information with the first code that jumps to the pile function entry address.

[0088] The original code represents the code for jumping to the target function corresponding to the application program interface; the code segment information setting module is used to save the original code of the target position in the code segment information; and the original code is set as the second code in the assembly code.

[0089] The pile function jump module is used for multiple threads to call the application program interface respectively; multiple threads call the first code of the application program interface from the first entry address so that the multiple threads jump to the pile function.

[0090] The target function jump module is used for at least one thread to call the second code of the application program interface from the second entry address in the stub function, so that multiple threads jump to the target function.

[0091] The code segment information includes an empty function code; the code segment information setting module is used to set a second code in the empty function code for jumping to a target function corresponding to the application program interface.

[0092] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the multi-threaded function processing device described above can refer to the corresponding process in the aforementioned embodiment of the multi-threaded function processing method, and will not be repeated here.

[0093] Embodiment 4:

[0094] The embodiment of the present invention also provides an electronic device for executing the multi-threaded function processing method; see Figure 5 A structural schematic diagram of an electronic device is shown, which includes a memory 100 and a processor 101, wherein the memory 100 is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor 101 to implement the above-mentioned multi-threaded function processing method.

[0095] Further, Figure 5 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 101 , the communication interface 103 and the memory 100 are connected via the bus 102 .

[0096] The memory 100 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0097] The processor 101 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 101. The above processor 101 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 100, and the processor 101 reads the information in the memory 100 and completes the steps of the method of the above embodiment in combination with its hardware.

[0098] An embodiment of the present invention also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned multi-threaded function processing method. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0099] The computer program product of the multi-threaded function processing method, device and electronic device provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method in the previous method embodiment. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0100] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and / or device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0101] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0102] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0103] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0104] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A multi-threaded function processing method, characterized in that: Applied to a terminal device, the method comprises: Get the code segment information of the application program interface; In the code segment information, a first code that jumps to the pile function entry address and a second code that jumps to the target function corresponding to the application program interface are set; wherein the first entry address of the first code is different from the second entry address of the second code; A plurality of threads call the application program interface based on the first entry address so that a plurality of the threads jump to the pile function; At least one described thread calls described application program interface at described second entry address in described pile function, so that multiple described threads jump to described target function; Multiple threads call the application program interface based on the first entry address, so that multiple threads jump to the step of the pile function, comprising: multiple threads call the application program interface respectively; Multiple threads call the first code of the application program interface from the first entry address, so that multiple threads jump to the pile function.

2. The method according to claim 1, characterized in that: Described code segment information comprises assembly code; The step of setting a first code that jumps to a pile function entry address and a second code that jumps to a target function corresponding to described application program interface in described code segment information comprises: The target location in the code segment information is arranged to jump to the first code of the pile function entry address; A second code for jumping to a target function corresponding to the application program interface is set in the assembly code.

3. The method according to claim 2, characterized in that The step of setting the first code that jumps to the pile function entry address at the target position in the code segment information comprises: Determine a target location in the code segment information based on the operating system information of the terminal device; The original code of the target location in the code segment information is replaced by the first code that jumps to the pile function entry address.

4. The method according to claim 3, characterized in that The original code represents the code that jumps to the target function corresponding to the application program interface; The step of setting a second code for jumping to a target function corresponding to the application program interface in the assembly code comprises: Saving the original code at the target location in the code segment information; The original code is set as a second code in the assembled code.

5. The method according to claim 1, characterized in that At least one of the threads described in the pile function calls the application program interface at the second entry address, so that a plurality of threads described in the pile function jump to the step of the target function, comprising: At least one of the threads calls the second code of the application program interface from the second entry address in the stub function, so that the multiple threads jump to the target function.

6. The method according to claim 1, characterized in that The code segment information includes an empty function code; The step of setting a second code for jumping to a target function corresponding to the application program interface in the code segment information comprises: A second code for jumping to a target function corresponding to the application program interface is set in the empty function code.

7. A multi-threaded function processing device, characterized in that: Applied to a terminal device, the device comprises: A code segment information acquisition module, used to acquire code segment information of an application program interface; A code segment information setting module is used for arranging a first code that jumps to a pile function entry address and a second code that jumps to a target function corresponding to the application program interface in the code segment information; wherein the first entry address of the first code is different from the second entry address of the second code; A pile function jump module is used for multiple threads to call the application program interface based on the first entry address, so that multiple threads jump to the pile function; Target function jump module, for at least one described thread, in described pile function, described second entry address calls described application program interface, so that multiple described threads jump to described target function; The pile function jump module is used for multiple threads to call the application program interface respectively; multiple threads call the first code of the application program interface from the first entry address so that multiple threads jump to the pile function.

8. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the multi-threaded function processing method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the multi-threaded function processing method described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Program processing methods and devices

    CN106445603A