File descriptor processing method and device and readable storage medium
By recording and comparing the execution unit that creates file descriptors and the execution unit that operates file descriptors, the problem of unexpected closing of file descriptors in multi-threaded or multi-process environments is solved, achieving safer and more reliable file descriptor management.
Patent Information
- Application Number
- CN202311174849.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-12
- Publication Date
- 2025-03-14
Smart Images

Figure CN119621659A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a method, device and readable storage medium for processing a file descriptor. Background Art
[0002] A file descriptor (FD) is an identifier used in the terminal's operating system to identify and track open files, sockets, and other input / output (I / O) resources.
[0003] In the related art, in a multi-threaded or multi-process environment without address isolation, if the execution unit such as a process or thread that operates a file descriptor is not the execution unit to which the file descriptor belongs, the file descriptor will be closed unexpectedly. Summary of the invention
[0004] In order to overcome the problems existing in the related art, the present disclosure provides a method, device and readable storage medium for processing a file descriptor.
[0005] According to a first aspect of an embodiment of the present disclosure, a method for processing a file descriptor is provided, comprising:
[0006] Record the first execution unit that creates the target file descriptor;
[0007] Determine whether the second execution unit of the current operation target file descriptor is the first execution unit;
[0008] In response to the second execution unit not being the first execution unit, an error message is displayed.
[0009] Optionally, the first execution unit has a first identifier, and the second execution unit has a second identifier; and determining whether the second execution unit of the current operation target file descriptor is the first execution unit includes:
[0010] Determine whether the second identifier is the first identifier.
[0011] Optionally, determining whether the second identifier is the first identifier includes:
[0012] Merging the target file descriptor and the first identifier to obtain fused data;
[0013] Restoring the fused data to obtain a first identifier and a target file descriptor;
[0014] Determine whether the second identifier is the first identifier.
[0015] Optionally, the fusing the target file descriptor and the first identifier to obtain fused data includes:
[0016] Transforming the binary information of the target file descriptor to obtain first transformed data;
[0017] Transforming the binary information of the first identifier to obtain second transformed data;
[0018] The first deformed data and the second deformed data are merged to obtain the merged data; wherein the positions occupied by the first preset character in the first deformed data and the second deformed data are complementary.
[0019] Optionally, the fusing the first deformation data and the second deformation data to obtain the fused data includes:
[0020] An OR operation is performed on the first deformation data and the second deformation data to obtain the fused data.
[0021] Optionally, the deforming the binary information of the target file descriptor to obtain the first deformed data includes: inserting a second preset character into the binary information of the target file descriptor, and clearing the target character at the head of the binary information of the target file descriptor to obtain the first deformed data;
[0022] The deforming the binary information of the first identifier to obtain the second deformed data includes: inserting the second preset character into the binary information of the first identifier, and clearing the target character at the head of the binary information of the first identifier to obtain the second deformed data.
[0023] Optionally, the restoring the fused data to obtain the first identifier and the target file descriptor includes:
[0024] Restoring the fused data to obtain second deformed data, where the second deformed data is data after the binary information of the first identifier is deformed;
[0025] The second deformed data is restored to obtain binary information of the first identifier.
[0026] Optionally, determining whether the second identifier is the first identifier includes:
[0027] Determine whether the binary information of the second identifier is the binary information of the first identifier.
[0028] Optionally, the method further comprises:
[0029] In response to the second execution unit being the first execution unit, the target file descriptor is processed by the second execution unit.
[0030] According to a second aspect of an embodiment of the present disclosure, a device for processing a file descriptor is provided, including:
[0031] A recording module configured to record a first execution unit that creates a target file descriptor;
[0032] A determination module, configured to determine whether the second execution unit of the current operation target file descriptor is the first execution unit;
[0033] The response module is configured to display an error message in response to the second execution unit not being the first execution unit.
[0034] According to a third aspect of an embodiment of the present disclosure, a device for processing a file descriptor is provided, including:
[0035] processor;
[0036] a memory for storing processor-executable instructions;
[0037] Wherein, the processor is configured to:
[0038] Execute the steps of the file descriptor processing method provided by the first aspect of the embodiment of the present disclosure.
[0039] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of the file descriptor processing method provided by the first aspect of the present disclosure are implemented.
[0040] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0041] On the first aspect, the present disclosure can display an error message when the first execution unit that creates the target file descriptor and the second execution unit that operates the target file descriptor are not the same execution unit, thereby avoiding the second execution unit operating the target file descriptor and accidentally closing the target file descriptor.
[0042] On the second aspect, the present application can reduce the workload of developers. Since the terminal can automatically record the first execution unit that creates the target file descriptor without the need to establish additional labels, the extra workload brought by developers in establishing labels can be reduced; and developers also do not need to additionally bind the label to the target file descriptor, that is, there is no need to establish a mapping relationship between the label and the target file descriptor, so the extra workload brought by developers in establishing the mapping relationship can be further reduced.
[0043] On the third aspect, the present disclosure can be applied in a multi-process environment without address isolation. Even if address isolation is not performed between multiple processes, the target file descriptor can be prevented from being misused in the multi-process environment without address isolation.
[0044] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0046] Figure 1 The present invention is a flowchart of a method for processing a file descriptor according to an exemplary embodiment.
[0047] Figure 2 The diagram is a schematic diagram showing two types of target file descriptors in a usage process according to an exemplary embodiment.
[0048] Figure 3 The diagram is a schematic diagram showing how to create a target file descriptor and use the target file descriptor using different interfaces according to an exemplary embodiment.
[0049] Figure 4 The figure is a schematic diagram of a scenario in which process B closes a target file descriptor according to an exemplary embodiment.
[0050] Figure 5 The figure is a schematic diagram of a scenario in which a process B closes a target file descriptor according to an exemplary embodiment.
[0051] Figure 6 The figure is a schematic diagram of a scenario in which a process B closes a target file descriptor according to an exemplary embodiment.
[0052] Figure 7 The invention is a block diagram of a device for processing a file descriptor according to an exemplary embodiment.
[0053] Figure 8 The invention is a block diagram of a device for processing a file descriptor according to an exemplary embodiment.
[0054] Fig. 9 The invention is a block diagram of a device for processing a file descriptor according to an exemplary embodiment. DETAILED DESCRIPTION
[0055] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0056] It should be noted that all actions of acquiring signals, information or data in the present disclosure are carried out in compliance with the relevant data protection laws and policies of the country where the device is located and with the authorization given by the owner of the corresponding device.
[0057] A file descriptor is an identifier used in the terminal's operating system to identify and track open files, sockets, and other input / output (I / O) resources. Applications can use file descriptors to identify and manage multiple open files or I / O resources. In simple terms, a file descriptor is an identifier assigned to a file by the operating system for the convenience of managing and operating files.
[0058] In the operating system, the following three file descriptors are commonly used:
[0059] Standard input file (stdin): The file descriptor is 0. The application identifies file descriptor 0 through the process and reads data from the standard input file corresponding to file descriptor 0.
[0060] Standard output file (stdout): The file descriptor is 1. The application identifies file descriptor 1 through the process and writes data to the standard output file corresponding to file descriptor 1.
[0061] Standard error file (stderr): The file descriptor is 2. The application identifies file descriptor 2 through the process and writes error data or information related to the error data to the standard error file corresponding to file descriptor 2.
[0062] Currently, if the ownership of the file descriptor is not handled correctly, the file descriptor will be closed unexpectedly. The main reasons for the unexpected closure of the file descriptor include:
[0063] (1) Failure to properly close file descriptors: After an application opens a file descriptor, it should close the file descriptor in a timely manner when it is no longer needed. If the application forgets to close the file descriptor, the file descriptor will remain open until the process ends or the file descriptor limit is reached. If too many file descriptors remain open, the terminal system may run out of resources, causing the file descriptor to be closed unexpectedly.
[0064] (2) Process exit or termination: When a process exits or is terminated, the operating system reclaims the file descriptors owned by the process. If the process does not close the file descriptors correctly when using them, the operating system will forcefully close these file descriptors, which may cause the file descriptors to be closed unexpectedly.
[0065] (3) File descriptor leak: When using dynamically allocated file descriptors in an application, resource leaks may occur. If a file descriptor is allocated but not released in time, it will cause a file descriptor leak, which may eventually cause the file descriptor to be closed unexpectedly.
[0066] (4) Concurrent access conflicts: In a multi-threaded or multi-process environment without address isolation, multiple execution units such as multiple threads or processes may operate the same file descriptor at the same time, which may cause concurrent access conflicts and cause the file descriptor to be accidentally closed. That is, the execution unit that creates the file descriptor is not the same as the execution unit that subsequently operates the file descriptor, which will cause the file descriptor to be accidentally closed. For example, the execution units include process A and process B. Process A creates file descriptor 10. Due to a code logic error and the lack of address isolation between processes, process A passes file descriptor 10 to process B for closing. If process B also happens to create file descriptor 10, process B will accidentally close the file corresponding to file descriptor 10, and the developer intends to close file descriptor 10 in process A, but accidentally closes file descriptor 10 in process B.
[0067] The unexpected closing of file descriptors can further lead to the following problems:
[0068] (1) Security vulnerability: A server is connected to multiple clients. Assuming that each client corresponds to a file descriptor, if the original old file descriptor is accidentally closed and the server generates a new file descriptor that is the same as the old file descriptor, the client may write data to the file corresponding to the new file descriptor instead of the file corresponding to the old file descriptor, resulting in file leakage and a security vulnerability.
[0069] (2) Program exception or crash: If the original old file descriptor is closed unexpectedly and the server generates a new file descriptor that is the same as the old file descriptor, the client may write illegal data into the file corresponding to the new file descriptor. After the execution unit operates the illegal data in the file corresponding to the new file descriptor, the program will fail or crash.
[0070] (3) Data corruption: If the original old file descriptor is closed unexpectedly and the server generates a new file descriptor that is the same as the old file descriptor, the client writes normal data to the file corresponding to the new file descriptor. Since the format of the written normal data is the same as the file format of the file corresponding to the old file descriptor, but the file format supported by the file corresponding to the new file descriptor is different, when the normal data is written to the file corresponding to the new file descriptor, the written normal data will be corrupted.
[0071] It can be seen that the accidental closing of the file descriptor will lead to the above three problems, and the present disclosure will focus on solving the above reason (4) that the concurrent access conflict leads to the accidental closing of the file descriptor.
[0072] In order to avoid the situation where multiple execution units operate a file descriptor at the same time and cause the file descriptor to be closed unexpectedly, a tag can be created for the file descriptor when the file descriptor is created, and the code can be set to indicate that the file descriptor belongs to the tag. When the execution unit closes the file descriptor, it can detect whether the tag corresponding to the current file descriptor is the tag to which the file descriptor belongs. If not, an error will be reported; if so, the execution unit will be allowed to close the current file descriptor.
[0073] For example, see Figure 2 As shown, in the case where a mapping relationship between a file descriptor and a tag is established, the execution unit will use the first interface android_fdsan_close_with_tag to identify whether the tag corresponding to the file descriptor is the tag to which the file descriptor belongs; in the case where a mapping relationship between a file descriptor and a tag is not established, the execution unit will use the second interface close to identify the file descriptor.
[0074] The workflow is as follows: Figure 3 , the execution unit will first create a file descriptor, then create a tag, and then bind the file descriptor to the tag to which it belongs, thereby forming a file descriptor mapping table. When the execution unit needs to close the file corresponding to the file descriptor, for the file descriptor without a tag, the execution unit identifies it through the second interface close. If the tag corresponding to the file descriptor is not 0, an error is reported; if the tag corresponding to the file descriptor is 0, the file descriptor is directly closed. For the file descriptor with a tag, the execution unit identifies it through the first interface android_fdsan_close_with_tag. If the tag corresponding to the file descriptor is not the tag to which it belongs, that is, the tag corresponding to the file descriptor is wrong, an error is reported; if the tag corresponding to the file descriptor is the tag to which it belongs, that is, the tag corresponding to the file descriptor is correct, the file descriptor will be closed.
[0075] However, in this solution, on the one hand, when creating a file descriptor, the developer not only needs to create a label, but also needs to establish the label to which the file descriptor belongs, that is, it is also necessary to establish a mapping relationship between the file descriptor and the label, which undoubtedly brings a large workload to the developer; on the other hand, due to the large number of file descriptors, the developer cannot bind the labels to all the file descriptors, so some file descriptors have labels to which they belong, while other file descriptors do not have labels to which they belong. For file descriptors without labels to which they belong, there will also be a situation where multiple execution units operate the same file descriptor at the same time, resulting in the file descriptor being accidentally closed.
[0076] Based on this, the present disclosure proposes a method for processing file descriptors. Figure 1 is a flowchart of a method for processing a file descriptor according to an exemplary embodiment. Figure 1 As shown, the method includes the following steps.
[0077] In step S11, the first execution unit that creates the target file descriptor is recorded.
[0078] The target file descriptor is used to describe, identify and track open files. The target file descriptor is usually a positive integer, such as 0, 1, 2, 3, 4, 5...1000, etc.
[0079] The first execution unit may be a thread or a process. A process is an execution instance in an operating system, a thread is an execution path in a process, and is the smallest unit for executing tasks in a process. A process may include multiple threads, which share the resources of the process and execute tasks concurrently.
[0080] Typically, developers assign a label to a target file descriptor when creating it. However, in the present disclosure, the terminal automatically records the first execution unit that creates the target file descriptor, i.e., automatically records the association between the target file descriptor and the first execution unit, without the need for the developer to additionally bind the label to which the target file descriptor belongs.
[0081] For example, if the first execution unit that creates the target file descriptor 5 is process A, the terminal will automatically associate the target file descriptor 5 with process A.
[0082] In step S12, it is determined whether the second execution unit of the current operation target file descriptor is the first execution unit.
[0083] The second execution unit currently operating the target file descriptor includes a second execution unit using the target file descriptor and a second execution unit closing the target file descriptor. The second execution unit using the target file descriptor can be an execution unit that writes data to the file corresponding to the target file descriptor or an execution unit that reads data from the file corresponding to the target file descriptor.
[0084] When multiple execution units execute concurrently, there may be a situation where multiple execution units operate the same target file descriptor at the same time. For example, process A and process B create target file descriptor 5 at the same time. Due to a code logic error, process A passes the target file descriptor 5 in process A to process B to perform a closing operation. Since the target file descriptors created by process A and process B are the same, process B will mistakenly close the target file descriptor 5 of process B.
[0085] The present disclosure may determine whether the second execution unit currently operating the target file descriptor is the first execution unit that created the target file descriptor. For example, process A passes the target file descriptor 5 to process B to perform a close operation, and the terminal will determine that it is process A that created the target file descriptor 5, and then determine whether it is process A that performs the close operation on the target file descriptor 5.
[0086] In step S13, in response to the second execution unit not being the first execution unit, an error message is displayed.
[0087] The error message is used to prompt the developer that the second execution unit operating the target file descriptor is not the first execution unit that created the target file descriptor, or to prompt the developer that the second execution unit fails to close the target file descriptor in the first execution unit.
[0088] Continuing with the example in step S12, process A and process B simultaneously create target file descriptor 5. Due to a code logic error, process A passes the target file descriptor 5 in process A to process B for closing operation. Since process A creates the target file descriptor 5, and process B currently closes the target file descriptor 5 in process A, an error will be reported, error information will be displayed, and process B is prohibited from operating the target file descriptor 5. Of course, process B processes the target file descriptor 5 in process B according to normal logic, for example, process B normally uses or closes the target file descriptor 5 in process B, so that the target file descriptor 5 in process B will not be accidentally closed.
[0089] Optionally, in response to the second execution unit being the first execution unit, the second execution unit may be allowed to process the target file descriptor. The second execution unit processing the target file descriptor includes but is not limited to: writing data to the file corresponding to the target file descriptor, reading data from the file corresponding to the target file descriptor, closing the file corresponding to the target file descriptor, etc.
[0090] Continuing with the example in step S12, when the process A creates the target file descriptor 5 and the process A currently performs the close operation on the target file descriptor 5, it means that the second execution unit operating the target file descriptor is the first execution unit that created the target file descriptor. At this time, the second execution unit can be allowed to process the target file descriptor.
[0091] In some cases, see Figure 4 As shown, process A and process B created a target file descriptor 10. When process A sends the target file descriptor 10 in process A to process B for closing, since process B operating the target file descriptor 10 is not process A that created the target file descriptor 10, an error will be reported, and process B will be prompted that closing the target file descriptor 10 of process A has failed.
[0092] See also Figure 5 As shown, process A and process B create a target file descriptor 10. When process B needs to close the target file descriptor 10 in process B, since the process that creates and closes the target file descriptor 10 is process B, the target file descriptor 10 can be successfully closed.
[0093] See also Figure 6 As shown, process A and process B created a target file descriptor 10. Based on the fact that process B has successfully closed the target file descriptor 10 created by itself, it is no longer possible to close the unexpected target file descriptor 10, for example, the unexpected target file descriptor 10 is sent by process A.
[0094] Through the above technical solution, the present invention can record the first execution unit that creates the target file descriptor, and determine whether the second execution unit that currently operates the target file descriptor is the first execution unit that creates the target file descriptor. If the two are not the same execution unit, the second execution unit is prohibited from operating the target file descriptor, and an error message is displayed.
[0095] In this scheme, on the one hand, the present disclosure can display an error message when the first execution unit that creates the target file descriptor and the second execution unit that operates the target file descriptor are not the same execution unit, thereby preventing the second execution unit from accidentally closing the target file descriptor it created; on the second hand, the present application can reduce the workload of developers, because the terminal can automatically record the first execution unit that creates the target file descriptor without the need to establish additional labels, so the additional workload brought by the developer to establish labels can be reduced; and the developer can also not need to additionally bind the label to the target file descriptor, that is, there is no need to establish a mapping relationship between the label and the target file descriptor, so the additional workload brought by the developer to establish the mapping relationship can be further reduced. On the third hand, the present disclosure can be applied in a multi-process environment without address isolation. Even if there is no address isolation between multiple processes, resulting in process A passing the target file descriptor to process B, the terminal can also determine that process B does not have the operation authority of the target file descriptor in process A and then report an error, so the present disclosure can prevent the target file descriptor from being misused in a multi-process environment without address isolation. Fourthly, since the present disclosure can avoid the accidental closing of the target file descriptor, it can further avoid the problems such as security vulnerabilities, program exceptions or crashes, data corruption, etc. caused by the accidental closing of the target file descriptor.
[0096] Some specific embodiments involved in the above steps S11 to S13 are introduced below.
[0097] Each different execution unit has its own identifier, for example, the first execution unit has a first identifier, and the second execution unit has a second identifier. Therefore, when determining whether the second execution unit that operates the target file descriptor is the first execution unit that creates the target file descriptor, the present disclosure determines whether the second identifier of the second execution unit that operates the target file descriptor is the same as the first identifier of the first execution unit that creates the target file descriptor. When the second identifier is the same as the first identifier, the second execution unit is considered to be the first execution unit. When the second identifier is different from the first identifier, the second execution unit is considered not to be the first execution unit. It specifically includes the following steps:
[0098] In step S21, the target file descriptor and the first identifier are fused to obtain fused data.
[0099] The fusion of the target file descriptor and the first identifier can be understood as combining the original target file descriptor and the first identifier into new fused data, in which the information of the target file descriptor and the first identifier is retained, so that the fused data obtained after different execution units create the target file descriptor are unique, thereby distinguishing different execution units that create the same target file descriptor.
[0100] For example, although the first identifier of process A and the second identifier of process B simultaneously create the target file descriptor 10, the fused data obtained by adding the target file descriptor 10 and the first identifier of process A is different from the fused data obtained by adding the target file descriptor 10 and the second identifier of process B.
[0101] Step S21 includes the following sub-steps:
[0102] Sub-step A1: transform the binary information of the target file descriptor to obtain first transformed data.
[0103] The purpose of deforming the binary information of the target file descriptor is to control the first preset character in the binary information of the target file descriptor to be in an odd position or an even position, and the purpose of deforming the binary information of the target file descriptor includes: inserting a second preset character into the binary information of the target file descriptor, and clearing the target character in the header of the binary information of the target file descriptor to obtain the first deformed data. The target character includes the second preset character.
[0104] The first deformed data is binary information transformed from the binary information of the target file descriptor, and the first preset character in the first deformed data occupies odd bits or even bits.
[0105] Inserting the second preset character into the binary information of the target file descriptor includes: inserting the second preset character between the first preset characters of the binary information of the target file descriptor, and / or inserting the second preset character at the end of the first preset character of the binary information of the target file descriptor.
[0106] In order to ensure that the data bits of the binary information of the target descriptor remain unchanged, for example, remain 32 bits, the number of the inserted second preset characters is equal to the number of target characters in the header of the binary information of the target file descriptor to be cleared. Clearing the target character in the header of the binary information of the target file descriptor can be understood as shifting the binary information of the target file descriptor to the left by N bits, and the number of N shifted to the left is equal to the number of the inserted second preset characters.
[0107]
[0108] Table 1
[0109] Refer to Table 1, taking the control of the first preset character in the first deformed data occupying an even number of bits as an example, the target file descriptor is 7, and the binary information corresponding to the target file descriptor is 00000000 0000000000000000 00000111, in which the head of the binary information is 0 on the left and the tail is 1 on the right. Insert the second preset character 0 into the first preset character 1 of the binary information of the target file descriptor 7, insert the second preset character 0 into the tail of the first preset character 1, and shift the binary information left by three bits (since the number of inserted 0s is three, shift left by three bits), and obtain the first deformed data 0000000000000000 00000000 00101010. In the first deformed data, from the tail to the head, it can be seen that the first preset character 1 occupies an even number of bits in the first deformed data.
[0110] Sub-step A2: deforming the binary information of the first identification to obtain second deformed data.
[0111] The purpose of deforming the binary information of the first identifier is to control the first preset character in the binary information of the first identifier to be in an odd position or an even position, and the position of the first preset character in the binary information of the first identifier is complementary to the position of the first preset character in the binary information of the target file descriptor. For example, if the position of the first preset character in the binary information of the target file descriptor is an even position, then the position of the first preset character in the binary information of the first identifier is an odd position, and vice versa. Deforming the binary information of the first identifier includes: inserting the second preset character into the binary information of the first identifier, and clearing the target character at the head of the binary information of the first identifier to obtain the second deformed data.
[0112] The second deformed data is binary information after the binary information of the first identifier is deformed, and the first preset character in the second deformed data occupies an odd number of bits or an even number of bits.
[0113] Inserting the second preset character into the binary information of the first identifier includes: inserting the second preset character between the first preset characters of the binary information of the first identifier, and inserting the second preset character at the end of the first preset character of the binary information of the first identifier.
[0114] In order to ensure that the data bits of the binary information of the first identifier remain unchanged, for example, maintained at 32 bits, the number of the inserted second preset characters is equal to the number of target characters in the header of the binary information of the first identifier to be cleared. Clearing the target characters in the header of the binary information of the first identifier can be understood as shifting the binary information of the first identifier to the left by N bits, and the number of N shifted to the left is equal to the number of the inserted second preset characters.
[0115]
[0116] Table 2
[0117] Refer to Table 2, taking the control of the first preset character in the second deformed data occupying an odd number of bits as an example, the first identifier is 7, and the binary information corresponding to the first identifier is 00000000 00000000 0000000000000111, in which the head is 0 and the tail is 1. The second preset character 0 is inserted into the first preset character 1 of the binary information of the first identifier 7, and the binary information is shifted left by two bits (since the number of inserted 0s is two, it is shifted left by two bits), and the second deformed data is 0000000000000000 00000000 00010101. In the second deformed data, from the order from the tail to the head, it can be seen that the first preset character 1 occupies an odd number of bits in the second deformed data.
[0118] By shaping the binary information of the target file descriptor to obtain the first deformed data, and shaping the binary information of the first identifier to obtain the second deformed data, the positions of the first preset characters in the first deformed data and the second deformed data can be made complementary. For example, the first preset character in the first deformed data is located at an odd position, and the first preset character in the second deformed data is located at an even position; for another example, the first preset character in the first deformed data is located at an even position, and the corresponding first preset character in the second deformed data is located at an odd position.
[0119] It can be understood that there is no limit on the number of second preset characters 0 inserted between two adjacent first preset characters 1. The above Tables 1 and 2 only show that the number of inserted second preset characters 0 is 1, and the number of inserted second preset characters 0 is determined according to whether the terminal controls the first deformation data and the second deformation data to be in an odd or even position.
[0120] For example, for the target file descriptor 3, its binary information is 00000000 0000000000000000000001010. If you want to control the first preset character 1 in the binary information to be in an even position, although the first preset character 1 in the binary information is in an even position, it is still necessary to insert the second preset character 0 so that the deformed data after deformation is 00000000 00000000 00000000 10001000, that is, the second preset character 1 in the deformed data after deformation is in an even position.
[0121] For another example, for the target file descriptor 240, its binary information is 00000000 0000000000000000000001011. If you want to control the first preset character 1 in the binary information to be in an even position, you need to insert the second preset character 0 so that the deformed data after deformation is 00000000 0000000000000000 10001010, that is, the second preset character in the deformed data after deformation is in an even position.
[0122] It can be seen that the number of 0s inserted into the second preset character in the binary information is determined according to the actual situation, and the ultimate purpose is to make the first preset character in the deformed data be in an even position or an odd position.
[0123] Sub-step A3: fusing the first deformed data and the second deformed data to obtain the fused data; wherein the positions occupied by the first preset character in the first deformed data and the second deformed data are complementary.
[0124] The fusion operation includes: performing an OR operation on the first deformation data and the second deformation data to obtain the fused data.
[0125] The OR operation means that if one of the two data is true, the result is true, and if all the data are false, the result is false. For example, if the data in the first deformed data is 1 and the data at the same position in the second deformed data is 0, then the data obtained after the final fusion is 1; if the data in the first deformed data is 0 and the data at the same position in the second deformed data is 0, then the data obtained after the final fusion is 0.
[0126] Continuing with the examples in the above sub-steps A1 and A2, the first deformed data is 000000000000000000000000 00101010, and the second deformed data is 00000000 000000000 00000000000010101. After the OR operation, the fused data obtained is 00000000 0000000000000000 00111111.
[0127] In step S22, the fused data is restored to obtain a first identifier and a target file descriptor.
[0128] Restoring the fused data includes: restoring the fused data to obtain second deformed data and first deformed data, wherein the second deformed data is the deformed data of the binary information of the first identifier, and the first deformed data is the deformed data of the binary information of the target file descriptor; restoring the second deformed data to obtain the binary information of the first identifier; restoring the first deformed data to obtain the binary information of the target file descriptor.
[0129] Take the example that the first preset character in the first deformed data occupies the even-numbered bits and the second preset character in the second deformed data occupies the odd-numbered bits. When restoring the fused data, the first preset character 1 in the even-numbered bits in the fused data is restored, the remaining blank data bits are filled with the second preset character 0, and the filled binary information is shifted right by N bits, thereby obtaining the first deformed data; the first preset character 1 in the odd-numbered bits in the fused data is restored, the remaining blank data bits are filled with the second preset character 0, and the filled binary information is shifted right by N bits, thereby obtaining the second deformed data.
[0130] It is understandable that since the binary information is shifted left by N bits in the process of obtaining the first deformed data and the second deformed data, when restoring the first deformed data and the second deformed data, the filled binary information needs to be shifted right by N bits to restore the first deformed data and the second deformed data.
[0131] In step S23, it is determined whether the second identifier is the first identifier.
[0132] Determining whether the second identifier is the first identifier includes: determining whether binary information of the second identifier is binary information of the first identifier.
[0133] For example, if the binary information of the first identifier of the first process that creates the target file descriptor after restoration is 00000000 00000000 00000000 00000111; and the binary information of the second identifier of the second process currently operating the target file descriptor is 00000000 00000000 0000000000000011, it can be determined that the second identifier is different from the first identifier, that is, the second process operating the target file descriptor is not the same process as the first process that creates the target file descriptor.
[0134] In the data processing process, binary information is usually identified, so when it is determined that the binary information of the second identifier is different from the binary information of the first identifier, it can be determined that the second identifier is not the first identifier, and an error can be reported at this time.
[0135] In the process of processing data by an execution unit such as a process or thread, the binary information of the target file descriptor is usually output as 32-bit data bits, and the value of the target file descriptor is usually within 1000, so many data bits in the binary information of the target file descriptor are the second preset character 0, and the number of data bits occupied by the first preset character 1 is relatively small. The present disclosure can use this feature to perform an OR operation on the first deformed data after the binary information of the target file descriptor is deformed and the second deformed data after the binary information of the first identifier is deformed to obtain fused data. Although the number of data bits occupied by the first preset character in the obtained fused data is more than before the fusion, it will not completely occupy all the 32-bit data bits, so that the fusion operation proposed by the present disclosure can be smoothly implemented.
[0136] Through the above technical solution, on the first hand, the first identifier and the second identifier in the present disclosure are inherent to the first execution unit and the second execution unit, for example, the first process has the first process identifier, and the second process has the second process identifier, which is already available without the need for additional configuration by the developer, thereby reducing the workload caused by additional configuration of the process identifier. On the second hand, after the first deformed data and the second deformed data are fused, what is presented to the developer is the fused data, not the target file descriptor, and the developer does not need to bind a label to the target file descriptor, which brings convenience to the developer. The program can automatically fuse the target file descriptor with the first identifier, and compare the second identifier with the restored first identifier, so that the developer can automatically detect whether the target file descriptor is misused without perception; on the third hand, after the developer binds the label to the target file descriptor, the mapping table between the two needs to be stored in additional storage space, but the present disclosure does not have such a mapping table, so it is naturally not necessary to store it, thereby saving storage space.
[0137] Figure 7 is a block diagram of a device for determining a file descriptor according to an exemplary embodiment. Figure 7 The file descriptor determination device 700 includes: a recording module 710, a determination module 720 and a response module 730.
[0138] A recording module 710, configured to record a first execution unit that creates a target file descriptor;
[0139] A determination module 720 is configured to determine whether the second execution unit of the current operation target file descriptor is the first execution unit;
[0140] The response module 730 is configured to display an error message in response to the second execution unit not being the first execution unit.
[0141] Optionally, the first execution unit has a first identifier, and the second execution unit has a second identifier; the determination module 720 includes:
[0142] The first determination submodule is configured to determine whether the second identifier is the first identifier.
[0143] Optionally, the first determining submodule includes:
[0144] A first fusion submodule is configured to fuse the target file descriptor with the first identifier to obtain fused data;
[0145] A first restoring submodule is configured to restore the fused data to obtain a first identifier and a target file descriptor;
[0146] The second determination submodule is configured to determine whether the second identifier is the first identifier.
[0147] Optionally, the first fusion submodule includes:
[0148] A first deformation submodule is configured to deform the binary information of the target file descriptor to obtain first deformation data;
[0149] A second deformation submodule is configured to deform the binary information of the first identifier to obtain second deformed data;
[0150] The second fusion submodule is configured to fuse the first deformation data and the second deformation data to obtain the fused data; wherein the positions occupied by the first preset character in the first deformation data and the second deformation data are complementary.
[0151] Optionally, the second fusion submodule includes:
[0152] The third fusion submodule is configured to perform an OR operation on the first deformation data and the second deformation data to obtain the fused data.
[0153] Optionally, the first deformation submodule includes:
[0154] The first processing submodule is configured to insert a second preset character into the binary information of the target file descriptor and clear the target character at the header of the binary information of the target file descriptor to obtain the first deformed data.
[0155] Optionally, the second deformation submodule includes:
[0156] The second processing submodule is configured to insert the second preset character into the binary information of the first mark, and clear the target character at the head of the binary information of the first mark to obtain the second deformed data.
[0157] Optionally, the first restoring submodule includes:
[0158] A second restoration submodule is configured to restore the fused data to obtain second deformed data, where the second deformed data is data after the binary information of the first identifier is deformed;
[0159] The third restoration submodule is configured to restore the second deformed data to obtain binary information of the first identifier.
[0160] Optionally, the first determining submodule includes:
[0161] The fourth determination submodule is configured to determine whether the binary information of the second identifier is the binary information of the first identifier.
[0162] Optionally, the file descriptor determination device 700 includes:
[0163] The processing module is configured to process the target file descriptor through the second execution unit in response to the second execution unit being the first execution unit.
[0164] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0165] The present disclosure also provides a computer-readable storage medium on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of the file descriptor processing method provided by the present disclosure are implemented.
[0166] Figure 8 8 is a block diagram of a device 800 for processing a file descriptor according to an exemplary embodiment. For example, the device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0167] Reference Figure 8 , the device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output interface 812 , a sensor component 814 , and a communication component 816 .
[0168] The processing component 802 generally controls the overall operation of the device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned file descriptor processing method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
[0169] The memory 804 is configured to store various types of data to support operations on the device 800. Examples of such data include instructions for any application or method operating on the device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0170] The power supply component 806 provides power to the various components of the device 800. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 800.
[0171] The multimedia component 808 includes a screen that provides an output interface between the device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0172] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the device 800 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.
[0173] The input / output interface 812 provides an interface between the processing component 802 and the peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0174] The sensor assembly 814 includes one or more sensors for providing various aspects of the status assessment of the device 800. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the device 800, and the sensor assembly 814 can also detect the position change of the device 800 or a component of the device 800, the presence or absence of user contact with the device 800, the orientation or acceleration / deceleration of the device 800, and the temperature change of the device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0175] The communication component 816 is configured to facilitate wired or wireless communication between the device 800 and other devices. The device 800 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0176] In an exemplary embodiment, the device 800 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to execute the above-mentioned file descriptor processing method.
[0177] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by the processor 820 of the device 800 to complete the above-mentioned file descriptor processing method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0178] In addition to being an independent electronic device, the above-mentioned device can also be a part of an independent electronic device. For example, in one embodiment, the device can be an integrated circuit (IC) or a chip, wherein the integrated circuit can be an IC or a collection of multiple ICs; the chip can include but is not limited to the following types: GPU (Graphics Processing Unit), CPU (Central Processing Unit), FPGA (Field Programmable Gate Array), DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), SOC (System on Chip, SoC), etc. The above-mentioned integrated circuit or chip can be used to execute executable instructions (or codes) to implement the above-mentioned file descriptor processing method. The executable instructions can be stored in the integrated circuit or chip, or can be obtained from other devices or equipment, such as the integrated circuit or chip includes a processor, a memory, and an interface for communicating with other devices. The executable instruction can be stored in the memory, and when the executable instruction is executed by the processor, the above-mentioned file descriptor processing method is implemented; alternatively, the integrated circuit or chip can receive the executable instruction through the interface and transmit it to the processor for execution, so as to implement the above-mentioned file descriptor processing method.
[0179] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above-mentioned file descriptor processing method when executed by the programmable device.
[0180] Fig. 9 is a block diagram of a device 900 for processing a file descriptor according to an exemplary embodiment. For example, the device 900 may be provided as a server. Fig. 9 , the device 900 includes a processing component 922, which further includes one or more processors, and a memory resource represented by a memory 932 for storing instructions that can be executed by the processing component 922, such as an application. The application stored in the memory 932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 922 is configured to execute instructions to perform the above-mentioned file descriptor processing method.
[0181] The device 900 may also include a power supply component 926 configured to perform power management of the device 900, a wired or wireless network interface 950 configured to connect the device 900 to a network, and an input / output interface 958. The device 900 may operate based on an operating system stored in the memory 932.
[0182] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0183] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for processing a file descriptor, characterized in that: include: Record the first execution unit that creates the target file descriptor; Determine whether the second execution unit of the current operation target file descriptor is the first execution unit; In response to the second execution unit not being the first execution unit, an error message is displayed.
2. The method according to claim 1, characterized in that The first execution unit has a first identifier, and the second execution unit has a second identifier; and determining whether the second execution unit of the current operation target file descriptor is the first execution unit includes: Determine whether the second identifier is the first identifier.
3. The method according to claim 2, characterized in that The determining whether the second identifier is the first identifier includes: Merging the target file descriptor and the first identifier to obtain fused data; Restoring the fused data to obtain a first identifier and a target file descriptor; Determine whether the second identifier is the first identifier.
4. The method according to claim 3, characterized in that The step of fusing the target file descriptor with the first identifier to obtain fused data includes: Transforming the binary information of the target file descriptor to obtain first transformed data; Transforming the binary information of the first identifier to obtain second transformed data; The first deformed data and the second deformed data are merged to obtain the merged data; wherein the positions occupied by the first preset character in the first deformed data and the second deformed data are complementary.
5. The method according to claim 4, characterized in that The fusing the first deformation data and the second deformation data to obtain the fused data includes: An OR operation is performed on the first deformation data and the second deformation data to obtain the fused data.
6. The method according to claim 4, characterized in that The step of deforming the binary information of the target file descriptor to obtain the first deformed data includes: inserting a second preset character into the binary information of the target file descriptor, and clearing the target character at the head of the binary information of the target file descriptor to obtain the first deformed data; The deforming the binary information of the first identifier to obtain the second deformed data includes: inserting the second preset character into the binary information of the first identifier, and clearing the target character at the head of the binary information of the first identifier to obtain the second deformed data.
7. The method according to claim 3, characterized in that The restoring the fused data to obtain a first identifier and a target file descriptor includes: Restoring the fused data to obtain second deformed data, where the second deformed data is data after the binary information of the first identifier is deformed; The second deformed data is restored to obtain binary information of the first identifier.
8. The method according to claim 2, characterized in that: The determining whether the second identifier is the first identifier includes: Determine whether the binary information of the second identifier is the binary information of the first identifier.
9. The method according to claim 1, characterized in that: The method further comprises: In response to the second execution unit being the first execution unit, the target file descriptor is processed by the second execution unit.
10. A file descriptor processing device, characterized in that: include: A recording module configured to record a first execution unit that creates a target file descriptor; A determination module, configured to determine whether the second execution unit of the current operation target file descriptor is the first execution unit; The response module is configured to display an error message in response to the second execution unit not being the first execution unit.
11. A file descriptor processing device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to: Execute the steps of the method according to any one of claims 1 to 9.
12. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the steps of the method described in any one of claims 1 to 9 are implemented.