File descriptor detection method and device
By detecting the match of dynamic link library information during the file descriptor closing operation, the problem of incorrect file descriptor closing caused by the mismatch between the dynamic link library and the created link library is solved, ensuring the stable operation of the application.
Patent Information
- Application Number
- CN202010858494.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-24
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2040-08-24
AI Technical Summary
When the application is running, when the dynamic link library opens and closes the file descriptor, due to the mismatch between the creation and closing of the dynamic link library, the file descriptor is incorrectly closed, which may cause the application to crash or exception.
When a file descriptor closing operation is detected, obtain the file descriptor to be closed and its associated closing and creation dynamic link library information, and determine whether the two match; if they do not match, report the error closing information and close the file descriptor to ensure Correctly detect and handle false shutdowns.
It achieves accurate detection and processing of file descriptor error closing, reduces the risk of application crashes or exceptions, and improves program stability and user experience.
Smart Images

Figure CN114185608B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular to a file descriptor detection method and device. Background Art
[0002] The file descriptor is an index created by the kernel to efficiently manage opened files and is used to point to opened files.
[0003] At present, when an application is running, multiple dynamic link libraries may be loaded. In the process of loading a dynamic link library, when the dynamic link library opens a file, the kernel will create a file descriptor corresponding to the file, and the dynamic link library can be used as the dynamic link library that creates the file descriptor. When the dynamic link library closes the file, it will be closed by closing the corresponding file descriptor. Since the file descriptor is globally accessible in the process, the dynamic link library that closes the file descriptor may be different from the dynamic link library that creates the file descriptor, resulting in the problem of incorrect closure of the file descriptor, which causes the application to crash or abnormally run.
[0004] Therefore, in order to reduce the risk of application crashes or exceptions during operation, there is an urgent need for a method to detect incorrectly closed file descriptors so that relevant developers can debug the application based on the detected incorrectly closed file descriptors, thereby reducing the risk of application crashes or exceptions, thereby improving the user experience of the program. Summary of the invention
[0005] The embodiments of the present disclosure provide a file descriptor detection method and device to detect a file descriptor that is closed incorrectly.
[0006] In a first aspect, an embodiment of the present disclosure provides a file descriptor detection method, comprising:
[0007] When a file descriptor closing operation is detected, obtaining the file descriptor to be closed corresponding to the file descriptor closing operation and the information of closing the dynamic link library corresponding to the file descriptor to be closed, and determining the information of creating the dynamic link library corresponding to the file descriptor to be closed;
[0008] When it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library, file descriptor error closing information is reported, and the file descriptor to be closed is closed.
[0009] In a second aspect, an embodiment of the present disclosure provides a file descriptor detection device, including:
[0010] An information acquisition module, used for acquiring, when a file descriptor closing operation is detected, a file descriptor to be closed corresponding to the file descriptor closing operation and information of a closed dynamic link library corresponding to the file descriptor to be closed, and determining information of creating a dynamic link library corresponding to the file descriptor to be closed;
[0011] The processing module is used to report file descriptor error closing information and close the file descriptor to be closed when it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library.
[0012] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: at least one processor and a memory.
[0013] The memory stores computer executable instructions.
[0014] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the file descriptor detection method described in the first aspect and various possible designs of the first aspect.
[0015] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the file descriptor detection method described in the first aspect and various possible designs of the first aspect is implemented.
[0016] The file descriptor detection method and device provided in the present embodiment include, when a file descriptor closing operation is detected, obtaining the file descriptor to be closed corresponding to the file descriptor closing operation and the information of closing the dynamic link library corresponding to the file descriptor to be closed, and determining the information of creating the dynamic link library corresponding to the file descriptor to be closed. When it is determined that the information of closing the dynamic link library does not match the information of creating the dynamic link library, the file descriptor error closing information is reported, and the file descriptor is closed. In the present embodiment, if a file descriptor closing operation is detected during the running or starting of the application, indicating that there is a dynamic link library closing the corresponding file descriptor, that is, the file descriptor is a file descriptor to be closed, and the dynamic link library is the dynamic link library to be closed corresponding to the file descriptor to be closed, then the information of the dynamic link library is obtained to obtain the information of closing the dynamic link library corresponding to the file descriptor to be closed, and the information of creating the dynamic link library corresponding to the file descriptor to be closed is obtained, that is, the information of the dynamic link library related to the creation of the file descriptor to be closed is obtained, and whether the information of closing the dynamic link library matches the information of creating the dynamic link library is determined to determine whether the dynamic link library to be closed and the dynamic link library to be created are the same dynamic link library. Link library, when it is determined that the information of the two does not match, it indicates that the closing dynamic link library corresponding to the file descriptor to be closed and the creating dynamic link library are not the same dynamic link library, that is, the dynamic link library that creates the file descriptor to be closed is different from the dynamic link library that closes the file descriptor to be closed, then it is determined that the file descriptor closing operation is an incorrect file descriptor closing operation, that is, the file descriptor to be closed is an incorrectly closed file descriptor, and automatic and accurate detection of incorrectly closed file descriptors is achieved, and the file descriptor incorrect closing information corresponding to the incorrectly closed file descriptor is reported, so that the relevant developers can debug the application according to the detected incorrectly closed file descriptor, reduce the risk of application crashes or exceptions, and thus improve the user experience of the program. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0018] Figure 1 A schematic diagram of a scenario of a file descriptor detection method provided by an embodiment of the present disclosure;
[0019] Figure 2 Schematic diagram of the process of the file descriptor detection method provided in the embodiment of the present disclosure Figure 1 ;
[0020] Figure 3 Schematic diagram of the process of the file descriptor detection method provided in the embodiment of the present disclosure Figure 2 ;
[0021] Figure 4 A schematic diagram of communication between an electronic device and a user terminal provided in an embodiment of the present disclosure;
[0022] Figure 5 A structural block diagram of a file descriptor detection device provided by an embodiment of the present disclosure;
[0023] Figure 6 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0025] See also Figure 1 , Figure 1 Figure 1 is a schematic diagram of the file descriptor detection scenario. Figure 1As shown, during the startup or operation of application 1, multiple dynamic link libraries (so) may be called. For example, application 1 needs to call dynamic link library 1 and dynamic link library 2. In the process of calling dynamic link library 1, file 1 needs to be opened. At this time, the processor in the electronic device where application 1 is located, that is, the kernel creates a file descriptor 1 corresponding to file 1. File descriptor 1 points to file 1. When operating file 1 subsequently, the operation can be performed through file descriptor 1. Since the file descriptor corresponding to the process is globally shared, dynamic link library 2 can also access file descriptor 1 during the process of calling dynamic link library 2. When dynamic link library 2 needs to close file 1, it can be closed by operating file descriptor 1, and the kernel will also close file descriptor 1. However, since the dynamic link library 2 related to closing file descriptor 1, that is, the closing dynamic link library corresponding to file descriptor 1, and the dynamic link library 1 related to creating file descriptor 1, that is, the creating dynamic link library corresponding to file descriptor 1 are not the same dynamic link library, the problem of incorrect closing of file descriptors occurs, which may cause crashes or abnormal problems in the operation of the application. Therefore, in order to reduce the risk of application crashes or exceptions during operation, there is an urgent need for a method to detect incorrectly closed file descriptors so that relevant developers can debug the application based on the detected incorrectly closed file descriptors, thereby reducing the risk of application crashes or exceptions, thereby improving the user experience of the program.
[0026] Therefore, in response to the above problems, the technical concept of the present invention is that during the running or startup of an application, if it is detected that there is a dynamic link library calling a custom shutdown proxy function, indicating that the file descriptor needs to be closed, the file descriptor is set as the file descriptor to be closed, and the dynamic link library is used as the closing dynamic link library corresponding to the file descriptor to be closed, the information of the dynamic link library is obtained to obtain the information of the closing dynamic link library corresponding to the file descriptor to be closed, and the information of the creation dynamic link library corresponding to the file descriptor to be closed is obtained from the file descriptor record table, that is, the information of the dynamic link library related to the creation of the file descriptor to be closed is obtained. After obtaining the information of closing the dynamic link library and creating the dynamic link library corresponding to the file descriptor to be closed, it is determined whether the information of closing the dynamic link library matches the information of creating the dynamic link library to determine whether the closing dynamic link library and the creating dynamic link library corresponding to the file descriptor to be closed are the same dynamic link library. When it is determined that the information of the two matches, it indicates that the closing dynamic link library and the creating dynamic link library are the same dynamic link library, that is, the dynamic link library that creates the file descriptor to be closed is the same as the dynamic link library that closes the file descriptor to be closed. If the file descriptor to be closed is a file descriptor closed normally, the file descriptor to be closed is closed normally, and the file descriptor identical to the file descriptor to be closed and the corresponding information of creating the dynamic link library are deleted from the file descriptor record table. When it is determined that the information of the two does not match, it indicates that the closing dynamic link library and the creating dynamic link library are not the same dynamic link library, that is, the dynamic link library that creates the file descriptor to be closed is different from the dynamic link library that closes the file descriptor to be closed, then the file descriptor to be closed is determined to be an erroneously closed file descriptor, thereby achieving automatic and accurate detection of the erroneously closed file descriptor, and continuing to normally close the file descriptor to be closed, so that the application can continue to run and avoid application interruption.
[0027] refer to Figure 2 , Figure 2 Schematic diagram of the process of the file descriptor detection method provided in the embodiment of the present disclosure Figure 1 The method of this embodiment can be applied in electronic devices, such as computers, servers, etc., and can be applied in processors in electronic devices, such as Figure 2 As shown, the file descriptor detection method includes:
[0028] S201. When a file descriptor closing operation is detected, obtain the file descriptor to be closed corresponding to the file descriptor closing operation and the information of closing the dynamic link library corresponding to the file descriptor to be closed, and determine the information of creating the dynamic link library corresponding to the file descriptor to be closed.
[0029] In this embodiment, when a file descriptor closing operation is detected, it indicates that there is a dynamic link library closing the dynamic file descriptor, that is, there is a dynamic link library performing an operation to close the dynamic descriptor, then the file descriptor to be closed by the dynamic link library is used as the file descriptor to be closed, and the dynamic link library that closes the file descriptor to be closed is used as the closed dynamic link library corresponding to the file descriptor to be closed.
[0030] After determining the closed dynamic link corresponding to the file descriptor to be closed, the closed dynamic link information is obtained, and the information of the creation dynamic link library corresponding to the file descriptor to be closed is obtained. The creation dynamic link library corresponding to the file descriptor to be closed is the dynamic link library that creates the file descriptor to be closed.
[0031] The information of closing the dynamic link library includes an identifier of closing the dynamic link library, and the information of creating the dynamic link library includes an identifier of creating the dynamic link library.
[0032] Optionally, the identifier of the dynamic link library may be the name of the dynamic link library.
[0033] S202: When it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library, report file descriptor error closing information, and close the file descriptor to be closed.
[0034] In this embodiment, after determining the closing dynamic link library and the creating dynamic link library corresponding to the file descriptor to be closed, that is, after determining the dynamic link library that creates the file descriptor to be closed and the dynamic link library that closes the file descriptor to be closed, it is determined whether the information of the closing dynamic link library matches the information of the creating dynamic link library, so as to determine whether the dynamic link library that closes the file descriptor to be closed and the dynamic link library that creates the file descriptor to be closed are the same dynamic link library. If it is determined that the information of the closing dynamic link library does not match the information of the creating dynamic link library, indicating that the dynamic link library that closes the file descriptor to be closed and the dynamic link library that creates the file descriptor to be closed are not the same dynamic link library, then the file descriptor closing operation is determined to be a file descriptor error closing operation, that is, the file descriptor to be closed is an error-closed file descriptor, and the detection of the error-closed file descriptor is realized.
[0035] In order to facilitate developers to know the wrongly closed file descriptors and debug the application according to the wrongly closed file descriptors, after detecting the wrongly closed file descriptors, the corresponding file descriptor wrongly closed information is generated and reported. And in order not to affect the operation of the application so that relevant personnel can continue to use the application, after determining the wrongly closed file descriptors, continue to close the file descriptors normally.
[0036] Optionally, the file descriptor error closing information may include at least one of the following: relevant information of the file descriptor to be closed, information on closing a dynamic link library corresponding to the file descriptor to be closed, and information on creating a dynamic link library corresponding to the file descriptor to be closed.
[0037] In addition, optionally, the relevant information of the file descriptor to be closed may include information such as the name of the file pointed to by the file descriptor to be closed and / or the name of the file description to be closed.
[0038] It should be noted that the information included in the file descriptor error closing information and the information included in the file descriptor to be closed can be set according to actual needs, and this embodiment is not limited to this.
[0039] From the above description, it can be seen that during the running of the application, if a file description closing operation is detected, it indicates that there is a dynamic link library closing the corresponding file descriptor, that is, the file descriptor is the file descriptor to be closed, and the dynamic link library is the closed dynamic link library corresponding to the file descriptor to be closed, then the information of the dynamic link library is obtained to obtain the information of the closed dynamic link library corresponding to the file descriptor to be closed, and the information of the created dynamic link library corresponding to the file descriptor to be closed is obtained, that is, the information of the dynamic link library related to the creation of the file descriptor to be closed is obtained, and it is determined whether the information of the closed dynamic link library matches the information of the created dynamic link library to determine whether the closed dynamic link library corresponding to the file descriptor to be closed and the created dynamic link library are the same dynamic link When it is determined that the information of the two does not match, it indicates that the closing dynamic link library corresponding to the file descriptor to be closed and the creating dynamic link library are not the same dynamic link library, that is, the dynamic link library that creates the file descriptor to be closed is different from the dynamic link library that closes the file descriptor to be closed, then it is determined that the file descriptor closing operation is an incorrect file descriptor closing operation, that is, the file descriptor to be closed is an incorrectly closed file descriptor, and automatic and accurate detection of incorrectly closed file descriptors is achieved, and the file descriptor incorrect closing information corresponding to the incorrectly closed file descriptor is reported, so that the relevant developers can debug the application according to the detected incorrectly closed file descriptor, reduce the risk of application crashes or exceptions, and thus improve the user experience of the program.
[0040] refer to Figure 3 , Figure 3 Schematic diagram of the process of the file descriptor detection method provided in the embodiment of the present disclosure Figure 2 .exist Figure 2Based on the embodiment, the identifier of creating a dynamic link library corresponding to the file descriptor to be closed and the identifier of closing the dynamic link library corresponding to the file descriptor to be closed are used to determine whether the file descriptor to be closed is an erroneously closed file descriptor, so as to realize the detection of the erroneously closed file descriptor. The process of detecting the erroneously closed file descriptor using the identifier of the dynamic link library will be described in detail in combination with a specific embodiment. Figure 3 As shown, the method includes:
[0041] S301. When a file descriptor closing operation is detected, the file descriptor to be closed corresponding to the file descriptor closing operation and the information of closing the dynamic link library corresponding to the file descriptor to be closed are obtained, and the information of creating the dynamic link library corresponding to the file descriptor to be closed is determined.
[0042] In this embodiment, during the process of application startup or operation, it is necessary to close the opened files, thereby it is necessary to close some file descriptors, and the file descriptors that need to be closed are used as the file descriptors to be closed. In order to determine the information of creating a dynamic link library corresponding to the file descriptor to be closed, when creating the file descriptor, the information of creating a dynamic link library corresponding to the file descriptor can be recorded in the file descriptor record table. Therefore, when it is necessary to obtain the information of creating a dynamic link library corresponding to the file descriptor to be closed, the file descriptor record table is obtained, and the target file descriptor identical to the file descriptor to be closed is obtained from the file descriptor record table, and the dynamic link library corresponding to the target file descriptor is used as the dynamic link library corresponding to the file descriptor to be closed.
[0043] The file descriptor record table includes at least one file descriptor and a dynamic link library corresponding to the file descriptor. That is, the file descriptor record table stores information about the file descriptors corresponding to the application and the dynamic link libraries corresponding to each file descriptor. The dynamic link library corresponding to the file descriptor is a dynamic link library related to the creation of the file descriptor, that is, a dynamic link library for opening or creating the file corresponding to the file descriptor.
[0044] Specifically, when obtaining the information of creating a dynamic link library corresponding to the file descriptor to be closed from the file descriptor record table, the file descriptor corresponding to the file descriptor to be closed is obtained from the file descriptor record table, and it is determined as the target file descriptor, and the dynamic link library created corresponding to the target file descriptor is used as the dynamic link library created corresponding to the file descriptor to be closed, so that the information of creating the dynamic link library corresponding to the target file descriptor is used as the information of creating the dynamic link library corresponding to the file descriptor to be closed, thereby realizing the acquisition of the information of creating the dynamic link library corresponding to the file descriptor to be closed.
[0045] In addition, optionally, the file descriptor record table can be stored in a corresponding location in the form of a file, or in the form of a collection. The location can be in the memory, specifically the location in the memory where the running data of the application is stored. Of course, the location can also be other locations, such as a hard disk, which is not limited here.
[0046] In this embodiment, optionally, in order to obtain information storing a file descriptor corresponding to an application and its corresponding dynamic link library creation, it is necessary to replace the function related to the creation of a file descriptor in the dynamic link library involved in the application with a custom creation proxy function, so as to use the creation proxy function to determine whether a newly created file descriptor exists, thereby recording the newly created file descriptor in the file descriptor record table. When replacing the function related to the creation of a file descriptor with the creation proxy function, the replacement can be performed in the following two ways.
[0047] One implementation method is: when detecting the application startup, all dynamic link libraries corresponding to the application and the descriptor creation association function corresponding to each dynamic link library are obtained. For each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0048] In this embodiment, when it is determined that an application is started, the dynamic link library in the code corresponding to the application is obtained to obtain all dynamic link libraries corresponding to the application. Then all descriptor creation association functions in each dynamic link library are determined respectively to obtain the descriptor creation association function corresponding to each dynamic link library. The descriptor creation association function represents a function related to creating a file descriptor, that is, when the dynamic link library calls the function, it indicates that the dynamic link library needs to open the file corresponding to the function or create a file, so the processor needs to create a file descriptor pointing to the file.
[0049] After obtaining all the descriptor creation association functions corresponding to the dynamic link library, record the name of each descriptor creation association function and save it to the specified location, so that when performing function replacement, the descriptor creation association function can be replaced with the corresponding creation proxy function according to the name of the descriptor creation association function in the specified location.
[0050] The designated location may be in the memory, specifically the location in the memory where the running data of the application is stored. Of course, the designated location may also be other locations, such as a hard disk, which is not limited here. In addition, the proxy creation function may be a custom create_proxy function, through which a file descriptor pointing to the file opened or created by the descriptor creation association function corresponding to the create_proxy function may be created, and the created file descriptor and the corresponding dynamic link library information are added to the file descriptor record table.
[0051] Specifically, when performing function replacement on all descriptor creation associated functions corresponding to each dynamic link library, for each descriptor creation associated function, the descriptor creation associated function is replaced with the creation proxy function corresponding to the descriptor creation associated function. During the running of the application, if the dynamic link library calls a creation proxy function, the creation proxy function first determines the file it needs to open or create by calling its corresponding descriptor creation associated function, that is, determines the file descriptor it needs to create, and then obtains the information of the dynamic link library, that is, obtains the information of the dynamic link library that calls the creation proxy function, and uses it as the creation dynamic link library information corresponding to the file descriptor, and records the file descriptor and its corresponding creation dynamic link library information in the file descriptor record table.
[0052] In this embodiment, when an application is started, all dynamic link libraries corresponding to the application and the descriptor creation association functions corresponding to each dynamic link library are obtained, and each descriptor creation association function is replaced by its corresponding creation proxy function, so as to ensure that when calling to create a file descriptor, the file descriptor to be created and the creation dynamic link library information corresponding to the file descriptor can be determined through the creation proxy function, and saved in the file descriptor record table, so as to avoid the situation where the file descriptor and its corresponding creation dynamic link library cannot be recorded when calling the descriptor creation association function to create the corresponding file descriptor due to the failure to timely replace the function of a descriptor creation association function, thereby causing the failure of obtaining the information of the creation dynamic link library corresponding to the file descriptor to be closed, and then causing the failure of detecting the incorrectly closed file descriptor.
[0053] Another implementation method is: when it is determined that the application is started or in the process of running, if it is determined that there is a dynamic link library called for the first time in the dynamic link library corresponding to the application, then the descriptor creation association function corresponding to the dynamic link library called for the first time is obtained. For each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0054] In this embodiment, when it is determined that the application is started or in the process of running, that is, before the application is terminated, the application may not use all dynamic link libraries, and may only use part of the dynamic link libraries. Therefore, in order to improve the efficiency of function replacement and reduce the waste of resources, only the descriptor creation association function of the used dynamic link library can be replaced. That is, when it is determined that the application calls the dynamic link library, and it is determined that the call is the first call, the descriptor creation association function corresponding to the dynamic link library is determined, and each descriptor creation association function is replaced, that is, it is replaced with its corresponding creation proxy function. Among them, the process of replacing the descriptor creation association function is similar to the process of replacing the above-mentioned descriptor function creation association function, and it will not be repeated here.
[0055] It can be understood that when determining the dynamic link library corresponding to the application and the descriptor creation association function in the dynamic link library, it can be determined based on relevant characters. For example, when it is determined that there are specific characters in the function, such as the characteristic character is open, the function is determined to be a descriptor creation association function.
[0056] Further, after replacing the descriptor creation association function corresponding to the dynamic link library with its corresponding creation proxy function, when it is determined that there is a dynamic link library calling the creation proxy function, it indicates that there is a dynamic link library opening or creating a file, that is, it indicates that a new file descriptor needs to be created, then a new file descriptor is created according to the proxy function, and the dynamic link library is used as the creation dynamic link library corresponding to the new file descriptor, the information of the creation dynamic link library corresponding to the new file descriptor is obtained, and the new file descriptor and its corresponding creation dynamic link library information are added to the file descriptor record table. That is, a new file descriptor pointing to the file is created by calling the creation proxy function, and the dynamic link library is used as the creation dynamic link library corresponding to the new file descriptor, and then the new file descriptor and its corresponding creation dynamic link library information are added to the file descriptor record table, so that when detecting the file descriptor that is closed by error, the file descriptor record table can be used for detection.
[0057] In addition, optionally, in order to detect the file descriptor closing operation corresponding to the application, it is necessary to replace the function related to closing the file descriptor in the dynamic link library involved in the application with a custom closing proxy function, so as to use the closing proxy function to determine whether there is a file descriptor closing operation. When replacing the function related to closing the file descriptor with the closing proxy function, the replacement can be performed in the following two ways.
[0058] One implementation is: when detecting the application startup, all dynamic link libraries corresponding to the application and the descriptor close associated function corresponding to each dynamic link library are obtained. For each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0059] In this embodiment, when it is determined that an application is started, the dynamic link library in the code corresponding to the application is obtained to obtain all dynamic link libraries corresponding to the application. Then, all descriptor close associated functions in each dynamic link library are determined respectively to obtain the descriptor close associated function corresponding to each dynamic link library. The descriptor close associated function represents a function related to closing a file descriptor, that is, when the dynamic link library calls the function, it indicates that the dynamic link library needs to close the file corresponding to the function, thereby closing the file descriptor pointing to the file.
[0060] After obtaining all the descriptor close associated functions corresponding to the dynamic link library, record the name of each descriptor close associated function and save it to the specified location, so that when replacing the function, the descriptor close associated function can be replaced with the corresponding close proxy function according to the name of the descriptor close associated function in the specified location.
[0061] The designated location may be in memory, specifically a location in memory where the running data of the application is stored. Of course, the designated location may also be other locations, such as a hard disk, which is not limited here. In addition, the closing proxy function may be a custom close_proxy function.
[0062] Specifically, when replacing all descriptor close associated functions corresponding to each dynamic link library, for each descriptor close associated function, the descriptor close associated function is replaced with the close proxy function corresponding to the descriptor close associated function. During the running of the application, if the dynamic link library calls a close proxy function, the close proxy function first determines the file to be closed by calling its corresponding descriptor close associated function, that is, determines the file descriptor to be closed, and then obtains the information of the dynamic link library, that is, obtains the information of the dynamic link library that calls the close proxy function, and uses it as the information of closing the dynamic link library corresponding to the file descriptor, and obtains the information of creating the dynamic link library corresponding to the file descriptor from the file descriptor record table. By judging whether the information of closing the dynamic link library corresponding to the file descriptor matches the information of creating the dynamic link library, it is determined whether the file descriptor is a file descriptor that is closed incorrectly.
[0063] Specifically, when the application is started, all dynamic link libraries corresponding to the application and the descriptor close associated functions corresponding to each dynamic link library are obtained, and each descriptor close associated function is replaced by its corresponding close proxy function, so as to ensure that when closing the file descriptor, it can be determined through the close proxy function whether the closed file descriptor is an erroneously closed file descriptor, so as to avoid the situation where the descriptor close associated function is not replaced in time, resulting in the inability to determine whether the file descriptor is an erroneously closed file descriptor when the descriptor close associated function is called to close the corresponding file descriptor.
[0064] Another implementation method is: when it is determined that the application is started or in the process of running, if it is determined that there is a dynamic link library called for the first time in the dynamic link library corresponding to the application, then the descriptor close associated function corresponding to the dynamic link library called for the first time is obtained. For each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0065] In this embodiment, when it is determined that the application is started or in the process of running, that is, before the application is terminated, the application may not use all dynamic link libraries, and may only use part of the dynamic link libraries. Therefore, in order to improve the efficiency of function replacement and reduce the waste of resources, only the descriptor close associated function of the used dynamic link library can be replaced. That is, when it is determined that the application calls the dynamic link library, and it is determined that the call is the first call, the descriptor close associated function corresponding to the dynamic link library is determined, and each descriptor close associated function is replaced, that is, it is replaced with its corresponding close proxy function. Among them, the process of function replacement is similar to the process of function replacement of the above-mentioned descriptor close associated function, and it will not be repeated here.
[0066] It can be understood that when determining the dynamic link library corresponding to the application and the descriptor close associated function in the dynamic link library, the determination can be made based on relevant characters. For example, when it is determined that there are specific characters in the function, such as the close character, the function is determined to be a descriptor close associated function.
[0067] In addition, further, since the dynamic link library needs to call the descriptor closing associated function corresponding to the file when closing a certain file, that is, it needs to call the corresponding closing proxy function, the file descriptor closing operation can be regarded as the dynamic link library calling the closing proxy function. Accordingly, when it is determined that there is a dynamic link library calling the closing proxy function, it indicates that the file corresponding to the closing proxy function needs to be closed, that is, the file descriptor corresponding to the file needs to be closed, and the file descriptor can be used as the file descriptor corresponding to the closing proxy function, then the file descriptor corresponding to the closing proxy function is used as the file descriptor to be closed, that is, as the file descriptor to be closed, and the dynamic link library is used as the closing dynamic link library corresponding to the file descriptor to be closed.
[0068] S302: Determine whether the identifier for closing the dynamic link library is the same as the identifier for creating the dynamic link library.
[0069] In this embodiment, it is determined whether the identifier of the closing dynamic link library corresponding to the file descriptor to be closed is the same as the identifier of the creating dynamic link library corresponding to the file descriptor to be closed, so as to determine whether the information of the closing dynamic link library matches the information of the creating dynamic link library, thereby determining whether the closing dynamic link library is the same as the creating dynamic link library.
[0070] S303: If the identifier for closing the dynamic link library is different from the identifier for creating the dynamic link library, it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library.
[0071] In this embodiment, when it is determined that the identifier of the closing dynamic link library corresponding to the file descriptor to be closed is different from the identifier of the creating dynamic link library corresponding to the file descriptor to be closed, it indicates that the closing dynamic link library is not the same as the creating dynamic link library, that is, they are not the same dynamic link library, then it is determined that the information of the closing dynamic link library does not match the information of the creating dynamic link library.
[0072] S304: If the identifier for closing the dynamic link library is the same as the identifier for creating the dynamic link library, it is determined that the information for closing the dynamic link library matches the information for creating the dynamic link library.
[0073] In this embodiment, when it is determined that the identifier of the closing dynamic link library corresponding to the file descriptor to be closed is the same as the identifier of the creating dynamic link library corresponding to the file descriptor to be closed, it indicates that the closing dynamic link library is the same as the creating dynamic link library, that is, the two are the same dynamic link library, then it is determined that the information of the closing dynamic link library matches the information of the creating dynamic link library.
[0074] S305: When it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library, report file descriptor error closing information, and close the file descriptor to be closed.
[0075] In this embodiment, when it is determined that the information of closing the dynamic link library corresponding to the file descriptor to be closed does not match the information of creating the dynamic link library corresponding to the file descriptor to be closed, that is, when it is determined that the dynamic link library that creates the file descriptor to be closed and the dynamic link library that closes the file descriptor to be closed are different dynamic link libraries, indicating that the file descriptor to be closed is an incorrectly closed file descriptor, then the file descriptor incorrect closing information corresponding to the file descriptor to be closed is reported so that relevant developers can solve the problem of incorrect closing of the file descriptor by analyzing the file descriptor incorrect closing information, thereby reducing the risk of abnormal operation or crash of the application and improving the robustness of the application.
[0076] Optionally, the descriptor error closing information includes call stack information corresponding to the file descriptor to be closed. That is, when it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library, the call stack related to the file descriptor to be closed is obtained to obtain the call stack information corresponding to the file descriptor to be closed. The call stack information includes the call path of the file descriptor to be closed, that is, according to the call stack information, relevant personnel can be informed of closing the dynamic link library described by the file to be closed and creating the dynamic link library described by the file to be closed.
[0077] In addition, optionally, after obtaining the call stack information corresponding to the file symbol to be closed, such as Figure 4 As shown, the electronic device 101 can report the call stack information corresponding to the file descriptor to be closed to the user terminal 102, so that relevant personnel can determine the file descriptor that is incorrectly closed in the application program based on the call stack information.
[0078] S306: When it is determined that the information for closing the dynamic link library matches the information for creating the dynamic link library, the target file description and its corresponding dynamic link library for creation are deleted from the file descriptor record table, and the file descriptor to be closed is closed.
[0079] In this embodiment, when it is determined that the information of closing the dynamic link library corresponding to the file descriptor to be closed matches the information of creating the dynamic link library corresponding to the file descriptor to be closed, that is, when it is determined that the dynamic link library that creates the file descriptor to be closed and the dynamic link library that closes the file descriptor to be closed are the same dynamic link library, it indicates that the file descriptor to be closed is a file descriptor that is closed normally, and there is no need to record the relevant information of the file descriptor to be closed, and it is only necessary to close the file descriptor to be closed normally.
[0080] Corresponding to the file descriptor detection method of the above embodiment, Figure 5A structural block diagram of a file descriptor detection device provided by an embodiment of the present disclosure. For ease of explanation, only the parts related to the embodiment of the present disclosure are shown. Figure 5 , the device includes: an information acquisition module 501 and a processing module 502.
[0081] Among them, the information acquisition module 501 is used to obtain the file descriptor to be closed corresponding to the file descriptor closing operation and the information of the closed dynamic link library corresponding to the file descriptor to be closed when the file descriptor closing operation is detected, and determine the information of creating the dynamic link library corresponding to the file descriptor to be closed.
[0082] The processing module 502 is used to report file descriptor error closing information and close the file descriptor to be closed when it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library.
[0083] In one embodiment of the present disclosure, the information of closing the dynamic link library includes an identifier of closing the dynamic link library, and the information of creating the dynamic link library includes an identifier of creating the dynamic link library. Then, the processing module 502 is further used to:
[0084] Determine whether the identification of closing the dynamic link library is the same as the identification of creating the dynamic link library. If the identification of closing the dynamic link library is the same as the identification of creating the dynamic link library, then determine that the information of closing the dynamic link library matches the information of creating the dynamic link library. If the identification of closing the dynamic link library is not the same as the identification of creating the dynamic link library, then determine that the information of closing the dynamic link library does not match the information of creating the dynamic link library.
[0085] In one embodiment of the present disclosure, the information acquisition module 501 is further used to:
[0086] A file descriptor record table is obtained, wherein the file descriptor record table includes at least one file descriptor and a creation dynamic link library corresponding to the file descriptor. A target file descriptor identical to the file descriptor to be closed is obtained from the file descriptor record table, and the creation dynamic link library corresponding to the target file descriptor is used as the creation dynamic link library corresponding to the file descriptor to be closed.
[0087] In one embodiment of the present disclosure, the processing module 502 is further configured to:
[0088] When it is determined that the information of closing the dynamic link library matches the information of creating the dynamic link library, the target file description and its corresponding dynamic link library creation are deleted from the file descriptor record table, and the file descriptor to be closed is closed.
[0089] In one embodiment of the present disclosure, the processing module 502 is further configured to:
[0090] When the application is detected to be started, all dynamic link libraries corresponding to the application and the descriptor creation association function corresponding to each dynamic link library are obtained. For each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0091] In one embodiment of the present disclosure, the processing module 502 is further configured to:
[0092] When it is determined that the application is started or in the process of running, if it is determined that there is a dynamic link library called for the first time in the dynamic link library corresponding to the application, the descriptor creation association function corresponding to the dynamic link library called for the first time is obtained. For each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0093] In one embodiment of the present disclosure, the processing module 502 is further configured to:
[0094] When it is determined that there is a dynamic link library call creation proxy function, a new file descriptor is created according to the proxy function, and the dynamic link library is used as the creation dynamic link library corresponding to the new file descriptor. The information of the creation dynamic link library corresponding to the new file descriptor is obtained, and the new file descriptor and its corresponding creation dynamic link library information are added to the file descriptor record table.
[0095] In one embodiment of the present disclosure, the processing module 502 is further configured to:
[0096] When the application is detected to be started, all dynamic link libraries corresponding to the application and the descriptor close associated functions corresponding to each dynamic link library are obtained. For each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0097] In one embodiment of the present disclosure, the processing module 502 is further configured to:
[0098] When it is determined that the application is started or in the process of running, if it is determined that there is a dynamic link library called for the first time in the dynamic link library corresponding to the application, the descriptor close associated function corresponding to the dynamic link library called for the first time is obtained. For each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0099] In one embodiment of the present disclosure, the file descriptor closing operation is a dynamic link library calling a closing proxy function, and the information acquisition module 501 is further used to:
[0100] When it is determined that there is a dynamic link library calling a close proxy function, the file descriptor corresponding to the close proxy function is used as the file descriptor to be closed, and the dynamic link library is used as the close dynamic link library corresponding to the file descriptor to be closed. Information of the close dynamic link library corresponding to the file descriptor to be closed is obtained.
[0101] In one embodiment of the present disclosure, the descriptor error closing information includes call stack information corresponding to the file descriptor to be closed, and the processing module 502 is further used to:
[0102] Report the call stack information corresponding to the file descriptor to be closed to the user terminal.
[0103] The device provided in this embodiment can be used to execute the technical solution of the above method embodiment. Its implementation principle and technical effect are similar, and this embodiment will not be repeated here.
[0104] refer to Figure 6 , which shows a schematic diagram of the structure of an electronic device 600 suitable for implementing the embodiment of the present disclosure, and the electronic device 600 may be a terminal device or a server. The terminal device may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0105] like Figure 6 As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 606 to a random access memory (RAM) 603. Various programs and data required for the operation of the electronic device 600 are also stored in the RAM 603. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0106] Typically, the following devices may be connected to the I / O interface 605: input devices 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 606 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 606. The communication devices 606 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0107] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 606, or installed from a storage device 606, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0108] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0109] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0110] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0111] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0112] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0113] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a unit does not limit the unit itself in some cases. For example, the first acquisition unit may also be described as a "unit for acquiring at least two Internet Protocol addresses".
[0114] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0115] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0116] In a first aspect, according to one or more embodiments of the present disclosure, a file descriptor detection method is provided, comprising:
[0117] When a file descriptor closing operation is detected, obtaining a file descriptor to be closed corresponding to the file descriptor closing operation and information of a closed dynamic link library corresponding to the file descriptor to be closed, and determining information of a created dynamic link library corresponding to the file descriptor to be closed;
[0118] When it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library, file descriptor error closing information is reported, and the file descriptor to be closed is closed.
[0119] According to one or more embodiments of the present disclosure, the method further includes: the information about closing the dynamic link library includes an identifier for closing the dynamic link library, and the information about creating the dynamic link library includes an identifier for creating the dynamic link library, and the method further includes:
[0120] Determine whether the identifier of closing the dynamic link library is the same as the identifier of creating the dynamic link library; if the identifier of closing the dynamic link library is the same as the identifier of creating the dynamic link library, determine that the information of closing the dynamic link library matches the information of creating the dynamic link library; if the identifier of closing the dynamic link library is not the same as the identifier of creating the dynamic link library, determine that the information of closing the dynamic link library does not match the information of creating the dynamic link library.
[0121] According to one or more embodiments of the present disclosure, the determining the information of creating a dynamic link library corresponding to the file descriptor to be closed includes:
[0122] Obtain a file descriptor record table, wherein the file descriptor record table includes at least one file descriptor and a creation dynamic link library corresponding to the file descriptor; obtain a target file descriptor that is the same as the file descriptor to be closed from the file descriptor record table, and use the creation dynamic link library corresponding to the target file descriptor as the creation dynamic link library corresponding to the file descriptor to be closed.
[0123] According to one or more embodiments of the present disclosure, the method further includes:
[0124] When it is determined that the information of closing the dynamic link library matches the information of creating the dynamic link library, the target file description and its corresponding dynamic link library creation are deleted from the file descriptor record table, and the file descriptor to be closed is closed.
[0125] According to one or more embodiments of the present disclosure, the method further includes:
[0126] When the startup of an application is detected, all dynamic link libraries corresponding to the application and the descriptor creation association function corresponding to each dynamic link library are obtained; for each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0127] According to one or more embodiments of the present disclosure, the method further includes:
[0128] When it is determined that an application is started or is in the process of running, if it is determined that there is a dynamic link library that is called for the first time in the dynamic link library corresponding to the application, the descriptor creation association function corresponding to the dynamic link library that is called for the first time is obtained; for each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0129] According to one or more embodiments of the present disclosure, the method further includes:
[0130] When it is determined that there is a dynamic link library calling a creation proxy function, a new file descriptor is created according to the proxy function, and the dynamic link library is used as the creation dynamic link library corresponding to the new file descriptor; information on the creation dynamic link library corresponding to the new file descriptor is obtained, and the new file descriptor and its corresponding creation dynamic link library information are added to the file descriptor record table.
[0131] According to one or more embodiments of the present disclosure, the method further includes:
[0132] When the application startup is detected, all dynamic link libraries corresponding to the application and the descriptor close associated function corresponding to each dynamic link library are obtained; for each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0133] According to one or more embodiments of the present disclosure, the method further includes:
[0134] When it is determined that an application is started or is in the process of running, if it is determined that there is a dynamic link library that is called for the first time in the dynamic link library corresponding to the application, the descriptor close associated function corresponding to the dynamic link library called for the first time is obtained; for each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0135] According to one or more embodiments of the present disclosure, the file descriptor closing operation is a dynamic link library calling a closing proxy function. When the file descriptor closing operation is detected, the file descriptor to be closed corresponding to the file descriptor closing operation and the information of closing the dynamic link library corresponding to the file descriptor to be closed are obtained, including:
[0136] When it is determined that there is a dynamic link library calling a closing proxy function, the file descriptor corresponding to the closing proxy function is used as the file descriptor to be closed, and the dynamic link library is used as the closing dynamic link library corresponding to the file descriptor to be closed; and the information of the closing dynamic link library corresponding to the file descriptor to be closed is obtained.
[0137] According to one or more embodiments of the present disclosure, the descriptor error closing information includes call stack information corresponding to the file descriptor to be closed, and the reporting of the file descriptor error closing information includes:
[0138] Report the call stack information corresponding to the file descriptor to be closed to the user terminal.
[0139] In a second aspect, according to one or more embodiments of the present disclosure, a file descriptor detection device is provided, including:
[0140] The information acquisition module is used to acquire the file descriptor to be closed corresponding to the file descriptor closing operation and the information of the closed dynamic link library corresponding to the file descriptor to be closed when a file descriptor closing operation is detected, and determine the information of creating a dynamic link library corresponding to the file descriptor to be closed;
[0141] The processing module is used to report file descriptor error closing information and close the file descriptor to be closed when it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library.
[0142] According to one or more embodiments of the present disclosure, the information about closing the dynamic link library includes an identifier for closing the dynamic link library, and the information about creating the dynamic link library includes an identifier for creating the dynamic link library, and the processing module is further configured to:
[0143] Determine whether the identifier of closing the dynamic link library is the same as the identifier of creating the dynamic link library; if the identifier of closing the dynamic link library is the same as the identifier of creating the dynamic link library, determine that the information of closing the dynamic link library matches the information of creating the dynamic link library; if the identifier of closing the dynamic link library is not the same as the identifier of creating the dynamic link library, determine that the information of closing the dynamic link library does not match the information of creating the dynamic link library.
[0144] According to one or more embodiments of the present disclosure, the information acquisition module is further used to:
[0145] Obtain a file descriptor record table, wherein the file descriptor record table includes at least one file descriptor and a creation dynamic link library corresponding to the file descriptor; obtain a target file descriptor that is the same as the file descriptor to be closed from the file descriptor record table, and use the creation dynamic link library corresponding to the target file descriptor as the creation dynamic link library corresponding to the file descriptor to be closed.
[0146] According to one or more embodiments of the present disclosure, the processing module is further configured to:
[0147] When it is determined that the information of closing the dynamic link library matches the information of creating the dynamic link library, the target file description and its corresponding dynamic link library creation are deleted from the file descriptor record table, and the file descriptor to be closed is closed.
[0148] According to one or more embodiments of the present disclosure, the processing module is further configured to:
[0149] When the startup of an application is detected, all dynamic link libraries corresponding to the application and the descriptor creation association function corresponding to each dynamic link library are obtained; for each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0150] According to one or more embodiments of the present disclosure, the processing module is further configured to:
[0151] When it is determined that an application is started or is in the process of running, if it is determined that there is a dynamic link library that is called for the first time in the dynamic link library corresponding to the application, the descriptor creation association function corresponding to the dynamic link library that is called for the first time is obtained; for each descriptor creation association function, the creation proxy function corresponding to the descriptor creation association function is obtained, and the descriptor creation association function is replaced with its corresponding creation proxy function.
[0152] According to one or more embodiments of the present disclosure, the processing module is further configured to:
[0153] When it is determined that there is a dynamic link library calling a creation proxy function, a new file descriptor is created according to the proxy function, and the dynamic link library is used as the creation dynamic link library corresponding to the new file descriptor; information on the creation dynamic link library corresponding to the new file descriptor is obtained, and the new file descriptor and its corresponding creation dynamic link library information are added to the file descriptor record table.
[0154] According to one or more embodiments of the present disclosure, the processing module is further configured to:
[0155] When the application startup is detected, all dynamic link libraries corresponding to the application and the descriptor close associated function corresponding to each dynamic link library are obtained; for each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0156] According to one or more embodiments of the present disclosure, the processing module is further configured to:
[0157] When it is determined that an application is started or is in the process of running, if it is determined that there is a dynamic link library that is called for the first time in the dynamic link library corresponding to the application, the descriptor close associated function corresponding to the dynamic link library called for the first time is obtained; for each descriptor close associated function, the close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
[0158] According to one or more embodiments of the present disclosure, the file descriptor closing operation is a dynamic link library calling a closing proxy function, and the information acquisition module is further used to:
[0159] When it is determined that there is a dynamic link library calling a closing proxy function, the file descriptor corresponding to the closing proxy function is used as the file descriptor to be closed, and the dynamic link library is used as the closing dynamic link library corresponding to the file descriptor to be closed; and the information of the closing dynamic link library corresponding to the file descriptor to be closed is obtained.
[0160] According to one or more embodiments of the present disclosure, the descriptor error closing information includes call stack information corresponding to the file descriptor to be closed, and the processing module is further used to:
[0161] Report the call stack information corresponding to the file descriptor to be closed to the user terminal.
[0162] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, comprising: at least one processor and a memory;
[0163] The memory stores computer-executable instructions;
[0164] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the file descriptor detection method described in the first aspect and various possible designs of the first aspect.
[0165] In a fourth aspect, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the file descriptor detection method described in the first aspect and various possible designs of the first aspect is implemented.
[0166] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0167] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0168] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A file descriptor detection method, It is characterized in that include: When a file descriptor closing operation is detected, obtaining a file descriptor to be closed corresponding to the file descriptor closing operation and information of a closed dynamic link library corresponding to the file descriptor to be closed, and determining information of a created dynamic link library corresponding to the file descriptor to be closed; the information of closing the dynamic link library includes an identifier of closing the dynamic link library; When it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library, file descriptor error closing information is reported, and the file descriptor to be closed is closed.
2. The method according to claim 1, It is characterized in that The information for creating a dynamic link library includes an identifier for creating a dynamic link library, and the method further includes: Determine whether the identifier for closing the dynamic link library is the same as the identifier for creating the dynamic link library; If the identifier of closing the dynamic link library is the same as the identifier of creating the dynamic link library, determining that the information of closing the dynamic link library matches the information of creating the dynamic link library; If the identifier of closing the dynamic link library is different from the identifier of creating the dynamic link library, it is determined that the information of closing the dynamic link library does not match the information of creating the dynamic link library.
3. The method according to claim 1, It is characterized in that The determining of the information for creating a dynamic link library corresponding to the file descriptor to be closed includes: Obtain a file descriptor record table, wherein the file descriptor record table includes at least one file descriptor and a creation dynamic link library corresponding to the file descriptor; A target file descriptor identical to the file descriptor to be closed is obtained from the file descriptor record table, and a creation dynamic link library corresponding to the target file descriptor is used as a creation dynamic link library corresponding to the file descriptor to be closed.
4. The method according to claim 3, It is characterized in that The method further comprises: When it is determined that the information of closing the dynamic link library matches the information of creating the dynamic link library, the target file description and its corresponding dynamic link library creation are deleted from the file descriptor record table, and the file descriptor to be closed is closed.
5. The method according to claim 1, It is characterized in that The method further comprises: When detecting that an application is started, obtaining all dynamic link libraries corresponding to the application and descriptors corresponding to each dynamic link library to create an association function; For each descriptor creation association function, obtain the creation proxy function corresponding to the descriptor creation association function, and replace the descriptor creation association function with its corresponding creation proxy function.
6. The method according to claim 1, It is characterized in that The method further comprises: When it is determined that the application is started or in the process of running, if it is determined that there is a dynamic link library called for the first time in the dynamic link library corresponding to the application, then a descriptor corresponding to the dynamic link library called for the first time is obtained to create an associated function; For each descriptor creation association function, obtain the creation proxy function corresponding to the descriptor creation association function, and replace the descriptor creation association function with its corresponding creation proxy function.
7. The method according to claim 5 or 6, It is characterized in that The method further comprises: When it is determined that there is a dynamic link library calling a creation proxy function, creating a new file descriptor according to the proxy function, and using the dynamic link library as a creation dynamic link library corresponding to the new file descriptor; The information of creating a dynamic link library corresponding to the new file descriptor is obtained, and the new file descriptor and the information of creating a dynamic link library corresponding to the new file descriptor and the new file descriptor are added to the file descriptor record table.
8. The method according to claim 1, It is characterized in that The method further comprises: When the application is detected to be started, all dynamic link libraries corresponding to the application and the descriptor corresponding to each dynamic link library are obtained to close the associated function; For each descriptor close associated function, a close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
9. The method according to claim 1, It is characterized in that The method further comprises: When it is determined that the application is started or in the process of running, if it is determined that there is a dynamic link library called for the first time in the dynamic link library corresponding to the application, then a descriptor closing associated function corresponding to the dynamic link library called for the first time is obtained; For each descriptor close associated function, a close proxy function corresponding to the descriptor close associated function is obtained, and the descriptor close associated function is replaced with its corresponding close proxy function.
10. The method according to claim 8 or 9, It is characterized in that The file descriptor closing operation is a dynamic link library calling a closing proxy function. When the file descriptor closing operation is detected, the file descriptor to be closed corresponding to the file descriptor closing operation and the information of closing the dynamic link library corresponding to the file descriptor to be closed are obtained, including: When it is determined that there is a dynamic link library calling a close proxy function, the file descriptor corresponding to the close proxy function is used as the file descriptor to be closed, and the dynamic link library is used as the close dynamic link library corresponding to the file descriptor to be closed; Obtain information about closing a dynamic link library corresponding to the file descriptor to be closed.
11. The method according to claim 1, It is characterized in that The descriptor error closing information includes call stack information corresponding to the file descriptor to be closed, and the reported file descriptor error closing information includes: Report the call stack information corresponding to the file descriptor to be closed to the user terminal.
12. A file descriptor detection device, It is characterized in that include: An information acquisition module, configured to, when a file descriptor closing operation is detected, acquire the file descriptor to be closed corresponding to the file descriptor closing operation and the information of closing the dynamic link library corresponding to the file descriptor to be closed, and determine the information of creating the dynamic link library corresponding to the file descriptor to be closed; the information of closing the dynamic link library includes an identifier of closing the dynamic link library; The processing module is used to report file descriptor error closing information and close the file descriptor to be closed when it is determined that the information for closing the dynamic link library does not match the information for creating the dynamic link library.
13. The device according to claim 12, It is characterized in that The information for creating a dynamic link library includes an identifier for creating a dynamic link library, and the processing module is further used for: Determine whether the identifier for closing the dynamic link library is the same as the identifier for creating the dynamic link library; If the identifier of closing the dynamic link library is the same as the identifier of creating the dynamic link library, determining that the information of closing the dynamic link library matches the information of creating the dynamic link library; If the identifier of closing the dynamic link library is different from the identifier of creating the dynamic link library, it is determined that the information of closing the dynamic link library does not match the information of creating the dynamic link library.
14. An electronic device, It is characterized in that include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the file descriptor detection method according to any one of claims 1 to 11.
15. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-executable instructions. When the processor executes the computer-executable instructions, the file descriptor detection method according to any one of claims 1 to 11 is implemented.
