CN116263690A - Method and device for virtual machine to read data from external system and relevant written data - Google Patents

Method and device for virtual machine to read data from external system and relevant written data Download PDF

Info

Publication number
CN116263690A
CN116263690A CN202111531401.6A CN202111531401A CN116263690A CN 116263690 A CN116263690 A CN 116263690A CN 202111531401 A CN202111531401 A CN 202111531401A CN 116263690 A CN116263690 A CN 116263690A
Authority
CN
China
Prior art keywords
address
length
data
external
buffer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111531401.6A
Other languages
Chinese (zh)
Inventor
穆长春
狄刚
李红岗
钱友才
刘杰群
顾策
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Digital Currency Institute of the Peoples Bank of China
Original Assignee
Digital Currency Institute of the Peoples Bank of China
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Digital Currency Institute of the Peoples Bank of China filed Critical Digital Currency Institute of the Peoples Bank of China
Priority to CN202111531401.6A priority Critical patent/CN116263690A/en
Publication of CN116263690A publication Critical patent/CN116263690A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0877Cache access modes

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention discloses a method and a device for a virtual machine to read data from an external system and write out data in a related manner, and relates to the technical field of computers. One embodiment of the method comprises the following steps: an address buffer area is created in an intelligent contract operated by a virtual machine, a storage address of external data is used as an entry of the intelligent contract, the external data is read from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type, and the external complex data type can be transferred to the inside of the intelligent contract executed by the Webassembly virtual machine. Another embodiment comprises: the data address of the address buffer is used as the parameter of the intelligent contract operated by the virtual machine, the data address is transmitted to the external system, wherein the parameter is of integer type, after the external system creates the external buffer, the data in the data address is copied to the external buffer, and the complex data type can be transmitted from the inside of the Webassembl virtual machine intelligent contract to the external system of the virtual machine.

Description

