Data access method and apparatus
By calculating the check factor of reference variables in the WebAssembly virtual machine runtime system, the storage area address and attribute information are ensured to be protected from unauthorized modification, thus solving the problem of unauthorized data access by applications and improving the security and reliability of data access.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING TONGFANG MICROELECTRONICS
- Filing Date
- 2023-11-28
- Publication Date
- 2026-05-01
AI Technical Summary
In a WebAssembly-based virtual machine operating system, an application's unauthorized modification of the storage address information of reference variables may lead to data access failures or unauthorized access to data from other applications, affecting the security and reliability of data access.
By calculating the first and second check factors associated with the referenced variables, it is ensured that the storage address and basic attribute information of the referenced variables are not illegally modified during the application's operation, and data access is only allowed when the check factors are consistent.
It improves the security and reliability of data access, and reduces data access errors and illegal data acquisition caused by unauthorized modification of reference variables.
Smart Images

Figure CN117573290B_ABST
Abstract
Description
Data access methods and apparatus Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data access method and apparatus. Background Technology
[0002] Currently, WebAssembly-based runtime systems can be deployed in resource-constrained chips or devices. WebAssembly-based runtime systems provide a runtime environment for applications, and the WebAssembly virtual machine interprets and executes the application's bytecode.
[0003] During application installation or runtime, the application requests data storage space from the runtime system by calling the interfaces provided by the WebAssembly virtual machine's runtime environment. Based on the storage address corresponding to the allocated data storage space, the runtime system constructs a reference variable for the application, recording address information related to the storage address of that data storage space. This allows the application to update the corresponding reference variable's data content based on its value. Therefore, when the application needs to access data stored within that data storage space, the WebAssembly virtual machine can access the data based on the address information in the reference variable provided by the application.
[0004] However, during application runtime, the application can modify this reference variable. Therefore, if the application illegally modifies the address information related to the data storage space in this reference variable, the WebAssembly virtual machine may be unable to accurately locate the application's corresponding data storage space based on the address information in the reference variable. This could not only lead to data access failures but also potentially send data from other applications' data storage spaces to that application, resulting in unauthorized access to other applications' data and compromising the security and reliability of data access. Summary of the Invention
[0005] This application provides a data access method and apparatus to improve the security and reliability of data access in a WebAssembly virtual machine-based operating system.
[0006] On the one hand, this application provides a data access method applied to a WebAssembly virtual machine-based operating system, the method comprising:
[0007] Obtain a data access instruction initiated by the application, the data access instruction carrying first variable data of a reference variable, the first variable data of the reference variable being used to indicate the data address of the target data to be accessed;
[0008] Based on the storage area identification information recorded in the first variable data of the referenced variable, the storage area address of the data storage area corresponding to the application is determined, and the storage area identification information is used to identify the data storage area corresponding to the application.
[0009] Based on the storage area address, obtain the basic attribute information recorded in the data storage area, the basic attribute information including the attribute information associated with the data storage area and the application;
[0010] Obtain the first verification factor associated with the reference variable. The first verification factor is calculated by the running system based on the storage area address and basic attribute information of the data storage area during the process of generating variable data corresponding to the reference variable for the application.
[0011] Based on the aforementioned basic attribute information and storage area address, calculate the second verification factor;
[0012] If the first check factor is the same as the second check factor, the target data is obtained from the data storage area based on the first variable data of the reference variable and the storage area address.
[0013] In one possible implementation, obtaining the first check factor associated with the reference variable includes at least one of the following:
[0014] Obtain the first verification factor from the first variable data of the referenced variable;
[0015] The first verification factor associated with the reference variable is obtained from the attribute storage area of the data storage area, wherein the attribute storage area is a storage area used to store the basic attribute information.
[0016] In yet another possible implementation, after receiving the data access instruction initiated by the application, the following is also included:
[0017] Obtain the storage area type identifier from the first variable data of the referenced variable. The storage area type identifier belongs to one of a first type identifier and a second type identifier. The first type identifier indicates that the storage capacity of the data storage area corresponding to the application is not less than a set threshold, and the second type identifier indicates that the storage capacity of the data storage area is less than the set threshold.
[0018] The step of obtaining the first verification factor from the first variable data of the referenced variable includes:
[0019] If the storage area type identifier is a first type identifier, obtain the first verification factor from the first variable data of the referenced variable;
[0020] The step of obtaining the first verification factor associated with the reference variable from the attribute storage area of the data storage area includes:
[0021] If the storage area type identifier is a second type identifier, obtain the first verification factor associated with the reference variable from the attribute storage area of the data storage area;
[0022] The first verification factor is calculated based on the storage area address, basic attribute information and storage area type identifier of the data storage area;
[0023] The calculation of the second verification factor based on the basic attribute information and storage area address includes:
[0024] The second verification factor is calculated based on the basic attribute information, storage area address, and storage area type identifier.
[0025] In another possible implementation, determining the storage address of the data storage area corresponding to the application based on the storage area identifier information recorded in the first variable data of the referenced variable includes:
[0026] If the storage area type identifier is a first type identifier, obtain the address index recorded in the first variable data of the referenced variable, and determine the storage area address of the data storage area corresponding to the application based on the address index. The address index is used to indicate the storage location of the storage area address of the data storage area in the address storage table.
[0027] If the storage area type identifier is a second type identifier, obtain the offset information recorded in the first variable data of the referenced variable, and determine the storage area address of the data storage area based on the offset information. The offset information is used to characterize the relative offset address of the storage area address of the data storage area relative to the starting address of the total space, where the starting address of the total space is the starting address of the total storage space of the running system.
[0028] In another possible implementation, obtaining the offset information recorded in the first variable data of the referenced variable, and determining the storage address of the data storage area based on the offset information, includes:
[0029] Obtain the first offset information and the second offset information recorded in the first variable data of the referenced variable, wherein the first offset information is the remainder obtained by dividing the relative offset address by the target number of bytes, and the second offset information is the quotient obtained by dividing the relative offset address by the target number of bytes;
[0030] Based on the first offset information and the second offset information, the relative offset address corresponding to the data storage area is determined;
[0031] The storage area address of the data storage area is determined based on the relative offset address.
[0032] In another possible implementation, the first variable data of the referenced variable includes the data offset address of the target data in the data storage area corresponding to the application.
[0033] If the first check factor is the same as the second check factor, retrieving the target data from the data storage area based on the first variable data of the referenced variable and the storage area address includes:
[0034] If the first check factor is the same as the second check factor, the target data is obtained from the data storage area based on the data offset address and the storage area address.
[0035] In yet another possible implementation, prior to obtaining the application-initiated data access instruction, the following is also included:
[0036] Obtain the storage area request initiated by the application, which is used to request storage space with a target storage capacity to be allocated to the application;
[0037] Based on the target storage capacity, a data storage area is created for the application, and a storage area type identifier corresponding to the data storage area is determined. The attribute storage area of the data storage area records basic attribute information associated with the data storage area and the application. If the target storage capacity is not less than a set threshold, the storage area type identifier is a first type identifier; if the target storage capacity is less than the set threshold, the storage area type identifier is a second type identifier.
[0038] Based on the storage area address of the data storage area, determine the storage area identification information of the data storage area;
[0039] Calculate the first verification factor based on the storage area address, basic attribute information, and storage area type identifier;
[0040] If the target storage capacity is not less than a set threshold, construct second variable data for the application's reference variables, including the storage area type identifier, the first check factor, and the storage area identifier information;
[0041] If the target storage capacity is less than a set threshold, construct third variable data including the storage area type identifier and storage area identifier information for the application's reference variables, and store the first verification factor in the attribute storage area of the data storage area.
[0042] In another possible implementation, determining the storage area identification information of the data storage area based on the storage area address of the data storage area includes:
[0043] If the target storage capacity is not less than a set threshold, the storage address of the data storage area is stored in the address storage table, and the address index of the storage area address in the address storage table is determined. The address index is used to indicate the storage location of the storage area address in the address storage table.
[0044] If the target storage capacity is less than a set threshold, the offset information corresponding to the storage area address of the data storage area is determined. The offset information is used to characterize the relative offset address of the storage area address of the data storage area relative to the starting address of the total space. The starting address of the total space is the starting address of the total storage space of the running system.
[0045] If the target storage capacity is not less than a set threshold, a second variable data is constructed for the application's reference variables, including the storage area type identifier, a first check factor, and storage area identifier information, comprising:
[0046] If the target storage capacity is not less than a set threshold, construct second variable data for the application's reference variables, including the storage area type identifier, a first check factor, and an address index;
[0047] If the target storage capacity is less than a set threshold, a third variable data is constructed for the application's reference variables, including the storage area type identifier and storage area identifier information, including:
[0048] If the target storage capacity is less than a set threshold, construct third variable data for the application's reference variables, including the storage area type identifier and offset information.
[0049] In another possible implementation, determining the offset information corresponding to the storage area address of the data storage area if the target storage capacity is less than a set threshold includes:
[0050] If the storage capacity is less than a set threshold, determine the relative offset address of the storage area address of the data storage area relative to the starting address of the total space;
[0051] Determine the quotient and remainder obtained by dividing the relative offset address by the target number of bytes, and determine the remainder as the first offset information and the quotient as the second offset information;
[0052] If the target storage capacity is less than a set threshold, a third variable data is constructed for the application's reference variable, including the storage area type identifier and offset information, comprising:
[0053] If the target storage capacity is less than a set threshold, a third variable data is constructed for the application's reference variable, including the storage area type identifier, first offset information, and second offset information.
[0054] Furthermore, this application also provides a data access device applied to a WebAssembly virtual machine-based operating system, the device comprising:
[0055] An instruction acquisition unit is used to acquire a data access instruction initiated by an application, wherein the data access instruction carries first variable data of a reference variable, and the first variable data of the reference variable is used to indicate the data address of the target data to be accessed.
[0056] The address determination unit is used to determine the storage area address of the data storage area corresponding to the application based on the storage area identification information recorded in the first variable data of the referenced variable, wherein the storage area identification information is used to identify the data storage area corresponding to the application.
[0057] An attribute acquisition unit is used to acquire basic attribute information recorded in the data storage area based on the storage area address. The basic attribute information includes attribute information associated with the data storage area and the application.
[0058] The factor acquisition unit is used to acquire the first verification factor associated with the reference variable. The first verification factor is calculated by the running system based on the storage area address and basic attribute information of the data storage area during the process of generating variable data corresponding to the reference variable for the application.
[0059] The first factor calculation unit is used to calculate the second verification factor based on the basic attribute information and the storage area address;
[0060] A data acquisition unit is configured to acquire the target data from the data storage area based on the first variable data of the reference variable and the storage area address if the first verification factor is the same as the second verification factor.
[0061] As can be seen from the above, in this application, after the operating system allocates a data storage area for the application, during the process of generating variable data for reference variables related to that data storage area, a first verification factor associated with the reference variable is calculated based on the basic attribute information stored in the data storage area and the storage area address corresponding to that data storage area. Based on this, since the basic attribute information and storage area address corresponding to the data storage area are fixed, if the application does not illegally modify the storage area identifier information of the data storage area in the reference variable during operation, then after the application initiates a data access instruction carrying the reference variable, the storage area address determined based on the storage area identifier information in the variable data of that reference variable is the actual storage area address of that data storage area. Correspondingly, the second verification factor calculated based on the storage area address and basic attribute information must be consistent with the first verification factor. Therefore, the target data will only be retrieved from the data storage area when the first and second verification factors are the same. This reduces the possibility of data access errors or illegal acquisition of data from other applications due to the application illegally modifying the storage area identifier information in the reference variable, thus improving the reliability and security of data access. Attached Figure Description
[0062] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0063] Figure 1 shows a schematic flowchart of a data access method provided in an embodiment of this application;
[0064] Figure 2 illustrates a schematic diagram of an implementation process for allocating data storage area and constructing variable data for reference variables in an embodiment of this application;
[0065] Figure 3 shows a schematic diagram of the composition structure of a reference variable;
[0066] Figure 4 shows a schematic diagram of the composition structure of a reference variable in an embodiment of this application;
[0067] Figure 5 shows another schematic diagram of the composition structure of the referenced variables in the embodiments of this application;
[0068] Figure 6 illustrates another implementation flow diagram of allocating data storage area and constructing variable data for reference variables in an embodiment of this application;
[0069] Figure 7 shows another schematic flowchart of a data access method provided in an embodiment of this application;
[0070] Figure 8 shows a schematic diagram of the composition structure of a data access device provided in an embodiment of this application. Detailed Implementation
[0071] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0072] Figure 1 shows a flowchart of a data access method provided in an embodiment of this application. The method in this embodiment is applied to a running system based on a WebAssembly virtual machine.
[0073] WebAssembly (Wasm for short) is a binary format. The runtime system based on the WebAssembly virtual machine is the runtime system corresponding to an embedded operating system based on the WebAssembly virtual machine. This runtime system includes the WebAssembly virtual machine and its corresponding runtime environment. Within this runtime system, the WebAssembly virtual machine can run the bytecode of applications written in WebAssembly using the runtime environment.
[0074] WebAssembly virtual machine-based operating systems are typically deployed on resource-constrained devices, which are chips or devices with limited computing power, power consumption, or storage capacity.
[0075] The data access method in this embodiment may include:
[0076] S101, Receive data access instruction initiated by the application.
[0077] The data access instruction carries the first variable data of the reference variable, which is used to indicate the data address of the target data to be accessed.
[0078] Among them, the reference variable is a variable used in the application to record the data storage area of the application and the address of the data to be accessed in that data storage area.
[0079] As can be understood, the variable data of a reference variable is essentially the data content of the reference variable, also known as its numerical value. When an application requests data storage from the runtime system based on the WebAssembly virtual machine, the runtime system determines an initial value for the reference variable for the application. The application then assigns a value to the reference variable based on this initial value. During application execution, it can legally modify the data address associated with the data to be accessed within the reference variable, thus ensuring that the variable data sent by the application when requesting data access is not entirely identical to the variable data generated by the runtime system for the application.
[0080] Therefore, for ease of distinction, the variable data of the referenced variable carried in the data access instruction initiated by the application is called the first variable data, while the variable data of the referenced variable subsequently generated by the running system for the application is called the second variable data or the third variable data.
[0081] Understandably, in a runtime system based on the WebAssembly virtual machine, the WebAssembly virtual machine can respond to data access instructions initiated by the application, obtain the data required by the application, and return it to the application.
[0082] S102, based on the storage area identifier information recorded in the first variable data of the referenced variable, determine the storage area address of the data storage area corresponding to the application.
[0083] Understandably, the WebAssembly virtual machine-based runtime system allocates different data storage areas to different applications. To distinguish the data storage areas corresponding to different applications, the WebAssembly virtual machine-based runtime system records the storage area identifier information of the data storage area corresponding to the application in the application's reference variable. Accordingly, the first variable data of this reference variable will include the storage area identifier information.
[0084] This storage area identifier is used to identify the data storage area corresponding to the application. However, this storage area identifier is different from the storage area address of the data storage area, where the storage area address can be the starting address of the data storage area.
[0085] In this application, the storage area identification information recorded in the reference variable can have several possible cases.
[0086] For example, in one possible scenario, the storage area identification information recorded in the first variable data of the referenced variable could be an address index. This address index indicates the storage location of the storage area address corresponding to the application's data storage area in the address storage table. For instance, the address index could be the sequence number of the data storage area address in the address storage table. This address storage table is used to record the storage area addresses of data storage areas for different applications.
[0087] In this possible scenario, after obtaining the address index from the first variable data of the referenced variable, the storage area address corresponding to the data storage area of the application can be queried from the address storage table based on the address index.
[0088] In another possible scenario, the storage area identification information recorded in the first variable data of the referenced variable can be the offset information corresponding to the application's data storage area. This offset information is used to characterize the relative offset address corresponding to the storage area address of the data storage area. Here, the relative offset address corresponding to the storage area address of the data storage area refers to the offset address of the data storage area address relative to the starting address of the total storage space in the running system. For ease of distinction, the starting address of the total storage space of the running system can also be called the total space starting address.
[0089] The offset information can be the relative offset address. Based on this, and using the relative offset address and the starting address of the total storage space in the running system, the storage address of the application's data storage area can be determined.
[0090] In an alternative approach, to represent the storage address corresponding to the data storage area using fewer bits, the offset information in this application may further include first offset information and second offset information. The first offset information is the remainder obtained by dividing the relative offset address corresponding to the data storage area by the target number of bytes. The second offset information is the quotient obtained by dividing the relative offset address corresponding to the data storage area by the target number of bytes.
[0091] The target number of bytes can be determined by combining the number of bits in the reference variable that can be used to record the address information of the data storage area, and there is no specific restriction. For example, considering that the range that can be addressed by 2 bytes (16 bits) in the memory chip is 64K, the target number of bytes can be 64K.
[0092] Understandably, dividing the relative offset address of the data storage area by the target number of bytes results in a relatively small number of bits in the quotient and remainder. Therefore, using the remainder as the first offset information and the quotient as the second offset information reduces the number of bits occupied by the first and second offset information in the reference variable. Furthermore, the relative offset address of the data storage area can be derived from the first and second offset information, allowing the storage address of the data storage area to be determined based on the relative offset address of the data storage area and the starting address of the total storage space of the running system.
[0093] In practical applications, one of the two possible scenarios for the above storage area identification information can be selected as needed, or the two scenarios can be used in combination, without any restrictions.
[0094] S103, based on the storage area address, obtain the basic attribute information of the record in the data storage area.
[0095] This basic attribute information includes attribute information associated with the data storage area and the application. These basic attribute information are inherent properties of the data storage area and the application, and remain unchanged during application execution.
[0096] For example, basic attribute information may include: the storage capacity of the data storage area (i.e., the size of the data storage area), the information of the application to which the data storage area belongs (e.g., the name or identifier of the application), the data type used by the data generated during the operation of the application stored in the data storage area, and information such as the randomly generated random factor.
[0097] It's understandable that an application's data storage is divided into two parts: an attribute storage area and a data body storage area. The attribute storage area, also known as the header, stores basic storage information; therefore, this basic attribute information is also called header information. The data body storage area stores data generated during application execution; therefore, the data stored in this area is also the data that the application needs to read during runtime.
[0098] S104, obtain the first check factor associated with the reference variable.
[0099] The first verification factor is calculated by the WebAssembly virtual machine-based operating system based on the storage area address and basic attribute information of the data storage area during the process of generating variable data related to the referenced variable for the application.
[0100] As mentioned earlier, after allocating a data storage area for the application, the runtime system based on the WebAssembly virtual machine needs to record the address information related to that data storage area into the corresponding reference variables of the application. Before the application runs, the variable data (i.e., the value) of this reference variable is empty or a default value. Therefore, in order to assign a value to this reference variable in the application, the runtime system needs to construct a reference variable containing the address information related to that data storage area, that is, generate the variable data of the reference variable, so that the application can assign a value to the reference variable in the application based on the variable data of the reference variable generated by the runtime system.
[0101] In this application, the specific data structure of the referenced variables and the specific implementation method by which the operating system determines the value of the referenced variables can have various possibilities, and this application does not impose any restrictions on them. Several possible cases will be illustrated later, and will not be elaborated further here.
[0102] It is understandable that the application may modify the data of the reference variable during runtime. For example, during application runtime, based on the data storage address of the data stored in the data storage area, the application may modify the data offset address in the reference variable corresponding to that data storage address. However, as described in the background section, if the application illegally modifies the address information related to the address of the data storage area in the reference variable, it will lead to abnormal data readings subsequently, potentially resulting in the illegal reading of data from other applications. Therefore, to verify whether the application has modified the address information related to the data storage area in the reference variable, this application adds a verification factor related to the reference variable.
[0103] To distinguish it from the verification factor generated in the verification phase in subsequent step S105, the verification factor determined during the process of generating the variable data of the reference variable for the application by the running system is called the first verification factor, while the verification factor generated in the verification phase is called the second verification factor.
[0104] It is understandable that, given a fixed data storage area allocated to an application, the storage address and basic attribute information of that data storage area are fixed and will not change as the application runs. In this application, the first verification factor is associated with the storage address corresponding to the application's data storage area. Therefore, if the application illegally modifies the storage area identifier information recorded in the reference variable, the storage address determined based on the storage area identifier information recorded in the reference variable will no longer be the actual storage address of the application's data storage area. Consequently, the verification factor subsequently determined based on this storage address will inevitably be inconsistent with the first verification factor.
[0105] Furthermore, since the reference variable records the storage area identifier information of the data storage area, which is different from the storage area address, the application generally cannot obtain the storage area address of the data storage area based on the storage area identifier information. Therefore, it cannot forge or reconstruct the first check factor. Additionally, even if the application obtains the storage area address of its data storage area through illegal means, it cannot obtain the basic attribute information stored in the data storage area. For example, the application cannot obtain the capacity of the data storage area. Even if it could obtain the capacity, it would be impossible to determine the random factor contained in the basic attribute information, thus greatly reducing the risk of the first check factor being cracked.
[0106] In this application, there are various possible implementations for calculating the first check factor based on the basic attribute information and the storage area address, and this application does not impose any restrictions on these implementations. For example, this application can calculate the first check factor based on the basic attribute information and the storage area address using a checksum algorithm, such as XOR, or a checksum algorithm like Cyclic Redundancy Check (CRC), and there are no restrictions on these implementations.
[0107] Understandably, in practical applications, the calculation of the first check factor can consider other parameters related to the data storage area or its address, in addition to the basic attribute information and the storage area address; there are no restrictions on this. For example, in one possible implementation, the first check factor can also be calculated based on the basic attribute information, the storage area address, and the storage area's identifier information.
[0108] S105, calculate the second check factor based on the basic attribute information and the storage area address.
[0109] In this application, the algorithm used to calculate the second check factor is the same as the algorithm used to calculate the first check factor. For example, if the first check factor is calculated using the CRC algorithm based on attribute information and storage area address, the second check factor can also be calculated using the CRC algorithm; details will not be elaborated further.
[0110] In one alternative approach, provided that the first verification factor is calculated based on the basic attribute information, the storage area address, and the storage area identification information, this application may also calculate the second verification factor based on the basic attribute information, the storage area address, and the storage area identification information in the reference variable.
[0111] S106, if the first check factor is the same as the second check factor, the target data is obtained from the data storage area based on the first variable data and the storage area address of the reference variable.
[0112] As we can see from the previous introduction, if the storage area identification information in the reference variable has not been illegally modified by the application, then the storage area address determined based on the storage area identification information is the actual storage address corresponding to the application's storage area. Based on this, the second check factor calculated based on the storage area address and basic attribute information must be the same as the first check factor.
[0113] Based on this, when the second verification factor is the same as the first verification factor, the running system can determine that the storage area address identifier in the first variable data of the referenced variable sent by the application has not been illegally modified. Therefore, the storage area address can be determined based on the storage area identifier, and the target data can be obtained from the data storage area pointed to by the storage area address.
[0114] In this application, the first variable data of the reference variable can be used to indicate the data address of the target data to be accessed. Therefore, based on the first variable data of the reference variable and the storage area address, the target data can be obtained from the data storage area.
[0115] In this application, there are no restrictions on the specific implementation method of the variable data indicating the data address of the target data.
[0116] In one possible implementation, the first variable data referencing the variable may include the data offset address of the target data to be accessed by the application within the data storage area corresponding to the application. This data offset address is the offset address of the target data's data storage address within that data storage area relative to the storage area address of that data storage area.
[0117] Accordingly, after obtaining the data offset address from the first variable data of the referenced variable, the target data can be retrieved from the data storage area based on the data offset address and the storage area address of the data storage area. For example, the data storage address of the target data in the data storage area can be determined based on the data offset address and the storage area address of the data storage area, and the target data can be retrieved from the data storage area based on that data storage address.
[0118] It is understood that this application can read target data from the data storage area based on the data offset address recorded in the variable data of the reference variable and the storage area address of the data storage area. Determining the target data to be accessed from the data storage area based on the data offset address and the data storage address is essentially a data access process based on pointers and other methods, thereby realizing quick access to application data by combining pointers, array subscripts or structure member references.
[0119] As can be seen from the above, in this application, after the operating system allocates a data storage area for the application, during the process of generating variable data for reference variables related to that data storage area, a first verification factor associated with the reference variable is calculated based on the basic attribute information stored in the data storage area and the storage area address corresponding to that data storage area. Based on this, since the basic attribute information and storage area address corresponding to the data storage area are fixed, if the application does not illegally modify the storage area identifier information of the data storage area in the reference variable during operation, then after the application initiates a data access instruction carrying the reference variable, the storage area address determined based on the storage area identifier information in the variable data of that reference variable is the actual storage area address of that data storage area. Correspondingly, the second verification factor calculated based on the storage area address and basic attribute information must be consistent with the first verification factor. Therefore, the target data will only be retrieved from the data storage area when the first and second verification factors are the same. This reduces the possibility of data access errors or illegal acquisition of data from other applications due to the application illegally modifying the storage area identifier information in the reference variable, thus improving the reliability and security of data access.
[0120] In this application, the first check factor and the referenced variable can be associated in various ways, and there are no restrictions on this. Two possible scenarios are illustrated below:
[0121] In the first possible scenario, this application can record the first check factor in the variable data of the referenced variable. For example, it can set six consecutive digits or other numbers of digits in the referenced variable to record the first check factor. Accordingly, this application can obtain the first check factor from the first variable data of the referenced variable.
[0122] In the second possible scenario, the first verification factor can also be stored in the attribute storage area of the data storage area corresponding to the application. As mentioned earlier, the attribute storage area is the storage region within the data storage area used to store basic attribute information. Accordingly, this application can obtain the first verification factor associated with the reference variable from the attribute storage area of the data storage area.
[0123] In the first possible scenario, the first check factor requires bits of the reference variable, which may limit the number of different application data storage areas that can be represented by the reference variable. In the second possible scenario, the first check factor does not require bits of the reference variable, allowing the reference variable to represent more different application data storage areas.
[0124] In practical applications, this application can select any of the above possible scenarios to record the first verification factor, taking into account the actual needs of the operating system based on the WebAssembly virtual machine.
[0125] In one implementation, this application may also determine which of the two possible scenarios to select for recording the first check factor based on the different sizes of the data storage area requested by the application.
[0126] To facilitate understanding, the process of allocating data storage areas and constructing variable data for reference variables in the WebAssembly virtual machine runtime system of this application will be described below.
[0127] Figure 2 illustrates a schematic diagram of an implementation process for allocating data storage areas and constructing variable data for reference variables in an embodiment of this application. The method of this embodiment may include:
[0128] S201, Obtain the storage area request initiated by the application, which is used to request storage space for the application to be allocated the target storage capacity.
[0129] For example, an application can request a storage area from a WebAssembly-based runtime system by calling a specified interface provided by the WebAssembly virtual machine.
[0130] The target storage capacity refers to the amount of storage space requested by the application. For example, the target storage capacity can be 6K, 12K, or 20K, etc., without any restrictions.
[0131] S202, based on the target storage capacity, create a data storage area for the application and determine the storage area type identifier corresponding to the data storage area.
[0132] Understandably, in a WebAssembly-based operating system, the embedded operating system can determine the data storage area that can be allocated to the application from the total storage space of the operating system based on the storage area request initiated by the application.
[0133] The data storage area can be divided into an attribute storage area and a data volume storage area. The attribute storage area records basic attribute information associated with the data storage area and the application. For example, basic attribute information may include: the target storage capacity of the data storage area, information about the application to which the data storage area belongs, a randomly generated random factor, and the data type used by the data storage area to store the data generated by the application.
[0134] The storage area type identifier is used to characterize the category to which the storage capacity of the data storage area belongs. Specifically, the data storage area is divided into two types: a first storage area type, which means that the storage capacity of the data storage area is not less than a set threshold; and a second storage area type, which means that the storage capacity of the data storage area is less than the set threshold.
[0135] This threshold can be set as needed. For example, if the application in the running system requests a large data storage area of 8K, then this threshold can be set to 8K.
[0136] Accordingly, the storage area type identifier may include: a first type identifier corresponding to the first storage area type, and a second type identifier corresponding to the second storage area type. Based on this, it can be seen that if the target storage capacity is not less than a set threshold, the storage area type identifier corresponding to the application's data storage area is the first type identifier; if the target storage capacity is less than the set threshold, the storage area type identifier of the data storage area is the second type identifier.
[0137] S203, Based on the storage area address of the data storage area, determine the storage area identification information of the data storage area.
[0138] It is understandable that using storage area identification information to identify the storage area address of the data storage area in reference variables (i.e., the variable data of the reference variable), instead of directly using the storage area address, can improve the security of the storage area address corresponding to the data storage area of each application.
[0139] As mentioned earlier, the storage area identification information can be the address index of the storage area address in the address storage table; or it can be the offset information corresponding to the storage area address of the data storage area, which is used to characterize the relative offset address corresponding to the storage area address of the data storage area.
[0140] In one possible implementation, if the target storage capacity is not less than a set threshold, the storage address of the data storage area is stored in an address storage table, the address index of the storage address in the address storage table is determined, and the address index is used as the storage area identification information of the data storage area corresponding to the application.
[0141] If the target storage capacity is less than the set threshold, determine the offset information corresponding to the storage area address of the data storage area, and use the offset information as the storage area identifier information of the data storage area.
[0142] S204. Calculate the first check factor based on the storage area address and basic attribute information of the data storage area.
[0143] The specific process for calculating the first check factor is as described above and will not be repeated here.
[0144] In an alternative approach, the first check factor can be calculated based on the storage area address, the basic attribute information, and the storage area type identifier of the data storage area. It is understood that when the first check factor is calculated in this manner, the second check factor can also be calculated based on the basic attribute information, the storage area address, and the storage area type identifier during the data access phase.
[0145] Of course, this application can also combine various methods for calculating the first verification factor mentioned in this embodiment to comprehensively calculate the first verification factor. For example, the first verification factor can be calculated based on the storage area address, basic attribute information, storage area type identifier, and storage area identifier information of the data storage area. Correspondingly, in the subsequent data access phase, the second verification factor can be calculated based on the storage area address, basic attribute information, storage area type identifier, and storage area identifier information of the data storage area.
[0146] S205, if the target storage capacity is not less than a set threshold, construct second variable data for the application's reference variables, including storage area type identifier, first check factor, and storage area identifier information.
[0147] S206, if the target storage capacity is less than the set threshold, construct third variable data including storage area type identifier and storage area identifier information for the application's reference variables, and store the first check factor in the attribute storage area of the data storage area.
[0148] Understandably, if an application requests a large amount of storage space, the number of data storage areas that the running system can allocate to the application will be relatively small. For example, to make it easier to understand, suppose the total storage space of the running system is 6400K. If each application requests a 32K data storage area, then the total storage space can only allocate data storage areas to 200 applications; if each application requests an 8K data storage area, then the total storage space can allocate data storage areas to 800 applications.
[0149] Understandably, the larger the storage capacity requested by an application, the fewer data storage areas can be divided based on the total storage space. Therefore, the number of bits required for the reference variable to distinguish the data storage areas of different applications is relatively small. Conversely, the smaller the storage capacity requested by an application, the more data storage areas can be divided based on the total storage space. Therefore, the number of bits required for the storage area identification information in the reference variable to distinguish the data storage areas of different applications is relatively large.
[0150] Understandably, since the number of bits in a reference variable is fixed and finite, the number of bits that can be used to represent the storage area identifier information of the data storage area is also relatively limited. Therefore, when the storage capacity of the data storage area requested by the application is small, resulting in a large number of bits required for the data storage area (i.e., when the target storage capacity is less than a set threshold), this application may omit the first check factor from the variable data of the reference variable and instead store the first check factor in the attribute storage area of the application's data storage area.
[0151] Correspondingly, if the target storage capacity is not less than the set threshold, then considering that the number of bits used to represent the storage area identification information in the reference variable is relatively small, the first check factor can be included in the variable data of the reference variable.
[0152] The composition of the variables referenced in this application can have many possibilities, and there are no restrictions on this.
[0153] Understandably, after constructing the second or third variable data of the reference variable, the running system can send the second or third variable data of the reference variable to the application, so that the application can assign a value to the reference variable in the application based on the second or third variable data of the reference variable.
[0154] Based on this embodiment, after the running system obtains the application's data access instruction, and then obtains the first variable data of the referenced variable from the data access instruction, the running system can first obtain the storage area type identifier in the first variable data. As described above, the storage area type identifier in the first variable data of the referenced variable can be a first storage type identifier or a second storage type identifier. The first type identifier indicates that the storage capacity of the data storage area corresponding to the application is not less than a set threshold, and the second type identifier indicates that the storage capacity of the data storage area is less than the set threshold.
[0155] Accordingly, if the storage area type identifier corresponding to the application is a first type identifier, the first check factor can be obtained from the first variable data of the referenced variable. If the storage area type identifier corresponding to the application is a second type identifier, the first check factor associated with the referenced variable can be obtained from the attribute storage area of the data storage area.
[0156] It is understandable that when the storage area corresponding to the data storage area of an application is of different types, the storage area identification information determined based on the storage area address corresponding to the data storage area of the application may also be different.
[0157] As mentioned earlier, during the process of constructing variable data for reference variables in the application, if the target storage capacity of the data storage area is not less than a set threshold, the storage area identification information is the index address. If the target storage capacity is less than the set threshold, the storage area identification information is the offset information.
[0158] Accordingly, during the data access phase, if the storage area type identifier obtained from the first variable data of the referenced variable is a first type identifier, the address index recorded in the first variable data of the referenced variable can be obtained, and the storage area address of the data storage area corresponding to the application can be determined based on the address index. If the storage area type identifier is a second type identifier, the offset information recorded in the first variable data of the referenced variable is obtained, and the storage area address of the data storage area corresponding to the application can be determined based on the offset information.
[0159] The following is a detailed explanation of this situation.
[0160] To facilitate understanding, the possible composition structure of the referenced variables in this application will be explained first.
[0161] The total number of bytes in a reference variable is fixed, but the specific number of bytes can be set as needed. Typically, reference variables are 4 bytes of data. For ease of explanation, the following explanation uses a 4-byte reference variable as an example.
[0162] In one possible implementation, as shown in Figure 3, a schematic diagram of the composition structure of a reference variable is illustrated.
[0163] In Figure 3, the referenced variables are divided into three parts.
[0164] The first part is the reference type area in Figure 3, specifically the highest bit (31st bit) of the reference variable, which identifies the variable category of the reference variable. In this application, the 31st bit is used to record that the reference variable is a variable used to represent the data storage area of the application.
[0165] The second part is the offset range area, specifically the 0th to 15th bits of the reference variable. It is used to record the offset range information that the reference variable can be modified, and the maximum offset range information is 64K.
[0166] This offset range information refers to the address range between the start and end addresses of the application's data storage area. The application can identify the data offset address of different data within this data storage area by modifying the specific value of this offset range information.
[0167] The third part is the address area, specifically bits 16 to 30 of the reference variable, used to record the address information of the data storage area corresponding to the application associated with that reference variable. For example, the storage area identification information mentioned earlier.
[0168] Taking storage area identification information as an address index as an example. The total storage space in a WebAssembly virtual machine-based operating system is limited, meaning the addressable range is finite. Within this limited storage space, the addresses of storage areas can be recorded using an address storage table. Correspondingly, bits 16 to 30 of the reference variable can be used to record the index address of the data storage area in the address storage table. For example, this index address could be the sequence number in the address storage table.
[0169] Based on this, the 16th to 30th bits can represent the index addresses of 32,767 different data storage areas.
[0170] Of course, the address information of 32,767 data storage areas may not be sufficient to meet the data storage needs of all applications running on a WebAssembly virtual machine. Therefore, this application can also adjust the number of bits occupied by the storage area identification information (such as address index) and offset range information in the reference variables according to the actual application scenario.
[0171] Considering that reference variables may be modified during application runtime, in order to improve the security of data access, this application can adopt different structural forms of reference variables depending on the size of the data storage area requested by the application.
[0172] If the target storage capacity of the data storage area requested by the application is not less than a set threshold (e.g., 8K), this application may adopt the first composition structure scheme of reference variables.
[0173] Specifically, based on Figure 3, a check factor needs to be added to the reference variable. Therefore, the number of bits in the address area of the reference variable needs to be adjusted, and a check factor area needs to be added. Figure 4 shows a schematic diagram of the composition structure of a reference variable applicable to the first storage area type in this application, that is, a schematic diagram of the data composition structure of the first type of reference variable.
[0174] As shown in Figure 4, the reference variable is divided into four parts:
[0175] In this application, the 31st bit of the reference variable is the storage type area. The storage type area identifies the storage type of the data storage area associated with the application. In order to identify that the data storage area corresponding to the reference variable is of the first storage type, the value of the 31st bit is a target value, such as 1. Accordingly, when the value of the 31st bit in the reference variable is 1, the storage type identifier in the reference variable is determined to be a first type identifier.
[0176] The 0th to 15th bits of the reference variable are still used as a 64K offset range area to record the offset range information of the data in the data storage area.
[0177] The 16th to 22nd bits of the reference variable are the index area, which is used to record the address index of the data storage area.
[0178] The 23rd to 30th positions of the reference variable are the check factor area, which is used to record the first check factor generated for this data storage area.
[0179] In the reference variables of Figure 4, the total number of bits in the index area is 7, which can represent 256 different index addresses. The number of data storage areas that can be used to identify application data storage areas is relatively small. As mentioned earlier, when the total storage space of the running system is fixed, the number of large-capacity data storage areas that can be divided is also relatively small. Therefore, the composition structure of the reference variables in Figure 4 is suitable for representing the address information of data storage areas with a target storage capacity not less than a set threshold.
[0180] For cases where the target storage capacity of the data storage area requested by the application is less than the set threshold (e.g., 8K), the second composition structure scheme of the reference variable can be adopted.
[0181] Specifically, in order to represent more application data storage areas through the address area of the reference variable, based on Figure 3, this application can reduce the number of bits occupied by the offset range area and increase the number of bits occupied by the address area used to record the address information of the data storage area. Figure 5 shows a schematic diagram of a data composition structure applicable to the second storage area type of reference variable, that is, a schematic diagram of the data composition structure of the second type of reference variable.
[0182] As can be seen from Figure 5:
[0183] The 31st and 30th bits of the reference variable together form the storage type area, as shown in Figure 5, where the 31st bit is storage type area 1 and the 30th bit is storage type area 2. The storage type area is used to identify the storage type identifier corresponding to the data storage area of the application associated with the reference variable. The value of the 31st bit in this second type of reference variable differs from the value of the 31st bit in the first type of reference variable.
[0184] Furthermore, in this application, the storage type areas of the first type of reference variable and the second type of reference variable can also be reused as reference type areas.
[0185] For example, in this application, when the value of the 31st bit of the first type of reference variable is set to 1, the value of the 31st bit of the second type of reference variable can be set to 0, while the value of the 30th bit of the second type of reference variable is set to 1. Based on this, if the running system recognizes that the value of the 31st bit of the reference variable is 1, it determines that the storage area type identifier in the reference variable is the first type identifier, and confirms that the reference variable belongs to the reference variable that identifies the data storage area.
[0186] If the 31st bit of the reference variable is identified as 0, the 30th bit of the reference variable can be further identified. If the value of the 30th bit is 1, the storage area type identifier in the reference variable is determined to be a second type identifier, and it can be confirmed that the reference variable belongs to the reference variable that identifies the data storage area; if the value of the 30th bit in the reference variable is 0, it is considered not to belong to the reference variable used to identify the data storage area.
[0187] The 0th to 12th bits of the reference variable are an 8K offset range used to record the offset address of the data in the data storage area relative to the data storage area.
[0188] The 13th to 29th bits of the reference variable are the storage area offset information recording area. This part can record the offset information corresponding to the application's data storage area. This offset information is used to characterize the relative offset address corresponding to the storage area address of the data storage area.
[0189] Furthermore, in order to enable bits 13 to 29 to be used to distinguish more application data storage areas, bits 16 to 29 in this application can be used to record first offset information, while bits 13 to 15 are used to record second offset information.
[0190] As mentioned earlier, the first offset information is the remainder obtained by dividing the relative offset address corresponding to the storage area address of the data storage area by the target number of bytes. For example, if the target number of bytes is 64K, then bits 13 to 29 in the reference variable actually record the relative offset of the relative offset address of the data storage area within one 64K.
[0191] The second offset information is the quotient of the relative offset address of the data storage area divided by the number of bytes of the target, which is how many complete 64K offsets exist in the relative offset address of the data storage area.
[0192] To avoid reducing the amount of data storage that the reference variable in Figure 5 can represent due to the check factor occupying the space of the reference variable, the second data composition structure scheme of the reference variable shown in Figure 5 does not include the first check factor.
[0193] The first check factor can be stored in the attribute storage area of the data storage area.
[0194] Combining the two structural schemes for reference variables mentioned above, the following describes another implementation method for allocating data storage areas and constructing variable data for reference variables in the application of this application.
[0195] Figure 6 illustrates another implementation flow diagram of the application allocating data storage area and constructing reference variables in this embodiment of the application. This embodiment is applied to a running system based on the WebAssembly virtual machine, and may include:
[0196] S601, obtains the storage area request initiated by the application.
[0197] This storage area request is used to request storage space to allocate the target storage capacity for the application.
[0198] S602, if the target storage capacity is not less than the set threshold, create a data storage area for the application and determine the storage area type identifier corresponding to the data storage area as the first type identifier.
[0199] For example, in the data structure of the referenced variables shown in Figures 4 and 5, the first type identifier can be represented as 1, while the second type identifier can be represented as 01.
[0200] The attribute storage area of the data storage area stores basic attribute information. This basic attribute information is generated based on the attributes of the data storage area and the attributes of the application after the running system determines the data storage area that can be allocated to the application.
[0201] For example, basic attribute information may include: the size of the data storage area (i.e., the target storage capacity), the name or other identification information of the application to which the data storage area belongs, the randomly generated random factor, and the data type used by the application to store the data in the data storage area.
[0202] S603, store the storage address of the data storage area into the address storage table, and determine the address index of the storage area address in the address storage table.
[0203] The address index indicates the storage location of the data storage area's address in the address storage table. For example, the address index can be the sequence number of the data storage area's address in the address storage table.
[0204] In one alternative approach, before storing the storage address of the data storage area in the address storage table, it can be checked whether there is a free location in the address storage table. If there is no free location in the address storage table, the data storage area cannot be allocated to the application, and an indication message indicating that the data storage area allocation failed can be returned to the application. If there is a free location in the address storage table, the storage address can be recorded in the address storage table.
[0205] S604, calculate the first check factor based on the storage area address of the data storage area, the basic attribute information of the records in the data storage area, the address index, and the first type identifier.
[0206] For example, by combining the storage area address, basic attribute information, address index, and first type identifier of the data storage area, a checksum is calculated using a checksum algorithm such as CRC algorithm to obtain the first check factor.
[0207] It is understood that this embodiment illustrates one implementation of calculating the first check factor. However, in practical applications, the first check factor can also be calculated based on the storage address of the data storage area, basic attribute information, and the first type identifier.
[0208] Similarly, calculating the first check factor based on the storage area address of the data storage area and the basic attribute information, or calculating the first check factor based on the storage area address of the data storage area, the basic attribute information, and the address index, is also applicable to this embodiment, and there is no limitation thereto.
[0209] S605, construct second variable data for the reference variable of the application, including a first type identifier, a first check factor and an address index, and send the second variable data of the reference variable to the application.
[0210] For example, taking a 4-byte reference variable as an example, the data structure of the second variable data of the reference variable can be seen in Figure 4, which will not be described in detail here.
[0211] It is understandable that in this embodiment, the first verification factor is associated with the storage area address. Moreover, since the application cannot usually obtain the storage area address, even if the application can obtain the storage area address, the application cannot obtain information such as the random factor in the basic attribute information, which reduces the possibility that the first verification factor can be cracked or arbitrarily forged.
[0212] Furthermore, to further enhance the security of the first check factor, this application incorporates a first type identifier and an address index when calculating the first check factor. This reduces the risk of the first check factor being easily cracked due to insufficient parameters used in its calculation. Therefore, after the reference variable is sent to the application, the application can modify the first check factor based on the relevant information, making it less likely that the first check factor can be forged.
[0213] S606, If the target storage capacity is less than the set threshold, create a data storage area for the application and determine the storage area type identifier corresponding to the data storage area as the second type identifier.
[0214] S607, determine the relative offset address of the storage area address of the data storage area relative to the starting address of the total space.
[0215] As mentioned earlier, the starting address of the total space is the starting address of the total storage space of the running system.
[0216] S608, determine the quotient and remainder obtained by dividing the relative offset address by the target number of bytes, determine the remainder as the first offset information, and determine the quotient as the second offset information.
[0217] For example, the target number of bytes is 64K, but it can be any other value; there are no restrictions on this.
[0218] S609, calculate the first check factor based on the storage area address of the data storage area, the basic attribute information recorded in the data storage area, the first offset information, the second offset information, and the second type identifier.
[0219] It is understandable that when the target storage capacity of the data storage area is less than the set threshold, step S609 is illustrated as an example of one implementation of calculating the first verification factor. In practical applications, the first verification factor can be calculated based on the storage area address and basic attribute information of the data storage area; or, the first verification factor can be calculated based on the storage area address, basic attribute information and second type identification information; or, the first verification factor can be calculated based on the storage area address, basic attribute information, first offset information and second offset information. This is also applicable to this embodiment.
[0220] In this embodiment, the offset information includes the first offset information and the second offset information as an example. For the case where the relative offset address corresponding to the data storage area is directly used as the offset information, it is only necessary to calculate the first verification factor based on the storage area address, the basic attribute information and the relative offset address (i.e., one type of offset information), or to calculate the first verification factor based on the storage area address, the basic attribute information, the relative offset address and the second type identifier. Both of these methods are also applicable to this embodiment, and will not be described in detail here.
[0221] S610, construct third variable data for the reference variable of the application, including the second type identifier, the first offset information and the second offset information, store the first check factor in the attribute storage area of the data storage area, and send the third variable data of the reference variable to the application.
[0222] For example, consider a 4-byte reference variable. The data structure of the third variable data of the reference variable constructed in step S610 can be seen in Figure 5.
[0223] As shown in Figure 5, the second type identifier can be recorded in bits 31 and 30 of the reference variable, the first offset information can be recorded in bits 16 to 29 of the reference variable, and the second offset information can be recorded in bits 13 to 15 of the reference variable, so that bits 13 to 29 constitute the storage area offset information. The offset range of the reference variable belongs to the address range that the application can modify, and this application does not impose any restrictions on it.
[0224] Based on Figure 6, one implementation of the data access method of this application will be introduced.
[0225] Figure 7 illustrates another flowchart of the data access method provided in this application embodiment. This embodiment is applied to a runtime system based on the WebAssembly virtual machine. The method of this embodiment may include:
[0226] S701, receive a data access instruction initiated by the application.
[0227] The data access instruction carries first variable data of a reference variable, which indicates the data address of the target data to be accessed. For example, the first variable data of the reference variable includes the data offset address corresponding to the target data to be accessed.
[0228] It is understandable that the first variable data of the reference variable sent by the application is different from the second or third variable data of the reference variable sent by the running system to the application. For example, the offset range area in the first variable data of the reference variable can record the data offset address corresponding to the target data to be accessed, while the offset range area in the reference variable sent by the running system to the application can be the default value.
[0229] S702, obtain the storage area type identifier in the first variable data of the referenced variable.
[0230] S703, if the storage area type identifier is a first type identifier, obtain the first check factor and address index from the first variable data of the referenced variable.
[0231] For example, taking Figure 4 as an example, in the data structure of the reference variable shown in Figure 4, if the 31st bit of the reference variable is 1 (of course, it can also be set to other target values according to actual needs), then the storage area type identifier of the data storage area of the application is determined to be the first type identifier. Correspondingly, the first check factor can be obtained from the 23rd to the 30th bits of the reference variable, and the address index can be obtained from the 16th to the 22nd bits.
[0232] S704, Based on this address index, determine the storage area address of the data storage area corresponding to the application.
[0233] For example, based on the address index, the storage area address corresponding to the address index can be retrieved from the address storage table to obtain the storage area address of the data storage area.
[0234] S705 retrieves basic attribute information from the application's data storage area based on the storage area address.
[0235] S706, calculate the second check factor based on the storage area address, basic attribute information, address index, and first type identifier of the data storage area.
[0236] For example, based on the storage area address, basic attribute information, address index, and first type identifier, a second check factor is calculated using checksum calculation algorithms such as CRC algorithm.
[0237] It is understood that step S706 is illustrated as an example of calculating the second check factor when the storage area type identifier is the first type identifier. However, if the first check factor is calculated based on the storage address and basic attribute information of the data storage area when the storage area type identifier is the first type identifier, then this application can also calculate the second check factor based on the storage area address and basic attribute information of the data storage area.
[0238] Similarly, if the first check factor is calculated based on the storage area address, basic attribute information, and the first type identifier, then the second check factor can be calculated based on the storage area address, basic attributes, and the first type identifier. If the first check factor is calculated based on the storage area address, basic attribute information, and address index, then the second check factor can also be calculated based on the storage area address, basic attribute information, and address index.
[0239] S707, if the storage area type identifier is a second type identifier, obtain the first offset information and the second offset information recorded in the first variable data of the referenced variable.
[0240] For example, based on the data composition structure of the reference variable shown in Figure 5, after determining the number of bits occupied by the first offset information and the second offset information in the reference variable, the first offset information and the second offset information can be obtained from the corresponding bits.
[0241] S708, based on the first offset information and the second offset information, determines the relative offset address corresponding to the data storage area.
[0242] For example, the relative offset address can be obtained by multiplying the second offset information by the target number of bytes and adding the first offset information.
[0243] Wherein, the relative offset address is the relative offset address of the data storage area address relative to the total space start address, and the total space start address is the start address of the total storage space of the running system.
[0244] It is understood that in this embodiment, the first offset information and the second offset information are recorded in the reference variable as an example. It is understood that if the relative offset address or other offset information is recorded in the reference variable, then the relative offset address or other offset information can be obtained directly from the reference variable.
[0245] S709, Based on the relative offset address, determine the storage area address of the data storage area.
[0246] For example, based on the relative offset address and the starting address of the total storage space of the running system, the storage area address of the data storage area can be determined.
[0247] S710 obtains basic attribute information and the first check factor from the data storage area based on the storage area address of the data storage area.
[0248] S711, calculate the second check factor based on the storage area address, basic attribute information, first offset information, second offset information, and the second type identifier of the data storage area.
[0249] It is understandable that step S711 is illustrated using one implementation of calculating the second check factor when the storage type identifier is the second type identifier. It is also understandable that, when the storage type identifier is the second type identifier, the first check factor can be calculated based on the storage area address of the data storage area and the basic attribute information; correspondingly, the second check factor can be calculated based on the storage area address of the data storage area and the basic attribute information.
[0250] Similarly, the second check factor can be calculated based on the storage area address, basic attribute information, and second type identifier of the data storage area; or, the second check factor can be calculated based on the storage area address, basic attribute information, first offset information, and second offset information.
[0251] Of course, if the first offset information and the second offset information are replaced with offset information such as relative offset address, in step S711, the second check factor can also be calculated based on the storage area address, basic attribute information, offset information (such as relative offset address) and the second type identifier; or, the second check factor can be calculated based on the storage area address, basic attribute information and offset information (such as relative offset address).
[0252] S712, if the first check factor is the same as the second check factor, the target data is obtained from the data storage area based on the first variable data of the reference variable and the storage area address.
[0253] For example, based on the data offset address in the first variable data of the referenced variable and the address of the storage area, the data storage address of the target data in the data storage area is determined, and the target data is obtained from the data storage area based on the data storage address.
[0254] Understandably, after obtaining the target data, it can also be sent to the application.
[0255] Corresponding to the data access method provided in the embodiments of this application, this application also provides a data access device.
[0256] Figure 8 shows a schematic diagram of the composition structure of a data access device provided in an embodiment of this application. The device in this embodiment is applied to a running system based on a WebAssembly virtual machine, and the device includes:
[0257] The instruction acquisition unit 801 is used to acquire a data access instruction initiated by the application, the data access instruction carrying first variable data of a reference variable, the first variable data of the reference variable being used to indicate the data address of the target data to be accessed;
[0258] Address determination unit 802 is used to determine the storage area address of the data storage area corresponding to the application based on the storage area identification information recorded in the first variable data of the reference variable. The storage area identification information is used to identify the data storage area corresponding to the application.
[0259] The attribute acquisition unit 803 is used to acquire basic attribute information of records in the data storage area based on the storage area address. The basic attribute information includes attribute information associated with the data storage area and the application.
[0260] The factor acquisition unit 804 is used to acquire the first verification factor associated with the first variable data of the reference variable. The first verification factor is calculated by the running system based on the storage area address and basic attribute information of the data storage area during the process of generating the variable data of the reference variable for the application.
[0261] The first factor calculation unit 805 is used to calculate the second check factor based on the basic attribute information and the storage area address;
[0262] The data acquisition unit 806 is used to acquire the target data from the data storage area based on the first variable data of the reference variable and the storage area address if the first check factor is the same as the second check factor.
[0263] In one possible implementation, the factor acquisition unit includes at least one of the following:
[0264] The first factor acquisition unit is used to acquire the first verification factor from the first variable data of the referenced variable;
[0265] The second factor acquisition unit is used to obtain the first verification factor associated with the reference variable from the attribute storage area of the data storage area, where the attribute storage area is used to store the basic attribute information.
[0266] In another possible implementation, the device further includes: a type obtaining unit, configured to obtain a storage area type identifier in the first variable data of the reference variable after the instruction obtaining unit obtains a data access instruction initiated by the application, wherein the storage area type identifier belongs to one of a first type identifier and a second type identifier, wherein the first type identifier indicates that the storage capacity of the data storage area corresponding to the application is not less than a set threshold, and the second type identifier indicates that the storage capacity of the data storage area is less than the set threshold.
[0267] The first factor acquisition unit is specifically used to acquire the first verification factor from the first variable data of the reference variable if the storage area type identifier is a first type identifier;
[0268] The second factor acquisition unit is specifically used to acquire the first verification factor associated with the reference variable from the attribute storage area of the data storage area if the storage area type identifier is a second type identifier.
[0269] In yet another possible implementation, the address determination unit includes:
[0270] The first address determination unit is used to obtain the address index recorded in the first variable data of the reference variable if the storage area type identifier is a first type identifier, and determine the storage area address of the data storage area corresponding to the application based on the address index. The address index is used to indicate the storage location of the storage area address of the data storage area in the address storage table.
[0271] The second address determination unit is used to obtain the offset information recorded in the first variable data of the referenced variable if the storage area type identifier is a second type identifier, and determine the storage area address of the data storage area based on the offset information. The offset information is used to characterize the relative offset address of the storage area address of the data storage area relative to the starting address of the total space, which is the starting address of the total storage space of the running system.
[0272] In yet another possible implementation, the second address determination unit includes:
[0273] Offset acquisition sub-unit, used to obtain first offset information and second offset information recorded in the first variable data of the reference variable if the storage area type identifier is a second type identifier. The first offset information is the remainder obtained by dividing the relative offset address corresponding to the storage area address of the data storage area by the target number of bytes, and the second offset information is the quotient of the relative offset address divided by the target number of bytes.
[0274] The offset determination subunit is used to determine the relative offset address corresponding to the data storage area based on the first offset information and the second offset information;
[0275] The address determination subunit is used to determine the storage area address of the data storage area based on the relative offset address.
[0276] In another possible implementation, the first verification factor is calculated based on the storage area address, basic attribute information, and storage area type identifier of the data storage area;
[0277] The first factor calculation unit is specifically used to calculate the second verification factor based on the basic attribute information, storage area address, and storage area type identifier.
[0278] In another possible implementation, the factor calculation unit is specifically used to calculate a second check factor based on the data storage area identifier, basic attribute information, and storage area address.
[0279] In another possible implementation, the first variable data of the reference variable obtained by the instruction obtaining unit of the device includes the data offset address of the target data in the data storage area corresponding to the application.
[0280] Specifically, the data acquisition unit is used to acquire target data from the data storage area based on the data offset address and the storage area address if the first check factor is the same as the second check factor.
[0281] In yet another possible implementation, the device further includes:
[0282] The request acquisition unit is used to obtain a storage area request initiated by the application before the instruction acquisition unit obtains a data access instruction initiated by the application. The storage area request is used to request storage space for allocating the target storage capacity to the application.
[0283] The storage area determination unit is used to create a data storage area for the application based on the target storage capacity, determine the storage area type identifier corresponding to the data storage area, and record basic attribute information associated with the data storage area and the application in the attribute storage area of the data storage area. If the target storage capacity is not less than a set threshold, the storage area type identifier is a first type identifier; if the target storage capacity is less than the set threshold, the storage area type identifier is a second type identifier.
[0284] The identifier determination unit is used to determine the storage area identifier information of the data storage area based on the storage area address of the data storage area;
[0285] The second factor calculation unit is used to calculate the first check factor based on the address of the storage area and the basic attribute information;
[0286] The first variable construction unit is used to construct second variable data for the application's reference variables, including storage area type identifier, first check factor, and storage area identifier information, if the target storage capacity is not less than a set threshold.
[0287] The second variable construction unit is used to construct third variable data, including storage area type identifier and storage area identifier information, for the application's reference variables if the target storage capacity is less than a set threshold, and to store the first verification factor in the attribute storage area of the data storage area.
[0288] In yet another possible implementation, the identifier determining unit includes:
[0289] The index determination unit is used to store the storage address of the data storage area into the address storage table if the target storage capacity is not less than a set threshold, and to determine the address index of the storage area address in the address storage table. The address index is used to indicate the storage location of the storage area address in the address storage table.
[0290] The offset determination unit is used to determine the offset information corresponding to the storage area address of the data storage area if the target storage capacity is less than a set threshold. The offset information is used to characterize the relative offset address of the storage area address of the data storage area relative to the starting address of the total space, which is the starting address of the total storage space of the running system.
[0291] Accordingly, the first variable construction unit is specifically used to construct second variable data, including storage area type identifier, first check factor and address index, for the reference variable of the application if the target storage capacity is not less than a set threshold;
[0292] The second variable construction unit is specifically used to construct a third variable data, including storage area type identifier and offset information, for the application's reference variable if the target storage capacity is less than a set threshold.
[0293] In another possible implementation, the offset determination unit includes:
[0294] The address determination subunit is used to determine the relative offset address of the storage area address of the data storage area relative to the starting address of the total space if the storage capacity is less than a set threshold.
[0295] The offset splitting subunit is used to determine the quotient and remainder obtained by dividing the relative offset address by the target number of bytes. The remainder is determined as the first offset information, and the quotient is determined as the second offset information.
[0296] Specifically, the second variable construction unit is used to construct a third variable data, including storage area type identifier, first offset information and second offset information, for the reference variable of the application if the target storage capacity is less than a set threshold.
[0297] It is understood that in this application, the terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings are used to distinguish similar parts and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in a sequence other than that illustrated herein.
[0298] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. Furthermore, the features described in the various embodiments of this specification can be substituted or combined with each other, enabling those skilled in the art to implement or use this application. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0299] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0300] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0301] The above are merely preferred embodiments of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A data access method, characterized in that, An application to a WebAssembly-based virtual machine runtime system includes: obtaining a data access instruction initiated by an application, the data access instruction carrying first variable data of a reference variable, the first variable data of the reference variable indicating the data address of the target data to be accessed; determining the storage area address of a data storage area corresponding to the application based on storage area identification information recorded in the first variable data of the reference variable, the storage area identification information identifying the data storage area corresponding to the application; obtaining basic attribute information recorded in the data storage area based on the storage area address, the basic attribute information including attribute information associated with the data storage area and the application; obtaining a first verification factor associated with the reference variable, the first verification factor being calculated by the runtime system based on the storage area address and basic attribute information during the process of generating variable data corresponding to the reference variable for the application; calculating a second verification factor based on the basic attribute information and the storage area address; if the first verification factor is the same as the second verification factor, obtaining the target data from the data storage area based on the first variable data of the reference variable and the storage area address.
2. The data access method according to claim 1, characterized in that, The step of obtaining the first verification factor associated with the reference variable includes at least one of the following: obtaining the first verification factor from the first variable data of the reference variable; obtaining the first verification factor associated with the reference variable from the attribute storage area of the data storage area, wherein the attribute storage area is a storage area used to store the basic attribute information.
3. The data access method according to claim 2, characterized in that, After receiving the data access instruction initiated by the application, the method further includes: obtaining a storage area type identifier from the first variable data of the referenced variable, wherein the storage area type identifier belongs to one of a first type identifier and a second type identifier, the first type identifier indicating that the storage capacity of the data storage area corresponding to the application is not less than a set threshold, and the second type identifier indicating that the storage capacity of the data storage area is less than the set threshold; obtaining a first verification factor from the first variable data of the referenced variable includes: if the storage area type identifier is a first type identifier, obtaining a first verification factor from the first variable data of the referenced variable; obtaining a first verification factor associated with the referenced variable from the attribute storage area of the data storage area includes: if the storage area type identifier is a second type identifier, obtaining a first verification factor associated with the referenced variable from the attribute storage area of the data storage area; wherein the first verification factor is calculated based on the storage area address, basic attribute information, and storage area type identifier of the data storage area; calculating a second verification factor based on the basic attribute information and storage area address includes: calculating a second verification factor based on the basic attribute information, storage area address, and storage area type identifier.
4. The data access method according to claim 3, characterized in that, The step of determining the storage area address of the data storage area corresponding to the application based on the storage area identifier information recorded in the first variable data of the reference variable includes: if the storage area type identifier is a first type identifier, obtaining the address index recorded in the first variable data of the reference variable, and determining the storage area address of the data storage area corresponding to the application based on the address index, wherein the address index is used to indicate the storage location of the storage area address of the data storage area in the address storage table; if the storage area type identifier is a second type identifier, obtaining the offset information recorded in the first variable data of the reference variable, and determining the storage area address of the data storage area based on the offset information, wherein the offset information is used to characterize the relative offset address of the storage area address of the data storage area relative to the starting address of the total space, wherein the starting address of the total space is the starting address of the total storage space of the running system.
5. The data access method according to claim 4, characterized in that, The step of obtaining the offset information recorded in the first variable data of the referenced variable and determining the storage area address of the data storage area based on the offset information includes: obtaining first offset information and second offset information recorded in the first variable data of the referenced variable, wherein the first offset information is the remainder obtained by dividing the relative offset address by the target number of bytes, and the second offset information is the quotient obtained by dividing the relative offset address by the target number of bytes; determining the relative offset address corresponding to the data storage area based on the first offset information and the second offset information; and determining the storage area address of the data storage area based on the relative offset address.
6. The data access method according to claim 1, characterized in that, The first variable data of the reference variable includes: the data offset address of the target data in the data storage area corresponding to the application; the step of obtaining the target data from the data storage area based on the first variable data of the reference variable and the storage area address if the first check factor is the same as the second check factor includes: obtaining the target data from the data storage area based on the data offset address and the storage area address if the first check factor is the same as the second check factor.
7. The data access method according to claim 3, characterized in that, Before obtaining the data access instruction initiated by the application, the method further includes: obtaining a storage area request initiated by the application, the storage area request being used to request storage space with a target storage capacity allocated to the application; creating a data storage area for the application based on the target storage capacity, determining the storage area type identifier corresponding to the data storage area, wherein the attribute storage area of the data storage area records basic attribute information associated with the data storage area and the application, wherein if the target storage capacity is not less than a set threshold, the storage area type identifier is a first type identifier, and if the target storage capacity is less than the set threshold, the storage area type identifier is a second type identifier; determining the storage area identifier information of the data storage area based on the storage area address of the data storage area; calculating a first verification factor based on the storage area address, basic attribute information, and storage area type identifier; if the target storage capacity is not less than the set threshold, constructing second variable data including the storage area type identifier, the first verification factor, and the storage area identifier information for the application's reference variables; if the target storage capacity is less than the set threshold, constructing third variable data including the storage area type identifier and the storage area identifier information for the application's reference variables, and storing the first verification factor in the attribute storage area of the data storage area.
8. The data access method according to claim 7, characterized in that, The step of determining the storage area identifier information of the data storage area based on the storage area address of the data storage area includes: if the target storage capacity is not less than a set threshold, storing the storage area address of the data storage area in an address storage table, and determining the address index of the storage area address in the address storage table, wherein the address index is used to indicate the storage location of the storage area address in the address storage table; if the target storage capacity is less than a set threshold, determining the offset information corresponding to the storage area address of the data storage area, wherein the offset information is used to characterize the relative offset address of the storage area address of the data storage area relative to the starting address of the total space, wherein the starting address of the total space is the starting address of the total storage space of the running system; the step of determining the storage area identifier information ... target storage capacity is less than a set threshold, determining the offset information corresponding to the storage area address of the data storage area, wherein the offset information is used to characterize the relative offset address of the storage area address of the data storage area relative to the starting address of the total space, wherein the starting address of the total space is the starting address of the total storage space of the running system; the step of determining the offset information based on the storage area If the target storage capacity is not less than a set threshold, construct second variable data for the application's reference variables, including the storage area type identifier, a first check factor, and storage area identifier information. This includes: if the target storage capacity is not less than the set threshold, constructing second variable data for the application's reference variables, including the storage area type identifier, a first check factor, and an address index; if the target storage capacity is less than the set threshold, construct third variable data for the application's reference variables, including the storage area type identifier and storage area identifier information. This includes: if the target storage capacity is less than the set threshold, constructing third variable data for the application's reference variables, including the storage area type identifier and offset information.
9. The data access method according to claim 8, characterized in that, The step of determining the offset information corresponding to the storage area address of the data storage area if the target storage capacity is less than a set threshold includes: if the storage capacity is less than the set threshold, determining the relative offset address of the storage area address of the data storage area relative to the starting address of the total space; determining the quotient and remainder obtained by dividing the relative offset address by the target number of bytes, determining the remainder as the first offset information, and determining the quotient as the second offset information; the step of constructing third variable data including the storage area type identifier and offset information for the reference variables of the application if the target storage capacity is less than the set threshold includes: if the target storage capacity is less than the set threshold, constructing third variable data including the storage area type identifier, the first offset information, and the second offset information for the reference variables of the application.
10. A data access device, characterized in that, An apparatus for use in a WebAssembly-based virtual machine operating system includes: an instruction acquisition unit for acquiring a data access instruction initiated by an application, the data access instruction carrying first variable data of a reference variable, the first variable data of the reference variable indicating the data address of the target data to be accessed; an address determination unit for determining the storage area address of a data storage area corresponding to the application based on storage area identification information recorded in the first variable data of the reference variable, the storage area identification information identifying the data storage area corresponding to the application; an attribute acquisition unit for acquiring basic attribute information recorded in the data storage area based on the storage area address, the basic attribute information including attribute information associated with the data storage area and the application; a factor acquisition unit for acquiring a first verification factor associated with the reference variable, the first verification factor being calculated by the operating system based on the storage area address and basic attribute information during the process of generating variable data corresponding to the reference variable for the application; a first factor calculation unit for calculating a second verification factor based on the basic attribute information and the storage area address; and a data acquisition unit for acquiring the target data from the data storage area based on the first variable data of the reference variable and the storage area address if the first verification factor is the same as the second verification factor.
Citation Information
Patent Citations
Block chain state storage method, block chain state verification method and block chain node
CN116049170A
Method and apparatus for verifying data in a storage system
CN1448827A