The enclave runtime currently supported by runE is occlum. In order to facilitate other libos programs to run in runE, a set of enclave rumtime API interfaces is defined. Libos only needs to support this set of API interfaces to run as an enclave runtime in runE.
# 2. enclave runtime in runE
runE enclave runtime is bounded by the enclave runtime pal API layer, below the API layer is runE, above the API layer is the enclave runtime, and the operating mode is libos.
## 2.2 encalve runtime Library file naming and function naming rules
The enclave runtime is generated as a so dynamic library, which is dynamically loaded by rune using dlopen; the enclave runtime needs to export symbols according to the function named in the previous chapter.<br/>
# 3. pal interface
## 3.1 pal_version
The value of this global variable is the version of pal_api, refer to the implementation:
```c
intpal_version()
{
return2;
}
```
## 3.2 pal_init
The main task of this interface should be to create an enclave space and complete the memory layout of the enclave space; libos also needs to complete the initialization of components such as VM, FS, and NET. Reference implementation:
```c
intpal_init(conststructpal_attr_t*attr)
{
...
sgx_launch_token_ttoken;
get_token(&token);
sgx_create_enclave(...,token,...);
...
}
```
## 3.3 pal_create_process
The main job of this interface is to create a new process, reference implementation:
The main job of this interface is to run a program created by pal_create_process, refer to the implementation:
```c
intpal_exec(structpal_exec_args*args)
{
...
libos_exec(...);
...
}
```
## 3.5 pal_kill
The main job of this interface is to send a signal to the specified pid, refer to the implementation:
```c
intpal_kill(intpid,intsig)
{
...
libos_kill(...)
...
}
```
## 3.6 pal_destroy
The main job of this interface is to destroy the entire enclave space. If it is libos, you need to do component de-initialization before destroying the enclave. Reference implementation:
Enclave Runtime PAL API defines a common interface to interact between `rune` and enclave runtime.
## 1. pal_version
| **Description** | Indicate PAL API version number implemented by runelet and enclave runtime; runelet is compatible with any enclave runtimes equal to or less than the indicated value. If this symbol is undefined in enclave runtime, version 1 is assuemd by runelet. |
| :---: | :--- |
| **Prototype** | `int pal_version();` |
| **Parameters** | N/A |
| **Return value** | N/A |
| **Availability ** | >=v2 |
## 2.pal_init()
| **Description** | Do libos initialization according to the incoming attr parameters. |
| **Parameters** | @path: The path of the binary file to be run (relative path in the libos file system).<br />@argv: Binary parameters, ending with a null element.<br />@env: Binary environment variables, ending with a null element.<br />@stdio: The fd of stdio.<br />@pid: If the function return value is 0, pid stores the pid of the new process in libos. |
| **Return value** | 0: Success<br/>-EINVAL: Invalid argument<br/>-ENOSYS: The function is not supported |
| **Availability ** | >=v2 |
## 4. pal_exec
| **Description** | Execute the program corresponding to pid. |
| :---: | :--- |
| **Prototype** | struct pal_exec_args {<br/> int pid;<br/> int *exit_value;};<br />}__attribute__((packed));<br />int pal_exec(struct pal_exec_args *attr); |
| **Parameters** | @pid: The pid of the generation process.<br/>@exit_value: The exit value of the process. |
## 5.pal_kill()
| **Description** | Send signals to processes running in enclave runtime. |
| :---: | :--- |
| **Prototype** | int pal_kill(int pid, int sig); |
| **Parameters** | @pid: Send to all processes if equal to -1, or send to current process if equal to 0, or send to the process that owns the pid if others. <br/>@sig: Signal number to be sent |
| **Return value** | 0: Success<br/>-EINVAL: Invalid argument<br/>-ENOSYS: The function is not supported |
| **Availability ** | >=v2 |
## 6.pal_destroy()
| **Description** | Destroy libos instance. |
| :---: | :--- |
| **Prototype** | int pal_destroy(); |
| **Parameters** | NA. |
| **Return value** | 0: Success<br/>-ENOSYS: The function is not supported |