Method and device for virtual machine to read data from external system and relevant written data
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method for a virtual machine to read data from an external system, and a related method and apparatus for writing data.
Background
Webassembly is not a language, but a new byte code format, is a binary instruction format based on a stack type virtual machine, and is designed to be directly compiled into Webassembly intermediate byte codes by using a high-level language (such as C/C++/Rust), the early Webassembly is mainly applied to web applications, but as the early Webassembly is developed, more and more projects are used as the final format of intelligent contracts, the Webassembly is loaded and run by using a virtual machine supporting Webassembly, and specific parsing and running of the Webassembly byte codes are run in a core virtual machine module.
The Webazembly-based virtual machine has remarkable improvement in speed and performance, supports multiple high-level development languages, limits the Webazembly bytecode to run in a safe sandbox execution environment, and only supports integer and floating point type operations in the Webazembly virtual machine standard.
In the process of implementing the present invention, the inventor finds that at least the following problems exist in the prior art:
the external complex data types cannot be passed inside the smart contract executed by the webassmbly virtual machine and the complex data types are not supported from inside the smart contract to the external system.
Disclosure of Invention
In view of this, the embodiments of the present invention provide a method for a virtual machine to read data from an external system, and a method and apparatus for writing data, which can implement that an external complex data type is transferred to the inside of an intelligent contract executed by a webassimbly virtual machine, and a complex data type can be transferred from the inside of the webassimbly virtual machine intelligent contract to the external system of the virtual machine.
To achieve the above object, according to one aspect of the embodiments of the present invention, there is provided a method for a virtual machine to read data from an external system.
A method for a virtual machine to read data from an external system, comprising: creating an address buffer area in an intelligent contract operated by a virtual machine, wherein the virtual machine is a Webassembly virtual machine; taking a storage address of external data as an entry of the intelligent contract, and reading the external data from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type.
Optionally, the method further comprises: a length buffer is created inside the smart contract, the length buffer being used to store the length of the address buffer.
Optionally, before the external data is read from the storage address of the external data to the address buffer, the method includes: and transmitting the offset to an external system where the external data is located.
Optionally, reading the external data from the storage address of the external data to the address buffer, including: and reading the external data from the external system to the address buffer according to the storage address determined according to the initial address of the external data and the offset.
Optionally, before the external data is read from the storage address of the external data to the address buffer, the method further includes: and transmitting the address of the length buffer area to an external system where the external data is located, so that the external system calculates the remaining length to be read of the external data according to the buffer area length of the external system and the offset, and then writing the remaining length to be read into the address of the length buffer area.
Optionally, the reading the external data from the storage address of the external data to the address buffer includes: comparing the length of the address buffer area with the length to be read, and reading byte content with the length equal to the length of the address buffer area from a storage address of the external data and copying the byte content to the address buffer area under the condition that the length of the address buffer area is smaller than or equal to the length to be read; and under the condition that the length of the address buffer area is larger than the remaining length to be read, reading byte content with the length equal to the remaining length to be read from the storage address of the external data, and copying the byte content to the address buffer area.
According to another aspect of the embodiment of the invention, a method for writing data to an external system by a virtual machine is provided.
A method for a virtual machine to write data to an external system, comprising: taking a data address of an address buffer area as a parameter of an intelligent contract operated by a virtual machine, and transmitting the data address to an external system, wherein the virtual machine is a Webassembly virtual machine; wherein the parameter is of integer type; after the external system creates an external buffer, the data in the data address is copied to the external buffer.
Optionally, the method further comprises: and taking the address of the length buffer area as the output parameter of the intelligent contract to be transmitted to the external system, wherein the length buffer area stores the length of the address buffer area, and the address of the length buffer area is used for the external system to read the length of the address buffer area and convert the length into the integer length so as to create the external buffer area according to the integer length.
According to still another aspect of the embodiment of the present invention, there is provided an apparatus for reading data from an external system by a virtual machine.
An apparatus for a virtual machine to read data from an external system, the virtual machine being a webassmbly virtual machine, the apparatus comprising: the buffer zone creating module is used for creating an address buffer zone in an intelligent contract operated by the virtual machine; and the data reading module is used for taking the storage address of the external data as the entry of the intelligent contract, and reading the external data from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type.
Optionally, the buffer creation module is further configured to: a length buffer is created inside the smart contract, the length buffer being used to store the length of the address buffer.
Optionally, the offset transmission module is further included for: and transmitting the offset to an external system where the external data is located.
Optionally, the data reading module is further configured to: and reading the external data from the external system to the address buffer according to the storage address determined according to the initial address of the external data and the offset.
Optionally, the system further includes a length buffer address transfer module, configured to transfer the address of the length buffer to an external system where the external data is located, so that after the external system calculates a remaining length to be read of the external data according to the buffer length of the external system and the offset, the remaining length to be read is written into the address of the length buffer.
Optionally, the data reading module is further configured to: comparing the length of the address buffer area with the length to be read, and reading byte content with the length equal to the length of the address buffer area from a storage address of the external data and copying the byte content to the address buffer area under the condition that the length of the address buffer area is smaller than or equal to the length to be read; and under the condition that the length of the address buffer area is larger than the remaining length to be read, reading byte content with the length equal to the remaining length to be read from the storage address of the external data, and copying the byte content to the address buffer area.
According to still another aspect of the embodiment of the present invention, there is provided an apparatus for writing data to an external system by a virtual machine.
An apparatus for writing data to an external system by a virtual machine, the virtual machine being a webassmbly virtual machine, the apparatus comprising: the first address transfer module is used for taking the data address of the address buffer area as the parameter of the intelligent contract operated by the virtual machine and transferring the data address to an external system; wherein the parameter is of integer type; and the data writing-out module is used for copying the data in the data address to the external buffer area after the external system creates the external buffer area.
Optionally, the system further comprises a second address transfer module for: and taking the address of the length buffer area as the output parameter of the intelligent contract to be transmitted to the external system, wherein the length buffer area stores the length of the address buffer area, and the address of the length buffer area is used for the external system to read the length of the address buffer area and convert the length into the integer length so as to create the external buffer area according to the integer length.
According to yet another aspect of an embodiment of the present invention, an electronic device is provided.
An electronic device, comprising: one or more processors; and the memory is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to realize a method for reading data from an external system by the virtual machine or a method for writing data to the external system by the virtual machine.
According to yet another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer readable medium has stored thereon a computer program which, when executed by a processor, implements a method for a virtual machine to read data from an external system or a method for the virtual machine to write data to the external system provided by an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: an address buffer area is created in an intelligent contract operated by a virtual machine, a storage address of external data is used as an entry of the intelligent contract, the external data is read from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type, and the external complex data type can be transferred to the inside of the intelligent contract executed by the Webassembly virtual machine. The data address of the address buffer is used as the parameter of the intelligent contract operated by the virtual machine, the data address is transmitted to the external system, wherein the parameter is of integer type, after the external system creates the external buffer, the data in the data address is copied to the external buffer, and the complex data type can be transmitted from the inside of the intelligent contract of the Webassembl virtual machine to the external system of the virtual machine.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a method for a virtual machine to read data from an external system according to one embodiment of the invention;
FIG. 2 is a schematic diagram of a Webassembly virtual machine intelligent contract framework, according to one embodiment of the invention;
FIG. 3 is a schematic diagram of a virtual machine local method reading frame, according to one embodiment of the invention;
FIG. 4 is a schematic diagram of a virtual machine local method read timing according to one embodiment of the invention;
FIG. 5 is a schematic diagram of the main steps of a method for writing data to an external system by a virtual machine according to one embodiment of the invention;
FIG. 6 is a diagram of a virtual machine local method write framework in accordance with one embodiment of the present invention;
FIG. 7 is a schematic diagram of a virtual machine local method write timing according to one embodiment of the invention;
FIG. 8 is a schematic diagram of the main modules of an apparatus for a virtual machine to read data from an external system according to one embodiment of the invention;
FIG. 9 is a schematic diagram of the main modules of an apparatus for writing data to an external system by a virtual machine according to one embodiment of the invention;
FIG. 10 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
FIG. 11 is a schematic diagram of a computer system suitable for use in implementing embodiments of the present invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
FIG. 1 is a schematic diagram of the main steps of a method for a virtual machine to read data from an external system according to one embodiment of the invention.
As shown in fig. 1, the method for reading data from an external system by a virtual machine according to an embodiment of the present invention mainly includes the following steps S101 to S102.
Step S101: an address buffer is created inside the intelligent contract run by the virtual machine.
Step S102: the storage address of the external data is used as the entry of the intelligent contract, the external data is read from the storage address of the external data to the address buffer area, wherein the storage address of the external data used as the entry is of integer type.
The virtual machine of the embodiment of the invention is a Webassembly virtual machine, namely a virtual machine developed based on Webassemly.
A length buffer may also be created inside the smart contract, the length buffer being used to store the length of the address buffer.
Before the external data is read from the storage address of the external data to the address buffer, an offset (offset value) may also be transferred to an external system where the external data is located, specifically, an offset of binary data in the external data storage address to be read by the smart contract.
The external data is read from the storage address of the external data to the address buffer, and specifically, the external data may be read from the external system where it is located to the address buffer according to the storage address determined according to the initial address and the offset of the external data.
Before external data is read from the storage address of the external data to the address buffer, the address of the length buffer can be transferred to an external system where the external data is located, so that the external system calculates the remaining length to be read of the external data according to the buffer length and the offset of the external system, and then writes the remaining length to be read into the address of the length buffer.
Reading external data from a storage address of the external data to an address buffer, specifically, comparing the length of the address buffer with the length to be read, and reading byte content with the length equal to the length of the address buffer from the storage address of the external data and copying the byte content to the address buffer when the length of the address buffer is smaller than or equal to the length to be read; and under the condition that the length of the address buffer area is larger than the length to be read, reading the byte content with the length equal to the length to be read from the storage address of the external data, and copying the byte content to the address buffer area. The length of the address buffer can be obtained according to the address of the length buffer, and the length of the address buffer obtained from the address of the length buffer can be converted into an integer length.
FIG. 2 is a schematic diagram of a Webassembly virtual machine intelligent contract framework, according to one embodiment of the invention. As shown in fig. 2, a framework of a webelementary virtual machine (Wasm virtual machine) running a smart contract may be abstracted into parts as shown in fig. 2, and when the smart contract (short contract) runs, data is obtained from input, env and I/O (input/output), and after the contract runs, the data is stored in an I/O database or put in output and returned to a contract caller. The input is the data input from the outside of the contract, the env is the data required by each contract call such as a contract caller, a contract ID (identification) and the like, the I/O is used for loading the data from the database depending on the contract operation, the data store is stored in the database depending on the contract operation, and the output is the data returned to the outside after the contract operation.
In the process of executing the smart contract by the webmaster virtual machine (i.e., the Wasm virtual machine), the smart contract and the input, env, output, I/O are interacted through a local method, and the local method specifically relates to reading and writing operations with external four parties.
The method of the Webazembly instruction intelligent contract executed by the virtual machine only supports integer type input and output, so that when the external input, env, output, I/O needs to perform data interaction with the inside of the intelligent contract, only one method can be converted, the method input of the intelligent contract is a storage address of external square data, the storage address can be represented by integer type, for example, 32 bit int type (basic integer type, namely short integer type), the data is read into a buffer of the intelligent contract from the storage address, and binary data in the buffer is deserialized into an actual object to be processed in the intelligent contract according to own service type.
Because the buffer size inside the intelligent contract is different from the buffer size of the external input and the buffer size of the external output, the virtual machine local method read-write mechanism of the embodiment of the invention can also realize that the data in the buffer of the external input is transferred to the buffer inside the intelligent contract and the data in the buffer of the intelligent contract is transferred to the buffer of the external output under the condition that the buffer size inside the intelligent contract is different from the buffer size of the external input and the buffer of the external output. Detailed procedures are further described in the examples below.
FIG. 3 is a schematic diagram of a virtual machine local method reading frame, according to one embodiment of the invention. As shown in fig. 3, the virtual machine local method reading frame of the present embodiment is implemented by the virtual machine reading data from an external system to local, where the external system is the back-end application in the present embodiment, and the external data is stored in an input buffer (i.e. a data buffer of the external system) of the back-end application, where an address of the input buffer is a storage address of the external data. Within the intelligent contract run by the webassmbly virtual machine, there are addr, len, offset three parameters, addr represents the buffer address of the intelligent contract, i.e. the data address of the address buffer. len denotes the buffer length of the smart contract, i.e. the length of the address buffer. offset represents the offset by which the smart contract is to read binary data in the input buffer. The read-write direction of the offset is that the back-end application reads from the intelligent contract direction of the webfreesubly virtual machine, namely the webfreesubly virtual machine transmits the offset to an external system. The buffer read-write direction represented by the len address (i.e. the address of the length buffer) is bidirectional, and the back-end application reads from the intelligent contract direction of the webelementary virtual machine and the back-end application writes to the intelligent contract direction of the webelementary virtual machine. The local method reading frame is a buffer where an addr of an intelligent contract for copying a data source from the buffer where an input is located to a virtual machine is located, namely, reading data from an external system to the virtual machine. When the input buffer length and the buffer length of the addr (i.e., the length of the address buffer addr buffer) are not identical, a plurality of read operations are required.
FIG. 4 is a schematic diagram of a read timing of a virtual machine local method according to one embodiment of the invention. Fig. 4 is a timing sequence of copying external input buffer data into addr buffer, namely a reading timing sequence of the local method of the virtual machine in this embodiment, and the flow of reading data from an external system by the virtual machine in this embodiment of the present invention is implemented through the reading timing sequence. The external input buffer data is external data of an external system, and the external system can be specifically a back-end application, namely an addr buffer which is an address buffer created inside an intelligent contract operated by a virtual machine.
Step S401: the back-end application reads an offset value (offset) from the virtual machine, with an initial value of 0;
step S402: the back-end application reads the len length from the virtual machine intelligent contract len buffer address;
the length buffer is a length buffer address, and the back-end application converts the read byte content (length) into an integer length, namely an addr address length representing a virtual machine intelligent contract, wherein the length is marked as addr_len;
step S403: writing the length of the input buffer to be read into the intelligent contract len buffer address of the virtual machine;
the input buffer is a data buffer area of an external system, and the length of the input buffer to be read is the length to be read, namely the length to be read, and the calculation formula is specifically:
remainder_length=input_length-offset
input_length is the length of the buffer of the external system, specifically the length of the data buffer of the external system. offset is an offset that is transferred to an external system.
Step S404: judging whether addr_len is smaller than or equal to the remaining length to be read (i.e. input_length-offset value), if yes, executing step S405, otherwise executing step S406.
addr_len is the length of the address buffer.
Step S405: reading byte content with the length of addr_len from an input buffer from a ptr (input) +offset address, and writing the byte content into the addr buffer;
the ptr (input) is an initial address of external data, and the ptr (input) +offset address is a storage address determined according to the initial address and the offset of external data. The operation executed by the step is as follows: the byte content equal to the length addr_len of the address buffer is read from the memory address and copied to the address buffer addr buffer.
Step S406: reading data with the length of input_length-offset from ptr (input) +offset address and copying the data into addr buffer;
that is, in the case where the length of the address buffer is greater than the remaining length to be read, byte contents having a length equal to the remaining length to be read are read from the storage address of the external data and copied to the address buffer.
After step S405 or step S406, step S407 is performed.
Step S407: updating the offset value to be offset=offset+addr_len;
and the data content in the external input buffer is transferred to the addr buffer in the intelligent contract through the time sequence.
The embodiment of the invention realizes that the data in the external input buffer (namely the external data of the external system) is copied into the intelligent contract addr buffer by opening up the len buffer (length buffer) and the addr buffer (address buffer) in the intelligent contract and calculating the offset value (offset) to be transmitted to the external system. The method for transferring the complex data structure from the external system of the virtual machine to the inside of the intelligent contract of the virtual machine is realized, so that the problem that the intelligent contract method supported by the Webassembly virtual machine only supports integer type participation, but cannot support transferring complex data types from the external system of the virtual machine to the internal system of the virtual machine is solved.
FIG. 5 is a schematic diagram of the main steps of a method for writing data to an external system by a virtual machine according to one embodiment of the invention.
As shown in fig. 5, the method for writing data to an external system by a virtual machine according to an embodiment of the present invention mainly includes the following steps S501 to S502. The virtual machine of the embodiment of the invention is a Webassembly virtual machine, namely a virtual machine developed based on Webassemly.
Step S501: taking the data address of the address buffer as the parameter of an intelligent contract operated by the virtual machine, and transmitting the data address to an external system; wherein the parameter is integer type.
Step S502: after the external system creates the external buffer, the data in the data address is copied to the external buffer.
The address of the length buffer area can be used as the output parameter of the intelligent contract to be transmitted to an external system, the length buffer area stores the length of the address buffer area, and the address of the length buffer area is used for the external system to read the length of the address buffer area and convert the length into integer length so as to create the external buffer area according to the integer length.
FIG. 6 is a schematic diagram of a virtual machine local method write framework in accordance with one embodiment of the present invention. The virtual machine local method writing framework of the embodiment of the invention is realized by writing data from the virtual machine to an external system, as shown in fig. 6, writing data from an intelligent contract addr buffer (address buffer) of the virtual machine to an external output buffer, wherein the external buffer is an external buffer created by the external system. The external system is the backend application in fig. 6, and the virtual machine is a Wasm virtual machine. The write logic of the embodiment of the invention only needs to transmit the intelligent contract addr buffer address and the length of the addr buffer to an external system; the length of the address buffer is read by ptr (len) address. The addr buffer address is the data address of the address buffer. The length of the addr buffer is the length of the address buffer, the address buffer is stored in the length buffer, the address of the length buffer can be transmitted to an external system, the external system reads the length of the address buffer from the address of the length buffer (that is, ptr (len) address) and converts the length of the address buffer into integer length, and the external buffer with corresponding length is created according to the integer length.
FIG. 7 is a schematic diagram of a virtual machine local method write timing according to one embodiment of the invention. The process of writing data to an external system by a virtual machine according to the present invention, which is the local method write sequence of the virtual machine shown in fig. 7, specifically includes:
step S701: the virtual machine smart contract writes addr buffer length into the four byte content of the address where the len buffer is located.
addr buffer is the address buffer zone created inside the intelligent contract operated by the virtual machine, addr buffer length is the length of the address buffer zone, and len buffer is the length buffer zone for storing the length of the address buffer zone.
Step S702: the virtual machine reads the four-byte content of ptr (len) buffer, and converts the read four-byte content into corresponding integer length.
The integer length obtained by conversion is the length of ptr (addr) buffer, and is marked by addr_length.
The external virtual machine is an external system, ptr (len) buffer is the address of a length buffer area, wherein four bytes of content are the length of the address buffer area, and the external system converts the length into integer length and marks the integer length by addr_length.
Step S703: the virtual machine externally opens up an output buffer with an addr_length length, and directly copies the data of the ptr (addr) address into the output buffer.
The output buffer is an external buffer created by an external system, the length of the external buffer is the same as that of the address buffer, the ptr (addr) address is a data address of the address buffer, and data in the data address is copied to the external buffer through the step.
According to the embodiment of the invention, the length of an addr buffer (address buffer) is represented by reading the length of the addr buffer (length buffer) in the intelligent contract, the addr buffer length is marked by addr_length, and an output buffer (external buffer) with the addr_length length is opened up in an external system and is used for receiving data written outwards by the contract. The complex data structure is transferred from the inside of the virtual machine intelligent contract to the outside of the virtual machine, so that the problem that the intelligent contract method supported by the Webassembly virtual machine only supports integer parameter extraction and cannot support complex data types to be transferred to an external system is solved.
Fig. 8 is a schematic diagram of main modules of an apparatus for a virtual machine to read data from an external system according to an embodiment of the present invention. As shown in fig. 8, an apparatus 800 for a virtual machine to read data from an external system according to an embodiment of the present invention mainly includes: a buffer creation module 801, a data reading module 802.
A buffer creating module 801, configured to create an address buffer inside an intelligent contract running in a virtual machine;
the data reading module 802 is configured to take a storage address of external data as an entry of the smart contract, and read the external data from the storage address of the external data to the address buffer, where the storage address is of an integer type.
The buffer creation module 801 is further configured to: a length buffer is created inside the smart contract, the length buffer being used to store the length of the address buffer.
The apparatus 800 for the virtual machine to read data from an external system may further include an offset delivery module for: and transmitting the offset to an external system where the external data is located.
The data reading module 802 may be specifically configured to: external data is read from the external system where it is located to the address buffer according to a storage address determined from the initial address and the offset of the external data.
The apparatus 800 for reading data from an external system by a virtual machine may further include a length buffer address transfer module, configured to transfer an address of a length buffer to an external system where external data is located, so that after the external system calculates a remaining length to be read of the external data according to a buffer length and an offset of the external system, the remaining length to be read is written into the address of the length buffer.
The data reading module 802 is specifically further configured to: comparing the length of the address buffer area with the length to be read, reading byte content with the length equal to the length of the address buffer area from a storage address of external data under the condition that the length of the address buffer area is smaller than or equal to the length to be read, and copying the byte content to the address buffer area; and under the condition that the length of the address buffer area is larger than the length to be read, reading the byte content with the length equal to the length to be read from the storage address of the external data, and copying the byte content to the address buffer area.
FIG. 9 is a schematic diagram of the main modules of an apparatus for writing data to an external system by a virtual machine according to one embodiment of the invention. As shown in fig. 9, an apparatus 900 for writing data to an external system by a virtual machine according to an embodiment of the present invention mainly includes: a first address transfer module 901, a data writing module 902.
The first address transfer module 901 is configured to transfer a data address of the address buffer to an external system by using the data address of the address buffer as a parameter of an intelligent contract operated by the virtual machine; wherein the parameter is integer type.
A data writing module 902, configured to copy the data in the data address to the external buffer after the external system creates the external buffer.
The apparatus 900 for writing data from a virtual machine to an external system may further include a second address transfer module configured to: the address of the length buffer is used as the output parameter of the intelligent contract to be transmitted to an external system, the length buffer stores the length of the address buffer, and the address of the length buffer is used for the external system to read the length of the address buffer and convert the length into integer length so as to create the external buffer according to the integer length.
In addition, in the embodiment of the present invention, the specific implementation content of the device for reading data from the external system by the virtual machine or the method for writing data to the external system by the virtual machine is described in detail in the method for reading data from the external system by the virtual machine or the method for writing data to the external system by the virtual machine, so that the description is not repeated here.
The embodiment of the invention can remove the limitation that Webassembl only supports integer, and can complete the transmission of complex data types from the inside of the virtual machine to the outside of the system and the transmission of the system outside to the inside of the virtual machine only by customizing a serialization and deserialization scheme.
Fig. 10 illustrates an exemplary system architecture 1000 of a method for a virtual machine to read data from an external system, a method for a virtual machine to write data to an external system, or a device for a virtual machine to read data from an external system, and a device for a virtual machine to write data to an external system, to which embodiments of the present invention may be applied.
As shown in fig. 10, a system architecture 1000 may include terminal devices 1001, 1002, 1003, a network 1004, and a server 1005. The network 1004 serves as a medium for providing a communication link between the terminal apparatuses 1001, 1002, 1003 and the server 1005. The network 1004 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user can interact with a server 1005 via a network 1004 using terminal apparatuses 1001, 1002, 1003 to receive or transmit messages or the like. Various communication client applications such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 1001, 1002, 1003.
The terminal devices 1001, 1002, 1003 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 1005 may be a server providing various services, such as a background management server (merely an example) providing support for websites browsed by the user using the terminal apparatuses 1001, 1002, 1003. The background management server may analyze and process the received data such as the information query request, and feed back the processing result (for example, the query result—merely an example) to the terminal device.
It should be noted that, in the method for the virtual machine to read data from the external system and the method for the virtual machine to write data to the external system provided in the embodiments of the present invention, the server 1005 is generally executed, and accordingly, the device for the virtual machine to read data from the external system and the device for the virtual machine to write data to the external system are generally set in the server 1005.
It should be understood that the number of terminal devices, networks and servers in fig. 10 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 11, there is illustrated a schematic diagram of a computer system 1100 suitable for use in implementing a server of an embodiment of the present application. The server illustrated in fig. 11 is merely an example, and should not impose any limitation on the functionality and scope of use of the embodiments of the present application.
As shown in fig. 11, the computer system 1100 includes a Central Processing Unit (CPU) 1101, which can execute various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 1102 or a program loaded from a storage section 1108 into a Random Access Memory (RAM) 1103. In the RAM 1103, various programs and data required for the operation of the system 1100 are also stored. The CPU 1101, ROM 1102, and RAM 1103 are connected to each other by a bus 1104. An input/output (I/O) interface 1105 is also connected to bus 1104.
The following components are connected to the I/O interface 1105: an input section 1106 including a keyboard, a mouse, and the like; an output portion 1107 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 1108 including a hard disk or the like; and a communication section 1109 including a network interface card such as a LAN card, a modem, and the like. The communication section 1109 performs communication processing via a network such as the internet. The drive 1110 is also connected to the I/O interface 1105 as needed. Removable media 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like, is installed as needed in drive 1110, so that a computer program read therefrom is installed as needed in storage section 1108.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication portion 1109, and/or installed from the removable media 1111. The above-described functions defined in the system of the present application are performed when the computer program is executed by a Central Processing Unit (CPU) 1101.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present application, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, as: a processor comprises a buffer creation module and a data reading module. The names of these modules do not constitute a limitation on the module itself in some cases, for example, the buffer creation module may also be described as "a module for creating an address buffer inside a smart contract run by a virtual machine".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: creating an address buffer area inside an intelligent contract operated by a virtual machine; taking a storage address of external data as an entry of the intelligent contract, and reading the external data from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type. Or comprises: taking the data address of the address buffer as the parameter of an intelligent contract operated by the virtual machine, and transmitting the data address to an external system; wherein the parameter is of integer type; after the external system creates an external buffer, the data in the data address is copied to the external buffer.
According to the technical scheme of the embodiment of the invention, the address buffer area is created in the intelligent contract operated by the virtual machine, the storage address of the external data is used as the input parameter of the intelligent contract, the external data is read from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type, and the transmission of the external complex data type to the inside of the intelligent contract executed by the Webastembl virtual machine can be realized. The data address of the address buffer is used as the parameter of the intelligent contract operated by the virtual machine, the data address is transmitted to the external system, wherein the parameter is of integer type, after the external system creates the external buffer, the data in the data address is copied to the external buffer, and the complex data type can be transmitted from the inside of the virtual machine intelligent contract to the external system of the virtual machine.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (18)

1. A method for a virtual machine to read data from an external system, comprising:
creating an address buffer area in an intelligent contract operated by a virtual machine, wherein the virtual machine is a Webassembly virtual machine;
taking a storage address of external data as an entry of the intelligent contract, and reading the external data from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type.
2. The method as recited in claim 1, further comprising:
a length buffer is created inside the smart contract, the length buffer being used to store the length of the address buffer.
3. The method of claim 2, wherein the reading the external data from the memory address of the external data to the address buffer is preceded by:
And transmitting the offset to an external system where the external data is located.
4. A method according to claim 3, wherein reading the external data from the memory address of the external data to the address buffer comprises:
and reading the external data from the external system to the address buffer according to the storage address determined according to the initial address of the external data and the offset.
5. The method of claim 3, wherein the reading the external data from the memory address of the external data to the address buffer is preceded by:
and transmitting the address of the length buffer area to an external system where the external data is located, so that the external system calculates the remaining length to be read of the external data according to the buffer area length of the external system and the offset, and then writing the remaining length to be read into the address of the length buffer area.
6. The method of claim 5, wherein the reading the external data from the memory address of the external data to the address buffer comprises:
Comparing the length of the address buffer area with the length to be read, and reading byte content with the length equal to the length of the address buffer area from a storage address of the external data and copying the byte content to the address buffer area under the condition that the length of the address buffer area is smaller than or equal to the length to be read; and under the condition that the length of the address buffer area is larger than the remaining length to be read, reading byte content with the length equal to the remaining length to be read from the storage address of the external data, and copying the byte content to the address buffer area.
7. A method for a virtual machine to write data to an external system, comprising:
taking the data address of the address buffer as the parameter of an intelligent contract operated by the virtual machine, and transmitting the data address to an external system; the parameter output is of integer type, and the virtual machine is a Webassembly virtual machine;
after the external system creates an external buffer, the data in the data address is copied to the external buffer.
8. The method as recited in claim 7, further comprising: and taking the address of the length buffer area as the output parameter of the intelligent contract to be transmitted to the external system, wherein the length buffer area stores the length of the address buffer area, and the address of the length buffer area is used for the external system to read the length of the address buffer area and convert the length into the integer length so as to create the external buffer area according to the integer length.
9. An apparatus for a virtual machine to read data from an external system, wherein the virtual machine is a webassmbly virtual machine, the apparatus comprising:
the buffer zone creating module is used for creating an address buffer zone in an intelligent contract operated by the virtual machine;
and the data reading module is used for taking the storage address of the external data as the entry of the intelligent contract, and reading the external data from the storage address of the external data to the address buffer area, wherein the storage address is of an integer type.
10. The apparatus of claim 9, wherein the buffer creation module is further to:
a length buffer is created inside the smart contract, the length buffer being used to store the length of the address buffer.
11. The apparatus of claim 10, further comprising an offset delivery module to:
and transmitting the offset to an external system where the external data is located.
12. The apparatus of claim 11, wherein the data reading module is further configured to:
and reading the external data from the external system to the address buffer according to the storage address determined according to the initial address of the external data and the offset.
13. The apparatus of claim 11, further comprising a length buffer address transfer module configured to transfer an address of the length buffer to an external system where the external data is located, so that after the external system calculates a remaining length to be read of the external data according to a buffer length of the external system and the offset, the remaining length to be read is written into the address of the length buffer.
14. The apparatus of claim 13, wherein the data reading module is further configured to:
comparing the length of the address buffer area with the length to be read, and reading byte content with the length equal to the length of the address buffer area from a storage address of the external data and copying the byte content to the address buffer area under the condition that the length of the address buffer area is smaller than or equal to the length to be read; and under the condition that the length of the address buffer area is larger than the remaining length to be read, reading byte content with the length equal to the remaining length to be read from the storage address of the external data, and copying the byte content to the address buffer area.
15. An apparatus for writing data from a virtual machine to an external system, wherein the virtual machine is a webassigy virtual machine, the apparatus comprising:
The first address transfer module is used for taking the data address of the address buffer area as the parameter of the intelligent contract operated by the virtual machine and transferring the data address to an external system; wherein the parameter is of integer type;
and the data writing-out module is used for copying the data in the data address to the external buffer area after the external system creates the external buffer area.
16. The apparatus of claim 15, further comprising a second address transfer module configured to: and taking the address of the length buffer area as the output parameter of the intelligent contract to be transmitted to the external system, wherein the length buffer area stores the length of the address buffer area, and the address of the length buffer area is used for the external system to read the length of the address buffer area and convert the length into the integer length so as to create the external buffer area according to the integer length.
17. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of claims 1-8.
18. A computer readable medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the method according to any of claims 1-8.
CN202111531401.6A 2021-12-14 2021-12-14 Method and device for virtual machine to read data from external system and relevant written data Pending CN116263690A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111531401.6A CN116263690A (en) 2021-12-14 2021-12-14 Method and device for virtual machine to read data from external system and relevant written data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111531401.6A CN116263690A (en) 2021-12-14 2021-12-14 Method and device for virtual machine to read data from external system and relevant written data

Publications (1)

Publication Number Publication Date
CN116263690A true CN116263690A (en) 2023-06-16

Family

ID=86722437

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111531401.6A Pending CN116263690A (en) 2021-12-14 2021-12-14 Method and device for virtual machine to read data from external system and relevant written data

Country Status (1)

Country Link
CN (1) CN116263690A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117130721A (en) * 2023-08-04 2023-11-28 北京中电华大电子设计有限责任公司 WebAssemblely code execution method and device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117130721A (en) * 2023-08-04 2023-11-28 北京中电华大电子设计有限责任公司 WebAssemblely code execution method and device
CN117130721B (en) * 2023-08-04 2024-03-29 北京中电华大电子设计有限责任公司 WebAssemblely code execution method and device

Similar Documents

Publication Publication Date Title
CN110263277B (en) Page data display method, page data updating device, page data equipment and storage medium
CN110688096B (en) Method and device for constructing application program containing plug-in, medium and electronic equipment
CN111447257A (en) Message conversion method and device
CN110928571A (en) Business program development method and device
CN110109983B (en) Method and device for operating Redis database
CN113761871A (en) Rich text rendering method and device, electronic equipment and storage medium
CN112988583A (en) Method and device for testing syntax compatibility of database
CN114816795A (en) Interface extension method, device, remote calling server and system
CN112835568A (en) Project construction method and device
CN116263690A (en) Method and device for virtual machine to read data from external system and relevant written data
CN111767498B (en) Method and device for realizing file information sharing
CN112416303B (en) Software development kit hot repair method and device and electronic equipment
CN116781586A (en) gRPC flow analysis method, device, equipment and medium
CN109408057B (en) Method, device, medium and computing equipment for automatically generating codes
WO2023083071A1 (en) View interaction method and apparatus, electronic device, and computer readable medium
CN113779122B (en) Method and device for exporting data
CN110858240A (en) Front-end module loading method and device
CN113779018A (en) Data processing method and device
EP4109263A1 (en) Low latency remoting to accelerators
CN112925573B (en) Method, device, equipment and computer readable medium for loading web page
US20240330016A1 (en) Class file processing method and apparatus, device, medium, and product
EP4191407A1 (en) Method and device for generating and registering ui service package and loading ui service
CN112445517B (en) Inlet file generation method, device, electronic equipment and computer readable medium
CN111562913B (en) Method, device and equipment for pre-creating view component and computer readable medium
CN116521170A (en) Conversion method, device, equipment and medium of client native application

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination