CN115167862A - Patch method and related equipment - Google Patents

Patch method and related equipment Download PDF

Info

Publication number
CN115167862A
CN115167862A CN202110297938.4A CN202110297938A CN115167862A CN 115167862 A CN115167862 A CN 115167862A CN 202110297938 A CN202110297938 A CN 202110297938A CN 115167862 A CN115167862 A CN 115167862A
Authority
CN
China
Prior art keywords
function
patch
file
index
called
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202110297938.4A
Other languages
Chinese (zh)
Inventor
朱金鹏
喻钢
任文杰
张毓
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202110297938.4A priority Critical patent/CN115167862A/en
Priority to PCT/CN2022/081029 priority patent/WO2022194173A1/en
Publication of CN115167862A publication Critical patent/CN115167862A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/52Binary to binary
    • 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
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • 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
    • G06F9/44568Immediately runnable code
    • 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/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution
    • 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/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects

Abstract

The embodiment of the application provides a patching method and related equipment, wherein the method comprises the following steps: in the compiling process of an original file, generating a compiling information table, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file; in the compiling process of the patch file, generating a function corresponding table according to the compiling information table, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between an original function and the patch function, and the patch function is a function in the patch file; and in the loading process of the original file, replacing the function address of the original function in the function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file. By adopting the method and the device, the function-level replacement and update of the WebAssembly application by using the patch can be realized.

Description

