Function call method and apparatus
By determining the function address and status information of the function to be called, the function is called only when the conditions are met, which solves the problem of strong coupling between modules and realizes the hot upgrade and update capability of the modules.
Patent Information
- Application Number
- CN202210197115.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-01
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2042-03-01
AI Technical Summary
In the prior art, function calls between modules lead to strong coupling, which hinders the hot upgrade and update operations of the called modules.
By determining the function address of the function to be called and querying its current state information, the function is called only when the preset calling conditions are met, avoiding displaying the dependencies of the exported functions.
It achieves decoupling between modules, allowing the called modules to be hot-upgraded and updated without affecting the calling modules, thus improving the flexibility and stability of the system.
Smart Images

Figure CN114461260B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of computer technology, and in particular to a function calling method. Background Art
[0002] With the continuous development of computer technology, modules in many operating systems can execute corresponding functions by calling functions. In the existing technology, the called module can explicitly export the function so that the calling module can call the exported function. However, when the calling module calls the function explicitly exported by the called module, the operating system will establish a strong coupling between the calling module and the called module, resulting in the called module being unable to perform update operations such as hot upgrades due to its dependence on the exported function. Summary of the Invention
[0003] In view of this, embodiments of this specification provide a function calling method. One or more embodiments of this specification also relate to a function calling apparatus, a computing device, a computer-readable storage medium, and a computer program to address technical deficiencies in the prior art.
[0004] According to a first aspect of an embodiment of this specification, a function calling method is provided, which is applied to a function calling module, including:
[0005] Determine a function address corresponding to the to-be-called function, wherein the function address is an address obtained by querying a function providing module based on attribute information of the to-be-called function;
[0006] Determine current state information of the to-be-called function in the function providing module based on the function address;
[0007] When the current state information meets a preset calling condition, the to-be-called function is called.
[0008] According to a second aspect of the embodiments of this specification, a function calling device is provided, which is applied to a function calling module, including:
[0009] A first determining module is configured to determine a function address corresponding to a to-be-called function, wherein the function address is an address obtained by querying from a function providing module based on attribute information of the to-be-called function;
[0010] a second determining module, configured to determine current state information of the to-be-called function in the function providing module based on the function address;
[0011] The calling module is configured to call the to-be-called function when the current state information satisfies a preset calling condition.
[0012] According to a third aspect of an embodiment of this specification, a computing device is provided, including:
[0013] memory and processor;
[0014] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the function calling method are implemented.
[0015] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the steps of the function calling method are implemented.
[0016] According to a fifth aspect of the embodiments of this specification, a computer program is provided, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the function calling method.
[0017] The function calling method provided in this specification is applied to a function calling module, and includes determining a function address corresponding to a function to be called, wherein the function address is an address obtained by querying a function providing module based on attribute information of the function to be called; determining current status information of the function to be called in the function providing module based on the function address; and calling the function to be called when the current status information meets a preset calling condition.
[0018] Specifically, in this method, the function-calling module proactively uses the attribute information of the function to be called to retrieve the function address from the function-providing module, and then calls the function to be called based on the function address. This avoids the tight coupling between the function-calling module and the function-providing module caused by calling the exported function, and further avoids the problem of the function-providing module being unable to perform update operations such as hot upgrades due to the dependency on the exported function. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is a scene diagram of a function calling method provided by an embodiment of this specification;
[0020] Figure 2 This is a flow chart of a function calling method provided by one embodiment of this specification;
[0021] Figure 3 This is a flowchart of a processing process of a function calling method provided by one embodiment of this specification;
[0022] Figure 4 This is a schematic diagram of the structure of a function calling device provided by one embodiment of this specification;
[0023] Figure 5 This is a structural block diagram of a computing device provided by one embodiment of this specification. DETAILED DESCRIPTION
[0024] The following description sets forth many specific details to facilitate a thorough understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the scope of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.
[0025] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "the," and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0026] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0027] With the continuous development of computer technology, many operating systems (such as the Linux operating system) can call functions between modules. For example, in a module-to-module calling method provided in this specification, a called module in the Linux operating system needs to export symbols (i.e., explicitly export functions) to facilitate the use of the calling module. At the same time, when the calling module calls the function exported by the explicitly exported method, that is, during the loading process of the calling module, if one module calls the exported symbol of another module, when loading the modules, the operating system will establish a dependency relationship between them and record it in the module dependency list. In addition, the reference count of the called module will increase, causing the reference count to become non-zero. When the reference count of the called module is non-zero, the called module cannot be uninstalled. Therefore, although this module-to-module calling method makes inter-module calls safer, it also brings strong coupling, resulting in dependencies between modules, which makes it impossible for the called module to perform update operations such as hot upgrades. Moreover, when a module calls an exported symbol, the dependency relationship between the modules persists unless the dependent module is uninstalled.
[0028] In practice, each module in the Linux operating system has a corresponding structure in the kernel representing module information. This structure is the kernel module structure, or the module's metadata. Function addresses within a module are recorded in the symbol table (also known as the function address table) of its kernel module structure (structmodule). These functions may or may not be explicitly exported. In other words, not all functions in a module are explicitly exported for use by other modules. If a function in a module is not explicitly exported, other modules cannot directly call it.
[0029] Based on this, Figure 1 This is a scene diagram of a function calling method provided by an embodiment of this specification, see Figure 1 In the function calling method provided in this specification, function calling module 102 can determine the function address corresponding to the function to be called, wherein the function address is the address obtained by function calling module 102 from function providing module 104 based on the attribute information of the function to be called. Based on the function address, function providing module 102 determines the current state information of the function to be called in function providing module 104; and if the current state information meets the preset calling conditions, the function to be called is called.
[0030] In other words, the function calling module 102 in the function calling method provided in this specification can query the function address of the function to be called based on the attribute information of the function to be called. The corresponding function is called through the function address. Since the function is not explicitly exported, there is no corresponding dependency relationship between the two modules, that is, a strong coupling relationship, thus avoiding the problem of the function providing module being unable to perform update operations such as hot upgrades due to the call of the exported function.
[0031] Specifically, in this specification, a function calling method is provided. This specification also involves a function calling device, a computing device, a computer-readable storage medium and a computer program, which are described in detail one by one in the following embodiments.
[0032] Figure 2 A flowchart of a function calling method provided according to an embodiment of the present specification is shown. The function calling method is applied to a function calling module and specifically includes the following steps.
[0033] Step 202: Determine a function address corresponding to the function to be called, wherein the function address is an address obtained by querying a function providing module based on attribute information of the function to be called.
[0034] In actual applications, the function calling module and the function providing module can be modules in the operating system respectively. For example, the function calling module can be a module that needs to call a function in the Linux operating system, and the function providing module can be a module that provides the called function (i.e., the function to be called) in the Linux operating system.
[0035] Among them, the function to be called can be understood as the function that the function calling module needs to call. In actual applications, the function to be called is the function provided by the function providing module; the function to be called can realize corresponding functions, such as numerical calculation functions, data search functions, etc. Correspondingly, the attribute information of the function to be called can be set according to the actual application scenario. For example, the attribute information of the function to be called can be the function identifier of the function to be called, and the function identifier includes but is not limited to the name, number, ID, etc. of the function to be called.
[0036] The following describes how to determine the function address corresponding to a function to be called, using the inter-module function call scenario in the Linux operating system as an example. The function to be called is function X, the function calling module is module A in the Linux operating system that needs to call function X, and the function providing module is module B in the Linux operating system that contains function X. The attribute information of the function to be called is the function name of function X. Based on this, module A in the Linux operating system can determine the function address corresponding to function X. This function address is obtained by module A in the Linux operating system from module B in the Linux operating system based on the function name of function X.
[0037] In one embodiment provided herein, the function calling module can query the function address based on the function name, kallsyms_lookup_name, provided by the Linux kernel. The corresponding function function can be called using the queried function address. Furthermore, since the module is not explicitly exported, there is no corresponding dependency between the two modules, thus avoiding the problem of subsequent function providing modules being unable to perform update operations such as hot upgrades due to the export function being called. The specific implementation is as follows.
[0038] Before determining the function address corresponding to the function to be called, the method further includes:
[0039] Determine the function to be called from the information storage object;
[0040] Based on the attribute information of the function to be called, querying the function address corresponding to the function to be called from the function providing module through the address query function;
[0041] The function address corresponding to the to-be-called function is stored in the information storage object.
[0042] Among them, the information storage object can be understood as an object that stores the attribute information of the function to be called. For example, the information storage object can be understood as a table, log file, cache, etc. that stores the function name; in actual application, the information storage object can be set in the function call module.
[0043] The address query function can be understood as a function that can query the function address based on the attribute information of the function to be queried. For example, the address query function can be understood as a function kallsyms_lookup_name (a function) provided by the kernel of the Linux operating system.
[0044] Specifically, the function calling module can determine the function to be called from the information storage object, and based on the attribute information of the function to be called, obtain the function address corresponding to the function to be called from the function providing module through the address query function, and store the function address in the information storage object.
[0045] Continuing with the above example, the information storage object can be understood as a function address table, which can store function names and corresponding function addresses. Based on this, before calling a function, module A needs to determine the function to be called from the function address table, and based on the function name corresponding to the function, use the function kallsyms_lookup_name provided by the Linux operating system kernel to look up the function addresses of each subsequent called function in the table from other functions in the Linux operating system except module A, and record the found function addresses in the function address table, wherein there is a corresponding relationship between the function names and function addresses in the function address table.
[0046] In the embodiments of this specification, based on the attribute information of the to-be-called function determined from the information storage object, the address of the to-be-called function is retrieved from the function providing module via an address query function, and the function address is stored in the information storage object. This avoids the problem of the function providing module being unable to perform subsequent update operations such as hot upgrades due to the exported function being called.
[0047] In one embodiment provided in this specification, since there is no dependency between modules, when the function calling module is in the process of calling function loading, it is also necessary to register a module notification chain callback; so that when the called module (function providing module) performs an update operation, the corresponding function address in the function address table is updated in time. The specific implementation method is as follows.
[0048] The function calling method further includes:
[0049] Determine the function providing module corresponding to the function to be called, and attribute information of the function providing module;
[0050] a module status monitoring unit that generates a module status notification request based on attribute information of the module provided by the function, and sends the module status notification request;
[0051] Upon receiving a module status change notification sent by the module status monitoring unit, updating a function address corresponding to the to-be-called function based on the module status change notification;
[0052] Among them, the module status change notification is a notification generated by the module status monitoring service based on the module status notification request when the module status of the function providing module changes. The attribute information of the function providing module can be set according to the actual application scenario. For example, the attribute information of the function providing module can be the function identifier of the function providing module, and the function identifier includes but is not limited to the name, number, ID, etc. of the function providing module. Correspondingly, the module status notification request can be understood as a request for the function calling module to register the module notification chain callback; the module status monitoring unit can be understood as a unit that can detect the current status of the called module and implement the module notification chain callback, such as a module notification chain mechanism. Correspondingly, the situation where the module status changes can be understood as the situation where operations such as updating, removing, and replacing the function providing module are performed.
[0053] Specifically, the function calling module can determine the function providing module corresponding to the function to be called, as well as the attribute information of the function providing module. The function calling module generates a module status notification request based on the attribute information of the function providing module, and sends the module status notification request to the module status monitoring unit; when the function calling module receives the module status change notification sent by the module status monitoring unit, it can update the function address corresponding to the function to be called based on the module status change notification; wherein, the module status change notification is a notification generated by the module status monitoring unit based on the module status notification request when the module status of the function providing module changes.
[0054] Continuing with the above example, the module status monitoring unit is a module notification chain mechanism, based on which module A can determine the module B corresponding to the function X and determine the module identifier of module B; then module A can generate a request to register a module notification chain callback (i.e., a module status notification request) based on the module identifier of module B, and send the request to the module notification chain mechanism. After module A completes registration, when module B changes its status due to operations such as update and removal, the module notification chain mechanism can generate a notification (i.e., a module status change notification) and send the notification to module A, thereby informing module A of the change in the status of module B. Based on the notification, module A can promptly update the function address corresponding to module B in the function address table, thereby improving the execution efficiency of module A and saving computing resources.
[0055] In one embodiment provided in this specification, determining the function address corresponding to the to-be-called function includes:
[0056] When a function call instruction for a function to be called is received and a function address corresponding to the function to be called exists, the function address corresponding to the function to be called is queried from an information storage object.
[0057] The function call instruction can be understood as an instruction indicating the function call module to call the to-be-called function. For example, the function call instruction can be understood as an instruction indicating the function call module to perform a specific task, and the function call module needs to call a specific function in the process of performing the specific task to complete the specific task.
[0058] Specifically, the function call module determines the function address corresponding to the to-be-called function from the information storage object in a case where the function call instruction for the to-be-called function is received, and queries the function address corresponding to the to-be-called function from the information storage object in a case where the function address corresponding to the to-be-called function exists.
[0059] In the above example, the module A determines whether the function address corresponding to the function X exists from the function address table based on the instruction in a case where the function call instruction for the function X is received, and queries the function address corresponding to the function X from the function address table in a case where the function address corresponding to the function X exists.
[0060] Further, in a case where the module A determines that the function address corresponding to the function X does not exist in the function address table, the function call module exits with an error and notifies the function management object of a function call failure, and the specific implementation manner is as follows.
[0061] The function call method further includes:
[0062] generating a function call failure notification based on the attribute information of the to-be-called function in a case where the function call instruction for the to-be-called function is received and the function address corresponding to the to-be-called function does not exist;
[0063] sending the function call failure notification to the function management object.
[0064] The function management object can be understood as an object capable of managing modules and functions in the modules in the linux operating system, for example, a smart robot, a program, a smart device, a neural module model, etc.
[0065] In the above example, the module A determines whether the function address corresponding to the function X exists from the function address table based on the instruction in a case where the function call instruction for the function X is received, and queries the function address corresponding to the function X from the function address table in a case where the function address corresponding to the function X exists.
[0066] In the embodiment of this specification, before calling the corresponding function, it is first determined whether the function address corresponding to the function exists. If so, the operation of calling the function to be called is continued; otherwise, an error is exited and the function management object is notified for processing, thereby further ensuring the operational stability of the module.
[0067] Step 204: Determine the current state information of the to-be-called function in the function providing module based on the function address.
[0068] The current state information may be understood as information indicating whether the function to be called currently exists.
[0069] Specifically, after determining the function address corresponding to the to-be-called function, the function calling module can determine the current state information of the to-be-called function in the function providing module based on the function address.
[0070] In one embodiment provided in this specification, considering that there is no explicit dependency between modules, when a function calling module calls a corresponding function based on a function address, the called function may be removed. To ensure a safe call, the function calling module needs to check the corresponding called module structure based on the previously obtained function address. If the called module structure exists, the module determines the current state information of the to-be-called function in the called module (the function providing module) based on the function address, thereby ensuring the safe call of the function. The specific implementation method is as follows.
[0071] The determining, based on the function address, the current state information of the to-be-called function in the function providing module includes:
[0072] Determine, based on the function address, current state information of a function providing module corresponding to the to-be-called function;
[0073] In a case where it is determined based on the current state information that the function providing module exists, the current state information of the to-be-called function in the function providing module is determined based on the function address.
[0074] The function providing the current status information of the module can be understood as information indicating whether the function provides the current status information of the module.
[0075] Specifically, when determining the current state information of a function to be called based on its address, the function calling module first needs to determine the current state information of the function providing module corresponding to the function to be called based on the function address. Upon determining that the function providing module currently exists based on this current state information, the function calling module then determines the current state information of the function to be called within the function providing module based on the function address. In practice, each module in the Linux operating system has its code segment range within its module structure. The function calling module can determine the module to which the called function belongs based on its address, and the Linux operating system also provides an interface to support this query.
[0076] In one embodiment provided in this specification, in order to ensure safe calling, the function calling module needs to reversely check the corresponding called module structure based on the previously obtained function address. However, if the called module structure is not found, that is, if the called module structure does not exist, it means that the called module has been removed or updated. In this case, the function address corresponding to the called module in the function address table is updated again based on the function name. The specific implementation method includes:
[0077] The function calling method further includes:
[0078] When it is determined based on the current state information that the function providing module does not exist, the function address corresponding to the to-be-called function is updated.
[0079] Specifically, when the function calling module determines based on current state information that the function providing module does not exist, it is necessary to update the function address corresponding to the function to be called. In actual applications, when the function calling module determines that the function providing module does not exist or the function providing module structure does not exist, the function calling module can query the updated function address corresponding to the function to be called through the address query function based on the attribute information of the function to be called, and update the function address corresponding to the function to be called based on the updated function address, further ensuring the subsequent implementation of calling the corresponding function based on the function address, thereby ensuring the stability of the function calling module. The specific implementation method is as follows.
[0080] The updating of the function address corresponding to the to-be-called function includes:
[0081] Determining attribute information of the function to be called;
[0082] In a case where it is determined based on the attribute information that the function to be called has a corresponding updated function address, the function address corresponding to the function to be called is replaced based on the updated function address corresponding to the function to be called.
[0083] Specifically, when the function calling module determines that the function providing module does not exist, it determines the attribute information of the function to be called, and based on the attribute information, determines through the address query function query that the function to be called has a corresponding updated function address, obtains the updated function address corresponding to the function to be called, and replaces the function address corresponding to the function to be called based on the updated function address, thereby completing the update of the function address.
[0084] In addition, when it is determined that the function to be called does not have a corresponding update function address, the function address can inform the function management object of the function update failure, and the specific implementation method is as follows.
[0085] The function calling method further includes:
[0086] If it is determined based on the attribute information that the function to be called does not have a corresponding update function address, generating a function update failure notification based on the attribute information of the function to be called;
[0087] Send the function update failure notification to the function management object.
[0088] Continuing with the above example, if module A fails to find module B, it means that module B has been removed or updated, and the new module address corresponding to the function will be searched again based on the function name and the function kallsyms_lookup_name. If module A fails to find the new function address, module A will exit with an error, and generate a function update failure notification based on the function name of function X, and send the function update failure notification to the function management object, so as to handle the function call failure based on the function management object, and ensure that the subsequent function call module can perform function calls smoothly.
[0089] Step 206: When the current state information satisfies a preset calling condition, the to-be-called function is called.
[0090] The preset calling condition can be set according to the actual application scenario, and this specification does not make specific settings for this. For example, the preset calling condition can be that the current state information indicates that the function to be called exists. In actual applications, when the current state information satisfies the preset calling condition, the function to be called is called. This can be understood as calling the function to be called when it is determined that the function to be called exists based on the current state information.
[0091] Furthermore, calling the function to be called can be understood as calling the function to execute the corresponding function, such as data calculation function, data search function, etc. In actual applications, in the process of calling the function to execute the corresponding function, the function calling module can obtain the corresponding result returned by the function to be called, such as the result generated by data calculation, the result of data search, etc.
[0092] In the embodiments provided herein, since the function called by the function-calling module is not explicitly exported, directly calling the function address will not be recorded in the module dependency list, resulting in no corresponding dependency relationship between the two modules. If the called module is removed during the calling process, the function-calling module will call an illegal address, causing a system crash. However, if a dependency relationship is forcibly added between modules, as in the inter-module calling method provided herein, the called module will be unable to perform necessary upgrades and maintenance. Therefore, before calling a function in the called module, the function-calling module increments the reference count of the called module's structure by 1. While the module's reference count is non-zero, the old module cannot be removed, thereby establishing a temporary dependency between the two modules and ensuring that the called module cannot be removed during the call. After calling the function in the called module using its address to execute the corresponding function and returning the corresponding result, the function-calling module decrements the reference count of the called function's module structure by 1, removing explicit protection (i.e., removing the temporary dependency). This ensures that any updates to the dependent module (the called module), such as new features or bug fixes, execute normally. It's important to note that the hot update operation for the called module requires replacing the old module with the new one. The following illustrates how the function-calling module increments the reference count of the called module's structure before calling the called module's function.
[0093] The calling of the to-be-called function comprises:
[0094] Determine an initial function call count corresponding to the function providing module, and set the function call count based on a preset counting rule to obtain a target function call count corresponding to the function providing module;
[0095] The to-be-called function is called based on the target function call count, and a function execution result returned by the to-be-called function is obtained.
[0096] The preset counting rule can be set according to the actual application scenario, and this specification does not make specific settings for this. For example, the initial function call count can be incremented by 1, the initial function call count can be incremented by 0.1, the initial function call count can be incremented by 10, etc. The following description assumes that the preset counting rule is to increment the initial function call count by 1.
[0097] The function call count can be understood as the reference count of the called function. Accordingly, the initial function call count can be the reference count before the function calling module performs the increment operation; accordingly, the target function call count is the reference count after the function calling module performs the increment operation.
[0098] The function execution result can be understood as the result returned by the called function in the process of calling the function to execute the corresponding function, for example, the result generated by data calculation, the result of data search, etc.
[0099] Continuing with the above example, before calling a function in module B, module A determines the reference count corresponding to module B (0) and, based on a preset counting rule, increments the reference count by 1, thereby obtaining an adjusted reference count (1) for module B. After incrementing the reference count by 1, the called module is guaranteed not to be removed during the call. Based on this, module A calls function X provided by module B to execute the corresponding function, thereby obtaining the execution result of function X.
[0100] Furthermore, the function calling module reduces the reference count of the module structure of the called function by 1, and the operation of releasing the display protection is as follows.
[0101] After obtaining the function execution result returned by the to-be-called function, the method further includes:
[0102] Determine a target function call count corresponding to the function providing module, and restore the target function call count to the initial function call count based on a preset restoration rule.
[0103] Among them, the preset recovery rule can be set according to the actual application scenario. This manual does not make specific settings for this. For example, when the preset counting rule is to increase the initial function call count by 1, the preset recovery rule is to decrement the initial function call count by 1. When the preset counting rule is to increase the initial function call count by 0.1, the preset recovery rule is to decrement the initial function call count by 0.1.
[0104] Continuing with the above example, after obtaining the execution result corresponding to function X, the module can reduce the reference count corresponding to module B by 1 based on the preset recovery rule, thereby obtaining the initial reference count corresponding to module B (0). By reducing the reference count of the module structure of the called function by 1, the display protection is released; during the actual execution of the function, a temporary dependency relationship is achieved between the calling module and the called module, and the called module can be removed or updated normally at other times. This avoids the strong coupling relationship between the function calling module and the function providing module caused by calling the exported function, and further avoids the problem of the function providing module being unable to perform update operations such as hot upgrades due to the dependency on the exported function.
[0105] In the function calling method provided in this specification, the function calling module proactively uses the attribute information of the function to be called to query the function address obtained from the function providing module, and then calls the function to be called based on this function address. This avoids the strong coupling relationship between the function calling module and the function providing module caused by calling the exported function, and further avoids the problem of the function providing module being unable to perform update operations such as hot upgrades due to the dependency of the exported function.
[0106] In the specific implementation process, the Linux operating system's called modules include two types: single-active called modules (the same module has only one in the system) and multi-active called modules (the same module has multiple in the system). The removal or update process of the single-active called module includes steps A1 to A5:
[0107] Step A1: The kernel performs module unloading operation;
[0108] Step A2: If the uninstallation fails, it means that the module function is being called by other modules. After a period of time, try to execute the above step A1 again.
[0109] Step A2: If the uninstallation is successful, the module can be removed successfully;
[0110] Step A3: The removal operation will automatically generate a module notification event to notify the calling module. After receiving the notification, if the calling module determines that there is no corresponding called module, the corresponding function address of the called module will be cleared;
[0111] Step A4: If an update is required, the kernel inserts the updated new module;
[0112] Step A5: The insert operation will automatically generate a module notification event to notify the calling module. After receiving the notification, the calling module updates the corresponding function address of the module.
[0113] The process of removing or updating the multi-active called module includes steps B1 to B7:
[0114] Step B1: The kernel inserts a new version of the multi-active module;
[0115] Step B2: The insert operation will automatically generate a module notification event to notify the calling module. After receiving the notification, the calling module will update the corresponding function address of the module.
[0116] Step B3: If necessary, remove the old version module from the multi-active module;
[0117] Step B4: The removal operation will automatically generate a module notification event, which will be handled accordingly in the calling module based on the version of the removed module.
[0118] Step B5: If the module being removed is the latest called module, the corresponding function address will be re-searched and updated to the address in the next latest version of the module;
[0119] Step B6: If the module being removed is not the latest one and there is any new version of the module being removed, the corresponding function address will not be updated;
[0120] Step B7: If it is the last called module to be removed, the corresponding function addresses in the calling module will be cleared;
[0121] The following combined Figure 3 , taking the application of the function calling method provided in this specification in the inter-module function calling scenario of the Linux operating system as an example, the function calling method is further explained. Figure 3 A flowchart of a processing process of a function calling method provided by an embodiment of this specification is shown, which specifically includes the following steps.
[0122] Step 302: The calling module needs to record the function name into a function address table configured in itself.
[0123] Step 304: The calling module queries the function address based on the function name and records it.
[0124] Specifically, during the process of calling function loading, the calling module searches for the function address corresponding to the called function based on the function name of each called function in the function address table through the function kallsyms_lookup_name, and records the function address in the function address table.
[0125] Step 306: The calling module executes the operation of calling the function when the called function has a corresponding function address.
[0126] Specifically, during the process of calling the corresponding function, the calling module executes the operation of calling the function if it is determined from the function address table that the called function has a corresponding function address.
[0127] In actual applications, when the calling module determines from the function address table that the called function does not have a corresponding function address, it exits with an error and informs the operation and maintenance management object of the operating system.
[0128] Step 308: When the calling module determines that the called module structure exists in the kernel, the calling module executes the operation of calling the function.
[0129] Specifically, considering that there is no explicit dependency between modules, in the function calling method provided in this specification, when the calling module calls the corresponding function address function, the called function may be removed; in order to ensure safe calling, it is necessary to reversely check the corresponding called module structure based on the previously obtained function address;
[0130] When the corresponding called module structure is found in the kernel, the reference count of the module structure is increased by 1 to ensure that the called module will not be removed during the calling process.
[0131] In actual applications, if the corresponding called module structure is not found from the kernel, it means that the called module has been removed or updated. The calling module then searches for the function address corresponding to the new module based on the function name and the function kallsyms_lookup_name. If it can be found, the function address is updated and the function call operation continues. Otherwise, it exits with an error and notifies the operation and maintenance management object of the operating system.
[0132] Step 310: The calling module calls the function in the called module through the function address to execute the corresponding function and obtain the result returned by the function.
[0133] Step 312: The calling module reduces the reference count of the module structure of the called function by 1 and releases the display protection.
[0134] In this way, there is a short-term dependency on the called module only during the actual execution of the function, and the called module can be removed or updated normally at other times;
[0135] In actual applications, the calling module also needs to register a module notification chain callback when calling function loading; so that when the module is updated, the function address in the corresponding function address table is updated in time.
[0136] The function calling method provided in this specification is a decoupled inter-module function calling method, which enables updating of the corresponding function address in the calling module when the called function is removed or updated, thereby avoiding the strong coupling relationship between the function calling module and the function providing module caused by calling the exported function, and further avoiding the problem of the function providing module being unable to perform update operations such as hot upgrades due to the dependence on the exported function.
[0137] Corresponding to the above method embodiment, this specification also provides a function calling device embodiment, Figure 4 FIG. 1 shows a schematic diagram of a structure of a function calling device provided by an embodiment of this specification. Figure 4 As shown, the device includes:
[0138] A first determining module 402 is configured to determine a function address corresponding to a to-be-called function, wherein the function address is an address obtained by querying a function providing module based on attribute information of the to-be-called function;
[0139] A second determining module 404 is configured to determine the current state information of the to-be-called function in the function providing module based on the function address;
[0140] The calling module 406 is configured to call the to-be-called function when the current state information satisfies a preset calling condition.
[0141] Optionally, the function calling device further includes a query module configured to:
[0142] Determine the function to be called from the information storage object;
[0143] Based on the attribute information of the function to be called, querying the function address corresponding to the function to be called from the function providing module through the address query function;
[0144] The function address corresponding to the to-be-called function is stored in the information storage object.
[0145] Optionally, the first determining module 402 is further configured to:
[0146] When a function call instruction for a function to be called is received and a function address corresponding to the function to be called exists, the function address corresponding to the function to be called is queried from an information storage object.
[0147] Optionally, the function calling device further includes a first sending module configured to:
[0148] When a function call instruction for a to-be-called function is received and a function address corresponding to the to-be-called function does not exist, generating a function call failure notification based on attribute information of the to-be-called function;
[0149] Send the function call failure notification to the function management object.
[0150] Alternatively, the function calling device may further include a monitoring module configured to:
[0151] Determine the function providing module corresponding to the function to be called, and attribute information of the function providing module;
[0152] a module status monitoring unit that generates a module status notification request based on attribute information of the module provided by the function, and sends the module status notification request;
[0153] Upon receiving a module status change notification sent by the module status monitoring unit, updating a function address corresponding to the to-be-called function based on the module status change notification;
[0154] The module status change notification is a notification generated by the module status monitoring unit based on the module status notification request when the module status of the function providing module changes.
[0155] Optionally, the second determining module 404 is further configured to:
[0156] Determine, based on the function address, current state information of a function providing module corresponding to the to-be-called function;
[0157] In a case where it is determined based on the current state information that the function providing module exists, the current state information of the to-be-called function in the function providing module is determined based on the function address.
[0158] Alternatively, the function calling device may further include an update module configured to:
[0159] When it is determined based on the current state information that the function providing module does not exist, the function address corresponding to the to-be-called function is updated.
[0160] Optionally, the update module is further configured to:
[0161] Determining attribute information of the function to be called;
[0162] In a case where it is determined based on the attribute information that the function to be called has a corresponding updated function address, the function address corresponding to the function to be called is replaced based on the updated function address corresponding to the function to be called.
[0163] Alternatively, the function calling device may further include a second sending module configured to:
[0164] If it is determined based on the attribute information that the function to be called does not have a corresponding update function address, generating a function update failure notification based on the attribute information of the function to be called;
[0165] Send the function update failure notification to the function management object.
[0166] Optionally, the calling module 404 is further configured to:
[0167] Determine an initial function call count corresponding to the function providing module, and set the function call count based on a preset counting rule to obtain a target function call count corresponding to the function providing module;
[0168] The to-be-called function is called based on the target function call count, and a function execution result returned by the to-be-called function is obtained.
[0169] Alternatively, the function calling device may further include a count recovery module configured to:
[0170] Determine a target function call count corresponding to the function providing module, and restore the target function call count to the initial function call count based on a preset restoration rule.
[0171] The function calling device provided herein uses the attribute information of the function to be called to obtain a function address from the function providing module, and then calls the function to be called based on the function address. This avoids the strong coupling between the function calling module and the function providing module caused by calling the exported function, and further avoids the problem of the function providing module being unable to perform update operations such as hot upgrades due to the dependency of the exported function.
[0172] The above is a schematic diagram of a function calling device according to this embodiment. It should be noted that the technical solution of the function calling device and the technical solution of the function calling method described above are based on the same concept. For details not described in detail in the technical solution of the function calling device, please refer to the description of the technical solution of the function calling method described above.
[0173] Figure 5 The block diagram of a computing device 500 according to one embodiment of the present disclosure is shown. Components of the computing device 500 include, but are not limited to, a memory 510 and a processor 520. The processor 520 is connected to the memory 510 via a bus 530, and a database 550 is used to store data.
[0174] The computing device 500 also includes an access device 540 that enables the computing device 500 to communicate via one or more networks 560. Examples of such networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of network interface (e.g., a network interface card (NIC)), whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0175] In one embodiment of the present specification, the above components of the computing device 500 and Figure 5 Other components not shown in the figure may also be connected to each other, for example, via a bus. Figure 5 The computing device structure block diagram shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art may add or replace other components as needed.
[0176] Computing device 500 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook computer, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. Computing device 500 can also be a mobile or stationary server.
[0177] The processor 520 is configured to execute the following computer-executable instructions, which, when executed by the processor 520 , implement the steps of the above-mentioned function calling method.
[0178] The above is a schematic solution of a computing device of this embodiment. It should be noted that the technical solution of the computing device and the technical solution of the function calling method described above are based on the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the function calling method described above.
[0179] An embodiment of the present specification further provides a computer-readable storage medium storing computer-executable instructions, which implement the steps of the above-mentioned function calling method when executed by a processor.
[0180] The above is a schematic solution of a computer-readable storage medium of this embodiment. It should be noted that the technical solution of this storage medium and the technical solution of the function calling method described above are based on the same concept. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the function calling method described above.
[0181] An embodiment of the present specification further provides a computer program, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the above-mentioned function calling method.
[0182] The above is an illustrative solution of a computer program of this embodiment. It should be noted that the technical solution of the computer program and the technical solution of the function calling method described above are based on the same concept. For details not described in detail in the technical solution of the computer program, please refer to the description of the technical solution of the function calling method described above.
[0183] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0184] The computer instructions include computer program code, which may be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0185] It should be noted that for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0186] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0187] The preferred embodiments disclosed above are intended only to help illustrate this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and variations can be made based on the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that those skilled in the art can better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.
Claims
1. A function calling method, applied to a function calling module, comprising: Determining a function address corresponding to a to-be-called function, wherein the function address is an address obtained from a function providing module based on attribute information of the to-be-called function, and the function address is updated based on current status information of the function providing module, and the current status information of the function providing module is monitored in real time via a callback of a module status monitoring unit; Determine current state information of the to-be-called function in the function providing module based on the function address; When the current state information meets a preset calling condition, the to-be-called function is called.
2. The function calling method according to claim 1, before determining the function address corresponding to the function to be called, further comprising: Determine the function to be called from the information storage object; Based on the attribute information of the function to be called, query the function address corresponding to the function to be called from the function providing module through the address query function; The function address corresponding to the to-be-called function is stored in the information storage object.
3. The function calling method according to claim 1, wherein determining the function address corresponding to the function to be called comprises: When a function call instruction for a function to be called is received and a function address corresponding to the function to be called exists, the function address corresponding to the function to be called is queried from an information storage object.
4. The function calling method according to claim 3, further comprising: When a function call instruction for a to-be-called function is received and a function address corresponding to the to-be-called function does not exist, generating a function call failure notification based on attribute information of the to-be-called function; Send the function call failure notification to the function management object.
5. The function calling method according to claim 1, further comprising: Determine the function providing module corresponding to the function to be called, and attribute information of the function providing module; a module status monitoring unit that generates a module status notification request based on attribute information of the module provided by the function, and sends the module status notification request; Upon receiving a module status change notification sent by the module status monitoring unit, updating a function address corresponding to the to-be-called function based on the module status change notification; The module status change notification is a notification generated by the module status monitoring unit based on the module status notification request when the module status of the function providing module changes.
6. The function calling method according to claim 1, wherein determining the current state information of the to-be-called function in the function providing module based on the function address comprises: Determine, based on the function address, current state information of a function providing module corresponding to the to-be-called function; In a case where it is determined based on the current state information that the function providing module exists, the current state information of the to-be-called function in the function providing module is determined based on the function address.
7. The function calling method according to claim 6, further comprising: When it is determined based on the current state information that the function providing module does not exist, the function address corresponding to the to-be-called function is updated.
8. The function calling method according to claim 7, wherein updating the function address corresponding to the to-be-called function comprises: Determining attribute information of the function to be called; In a case where it is determined based on the attribute information that the function to be called has a corresponding updated function address, the function address corresponding to the function to be called is replaced based on the updated function address corresponding to the function to be called.
9. The function calling method according to claim 8, further comprising: If it is determined based on the attribute information that the function to be called does not have a corresponding update function address, generating a function update failure notification based on the attribute information of the function to be called; Send the function update failure notification to the function management object.
10. The function calling method according to claim 1, wherein calling the to-be-called function comprises: Determine an initial function call count corresponding to the function providing module, and set the function call count based on a preset counting rule to obtain a target function call count corresponding to the function providing module; The to-be-called function is called based on the target function call count, and a function execution result returned by the to-be-called function is obtained.
11. The function calling method according to claim 10, further comprising: after obtaining the function execution result returned by the to-be-called function: Determine a target function call count corresponding to the function providing module, and restore the target function call count to the initial function call count based on a preset restoration rule.
12. A function calling device, applied to a function calling module, comprising: a first determining module configured to determine a function address corresponding to a to-be-called function, wherein the function address is an address obtained by querying a function providing module based on attribute information of the to-be-called function, and the function address is updated based on current state information of the function providing module, and the current state information of the function providing module is monitored in real time via a callback of a module state monitoring unit; a second determining module, configured to determine current state information of the to-be-called function in the function providing module based on the function address; The calling module is configured to call the to-be-called function when the current state information satisfies a preset calling condition.
13. A computing device comprising: memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the function calling method described in any one of claims 1 to 11 are implemented.
14. A computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, implement the steps of the function calling method according to any one of claims 1 to 11.
15. A computer program product, characterized in that The method comprises computer instructions, which, when executed by a processor, implement the steps of the function calling method according to any one of claims 1 to 11.