Unix socket communication socket file method and device across libos, electronic device and medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU NUOWEI INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-09-26
- Publication Date
- 2026-07-03
Smart Images

Figure CN115454678B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of LibOS technology, and in particular to a socket file connection method, apparatus, electronic device and medium. Background Technology
[0002] In the field of confidential computing based on Intel Instruction Set Extensions (Software Guard Extension, SGX), the common software development approach is to use C++ or Rust Software Development Kits (SDKs). While SDKs can produce high-performance SGX applications, the process of rewriting them is tantamount to building an entire ecosystem, which is prohibitively expensive for most users due to the associated development and maintenance costs. Therefore, some organizations have integrated Library Operating Systems (LibOS) into SGX, attempting to run existing software directly within their LibOS to avoid the need for SDK-based software reconstruction.
[0003] Taking Occlum, a relatively mature LibOS product and multi-process library, as an example, Occlum is a memory-safe LibOS for Intel SGX. Occlum includes several built-in Socket files for system calls within LibOS, with different Socket files corresponding to different functions. A Socket, also commonly called a "socket," describes the send and receive buffers of an established connection. Applications use read and write operations on this file to send network data. Applications typically use sockets to send requests to the network or respond to network requests.
[0004] However, currently, applications running on LibOS can only call Socket files created by LibOS itself, and cannot call Socket files created by the host machine. This means that applications running on LibOS cannot use the functions corresponding to the Socket files created by the host machine, and developers have to redevelop the corresponding functions, which increases the workload of developers. Summary of the Invention
[0005] Based on the above-mentioned situation of the prior art, the purpose of the embodiments of the present invention is to provide a Socket file connection method, device, electronic device and medium, which can reduce the workload of developers through a new LibOS connection mechanism.
[0006] To achieve the above objectives, according to one aspect of the present invention, a socket file connection method is provided. The method is applied to a target device, the target device including a LibOS kernel, a storage area, and a host kernel. The storage area stores socket files created by the LibOS kernel and socket files mapped from the host environment. The method includes:
[0007] The LibOS kernel sends a connection request to the target socket file;
[0008] When it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, a connection is established between the LibOS kernel and the target Socket file in storage;
[0009] When the LibOS kernel determines that the target socket file corresponding to the connection request is a socket file mapped from the host environment, it forwards the access request to the host kernel, and establishes a connection between the LibOS kernel and the target socket file in memory through the relay of the host kernel.
[0010] Furthermore, the method also includes:
[0011] Send the LibOS kernel connection request to the memory;
[0012] The memory sends feedback information to the LibOS kernel, including a first feedback message indicating a successful connection and a second feedback message indicating a failure to connect.
[0013] When the prompt message is the first prompt message, it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel;
[0014] When the prompt message is the second prompt message, it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment.
[0015] Furthermore, before sending the LibOS kernel connection request to the memory, the method also includes:
[0016] Obtain the Socket file type table, which contains a preset host machine Socket file list and a Socket file list within LibOS;
[0017] Based on the Socket file type table and the file information of the target Socket file corresponding to the connection request, determine whether the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, or determine whether the target Socket file corresponding to the connection request is a Socket file mapped from the host environment.
[0018] Furthermore, the method also includes:
[0019] Update the Socket file type table based on the provided prompt.
[0020] Furthermore, the method also includes:
[0021] When the file information in the Socket file type table reaches the target threshold, the type of the target Socket file is determined using the Socket file type table.
[0022] Furthermore, the method also includes:
[0023] When a match between the target socket file's file information and the socket file type table fails, the LibOS kernel sends the connection request to the memory.
[0024] Furthermore, the method also includes:
[0025] The LibOS performs data output, data input, and data processing tasks based on the target Socket file to which the connection is established.
[0026] According to a second aspect of the present invention, a socket file connection apparatus is provided, the apparatus being applied to a target device, the target device including a LibOS kernel, a storage area, and a host kernel, the storage area storing socket files created by the LibOS kernel and socket files mapped from the host environment created by the host kernel; the apparatus includes:
[0027] The connection request sending module is responsible for sending connection requests to the target Socket file via the LibOS kernel.
[0028] The first port connection module is used to establish a connection between the LibOS kernel and the target Socket file in memory when it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel.
[0029] The second port connection module is used to forward the access request to the host kernel when it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment. The LibOS kernel then establishes a connection between the LibOS kernel and the target Socket file in memory through the relay of the host kernel.
[0030] According to a third aspect of the present invention, an electronic device is provided, comprising:
[0031] processor; and
[0032] A memory having executable code stored thereon, which, when executed by a processor, performs the method as described in the first aspect of the invention.
[0033] According to a fourth aspect of the invention, one or more machine-readable storage media are provided having executable code stored thereon, which, when executed by a processor, performs the method as described in the first aspect of the invention.
[0034] In summary, embodiments of the present invention provide a socket file connection method, apparatus, electronic device, and medium. The method includes: the LibOS kernel issuing a connection request to a target socket file; when it is determined that the target socket file corresponding to the connection request is a socket file created by the LibOS kernel, establishing a connection between the LibOS kernel and the target socket file in storage; when it is determined that the target socket file corresponding to the connection request is a socket file mapped from the host environment, the LibOS kernel forwards the access request to the host kernel, and establishes a connection between the LibOS kernel and the target socket file in storage through the relay of the host kernel. The technical solution of the present invention, by providing a new LibOS connection mechanism, enables applications running in LibOS to call not only socket files created by LibOS itself, but also socket files created by the host machine. This expands the communication means and functions of LibOS without affecting existing port operations, improves the communication efficiency and reliability between LibOS and the host machine, and reduces the workload of developers. Attached Figure Description
[0035] Figure 1 This is a schematic diagram illustrating the interaction of the LibOS kernel when performing Socket file connection in existing technology;
[0036] Figure 2 This is a flowchart of the Socket file connection method provided in the embodiments of the present invention;
[0037] Figure 3This is a structural block diagram of the target device provided in the embodiments of the present invention;
[0038] Figure 4 This is a block diagram of the Socket file connection device provided in the embodiments of the present invention;
[0039] Figure 5 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0040] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments and the accompanying drawings. It should be understood that these descriptions are merely exemplary and not intended to limit the scope of the invention. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concept of the invention.
[0041] It should be noted that, unless otherwise defined, the technical or scientific terms used in one or more embodiments of the present invention should have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms "first," "second," and similar terms used in one or more embodiments of the present invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the element or object listed following the word and its equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.
[0042] In LibOS communication, taking the LibOS product Occlum as an example, external ports (Sockets) can be called through Occlum in SGX. A port (or external port) can also be referred to as a data structure. LibOS is essentially a small operating system that can meet the needs of most software development. Unix sockets allow inter-process communication without commands; communication can be performed based on addresses in files. However, some ports (Sockets) are created by the LibOS kernel, and some are created by the host machine. The LibOS kernel cannot use ports (Sockets) created by the host machine, thus leading to connection failures. Figure 1 The diagram illustrates the interaction between the LibOS kernel and port connections in the prior art. Figure 1In the data transmission path, there are ports to be connected, some created by the host machine and some by the LibOS kernel. The LibOS kernel sends a target port connection request to the data transmission path. Normally, the target port is the one created by the LibOS kernel by default. When the target port (Socket) is indeed created by the LibOS kernel, the connection succeeds. However, when a host machine port (Socket) is mapped to LibOS, attempting to allow LibOS to connect the port (Socket) to communicate with the host machine, problems arise because the mapped port (Socket) file is not associated with any application within LibOS, leading to connection failures. This invention provides a new Socket file connection method to solve the above problems.
[0043] The technical solution of the present invention will now be described in detail with reference to the accompanying drawings. Figure 2 This is a flowchart of a Socket file connection method 200 provided in an embodiment of the present invention. The method is applied to a target device, which includes a LibOS kernel, a storage area, and a host kernel. Figure 3 The diagram shows the structural block diagram of the target device, such as... Figure 3 As shown, the upper box is a structural diagram of the host kernel, the lower box is a structural diagram of the LibOS kernel (e.g., the LibOS kernel), and the middle part is a storage area that stores Socket files created by the LibOS kernel and Socket files mapped from the host environment.
[0044] The socket file connection method includes the following steps:
[0045] S202. The LibOS kernel issues a connection request to the target Socket file. This step also includes sending the LibOS kernel's connection request to the memory. For example, the connection request can be sent to the memory if the file information of the target Socket file fails to match the Socket file type table. The memory sends feedback information to the LibOS kernel. The feedback information includes a first feedback information indicating a successful connection and a second feedback information indicating a connection failure. For example, if the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, the first feedback information Ok(0) is returned; if the target Socket file corresponding to the connection request is a Socket file mapped from the host environment, ADDRESS_SPACE.get_listener_ref will return the second feedback information None, ultimately causing ADDRESS_SPACE.push_incoming to return ECONNREFUSED "no one's listening on the remote address". When the feedback information is the first feedback information, it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel; when the feedback information is the second feedback information, it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment.
[0046] According to some optional embodiments, the method may further include: updating the Socket file type table based on the prompt information; and, when the file information in the Socket file type table reaches a target threshold, using the Socket file type table to determine the type of the target Socket file.
[0047] According to some optional embodiments, before sending the LibOS kernel connection request to the memory, the method may further include: obtaining a Socket file type table, which contains a preset host Socket file list and a Socket file list within LibOS; determining, based on the Socket file type table and the file information of the target Socket file corresponding to the connection request, whether the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, or whether the target Socket file corresponding to the connection request is a Socket file mapped from the host environment. When returning a second prompt message to the LibOS kernel, the target port corresponding to the second prompt message can be recorded; the recorded target port corresponding to the second prompt message can be set as the Socket file type table. By setting this Socket file type table, all port (Socket) files in this directory are considered to be created by the host, thereby reducing one connection overhead, and this directory can be dynamically created at runtime, saving computing resources.
[0048] S204. When it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, a connection is established between the LibOS kernel and the target Socket file in memory. For example, the do_socket function can be used in LibOS to establish the above connection.
[0049] S206. When it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment, the LibOS kernel forwards the access request to the host kernel, establishing a connection between the LibOS kernel and the target Socket file in memory through the host kernel's relay. For example, when LibOS receives the second prompt message, it replaces the previously used do_socket function with the HostSocket function, uses ocall to enter the host environment, forwards the access request to the host kernel, and establishes a connection between the LibOS kernel and the target Socket file in memory through the host kernel's relay.
[0050] According to some optional embodiments, the method may further include: LibOS performing data output tasks, data input tasks, and data processing tasks based on the target Socket file for which the connection is established.
[0051] Figure 3 The block diagram of the target device shown also illustrates the interaction process of LibOS establishing a Socket connection. For example... Figure 3As shown, the target device includes the LibOS kernel, a storage area, and a host kernel. The storage area stores Socket files created by the LibOS kernel and Socket files mapped from the host environment created by the host kernel. The LibOS kernel issues a connection request to the target Socket file. Typically, the target port is the port (Socket) created by LibOS by default. When it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, a connection is established between the LibOS kernel and the target Socket file in storage. When it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment, the LibOS kernel forwards the access request to the host kernel, and the connection between the LibOS kernel and the target Socket file in storage is established through the relay of the host kernel.
[0052] The LibOS kernel uses a first connection function (e.g., the `do_socket` function) to send a target port connection request to the data transmission path. Typically, this target port is a port (Socket) created by LibOS. If the target port is a LibOS-created port (Socket), a connection result is returned upon successful connection. The LibOS kernel checks the address's validity; if valid, it copies the address to the kernel. If the target port is a port (Socket) created by the host machine, a connection failure message is returned to the LibOS kernel. In this case, the LibOS kernel initiates a connection again, this time using a second connection function (e.g., using `HostSocket` in the `do_socket` function) to enter the host environment using `ocall`. The host machine checks the address's validity; if valid, it copies the address to the kernel and establishes a corresponding target port connection based on the connection request. This target port connection is associated with the corresponding target port on the data transmission path. Upon successful connection, the result is returned to the LibOS kernel.
[0053] Another embodiment of the present invention provides a socket file connection device. The device is applied to a target device, which includes a LibOS kernel, a storage area, and a host kernel. The storage area stores socket files created by the LibOS kernel and socket files mapped from the host environment by the host kernel. Figure 4 The diagram shows a block diagram of the Socket file connection device 400, which includes:
[0054] The connection request sending module 401 sends a connection request to the target Socket file via the LibOS kernel.
[0055] The first port connection module 402 is used to establish a connection between the LibOS kernel and the target Socket file in memory when it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel.
[0056] The second port connection module 403 is used to forward the access request to the host kernel when it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment. The LibOS kernel then establishes a connection between the LibOS kernel and the target Socket file in the memory through the relay of the host kernel.
[0057] The specific process by which each module in the Socket file connection device provided in the above embodiments of the present invention implements its function is the same as the steps of the Socket file connection method provided in the above embodiments of the present invention. Therefore, repeated descriptions will be omitted here.
[0058] Figure 5 The diagram shown is a structural schematic of an electronic device according to an embodiment of the present invention. Figure 5 As shown, the electronic device 500 includes: one or more processors 501 and a memory 502; and computer program instructions stored in the memory 502, which, when executed by the processor 501, cause the processor 501 to perform the Socket file connection method as described in any of the above embodiments. The processor 501 may be a central processing unit (CPU) or other form of processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
[0059] The memory 502 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 501 may execute the program instructions to implement the steps in the Socket file connection methods of the various embodiments of the present invention described above, and / or other desired functions.
[0060] In some embodiments, the electronic device 500 may further include an input device 503 and an output device 504, these components being connected via a bus system and / or other forms of connection mechanisms. Figure 5 (Not shown in the diagram) interconnected. For example, when the electronic device is a standalone device, the input device 503 can be a communication network connector for receiving acquired input signals from external mobile devices. Furthermore, the input device 503 may also include, for example, a keyboard, mouse, microphone, etc. The output device 504 can output various information to the outside, and may include, for example, a monitor, speaker, printer, and communication network and its connected remote output devices.
[0061] In addition to the methods and devices described above, embodiments of the present invention may also be computer program products, including computer program instructions, which, when executed by a processor, cause the processor to perform the steps in the Socket file connection method as described in any of the above embodiments.
[0062] Computer program products can be written in any combination of one or more programming languages to perform the operations of the embodiments of the present invention. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0063] Furthermore, embodiments of the present invention may also be computer-readable storage media storing computer program instructions, which, when executed by a processor, cause the processor to perform the steps in the Socket file connection method of various embodiments of the present invention.
[0064] Computer-readable storage media may take the form of any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0065] It should be understood that the processor in the embodiments of the present invention can be a Central Processing Unit (CPU), or it can be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0066] In summary, the embodiments of the present invention relate to a socket file connection method, apparatus, electronic device, and medium. The method includes: the LibOS kernel issuing a connection request to a target socket file; when it is determined that the target socket file corresponding to the connection request is a socket file created by the LibOS kernel, establishing a connection between the LibOS kernel and the target socket file in storage; when it is determined that the target socket file corresponding to the connection request is a socket file mapped from the host environment, the LibOS kernel forwards the access request to the host kernel, and establishes a connection between the LibOS kernel and the target socket file in storage through the relay of the host kernel. The technical solution of the present invention provides a new LibOS connection mechanism, enabling applications running in LibOS to call not only socket files created by LibOS itself, but also socket files created by the host machine. This expands the communication means and functionality of LibOS without affecting existing port operations, improves the communication efficiency and reliability between LibOS and the host machine, and reduces the workload of developers.
[0067] It should be understood that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of the invention (including the claims) is limited to these examples. Within the framework of this invention, technical features of the above embodiments or different embodiments can also be combined, steps can be implemented in any order, and many other variations exist regarding different aspects of one or more embodiments of the invention as described above; for the sake of brevity, they are not provided in the details. The specific embodiments described above are merely illustrative or explanatory of the principles of the invention and do not constitute a limitation thereof. Therefore, any modifications, equivalent substitutions, improvements, etc., made without departing from the spirit and scope of the invention should be included within the protection scope of the invention. Furthermore, the appended claims are intended to cover all variations and modifications falling within the scope and boundaries of the appended claims, or equivalent forms of such scope and boundaries.
Claims
1. A method of socket file connection, characterized by, The method is applied to a target device, which includes a LibOS kernel, a storage area, and a host kernel. The storage area stores socket files created by the LibOS kernel and socket files mapped from the host kernel environment. The method includes: The LibOS kernel issues a connection request to the target socket file, including: Send the LibOS kernel connection request to the memory; The memory sends feedback information to the LibOS kernel, including a first feedback message indicating a successful connection and a second feedback message indicating a failure to connect. When the prompt message is the first prompt message, it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel; When the prompt message is the second prompt message, it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host machine environment; When it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, a connection is established between the LibOS kernel and the target Socket file in storage; When the LibOS kernel determines that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment, it forwards the access request to the host kernel, and establishes a connection between the LibOS kernel and the target Socket file in memory through the relay of the host kernel. The method further includes, before sending the LibOS kernel connection request to the memory: Obtain the Socket file type table, which contains a preset host machine Socket file list and a Socket file list within LibOS; Based on the Socket file type table and the file information of the target Socket file corresponding to the connection request, determine whether the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, or determine whether the target Socket file corresponding to the connection request is a Socket file mapped from the host environment; The method further includes: updating the Socket file type table based on the prompt information; and, When a match between the target socket file's file information and the socket file type table fails, the LibOS kernel sends the connection request to the memory.
2. The method of claim 1, wherein, The method further includes: When the file information in the Socket file type table reaches the target threshold, the type of the target Socket file is determined using the Socket file type table.
3. The method of claim 1, wherein, The method further includes: The LibOS performs data output, data input, and data processing tasks based on the target Socket file to which the connection is established.
4. A socket file connection apparatus, characterized by comprising: The device is applied to a target device, which includes a LibOS kernel, a storage area, and a host kernel. The storage area stores Socket files created by the LibOS kernel and Socket files mapped from the host environment. The device includes: The connection request sending module, initiated by the LibOS kernel, sends connection requests to the target socket file, including: Send the LibOS kernel connection request to the memory; The memory sends feedback information to the LibOS kernel, including a first feedback message indicating a successful connection and a second feedback message indicating a failure to connect. When the prompt message is the first prompt message, it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel; When the prompt message is the second prompt message, it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host machine environment; The device further includes the following components before sending the LibOS kernel connection request to the memory: Obtain the Socket file type table, which contains a preset host machine Socket file list and a Socket file list within LibOS; Based on the Socket file type table and the file information of the target Socket file corresponding to the connection request, determine whether the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel, or determine whether the target Socket file corresponding to the connection request is a Socket file mapped from the host environment; The first port connection module is used to establish a connection between the LibOS kernel and the target Socket file in memory when it is determined that the target Socket file corresponding to the connection request is a Socket file created by the LibOS kernel. The second port connection module is used to forward the access request to the host kernel when it is determined that the target Socket file corresponding to the connection request is a Socket file mapped from the host environment. The LibOS kernel then establishes a connection between the LibOS kernel and the target Socket file in the memory through the relay of the host kernel. The device further includes a module for updating the Socket file type table based on the prompt information; and for sending the LibOS kernel connection request to the memory when the file information of the target Socket file fails to match the Socket file type table.
5. An electronic device, comprising: include: processor; and A memory having executable code stored thereon, which, when executed by a processor, performs the method as described in any one of claims 1-3.
6. One or more machine -readable storage media having stored thereon executable code for causing a machine to perform a method comprising the steps of: When the executable code is executed by the processor, the method as described in any one of claims 1-3 is performed.