Patch method and related equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a patching method and related devices.
Background
At present, no patch scheme for WebAssembly application is available, and if a specific function in a WebAssembly file needs to be replaced, the whole source file needs to be recompiled to obtain a new binary format wasm file after the function is replaced, and the wasm file is loaded and operated in a WebAssembly virtual machine in a new version application form.
Disclosure of Invention
The embodiment of the application provides a patching method and related equipment, which can realize function-level replacement and updating of WebAssembly application by using patches.
In a first aspect, an embodiment of the present application provides a patching method, including: generating a compiling information table in the compiling process of an original file, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file; generating a function corresponding table according to the compiling information table in the compiling process of the patch file, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between the original function and the patch function, and the patch function is a function in the patch file; and in the loading process of the original file, replacing the function address of the original function in a function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file. In the embodiment of the application, in the process of compiling an original file in a WebAssembly binary format, a compiling information table is generated, and the compiling information table records the function index of an original function in the original file; in the process of compiling to obtain a patch file in a WebAssembly binary format, generating a function corresponding table according to a function index of an original function in a compiling information table and a function index of a patch function in the patch file, wherein the function corresponding table records a corresponding relation between the original function and the patch function; that is, the function index of the original function is obtained from the compiling information table, the function index of the patch function is obtained from the patch file, and the function index of the original function and the function index of the patch function are recorded in the function corresponding table in an associated manner, so that the function corresponding table is generated; in the process of loading the original file, a function index space is generated, the function address of the original function is recorded in the function index space, and the corresponding relation between the original function and the patch function is recorded in the function corresponding table, so that the function address of the patch function can be obtained from the patch file, and then the function address of the original function in the function index space is replaced by the function address of the patch function according to the corresponding relation between the original function and the patch function recorded in the function corresponding table; in the function index space, the function address of the original function is replaced by the function address of the patch function, and the function executed during the later function application is the patch function, so that the function-level replacement and updating of the WebAssembly application by using the patch are realized. It should be understood that the primitive functions or patch functions described in the embodiments of the present application do not refer to one function, but refer to a class of functions; for example, a primitive function refers to a general term of a function that needs to be patched, and a patch function refers to a general term of a function for patching.
In one possible implementation, the functions in the patch file are and only patch functions. In the embodiment of the application, the functions in the patch file include and only include the patch function, that is, any function in the patch file is a function beneficial to the patch, which is beneficial to making the patch file have a small volume and short time required for downloading and loading.
In a possible implementation manner, the replacing, according to the function correspondence table, the function address of the original function in the function index space with the function address of the patch function includes: judging whether the patch function exists according to the function corresponding table; if the patch function exists, acquiring a function address of the patch function from a code segment of the patch file; and replacing the function address of the original function in the function index space with the function address of the patch function. In the embodiment of the application, in the loading process of an original file, a function address of an original function is obtained from the original file and added to a function index space; when patching is needed, judging whether the original function needs to be replaced or not through a function corresponding table, when the corresponding relation between the original function and the patching function is recorded in the function corresponding table, indicating that the original function needs to be replaced by the patching function, judging whether the patching function exists or not according to the function corresponding table, if the patching function exists, acquiring a function address of the patching function from a code segment of a patching file, and replacing the function address of the original function in a function index space with the function address of the patching function; or, the function address of the original function is not added to the function index space, but the function address of the patch function is added to the function index space, so that the original function is replaced by the patch function.
In a possible implementation manner, the compiling information table further records a memory segment size of the original file; the method further comprises the following steps: in the compiling process of the patch file, acquiring the memory segment size of the original file from the compiling information table; and compiling the code segment of the patch file according to the size of the memory segment of the original file and the data offset of the patch function. In the embodiment of the present application, if the patch function relates to a memory operation, the memory operation of the code segment of the patch file needs to be corrected; in this case, the size of the memory segment of the original file is recorded in the compiling information table generated in the process of compiling the original file; in the process of obtaining the patch file through compiling, the memory segment size of the original file is obtained from the compiling information table, the memory segment size of the original file and the data offset of the patch function are used as new offsets, and the new offsets are written into the code segment of the patch file, so that the patch function can normally perform memory operation.
In a possible implementation manner, the compiling information table further records a function index of a called function, where the called function is a function called by the original function; the method further comprises the following steps: in the compiling process of the patch file, acquiring a function index of the called function from the compiling information table; and compiling the code segment of the patch file according to the function index of the called function. In the embodiment of the application, if the original function relates to calling other functions, after the original function is replaced by the patch function, the patch function also relates to calling the function originally called by the original function, and the code segment of the patch file needs to be corrected; in this case, the compiling information table further records a function index of the called function, and the called function is a function called by the original function; in the process of obtaining the patch file through compiling, the function index of the called function is obtained from the compiling information table, the function index of the called function is compiled and written into the code section of the patch file, and therefore after the original function is replaced by the patch function through a patching mode, the patch function can also call the function originally called by the original function.
In a possible implementation manner, the called function is a function directly called by the primitive function, and the code segment of the patch file includes a direct call instruction, and the direct call instruction includes a function index of the called function. In the embodiment of the application, if the called function is a function directly called by the original function, the called function is also a function directly called by the patch function after the original function is replaced by the patch function; in this case, the compiling information table also records the function index of the called function; therefore, the function index of the called function is obtained from the compiling information table, and after the function index of the called function is written into the direct calling instruction of the code segment of the patch file, the direct calling of the called function by the patch function can be realized, so that after the original function is replaced by the patch function in a patch mode, the patch function can also directly call the function originally called by the original function.
In a possible implementation manner, the compiling information table further records a function signature index of the called function and an element segment size of the original file; the called function is a function indirectly called by the original function; the code segment for compiling the patch file according to the function index of the called function comprises: acquiring a function signature index of the called function from the compiling information table; compiling the element segment of the patch file according to the function index of the called function to obtain the element index of the called function; compiling the code segment of the patch file according to the element segment size of the original file and the element index of the called function, wherein the code segment of the patch file comprises an indirect call instruction, and the indirect call instruction comprises a function signature index of the called function. In the embodiment of the application, if the called function is a function indirectly called by the original function, the called function is also a function indirectly called by the patch function after the original function is replaced by the patch function; in this case, the compiling information table further records a function index of the called function, a function signature index of the called function, and an element segment size of the original file; acquiring a function index of a called function from the compiling information table, and writing the function index of the called function into an element segment of the patch file to obtain the element index of the called function; acquiring the size of an element segment of an original file from a compiling information table, and writing the size of the element segment of the original file and an element index of a called function into a code segment of a patch file; the function signature index of the called function is obtained from the compiling information table, and the function signature index of the called function is written into the indirect calling instruction in the code segment of the patch file, so that the indirect calling of the called function by the patch function can be realized, and therefore, after the original function is replaced by the patch function in a patch mode, the patch function can also indirectly call the original function indirectly called by the original function.
In one possible implementation, the method further includes: acquiring the element index of the called function from the patch file in the loading process of the original file; and adding the element index of the called function into a table index space, wherein the table index space is generated in the loading process of the original file. In the embodiment of the application, for indirect calling, since it is specifically required to call which function is unknown in the compiling period, the function can be known only in the running process, and the called function is not directly positioned through the function index of the called function in the function index space, but is indirectly positioned through the table index space, and the table index space is generated by loading the original file; therefore, in the loading process of the original file, the element index of the called function needs to be acquired from the patch file, and the element index of the called function is added to the table index space; therefore, when the patch function runs, the element index of the called function can be obtained from the table index space, and the called function is further positioned, so that the called function is indirectly called.
In one possible implementation, the called function is a virtual machine import function; before the obtaining the function index of the called function from the compiling information table, the method further comprises: generating a function index of the called function; adding a function index of the called function to the compilation information table. In this embodiment of the present application, the called function is a virtual machine import function, and a function index of the called function is not recorded in a compiling information table generated in the process of compiling the original file, so that a function index of the called function needs to be generated, and the function index of the called function is added to the compiling information table, which is favorable for implementing a patch function to call the called function.
In one possible implementation, the method further includes: and in the loading process of the original file, adding the called function to the function index space through the import section of the original file. In the embodiment of the application, the called function is a virtual machine import function, so that the called function does not exist in a function index space generated in the loading process of the original file, and therefore the called function needs to be added to the function index space through an import section of the original file, so that the called function exists in the function index space; thereby facilitating the implementation of the patch function to call the called function.
In a second aspect, the present application provides a patch device, and beneficial effects may be seen in the description of the first aspect, which is not described herein again. The apparatus comprises a processing unit to: generating a compiling information table in the compiling process of an original file, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file; generating a function corresponding table according to the compiling information table in the compiling process of the patch file, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between the original function and the patch function, and the patch function is a function in the patch file; and in the loading process of the original file, replacing the function address of the original function in a function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file.
In one possible implementation, the functions in the patch file are and only patch functions.
In a possible implementation manner, the processing unit is specifically configured to: judging whether the patch function exists according to the function corresponding table; if the patch function exists, acquiring a function address of the patch function from a code segment of the patch file; and replacing the function address of the original function in the function index space with the function address of the patch function.
In a possible implementation manner, the compiling information table further records a memory segment size of the original file; the processing unit is further to: in the compiling process of the patch file, acquiring the memory segment size of the original file from the compiling information table; and compiling the code segment of the patch file according to the size of the memory segment of the original file and the data offset of the patch function.
In a possible implementation manner, the compiling information table further records a function index of a called function, where the called function is a function called by the primitive function; the processing unit is further to: acquiring a function index of the called function from the compiling information table in the compiling process of the patch file; and compiling the code segment of the patch file according to the function index of the called function.
In one possible implementation, the called function is a function directly called by the original function, and the code segment of the patch file includes a direct call instruction, where the direct call instruction includes a function index of the called function.
In a possible implementation manner, the compiling information table further records a function signature index of the called function and an element segment size of the original file; the called function is a function indirectly called by the original function; the processing unit is specifically configured to: acquiring a function signature index of the called function from the compiling information table; compiling the element segment of the patch file according to the function index of the called function to obtain the element index of the called function; compiling the code segment of the patch file according to the element segment size of the original file and the element index of the called function, wherein the code segment of the patch file comprises an indirect call instruction, and the indirect call instruction comprises a function signature index of the called function.
In one possible implementation, the processing unit is further configured to: in the loading process of the original file, acquiring an element index of the called function from the patch file; and adding the element index of the called function into a table index space, wherein the table index space is generated in the loading process of the original file.
In one possible implementation, the called function is a virtual machine import function; the processing unit is further to: before the obtaining of the function index of the called function from the compiling information table; generating a function index of the called function; adding a function index of the called function to the compilation information table.
In one possible implementation, the processing unit is further configured to: and in the loading process of the original file, adding the called function to the function index space through the import section of the original file.
In a third aspect, an embodiment of the present application provides a patch device, including a processor, a memory, a communication interface, and one or more programs, the one or more programs being stored in the memory and configured to be executed by the processor, the programs including instructions for performing the steps in the method according to any one of the first aspect.
In a fourth aspect, an embodiment of the present application provides a chip, including: a processor for calling and running a computer program from a memory so that a device on which the chip is installed performs the method according to any of the first aspects.
In a fifth aspect, the present application provides a computer-readable storage medium storing a computer program for electronic data exchange, wherein the computer program causes a computer to execute the method according to any one of the above first aspects.
In a sixth aspect, the present application provides a computer program, which enables a computer to execute the method according to any one of the above first aspects.
Drawings
Fig. 1 is a schematic diagram of a main segment structure and a structure after loading and parsing of a WebAssembly file provided in an embodiment of the present application.
Fig. 2 is a schematic diagram of a WebAssembly function calling manner provided in an embodiment of the present application.
Fig. 3 is a schematic flowchart of a patching method according to an embodiment of the present application.
Fig. 4 is a schematic view of a loading flow of each segment of WebAssembly provided in an embodiment of the present application.
Fig. 5 is a schematic diagram of an original loading flow of function segments of WebAssembly provided in an embodiment of the present application.
Fig. 6 is a schematic diagram of a modified loading flow of function segments of WebAssembly according to an embodiment of the present application.
Fig. 7 is a schematic diagram of an original compiling flow of a code segment of WebAssembly when a presence function is directly called, according to an embodiment of the present application.
Fig. 8 is a flowchart illustrating a modified compiling process of a code segment of a WebAssembly when a presence function is directly called according to an embodiment of the present application.
Fig. 9 is a schematic diagram of an original compiling flow of a code segment of WebAssembly when a function indirect call exists, according to an embodiment of the present application.
Fig. 10 is a schematic diagram of a modified compiling flow of a code segment of WebAssembly when a presence function is indirectly called according to an embodiment of the present application.
Fig. 11 is a schematic diagram of a WebAssembly compiling process provided in an embodiment of the present application.
Fig. 12 is a schematic diagram of a WebAssembly patch making process according to an embodiment of the present application.
Fig. 13 is a schematic diagram of a function index space modification process according to an embodiment of the present application.
Fig. 14 is a schematic diagram of another WebAssembly patch making process provided in an embodiment of the present application.
Fig. 15 is a schematic diagram of another WebAssembly compiling process provided in an embodiment of the present application.
Fig. 16 is a schematic diagram of a process for making yet another WebAssembly patch according to an embodiment of the present application.
Fig. 17 is a schematic diagram of a table index space modification process according to an embodiment of the present application.
Fig. 18 is a schematic structural diagram of a patch device according to an embodiment of the present application.
Fig. 19 is a schematic structural diagram of a patch device according to an embodiment of the present application.
Detailed Description
In order to make the technical solutions of the present application better understood, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "including" and "having," and any variations thereof, in the description and claims of this application and the drawings described above, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described in this specification can be combined with other embodiments.
First, abbreviations and term definitions that may be referred to in the present application are provided to facilitate understanding by those skilled in the art, as shown in table 1.
TABLE 1 abbreviations and terminology Definitions Table
English abbreviation Complete English expression/English standard expression Chinese expression/Chinese term
wasm WebAssembly Novel binary format
i32 i32 WebAssembly data type: 32 bit integer number
call call WebAssembly instruction: direct call
call_indirect call_indirect WebAssembly instruction: indirect invocation
i32.store i32.store WebAssembly instruction: linear memory with memory
Next, the related art knowledge to which the embodiments of the present application relate is described herein. As described below:
WebAssembly, an underlying code execution specification designed and pushed by several browser vendors like Google, apple, microsoft, etc., in recent years, is designed as a portable, secure, low-size, efficient binary format. The WebAssembly can generate a wasm file in a binary format by compiling C/C + + codes and can run in a virtual machine conforming to the WebAssembly specification. The sandbox functionality of WebAssembly enables the wsm file, when loaded into the runtime engine, to actually run in its private sandbox, without the programs in the sandbox having access to the address space outside of the sandbox. The WebAssembly operating code is simplified in design, not only can the high compiling speed be achieved, but also the high running speed can be obtained. The characteristics of the WebAssembly, such as the capability of safely running third-party codes, ultra-light weight, high performance and the like, have great value on mobile equipment, internet of things equipment, small intelligent appliances and trusted running environments.
When embedded device products need to provide a browser-like approach to loading third party modules, using WebAssembly as the media format is a very attractive solution. The developer can publish its own algorithm in the manner of WebAssembly application. The embedded device can load and use the application in different architectures, different platforms and different environments by integrating the WebAssembly virtual machine.
1) WebAssembly binary format
The WebAssembly top layer structure is a module, each WebAssembly binary file corresponds to one module, the module body is composed of a plurality of segments, each segment is identified by a unique segment number, and the specific structure is shown in figure 1.
Here, since the function refers to information such as an index of the function, a type of the function, and a function code, the function is collectively represented by a function section, a type section, and a code section.
Type section: the function signature type is stored, and the function signature type comprises parameters and return values of the function.
A code segment: storing local variable information and execution code information of the function.
Function section: the index of the function signature of each function in the type segment is stored in sequence.
An introduction section: and the method supports the import of external functions for the module to call, and the imported functions consist of function names and function signatures.
Table segment and element segment: function references may be saved and the function pointer function may be implemented via the table segment and the element segment.
A memory segment: the linear memory is used for storing dynamic data of program operation.
And (3) data segment: and storing static data of the initialization memory.
2) WebAssembly virtual machine
The WebAssembly code (i.e., webAssembly file) runs on a virtual machine supporting the WebAssembly specification, and the WebAssembly virtual machine executes the WebAssembly file by parsing and loading the WebAssembly binary format.
The structure related to the function generated by the WebAssembly virtual machine in the process of analyzing and loading the WebAssembly file is shown in fig. 1, and includes:
function index space: the function index comprises all function information including function signatures, function addresses and the like; function type is identified by function initial address identification function and function signature identification function type, and the compiler records wasm compilation information and records the wasm information in a wasm file. The function address is a Webassembly virtual address, and at the time of compiling the function, the compiler specifies the function.
Table index space: and saving function references, wherein the function references are used for indirect calling of functions and are analyzed by the table segments and the element segments.
Linear memory index space: and the memory structure is used for storing dynamic data of program operation and is analyzed by the memory section and the data section.
3) WebAssembly function call
There are two ways to call functions in WebAssembly, as shown in fig. 2, including:
direct calling: using a call instruction, wherein the call instruction firstly obtains a function index (func _ idx), and then obtains a function address through the function index to call a function; where the function index is specified by the immediate parameter of the instruction.
Indirect calling: the method comprises the steps of using a call _ index instruction and a table index space to cooperate, wherein the call _ index instruction firstly obtains a function signature index (type-idx), the function signature index is placed in an immediate number, then a (table) element index is obtained in a stack, then a function index is obtained through the element index, and a function address calling function is obtained through the function index under the condition that the function signatures are matched through dynamically checking the function signatures. The wasm specification definition module can only define one table at most, and the element type must be a function reference (coded as 0x 70). In addition to element types, table types also require a limit specifying the number of elements, where a lower limit must be specified and an upper limit is optional. Wherein, the table index is pointed to in the table segment, and the function reference (function initial address) of indirect call is taken through the index value. Where the immediate is the index and the finger obtained at the table segment index is the function reference (function first address) of the indirect call.
Again, to facilitate understanding of the embodiments of the present application, the technical problems specifically addressed by the present application are further analyzed and presented. As described below:
at present, a patch scheme realized for WebAssembly application does not exist, and if a specific function in a WebAssembly file needs to be replaced, the whole source file needs to be recompiled to obtain a new binary format wasm file after the function is replaced, and the wasm file is loaded and operated in a WebAssembly virtual machine in a new version application form. However, the way to regenerate the WebAssembly binary file has the following disadvantages:
1) Therefore, the whole application file has the advantages of more data, larger volume, longer time for downloading, replacing and loading, and incapability of realizing light weight and quick updating.
2) In the case that the WebAssembly application needs to update local codes frequently without wanting to affect the application version, if a new version of the wasm file is regenerated each time, the application version number is also continuously increased, resulting in version redundancy.
In view of the problems existing in the analysis, the application provides a patch compiling and loading method for WebAssembly, a patch file is manufactured in a WebAssembly binary format, and function-level replacement and updating of WebAssembly application by using a patch are realized. The innovation points of the application include: the method aims at the WebAssembly format to make and load the patch, and mainly comprises the following two aspects:
1) Patch creation
And (3) compiling: the method comprises the steps of compiling the wasm file into a WebAssembly binary format by using an application developed by C/C + +, recording compilation information in the compiling process, wherein the compilation information comprises a function name, a corresponding relation of a function index and the like, and generating and exporting a compilation information table which comprises a function index table and the like.
Patch making stage: compiling the WebAssembly patch file according to the compiling information table derived by the WebAssembly application, and meanwhile, correcting the code segment during compiling the patch file. During the process of compiling the patch file, the production of the compiled patch file is referred, and the correction of the code segment refers to the replacement of the original function and refers to the reference of the patch function in the patch file.
2) Patch loading
A loading stage: and replacing the function address in the function index space during loading, and replacing the original function address with the patch function address. The function address refers to a function code block head address, and is also referred to as a function code address, and a function code block head address. If the patch function involves other function calls, the table index space needs to be modified.
The method is applied to scenes such as WebAssembly application upgrading updating or application defect repairing. Due to the fact that the patch file is small in size and short in time required by downloading and loading, the WebAssembly application upgrading and updating time or the application defect repairing time is shortened.
Referring to fig. 3, fig. 3 is a schematic flowchart of a patching method according to an embodiment of the present application, where the method includes, but is not limited to, the following steps:
301. in the compiling process of an original file, generating a compiling information table, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file.
302. And in the compiling process of the patch file, generating a function corresponding table according to the compiling information table, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between the original function and the patch function, and the patch function is a function in the patch file.
303. And in the loading process of the original file, replacing the function address of the original function in a function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file.
The compiling information table comprises a function index table, and function indexes of all functions in the original file are recorded in the function index table; the function correspondence table records the correspondence between all original functions to be replaced and the corresponding patch functions.
It should be understood that the original files and patch files in the WebAssembly binary format can be obtained by writing C/C + + source codes and then compiling into wasm files. In the compiling process of the original file, the original file is compiled into the original file in the WebAssembly binary format from files in other formats; in the process of compiling the patch file, the patch file is compiled from files in other formats into a patch file in a WebAssembly binary format.
Illustratively, the generating a function correspondence table according to the compiling information table includes: acquiring a function index of the primitive function from the compiling information table; and generating the function corresponding table according to the function index of the original function and the function index of the patch function. The function correspondence table may record an index of the original function and a function index of the patch function, which are recorded in association with each other in the function correspondence table. For example, in the process of compiling the patch file, the function index of the original function is acquired from the compiling information table, the function index of the patch function is acquired from the patch file, and the function index of the original function and the function index of the patch function are recorded in the function correspondence table in an associated manner, so that the function correspondence table is generated.
It should be noted that, the primitive functions or patch functions described in the embodiments of the present application do not refer to one function, but refer to a class of functions, which may be multiple; for example, the original function refers to a general name of a function that needs to be patched, and there may be multiple functions that need to be replaced in an original file, and these multiple functions that need to be replaced are also referred to as original functions; the patch function refers to a general term of a function for a patch, and a plurality of functions for replacing an original function in an original file may exist in a patch file, and these functions for replacing an original function in an original file are collectively referred to as a patch function.
In the embodiment of the application, in the process of compiling to obtain the original file in the WebAssembly binary format, a compiling information table is generated, and the compiling information table records the function index of the original function in the original file; in the process of compiling to obtain a patch file in a WebAssembly binary format, generating a function corresponding table according to a function index of an original function in a compiling information table and a function index of a patch function in the patch file, wherein the function corresponding table records a corresponding relation between the original function and the patch function; that is, the function index of the original function is obtained from the compiling information table, the function index of the patch function is obtained from the patch file, and the function index of the original function and the function index of the patch function are recorded in the function corresponding table in an associated manner, so that the function corresponding table is generated; in the process of loading the original file, a function index space is generated, the function address of the original function is recorded in the function index space, and the corresponding relation between the original function and the patch function is recorded in the function corresponding table, so that the function address of the patch function can be obtained from the patch file, and then the function address of the original function in the function index space is replaced by the function address of the patch function according to the corresponding relation between the original function and the patch function recorded in the function corresponding table; in the function index space, the function address of the original function is replaced by the function address of the patch function, and the function executed during the later function application is the patch function, so that the function-level replacement and updating of the WebAssembly application by using the patch are realized.
In one possible implementation, the functions in the patch file are and only patch functions.
Specifically, the source code of the patch file includes and only has functions and modules that need to be patched in the original file, and it is expressed that any function in the patch file is a function of a beneficial patch, that is, the functions in the patch file are patch functions.
In the embodiment of the application, the functions in the patch file include and only include the patch function, that is, any function in the patch file is a function beneficial to the patch, which is beneficial to making the patch file have a small volume and short time required for downloading and loading.
In a possible implementation manner, the replacing, according to the function correspondence table, the function address of the original function in the function index space with the function address of the patch function includes: judging whether the patch function exists according to the function corresponding table; if the patch function exists, acquiring a function address of the patch function from the code segment of the patch file; and replacing the function address of the original function in the function index space with the function address of the patch function.
Specifically, in the process of loading the function section of the original file, whether a patch function exists is judged according to the function correspondence table, and when the patch function exists, the function address of the patch function is acquired from the code section of the patch file, and the function address of the original function in the function index space is replaced by the function address of the patch function.
Wherein, the loading flow of each segment of the WebAssembly is shown in fig. 4, and the loading sequence of each segment is as follows: the system comprises a type section, a leading-in section, a function section, a table section, a memory section, a global section, a leading-out section, a starting section, an element section, a code section and a data section.
The original loading flow of the function segment of the WebAssembly is shown in fig. 5, and includes the following steps:
501. and judging whether the number of the loaded functions is less than the total number of the functions. If the number of the loaded functions is not less than the total number of the functions, it is indicated that all the functions are loaded, and the process of loading the function section is ended.
502. And if the number of the loaded functions is less than the total number of the functions, acquiring the function signature index from the function segment. That is, the function signature index of the function that has not been loaded is obtained.
503. The function address of the function is obtained from the code segment. Wherein the function address of the function is obtained from the code segment by the function signature index.
504. The function is added to the function index space. That is, a function signature, a function address, and the like of the function are added to the function index space.
It should be understood that in the original loading process of the function segment of the WebAssembly, for each function, information such as a function signature index is obtained from the function segment, a first address (that is, a function address) of a corresponding function code block is obtained from a code segment, and after all data of the function is obtained, the function is added to a function index space.
The foregoing describes an original loading flow of a function segment of a WebAssembly, and in a scene where a patch needs to be loaded, since function interfaces need to be kept consistent, function names and function signatures of an original function and a patch function are consistent, so that only a function address of the patch function in a function index space needs to be corrected in a loading stage. According to the method and the device, the original loading process of the WebAssembly function section is modified, and the function address of the patch function is corrected in the loading process of the function section, so that the original function is replaced by the patch function. The modified loading flow of the function segment of the WebAssembly provided by the embodiment of the present application is shown in fig. 6, and includes the following steps:
601. and judging whether the number of the loaded functions is less than the total number of the functions. If the number of the loaded functions is not less than the total number of the functions, it is indicated that all the functions are loaded, and the process of loading the function section is ended.
602. If the number of the loaded functions is less than the total number of the functions, acquiring a function signature index from the function segment; i.e. to obtain the function signature index of functions that have not yet been loaded. It should be understood that a function signature is a collection of function name, parameter list, return type of a function, and a function signature index includes a function index, etc.
603. And searching a function corresponding table. The function mapping table records the original function index and the function index of the patch function.
604. And judging whether a patch function exists. That is, whether a patch function exists is judged according to the corresponding relation between the original function and the patch function recorded in the function correspondence table; when the corresponding relation between the original function and the patch function is recorded in the function corresponding table, the patch function is indicated to exist; when the corresponding relation between the original function and the patch function is not recorded in the function corresponding table, it is indicated that no patch function exists.
605. And if the patch function does not exist, acquiring the function address of the function from the code segment of the original file.
606. If the patch function exists, the function address of the function is obtained from the code section of the patch file.
607. The function is added to the function index space.
It should be noted that, in the loading process of the function segment of the WebAssembly provided in the embodiment of the present application, for each function, information such as a function signature index is obtained from the function segment of the original function (original file), which is different from the original loading process of the function segment of the WebAssembly, the present application adds a step of identifying a patch function and correcting an address of the patch function, if the function needs to be replaced by the patch function, a head address of a corresponding function code block is obtained from a patch file code segment, otherwise, the head address of the corresponding function code block is still obtained from the original file code segment, and finally, after all data of the function is obtained, function address replacement is completed, and the function is added to a function index space.
In the embodiment of the application, in the loading process of an original file, a function address of an original function is obtained from the original file and added to a function index space; when patching is needed, judging whether the original function needs to be replaced or not through a function corresponding table, when the corresponding relation between the original function and the patching function is recorded in the function corresponding table, indicating that the original function needs to be replaced by the patching function, judging whether the patching function exists or not according to the function corresponding table, if the patching function exists, acquiring a function address of the patching function from a code segment of a patching file, and replacing the function address of the original function in a function index space with the function address of the patching function; or, the function address of the original function is not added to the function index space, but the function address of the patch function is added to the function index space, so that the original function is replaced by the patch function.
In a possible implementation manner, the compiling information table further records a memory segment size of the original file; the method further comprises the following steps: in the compiling process of the patch file, acquiring the memory segment size of the original file from the compiling information table; and compiling the code segment of the patch file according to the size of the memory segment of the original file and the data offset of the patch function.
When the patch function relates to the memory operation, the memory operation of the code segment of the patch file is corrected; in this case, the size of the memory segment of the original file is recorded in the compiling information table generated in the process of compiling the original file.
For example, assume that there are 6 functions in the original file, which are function a (the memory occupied in the memory segment is 0-100), function B (the memory occupied in the memory segment is 100-300), function C (the memory occupied in the memory segment is 300-400), function D (the memory occupied in the memory segment is 400-600), function E (the memory occupied in the memory segment is 600-800), and function F (the memory occupied in the memory segment is 800-1200), so the memory segment size of the original file is 0-1200; assuming that the function D needs to be replaced by a function D ', the data offset of the function D ' is 300, the memory occupied by the function D ' is arranged at 1200-1500, so that the new data offset is 1200+300=1500, and the data offset is 1500, which is written into the code segment of the patch file.
In the embodiment of the present application, if the patch function relates to a memory operation, the memory operation of the code segment of the patch file needs to be modified; in this case, the size of the memory segment of the original file is recorded in the compiling information table generated in the process of compiling the original file; in the process of compiling to obtain the patch file, the memory segment size of the original file is obtained from the compiling information table, the memory segment size of the original file and the data offset of the patch function are used as new offsets, and the new offsets are written into the code segment of the patch file, so that the patch function can normally perform memory operation.
In a possible implementation manner, the compiling information table further records a function index of a called function, where the called function is a function called by the original function; the method further comprises the following steps: in the compiling process of the patch file, acquiring a function index of the called function from the compiling information table; and compiling the code segment of the patch file according to the function index of the called function.
It should be noted that, when the original function has a function call, in the process of compiling to obtain the patch file, the relevant instruction code segment of the function call in the patch function needs to be modified to ensure the correctness of the call relationship between the functions, so the code segment of the patch file needs to be compiled according to the function index of the called function of the original function.
In the embodiment of the application, if the original function relates to calling other functions, after the original function is replaced by the patch function, the patch function also relates to calling the function originally called by the original function, and the code segment of the patch file needs to be corrected; in this case, the compiling information table further records a function index of the called function, and the called function is a function called by the original function; in the process of obtaining the patch file through compiling, the function index of the called function is obtained from the compiling information table, the function index of the called function is compiled and written into the code section of the patch file, and therefore after the original function is replaced by the patch function through a patching mode, the patch function can also call the function originally called by the original function.
In one possible implementation, the called function is a function directly called by the original function, and the code segment of the patch file includes a direct call instruction, where the direct call instruction includes a function index of the called function.
When a function is directly called, the called function is directly located by the function index in the function index space, and therefore, the function index after the direct call (call) instruction of the code segment needs to be updated.
The original compiling flow of the code segment of the WebAssembly when the function is directly called is shown in fig. 7, and the method comprises the following steps:
701. the function index (fun _ id) of the called function is obtained at compile time.
702. A direct call instruction (call fun _ id) is written to the code section.
For example, when compiling code segments of the original file, the flow shown in fig. 7 may be performed.
It should be noted that, the patch is introduced in the embodiment of the present application, and therefore, the compiling flow of the code segment needs to be modified. And for the compiling of the patch file, acquiring a called function index from a compiling information table, and correcting the code segment of the patch file. Fig. 8 is a schematic diagram of a modified compiling flow of a code segment of a WebAssembly when a presence function is directly called, which is provided in an embodiment of the present application, and includes the following steps:
801. and judging whether the file is a patch file. That is, it is determined whether the currently compiled file is a patch file.
802. If the file is not a patch file, a function index (fun _ id) of the called function is acquired at the time of compilation. If the currently compiled file is not a patch file, that is, if the currently compiled file is an original file, the compiling process is the same as the original compiling process of the code segment.
803. If the file is a patch file, a function index (fun _ id) of the called function is acquired from the compilation information table.
804. A direct call instruction (call fun _ id) is written to the code section.
In the embodiment of the application, if the called function is a function directly called by the original function, after the original function is replaced by the patch function, the called function is also a function directly called by the patch function; in this case, the compiling information table also records the function index of the called function; therefore, the function index of the called function is obtained from the compiling information table, and after the function index of the called function is written into the direct calling instruction of the code segment of the patch file, the direct calling of the called function by the patch function can be realized, so that after the original function is replaced by the patch function in a patch mode, the patch function can also directly call the original function directly called by the original function.
In a possible implementation manner, the compiling information table further records a function signature index of the called function and an element segment size of the original file; the called function is a function indirectly called by the original function; the code segment for compiling the patch file according to the function index of the called function comprises: acquiring a function signature index of the called function from the compiling information table; compiling the element segment of the patch file according to the function index of the called function to obtain the element index of the called function; compiling the code segment of the patch file according to the element segment size of the original file and the element index of the called function, wherein the code segment of the patch file comprises an indirect call instruction, and the indirect call instruction comprises a function signature index of the called function.
The compiling information table also comprises a function signature index table, and a function signature index of the called function is recorded in the function signature index table; the compilation information table also includes the element segment size of the original file.
For indirect calling of a function, since it is not known at compile time specifically which function is to be called, and it is only known at runtime, the called function is not directly located by a function index of a function index space, but indirectly located from a table index space, it is necessary to update element entries in an element segment at compile time.
The original compiling flow of the code segment of the WebAssembly when the indirect calling of the function exists is shown in fig. 9, and comprises the following steps:
901. the function index (fun _ id) of the called function is obtained at compile time.
902. The function signature index (type _ id) of the called function is obtained at compile time.
903. And writing the function index (fun _ id) of the called function into the element segment to obtain the element index (elem _ id) of the called function.
904. The element index (elem _ id) of the called function is written into the code fragment.
905. An indirect call instruction (call _ index type _ id) is written to the code section.
It should be noted that, the patch is introduced in the embodiment of the present application, and therefore, the compiling flow of the code segment needs to be modified. If the patch file is compiled, the function index of the called function is obtained from the function index table, the function signature index of the called function is obtained from the function signature index table, the size of the element segment is obtained, and the element segment and the code segment are corrected. Fig. 10 is a schematic diagram of a modified compiling flow of a code segment of WebAssembly when a presence function is indirectly called according to an embodiment of the present application, including the following steps:
1001. whether the file is a patch file. That is, it is determined whether the currently compiled file is a patch file.
1002. If the file is not a patch file, a function index (fun _ id) of the called function is acquired at the time of compilation. If the currently compiled file is not a patch file, that is, the currently compiled file is an original file, the compiling process is the same as the original compiling process of the code segment.
1003. If the file is not a patch file, a function signature index (type _ id) of the called function is acquired at the time of compilation.
1004. If the file is a patch file, a function index (fun _ id) of the called function is acquired from the compilation information table.
1005. If the file is a patch file, a function signature index (type _ id) of the called function is acquired from the compilation information table.
1006. And writing the function index (fun _ id) of the called function into the element segment to obtain the element index (elem _ id) of the called function.
1007. If the file is not a patch file, an element index (elem _ id) of the called function is written into the code segment.
1008. If the file is a patch file, the element index (elem _ id) and the element segment size (table _ size) of the called function are written into the code segment.
1009. An indirect call instruction (call _ index type _ id) is written to the code section.
In the embodiment of the application, if the called function is a function indirectly called by the original function, the called function is also a function indirectly called by the patch function after the original function is replaced by the patch function; in this case, the compiling information table further records a function index of the called function, a function signature index of the called function, and an element segment size of the original file; acquiring a function index of the called function from the compiling information table, and writing the function index of the called function into an element segment of the patch file to obtain the element index of the called function; acquiring the size of an element segment of an original file from a compiling information table, and writing the size of the element segment of the original file and an element index of a called function into a code segment of a patch file; the function signature index of the called function is obtained from the compiling information table, and the function signature index of the called function is written into the indirect calling instruction in the code segment of the patch file, so that the indirect calling of the called function by the patch function can be realized, and therefore, after the original function is replaced by the patch function in a patch mode, the patch function can also indirectly call the original function indirectly called by the original function.
In one possible implementation, the method further includes: in the loading process of the original file, acquiring an element index of the called function from the patch file; and adding the element index of the called function into a table index space, wherein the table index space is generated in the loading process of the original file.
In the embodiment of the application, for indirect calling, since which function to be called is not known in the compiling period, the function can be known only in the running process, and the called function is not directly positioned through the function index of the called function in the function index space, but is indirectly positioned through the table index space, and the table index space is generated by loading an original file; therefore, in the loading process of the original file, the element index of the called function needs to be acquired from the patch file, and the element index of the called function is added to the table index space; therefore, when the patch function runs, the element index of the called function can be obtained from the table index space, and the called function is further positioned, so that the called function is indirectly called.
In one possible implementation, the called function is a virtual machine import function; before the obtaining the function index of the called function from the compiling information table, the method further comprises: generating a function index of the called function; adding a function index of the called function to the compilation information table.
If the called function is a virtual machine import function, a new function index needs to be generated and added to a function index table in the compilation information table. If the called function is not the virtual machine import function, the function index of the called function is already in the function index table.
In this embodiment of the present application, the called function is a virtual machine import function, and a function index of the called function is not recorded in a compiling information table generated in the process of compiling the original file, so that a function index of the called function needs to be generated, and the function index of the called function is added to the compiling information table, which is favorable for implementing a patch function to call the called function.
In one possible implementation, the method further includes: and in the loading process of the original file, adding the called function to the function index space through the import section of the original file.
In the embodiment of the application, the called function is a virtual machine import function, so the called function does not exist in the function index space generated in the loading process of the original file, and therefore the called function needs to be added to the function index space through the import section of the original file, so that the called function exists in the function index space; thereby facilitating the implementation of the patch function to invoke the called function.
The technical solutions provided in the present application are described below by specific examples.
Example 1
Example 1 is an application scenario of the present application, in order to update a WebAssembly application or repair a defect, a function in an existing WebAssembly application file computer needs to be replaced, and taking computing function computer as an example, a function implementation is replaced from a-b to a + b. The specific technical scheme of the example 1 is as follows:
step one, compiling
The compilation flow is shown in fig. 11.
1. Compiling the application source file main.c into a WebAssembly binary format file main.wasm through a compiler tool chain; wherein mail.wasm is an original file. Optionally, the wap binary format is translated into the wat text format, making the WebAssembly binary format file main.
1) The type segment contains two types of function signatures. In FIG. 11, there are (type (; 0;) (func (param i32 i 32) (result i 32))) and (type (; 1;) (func (result i 32))).
2) The function segment contains two functions, with the function indices 0 and 1, respectively, and the function names have been dropped during the compilation stage. I.e., func (; 0;) and func (; 1;) in FIG. 11.
2. Generating and exporting a compiling information table in the compiling process; in example 1, the correspondence between each function in the source code and the function index is recorded, a function index table is generated and derived, and other structures of the compiled information table are introduced in the following examples. The function index table is shown in fig. 11, and the structure is explained as follows:
1) Function index: the index assigned to each function by the compiler during compilation is related to the compilation order.
2) The function name: and function names actually corresponding to the function indexes in the WebAssembly file.
It can be seen that the function index table corresponding to main includes two items, which are function number 0 and function number 1. Where index 0 corresponds to func (; 0;), the computer in example 1, in compilation order; index 1 corresponds to func (; 1;), main in example 1.
Step two, making patches
The patch making process is shown in fig. 12.
1. And querying a corresponding function index of the original function in the function index table according to the function index table derived in the first step. If the function computer needs to be replaced in this example, it can be known by querying the function index table that the function index corresponding to the function computer is 0.
2. In the process of compiling a patch function file (patch.c) into a WebAssembly binary format file patch.wasm, two modes are adopted to record the corresponding relation between an original file function and a function in the patch file; and the patch is a patch file.
1) The content of the original file function section is kept consistent with that of the patch file function section, and the volume of the patch file is increased by adopting the method. That is, the functions in the original file refer to computer and main, and the functions in the patch file refer to computer and main. computer is to be patched changed and main is to remain unchanged. This means that while keeping both computer and main inside the patch file, one copy is regenerated, and main is actually redundant.
2) And generating a function corresponding table by using the function index of the original function in the function index table and the function index of the patch function in the patch file, thereby obtaining the corresponding relation between the new function and the old function. In the application, indexes are added to changed parts in the WebAssembly, and the original positions for referring to old functions are modified and replaced by updated parts in patches, so that a changed function corresponding table is provided, and the function corresponding table of the change has the corresponding relation between the function indexes of the original functions and the function indexes of the patch functions. This implementation is used below.
Step three, loading
Taking a computer function as an example, as shown in fig. 13, when the original file main is loaded in the wasm analysis, the computer function needs to be replaced by the computer function in the patch file, and if the function address of the computer function is obtained from the original file quota code segment, the address 0x08020000 is obtained; if the patch file is loaded, the function address of the computer function is obtained from the code block of the patch file, the address 0x08020200 is obtained, the original function computer { a-b } address 0x08020000 is replaced by the patch function computer { a + b } address 0x08020200, and the function address replacement is completed. It should be understood that the initial address of the computer () function can be obtained from either main.wasm or patch.wasm, where the reference to the computer function is replaced, the new computer function into which patch file patch.wasm is entered and the original main.wasm computer function are all there, just calling for a point change to achieve the effect of the replacement.
By adopting the method, the WebAssembly application can be updated by using the patch file with a smaller volume, the application version which is formally released is not influenced, and the lightweight and quick upgrading updating and application defect repairing of the WebAssembly application are realized. The method comprises the steps of realizing upgrading and updating of WebAssembly application or application defect repair, making and loading patches according to a WebAssembly format, recording and exporting a function index table in a compiling stage, obtaining a function index of an original function, compiling patch files by combining patch functions, and replacing a function address of the original function with a function address of a patch function when the application is loaded, so that patch function level replacement and updating are realized.
Example 2
Example 2 is another application scenario of the present application, and example 2 is different from example 1 in that when there is an operating memory in a patch function, taking function computer as an example, a new array needs to be declared and assigned in function implementation. The specific technical scheme of example 2 is as follows:
step one, compiling
The compilation flow adds steps to the compilation flow of example 1.
1. The application source file main.c is compiled into a WebAssembly binary format file main.wasm through a compiler toolchain.
2. Generating and deriving a compiling information table in the compiling process, wherein the compiling information table comprises the following structures:
1) Function index table: and recording the corresponding relation between each function in the application code and the function index in the compiling process, and generating and deriving a function index table.
2) The size of the memory segment is as follows: and recording the size of the memory segment in the compiling process, and deriving the size of the memory segment.
Step two, making patch
The patch making flow adds steps to the flow of making patches of example 1, as shown in fig. 14.
1. And inquiring the corresponding function index of the original function in the function index table according to the function index table derived in the step one.
2. In the process of compiling the patch function file (patch.c) into the WebAssembly binary format file patch.wasm, the relevant instruction code segment of the operation memory in the patch function needs to be modified to ensure the correctness of the operation memory.
The specific process is as follows: the compiling information table can know the size of the used memory segment, and when the patch file is compiled, the offset of the patch file (or patch function) and the size of the used memory segment are used as a new offset to correct the instruction related to the operation memory and write the instruction into the code segment of the patch file. It should be appreciated that because the patch modifies the size of the dataram, the size of the data segment needs to be expanded so that the new patch function operates on the new data, while the old version can still operate on its own data. Here the new data offset is no longer indexed from 0 but from the end of the old data segment (used memory data segment), so "new offset = offset + used memory segment size".
3. In the process of compiling the patch function file into the WebAssembly binary format file patch.
Step three, loading
The loading flow adds steps to the loading flow of example 1. Additionally loading the data segment in the patch file into a linear memory space with an offset being the size of the used memory segment.
By adopting the method, the WebAssembly application can be updated by using the patch file with a smaller volume, the application version which is formally released is not influenced, and the lightweight and quick upgrading updating and application defect repairing of the WebAssembly application are realized. Aiming at the scene of linear memory operation in the patch function, the correct replacement of the patch function is realized through the processing in the compiling and loading stages. The method comprises the steps of realizing upgrading and updating of WebAssembly application or application defect repair, making and loading patches aiming at the WebAssembly format, recording and exporting compiling information including a function index table and a memory segment size in a compiling stage, obtaining a function index and the memory segment size of an original function, correcting the memory operation of a code segment because a patch function relates to the memory operation, and compiling the patch function into a WebAssembly patch file. And when the application is loaded, replacing the function address of the original function with the function address of the patch function for loading.
Example 3
Example 3 is a more complex application scenario of the present application, and the difference between example 3 and example 1 is that there is a case where another function is called in a patch function, and taking function computer as an example, in function implementation, it is necessary to replace a directly calling function add with a directly calling function sub, and replace an indirectly calling function sub with an indirectly calling function add. Example 3 specific technical solutions are as follows:
step one, compiling
The compilation flow adds steps to the compilation flow of example 1, as shown in fig. 15.
1. The application source file main.c is compiled into a WebAssembly binary format file main.wasm through a compiler toolchain. Optionally, translating the wap binary format into the wat text format to make the WebAssembly binary format file main, wasm readable, as shown in fig. 15:
the table segment contains an element, which is a function reference, and is a function reference corresponding to the function index 1, and is used for function indirect calling. Here, in fact, a reference space for addresses is reserved in the table segment, which dynamically stores the value of p, but is preset as sub; statement "p = sub" execution time { local.get 0; call _ index (type 0) }, wasm writes the address of sub into the table segment reference index 1, and then "int ret = (= p) (a, b)" reads the indirect call address to be executed from the reference index 1, that is, the sub function calls the sub function.
2. Generating and deriving a compiling information table in the compiling process, wherein the compiling information table comprises the following structures:
1) Function index table: and recording the corresponding relation between each function and the function index in the compiling process, and generating and deriving a function index table.
2) Function signature index table: and recording the corresponding relation between each function signature and the function signature index in the compiling process, and generating and deriving a function signature index table. The function signature index table structure comprises:
function signature indexing: the compiler signs the assigned index for each function during compilation.
And function signature: and the function signature type corresponding to the function signature index in the type segment in the WebAssembly file.
3) Element segment size: and recording the size of the element segment in the compiling process and deriving the size of the element segment.
4) The size of the memory segment is as follows: and recording the size of the memory segment in the compiling process, and deriving the size of the memory segment.
Step two, making patch
The flow of making a patch adds steps to the flow of making a patch of example 1, as shown in fig. 16.
1. And if the called function is the virtual machine import function, generating a new function index and adding the new function index to the function index table.
2. And inquiring the corresponding function index of the original function in the function index table according to the function index table derived in the step one. If the function computer needs to be replaced in this example, it can be known by querying the function index table that the function index corresponding to the function computer is 2.
3. In the process of compiling the patch function file (patch.c) into the WebAssembly binary format file patch.wasm, the relevant instruction code segment of the function call in the patch function needs to be modified to ensure the correctness of the call relationship between the functions. For different function calling modes, the specific process is as follows:
direct calling: the called function is directly located by the function index of the function index space, so the function index after the call instruction of the code segment needs to be updated, as shown in fig. 7 and 8. And if the patch file is compiled, acquiring the function index of the called function from the function index table, and correcting the code segment.
Indirect calling: since it is not known at compile time which function is specifically called, it is only known at runtime that the called function is not located directly by the function index of the function index space, but indirectly from the table index space. The element entries in the element segment need to be updated as shown in fig. 9 and 10. If the patch file is compiled, the called function index is obtained from the function index table, the function signature index of the called function is obtained from the function signature index table, the size of the element segment is obtained, and the element segment and the code segment are corrected.
4. In the process of compiling the patch function file (patch.c) into the WebAssembly binary format file patch.wax, a function corresponding table is generated by using the function index of the original function in the function index table and the function index of the patch function in the patch file, so that the corresponding relation between the new function and the old function is obtained.
Step three, loading
The loading flow adds steps to the loading flow of example 1.
1. For the patch function:
the loading step according to example 1 modifies the patch function code address in the function index space, i.e. replaces the function address of the original function with the function address of the patch function.
2. For other functions called in the patch function:
if the called function is a virtual machine import function, the called function is added into the function index space from the import section of the patch function, and then different steps are executed according to different function calling modes, and the specific process is as follows:
direct calling: the called function is directly positioned through the function index in the function index space, the function index after the call instruction in the code segment is corrected in the early compiling stage, and the function address of the called function is not changed, so that the direct calling accuracy of the function can be ensured.
Indirect calling: since it is not known at compile time which function is specifically called, it is only known at runtime that the called function is not located directly by the function index in the function index space, but indirectly from the table index space. Therefore, in the process of parsing the original file to obtain the table index space, the modification function refers to and adds the corresponding element entry in the table index space, as shown in fig. 17, the newly added entry index in the table index space is the sum of the element segment size of the original file and the element index of the patch file.
By adopting the method, the WebAssembly application can be updated by using the patch file with a smaller volume, the application version which is formally released is not influenced, and the lightweight and quick upgrading updating and application defect repairing of the WebAssembly application are realized. Aiming at the scene that other functions are called in the patch function, the correct replacement of the patch function is realized through the processing in the compiling and loading stages. The method comprises the steps of realizing upgrading updating or application defect repairing of WebAssembly application, making and loading patches aiming at a WebAssembly format, recording and exporting a compiling information table comprising a function index table, a function signature index table and element segment sizes in a compiling stage, and obtaining the function index, the function signature index and the element segment sizes of original functions. When the application is loaded, the original function address is replaced by the patch function address for the patch function. For other functions called in the patch function, the processing is carried out according to different calling modes of the functions, so that the replacement and the update of the patch function level are realized.
Referring to fig. 18, fig. 18 is a schematic structural diagram of a patch apparatus according to an embodiment of the present application, where the patch apparatus 1800 may include a processing unit 1801 and a communication unit 1802, where the processing unit 1801 is configured to execute any step in the method embodiments shown in fig. 8 to fig. 12, and when data transmission, such as acquisition and the like, is performed, the communication unit 1802 may be optionally called to complete a corresponding operation. The details will be described below.
The processing unit 1801 is configured to: generating a compiling information table in the compiling process of an original file, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file; generating a function corresponding table according to the compiling information table in the compiling process of the patch file, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between the original function and the patch function, and the patch function is a function in the patch file; and in the loading process of the original file, replacing the function address of the original function in a function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file.
In one possible implementation, the functions in the patch file are and only patch functions.
In a possible implementation manner, the processing unit 1801 is specifically configured to: judging whether the patch function exists according to the function corresponding table; if the patch function exists, acquiring a function address of the patch function from the code segment of the patch file; and replacing the function address of the original function in the function index space with the function address of the patch function.
In a possible implementation manner, the compiling information table further records a memory segment size of the original file; the processing unit 1801 is further configured to: in the compiling process of the patch file, acquiring the memory segment size of the original file from the compiling information table; and compiling the code segment of the patch file according to the size of the memory segment of the original file and the data offset of the patch function.
In a possible implementation manner, the compiling information table further records a function index of a called function, where the called function is a function called by the primitive function; the processing unit 1801 is further configured to: in the compiling process of the patch file, acquiring a function index of the called function from the compiling information table; and compiling the code segment of the patch file according to the function index of the called function.
In a possible implementation manner, the called function is a function directly called by the primitive function, and the code segment of the patch file includes a direct call instruction, and the direct call instruction includes a function index of the called function.
In a possible implementation manner, the compiling information table further records a function signature index of the called function and an element segment size of the original file; the called function is a function indirectly called by the original function; the processing unit 1801 is specifically configured to: acquiring a function signature index of the called function from the compiling information table; compiling the element segment of the patch file according to the function index of the called function to obtain the element index of the called function; compiling the code segment of the patch file according to the element segment size of the original file and the element index of the called function, wherein the code segment of the patch file comprises an indirect call instruction, and the indirect call instruction comprises a function signature index of the called function.
In a possible implementation manner, the processing unit 1801 is further configured to: acquiring the element index of the called function from the patch file in the loading process of the original file; and adding the element index of the called function into a table index space, wherein the table index space is generated in the loading process of the original file.
In one possible implementation, the called function is a virtual machine import function; the processing unit 1801 is further configured to: before the obtaining of the function index of the called function from the compiling information table; generating a function index of the called function; adding a function index of the called function to the compilation information table.
In a possible implementation manner, the processing unit 1801 is further configured to: and in the loading process of the original file, adding the called function to the function index space through the import section of the original file.
The patch device 1800 may further include a storage unit 1803 for storing program codes and data of the terminal. The processing unit 1801 may be a processor, the communication unit 1802 may be a transceiver, and the storage unit 1803 may be a memory.
It should be noted that the implementation of each unit may also correspond to the corresponding description of the method embodiments shown in fig. 3 to 17.
The patch device 1800 depicted in fig. 18 generates a compilation information table in the process of compiling to obtain an original file in the WebAssembly binary format, where the compilation information table records a function index of an original function in the original file; in the process of compiling to obtain a patch file in a WebAssembly binary format, generating a function corresponding table according to a function index of an original function in a compiling information table and a function index of a patch function in the patch file, wherein the function corresponding table records a corresponding relation between the original function and the patch function; that is, the function index of the original function is obtained from the compiling information table, the function index of the patch function is obtained from the patch file, and the function index of the original function and the function index of the patch function are recorded in the function corresponding table in an associated manner, so that the function corresponding table is generated; in the process of loading the original file, a function index space is generated, the function address of the original function is recorded in the function index space, and the corresponding relation between the original function and the patch function is recorded in the function corresponding table, so that the function address of the patch function can be obtained from the patch file, and then the function address of the original function in the function index space is replaced by the function address of the patch function according to the corresponding relation between the original function and the patch function recorded in the function corresponding table; in the function index space, the function address of the original function is replaced by the function address of the patch function, and the function executed during the later function application is the patch function, so that the function-level replacement and updating of the WebAssembly application by using the patch are realized.
Referring to fig. 19, fig. 19 is a schematic structural diagram of a patch device according to an embodiment of the present application, where the patch device 1910 includes a transceiver 1911, a processor 1912, and a memory 1913, and the transceiver 1911, the processor 1912, and the memory 1913 are connected to each other through a bus 1914.
The memory 1913 includes, but is not limited to, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), or a compact disk read-only memory (CD-ROM), and the memory 1913 is used for related instructions and data.
The transceiver 1911 is used to receive and transmit data.
The processor 1912 may be one or more Central Processing Units (CPUs), and in the case where the processor 1912 is a CPU, the CPU may be a single-core CPU or a multi-core CPU.
The processor 1912 in the patch device 1910 is configured to read the program code stored in the memory 1913, and perform the following operations: generating a compiling information table in the compiling process of an original file, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file; generating a function corresponding table according to the compiling information table in the compiling process of the patch file, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between the original function and the patch function, and the patch function is a function in the patch file; and in the loading process of the original file, replacing the function address of the original function in a function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file.
It should be noted that, the implementation of each operation may also correspond to the corresponding description of the method embodiments described with reference to fig. 3 to 17.
The patch device 1910 illustrated in fig. 19 generates a compiling information table in the process of compiling the original file in the WebAssembly binary format, where the compiling information table records a function index of an original function in the original file; in the process of compiling to obtain a patch file in a WebAssembly binary format, generating a function corresponding table according to a function index of an original function in a compiling information table and a function index of a patch function in the patch file, wherein the function corresponding table records a corresponding relation between the original function and the patch function; that is, the function index of the original function is obtained from the compiling information table, the function index of the patch function is obtained from the patch file, and the function index of the original function and the function index of the patch function are recorded in the function corresponding table in an associated manner, so that the function corresponding table is generated; in the process of loading the original file, a function index space is generated, the function address of the original function is recorded in the function index space, and the corresponding relation between the original function and the patch function is recorded in the function corresponding table, so that the function address of the patch function can be obtained from the patch file, and then the function address of the original function in the function index space is replaced by the function address of the patch function according to the corresponding relation between the original function and the patch function recorded in the function corresponding table; in the function index space, the function address of the original function is replaced by the function address of the patch function, and the function executed during the later function application is the patch function, so that the function-level replacement and updating of the WebAssembly application by using the patch are realized.
The embodiment of the present application further provides a chip, which includes at least one processor, a memory and an interface circuit, where the memory, the transceiver and the at least one processor are interconnected by a line, and the at least one memory stores a computer program; when the computer program is executed by the processor, the method flows shown in the method embodiments are implemented.
An embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and when the computer program runs on an electronic device, the method flows shown in the foregoing method embodiments are implemented.
Embodiments of the present application further provide a computer program, where when the computer program runs on an electronic device, the method flows shown in the foregoing method embodiments are implemented.
It should be understood that the Processor mentioned in the embodiments of the present Application may be a Central Processing Unit (CPU), and may also be other general purpose processors, digital Signal Processors (DSP), application Specific Integrated Circuits (ASIC), field Programmable Gate Arrays (FPGA) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, and the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will also be appreciated that the memory referred to in the embodiments herein may be either volatile memory or nonvolatile memory, or may include both volatile and nonvolatile memory. The non-volatile Memory may be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable PROM (EEPROM), or a flash Memory. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of example, but not limitation, many forms of RAM are available, such as Static random access memory (Static RAM, SRAM), dynamic Random Access Memory (DRAM), synchronous Dynamic random access memory (Synchronous DRAM, SDRAM), double Data Rate Synchronous Dynamic random access memory (DDR SDRAM), enhanced Synchronous SDRAM (ESDRAM), synchronous link SDRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
It should be noted that when the processor is a general-purpose processor, a DSP, an ASIC, an FPGA or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, the memory (memory module) is integrated in the processor.
It should be noted that the memory described herein is intended to comprise, without being limited to, these and any other suitable types of memory.
It should be understood that, in the various embodiments of the present application, the sequence numbers of the above-mentioned processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the above-described division of units is only one type of division of logical functions, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The above functions, if implemented in the form of software functional units and sold or used as a separate product, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a patch device) to perform all or part of the steps of the above-mentioned method according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The steps in the method of the embodiment of the application can be sequentially adjusted, combined and deleted according to actual needs. In addition, the terms and explanations in the embodiments of the present application may refer to the corresponding descriptions in the other embodiments.
The modules in the device can be merged, divided and deleted according to actual needs.
The above description, the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and these modifications or substitutions do not depart from the scope of the technical solutions of the embodiments of the present application.

Claims (23)

1. A patching method, comprising:
generating a compiling information table in the compiling process of an original file, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file;
generating a function corresponding table according to the compiling information table in the compiling process of the patch file, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between the original function and the patch function, and the patch function is a function in the patch file;
and in the loading process of the original file, replacing the function address of the original function in a function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file.
2. The method of claim 1, wherein the functions in the patch file are patch functions and only patch functions.
3. The method according to claim 1 or 2, wherein the replacing the function address of the primitive function in the function index space with the function address of the patch function according to the function correspondence table comprises:
judging whether the patch function exists according to the function corresponding table;
if the patch function exists, acquiring a function address of the patch function from the code segment of the patch file;
and replacing the function address of the original function in the function index space with the function address of the patch function.
4. The method according to any one of claims 1 to 3, wherein the compiling information table further records a memory segment size of the original file; the method further comprises the following steps:
in the compiling process of the patch file, acquiring the memory segment size of the original file from the compiling information table;
and compiling the code segment of the patch file according to the size of the memory segment of the original file and the data offset of the patch function.
5. The method according to any one of claims 1 to 4, wherein the compilation information table further records a function index of a called function, the called function being a function called by the primitive function; the method further comprises the following steps:
in the compiling process of the patch file, acquiring a function index of the called function from the compiling information table;
and compiling the code segment of the patch file according to the function index of the called function.
6. The method as recited in claim 5, wherein the called function is a function directly called by the primitive function, and wherein the code segment of the patch file includes a direct call instruction including a function index of the called function.
7. The method according to claim 5, wherein the compilation information table further records a function signature index of the called function, and an element segment size of the original file; the called function is a function indirectly called by the original function; the code segment for compiling the patch file according to the function index of the called function comprises:
acquiring a function signature index of the called function from the compiling information table;
compiling the element segment of the patch file according to the function index of the called function to obtain the element index of the called function;
compiling the code segment of the patch file according to the element segment size of the original file and the element index of the called function, wherein the code segment of the patch file comprises an indirect call instruction, and the indirect call instruction comprises a function signature index of the called function.
8. The method of claim 7, further comprising:
in the loading process of the original file, acquiring an element index of the called function from the patch file;
and adding the element index of the called function into a table index space, wherein the table index space is generated in the loading process of the original file.
9. The method of any of claims 5-8, wherein the called function is a virtual machine import function; before the obtaining the function index of the called function from the compiling information table, the method further comprises:
generating a function index of the called function;
adding a function index of the called function to the compilation information table.
10. The method of claim 9, further comprising:
and in the loading process of the original file, adding the called function to the function index space through the import section of the original file.
11. A patch device, the device comprising a processing unit configured to:
generating a compiling information table in the compiling process of an original file, wherein the original file is a file in a WebAssembly binary format, the compiling information table records a function index of an original function, and the original function is a function in the original file;
generating a function corresponding table according to the compiling information table in the compiling process of the patch file, wherein the patch file is a file in a WebAssembly binary format, the function corresponding table records the corresponding relation between the original function and the patch function, and the patch function is a function in the patch file;
and in the loading process of the original file, replacing the function address of the original function in a function index space with the function address of the patch function according to the function corresponding table, wherein the function index space is generated in the loading process of the original file.
12. The apparatus of claim 11, wherein the function in the patch file is and only has a patch function.
13. The apparatus according to claim 11 or 12, wherein the processing unit is specifically configured to:
judging whether the patch function exists according to the function corresponding table;
if the patch function exists, acquiring a function address of the patch function from the code segment of the patch file;
and replacing the function address of the original function in the function index space with the function address of the patch function.
14. The apparatus according to any of claims 11-13, wherein the compiling information table further records a memory segment size of the original file; the processing unit is further to:
in the compiling process of the patch file, acquiring the memory segment size of the original file from the compiling information table;
and compiling the code segment of the patch file according to the size of the memory segment of the original file and the data offset of the patch function.
15. The apparatus according to any one of claims 11-14, wherein the compilation information table further records a function index of a called function, the called function being a function called by the primitive function; the processing unit is further to:
acquiring a function index of the called function from the compiling information table in the compiling process of the patch file;
and compiling the code segment of the patch file according to the function index of the called function.
16. The apparatus of claim 15, wherein the called function is a function directly called by the primitive function, and wherein the code segment of the patch file comprises a direct call instruction, and wherein the direct call instruction comprises a function index of the called function.
17. The apparatus according to claim 15, wherein the compilation information table further records a function signature index of the called function, and an element segment size of the original file; the called function is a function indirectly called by the original function; the processing unit is specifically configured to:
acquiring a function signature index of the called function from the compiling information table;
compiling the element segment of the patch file according to the function index of the called function to obtain the element index of the called function;
compiling the code segment of the patch file according to the element segment size of the original file and the element index of the called function, wherein the code segment of the patch file comprises an indirect call instruction, and the indirect call instruction comprises a function signature index of the called function.
18. The apparatus of claim 17, wherein the processing unit is further configured to:
in the loading process of the original file, acquiring an element index of the called function from the patch file;
and adding the element index of the called function into a table index space, wherein the table index space is generated in the loading process of the original file.
19. The apparatus according to any of claims 15-18, wherein the called function is a virtual machine import function; the processing unit is further to:
before the obtaining of the function index of the called function from the compiling information table;
generating a function index of the called function;
adding a function index of the called function to the compilation information table.
20. The apparatus of claim 19, wherein the processing unit is further configured to:
and in the loading process of the original file, adding the called function to the function index space through the import section of the original file.
21. A patch device comprising a processor, a memory, a communication interface, and one or more programs stored in the memory and configured for execution by the processor, the programs including instructions for performing the steps of the method of any of claims 1-10.
22. A chip, comprising: a processor for calling and running a computer program from a memory so that a device on which the chip is installed performs the method of any one of claims 1-10.
23. A computer-readable storage medium, characterized in that it stores a computer program for electronic data exchange, wherein the computer program causes a computer to perform the method according to any one of claims 1-10.
CN202110297938.4A 2021-03-19 2021-03-19 Patch method and related equipment Pending CN115167862A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202110297938.4A CN115167862A (en) 2021-03-19 2021-03-19 Patch method and related equipment
PCT/CN2022/081029 WO2022194173A1 (en) 2021-03-19 2022-03-15 Patching method and relevant device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110297938.4A CN115167862A (en) 2021-03-19 2021-03-19 Patch method and related equipment

Publications (1)

Publication Number Publication Date
CN115167862A true CN115167862A (en) 2022-10-11

Family

ID=83321725

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110297938.4A Pending CN115167862A (en) 2021-03-19 2021-03-19 Patch method and related equipment

Country Status (2)

Country Link
CN (1) CN115167862A (en)
WO (1) WO2022194173A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117251234A (en) * 2023-11-16 2023-12-19 北京中电华大电子设计有限责任公司 Function calling method and device based on patches

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103309683B (en) * 2012-03-07 2016-08-03 京信通信系统(中国)有限公司 The software patch embedding grammar of hardware device and device
CN103744709B (en) * 2014-01-23 2017-02-15 华为技术有限公司 patch loading method and device
US10552639B1 (en) * 2019-02-04 2020-02-04 S2 Systems Corporation Local isolator application with cohesive application-isolation interface
CN112015491B (en) * 2019-05-30 2022-08-09 华为技术有限公司 Method, device and computer storage medium for realizing function jump
CN110673837B (en) * 2019-08-29 2020-11-17 腾讯科技(深圳)有限公司 Code repairing method and device, electronic equipment and computer readable storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117251234A (en) * 2023-11-16 2023-12-19 北京中电华大电子设计有限责任公司 Function calling method and device based on patches
CN117251234B (en) * 2023-11-16 2024-03-29 北京中电华大电子设计有限责任公司 Function calling method and device based on patches

Also Published As

Publication number Publication date
WO2022194173A1 (en) 2022-09-22

Similar Documents

Publication Publication Date Title
US8296535B2 (en) Generating incremental program updates
US8261247B2 (en) Method of modifying code of a running computer program based on symbol values discovered from comparison of running code to corresponding object code
CN107506219A (en) A kind of general version upgrade method based on android system
CN104239082A (en) Hot patching implementation method of embedded system
JPH0836488A (en) Method and device for checking run-time error using dynamic patching
US20080005728A1 (en) Methods, systems, and computer program products for enabling cross language access to an addressable entity in an execution environment
US20080005727A1 (en) Methods, systems, and computer program products for enabling cross language access to an addressable entity
US20190087208A1 (en) Method and apparatus for loading elf file of linux system in windows system
CN112612502A (en) Patch generation method, device, equipment and storage medium
CN102364433A (en) Method for realizing Wine construction tool transplanting on ARM (Advanced RISC Machines) processor
WO2022194173A1 (en) Patching method and relevant device
CN111666102A (en) File format conversion method, chip verification method, related device and network chip
CN113641389B (en) Software upgrading method, device and equipment based on OpenCPU
CN115185550A (en) Service deployment method, device, computer equipment and storage medium
CN108958795B (en) BootLoader code reuse method and development board in embedded system
CN113504934A (en) Patch compiling method, patch program repairing method and related equipment
CN117251234B (en) Function calling method and device based on patches
EP4350504A1 (en) Cross-linking method and apparatus, electronic device, and storage medium
CN117075960B (en) Program reconstruction method, application cross-platform migration method, device and computing equipment
CN115421876B (en) Binary translation method and device
CN113672238B (en) Operation method, device and equipment based on real-time operating system modularized management
KR20070081868A (en) Method for updating software efficiently in mobile communication system
CN116243971B (en) Static dependency bootstrapping-based kernel-independent module construction method
US11249733B2 (en) Electronic apparatus and control method thereof
US8453108B1 (en) Static, configurable kernel interface

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination