Function calling method, device, equipment and storage medium

By determining the architecture of the function to be called in the target program and synchronously processing parameters, and using a translator to translate heterogeneous functions, the problem of low function call efficiency between systems in different architectures is solved, and efficient function calls under different CPU architectures are achieved.

CN119557020BActive Publication Date: 2025-05-09LOONGSON TECH CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510113043.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-05-09
Estimated Expiration
2045-01-24

Smart Images

  • Figure CN119557020B_ABST
    Figure CN119557020B_ABST
Patent Text Reader

Abstract

The embodiments of the present application relate to the field of computer technology, and specifically to a function calling method, apparatus, device and storage medium, which are intended to realize efficient cross-system function calling. The method comprises: during the operation of the target program, determining the function architecture of the function to be called; when the function architecture of the function to be called is different from the function architecture of the last called function, synchronously processing the input parameters corresponding to the function to be called into the parameters to be processed that can be processed by the function architecture corresponding to the function to be called; calling the function to be called according to the parameters to be processed, and outputting the processing result parameters.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a function calling method, apparatus, device and storage medium. Background Art

[0002] With the development of computer technology, the types of computer system architectures have gradually become richer. Systems with different architectures have different binary libraries. When a computer is running an operating system, it cannot directly call an operating system program with a different bit number of another architecture. For example, a 64-bit operating system of architecture A cannot directly call a 32-bit operating system program of architecture B. In related technologies, in order to call binary libraries across operating systems with different architectures and different bit numbers, the computer's central processing unit (CPU) needs to support systems of both architectures at the same time. When running a program corresponding to a system of one architecture, the CPU is switched to a mode corresponding to the architecture, and when running a program corresponding to a system of another architecture, the CPU is switched to a mode corresponding to the other architecture.

[0003] In the related art, when running programs across different architectures, the requirements for the CPU are high, and frequent system switching is also prone to errors, resulting in low efficiency of function calls. Summary of the invention

[0004] The embodiments of the present application provide a function method, apparatus, device and storage medium, aiming to realize efficient cross-system function calling.

[0005] A first aspect of an embodiment of the present application provides a function calling method, the method comprising:

[0006] During the running of the target program, the function architecture of the function to be called is determined;

[0007] When the function architecture of the to-be-called function is different from the function architecture of the last called function, synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function;

[0008] The function to be called is called according to the parameters to be processed, and a processing result parameter is output.

[0009] Optionally, the method further comprises:

[0010] When the function architecture of the to-be-called function is different from the first architecture of the local machine, the input parameters corresponding to the to-be-called function are synchronously processed into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function.

[0011] Optionally, calling the to-be-called function according to the to-be-processed parameter and outputting a processing result parameter includes:

[0012] When the function architecture of the to-be-called function is not a native architecture, using a translator to translate the to-be-called function;

[0013] The parameters to be processed are processed by the translated function to be called to obtain processing result parameters.

[0014] Optionally, before determining the function architecture of the function to be called, the method further includes:

[0015] Loading the first architecture environment library and the second architecture environment library corresponding to the target program;

[0016] Obtaining function prototypes, data types, and global variables of all functions in the first architecture environment library and the second architecture environment library;

[0017] Determine the corresponding relationship between each function prototype and the storage address.

[0018] Optionally, determining the function architecture of the function to be called includes:

[0019] Determine the number of bytes occupied by the offset address corresponding to the function to be called;

[0020] When the number of bytes occupied by the offset address is the first number of bytes, determining that the function architecture of the to-be-called function is the first architecture;

[0021] When the number of bytes occupied by the offset address is the second number of bytes, it is determined that the function architecture of the to-be-called function is the second architecture.

[0022] Optionally, the step of synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function includes:

[0023] Extracting a value corresponding to the parameter to be processed from the offset address corresponding to the parameter to be processed;

[0024] The numerical value corresponding to the parameter to be processed is stored at the offset address corresponding to the function architecture corresponding to the function to be called.

[0025] Optionally, the using a translator to translate the to-be-called function includes:

[0026] Divide the to-be-called function into a plurality of translation blocks;

[0027] The translation blocks corresponding to the to-be-called functions are translated one by one by the translator.

[0028] Optionally, the method further comprises:

[0029] Determine the jump address corresponding to each of the translation blocks;

[0030] When the jump address is a local address, the translator is stopped.

[0031] Optionally, the method further comprises:

[0032] The processing result parameter is stored at an offset address corresponding to the first architecture of the local machine by default;

[0033] Continue to execute the functions of the first architecture.

[0034] A second aspect of an embodiment of the present application provides a function calling device, the device comprising:

[0035] The architecture determination module is used to determine the function architecture of the function to be called during the running of the target program;

[0036] A synchronization processing module, used for, when the function architecture of the to-be-called function is different from the function architecture of the last called function, synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function;

[0037] The processing result parameter acquisition module is used to call the to-be-called function according to the to-be-processed parameters and output the processing result parameters.

[0038] Optionally, the device further comprises:

[0039] The second synchronization processing module is used to synchronize the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function when the function architecture of the to-be-called function is different from the first architecture of the local machine.

[0040] Optionally, the processing result parameter obtaining module includes:

[0041] A function translation submodule, used for translating the function to be called using a translator when the function architecture of the function to be called is not a native architecture;

[0042] The parameter processing submodule is used to process the parameters to be processed through the translated function to be called to obtain processing result parameters.

[0043] Optionally, the device further comprises:

[0044] An environment library loading module, used to load the first architecture environment library and the second architecture environment library corresponding to the target program;

[0045] A function parsing module, used to obtain function prototypes, data types and global variables of all functions in the first architecture environment library and the second architecture environment library;

[0046] The relationship determination module is used to determine the corresponding relationship between each of the function prototypes and the storage address.

[0047] Optionally, the architecture determination module includes:

[0048] A byte number determination submodule, used to determine the number of bytes occupied by the offset address corresponding to the function to be called;

[0049] A first architecture determination submodule, configured to determine, when the number of bytes occupied by the offset address is a first number of bytes, that the function architecture of the to-be-called function is the first architecture;

[0050] The second architecture determination submodule is used to determine that the function architecture of the to-be-called function is the second architecture when the number of bytes occupied by the offset address is the second number of bytes.

[0051] Optionally, the synchronization processing module includes:

[0052] A value extraction submodule, used to extract a value corresponding to the parameter to be processed from an offset address corresponding to the parameter to be processed;

[0053] The numerical value storage submodule is used to store the numerical value corresponding to the parameter to be processed at the offset address corresponding to the function architecture corresponding to the function to be called.

[0054] Optionally, the function translation module includes:

[0055] A function block submodule, used for dividing the to-be-called function into a plurality of translation blocks;

[0056] The function translation submodule is used to translate the translation blocks corresponding to the to-be-called function one by one through the translator.

[0057] Optionally, the function translation module further includes:

[0058] A jump address determination submodule, used to determine the jump address corresponding to each of the translation blocks;

[0059] The translation stop submodule is used to stop using the translator when the jump address is a local address.

[0060] Optionally, the device further comprises:

[0061] The result storage module stores the processing result parameter at an offset address corresponding to the first architecture of the local machine by default;

[0062] A third aspect of an embodiment of the present application provides a readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps in the method described in the first aspect of the present application are implemented.

[0063] A fourth aspect of an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method described in the first aspect of the present application are implemented.

[0064] Using the function calling method provided by the present application, during the running of the target program, the function architecture of the function to be called is determined; when the function architecture of the function to be called is different from the function architecture of the last called function, the input parameters corresponding to the function to be called are synchronously processed into parameters to be processed that can be processed by the function architecture corresponding to the function to be called; the function to be called is called according to the parameters to be processed, and the processing result parameters are output. In the function calling method provided by the present application, the function architecture of the function to be called is first determined during the running of the program. When the function architecture of the function to be called is different from the function architecture of the last called function, the corresponding parameters to be processed are synchronously processed, and then a translator is used to translate the function to be called, and the translated function to be called is used to process the parameters to be processed to obtain the processing result parameters. In this way, the calling of functions of different bit numbers under different CPU architectures can be realized, which improves the overall running speed of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0066] Figure 1 is a flow chart of a function calling method proposed in one embodiment of the present application;

[0067] Figure 2 This is a schematic diagram of a function call flow proposed in an embodiment of the present application;

[0068] Figure 3 It is a schematic diagram of a pointer data processing flow proposed in an embodiment of the present application;

[0069] Figure 4 is a schematic diagram of a function calling device proposed in an embodiment of the present application;

[0070] Figure 5 It is a schematic diagram of an electronic device proposed in an embodiment of the present application. DETAILED DESCRIPTION

[0071] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0072] refer to Figure 1 , Figure 1 : is a flow chart of a function calling method proposed in one embodiment of the present application. Figure 1 As shown, the method comprises the following steps:

[0073] S11: During the running of the target program, the function architecture of the function to be called is determined.

[0074] In this embodiment, the target program is a program running in the first architecture, the function to be called is a function that needs to be called during the running of the target program, and the first architecture is the native architecture.

[0075] In this embodiment, when the target program is running, it runs in the first architecture by default. At this time, it is necessary to check the data structure of the function to be called, and then determine the function architecture of the function to be called. The function that conforms to the first architecture is the first architecture function, and the function that does not conform to the first architecture is the second architecture function, also known as heterogeneous functions. The offset addresses of the parameters corresponding to the first architecture function and the second architecture function occupy different numbers of bytes. The first architecture is an architecture with a higher processing bit number, and the offset address corresponding to the first architecture function usually occupies more bits. The second architecture is an architecture with a lower processing bit number, and the offset address corresponding to the second architecture function usually occupies fewer bits. The function can be judged as the first architecture function or the second architecture function based on the number of bytes occupied by the offset address of the function, such as 64-bit architecture and 32-bit architecture.

[0076] In some special cases, the number of bytes occupied by the function offset address of the 64-bit architecture and the function offset address of the 32-bit architecture may change. For example, memory alignment and compiler optimization will affect the number of bytes of the offset address.

[0077] In this embodiment, the number of bytes occupied by the function offset address corresponding to the 64-bit architecture and the 32-bit architecture is different, and the architecture of the function is determined based on this characteristic.

[0078] In this embodiment, the specific steps of determining the function architecture of the function to be called include:

[0079] S11-1: Determine the number of bytes occupied by the offset address corresponding to the function to be called.

[0080] In this embodiment, the offset address of a function refers to the position offset of data in a storage medium relative to a reference point, and the number of bytes occupied by the offset addresses of functions of different architectures is different.

[0081] In this embodiment, to determine the function architecture of the function to be called, firstly, the offset address of the function to be called is obtained.

[0082] S11-2: When the number of bytes occupied by the offset address is the first number of bytes, determine that the function architecture of the to-be-called function is the first architecture.

[0083] In this embodiment, the first byte number is the number of bytes occupied by the offset address corresponding to the first architecture function. When the number of bytes occupied by the offset address corresponding to a function is the first byte number, it is determined to be the first architecture function.

[0084] In this embodiment, after the offset address of the function to be called is obtained, the number of bytes occupied by the offset address is checked. When the number of bytes occupied by the function to be called is the first number of bytes, the function architecture of the function to be called is determined to be the first architecture.

[0085] S11-3: When the number of bytes occupied by the offset address is the second number of bytes, determine that the function architecture of the to-be-called function is the second architecture.

[0086] In this embodiment, the second byte number is the number of bytes occupied by the offset address corresponding to the heterogeneous function. When the number of bytes occupied by the offset address corresponding to a function is the second byte number, the function architecture of the function is determined to be the second architecture, and the second architecture is a system architecture different from the second architecture.

[0087] In this embodiment, after the offset address corresponding to the function to be called is obtained, the number of bytes occupied by the offset address is checked, and when the number of bytes occupied by the offset address is the second number of bytes, the function to be called is determined to be a heterogeneous function.

[0088] For example, the first architecture is a CPU architecture with a processing bit number of 64 bits, and the second architecture is a CPU architecture with a processing bit number of 32 bits. The number of bytes occupied by the offset address corresponding to the first architecture function is 8 bytes, and the number of bytes occupied by the offset address corresponding to the second architecture is 4 bytes.

[0089] S12: When the function architecture of the to-be-called function is different from the function architecture of the last called function, the input parameters corresponding to the to-be-called function are synchronously processed into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function.

[0090] In this embodiment, the parameters to be processed are parameters that need to be processed by a function during the operation of the target program. The parameters to be processed corresponding to the function to be called include the result parameters output by the last called function and the related parameters that the function to be called needs to use. The form of the offset address corresponding to the parameters to be processed when stored in the first architecture is different from the form of the offset address corresponding to the parameters when stored in the second architecture.

[0091] In this embodiment, when the function architecture of the function to be called is the second architecture, it cannot be directly called by the local machine. The parameters that need to be processed by the first architecture are also parameters stored based on the first architecture. The heterogeneous function cannot directly process the parameters corresponding to the first architecture. At this time, the parameters to be processed corresponding to the first architecture need to be synchronously processed as the parameters to be processed corresponding to the heterogeneous function. After the heterogeneous function is called, the heterogeneous function can process the parameters to be processed.

[0092] In this embodiment, when the architecture of the function to be called is the second architecture, the parameters to be processed corresponding to the first architecture function are synchronously processed as the parameters to be processed corresponding to the second architecture function. During processing, the value of the parameter to be processed in the offset address corresponding to the first architecture function is first extracted, and then the value is stored at the offset address corresponding to the heterogeneous function. In this way, the synchronous processing of the parameters corresponding to the first architecture function is completed.

[0093] In this embodiment, the specific steps of synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function include:

[0094] S12-1: Extracting a value corresponding to the parameter to be processed from an offset address corresponding to the parameter to be processed.

[0095] In this embodiment, when synchronously processing the parameter to be processed, firstly, a value corresponding to the parameter to be processed is extracted from an offset address corresponding to the parameter to be processed.

[0096] In this embodiment, the parameter to be processed is stored in the first architecture at the offset address corresponding to the first architecture, and the number of bits occupied is the number of bits occupied by the offset address corresponding to the first architecture. The parameter cannot be directly read by the heterogeneous function. Therefore, the function calling the second architecture cannot directly process the parameter corresponding to the first architecture function, and it is necessary to extract the value of the parameter to be processed corresponding to the first architecture function first.

[0097] For example, the offset address of the parameter to be processed corresponding to the first architecture function is 0xccccccccdddddddd, and the corresponding value extracted from the offset address is 5.

[0098] S12-2: Store the numerical value corresponding to the parameter to be processed at the offset address corresponding to the function architecture corresponding to the function to be called.

[0099] In this embodiment, after extracting the corresponding numerical value from the offset address corresponding to the first architecture, the numerical value is stored at the offset address corresponding to the second architecture of the function to be called. After the parameter to be processed is stored at the offset address corresponding to the second architecture, the heterogeneous function can read the corresponding offset address during runtime and obtain the numerical value of the parameter to be processed from the offset address.

[0100] For example, the offset address of the parameter to be processed corresponding to the second architecture is 0xcccccccc.

[0101] S13: calling the function to be called according to the parameters to be processed, and outputting processing result parameters.

[0102] In this embodiment, the processing result parameter is a result parameter output after the to-be-called function processes the to-be-processed parameter.

[0103] In this embodiment, after obtaining the parameters to be processed, the parameters to be processed are processed by the function to be called to obtain processing result parameters, and the processing result parameters are stored at the offset address corresponding to the second architecture.

[0104] In another embodiment of the present application, the method further includes:

[0105] S21: When the function architecture of the to-be-called function is different from the first architecture of the local machine, synchronously process the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function.

[0106] In this embodiment, if the function called at the beginning of program startup is a heterogeneous function of the first architecture different from the local default, the relevant parameters needed by the function to be called are directly synchronized and processed into the parameters of the second architecture corresponding to the function to be called to obtain the parameters to be processed.

[0107] In another embodiment of the present application, the method further includes:

[0108] S31: When the function architecture of the to-be-called function is not a native architecture, using a translator to translate the to-be-called function.

[0109] In this embodiment, the translator is used to translate binary functions and translate heterogeneous functions into functions that can be run by the first architecture. The translator is an executable program based on the translation function and is stored in a local database.

[0110] In this embodiment, when a heterogeneous function needs to be translated, a translator is used to run the function to be called. After the translator reads the function to be called, the heterogeneous function can be translated into a first architecture function.

[0111] In this embodiment, the using a translator to translate the to-be-called function includes:

[0112] S31-1: Divide the to-be-called function into multiple translation blocks.

[0113] In this embodiment, when the translator translates a function to be called, it first divides the function into multiple translation blocks so as to facilitate translation block by block.

[0114] In this embodiment, the size of the translation block can be set according to actual conditions.

[0115] S31 - 2 : The translation blocks corresponding to the to-be-called functions are translated one by one by the translator.

[0116] In this embodiment, after the function to be called is divided into a plurality of translation blocks, the translation blocks corresponding to the function to be called are translated one by one by the translator. When the translation is in progress, the jump address at the beginning of each translation block is first read, and the jump address can represent the architecture of the function in the translation block. After reading the jump address at the beginning of the translation block, when it is determined that the function of the translation block is a heterogeneous function, the translation function is used to translate the heterogeneous function in the translation block. The translated function is obtained, and the translated function is the first architecture function. The translator is stopped until the function to be called is fully translated. When the jump address of the translation block read by the translator becomes the address corresponding to the first architecture function, it is determined that the heterogeneous function has been translated. At this time, the translator is closed and the first architecture function is directly run.

[0117] In this embodiment, the method further includes:

[0118] S31 - 3 : Determine the jump address corresponding to each of the translation blocks.

[0119] In this embodiment, each translation block has a corresponding jump address at the beginning, and the jump address can guide the translator to translate the content in the next translation block.

[0120] In this embodiment, when the translator translates each translation block, it first reads the jump address of the translation block.

[0121] S31-4: When the jump address is a local address, stop using the translator.

[0122] In this embodiment, when the jump address corresponding to the translation block is read as a native address, it means that the heterogeneous function has been translated. At this time, the translator is stopped, and the variables are synchronized and then the native function is continued to be executed in the first architecture.

[0123] S32: Processing the parameters to be processed by the translated function to be called to obtain processing result parameters.

[0124] In this embodiment, the processing result parameter is a parameter obtained after processing the parameter to be processed.

[0125] In this embodiment, after the function to be called is translated into the first architecture function, the parameters to be processed are processed by the translated function to be called. At this time, the storage address corresponding to the parameters to be processed is processed into an address that can be read by the heterogeneous function after synchronization processing. At this time, the translated function to be called obtains the parameters to be processed from the offset address after synchronization processing, processes the parameters to be processed, and obtains the result parameters.

[0126] In this embodiment, when the target program is running, the parameters are continuously synchronized and the heterogeneous functions are translated according to the function architecture of the function to be called. When jumping out of the translator, the parameters need to be synchronized again before being executed locally.

[0127] In this embodiment, during the running of the target program, the function architecture of the function to be called is first determined. When the function architecture of the function to be called is the second architecture, the function to be called is translated by a translator. At the same time, the parameters to be processed need to be processed synchronously so that the parameters to be processed can be obtained by the heterogeneous function. The translated function to be called is then used to process the parameters to be processed to obtain the result parameters. In this way, the purpose of directly calling the function of the second architecture during the running of the target application program in the first architecture is achieved, thereby improving the running efficiency of the program.

[0128] In another embodiment of the present application, before determining the function architecture of the function to be called, the method further includes:

[0129] S41: Load the first architecture environment library and the second architecture environment library corresponding to the target program.

[0130] In this embodiment, the first architecture environment library includes functions, variables, etc. required by the first architecture when running the target program, and the second architecture environment library includes functions, variables, etc. of another architecture different from the first architecture.

[0131] In this embodiment, when running the target program, the first architecture environment library and the second architecture environment library corresponding to the target program are first loaded. The first architecture environment library corresponding to the target program can be directly called and loaded. Before loading the second architecture environment library, check which heterogeneous functions the target running program depends on, and then load the corresponding second architecture environment library.

[0132] S42: Obtain function prototypes, data types, and global variables of all functions in the first architecture environment library and the second architecture environment library.

[0133] In this embodiment, the function prototype is a form of function declaration, also known as function declaration. It consists of the function return type, function name and parameter list. The parameter list must include the parameter type, but the parameter does not need to be named. The function prototype describes the interface of the function, similar to the function header when the function is defined. The function prototype is used to check the correctness of the function call during the program compilation stage, including checking the function's return value type, function name, and parameter list.

[0134] In this embodiment, after the first architecture environment library and the second architecture environment library corresponding to the target program are obtained, for each function in the first architecture environment library and the second architecture environment library, all function prototypes, data types and global variables in the first architecture environment library and the second architecture environment library are obtained.

[0135] S43: Determine the corresponding relationship between each of the function prototypes and the storage address.

[0136] In this embodiment, each function prototype corresponds to a function address. After the function address corresponding to the function prototype is determined, the corresponding function prototype can be obtained from the function address, thereby implementing the call to the function.

[0137] In this embodiment, after parsing the function prototypes in the first architecture environment library and the second architecture environment library, the correspondence between each function prototype and the storage address is determined, and the correspondence between each function and the storage address is recorded to facilitate calling the function.

[0138] For example, a function address 0xdddddddd corresponds to the function prototype intfunc(int, void), and the function prototype can be obtained according to the address 0xdddddddd.

[0139] In this embodiment, before starting the target program, the first architecture environment library corresponding to the target program and the second architecture environment library that the target program depends on are first loaded, and then the function prototypes, data types, global variables and other parameters in the first architecture environment library and the second architecture environment library are parsed to obtain the storage address corresponding to each function prototype, thereby facilitating the local machine's call to the function.

[0140] In another embodiment of the present application, after step S14, the method further includes:

[0141] S51: Store the processing result parameters at the offset address corresponding to the first architecture function.

[0142] In this embodiment, after processing the processing parameters by calling heterogeneous functions to obtain the processing result parameters, the storage address corresponding to the processing result parameters needs to be stored at the offset address corresponding to the first architecture function to ensure that the first architecture can access the corresponding offset address at any time and extract the corresponding result parameters for subsequent calculations.

[0143] In this embodiment, after the processing result parameter is stored at the offset address corresponding to the first architecture function, the first architecture function continues to be executed until the target program is completed.

[0144] In this embodiment, after obtaining the processing result parameters, the processing result parameters are synchronously processed and stored at the offset address corresponding to the first architecture function, which facilitates the first architecture to call the processing result parameters and improves the running speed of the target program.

[0145] In another embodiment of the present application, reference Figure 2 , Figure 2 is a schematic diagram of a function call flow proposed in an embodiment of the present application, such as Figure 2 As shown, in the process of running a heterogeneous function in the first architecture, the first architecture environment library and the second architecture environment library are first loaded, and then the corresponding data types are loaded. The first architecture environment library and the second architecture environment library are parsed to obtain function prototypes, global variables, etc. When running the function, the entry of each function is judged. When the entry of the function is the function entry corresponding to the first architecture, the function is directly called. When the function entry of the function is the function entry corresponding to the second architecture, the function is translated by the translator, and the offset address corresponding to the function is marked as guest (heterogeneous). After translating a translation block, the next translation block is continued to be translated. When the function in the next translation block is still a heterogeneous function, the translator is continued to be used for translation. When the function in the next translation block is a first architecture function, the translator is stopped and the function is directly called. Before calling the heterogeneous function, the input parameters of the heterogeneous function need to be synchronized and processed as parameters that can be called by the heterogeneous function. After the heterogeneous function is called, the result parameters output by the heterogeneous function are synchronized and processed as parameters that can be called by the first architecture function.

[0146] In another embodiment of the present application, reference Figure 3 , Figure 3 : is a schematic diagram of a pointer data processing flow proposed in an embodiment of the present application. Figure 3 As shown, when performing data synchronization, if a pointer is read, the pointer is converted into an offset address corresponding to the second architecture. For example, if the heterogeneous function is a 32-bit function, it is converted into an offset address corresponding to the 32-bit system. When a structure is read, data synchronization is performed on the structure, and the address corresponding to the structure is converted into an offset address corresponding to the second architecture. If the data read is basic type data, the data is directly called without parameter synchronization.

[0147] In another embodiment of the present application, the first architecture is a 32-bit CPU architecture, and the second architecture is a 64-bit CPU architecture. When the target program of the first architecture calls the binary library of the second architecture, the second architecture function needs to be translated into the first architecture function through the translator, and the corresponding parameters are stored as 32-bit offset addresses.

[0148] In the above embodiments of the present application, by synchronously processing the parameters to be processed corresponding to different architectures and using a translator to translate the functions of different architectures, the computer can call heterogeneous functions to process the parameters while running the native architecture functions, and then obtain the processing results, thereby realizing the function calling across different architectures and improving the running speed of the program.

[0149] Based on the same inventive concept, an embodiment of the present application provides a function calling device. Figure 4 , Figure 4 FIG. 4 is a schematic diagram of a function calling device 400 proposed in an embodiment of the present application. Figure 4 As shown, the device comprises:

[0150] The architecture determination module 401 is used to determine the function architecture of the function to be called during the running of the target program;

[0151] A synchronization processing module 402 is used to synchronize the input parameters corresponding to the function to be called into parameters to be processed that can be processed by the function architecture corresponding to the function to be called when the function architecture of the function to be called is different from the function architecture of the last called function;

[0152] The processing result parameter obtaining module 403 is used to call the to-be-called function according to the to-be-processed parameters and output the processing result parameters.

[0153] Optionally, the device further comprises:

[0154] The second synchronization processing module is used to synchronize the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function when the function architecture of the to-be-called function is different from the first architecture of the local machine.

[0155] Optionally, the processing result parameter obtaining module includes:

[0156] A function translation submodule, used for translating the function to be called using a translator when the function architecture of the function to be called is not a native architecture;

[0157] The parameter processing submodule is used to process the parameters to be processed through the translated function to be called to obtain processing result parameters.

[0158] An environment library loading module, used to load the first architecture environment library and the second architecture environment library corresponding to the target program;

[0159] A function parsing module, used to obtain function prototypes, data types and global variables of all functions in the first architecture environment library and the second architecture environment library;

[0160] The relationship determination module is used to determine the corresponding relationship between each of the function prototypes and the storage address.

[0161] Optionally, the architecture determination module includes:

[0162] A byte number determination submodule, used to determine the number of bytes occupied by the offset address corresponding to the function to be called;

[0163] A first architecture determination submodule, configured to determine, when the number of bytes occupied by the offset address is a first number of bytes, that the function architecture of the to-be-called function is the first architecture;

[0164] The second architecture determination submodule is used to determine that the function architecture of the to-be-called function is the second architecture when the number of bytes occupied by the offset address is the second number of bytes.

[0165] Optionally, the synchronization processing module includes:

[0166] A value extraction submodule, used to extract a value corresponding to the parameter to be processed from an offset address corresponding to the parameter to be processed;

[0167] The numerical value storage submodule is used to store the numerical value corresponding to the parameter to be processed at the offset address corresponding to the function architecture corresponding to the function to be called.

[0168] Optionally, the function translation module includes:

[0169] A function block submodule, used for dividing the to-be-called function into a plurality of translation blocks;

[0170] The function translation submodule is used to translate the translation blocks corresponding to the to-be-called function one by one through the translator.

[0171] Optionally, the function translation module further includes:

[0172] A jump address determination submodule, used to determine the jump address corresponding to each of the translation blocks;

[0173] The translation stop submodule is used to stop using the translator when the jump address is a local address.

[0174] Optionally, the device further comprises:

[0175] The result storage module stores the processing result parameter at an offset address corresponding to the first architecture of the local machine by default;

[0176] Based on the same inventive concept, another embodiment of the present application provides a readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps in the function calling method described in any of the above embodiments of the present application are implemented.

[0177] Based on the same inventive concept, another embodiment of the present application provides an electronic device, Figure 5 It is a schematic diagram of an electronic device 500 proposed in one embodiment of the present application, including a memory 502, a processor 501 and a computer program stored in the memory and executable on the processor, and when the processor executes, the steps in the function calling method described in any of the above embodiments of the present application are implemented.

[0178] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0179] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0180] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0181] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0182] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0183] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0184] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0185] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0186] The function calling method, apparatus, device and storage medium provided by the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A function calling method, characterized in that: The method is applied to a central processing unit of a first architecture, comprising: During the running of the target program, determining a function architecture of a function to be called, wherein the function architecture represents a central processing unit architecture corresponding to the function, and the function architecture includes a first architecture and a second architecture, wherein the first architecture and the second architecture are based on different instruction set architectures and have different processing bits; When the function architecture of the to-be-called function is different from the function architecture of the last called function, synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function; Call the function to be called according to the parameters to be processed, and output the processing result parameters; The step of synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function includes: Extracting a value corresponding to the parameter to be processed from the offset address corresponding to the parameter to be processed; The value corresponding to the parameter to be processed is stored at the offset address corresponding to the function architecture corresponding to the function to be called, and the number of bytes occupied by the offset address corresponding to the function architecture corresponding to the function to be called corresponds to the number of processing bits of the central processing unit architecture corresponding to the function to be called; In the case where the parameter to be processed is a pointer, converting the pointer into an offset address corresponding to the function architecture of the function to be called; When the parameter to be processed is a structure, the address corresponding to the structure is converted into an offset address corresponding to the function architecture of the function to be called.

2. The method according to claim 1, characterized in that The method further comprises: When the function architecture of the to-be-called function is different from the first architecture of the local machine, the input parameters corresponding to the to-be-called function are synchronously processed into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function.

3. The method according to claim 1, characterized in that The calling of the to-be-called function according to the to-be-processed parameter and outputting the processing result parameter comprises: When the function architecture of the to-be-called function is not a native architecture, using a translator to translate the to-be-called function; The parameters to be processed are processed by the translated function to be called to obtain processing result parameters.

4. The method according to claim 1, characterized in that: Before determining the function architecture of the function to be called, the method further includes: Loading the first architecture environment library and the second architecture environment library corresponding to the target program; Obtaining function prototypes, data types, and global variables of all functions in the first architecture environment library and the second architecture environment library; Determine the corresponding relationship between each function prototype and the storage address.

5. The method according to claim 1, characterized in that The step of determining the function architecture of the function to be called includes: Determine the number of bytes occupied by the offset address corresponding to the function to be called; When the number of bytes occupied by the offset address is the first number of bytes, determining that the function architecture of the to-be-called function is the first architecture; When the number of bytes occupied by the offset address is the second number of bytes, it is determined that the function architecture of the to-be-called function is the second architecture.

6. The method according to claim 3, characterized in that The using a translator to translate the function to be called includes: Divide the to-be-called function into a plurality of translation blocks; The translation blocks corresponding to the to-be-called functions are translated one by one by the translator.

7. The method according to claim 6, characterized in that The method further comprises: Determine the jump address corresponding to each of the translation blocks; When the jump address is a local address, the translator is stopped.

8. The method according to claim 1, characterized in that The method further comprises: The processing result parameter is stored at an offset address corresponding to the first architecture of the local machine by default.

9. A function calling device, characterized in that: The device comprises: An architecture determination module is used to determine the function architecture of the function to be called during the running of the target program, wherein the function architecture represents the central processing unit architecture corresponding to the function, and the function architecture includes a first architecture and a second architecture, wherein the first architecture and the second architecture are based on different instruction set architectures and have different processing bits; A synchronization processing module, used for, when the function architecture of the to-be-called function is different from the function architecture of the last called function, synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function; A processing result parameter obtaining module, used for calling the to-be-called function according to the to-be-processed parameter, and outputting the processing result parameter; The step of synchronously processing the input parameters corresponding to the to-be-called function into to-be-processed parameters that can be processed by the function architecture corresponding to the to-be-called function includes: Extracting a value corresponding to the parameter to be processed from the offset address corresponding to the parameter to be processed; The value corresponding to the parameter to be processed is stored at the offset address corresponding to the function architecture corresponding to the function to be called, and the number of bytes occupied by the offset address corresponding to the function architecture corresponding to the function to be called corresponds to the number of processing bits of the central processing unit architecture corresponding to the function to be called; In the case where the parameter to be processed is a pointer, converting the pointer into an offset address corresponding to the function architecture of the function to be called; When the parameter to be processed is a structure, the address corresponding to the structure is converted into an offset address corresponding to the function architecture of the function to be called.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in the method according to any one of claims 1 to 8 are implemented.

11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Heterogeneous computing system executable file acquisition method, operation method and related product

    CN109656566A

  • Function calling method and device, equipment and medium

    CN117093281A