CN115167862A - Patch method and related equipment - Google Patents
Patch method and related equipment Download PDFInfo
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/52—Binary to binary
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44568—Immediately runnable code
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
- G06F9/449—Object-oriented method invocation or resolution
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
本申请实施例提供一种补丁方法及相关设备,该方法包括:在原文件的编译过程中,生成编译信息表,原文件为WebAssembly二进制格式的文件,编译信息表记录有原函数的函数索引,原函数为原文件中的函数;在补丁文件的编译过程中,根据编译信息表生成函数对应表,补丁文件为WebAssembly二进制格式的文件,函数对应表记录有原函数与补丁函数的对应关系,补丁函数为补丁文件中的函数;在原文件的加载过程中,根据函数对应表将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址,函数索引空间在原文件的加载过程中生成。采用本申请实施例,能够实现使用补丁对WebAssembly应用进行函数级的替换和更新。
The embodiments of the present application provide a patching method and related equipment. The method includes: in the process of compiling an original file, generating a compilation information table, the original file is a file in the WebAssembly binary format, the compilation information table records the function index of the original function, and the original file is in the WebAssembly binary format. The function is the function in the original file; during the compilation process of the patch file, a function correspondence table is generated according to the compilation information table. The patch file is a file in the WebAssembly binary format. The function correspondence table records the correspondence between the original function and the patch function. The patch function is the function in the patch file; during the loading process of the original file, the function address of the original function in the function index space is replaced with the function address of the patch function according to the function correspondence table, and the function index space is generated during the loading process of the original file. With the embodiments of the present application, it is possible to use patches to perform function-level replacement and update of WebAssembly applications.
Description
技术领域technical field
本申请涉及计算机技术领域,尤其涉及一种补丁方法及相关设备。The present application relates to the field of computer technology, and in particular, to a patching method and related equipment.
背景技术Background technique
现在还未有针对WebAssembly应用实现的补丁方案,如需替换WebAssembly文件中的特定函数,则需要重新编译整个源文件,得到替换函数后的新二进制格式的.wasm文件,以新版本应用的形式在WebAssembly虚拟机中进行加载运行。There is no patch solution implemented for WebAssembly applications yet. If you want to replace a specific function in the WebAssembly file, you need to recompile the entire source file to get the .wasm file in the new binary format after the function is replaced, which is in the form of a new version of the application. Load and run in the WebAssembly virtual machine.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供了一种补丁方法及相关设备,能够实现使用补丁对WebAssembly应用进行函数级的替换和更新。The embodiments of the present application provide a patch method and related equipment, which can implement function-level replacement and update of a WebAssembly application by using a patch.
第一方面,本申请实施例提供了一种补丁方法,包括:在原文件的编译过程中,生成编译信息表,其中,所述原文件为WebAssembly二进制格式的文件,所述编译信息表记录有原函数的函数索引,所述原函数为所述原文件中的函数;在补丁文件的编译过程中,根据所述编译信息表生成函数对应表,其中,所述补丁文件为WebAssembly二进制格式的文件,所述函数对应表记录有所述原函数与补丁函数的对应关系,所述补丁函数为所述补丁文件中的函数;在所述原文件的加载过程中,根据所述函数对应表将函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址,其中,所述函数索引空间在所述原文件的加载过程中生成。在本申请实施例中,在编译得到WebAssembly二进制格式的原文件的过程中,生成编译信息表,该编译信息表记录有原文件中的原函数的函数索引;在编译得到WebAssembly二进制格式的补丁文件的过程中,根据编译信息表中的原函数的函数索引以及补丁文件中的补丁函数的函数索引生成函数对应表,函数对应表记录有原函数与补丁函数的对应关系;也即从编译信息表中获取原函数的函数索引,从补丁文件中获取补丁函数的函数索引,将原函数的函数索引和补丁函数的函数索引关联记录在函数对应表上,从而生成函数对应表;在加载原文件的过程中,会生成函数索引空间,函数索引空间中记录有原函数的函数地址,而函数对应表记录有原函数和补丁函数的对应关系,因此可以从补丁文件中获取补丁函数的函数地址,然后根据函数对应表记录的原函数和补丁函数的对应关系,将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址;由于在函数索引空间中,原函数的函数地址替换为了补丁函数的函数地址,后期函数应用时执行的函数即为补丁函数,从而实现使用补丁对WebAssembly应用进行函数级的替换和更新。应理解,本申请实施例所描述的原函数或补丁函数并非指一个函数,而是指一类函数;例如,原函数指需要被补丁的函数的统称,补丁函数指用于补丁的函数的统称。In a first aspect, an embodiment of the present application provides a patching method, which includes: in the process of compiling an original file, generating a compilation information table, wherein the original file is a file in the WebAssembly binary format, and the compilation information table records the original file. a function index of a function, where the original function is a function in the original file; during the compilation process of the patch file, a function correspondence table is generated according to the compilation information table, wherein the patch file is a file in the WebAssembly binary format, The function correspondence table records the correspondence between the original function and the patch function, and the patch function is a function in the patch file; during the loading process of the original file, the function index is indexed according to the function correspondence table. The function address of the original function in the space is replaced with the function address of the patch function, wherein the function index space is generated during the loading process of the original file. In the embodiment of the present application, in the process of compiling to obtain the original file in the WebAssembly binary format, a compilation information table is generated, and the compilation information table records the function index of the original function in the original file; after compiling to obtain the patch file in the WebAssembly binary format In the process of compiling, a function correspondence table is generated according to the function index of the original function in the compilation information table and the function index of the patch function in the patch file, and the function correspondence table records the correspondence between the original function and the patch function; that is, from the compilation information table Obtain the function index of the original function from , obtain the function index of the patch function from the patch file, record the function index of the original function and the function index of the patch function in the function correspondence table, thereby generating the function correspondence table; During the process, a function index space will be generated. The function index space records the function address of the original function, and the function correspondence table records the corresponding relationship between the original function and the patch function. Therefore, the function address of the patch function can be obtained from the patch file, and then According to the correspondence between the original function and the patch function recorded in the function correspondence table, replace the function address of the original function in the function index space with the function address of the patch function; because in the function index space, the function address of the original function is replaced by the patch function The function address of the later function application is the patch function, so as to realize the function-level replacement and update of the WebAssembly application using the patch. It should be understood that the original function or patch function described in the embodiments of the present application does not refer to a function, but refers to a type of function; for example, the original function refers to the general name of the functions that need to be patched, and the patch function refers to the general name of the functions used for patching. .
在一种可能的实现方式中,所述补丁文件中的函数有且仅有补丁函数。在本申请实施例中,补丁文件中的函数有且仅有所述补丁函数,也即补丁文件中任何一个函数都是有益补丁的函数,有利于使得补丁文件体积较小、下载和加载所需时间短。In a possible implementation manner, the functions in the patch file have one and only patch functions. In the embodiment of the present application, the functions in the patch file include and only the patch function, that is, any function in the patch file is a function that is beneficial to the patch, which is conducive to making the patch file smaller in size and required for downloading and loading. short time.
在一种可能的实现方式中,所述根据所述函数对应表将函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址,包括:根据所述函数对应表判断是否存在所述补丁函数;若存在所述补丁函数,则从所述补丁文件的代码段中获取所述补丁函数的函数地址;将所述函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址。在本申请实施例中,在原文件的加载过程中,从原文件中获取原函数的函数地址,添加到函数索引空间中;当需要打补丁时,可以通过函数对应表来判断是否需要对原函数进行替换,当函数对应表中记录有原函数与补丁函数的对应关系时,说明需要将原函数替换为补丁函数,如此可以根据函数对应表判断是否存在补丁函数,如果存在补丁函数,则从补丁文件的代码段中获取补丁函数的函数地址,再将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址;或者说,不将原函数的函数地址添加到函数索引空间,而是将补丁函数的函数地址添加到函数索引空间,从而实现补丁函数对原函数的替换。In a possible implementation manner, the 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 correspondence table includes: judging whether or not according to the function correspondence table The patch function exists; if the patch function exists, obtain the function address of the patch function from the code segment of the patch file; replace the function address of the original function in the function index space with the The function address of the patch function described above. In the embodiment of the present application, during the loading process of the original file, the function address of the original function is obtained from the original file and added to the function index space; when patching is required, the function correspondence table can be used to determine whether the original function needs to be updated. Replace, when the corresponding relationship between the original function and the patch function is recorded in the function correspondence table, it indicates that the original function needs to be replaced with a patch function. In this way, it can be judged whether there is a patch function according to the function correspondence table. Obtain the function address of the patch function from the code segment of the file, and then replace the function address of the original function in the function index space with the function address of the patch function; in other words, instead of adding the function address of the original function to the function index space, The function address of the patch function is added to the function index space, thereby realizing the replacement of the original function by the patch function.
在一种可能的实现方式中,所述编译信息表还记录有所述原文件的内存段尺寸;所述方法还包括:在所述补丁文件的编译过程中,从所述编译信息表中获取所述原文件的内存段尺寸;根据所述原文件的内存段尺寸和所述补丁函数的数据偏移量编译所述补丁文件的代码段。在本申请实施例中,若补丁函数涉及内存操作,则需要对补丁文件的代码段的内存操作进行修正;此种情况下,编译原文件的过程中生成的编译信息表中还记录有原文件的内存段尺寸;在编译得到补丁文件的过程中,从编译信息表中获取原文件的内存段尺寸,将原文件的内存段尺寸和补丁函数的数据偏移量作为新的偏移量,写入补丁文件的代码段,从而使得补丁函数可以正常进行内存操作。In a possible implementation manner, the compilation information table further records the size of the memory segment of the original file; the method further includes: during the compilation process of the patch file, obtaining from the compilation information table The size of the memory segment of the original file; the code segment of the patch file is compiled 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 involves a memory operation, the memory operation of the code segment of the patch file needs to be corrected; in this case, the compilation information table generated in the process of compiling the original file also records the original file In the process of compiling and obtaining the patch file, the memory segment size of the original file is obtained from the compilation information table, and the memory segment size of the original file and the data offset of the patch function are used as the new offset, and write Enter the code segment of the patch file, so that the patch function can perform memory operations normally.
在一种可能的实现方式中,所述编译信息表还记录有被调用函数的函数索引,所述被调用函数为被所述原函数调用的函数;所述方法还包括:在所述补丁文件的编译过程中,从所述编译信息表中获取所述被调用函数的函数索引;根据所述被调用函数的函数索引编译所述补丁文件的代码段。在本申请实施例中,若原函数涉及调用其他函数,则当原函数被替换为补丁函数后,补丁函数也涉及调用原先由原函数调用的函数,需要对补丁文件的代码段进行修正;此种情况下,编译信息表还记录有被调用函数的函数索引,被调用函数为被原函数调用的函数;在编译得到补丁文件的过程中,从编译信息表中获取被调用函数的函数索引,将被调用函数的函数索引编译写入补丁文件的代码段,从而通过补丁的方式将原函数替换为补丁函数后,补丁函数也可以调用原先由原函数调用的函数。In a possible implementation manner, the compilation information table further records a function index of a called function, and the called function is a function called by the original function; the method further includes: in the patch file During the compiling process, the function index of the called function is obtained from the compilation information table; the code segment of the patch file is compiled according to the function index of the called function. In the embodiment of the present application, if the original function involves calling other functions, after the original function is replaced by the patch function, the patch function also involves calling the function originally called by the original function, and the code segment of the patch file needs to be corrected; this kind of In this case, the compilation information table also records the function index of the called function, and the called function is the function called by the original function; in the process of compiling to obtain the patch file, the function index of the called function is obtained from the compilation information table, and the The function index of the called function compiles the code segment written into the patch file, so that after replacing the original function with the patch function by means of a patch, 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 original function, the code segment of the patch file includes a direct calling instruction, and the direct calling instruction includes a function of the called function index. In the embodiment of the present application, if the called function is a function directly called by the original function, then after the original function is replaced by the patch function, the called function is also the function directly called by the patch function; in this case, the compilation information table The function index of the called function is also recorded; therefore, after obtaining the function index of the called function from the compilation information table, and writing the function index of the called function into the direct calling instruction of the code segment of the patch file, the patch function can be implemented. After directly calling the called function, after replacing the original function with the patch function by means of a patch, the patch function can also directly call the function originally called directly by the original function.
在一种可能的实现方式中,所述编译信息表还记录有所述被调用函数的函数签名索引、所述原文件的元素段尺寸;所述被调用函数为被所述原函数间接调用的函数;所述根据所述被调用函数的函数索引编译所述补丁文件的代码段,包括:从所述编译信息表中获取所述被调用函数的函数签名索引;根据所述被调用函数的函数索引编译所述补丁文件的元素段,以得到所述被调用函数的元素索引;根据所述原文件的元素段尺寸和所述被调用函数的元素索引编译所述补丁文件的代码段,其中,所述补丁文件的代码段包括间接调用指令,所述间接调用指令包括所述被调用函数的函数签名索引。在本申请实施例中,若被调用函数为被原函数间接调用的函数,那么原函数被补丁函数替换后,被调用函数也为被补丁函数间接调用的函数;此种情况下,编译信息表还记录有被调用函数的函数索引、被调用函数的函数签名索引、原文件的元素段尺寸;从编译信息表中获取被调用函数的函数索引,将被调用函数的函数索引写入补丁文件的元素段,可以得到被调用函数的元素索引;从编译信息表中获取原文件的元素段尺寸,将原文件的元素段尺寸和被调用函数的元素索引写入补丁文件的代码段;从编译信息表中获取被调用函数的函数签名索引,将被调用函数的函数签名索引写入补丁文件的代码段中的间接调用指令后,即可实现补丁函数对该被调用函数的间接调用,从而通过补丁的方式将原函数替换为补丁函数后,补丁函数也可以间接调用原先由原函数间接调用的函数。In a possible implementation manner, the compilation information table further records the function signature index of the called function and the element segment size of the original file; the called function is indirectly called by the original function function; the compiling the code segment of the patch file according to the function index of the called function includes: acquiring the function signature index of the called function from the compilation information table; according to the function index of the called function Index compiling the element segment of the patch file 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 includes an indirect call instruction, and the indirect call instruction includes a function signature index of the called function. In the embodiment of the present application, if the called function is a function indirectly called by the original function, then after the original function is replaced by the patch function, the called function is also the function indirectly called by the patch function; in this case, the compilation information table It also records the function index of the called function, the function signature index of the called function, and the element segment size of the original file; obtains the function index of the called function from the compilation information table, and writes the function index of the called function into the patch file. Element segment, the element index of the called function can be obtained; obtain the element segment size of the original file from the compilation information table, and write the element segment size of the original file and the element index of the called function into the code segment of the patch file; from the compilation information The function signature index of the called function is obtained from the table, and after the function signature index of the called function is written into the indirect call instruction in the code segment of the patch file, the indirect call of the called function by the patch function can be realized. After replacing the original function with the patch function, the patch function can also indirectly call the function originally called indirectly by the original function.
在一种可能的实现方式中,所述方法还包括:在所述原文件的加载过程中,从所述补丁文件中获取所述被调用函数的元素索引;将所述被调用函数的元素索引添加至表格索引空间中,其中,所述表格索引空间在所述原文件的加载过程中生成。在本申请实施例中,对于间接调用,由于具体要调用的是哪个函数在编译期并不知道,只在运行时才能知道,且被调用函数并不是通过函数索引空间中该被调用函数的函数索引直接定位的,而是通过表格索引空间间接定位的,表格索引空间由原文件加载生成的;因此,在原文件的加载过程中,需要从补丁文件中获取被调用函数的元素索引,并将被调用函数的元素索引添加至表格索引空间中;如此,在运行时,补丁函数就可以从表格索引空间中获取该被调用函数的元素索引,进而定位该被调用函数,实现间接调用该被调用函数。In a possible implementation manner, the method further includes: during the loading process of the original file, acquiring the element index of the called function from the patch file; storing the element index of the called function It is added to the table index space, wherein the table index space is generated during the loading process of the original file. In the embodiment of the present application, for indirect calls, since the specific function to be called is not known at compile time, it can only be known at runtime, and the called function is not a function of the called function in the function index space. The index is located directly, but indirectly through the table index space, which is generated by loading the original file; therefore, during the loading process of the original file, the element index of the called function needs to be obtained from the patch file, and will be The element index of the calling function is added to the table index space; in this way, at runtime, the patch function can obtain the element index of the called function from the table index space, and then locate the called function and indirectly call the called function .
在一种可能的实现方式中,所述被调用函数为虚拟机导入函数;在所述从所述编译信息表中获取所述被调用函数的函数索引之前,所述方法还包括:生成所述被调用函数的函数索引;将所述被调用函数的函数索引添加至所述编译信息表中。在本申请实施例中,被调用函数为虚拟机导入函数,则编译原文件过程中生成的编译信息表中没有记录该被调用函数的函数索引,因此需要生成该被调用函数的函数索引,并将该被调用函数的函数索引添加至编译信息表中,从而有利于实现补丁函数调用该被调用函数。In a possible implementation manner, the called function is a virtual machine import function; before acquiring the function index of the called function from the compilation information table, the method further includes: generating the The function index of the called function; the function index of the called function is added to the compilation information table. In the embodiment of the present application, the called function is a virtual machine import function, and the compilation information table generated during the process of compiling the original file does not record the function index of the called function, so it is necessary to generate the function index of the called function, and The function index of the called function is added to the compilation information table, so as to facilitate the implementation of the patch function to call the called function.
在一种可能的实现方式中,所述方法还包括:在所述原文件的加载过程中,通过所述原文件的导入段将所述被调用函数添加至所述函数索引空间中。在本申请实施例中,被调用函数为虚拟机导入函数,故原文件的加载过程中生成的函数索引空间中并没有该被调用函数,因此需要通过原文件的导入段将被调用函数添加至函数索引空间中,以使得函数索引空间中存在该被调用函数;从而有利于实现补丁函数调用该被调用函数。In a possible implementation manner, the method further includes: during the loading process of the original file, adding the called function to the function index space through an import section of the original file. In the embodiment of the present application, the called function is a virtual machine import function, so the function index space generated during the loading process of the original file does not have the called function. Therefore, the called function needs to be added to the import section of the original file. in the function index space, so that the called function exists in the function index space; thus, it is beneficial to realize that the patch function calls the called function.
第二方面,本申请实施例提供了一种补丁装置,有益效果可以参见第一方面的描述,此处不再赘述。所述装置包括处理单元,所述处理单元用于:在原文件的编译过程中,生成编译信息表,其中,所述原文件为WebAssembly二进制格式的文件,所述编译信息表记录有原函数的函数索引,所述原函数为所述原文件中的函数;在补丁文件的编译过程中,根据所述编译信息表生成函数对应表,其中,所述补丁文件为WebAssembly二进制格式的文件,所述函数对应表记录有所述原函数与补丁函数的对应关系,所述补丁函数为所述补丁文件中的函数;在所述原文件的加载过程中,根据所述函数对应表将函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址,其中,所述函数索引空间在所述原文件的加载过程中生成。In the second aspect, an embodiment of the present application provides a patch device, and the beneficial effects can be found in the description of the first aspect, which will not be repeated here. The apparatus includes a processing unit, and the processing unit is configured to: in the process of compiling the original file, generate a compilation information table, wherein the original file is a file in the WebAssembly binary format, and the compilation information table records the function of the original function index, the original function is the function in the original file; in the process of compiling the patch file, a function correspondence table is generated according to the compilation information table, wherein the patch file is a file in the WebAssembly binary format, and the function The correspondence table records the correspondence between the original function and the patch function, and the patch function is a function in the patch file; during the loading process of the original file, the function index space is stored according to the function correspondence table. The function address of the original function is replaced with the function address of the patch function, wherein the function index space is generated during the loading process of the original file.
在一种可能的实现方式中,所述补丁文件中的函数有且仅有补丁函数。In a possible implementation manner, the functions in the patch file have one and only patch functions.
在一种可能的实现方式中,所述处理单元具体用于:根据所述函数对应表判断是否存在所述补丁函数;若存在所述补丁函数,则从所述补丁文件的代码段中获取所述补丁函数的函数地址;将所述函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址。In a possible implementation manner, the processing unit is specifically configured to: determine whether the patch function exists according to the function correspondence table; if the patch function exists, obtain the patch function from the code segment of the patch file the function address of the patch function; replace 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 compilation information table further records the size of the memory segment of the original file; the processing unit is further configured to: in the process of compiling the patch file, from the compilation information table to obtain the memory segment size of the original file; compile the code segment of the patch file according to the memory segment size of the original file and the data offset of the patch function.
在一种可能的实现方式中,所述编译信息表还记录有被调用函数的函数索引,所述被调用函数为被所述原函数调用的函数;所述处理单元还用于:在所述补丁文件的编译过程中,从所述编译信息表中获取所述被调用函数的函数索引;根据所述被调用函数的函数索引编译所述补丁文件的代码段。In a possible implementation manner, the compilation information table further records a function index of a called function, where the called function is a function called by the original function; the processing unit is further configured to: in the During the compilation process of the patch file, the function index of the called function is obtained from the compilation information table; the code segment of the patch file is compiled according to the function index of the called function.
在一种可能的实现方式中,所述被调用函数为被所述原函数直接调用的函数,所述补丁文件的代码段包括直接调用指令,所述直接调用指令包括所述被调用函数的函数索引。In a possible implementation manner, the called function is a function directly called by the original function, the code segment of the patch file includes a direct calling instruction, and the direct calling instruction includes a function of the called function index.
在一种可能的实现方式中,所述编译信息表还记录有所述被调用函数的函数签名索引、所述原文件的元素段尺寸;所述被调用函数为被所述原函数间接调用的函数;所述处理单元具体用于:从所述编译信息表中获取所述被调用函数的函数签名索引;根据所述被调用函数的函数索引编译所述补丁文件的元素段,以得到所述被调用函数的元素索引;根据所述原文件的元素段尺寸和所述被调用函数的元素索引编译所述补丁文件的代码段,其中,所述补丁文件的代码段包括间接调用指令,所述间接调用指令包括所述被调用函数的函数签名索引。In a possible implementation manner, the compilation information table further records the function signature index of the called function and the element segment size of the original file; the called function is indirectly called by the original function The processing unit is specifically configured to: obtain the function signature index of the called function from the compilation information table; compile the element segment of the patch file according to the function index of the called function to obtain the The element index of the called function; compile 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 includes an indirect call instruction, the The indirect call instruction includes the function signature index of the called function.
在一种可能的实现方式中,所述处理单元还用于:在所述原文件的加载过程中,从所述补丁文件中获取所述被调用函数的元素索引;将所述被调用函数的元素索引添加至表格索引空间中,其中,所述表格索引空间在所述原文件的加载过程中生成。In a possible implementation manner, the processing unit is further configured to: during the loading process of the original file, obtain the element index of the called function from the patch file; The element index is added to the table index space, wherein the table index space is generated during the loading process of the original file.
在一种可能的实现方式中,所述被调用函数为虚拟机导入函数;所述处理单元还用于:在所述从所述编译信息表中获取所述被调用函数的函数索引之前;生成所述被调用函数的函数索引;将所述被调用函数的函数索引添加至所述编译信息表中。In a possible implementation manner, the called function is a virtual machine import function; the processing unit is further configured to: before acquiring the function index of the called function from the compilation information table; generate The function index of the called function; adding the function index of the called function to the compilation information table.
在一种可能的实现方式中,所述处理单元还用于:在所述原文件的加载过程中,通过所述原文件的导入段将所述被调用函数添加至所述函数索引空间中。In a possible implementation manner, the processing unit is further configured to: during the loading process of the original file, add the called function to the function index space through an import segment 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, where the one or more programs are stored in the memory and configured to be processed by the above-mentioned process The above program includes instructions for performing the steps in the method according to any one of the above first aspects.
第四方面,本申请实施例提供了一种芯片,包括:处理器,用于从存储器中调用并运行计算机程序,使得安装有所述芯片的设备执行如上述第一方面中任一项所述的方法。In a fourth aspect, an embodiment of the present application provides a chip, including: a processor, configured to call and run a computer program from a memory, so that a device installed with the chip executes any one of the above-mentioned first aspects. Methods.
第五方面,本申请实施例提供了一种计算机可读存储介质,其存储用于电子数据交换的计算机程序,其中,所述计算机程序使得计算机执行如上述第一方面中任一项所述的方法。In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program for electronic data exchange, wherein the computer program causes a computer to execute the method described in any one of the foregoing first aspects. method.
第六方面,本申请实施例提供了一种计算机程序,所述计算机程序使得计算机执行如上述第一方面中任一项所述的方法。In a sixth aspect, an embodiment of the present application provides a computer program, where the computer program causes a computer to execute the method according to any one of the foregoing first aspects.
附图说明Description of drawings
图1是本申请实施例提供的WebAssembly文件的主要段结构及加载解析后结构的示意图。FIG. 1 is a schematic diagram of a main segment structure and a loaded and parsed structure of a WebAssembly file provided by an embodiment of the present application.
图2是本申请实施例提供的WebAssembly函数调用方式示意图。FIG. 2 is a schematic diagram of a WebAssembly function calling manner provided by an embodiment of the present application.
图3是本申请实施例提供的一种补丁方法的流程示意图。FIG. 3 is a schematic flowchart of a patching method provided by an embodiment of the present application.
图4是本申请实施例提供的WebAssembly各段加载流程示意图。FIG. 4 is a schematic diagram of a loading process of each segment of WebAssembly provided by an embodiment of the present application.
图5是本申请实施例提供的WebAssembly的函数段的原始加载流程示意图。FIG. 5 is a schematic diagram of an original loading process of a WebAssembly function segment provided by an embodiment of the present application.
图6是本申请实施例提供的WebAssembly的函数段的修正后加载流程示意图。FIG. 6 is a schematic diagram of a loading process after modification of a WebAssembly function segment provided by an embodiment of the present application.
图7是本申请实施例提供的存在函数直接调用时WebAssembly的代码段的原始编译流程示意图。FIG. 7 is a schematic diagram of an original compilation flow of a code segment of WebAssembly when a function is directly called according to an embodiment of the present application.
图8是本申请实施例提供的存在函数直接调用时WebAssembly的代码段的修正后编译流程示意图。FIG. 8 is a schematic diagram of a modified compilation flow of a WebAssembly code segment when a function is directly called according to an embodiment of the present application.
图9是本申请实施例提供的存在函数间接调用时WebAssembly的代码段的原始编译流程示意图。FIG. 9 is a schematic diagram of an original compilation flow of a code segment of WebAssembly when there is an indirect function call provided by an embodiment of the present application.
图10是本申请实施例提供的存在函数间接调用时WebAssembly的代码段的修正后编译流程示意图。FIG. 10 is a schematic diagram of a modified compilation flow of a WebAssembly code segment when there is an indirect function call provided by an embodiment of the present application.
图11是本申请实施例提供的一种WebAssembly编译过程示意图。FIG. 11 is a schematic diagram of a WebAssembly compilation process provided by an embodiment of the present application.
图12是本申请实施例提供的一种WebAssembly补丁制作过程示意图。FIG. 12 is a schematic diagram of a WebAssembly patch creation process provided by an embodiment of the present application.
图13是本申请实施例提供的一种函数索引空间修正过程示意图。FIG. 13 is a schematic diagram of a function index space correction process provided by an embodiment of the present application.
图14是本申请实施例提供的另一种WebAssembly补丁制作过程示意图。FIG. 14 is a schematic diagram of another WebAssembly patch creation process provided by an embodiment of the present application.
图15是本申请实施例提供的另一种WebAssembly编译过程示意图。FIG. 15 is a schematic diagram of another WebAssembly compilation process provided by an embodiment of the present application.
图16是本申请实施例提供的又一种WebAssembly补丁制作过程示意图。FIG. 16 is a schematic diagram of another WebAssembly patch creation process provided by an embodiment of the present application.
图17是本申请实施例提供的一种表格索引空间修正过程示意图。FIG. 17 is a schematic diagram of a table index space correction process provided by an embodiment of the present application.
图18是本申请实施例提供的一种补丁装置的结构示意图。FIG. 18 is a schematic structural diagram of a patch device provided by an embodiment of the present application.
图19是本申请实施例提供的一种补丁设备的结构示意图。FIG. 19 is a schematic structural diagram of a patch device provided by an embodiment of the present application.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make those skilled in the art better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only It is a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application.
本申请的说明书和权利要求书及上述附图中的术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其他步骤或单元。The terms "comprising" and "having", and any variations thereof, in the description and claims of this application and the above figures are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes unlisted steps or units, or optionally also includes For other steps or units inherent to these processes, methods, products or devices.
在本说明书中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本申请的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本说明书所描述的实施例可以与其它实施例相结合。Reference in this 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 present application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor a separate or alternative embodiment that is mutually exclusive of other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this specification may be combined with other embodiments.
首先,提供本申请可能涉及的缩略语和术语定义,以便于本领域技术人员理解,如表1所示。First, definitions of abbreviations and terms that may be involved in this application are provided so as to be easily understood by those skilled in the art, as shown in Table 1.
表1缩略语和术语定义表Table 1 Abbreviations and Definitions of Terms
其次,在此介绍本申请实施例涉及的相关技术知识。如下描述:Next, the relevant technical knowledge involved in the embodiments of the present application is introduced here. Described as follows:
WebAssembly是近年来由谷歌、苹果、微软等几大浏览器厂商设计并推动的一项底层代码执行规范,它被设计为一种可移植的、安全的、低尺寸的、高效的二进制格式。WebAssembly可以通过编写C/C++代码,通过编译生成二进制格式的.wasm文件,可在遵循WebAssembly规范的虚拟机中运行。WebAssembly的沙箱功能使得.wasm文件加载到运行引擎中时,实际上运行在其私有的沙箱中,沙箱中的程序不能访问沙箱以外的地址空间。WebAssembly操作码设计精简,不仅可以达到很快的编译速度,还可以获得很高的运行速度。WebAssembly的可安全运行第三方代码、超轻量级、高性能等特性在移动设备、物联网设备、智能小家电以及可信运行环境上具有很大的价值。WebAssembly is a low-level code execution specification designed and promoted by several major browser manufacturers such as Google, Apple, and Microsoft in recent years. It is designed as a portable, safe, low-size, and efficient binary format. WebAssembly can generate .wasm files in binary format by writing C/C++ code, and can run in a virtual machine that follows the WebAssembly specification. The sandbox function of WebAssembly makes the .wasm file actually run in its private sandbox when it is loaded into the runtime engine, and the programs in the sandbox cannot access the address space outside the sandbox. The WebAssembly opcode design is streamlined, which not only achieves fast compilation speed, but also high running speed. The features of WebAssembly, which can safely run third-party code, ultra-lightweight, and high-performance, are of great value in mobile devices, IoT devices, smart small appliances, and trusted operating environments.
当嵌入式设备产品需要提供类似浏览器方式来装载第三方模块时,使用WebAssembly作为媒介格式是一个非常有吸引力的方案。开发者可以把自己的算法以WebAssembly应用的方式发布。嵌入式设备通过集成WebAssembly虚拟机就可以在不同架构、不同平台、不同环境加载使用该应用。When embedded device products need to provide a browser-like way to load third-party modules, using WebAssembly as a media format is a very attractive solution. Developers can publish their own algorithms as WebAssembly applications. Embedded devices can load and use the application in different architectures, platforms, and environments by integrating the WebAssembly virtual machine.
1)WebAssembly二进制格式1) WebAssembly binary format
WebAssembly顶层结构是模块,每一个WebAssembly二进制文件对应一个模块,模块主体由多个段组成,每个段都有唯一的段号来标识,具体结构如图1所示。The top-level structure of WebAssembly is a module. Each WebAssembly binary file corresponds to a module. The main body of the module consists of multiple segments, and each segment is identified by a unique segment number. The specific structure is shown in Figure 1.
其中,因为函数涉及函数的索引、函数的类型以及函数代码等信息,所以函数由函数段、类型段和代码段共同来表示。Among them, because the function involves information such as the index of the function, the type of the function, and the function code, the function is jointly represented by the function segment, the type segment, and the code segment.
类型段:用来存放函数签名类型,包括函数的参数及返回值。Type segment: used to store the function signature type, including function parameters and return values.
代码段:存放函数的局部变量信息和执行代码信息。Code segment: Stores the local variable information and execution code information of the function.
函数段:按顺序存储了每一个函数的函数签名在类型段中的索引。Function section: Stores the index of the function signature of each function in the type section in order.
导入段:支持导入外部函数供模块调用,导入的函数由函数名和函数签名组成。Import section: Supports importing external functions for the module to call. The imported functions are composed of function names and function signatures.
表格段与元素段:可以保存函数引用,通过表格段与元素段可以实现函数指针的功能。Table segment and element segment: Function references can be saved, and the function pointer function can be realized through the table segment and element segment.
内存段:用于定义线性内存,线性内存用于存储程序运行的动态数据。Memory segment: used to define linear memory, which is used to store dynamic data for program operation.
数据段:存储初始化内存的静态数据。Data segment: Stores static data that initializes memory.
2)WebAssembly虚拟机2) WebAssembly virtual machine
WebAssembly代码(也即WebAssembly文件)运行在支持WebAssembly规范的虚拟机上,WebAssembly虚拟机通过解析加载WebAssembly二进制格式来执行WebAssembly文件。The WebAssembly code (that is, the WebAssembly file) runs on a virtual machine that supports the WebAssembly specification, and the WebAssembly virtual machine executes the WebAssembly file by parsing and loading the WebAssembly binary format.
WebAssembly虚拟机在解析加载WebAssembly文件的过程中所生成的与函数相关的结构如图1所示,包括:The function-related structure generated by the WebAssembly virtual machine in the process of parsing and loading WebAssembly files is shown in Figure 1, including:
函数索引空间:函数索引,包括所有的函数信息,包括函数签名和函数地址等;由函数段和代码段解析,函数首地址标识函数,函数签名标识函数类型,编译器记录wasm编译信息,并记录在.wasm文件中。其中,这里的函数地址是一个Webassembly虚拟地址,在函数编译时刻,编译器为函数指定。Function index space: function index, including all function information, including function signature and function address; parsed by function segment and code segment, the first address of the function identifies the function, the function signature identifies the function type, the compiler records the wasm compilation information, and records in the .wasm file. Among them, the function address here is a Webassembly virtual address, which is specified by the compiler for the function when the function is compiled.
表格索引空间:保存函数引用,用于函数的间接调用,由表格段和元素段解析。Table index space: holds function references, used for indirect calls of functions, resolved by table and element segments.
线性内存索引空间:一个地址连续的、可以进行字节寻址的内存结构,用于存储程序运行的动态数据,由内存段和数据段解析。Linear memory index space: A memory structure with contiguous addresses that can be byte-addressable, used to store dynamic data for program operation, and parsed by memory segments and data segments.
3)WebAssembly函数调用3) WebAssembly function call
WebAssembly中有两种调用函数的方式,如图2所示,包括:There are two ways to call functions in WebAssembly, as shown in Figure 2, including:
直接调用:使用call指令,call指令首先得到函数索引(func_idx),然后通过函数索引获取函数地址来调用函数;其中,函数索引由指令的立即数参数指定。Direct call: Using the call instruction, the call instruction first obtains the function index (func_idx), and then obtains the function address through the function index to call the function; the function index is specified by the immediate parameter of the instruction.
间接调用:使用call_indirect指令和表格索引空间协同完成,call_indirect指令首先取得函数签名索引(type-idx),函数签名索引放在立即数里,然后在栈内得到(表格)元素索引,再通过元素索引得到函数索引,经过动态检查函数签名,在函数签名匹配的情况下通过函数索引获取函数地址调用函数。其中,wasm规范定义模块最多只能定义一张表,且元素类型必须为函数引用(编码为0x70)。除了元素类型,表类型还需要指定元素数量的限制,其中必须指定下限,上限则可选。其中,表格索引指在表段,通过索引值,拿到间接调用的函数引用(函数首地址)。其中,立即数就是索引,在表格段索引处获得的指,就是间接调用的函数引用(函数首地址)。Indirect call: use the call_indirect instruction and the table index space to complete, the call_indirect instruction first obtains the function signature index (type-idx), the function signature index is placed in the immediate value, and then the (table) element index is obtained in the stack, and then the element index is passed. The function index is obtained, and the function signature is dynamically checked. If the function signature matches, the function address is obtained through the function index and the function is called. Among them, the wasm specification defines that the module can only define at most one table, and the element type must be a function reference (encoded as 0x70). In addition to the element type, the table type also needs to specify a limit on the number of elements, where a lower limit must be specified, and an upper limit is optional. Among them, the table index refers to the function reference (the first address of the function) that is indirectly called in the table segment through the index value. Among them, the immediate value is the index, and the index obtained at the table segment index is the function reference (function first address) of the indirect call.
再次,为了便于理解本申请实施例,进一步分析并提出本申请所具体要解决的技术问题。如下描述:Thirdly, in order to facilitate the understanding of the embodiments of the present application, the technical problems to be solved by the present application are further analyzed and proposed. Described as follows:
现在还未有针对WebAssembly应用实现的补丁方案,如需替换WebAssembly文件中的特定函数,则需要重新编译整个源文件,得到替换函数后的新二进制格式的.wasm文件,以新版本应用的形式在WebAssembly虚拟机中进行加载运行。然而,重新生成WebAssembly二进制文件的方式具有以下缺点:There is no patch solution implemented for WebAssembly applications yet. If you want to replace a specific function in the WebAssembly file, you need to recompile the entire source file to get the .wasm file in the new binary format after the function is replaced, which is in the form of a new version of the application. Load and run in the WebAssembly virtual machine. However, the way to regenerate WebAssembly binaries has the following disadvantages:
1)使得整个应用文件数据多、体积较大,下载、替换、加载需要的时间较长,无法做到轻量且快速更新。1) The entire application file has a lot of data and a large volume, and it takes a long time to download, replace, and load, and it cannot be lightweight and quickly updated.
2)在WebAssembly应用需要频繁更新局部代码而不想影响应用版本的情况下,如果每次都重新生成新版本的.wasm文件,应用版本号也在不断地增长,造成了版本的冗余。2) In the case that the WebAssembly application needs to update the local code frequently without affecting the application version, if a new version of the .wasm file is regenerated every time, the application version number is also constantly increasing, resulting in version redundancy.
鉴于上述分析存在的问题,本申请提出一种针对WebAssembly的补丁编译和加载方法,针对WebAssembly二进制格式制作补丁文件,实现了使用补丁对WebAssembly应用进行函数级别的替换和更新。本申请的创新点包括:针对WebAssembly格式进行补丁的制作与加载,主要表现在以下两方面:In view of the problems existing in the above analysis, this application proposes a method for compiling and loading patches for WebAssembly, making patch files for the WebAssembly binary format, and realizing the function-level replacement and update of WebAssembly applications using patches. The innovations of this application include: making and loading patches for the WebAssembly format, mainly in the following two aspects:
1)补丁制作1) Patch making
编译阶段:使用C/C++开发的应用,编译为WebAssembly二进制格式的.wasm文件,在编译过程中记录编译信息,包括函数名和函数索引的对应关系等,生成并导出编译信息表,该编译信息表包括函数索引表等。Compilation stage: The application developed in C/C++ is compiled into a .wasm file in WebAssembly binary format, the compilation information is recorded during the compilation process, including the correspondence between function names and function indexes, etc., and the compilation information table is generated and exported. The compilation information table Including function index table and so on.
制作补丁阶段:根据WebAssembly应用导出的编译信息表编译WebAssembly补丁文件,同时在编译补丁文件期间对代码段进行修正。其中,编译补丁文件期间,指的是编译补丁文件的制作,对代码段进行修正指替换引用原函数的引用为补丁文件中补丁函数的引用。Patch making phase: Compile the WebAssembly patch file according to the compilation information table exported by the WebAssembly application, and at the same time correct the code segment during the compilation of the patch file. Wherein, the period of compiling the patch file refers to the production of the compiling patch file, and revising the code segment refers to replacing the reference of the original function with the reference of the patch function in the patch file.
2)补丁加载2) Patch loading
加载阶段:在加载时对函数索引空间中的函数地址进行替换,将原函数地址替换为补丁函数地址。其中,函数地址是指函数代码块首地址,也被称为函数代码地址、函数的代码地址、函数代码块的首地址。如补丁函数涉及其他函数调用,需要修正表格索引空间。Loading stage: Replace the function address in the function index space during loading, and replace the original function address with the patch function address. The function address refers to the first address of the function code block, which is also called the function code address, the function code address, and the first address of the function code block. If the patch function involves other function calls, the table index space needs to be corrected.
本申请应用在WebAssembly应用升级更新或应用缺陷修复等场景下。由于补丁文件体积较小,下载、加载所需时间短,从而使得WebAssembly应用升级更新或应用缺陷修复时间缩短。This application is applied in scenarios such as WebAssembly application upgrade and update or application defect repair. Due to the small size of the patch file, the time required for downloading and loading is short, which shortens the time for updating WebAssembly applications or repairing application defects.
请参阅图3,图3是本申请实施例提供的一种补丁方法的流程示意图,该方法包括但不限于如下步骤:Please refer to FIG. 3. FIG. 3 is a schematic flowchart of a patching method provided by an embodiment of the present application. The method includes but is not limited to the following steps:
301、在原文件的编译过程中,生成编译信息表,其中,所述原文件为WebAssembly二进制格式的文件,所述编译信息表记录有原函数的函数索引,所述原函数为所述原文件中的函数。301. In the compilation process of the original file, a compilation information table is generated, wherein the original file is a file in the WebAssembly binary format, and the compilation information table records the function index of the original function, and the original function is in the original file. The function.
302、在补丁文件的编译过程中,根据所述编译信息表生成函数对应表,其中,所述补丁文件为WebAssembly二进制格式的文件,所述函数对应表记录有所述原函数与补丁函数的对应关系,所述补丁函数为所述补丁文件中的函数。302. During the compilation process of the patch file, generate a function correspondence table according to the compilation information table, wherein the patch file is a file in the WebAssembly binary format, and the function correspondence table records the correspondence between the original function and the patch function. relationship, the patch function is a function in the patch file.
303、在所述原文件的加载过程中,根据所述函数对应表将函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址,其中,所述函数索引空间在所述原文件的加载过程中生成。303. During the loading process of the original file, replace the function address of the original function in the function index space with the function address of the patch function according to the function correspondence table, wherein the function index space is in the generated during the loading process of the original file described above.
其中,编译信息表包括函数索引表,函数索引表中记录有原文件中的所有函数的函数索引;函数对应表中记录有所有需要被替换的原函数与其对应的补丁函数的对应关系。The compilation information table includes a function index table, which records the function indexes of all functions in the original file; the function correspondence table records the correspondence between all original functions that need to be replaced and their corresponding patch functions.
应理解,WebAssembly二进制格式的原文件和补丁文件可以通过先编写C/C++源代码,再编译成.wasm文件得到。在原文件的编译过程中,指从其他格式的文件编译成WebAssembly二进制格式的原文件的过程中;在补丁文件的编译过程中,指从其他格式的文件编译成WebAssembly二进制格式的补丁文件的过程中。It should be understood that the original files and patch files in the WebAssembly binary format can be obtained by first writing C/C++ source codes and then compiling them into .wasm files. In the process of compiling the original file, it refers to the process of compiling from other formats to the original file in WebAssembly binary format; in the process of compiling the patch file, it refers to the process of compiling from other formats into the patch file in WebAssembly binary format. .
示例性的,所述根据所述编译信息表生成函数对应表,包括:从所述编译信息表中获取所述原函数的函数索引;根据所述原函数的函数索引和所述补丁函数的函数索引生成所述函数对应表。函数对应表中可以记录原函数的索引与补丁函数的函数索引,两者是关联记录在函数对应表中的。例如,在补丁文件的编译过程中,从编译信息表中获取原函数的函数索引,从补丁文件中获取补丁函数的函数索引,将原函数的函数索引和补丁函数的函数索引关联记录在函数对应表上,从而生成函数对应表。Exemplarily, the generating a function correspondence table according to the compilation information table includes: acquiring a function index of the original function from the compilation information table; according to the function index of the original function and the function of the patch function The index generates the function correspondence table. The function correspondence table can record the index of the original function and the function index of the patch function, and the two are associated and recorded in the function correspondence table. For example, in the process of compiling the patch file, the function index of the original function is obtained from the compilation 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 associated and recorded in the corresponding function of the function. table, so as to generate a function corresponding table.
需要说明的是,本申请实施例所描述的原函数或补丁函数并非指一个函数,而是指一类函数,其可能有多个;例如,原函数指需要被补丁的函数的统称,原文件中可能存在多个需要被替换的函数,这多个需要被替换的函数也即统称为原函数;补丁函数指用于补丁的函数的统称,补丁文件中可能存在多个用于替换原文件中的原函数的函数,这多个用于替换原文件中的原函数的函数统称为补丁函数。It should be noted that the original function or patch function described in the embodiments of this application does not refer to one function, but refers to a type of function, which may have multiple; There may be multiple functions that need to be replaced in the patch file, and these multiple functions that need to be replaced are collectively referred to as the original function; the patch function refers to the general name of the functions used for patching, and there may be multiple functions in the patch file that are used to replace the original file. The functions of the original function, these multiple functions used to replace the original function in the original file are collectively referred to as patch functions.
在本申请实施例中,在编译得到WebAssembly二进制格式的原文件的过程中,生成编译信息表,该编译信息表记录有原文件中的原函数的函数索引;在编译得到WebAssembly二进制格式的补丁文件的过程中,根据编译信息表中的原函数的函数索引以及补丁文件中的补丁函数的函数索引生成函数对应表,函数对应表记录有原函数与补丁函数的对应关系;也即从编译信息表中获取原函数的函数索引,从补丁文件中获取补丁函数的函数索引,将原函数的函数索引和补丁函数的函数索引关联记录在函数对应表上,从而生成函数对应表;在加载原文件的过程中,会生成函数索引空间,函数索引空间中记录有原函数的函数地址,而函数对应表记录有原函数和补丁函数的对应关系,因此可以从补丁文件中获取补丁函数的函数地址,然后根据函数对应表记录的原函数和补丁函数的对应关系,将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址;由于在函数索引空间中,原函数的函数地址替换为了补丁函数的函数地址,后期函数应用时执行的函数即为补丁函数,从而实现使用补丁对WebAssembly应用进行函数级的替换和更新。In the embodiment of the present application, in the process of compiling to obtain the original file in the WebAssembly binary format, a compilation information table is generated, and the compilation information table records the function index of the original function in the original file; after compiling to obtain the patch file in the WebAssembly binary format In the process of compiling, a function correspondence table is generated according to the function index of the original function in the compilation information table and the function index of the patch function in the patch file, and the function correspondence table records the correspondence between the original function and the patch function; that is, from the compilation information table Obtain the function index of the original function from , obtain the function index of the patch function from the patch file, record the function index of the original function and the function index of the patch function in the function correspondence table, thereby generating the function correspondence table; During the process, a function index space will be generated. The function index space records the function address of the original function, and the function correspondence table records the corresponding relationship between the original function and the patch function. Therefore, the function address of the patch function can be obtained from the patch file, and then According to the correspondence between the original function and the patch function recorded in the function correspondence table, replace the function address of the original function in the function index space with the function address of the patch function; because in the function index space, the function address of the original function is replaced by the patch function The function address of the later function application is the patch function, so as to realize the function-level replacement and update of the WebAssembly application using the patch.
在一种可能的实现方式中,所述补丁文件中的函数有且仅有补丁函数。In a possible implementation manner, the functions in the patch file have one and only patch functions.
具体地,补丁文件的源代码,有且仅有原文件中需要补丁的函数及模块,表现为补丁文件中任何一个函数都是有益补丁的函数,也即补丁文件中的函数都是补丁函数。Specifically, the source code of the patch file contains only functions and modules that need to be patched in the original file, which means that any function in the patch file is a useful patch function, that is, the functions in the patch file are all patch functions.
在本申请实施例中,补丁文件中的函数有且仅有所述补丁函数,也即补丁文件中任何一个函数都是有益补丁的函数,有利于使得补丁文件体积较小、下载和加载所需时间短。In the embodiment of the present application, the functions in the patch file include and only the patch function, that is, any function in the patch file is a function that is beneficial to the patch, which is conducive to making the patch file smaller in size and required for downloading and loading. short time.
在一种可能的实现方式中,所述根据所述函数对应表将函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址,包括:根据所述函数对应表判断是否存在所述补丁函数;若存在所述补丁函数,则从所述补丁文件的代码段中获取所述补丁函数的函数地址;将所述函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址。In a possible implementation manner, the 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 correspondence table includes: judging whether or not according to the function correspondence table The patch function exists; if the patch function exists, obtain the function address of the patch function from the code segment of the patch file; replace the function address of the original function in the function index space with the The function address of the patch function described above.
具体地,在原文件的函数段加载过程中,根据函数对应表判断是否存在补丁函数,在存在补丁函数的时候,从补丁文件的代码段中获取补丁函数的函数地址,并将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址。Specifically, in the process of loading the function segment of the original file, it is judged whether there is a patch function according to the function correspondence table. When there is a patch function, the function address of the patch function is obtained from the code segment of the patch file, and the function address in the function index space is The function address of the original function is replaced with the function address of the patch function.
其中,WebAssembly各个段加载流程如图4所示,各个段的加载顺序依次为:类型段、导入段、函数段、表格段、内存段、全局段、导出段、开始段、元素段、代码段、数据段。The loading process of each segment of WebAssembly is shown in Figure 4. The loading sequence of each segment is: type segment, import segment, function segment, table segment, memory segment, global segment, export segment, start segment, element segment, and code segment. , data segment.
其中,WebAssembly的函数段的原始加载流程如图5所示,包括以下步骤:Among them, the original loading process of the function segment of WebAssembly is shown in Figure 5, including the following steps:
501、判断已加载函数数量是否小于函数总数。其中,若已加载函数数量不小于函数总数,说明所有函数都加载完了,则结束加载函数段的流程。501. Determine whether the number of loaded functions is less than the total number of functions. Among them, if the number of loaded functions is not less than the total number of functions, it means that all functions have been loaded, and the process of loading the function segment ends.
502、若已加载函数数量小于函数总数,则从函数段中获取函数签名索引。也即,获取还未加载的函数的函数签名索引。502. If the number of loaded functions is less than the total number of functions, obtain the function signature index from the function segment. That is, get the function signature index of a function that has not yet been loaded.
503、从代码段中获取函数的函数地址。其中,通过函数签名索引从代码段获取函数的函数地址。503. Obtain the function address of the function from the code segment. Among them, the function address of the function is obtained from the code segment through the function signature index.
504、将函数添加至函数索引空间。也即,将函数的函数签名、函数地址等添加到函数索引空间。504. Add the function to the function index space. That is, add the function signature, function address, etc. of the function to the function index space.
应理解,WebAssembly的函数段的原始加载流程中,对于每个函数,从函数段中获取函数签名索引等信息,在代码段中获取相应的函数代码块的首地址(也即函数地址),获取到该函数的所有数据后,将该函数添加至函数索引空间中。It should be understood that in the original loading process of the function segment of WebAssembly, for each function, information such as the function signature index is obtained from the function segment, and the first address (that is, the function address) of the corresponding function code block is obtained in the code segment, and the After all the data for the function is available, the function is added to the function index space.
前文描述了WebAssembly的函数段的原始加载流程,在需要加载补丁的场景下,由于需要保持函数接口一致,故原函数与补丁函数的函数名称、函数签名是一致的,所以在加载阶段只需要修正函数索引空间中补丁函数的函数地址。本申请通过修改WebAssembly函数段的原始加载流程,在函数段加载过程中修正补丁函数的函数地址,从而实现补丁函数对原函数的替换。本申请实施例提供的WebAssembly的函数段的修正后加载流程如图6所示,包括以下步骤:The original loading process of the WebAssembly function segment is described above. In the scenario where the patch needs to be loaded, since the function interface needs to be kept consistent, the function name and function signature of the original function and the patch function are consistent, so only need to be corrected in the loading stage. The function address of the patch function in the function index space. The present application modifies the original loading process of the WebAssembly function segment, and corrects the function address of the patch function during the loading process of the function segment, thereby realizing the replacement of the original function by the patch function. The modified loading process of the WebAssembly function segment provided by the embodiment of the present application is shown in FIG. 6 , and includes the following steps:
601、判断已加载函数数量是否小于函数总数。其中,若已加载函数数量不小于函数总数,说明所有函数都加载完了,则结束加载函数段的流程。601. Determine whether the number of loaded functions is less than the total number of functions. Among them, if the number of loaded functions is not less than the total number of functions, it means that all functions have been loaded, and the process of loading the function segment ends.
602、若已加载函数数量小于函数总数,则从函数段中获取函数签名索引;也即获取还未加载的函数的函数签名索引。应理解,函数签名即一个函数的函数名、参数列表、返回类型的统称,函数签名索引包括函数索引等。602. If the number of loaded functions is less than the total number of functions, obtain the function signature index from the function segment; that is, obtain the function signature index of the function that has not been loaded yet. It should be understood that a function signature is a general name of a function's function name, parameter list, and return type, and the function signature index includes a function index and the like.
603、查找函数对应表。其中,函数对应表记录有原函数索引与补丁函数的函数索引。603. Find a function corresponding table. The function correspondence table records the original function index and the function index of the patch function.
604、判断是否存在补丁函数。也即,根据函数对应表中记录的原函数与补丁函数的对应关系来判断是否存在补丁函数;当函数对应表中记录有原函数与补丁函数的对应关系时,说明存在补丁函数;当函数对应表中没有记录原函数与补丁函数的对应关系时,说明不存在补丁函数。604. Determine whether a patch function exists. That is, according to the correspondence between the original function and the patch function recorded in the function correspondence table, it is judged whether there is a patch function; when the correspondence between the original function and the patch function is recorded in the function correspondence table, it means that there is a patch function; when the function corresponds to If the corresponding relationship between the original function and the patch function is not recorded in the table, it means that there is no patch function.
605、若不存在补丁函数,则从原文件的代码段中获取函数的函数地址。605. If the patch function does not exist, obtain the function address of the function from the code segment of the original file.
606、若存在补丁函数,则从补丁文件的代码段中获取函数的函数地址。606. If the patch function exists, obtain the function address of the function from the code segment of the patch file.
607、将函数添加至函数索引空间。607. Add the function to the function index space.
需要说明的是,本申请实施例提供的WebAssembly的函数段的加载流程,对于每个函数,从原函数(原文件)的函数段中获取函数签名索引等信息,与WebAssembly的函数段的原始加载流程不同的是,本申请添加了识别补丁函数、修正补丁函数地址的步骤,如果该函数需替换为补丁函数,则从补丁文件代码段获取相应函数代码块的首地址,否则仍从原文件代码段中获取相应函数代码块的首地址,最后在获取到该函数的所有数据后,函数地址替换已经完成,将该函数添加至函数索引空间中。It should be noted that, in the loading process of the WebAssembly function segment provided by the embodiment of the present application, for each function, information such as the function signature index is obtained from the function segment of the original function (original file), which is consistent with the original loading of the WebAssembly function segment. The difference in the process is that this application adds the steps of identifying the patch function and correcting the address of the patch function. If the function needs to be replaced with a patch function, the first address of the corresponding function code block is obtained from the patch file code segment, otherwise, the original file code is still used. The first address of the corresponding function code block is obtained in the segment. Finally, after all the data of the function is obtained, the function address replacement has been completed, and the function is added to the function index space.
在本申请实施例中,在原文件的加载过程中,从原文件中获取原函数的函数地址,添加到函数索引空间中;当需要打补丁时,可以通过函数对应表来判断是否需要对原函数进行替换,当函数对应表中记录有原函数与补丁函数的对应关系时,说明需要将原函数替换为补丁函数,如此可以根据函数对应表判断是否存在补丁函数,如果存在补丁函数,则从补丁文件的代码段中获取补丁函数的函数地址,再将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址;或者说,不将原函数的函数地址添加到函数索引空间,而是将补丁函数的函数地址添加到函数索引空间,从而实现补丁函数对原函数的替换。In the embodiment of the present application, during the loading process of the original file, the function address of the original function is obtained from the original file and added to the function index space; when patching is required, the function correspondence table can be used to determine whether the original function needs to be updated. Replace, when the corresponding relationship between the original function and the patch function is recorded in the function correspondence table, it indicates that the original function needs to be replaced with a patch function. In this way, it can be judged whether there is a patch function according to the function correspondence table. Obtain the function address of the patch function from the code segment of the file, and then replace the function address of the original function in the function index space with the function address of the patch function; in other words, instead of adding the function address of the original function to the function index space, The function address of the patch function is added to the function index space, thereby realizing the replacement of the original function by the patch function.
在一种可能的实现方式中,所述编译信息表还记录有所述原文件的内存段尺寸;所述方法还包括:在所述补丁文件的编译过程中,从所述编译信息表中获取所述原文件的内存段尺寸;根据所述原文件的内存段尺寸和所述补丁函数的数据偏移量编译所述补丁文件的代码段。In a possible implementation manner, the compilation information table further records the size of the memory segment of the original file; the method further includes: during the compilation process of the patch file, obtaining from the compilation information table The size of the memory segment of the original file; the code segment of the patch file is compiled according to the size of the memory segment of the original file and the data offset of the patch function.
其中,当补丁函数涉及内存操作时,要对补丁文件的代码段的内存操作进行修正;此种情况下,编译原文件的过程中生成的编译信息表中还记录有原文件的内存段尺寸。Wherein, when the patch function involves memory operation, the memory operation of the code segment of the patch file should be corrected; in this case, the size of the memory segment of the original file is also recorded in the compilation information table generated during the process of compiling the original file.
举例来说,假设原文件中有6个函数,分别为函数A(在内存段中占用的内存为0-100)、函数B(在内存段中占用的内存为100-300)、函数C(在内存段中占用的内存为300-400)、函数D(在内存段中占用的内存为400-600)、函数E(在内存段中占用的内存为600-800)、函数F(在内存段中占用的内存为800-1200),故原文件的内存段尺寸为0-1200;假设函数D需要被替换为函数D’,函数D’的数据偏移量为300,将函数D’占用的内存安排在1200-1500,从而新的数据偏移量为1200+300=1500,将数据偏移量为1500写入补丁文件的代码段。For example, suppose there are 6 functions in the original file, namely 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), the function D (the memory occupied in the memory segment is 400-600), the function E (the memory occupied in the memory segment is 600-800), the function F (the memory occupied in the memory segment is 600-800) The memory occupied in the segment is 800-1200), so the memory segment size of the original file is 0-1200; assuming that function D needs to be replaced with function D', the data offset of function D' is 300, and function D' is occupied by The memory is arranged at 1200-1500, so the new data offset is 1200+300=1500, and the data offset 1500 is written to the code segment of the patch file.
在本申请实施例中,若补丁函数涉及内存操作,则需要对补丁文件的代码段的内存操作进行修正;此种情况下,编译原文件的过程中生成的编译信息表中还记录有原文件的内存段尺寸;在编译得到补丁文件的过程中,从编译信息表中获取原文件的内存段尺寸,将原文件的内存段尺寸和补丁函数的数据偏移量作为新的偏移量,写入补丁文件的代码段,从而使得补丁函数可以正常进行内存操作。In the embodiment of the present application, if the patch function involves a memory operation, the memory operation of the code segment of the patch file needs to be corrected; in this case, the compilation information table generated in the process of compiling the original file also records the original file In the process of compiling and obtaining the patch file, the memory segment size of the original file is obtained from the compilation information table, and the memory segment size of the original file and the data offset of the patch function are used as the new offset, and write Enter the code segment of the patch file, so that the patch function can perform memory operations normally.
在一种可能的实现方式中,所述编译信息表还记录有被调用函数的函数索引,所述被调用函数为被所述原函数调用的函数;所述方法还包括:在所述补丁文件的编译过程中,从所述编译信息表中获取所述被调用函数的函数索引;根据所述被调用函数的函数索引编译所述补丁文件的代码段。In a possible implementation manner, the compilation information table further records a function index of a called function, and the called function is a function called by the original function; the method further includes: in the patch file During the compiling process, the function index of the called function is obtained from the compilation information table; the code segment of the patch file is compiled according to the function index of the called function.
需要说明的是,当原函数存在函数调用的情况时,在编译得到补丁文件的过程中,需要修正补丁函数内函数调用的相关指令代码段,以保证函数间调用关系的正确性,故需要根据原函数的被调用函数的函数索引来编译补丁文件的代码段。It should be noted that when there is a function call in the original function, in the process of compiling the patch file, the relevant instruction code segment of the function call in the patch function needs to be corrected to ensure the correctness of the calling relationship between the functions. The function index of the called function of the original function to compile the code segment of the patch file.
在本申请实施例中,若原函数涉及调用其他函数,则当原函数被替换为补丁函数后,补丁函数也涉及调用原先由原函数调用的函数,需要对补丁文件的代码段进行修正;此种情况下,编译信息表还记录有被调用函数的函数索引,被调用函数为被原函数调用的函数;在编译得到补丁文件的过程中,从编译信息表中获取被调用函数的函数索引,将被调用函数的函数索引编译写入补丁文件的代码段,从而通过补丁的方式将原函数替换为补丁函数后,补丁函数也可以调用原先由原函数调用的函数。In the embodiment of the present application, if the original function involves calling other functions, after the original function is replaced by the patch function, the patch function also involves calling the function originally called by the original function, and the code segment of the patch file needs to be corrected; this kind of In this case, the compilation information table also records the function index of the called function, and the called function is the function called by the original function; in the process of compiling to obtain the patch file, the function index of the called function is obtained from the compilation information table, and the The function index of the called function compiles the code segment written into the patch file, so that after replacing the original function with the patch function by means of a patch, 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 original function, the code segment of the patch file includes a direct calling instruction, and the direct calling instruction includes a function of the called function index.
函数的直接调用时,被调用函数通过函数索引空间的函数索引直接定位,所以需要更新代码段的直接调用(call)指令后的函数索引。When a function is called directly, the called function is located directly by the function index in the function index space, so the function index after the direct call instruction of the code segment needs to be updated.
其中,存在函数直接调用时WebAssembly的代码段的原始编译流程如图7所示,包括以下步骤:Among them, the original compilation process of the WebAssembly code segment when the function is directly called is shown in Figure 7, including the following steps:
701、编译时获取被调用函数的函数索引(fun_id)。701. Obtain the function index (fun_id) of the called function during compilation.
702、将直接调用指令(call fun_id)写入代码段。702. Write the direct call instruction (call fun_id) into the code segment.
例如,在编译原文件的代码段时,可执行图7所示的流程。For example, when compiling the code segment of the original file, the flow shown in FIG. 7 can be executed.
需要说明的是,本申请实施例引入了补丁,因此需要对代码段的编译流程进行修正。对于补丁文件的编译,从编译信息表中获取被调用的函数索引,修正补丁文件的代码段。图8是本申请实施例提供的存在函数直接调用时WebAssembly的代码段的修正后编译流程示意图,包括以下步骤:It should be noted that the embodiment of the present application introduces a patch, so the compilation process of the code segment needs to be corrected. For the compilation of the patch file, the function index to be called is obtained from the compilation information table, and the code segment of the patch file is corrected. 8 is a schematic diagram of a post-correction compilation flow diagram of a code segment of WebAssembly when there is a direct invocation of a function provided by an embodiment of the present application, including the following steps:
801、判断文件是否为补丁文件。也即,判断当前编译的文件是否为补丁文件。801. Determine whether the file is a patch file. That is, it is determined whether the currently compiled file is a patch file.
802、若文件不是补丁文件,则编译时获取被调用函数的函数索引(fun_id)。若当前编译的文件不是补丁文件时,也即当前编译的文件是原文件时,编译过程与代码段的原始编译过程相同。802. If the file is not a patch file, obtain the function index (fun_id) of the called function during compilation. If the currently compiled file is not a patch file, that is, when the currently compiled file is the original file, the compilation process is the same as the original compilation process of the code segment.
803、若文件是补丁文件,则从编译信息表中获取被调用函数的函数索引(fun_id)。803. If the file is a patch file, obtain the function index (fun_id) of the called function from the compilation information table.
804、将直接调用指令(call fun_id)写入代码段。804. Write the direct call instruction (call fun_id) into the code segment.
在本申请实施例中,若被调用函数为被原函数直接调用的函数,那么原函数被补丁函数替换后,被调用函数也为被补丁函数直接调用的函数;此种情况下,编译信息表还记录有被调用函数的函数索引;因此,从编译信息表中获取被调用函数的函数索引,将被调用函数的函数索引写入补丁文件的代码段的直接调用指令后,即可实现补丁函数对该被调用函数的直接调用,从而通过补丁的方式将原函数替换为补丁函数后,补丁函数也可以直接调用原先由原函数直接调用的函数。In the embodiment of the present application, if the called function is a function directly called by the original function, then after the original function is replaced by the patch function, the called function is also the function directly called by the patch function; in this case, the compilation information table The function index of the called function is also recorded; therefore, after obtaining the function index of the called function from the compilation information table, and writing the function index of the called function into the direct calling instruction of the code segment of the patch file, the patch function can be implemented. After directly calling the called function, after replacing the original function with the patch function by means of a patch, the patch function can also directly call the function originally called directly by the original function.
在一种可能的实现方式中,所述编译信息表还记录有所述被调用函数的函数签名索引、所述原文件的元素段尺寸;所述被调用函数为被所述原函数间接调用的函数;所述根据所述被调用函数的函数索引编译所述补丁文件的代码段,包括:从所述编译信息表中获取所述被调用函数的函数签名索引;根据所述被调用函数的函数索引编译所述补丁文件的元素段,以得到所述被调用函数的元素索引;根据所述原文件的元素段尺寸和所述被调用函数的元素索引编译所述补丁文件的代码段,其中,所述补丁文件的代码段包括间接调用指令,所述间接调用指令包括所述被调用函数的函数签名索引。In a possible implementation manner, the compilation information table further records the function signature index of the called function and the element segment size of the original file; the called function is indirectly called by the original function function; the compiling the code segment of the patch file according to the function index of the called function includes: acquiring the function signature index of the called function from the compilation information table; according to the function index of the called function Index compiling the element segment of the patch file 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 includes an indirect call instruction, and the indirect call instruction includes a function signature index of the called function.
其中,编译信息表还包括函数签名索引表,函数签名索引表中记录有被调用函数的函数签名索引;编译信息表还包括原文件的元素段尺寸。The compilation information table further includes a function signature index table, in which the function signature index of the called function is recorded; the compilation information table also includes the size of the element segment of the original file.
对于函数的间接调用,由于具体要调用的是哪个函数在编译期并不知道,只在运行时才能知道,被调用函数并不是通过函数索引空间的函数索引直接定位,而是从表格索引空间中间接定位,所以在编译时需要更新元素段中的元素项。For the indirect call of a function, since the specific function to be called is not known at compile time, it can only be known at runtime. The called function is not located directly through the function index of the function index space, but is located from the table index space. Indirect positioning, so the element items in the element section need to be updated at compile time.
其中,存在函数间接调用时WebAssembly的代码段的原始编译流程如图9所示,包括以下步骤:Among them, the original compilation process of the WebAssembly code segment when there is an indirect function call is shown in Figure 9, including the following steps:
901、编译时获取被调用函数的函数索引(fun_id)。901. Obtain the function index (fun_id) of the called function during compilation.
902、编译时获取被调用函数的函数签名索引(type_id)。902. Obtain the function signature index (type_id) of the called function during compilation.
903、将被调用函数的函数索引(fun_id)写入元素段,获得被调用函数的元素索引(elem_id)。903. Write the function index (fun_id) of the called function into the element segment, and obtain the element index (elem_id) of the called function.
904、将被调用函数的元素索引(elem_id)写入代码段。904. Write the element index (elem_id) of the called function into the code segment.
905、将间接调用指令(call_indirent type_id)写入代码段。905. Write the indirect call instruction (call_indirent type_id) into the code segment.
需要说明的是,本申请实施例引入了补丁,因此需要对代码段的编译流程进行修正。若编译补丁文件,则从函数索引表中获取被调用函数的函数索引,从函数签名索引表中获取被调用函数的函数签名索引,获取元素段尺寸,同时修正元素段与代码段。图10是本申请实施例提供的存在函数间接调用时WebAssembly的代码段的修正后编译流程示意图,包括以下步骤:It should be noted that the embodiment of the present application introduces a patch, so the compilation process of the code segment needs to be corrected. 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 modified at the same time. 10 is a schematic diagram of a post-correction compilation flow diagram of a code segment of WebAssembly when there is an indirect function call provided by an embodiment of the present application, including the following steps:
1001、文件是否为补丁文件。也即,判断当前编译的文件是否为补丁文件。1001. Whether the file is a patch file. That is, it is determined whether the currently compiled file is a patch file.
1002、若文件不是补丁文件,则编译时获取被调用函数的函数索引(fun_id)。若当前编译的文件不是补丁文件,也即当前编译的文件是原文件时,编译过程与代码段的原始编译过程相同。1002. If the file is not a patch file, obtain the function index (fun_id) of the called function during compilation. If the currently compiled file is not a patch file, that is, when the currently compiled file is the original file, the compilation process is the same as the original compilation process of the code segment.
1003、若文件不是补丁文件,则编译时获取被调用函数的函数签名索引(type_id)。1003. If the file is not a patch file, obtain the function signature index (type_id) of the called function during compilation.
1004、若文件是补丁文件,则从编译信息表中获取被调用函数的函数索引(fun_id)。1004. If the file is a patch file, obtain the function index (fun_id) of the called function from the compilation information table.
1005、若文件是补丁文件,则从编译信息表中获取被调用函数的函数签名索引(type_id)。1005. If the file is a patch file, obtain the function signature index (type_id) of the called function from the compilation information table.
1006、将被调用函数的函数索引(fun_id)写入元素段,获得被调用函数的元素索引(elem_id)。1006. Write 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、若文件不是补丁文件,则将被调用函数的元素索引(elem_id)写入代码段。1007. If the file is not a patch file, write the element index (elem_id) of the called function into the code segment.
1008、若文件是补丁文件,则将被调用函数的元素索引(elem_id)和元素段尺寸(table_size)写入代码段。1008. If the file is a patch file, write the element index (elem_id) and element segment size (table_size) of the called function into the code segment.
1009、将间接调用指令(call_indirent type_id)写入代码段。1009. Write the indirect call instruction (call_indirent type_id) into the code segment.
在本申请实施例中,若被调用函数为被原函数间接调用的函数,那么原函数被补丁函数替换后,被调用函数也为被补丁函数间接调用的函数;此种情况下,编译信息表还记录有被调用函数的函数索引、被调用函数的函数签名索引、原文件的元素段尺寸;从编译信息表中获取被调用函数的函数索引,将被调用函数的函数索引写入补丁文件的元素段,可以得到被调用函数的元素索引;从编译信息表中获取原文件的元素段尺寸,将原文件的元素段尺寸和被调用函数的元素索引写入补丁文件的代码段;从编译信息表中获取被调用函数的函数签名索引,将被调用函数的函数签名索引写入补丁文件的代码段中的间接调用指令后,即可实现补丁函数对该被调用函数的间接调用,从而通过补丁的方式将原函数替换为补丁函数后,补丁函数也可以间接调用原先由原函数间接调用的函数。In the embodiment of the present application, if the called function is a function indirectly called by the original function, then after the original function is replaced by the patch function, the called function is also the function indirectly called by the patch function; in this case, the compilation information table It also records the function index of the called function, the function signature index of the called function, and the element segment size of the original file; obtains the function index of the called function from the compilation information table, and writes the function index of the called function into the patch file. Element segment, the element index of the called function can be obtained; obtain the element segment size of the original file from the compilation information table, and write the element segment size of the original file and the element index of the called function into the code segment of the patch file; from the compilation information The function signature index of the called function is obtained from the table, and after the function signature index of the called function is written into the indirect call instruction in the code segment of the patch file, the indirect call of the called function by the patch function can be realized. After replacing the original function with the patch function, the patch function can also indirectly call the function originally called indirectly by the original function.
在一种可能的实现方式中,所述方法还包括:在所述原文件的加载过程中,从所述补丁文件中获取所述被调用函数的元素索引;将所述被调用函数的元素索引添加至表格索引空间中,其中,所述表格索引空间在所述原文件的加载过程中生成。In a possible implementation manner, the method further includes: during the loading process of the original file, acquiring the element index of the called function from the patch file; storing the element index of the called function It is added to the table index space, wherein the table index space is generated during the loading process of the original file.
在本申请实施例中,对于间接调用,由于具体要调用的是哪个函数在编译期并不知道,只在运行时才能知道,且被调用函数并不是通过函数索引空间中该被调用函数的函数索引直接定位的,而是通过表格索引空间间接定位的,表格索引空间由原文件加载生成的;因此,在原文件的加载过程中,需要从补丁文件中获取被调用函数的元素索引,并将被调用函数的元素索引添加至表格索引空间中;如此,在运行时,补丁函数就可以从表格索引空间中获取该被调用函数的元素索引,进而定位该被调用函数,实现间接调用该被调用函数。In the embodiment of the present application, for indirect calls, since the specific function to be called is not known at compile time, it can only be known at runtime, and the called function is not a function of the called function in the function index space. The index is located directly, but indirectly through the table index space, which is generated by loading the original file; therefore, during the loading process of the original file, the element index of the called function needs to be obtained from the patch file, and will be The element index of the calling function is added to the table index space; in this way, at runtime, the patch function can obtain the element index of the called function from the table index space, and then locate the called function and indirectly call the called function .
在一种可能的实现方式中,所述被调用函数为虚拟机导入函数;在所述从所述编译信息表中获取所述被调用函数的函数索引之前,所述方法还包括:生成所述被调用函数的函数索引;将所述被调用函数的函数索引添加至所述编译信息表中。In a possible implementation manner, the called function is a virtual machine import function; before acquiring the function index of the called function from the compilation information table, the method further includes: generating the The function index of the called function; the function index of the called function is added to the compilation information table.
其中,若被调用函数为虚拟机导入函数,则需要生成新的函数索引,并添加至编译信息表中的函数索引表中。若被调用函数不是虚拟机导入函数,则被调用函数的函数索引本来就已经在函数索引表中了。Wherein, if the called function is a virtual machine import function, a new function index needs to be generated and added to the function index table in the compilation information table. If the called function is not a virtual machine imported function, the function index of the called function is already in the function index table.
在本申请实施例中,被调用函数为虚拟机导入函数,则编译原文件过程中生成的编译信息表中没有记录该被调用函数的函数索引,因此需要生成该被调用函数的函数索引,并将该被调用函数的函数索引添加至编译信息表中,从而有利于实现补丁函数调用该被调用函数。In the embodiment of the present application, the called function is a virtual machine import function, and the compilation information table generated during the process of compiling the original file does not record the function index of the called function, so it is necessary to generate the function index of the called function, and The function index of the called function is added to the compilation information table, so as to facilitate the implementation of the patch function to call the called function.
在一种可能的实现方式中,所述方法还包括:在所述原文件的加载过程中,通过所述原文件的导入段将所述被调用函数添加至所述函数索引空间中。In a possible implementation manner, the method further includes: during the loading process of the original file, adding the called function to the function index space through an import section of the original file.
在本申请实施例中,被调用函数为虚拟机导入函数,故原文件的加载过程中生成的函数索引空间中并没有该被调用函数,因此需要通过原文件的导入段将被调用函数添加至函数索引空间中,以使得函数索引空间中存在该被调用函数;从而有利于实现补丁函数调用该被调用函数。In the embodiment of the present application, the called function is a virtual machine import function, so the function index space generated during the loading process of the original file does not have the called function. Therefore, the called function needs to be added to the import section of the original file. in the function index space, so that the called function exists in the function index space; thus, it is beneficial to realize that the patch function calls the called function.
下面通过具体示例来介绍本申请提供的技术方案。The technical solutions provided by the present application are described below through specific examples.
示例1Example 1
示例1为本申请的一种应用场景,为了WebAssembly应用的升级更新或缺陷修复,需替换已有的WebAssembly应用文件compute.wasm中的函数,以计算函数compute为例,将函数实现由a-b替换为a+b。示例1的具体技术方案如下:Example 1 is an application scenario of this application. In order to upgrade or repair the WebAssembly application, the function in the existing WebAssembly application file compute.wasm needs to be replaced. Taking the calculation function compute as an example, the function implementation is replaced by a-b with a+b. The specific technical solution of Example 1 is as follows:
步骤一、编译
编译流程如图11所示。The compilation process is shown in Figure 11.
1、使用应用源文件main.c,通过编译器工具链编译为WebAssembly二进制格式文件main.wasm;其中,main.wasm为原文件。可选地,将wasm二进制格式转译为wat文本格式,使WebAssembly二进制格式文件main.wasm可读,如图11所示。1. Use the application source file main.c and compile it into the WebAssembly binary format file main.wasm through the compiler tool chain; among them, main.wasm is the original file. Optionally, translate the wasm binary format into wat text format, so that the WebAssembly binary format file main.wasm is readable, as shown in Figure 11.
1)类型段包含两类函数签名。在图11中,分别对应于(type(;0;)(func(param i32i32)(result i32)))和(type(;1;)(func(result i32)))。1) The type segment contains two types of function signatures. In FIG. 11, they correspond to (type(;0;)(func(param i32i32)(result i32))) and (type(;1;)(func(result i32))), respectively.
2)函数段包含两个函数,函数索引分别为0和1,函数名在编译阶段已经舍去。也即在图11中的func(;0;)和func(;1;)。2) The function section contains two functions, the function indexes are 0 and 1 respectively, and the function name has been discarded in the compilation stage. That is, func(;0;) and func(;1;) in FIG. 11 .
2、在编译过程中生成、导出编译信息表;在示例1中,记录源代码中每个函数和函数索引的对应关系,生成并导出函数索引表,编译信息表的其他结构在后续示例中介绍。函数索引表如图11所示,结构说明如下:2. Generate and export the compilation information table during the compilation process; in example 1, record the correspondence between each function and function index in the source code, generate and export the function index table, and other structures of the compilation information table are introduced in subsequent examples . The function index table is shown in Figure 11, and the structure is explained as follows:
1)函数索引:编译过程中编译器为每个函数分配的索引,和编译顺序有关。1) Function index: The index assigned by the compiler to each function during the compilation process is related to the compilation order.
2)函数名:WebAssembly文件中函数索引实际所对应的函数名称。2) Function name: The actual function name corresponding to the function index in the WebAssembly file.
可以看到,main.wasm对应的函数索引表包含两项,分别为0号函数compute和1号函数main。其中,按照编译顺序,索引0对应于func(;0;),示例1中的compute;索引1对应于func(;1;),示例1中的main。It can be seen that the function index table corresponding to main.wasm contains two items, which are the No. 0 function compute and No. 1 function main. Among them, according to the compilation order,
步骤二、制作补丁Step 2: Make a patch
制作补丁流程如图12所示。The process of making a patch is shown in Figure 12.
1、根据步骤一导出的函数索引表,查询原函数在函数索引表中对应的函数索引。如本例中需要替换函数compute,通过查询函数索引表可知,compute函数对应的函数索引为0。1. According to the function index table exported in
2、在使用补丁函数文件(patch.c)编译为WebAssembly二进制格式文件patch.wasm的过程中,有两种方式来记录原文件函数和补丁文件中函数的对应关系;其中,patch.wasm为补丁文件。2. In the process of compiling the patch function file (patch.c) into the WebAssembly binary format file patch.wasm, there are two ways to record the correspondence between the function in the original file and the function in the patch file; among them, patch.wasm is the patch document.
1)保持原文件函数段和补丁文件函数段内容一致,采用这种方式会增大补丁文件的体积。也即原文件中的函数指的是compute和main,补丁文件中的函数还是compute和main。compute是要补丁变化的,main是保持不变的。这里指的是补丁文件里面同时保持compute和main,都重新生成一份,实际上main是冗余的。1) Keep the content of the function section of the original file and the function section of the patch file consistent, as this method will increase the size of the patch file. That is, the functions in the original file refer to compute and main, and the functions in the patch file are still compute and main. Compute is to be patched and changed, and main remains unchanged. This refers to the fact that compute and main are maintained in the patch file, and both are regenerated. In fact, main is redundant.
2)使用函数索引表中原函数的函数索引和补丁文件中补丁函数的函数索引生成函数对应表,从而得到新旧函数的对应关系。本申请中,WebAssembly中变化的部分增加索引,原来引用老函数的地方修改替换为补丁里面更新的部分,所以有一个变化的函数对应表,这个变换的函数对应表里面有原函数的函数索引和补丁函数的函数索引的对应关系。以下均采用这种实现方式。2) A function correspondence table is generated 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 as to obtain the correspondence between the old and new functions. In this application, an index is added to the changed part in WebAssembly, and the original reference to the old function is modified and replaced with the updated part in the patch, so there is a changed function correspondence table, and the transformed function correspondence table contains the function index of the original function and Correspondence of the function index of the patch function. This implementation is adopted below.
步骤三、加载
以compute函数为例,如图13所示,在原文件main.wasm解析加载时,compute函数需替换为补丁文件中的compute函数,若从原文件额代码段获取compute函数的函数地址,获得地址0x08020000;而若加载补丁文件,从补丁文件的代码块获取compute函数的函数地址,则获得地址0x08020200,将原函数compute{a-b}地址0x08020000替换为补丁函数compute{a+b}地址0x08020200,函数地址替换完成。应理解,不管是从main.wasm,还是从patch.wasm都可以获取compute()函数的首地址,这里替换的是到compute函数的引用,补丁文件patch.wasm进去的新compute函数和原有main.wasm的compute函数都在那里了,只是调用点更改来达到替换的效果。Taking the compute function as an example, as shown in Figure 13, when the original file main.wasm is parsed and loaded, the compute function needs to be replaced with the compute function in the patch file. If the function address of the compute function is obtained from the code segment of the original file, the address is 0x08020000 ;If the patch file is loaded and the function address of the compute function is obtained from the code block of the patch file, the address 0x08020200 is obtained, and the address 0x08020000 of the original function compute{a-b} is replaced with the address 0x08020200 of the patch function compute{a+b}, and the function address is replaced Finish. It should be understood that the first address of the compute() function can be obtained from either main.wasm or patch.wasm. The reference to the compute function is replaced here, the new compute function and the original main in the patch file patch.wasm The compute functions of .wasm are all there, but the call point is changed to achieve the effect of replacement.
采用本示例,可使用较小体积的补丁文件对WebAssembly应用进行更新,并且不影响已经正式发布的应用版本,做到了轻量快速的WebAssembly应用的升级更新与应用缺陷修复。实现WebAssembly应用的升级更新或应用缺陷修复,针对WebAssembly格式进行补丁的制作与加载,通过在编译阶段记录并且导出函数索引表,获取原函数的函数索引,结合补丁函数编译补丁文件,在加载应用时,将原函数的函数地址替换为补丁函数的函数地址,从而实现了补丁函数级的替换与更新。Using this example, the WebAssembly application can be updated with a small patch file without affecting the officially released application version, so that lightweight and fast WebAssembly application upgrades and application bug fixes can be achieved. Realize the upgrade and update of WebAssembly applications or repair application defects, create and load patches for the WebAssembly format, record and export the function index table in the compilation stage, obtain the function index of the original function, and compile the patch file with the patch function, when loading the application. , replace the function address of the original function with the function address of the patch function, thus realizing the replacement and update of the patch function level.
示例2Example 2
示例2为本申请的另一种应用场景,示例2与示例1的区别在于在补丁函数中存在操作内存的情况,以函数compute为例,在函数实现中需要声明新的数组并对数组赋值。示例2的具体技术方案如下:Example 2 is another application scenario of this application. The difference between Example 2 and Example 1 is that there is a case of operating memory in the patch function. Taking the function compute as an example, a new array needs to be declared and assigned a value in the function implementation. The specific technical solution of Example 2 is as follows:
步骤一、编译
编译流程在示例1的编译流程的基础上增加步骤。The compilation process adds steps to the compilation process of Example 1.
1、使用应用源文件main.c,通过编译器工具链编译为WebAssembly二进制格式文件main.wasm。1. Use the application source file main.c and compile it into the WebAssembly binary format file main.wasm through the compiler tool chain.
2、在编译过程中生成、导出编译信息表,编译信息表包括以下结构:2. Generate and export the compilation information table during the compilation process. The compilation information table includes the following structure:
1)函数索引表:在编译过程中记录应用代码中每个函数和函数索引的对应关系,生成并导出函数索引表。1) Function index table: Record the correspondence between each function and function index in the application code during the compilation process, and generate and export the function index table.
2)内存段尺寸:在编译过程中记录内存段所用大小,导出内存段尺寸。2) Memory segment size: Record the size of the memory segment during the compilation process, and export the memory segment size.
步骤二、制作补丁Step 2: Make a patch
制作补丁流程在示例1制作补丁的流程的基础上增加步骤,如图14所示。The process of making a patch adds steps to the process of making a patch in Example 1, as shown in Figure 14.
1、根据步骤一导出的函数索引表,查询原函数在函数索引表中对应的函数索引。1. According to the function index table exported in
2、在使用补丁函数文件(patch.c)编译为WebAssembly二进制格式文件patch.wasm的过程中,需要修正补丁函数内操作内存的相关指令代码段,以保证操作内存的正确性。2. In the process of compiling the patch function file (patch.c) into the WebAssembly binary format file patch.wasm, it is necessary to correct the relevant instruction code segment for operating the memory in the patch function to ensure the correctness of the operating memory.
具体过程如下:由编译信息表可知已使用的内存段尺寸,在编译补丁文件时,使用补丁文件(或补丁函数)的偏移量加已使用的内存段尺寸作为新的偏移量来修正操作内存相关指令,写入补丁文件的代码段。应理解,因为补丁中修改了数据内存的大小,则需扩展数据段的大小,让新的patch函数操作新的数据,而老版本可以依旧操作自己的数据。这里新的数据偏移不再是从0开始索引,而是从老数据段(已使用的内存数据段)末尾开始,所以“新偏移量=偏移量+已使用的内存段尺寸”。The specific process is as follows: The used memory segment size can be known from the compilation information table. When compiling the patch file, the offset of the patch file (or patch function) plus the used memory segment size is used as the new offset to correct the operation. Memory-related instructions, the code segment that writes the patch file. It should be understood that because the size of the data memory is modified in the patch, the size of the data segment needs to be expanded so that the new patch function can operate on new data, while the old version can still operate its own data. Here the new data offset is no longer indexed from 0, but starts from the end of the old data segment (used memory data segment), so "new offset = offset + used memory segment size".
3、在使用补丁函数文件编译为WebAssembly二进制格式文件patch.wasm的过程中,使用函数索引表中原函数的函数索引和补丁文件中补丁函数的函数索引生成函数对应表,从而得到新旧函数的对应关系。3. In the process of compiling the patch function file into the WebAssembly binary format file patch.wasm, use the function index of the original function in the function index table and the function index of the patch function in the patch file to generate a function correspondence table, so as to obtain the correspondence between the old and new functions. .
步骤三、加载
加载流程在示例1的加载流程的基础上增加步骤。额外加载补丁文件中的数据段至线性内存空间,偏移量为已使用内存段的大小。The loading process adds steps to the loading process of Example 1. The data segment in the patch file is additionally loaded into the linear memory space, and the offset is the size of the used memory segment.
采用本示例,可使用较小体积的补丁文件对WebAssembly应用进行更新,并且不影响已经正式发布的应用版本,做到了轻量快速的WebAssembly应用的升级更新与应用缺陷修复。针对在补丁函数中进行线性内存操作的场景,通过在编译、加载阶段的处理,实现了补丁函数的正确替换。实现WebAssembly应用的升级更新或应用缺陷修复,针对WebAssembly格式进行补丁的制作与加载,通过在编译阶段记录并且导出编译信息,包括函数索引表和内存段尺寸,获取原函数的函数索引和内存段大小,因为补丁函数涉及内存操作,所以对代码段的内存操作进行修正,将补丁函数编译为WebAssembly补丁文件。在加载应用时,将原函数的函数地址替换为补丁函数的函数地址进行加载。Using this example, the WebAssembly application can be updated with a small patch file without affecting the officially released application version, so that lightweight and fast WebAssembly application upgrades and application bug fixes can be achieved. For the scenario of linear memory operation in the patch function, the correct replacement of the patch function is realized through the processing in the compilation and loading stages. Realize the upgrade and update of WebAssembly applications or repair application bugs, create and load patches for the WebAssembly format, and obtain the function index and memory segment size of the original function by recording and exporting compilation information during the compilation phase, including the function index table and memory segment size. , because the patch function involves memory operations, the memory operation of the code segment is corrected, and the patch function is compiled into a WebAssembly patch file. When loading the application, replace the function address of the original function with the function address of the patch function to load.
示例3Example 3
示例3为本申请的一种更复杂的应用场景,示例3和示例1的区别在于在补丁函数中存在调用其他函数的情况,以函数compute为例,在函数实现中需要将直接调用函数add替换为直接调用函数sub,将间接调用函数sub替换为间接调用函数add。示例3额具体技术方案如下:Example 3 is a more complex application scenario of the application. The difference between Example 3 and Example 1 is that other functions are called in the patch function. Taking the function compute as an example, the directly calling function add needs to be replaced in the function implementation. To directly call the function sub, replace the indirect call function sub with the indirect call function add. Example 3 The specific technical solutions are as follows:
步骤一、编译
编译流程在示例1的编译流程的基础上增加步骤,如图15所示。The compilation process adds steps to the compilation process of Example 1, as shown in FIG. 15 .
1、使用应用源文件main.c,通过编译器工具链编译为WebAssembly二进制格式文件main.wasm。可选地,将wasm二进制格式转译为wat文本格式,使WebAssembly二进制格式文件main.wasm可读,如图15所示:1. Use the application source file main.c and compile it into the WebAssembly binary format file main.wasm through the compiler tool chain. Optionally, translate the wasm binary format to wat text format to make the WebAssembly binary format file main.wasm readable, as shown in Figure 15:
表格段包含一个元素,为一个函数引用,是函数索引1对应的函数引用,用于函数间接调用。这里实际上在表格段预留了一个地址的引用空间,它动态保存p的值,但预设为sub;语句“p=sub”执行时刻{local.get 0;call_indirect(type0)},wasm把sub的地址写入表格段引用索引1,紧接着,“int ret=(*p)(a,b)”从引用索引1读取即将执行的间接调用地址,也即sub,函数调用sub函数。The table segment contains one element, which is a function reference, which is the function reference corresponding to function
2、在编译过程中生成、导出编译信息表,编译信息表包括以下结构:2. Generate and export the compilation information table during the compilation process. The compilation information table includes the following structure:
1)函数索引表:在编译过程中记录每个函数和函数索引的对应关系,生成并导出函数索引表。1) Function index table: Record the correspondence between each function and function index during the compilation process, and generate and export the function index table.
2)函数签名索引表:在编译过程中记录每个函数签名和函数签名索引的对应关系,生成并导出函数签名索引表。函数签名索引表结构包括:2) Function signature index table: record the correspondence between each function signature and function signature index during the compilation process, and generate and export the function signature index table. The function signature index table structure includes:
函数签名索引:编译过程中编译器为每个函数签名分配的索引。Function Signature Index: The index assigned by the compiler to each function signature during compilation.
函数签名:WebAssembly文件中类型段中函数签名索引所对应的函数签名类型。Function signature: The function signature type corresponding to the function signature index in the type section of the WebAssembly file.
3)元素段尺寸:在编译过程中记录元素段大小,导出元素段尺寸。3) Element segment size: The element segment size is recorded during the compilation process, and the element segment size is derived.
4)内存段尺寸:在编译过程中记录内存段所用大小,导出内存段尺寸。4) Memory segment size: Record the size of the memory segment during the compilation process, and export the memory segment size.
步骤二、制作补丁Step 2: Make a patch
制作补丁的流程在示例1制作补丁的流程的基础上增加步骤,如图16所示。The process of making a patch adds steps to the process of making a patch in Example 1, as shown in Figure 16.
1、若被调用函数为虚拟机导入函数,则生成新的函数索引,添加至函数索引表。1. If the called function is a virtual machine import function, a new function index is generated and added to the function index table.
2、根据步骤一导出的函数索引表,查询原函数在函数索引表中对应的函数索引。如本例中需要替换函数compute,通过查询函数索引表可知,compute函数对应的函数索引为2。2. According to the function index table exported in
3、在使用补丁函数文件(patch.c)编译为WebAssembly二进制格式文件patch.wasm的过程中,需要修正补丁函数内函数调用的相关指令代码段,以保证函数间调用关系的正确性。针对不同的函数调用方式,具体过程如下:3. In the process of compiling the patch function file (patch.c) into the WebAssembly binary format file patch.wasm, it is necessary to correct the relevant instruction code segment of the function call in the patch function to ensure the correctness of the calling relationship between functions. For different function calling methods, the specific process is as follows:
直接调用:被调用函数通过函数索引空间的函数索引直接定位,所以需要更新代码段call指令后的函数索引,如图7和图8所示。若编译补丁文件,则从函数索引表中获取被调用函数的函数索引,修正代码段。Direct call: The called function is located directly by the function index in the function index space, so the function index after the code segment call instruction needs to be updated, as shown in Figure 7 and Figure 8. If the patch file is compiled, the function index of the called function is obtained from the function index table, and the code segment is corrected.
间接调用:由于具体要调用的是哪个函数在编译期并不知道,只在运行时才能知道,被调用函数并不是通过函数索引空间的函数索引直接定位,而是从表格索引空间中间接定位。所以需要更新元素段中的元素项,如图9和图10所示。若编译补丁文件,则从函数索引表中获取所调用的函数索引,从函数签名索引表中获取被调用函数的函数签名索引,获取元素段尺寸,同时修正元素段与代码段。Indirect call: Since the specific function to be called is not known at compile time and can only be known at runtime, the called function is not directly located through the function index of the function index space, but indirectly located from the table index space. Therefore, the element items in the element segment need to be updated, as shown in Figure 9 and Figure 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 modified at the same time.
4、在使用补丁函数文件(patch.c)编译为WebAssembly二进制格式文件patch.wasm的过程中,使用函数索引表中原函数的函数索引和补丁文件中补丁函数的函数索引生成函数对应表,从而得到新旧函数的对应关系。4. In the process of compiling the patch function file (patch.c) into the WebAssembly binary format file patch.wasm, use the function index of the original function in the function index table and the function index of the patch function in the patch file to generate the function correspondence table, so as to obtain Correspondence between old and new functions.
步骤三、加载
加载流程在示例1的加载流程的基础上增加步骤。The loading process adds steps to the loading process of Example 1.
1、对于补丁函数:1. For the patch function:
按照示例1的加载步骤修正函数索引空间中补丁函数代码地址,也即将原函数的函数地址替换为补丁函数的函数地址。Correct the patch function code address in the function index space according to the loading steps of Example 1, that is, replace the function address of the original function with the function address of the patch function.
2、对于补丁函数中调用的其他函数:2. For other functions called in the patch function:
若被调用函数为虚拟机导入函数,则先将被调用函数从补丁函数的导入段添加至函数索引空间中,接着针对不同的函数调用方式执行不同步骤,具体过程如下:If the called function is a virtual machine import function, first add the called function from the import segment of the patch function to the function index space, and then perform different steps for different function calling methods. The specific process is as follows:
直接调用:被调用函数通过函数索引空间中的函数索引直接定位,在前期编译阶段已经修正了代码段中call指令后的函数索引,且该被调用函数的函数地址未发生变化,所以可以保证函数直接调用的正确性。Direct call: The called function is located directly through the function index in the function index space. The function index after the call instruction in the code segment has been corrected in the pre-compilation stage, and the function address of the called function has not changed, so it can be guaranteed that the function Correctness of direct calls.
间接调用:由于具体要调用的是哪个函数在编译期并不知道,只在运行时才能知道,被调用函数并不是通过函数索引空间中的函数索引直接定位,而是从表格索引空间中间接定位。所以需要在从原文件解析得到表格索引空间的过程中,修正函数引用,添加表格索引空间中相应的元素项,如图17所示,表格索引空间中新增项索引为原文件的元素段尺寸和补丁文件的元素索引的和。Indirect call: Since the specific function to be called is not known at compile time and only known at runtime, the called function is not directly located by the function index in the function index space, but indirectly located from the table index space . Therefore, in the process of obtaining the table index space from the original file, it is necessary to modify the function reference and add the corresponding element item in the table index space. As shown in Figure 17, the index of the newly added item in the table index space is the element segment size of the original file. and the sum of the element indices of the patch file.
采用本示例,可使用较小体积的补丁文件对WebAssembly应用进行更新,并且不影响已经正式发布的应用版本,做到了轻量快速的WebAssembly应用的升级更新与应用缺陷修复。针对在补丁函数中调用其他函数的场景,通过在编译、加载阶段的处理,实现了补丁函数的正确替换。实现WebAssembly应用的升级更新或应用缺陷修复,针对WebAssembly格式进行补丁的制作与加载,通过在编译阶段记录并且导出编译信息表,包括函数索引表、函数签名索引表和元素段尺寸,获取原函数的函数索引、函数签名索引和元素段尺寸,因为补丁函数涉及其他函数调用,所以结合导出的编译信息表,对代码段进行修正,将补丁函数编译为WebAssembly补丁文件。在加载应用时,对于补丁函数,将原函数地址替换为补丁函数地址。对于补丁函数中调用的其他函数,针对函数的不同调用方式进行处理,从而实现了补丁函数级的替换与更新。Using this example, the WebAssembly application can be updated with a small patch file without affecting the officially released application version, so that lightweight and fast WebAssembly application upgrades and application bug fixes can be achieved. For the scenario of calling other functions in the patch function, the correct replacement of the patch function is realized through the processing in the compilation and loading stages. Realize the upgrade and update of WebAssembly applications or repair application defects, create and load patches for the WebAssembly format, record and export the compilation information table in the compilation stage, including the function index table, function signature index table and element segment size, obtain the original function's size. Function index, function signature index, and element segment size. Because the patch function involves other function calls, the code segment is revised based on the exported compilation information table, and the patch function is compiled into a WebAssembly patch file. When loading the application, for the patch function, replace the original function address with the patch function address. For other functions called in the patch function, different calling methods of the functions are processed, thereby realizing the replacement and update of the patch function level.
请参阅图18,图18是本申请实施例提供的一种补丁装置的结构示意图,该补丁装置1800可以包括处理单元1801和通信单元1802,其中,该处理单元1801,用于执行如图8至图12所示的方法实施例中的任一步骤,且在执行诸如获取等数据传输时,可选择的调用该通信单元1802来完成相应操作。下面进行详细说明。Please refer to FIG. 18. FIG. 18 is a schematic structural diagram of a patch device provided by an embodiment of the present application. The
所述处理单元1801用于:在原文件的编译过程中,生成编译信息表,其中,所述原文件为WebAssembly二进制格式的文件,所述编译信息表记录有原函数的函数索引,所述原函数为所述原文件中的函数;在补丁文件的编译过程中,根据所述编译信息表生成函数对应表,其中,所述补丁文件为WebAssembly二进制格式的文件,所述函数对应表记录有所述原函数与补丁函数的对应关系,所述补丁函数为所述补丁文件中的函数;在所述原文件的加载过程中,根据所述函数对应表将函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址,其中,所述函数索引空间在所述原文件的加载过程中生成。The
在一种可能的实现方式中,所述补丁文件中的函数有且仅有补丁函数。In a possible implementation manner, the functions in the patch file have one and only patch functions.
在一种可能的实现方式中,所述处理单元1801具体用于:根据所述函数对应表判断是否存在所述补丁函数;若存在所述补丁函数,则从所述补丁文件的代码段中获取所述补丁函数的函数地址;将所述函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址。In a possible implementation manner, the
在一种可能的实现方式中,所述编译信息表还记录有所述原文件的内存段尺寸;所述处理单元1801还用于:在所述补丁文件的编译过程中,从所述编译信息表中获取所述原文件的内存段尺寸;根据所述原文件的内存段尺寸和所述补丁函数的数据偏移量编译所述补丁文件的代码段。In a possible implementation manner, the compilation information table further records the size of the memory segment of the original file; the
在一种可能的实现方式中,所述编译信息表还记录有被调用函数的函数索引,所述被调用函数为被所述原函数调用的函数;所述处理单元1801还用于:在所述补丁文件的编译过程中,从所述编译信息表中获取所述被调用函数的函数索引;根据所述被调用函数的函数索引编译所述补丁文件的代码段。In a possible implementation manner, the compilation information table further records the function index of the called function, and the called function is the function called by the original function; the
在一种可能的实现方式中,所述被调用函数为被所述原函数直接调用的函数,所述补丁文件的代码段包括直接调用指令,所述直接调用指令包括所述被调用函数的函数索引。In a possible implementation manner, the called function is a function directly called by the original function, the code segment of the patch file includes a direct calling instruction, and the direct calling instruction includes a function of the called function index.
在一种可能的实现方式中,所述编译信息表还记录有所述被调用函数的函数签名索引、所述原文件的元素段尺寸;所述被调用函数为被所述原函数间接调用的函数;所述处理单元1801具体用于:从所述编译信息表中获取所述被调用函数的函数签名索引;根据所述被调用函数的函数索引编译所述补丁文件的元素段,以得到所述被调用函数的元素索引;根据所述原文件的元素段尺寸和所述被调用函数的元素索引编译所述补丁文件的代码段,其中,所述补丁文件的代码段包括间接调用指令,所述间接调用指令包括所述被调用函数的函数签名索引。In a possible implementation manner, the compilation information table further records the function signature index of the called function and the element segment size of the original file; the called function is indirectly called by the original function The
在一种可能的实现方式中,所述处理单元1801还用于:在所述原文件的加载过程中,从所述补丁文件中获取所述被调用函数的元素索引;将所述被调用函数的元素索引添加至表格索引空间中,其中,所述表格索引空间在所述原文件的加载过程中生成。In a possible implementation manner, the
在一种可能的实现方式中,所述被调用函数为虚拟机导入函数;所述处理单元1801还用于:在所述从所述编译信息表中获取所述被调用函数的函数索引之前;生成所述被调用函数的函数索引;将所述被调用函数的函数索引添加至所述编译信息表中。In a possible implementation manner, the called function is a virtual machine import function; the
在一种可能的实现方式中,所述处理单元1801还用于:在所述原文件的加载过程中,通过所述原文件的导入段将所述被调用函数添加至所述函数索引空间中。In a possible implementation manner, the
其中,该补丁装置1800还可以包括存储单元1803,用于存储终端的程序代码和数据。该处理单元1801可以是处理器,该通信单元1802可以收发器,该存储单元1803可以是存储器。Wherein, the
需要说明的是,各个单元的实现还可以对应参照图3至图17所示的方法实施例的相应描述。It should be noted that, the implementation of each unit may also correspond to the corresponding description with reference to the method embodiments shown in FIG. 3 to FIG. 17 .
图18所描述的补丁装置1800,在编译得到WebAssembly二进制格式的原文件的过程中,生成编译信息表,该编译信息表记录有原文件中的原函数的函数索引;在编译得到WebAssembly二进制格式的补丁文件的过程中,根据编译信息表中的原函数的函数索引以及补丁文件中的补丁函数的函数索引生成函数对应表,函数对应表记录有原函数与补丁函数的对应关系;也即从编译信息表中获取原函数的函数索引,从补丁文件中获取补丁函数的函数索引,将原函数的函数索引和补丁函数的函数索引关联记录在函数对应表上,从而生成函数对应表;在加载原文件的过程中,会生成函数索引空间,函数索引空间中记录有原函数的函数地址,而函数对应表记录有原函数和补丁函数的对应关系,因此可以从补丁文件中获取补丁函数的函数地址,然后根据函数对应表记录的原函数和补丁函数的对应关系,将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址;由于在函数索引空间中,原函数的函数地址替换为了补丁函数的函数地址,后期函数应用时执行的函数即为补丁函数,从而实现使用补丁对WebAssembly应用进行函数级的替换和更新。The
请参阅图19,图19是本申请实施例提供的一种补丁设备的结构示意图,该补丁设备1910包括收发器1911、处理器1912和存储器1913,所述收发器1911、所述处理器1912和所述存储器1913通过总线1914相互连接。Please refer to FIG. 19. FIG. 19 is a schematic structural diagram of a patch device provided by an embodiment of the present application. The
存储器1913包括但不限于是随机存储记忆体(random access memory,RAM)、只读存储器(read-only memory,ROM)、可擦除可编程只读存储器(erasable programmableread only memory,EPROM)、或便携式只读存储器(compact disc read-only memory,CD-ROM),该存储器1913用于相关指令及数据。The
收发器1911用于接收和发送数据。The
处理器1912可以是一个或多个中央处理器(central processing unit,CPU),在处理器1912是一个CPU的情况下,该CPU可以是单核CPU,也可以是多核CPU。The
该补丁设备1910中的所述处理器1912用于读取所述存储器1913中存储的程序代码,执行以下操作:在原文件的编译过程中,生成编译信息表,其中,所述原文件为WebAssembly二进制格式的文件,所述编译信息表记录有原函数的函数索引,所述原函数为所述原文件中的函数;在补丁文件的编译过程中,根据所述编译信息表生成函数对应表,其中,所述补丁文件为WebAssembly二进制格式的文件,所述函数对应表记录有所述原函数与补丁函数的对应关系,所述补丁函数为所述补丁文件中的函数;在所述原文件的加载过程中,根据所述函数对应表将函数索引空间中的所述原函数的函数地址替换为所述补丁函数的函数地址,其中,所述函数索引空间在所述原文件的加载过程中生成。The
需要说明的是,各个操作的实现还可以对应参照图3至图17所述的方法实施例的相应描述。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 FIG. 17 .
图19所描述的补丁设备1910,在编译得到WebAssembly二进制格式的原文件的过程中,生成编译信息表,该编译信息表记录有原文件中的原函数的函数索引;在编译得到WebAssembly二进制格式的补丁文件的过程中,根据编译信息表中的原函数的函数索引以及补丁文件中的补丁函数的函数索引生成函数对应表,函数对应表记录有原函数与补丁函数的对应关系;也即从编译信息表中获取原函数的函数索引,从补丁文件中获取补丁函数的函数索引,将原函数的函数索引和补丁函数的函数索引关联记录在函数对应表上,从而生成函数对应表;在加载原文件的过程中,会生成函数索引空间,函数索引空间中记录有原函数的函数地址,而函数对应表记录有原函数和补丁函数的对应关系,因此可以从补丁文件中获取补丁函数的函数地址,然后根据函数对应表记录的原函数和补丁函数的对应关系,将函数索引空间中的原函数的函数地址替换为补丁函数的函数地址;由于在函数索引空间中,原函数的函数地址替换为了补丁函数的函数地址,后期函数应用时执行的函数即为补丁函数,从而实现使用补丁对WebAssembly应用进行函数级的替换和更新。The
本申请实施例还提供一种芯片,该芯片包括至少一个处理器,存储器和接口电路,上述存储器、上述收发器和上述至少一个处理器通过线路互联,上述至少一个存储器中存储有计算机程序;上述计算机程序被上述处理器执行时,上述方法实施例中所示的方法流程得以实现。The embodiment of the present application further provides a chip, the chip includes at least one processor, a memory and an interface circuit, the above-mentioned memory, the above-mentioned transceiver and the above-mentioned at least one processor are interconnected through a line, and the above-mentioned at least one memory stores a computer program; the above-mentioned When the computer program is executed by the above-mentioned processor, the method flow shown in the above-mentioned method embodiment is realized.
本申请实施例还提供一种计算机可读存储介质,上述计算机可读存储介质中存储有计算机程序,当其在电子设备上运行时,上述方法实施例中所示的方法流程得以实现。Embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed on an electronic device, the method flow shown in the foregoing method embodiments is realized.
本申请实施例还提供一种计算机程序,当上述计算机程序在电子设备上运行时,上述方法实施例中所示的方法流程得以实现。The embodiments of the present application further provide a computer program, when the computer program is executed on an electronic device, the method flow shown in the above method embodiments can be realized.
应理解,本申请实施例中提及的处理器可以是中央处理单元(CentralProcessing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital SignalProcessor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。It should be understood that the processor mentioned in the embodiments of the present application may be a central processing unit (Central Processing Unit, CPU), and may also be other general-purpose processors, digital signal processors (Digital Signal Processors, DSP), application specific integrated circuits (Application Specific Integrated Circuits) Integrated Circuit, ASIC), off-the-shelf Programmable Gate Array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
还应理解,本申请实施例中提及的存储器可以是易失性存储器或非易失性存储器,或可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(Read-Only Memory,ROM)、可编程只读存储器(Programmable ROM,PROM)、可擦除可编程只读存储器(Erasable PROM,EPROM)、电可擦除可编程只读存储器(Electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(Random Access Memory,RAM),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(Static RAM,SRAM)、动态随机存取存储器(Dynamic RAM,DRAM)、同步动态随机存取存储器(Synchronous DRAM,SDRAM)、双倍数据速率同步动态随机存取存储器(Double DataRate SDRAM,DDR SDRAM)、增强型同步动态随机存取存储器(Enhanced SDRAM,ESDRAM)、同步连接动态随机存取存储器(Synchlink DRAM,SLDRAM)和直接内存总线随机存取存储器(Direct Rambus RAM,DR RAM)。It should also be understood that the memory mentioned in the embodiments of the present application may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Wherein, the non-volatile memory may be Read-Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (Erasable PROM, EPROM), Erase programmable read-only memory (Electrically EPROM, EEPROM) or flash memory. The volatile memory may be random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (Double DataRate SDRAM, DDR SDRAM), enhanced synchronous dynamic random access memory (Enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (Synchlink DRAM, SLDRAM) And direct memory bus random access memory (Direct Rambus RAM, DR RAM).
需要说明的是,当处理器为通用处理器、DSP、ASIC、FPGA或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件时,存储器(存储模块)集成在处理器中。It should be noted that when the processor is a general-purpose processor, DSP, ASIC, FPGA or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components, the memory (storage module) is integrated in the processor.
应注意,本说明书描述的存储器旨在包括但不限于这些和任意其它适合类型的存储器。It should be noted that the memory described in this specification is intended to include, but not be limited to, these and any other suitable types of memory.
应理解,在本申请的各种实施例中,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that, in various embodiments of the present application, the size of the sequence numbers of the above-mentioned processes does not mean the sequence of execution, and the execution sequence of each process should be determined by its functions and internal logic, and should not be dealt with in the embodiments of the present application. implementation constitutes any limitation.
本领域普通技术人员可以意识到,结合本说明书中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this specification can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each particular application, but such implementations should not be considered beyond the scope of this application.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described systems, devices and units may refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,上述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are only illustrative. For example, the division of the above units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or may be Integration into another system, or some features can be ignored, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.
上述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described above as separate components may or may not be physically separated, and components shown as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
上述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者补丁设备等)执行本申请各个实施例上述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。If the above functions are implemented in the form of software functional units and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be embodied in the form of a software product in essence, or the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including Several instructions are used to cause a computer device (which may be a personal computer, a server, or a patch device, etc.) to execute all or part of the steps of the above-mentioned methods in various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes .
本申请实施例方法中的步骤可以根据实际需要进行顺序调整、合并和删减。此外,本申请各实施例中的术语、解释说明,可以参照其他实施例中相应的描述。The steps in the method of the embodiment of the present application may be adjusted, combined and deleted in sequence according to actual needs. In addition, for terms and explanations in each embodiment of the present application, reference may be made to corresponding descriptions in other embodiments.
本申请实施例装置中的模块可以根据实际需要进行合并、划分和删减。The modules in the apparatus of the embodiment of the present application may be combined, divided and deleted according to actual needs.
以上描述,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。As described above, the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand: The technical solutions described in the embodiments are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.
Claims (23)
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 (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115525850A (en) * | 2022-10-19 | 2022-12-27 | 上海傅利叶智能科技有限公司 | Method for improving speed of downloading and loading model at Web end and offline loading |
| CN117251234A (en) * | 2023-11-16 | 2023-12-19 | 北京中电华大电子设计有限责任公司 | Function calling method and device based on patches |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101799763A (en) * | 2009-02-10 | 2010-08-11 | 华为技术有限公司 | Method, device and system for patching kernel on line |
| CN105094784A (en) * | 2014-05-20 | 2015-11-25 | 上海新跃仪表厂 | Method and device for on-board programming of indirect addressing skip mode based on SRAM (Static Random Access Memory) |
| US20190303579A1 (en) * | 2018-04-02 | 2019-10-03 | Ca, Inc. | Decentralized, immutable, tamper-evident, directed acyclic graphs documenting software supply-chains with cryptographically signed records of software-development life cycle state and cryptographic digests of executable code |
| CN111666096A (en) * | 2020-07-02 | 2020-09-15 | 腾讯科技(深圳)有限公司 | Hot updating method and device for target application, storage medium and electronic equipment |
| CN112433816A (en) * | 2020-11-27 | 2021-03-02 | 北京达佳互联信息技术有限公司 | Performance optimization method and device based on Javascript engine |
Family Cites Families (5)
| 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 |
-
2021
- 2021-03-19 CN CN202110297938.4A patent/CN115167862A/en active Pending
-
2022
- 2022-03-15 WO PCT/CN2022/081029 patent/WO2022194173A1/en not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101799763A (en) * | 2009-02-10 | 2010-08-11 | 华为技术有限公司 | Method, device and system for patching kernel on line |
| CN105094784A (en) * | 2014-05-20 | 2015-11-25 | 上海新跃仪表厂 | Method and device for on-board programming of indirect addressing skip mode based on SRAM (Static Random Access Memory) |
| US20190303579A1 (en) * | 2018-04-02 | 2019-10-03 | Ca, Inc. | Decentralized, immutable, tamper-evident, directed acyclic graphs documenting software supply-chains with cryptographically signed records of software-development life cycle state and cryptographic digests of executable code |
| CN111666096A (en) * | 2020-07-02 | 2020-09-15 | 腾讯科技(深圳)有限公司 | Hot updating method and device for target application, storage medium and electronic equipment |
| CN112433816A (en) * | 2020-11-27 | 2021-03-02 | 北京达佳互联信息技术有限公司 | Performance optimization method and device based on Javascript engine |
Non-Patent Citations (1)
| Title |
|---|
| 程友清;: "嵌入式网络设备软件热补丁技术研究", 微电子学与计算机, no. 01, 5 January 2013 (2013-01-05) * |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115525850A (en) * | 2022-10-19 | 2022-12-27 | 上海傅利叶智能科技有限公司 | Method for improving speed of downloading and loading model at Web end and offline loading |
| 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 |
|---|---|---|
| WO2020173128A1 (en) | Method and device for generating software development kit, and terminal device | |
| 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 | |
| US8954939B2 (en) | Extending a development environment | |
| US20250199785A1 (en) | Compilation methods, compilers, and wasm virtual machines | |
| JP2006092544A (en) | Dynamic link of module in pre-operating system environment | |
| CN106648755A (en) | Method and device for dynamically loading dex in android art environment | |
| CN111666102A (en) | File format conversion method, chip verification method, related device and network chip | |
| WO2022194173A1 (en) | Patching method and relevant device | |
| CN112905447A (en) | Test method and system for block chain virtual machine | |
| CN109960511B (en) | Dynamic library issuing method based on virtualization technology, storage medium and intelligent terminal | |
| CN101782860B (en) | Method and device for linking program | |
| CN114691246A (en) | Native platform function invocation method, apparatus and computer device | |
| CN117075960B (en) | Program reconstruction method, application cross-platform migration method, device and computing equipment | |
| CN105117201A (en) | Method and apparatus for data processing | |
| CN108958795B (en) | BootLoader code reuse method and development board in embedded system | |
| CN111367512A (en) | Method and device for creating Android library module dependency relationship in application development | |
| CN117193872A (en) | Chip starting firmware device and method based on symbol table dynamic execution | |
| CN113641389B (en) | Software upgrading method, device and equipment based on OpenCPU | |
| CN116775087A (en) | Thermal repair method, device, electronic equipment and storage medium | |
| CN110275710B (en) | Method and system for checking consistency of Java local interface, storage medium and terminal | |
| CN114942779A (en) | Patch implementation method and device, embedded system and storage medium | |
| CN112631650A (en) | Plug-in version information checking method, computing device and storage medium | |
| CN114879975B (en) | Code compiling method and device and electronic equipment | |
| US12353884B2 (en) | Cross-linking method and apparatus, electronic device and storage medium | |
| US11249733B2 (en) | Electronic apparatus and control method thereof |
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 |