Interface call control method, device, storage medium and electronic device
By deploying interface calling tools between applications and interface libraries, and using resource monitoring programs to monitor system operating resources, the problem of low monitoring efficiency in the existing technology is solved, and efficient resource management and performance improvement are achieved.
Patent Information
- Application Number
- CN202411003253.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-25
AI Technical Summary
In the existing technology, the monitoring efficiency of system operating resources is low, which affects the performance and stability of the application and causes high maintenance costs.
Deploy the interface calling tool between the application program and the interface library, monitor the operation of system running resources through the resource monitoring program, and forward the calling request to the interface library to achieve efficient monitoring of system running resources.
Without modifying the application source code, the monitoring efficiency of system operating resources is improved, maintenance costs are reduced, and the performance and stability of the application are improved.
Smart Images

Figure CN118519860B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computers, and in particular, to a method, device, storage medium and electronic device for controlling interface calls. Background Art
[0002] Since the operation of the application and the data generated during the operation need to be processed and stored by the system operation resources, the management of system operation resources is crucial to the performance and stability of the application. At present, the usage information of the application calling the application interface to use the system operation resources is generally obtained through the hook function. However, this method will modify the source code of the application in order to insert the hook point. Modifying the source code will not only affect the security of the use of the application, but also bring additional maintenance costs, resulting in reduced efficiency in the application's monitoring of system operation resources.
[0003] In view of the problems in related technologies such as low efficiency in monitoring system operating resources, no effective solutions have been proposed yet. Summary of the invention
[0004] The embodiments of the present application provide a method, device, storage medium and electronic device for controlling an interface call, so as to at least solve the problem of low efficiency in monitoring system operation resources in the related art.
[0005] According to an embodiment of the present application, a method for controlling interface calls is provided. An operating system includes an application program, an interface library, and system operation resources. The application interface stored in the interface library is used to respond to the call of the application program to perform operations on the system operation resources. The method is applied to an interface call tool, which is deployed between the application program and the interface library. A resource monitoring program is stored in the interface call tool, and the resource monitoring program is used to monitor the operations performed on the system operation resources. The method includes:
[0006] Receiving a first call request initiated by the application, wherein the first call request is used to request to call an application interface in the interface library;
[0007] In response to the first call request, detecting the application interface requested to be called by the first call request, and obtaining a target application interface;
[0008] In the case that the target application interface is an application interface that allows calling the resource monitoring program, the resource monitoring program is run, and the first calling request is forwarded to the interface library.
[0009] In an exemplary embodiment, the detecting of the application interface requested by the first call request to obtain the target application interface includes: extracting the target interface identifier from the first call request; traversing an interface identifier library to search for the target interface identifier from the interface identifier library, wherein the interface identifier library is used to store interface identifiers of the application interfaces stored in the interface identifier library; and when the target interface identifier is found from the interface identifier library, determining the application interface corresponding to the target interface identifier as the target application interface.
[0010] In an exemplary embodiment, before running the resource monitoring program and forwarding the first call request to the interface library, the method also includes: searching for the target interface identifier from a target identifier set in the interface identifier library, wherein the target identifier set is added to the interface identifier library by the interface calling tool; and when the target interface identifier is found from the target identifier set, determining that the target application interface is an application interface that allows calling the resource monitoring program.
[0011] In an exemplary embodiment, running the resource monitoring program includes: calling the resource monitoring program to obtain target request information, wherein the target request information is used to describe the application that initiates the first call request, and the operation performed by the application on the system running resources by initiating the application interface in the interface library requested to be called by the first call request; storing the target request information in a target memory space, wherein the target memory space is a memory space allowed to be used by the interface calling tool.
[0012] In an exemplary embodiment, calling the resource monitoring program to obtain target request information includes: calling an address function through the resource monitoring program to obtain address information returned by the address function, wherein the address information is used to indicate the location of the application, and the target request information includes the address information; detecting a program state of the application according to the address information, wherein the program state is used to indicate whether the address information falls within a target range; and in the case of detecting that the program state indicates that the address information falls within the target range, calling a target function through the resource monitoring program to obtain the target request information returned by the target function.
[0013] In an exemplary embodiment, storing the target request information in the target memory space includes: calculating the target slot of the target request information in a hash table through a hash function, wherein the hash table is stored in the target memory space; and writing the target request information into the target slot.
[0014] In an exemplary embodiment, before forwarding the first call request to the interface library, the method further includes: detecting an interface status of the target application interface, wherein the interface status is used to indicate whether the system operating resources on which the target application interface is to perform an operation are memory resources; in a case where it is detected that the interface status is used to indicate that the system operating resources on which the target application interface is to perform an operation are memory resources, converting the first call request into a target call request; and sending the target call request to the interface library.
[0015] In an exemplary embodiment, converting the first call request into a target call request includes:
[0016] Detecting a request status of the first call request, wherein the request status is used to indicate a target operation to be performed on the memory resource by the target application interface called by the first call request, and the operation performed by the application interface on the memory resource includes a memory allocation operation, a memory release operation, and a memory access operation, wherein the memory allocation operation is used to allocate memory resources to the application, the memory release operation is used to release the memory resources of the application, and the memory access operation is used to access the memory resources of the application;
[0017] In a case where it is detected that the request state is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory allocation operation, converting the first call request into a second call request, wherein the first call request is used to request calling the target application interface to allocate a first amount of memory resources for the application program, the second call request is used to request calling the target application interface to allocate a second amount of memory resources for the application program, the first amount of resources is less than the second amount of resources, and the target call request includes the second call request;
[0018] In the case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, the first call request is converted into a third call request, wherein the first call request is used to request to call the target application interface to release a third amount of memory resources for the application, and the third call request is used to request to call the target application interface to release a fourth amount of memory resources for the application, and the resource status of the resource difference between the memory resources of the third amount of memory resources and the memory resources of the fourth amount of memory resources is detected, the resource difference being the memory resources additionally allocated when the memory resources of the third amount of memory resources are allocated to the application, and the resource status is used to indicate whether the memory resources corresponding to the resource difference are modified, the third amount of resources is less than the fourth amount of resources, and the target call request includes the third call request;
[0019] In a case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface called by the first call request is the memory access operation, the first call request is determined as the target call request.
[0020] In an exemplary embodiment, converting the first call request into a second call request includes: searching for an initial resource parameter from the first call request, wherein the initial resource parameter is used to indicate the memory resource of the first resource amount to be allocated to the application; modifying the initial resource parameter in the first call request to a target resource parameter to obtain the second call request, wherein the target resource parameter is used to indicate the memory resource of the second resource amount to be allocated to the application.
[0021] In an exemplary embodiment, the modification of the initial resource parameter in the first call request to the target resource parameter to obtain the second call request includes at least one of the following: increasing the target length of the initial resource parameter to obtain the target resource parameter, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target length; increasing the target memory page of the initial resource parameter to obtain a reference resource parameter; adding the access permission parameter of the target memory page to the reference resource parameter, and configuring the access permission parameter to read-only mode to obtain the target resource parameter, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target memory page.
[0022] In an exemplary embodiment, after forwarding the first call request to the interface library, the method further includes: when detecting that a memory access operation exists on the target memory page, obtaining request information of an access request for accessing the target memory page through a hijacking signal; and outputting request information of the access request for accessing the target memory page.
[0023] In an exemplary embodiment, after forwarding the first call request to the interface library, the method further includes: when it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, the interface library responds to the third call request, calls the target application interface to release the fourth amount of memory resources for the application, and detects the resource status of the resource difference; receives the resource status returned by the interface library; and when the resource status is used to indicate that the memory resource corresponding to the resource difference is modified, outputs request information for modifying the memory resource corresponding to the resource difference.
[0024] In an exemplary embodiment, before running the resource monitoring program, the method further includes: running a loading function, and deploying the interface calling tool between the application and the interface library through the loading function, wherein the loading function includes void __attribute__((constructor)) _init(void);
[0025] After running the resource monitoring program, the method further includes: running an initialization function, and restoring the connection between the application and the interface library through the initialization function, wherein the initialization function includes void__attribute__((destructor)) _fini(void).
[0026] According to another embodiment of the present application, a control device for interface calling is provided, wherein an operating system includes an application program, an interface library, and system operation resources, wherein the application interface stored in the interface library is used to perform operations on the system operation resources in response to a call of the application program, wherein the device is applied to an interface calling tool, wherein the interface calling tool is deployed between the application program and the interface library, wherein a resource monitoring program is stored in the interface calling tool, wherein the resource monitoring program is used to monitor operations performed on the system operation resources, wherein the device includes:
[0027] A receiving module, configured to receive a first call request initiated by the application program, wherein the first call request is used to request to call an application interface in the interface library;
[0028] A first detection module, configured to respond to the first call request, detect the application interface requested to be called by the first call request, and obtain a target application interface;
[0029] The first processing module is used to run the resource monitoring program and forward the first calling request to the interface library when the target application interface is an application interface that allows calling the resource monitoring program.
[0030] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0031] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0032] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0033] Through this application, a first call request initiated by an application is received, wherein the first call request is used to request to call an application interface in an interface library; in response to the first call request, the application interface requested to be called by the first call request is detected to obtain a target application interface; in the case where the target application interface is an application interface that allows calling a resource monitoring program, the resource monitoring program is run, and the first call request is forwarded to the interface library. That is to say, an interface call tool is deployed between the application and the interface library, and the interface call tool is first used to respond to the first call request initiated by the application, and the calling process of the resource monitoring program is executed, and the resource monitoring program completes the monitoring of the operations performed on the system operation resources, and then the first call request is forwarded to the interface library, and the application interface stored in the interface library responds to the first call request to perform operations on the system operation resources. Through the interface call tool, the operations performed on the system operation resources are monitored without modifying the source code of the application, so the problem of low monitoring efficiency of the system operation resources can be solved, and the effect of improving the monitoring efficiency of the system operation resources is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a hardware structure block diagram of a server device of an interface call control method according to an embodiment of the present application;
[0035] Figure 2 is a flow chart of a control method for interface calling according to an embodiment of the present application;
[0036] Figure 3 is a schematic diagram of an interface identification library and an interface library according to an embodiment of the present application;
[0037] Figure 4 is a schematic diagram of a hash table according to an embodiment of the present application;
[0038] Figure 5 is a schematic diagram of a target resource parameter according to an embodiment of the present application;
[0039] Figure 6 is a schematic diagram of a working process of an operating system according to an embodiment of the present application;
[0040] Figure 7 is a schematic diagram of a working process of an interface calling tool according to an embodiment of the present application;
[0041] Figure 8 is a structural block diagram of a control device for interface calling according to an embodiment of the present application;
[0042] Fig. 9 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0043] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0044] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0045] The method embodiments provided in the embodiments of the present application can be executed in a server device or a similar computing device. Taking running on a server device as an example, Figure 1 1 is a hardware structure block diagram of a server device of an interface call control method according to an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned server device may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0046] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the control method called by the interface in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0047] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0048] In this embodiment, a method for controlling interface calls is provided. An operating system includes an application program, an interface library, and system operation resources. The application interface stored in the interface library is used to respond to the call of the application program to perform operations on the system operation resources. The method is applied to an interface call tool, which is deployed between the application program and the interface library. A resource monitoring program is stored in the interface call tool, and the resource monitoring program is used to monitor the operations performed on the system operation resources. Figure 2 is a flow chart of a control method for interface calling according to an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps:
[0049] Step S202, receiving a first call request initiated by the application, wherein the first call request is used to request to call an application interface in the interface library;
[0050] Step S204, responding to the first call request, detecting the application interface requested to be called by the first call request, and obtaining a target application interface;
[0051] Step S206: When the target application interface is an application interface that allows calling the resource monitoring program, run the resource monitoring program and forward the first calling request to the interface library.
[0052] Through the above steps, a first call request initiated by an application is received, wherein the first call request is used to request to call an application interface in an interface library; the first call request is responded to, the application interface requested to be called by the first call request is detected, and a target application interface is obtained; when the target application interface is an application interface that allows calling a resource monitoring program, the resource monitoring program is run, and the first call request is forwarded to the interface library. That is to say, an interface call tool is deployed between the application and the interface library, and the interface call tool is first used to respond to the first call request initiated by the application, and the calling process of the resource monitoring program is executed, and the resource monitoring program completes the monitoring of the operations executed on the system operation resources, and then the first call request is forwarded to the interface library, and the application interface stored in the interface library responds to the first call request to execute the operations on the system operation resources. Through the interface call tool, the operations executed on the system operation resources are monitored without modifying the source code of the application, so the problem of low monitoring efficiency of the system operation resources can be solved, and the effect of improving the monitoring efficiency of the system operation resources is achieved.
[0053] Optionally, in this embodiment, the operating system provides a basic platform for the application to run, and provides an abstract layer for the system running resources, so that the application can access and manage the system running resources through the application interface. The system running resources may include, but are not limited to: storage resources, processing resources, I / O (Input / Output) resources, etc.
[0054] Optionally, in this embodiment, the application program invokes an application interface in the interface library by initiating a call request to the interface library, and the interface library invokes the corresponding application interface by receiving and responding to the call request initiated by the application program.
[0055] Optionally, in this embodiment, the above-mentioned interface library can be but is not limited to being used to store application interfaces, and the operations that the application is allowed to perform on the system operating resources through the application interface can include but are not limited to: when the system operating resources are storage resources, the application performs allocation operations and release operations on the storage resources through the memory management interface in the application interface; when the system operating resources are processing resources, the application performs calling operations on the processing resources through the calling interface in the application interface, etc.
[0056] Optionally, in this embodiment, the interface calling tool is a tool that allows obtaining and responding to call requests initiated by the application to which it is connected. It can obtain call requests in a variety of ways, but is not limited to: the interface calling tool actively intercepts call requests initiated by the application; or, the application is configured to send call requests to the interface library through the interface calling tool; or, the interface calling tool is configured to give priority to responding to call requests initiated by the application, etc.
[0057] Optionally, in this embodiment, the interface calling tool monitors the operations executed by the system operating resources through the resource monitoring program. For example, the interface calling tool obtains and stores information about the operations executed by the system operating resources through the resource monitoring program, and the interface calling tool verifies the operations executed by the system operating resources through the resource monitoring program.
[0058] In the technical solution provided in the above step S202, the above first call request may be, but is not limited to, automatically generated by the application in various situations, such as: the application's regular self-check of system operating resources, the application's checking of relevant information of system operating resources, the user's issuance of instructions to the application, and the application's response to the user's instructions, etc. Alternatively, the first call request may also be generated in other ways and then sent to the application, and then initiated by the application.
[0059] Optionally, in this embodiment, the interface library may, but is not limited to, respond to calling the corresponding application interface in the above-mentioned first calling request. The first calling request may, but is not limited to, carry information that allows the interface library to identify, such as: interface identifier, interface name, etc., which are used to identify the application interface to be called.
[0060] Optionally, in this embodiment, the interface calling tool is deployed between the application and the interface library, so that the interface calling tool can receive the first calling request initiated by the application before the interface library. For the application, it can, but is not limited to, allow the first calling request to be transmitted in the order of connection, that is, from the application to the interface calling tool to the interface library.
[0061] In the technical solution provided in the above step S204, the above interface calling tool may be, but is not limited to, another interface library storing the resource monitoring program, for example: the interface calling tool detects and obtains the target application interface according to the first calling request in accordance with the working mode of the interface library. Alternatively, the interface calling tool may also be a functional module that deploys the resource monitoring program and has the function of detecting the target application interface requested to be called according to the first calling request, for example: the interface calling tool inputs the first calling request into the corresponding function to obtain the target application interface.
[0062] In an exemplary embodiment, the application interface requested to be called by the first call request can be detected in the following manner but is not limited to: extracting the target interface identifier from the first call request; traversing an interface identifier library to search for the target interface identifier from the interface identifier library, wherein the interface identifier library is used to store interface identifiers of application interfaces stored in the interface library; when the target interface identifier is found from the interface identifier library, determining the application interface corresponding to the target interface identifier as the target application interface.
[0063] Optionally, in this embodiment, information such as an interface name for identifying the application interface to be called can be carried in the call request as an interface identifier but is not limited thereto. The interface call tool uses the interface identifier extracted from the first call request as the target interface identifier.
[0064] Optionally, in this embodiment, the interface identification library is a library for storing interface identifications corresponding to application interfaces, and the corresponding relationship between interface identifications and application interfaces. The above-mentioned application interfaces may include, but are not limited to, application interfaces in the interface library connected to the interface calling tool. The interface identification library may be constructed in the following manners, but are not limited to:
[0065] Method 1: Obtain the interface identifiers of the application interfaces in the interface library connected to the interface calling tool and the interface identifiers of other application interfaces that the application program is allowed to call, and build an interface identifier library based on the correspondence between the application interfaces and the interface identifiers of the application interfaces. It should be noted that the interface identifier library constructed by method 1 can be directly deployed in the interface calling tool, but is not limited to it, and can also realize information interaction between the interface calling tool and the interface identifier library by building a connection between the two.
[0066] Method 2: Determine the corresponding relationship between the application interface stored in the interface library and the interface identifier of the application interface as the interface identifier library. It should be noted that the interface identifier library obtained by method 2 is stored in the interface library, and the application can interact with the interface identifier library to achieve information interaction with the interface identifier library.
[0067] Method 3: Obtain the interface identifier of the application interface stored in the interface library, and generate the interface identifier library according to the interface identifier. It should be noted that when the interface identifier library constructed by method 3 finds the target interface identifier, it needs to interact with the interface library to realize the search of the target application interface.
[0068] Method 4: Obtain the interface identifier of the application interface stored in the interface library, and use the interface identifier as the identifier of the resource monitoring program. It should be noted that when the interface identifier library constructed by method 4 finds the target interface identifier, it can choose to continue to interact with the interface library to realize the search of the target application interface, or it can directly determine that the target application interface is obtained, and the target application interface is an application interface that allows calling the resource monitoring program.
[0069] In the technical solution provided in the above step S206, when the interface calling tool detects the application interface requested by the first calling request and obtains the target application interface, it can, but is not limited to, detect whether the target application interface is an application interface that allows calling the resource monitoring program. When the target application interface is an application interface that allows calling the resource monitoring program, the resource monitoring program is run and the first calling request is forwarded to the interface library; or, when the target application interface is an application interface that does not allow calling the resource monitoring program, the first calling request is directly forwarded to the interface library.
[0070] In an exemplary embodiment, before running the resource monitoring program and forwarding the first call request to the interface library, it is possible but not limited to the following method to detect whether the target application interface is an application interface that allows calling the resource monitoring program: searching for the target interface identifier from a target identifier set in the interface identifier library, wherein the target identifier set is added to the interface identifier library by the interface calling tool; and when the target interface identifier is found from the target identifier set, determining that the target application interface is an application interface that allows calling the resource monitoring program.
[0071] Optionally, in this embodiment, the target identifier set may include, but is not limited to, an interface identifier corresponding to an application interface that allows calling a resource monitoring program. The interface calling tool adds the target identifier set to the above target identifier set during initialization and deployment in the operating system.
[0072] Optionally, in this embodiment, Figure 3 is a schematic diagram of an interface identification library and an interface library according to an embodiment of the present application, such as Figure 3 As shown, taking the application interface A stored in the interface library as an example, the function name of the application interface A is obtained, and the function name of the application interface A is used to construct an application interface B with the same function name for calling the resource monitoring program in the interface identification library.
[0073] Further, when the target interface identifier "malloc (dynamic memory allocation)" is extracted from the first call request, application interface B with the same target interface identifier "malloc" is found from the interface identifier library, and application interface B is an application interface for calling the resource monitoring program. Therefore, application interface B is determined to be an application interface that allows calling the resource monitoring program.
[0074] It should be noted that the function of the application interface B found by the interface calling tool from the interface identification library is to run the resource monitoring program, and the application interface that actually responds to the first calling request is the application interface A in the interface library. Therefore, for the interface calling tool, it detects the application interface requested to be called by the first calling request, and the target application interface obtained is application interface B, and the first calling request is forwarded to the interface library, and the target application interface actually called by the interface library is application interface A. By encapsulating and replacing application interface A to generate application interface B, the application program can first call application interface B to perform the monitoring process of the operation when initiating the first calling request, without modifying application interface A and the operating logic of the application program, and the interface calling tool can be more easily integrated into the existing system without complicated adaptation of the existing code.
[0075] In an exemplary embodiment, the resource monitoring program can be run in the following manner but is not limited to: calling the resource monitoring program to obtain target request information, wherein the target request information is used to describe the application that initiates the first call request, and the operation performed by the application on the system running resources by initiating the application interface in the interface library requested to be called by the first call request; storing the target request information in a target memory space, wherein the target memory space is a memory space allowed to be used by the interface calling tool.
[0076] Optionally, in this embodiment, the target memory space may be, but is not limited to, a storage space allocated to the interface calling tool when the interface calling tool is deployed in the operating system.
[0077] Optionally, in this embodiment, the target request information obtained by the resource monitoring program includes program information of the application that initiates the first call request and operation information of the application requesting to be performed on the system operation resources through the called application interface. The program information of the above application may include, but is not limited to: address information of the application, resource occupancy information of the application, process information, etc. The above operation information may include, but is not limited to: allocation of storage resources, release of storage resources, release of processing resources, allocation of processing resources, etc.
[0078] In an exemplary embodiment, the resource monitoring program may be called to obtain target request information in the following manner, but is not limited to: the resource monitoring program calls an address function to obtain address information returned by the address function, wherein the address information is used to indicate the location of the application, and the target request information includes the address information; the program state of the application is detected based on the address information, wherein the program state is used to indicate whether the address information falls within a target range; and when it is detected that the program state indicates that the address information falls within the target range, the resource monitoring program calls a target function to obtain the target request information returned by the target function.
[0079] Optionally, in this embodiment, the above target range is used to indicate the address range of the application program that requests to perform operations on the system running resources. Taking the system running resources as memory resources in the storage resources as an example, since it is not only necessary to perform memory resource adjustment operations (such as allocation, release, access, etc.) for the application program, but also possible to receive memory resource adjustment requests from the interface library and the interface calling tool, it is necessary to determine whether the first call request currently received is from the application program according to the target range, and only monitor the first call request from the application program, for example: the resource monitoring program calls the address function (__builtin_return_address()) to obtain the address information of the application program returned by the address function, and judges whether the address indicated by the address information falls into the target range. If yes, the target request information is obtained and stored; if not, only the target request information is obtained and output. It should be noted that in the case where it is necessary to monitor other programs such as the interface calling tool and the interface library, the corresponding monitoring work can be achieved by adjusting the target range.
[0080] Optionally, in this embodiment, taking the system running resources as memory resources in storage resources as an example, multiple target functions can be called but are not limited to respectively obtaining corresponding target request information, such as: using the function __builtin_return_address() to obtain the address information of the application, reading the parameter size_t size = t in the first call request to obtain the amount of memory resources t requested by the application, using the function time() to obtain the timestamp of the current time, using the function pthread_self() to obtain the identifier of the current thread, etc.
[0081] In an exemplary embodiment, the target request information can be stored in the target memory space in the following manner but is not limited to: calculating the target slot of the target request information in a hash table through a hash function, wherein the hash table is stored in the target memory space; and writing the target request information into the target slot.
[0082] Optionally, in this embodiment, during the initialization of the interface calling tool, a data structure may be designed to store detailed information of subsequent target request information, for example, creating a structure to accommodate each relevant field in the target request information.
[0083] Optionally, in this embodiment, a hash function can be selected based on the key information of the record, such as using the address of a memory block as the key of the hash table. Create and initialize a hash table, which is usually implemented by an array or a linked list array, and each element stores a linked list to resolve hash conflicts. When the target request information is obtained, create a record, use a hash function to determine where the record should be stored in the hash table, and insert it into the hash table. Hash conflicts can be handled using, but are not limited to, a chain address resolution strategy, that is, a linked list is maintained in each slot of the hash table, and all records hashed to the slot are stored in this linked list. When a record needs to be retrieved, the same hash function is used to calculate the index of the key, and a matching record is searched in the corresponding linked list.
[0084] In an exemplary embodiment, an example of a hash table is provided. Figure 4 is a schematic diagram of a hash table according to an embodiment of the present application, such as Figure 4 As shown, taking the memory resources in the storage resources as the system running resources as an example, the memory resource adjustment operations performed by the application may include but are not limited to memory allocation, memory release, memory access, etc. In the process of initializing the interface calling tool, hash table 1 for storing target request information and hash table 2 for statistics are constructed respectively. Hash table 1 is stored in the application record node space, and hash table 2 is stored in the statistical node space.
[0085] Hash table 1 uses the memory address as an index to record target request information; hash table 2 uses the thread that triggers the application interface as an index to record information about each thread.
[0086] Since the target request information involves a large amount of data, ordinary storage methods are extremely unfriendly to information retrieval, so a HASH array plus a linked list is used for storage. The hash value is calculated based on the passed parameters, and the calculated value is used as the array subscript to achieve fast data search.
[0087] In an exemplary embodiment, before forwarding the first call request to the interface library, the first call request can be processed in the following manner but is not limited to: detecting the interface status of the target application interface, wherein the interface status is used to indicate whether the system operating resources to be operated by the target application interface are memory resources; in the case where it is detected that the interface status is used to indicate that the system operating resources to be operated by the target application interface are memory resources, converting the first call request into a target call request; and sending the target call request to the interface library.
[0088] Optionally, in this embodiment, it is possible but not limited to determining from the target application interface requested to be called by the first call request whether the system operating resources for the operation to be executed by the target application interface are memory resources. For example, when the target application interface is malloc, new or other interfaces, it is determined that the system operating resources for the operation to be executed by the target application interface are memory resources.
[0089] Optionally, in this embodiment, since the application is allowed to initiate a call request for the application interface for performing operations on different system running resources, the first call request can be identified before being forwarded to the interface library, and when the application requests to perform an operation on memory resources, the first call request can be converted into a target call request, and the operation on the memory resources is performed using the target call interface, and memory out-of-bounds detection and memory trampling location process of the memory resources are implemented.
[0090] In an exemplary embodiment, the first call request may be converted to a target call request in the following manner, but is not limited to: detecting a request status of the first call request, wherein the request status is used to indicate a target operation to be performed on the memory resource by the target application interface requested to be called by the first call request, and the operations performed by the application interface on the memory resource include a memory allocation operation, a memory release operation, and a memory access operation, wherein the memory allocation operation is used to allocate memory resources to the application, the memory release operation is used to release the memory resources of the application, and the memory access operation is used to access the memory resources of the application; in the case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory allocation operation, converting the first call request to a second call request, wherein the first call request is used to request calling the target application interface to allocate a first amount of memory resources to the application, and the second call request is used to request calling the target application interface to allocate a second amount of memory resources to the application, the first amount of resources is less than the second amount of resources, and the target call request packet The target call request includes the second call request; in the case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, the first call request is converted into a third call request, wherein the first call request is used to request to call the target application interface to release the memory resource of a third resource amount for the application program, the third call request is used to request to call the target application interface to release the memory resource of a fourth resource amount for the application program, and the resource status of the resource difference between the memory resource of the third resource amount and the memory resource of the fourth resource amount is detected, the resource difference is the memory resource additionally allocated when the memory resource of the third resource amount is allocated to the application program, the resource status is used to indicate whether the memory resource corresponding to the resource difference is modified, the third resource amount is less than the fourth resource amount, and the target call request includes the third call request; in the case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory access operation, the first call request is determined as the target call request.
[0091] Optionally, in this embodiment, the target operation to be performed by the target application interface on the memory resource can be determined from the target application interface requested to be called by the first call request, but is not limited to: when the target application interface is malloc, the target operation is determined to be a memory allocation operation; when the target application interface is new (dynamic memory allocation), the target operation is determined to be a memory allocation operation; when the target application interface is free (release), the target operation is determined to be a memory release operation; when the target application interface is free, the target operation is determined to be a memory release operation, etc. It should be noted that multiple target application interfaces can indicate the same target operation.
[0092] Optionally, in this embodiment, when it is detected that the request status is used to indicate that the target operation to be performed on the memory resources by the target application interface requested to be called by the first call request is a memory allocation operation, the first call request is converted into a second call request to apply for an additional portion of memory space for the application, and subsequent memory out-of-bounds detection and memory trampling detection are implemented through this additional portion of memory space.
[0093] Optionally, in this embodiment, when it is detected that the request status is used to indicate that the target operation to be performed on the memory resources by the target application interface requested to be called by the first call request is a memory release operation, the first call request is converted into a third call request to implement a verification process for the over-allocated memory space when the target operation is a memory allocation operation, thereby performing memory out-of-bounds detection.
[0094] In an exemplary embodiment, the first call request can be converted into the second call request in the following manner, but is not limited to: searching for initial resource parameters from the first call request, wherein the initial resource parameters are used to indicate the memory resources of the first resource amount to be allocated to the application; modifying the initial resource parameters in the first call request to target resource parameters to obtain the second call request, wherein the target resource parameters are used to indicate the memory resources of the second resource amount to be allocated to the application.
[0095] Optionally, in this embodiment, the first call request may, but is not limited to, carry an initial resource parameter for indicating a first resource amount of memory resources requested to be allocated by the application, and the initial resource parameter is expanded and modified to a target resource parameter to allocate an additional portion of memory resources to the application in the interface library.
[0096] In an exemplary embodiment, the initial resource parameter in the first call request can be modified to a target resource parameter to obtain the second call request in at least one of the following ways, but is not limited to: increasing the target length of the initial resource parameter to obtain the target resource parameter, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target length; increasing the target memory page of the initial resource parameter to obtain a reference resource parameter; adding the access permission parameter of the target memory page to the reference resource parameter, and configuring the access permission parameter to read-only mode to obtain the target resource parameter, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target memory page.
[0097] Optionally, in this embodiment, the target length is an integer unit of the memory block allocated to the application, for example: taking 4k as a memory block, 4k is used as a target length, 8k is used as a target length, and so on.
[0098] Optionally, in this embodiment, the target memory page is an integer unit of the memory page, for example, taking 4k as a memory page as an example, the target memory page can be but not limited to 4k, 8k, etc. It is worth noting that when allocating memory resources of the target memory page to the application, it is necessary to maintain the byte alignment principle to make the memory size applied by the target process adjacent to the target memory page, that is, no gap is allowed between the target memory page and the original memory resources of the application.
[0099] Optionally, in this embodiment, the second resource amount can be determined based on, but not limited to, the actual usage scenario of the application, such as: increasing the initial resource parameter by a target length, increasing the initial resource parameter by a target memory page, increasing the initial resource parameter by a target length and a target memory page.
[0100] In an exemplary embodiment, after forwarding the first call request to the interface library, memory trampling can be located in the following manner but is not limited to: when a memory access operation is detected on the target memory page, request information of the access request for accessing the target memory page is obtained by hijacking a signal; and request information of the access request for accessing the target memory page is output.
[0101] Optionally, in this embodiment, memory trampling is a memory access error, which usually causes the program to crash or undefined behavior, such as SIGEGV (signal 11) (segment fault). However, the calling relationship of the stack address printed by the monitoring tool in the current related art when the kernel crashes is not necessarily the initiator of the memory trampling. Most of the time, the memory is trampled somewhere during the operation of the target process, resulting in memory data being tampered with. When the normal business logic uses this tampered memory resource, a crash occurs (that is, the monitoring tool in the current related art can only realize the business information of the current attempt to use this tampered memory resource, and cannot obtain the relevant business information of the initiator of the memory trampling).
[0102] In the control method of interface call proposed in the present application, the reference resource parameter is obtained by adding the target memory page to the initial resource parameter, and the access permission parameter of the target memory page is set to read-only mode. That is to say, the target resource amount actually obtained by the application = the first resource amount + the target memory page, and the target memory page is set to read-only mode through mprotect (memory protect), and the memory resources applied for by the target process and the target memory page are adjacent through the byte alignment principle.
[0103] When a non-current application writes to the memory resources of the current application (memory trampling occurs), the application will detect that the target memory page triggers a segmentation fault and trigger a call request to the interface calling tool. The resource monitoring program in the interface calling tool calls the corresponding interface function through the application interface to obtain the corresponding target request information, thereby reproducing the segmentation fault scenario and locating the initiator.
[0104] In an exemplary embodiment, after forwarding the first call request to the interface library, memory out-of-bounds detection can be performed in the following manner but is not limited to: when it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, the interface library responds to the third call request, calls the target application interface to release the fourth amount of memory resources for the application, and detects the resource status of the resource difference; receives the resource status returned by the interface library; and when the resource status is used to indicate that the memory resource corresponding to the resource difference is modified, outputs request information for modifying the memory resource corresponding to the resource difference.
[0105] Optionally, in this embodiment, since a target length (which may be but is not limited to a fixed length of four bytes) is added to the initial resource parameters in the process of allocating memory resources to the application, in the process of releasing the third amount of resources, it is necessary to increase the amount of resources by the resource difference (i.e., the above-mentioned target length), i.e., release the fourth amount of resources which is the sum of the third amount of resources and the resource difference.
[0106] Optionally, in this embodiment, it is possible but not limited to detecting whether the resource difference is modified during the process of releasing the fourth amount of resources to determine whether additional data writing has occurred in the application, that is, a memory out-of-bounds situation. For example, when the target process calls the interface to apply for resources, a fixed length of four bytes is appended as the target length, and fixed data is written to these four bytes. During the process of releasing the memory resources, it is checked whether the last four bytes of the released resource address are pre-written fixed data. If the fixed data is changed, it is considered that the memory has been used beyond the last byte of the applied memory, that is, a memory out-of-bounds situation has occurred; if the fixed data is not changed, it is considered that the memory has not been used beyond the last byte of the applied memory, that is, a memory out-of-bounds situation has not occurred.
[0107] At present, errors and leakage events of system operating resources are generally detected by simulating the operating environment of the application. However, simulating the operating environment of the application has a large performance overhead on the operating system and is not suitable for application in all environments. The control method of interface call proposed in this application can effectively detect the situation of memory out-of-bounds use by appending specific length and fixed data value when allocating memory, and report it in time. Through special memory application functions and page protection mechanisms, the source of the problem can be quickly located when memory trampling occurs, without the need for a large amount of additional calculations when the application is running. The interface call tool can count memory usage in real time and quickly locate common problems such as memory leaks, secondary memory release, memory overflow, and memory out-of-bounds.
[0108] In an exemplary embodiment, an example of a target resource parameter is provided. Figure 5 is a schematic diagram of a target resource parameter according to an embodiment of the present application, such as Figure 5 As shown, in the case where the first call request is used to request to call the target application interface "malloc" to allocate memory resources for the application, the initial resource parameter (size) is extracted from the first call request. In order to detect memory out-of-bounds, the initial resource parameter is increased by the target length, and fixed data (MAGIC) is written to the target length. In order to locate the memory trampling, the initial resource parameter is increased by 2*page of the target memory page, and the memory data of the application is aligned with the target memory page 4k.
[0109] In an exemplary embodiment, before the resource monitoring program is run, the interface calling tool may be initialized in the following manner, but not limited to: running a loading function, deploying the interface calling tool between the application and the interface library through the loading function, wherein the loading function includes void __attribute__((constructor)) _init(void); after the resource monitoring program is run, the operating system may be initialized in the following manner, but not limited to: running an initialization function, restoring the connection between the application and the interface library through the initialization function, wherein the initialization function includes void __attribute__((destructor)) _fini(void).
[0110] Optionally, in this embodiment, the __attribute__((constructor)) and __attribute__((destructor)) function attributes can be used, but are not limited to, to output its constructor and destructor. The constructor will be called before dlopen() returns or when the library is loaded, and the destructor will be called in the following situations: before dlclose() returns, or after main() returns, or when exit() is called during the library loading process, for example: the interface calling tool is deployed between the application and the interface library by loading the function void __attribute__((constructor)) _init(void); the connection between the application and the interface library is restored by initializing the function void __attribute__((destructor)) _fini(void).
[0111] Optionally, in this embodiment, the operating system (OS) is an important part of the computer system, and it plays the role of an interface between the resource manager and the software and hardware. In software development, the operating system provides an operating environment and services for the application, so that the application can run concurrently and efficiently, and realize various operations and interactions. The core features of the operating system mainly include: process management, memory management, file system management, network communication, security and protection, etc. Among them, memory management is an important function in the operating system, which is responsible for managing the memory resources in the computer system, including memory allocation, recycling and protection. Memory management is crucial to the performance and stability of the application. After all, the operation of the program and the data generated during the operation need to be stored in the memory. The introduction of MMU (Memory Management Unit) makes virtual memory one of the important inventions of the operating system, which provides a consistent, private, and continuous address space for each process. It can make application developers not worry too much about insufficient memory when the main memory space is limited. At the same time, it also simplifies memory management and protects the process address from being destroyed by other processes. However, things always have two sides. In the actual development and application of introducing virtual memory management, there are problems such as memory leaks and memory overflows. In order to solve the above problems, the present application proposes a control method for interface calling. Due to the existence of the interface calling tool, not only the operations executed on the memory resources are monitored, but also the problems of memory leak, memory overflow, etc. are monitored.
[0112] In one exemplary embodiment, an example of an operating system is provided. Figure 6 is a schematic diagram of the working process of an operating system according to an embodiment of the present application, such as Figure 6 As shown, the operating system includes an application program, an interface calling tool and an interface library which are connected in sequence, wherein the interface library includes a malloc interface and a free interface.
[0113] Generate the interface identification library in the interface calling tool according to the malloc interface and free interface in the interface library. For example, obtain the interface identification "malloc" of the malloc interface, and define the interface identification "malloc" in the interface identification library to be used to call the application interface "rp_malloc" of the resource monitoring program. In other words, the application interface "rp_malloc" with the calling function of the resource monitoring program is obtained by macro replacement of the malloc interface in the interface library, and the application interface "rp_malloc" is deployed in the interface identification library.
[0114] Similarly, obtain the interface identifier "free" of the free interface, and define the interface identifier "free" in the interface identifier library to be used to call the application interface "wrap_free" of the resource monitoring program. In other words, by performing macro replacement on the free interface in the interface library, the application interface "wrap_free" with the calling function of the resource monitoring program is obtained, and the application interface "wrap_free" is deployed in the interface identifier library.
[0115] For the application interface in the interface identification library, on the one hand, it is used to call the resource monitoring program to complete the monitoring of the target request information, and on the other hand, it can also be used, but not limited to, to complete the conversion from the first call request to the target call request. For example: the first call request is converted to the second call request through the application interface "rp_malloc", and the first call request is converted to the third call request through the application interface "wrap_free".
[0116] Optionally, in this embodiment, in order to better understand the working process of the above-mentioned interface calling tool in the interface calling control method proposed in this application, the above-mentioned process is described in combination with the optional embodiment below, but it is not used to limit the technical solution of the embodiment of this application.
[0117] In an exemplary embodiment, an example of a working process of an interface calling tool is provided. Figure 7 is a schematic diagram of the working process of an interface calling tool according to an embodiment of the present application, such as Figure 7 As shown, before the application is started, the interface calling tool can work in the following ways, but is not limited to:
[0118] The initialization function (__init) is used to load the interface identification library included in the interface calling tool before the interface library. For example, if the interface identification library includes an application interface with the same interface identification as that in the interface library, the application interface in the interface identification library is initialized between the application and the interface library. Since the application will call the application interface according to the interface identification, before the application initiates a call request, the application interface deployed before the interface library will first respond to the call request and run the resource monitoring program.
[0119] Find the replaced function symbol (dlsym), which is used to call the loading function void __attribute__((constructor)) _init(void) before the main function of the target process through the constructor modification attribute, and add the target identification set to the interface identification library;
[0120] Apply for memory resource allocation and initialize the hash list of each module: Apply for sufficient memory space for the interface calling tool, and perform initialization of the corresponding hash table, including stack module related initialization, dynamic library module related initialization, shared memory module related initialization, etc.
[0121] After the deployment process of the interface calling tool is completed, you can perform the following operations, but are not limited to:
[0122] Start the working thread: The interface calls the tool to start the thread, including starting the timed output thread, registering the specified output module information and interval, and detecting the output directory;
[0123] Replace some signal processing functions: The thread responds to the call request initiated by the application and outputs the request information regularly.
[0124] It is worth noting that in the solution proposed in this application, taking the libc dynamic library as an example, the target program usually calls the malloc, new and other application interfaces in the libc dynamic library to apply for memory resources. By adding the interface identification library generated by encapsulating and replacing the key application interfaces in the libc dynamic library in the interface calling tool, and deploying the interface identification library between the application and the interface library, the purpose is to allow the application to give priority to calling the application interface in the interface identification library when applying for and releasing memory resources and traversing the application interface.
[0125] In this way, not only can the acquisition function for obtaining memory application and release information (application time, application address, application size, return address of calling application, heap function called by the applicant) be added to the application interface in the repackaged interface identification library, but also the function for converting call requests can be added.
[0126] After completing the encapsulation and replacement of the application interface in the interface identification library, the interface library can, but is not limited to, use dynamic libraries such as dlsym to load related functions. For example, use the function dlsym(RTLD_NEXT,"malloc") to find the actual "malloc" application interface from the interface library. If some functions in some libraries cannot find the corresponding symbols, the correct function symbols can be located through functions such as dlopen.
[0127] After symbol replacement and actual function implementation are completed, the constructor and destructor are exported through the __attribute__((constructor)) and __attribute__((destructor)) function attributes. The constructor will be called before dlopen() returns or when the library is loaded, and the destructor will be called before dlclose() returns, after main() returns, or when exit() is called during the loading of the library.
[0128] Regarding information output, you can replace the signal processing function, hijack the signal when an exception occurs, then print the stack traceback and check the stack information and output the error information. Currently, the commonly used hijacking signals are: SIGEGV (signal 11), SIGABRT (signal 6), etc. It should be noted that in the process of executing memory release, you need to first find the statistical node of the application information in the hash list according to the passed-in address, clear the node information, and then call the replaced real release interface function. This order cannot be reversed, otherwise it will cause a false alarm of secondary release.
[0129] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), including a number of instructions to enable a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0130] In the present embodiment, a control device for interface calling is also provided, the operating system includes an application, an interface library and a system operation resource, the application interface stored in the interface library is used to respond to the call of the application to perform operations on the system operation resource, the device is applied to an interface calling tool, the interface calling tool is deployed between the application and the interface library, a resource monitoring program is stored in the interface calling tool, the resource monitoring program is used to monitor the operations performed on the system operation resource, the device is used to implement the above-mentioned embodiments and preferred implementation modes, and those that have been explained will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0131] Figure 8 is a structural block diagram of a control device for interface calling according to an embodiment of the present application, such as Figure 8 As shown, the device comprises:
[0132] A receiving module 82, configured to receive a first call request initiated by the application program, wherein the first call request is used to request to call an application interface in the interface library;
[0133] A first detection module 84 is used to respond to the first call request, detect the application interface called by the first call request, and obtain a target application interface;
[0134] The first processing module 86 is configured to run the resource monitoring program and forward the first calling request to the interface library when the target application interface is an application interface that allows calling the resource monitoring program.
[0135] Through the above device, a first call request initiated by an application is received, wherein the first call request is used to request to call an application interface in an interface library; in response to the first call request, the application interface requested to be called by the first call request is detected to obtain a target application interface; in the case where the target application interface is an application interface that allows calling a resource monitoring program, the resource monitoring program is run, and the first call request is forwarded to the interface library. That is to say, an interface call tool is deployed between the application and the interface library, and the interface call tool first responds to the first call request initiated by the application, executes the call process of the resource monitoring program, and the resource monitoring program completes the monitoring of the operations executed on the system operation resources, and then the first call request is forwarded to the interface library, and the application interface stored in the interface library responds to the first call request to execute the operations on the system operation resources. Through the interface call tool, the operations executed on the system operation resources are monitored without modifying the source code of the application, so the problem of low monitoring efficiency of the system operation resources can be solved, and the effect of improving the monitoring efficiency of the system operation resources is achieved.
[0136] In an exemplary embodiment, the first detection module includes:
[0137] The first detection unit is configured to detect the application interface requested to be called by the first call request to obtain a target application interface, including:
[0138] An extraction unit, used to extract a target interface identifier from the first call request;
[0139] A search unit, used for traversing an interface identification library to search for the target interface identification from the interface identification library, wherein the interface identification library is used to store the interface identifications of the application interfaces stored in the interface library;
[0140] The first determining unit is configured to determine the application interface corresponding to the target interface identifier as the target application interface when the target interface identifier is found in the interface identifier library.
[0141] In an exemplary embodiment, before running the resource monitoring program and forwarding the first call request to the interface library, the device further includes:
[0142] A search module, used for searching the target interface identifier from a target identifier set in the interface identifier library, wherein the target identifier set is added to the interface identifier library through the interface calling tool;
[0143] The determination module is used to determine that the target application interface is an application interface that allows calling the resource monitoring program when the target interface identifier is found in the target identifier set.
[0144] In an exemplary embodiment, the first processing module includes:
[0145] A calling unit, configured to call the resource monitoring program to obtain target request information, wherein the target request information is used to describe the application program that initiates the first calling request, and the operation performed by the application program on the system running resources by initiating the application interface in the interface library requested to be called by the first calling request;
[0146] A storage unit is used to store the target request information in a target memory space, wherein the target memory space is a memory space that the interface calling tool is allowed to use.
[0147] In an exemplary embodiment, the calling unit is further used to: call the address function through the resource monitoring program to obtain address information returned by the address function, wherein the address information is used to indicate the location of the application, and the target request information includes the address information; detect the program state of the application according to the address information, wherein the program state is used to indicate whether the address information falls within a target range; and when it is detected that the program state indicates that the address information falls within the target range, call the target function through the resource monitoring program to obtain the target request information returned by the target function.
[0148] In an exemplary embodiment, the storage unit is further used to: calculate the target slot of the target request information in a hash table through a hash function, wherein the hash table is stored in the target memory space; and write the target request information into the target slot.
[0149] In an exemplary embodiment, before forwarding the first call request to the interface library, the apparatus further includes:
[0150] A second detection module, used for detecting the interface status of the target application interface, wherein the interface status is used to indicate whether the system operation resource to be operated by the target application interface is a memory resource;
[0151] a conversion module, configured to convert the first call request into a target call request when it is detected that the interface state is used to indicate that the system operation resource to be operated by the target application interface is the memory resource;
[0152] A sending module is used to send the target call request to the interface library.
[0153] In an exemplary embodiment, the conversion module comprises:
[0154] a second detection unit, configured to detect a request status of the first call request, wherein the request status is used to indicate a target operation to be performed on the memory resource by the target application interface requested to be called by the first call request, and the operation performed by the application interface on the memory resource includes a memory allocation operation, a memory release operation, and a memory access operation, wherein the memory allocation operation is used to allocate memory resources to the application, the memory release operation is used to release the memory resources of the application, and the memory access operation is used to access the memory resources of the application;
[0155] A first conversion unit is configured to convert the first call request into a second call request when it is detected that the request state is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory allocation operation, wherein the first call request is used to request to call the target application interface to allocate a first amount of memory resources to the application program, the second call request is used to request to call the target application interface to allocate a second amount of memory resources to the application program, the first amount of resources is less than the second amount of resources, and the target call request includes the second call request;
[0156] a second conversion unit, configured to convert the first call request into a third call request, when it is detected that the request status indicates that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, wherein the first call request is used to request to call the target application interface to release a third amount of memory resources for the application program, and the third call request is used to request to call the target application interface to release a fourth amount of memory resources for the application program, and detect a resource status of a resource difference between the memory resources of the third amount of memory resources and the memory resources of the fourth amount of memory resources, wherein the resource difference is additionally allocated memory resources when allocating the third amount of memory resources to the application program, and the resource status is used to indicate whether the memory resources corresponding to the resource difference are modified, the third amount of resources is less than the fourth amount of resources, and the target call request includes the third call request;
[0157] A second determining unit is configured to determine the first call request as the target call request when it is detected that the request status indicates that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory access operation.
[0158] In an exemplary embodiment, the first conversion unit is further used to: search for initial resource parameters from the first call request, wherein the initial resource parameters are used to indicate the memory resources of the first resource amount to be allocated to the application; modify the initial resource parameters in the first call request to target resource parameters to obtain the second call request, wherein the target resource parameters are used to indicate the memory resources of the second resource amount to be allocated to the application.
[0159] In an exemplary embodiment, the first conversion unit is also used for at least one of the following: increasing the initial resource parameter by the target length to obtain the target resource parameter, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target length; increasing the initial resource parameter by the target memory page to obtain a reference resource parameter; adding the access permission parameter of the target memory page to the reference resource parameter, and configuring the access permission parameter to read-only mode to obtain the target resource parameter, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target memory page.
[0160] In an exemplary embodiment, after forwarding the first call request to the interface library, the apparatus further includes:
[0161] An acquisition module, configured to acquire request information of an access request for accessing the target memory page by hijacking a signal when a memory access operation is detected on the target memory page;
[0162] The first output module is used to output request information of an access request for accessing the target memory page.
[0163] In an exemplary embodiment, after forwarding the first call request to the interface library, the apparatus further includes:
[0164] A second processing module is configured to, when it is detected that the request status indicates that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, the interface library responds to the third call request, calls the target application interface to release the memory resource of the fourth resource amount for the application, and detects the resource status of the resource difference;
[0165] A receiving module, used for receiving the resource status returned by the interface library;
[0166] The second output module is used to output request information for modifying the memory resource corresponding to the resource difference value when the resource status indicates that the memory resource corresponding to the resource difference value is modified.
[0167] In an exemplary embodiment, before running the resource monitoring program, the device further includes:
[0168] A first running module, used to run a loading function, and deploy the interface calling tool between the application and the interface library through the loading function, wherein the loading function includes void __attribute__((constructor)) _init(void);
[0169] After running the resource monitoring program, the device further includes:
[0170] The second running module is used to run an initialization function to restore the connection between the application and the interface library through the initialization function, wherein the initialization function includes void __attribute__((destructor))_fini(void).
[0171] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0172] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0173] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0174] An embodiment of the present application further provides an electronic device, Fig. 9 is a structural block diagram of an electronic device according to an embodiment of the present application, such as Fig. 9As shown, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the method embodiments described above.
[0175] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0176] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0177] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0178] The embodiments of the present application also provide a computer program, which includes computer instructions stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any one of the above method embodiments.
[0179] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0180] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0181] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A control method for interface calling, It is characterized in that The operating system includes an application program, an interface library and system operation resources. The application interface stored in the interface library is used to respond to the call of the application program to perform operations on the system operation resources. The method is applied to an interface calling tool, which is deployed between the application program and the interface library. A resource monitoring program is stored in the interface calling tool, and the resource monitoring program is used to monitor the operations performed on the system operation resources. The method includes: Receiving a first call request initiated by the application, wherein the first call request is used to request to call an application interface in the interface library; In response to the first call request, detecting the application interface requested to be called by the first call request, and obtaining a target application interface; In the case where the target application interface is an application interface that allows calling the resource monitoring program, running the resource monitoring program and forwarding the first calling request to the interface library; Wherein, the running of the resource monitoring program includes: calling the resource monitoring program to obtain target request information, wherein the target request information is used to describe the application that initiates the first call request, and the operation performed by the application on the system running resources by initiating the application interface in the interface library requested to be called by the first call request; storing the target request information in the target memory space, wherein the target memory space is the memory space allowed to be used by the interface calling tool.
2. The method according to claim 1, It is characterized in that The detecting the application interface requested to be called by the first call request to obtain the target application interface includes: Extracting a target interface identifier from the first call request; Traversing an interface identification library to search for the target interface identification from the interface identification library, wherein the interface identification library is used to store interface identifications of application interfaces stored in the interface library; When the target interface identifier is found in the interface identifier library, the application interface corresponding to the target interface identifier is determined as the target application interface.
3. The method according to claim 2, It is characterized in that Before running the resource monitoring program and forwarding the first call request to the interface library, the method further includes: Searching for the target interface identifier from a target identifier set in the interface identifier library, wherein the target identifier set is added to the interface identifier library through the interface calling tool; When the target interface identifier is found in the target identifier set, the target application interface is determined to be an application interface that allows calling the resource monitoring program.
4. The method according to claim 1, It is characterized in that The calling of the resource monitoring program to obtain target request information includes: Calling an address function through the resource monitoring program obtains address information returned by the address function, wherein the address information is used to indicate the location of the application program, and the target request information includes the address information; detecting a program state of the application program according to the address information, wherein the program state is used to indicate whether the address information falls within a target range; When it is detected that the program state indicates that the address information falls within the target range, the target function is called by the resource monitoring program to obtain the target request information returned by the target function.
5. The method according to claim 1, It is characterized in that The storing the target request information into the target memory space includes: Calculating a target slot of the target request information in a hash table by a hash function, wherein the hash table is stored in the target memory space; The target request information is written into the target slot.
6. The method according to claim 1, It is characterized in that Before forwarding the first call request to the interface library, the method further includes: Detecting an interface state of the target application interface, wherein the interface state is used to indicate whether the system operation resource to be operated by the target application interface is a memory resource; In a case where it is detected that the interface state is used to indicate that the system operating resource to be operated by the target application interface is the memory resource, converting the first call request into a target call request; The target call request is sent to the interface library.
7. The method according to claim 6, It is characterized in that The converting the first call request into a target call request comprises: Detecting a request status of the first call request, wherein the request status is used to indicate a target operation to be performed on the memory resource by the target application interface called by the first call request, and the operation performed by the application interface on the memory resource includes a memory allocation operation, a memory release operation, and a memory access operation, wherein the memory allocation operation is used to allocate memory resources to the application, the memory release operation is used to release the memory resources of the application, and the memory access operation is used to access the memory resources of the application; In a case where it is detected that the request state is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory allocation operation, converting the first call request into a second call request, wherein the first call request is used to request calling the target application interface to allocate a first amount of memory resources for the application program, the second call request is used to request calling the target application interface to allocate a second amount of memory resources for the application program, the first amount of resources is less than the second amount of resources, and the target call request includes the second call request; In the case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, the first call request is converted into a third call request, wherein the first call request is used to request to call the target application interface to release a third amount of memory resources for the application, and the third call request is used to request to call the target application interface to release a fourth amount of memory resources for the application, and the resource status of the resource difference between the memory resources of the third amount of memory resources and the memory resources of the fourth amount of memory resources is detected, the resource difference being the memory resources additionally allocated when the memory resources of the third amount of memory resources are allocated to the application, and the resource status is used to indicate whether the memory resources corresponding to the resource difference are modified, the third amount of resources is less than the fourth amount of resources, and the target call request includes the third call request; In a case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface called by the first call request is the memory access operation, the first call request is determined as the target call request.
8. The method according to claim 7, It is characterized in that The converting the first call request into a second call request comprises: searching for an initial resource parameter from the first call request, wherein the initial resource parameter is used to indicate a memory resource of the first resource amount to be allocated to the application program; The initial resource parameter in the first call request is modified into a target resource parameter to obtain the second call request, wherein the target resource parameter is used to indicate the memory resource of the second resource amount to be allocated to the application.
9. The method according to claim 8, It is characterized in that The step of modifying the initial resource parameter in the first call request to a target resource parameter to obtain the second call request includes at least one of the following: The target resource parameter is obtained by increasing the target length by the initial resource parameter, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target length; The initial resource parameters are increased by the target memory page to obtain reference resource parameters; the access permission parameters of the target memory page are added to the reference resource parameters, and the access permission parameters are configured as read-only mode to obtain the target resource parameters, wherein the second resource amount includes the sum of the first resource amount and the resource amount corresponding to the target memory page.
10. The method according to claim 9, It is characterized in that After forwarding the first call request to the interface library, the method further includes: When a memory access operation is detected on the target memory page, obtaining request information of an access request for accessing the target memory page by hijacking a signal; Output request information of an access request for accessing the target memory page.
11. The method according to claim 7, It is characterized in that After forwarding the first call request to the interface library, the method further includes: In the case where it is detected that the request status is used to indicate that the target operation to be performed on the memory resource by the target application interface requested to be called by the first call request is the memory release operation, the interface library responds to the third call request, calls the target application interface to release the memory resource of the fourth resource amount for the application, and detects the resource status of the resource difference; Receiving the resource status returned by the interface library; In a case where the resource status is used to indicate that the memory resource corresponding to the resource difference value is modified, request information for modifying the memory resource corresponding to the resource difference value is output.
12. The method according to claim 1, It is characterized in that Before running the resource monitoring program, the method further includes: running a loading function, and deploying the interface calling tool between the application and the interface library through the loading function, wherein the loading function includes void __attribute__((constructor)) _init(void); After running the resource monitoring program, the method further includes: running an initialization function, and restoring the connection between the application and the interface library through the initialization function, wherein the initialization function includes void __attribute__((destructor)) _fini(void).
13. A control device for interface calling, It is characterized in that The operating system includes an application program, an interface library and system operation resources. The application interface stored in the interface library is used to respond to the call of the application program to perform operations on the system operation resources. The device is applied to an interface calling tool, and the interface calling tool is deployed between the application program and the interface library. The interface calling tool stores a resource monitoring program, and the resource monitoring program is used to monitor the operations performed on the system operation resources. The device includes: A receiving module, configured to receive a first call request initiated by the application program, wherein the first call request is used to request to call an application interface in the interface library; A first detection module, configured to respond to the first call request, detect the application interface requested to be called by the first call request, and obtain a target application interface; A first processing module, configured to run the resource monitoring program and forward the first calling request to the interface library when the target application interface is an application interface that allows calling the resource monitoring program; Among them, the first processing module includes: a calling unit, used to call the resource monitoring program to obtain target request information, wherein the target request information is used to describe the application that initiates the first calling request, and the operation performed by the application on the system running resources by initiating the application interface in the interface library requested to be called by the first calling request; a storage unit, used to store the target request information in a target memory space, wherein the target memory space is a memory space allowed to be used by the interface calling tool.
14. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 12 when executed by a processor.
15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the steps of the method described in any one of claims 1 to 12 are implemented.
16. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Application program monitoring method and device
CN106897607A
Terminal equipment and application program interface calling control method thereof
CN111338828A
Performance evaluation of applications that access external resources
US9935812B1
