WO2022088711A1 - 程序执行方法、程序处理方法以及相关设备 - Google Patents

程序执行方法、程序处理方法以及相关设备 Download PDF

Info

Publication number
WO2022088711A1
WO2022088711A1 PCT/CN2021/101965 CN2021101965W WO2022088711A1 WO 2022088711 A1 WO2022088711 A1 WO 2022088711A1 CN 2021101965 W CN2021101965 W CN 2021101965W WO 2022088711 A1 WO2022088711 A1 WO 2022088711A1
Authority
WO
WIPO (PCT)
Prior art keywords
function
small
complementary
real
functions
Prior art date
Application number
PCT/CN2021/101965
Other languages
English (en)
French (fr)
Inventor
刘健平
代雷
钟钜斌
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP21884452.0A priority Critical patent/EP4227803A4/en
Publication of WO2022088711A1 publication Critical patent/WO2022088711A1/zh
Priority to US18/309,501 priority patent/US20230259370A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • G06F8/63Image based installation; Cloning; Build to order
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44568Immediately runnable code

Definitions

  • the present application relates to the field of program processing, and in particular, to a program execution method, a program processing method, and related equipment.
  • miniaturized operating system OS
  • complementary OS is also called a complementary mirror
  • Small mirror and complementary mirror technology refers to the process of computer equipment generating small mirror and complementary mirror according to source code and the process of using small mirror and complementary mirror.
  • the specific generation method is as follows: First, the computer device distinguishes the function set B that has a dependency relationship with the entry point of the program in the source code, and the function set A that has no dependency relationship with the entry point.
  • the computer device deletes the functions in the function set A from the source code, retains the functions in the function set B, and obtains a small image; the computer device retains the functions in the function set A from the source code, and uses the functions in the function set B with empty ( null) function instead to obtain the complementary mirror image.
  • the functions in the function set A in the complementary mirror image are called real functions.
  • the empty function set in the complementary mirror corresponds to the function set B in the small mirror, or the functions of the empty function set in the complementary mirror correspond to the functions in the function set B in the small mirror one-to-one.
  • Small mirrors are statically linked, and complementary mirrors are dynamically linked.
  • the running memory of the first device is generally limited. If the code of the third-party program calls too many functions, the running memory may be insufficient and the third-party program fails to run.
  • the present application provides a program execution method, a program processing method and related equipment, which can reduce the requirement of the first program on the running memory.
  • a first aspect of the present application provides a program execution method, which is applied to a computer system.
  • the computer system includes a first small image.
  • the method can be executed by the computer system or by a first device on which the computer system is installed. The following It will be explained by taking as an example that the method can be performed by the first device.
  • the method includes: a first device receives a request for calling a small stub function from a first program, the small stub function is a function in a small stub function set, and the first small image includes a small stub function set and a small real function set; the first device Load the small stub function according to the calling request; the first device determines whether to load the complementary real function corresponding to the small stub function according to the small stub function, the complementary real function is a function in the complementary real function set, and the first complementary image includes the complementary real function set and the complementary stub function set, the complementary stub function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.
  • the functions that the first program may actually need to call are complementary real functions, and the small stub function can be understood as a buffer for loading complementary real functions. By increasing the buffer, it is possible to control whether to load the complementary real function, thereby reducing the running memory requirement of the first program. For example, when the first program does not enable the relevant function corresponding to the complementary real function, the complementary real function is not loaded.
  • the first device tries to run the small stub function according to the instructions of the first program, and loads the complementary real function if an abnormality is detected.
  • the first device may receive an instruction of the first program.
  • the instruction may specifically be a change of a judgment variable in the code of the first program (or a function called by the code) that affects the program flow, and the change of the judgment variable will trigger the operation of the small stub function. After triggering the small stub function, the first device attempts to run the small stub function.
  • the first device may not necessarily be able to run the small stub function, and may just have the intention of trying to run the small stub function, for example, the address of the small stub function is obtained, and some preparations for running the small stub function are made.
  • the first device can know that the first program will start the relevant function corresponding to the complementary real function, and then loads the complementary real function. Conversely, the first device may not need to load the complementary real function until the anomaly is detected.
  • the present application triggers the loading of complementary real functions by detecting relevant exceptions of small stub functions. When an exception is detected, it means that the small stub function has not been successfully executed.
  • the present application not only adds a buffer for loading complementary real functions, but also suspends the first program, which provides a time basis for loading complementary real functions, reduces possible errors in the first program, and improves user experience.
  • the small set of real functions is the set of functions that the target code runs in the process of running the set of target use cases
  • the set of complementary real functions is the set of functions that the target code does not run during the process of running the set of target use cases.
  • the small mirror image and the complementary mirror image obtained according to the above-mentioned small real function set and complementary real function set are called the small mirror image and the complementary mirror image obtained according to the coverage ratio.
  • the small mirror image and the complementary mirror image obtained according to the function set B and the function set A in the background art are called the small mirror image and the complementary mirror image obtained according to the dependency ratio.
  • the set of small real functions in the small image obtained according to the coverage ratio will be smaller than the set of functions B in the small image obtained according to the dependency ratio.
  • the smaller the range of the small real function set the smaller the number of functions directly loaded by the first program, thereby further reducing the running memory requirement of the first program.
  • Direct loading means loading without going through a small stub function.
  • the functions loaded through small stub functions are called indirectly loaded functions.
  • the indirectly loaded function is not directly loaded into the running memory of the first device, but the first device loads the function into the running memory only when the first program enables the function related to the function. If the first device does not start the function related to the function, the first device may not load the function. Simply put, the scope of directly loaded functions becomes smaller, and the scope of indirectly loaded functions becomes larger.
  • the method further includes: the first device loads a target function, the target function includes a target string, and the The amount of data is less than that of the source string, the target code includes the target function, the target code is obtained from the source code, the source code includes the source function, and the source function includes the source string.
  • the source function corresponds to the target function.
  • the correspondence here means that the source function and the target function have the same processing ability on strings, but the specific strings are different. One is the target string and the other is the source string.
  • the user does not need to read the source string through the first device, such as the log data of the washing machine and the alarm log of the UE.
  • the functions corresponding to the source strings are loaded, these source strings are also loaded into the running memory, thereby occupying the running memory of the first device.
  • the "ID" method to process the source string, the demand for the running memory of the first device can be reduced, and the security of the source string can be increased, and the source string cannot be easily read by malicious persons.
  • the method further includes: the first device sends the target to the second device character string, the target character string is used by the second device to obtain the source character string according to the target correspondence and the target character string. Among them, restoring the source string through the target string can facilitate reading and improve user experience.
  • the second device appears in multiple implementations in the first aspect of the present application.
  • the second device is one or more second devices different from the first device, that is, the second devices in different embodiments may be the same computer device or different computer devices.
  • the first device executes the data from the second device according to the small stub function.
  • Load complementary real functions wherein, by storing the first complementary image in the second device, the storage space requirement of the first device can be reduced.
  • the fifth embodiment refers to the second embodiment, compared with the small image obtained according to the dependency ratio, the small image obtained by the coverage rate generally has a smaller volume, or a smaller amount of data, so it can be further reduced Demand for storage space of the first device.
  • the coverage is obtained according to the target use case set.
  • the commonly used functions of the first device can be placed in the first small mirror, and the less commonly used functions can be placed in the first complementary mirror. Therefore, a reasonable point can be found between reducing the data transmission amount, which is the data amount of the complementary real function sent by the second device to the first device, and reducing the memory requirement for the first device. Therefore, compared with the small mirror and complementary mirror obtained according to the dependency ratio, the combination of the small mirror and the complementary mirror obtained according to the coverage ratio with the distributed scene has a greater advantage.
  • the first complementary mirror image and the third A small image is stored in a different storage medium of the first device.
  • the first small image includes functions commonly used by the first device
  • the first complementary image includes functions that are not commonly used by the first device. function. Therefore, the requirements of the first device for the first small mirror image and the requirements for the first complementary mirror are different, such as reading frequency, reading speed, and the like. Therefore, storing the first complementary mirror image and the first small mirror image in different storage media, for example, storage media with different costs, can reduce the cost of the first device.
  • the seventh embodiment of the first aspect of the present application if the first device is based on a small
  • the stub function determines that the complementary real function is loaded, and the first device sends the relevant information of the complementary real function to the second device, and the relevant information is used by the second device to obtain a second small image according to the relevant information.
  • the second small image includes a set of small real functions and Complementary real functions. Wherein, adding the complementary real function to the second small mirror image can improve the speed of calling the complementary real function by the first program and improve the user experience.
  • a second aspect of the present application provides a program processing method.
  • the method includes: the second device sends a first small image to the first device, the first small image includes a small real function set and a small stub function set, the small stub function set corresponds to the complementary real function set of the first complementary image, the small real function set
  • the function set corresponds to the complementary stub function set of the first complementary image
  • the small stub function set includes small stub functions
  • the small stub function is used by the first device to determine whether to load the complementary real function corresponding to the small stub function according to the small stub function.
  • the set of functions includes complementary real functions.
  • the small stub function is specifically used by the first device to try to run the small stub function according to the instructions of the first program, and if an abnormality is detected, load the complementary function real function.
  • the small set of real functions is the set of functions that the target code runs in the process of running the set of target use cases
  • the set of complementary real functions is the set of functions that the target code does not run in the process of running the set of target use cases.
  • the target code includes a target function
  • the target function includes a target string
  • the data volume of the target string is smaller than that of the source string
  • the target code is obtained from the source code
  • the source code includes the source function
  • the source function includes the source string.
  • the target character string is used to obtain the source character string in a corresponding relationship with the target.
  • the first device stores the first A small image, the first small image and the first complementary image are stored on different devices.
  • the first complementary mirror image and the third A small image is stored in a different storage medium of the first device.
  • the second device receives the first Relevant information of complementary real functions sent by the device; the second device obtains a second small mirror image according to the relevant information, and the second small mirror image includes a set of small real functions and complementary real functions.
  • a third aspect of the present application provides an apparatus for executing a program.
  • the device is installed with a computer system, the computer system includes a first small image, and the device includes: a receiving module for receiving a request for invoking a small stub function from a first program, where the small stub function is a function in a set of small stub functions, the first A small image includes a small stub function set and a small real function set; the loading module is used to load the small stub function according to the calling request; the processing module is used to determine whether to load the complementary real function corresponding to the small stub function according to the small stub function.
  • the real function is a function in the complementary real function set.
  • the first complementary image includes a complementary real function set and a complementary stub function set.
  • the complementary stub function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.
  • the processing module is specifically configured to try to run the small stub function according to the instructions of the first program, and if an abnormality is detected, load the complementary real function.
  • the small set of real functions is the set of functions that the target code runs during the process of running the set of target use cases
  • the set of complementary real functions is the set of functions that the target code does not run in the process of running the set of target use cases.
  • the loading module is further configured to load an objective function, the objective function includes a target string, and the data amount of the target string is less than The data volume of the source string, the target code includes the target function, the target code is obtained from the source code, the source code includes the source function, and the source function includes the source string.
  • the apparatus further includes: a first sending module, configured to send a target character string to the second device, the target character string The string is used by the second device to obtain the source character string according to the target correspondence and the target character string.
  • the processing module is specifically configured to convert the Two devices load complementary real functions.
  • the first complementary mirror image and the third A small image is stored in a different storage medium of the first device.
  • the device further includes: 2.
  • the sending module is configured to send the relevant information of the complementary real function to the second device if the complementary real function is determined to be loaded according to the small stub function, and the relevant information is used for the second device to obtain the second small mirror according to the relevant information, and the second small mirror Includes a small set of real functions and complementary real functions.
  • a fourth aspect of the present application provides a computer system, the system comprising: a processor and a storage;
  • the processor is configured to receive a call request from a first program to a small stub function, where the small stub function is a function in a small stub function set, and the first small image includes the small stub function set and a small real function set ;
  • the processor is further configured to load the small stub function according to the calling request;
  • the processor is further configured to determine whether to load a complementary real function corresponding to the small stub function according to the small stub function, where the complementary real function is a function in a set of complementary real functions, and the first complementary image includes The complementary real function set and the complementary stub function set, the complementary stub function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.
  • the processor is specifically configured to try to run the small stub function according to an instruction of the first program, and if an abnormality is detected, the Load the complementary real function.
  • the set of small real functions is the set of small real functions that the target code runs in the process of running the set of target use cases A set of functions, where the set of complementary real functions is a set of functions not executed by the target code during the process of running the set of target use cases.
  • the processor is further configured to load an objective function, the objective function includes an objective string, and the objective The data volume of the string is smaller than the data volume of the source string, the target code includes the target function, the target code is obtained from the source code, the source code includes the source function, and the source function includes the source string.
  • the processor is further configured to send the target character string to the second device, where the target character string for the second device to obtain the source character string according to the target correspondence and the target character string.
  • the processor is specifically configured to The stub function loads the complementary real function from the second device.
  • the first complementary mirror image and the first small image are stored in different storage media of the first device.
  • the processor further uses If it is determined to load the complementary real function according to the small stub function, the related information of the complementary real function is sent to the second device, and the related information is used by the second device to obtain the second complementary real function according to the related information.
  • a small mirror, the second small mirror includes the set of small real functions and the complementary real functions.
  • a fifth aspect of the present application provides a program processing apparatus.
  • the apparatus includes: a sending module for sending a first small image to a first device, the first small image includes a small real function set and a small stub function set, and the small stub function set corresponds to the complementary real function set of the first complementary image,
  • the small real function set corresponds to the complementary stub function set of the first complementary image
  • the small stub function set includes the small stub function
  • the small stub function is used by the first device to determine whether to load the complementary real function corresponding to the small stub function according to the small stub function
  • the set of complementary real functions includes complementary real functions.
  • the small stub function is specifically used by the first device to try to run the small stub function according to the instructions of the first program, and if an abnormality is detected, load the complementary function real function.
  • the small set of real functions is the set of functions run by the target code in the process of running the target use case set
  • the set of complementary real functions is the set of functions that the target code does not run in the process of running the set of target use cases.
  • the target code includes a target function
  • the target function includes a target string
  • the data volume of the target string is smaller than the source string
  • the target code is obtained from the source code
  • the source code includes the source function
  • the source function includes the source string.
  • the target character string is used to obtain the source character string in a corresponding relationship with the target.
  • the first device stores the first A small image, the first small image and the first complementary image are stored in different devices, the device storing the first complementary image is used to provide a set of complementary real functions for multiple devices, and the multiple devices include the first device.
  • the first complementary mirror image and the third A small image is stored in a different storage medium of the first device.
  • the apparatus further includes: receiving The module is used to receive the related information of the complementary real function sent by the first device; the processing module is used to obtain the second small mirror image according to the relevant information, and the second small mirror image includes the small real function set and the complementary real function.
  • a sixth aspect of the present application provides a program execution device, which is characterized by comprising: a processor and a memory; the memory stores a first small image and an execution program, the first small image includes a small stub function; The processor is configured to acquire the execution program from the memory, and process the small stub function according to the execution program.
  • a specific processing method includes the method described in the first aspect or any one of the implementation manners of the first aspect.
  • a seventh aspect of the present application provides a program processing device, comprising: a processor and a memory; the memory stores a processing program; the processor is configured to acquire the processing program from the memory, according to The processing program and the source code obtain the first small image, and the specific processing method includes the method described in the second aspect or any one of the implementation manners of the second aspect.
  • An eighth aspect of the present application provides a computer storage medium, characterized in that, the computer storage medium stores instructions, and when the instructions are executed on a computer, the computer is made to execute the first aspect or any one of the first aspect.
  • a ninth aspect of the present application provides a computer program product, characterized in that, when the computer program product is executed on a computer, the computer causes the computer to execute the method according to the first aspect or any one of the implementation manners of the first aspect. , or cause the computer to execute the method according to the second aspect or any one of the implementation manners of the second aspect.
  • Fig. 1 is a schematic flow chart of function tailoring according to function dependence rate
  • Fig. 2 is the schematic flow chart of obtaining small mirror image and complementary mirror image according to source code
  • FIG. 3 is a schematic flowchart of a processing procedure in an embodiment of the present application.
  • FIG. 4 is a schematic diagram of an application scenario in an embodiment of the present application.
  • FIG. 5 is a schematic flowchart of a program processing method in an embodiment of the present application.
  • FIG. 6 is a schematic flowchart of miniaturizing character strings through “IDization” in an embodiment of the application
  • Figure 7 is a schematic diagram of the relationship between a function with a dependency relationship and a covered function in the source code
  • FIG. 8 is a schematic flowchart of obtaining a mirror image according to a coverage ratio in an embodiment of the present application.
  • FIG. 9 is a schematic flowchart of a program execution method in an embodiment of the present application.
  • FIG. 10 is a schematic structural diagram of a program execution device in an embodiment of the present application.
  • FIG. 11 is a schematic structural diagram of a program processing apparatus in an embodiment of the present application.
  • FIG. 12 is a schematic structural diagram of a first device or a second device in an embodiment of the present application.
  • the embodiments of the present application provide a program execution method, a program processing method, and a related device, which are applied to the field of program processing and can reduce the requirement of a first program on running memory.
  • Functional dependency is a mathematically derived term that characterizes the dependence of the value of one attribute or set of attributes on the value of another attribute or set of attributes.
  • R(U) be a relational schema on an attribute set U
  • X determines Y, or Y depends on X.
  • the functional dependency rate represents the proportion of functions with dependencies (or calling relationships) in the program.
  • the functional dependency rate can be obtained by the following steps: Assuming that the number of all functions in the program is N, scan the sub-functions of this program that the entry point depends on from the entry point of the program (such as main), all sub-functions and entry points. Form set A; assuming that the number of functions in set A is M, set A and the program do not include repeated functions (if set A includes repeated functions, the number of functions in set A after deduplication is M) , then the functional dependence rate of this program is equal to M/N.
  • Function coverage represents the proportion of functions that have been run in the program.
  • the function coverage can be obtained through the following steps: assuming that the number of all functions in the program is N; assuming that the program runs a set of use cases and the number of functions that have been run is K, then the function coverage is equal to K/N. Among the functions that have been run, duplicate functions are only counted once.
  • the stub function is also called stub point, stub function, and stub function.
  • the stub function is generally used to replace some interface functions and to test the characteristics of the current function.
  • the stub function in this application may be a function with a small volume or a null function in implementation.
  • the stub function in this application can be specially designed so that an exception will be generated when the stub function is executed.
  • a computer system consists of a hardware system and a software system.
  • the former is an organic combination of various physical components formed by the principles of electricity, magnetism, light, and mechanics, and is the entity on which the system works.
  • the latter are the various procedures and documents used to direct the entire system to work as specified. Therefore, macroscopically speaking, the software system of a computer system is also a program, which can also be tailored.
  • Some computer systems can provide a running environment for third-party programs, such as a computer system on a UE, a computer system on a laptop, and so on.
  • the function-granularity clipping is the smallest-granularity clipping in the above-mentioned clipping, which is referred to as function clipping for short.
  • the gcc compiler puts each function and global variable into a separate section during the source code compilation process.
  • a section can be a function or a global variable.
  • the gcc compiler identifies the dependencies between each section and entry point during the linking process, and deletes sections that have no dependencies on entry points. This is described in detail below, and some specific codes are introduced for the convenience of understanding.
  • FIG. 1 is a schematic diagram of the flow of function tailoring according to the functional dependency ratio.
  • Step 11 is the compilation phase, the gcc compiler compiles each function in the source code 101 into an independent section.
  • the source code is also called the source code.
  • the source code 101 includes four functions, namely hello1(), hello2(), hello3(), and main(). The specific content of the first three functions is not shown in Figure 1, and it is assumed here that there is no dependency between hello1(), hello2() and hello3().
  • the function main() is the entry point of the program.
  • the function main() includes the codes hello1() and hello3(), which means that hello1() and hello3() will be called when main() is executed, that is, hello1(), hello3() and There is a dependency between main().
  • a section set 102 can be obtained.
  • the section set 102 includes 4 sections, which are named .text.hello1-3 and .text.main.
  • Step 12 is the link preparation stage. The linker in the gcc compiler starts to scan the calling relationship from the entry point.
  • Step 13 is the linking stage, the linker deletes the section corresponding to the isolated function, and generates an executable file 104 .
  • the trimming basis of the above-mentioned function trimming is the function dependency rate.
  • This cropping method is generally suitable for cropping programs containing entry points (such as main), but not for cropping shared libraries and OS kernels (system kernels), such as computer systems that include shared libraries or OS kernels (system kernels).
  • system kernels shared libraries and OS kernels
  • the shared library in the computer system or the operating environment provided by the OS kernel (system kernel) for the third-party program may include a function that has no dependency on the entry point of the computer system, but has a dependency on the entry point of the third-party program relation. If the function is deleted through the above function clipping method, the third-party program may not run normally.
  • small mirror-complementary mirror technology
  • the first part is the process of obtaining small mirrors and complementary mirrors according to the source code
  • the second part is the process of using small mirrors and complementary mirrors. , which are described below.
  • FIG. 2 is a schematic flowchart of obtaining a small mirror and a complementary mirror according to the source code.
  • the computer device distinguishes the function set B that has a dependency relationship with the entry point in the source code, and the function set A that has no dependency relationship with the entry point.
  • the computer device deletes the functions in the function set A from the source code, retains the functions in the function set B, and obtains a small image.
  • the computer device retains the functions in the function set A from the source code, and replaces the functions in the function set B with empty (null) functions, that is, replaces the function set B with the empty function set, to obtain a complementary mirror image .
  • the functions in the function set A in the complementary mirror image are called real functions.
  • the empty function set in the complementary mirror corresponds to the function set B in the small mirror, or the functions of the empty function set in the complementary mirror correspond to the functions in the function set B in the small mirror one-to-one.
  • the description is made in conjunction with the source code 101 in FIG. 1 above.
  • the small image is equal to the executable file 104, and the small image includes hello1(), hello3() and main(); the complementary image includes hello2(), empty function 1, empty function 3 and empty function 2.
  • empty function 1 corresponds to hello1()
  • empty function 3 corresponds to hello3()
  • empty function 2 corresponds to main().
  • the second part is the process of using the small image and the complementary image, which is performed by the first device on which the computer system is installed.
  • code in a third-party program calls function 1 and function 2, where function 1 is the function in the small mirror and function 2 is the real function in the complementary mirror.
  • the first device loads the function 1 and the function 2 in the flash memory or the hard disk into the running memory of the first device.
  • the running memory of the first device is generally limited, and if the code of the third-party program calls too many functions, the running memory may be insufficient, causing the third-party program to fail to run.
  • the present application proposes a program processing method.
  • the computer device performing the first part of the operation does not delete the complementary real function set in the process of obtaining a small image according to the source code, but replaces the complementary real function with the stub function. function, that is, replacing the set of complementary real functions with a small set of stub functions.
  • the set of complementary real functions described here may or may not be the set of functions A described above.
  • the complementary real function set is the function set A
  • the complementary real function set is obtained according to the dependency rate
  • the complementary real function set refers to the function set that has no functional dependency relationship with the entry point in the source code
  • the complementary real function set is not a function set
  • the complementary real function set can be obtained according to the function coverage
  • the complementary real function set is the function set that the source code does not run during the process of running the target use case set.
  • the computer device In addition to replacing the complementary real function set with the small stub function set, the computer device also retains the correspondence between the small stub function set and the complementary real function set in the complementary mirror.
  • the program execution method provided by the present application is used to run a third-party program in the first device, if the third-party program includes codes for calling complementary real functions, the first device will not directly load the complementary real functions when starting the third-party program To the running memory, the small stub function corresponding to the complementary real function is loaded first.
  • the small stub function is about to run or runs, the computer device indirectly loads the complementary real function through the small stub function.
  • a small stub function can be understood as a buffer for a computer device to load complementary real functions. By increasing the buffer, it is possible to control whether to load complementary real functions, thereby reducing the demand for running memory of the third-party program. For example, when the third-party program does not enable related functions corresponding to complementary real functions, complementary real functions are not loaded.
  • FIG. 3 is a schematic flowchart of a processing procedure in an embodiment of the present application.
  • the flow of the processing program may include program writing 301 , program processing 302 , and program execution 303 .
  • Programming 301 refers to the process of generating source code, including but not limited to manual input, software generation, and the like.
  • the program processing 302 refers to the process of preprocessing the program written in whole or in part on the basis of program writing, such as automatic correction, trimming, compiling, and the like.
  • Trimming refers to reducing the size of the source code by deleting or replacing some functions in the source code.
  • the program processing 302 in the embodiment of the present application mainly includes the above-mentioned program processing method: obtaining a complementary real function set and a small real function set by trimming the source code, obtaining a small mirror image and a complementary mirror image according to the complementary real function set and the small real function set, Small mirrors include small real functions and small stub functions, and complementary mirrors include complementary real functions and complementary stub functions.
  • the program execution 303 refers to the running process of the third-party program, and the third-party program realizes its corresponding related functions by running.
  • the third-party program when the third-party program is a program related to taking pictures, the related functions can be taking pictures, photo editing, character beauty, etc. .
  • the third-party program relies on the functions in the small mirror and the complementary mirror to implement related functions.
  • the program execution 303 in the embodiment of the present application mainly includes the above-mentioned program execution method: a certain function that the third-party program actually depends on, or a certain function that the third-party program needs to call is a complementary real function, and the complementary real function is in the complementary image, When the third-party program needs to call the complementary real function, the third-party program can call the complementary real function through the small stub function in the small image.
  • FIG. 4 is a schematic diagram of an application scenario in this embodiment of the present application. As shown in FIG.
  • the source code is obtained in the second device 401 , and the source code may be compiled in the second device 401 , or It is written by other devices.
  • the second device 401 performs program processing 302 on the source code to obtain a small mirror image and a complementary mirror image.
  • the second device 401 transfers the small mirror image and the complementary mirror image to the first device 402, and the first device 402 executes the steps of program execution 303, specifically, the computer system in the first device 402 can execute the program Step 303 is performed, that is, the execution subject of the program execution method in the embodiment of the present application may be the first device 402 or the computer system 402 .
  • the first device 402 will be used as an example for description.
  • FIG. 4 will be used as an example for description in the following, and the corresponding processing in other scenarios may refer to the description of the scenario in FIG. 4 .
  • the second device 401 may be a desktop computer, a notebook, a server, or the like.
  • the first device 402 may be a wristband, a washing machine, a router, a desktop computer, a notebook, or a smart phone, or the like.
  • the second device 401 may establish a connection with the first device 402, or may not establish a connection. If the second device 401 establishes a connection with the first device 402, the connection may be a wired connection or a wireless connection, and the wireless connection may be a wireless hotspot or Bluetooth. If the second device 401 does not establish a connection with the first device 402, the small image and the complementary image can be transferred by means of a storage medium, such as a USB flash drive.
  • FIG. 5 is a schematic flowchart of a program processing method in an embodiment of the present application.
  • step 51 the second device obtains the target code according to the source code.
  • the source code may include some strings, and these strings will occupy a certain volume in the source code.
  • the program log the program log refers to the log that the program needs to record or print during the operation; for a program, the log is often recorded or printed when the critical initialization or abnormal branch occurs (to facilitate maintenance and testing).
  • the log-related strings in the source code will be compiled into the executable program, increasing the size of the program.
  • the log string In a compiled executable program, the log string generally accounts for 5% to 10% of the program volume; the impact of this part of the volume consumption on the storage space of the first device cannot be ignored.
  • the present application uses the method of "IDization" to miniaturize character strings, which will be described in detail below. Please refer to FIG. 6 .
  • FIG. 6 is a schematic flowchart of miniaturizing character strings through "IDization” in an embodiment of the present application.
  • step 511 the second device obtains a character string in the source code.
  • the specific source code is introduced below for description, and the source code includes a FuncA function.
  • Source string 1 indicates that the initialization failed and the return value is output
  • source string 2 indicates that the initialization was successful.
  • the second device obtains the source string 1.
  • step 512 the second device obtains the hash value (also called hash value or hash value) of the source string.
  • step 513 the second device determines whether a hash value conflict occurs.
  • the number of strings is not determined, and step 511 only illustrates part of the code of a function in the source code. If there are multiple strings in the source code, and the second device obtains the hash values of multiple strings, it may happen that the hash values of the two strings are the same, that is, a hash value conflict occurs. Certainly, if the source character string 1 is the first character string obtained by the second device, the operation of this step may not be performed. If the second device determines that a hash value conflict occurs, step 514 is performed; otherwise, step 511 is performed.
  • step 514 the computer determines whether the source string is the same as the source string corresponding to the hash value conflict.
  • the target correspondence list stores the correspondence between the source character string and the target character string, and the embodiment of the present application takes the target character string as the hash value as an example for description.
  • the hash value corresponding to the source string 1 is called hash value 1
  • the hash value that conflicts with hash value 1 is called hash value 3.
  • the hash value 3 is obtained by the second device according to the source string 3.
  • the computer determines whether the source string 1 is the same as the source string 3 in the target correspondence list. If the same, skip the source string 1.
  • the second device obtains the next source character string, and restarts the execution from step 511 . If not, go to step 515.
  • step 515 the second device increments the hash value by 1. In order to resolve the hash value conflict, the second device adds 1 to the hash value corresponding to the source string 1.
  • step 516 the second device determines whether to resolve the hash value conflict. If not, go to step 515 until the hash value conflict is resolved. If so, the second device obtains the next source character string, and restarts the execution from step 511 .
  • the second device can obtain the target character string corresponding to the source character string and the target correspondence.
  • the second device replaces the source string in the source function with the target string to obtain the target function.
  • the above FuncA is the source function, and the target function is as follows.
  • the hash value 1 is afab9b15
  • the hash value corresponding to the source string 2 is 8a52d706.
  • the above-mentioned objective function and source function have the same other functions, and the objective function corresponds to the source function.
  • step 52 the second device obtains a set of small real functions and a set of complementary real functions according to the target code.
  • the set of complementary real functions may be the set of functions A obtained according to the functional dependency ratio in FIG. 2, or may be obtained according to the function coverage ratio.
  • the small real function set may be the function set B obtained according to the function dependency ratio in FIG. 2 , or may be obtained according to the function coverage ratio.
  • step 42 may refer to the process of obtaining the function set A by the computer device in the foregoing FIG. 2 .
  • the process of obtaining a small set of real functions and a set of complementary real functions by the second device according to the function coverage is mainly described.
  • function coverage refers to the ratio of the number of functions run by the source code in the process of running the target use case set to the number of functions in the source code.
  • the run function nor the function in the source code include duplicate functions.
  • different use cases or even the same use case may call a function repeatedly. But when counting the number of functions that have been run, the function will only be counted once.
  • the definition of function coverage the definition of small real function set and complementary real function set can be obtained.
  • the small set of real functions is the set of functions that the target code runs during the process of running the set of target use cases
  • the set of complementary real functions is the set of functions that the target code does not run during the process of running the set of target use cases.
  • the second device compiles the target code, and runs the target use case set through the compiled target code.
  • the set of target use cases includes all or part of the functions that can be performed by the compiled target code.
  • the functions that the target code can perform include taking pictures, editing photos, and beautifying people.
  • the target use case set includes any one or more of the 3 functions.
  • the set of target use cases includes photo taking and photo editing.
  • the second device can pass the program compiled by the target code to a certain device (for example, the first device), so that a certain device can run photography and photo editing by installing the program compiled by the target code, and return the function coverage information to the second device. .
  • the second device obtains a small set of real functions and a set of complementary real functions according to the function coverage information. Or the second device simulates the functions of taking pictures and photo editing through the object code. After that, the second device counts the function set that the target code has run and the function set that has not been run during the process of running the target use case set, the run function set is the small real function set, and the unrun function set is the complementary real function set. Function set, the ratio of the number of functions in the run function set to the number of functions in the target code is the function coverage of the target code. It should be understood that the examples of the target use case set here are only for the convenience of the technical solutions in the embodiments of the present application, and cannot be used as conditions for limiting the present application. For example, the compiled object code can return a value to the third-party program, and returning a value to the third-party program also belongs to the function that the compiled object code can execute.
  • the second device obtains the small set of real functions and the set of complementary real functions through the target code. It should be understood that, since the target code and the source code are corresponding, the second device can also obtain the small real function set and the complementary real function set through the source code.
  • the second device transmits a program compiled from source code to the first device, and the first device runs photographing and photo editing by installing the program compiled from source code.
  • the first device returns function coverage information to the second device.
  • the function coverage information includes a set of serial numbers corresponding to functions that have been run in the source code. In the source code and object code, all functions are numbered according to their order, that is, each function has its corresponding serial number.
  • the corresponding functions have the same serial number, such as the source function and the target function. Therefore, even if the sequence number returned by the first device is the sequence number set corresponding to the function in the source code, the second device can determine the small real function set in the target code according to the sequence number set, and then determine the complementary real function set.
  • step 53 the second device obtains a set of complementary stub functions according to the set of small real functions, and obtains a set of small stub functions according to the set of complementary real functions.
  • the second device replaces each function of the small real function set with a stub function to obtain a complementary stub function set; and replaces each function of the complementary real function set with a stub function to obtain a small stub function set.
  • step 54 and step 55 the second device obtains the small mirror image according to the small real function set and the small stub function set, and obtains the complementary mirror image according to the complementary real function set and the complementary stub function set.
  • the second device compiles the code composed of the small real function set and the small stub function set to obtain the small mirror image; the second device compiles the code composed of the complementary real function set and the complementary stub function set to obtain the complementary mirror image.
  • the second device replaces the set of complementary real functions in the source code with a set of small stub functions, and then compiles the source code to obtain a small image; the second device replaces the set of small real functions in the source code with a set of complementary stub functions, and then compiles the source code to obtain complementary mirror.
  • the second device needs to retain the correspondence between the set of small stub functions and the set of complementary real functions, that is, one small stub function corresponds to one complementary real function.
  • the second device may generate a mapping table, and the mapping table includes the correspondence between the small stub function and the complementary real function.
  • the second device sets the function name of the complementary real function to be the same as or similar to the function name of the small stub function, so as to preserve the corresponding relationship between the small stub function and the complementary real function.
  • the set of small stub functions of the smallest mirror and the set of complementary real functions of the complementary mirror are sorted in the same order, and the set of small real functions of the smallest mirror and the set of complementary stub functions of the complementary mirror are sorted in the same order, so that the loader can Function load, find the offset address of the function.
  • the second device may retain the correspondence between the small stub function and the complementary real function through the serial number of the function.
  • the small stub function set and the complementary real function set number the functions according to the order of their functions, and the corresponding functions have the same serial number.
  • the small stub function and the complementary real function have the same serial number.
  • the first device may call the complementary real function through the exception of the small stub function.
  • the second device may make the small stub function non-executable. Specifically, the second device aggregates all small stub functions into a separate section, aligns the address of this section according to the page size, and sets the attribute of this section to be non-executable.
  • the small stub functions are empty functions.
  • exceptions can also be implemented by code in small stub functions.
  • the following specifically provides an example of a small stub function.
  • the function name of the small stub function is Int F4func.
  • the first device executes the above small stub function, the first device first pushes the registers r0 to r2 into the stack, and then assigns a value to the r0 register.
  • the assigned value is a An address that can generate an exception when accessed.
  • this instruction stores the r1 register into the address pointed to by r0; because r0 stores the address that will generate an exception when accessing, this instruction will generate a data exception.
  • step 51 may not be executed, and the target code in step 52 at this time is the source code. If the above step 51 is executed, the essence of step 51 is to replace the source function with the target function. Therefore, there is no strict timing requirement between step 51 and steps 52-53.
  • the second device can replace the source function with the target function after obtaining the small mirror image and the complementary mirror image through steps 55 and 54 ; or the second device can complete step 51 while executing step 52 . There are also no strict timing requirements between steps 54 and 55.
  • FIG. 7 is a schematic diagram of the relationship between the functions with dependencies in the source code and the overridden functions.
  • a function with a dependency refers to a set of functions that have a dependency on the entry point in the source code.
  • Covered functions refer to the set of functions that are run during the process of running the set of target use cases through the source code. In general, since functions that have dependencies on entry points do not necessarily run in the process of running the use case set, the scope of functions with dependencies is generally larger than that of covered functions.
  • the small real function set is smaller than the function set B, so the volume of the small mirror obtained according to the coverage ratio (referred to as small mirror 1) is generally smaller than the volume of the small mirror obtained according to the dependency ratio (referred to as small mirror 2). Because the stub function can be an empty function, the volume of the small stub function is ignored here.
  • the first device can reduce costs in a number of ways. For example, the first device places the small mirror 1 and the complementary mirror 1 in different storage media, and the different storage media includes storage medium 1 and storage medium 2, the small mirror 1 is stored in the storage medium 1, and the complementary mirror 1 is stored in the storage medium medium 2. In the case of the same storage space size, the cost of the storage medium 2 is lower than the cost of the storage medium 1.
  • the first device can save the storage space of the storage medium 1, that is, reduce the cost of the first device on the storage medium.
  • the first device stores the small image 1 locally, and the complementary image 1 is stored in the cloud platform or the central device. In this case, the cost of the first device is also reduced. Further, the cloud platform or the central device provides the complementary image 1 for the multiple first devices, which can save the cost of the multiple first devices.
  • the mirror image obtained according to the coverage rate is suitable for the scenario of the product family.
  • low-end products providing smaller specifications or tailored functions
  • mid-end products providing standard functions
  • high-end products providing high-specification and richer functions.
  • the functions of low-end products include taking pictures
  • the functions of mid-end products include taking pictures and photo editing
  • the functions of high-end products include taking pictures, photo editing and character beauty.
  • products of the same product family generally use the same design scheme, the same software version, that is, the same image.
  • the second device can run the target code with different target use case sets, thereby obtaining different function coverages, that is, obtaining different small mirrors and complementary mirrors.
  • target use case set 1 For example, for small mirrors and complementary mirrors that need to be used in high-end products, the second device runs target use case set 1 through the target code, and target use case set 1 includes taking pictures, photo editing and people beauty.
  • the second device runs target use case set 2 through target code, and target use case set 2 includes taking pictures and photo clips.
  • target use case set 3 For small mirrors and complementary mirrors that need to be used in low-end products, the second device runs target use case set 3 through the target code, and target use case set 3 includes taking pictures.
  • the functional dependency rate is fixed, but the functional coverage can be adjusted according to the target set of use cases. Therefore, the mirror image obtained according to the coverage rate is suitable for the scene of the product family.
  • a certain product family includes low-end, mid-range and high-end products
  • the image of the low-end product is obtained according to the target use case set 1
  • the image of the mid-end product is obtained according to the target use case set 2
  • the high-end product image is obtained according to the target use case set 2.
  • the image of is obtained from target use case set 3
  • target use case set 1 is a subset of target use case set 2
  • target use case set 2 is a subset of target use case set 3.
  • the three products are products of the same product family; for example, when the product names corresponding to these three products are similar, the three products are products of the same product family
  • the low-end product is named ZXX5-m
  • the mid-end product is named ZXX5
  • the high-end product is named ZXX5-pro or ZXX5-sup or ZXX5-mate.
  • a certain product family includes low-end and high-end products, the image of the low-end product is obtained according to the target use case set 1, and the image of the high-end product is obtained according to the target use case set 2, and the target use case set 1 is the target A subset of use case set 2.
  • the source code (such as shared library, OS kernel) with "external function interface” can be trimmed according to the trimming of coverage.
  • the compiler cannot predict which interfaces in the external interface set of this source code will be used by the third-party program.
  • the C library glibc provides thousands of external function interfaces.
  • the compiler cannot Predict which interfaces in the glibc external interface set will be used by third-party programs. According to the tailoring of coverage, some or all of the external function interfaces in the C library glibc can be called by setting the target use case set, so that some or all of the functions in the external function interface are in a small set of real functions.
  • FIG. 8 is a schematic flowchart of obtaining a mirror image according to a coverage ratio in an embodiment of the present application.
  • the small real function set in Figure 8 is the function that runs in the process of running the target use case set from the source code
  • the complementary real function set is the function that is not run in the process of running the target use case set from the source code
  • the stub function set can be an empty function set.
  • the program processing method provided by the present application is described above.
  • the second device obtains a small mirror image and a complementary mirror image according to the source code.
  • the small mirror image is also called the first small mirror image
  • the complementary mirror image is also called the first small mirror image. Complementary mirror image.
  • the first device can use the method described in FIG. 2 to run the small mirror and complementary mirror, that is, the first device does not call the complementary mirror in the complementary mirror through the small stub function in the small mirror real function. Specifically, reference may be made to the relevant description in the aforementioned FIG. 2 .
  • the program execution method provided by the present application is described below.
  • the first device will call the complementary real function through the small stub function.
  • the descriptions related to the program execution method in the above program processing method such as the content included in the small image and the complementary image, and the content included in the small stub function, can be referred to the program execution method accordingly.
  • FIG. 9 is a schematic flowchart of a program execution method in an embodiment of the present application.
  • the first device receives a call request for the small stub function.
  • the first device loads the functions to be called by the first program into the running memory, and the functions to be called by the first program include complementary real functions.
  • the call request corresponding to the real function).
  • the code in the first program will include the function name of the small stub function.
  • the first device preferentially searches the small image for the function name, so as to load the searched small stub function into the running memory.
  • the function that the first program needs to call does not mean that the first device must run the function.
  • the function will be stored in the running memory, waiting for the corresponding relevant function to be started.
  • the functions to be called by the first program may include functions in the small real function set, or may not include functions in the small real function set.
  • the first program may be in the hard disk in FIG. 9 .
  • the first program is not necessarily a third-party program, and may also be a self-contained program of the computer system of the first device.
  • the first device loads the small stub function according to the calling request.
  • the small image includes a small stub function collection and a small real function collection, and the small stub function collection includes a small stub function.
  • the first device loads the small stub function in the small image according to the calling request.
  • the first device determines to load a complementary real function corresponding to the small stub function according to the small stub function.
  • the first device will try to run the small stub function, and if an abnormality is detected, the first device loads the complementary real function.
  • the complementary functions are dynamically linked, and the first device calls the loader to load the complementary real functions.
  • the loader loads the complementary real function in the complementary image from a specific path according to the small stub function.
  • the "specific path" described here refers to an agreed and fixed path; for example, the system often searches for libraries under /lib and /usr/lib by default.
  • the above program processing method specifically describes two ways to generate exceptions, one of which is to set the attribute corresponding to the section where the small stub function is located to be non-executable. Attributes generally include whether it is readable, whether it is writable, and whether it is executable. When this property is set to non-executable, the first device cannot run the small stub function, thereby detecting the exception. Another way is to implement exceptions through the content of the code in a small stub function. In the first way, the first device does not run the code in the small stub function; in the second way, the first device runs part of the code in the small stub function.
  • Loading complementary real functions by detecting anomalies is a preferred method in this embodiment of the present application.
  • the first device can know that the first program will start relevant functions corresponding to complementary real functions, and then load complementary real functions. And before the first device detects an exception, the first device does not load the complementary real function. When an exception is detected, it means that the small stub function has not been successfully executed. At this time, the first program will not continue to execute because the small stub function has been executed. Therefore, the embodiment of the present application not only increases the buffer for loading complementary real functions, but also suspends the first program, which provides a time basis for loading complementary real functions, reduces possible errors in the first program, and improves user experience.
  • the method of loading complementary real functions by detecting anomalies has been described above, and a method of loading complementary real functions without detecting anomalies is described below.
  • the first device monitors a physical address, and when the value in the physical address is refreshed, the first device can monitor the refresh this time.
  • the small stub function contains code that writes a value at that physical address.
  • the first program runs the relevant function corresponding to the complementary real function
  • the first device runs a small stub function, and writes a certain value in the physical address.
  • the first device suspends the running of the first program through the processor, searches for the complementary real function in the complementary mirror according to the small stub function and the corresponding relationship, and loads the complementary real function through the loader.
  • the first device needs to monitor the refresh of the physical address at all times, and the processor needs to suspend the first program in time, otherwise the first program may regard the small stub function as a complementary real function, thereby skipping the complementary real function Called, causing an exception in the business of the first program.
  • the second device retains the correspondence between the small stub function and the complementary real function. name. If the corresponding relationship is a serial number, the first device can obtain the serial number of the small stub function. When the complementary real function needs to be loaded through the small stub function, the second device uses the serial number to load the complementary real function with the same serial number in the complementary mirror. If the corresponding relationship is a mapping table, the first device also needs to acquire the mapping table. If the correspondence is a function name, the function name of the small stub function can be the same as or similar to the function name of the complementary real function.
  • the second device replaces the source function in the source code with the target function through "IDization", and generates the target correspondence. Therefore, the objective function is included in the small image and/or complementary image obtained from the source code.
  • the first device can obtain the target character string. The first device sends the target string to the second device or other device, and the second device or other device obtains the source string through the target correspondence of the target string. If the string is a log, the restored source string is generally in a human-readable language.
  • the objective function may be a function in a small set of real functions or a function in a set of complementary real functions, that is, the objective function may be a complementary real function.
  • the first device may also store the target correspondence, and when the source character string needs to be read, the first device obtains the source character string according to the target correspondence relation and the target character string.
  • the first device locally stores the small image 1, and the complementary image 1 is stored in the second device
  • the second device may be a cloud platform or a central device
  • the second device here may be the above-mentioned program
  • the second device in the processing method may not be the second device in the above program processing method.
  • the first device needs to call the complementary real function in the complementary image
  • the first device calls the complementary real function from the cloud platform or the central device, thereby reducing the cost of the first device.
  • the second device provides the complementary mirror image 1 for the multiple first devices, which can save the cost of the multiple first devices.
  • the small mirrors in the embodiments of the present application are dynamically linked. Through the dynamic linking, the occupation of the running memory of the first device by the first program is further reduced.
  • the first device after the first device calls the complementary real function according to the program execution method in the embodiment of the present application, the first device sends relevant information about the complementary real function to the second device or other devices, and the second device can Mirrors update small mirrors and complementary mirrors.
  • the small mirror and the complementary mirror before the update are called the first small mirror and the first complementary mirror
  • the small mirror and the complementary mirror after the update are called the second small mirror and the second complementary mirror.
  • the complementary real function is in the set of complementary real functions of the first complementary mirror
  • the complementary real function is in the set of small real functions in the second small mirror.
  • the second device enlarges the volume or range of the set of small real functions and reduces the volume or range of the set of complementary real functions.
  • FIG. 10 is a schematic structural diagram of a program execution apparatus according to an embodiment of the present application.
  • the device includes: a receiving module 1001, configured to receive a call request from a first program to a small stub function, the small stub function is a function in a small stub function set, and the first small image includes a small stub function set and a small real function set;
  • Loading module 1002 for loading small stub functions according to the calling request
  • the processing module 1003 is configured to determine whether to load the complementary real function corresponding to the small stub function according to the small stub function, the complementary real function is a function in the complementary real function set, and the first complementary image includes the complementary real function set and the complementary stub function set , the set of complementary stub functions corresponds to the set of small real functions, and the set of complementary real functions corresponds to the set of small stub functions.
  • the apparatus may further include a first sending module or a second sending module or the like.
  • the modules in the apparatus are specifically configured to perform all or part of the operations that can be performed by the first device in the foregoing embodiment corresponding to FIG. 9 .
  • FIG. 11 is a schematic structural diagram of a program processing apparatus according to an embodiment of the present application.
  • the apparatus includes: a sending module 1101, configured to send a first small image to a first device, where the first small image includes a small real function set and a small stub function set, and the small stub function set corresponds to the complementary real function set of the first complementary image , the small real function set corresponds to the complementary stub function set of the first complementary mirror, the small stub function set includes small stub functions, and the small stub function is used by the first device to determine whether to load the complementary real function corresponding to the small stub function according to the small stub function , the set of complementary real functions includes complementary real functions.
  • the apparatus may further include a receiving module or a processing module or the like.
  • the modules in the apparatus are specifically configured to perform all or part of the operations that can be performed by the second device in the embodiment corresponding to FIG. 5 or FIG. 6 .
  • FIG. 12 is a schematic structural diagram of a first device or a second device in an embodiment of the present application.
  • an apparatus for processing a program or an apparatus for executing a program 1200 includes a processor 1210 and a memory 1220 coupled to the processor 1210 .
  • the processor 1210 may be a central processing unit (CPU), a network processor (NP), or a combination of CPU and NP.
  • the processor may also be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof.
  • ASIC application-specific integrated circuit
  • PLD programmable logic device
  • the above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a general-purpose array logic (generic array logic, GAL) or any combination thereof.
  • the processor 1210 may refer to one processor, or may include multiple processors.
  • the memory 1220 may include volatile memory (volatile memory), such as random-access memory (RAM); the memory 1220 may also include non-volatile memory (non-volatile memory), such as read-only memory (read only memory) -only memory, ROM), FRAM memory, flash memory (flash memory), hard disk drive (HDD) or solid-state drive (solid-state drive, SSD); the memory 1220 may also include a combination of the above types of memory.
  • volatile memory such as random-access memory (RAM)
  • non-volatile memory such as read-only memory (read only memory) -only memory, ROM), FRAM memory, flash memory (flash memory), hard disk drive (HDD) or solid-state drive (solid-state drive, SSD
  • the memory 1220 may also include a combination of the above types of memory.
  • Figure 12 is a schematic structural diagram of a program execution device:
  • the processor 1210 is configured to receive a call request for a small stub function from the first program, the small stub function is a function in a small stub function set, and the first small image includes a small stub function set and a small real function set; load the small stub function according to the calling request. stub function; determine whether to load the complementary real function corresponding to the small stub function according to the small stub function, the complementary real function is a function in the complementary real function set, the first complementary image includes the complementary real function set and the complementary stub function set, the complementary stub
  • the function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.
  • the processor 1210 is further configured to, after executing the computer-readable instructions in the memory 1220, execute all or part of the operations that can be performed by the first device according to the instructions of the computer-readable instructions. Operations performed in the embodiment corresponding to FIG. 9 .
  • Figure 12 is a schematic structural diagram of a program processing device:
  • the processor 1210 is configured to send a first small image to the first device, where the first small image includes a small real function set and a small stub function set, the small stub function set corresponds to the complementary real function set of the first complementary image, and the small real function set Corresponding to the complementary stub function set of the first complementary image, the small stub function set includes small stub functions, and the small stub function is used by the first device to determine whether to load the complementary real function corresponding to the small stub function according to the small stub function, and the complementary real function set Complementary real functions are included.
  • the processor 1210 is further configured to, after executing the computer-readable instructions in the memory 1220, execute all or part of the operations that can be performed by the second device according to the instructions of the computer-readable instructions. Operations performed in the embodiment corresponding to FIG. 5 or FIG. 6 .
  • the disclosed system, apparatus and method may be implemented in other manners.
  • the apparatus embodiments described above are only illustrative.
  • the division of the units is only a logical function division. In actual implementation, there may be other division methods.
  • multiple units or components may be combined or Can be integrated into another system, or some features can be ignored, or not implemented.
  • 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 as separate components may or may not be physically separated, and components displayed 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.
  • 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.
  • the above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units.
  • the integrated unit if implemented in the form of a software functional unit and sold or used as an independent product, may be stored in a computer-readable storage medium.
  • the technical solutions of the present application can be embodied in the form of software products in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, and the computer software products are stored in a storage medium , including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
  • the aforementioned storage medium includes: a flash disk, a removable hard disk, a ROM, a RAM, a magnetic disk or an optical disk and other mediums that can store program codes.

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

本申请公开了一种程序执行方法,可以应用于程序处理领域,该方法包括:接收第一程序对小型stub函数的调用请求,根据调用请求加载小型stub函数;根据小型stub函数确定是否加载与小型stub函数对应的互补实函数。其中,第一程序实际可能需要调用的函数为互补实函数,小型stub函数可以理解为加载互补实函数的缓冲。通过增加缓冲,可以控制是否加载互补实函数,从而可以减少第一程序对运行内存的需求。

Description

程序执行方法、程序处理方法以及相关设备
本申请要求于2020年10月31日提交中国专利局、申请号为202011198663.0、发明名称为“程序执行方法、程序处理方法以及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及程序处理领域,尤其涉及一种程序执行方法、程序处理方法以及相关设备。
背景技术
为了简化计算机***中的软件***对设备内存的占用,工业界使用“小型化操作***(Operating System,OS)-互补OS”的技术,小型化OS也称小型镜像,互补OS也称互补镜像。
小型镜像和互补镜像技术是指计算机设备根据源代码生成小型镜像和互补镜像的过程以及使用小型镜像和互补镜像的过程。具体生成方式如下:首先,计算机设备区分源代码中与程序的入口点entry point有依赖关系的函数集合B,以及与entry point没有依赖关系的函数集合A。计算机设备从源代码中删除函数集合A中的函数,保留函数集合B中的函数,获得小型镜像;计算机设备从源代码中保留函数集合A中的函数,将函数集合B中的函数用空(null)函数代替,获得互补镜像。其中,将互补镜像中的函数集合A中的函数称为实函数。互补镜像中的空函数集合和小型镜像中的函数集合B对应,或者说互补镜像中的空函数集合的函数和小型镜像中的函数集合B中的函数一一对应。小型镜像是静态链接,互补镜像是动态链接。当有第三方程序中的代码包括互补镜像中的某个函数,在启动第三方程序时,第一设备会提前将该函数加载至运行内存,等待该函数被执行。
第一设备的运行内存一般有限,若第三方程序的代码调用的函数过多,可能会导致运行内存不足,使得第三方程序运行失败。
发明内容
本申请提供了一种程序执行方法、程序处理方法以及相关设备,可以减少第一程序对运行内存的需求。
本申请第一方面提供了一种程序执行方法,应用于计算机***,所述计算机***包括第一小型镜像,该方法可以由计算机***执行,也可以由安装有计算机***的第一设备执行,下面将以该方法可以由第一设备执行为例进行阐述。
该方法包括:第一设备接收第一程序对小型stub函数的调用请求,小型stub函数为小型stub函数集合中的一个函数,第一小型镜像包括小型stub函数集合和小型实函数集合;第一设备根据调用请求加载小型stub函数;第一设备根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数为互补实函数集合中的一个函数,第一互补镜像包括互补实函数集合和互补stub函数集合,互补stub函数集合与小型实函数集合对应, 互补实函数集合与小型stub函数集合对应。
其中,第一程序实际可能需要调用的函数为互补实函数,小型stub函数可以理解为加载互补实函数的缓冲。通过增加缓冲,可以控制是否加载互补实函数,从而可以减少第一程序对运行内存的需求,例如第一程序未启用与互补实函数对应的相关功能时,不加载互补实函数。
基于本申请第一方面,在本申请第一方面的第一种实施方式中,第一设备根据第一程序的指令尝试运行小型stub函数,若检测到异常,则加载互补实函数。其中,当第一程序要启用与互补实函数对应的相关功能时,第一设备可以接收到第一程序的指令。需要说明的是,该指令具体可以是第一程序的代码(或代码调用的函数)中某个影响程序流程的判断变量的变化,该判断变量的变化会触发小型stub函数的运行。在触发小型stub函数后,第一设备尝试运行小型stub函数。尝试是指第一设备并不一定能运行小型stub函数,可能只是有试图运行小型stub函数的意图,例如获取了小型stub函数的地址,做好了运行小型stub函数的部分准备。通过检测异常,第一设备可以知道第一程序将要启动与互补实函数对应的相关功能,进而加载互补实函数。反过来说,在检测到该异常前,第一设备可以无需加载互补实函数。简单来说,本申请通过检测小型stub函数的相关异常来触发加载互补实函数。当检测到异常,说明小型stub函数未成功运行完毕,此时第一程序不会因为小型stub函数执行完毕而继续执行。因此,本申请不仅为加载互补实函数增加了缓冲,还暂停了第一程序,为加载互补实函数提供了时间上的基础,减少了第一程序可能发生的错误,提升用户体验。
基于本申请第一方面,或第一方面的第一种实施方式,在本申请第一方面的第二种实施方式中,小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,互补实函数集合为所述目标代码在运行所述目标用例集合过程中未运行的函数集合。其中,将根据上述小型实函数集合和互补实函数集合得到的小型镜像和互补镜像称为根据覆盖率得到的小型镜像和互补镜像。将根据背景技术中的函数集合B和函数集合A得到的小型镜像和互补镜像称为根据依赖率得到的小型镜像和互补镜像。在一些场景中,根据覆盖率得到的小型镜像中的小型实函数集合会小于根据依赖率得到的小型镜像中的函数集合B。小型实函数集合的范围越小,第一程序直接加载的函数的数量越少,从而进一步减少第一程序对运行内存需求。直接加载是指不通过小型stub函数加载。为了方便描述,将通过小型stub函数加载的函数称为间接加载的函数。间接加载的函数并不会直接被加载至第一设备的运行内存,而是在第一程序启用该函数相关的功能时,第一设备才将该函数加载至运行内存。若第一设备不启动该函数相关的功能,则第一设备可以不加载该函数。简单来说,直接加载的函数的范围变小了,间接加载的函数的范围变大了。
基于本申请第一方面的第二种实施方式,在本申请第一方面的第三种实施方式中,该方法还包括:第一设备加载目标函数,目标函数包括目标字符串,目标字符串的数据量小于源字符串的数据量,目标代码包括目标函数,目标代码是根据源代码得到的,源代码包括源函数,源函数包括源字符串。其中,源函数和目标函数对应,此处的对应是指源函数和目标函数对字符串的处理能力相同,但是具体处理的字符串不同,一个为目标字符串,一个为源字符串。在许多场景中,用户并不需要通过第一设备阅读源字符串,例如洗衣机 的日志数据,UE的告警日志。当与源字符串对应的函数被加载时,这些源字符串也会被加载至运行内存,从而占用第一设备的运行内存。本申请通过使用“ID化”的方法处理源字符串,可以减少对第一设备的运行内存的需求,并且增加了源字符串的安全性,源字符串不容易被恶意者读取。
基于本申请第一方面的第三种实施方式,在本申请第一方面的第四种实施方式中,在第一设备加载目标函数后,该方法还包括:第一设备向第二设备发送目标字符串,目标字符串用于第二设备根据目标对应关系和目标字符串得到源字符串。其中,通过目标字符串还原源字符串,可以方便阅读,提升用户体验。
需要说明的是,为了描述方便,本申请第一方面中的多个实施方式中出现了第二设备。该第二设备是不同于第一设备的一个或多个第二设备,即不同实施方式中的第二设备可以是同一个计算机设备,也可以是不同的计算机设备。
基于本申请第一方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第一方面的第五种实施方式中,第一设备根据小型stub函数从第二设备加载互补实函数。其中,通过将第一互补镜像存储在第二设备中,可以减少对第一设备的存储空间的需求。当第五种实施方式引用第二种实施方式时,相比于根据依赖率得到的小型镜像,通过覆盖率得到的小型镜像一般有着更小体积,或者说更小的数据量,因此可以进一步减少对第一设备的存储空间的需求。并且,覆盖率根据目标用例集合得到,通过合理设置目标用例集合,可以使得第一设备常用的函数在第一小型镜像中,不常用的函数在第一互补镜像。从而可以在降低数据传输量和减小对第一设备的内存需求之间找到一个合理的点,该数据传输量为第二设备向第一设备发送的互补实函数的数据量。因此,相比于根据依赖率得到的小型镜像和互补镜像,根据覆盖率得到的小型镜像和互补镜像与分布式场景的结合有着更大的优势。
基于本申请第一方面,或第一方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第一方面的第六种实施方式中,第一互补镜像和第一小型镜像存储于第一设备的不同存储介质中。其中,当第六种实施方式引用第二种实施方式时,根据上述第五种实施方式的描述可知,第一小型镜像包括第一设备常用的函数,第一互补镜像包括第一设备不常用的函数。因此,第一设备对第一小型镜像的需求和对第一互补镜像的需求是不同的,例如读取频率,读取速度等。因此,将第一互补镜像和第一小型镜像存储于不同的存储介质,例如不同成本的存储介质中,可以降低第一设备的成本。
基于本申请第一方面,或第一方面的第一种实施方式至第六种实施方式中的任一实施方式,在本申请第一方面的第七种实施方式中,若第一设备根据小型stub函数确定加载互补实函数,则第一设备向第二设备发送互补实函数的相关信息,相关信息用于第二设备根据相关信息得到第二小型镜像,第二小型镜像包括小型实函数集合和互补实函数。其中,将互补实函数加入第二小型镜像,可以提升第一程序调用该互补实函数的速度,提升用户体验。
本申请第二方面提供了一种程序处理方法。
该方法包括:第二设备向第一设备发送第一小型镜像,第一小型镜像包括小型实函数集合和小型stub函数集合,小型stub函数集合与第一互补镜像的互补实函数集合对应,小 型实函数集合与第一互补镜像的互补stub函数集合对应,小型stub函数集合包括小型stub函数,小型stub函数用于第一设备根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数集合包括互补实函数。
关于对本申请第二方面的有益效果的描述,可以参考前述对本申请第一方面的有益效果的描述。
基于本申请第二方面,在本申请第二方面的第一种实施方式中,小型stub函数具体用于第一设备根据第一程序的指令尝试运行小型stub函数,若检测到异常,则加载互补实函数。
基于本申请第二方面,或第二方面的第一种实施方式,在本申请第二方面的第二种实施方式中,小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,互补实函数集合为目标代码在运行目标用例集合过程中未运行的函数集合。
基于本申请第二方面的第二种实施方式,在本申请第二方面的第三种实施方式中,目标代码包括目标函数,目标函数包括目标字符串,目标字符串的数据量小于源字符串的数据量,目标代码是根据源代码得到的,源代码包括源函数,源函数包括源字符串。
基于本申请第二方面的第三种实施方式,在本申请第二方面的第四种实施方式中,目标字符串用于和目标对应关系得到源字符串。
基于本申请第二方面,或第二方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第二方面的第五种实施方式中,第一设备存储有第一小型镜像,第一小型镜像和第一互补镜像存储于不同的设备。
基于本申请第二方面,或第二方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第二方面的第六种实施方式中,第一互补镜像和第一小型镜像存储于第一设备的不同存储介质中。
基于本申请第二方面,或第二方面的第一种实施方式至第六种实施方式中的任一实施方式,在本申请第二方面的第七种实施方式中,第二设备接收第一设备发送的互补实函数的相关信息;第二设备根据相关信息得到第二小型镜像,第二小型镜像包括小型实函数集合和互补实函数。
本申请第三方面提供了一种执行程序的装置。该装置安装有计算机***,计算机***包括第一小型镜像,该装置包括:接收模块,用于接收第一程序对小型stub函数的调用请求,小型stub函数为小型stub函数集合中的一个函数,第一小型镜像包括小型stub函数集合和小型实函数集合;加载模块,用于根据调用请求加载小型stub函数;处理模块,用于根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数为互补实函数集合中的一个函数,第一互补镜像包括互补实函数集合和互补stub函数集合,互补stub函数集合与小型实函数集合对应,互补实函数集合与小型stub函数集合对应。
基于本申请第三方面,在本申请第三方面的第一种实施方式中,处理模块具体用于根据第一程序的指令尝试运行小型stub函数,若检测到异常,则加载互补实函数。
基于本申请第三方面,或第三方面的第一种实施方式,在本申请第三方面的第二种实施方式中,小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,互补实函数集合为目标代码在运行目标用例集合过程中未运行的函数集合。
基于本申请第三方面的第二种实施方式,在本申请第三方面的第三种实施方式中,加载模块还用于加载目标函数,目标函数包括目标字符串,目标字符串的数据量小于源字符串的数据量,目标代码包括目标函数,目标代码是根据源代码得到的,源代码包括源函数,源函数包括源字符串。
基于本申请第三方面的第三种实施方式,在本申请第三方面的第四种实施方式中,该装置还包括:第一发送模块,用于向第二设备发送目标字符串,目标字符串用于第二设备根据目标对应关系和目标字符串得到源字符串。
基于本申请第三方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第三方面的第五种实施方式中,处理模块具体用于根据小型stub函数从第二设备加载互补实函数。
基于本申请第三方面,或第三方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第三方面的第六种实施方式中,第一互补镜像和第一小型镜像存储于第一设备的不同存储介质中。
基于本申请第三方面,或第三方面的第一种实施方式至第六种实施方式中的任一实施方式,在本申请第三方面的第七种实施方式中,该装置还包括:第二发送模块,用于若根据小型stub函数确定加载互补实函数,则向第二设备发送互补实函数的相关信息,相关信息用于第二设备根据相关信息得到第二小型镜像,第二小型镜像包括小型实函数集合和互补实函数。
本申请第四方面提供了一种计算机***,该***包括:处理器和储存器;
所述储存器中存储有第一小型镜像;
所述处理器用于接收第一程序对小型stub函数的调用请求,所述小型stub函数为小型stub函数集合中的一个函数,所述第一小型镜像包括所述小型stub函数集合和小型实函数集合;
所述处理器还用于根据所述调用请求加载所述小型stub函数;
所述处理器还用于根据所述小型stub函数确定是否加载与所述小型stub函数对应的互补实函数,所述互补实函数为互补实函数集合中的一个函数,所述第一互补镜像包括所述互补实函数集合和互补stub函数集合,所述互补stub函数集合与所述小型实函数集合对应,所述互补实函数集合与所述小型stub函数集合对应。
基于本申请第四方面,在本申请第四方面的第一种实施方式中,所述处理器具体用于根据所述第一程序的指令尝试运行所述小型stub函数,若检测到异常,则加载所述互补实函数。
基于本申请第四方面,或第四方面的第一种实施方式,在本申请第四方面的第二种实施方式中,所述小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,所述互补实函数集合为所述目标代码在运行所述目标用例集合过程中未运行的函数集合。
基于本申请第四方面的第二种实施方式,在本申请第四方面的第三种实施方式中,所述处理器还用于加载目标函数,所述目标函数包括目标字符串,所述目标字符串的数据量小于源字符串的数据量,所述目标代码包括所述目标函数,所述目标代码是根据源代码得到的,所述源代码包括源函数,所述源函数包括所述源字符串。
基于本申请第四方面的第三种实施方式,在本申请第四方面的第四种实施方式中,所述处理器还用于向第二设备发送所述目标字符串,所述目标字符串用于所述第二设备根据目标对应关系和所述目标字符串得到所述源字符串。
基于本申请第四方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第四方面的第五种实施方式中,所述处理器具体用于根据所述小型stub函数从第二设备加载所述互补实函数。
基于本申请第四方面,或第四方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第四方面的第六种实施方式中,所述第一互补镜像和所述第一小型镜像存储于所述第一设备的不同存储介质中。
基于本申请第四方面,或第四方面的第一种实施方式至第六种实施方式中的任一实施方式,在本申请第四方面的第七种实施方式中,所述处理器还用于若根据所述小型stub函数确定加载所述互补实函数,则向第二设备发送所述互补实函数的相关信息,所述相关信息用于所述第二设备根据所述相关信息得到第二小型镜像,所述第二小型镜像包括所述小型实函数集合和所述互补实函数。
本申请第五方面提供了一种程序处理装置。该装置包括:发送模块,用于向第一设备发送第一小型镜像,第一小型镜像包括小型实函数集合和小型stub函数集合,小型stub函数集合与第一互补镜像的互补实函数集合对应,小型实函数集合与第一互补镜像的互补stub函数集合对应,小型stub函数集合包括小型stub函数,小型stub函数用于第一设备根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数集合包括互补实函数。
基于本申请第五方面,在本申请第五方面的第一种实施方式中,小型stub函数具体用于第一设备根据第一程序的指令尝试运行小型stub函数,若检测到异常,则加载互补实函数。
基于本申请第五方面,或第五方面的第一种实施方式,在本申请第五方面的第二种实施方式中,小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,互补实函数集合为目标代码在运行目标用例集合过程中未运行的函数集合。
基于本申请第五方面的第二种实施方式,在本申请第五方面的第三种实施方式中,目标代码包括目标函数,目标函数包括目标字符串,目标字符串的数据量小于源字符串的数据量,目标代码是根据源代码得到的,源代码包括源函数,源函数包括源字符串。
基于本申请第五方面的第三种实施方式,在本申请第五方面的第四种实施方式中,目标字符串用于和目标对应关系得到源字符串。
基于本申请第五方面,或第五方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第五方面的第五种实施方式中,第一设备存储有第一小型镜像,第一小型镜像和第一互补镜像存储于不同的设备,存储第一互补镜像的设备用于为多个设备提供互补实函数集合,多个设备包括第一设备。
基于本申请第五方面,或第五方面的第一种实施方式至第四种实施方式中的任一实施方式,在本申请第五方面的第六种实施方式中,第一互补镜像和第一小型镜像存储于第一设备的不同存储介质中。
基于本申请第五方面,或第五方面的第一种实施方式至第六种实施方式中的任一实施方式,在本申请第五方面的第七种实施方式中,该装置还包括:接收模块,用于接收第一设备发送的互补实函数的相关信息;处理模块,用于根据相关信息得到第二小型镜像,第二小型镜像包括小型实函数集合和互补实函数。
本申请第六方面提供了一种程序执行设备,其特征在于,包括:处理器和存储器;所述存储器中存储有第一小型镜像和执行程序,所述第一小型镜像包括小型stub函数;所述处理器用于从所述存储器中获取所述执行程序,根据所述执行程序处理所述小型stub函数,具体的处理方法包括前述第一方面或第一方面任意一种实施方式所述的方法。
本申请第七方面提供了一种程序处理设备,其特征在于,包括:处理器和存储器;所述存储器中存储有处理程序;所述处理器用于从所述存储器中获取所述处理程序,根据所述处理程序和源码得到第一小型镜像,具体的处理方法包括前述第二方面或第二方面任意一种实施方式所述的方法。
本申请第八方面提供了一种计算机存储介质,其特征在于,所述计算机存储介质中存储有指令,所述指令在计算机上执行时,使得所述计算机执行如第一方面或第一方面任意一种实施方式所述的方法,或使得所述计算机执行如第二方面或第二方面任意一种实施方式所述的方法。
本申请第九方面提供了一种计算机程序产品,其特征在于,所述计算机程序产品在计算机上执行时,使得所述计算机执行如第一方面或第一方面任意一种实施方式所述的方法,或使得所述计算机执行如第二方面或第二方面任意一种实施方式所述的方法。
附图说明
图1为根据函数依赖率进行函数裁剪的流程示意图;
图2为根据源代码得到小型镜像和互补镜像的流程示意图;
图3为本申请实施例中处理程序的流程示意图;
图4为本申请实施例中应用场景的一个示意图;
图5为本申请实施例中程序处理方法的流程示意图;
图6为本申请实施例中通过“ID化”将字符串小型化的流程示意图;
图7为源码中有依赖关系的函数和被覆盖的函数的关系示意图;
图8为本申请实施例中根据覆盖率得到镜像的流程示意图;
图9为本申请实施例中程序执行方法的流程示意图;
图10为本申请实施例中程序执行装置的结构示意图;
图11为本申请实施例中程序处理装置的结构示意图;
图12为本申请实施例中第一设备或第二设备的结构示意图。
具体实施方式
本申请实施例提供了一种程序执行方法、程序处理方法以及相关设备,应用于程序处理领域,可以减少第一程序对运行内存的需求。
为了方便理解本申请提供的技术方案,下面先对一些相关概念进行描述。
函数依赖是由数学派生的术语,它表征一个属性或属性集合的值对另一个属性或属性集合的值的依赖性。设R(U)是一个属性集U上的关系模式,X和Y是U的子集,若对于R(U)的任意两个可能的关系r1、r2,若r1[x]=r2[x],则r1[y]=r2[y],或者若r1[y]不等于r2[y],则r1[x]不等于r2[x],称X决定Y,或者Y依赖X。
函数依赖率(简称依赖率)表示程序里有依赖关系(或调用关系)的函数的比例。函数依赖率可以通过下面步骤求得:假设程序中所有函数的个数为N,从程序的入口点entry point(如main)扫描entry point所依赖的本程序的子函数,所有子函数和entry point组成集合A;假设集合A中的函数的个数为M,集合A和程序中不包括重复的函数(若集合A包括重复的函数,则集合A中的函数去重后的个数为M),则此程序的函数依赖率等于M/N。
函数覆盖率(简称覆盖率)表示程序里被运行过的函数比例。函数覆盖率可以通过以下步骤求得:假设程序中所有函数的个数为N;假设程序运行完一个用例集合,被运行过的函数个数为K,则函数覆盖率等于K/N。在被运行过的函数中,重复的函数只会被计一次。
stub函数也叫桩点、桩函数、存根函数,stub函数一般用于替换一些接口函数,用于测试当前函数的特性。本申请中的stub函数,在实现上可以是体积较小的函数,还可以是空(null)函数。并且,本申请中的stub函数,可以通过特殊的设计,使得执行stub函数时会产生异常。
计算机***由硬件***和软件***组成。前者是借助电、磁、光、机械等原理构成的各种物理部件的有机组合,是***赖以工作的实体。后者是各种程序和文件,用于指挥全***按指定的要求进行工作。因此,宏观上来说,计算机***的软件***也是一个程序,也可以对其进行裁剪。有些计算机***可以为第三方程序提供运行环境,例如UE上的计算机***,笔记本电脑上的计算机***等。
随着互联网的快速发展,计算机设备的销量不断增长。例如在2019年,全球TOP3的手机厂商的手机销量均超过2亿部。面对海量的销售数量,除用户体验、产品质量外,计算机设备的成本是重要的竞争力之一。计算机设备一般都需要通过程序来实现相应的功能,而程序的存储和运行离不开存储介质。在嵌入式领域,存储介质的成本是设备成本的重要部分。为了减少存储介质的成本,可以对程序进行小型化的处理。通过程序小型化,可以减少程序的体积,从而节约存储空间。小型化技术有如下几种:1、程序、服务粒度的裁剪(如Windows、Android);2、软件包粒度的裁剪(如RedHat、Suse、Ubuntu);3、文件粒度的裁剪(如window和linux***直接通过命令删除无用文件);4、函数粒度的裁剪(如gcc编译器的--gc-section链接选项)。其中,函数粒度的裁剪是上述裁剪中最小粒度的裁剪,简称为函数裁剪。下面以gcc编译器为例,对函数裁剪进行描述。
总的来说,gcc编译器是在对源码的编译过程将每个函数、全局变量放到独立的部分section中,一个section可以是一个函数,也可以是全局变量。gcc编译器在链接过程中识别每个section和entry point的依赖关系,删除和entry point没有依赖关系的section。下面对此进行详细描述,为了方便理解,引入了部分具体的代码。
请参阅图1,图1为根据函数依赖率进行函数裁剪的流程示意图。步骤11为编译阶段,gcc编译器将源代码101中的每个函数编译成独立的section。源代码也称源码,源码101 包括4个函数,分别是hello1(),hello2(),hello3(),main()。图1中未示出前3个函数的具体内容,此处假设hello1(),hello2()和hello3()之间没有依赖关系。函数main()是程序的entry point,函数main()中包括代码hello1()和hello3(),表征执行main()时会调用hello1()和hello3(),即hello1(),hello3()与main()之间存在依赖关系。通过gcc编译器的编译,可以得到section集合102,section集合102包括4个section,将其命名为.text.hello1~3和.text.main。步骤12为链接准备阶段,gcc编译器中的链接器从entry point开始扫描调用关系。根据上述步骤1的举例,可以得到.text.hello1,.text.hello3与.text.main之间存在依赖关系;.text.hello2是孤立的函数,即text.hello2与.text.main之间不存在依赖关系。步骤13为链接阶段,链接器删除孤立的函数所对应的section,生成可执行文件104。
上述函数裁剪的裁剪依据是函数依赖率,函数依赖率越小,函数裁剪的效果越好,得到的可执行文件104的体积越小。该裁剪方式一般适用于包含entry point(如main)的程序进行裁剪,而不适用于对共享库、OS kernel(***内核)进行裁剪,例如包括共享库或OS kernel(***内核)的计算机***。因为计算机***中的共享库或OS kernel(***内核)为第三方程序提供的运行环境可能包括某个函数,该函数与计算机***的entry point没有依赖关系,但是与第三方程序的entry point有依赖关系。若通过上述函数裁剪方式删除了该函数,则第三方程序可能无法正常运行。为此,工业界使用“小型镜像-互补镜像”的技术,该技术可以分为两部分,第一部分是根据源码得到小型镜像和互补镜像的过程,第二部分是小型镜像和互补镜像的使用过程,下面分别进行描述。
第一部分一般由计算机设备完成。请参阅图2,图2为根据源代码得到小型镜像和互补镜像的流程示意图。在步骤21中,计算机设备区分源代码中与entry point有依赖关系的函数集合B,以及与entry point没有依赖关系的函数集合A。在步骤22中,计算机设备从源代码中删除函数集合A中的函数,保留函数集合B中的函数,获得小型镜像。在步骤23和步骤24中,计算机设备从源代码中保留函数集合A中的函数,将函数集合B中的函数用空(null)函数代替,即用空函数集合代替函数集合B,获得互补镜像。其中,将互补镜像中的函数集合A中的函数称为实函数。互补镜像中的空函数集合和小型镜像中的函数集合B对应,或者说互补镜像中的空函数集合的函数和小型镜像中的函数集合B中的函数一一对应。为了方便理解,结合上述图1中的源码101进行描述。当图2中的源码等于图1中的源码101时,小型镜像等于可执行文件104,小型镜像包括hello1(),hello3()和main();互补镜像包括hello2(),空函数1,空函数3和空函数2。其中,空函数1和hello1()对应,空函数3和hello3()对应,空函数2和main()对应。
第二部分是小型镜像和互补镜像的使用过程,由安装有计算机***的第一设备执行。假设某个第三方程序中的代码会调用函数1和函数2,函数1为小型镜像中的函数,函数2为互补镜像中的实函数。第一设备在启动第三程序时,第一设备会将闪存flash或硬盘中的函数1和函数2加载至第一设备的运行内存。但是,在实际应用中,第一设备的运行内存一般有限,若第三方程序的代码调用的函数过多,可能会导致运行内存不足,使得第三方程序运行失败。
为此,本申请提出了一种程序处理方法,在该方法中,执行第一部分操作的计算机设 备在根据源码得到小型镜像的过程中,不删除互补实函数集合,而是用stub函数代替互补实函数,即用小型stub函数集合代替互补实函数集合。此处描述的互补实函数集合可以是上述函数集合A,也可以不是函数集合A。当互补实函数集合是函数集合A时,互补实函数集合是根据依赖率得到的,互补实函数集合是指在源码中与entry point没有函数依赖关系的函数集合;当互补实函数集合不是函数集合A时,互补实函数集合可以是根据函数覆盖率得到的,互补实函数集合是源码在运行目标用例集合过程中未运行的函数集合。除了用小型stub函数集合代替互补实函数集合,计算机设备还会保留小型stub函数集合与互补镜像中的互补实函数集合的对应关系。
当在第一设备中使用本申请提供的程序执行方法运行第三方程序时,若第三方程序包括调用互补实函数的代码,第一设备在启动第三方程序时并不会直接将互补实函数加载至运行内存,而是会先加载与互补实函数对应的小型stub函数。在小型stub函数即将运行或运行时,计算机设备才会通过小型stub函数间接加载互补实函数。小型stub函数可以理解为计算机设备加载互补实函数的缓冲。通过增加缓冲,可以控制是否加载互补实函数,从而可以减少第三方程序对运行内存的需求,例如第三方程序未启用与互补实函数对应的相关功能时,不加载互补实函数。
为了方便理解本申请实施例中提供的技术方案,先对处理程序的流程进行描述。请参阅图3,图3为本申请实施例中处理程序的流程示意图。如图3所示,处理程序的流程可以包括程序编写301,程序处理302,程序执行303。程序编写301是指生成源代码的过程,包括但不限于手工输入,软件生成等。程序处理302是指在程序编写的基础上,对全部或部分编写完成的程序进行预处理的过程,例如自动校正,剪裁,编译等。剪裁是指通过删除或者替换源代码中的部分函数,以减小源代码的体积。本申请实施例中的程序处理302主要包括上述程序处理方法:通过对源代码进行剪裁得到互补实函数集合和小型实函数集合,根据互补实函数集合和小型实函数集合得到小型镜像和互补镜像,小型镜像包括小型实函数和小型stub函数,互补镜像包括互补实函数和互补stub函数。程序执行303是指第三方程序的运行过程,第三方程序通过运行实现其对应的相关功能,例如当第三方程序是与拍照相关的程序时,相关功能可以是拍照、照片编辑、人物美颜等。在第三方程序的运行过程中,第三方程序依赖小型镜像和互补镜像中的函数来实现相关功能。本申请实施例中的程序执行303主要包括上述程序执行方法:第三方程序实际依赖的某个函数,或者说第三方程序需要调用的某个函数为互补实函数,互补实函数在互补镜像中,在第三方程序需要调用互补实函数时,第三方程序可以通过小型镜像中的小型stub函数来调用互补实函数。
上面对处理程序的流程进行了阐述,大致将流程划分为程序编写301,程序处理302和程序执行303。处理程序的流程需要具体的计算机设备来执行,不同的步骤可以在不同的计算机设备中完成,也可以在相同的计算机设备中完成。例如程序编写301在设备1中完成,设备1将完成的源码发送给设备2,设备2根据源码得到小型镜像和互补镜像,设备2通过小型镜像和互补镜像运行第三方程序。或者,请参阅图4,图4为本申请实施例中应用场景的一个示意图,如图4所示,在第二设备401获取源码,源码可以是在第二设备401中编写完成的,也可以是其它设备编写完成的。获取到源码后,第二设备401对源 码进行程序处理302,以获得小型镜像和互补镜像。获得小型镜像和互补镜像后,第二设备401向第一设备402传递小型镜像和互补镜像,第一设备402进行程序执行303的步骤,具体地,可以是第一设备402中的计算机***进行程序执行303的步骤,即本申请实施例中的程序执行方法的执行主体可以是第一设备402或计算机***402。本申请实施例后续的描述中,将以第一设备402作为执行主体为例进行描述。本申请实施例中,后续将以图4为例进行说明,其它场景下的相应处理可以参考对图4中的场景的描述。
在图4的场景中,第二设备401可以是台式电脑、笔记本、或服务器等。第一设备402可以是手环、洗衣机、路由器、台式电脑、笔记本、或智能手机等。第二设备401可以与第一设备402建立连接,也可以不建立连接。若第二设备401与第一设备402建立连接,连接的方式可以是有线连接,也可以是无线连接,无线连接可以是无线热点或蓝牙等。若第二设备401与第一设备402不建立连接,小型镜像和互补镜像可以依靠存储介质传递,例如U盘。
下面对本申请实施例中的程序处理方法和程序执行方法分别进行描述。请参阅图5,图5为本申请实施例中程序处理方法的流程示意图。
在步骤51,第二设备根据源码得到目标代码。
源码中可能会包括一些字符串,这些字符串会在源码中占据一定的体积。例如程序日志,程序日志是指程序在运行中需要记录或者打印的日志;对于一个程序,常在关键初始化、异常分支发生时,会记录或打印日志(便于维护和测试)。源码中与日志相关的字符串会被编译进可执行程序、增大程序的体积。在一个已编译好的可执行程序中,日志字符串一般会占程序体积的5%~10%;这部分体积消耗对于第一设备的存储空间的影响是不可忽略的。为此,本申请通过“ID化”的方法将字符串小型化,下面进行详细描述。请参阅图6,图6为本申请实施例中通过“ID化”将字符串小型化的流程示意图。
在步骤511,第二设备获取源码中的一个字符串。为了方便理解,下面带入具体的源码进行描述,该源码包括一个FuncA函数。
源码:
FuncA/*函数名*/
{……;/*表示此处可能还有其它代码*/
If(ret!=0)/*如果ret不等于0*/
{Printf(“Error:FuncA init Failed!The ret is%d\n”,ret);/*输出Error:FuncA init Failed!The ret is%d*/;
}else/*否则*/
{Printf(“FuncA init success!\n”);}/*输出FuncA init success!*/
Return ret;}/*返回ret*/
在上述源码中,Error:FuncA init Failed!The ret is和FuncA init success!是两个字符串。两个字符串简称为源字符串1和源字符串2,源字符串1表示初始化失败,输出返回值,源字符串2表示初始化成功。第二设备获取源字符串1。
在步骤512中,第二设备获取源字符串的hash值(也叫散列值或哈希值)。
在步骤513中,第二设备确定是否发生hash值冲突。在源码中,字符串的个数并不确 定,在步骤511中只是举例说明了源码中的一个函数的部分代码。若源码出现多个字符串,第二设备获取多个字符串的hash值,则可能会出现2个字符串的hash值相同的情况,即发生了hash值冲突。当然,若源字符串1是第二设备获取的第一字符串,则可以不必进行该步骤的操作。若第二设备确定发生hash值冲突,则执行步骤514,否则执行步骤511。
在步骤514中,计算机确定源字符串是否与hash值冲突对应的源字符串相同。
目标对应关系列表存储有源字符串与目标字符串的对应关系,本申请实施例以目标字符串为hash值为例进行描述。将源字符串1对应的hash值称为hash值1,与hash值1冲突的hash值称为hash值3。hash值3是第二设备根据源字符串3得到的。计算机确定源字符串1是否与目标对应关系列表中的源字符串3相同。若相同,则跳过源字符串1。第二设备获取下一个源字符串,从步骤511重新开始执行。若不同,则执行步骤515。
在步骤515中,第二设备将hash值加1。为了解决hash值冲突,第二设备将源字符串1对应的hash值加1。
在步骤516中,第二设备确定是否解决hash值冲突。若否,执行步骤515,直到解决hash值冲突。若是,则第二设备获取下一个源字符串,从步骤511重新开始执行。
通过执行上述511~516中的步骤,第二设备可以得到与源字符串对应的目标字符串,以及目标对应关系。第二设备将源函数中的源字符串替换为目标字符串,得到目标函数。上述FuncA为源函数,目标函数具体如下。
目标函数:
FuncA/*函数名*/
{……;/*表示此处可能还有其它代码*/If(ret!=0)/*如果ret不等于0*/
{Printf(“afab9b15%d\n”,ret);/*输出afab9b15%d*/
}else/*否则*/
{Printf(“8a52d706\n”);}/*输出8a52d706*/
Return ret;}/*返回ret*/
在上述目标函数中,hash值1为afab9b15,源字符串2对应的hash值为8a52d706。除了输出的内容不同,上述目标函数和源函数的其它功能相同,目标函数和源函数对应。
在步骤52中,第二设备根据目标代码得到小型实函数集合和互补实函数集合。
根据上面的描述可知,互补实函数集合可以是图2中根据函数依赖率得到的函数集合A,也可以是根据函数覆盖率得到的。与之相对的,小型实函数集合可以是图2中根据函数依赖率得到的函数集合B,也可以是根据函数覆盖率得到的。若互补实函数集合是函数集合A,则步骤42可以参考前述图2中计算机设备获取函数集合A的过程。此处重点描述第二设备根据函数覆盖率得到小型实函数集合和互补实函数集合的过程。根据上述对函数覆盖率的定义可知,函数覆盖率是指源码在运行目标用例集合过程中运行过的函数的数量与源码中的函数的数量的比值。为了方便理解,运行过的函数和源码中的函数都不包括重复的函数。在运行目标用例集合的过程中,不同的用例,甚至同一个用例可能会重复的调用某个函数。但是在计算运行过的函数的数量时,该函数只会被计算一次。根据函数覆盖率的定义,可以得到小型实函数集合和互补实函数集合的定义。小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,互补实函数集合为目标代码在运行目标用 例集合过程中未运行的函数集合。
在第二设备运行代码前,第二设备对目标代码进行编译,通过编译后的目标代码运行目标用例集合。目标用例集合包括编译后的目标代码所能执行的全部或部分功能。例如,目标代码所能执行的功能包括拍照,照片编辑,人物美颜3个功能时。目标用例集合包括3个功能中的任意一个或多个功能。例如,目标用例集合包括拍照和照片编辑。第二设备可以向某台设备(例如第一设备)传递目标代码编译后的程序,使得某台设备通过安装目标代码编译后的程序来运行拍照和照片编辑,向第二设备返回函数覆盖率信息。第二设备根据函数覆盖率信息得到小型实函数集合和互补实函数集合。或者第二设备通过目标代码模拟拍照和照片编辑的功能。之后,第二设备统计目标代码在运行目标用例集合过程中运行过的函数集合和未运行过的函数集合,运行过的函数集合即为小型实函数集合,未运行过的函数集合即为互补实函数集合,运行过的函数集合中的函数的数量与目标代码中的函数的数量的比值即为目标代码的函数覆盖率。应当理解的是,此处对目标用例集合的举例只是为了方便本申请实施例中的技术方案,并不能作为限定本申请的条件。例如,编译后的目标代码可以向第三方程序返回一个值,则向第三方程序返回一个值也属于编译后的目标代码所能执行的功能。
上面对第二设备通过目标代码获取小型实函数集合和互补实函数集合进行了描述。应当理解的是,由于目标代码和源码是对应的,因此第二设备也可以通过源码获取小型实函数集合和互补实函数集合。例如,第二设备向第一设备传递源码编译后的程序,第一设备通过安装源码编译后的程序运行拍照和照片编辑。第一设备向第二设备返回函数覆盖率信息。函数覆盖率信息包括源码中运行过的函数对应的序号集合。在源码和目标代码中,所有的函数根据其排列顺序编号,即每个函数有其对应的序号。在源码和目标代码中,相对应的函数的序号相同,例如源函数和目标函数。因此,即使第一设备返回的序号是源码中的函数对应的序号集合,第二设备也可以根据该序号集合确定目标代码中的小型实函数集合,进而确定互补实函数集合。
在步骤53中,第二设备根据小型实函数集合获取互补stub函数集合,根据互补实函数集合获取小型stub函数集合。
第二设备将小型实函数集合的每个函数用stub函数代替,得到互补stub函数集合;将互补实函数集合的每个函数用stub函数代替,得到小型stub函数集合。
在步骤54和步骤55中,第二设备根据小型实函数集合和小型stub函数集合得到小型镜像,根据互补实函数集合和互补stub函数集合得到互补镜像。
第二设备编译小型实函数集合和小型stub函数集合组成的代码,得到小型镜像;第二设备编译互补实函数集合和互补stub函数集合组成的代码,得到互补镜像。或者说第二设备用小型stub函数集合代替源码中的互补实函数集合,然后编译源码,得到小型镜像;第二设备用互补stub函数集合代替源码中的小型实函数集合,然后编译源码,得到互补镜像。
第二设备需要保留小型stub函数集合和互补实函数集合的对应关系,即一个小型stub函数对应一个互补实函数。第二设备可以生成一个映射表,映射表中包括小型stub函数和互补实函数的对应关系。或者在其他实施例中,第二设备将互补实函数的函数名设置为与小型stub函数的函数名相同或类似,以保留小型stub函数和互补实函数的对应关系。在其 他实施例中,最小镜像的小型stub函数集合和互补镜像的互补实函数集合采用相同顺序排序,最小镜像的小型实函数集合和互补镜像的互补stub函数集合采用相同顺序排序,以便加载器进行函数加载、找到函数的偏移地址。例如,第二设备可以通过函数的序号保留小型stub函数和互补实函数的对应关系。在小型镜像和互补镜像中,小型stub函数集合和互补实函数集合根据其函数排列顺序对函数进行编号,相对应的函数的序号相同,例如小型stub函数和互补实函数的序号相同。
在后续第一设备运行第三方程序时,第一设备可以通过小型stub函数的异常来调用互补实函数。为了在尝试运行小型stub函数时产生异常,第二设备可以将小型stub函数设为不可执行。具体地,第二设备将所有的小型stub函数汇总到单独的section,并让这个section的地址按照page size对齐,设置这个section的属性为不可执行。在第一设备尝试运行小型stub函数时,由于该小型stub函数不可执行,会产生异常。在其他实施例中,为了减少小型stub函数集合的体积,小型stub函数为空函数。
除了上述方法,还可以通过小型stub函数中的代码来实现异常。例如,下面具体提供一个小型stub函数的示例。
Int F4func(int a,void*b)/*函数名*/
{asm volatile(
“push{r0~r2\n}”/*将r0~r2寄存器入栈*/
“mov r0,#STUB_ABORT_ADDR\n”/*向r0寄存器赋值,所赋的值为一个访问时能产生异常的地址*/
“mov r1,#STUB_ABORT_VALUE\n”/*向r1寄存器赋值,为一个立即数*/
“str r1,[r0]\n”/*将r1寄存器存入r0所指的地址,r0存了访问时会产生异常的地址,因此这条指令会产生数据异常*/
“pop r1,{r0~r2}\n”;))/*将r0~r2寄存器出栈*/
return 0;/*返回*/}
在该示例中,小型stub函数的函数名为Int F4func,当第一设备执行上述小型stub函数时,第一设备先将r0~r2寄存器入栈,然后向r0寄存器赋值,所赋的值为一个访问时能产生异常的地址。当执行到“str r1,[r0]\n”时,此指令将r1寄存器存入r0所指的地址;因为r0存了访问时会产生异常的地址,因此这条指令会产生数据异常。
需要说明的是,本申请实施例未将所有能产生异常的方法进行穷举。对本领域技术人员来说,可以利用CPU的段属性/页表属性构造异常、构造特殊的非法指令、构造特殊的数据异常,使得第一设备在尝试运行小型stub函数产生异常,都属于本申请的保护范围。
需要说明的是,上述步骤51可以不执行,则此时步骤52中的目标代码为源码。若执行上述步骤51,步骤51的本质在于用目标函数替换源函数。因此,步骤51与步骤52~53之间没有严格的时序要求。例如第二设备可以在通过步骤55和步骤54得到小型镜像和互补镜像后,再用目标函数替换源函数;或者第二设备在执行步骤52的同时,完成步骤51。步骤54和步骤55之间也没有严格的时序要求。
此处补充说明根据函数覆盖率进行的裁剪和根据函数依赖率进行的裁剪的区别。
首先,根据函数覆盖率得到的小型镜像的体积一般小于根据函数依赖率得到的小型镜 像的体积。如图7所示,图7为源码中有依赖关系的函数和被覆盖的函数的关系示意图。有依赖关系的函数是指与源码中的entry point有依赖关系的函数集合。被覆盖的函数是指通过源码运行目标用例集合的过程中运行的函数集合。一般情况下,由于与entry point有依赖关系的函数不一定在运行用例集合的过程中运行,因此,有依赖关系的函数的范围一般大于被覆盖的函数。因此小型实函数集合小于函数集合B,因此根据覆盖率得到的小型镜像(简称小型镜像1)的体积一般小于根据依赖率得到的小型镜像(简称小型镜像2)的体积。因为stub函数可以为空函数,此处忽略小型stub函数的体积。
在小型镜像1的体积小于小型镜像2的体积的情况下,小型镜像1对应的互补镜像1的体积会大于小型镜像2对应的互补镜像2的体积。第一设备可以通过一些方式来降低成本。例如,第一设备将小型镜像1和互补镜像1放置在不同的存储介质中,不同的存储介质包括存储介质1和存储介质2,小型镜像1存储在存储介质1中,互补镜像1存储在存储介质2中。在存储空间大小相同情况下,存储介质2的成本低于存储介质1的成本。由于小型镜像1的体积小于小型镜像2的体积,因此,第一设备可以节约存储介质1的存储空间,即降低了第一设备在存储介质上的成本。在其他实施例中,第一设备本地存储小型镜像1,互补镜像1存储在云平台或中心设备中。在这种情况下,也降低了第一设备的成本。进一步地,云平台或中心设备为多个第一设备提供互补镜像1,可以节约多个第一设备的成本。
其次,根据覆盖率得到的镜像适用于产品族的场景。例如,在同一产品族中,常分为低端产品(提供规格较小、或裁剪后的功能)、中端产品(提供标配功能)、高端产品(提供高规格、更丰富的功能)。为了方便理解,假设低端产品的功能包括拍照,中端产品的功能包括拍照和照片剪辑,高端产品的功能包括拍照,照片剪辑和人物美颜。为节约研发成本,在现代管理方法和软件工程中,同一产品族的产品一般采用相同的设计方案、同一软件版本,即相同的镜像。在同一产品族中,将高端产品的软件版本放在低端产品中,可能导致低端产品也要提供较大的存储空间、不利于降低低端产品的成本。并且,将包含拍照,照片剪辑和人物美颜功能的镜像放入到一般只需要拍照的低端产品中也是对存储空间的浪费。对于不同级别的产品,第二设备可以用不同的目标用例集合去运行目标代码,从而得到不同的函数覆盖率,即得到不同的小型镜像和互补镜像。例如,对于需要在高端产品中使用的小型镜像和互补镜像,第二设备通过目标代码运行目标用例集合1,目标用例集合1包括拍照,照片剪辑和人物美颜。对于需要在中端产品中使用的小型镜像和互补镜像,第二设备通过目标代码运行目标用例集合2,目标用例集合2包括拍照,照片剪辑。对于需要在低端产品中使用的小型镜像和互补镜像,第二设备通过目标代码运行目标用例集合3,目标用例集合3包括拍照。对于源码而言,函数依赖率是固定的,但是函数覆盖率可以根据目标用例集合进行调节。因此,根据覆盖率得到的镜像适用于产品族的场景。
在其他实施例中,某一产品族包括低端、中端和高端产品,低端产品的镜像是根据目标用例集合1得到的,中端产品的镜像是根据目标用例集合2得到的,高端产品的镜像是根据目标用例集合3得到的,目标用例集合1为目标用例集合2的子集,目标用例集合2为目标用例集合3的子集。其中,可以通过低端、中端和高端产品使用的源码、镜像,以及产品发布时间、产品名称等确定这3种产品是否为同一产品族的产品。例如当这3种产 品对应的源码相同或类似时,则这3种产品为同一产品族的产品;例如当这3种产品对应的产品名称类似时,则这3种产品为同一产品族的产品,例如低端产品的名称为ZXX5-m,中端产品是名称为ZXX5,高端产品的名称为ZXX5-pro或ZXX5-sup或ZXX5-mate。
在其他实施例中,某一产品族包括低端、高端产品,低端产品的镜像是根据目标用例集合1得到的,高端产品的镜像是根据目标用例集合2得到的,目标用例集合1为目标用例集合2的子集。
最后,根据覆盖率的裁剪可以对“含对外函数接口”的源码(如共享库、OS kernel)进行裁剪。编译“含对外函数接口”的源码时,编译器无法预知第三方程序会使用此源码对外接口集中的哪些接口例如,C库glibc提供数千个对外函数接口,编译C库glibc时,编译器无法预知第三方程序会使用glibc对外接口集中的哪些接口。根据覆盖率的裁剪可以通过设定目标用例集合来调用C库glibc中的部分或全部对外函数接口,使得对外函数接口中的部分或全部函数在小型实函数集合中。而根据函数依赖率进行的裁剪中,由于编译器需要扫描依赖关系;没有entry point的程序(如共享库),编译器就无法从entry point去扫描函数依赖关系,使得C库glibc中的部分或全部对外函数接口无法包含在函1数集合B中。
需要说明的是,本申请实施例中的根据覆盖率得到的小型镜像不一定要包括小型函数。如图8所示,图8为本申请实施例中根据覆盖率得到镜像的流程示意图。图8中的小型实函数集合为源码运行目标用例集合的过程中运行的函数,互补实函数集合为源码运行目标用例集合的过程中未运行的函数,stub函数集合可以是空函数集合。关于图8的相关描述可以参考前述图2中的相关描述。
上面对本申请提供的程序处理方法进行了描述,通过本申请提供的程序处理方法,第二设备根据源码得到小型镜像和互补镜像,小型镜像也称为第一小型镜像,互补镜像也称为第一互补镜像。对于通过该方法得到的小型镜像和互补镜像,第一设备可以采用图2所述的方法运行该小型镜像和互补镜像,即第一设备不通过小型镜像中的小型stub函数调用互补镜像中的互补实函数。具体地,可以参考前述图2中的相关描述。下面对本申请提供的程序执行方法进行描述,在该方法中,第一设备将通过小型stub函数调用互补实函数。为了描述简洁,上述程序处理方法中与程序执行方法相关的描述,例如小型镜像和互补镜像包括的内容,小型stub函数包括的内容等,都可以相应的引用到程序执行方法中。请参阅图9,图9为本申请实施例中程序执行方法的流程示意图。
在步骤91中,第一设备接收对小型stub函数的调用请求。在第一程序启动时,第一设备将第一程序需要调用的函数加载至运行内存,第一程序需要调用的函数包括互补实函数,因此,第一设备可以接收到对小型stub函数(与互补实函数对应)的调用请求。具体地,第一程序中的代码会包括小型stub函数的函数名。第一设备优先在小型镜像中搜索该函数名,从而将搜索到的小型stub函数加载至运行内存。第一程序需要调用的函数并不是指第一设备一定会运行该函数。在第一程序未启动与该函数对应的相关功能时,该函数会存储在运行内存中,等待对应的相关功能被启动。在对应的相关功能被启动时,第一设备会运行该函数。第一程序需要调用的函数可以包括小型实函数集合中的函数,也可以不包括小型实函数集合中的函数。第一程序可以在图9中的硬盘中。第一程序不一定是第三方程序, 也可以是第一设备的计算机***自带的程序。
在步骤92中,第一设备根据调用请求加载小型stub函数。小型镜像包括小型stub函数集合和小型实函数集合,小型stub函数集合包括小型stub函数。第一设备根据调用请求在小型镜像中加载小型stub函数。
在步骤93中,第一设备根据小型stub函数确定加载与小型stub函数对应的互补实函数。在第一程序启动与小型stub函数对应的相关功能时,第一设备会尝试运行小型stub函数,若检测到异常,则第一设备加载互补实函数。具体地,互补函数是动态链接的,第一设备调用加载器加载互补实函数。加载器根据小型stub函数,从特定的路径下加载互补镜像中的互补实函数。此处描述的“特定路径”,是指约定好的、固定的路径;例如***经常默认从/lib、/usr/lib下搜索库。
在上述程序处理方法中具体描述了两种产生异常的方式,其中一种是将小型stub函数所在的section对应的属性设置为不可执行。属性一般包括是否可读、是否可写和是否可执行。当该属性被设置为不可执行时,第一设备无法运行小型stub函数,从而检测到异常。另一种方式是通过小型stub函数中代码的内容来实现异常。在第一种方式中,第一设备没有运行小型stub函数中的代码;在第二种方式中,第一设备运行了小型stub函数中的部分代码。
通过检测异常来加载互补实函数是本申请实施例中的一种优选方法,通过该方法,第一设备可以知道第一程序将要启动与互补实函数对应的相关功能,进而加载互补实函数。并在第一设备在未检测到异常前,第一设备不加载互补实函数。当检测到异常,说明小型stub函数未成功运行完毕,此时第一程序不会因为小型stub函数执行完毕而继续执行。因此,本申请实施例不仅为加载互补实函数增加了缓冲,还暂停了第一程序,为加载互补实函数提供了时间上的基础,减少了第一程序可能发生的错误,提升用户体验。
上面对通过检测异常来加载互补实函数的方法进行了描述,下面对不通过检测异常来加载互补实函数的方法进行描述。第一设备监控一个物理地址,当物理地址中的数值刷新时,第一设备可以监控到此次的刷新。小型stub函数中包括在该物理地址中写入某个数值的代码。在第一程序运行与互补实函数对应的相关功能时,第一设备会运行小型stub函数,在该物理地址中写入某个数值。第一设备监控到该物理地址中的数值发生刷新后,第一设备通过处理器暂停第一程序的运行,并根据小型stub函数和对应关系在互补镜像中查找互补实函数,通过加载器加载互补实函数,并通过重定向完成第一程序对互补实函数的调用。在该方法中,需要第一设备时刻监控该物理地址的刷新情况,并且处理器需要及时暂停第一程序,否则第一程序可能将小型stub函数当成互补实函数,从而跳过对互补实函数的调用,造成第一程序的业务发生异常。
根据上述程序处理方法中的描述可知,第二设备保留了小型stub函数和互补实函数的对应关系,该对应关系可以是序号或映射表,也可以是小型stub函数的函数名和互补实函数的函数名。若对应关系是序号,第一设备可以获取小型stub函数的序号,在需要通过小型stub函数加载互补实函数时,第二设备通过该序号在互补镜像中加载与该序号相同的互补实函数。若对应关系是映射表,则第一设备还需要获取映射表。若对应关系是函数名,小型stub函数的函数名可以和互补实函数的函数名相同或类似。
根据上述程序处理方法中的描述可知,第二设备通过“ID化”将源码中的源函数替换为了目标函数,并生成了目标对应关系。因此,通过源码得到的小型镜像和/或互补镜像中包括目标函数。当第一程序运行目标函数后,第一设备可以得到目标字符串。第一设备向第二设备或其他设备发送目标字符串,第二设备或其他设备通过目标字符串的目标对应关系得到源字符串。若字符串为日志,则还原的源字符串一般为人类方便阅读的语言。需要说明的是,目标函数可以是小型实函数集合中的函数,也可以是互补实函数集合中的函数,即目标函数可以是互补实函数。在其他实施例中,第一设备也可以存储有目标对应关系,在需要读取源字符串时,第一设备根据目标对应关系和目标字符串得到源字符串。
在其他实施例的分布式场景中,第一设备本地存储小型镜像1,互补镜像1存储在第二设备中,第二设备可以是云平台或中心设备,此处的第二设备可以是上述程序处理方法中的第二设备,也可以不是上述程序处理方法中的第二设备。在第一设备需要调用互补镜像中的互补实函数时,第一设备从云平台或中心设备调用互补实函数,降低第一设备的成本。进一步地,第二设备为多个第一设备提供互补镜像1,可以节约多个第一设备的成本。
在其他实施例中,本申请实施例中的小型镜像是动态链接中。通过动态链接,进一步减少第一程序对第一设备的运行内存的占用。
在其他实施例中,第一设备根据本申请实施例中的程序执行方法调用互补实函数后,第一设备向第二设备或其他设备发送与互补实函数的相关信息,第二设备可以根据相关镜像更新小型镜像和互补镜像。更新前的小型镜像和互补镜像称为第一小型镜像和第一互补镜像,更新后的小型镜像和互补镜像称为第二小型镜像和第二互补镜像。在更新前,互补实函数在第一互补镜像的互补实函数集合中,在更新后,互补实函数在第二小型镜像中的小型实函数集合中。简单来说,第二设备扩大了小型实函数集合的体积或者范围,减少了互补实函数集合的体积或者范围。
上面对本申请实施例中程序处理方法和程序执行方法进行了描述,下面对本申请实施例中的程序处理装置和程序执行装置进行描述。请参阅图10,图10为本申请实施例中程序执行装置的结构示意图。
该装置包括:接收模块1001,用于接收第一程序对小型stub函数的调用请求,小型stub函数为小型stub函数集合中的一个函数,第一小型镜像包括小型stub函数集合和小型实函数集合;
加载模块1002,用于根据调用请求加载小型stub函数;
处理模块1003,用于根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数为互补实函数集合中的一个函数,第一互补镜像包括互补实函数集合和互补stub函数集合,互补stub函数集合与小型实函数集合对应,互补实函数集合与小型stub函数集合对应。
在其他实施例中,该装置还可以包括第一发送模块或第二发送模块等。该装置中的模块具体用于执行前述图9对应的实施例中的第一设备可以执行的全部或部分操作。
请参阅图11,图11为本申请实施例中程序处理装置的结构示意图。
该装置包括:发送模块1101,用于向第一设备发送第一小型镜像,第一小型镜像包括小型实函数集合和小型stub函数集合,小型stub函数集合与第一互补镜像的互补实函数集 合对应,小型实函数集合与第一互补镜像的互补stub函数集合对应,小型stub函数集合包括小型stub函数,小型stub函数用于第一设备根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数集合包括互补实函数。
在其他实施例中,该装置还可以包括接收模块或处理模块等。该装置中的模块具体用于执行前述图5或图6对应的实施例中的第二设备可以执行的全部或部分操作。
上面对本申请实施例中的程序处理装置和程序执行装置进行了描述,下面对本申请实施例中的第一设备和第二设备进行描述。
请参阅图12,图12为本申请实施例中第一设备或第二设备的结构示意图。
如图12所示,处理程序的设备或执行程序的设备1200包括处理器1210,与所述处理器1210耦接的存储器1220。处理器1210可以是中央处理器(central processing unit,CPU),网络处理器(network processor,NP)或者CPU和NP的组合。处理器还可以是专用集成电路(application-specific integrated circuit,ASIC),可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD),现场可编程逻辑门阵列(field-programmable gate array,FPGA),通用阵列逻辑(generic array logic,GAL)或其任意组合。处理器1210可以是指一个处理器,也可以包括多个处理器。
存储器1220可以包括易失性存储器(volatile memory),例如随机存取存储器(random-access memory,RAM);存储器1220也可以包括非易失性存储器(non-volatile memory),例如只读存储器(read-only memory,ROM),FRAM存储器,快闪存储器(flash memory),硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器1220还可以包括上述种类的存储器的组合。
当图12是程序执行设备的结构示意图时:
处理器1210用于接收第一程序对小型stub函数的调用请求,小型stub函数为小型stub函数集合中的一个函数,第一小型镜像包括小型stub函数集合和小型实函数集合;根据调用请求加载小型stub函数;根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数为互补实函数集合中的一个函数,第一互补镜像包括互补实函数集合和互补stub函数集合,互补stub函数集合与小型实函数集合对应,互补实函数集合与小型stub函数集合对应。
在其他实施例中,处理器1210还用于执行存储器1220中的计算机可读指令后,按照所述计算机可读指令的指示,执行第一设备可以执行的全部或部分操作,例如第一设备在与图9对应的实施例中执行的操作。
当图12是程序处理设备的结构示意图时:
处理器1210用于向第一设备发送第一小型镜像,第一小型镜像包括小型实函数集合和小型stub函数集合,小型stub函数集合与第一互补镜像的互补实函数集合对应,小型实函数集合与第一互补镜像的互补stub函数集合对应,小型stub函数集合包括小型stub函数,小型stub函数用于第一设备根据小型stub函数确定是否加载与小型stub函数对应的互补实函数,互补实函数集合包括互补实函数。
在其他实施例中,处理器1210还用于执行存储器1220中的计算机可读指令后,按照 所述计算机可读指令的指示,执行第二设备可以执行的全部或部分操作,例如第二设备在与图5或图6对应的实施例中执行的操作。
在本申请所提供的几个实施例中,应该理解到,所揭露的***,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个***,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:闪存盘、移动硬盘、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。

Claims (30)

  1. 一种程序执行方法,其特征在于,应用于计算机***,所述计算机***包括第一小型镜像,所述方法包括:
    接收第一程序对小型stub函数的调用请求,所述小型stub函数为小型stub函数集合中的一个函数,所述第一小型镜像包括所述小型stub函数集合和小型实函数集合;
    根据所述调用请求加载所述小型stub函数;
    根据所述小型stub函数确定是否加载与所述小型stub函数对应的互补实函数,所述互补实函数为互补实函数集合中的一个函数,第一互补镜像包括所述互补实函数集合和互补stub函数集合,所述互补stub函数集合与所述小型实函数集合对应,所述互补实函数集合与所述小型stub函数集合对应。
  2. 根据权利要求1所述的方法,其特征在于,根据所述小型stub函数确定是否加载互补实函数包括:
    根据所述第一程序的指令尝试运行所述小型stub函数,若检测到异常,则加载所述互补实函数。
  3. 根据权利要求1或2所述的方法,其特征在于,所述小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,所述互补实函数集合为所述目标代码在运行所述目标用例集合过程中未运行的函数集合。
  4. 根据权利要求3所述的方法,其特征在于,所述方法还包括:
    加载目标函数,所述目标函数包括目标字符串,所述目标字符串的数据量小于源字符串的数据量,所述目标代码包括所述目标函数,所述目标代码是根据源代码得到的,所述源代码包括源函数,所述源函数包括所述源字符串。
  5. 根据权利要求4所述的方法,其特征在于,在所述加载所述目标函数后,所述方法还包括:
    向第二设备发送所述目标字符串,所述目标字符串用于所述第二设备根据目标对应关系和所述目标字符串得到所述源字符串。
  6. 根据权利要求2至5中任意一项所述的方法,其特征在于,
    所述加载所述互补实函数包括:
    根据所述小型stub函数从第二设备加载所述互补实函数。
  7. 根据权利要求1至5中任意一项所述的方法,其特征在于,所述第一互补镜像和所述第一小型镜像存储于所述第一设备的不同存储介质中。
  8. 根据权利要求1至7中任意一项所述的方法,其特征在于,所述方法还包括:
    若根据所述小型stub函数确定加载所述互补实函数,则向第二设备发送所述互补实函数的相关信息,所述相关信息用于所述第二设备根据所述相关信息得到第二小型镜像,所述第二小型镜像包括所述小型实函数集合和所述互补实函数。
  9. 一种程序处理方法,其特征在于,包括:
    第二设备向第一设备发送第一小型镜像,所述第一小型镜像包括小型实函数集合和小型stub函数集合,所述小型stub函数集合与第一互补镜像的互补实函数集合对应,所述小型实函数集合与所述第一互补镜像的互补stub函数集合对应,所述小型stub函数集合包括 小型stub函数,所述小型stub函数用于第一设备根据所述小型stub函数确定是否加载与所述小型stub函数对应的互补实函数,所述互补实函数集合包括所述互补实函数。
  10. 根据权利要求9所述的方法,其特征在于,所述小型stub函数具体用于所述第一设备根据第一程序的指令尝试运行所述小型stub函数,若检测到异常,则加载所述互补实函数。
  11. 根据权利要求9或10所述的方法,其特征在于,所述小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,所述互补实函数集合为所述目标代码在运行所述目标用例集合过程中未运行的函数集合。
  12. 根据权利要求11所述的方法,其特征在于,所述目标代码包括所述目标函数,所述目标函数包括目标字符串,所述目标字符串的数据量小于源字符串的数据量,所述目标代码是根据源代码得到的,所述源代码包括源函数,所述源函数包括所述源字符串。
  13. 根据权利要求12所述的方法,其特征在于,所述目标字符串用于和目标对应关系得到所述源字符串。
  14. 根据权利要求9至13中任意一项所述的方法,其特征在于,所述第一设备存储有所述第一小型镜像,所述第一小型镜像和所述第一互补镜像存储于不同的设备。
  15. 根据权利要求9至13中任意一项所述的方法,其特征在于,所述第一互补镜像和所述第一小型镜像存储于所述第一设备的不同存储介质中。
  16. 根据权利要求9至15中任意一项所述的方法,其特征在于,所述方法还包括:
    所述第二设备接收所述第一设备发送的所述互补实函数的相关信息;
    所述第二设备根据所述相关信息得到第二小型镜像,所述第二小型镜像包括所述小型实函数集合和所述互补实函数。
  17. 一种程序执行装置,其特征在于,所述装置安装有计算机***,所述计算机***包括第一小型镜像,所述装置包括:
    接收模块,用于接收第一程序对小型stub函数的调用请求,所述小型stub函数为小型stub函数集合中的一个函数,所述第一小型镜像包括所述小型stub函数集合和小型实函数集合;
    加载模块,用于根据所述调用请求加载所述小型stub函数;
    处理模块,用于根据所述小型stub函数确定是否加载与所述小型stub函数对应的互补实函数,所述互补实函数为互补实函数集合中的一个函数,所述第一互补镜像包括所述互补实函数集合和互补stub函数集合,所述互补stub函数集合与所述小型实函数集合对应,所述互补实函数集合与所述小型stub函数集合对应。
  18. 根据权利要求17所述的装置,其特征在于,所述处理模块具体用于根据所述第一程序的指令尝试运行所述小型stub函数,若检测到异常,则加载所述互补实函数。
  19. 根据权利要求17或18所述的装置,其特征在于,所述小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,所述互补实函数集合为所述目标代码在运行所述目标用例集合过程中未运行的函数集合。
  20. 根据权利要求19所述的装置,其特征在于,
    所述加载模块还用于加载目标函数,所述目标函数包括目标字符串,所述目标字符串 的数据量小于源字符串的数据量,所述目标代码包括所述目标函数,所述目标代码是根据源代码得到的,所述源代码包括源函数,所述源函数包括所述源字符串。
  21. 根据权利要求20所述的装置,其特征在于,所述装置还包括:
    第一发送模块,用于向第二设备发送所述目标字符串,所述目标字符串用于所述第二设备根据目标对应关系和所述目标字符串得到所述源字符串。
  22. 根据权利要求18至21中任意一项所述的装置,其特征在于,
    所述处理模块具体用于根据所述小型stub函数从第二设备加载所述互补实函数。
  23. 根据权利要求17至21中任意一项所述的装置,其特征在于,所述第一互补镜像和所述第一小型镜像存储于所述第一设备的不同存储介质中。
  24. 根据权利要求17至23中任意一项所述的装置,其特征在于,所述装置还包括:
    第二发送模块,用于若根据所述小型stub函数确定加载所述互补实函数,则向第二设备发送所述互补实函数的相关信息,所述相关信息用于所述第二设备根据所述相关信息得到第二小型镜像,所述第二小型镜像包括所述小型实函数集合和所述互补实函数。
  25. 一种程序处理装置,其特征在于,包括:
    发送模块,用于向第一设备发送第一小型镜像,所述第一小型镜像包括小型实函数集合和小型stub函数集合,所述小型stub函数集合与第一互补镜像的互补实函数集合对应,所述小型实函数集合与所述第一互补镜像的互补stub函数集合对应,所述小型stub函数集合包括小型stub函数,所述小型stub函数用于第一设备根据所述小型stub函数确定是否加载与所述小型stub函数对应的互补实函数,所述互补实函数集合包括所述互补实函数。
  26. 根据权利要求25所述的装置,其特征在于,所述小型stub函数具体用于所述第一设备根据第一程序的指令尝试运行所述小型stub函数,若检测到异常,则加载所述互补实函数。
  27. 根据权利要求25或26所述的装置,其特征在于,所述小型实函数集合为目标代码在运行目标用例集合过程中运行的函数集合,所述互补实函数集合为所述目标代码在运行所述目标用例集合过程中未运行的函数集合。
  28. 根据权利要求27所述的装置,其特征在于,所述目标代码包括所述目标函数,所述目标函数包括目标字符串,所述目标字符串的数据量小于源字符串的数据量,所述目标代码是根据源代码得到的,所述源代码包括源函数,所述源函数包括所述源字符串。
  29. 一种程序执行设备,其特征在于,包括:处理器和存储器;
    所述存储器中存储有第一小型镜像和执行程序,所述第一小型镜像包括小型stub函数;
    所述处理器用于从所述存储器中获取所述执行程序,根据所述执行程序处理所述小型stub函数,具体的处理方法包括前述权利要求1至8中的任意一项所述的方法。
  30. 一种程序处理设备,其特征在于,包括:处理器和存储器;
    所述存储器中存储有处理程序;
    所述处理器用于从所述存储器中获取所述处理程序,根据所述处理程序和源代码得到第一小型镜像,具体的处理方法包括前述权利要求9至16中的任意一项所述的方法。
PCT/CN2021/101965 2020-10-31 2021-06-24 程序执行方法、程序处理方法以及相关设备 WO2022088711A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP21884452.0A EP4227803A4 (en) 2020-10-31 2021-06-24 PROGRAM EXECUTION METHOD, PROGRAM PROCESSING METHOD AND RELATED DEVICE
US18/309,501 US20230259370A1 (en) 2020-10-31 2023-04-28 Program execution method, program processing method, and related device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011198663.0A CN114518913A (zh) 2020-10-31 2020-10-31 程序执行方法、程序处理方法以及相关设备
CN202011198663.0 2020-10-31

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US18/309,501 Continuation US20230259370A1 (en) 2020-10-31 2023-04-28 Program execution method, program processing method, and related device

Publications (1)

Publication Number Publication Date
WO2022088711A1 true WO2022088711A1 (zh) 2022-05-05

Family

ID=81383472

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/101965 WO2022088711A1 (zh) 2020-10-31 2021-06-24 程序执行方法、程序处理方法以及相关设备

Country Status (4)

Country Link
US (1) US20230259370A1 (zh)
EP (1) EP4227803A4 (zh)
CN (1) CN114518913A (zh)
WO (1) WO2022088711A1 (zh)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060200815A1 (en) * 2004-12-08 2006-09-07 Wu-Cheng Li Electronic Device and Method for Updating Related Programs
US20160364222A1 (en) * 2015-06-15 2016-12-15 Unisys Corporation Methods and systems for running modern applications in legacy software environments
CN108920217A (zh) * 2018-03-30 2018-11-30 惠州市德赛西威汽车电子股份有限公司 一种减少不可重入函数的重构方法
CN110851181A (zh) * 2018-08-20 2020-02-28 阿里巴巴集团控股有限公司 数据处理方法、装置及计算设备

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060080680A1 (en) * 2004-10-12 2006-04-13 Majid Anwar Platform independent dynamic linking
US9354947B2 (en) * 2014-10-28 2016-05-31 International Business Machines Corporation Linking a function with dual entry points

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060200815A1 (en) * 2004-12-08 2006-09-07 Wu-Cheng Li Electronic Device and Method for Updating Related Programs
US20160364222A1 (en) * 2015-06-15 2016-12-15 Unisys Corporation Methods and systems for running modern applications in legacy software environments
CN108920217A (zh) * 2018-03-30 2018-11-30 惠州市德赛西威汽车电子股份有限公司 一种减少不可重入函数的重构方法
CN110851181A (zh) * 2018-08-20 2020-02-28 阿里巴巴集团控股有限公司 数据处理方法、装置及计算设备

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4227803A4

Also Published As

Publication number Publication date
US20230259370A1 (en) 2023-08-17
CN114518913A (zh) 2022-05-20
EP4227803A1 (en) 2023-08-16
EP4227803A4 (en) 2024-04-10

Similar Documents

Publication Publication Date Title
US9146735B2 (en) Associating workflows with code sections in a document control system
US8126859B2 (en) Updating a local version of a file based on a rule
WO2019019643A1 (zh) 应用程序热更新方法、装置、终端和存储介质
CN107038045A (zh) 加载库文件的方法及装置
US20160283357A1 (en) Call stack relationship acquiring method and apparatus
JP2006236328A (ja) ファイルシステムアイテムおよび関連エンティティのシリアライゼーション
US20180121101A1 (en) Smart Storage Policy
CN109684298B (zh) 数据库迁移方法、装置、设备及存储介质
US20140040207A1 (en) Method for a cloning process to enable cloning a larger System drive to a smaller system
CN112667246A (zh) 应用功能扩展的方法、装置及电子设备
WO2018049883A1 (zh) 文件操作方法及装置
WO2024078348A1 (zh) 应用移植环境下注册表操作的处理方法、装置和介质
CA2930061C (en) Variants of files in a file system
WO2022088711A1 (zh) 程序执行方法、程序处理方法以及相关设备
WO2023071158A1 (zh) 内存优化方法、装置、终端、存储介质
CN116628773A (zh) 数据处理方法、装置、电子设备及存储介质
US9940334B2 (en) Image forming apparatus and control method thereof
US8990265B1 (en) Context-aware durability of file variants
US10146467B1 (en) Method and system for archival load balancing
US8538917B2 (en) System and method for file coordination
CN115421785B (zh) 应用程序的移植处理方法、装置和介质
US20220308965A1 (en) Efficient Mechanism for Data Protection Against Cloud Region Failure or Site Disasters and Recovery Time Objective (RTO) Improvement for Backup Applications
US11755425B1 (en) Methods and systems for synchronous distributed data backup and metadata aggregation
CN111522780B (zh) 一种记录文件创建者信息的方法及终端
CN113296699A (zh) 数据处理方法及装置

Legal Events

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

Ref document number: 21884452

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2021884452

Country of ref document: EP

Effective date: 20230509

NENP Non-entry into the national phase

Ref country code: DE