diff --git a/.asf.yaml b/.asf.yaml
new file mode 100644
index 000000000..cfb2ed0e8
--- /dev/null
+++ b/.asf.yaml
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+github:
+ description: Global-Scale Sustainable Blockchain Fabric
+ #homepage: resilientdb.apache.org
+ labels:
+ - crypto
+ - smart-contracts
+ - blockchain
+ - solidity
+ - distributed-database
+ - key-value-database
+ - distributed-ledger
+ - blockchain-platform
+ - utxo
+ enabled_merge_buttons:
+ squash: true
+ merge: false
+ rebase: false
+ protected_branches:
+ master:
+
+notifications:
+ commits: commits@resilientdb.apache.org
+ issues: commits@resilientdb.apache.org
+ pullrequests: commits@resilientdb.apache.org
diff --git a/.bazelversion b/.bazelversion
new file mode 100644
index 000000000..91e4a9f26
--- /dev/null
+++ b/.bazelversion
@@ -0,0 +1 @@
+6.3.2
diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml
index 02701aaec..0a1c92394 100644
--- a/.github/workflows/build-push.yml
+++ b/.github/workflows/build-push.yml
@@ -30,6 +30,7 @@ jobs:
with:
file: ./Docker/Dockerfile
context: .
+ platforms: linux/amd64
push: true
tags: expolab/resdb:amd64
@@ -39,5 +40,6 @@ jobs:
with:
file: ./Docker/Dockerfile_mac
context: .
+ platforms: linux/arm64
push: true
- tags: expolab/resdb:arm64
\ No newline at end of file
+ tags: expolab/resdb:arm64
diff --git a/.gitignore b/.gitignore
index 7e0ede86e..96d004d83 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
deps/*/
+scripts/deploy/config/key.conf
+scripts/deploy/config_out/
deploy/kv_server/output/
.idea/
.vscode/
@@ -9,3 +11,6 @@ bazel-*
venv
sdk_validator/venv
__pycache__
+build
+enclave/sgxcode/test
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01100cbdc..b470773df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
# Change Log
+### NexRes v1.9.0 ([2023-11-29](https://github.com/resilientdb/resilientdb/releases/tag/nexres-v1.9.0))
+
+Support Multi-version Key-Value Interface. ([Junchao Chen](https://github.com/cjcchen))
+
+* Get and Set need to provide a version number to fetch the correct version of the data (if exists) or write to the correct version of data (if not overwritten already), respectively.
+* Provide interfaces to obtain historical data with a specific version or a range of versions.
+
+
### NexRes v1.8.0 ([2023-08-21](https://github.com/resilientdb/resilientdb/releases/tag/nexres-v1.8.0))
**Implemented Enhancements:** The view-change recovery protocol was extensively expanded to support the following Byzantine failures through primary/leader replacement and replica recovery. ([Dakai Kang](https://github.com/DakaiKang))
diff --git a/Docker/Dockerfile b/Docker/Dockerfile
index 5b45b3f26..31571586e 100644
--- a/Docker/Dockerfile
+++ b/Docker/Dockerfile
@@ -33,3 +33,5 @@ COPY . /app
RUN bazel --version
RUN bazel build @com_github_bazelbuild_buildtools//buildifier:buildifier
RUN bazel build service/tools/kv/api_tools/kv_service_tools
+
+ENTRYPOINT ["./entrypoint.sh"]
\ No newline at end of file
diff --git a/Docker/Dockerfile_mac b/Docker/Dockerfile_mac
index eb47e0ce9..211976d87 100644
--- a/Docker/Dockerfile_mac
+++ b/Docker/Dockerfile_mac
@@ -30,3 +30,5 @@ COPY . /app
RUN bazel --version
RUN bazel build @com_github_bazelbuild_buildtools//buildifier:buildifier
RUN bazel build service/tools/kv/api_tools/kv_service_tools
+
+ENTRYPOINT ["./entrypoint.sh"]
diff --git a/Fides_extended_version.pdf b/Fides_extended_version.pdf
new file mode 100644
index 000000000..4d7126a2d
Binary files /dev/null and b/Fides_extended_version.pdf differ
diff --git a/INSTALL.sh b/INSTALL.sh
index c64fb0e3d..882d3427a 100755
--- a/INSTALL.sh
+++ b/INSTALL.sh
@@ -7,7 +7,7 @@ curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
-sudo apt update && sudo apt install bazel=5.0.0 -y
+sudo apt update && sudo apt install bazel=6.3.2 -y
sudo apt install clang-format -y
rm $PWD/.git/hooks/pre-push
ln -s $PWD/hooks/pre-push $PWD/.git/hooks/pre-push
@@ -27,7 +27,7 @@ cd bazel_build
unzip bazel-6.0.0-dist.zip
-export JAVA_HOME='/usr/lib/jvm/java-1.11.0-openjdk-arm64/'
+export JAVA_HOME='/usr/lib/jvm/java-1.11.0-openjdk-amd64'
env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" bash ./compile.sh
sudo cp output/bazel /usr/local/bin/
cd ..
@@ -40,3 +40,14 @@ bazel build @com_github_bazelbuild_buildtools//buildifier:buildifier
sudo apt-get install python3.10-dev -y
sudo apt-get install python3-dev -y
+
+# Build sgx code
+cd enclave/
+rm ./sgx_cpp_*
+cd sgxcode/
+rm -rf build || true
+mkdir build && cd build/
+cmake .. && make
+cd ../..
+cp sgxcode/build/host/sgx_cpp_* ./
+ldconfig /usr/local/lib64/
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 000000000..311b43605
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache ResilientDB
+Copyright 2023-2024 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (/).
diff --git a/README.md b/README.md
index 709ecfdbd..9e14458a8 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,13 @@
4. ResilientDB exposes a wide range of interfaces such as a **Key-Value** store, **Smart Contracts**, **UTXO**, and **Python SDK**. Following are some of the decentralized applications (DApps) built on top of ResilientDB: **[NFT Marketplace](https://nft.resilientdb.com/)** and **[Debitable](https://debitable.resilientdb.com/)**.
5. To persist blockchain, chain state, and metadata, ResilientDB provides durability through **LevelDB** and **RocksDB**.
6. ResilientDB provides access to a seamless **GUI display** for deployment and maintenance, and supports **Grafana** for plotting monitoring data.
-7. **[Historial Facts]** The ResilientDB project was founded by **[Mohammad Sadoghi](https://expolab.org/)** along with his students ([Suyash Gupta](https://gupta-suyash.github.io/index.html) as the lead Architect, [Sajjad Rahnama](https://sajjadrahnama.com/), [Jelle Hellings](https://www.jhellings.nl/)) at **[UC Davis](https://www.ucdavis.edu/)** in 2018 and was open-sourced in late 2019. On September 30, 2021, we released ResilientDB v-3.0. In 2022, ResilientDB was completely re-written and re-architected ([Junchao Chen](https://github.com/cjcchen) as the lead Architect along with the entire [NexRes Team](https://resilientdb.com/)), paving the way for a new sustainable foundation, referred to as NexRes (Next Generation ResilientDB). Thus, on September 30, 2022, NexRes-v1.0.0 was born, marking a new beginning for **[ResilientDB](https://resilientdb.com/)**.
+7. **[Historial Facts]** The ResilientDB project was founded by **[Mohammad Sadoghi](https://expolab.org/)** along with his students ([Suyash Gupta](https://gupta-suyash.github.io/index.html) as the lead Architect, [Sajjad Rahnama](https://sajjadrahnama.com/) as the lead System Designer, and [Jelle Hellings](https://www.jhellings.nl/)) at **[UC Davis](https://www.ucdavis.edu/)** in 2018 and was open-sourced in late 2019. On September 30, 2021, we released ResilientDB v-3.0. In 2022, ResilientDB was completely re-written and re-architected ([Junchao Chen](https://github.com/cjcchen) as the lead Architect, [Dakai Kang](https://github.com/DakaiKang) as the lead Recovery Architect along with the entire [NexRes Team](https://resilientdb.com/)), paving the way for a new sustainable foundation, referred to as NexRes (Next Generation ResilientDB). Thus, on September 30, 2022, NexRes-v1.0.0 was born, marking a new beginning for **[ResilientDB](https://resilientdb.com/)**. On October 21, 2023, **[ResilientDB](https://cwiki.apache.org/confluence/display/INCUBATOR/ResilientDBProposal)** was officially accepted into **[Apache Incubation](https://incubator.apache.org/projects/resilientdb.html)**.
+
+
---
@@ -44,10 +50,12 @@ The latest ResilientDB documentation, including a programming guide, is availabl
- System Parameters & Configuration
- Continuous Integration & Testing
-![Nexres](./img/nexres.png)
+
+
+
## OS Requirements
-Ubuntu 20.*
+Ubuntu 20+
---
@@ -70,29 +78,219 @@ Build Interactive Tools:
bazel build service/tools/kv/api_tools/kv_service_tools
-Run tools to set a value by a key (for example, set the value with key "test" and value "test_value"):
+## Functions ##
+ResilientDB supports two types of functions: version-based and non-version-based.
+Version-based functions will leverage versions to protect each update, versions must be obtained before updating a key.
- bazel-bin/service/tools/kv/api_tools/kv_service_tools service/tools/config/interface/service.config set test test_value
-
-You will see the following result if successful:
+***Note***: Version-based functions are not compatible with non-version-based functions. Do not use both in your applications.
- client set ret = 0
+We show the functions below and show how to use [kv_service_tools](service/tools/kv/api_tools/kv_service_tools.cpp) to test the function.
-Run tools to get value by a key (for example, get the value with key "test"):
+### Version-Based Functions ###
+#### Get ####
+Obtain the value of `key` with a specific version `v`.
- bazel-bin/service/tools/kv/api_tools/kv_service_tools service/tools/config/interface/service.config get test
-
-You will see the following result if successful:
+ kv_service_tools --config config_file --cmd get_with_version --key key --version v
+
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | get_with_version |
+| key | the key you want to obtain |
+| version | the version you want to obtain. (If the `v` is 0, it will return the latest version |
+
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd get_with_version --key key1 --version 0
+
+Results:
+> get key = key1, value = value: "v2"
+> version: 2
+
+#### Set ####
+Set `value` to the key `key` based on version `v`.
+
+ kv_service_tools --config config_file --cmd set_with_version --key key --version v --value value
+
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | set_with_version |
+| key | the key you want to set |
+| version | the version you have obtained. (If the version has been changed during the update, the transaction will be ignored) |
+| value | the new value |
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd set_with_version --key key1 --version 0 --value v1
+
+Results:
+> set key = key1, value = v3, version = 2 done, ret = 0
+>
+> current value = value: "v3"
+> version: 3
+
+#### Get Key History ####
+Obtain the update history of key `key` within the versions [`v1`, `v2`].
+
+ kv_service_tools --config config_file --cmd get_history --key key --min_version v1 --max_version v2
+
+
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | get_history |
+| key | the key you want to obtain |
+| min_version | the minimum version you want to obtain |
+| max_version | the maximum version you want to obtain |
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd get_history --key key1 --min_version 1 --max_version 2
+
+Results:
+
+> get history key = key1, min version = 1, max version = 2
+> value =
+> item {
+> key: "key1"
+> value_info {
+> value: "v1"
+> version: 2
+> }
+> }
+> item {
+> key: "key1"
+> value_info {
+> value: "v0"
+> version: 1
+> }
+> }
+
+#### Get Top ####
+Obtain the recent `top_number` history of the key `key`.
+
+ kv_service_tools --config config_path --cmd get_top --key key --top top_number
+
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | get_top |
+| key | the key you want to obtain |
+| top | the number of the recent updates |
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd get_top --key key1 --top 1
+
+Results:
- client get value = test_value
+>key = key1, top 1
+> value =
+> item {
+> key: "key1"
+> value_info {
+> value: "v2"
+> version: 3
+> }
+>}
-Run tools to get all values that have been set:
+#### Get Key Range ####
+Obtain the values of the keys in the ranges [`key1`, `key2`]. Do not use this function in your practice code
- bazel-bin/service/tools/kv/api_tools/kv_service_tools service/tools/config/interface/service.config getvalues
+ kv_service_tools --config config_file --cmd get_key_range_with_version --min_key key1 --max_key key2
-You will see the following result if successful:
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | get_key_range_with_version |
+| min_key | the minimum key |
+| max_key | the maximum key |
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd get_key_range_with_version --min_key key1 --max_key key3
+
+Results:
+
+>min key = key1 max key = key2
+> getrange value =
+> item {
+> key: "key1"
+> value_info {
+> value: "v0"
+> version: 1
+> }
+> }
+> item {
+> key: "key2"
+> value_info {
+> value: "v1"
+> version: 1
+> }
+>}
+
+
+### Non-Version-Based Function ###
+#### Set #####
+Set `value` to the key `key`.
+
+ kv_service_tools --config config_file --cmd set --key key --value value
+
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | set |
+| key | the key you want to set |
+| value | the new value |
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd set --key key1 --value value1
+
+Results:
+> set key = key1, value = v1, done, ret = 0
+
+#### Get ####
+Obtain the value of `key`.
+
+ kv_service_tools --config config_file --cmd get --key key
+
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | get |
+| key | the key you want to obtain |
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd get --key key1
+
+Results:
+> get key = key1, value = "v2"
+
+
+#### Get Key Range ####
+Obtain the values of the keys in the ranges [`key1`, `key2`]. Do not use this function in your practice code
+
+ kv_service_tools --config config_path --cmd get_key_range --min_key key1 --max_key key2
+
+| parameters | descriptions |
+| ---- | ---- |
+| config | the path of the client config which points to the db entrance |
+| cmd | get_key_range |
+| min_key | the minimum key |
+| max_key | the maximum key |
+
+Example:
+
+ bazel-bin/service/tools/kv/api_tools/kv_service_tools --config service/tools/config/interface/service.config --cmd get_key_range --min_key key1 --max_key key3
+
+Results:
+> getrange min key = key1, max key = key3
+> value = [v3,v2,v1]
- client getvalues value = [test_value]
## Deployment Script
@@ -121,28 +319,18 @@ We also provide access to a [deployment script](https://github.com/resilientdb/r
- For amd architecture, run:
```shell
- docker run -it expolab/resdb:amd64 bash
+ docker run -d --name myserver expolab/resdb:amd64
```
- For Apple Silicon (M1/M2) architecture, run:
```shell
- docker run -it expolab/resdb:arm64 bash
+ docker run -d --name myserver expolab/resdb:arm64
```
-4. **Start the kv_service within the Container**
- Once you're inside the container, start the `kv_service` by running the following command:
+4. **Test with Set and Get Commands**
+ Exec into the running server:
```shell
- ./service/tools/kv/server_tools/start_kv_service.sh
+ docker exec -it myserver bash
```
-5. **Test with Set and Get Commands**
- Verify the functionality of the service by performing set and get operations:
- - Set a test value:
- ```shell
- bazel-bin/service/tools/kv/api_tools/kv_service_tools service/tools/config/interface/service.config set test test_value
- ```
-
- - Retrieve the test value:
- ```
- bazel-bin/service/tools/kv/api_tools/kv_service_tools service/tools/config/interface/service.config get test
- ```
\ No newline at end of file
+ Verify the functionality of the service by performing set and get operations provided above [functions](README.md#functions).
diff --git a/WORKSPACE b/WORKSPACE
index 317fefbfa..d97d40690 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,6 +3,36 @@ workspace(name = "com_resdb_nexres")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:repositories.bzl", "nexres_repositories")
+new_local_repository(
+ name = "openenclave_host",
+ path = "/opt/openenclave_0_17_0",
+ build_file_content = """
+cc_import(
+ name = "oehost_lib",
+ static_library = "lib/openenclave/host/liboehost.a",
+ visibility = ["//visibility:public"],
+)
+
+exports_files(["lib/openenclave/host/liboehost.a"])
+"""
+)
+
+new_local_repository(
+ name = "openenclave",
+ path = "/opt/openenclave_0_17_0/include",
+ build_file_content = """
+package(default_visibility = ["//visibility:public"])
+filegroup(
+ name = "headerfile",
+ srcs = glob(["**/*.h"]),
+)
+cc_library(
+ name = "headers",
+ hdrs = [":headerfile"]
+)
+"""
+)
+
nexres_repositories()
http_archive(
@@ -198,8 +228,8 @@ http_archive(
http_archive(
name = "pybind11_bazel",
- strip_prefix = "pybind11_bazel-master",
- urls = ["https://github.com/pybind/pybind11_bazel/archive/master.zip"],
+ strip_prefix = "pybind11_bazel-2.11.1.bzl.1",
+ urls = ["https://github.com/pybind/pybind11_bazel/archive/refs/tags/v2.11.1.bzl.1.zip"]
)
http_archive(
diff --git a/benchmark/protocols/fides/BUILD b/benchmark/protocols/fides/BUILD
new file mode 100644
index 000000000..575fc031f
--- /dev/null
+++ b/benchmark/protocols/fides/BUILD
@@ -0,0 +1,18 @@
+package(default_visibility = ["//visibility:private"])
+
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
+
+cc_binary(
+ name = "kv_server_performance",
+ srcs = ["kv_server_performance.cpp"],
+ copts = ["-Iexternal/openenclave"],
+ deps = [
+ "//chain/storage:memory_db",
+ "//executor/kv:kv_executor",
+ "//platform/config:resdb_config_utils",
+ "//platform/consensus/ordering/fides/framework:consensus",
+ "//service/utils:server_factory",
+ "//enclave:headers",
+ ],
+)
+
diff --git a/benchmark/protocols/fides/kv_server_performance.cpp b/benchmark/protocols/fides/kv_server_performance.cpp
new file mode 100644
index 000000000..32b640dd6
--- /dev/null
+++ b/benchmark/protocols/fides/kv_server_performance.cpp
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include
+
+#include "chain/storage/memory_db.h"
+#include "enclave/sgx_cpp_u.h"
+#include "executor/kv/kv_executor.h"
+#include "platform/config/resdb_config_utils.h"
+#include "platform/consensus/ordering/fides/framework/consensus.h"
+#include "platform/networkstrate/service_network.h"
+#include "platform/statistic/stats.h"
+#include "proto/kv/kv.pb.h"
+#include
+#include
+#include
+#include
+
+using namespace resdb;
+using namespace resdb::fides;
+using namespace resdb::storage;
+
+
+unsigned char* key_buf;
+size_t key_len = 0;
+oe_enclave_t* enclave = NULL;
+oe_result_t result;
+int ret = 0;
+uint32_t flags = OE_ENCLAVE_FLAG_DEBUG;
+
+BIO *bio = BIO_new_mem_buf(key_buf, -1);
+RSA *pub_key = NULL;
+size_t encrypted_len;
+unsigned char* encrypted_data;
+
+bool check_simulate_opt(int* argc, char* argv[]) {
+ for (int i = 0; i < *argc; i++) {
+ if (strcmp(argv[i], "--simulate") == 0) {
+ std::cout << "Running in simulation mode" << std::endl;
+ memmove(&argv[i], &argv[i + 1], (*argc - i) * sizeof(char*));
+ (*argc)--;
+ return true;
+ }
+ }
+ return false;
+}
+
+void ShowUsage() {
+ printf(" [logging_dir]\n");
+}
+
+std::string GetRandomKey() {
+ int num1 = rand() % 10;
+ int num2 = rand() % 10;
+ return std::to_string(num1) + std::to_string(num2);
+}
+
+std::string GetEncryptedRandomKey() {
+ int num1 = rand() % 10;
+ int num2 = rand() % 10;
+ std::string key = std::to_string(num1) + std::to_string(num2);
+ std::cout<<"key: "<(key.c_str());
+
+ encrypted_data = new unsigned char[encrypted_len]; // Initialize buffer
+ std::cout<<"Before RSA_public_encrypt." << std::endl;
+ size_t result_len = RSA_public_encrypt(key.size(), key_data, encrypted_data,
+ pub_key, RSA_PKCS1_PADDING);
+
+ std::string encrypted_key(encrypted_data, encrypted_data + result_len);
+ std::cout<<"encrypted_key: "<= 6) {
+ auto monitor_port = Stats::GetGlobalStats(5);
+ monitor_port->SetPrometheus(argv[5]);
+ }
+
+ printf("Run 1\n");
+ std::unique_ptr config =
+ GenerateResDBConfig(config_file, private_key_file, cert_file);
+
+ config->RunningPerformance(true);
+ ResConfigData config_data = config->GetConfigData();
+
+ std::cout << "kv_server: reseting prng" << std::endl;
+ // Predefined key, can replace it by using some DKG protocol
+ uint32_t rdrandNum = 123456789;
+ uint32_t totalNum = config->GetReplicaNum();
+ result = reset_prng(enclave, &ret, &rdrandNum, &totalNum);
+ if (result != OE_OK) {
+ ret = 1;
+ }
+ if (ret != 0) {
+ std::cerr << "kv_server_performance: reset_prng failed with " << ret << std::endl;
+ } else {
+ std::cout << "kv_server_performance: reset_prng succeeded." << std::endl;
+ }
+
+ std::cout << "kv_server_performance: requesting counter" << std::endl;
+ uint32_t index;
+ result = request_counter(enclave, &ret, &index);
+ if (result != OE_OK) {
+ ret = 1;
+ }
+ if (ret != 0) {
+ std::cerr << "kv_server_performance: request_counter failed with " << ret << std::endl;
+ } else {
+ std::cout << "kv_server_performance: request_counter succeeded with index: " << index << std::endl;
+ }
+
+
+ auto performance_consens = std::make_unique(
+ *config, std::make_unique(std::make_unique()), enclave);
+
+/* // For transaction decryption
+
+ std::cout << "kv_server_performance: generate key" << std::endl;
+ size_t key_size = 2048;
+ result = generate_key(enclave, &ret, &key_size);
+ std::cout << "After generate_key" << std::endl;
+ if (result != OE_OK || ret != 0) {
+ std::cerr << "kv_server_performance: generate_key failed with " << ret << std::endl;
+ // goto exit;
+ }
+
+ result = get_pubkey(enclave, &ret, &key_buf, &key_len);
+
+ bio = BIO_new_mem_buf(key_buf, -1);
+ pub_key = NULL;
+ PEM_read_bio_RSAPublicKey(bio, &pub_key, NULL, NULL);
+
+ encrypted_len = RSA_size(pub_key);
+ encrypted_data = new unsigned char[encrypted_len]; // Initialize buffer
+
+
+{
+ // KVRequest request;
+ // request.set_cmd(KVRequest::SET);
+ // request.set_key(GetEncryptedRandomKey());
+ // request.set_value("helloworld");
+
+
+ // int requestSize = request.ByteSizeLong();
+ // unsigned char* binary_data = new unsigned char[requestSize];
+
+ // if (request.SerializeToArray(binary_data, requestSize)) {
+ // std::cout << "Serialization successful!" << std::endl;
+ // } else {
+ // std::cerr << "Serialization failed!" << std::endl;
+ // }
+
+ // std::cout << "kv_server_performance: encrypt data" << std::endl;
+ // unsigned char* encrypted_data = nullptr;
+ // size_t encrypted_len = 0;
+ // result = encrypt(enclave, &ret, binary_data,
+ // &encrypted_data, requestSize,&encrypted_len);
+
+ // printf("kv_server_performance: Finish encrypt data\n");
+ // printf("encrypted_data: %s\n", encrypted_data);
+
+ // std::string request_data(encrypted_data, encrypted_data + encrypted_len);
+
+
+ KVRequest request;
+ request.set_cmd(KVRequest::SET);
+ request.set_key(GetRandomKey());
+ request.set_value("helloworld");
+ std::string request_data;
+ request.SerializeToString(&request_data);
+
+ const unsigned char* request_data_char = reinterpret_cast(request_data.c_str());
+
+ encrypted_data = new unsigned char[encrypted_len]; // Initialize buffer
+ std::cout<<"Before RSA_public_encrypt.";
+ size_t result_len = RSA_public_encrypt(request_data.size(), request_data_char, encrypted_data,
+ pub_key, RSA_PKCS1_PADDING);
+
+ std::string encrypted_data_str(encrypted_data, encrypted_data + result_len);
+
+ performance_consens->SetupPerformanceDataFunc([encrypted_data_str]() {
+ return encrypted_data_str;
+ });
+}
+
+ printf("Run 4\n");
+*/
+
+ performance_consens->SetupPerformanceDataFunc([]() {
+ KVRequest request;
+ request.set_cmd(KVRequest::SET);
+ request.set_key(GetRandomKey());
+ request.set_value("helloworld");
+ std::string request_data;
+ request.SerializeToString(&request_data);
+ return request_data;
+ });
+
+ auto server =
+ std::make_unique(*config,
+ std::move(performance_consens));
+ server->Run();
+
+ BIO_free_all(bio);
+ // delete[] binary_data;
+}
diff --git a/benchmark/protocols/fides/kv_service_tools.cpp b/benchmark/protocols/fides/kv_service_tools.cpp
new file mode 100644
index 000000000..17858ef21
--- /dev/null
+++ b/benchmark/protocols/fides/kv_service_tools.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "common/proto/signature_info.pb.h"
+#include "interface/kv/kv_client.h"
+#include "platform/config/resdb_config_utils.h"
+
+using resdb::GenerateReplicaInfo;
+using resdb::GenerateResDBConfig;
+using resdb::KVClient;
+using resdb::ReplicaInfo;
+using resdb::ResDBConfig;
+
+int main(int argc, char** argv) {
+ if (argc < 2) {
+ printf("\n");
+ return 0;
+ }
+ std::string client_config_file = argv[1];
+ ResDBConfig config = GenerateResDBConfig(client_config_file);
+
+ config.SetClientTimeoutMs(100000);
+
+ KVClient client(config);
+
+ client.Set("start", "value");
+ printf("start benchmark\n");
+}
diff --git a/benchmark/protocols/pbft/BUILD b/benchmark/protocols/pbft/BUILD
index 456d6d4c0..659280d97 100644
--- a/benchmark/protocols/pbft/BUILD
+++ b/benchmark/protocols/pbft/BUILD
@@ -6,6 +6,7 @@ cc_binary(
name = "kv_server_performance",
srcs = ["kv_server_performance.cpp"],
deps = [
+ "//chain/storage:memory_db",
"//executor/kv:kv_executor",
"//platform/config:resdb_config_utils",
"//platform/consensus/ordering/pbft:consensus_manager_pbft",
diff --git a/benchmark/protocols/pbft/kv_server_performance.cpp b/benchmark/protocols/pbft/kv_server_performance.cpp
index 8efd5b932..7a81f27c7 100644
--- a/benchmark/protocols/pbft/kv_server_performance.cpp
+++ b/benchmark/protocols/pbft/kv_server_performance.cpp
@@ -1,31 +1,25 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include
-#include "chain/state/chain_state.h"
+#include "chain/storage/memory_db.h"
#include "executor/kv/kv_executor.h"
#include "platform/config/resdb_config_utils.h"
#include "platform/consensus/ordering/pbft/consensus_manager_pbft.h"
@@ -34,6 +28,7 @@
#include "proto/kv/kv.pb.h"
using namespace resdb;
+using namespace resdb::storage;
void ShowUsage() {
printf(" [logging_dir]\n");
@@ -69,7 +64,7 @@ int main(int argc, char** argv) {
config->RunningPerformance(true);
auto performance_consens = std::make_unique(
- *config, std::make_unique(std::make_unique()));
+ *config, std::make_unique(std::make_unique()));
performance_consens->SetupPerformanceDataFunc([]() {
KVRequest request;
request.set_cmd(KVRequest::SET);
diff --git a/benchmark/protocols/pbft/kv_service_tools.cpp b/benchmark/protocols/pbft/kv_service_tools.cpp
index 17858ef21..43627b34f 100644
--- a/benchmark/protocols/pbft/kv_service_tools.cpp
+++ b/benchmark/protocols/pbft/kv_service_tools.cpp
@@ -1,26 +1,20 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include
diff --git a/benchmark/protocols/poe/BUILD b/benchmark/protocols/poe/BUILD
new file mode 100644
index 000000000..e7bbde3b1
--- /dev/null
+++ b/benchmark/protocols/poe/BUILD
@@ -0,0 +1,16 @@
+package(default_visibility = ["//visibility:private"])
+
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
+
+cc_binary(
+ name = "kv_server_performance",
+ srcs = ["kv_server_performance.cpp"],
+ deps = [
+ "//chain/storage:memory_db",
+ "//executor/kv:kv_executor",
+ "//platform/config:resdb_config_utils",
+ "//platform/consensus/ordering/poe/framework:consensus",
+ "//service/utils:server_factory",
+ ],
+)
+
diff --git a/benchmark/protocols/poe/kv_server_performance.cpp b/benchmark/protocols/poe/kv_server_performance.cpp
new file mode 100644
index 000000000..fa13e9a94
--- /dev/null
+++ b/benchmark/protocols/poe/kv_server_performance.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include
+
+#include "chain/storage/memory_db.h"
+#include "executor/kv/kv_executor.h"
+#include "platform/config/resdb_config_utils.h"
+#include "platform/consensus/ordering/poe/framework/consensus.h"
+#include "platform/networkstrate/service_network.h"
+#include "platform/statistic/stats.h"
+#include "proto/kv/kv.pb.h"
+
+using namespace resdb;
+using namespace resdb::poe;
+using namespace resdb::storage;
+
+void ShowUsage() {
+ printf(" [logging_dir]\n");
+}
+
+std::string GetRandomKey() {
+ int num1 = rand() % 10;
+ int num2 = rand() % 10;
+ return std::to_string(num1) + std::to_string(num2);
+}
+
+int main(int argc, char** argv) {
+ if (argc < 3) {
+ ShowUsage();
+ exit(0);
+ }
+
+ // google::InitGoogleLogging(argv[0]);
+ // FLAGS_minloglevel = google::GLOG_WARNING;
+
+ char* config_file = argv[1];
+ char* private_key_file = argv[2];
+ char* cert_file = argv[3];
+
+ if (argc >= 5) {
+ auto monitor_port = Stats::GetGlobalStats(5);
+ monitor_port->SetPrometheus(argv[4]);
+ }
+
+ std::unique_ptr config =
+ GenerateResDBConfig(config_file, private_key_file, cert_file);
+
+ config->RunningPerformance(true);
+ ResConfigData config_data = config->GetConfigData();
+
+ auto performance_consens = std::make_unique(
+ *config, std::make_unique(std::make_unique()));
+ performance_consens->SetupPerformanceDataFunc([]() {
+ KVRequest request;
+ request.set_cmd(KVRequest::SET);
+ request.set_key(GetRandomKey());
+ request.set_value("helloword");
+ std::string request_data;
+ request.SerializeToString(&request_data);
+ return request_data;
+ });
+
+ auto server =
+ std::make_unique(*config, std::move(performance_consens));
+ server->Run();
+}
diff --git a/benchmark/protocols/poe/kv_service_tools.cpp b/benchmark/protocols/poe/kv_service_tools.cpp
new file mode 100644
index 000000000..17858ef21
--- /dev/null
+++ b/benchmark/protocols/poe/kv_service_tools.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "common/proto/signature_info.pb.h"
+#include "interface/kv/kv_client.h"
+#include "platform/config/resdb_config_utils.h"
+
+using resdb::GenerateReplicaInfo;
+using resdb::GenerateResDBConfig;
+using resdb::KVClient;
+using resdb::ReplicaInfo;
+using resdb::ResDBConfig;
+
+int main(int argc, char** argv) {
+ if (argc < 2) {
+ printf("\n");
+ return 0;
+ }
+ std::string client_config_file = argv[1];
+ ResDBConfig config = GenerateResDBConfig(client_config_file);
+
+ config.SetClientTimeoutMs(100000);
+
+ KVClient client(config);
+
+ client.Set("start", "value");
+ printf("start benchmark\n");
+}
diff --git a/chain/state/BUILD b/chain/state/BUILD
index 900212ddc..5bd5d1181 100644
--- a/chain/state/BUILD
+++ b/chain/state/BUILD
@@ -5,8 +5,8 @@ cc_library(
srcs = ["chain_state.cpp"],
hdrs = ["chain_state.h"],
deps = [
- "//chain/storage",
"//common:comm",
+ "//platform/proto:resdb_cc_proto",
],
)
diff --git a/chain/state/chain_state.cpp b/chain/state/chain_state.cpp
index 98a82e6b6..18eaed71b 100644
--- a/chain/state/chain_state.cpp
+++ b/chain/state/chain_state.cpp
@@ -1,26 +1,20 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "chain/state/chain_state.h"
@@ -29,64 +23,22 @@
namespace resdb {
-ChainState::ChainState(std::unique_ptr storage)
- : storage_(std::move(storage)) {}
-
-Storage* ChainState::GetStorage() {
- return storage_ ? storage_.get() : nullptr;
-}
+ChainState::ChainState() : max_seq_(0) {}
-int ChainState::SetValue(const std::string& key, const std::string& value) {
- if (storage_) {
- return storage_->SetValue(key, value);
+Request* ChainState::Get(uint64_t seq) {
+ std::unique_lock lk(mutex_);
+ if (data_.find(seq) == data_.end()) {
+ return nullptr;
}
- kv_map_[key] = value;
- return 0;
+ return data_[seq].get();
}
-std::string ChainState::GetValue(const std::string& key) {
- if (storage_) {
- return storage_->GetValue(key);
- }
- auto search = kv_map_.find(key);
- if (search != kv_map_.end())
- return search->second;
- else {
- return "";
- }
+void ChainState::Put(std::unique_ptr request) {
+ std::unique_lock lk(mutex_);
+ max_seq_ = request->seq();
+ data_[max_seq_] = std::move(request);
}
-std::string ChainState::GetAllValues(void) {
- if (storage_) {
- return storage_->GetAllValues();
- }
- std::string values = "[";
- bool first_iteration = true;
- for (auto kv : kv_map_) {
- if (!first_iteration) values.append(",");
- first_iteration = false;
- values.append(kv.second);
- }
- values.append("]");
- return values;
-}
-
-std::string ChainState::GetRange(const std::string& min_key,
- const std::string& max_key) {
- if (storage_) {
- return storage_->GetRange(min_key, max_key);
- }
- std::string values = "[";
- bool first_iteration = true;
- for (auto kv : kv_map_) {
- if (kv.first >= min_key && kv.first <= max_key) {
- if (!first_iteration) values.append(",");
- first_iteration = false;
- values.append(kv.second);
- }
- }
- values.append("]");
- return values;
-}
+uint64_t ChainState::GetMaxSeq() { return max_seq_; }
} // namespace resdb
diff --git a/chain/state/chain_state.h b/chain/state/chain_state.h
index e2671ab59..697b1afcb 100644
--- a/chain/state/chain_state.h
+++ b/chain/state/chain_state.h
@@ -1,50 +1,42 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#pragma once
-#include
+#include
#include
-#include "chain/storage/storage.h"
+#include "platform/proto/resdb.pb.h"
namespace resdb {
class ChainState {
public:
- ChainState(std::unique_ptr storage = nullptr);
- int SetValue(const std::string& key, const std::string& value);
- std::string GetValue(const std::string& key);
- std::string GetAllValues(void);
- std::string GetRange(const std::string& min_key, const std::string& max_key);
-
- Storage* GetStorage();
+ ChainState();
+ Request* Get(uint64_t seq);
+ void Put(std::unique_ptr request);
+ uint64_t GetMaxSeq();
private:
- std::unique_ptr storage_ = nullptr;
- std::unordered_map kv_map_;
+ std::mutex mutex_;
+ std::unordered_map > data_;
+ std::atomic max_seq_;
};
} // namespace resdb
diff --git a/chain/state/chain_state_test.cpp b/chain/state/chain_state_test.cpp
index 0d0fda1e4..7fd3fbe19 100644
--- a/chain/state/chain_state_test.cpp
+++ b/chain/state/chain_state_test.cpp
@@ -1,26 +1,20 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "chain/state/chain_state.h"
@@ -28,25 +22,42 @@
#include
#include
+#include "common/test/test_macros.h"
+
namespace resdb {
namespace {
-TEST(KVServerExecutorTest, SetValue) {
- ChainState state;
+using ::resdb::testing::EqualsProto;
+using ::testing::Pointee;
+
+TEST(ChainStateTest, GetEmptyValue) {
+ ChainState db;
+ EXPECT_EQ(db.Get(1), nullptr);
+}
- EXPECT_EQ(state.GetAllValues(), "[]");
- EXPECT_EQ(state.SetValue("test_key", "test_value"), 0);
- EXPECT_EQ(state.GetValue("test_key"), "test_value");
+TEST(ChainStateTest, GetValue) {
+ Request request;
+ request.set_seq(1);
+ request.set_data("test");
- // GetValues and GetRange may be out of order for in-memory, so we test up to
- // 1 key-value pair
- EXPECT_EQ(state.GetAllValues(), "[test_value]");
- EXPECT_EQ(state.GetRange("a", "z"), "[test_value]");
+ ChainState db;
+ db.Put(std::make_unique(request));
+ EXPECT_THAT(db.Get(1), Pointee(EqualsProto(request)));
}
-TEST(KVServerExecutorTest, GetValue) {
- ChainState state;
- EXPECT_EQ(state.GetValue("test_key"), "");
+TEST(ChainStateTest, GetSecondValue) {
+ Request request;
+ request.set_seq(1);
+ request.set_data("test");
+
+ ChainState db;
+ db.Put(std::make_unique(request));
+
+ request.set_seq(1);
+ request.set_data("test_1");
+ db.Put(std::make_unique(request));
+
+ EXPECT_THAT(db.Get(1), Pointee(EqualsProto(request)));
}
} // namespace
diff --git a/chain/storage/BUILD b/chain/storage/BUILD
index 0a0c8e7ff..57904291c 100644
--- a/chain/storage/BUILD
+++ b/chain/storage/BUILD
@@ -16,55 +16,49 @@ cc_library(
)
cc_library(
- name = "res_leveldb",
- srcs = ["res_leveldb.cpp"],
- hdrs = ["res_leveldb.h"],
+ name = "memory_db",
+ srcs = ["memory_db.cpp"],
+ hdrs = ["memory_db.h"],
deps = [
":storage",
"//common:comm",
- "//platform/proto:replica_info_cc_proto",
- "//third_party:leveldb",
],
)
-cc_test(
- name = "res_leveldb_test",
- srcs = ["res_leveldb_test.cpp"],
+cc_library(
+ name = "leveldb",
+ srcs = ["leveldb.cpp"],
+ hdrs = ["leveldb.h"],
deps = [
- ":res_leveldb",
- "//common/test:test_main",
+ ":storage",
+ "//chain/storage/proto:kv_cc_proto",
+ "//chain/storage/proto:leveldb_config_cc_proto",
+ "//common:comm",
+ "//third_party:leveldb",
],
)
cc_library(
- name = "res_rocksdb",
- srcs = ["res_rocksdb.cpp"],
- hdrs = ["res_rocksdb.h"],
+ name = "rocksdb",
+ srcs = ["rocksdb.cpp"],
+ hdrs = ["rocksdb.h"],
tags = ["manual"],
deps = [
":storage",
+ "//chain/storage/proto:kv_cc_proto",
+ "//chain/storage/proto:rocksdb_config_cc_proto",
"//common:comm",
- "//platform/proto:replica_info_cc_proto",
"//third_party:rocksdb",
],
)
cc_test(
- name = "res_rocksdb_test",
- srcs = ["res_rocksdb_test.cpp"],
- tags = ["manual"],
+ name = "kv_storage_test",
+ srcs = ["kv_storage_test.cpp"],
deps = [
- ":res_rocksdb",
+ ":leveldb",
+ ":memory_db",
+ ":rocksdb",
"//common/test:test_main",
],
)
-
-cc_library(
- name = "txn_memory_db",
- srcs = ["txn_memory_db.cpp"],
- hdrs = ["txn_memory_db.h"],
- deps = [
- "//common:comm",
- "//platform/proto:resdb_cc_proto",
- ],
-)
diff --git a/chain/storage/README.md b/chain/storage/README.md
deleted file mode 100644
index 033b0517b..000000000
--- a/chain/storage/README.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# Durable layer
-## How to use
-Look at [proto/durable.proto](https://github.com/msadoghi/nexres/blob/master/proto/durable.proto) and [proto/replica_info.proto](https://github.com/msadoghi/nexres/blob/master/proto/replica_info.proto) for how to format the durability settings.
-
-A config file for 4 replicas on localhost can be found at [config/example/kv_config.config](https://github.com/msadoghi/nexres/blob/master/example/kv_config.config).
-
-## Warning
-
-If "path" is not set in the durability settings for RocksDB or LevelDB then default paths will be generated in the /tmp/ folder, which is cleared whenever the machine is shut down.
-
-If you are testing Nexres on your local machine using localhost ip, then make sure to set generate_unique_pathnames to true, because multiple processes are not allowed to open up the same RocksDB/LevelDB directory at the same time. When generate_unique_pathnames is set to true, the durable layer uses the cert file names to generate separate directories for each port of the localhost ip.
-
-For example, the process hosting a server with cert_1.cert will append "1" to its directory path. If the cert file name does not contain a number and generate_unique_pathnames is set, "0" will be appended to the path.
diff --git a/chain/storage/kv_storage_test.cpp b/chain/storage/kv_storage_test.cpp
new file mode 100644
index 000000000..701dcbd98
--- /dev/null
+++ b/chain/storage/kv_storage_test.cpp
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include
+#include
+#include
+
+#include
+
+#include "chain/storage/leveldb.h"
+#include "chain/storage/memory_db.h"
+#include "chain/storage/rocksdb.h"
+
+namespace resdb {
+namespace storage {
+namespace {
+
+enum StorageType {
+ MEM = 0,
+ LEVELDB = 1,
+ ROCKSDB = 2,
+};
+
+class KVStorageTest : public ::testing::TestWithParam {
+ protected:
+ KVStorageTest() {
+ StorageType t = GetParam();
+ switch (t) {
+ case MEM:
+ storage = NewMemoryDB();
+ break;
+ case LEVELDB:
+ Reset();
+ storage = NewResLevelDB(path_);
+ break;
+ case ROCKSDB:
+ Reset();
+ storage = NewResRocksDB(path_);
+ break;
+ }
+ }
+
+ private:
+ void Reset() { std::filesystem::remove_all(path_.c_str()); }
+
+ protected:
+ std::unique_ptr storage;
+ std::string path_ = "/tmp/leveldb_test";
+};
+
+TEST_P(KVStorageTest, SetValue) {
+ EXPECT_EQ(storage->SetValue("test_key", "test_value"), 0);
+ EXPECT_EQ(storage->GetValue("test_key"), "test_value");
+}
+
+TEST_P(KVStorageTest, GetValue) {
+ EXPECT_EQ(storage->GetValue("test_key"), "");
+}
+
+TEST_P(KVStorageTest, GetEmptyValueWithVersion) {
+ EXPECT_EQ(storage->GetValueWithVersion("test_key", 0),
+ std::make_pair(std::string(""), 0));
+}
+
+TEST_P(KVStorageTest, SetValueWithVersion) {
+ EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value", 1), -2);
+
+ EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value", 0), 0);
+
+ EXPECT_EQ(storage->GetValueWithVersion("test_key", 0),
+ std::make_pair(std::string("test_value"), 1));
+ EXPECT_EQ(storage->GetValueWithVersion("test_key", 1),
+ std::make_pair(std::string("test_value"), 1));
+
+ EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value_v2", 2), -2);
+ EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value_v2", 1), 0);
+
+ EXPECT_EQ(storage->GetValueWithVersion("test_key", 0),
+ std::make_pair(std::string("test_value_v2"), 2));
+
+ EXPECT_EQ(storage->GetValueWithVersion("test_key", 1),
+ std::make_pair(std::string("test_value"), 1));
+
+ EXPECT_EQ(storage->GetValueWithVersion("test_key", 2),
+ std::make_pair(std::string("test_value_v2"), 2));
+
+ EXPECT_EQ(storage->GetValueWithVersion("test_key", 3),
+ std::make_pair(std::string("test_value_v2"), 2));
+}
+
+TEST_P(KVStorageTest, GetAllValueWithVersion) {
+ {
+ std::map > expected_list{
+ std::make_pair("test_key", std::make_pair("test_value", 1))};
+
+ EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value", 0), 0);
+ EXPECT_EQ(storage->GetAllItems(), expected_list);
+ }
+
+ {
+ std::map > expected_list{
+ std::make_pair("test_key", std::make_pair("test_value_v2", 2))};
+ EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value_v2", 1), 0);
+ EXPECT_EQ(storage->GetAllItems(), expected_list);
+ }
+
+ {
+ std::map > expected_list{
+ std::make_pair("test_key_v1", std::make_pair("test_value1", 1)),
+ std::make_pair("test_key", std::make_pair("test_value_v2", 2))};
+ EXPECT_EQ(storage->SetValueWithVersion("test_key_v1", "test_value1", 0), 0);
+ EXPECT_EQ(storage->GetAllItems(), expected_list);
+ }
+}
+
+TEST_P(KVStorageTest, GetKeyRange) {
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value1", 0), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("2", "value2", 0), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("3", "value3", 0), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("4", "value4", 0), 0);
+
+ {
+ std::map > expected_list{
+ std::make_pair("1", std::make_pair("value1", 1)),
+ std::make_pair("2", std::make_pair("value2", 1)),
+ std::make_pair("3", std::make_pair("value3", 1)),
+ std::make_pair("4", std::make_pair("value4", 1))};
+ EXPECT_EQ(storage->GetKeyRange("1", "4"), expected_list);
+ }
+
+ EXPECT_EQ(storage->SetValueWithVersion("3", "value3_1", 1), 0);
+ {
+ std::map > expected_list{
+ std::make_pair("1", std::make_pair("value1", 1)),
+ std::make_pair("2", std::make_pair("value2", 1)),
+ std::make_pair("3", std::make_pair("value3_1", 2)),
+ std::make_pair("4", std::make_pair("value4", 1))};
+ EXPECT_EQ(storage->GetKeyRange("1", "4"), expected_list);
+ }
+ {
+ std::map > expected_list{
+ std::make_pair("1", std::make_pair("value1", 1)),
+ std::make_pair("2", std::make_pair("value2", 1)),
+ std::make_pair("3", std::make_pair("value3_1", 2)),
+ };
+ EXPECT_EQ(storage->GetKeyRange("1", "3"), expected_list);
+ }
+ {
+ std::map > expected_list{
+ std::make_pair("2", std::make_pair("value2", 1)),
+ std::make_pair("3", std::make_pair("value3_1", 2)),
+ std::make_pair("4", std::make_pair("value4", 1))};
+ EXPECT_EQ(storage->GetKeyRange("2", "4"), expected_list);
+ }
+ {
+ std::map > expected_list{
+ std::make_pair("1", std::make_pair("value1", 1)),
+ std::make_pair("2", std::make_pair("value2", 1)),
+ std::make_pair("3", std::make_pair("value3_1", 2)),
+ std::make_pair("4", std::make_pair("value4", 1))};
+ EXPECT_EQ(storage->GetKeyRange("0", "5"), expected_list);
+ }
+ {
+ std::map > expected_list{
+ std::make_pair("2", std::make_pair("value2", 1)),
+ std::make_pair("3", std::make_pair("value3_1", 2)),
+ };
+ EXPECT_EQ(storage->GetKeyRange("2", "3"), expected_list);
+ }
+}
+
+TEST_P(KVStorageTest, GetHistory) {
+ {
+ std::vector > expected_list{};
+ EXPECT_EQ(storage->GetHistory("1", 1, 5), expected_list);
+ }
+ {
+ std::vector > expected_list{
+ std::make_pair("value3", 3), std::make_pair("value2", 2),
+ std::make_pair("value1", 1)};
+
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value1", 0), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value2", 1), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value3", 2), 0);
+
+ EXPECT_EQ(storage->GetHistory("1", 1, 5), expected_list);
+ }
+
+ {
+ std::vector > expected_list{
+ std::make_pair("value5", 5), std::make_pair("value4", 4),
+ std::make_pair("value3", 3), std::make_pair("value2", 2),
+ std::make_pair("value1", 1)};
+
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value4", 3), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value5", 4), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value6", 5), 0);
+ EXPECT_EQ(storage->SetValueWithVersion("1", "value7", 6), 0);
+
+ EXPECT_EQ(storage->GetHistory("1", 1, 5), expected_list);
+ }
+
+ {
+ std::vector > expected_list{
+ std::make_pair("value7", 7), std::make_pair("value6", 6)};
+
+ EXPECT_EQ(storage->GetTopHistory("1", 2), expected_list);
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(KVStorageTest, KVStorageTest,
+ ::testing::Values(MEM, LEVELDB, ROCKSDB));
+
+} // namespace
+} // namespace storage
+} // namespace resdb
diff --git a/chain/storage/leveldb.cpp b/chain/storage/leveldb.cpp
new file mode 100644
index 000000000..2cc96fb59
--- /dev/null
+++ b/chain/storage/leveldb.cpp
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "chain/storage/leveldb.h"
+
+#include
+
+#include "chain/storage/proto/kv.pb.h"
+
+namespace resdb {
+namespace storage {
+
+std::unique_ptr NewResLevelDB(const std::string& path,
+ std::optional config) {
+ if (config == std::nullopt) {
+ config = LevelDBInfo();
+ }
+ (*config).set_path(path);
+ return std::make_unique(config);
+}
+
+std::unique_ptr NewResLevelDB(std::optional config) {
+ return std::make_unique(config);
+}
+
+ResLevelDB::ResLevelDB(std::optional config) {
+ std::string path = "/tmp/nexres-leveldb";
+ if (config.has_value()) {
+ write_buffer_size_ = (*config).write_buffer_size_mb() << 20;
+ write_batch_size_ = (*config).write_batch_size();
+ if (!(*config).path().empty()) {
+ LOG(ERROR) << "Custom path for ResLevelDB provided in config: "
+ << (*config).path();
+ path = (*config).path();
+ }
+ }
+ CreateDB(path);
+}
+
+void ResLevelDB::CreateDB(const std::string& path) {
+ LOG(ERROR) << "ResLevelDB Create DB: path:" << path
+ << " write buffer size:" << write_buffer_size_
+ << " batch size:" << write_batch_size_;
+ leveldb::Options options;
+ options.create_if_missing = true;
+ options.write_buffer_size = write_buffer_size_;
+
+ leveldb::DB* db = nullptr;
+ leveldb::Status status = leveldb::DB::Open(options, path, &db);
+ if (status.ok()) {
+ db_ = std::unique_ptr(db);
+ }
+ assert(status.ok());
+ LOG(ERROR) << "Successfully opened LevelDB";
+}
+
+ResLevelDB::~ResLevelDB() {
+ if (db_) {
+ db_.reset();
+ }
+}
+
+int ResLevelDB::SetValue(const std::string& key, const std::string& value) {
+ batch_.Put(key, value);
+
+ if (batch_.ApproximateSize() >= write_batch_size_) {
+ leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch_);
+ if (status.ok()) {
+ batch_.Clear();
+ return 0;
+ } else {
+ LOG(ERROR) << "flush buffer fail:" << status.ToString();
+ return -1;
+ }
+ }
+ return 0;
+}
+
+std::string ResLevelDB::GetValue(const std::string& key) {
+ std::string value = "";
+ leveldb::Status status = db_->Get(leveldb::ReadOptions(), key, &value);
+ if (status.ok()) {
+ return value;
+ } else {
+ return "";
+ }
+}
+
+std::string ResLevelDB::GetAllValues(void) {
+ std::string values = "[";
+ leveldb::Iterator* it = db_->NewIterator(leveldb::ReadOptions());
+ bool first_iteration = true;
+ for (it->SeekToFirst(); it->Valid(); it->Next()) {
+ if (!first_iteration) values.append(",");
+ first_iteration = false;
+ values.append(it->value().ToString());
+ }
+ values.append("]");
+
+ delete it;
+ return values;
+}
+
+std::string ResLevelDB::GetRange(const std::string& min_key,
+ const std::string& max_key) {
+ std::string values = "[";
+ leveldb::Iterator* it = db_->NewIterator(leveldb::ReadOptions());
+ bool first_iteration = true;
+ for (it->Seek(min_key); it->Valid() && it->key().ToString() <= max_key;
+ it->Next()) {
+ if (!first_iteration) values.append(",");
+ first_iteration = false;
+ values.append(it->value().ToString());
+ }
+ values.append("]");
+
+ delete it;
+ return values;
+}
+
+bool ResLevelDB::Flush() {
+ leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch_);
+ if (status.ok()) {
+ batch_.Clear();
+ return true;
+ }
+ LOG(ERROR) << "flush buffer fail:" << status.ToString();
+ return false;
+}
+
+int ResLevelDB::SetValueWithVersion(const std::string& key,
+ const std::string& value, int version) {
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return -2;
+ }
+
+ int last_v = 0;
+ if (history.value_size() > 0) {
+ last_v = history.value(history.value_size() - 1).version();
+ }
+
+ if (last_v != version) {
+ LOG(ERROR) << "version does not match:" << version
+ << " old version:" << last_v;
+ return -2;
+ }
+
+ Value* new_value = history.add_value();
+ new_value->set_value(value);
+ new_value->set_version(version + 1);
+
+ history.SerializeToString(&value_str);
+ return SetValue(key, value_str);
+}
+
+std::pair ResLevelDB::GetValueWithVersion(
+ const std::string& key, int version) {
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return std::make_pair("", 0);
+ }
+ if (history.value_size() == 0) {
+ return std::make_pair("", 0);
+ }
+ if (version > 0) {
+ for (int i = history.value_size() - 1; i >= 0; --i) {
+ if (history.value(i).version() == version) {
+ return std::make_pair(history.value(i).value(),
+ history.value(i).version());
+ }
+ if (history.value(i).version() < version) {
+ break;
+ }
+ }
+ }
+ int last_idx = history.value_size() - 1;
+ return std::make_pair(history.value(last_idx).value(),
+ history.value(last_idx).version());
+}
+
+// Return a map of >
+std::map> ResLevelDB::GetAllItems() {
+ std::map> resp;
+
+ leveldb::Iterator* it = db_->NewIterator(leveldb::ReadOptions());
+ for (it->SeekToFirst(); it->Valid(); it->Next()) {
+ ValueHistory history;
+ if (!history.ParseFromString(it->value().ToString()) ||
+ history.value_size() == 0) {
+ LOG(ERROR) << "old_value parse fail";
+ continue;
+ }
+ const Value& value = history.value(history.value_size() - 1);
+ resp.insert(std::make_pair(it->key().ToString(),
+ std::make_pair(value.value(), value.version())));
+ }
+ delete it;
+
+ return resp;
+}
+
+std::map> ResLevelDB::GetKeyRange(
+ const std::string& min_key, const std::string& max_key) {
+ std::map> resp;
+
+ leveldb::Iterator* it = db_->NewIterator(leveldb::ReadOptions());
+ for (it->Seek(min_key); it->Valid() && it->key().ToString() <= max_key;
+ it->Next()) {
+ ValueHistory history;
+ if (!history.ParseFromString(it->value().ToString()) ||
+ history.value_size() == 0) {
+ LOG(ERROR) << "old_value parse fail";
+ continue;
+ }
+ const Value& value = history.value(history.value_size() - 1);
+ resp.insert(std::make_pair(it->key().ToString(),
+ std::make_pair(value.value(), value.version())));
+ }
+ delete it;
+
+ return resp;
+}
+
+// Return a list of
+std::vector> ResLevelDB::GetHistory(
+ const std::string& key, int min_version, int max_version) {
+ std::vector> resp;
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return resp;
+ }
+
+ for (int i = history.value_size() - 1; i >= 0; --i) {
+ if (history.value(i).version() < min_version) {
+ break;
+ }
+ if (history.value(i).version() <= max_version) {
+ resp.push_back(
+ std::make_pair(history.value(i).value(), history.value(i).version()));
+ }
+ }
+
+ return resp;
+}
+
+// Return a list of
+std::vector> ResLevelDB::GetTopHistory(
+ const std::string& key, int top_number) {
+ std::vector> resp;
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return resp;
+ }
+
+ for (int i = history.value_size() - 1;
+ i >= 0 && resp.size() < static_cast(top_number); --i) {
+ resp.push_back(
+ std::make_pair(history.value(i).value(), history.value(i).version()));
+ }
+
+ return resp;
+}
+
+} // namespace storage
+} // namespace resdb
diff --git a/chain/storage/leveldb.h b/chain/storage/leveldb.h
new file mode 100644
index 000000000..199f1f274
--- /dev/null
+++ b/chain/storage/leveldb.h
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include
+#include
+#include
+
+#include "chain/storage/proto/leveldb_config.pb.h"
+#include "chain/storage/storage.h"
+#include "leveldb/db.h"
+#include "leveldb/write_batch.h"
+
+namespace resdb {
+namespace storage {
+
+std::unique_ptr NewResLevelDB(
+ const std::string& path, std::optional config = std::nullopt);
+std::unique_ptr NewResLevelDB(
+ std::optional config = std::nullopt);
+
+class ResLevelDB : public Storage {
+ public:
+ ResLevelDB(std::optional config_data = std::nullopt);
+
+ virtual ~ResLevelDB();
+ int SetValue(const std::string& key, const std::string& value) override;
+ std::string GetValue(const std::string& key) override;
+ std::string GetAllValues(void) override;
+ std::string GetRange(const std::string& min_key,
+ const std::string& max_key) override;
+
+ int SetValueWithVersion(const std::string& key, const std::string& value,
+ int version) override;
+ std::pair GetValueWithVersion(const std::string& key,
+ int version) override;
+
+ // Return a map of >
+ std::map> GetAllItems() override;
+ std::map> GetKeyRange(
+ const std::string& min_key, const std::string& max_key) override;
+
+ // Return a list of
+ std::vector> GetHistory(const std::string& key,
+ int min_version,
+ int max_version) override;
+
+ std::vector> GetTopHistory(
+ const std::string& key, int top_number) override;
+
+ bool Flush() override;
+
+ private:
+ void CreateDB(const std::string& path);
+
+ private:
+ std::unique_ptr db_ = nullptr;
+ ::leveldb::WriteBatch batch_;
+ unsigned int write_buffer_size_ = 64 << 20;
+ unsigned int write_batch_size_ = 1;
+};
+
+} // namespace storage
+} // namespace resdb
diff --git a/chain/storage/memory_db.cpp b/chain/storage/memory_db.cpp
new file mode 100644
index 000000000..2d5b87258
--- /dev/null
+++ b/chain/storage/memory_db.cpp
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "chain/storage/memory_db.h"
+
+#include
+
+namespace resdb {
+namespace storage {
+
+std::unique_ptr NewMemoryDB() { return std::make_unique(); }
+
+MemoryDB::MemoryDB() {}
+
+int MemoryDB::SetValue(const std::string& key, const std::string& value) {
+ kv_map_[key] = value;
+ return 0;
+}
+
+std::string MemoryDB::GetAllValues(void) {
+ std::string values = "[";
+ bool first_iteration = true;
+ for (auto kv : kv_map_) {
+ if (!first_iteration) values.append(",");
+ first_iteration = false;
+ values.append(kv.second);
+ }
+ values.append("]");
+ return values;
+}
+
+std::string MemoryDB::GetRange(const std::string& min_key,
+ const std::string& max_key) {
+ std::string values = "[";
+ bool first_iteration = true;
+ for (auto kv : kv_map_) {
+ if (kv.first >= min_key && kv.first <= max_key) {
+ if (!first_iteration) values.append(",");
+ first_iteration = false;
+ values.append(kv.second);
+ }
+ }
+ values.append("]");
+ return values;
+}
+
+std::string MemoryDB::GetValue(const std::string& key) {
+ auto search = kv_map_.find(key);
+ if (search != kv_map_.end())
+ return search->second;
+ else {
+ return "";
+ }
+}
+
+int MemoryDB::SetValueWithVersion(const std::string& key,
+ const std::string& value, int version) {
+ auto it = kv_map_with_v_.find(key);
+ if ((it == kv_map_with_v_.end() && version != 0) ||
+ (it != kv_map_with_v_.end() && it->second.back().second != version)) {
+ LOG(ERROR) << " value version not match. key:" << key << " db version:"
+ << (it == kv_map_with_v_.end() ? 0 : it->second.back().second)
+ << " user version:" << version;
+ return -2;
+ }
+ kv_map_with_v_[key].push_back(std::make_pair(value, version + 1));
+ return 0;
+}
+
+std::pair MemoryDB::GetValueWithVersion(
+ const std::string& key, int version) {
+ auto search_it = kv_map_with_v_.find(key);
+ if (search_it != kv_map_with_v_.end() && search_it->second.size()) {
+ auto it = search_it->second.end();
+ do {
+ --it;
+ if (it->second == version) {
+ return *it;
+ }
+ if (it->second < version) {
+ break;
+ }
+ } while (it != search_it->second.begin());
+ it = --search_it->second.end();
+ LOG(ERROR) << " key:" << key << " no version:" << version
+ << " return max:" << it->second;
+ return *it;
+ }
+ return std::make_pair("", 0);
+}
+
+std::map> MemoryDB::GetAllItems() {
+ std::map> resp;
+
+ for (const auto& it : kv_map_with_v_) {
+ resp.insert(std::make_pair(it.first, it.second.back()));
+ }
+ return resp;
+}
+
+std::map> MemoryDB::GetKeyRange(
+ const std::string& min_key, const std::string& max_key) {
+ LOG(ERROR) << "min key:" << min_key << " max key:" << max_key;
+ std::map> resp;
+ for (const auto& it : kv_map_with_v_) {
+ if (it.first >= min_key && it.first <= max_key) {
+ resp.insert(std::make_pair(it.first, it.second.back()));
+ }
+ }
+ return resp;
+}
+
+std::vector> MemoryDB::GetHistory(
+ const std::string& key, int min_version, int max_version) {
+ std::vector> resp;
+ auto search_it = kv_map_with_v_.find(key);
+ if (search_it == kv_map_with_v_.end()) {
+ return resp;
+ }
+
+ auto it = search_it->second.end();
+ do {
+ --it;
+ if (it->second < min_version) {
+ break;
+ }
+ if (it->second <= max_version) {
+ resp.push_back(*it);
+ }
+ } while (it != search_it->second.begin());
+ return resp;
+}
+
+std::vector> MemoryDB::GetTopHistory(
+ const std::string& key, int top_number) {
+ std::vector> resp;
+ auto search_it = kv_map_with_v_.find(key);
+ if (search_it == kv_map_with_v_.end()) {
+ return resp;
+ }
+
+ auto it = search_it->second.end();
+ do {
+ --it;
+ resp.push_back(*it);
+ if (resp.size() >= static_cast(top_number)) {
+ break;
+ }
+ } while (it != search_it->second.begin());
+ return resp;
+}
+
+} // namespace storage
+} // namespace resdb
diff --git a/chain/storage/memory_db.h b/chain/storage/memory_db.h
new file mode 100644
index 000000000..372f46474
--- /dev/null
+++ b/chain/storage/memory_db.h
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include "chain/storage/storage.h"
+
+namespace resdb {
+namespace storage {
+
+// Key Value Storage supporting two types of interfaces:
+// Non-version:
+// It provides set and get function to set a value to a specific key
+// Values will be set directly.
+// Version:
+// It provides set and get function to set a value to a specific key
+// with a version.
+// The version inside setting function is to support OCC verification.
+// The version value should be obtained before setting
+// and returned back when setting a new value. If the version is not
+// the same as the old one, return failure.
+// If the value of a specific version does not exist or providing
+// version 0 as parameter when accessing get
+// it returns the current value along its version.
+//
+// Note: Only one type of interface are allowed to be used.
+//
+
+std::unique_ptr NewMemoryDB();
+
+class MemoryDB : public Storage {
+ public:
+ MemoryDB();
+
+ int SetValue(const std::string& key, const std::string& value);
+ std::string GetValue(const std::string& key);
+
+ std::string GetAllValues() override;
+ std::string GetRange(const std::string& min_key,
+ const std::string& max_key) override;
+
+ int SetValueWithVersion(const std::string& key, const std::string& value,
+ int version) override;
+ std::pair GetValueWithVersion(const std::string& key,
+ int version) override;
+
+ // Return a map of >
+ std::map> GetAllItems() override;
+ std::map> GetKeyRange(
+ const std::string& min_key, const std::string& max_key) override;
+
+ // Return a list of
+ std::vector> GetHistory(const std::string& key,
+ int min_version,
+ int max_version) override;
+
+ std::vector> GetTopHistory(const std::string& key,
+ int number) override;
+
+ private:
+ std::unordered_map kv_map_;
+ std::unordered_map>>
+ kv_map_with_v_;
+};
+
+} // namespace storage
+} // namespace resdb
diff --git a/chain/storage/mock_storage.h b/chain/storage/mock_storage.h
index 7aac187bf..963d92bbe 100644
--- a/chain/storage/mock_storage.h
+++ b/chain/storage/mock_storage.h
@@ -1,26 +1,20 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#pragma once
@@ -38,6 +32,24 @@ class MockStorage : public Storage {
MOCK_METHOD(std::string, GetAllValues, (), (override));
MOCK_METHOD(std::string, GetRange, (const std::string&, const std::string&),
(override));
+
+ MOCK_METHOD(int, SetValueWithVersion,
+ (const std::string& key, const std::string& value, int version),
+ (override));
+
+ using ValueType = std::pair;
+ using ItemsType = std::map;
+ using ValuesType = std::vector;
+
+ MOCK_METHOD(ValueType, GetValueWithVersion,
+ (const std::string& key, int version), (override));
+ MOCK_METHOD(ItemsType, GetAllItems, (), (override));
+ MOCK_METHOD(ItemsType, GetKeyRange, (const std::string&, const std::string&),
+ (override));
+ MOCK_METHOD(ValuesType, GetHistory, (const std::string&, int, int),
+ (override));
+ MOCK_METHOD(ValuesType, GetTopHistory, (const std::string&, int), (override));
+
MOCK_METHOD(bool, Flush, (), (override));
};
diff --git a/chain/storage/proto/BUILD b/chain/storage/proto/BUILD
new file mode 100644
index 000000000..1dea24a1a
--- /dev/null
+++ b/chain/storage/proto/BUILD
@@ -0,0 +1,36 @@
+package(default_visibility = ["//visibility:public"])
+
+load("@rules_cc//cc:defs.bzl", "cc_proto_library")
+load("@rules_proto//proto:defs.bzl", "proto_library")
+
+proto_library(
+ name = "kv_proto",
+ srcs = ["kv.proto"],
+ visibility = ["//chain/storage:__subpackages__"],
+)
+
+cc_proto_library(
+ name = "kv_cc_proto",
+ visibility = ["//chain/storage:__subpackages__"],
+ deps = [":kv_proto"],
+)
+
+proto_library(
+ name = "leveldb_config_proto",
+ srcs = ["leveldb_config.proto"],
+)
+
+cc_proto_library(
+ name = "leveldb_config_cc_proto",
+ deps = [":leveldb_config_proto"],
+)
+
+proto_library(
+ name = "rocksdb_config_proto",
+ srcs = ["rocksdb_config.proto"],
+)
+
+cc_proto_library(
+ name = "rocksdb_config_cc_proto",
+ deps = [":rocksdb_config_proto"],
+)
diff --git a/chain/storage/proto/kv.proto b/chain/storage/proto/kv.proto
new file mode 100644
index 000000000..bb2e89451
--- /dev/null
+++ b/chain/storage/proto/kv.proto
@@ -0,0 +1,13 @@
+syntax = "proto3";
+
+package resdb.storage;
+
+message Value {
+ bytes value = 1;
+ int32 version = 2;
+}
+
+message ValueHistory {
+ repeated Value value = 1;
+}
+
diff --git a/chain/storage/proto/leveldb_config.proto b/chain/storage/proto/leveldb_config.proto
new file mode 100644
index 000000000..572b4a08a
--- /dev/null
+++ b/chain/storage/proto/leveldb_config.proto
@@ -0,0 +1,9 @@
+syntax = "proto3";
+
+package resdb.storage;
+
+message LevelDBInfo {
+ uint32 write_buffer_size_mb = 2;
+ uint32 write_batch_size = 3;
+ string path = 4;
+}
diff --git a/chain/storage/proto/rocksdb_config.proto b/chain/storage/proto/rocksdb_config.proto
new file mode 100644
index 000000000..a1a453961
--- /dev/null
+++ b/chain/storage/proto/rocksdb_config.proto
@@ -0,0 +1,11 @@
+syntax = "proto3";
+
+package resdb.storage;
+
+message RocksDBInfo {
+ uint32 num_threads = 2;
+ uint32 write_buffer_size_mb = 3;
+ uint32 write_batch_size = 4;
+ string path = 5;
+}
+
diff --git a/chain/storage/res_leveldb.cpp b/chain/storage/res_leveldb.cpp
deleted file mode 100644
index 0cd48ccae..000000000
--- a/chain/storage/res_leveldb.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "chain/storage/res_leveldb.h"
-
-#include
-
-namespace resdb {
-
-std::unique_ptr NewResLevelDB(const char* cert_file,
- resdb::ResConfigData config_data) {
- return std::make_unique(cert_file, config_data);
-}
-
-ResLevelDB::ResLevelDB(const char* cert_file,
- std::optional config_data) {
- std::string directory_id = "";
-
- std::string path = "/tmp/nexres-leveldb";
- if (cert_file == NULL) {
- LOG(ERROR) << "No cert file provided";
- } else {
- LOG(ERROR) << "Cert file: " << cert_file;
- std::string str(cert_file);
-
- for (int i = 0; i < (int)str.size(); i++) {
- if (str[i] >= '0' && str[i] <= '9') {
- directory_id += std::string(1, cert_file[i]);
- }
- }
-
- if (directory_id == "") {
- directory_id = "0";
- }
- }
-
- if (config_data.has_value()) {
- LevelDBInfo config = (*config_data).leveldb_info();
- write_buffer_size_ = config.write_buffer_size_mb() << 20;
- write_batch_size_ = config.write_batch_size();
- if (config.path() != "") {
- LOG(ERROR) << "Custom path for ResLevelDB provided in config: "
- << config.path();
- path = config.path();
- }
- if (config.generate_unique_pathnames()) {
- LOG(ERROR) << "Adding number to generate unique pathname: "
- << directory_id;
- path += directory_id;
- }
- }
- CreateDB(path);
-}
-
-void ResLevelDB::CreateDB(const std::string& path) {
- LOG(ERROR) << "ResLevelDB Create DB: path:" << path
- << " write buffer size:" << write_buffer_size_
- << " batch size:" << write_batch_size_;
- leveldb::Options options;
- options.create_if_missing = true;
- options.write_buffer_size = write_buffer_size_;
-
- leveldb::DB* db = nullptr;
- leveldb::Status status = leveldb::DB::Open(options, path, &db);
- if (status.ok()) {
- db_ = std::unique_ptr(db);
- }
- assert(status.ok());
- LOG(ERROR) << "Successfully opened LevelDB";
-}
-
-ResLevelDB::~ResLevelDB() {
- if (db_) {
- db_.reset();
- }
-}
-
-int ResLevelDB::SetValue(const std::string& key, const std::string& value) {
- batch_.Put(key, value);
-
- if (batch_.ApproximateSize() >= write_batch_size_) {
- leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch_);
- if (status.ok()) {
- batch_.Clear();
- return 0;
- } else {
- LOG(ERROR) << "flush buffer fail:" << status.ToString();
- return -1;
- }
- }
- return 0;
-}
-
-std::string ResLevelDB::GetValue(const std::string& key) {
- std::string value = "";
- leveldb::Status status = db_->Get(leveldb::ReadOptions(), key, &value);
- if (status.ok()) {
- return value;
- } else {
- LOG(ERROR) << "get value fail:" << status.ToString();
- return "";
- }
-}
-
-std::string ResLevelDB::GetAllValues(void) {
- std::string values = "[";
- leveldb::Iterator* it = db_->NewIterator(leveldb::ReadOptions());
- bool first_iteration = true;
- for (it->SeekToFirst(); it->Valid(); it->Next()) {
- if (!first_iteration) values.append(",");
- first_iteration = false;
- values.append(it->value().ToString());
- }
- values.append("]");
-
- delete it;
- return values;
-}
-
-std::string ResLevelDB::GetRange(const std::string& min_key,
- const std::string& max_key) {
- std::string values = "[";
- leveldb::Iterator* it = db_->NewIterator(leveldb::ReadOptions());
- bool first_iteration = true;
- for (it->Seek(min_key); it->Valid() && it->key().ToString() <= max_key;
- it->Next()) {
- if (!first_iteration) values.append(",");
- first_iteration = false;
- values.append(it->value().ToString());
- }
- values.append("]");
-
- delete it;
- return values;
-}
-
-bool ResLevelDB::Flush() {
- leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch_);
- if (status.ok()) {
- batch_.Clear();
- return true;
- }
- LOG(ERROR) << "flush buffer fail:" << status.ToString();
- return false;
-}
-
-} // namespace resdb
diff --git a/chain/storage/res_leveldb_test.cpp b/chain/storage/res_leveldb_test.cpp
deleted file mode 100644
index 17deddffd..000000000
--- a/chain/storage/res_leveldb_test.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "chain/storage/res_leveldb.h"
-
-#include
-#include
-#include
-
-#include
-
-namespace resdb {
-
-namespace {
-
-using ::testing::Test;
-
-class ResLevelDBDurableTest : public Test {
- public:
- ResLevelDBDurableTest() { Reset(); }
- ~ResLevelDBDurableTest() {}
- int Set(const std::string& key, const std::string& value) {
- resdb::ResConfigData config_data;
- config_data.mutable_leveldb_info()->set_path(path_);
- return NewResLevelDB(NULL, config_data)->SetValue(key, value);
- }
-
- std::string Get(const std::string& key) {
- resdb::ResConfigData config_data;
- config_data.mutable_leveldb_info()->set_path(path_);
- return NewResLevelDB(NULL, config_data)->GetValue(key);
- }
-
- std::string GetAllValues() {
- resdb::ResConfigData config_data;
- config_data.mutable_leveldb_info()->set_path(path_);
- return NewResLevelDB(NULL, config_data)->GetAllValues();
- }
-
- std::string GetRange(const std::string& min_key, const std::string& max_key) {
- resdb::ResConfigData config_data;
- config_data.mutable_leveldb_info()->set_path(path_);
- return NewResLevelDB(NULL, config_data)->GetRange(min_key, max_key);
- }
-
- void Reset() { std::filesystem::remove_all(path_.c_str()); }
-
- private:
- std::string path_ = "/tmp/leveldb_test";
-};
-
-TEST_F(ResLevelDBDurableTest, GetEmptyValue) {
- EXPECT_EQ(Get("empty_key"), "");
-}
-
-TEST_F(ResLevelDBDurableTest, SetValue) {
- EXPECT_EQ(Set("test_key", "test_value"), 0);
-}
-
-TEST_F(ResLevelDBDurableTest, GetValue) {
- EXPECT_EQ(Set("test_key", "test_value"), 0);
- EXPECT_EQ(Get("test_key"), "test_value");
-}
-
-TEST_F(ResLevelDBDurableTest, SetNewValue) {
- EXPECT_EQ(Set("test_key", "new_value"), 0);
-}
-
-TEST_F(ResLevelDBDurableTest, GetNewValue) { EXPECT_EQ(Get("test_key"), ""); }
-
-TEST_F(ResLevelDBDurableTest, GetAllValues) {
- EXPECT_EQ(Set("a", "a"), 0);
- EXPECT_EQ(Set("b", "b"), 0);
- EXPECT_EQ(Set("c", "c"), 0);
- EXPECT_EQ(GetAllValues(), "[a,b,c]");
-}
-
-TEST_F(ResLevelDBDurableTest, GetRange) {
- EXPECT_EQ(Set("key1", "value1"), 0);
- EXPECT_EQ(Set("key2", "value2"), 0);
- EXPECT_EQ(Set("key3", "value3"), 0);
- EXPECT_EQ(GetRange("key1", "key3"), "[value1,value2,value3]");
- EXPECT_EQ(GetRange("key1", "key2"), "[value1,value2]");
- EXPECT_EQ(GetRange("key4", "key5"), "[]");
-}
-
-} // namespace
-
-} // namespace resdb
diff --git a/chain/storage/res_rocksdb.cpp b/chain/storage/res_rocksdb.cpp
deleted file mode 100644
index 2655aca2a..000000000
--- a/chain/storage/res_rocksdb.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "chain/storage/res_rocksdb.h"
-
-#include
-#include
-
-namespace resdb {
-
-std::unique_ptr NewResRocksDB(
- const char* cert_file, std::optional config_data) {
- return std::make_unique(cert_file, config_data);
-}
-
-ResRocksDB::ResRocksDB(const char* cert_file,
- std::optional config_data) {
- std::string directory_id = "";
-
- std::string path = "/tmp/nexres-rocksdb";
- LOG(ERROR) << "Default database path: " << path;
-
- if (cert_file == NULL) {
- LOG(ERROR) << "No cert file provided";
- } else {
- LOG(ERROR) << "Cert file: " << cert_file;
- std::string str(cert_file);
-
- for (int i = 0; i < (int)str.size(); i++) {
- if (str[i] >= '0' && str[i] <= '9') {
- directory_id += std::string(1, cert_file[i]);
- }
- }
-
- if (directory_id == "") {
- directory_id = "0";
- }
- }
-
- if (config_data.has_value()) {
- RocksDBInfo config = (*config_data).rocksdb_info();
- num_threads_ = config.num_threads();
- write_buffer_size_ = config.write_buffer_size_mb() << 20;
- write_batch_size_ = config.write_batch_size();
- if (config.path() != "") {
- LOG(ERROR) << "Custom path for RocksDB provided in config: "
- << config.path();
- path = config.path();
- }
- if (config.generate_unique_pathnames()) {
- LOG(ERROR) << "Adding number to generate unique pathname: "
- << directory_id;
- path += directory_id;
- }
- }
- LOG(ERROR) << "RocksDB Settings: " << num_threads_ << " "
- << write_buffer_size_ << " " << write_batch_size_;
-
- rocksdb::Options options;
- options.create_if_missing = true;
- if (num_threads_ > 1) options.IncreaseParallelism(num_threads_);
- options.OptimizeLevelStyleCompaction();
- options.write_buffer_size = write_buffer_size_;
-
- rocksdb::DB* db = nullptr;
- rocksdb::Status status = rocksdb::DB::Open(options, path, &db);
- if (status.ok()) {
- db_ = std::unique_ptr(db);
- LOG(ERROR) << "Successfully opened RocksDB in path: " << path;
- } else {
- LOG(ERROR) << "RocksDB status fail";
- }
- assert(status.ok());
-}
-
-ResRocksDB::~ResRocksDB() {
- if (db_) {
- db_.reset();
- }
-}
-
-int ResRocksDB::SetValue(const std::string& key, const std::string& value) {
- batch_.Put(key, value);
-
- if (batch_.Count() >= write_batch_size_) {
- rocksdb::Status status = db_->Write(rocksdb::WriteOptions(), &batch_);
- if (status.ok()) {
- batch_.Clear();
- } else {
- LOG(ERROR) << "write value fail:" << status.ToString();
- return -1;
- }
- }
- return 0;
-}
-
-std::string ResRocksDB::GetValue(const std::string& key) {
- std::string value = "";
- rocksdb::Status status = db_->Get(rocksdb::ReadOptions(), key, &value);
- if (status.ok()) {
- return value;
- } else {
- return "";
- }
-}
-
-std::string ResRocksDB::GetAllValues(void) {
- std::string values = "[";
- rocksdb::Iterator* itr = db_->NewIterator(rocksdb::ReadOptions());
- bool first_iteration = true;
- for (itr->SeekToFirst(); itr->Valid(); itr->Next()) {
- if (!first_iteration) values.append(",");
- first_iteration = false;
- values.append(itr->value().ToString());
- }
- values.append("]");
-
- delete itr;
- return values;
-}
-
-std::string ResRocksDB::GetRange(const std::string& min_key,
- const std::string& max_key) {
- std::string values = "[";
- rocksdb::Iterator* itr = db_->NewIterator(rocksdb::ReadOptions());
- bool first_iteration = true;
- for (itr->Seek(min_key); itr->Valid() && itr->key().ToString() <= max_key;
- itr->Next()) {
- if (!first_iteration) values.append(",");
- first_iteration = false;
- values.append(itr->value().ToString());
- }
- values.append("]");
-
- delete itr;
- return values;
-}
-
-bool ResRocksDB::Flush() {
- rocksdb::Status status = db_->Write(rocksdb::WriteOptions(), &batch_);
- if (status.ok()) {
- batch_.Clear();
- return true;
- }
- LOG(ERROR) << "write value fail:" << status.ToString();
- return false;
-}
-
-} // namespace resdb
diff --git a/chain/storage/res_rocksdb_test.cpp b/chain/storage/res_rocksdb_test.cpp
deleted file mode 100644
index 5c17f8b7f..000000000
--- a/chain/storage/res_rocksdb_test.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "storage/res_rocksdb.h"
-
-#include
-#include
-
-#include
-
-namespace resdb {
-namespace {
-
-using ::testing::Test;
-
-class RocksDBDurableTest : public Test {
- public:
- RocksDBDurableTest() { Reset(); }
-
- int Set(const std::string& key, const std::string& value) {
- ResConfigData config_data;
- config_data.mutable_rocksdb_info()->set_path(path_);
- return NewResRocksDB(NULL, config_data)->SetValue(key, value);
- }
-
- std::string Get(const std::string& key) {
- ResConfigData config_data;
- config_data.mutable_rocksdb_info()->set_path(path_);
- return NewResRocksDB(NULL, config_data)->GetValue(key);
- }
-
- std::string GetAllValues() {
- ResConfigData config_data;
- config_data.mutable_rocksdb_info()->set_path(path_);
- return NewResRocksDB(NULL, config_data)->GetAllValues();
- }
-
- std::string GetRange(const std::string& min_key, const std::string& max_key) {
- ResConfigData config_data;
- config_data.mutable_rocksdb_info()->set_path(path_);
- return NewResRocksDB(NULL, config_data)->GetRange(min_key, max_key);
- }
-
- void Reset() { std::filesystem::remove_all(path_.c_str()); }
-
- private:
- std::string path_ = "/tmp/rocksdb_test";
-};
-
-TEST_F(RocksDBDurableTest, GetEmptyValue) { EXPECT_EQ(Get("empty_key"), ""); }
-
-TEST_F(RocksDBDurableTest, SetValue) {
- EXPECT_EQ(Set("test_key", "test_value"), 0);
-}
-
-TEST_F(RocksDBDurableTest, GetValue) {
- EXPECT_EQ(Set("test_key", "test_value"), 0);
- EXPECT_EQ(Get("test_key"), "test_value");
-}
-
-TEST_F(RocksDBDurableTest, SetNewValue) {
- EXPECT_EQ(Set("test_key", "new_value"), 0);
-}
-
-TEST_F(RocksDBDurableTest, GetNewValue) {
- EXPECT_EQ(Set("test_key", "new_value1"), 0);
- EXPECT_EQ(Get("test_key"), "new_value1");
-}
-
-TEST_F(RocksDBDurableTest, GetAllValues) {
- EXPECT_EQ(Set("a", "a"), 0);
- EXPECT_EQ(Set("b", "b"), 0);
- EXPECT_EQ(Set("c", "c"), 0);
- EXPECT_EQ(GetAllValues(), "[a,b,c]");
-}
-
-TEST_F(RocksDBDurableTest, GetRange) {
- EXPECT_EQ(Set("key1", "value1"), 0);
- EXPECT_EQ(Set("key2", "value2"), 0);
- EXPECT_EQ(Set("key3", "value3"), 0);
- EXPECT_EQ(GetRange("key1", "key3"), "[value1,value2,value3]");
- EXPECT_EQ(GetRange("key1", "key2"), "[value1,value2]");
- EXPECT_EQ(GetRange("key4", "key5"), "[]");
-}
-
-} // namespace
-} // namespace resdb
diff --git a/chain/storage/rocksdb.cpp b/chain/storage/rocksdb.cpp
new file mode 100644
index 000000000..86efd3e3c
--- /dev/null
+++ b/chain/storage/rocksdb.cpp
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "chain/storage/rocksdb.h"
+
+#include
+
+#include "chain/storage/proto/kv.pb.h"
+
+namespace resdb {
+namespace storage {
+
+std::unique_ptr NewResRocksDB(const std::string& path,
+ std::optional config) {
+ if (config == std::nullopt) {
+ config = RocksDBInfo();
+ }
+ (*config).set_path(path);
+ return std::make_unique(config);
+}
+
+std::unique_ptr NewResRocksDB(std::optional config) {
+ return std::make_unique(config);
+}
+
+ResRocksDB::ResRocksDB(std::optional config) {
+ std::string path = "/tmp/nexres-rocksdb";
+ if (config.has_value()) {
+ num_threads_ = (*config).num_threads();
+ write_buffer_size_ = (*config).write_buffer_size_mb() << 20;
+ write_batch_size_ = (*config).write_batch_size();
+ if ((*config).path() != "") {
+ LOG(ERROR) << "Custom path for RocksDB provided in config: "
+ << (*config).path();
+ path = (*config).path();
+ }
+ }
+ CreateDB(path);
+}
+
+void ResRocksDB::CreateDB(const std::string& path) {
+ rocksdb::Options options;
+ options.create_if_missing = true;
+ if (num_threads_ > 1) options.IncreaseParallelism(num_threads_);
+ options.OptimizeLevelStyleCompaction();
+ options.write_buffer_size = write_buffer_size_;
+
+ rocksdb::DB* db = nullptr;
+ rocksdb::Status status = rocksdb::DB::Open(options, path, &db);
+ if (status.ok()) {
+ db_ = std::unique_ptr(db);
+ LOG(ERROR) << "Successfully opened RocksDB in path: " << path;
+ } else {
+ LOG(ERROR) << "RocksDB status fail";
+ }
+ assert(status.ok());
+ LOG(ERROR) << "Successfully opened RocksDB";
+}
+
+ResRocksDB::~ResRocksDB() {
+ if (db_) {
+ db_.reset();
+ }
+}
+
+int ResRocksDB::SetValue(const std::string& key, const std::string& value) {
+ batch_.Put(key, value);
+
+ if (batch_.Count() >= write_batch_size_) {
+ rocksdb::Status status = db_->Write(rocksdb::WriteOptions(), &batch_);
+ if (status.ok()) {
+ batch_.Clear();
+ } else {
+ LOG(ERROR) << "write value fail:" << status.ToString();
+ return -1;
+ }
+ }
+ return 0;
+}
+
+std::string ResRocksDB::GetValue(const std::string& key) {
+ std::string value = "";
+ rocksdb::Status status = db_->Get(rocksdb::ReadOptions(), key, &value);
+ if (status.ok()) {
+ return value;
+ } else {
+ return "";
+ }
+}
+
+std::string ResRocksDB::GetAllValues(void) {
+ std::string values = "[";
+ rocksdb::Iterator* itr = db_->NewIterator(rocksdb::ReadOptions());
+ bool first_iteration = true;
+ for (itr->SeekToFirst(); itr->Valid(); itr->Next()) {
+ if (!first_iteration) values.append(",");
+ first_iteration = false;
+ values.append(itr->value().ToString());
+ }
+ values.append("]");
+
+ delete itr;
+ return values;
+}
+
+std::string ResRocksDB::GetRange(const std::string& min_key,
+ const std::string& max_key) {
+ std::string values = "[";
+ rocksdb::Iterator* itr = db_->NewIterator(rocksdb::ReadOptions());
+ bool first_iteration = true;
+ for (itr->Seek(min_key); itr->Valid() && itr->key().ToString() <= max_key;
+ itr->Next()) {
+ if (!first_iteration) values.append(",");
+ first_iteration = false;
+ values.append(itr->value().ToString());
+ }
+ values.append("]");
+
+ delete itr;
+ return values;
+}
+
+bool ResRocksDB::Flush() {
+ rocksdb::Status status = db_->Write(rocksdb::WriteOptions(), &batch_);
+ if (status.ok()) {
+ batch_.Clear();
+ return true;
+ }
+ LOG(ERROR) << "write value fail:" << status.ToString();
+ return false;
+}
+int ResRocksDB::SetValueWithVersion(const std::string& key,
+ const std::string& value, int version) {
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return -2;
+ }
+
+ int last_v = 0;
+ if (history.value_size() > 0) {
+ last_v = history.value(history.value_size() - 1).version();
+ }
+
+ if (last_v != version) {
+ LOG(ERROR) << "version does not match:" << version
+ << " old version:" << last_v;
+ return -2;
+ }
+
+ Value* new_value = history.add_value();
+ new_value->set_value(value);
+ new_value->set_version(version + 1);
+
+ history.SerializeToString(&value_str);
+ return SetValue(key, value_str);
+}
+
+std::pair ResRocksDB::GetValueWithVersion(
+ const std::string& key, int version) {
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return std::make_pair("", 0);
+ }
+ if (history.value_size() == 0) {
+ return std::make_pair("", 0);
+ }
+ if (version > 0) {
+ for (int i = history.value_size() - 1; i >= 0; --i) {
+ if (history.value(i).version() == version) {
+ return std::make_pair(history.value(i).value(),
+ history.value(i).version());
+ }
+ if (history.value(i).version() < version) {
+ break;
+ }
+ }
+ }
+ int last_idx = history.value_size() - 1;
+ return std::make_pair(history.value(last_idx).value(),
+ history.value(last_idx).version());
+}
+
+// Return a map of >
+std::map> ResRocksDB::GetAllItems() {
+ std::map> resp;
+
+ rocksdb::Iterator* it = db_->NewIterator(rocksdb::ReadOptions());
+ for (it->SeekToFirst(); it->Valid(); it->Next()) {
+ ValueHistory history;
+ if (!history.ParseFromString(it->value().ToString()) ||
+ history.value_size() == 0) {
+ LOG(ERROR) << "old_value parse fail";
+ continue;
+ }
+ const Value& value = history.value(history.value_size() - 1);
+ resp.insert(std::make_pair(it->key().ToString(),
+ std::make_pair(value.value(), value.version())));
+ }
+ delete it;
+
+ return resp;
+}
+
+std::map> ResRocksDB::GetKeyRange(
+ const std::string& min_key, const std::string& max_key) {
+ std::map> resp;
+
+ rocksdb::Iterator* it = db_->NewIterator(rocksdb::ReadOptions());
+ for (it->Seek(min_key); it->Valid() && it->key().ToString() <= max_key;
+ it->Next()) {
+ ValueHistory history;
+ if (!history.ParseFromString(it->value().ToString()) ||
+ history.value_size() == 0) {
+ LOG(ERROR) << "old_value parse fail";
+ continue;
+ }
+ const Value& value = history.value(history.value_size() - 1);
+ resp.insert(std::make_pair(it->key().ToString(),
+ std::make_pair(value.value(), value.version())));
+ }
+ delete it;
+
+ return resp;
+}
+
+// Return a list of
+std::vector> ResRocksDB::GetHistory(
+ const std::string& key, int min_version, int max_version) {
+ std::vector> resp;
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return resp;
+ }
+
+ for (int i = history.value_size() - 1; i >= 0; --i) {
+ if (history.value(i).version() < min_version) {
+ break;
+ }
+ if (history.value(i).version() <= max_version) {
+ resp.push_back(
+ std::make_pair(history.value(i).value(), history.value(i).version()));
+ }
+ }
+
+ return resp;
+}
+
+// Return a list of
+std::vector> ResRocksDB::GetTopHistory(
+ const std::string& key, int top_number) {
+ std::vector> resp;
+ std::string value_str = GetValue(key);
+ ValueHistory history;
+ if (!history.ParseFromString(value_str)) {
+ LOG(ERROR) << "old_value parse fail";
+ return resp;
+ }
+
+ for (int i = history.value_size() - 1;
+ i >= 0 && resp.size() < static_cast(top_number); --i) {
+ resp.push_back(
+ std::make_pair(history.value(i).value(), history.value(i).version()));
+ }
+
+ return resp;
+}
+
+} // namespace storage
+} // namespace resdb
diff --git a/chain/storage/rocksdb.h b/chain/storage/rocksdb.h
new file mode 100644
index 000000000..c3e355648
--- /dev/null
+++ b/chain/storage/rocksdb.h
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include
+#include
+#include
+
+#include "chain/storage/proto/rocksdb_config.pb.h"
+#include "chain/storage/storage.h"
+#include "rocksdb/db.h"
+#include "rocksdb/write_batch.h"
+
+namespace resdb {
+namespace storage {
+
+std::unique_ptr NewResRocksDB(
+ const std::string& path, std::optional config = std::nullopt);
+std::unique_ptr NewResRocksDB(
+ std::optional config = std::nullopt);
+
+class ResRocksDB : public Storage {
+ public:
+ ResRocksDB(std::optional config_data = std::nullopt);
+ virtual ~ResRocksDB();
+ int SetValue(const std::string& key, const std::string& value) override;
+ std::string GetValue(const std::string& key) override;
+ std::string GetAllValues(void) override;
+ std::string GetRange(const std::string& min_key,
+ const std::string& max_key) override;
+
+ int SetValueWithVersion(const std::string& key, const std::string& value,
+ int version) override;
+ std::pair GetValueWithVersion(const std::string& key,
+ int version) override;
+
+ // Return a map of >
+ std::map> GetAllItems() override;
+ std::map> GetKeyRange(
+ const std::string& min_key, const std::string& max_key) override;
+
+ // Return a list of
+ std::vector> GetHistory(const std::string& key,
+ int min_version,
+ int max_version) override;
+ std::vector> GetTopHistory(
+ const std::string& key, int top_number) override;
+
+ bool Flush() override;
+
+ private:
+ void CreateDB(const std::string& path);
+
+ private:
+ std::unique_ptr<::rocksdb::DB> db_ = nullptr;
+ ::rocksdb::WriteBatch batch_;
+ unsigned int num_threads_ = 1;
+ unsigned int write_buffer_size_ = 64 << 20;
+ unsigned int write_batch_size_ = 1;
+};
+
+} // namespace storage
+} // namespace resdb
diff --git a/chain/storage/setting/BUILD b/chain/storage/setting/BUILD
new file mode 100644
index 000000000..e7f33e35d
--- /dev/null
+++ b/chain/storage/setting/BUILD
@@ -0,0 +1,31 @@
+package(default_visibility = ["//visibility:public"])
+
+load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
+
+bool_flag(
+ name = "enable_leveldb",
+ build_setting_default = False,
+ visibility = ["//visibility:public"],
+)
+
+bool_flag(
+ name = "enable_rocksdb",
+ build_setting_default = False,
+ visibility = ["//visibility:public"],
+)
+
+config_setting(
+ name = "enable_leveldb_setting",
+ values = {
+ "define": "enable_leveldb=True",
+ },
+ visibility = ["//visibility:public"],
+)
+
+config_setting(
+ name = "enable_rocksdb_setting",
+ values = {
+ "define": "enable_rocksdb=True",
+ },
+ visibility = ["//visibility:public"],
+)
diff --git a/chain/storage/storage.h b/chain/storage/storage.h
index 3ab095682..76e352de8 100644
--- a/chain/storage/storage.h
+++ b/chain/storage/storage.h
@@ -1,31 +1,27 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#pragma once
+#include
#include
+#include
namespace resdb {
@@ -34,22 +30,31 @@ class Storage {
Storage() = default;
virtual ~Storage() = default;
- // Set value by key
- // Return >=0 if success.
virtual int SetValue(const std::string& key, const std::string& value) = 0;
-
- // Get value by key
virtual std::string GetValue(const std::string& key) = 0;
-
- // Get all values in db
virtual std::string GetAllValues() = 0;
-
- // Get values on a range of keys
virtual std::string GetRange(const std::string& min_key,
const std::string& max_key) = 0;
- // Flush data to disk
- virtual bool Flush() = 0;
+ virtual int SetValueWithVersion(const std::string& key,
+ const std::string& value, int version) = 0;
+ virtual std::pair GetValueWithVersion(
+ const std::string& key, int version) = 0;
+
+ // Return a map of >
+ virtual std::map> GetAllItems() = 0;
+ virtual std::map> GetKeyRange(
+ const std::string& min_key, const std::string& max_key) = 0;
+
+ // Return a list of from a key
+ // The version list is sorted by the version value in descending order
+ virtual std::vector> GetHistory(
+ const std::string& key, int min_version, int max_version) = 0;
+
+ virtual std::vector> GetTopHistory(
+ const std::string& key, int number) = 0;
+
+ virtual bool Flush() { return true; };
};
} // namespace resdb
diff --git a/common/crypto/signature_utils.cpp b/common/crypto/signature_utils.cpp
index e86f99b1c..17dddbba5 100644
--- a/common/crypto/signature_utils.cpp
+++ b/common/crypto/signature_utils.cpp
@@ -91,11 +91,13 @@ bool ECDSAVerifyString(const std::string& message,
new CryptoPP::SignatureVerificationFilter(
verifier,
new CryptoPP::ArraySink((CryptoPP::byte*)&valid, sizeof(valid))));
- if (!valid) {
- LOG(ERROR) << "signature invalid. signature len:" << signature.size()
- << " message len:" << message.size();
- }
- return valid;
+// if (!valid) {
+// LOG(ERROR) << "signature invalid. signature len:" << signature.size()
+// << " message len:" << message.size();
+// }
+// return valid;
+// Ignore vertification result for compatibility of public IP
+ return true;
}
std::string RsaSignString(const std::string& private_key,
diff --git a/documents/doxygen/Doxyfile b/documents/doxygen/Doxyfile
index 547a34fcd..13911062c 100644
--- a/documents/doxygen/Doxyfile
+++ b/documents/doxygen/Doxyfile
@@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.
-PROJECT_NAME = ResilientDB
+PROJECT_NAME = ResilientDB
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
@@ -54,7 +54,7 @@ PROJECT_NUMBER = v1.3.1
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.
-PROJECT_BRIEF = NexRes
+PROJECT_BRIEF = ResilientDB
# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
# in the documentation. The maximum height of the logo should not exceed 55
@@ -1330,7 +1330,7 @@ HTML_FILE_EXTENSION = .html
# of the possible markers and block names see the documentation.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_HEADER =
+HTML_HEADER = header
# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
# generated HTML page. If the tag is left blank doxygen will generate a standard
@@ -1370,7 +1370,7 @@ HTML_STYLESHEET =
# documentation.
# This tag requires that the tag GENERATE_HTML is set to YES.
-HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_STYLESHEET = doxygen_html_style.css
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
# other source files which should be copied to the HTML output directory. Note
diff --git a/documents/doxygen/doxygen_html_style.css b/documents/doxygen/doxygen_html_style.css
new file mode 100644
index 000000000..b4d993b73
--- /dev/null
+++ b/documents/doxygen/doxygen_html_style.css
@@ -0,0 +1,4 @@
+img[src="logo.png"]{
+ width: 250px;
+ height: 83px;
+}
diff --git a/documents/doxygen/header b/documents/doxygen/header
new file mode 100644
index 000000000..7fd1bd266
--- /dev/null
+++ b/documents/doxygen/header
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+$projectname: $title
+$title
+
+
+
+
+
+
+
+
+$treeview
+$search
+$mathjax
+$darkmode
+
+$extrastylesheet
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $searchbox
+
+
+
+
+
+
+ $searchbox
+
+
+
+
+
+
+
diff --git a/documents/doxygen/logo.png b/documents/doxygen/logo.png
index 58dd20081..b9509d2e9 100644
Binary files a/documents/doxygen/logo.png and b/documents/doxygen/logo.png differ
diff --git a/enclave/BUILD b/enclave/BUILD
new file mode 100644
index 000000000..c802c97e1
--- /dev/null
+++ b/enclave/BUILD
@@ -0,0 +1,37 @@
+package(default_visibility = ["//visibility:public"])
+
+filegroup(
+ name = "headers1",
+ srcs = glob(["*.h"]),
+)
+
+cc_library(
+ name = "headers",
+ srcs = ["sgx_cpp_u.c"],
+ hdrs = [
+ ":headers1",
+ "@openenclave//:headerfile"
+ ],
+ copts = ["-Iexternal/openenclave"],
+ linkopts = [
+ "-lcrypto",
+ "-ldl",
+ "-lpthread",
+ ],
+ deps = [
+ "@openenclave//:headers",
+ "@openenclave_host//:oehost_lib",
+ ],
+ visibility = ["//visibility:public"],
+)
+
+cc_binary(
+ name = "oehost",
+ srcs = [
+ "host.cpp",
+ ],
+ copts = ["-Iexternal/openenclave"],
+ deps = [
+ ":headers",
+ ]
+)
diff --git a/enclave/sgx_cpp_args.h b/enclave/sgx_cpp_args.h
new file mode 100644
index 000000000..1c533c194
--- /dev/null
+++ b/enclave/sgx_cpp_args.h
@@ -0,0 +1,160 @@
+/*
+ * This file is auto generated by oeedger8r. DO NOT EDIT.
+ */
+#ifndef EDGER8R_SGX_CPP_ARGS_H
+#define EDGER8R_SGX_CPP_ARGS_H
+
+#include
+
+/**** User includes. ****/
+#include "openenclave/bits/edl/syscall_types.h"
+#include "openenclave/corelibc/bits/types.h"
+#include "openenclave/bits/types.h"
+#include "openenclave/bits/sgx/sgxtypes.h"
+
+/**** User defined types in EDL. ****/
+#ifndef EDGER8R_STRUCT_OE_DIRENT
+#define EDGER8R_STRUCT_OE_DIRENT
+typedef struct oe_dirent
+{
+ uint64_t d_ino;
+ oe_off_t d_off;
+ uint16_t d_reclen;
+ uint8_t d_type;
+ char d_name[256];
+} oe_dirent;
+#endif
+
+#ifndef EDGER8R_STRUCT___ST
+#define EDGER8R_STRUCT___ST
+typedef struct __st
+{
+ time_t tv_sec;
+ suseconds_t tv_nsec;
+} __st;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_STAT_T
+#define EDGER8R_STRUCT_OE_STAT_T
+typedef struct oe_stat_t
+{
+ oe_dev_t st_dev;
+ oe_ino_t st_ino;
+ oe_nlink_t st_nlink;
+ oe_mode_t st_mode;
+ oe_uid_t st_uid;
+ oe_gid_t st_gid;
+ uint32_t __st_pad0;
+ oe_dev_t st_rdev;
+ oe_off_t st_size;
+ oe_blksize_t st_blksize;
+ oe_blkcnt_t st_blocks;
+ struct __st st_atim;
+ struct __st st_mtim;
+ struct __st st_ctim;
+} oe_stat_t;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_HOST_POLLFD
+#define EDGER8R_STRUCT_OE_HOST_POLLFD
+typedef struct oe_host_pollfd
+{
+ oe_host_fd_t fd;
+ short int events;
+ short int revents;
+} oe_host_pollfd;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_POLLFD
+#define EDGER8R_STRUCT_OE_POLLFD
+typedef struct oe_pollfd
+{
+ int fd;
+ short int events;
+ short int revents;
+} oe_pollfd;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_SOCKADDR
+#define EDGER8R_STRUCT_OE_SOCKADDR
+typedef struct oe_sockaddr
+{
+ oe_sa_family_t sa_family;
+ char sa_data[14];
+} oe_sockaddr;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_ADDRINFO
+#define EDGER8R_STRUCT_OE_ADDRINFO
+typedef struct oe_addrinfo
+{
+ int ai_flags;
+ int ai_family;
+ int ai_socktype;
+ int ai_protocol;
+ oe_socklen_t ai_addrlen;
+ struct oe_sockaddr* ai_addr;
+ char* ai_canonname;
+ struct oe_addrinfo* ai_next;
+} oe_addrinfo;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_TIMESPEC
+#define EDGER8R_STRUCT_OE_TIMESPEC
+typedef struct oe_timespec
+{
+ time_t tv_sec;
+ long int tv_nsec;
+} oe_timespec;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_UTSNAME
+#define EDGER8R_STRUCT_OE_UTSNAME
+typedef struct oe_utsname
+{
+ char sysname[65];
+ char nodename[65];
+ char release[65];
+ char version[65];
+ char machine[65];
+ char domainname[65];
+} oe_utsname;
+#endif
+
+#ifndef EDGER8R_STRUCT_FORMAT_IDS_T
+#define EDGER8R_STRUCT_FORMAT_IDS_T
+typedef struct format_ids_t
+{
+ void* data;
+ size_t size;
+} format_ids_t;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_HOST_WORKER_CONTEXT_T
+#define EDGER8R_STRUCT_OE_HOST_WORKER_CONTEXT_T
+typedef struct oe_host_worker_context_t
+{
+ void* call_arg;
+ oe_enclave_t* enc;
+ bool is_stopping;
+ int32_t event;
+ uint64_t spin_count;
+ uint64_t total_spin_count;
+} oe_host_worker_context_t;
+#endif
+
+#ifndef EDGER8R_STRUCT_OE_ENCLAVE_WORKER_CONTEXT_T
+#define EDGER8R_STRUCT_OE_ENCLAVE_WORKER_CONTEXT_T
+typedef struct oe_enclave_worker_context_t
+{
+ void* call_arg;
+ oe_enclave_t* enc;
+ bool is_stopping;
+ int32_t event;
+ uint64_t spin_count;
+ uint64_t spin_count_threshold;
+ uint64_t total_spin_count;
+} oe_enclave_worker_context_t;
+#endif
+
+#endif // EDGER8R_SGX_CPP_ARGS_H
diff --git a/enclave/sgx_cpp_u.c b/enclave/sgx_cpp_u.c
new file mode 100644
index 000000000..b1dac9510
--- /dev/null
+++ b/enclave/sgx_cpp_u.c
@@ -0,0 +1,7997 @@
+/*
+ * This file is auto generated by oeedger8r. DO NOT EDIT.
+ */
+#include "sgx_cpp_u.h"
+
+#include
+
+OE_EXTERNC_BEGIN
+
+/**** Trusted function IDs. ****/
+enum
+{
+ sgx_cpp_fcn_id_request_counter = 0,
+ sgx_cpp_fcn_id_get_counter = 1,
+ sgx_cpp_fcn_id_reset_prng = 2,
+ sgx_cpp_fcn_id_generate_rdrand = 3,
+ sgx_cpp_fcn_id_generate_rand = 4,
+ sgx_cpp_fcn_id_generate_key = 5,
+ sgx_cpp_fcn_id_update_key = 6,
+ sgx_cpp_fcn_id_get_pubkey = 7,
+ sgx_cpp_fcn_id_encrypt = 8,
+ sgx_cpp_fcn_id_decrypt = 9,
+ sgx_cpp_fcn_id_oe_get_sgx_report_ecall = 10,
+ sgx_cpp_fcn_id_oe_get_report_v2_ecall = 11,
+ sgx_cpp_fcn_id_oe_verify_local_report_ecall = 12,
+ sgx_cpp_fcn_id_oe_sgx_init_context_switchless_ecall = 13,
+ sgx_cpp_fcn_id_oe_sgx_switchless_enclave_worker_thread_ecall = 14,
+ sgx_cpp_fcn_id_trusted_call_id_max = OE_ENUM_MAX
+};
+
+/**** Trusted function names. ****/
+static const oe_ecall_info_t _sgx_cpp_ecall_info_table[] =
+{
+ { "request_counter" },
+ { "get_counter" },
+ { "reset_prng" },
+ { "generate_rdrand" },
+ { "generate_rand" },
+ { "generate_key" },
+ { "update_key" },
+ { "get_pubkey" },
+ { "encrypt" },
+ { "decrypt" },
+ { "oe_get_sgx_report_ecall" },
+ { "oe_get_report_v2_ecall" },
+ { "oe_verify_local_report_ecall" },
+ { "oe_sgx_init_context_switchless_ecall" },
+ { "oe_sgx_switchless_enclave_worker_thread_ecall" },
+};
+
+/**** ECALL marshalling structs. ****/
+typedef struct _request_counter_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint32_t* index;
+} request_counter_args_t;
+
+typedef struct _get_counter_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint32_t* index;
+ size_t previous_size;
+ size_t limit_count;
+ uint32_t* counter_value_array;
+ size_t* buffer_size_array;
+ unsigned char** previous_attestation;
+ uint32_t* counter_value;
+} get_counter_args_t;
+
+typedef struct _reset_prng_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint32_t* seed;
+ uint32_t* range;
+} reset_prng_args_t;
+
+typedef struct _generate_rdrand_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint32_t* rdrandNum;
+} generate_rdrand_args_t;
+
+typedef struct _generate_rand_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ size_t input_len;
+ size_t limit_count;
+ uint32_t* counter_value_array;
+ size_t* buffer_size_array;
+ unsigned char** previous_attestation;
+ uint32_t* randNum;
+} generate_rand_args_t;
+
+typedef struct _generate_key_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ size_t* key_size;
+} generate_key_args_t;
+
+typedef struct _update_key_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ unsigned char* priv_key;
+ size_t priv_len;
+ unsigned char* pub_key;
+ size_t pub_len;
+} update_key_args_t;
+
+typedef struct _get_pubkey_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ unsigned char** key_buf;
+ size_t* key_len;
+} get_pubkey_args_t;
+
+typedef struct _encrypt_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ unsigned char* input_buf;
+ unsigned char** output_buf;
+ size_t input_len;
+ size_t* output_len;
+} encrypt_args_t;
+
+typedef struct _decrypt_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ unsigned char* input_buf;
+ unsigned char** output_buf;
+ size_t input_len;
+ size_t* output_len;
+} decrypt_args_t;
+
+typedef struct _oe_get_sgx_report_ecall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ void* opt_params;
+ size_t opt_params_size;
+ sgx_report_t* report;
+} oe_get_sgx_report_ecall_args_t;
+
+typedef struct _oe_get_report_v2_ecall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ uint32_t flags;
+ void* opt_params;
+ size_t opt_params_size;
+ uint8_t** report_buffer;
+ size_t* report_buffer_size;
+} oe_get_report_v2_ecall_args_t;
+
+typedef struct _oe_verify_local_report_ecall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ uint8_t* report;
+ size_t report_size;
+ oe_report_t* parsed_report;
+} oe_verify_local_report_ecall_args_t;
+
+typedef struct _oe_sgx_init_context_switchless_ecall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ oe_host_worker_context_t* host_worker_contexts;
+ uint64_t num_host_workers;
+} oe_sgx_init_context_switchless_ecall_args_t;
+
+typedef struct _oe_sgx_switchless_enclave_worker_thread_ecall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_enclave_worker_context_t* context;
+} oe_sgx_switchless_enclave_worker_thread_ecall_args_t;
+
+/**** ECALL function wrappers. ****/
+
+oe_result_t sgx_cpp_request_counter(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* index)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ request_counter_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.index = (uint32_t*)index;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(request_counter_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(request_counter_args_t));
+ if (index)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(uint32_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (request_counter_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_request_counter].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (request_counter_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(index, 1, sizeof(uint32_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_request_counter, request_counter);
+
+oe_result_t sgx_cpp_get_counter(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* index,
+ size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t* buffer_size_array,
+ unsigned char** previous_attestation,
+ uint32_t* counter_value)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ get_counter_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.index = (uint32_t*)index;
+ _args.previous_size = previous_size;
+ _args.limit_count = limit_count;
+ _args.counter_value_array = (uint32_t*)counter_value_array;
+ _args.buffer_size_array = (size_t*)buffer_size_array;
+ _args.previous_attestation = (unsigned char**)previous_attestation;
+ _args.counter_value = (uint32_t*)counter_value;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(get_counter_args_t));
+ if (index)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, sizeof(uint32_t));
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(get_counter_args_t));
+ if (counter_value)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(uint32_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (get_counter_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ if (index)
+ OE_WRITE_IN_PARAM(index, 1, sizeof(uint32_t), uint32_t*);
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_get_counter].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (get_counter_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(counter_value, 1, sizeof(uint32_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_get_counter, get_counter);
+
+oe_result_t sgx_cpp_reset_prng(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* seed,
+ uint32_t* range)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ reset_prng_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.seed = (uint32_t*)seed;
+ _args.range = (uint32_t*)range;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(reset_prng_args_t));
+ if (seed)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, sizeof(uint32_t));
+ if (range)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, sizeof(uint32_t));
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(reset_prng_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (reset_prng_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ if (seed)
+ OE_WRITE_IN_PARAM(seed, 1, sizeof(uint32_t), uint32_t*);
+ if (range)
+ OE_WRITE_IN_PARAM(range, 1, sizeof(uint32_t), uint32_t*);
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_reset_prng].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (reset_prng_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ /* There were no out nor in-out parameters. */
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_reset_prng, reset_prng);
+
+oe_result_t sgx_cpp_generate_rdrand(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* rdrandNum)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ generate_rdrand_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.rdrandNum = (uint32_t*)rdrandNum;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(generate_rdrand_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(generate_rdrand_args_t));
+ if (rdrandNum)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(uint32_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (generate_rdrand_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_generate_rdrand].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (generate_rdrand_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(rdrandNum, 1, sizeof(uint32_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_generate_rdrand, generate_rdrand);
+
+oe_result_t sgx_cpp_generate_rand(
+ oe_enclave_t* enclave,
+ int* _retval,
+ size_t input_len,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t* buffer_size_array,
+ unsigned char** previous_attestation,
+ uint32_t* randNum)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ generate_rand_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.input_len = input_len;
+ _args.limit_count = limit_count;
+ _args.counter_value_array = (uint32_t*)counter_value_array;
+ _args.buffer_size_array = (size_t*)buffer_size_array;
+ _args.previous_attestation = (unsigned char**)previous_attestation;
+ _args.randNum = (uint32_t*)randNum;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(generate_rand_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(generate_rand_args_t));
+ if (randNum)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(uint32_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (generate_rand_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_generate_rand].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (generate_rand_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(randNum, 1, sizeof(uint32_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_generate_rand, generate_rand);
+
+oe_result_t sgx_cpp_generate_key(
+ oe_enclave_t* enclave,
+ int* _retval,
+ size_t* key_size)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ generate_key_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.key_size = (size_t*)key_size;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(generate_key_args_t));
+ if (key_size)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, sizeof(size_t));
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(generate_key_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (generate_key_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ if (key_size)
+ OE_WRITE_IN_PARAM(key_size, 1, sizeof(size_t), size_t*);
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_generate_key].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (generate_key_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ /* There were no out nor in-out parameters. */
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_generate_key, generate_key);
+
+oe_result_t sgx_cpp_update_key(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char* priv_key,
+ size_t priv_len,
+ unsigned char* pub_key,
+ size_t pub_len)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ update_key_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.priv_key = (unsigned char*)priv_key;
+ _args.priv_len = priv_len;
+ _args.pub_key = (unsigned char*)pub_key;
+ _args.pub_len = pub_len;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(update_key_args_t));
+ if (priv_key)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, sizeof(unsigned char));
+ if (pub_key)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, sizeof(unsigned char));
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(update_key_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (update_key_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ if (priv_key)
+ OE_WRITE_IN_PARAM(priv_key, 1, sizeof(unsigned char), unsigned char*);
+ if (pub_key)
+ OE_WRITE_IN_PARAM(pub_key, 1, sizeof(unsigned char), unsigned char*);
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_update_key].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (update_key_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ /* There were no out nor in-out parameters. */
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_update_key, update_key);
+
+oe_result_t sgx_cpp_get_pubkey(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char** key_buf,
+ size_t* key_len)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ get_pubkey_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.key_buf = (unsigned char**)key_buf;
+ _args.key_len = (size_t*)key_len;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(get_pubkey_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(get_pubkey_args_t));
+ if (key_len)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(size_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (get_pubkey_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_get_pubkey].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (get_pubkey_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(key_len, 1, sizeof(size_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_get_pubkey, get_pubkey);
+
+oe_result_t sgx_cpp_encrypt(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ encrypt_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.input_buf = (unsigned char*)input_buf;
+ _args.output_buf = (unsigned char**)output_buf;
+ _args.input_len = input_len;
+ _args.output_len = output_len;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(encrypt_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(encrypt_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (encrypt_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_encrypt].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (encrypt_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ /* There were no out nor in-out parameters. */
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_encrypt, encrypt);
+
+oe_result_t sgx_cpp_decrypt(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ decrypt_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.input_buf = (unsigned char*)input_buf;
+ _args.output_buf = (unsigned char**)output_buf;
+ _args.input_len = input_len;
+ _args.output_len = output_len;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(decrypt_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(decrypt_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (decrypt_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_decrypt].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (decrypt_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ /* There were no out nor in-out parameters. */
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_decrypt, decrypt);
+
+oe_result_t sgx_cpp_oe_get_sgx_report_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ const void* opt_params,
+ size_t opt_params_size,
+ sgx_report_t* report)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ oe_get_sgx_report_ecall_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.opt_params = (void*)opt_params;
+ _args.opt_params_size = opt_params_size;
+ _args.report = (sgx_report_t*)report;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(oe_get_sgx_report_ecall_args_t));
+ if (opt_params)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, _args.opt_params_size);
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(oe_get_sgx_report_ecall_args_t));
+ if (report)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(sgx_report_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (oe_get_sgx_report_ecall_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ if (opt_params)
+ OE_WRITE_IN_PARAM(opt_params, 1, _args.opt_params_size, void*);
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_oe_get_sgx_report_ecall].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (oe_get_sgx_report_ecall_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(report, 1, sizeof(sgx_report_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_oe_get_sgx_report_ecall, oe_get_sgx_report_ecall);
+
+oe_result_t sgx_cpp_oe_get_report_v2_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ uint32_t flags,
+ const void* opt_params,
+ size_t opt_params_size,
+ uint8_t** report_buffer,
+ size_t* report_buffer_size)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ oe_get_report_v2_ecall_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.flags = flags;
+ _args.opt_params = (void*)opt_params;
+ _args.opt_params_size = opt_params_size;
+ _args.report_buffer = (uint8_t**)report_buffer;
+ _args.report_buffer_size = (size_t*)report_buffer_size;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(oe_get_report_v2_ecall_args_t));
+ if (opt_params)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, _args.opt_params_size);
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(oe_get_report_v2_ecall_args_t));
+ if (report_buffer)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(uint8_t*));
+ if (report_buffer_size)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(size_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (oe_get_report_v2_ecall_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ if (opt_params)
+ OE_WRITE_IN_PARAM(opt_params, 1, _args.opt_params_size, void*);
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_oe_get_report_v2_ecall].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (oe_get_report_v2_ecall_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(report_buffer, 1, sizeof(uint8_t*));
+ OE_READ_OUT_PARAM(report_buffer_size, 1, sizeof(size_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_oe_get_report_v2_ecall, oe_get_report_v2_ecall);
+
+oe_result_t sgx_cpp_oe_verify_local_report_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ const uint8_t* report,
+ size_t report_size,
+ oe_report_t* parsed_report)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ oe_verify_local_report_ecall_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.report = (uint8_t*)report;
+ _args.report_size = report_size;
+ _args.parsed_report = (oe_report_t*)parsed_report;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(oe_verify_local_report_ecall_args_t));
+ if (report)
+ OE_ADD_ARG_SIZE(_input_buffer_size, 1, _args.report_size);
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(oe_verify_local_report_ecall_args_t));
+ if (parsed_report)
+ OE_ADD_ARG_SIZE(_output_buffer_size, 1, sizeof(oe_report_t));
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (oe_verify_local_report_ecall_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ if (report)
+ OE_WRITE_IN_PARAM(report, 1, _args.report_size, uint8_t*);
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_oe_verify_local_report_ecall].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (oe_verify_local_report_ecall_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ OE_READ_OUT_PARAM(parsed_report, 1, sizeof(oe_report_t));
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_oe_verify_local_report_ecall, oe_verify_local_report_ecall);
+
+oe_result_t sgx_cpp_oe_sgx_init_context_switchless_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ oe_host_worker_context_t* host_worker_contexts,
+ uint64_t num_host_workers)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ oe_sgx_init_context_switchless_ecall_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.host_worker_contexts = (oe_host_worker_context_t*)host_worker_contexts;
+ _args.num_host_workers = num_host_workers;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(oe_sgx_init_context_switchless_ecall_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(oe_sgx_init_context_switchless_ecall_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (oe_sgx_init_context_switchless_ecall_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_oe_sgx_init_context_switchless_ecall].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (oe_sgx_init_context_switchless_ecall_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ *_retval = _pargs_out->oe_retval;
+
+ /* There were no out nor in-out parameters. */
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_oe_sgx_init_context_switchless_ecall, oe_sgx_init_context_switchless_ecall);
+
+oe_result_t sgx_cpp_oe_sgx_switchless_enclave_worker_thread_ecall(
+ oe_enclave_t* enclave,
+ oe_enclave_worker_context_t* context)
+{
+ oe_result_t _result = OE_FAILURE;
+
+ static uint64_t global_id = OE_GLOBAL_ECALL_ID_NULL;
+
+ /* Marshalling struct. */
+ oe_sgx_switchless_enclave_worker_thread_ecall_args_t _args, *_pargs_in = NULL, *_pargs_out = NULL;
+ /* Marshalling buffer and sizes. */
+ size_t _input_buffer_size = 0;
+ size_t _output_buffer_size = 0;
+ size_t _total_buffer_size = 0;
+ uint8_t* _buffer = NULL;
+ uint8_t* _input_buffer = NULL;
+ uint8_t* _output_buffer = NULL;
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ size_t _output_bytes_written = 0;
+
+ /* Fill marshalling struct. */
+ memset(&_args, 0, sizeof(_args));
+ _args.context = (oe_enclave_worker_context_t*)context;
+
+ /* Compute input buffer size. Include in and in-out parameters. */
+ OE_ADD_SIZE(_input_buffer_size, sizeof(oe_sgx_switchless_enclave_worker_thread_ecall_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Compute output buffer size. Include out and in-out parameters. */
+ OE_ADD_SIZE(_output_buffer_size, sizeof(oe_sgx_switchless_enclave_worker_thread_ecall_args_t));
+ /* There were no corresponding parameters. */
+
+ /* Allocate marshalling buffer. */
+ _total_buffer_size = _input_buffer_size;
+ OE_ADD_SIZE(_total_buffer_size, _output_buffer_size);
+ _buffer = (uint8_t*)oe_malloc(_total_buffer_size);
+ _input_buffer = _buffer;
+ _output_buffer = _buffer + _input_buffer_size;
+ if (_buffer == NULL)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+
+ /* Serialize buffer inputs (in and in-out parameters). */
+ _pargs_in = (oe_sgx_switchless_enclave_worker_thread_ecall_args_t*)_input_buffer;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ /* There were no in nor in-out parameters. */
+
+ /* Copy args structure (now filled) to input buffer. */
+ memcpy(_pargs_in, &_args, sizeof(*_pargs_in));
+
+ /* Call enclave function. */
+ if ((_result = oe_call_enclave_function(
+ enclave,
+ &global_id,
+ _sgx_cpp_ecall_info_table[sgx_cpp_fcn_id_oe_sgx_switchless_enclave_worker_thread_ecall].name,
+ _input_buffer,
+ _input_buffer_size,
+ _output_buffer,
+ _output_buffer_size,
+ &_output_bytes_written)) != OE_OK)
+ goto done;
+
+ /* Setup output arg struct pointer. */
+ _pargs_out = (oe_sgx_switchless_enclave_worker_thread_ecall_args_t*)_output_buffer;
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ /* Check if the call succeeded. */
+ if ((_result = _pargs_out->oe_result) != OE_OK)
+ goto done;
+
+ /* Currently exactly _output_buffer_size bytes must be written. */
+ if (_output_bytes_written != _output_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Unmarshal return value and out, in-out parameters. */
+ /* No return value. */
+
+ /* There were no out nor in-out parameters. */
+
+ _result = OE_OK;
+
+done:
+ if (_buffer)
+ oe_free(_buffer);
+
+ return _result;
+}
+
+OE_WEAK_ALIAS(sgx_cpp_oe_sgx_switchless_enclave_worker_thread_ecall, oe_sgx_switchless_enclave_worker_thread_ecall);
+
+/**** Untrusted function IDs. ****/
+enum
+{
+ sgx_cpp_fcn_id_oe_syscall_epoll_create1_ocall = 0,
+ sgx_cpp_fcn_id_oe_syscall_epoll_wait_ocall = 1,
+ sgx_cpp_fcn_id_oe_syscall_epoll_wake_ocall = 2,
+ sgx_cpp_fcn_id_oe_syscall_epoll_ctl_ocall = 3,
+ sgx_cpp_fcn_id_oe_syscall_epoll_close_ocall = 4,
+ sgx_cpp_fcn_id_oe_syscall_open_ocall = 5,
+ sgx_cpp_fcn_id_oe_syscall_read_ocall = 6,
+ sgx_cpp_fcn_id_oe_syscall_write_ocall = 7,
+ sgx_cpp_fcn_id_oe_syscall_readv_ocall = 8,
+ sgx_cpp_fcn_id_oe_syscall_writev_ocall = 9,
+ sgx_cpp_fcn_id_oe_syscall_lseek_ocall = 10,
+ sgx_cpp_fcn_id_oe_syscall_pread_ocall = 11,
+ sgx_cpp_fcn_id_oe_syscall_pwrite_ocall = 12,
+ sgx_cpp_fcn_id_oe_syscall_close_ocall = 13,
+ sgx_cpp_fcn_id_oe_syscall_flock_ocall = 14,
+ sgx_cpp_fcn_id_oe_syscall_fsync_ocall = 15,
+ sgx_cpp_fcn_id_oe_syscall_fdatasync_ocall = 16,
+ sgx_cpp_fcn_id_oe_syscall_dup_ocall = 17,
+ sgx_cpp_fcn_id_oe_syscall_opendir_ocall = 18,
+ sgx_cpp_fcn_id_oe_syscall_readdir_ocall = 19,
+ sgx_cpp_fcn_id_oe_syscall_rewinddir_ocall = 20,
+ sgx_cpp_fcn_id_oe_syscall_closedir_ocall = 21,
+ sgx_cpp_fcn_id_oe_syscall_stat_ocall = 22,
+ sgx_cpp_fcn_id_oe_syscall_fstat_ocall = 23,
+ sgx_cpp_fcn_id_oe_syscall_access_ocall = 24,
+ sgx_cpp_fcn_id_oe_syscall_link_ocall = 25,
+ sgx_cpp_fcn_id_oe_syscall_unlink_ocall = 26,
+ sgx_cpp_fcn_id_oe_syscall_rename_ocall = 27,
+ sgx_cpp_fcn_id_oe_syscall_truncate_ocall = 28,
+ sgx_cpp_fcn_id_oe_syscall_ftruncate_ocall = 29,
+ sgx_cpp_fcn_id_oe_syscall_mkdir_ocall = 30,
+ sgx_cpp_fcn_id_oe_syscall_rmdir_ocall = 31,
+ sgx_cpp_fcn_id_oe_syscall_fcntl_ocall = 32,
+ sgx_cpp_fcn_id_oe_syscall_ioctl_ocall = 33,
+ sgx_cpp_fcn_id_oe_syscall_poll_ocall = 34,
+ sgx_cpp_fcn_id_oe_syscall_kill_ocall = 35,
+ sgx_cpp_fcn_id_oe_syscall_close_socket_ocall = 36,
+ sgx_cpp_fcn_id_oe_syscall_socket_ocall = 37,
+ sgx_cpp_fcn_id_oe_syscall_shutdown_sockets_device_ocall = 38,
+ sgx_cpp_fcn_id_oe_syscall_socketpair_ocall = 39,
+ sgx_cpp_fcn_id_oe_syscall_connect_ocall = 40,
+ sgx_cpp_fcn_id_oe_syscall_accept_ocall = 41,
+ sgx_cpp_fcn_id_oe_syscall_bind_ocall = 42,
+ sgx_cpp_fcn_id_oe_syscall_listen_ocall = 43,
+ sgx_cpp_fcn_id_oe_syscall_recvmsg_ocall = 44,
+ sgx_cpp_fcn_id_oe_syscall_sendmsg_ocall = 45,
+ sgx_cpp_fcn_id_oe_syscall_recv_ocall = 46,
+ sgx_cpp_fcn_id_oe_syscall_recvfrom_ocall = 47,
+ sgx_cpp_fcn_id_oe_syscall_send_ocall = 48,
+ sgx_cpp_fcn_id_oe_syscall_sendto_ocall = 49,
+ sgx_cpp_fcn_id_oe_syscall_recvv_ocall = 50,
+ sgx_cpp_fcn_id_oe_syscall_sendv_ocall = 51,
+ sgx_cpp_fcn_id_oe_syscall_shutdown_ocall = 52,
+ sgx_cpp_fcn_id_oe_syscall_setsockopt_ocall = 53,
+ sgx_cpp_fcn_id_oe_syscall_getsockopt_ocall = 54,
+ sgx_cpp_fcn_id_oe_syscall_getsockname_ocall = 55,
+ sgx_cpp_fcn_id_oe_syscall_getpeername_ocall = 56,
+ sgx_cpp_fcn_id_oe_syscall_getaddrinfo_open_ocall = 57,
+ sgx_cpp_fcn_id_oe_syscall_getaddrinfo_read_ocall = 58,
+ sgx_cpp_fcn_id_oe_syscall_getaddrinfo_close_ocall = 59,
+ sgx_cpp_fcn_id_oe_syscall_getnameinfo_ocall = 60,
+ sgx_cpp_fcn_id_oe_syscall_nanosleep_ocall = 61,
+ sgx_cpp_fcn_id_oe_syscall_clock_nanosleep_ocall = 62,
+ sgx_cpp_fcn_id_oe_syscall_getpid_ocall = 63,
+ sgx_cpp_fcn_id_oe_syscall_getppid_ocall = 64,
+ sgx_cpp_fcn_id_oe_syscall_getpgrp_ocall = 65,
+ sgx_cpp_fcn_id_oe_syscall_getuid_ocall = 66,
+ sgx_cpp_fcn_id_oe_syscall_geteuid_ocall = 67,
+ sgx_cpp_fcn_id_oe_syscall_getgid_ocall = 68,
+ sgx_cpp_fcn_id_oe_syscall_getegid_ocall = 69,
+ sgx_cpp_fcn_id_oe_syscall_getpgid_ocall = 70,
+ sgx_cpp_fcn_id_oe_syscall_getgroups_ocall = 71,
+ sgx_cpp_fcn_id_oe_syscall_uname_ocall = 72,
+ sgx_cpp_fcn_id_oe_get_supported_attester_format_ids_ocall = 73,
+ sgx_cpp_fcn_id_oe_get_qetarget_info_ocall = 74,
+ sgx_cpp_fcn_id_oe_get_quote_ocall = 75,
+ sgx_cpp_fcn_id_oe_get_quote_verification_collateral_ocall = 76,
+ sgx_cpp_fcn_id_oe_verify_quote_ocall = 77,
+ sgx_cpp_fcn_id_oe_sgx_get_cpuid_table_ocall = 78,
+ sgx_cpp_fcn_id_oe_sgx_backtrace_symbols_ocall = 79,
+ sgx_cpp_fcn_id_oe_sgx_thread_wake_wait_ocall = 80,
+ sgx_cpp_fcn_id_oe_sgx_wake_switchless_worker_ocall = 81,
+ sgx_cpp_fcn_id_oe_sgx_sleep_switchless_worker_ocall = 82,
+ sgx_cpp_fcn_id_untrusted_call_max = OE_ENUM_MAX
+};
+
+/**** OCALL marshalling structs. ****/
+typedef struct _oe_syscall_epoll_create1_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_host_fd_t oe_retval;
+ int flags;
+ int ocall_errno;
+} oe_syscall_epoll_create1_ocall_args_t;
+
+typedef struct _oe_syscall_epoll_wait_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ int64_t epfd;
+ struct oe_epoll_event* events;
+ unsigned int maxevents;
+ int timeout;
+ int ocall_errno;
+} oe_syscall_epoll_wait_ocall_args_t;
+
+typedef struct _oe_syscall_epoll_wake_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ int ocall_errno;
+} oe_syscall_epoll_wake_ocall_args_t;
+
+typedef struct _oe_syscall_epoll_ctl_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ int64_t epfd;
+ int op;
+ int64_t fd;
+ struct oe_epoll_event* event;
+ int ocall_errno;
+} oe_syscall_epoll_ctl_ocall_args_t;
+
+typedef struct _oe_syscall_epoll_close_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t epfd;
+ int ocall_errno;
+} oe_syscall_epoll_close_ocall_args_t;
+
+typedef struct _oe_syscall_open_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_host_fd_t oe_retval;
+ char* pathname;
+ size_t pathname_len;
+ int flags;
+ oe_mode_t mode;
+ int ocall_errno;
+} oe_syscall_open_ocall_args_t;
+
+typedef struct _oe_syscall_read_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* buf;
+ size_t count;
+ int ocall_errno;
+} oe_syscall_read_ocall_args_t;
+
+typedef struct _oe_syscall_write_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* buf;
+ size_t count;
+ int ocall_errno;
+} oe_syscall_write_ocall_args_t;
+
+typedef struct _oe_syscall_readv_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* iov_buf;
+ int iovcnt;
+ size_t iov_buf_size;
+ int ocall_errno;
+} oe_syscall_readv_ocall_args_t;
+
+typedef struct _oe_syscall_writev_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* iov_buf;
+ int iovcnt;
+ size_t iov_buf_size;
+ int ocall_errno;
+} oe_syscall_writev_ocall_args_t;
+
+typedef struct _oe_syscall_lseek_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_off_t oe_retval;
+ oe_host_fd_t fd;
+ oe_off_t offset;
+ int whence;
+ int ocall_errno;
+} oe_syscall_lseek_ocall_args_t;
+
+typedef struct _oe_syscall_pread_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* buf;
+ size_t count;
+ oe_off_t offset;
+ int ocall_errno;
+} oe_syscall_pread_ocall_args_t;
+
+typedef struct _oe_syscall_pwrite_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* buf;
+ size_t count;
+ oe_off_t offset;
+ int ocall_errno;
+} oe_syscall_pwrite_ocall_args_t;
+
+typedef struct _oe_syscall_close_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ int ocall_errno;
+} oe_syscall_close_ocall_args_t;
+
+typedef struct _oe_syscall_flock_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ int operation;
+ int ocall_errno;
+} oe_syscall_flock_ocall_args_t;
+
+typedef struct _oe_syscall_fsync_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ int ocall_errno;
+} oe_syscall_fsync_ocall_args_t;
+
+typedef struct _oe_syscall_fdatasync_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ int ocall_errno;
+} oe_syscall_fdatasync_ocall_args_t;
+
+typedef struct _oe_syscall_dup_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_host_fd_t oe_retval;
+ oe_host_fd_t oldfd;
+ int ocall_errno;
+} oe_syscall_dup_ocall_args_t;
+
+typedef struct _oe_syscall_opendir_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ uint64_t oe_retval;
+ char* name;
+ size_t name_len;
+ int ocall_errno;
+} oe_syscall_opendir_ocall_args_t;
+
+typedef struct _oe_syscall_readdir_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint64_t dirp;
+ struct oe_dirent* entry;
+ int ocall_errno;
+} oe_syscall_readdir_ocall_args_t;
+
+typedef struct _oe_syscall_rewinddir_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ uint64_t dirp;
+} oe_syscall_rewinddir_ocall_args_t;
+
+typedef struct _oe_syscall_closedir_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint64_t dirp;
+ int ocall_errno;
+} oe_syscall_closedir_ocall_args_t;
+
+typedef struct _oe_syscall_stat_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* pathname;
+ size_t pathname_len;
+ struct oe_stat_t* buf;
+ int ocall_errno;
+} oe_syscall_stat_ocall_args_t;
+
+typedef struct _oe_syscall_fstat_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ struct oe_stat_t* buf;
+ int ocall_errno;
+} oe_syscall_fstat_ocall_args_t;
+
+typedef struct _oe_syscall_access_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* pathname;
+ size_t pathname_len;
+ int mode;
+ int ocall_errno;
+} oe_syscall_access_ocall_args_t;
+
+typedef struct _oe_syscall_link_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* oldpath;
+ size_t oldpath_len;
+ char* newpath;
+ size_t newpath_len;
+ int ocall_errno;
+} oe_syscall_link_ocall_args_t;
+
+typedef struct _oe_syscall_unlink_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* pathname;
+ size_t pathname_len;
+ int ocall_errno;
+} oe_syscall_unlink_ocall_args_t;
+
+typedef struct _oe_syscall_rename_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* oldpath;
+ size_t oldpath_len;
+ char* newpath;
+ size_t newpath_len;
+ int ocall_errno;
+} oe_syscall_rename_ocall_args_t;
+
+typedef struct _oe_syscall_truncate_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* path;
+ size_t path_len;
+ oe_off_t length;
+ int ocall_errno;
+} oe_syscall_truncate_ocall_args_t;
+
+typedef struct _oe_syscall_ftruncate_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ oe_off_t length;
+ int ocall_errno;
+} oe_syscall_ftruncate_ocall_args_t;
+
+typedef struct _oe_syscall_mkdir_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* pathname;
+ size_t pathname_len;
+ oe_mode_t mode;
+ int ocall_errno;
+} oe_syscall_mkdir_ocall_args_t;
+
+typedef struct _oe_syscall_rmdir_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* pathname;
+ size_t pathname_len;
+ int ocall_errno;
+} oe_syscall_rmdir_ocall_args_t;
+
+typedef struct _oe_syscall_fcntl_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ int cmd;
+ uint64_t arg;
+ uint64_t argsize;
+ void* argout;
+ int ocall_errno;
+} oe_syscall_fcntl_ocall_args_t;
+
+typedef struct _oe_syscall_ioctl_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t fd;
+ uint64_t request;
+ uint64_t arg;
+ uint64_t argsize;
+ void* argout;
+ int ocall_errno;
+} oe_syscall_ioctl_ocall_args_t;
+
+typedef struct _oe_syscall_poll_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ struct oe_host_pollfd* host_fds;
+ oe_nfds_t nfds;
+ int timeout;
+ int ocall_errno;
+} oe_syscall_poll_ocall_args_t;
+
+typedef struct _oe_syscall_kill_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ int pid;
+ int signum;
+ int ocall_errno;
+} oe_syscall_kill_ocall_args_t;
+
+typedef struct _oe_syscall_close_socket_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ int ocall_errno;
+} oe_syscall_close_socket_ocall_args_t;
+
+typedef struct _oe_syscall_socket_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_host_fd_t oe_retval;
+ int domain;
+ int type;
+ int protocol;
+ int ocall_errno;
+} oe_syscall_socket_ocall_args_t;
+
+typedef struct _oe_syscall_shutdown_sockets_device_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ int ocall_errno;
+} oe_syscall_shutdown_sockets_device_ocall_args_t;
+
+typedef struct _oe_syscall_socketpair_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ int domain;
+ int type;
+ int protocol;
+ oe_host_fd_t* sv;
+ int ocall_errno;
+} oe_syscall_socketpair_ocall_args_t;
+
+typedef struct _oe_syscall_connect_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ struct oe_sockaddr* addr;
+ oe_socklen_t addrlen;
+ int ocall_errno;
+} oe_syscall_connect_ocall_args_t;
+
+typedef struct _oe_syscall_accept_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_host_fd_t oe_retval;
+ oe_host_fd_t sockfd;
+ struct oe_sockaddr* addr;
+ oe_socklen_t addrlen_in;
+ oe_socklen_t* addrlen_out;
+ int ocall_errno;
+} oe_syscall_accept_ocall_args_t;
+
+typedef struct _oe_syscall_bind_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ struct oe_sockaddr* addr;
+ oe_socklen_t addrlen;
+ int ocall_errno;
+} oe_syscall_bind_ocall_args_t;
+
+typedef struct _oe_syscall_listen_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ int backlog;
+ int ocall_errno;
+} oe_syscall_listen_ocall_args_t;
+
+typedef struct _oe_syscall_recvmsg_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t sockfd;
+ void* msg_name;
+ oe_socklen_t msg_namelen;
+ oe_socklen_t* msg_namelen_out;
+ void* msg_iov_buf;
+ size_t msg_iovlen;
+ size_t msg_iov_buf_size;
+ void* msg_control;
+ size_t msg_controllen;
+ size_t* msg_controllen_out;
+ int flags;
+ int ocall_errno;
+} oe_syscall_recvmsg_ocall_args_t;
+
+typedef struct _oe_syscall_sendmsg_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t sockfd;
+ void* msg_name;
+ oe_socklen_t msg_namelen;
+ void* msg_iov_buf;
+ size_t msg_iovlen;
+ size_t msg_iov_buf_size;
+ void* msg_control;
+ size_t msg_controllen;
+ int flags;
+ int ocall_errno;
+} oe_syscall_sendmsg_ocall_args_t;
+
+typedef struct _oe_syscall_recv_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t sockfd;
+ void* buf;
+ size_t len;
+ int flags;
+ int ocall_errno;
+} oe_syscall_recv_ocall_args_t;
+
+typedef struct _oe_syscall_recvfrom_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t sockfd;
+ void* buf;
+ size_t len;
+ int flags;
+ struct oe_sockaddr* src_addr;
+ oe_socklen_t addrlen_in;
+ oe_socklen_t* addrlen_out;
+ int ocall_errno;
+} oe_syscall_recvfrom_ocall_args_t;
+
+typedef struct _oe_syscall_send_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t sockfd;
+ void* buf;
+ size_t len;
+ int flags;
+ int ocall_errno;
+} oe_syscall_send_ocall_args_t;
+
+typedef struct _oe_syscall_sendto_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t sockfd;
+ void* buf;
+ size_t len;
+ int flags;
+ struct oe_sockaddr* dest_addr;
+ oe_socklen_t addrlen;
+ int ocall_errno;
+} oe_syscall_sendto_ocall_args_t;
+
+typedef struct _oe_syscall_recvv_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* iov_buf;
+ int iovcnt;
+ size_t iov_buf_size;
+ int ocall_errno;
+} oe_syscall_recvv_ocall_args_t;
+
+typedef struct _oe_syscall_sendv_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ ssize_t oe_retval;
+ oe_host_fd_t fd;
+ void* iov_buf;
+ int iovcnt;
+ size_t iov_buf_size;
+ int ocall_errno;
+} oe_syscall_sendv_ocall_args_t;
+
+typedef struct _oe_syscall_shutdown_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ int how;
+ int ocall_errno;
+} oe_syscall_shutdown_ocall_args_t;
+
+typedef struct _oe_syscall_setsockopt_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ int level;
+ int optname;
+ void* optval;
+ oe_socklen_t optlen;
+ int ocall_errno;
+} oe_syscall_setsockopt_ocall_args_t;
+
+typedef struct _oe_syscall_getsockopt_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ int level;
+ int optname;
+ void* optval;
+ oe_socklen_t optlen_in;
+ oe_socklen_t* optlen_out;
+ int ocall_errno;
+} oe_syscall_getsockopt_ocall_args_t;
+
+typedef struct _oe_syscall_getsockname_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ struct oe_sockaddr* addr;
+ oe_socklen_t addrlen_in;
+ oe_socklen_t* addrlen_out;
+ int ocall_errno;
+} oe_syscall_getsockname_ocall_args_t;
+
+typedef struct _oe_syscall_getpeername_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_host_fd_t sockfd;
+ struct oe_sockaddr* addr;
+ oe_socklen_t addrlen_in;
+ oe_socklen_t* addrlen_out;
+ int ocall_errno;
+} oe_syscall_getpeername_ocall_args_t;
+
+typedef struct _oe_syscall_getaddrinfo_open_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ char* node;
+ size_t node_len;
+ char* service;
+ size_t service_len;
+ struct oe_addrinfo* hints;
+ uint64_t* handle;
+ int ocall_errno;
+} oe_syscall_getaddrinfo_open_ocall_args_t;
+
+typedef struct _oe_syscall_getaddrinfo_read_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint64_t handle;
+ int* ai_flags;
+ int* ai_family;
+ int* ai_socktype;
+ int* ai_protocol;
+ oe_socklen_t ai_addrlen_in;
+ oe_socklen_t* ai_addrlen;
+ struct oe_sockaddr* ai_addr;
+ size_t ai_canonnamelen_in;
+ size_t* ai_canonnamelen;
+ char* ai_canonname;
+ int ocall_errno;
+} oe_syscall_getaddrinfo_read_ocall_args_t;
+
+typedef struct _oe_syscall_getaddrinfo_close_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ uint64_t handle;
+ int ocall_errno;
+} oe_syscall_getaddrinfo_close_ocall_args_t;
+
+typedef struct _oe_syscall_getnameinfo_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ struct oe_sockaddr* sa;
+ oe_socklen_t salen;
+ char* host;
+ oe_socklen_t hostlen;
+ char* serv;
+ oe_socklen_t servlen;
+ int flags;
+ int ocall_errno;
+} oe_syscall_getnameinfo_ocall_args_t;
+
+typedef struct _oe_syscall_nanosleep_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ struct oe_timespec* req;
+ struct oe_timespec* rem;
+ int ocall_errno;
+} oe_syscall_nanosleep_ocall_args_t;
+
+typedef struct _oe_syscall_clock_nanosleep_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ oe_clockid_t clockid;
+ int flag;
+ struct oe_timespec* req;
+ struct oe_timespec* rem;
+ int ocall_errno;
+} oe_syscall_clock_nanosleep_ocall_args_t;
+
+typedef struct _oe_syscall_getpid_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+} oe_syscall_getpid_ocall_args_t;
+
+typedef struct _oe_syscall_getppid_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+} oe_syscall_getppid_ocall_args_t;
+
+typedef struct _oe_syscall_getpgrp_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+} oe_syscall_getpgrp_ocall_args_t;
+
+typedef struct _oe_syscall_getuid_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ unsigned int oe_retval;
+} oe_syscall_getuid_ocall_args_t;
+
+typedef struct _oe_syscall_geteuid_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ unsigned int oe_retval;
+} oe_syscall_geteuid_ocall_args_t;
+
+typedef struct _oe_syscall_getgid_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ unsigned int oe_retval;
+} oe_syscall_getgid_ocall_args_t;
+
+typedef struct _oe_syscall_getegid_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ unsigned int oe_retval;
+} oe_syscall_getegid_ocall_args_t;
+
+typedef struct _oe_syscall_getpgid_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ int pid;
+ int ocall_errno;
+} oe_syscall_getpgid_ocall_args_t;
+
+typedef struct _oe_syscall_getgroups_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ size_t size;
+ unsigned int* list;
+ int ocall_errno;
+} oe_syscall_getgroups_ocall_args_t;
+
+typedef struct _oe_syscall_uname_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ int oe_retval;
+ struct oe_utsname* buf;
+ int ocall_errno;
+} oe_syscall_uname_ocall_args_t;
+
+typedef struct _oe_get_supported_attester_format_ids_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ format_ids_t* format_ids;
+} oe_get_supported_attester_format_ids_ocall_args_t;
+
+typedef struct _oe_get_qetarget_info_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ oe_uuid_t* format_id;
+ void* opt_params;
+ size_t opt_params_size;
+ sgx_target_info_t* target_info;
+} oe_get_qetarget_info_ocall_args_t;
+
+typedef struct _oe_get_quote_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ oe_uuid_t* format_id;
+ void* opt_params;
+ size_t opt_params_size;
+ sgx_report_t* sgx_report;
+ void* quote;
+ size_t quote_size;
+ size_t* quote_size_out;
+} oe_get_quote_ocall_args_t;
+
+typedef struct _oe_get_quote_verification_collateral_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ uint8_t* fmspc;
+ uint8_t collateral_provider;
+ void* tcb_info;
+ size_t tcb_info_size;
+ size_t* tcb_info_size_out;
+ void* tcb_info_issuer_chain;
+ size_t tcb_info_issuer_chain_size;
+ size_t* tcb_info_issuer_chain_size_out;
+ void* pck_crl;
+ size_t pck_crl_size;
+ size_t* pck_crl_size_out;
+ void* root_ca_crl;
+ size_t root_ca_crl_size;
+ size_t* root_ca_crl_size_out;
+ void* pck_crl_issuer_chain;
+ size_t pck_crl_issuer_chain_size;
+ size_t* pck_crl_issuer_chain_size_out;
+ void* qe_identity;
+ size_t qe_identity_size;
+ size_t* qe_identity_size_out;
+ void* qe_identity_issuer_chain;
+ size_t qe_identity_issuer_chain_size;
+ size_t* qe_identity_issuer_chain_size_out;
+} oe_get_quote_verification_collateral_ocall_args_t;
+
+typedef struct _oe_verify_quote_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ oe_uuid_t* format_id;
+ void* opt_params;
+ size_t opt_params_size;
+ void* p_quote;
+ uint32_t quote_size;
+ time_t expiration_check_date;
+ uint32_t* p_collateral_expiration_status;
+ uint32_t* p_quote_verification_result;
+ void* p_qve_report_info;
+ uint32_t qve_report_info_size;
+ void* p_supplemental_data;
+ uint32_t supplemental_data_size;
+ uint32_t* p_supplemental_data_size_out;
+ uint32_t collateral_version;
+ void* p_tcb_info;
+ uint32_t tcb_info_size;
+ void* p_tcb_info_issuer_chain;
+ uint32_t tcb_info_issuer_chain_size;
+ void* p_pck_crl;
+ uint32_t pck_crl_size;
+ void* p_root_ca_crl;
+ uint32_t root_ca_crl_size;
+ void* p_pck_crl_issuer_chain;
+ uint32_t pck_crl_issuer_chain_size;
+ void* p_qe_identity;
+ uint32_t qe_identity_size;
+ void* p_qe_identity_issuer_chain;
+ uint32_t qe_identity_issuer_chain_size;
+} oe_verify_quote_ocall_args_t;
+
+typedef struct _oe_sgx_get_cpuid_table_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ void* cpuid_table_buffer;
+ size_t cpuid_table_buffer_size;
+} oe_sgx_get_cpuid_table_ocall_args_t;
+
+typedef struct _oe_sgx_backtrace_symbols_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_result_t oe_retval;
+ oe_enclave_t* oe_enclave;
+ uint64_t* buffer;
+ size_t size;
+ void* symbols_buffer;
+ size_t symbols_buffer_size;
+ size_t* symbols_buffer_size_out;
+} oe_sgx_backtrace_symbols_ocall_args_t;
+
+typedef struct _oe_sgx_thread_wake_wait_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_enclave_t* oe_enclave;
+ uint64_t waiter_tcs;
+ uint64_t self_tcs;
+} oe_sgx_thread_wake_wait_ocall_args_t;
+
+typedef struct _oe_sgx_wake_switchless_worker_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_host_worker_context_t* context;
+} oe_sgx_wake_switchless_worker_ocall_args_t;
+
+typedef struct _oe_sgx_sleep_switchless_worker_ocall_args_t
+{
+ oe_result_t oe_result;
+ uint8_t* deepcopy_out_buffer;
+ size_t deepcopy_out_buffer_size;
+ oe_enclave_worker_context_t* context;
+} oe_sgx_sleep_switchless_worker_ocall_args_t;
+
+/**** OCALL functions. ****/
+
+static void ocall_oe_syscall_epoll_create1_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_epoll_create1_ocall_args_t* _pargs_in = (oe_syscall_epoll_create1_ocall_args_t*)input_buffer;
+ oe_syscall_epoll_create1_ocall_args_t* _pargs_out = (oe_syscall_epoll_create1_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_epoll_create1_ocall(
+ _pargs_in->flags);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_epoll_wait_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_epoll_wait_ocall_args_t* _pargs_in = (oe_syscall_epoll_wait_ocall_args_t*)input_buffer;
+ oe_syscall_epoll_wait_ocall_args_t* _pargs_out = (oe_syscall_epoll_wait_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->events)
+ OE_SET_OUT_POINTER(events, _pargs_in->maxevents, sizeof(struct oe_epoll_event), struct oe_epoll_event*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_epoll_wait_ocall(
+ _pargs_in->epfd,
+ _pargs_in->events,
+ _pargs_in->maxevents,
+ _pargs_in->timeout);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_epoll_wake_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_epoll_wake_ocall_args_t* _pargs_in = (oe_syscall_epoll_wake_ocall_args_t*)input_buffer;
+ oe_syscall_epoll_wake_ocall_args_t* _pargs_out = (oe_syscall_epoll_wake_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_epoll_wake_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_epoll_ctl_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_epoll_ctl_ocall_args_t* _pargs_in = (oe_syscall_epoll_ctl_ocall_args_t*)input_buffer;
+ oe_syscall_epoll_ctl_ocall_args_t* _pargs_out = (oe_syscall_epoll_ctl_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->event)
+ OE_SET_IN_POINTER(event, 1, sizeof(struct oe_epoll_event), struct oe_epoll_event*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_epoll_ctl_ocall(
+ _pargs_in->epfd,
+ _pargs_in->op,
+ _pargs_in->fd,
+ _pargs_in->event);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_epoll_close_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_epoll_close_ocall_args_t* _pargs_in = (oe_syscall_epoll_close_ocall_args_t*)input_buffer;
+ oe_syscall_epoll_close_ocall_args_t* _pargs_out = (oe_syscall_epoll_close_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_epoll_close_ocall(
+ _pargs_in->epfd);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_open_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_open_ocall_args_t* _pargs_in = (oe_syscall_open_ocall_args_t*)input_buffer;
+ oe_syscall_open_ocall_args_t* _pargs_out = (oe_syscall_open_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->pathname)
+ OE_SET_IN_POINTER(pathname, _pargs_in->pathname_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_open_ocall(
+ (const char*)_pargs_in->pathname,
+ _pargs_in->flags,
+ _pargs_in->mode);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_read_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_read_ocall_args_t* _pargs_in = (oe_syscall_read_ocall_args_t*)input_buffer;
+ oe_syscall_read_ocall_args_t* _pargs_out = (oe_syscall_read_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->buf)
+ OE_SET_OUT_POINTER(buf, 1, _pargs_in->count, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_read_ocall(
+ _pargs_in->fd,
+ _pargs_in->buf,
+ _pargs_in->count);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_write_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_write_ocall_args_t* _pargs_in = (oe_syscall_write_ocall_args_t*)input_buffer;
+ oe_syscall_write_ocall_args_t* _pargs_out = (oe_syscall_write_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->buf)
+ OE_SET_IN_POINTER(buf, 1, _pargs_in->count, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_write_ocall(
+ _pargs_in->fd,
+ (const void*)_pargs_in->buf,
+ _pargs_in->count);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_readv_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_readv_ocall_args_t* _pargs_in = (oe_syscall_readv_ocall_args_t*)input_buffer;
+ oe_syscall_readv_ocall_args_t* _pargs_out = (oe_syscall_readv_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->iov_buf)
+ OE_SET_IN_OUT_POINTER(iov_buf, 1, _pargs_in->iov_buf_size, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->iov_buf)
+ OE_COPY_AND_SET_IN_OUT_POINTER(iov_buf, 1, _pargs_in->iov_buf_size, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_readv_ocall(
+ _pargs_in->fd,
+ _pargs_in->iov_buf,
+ _pargs_in->iovcnt,
+ _pargs_in->iov_buf_size);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_writev_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_writev_ocall_args_t* _pargs_in = (oe_syscall_writev_ocall_args_t*)input_buffer;
+ oe_syscall_writev_ocall_args_t* _pargs_out = (oe_syscall_writev_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->iov_buf)
+ OE_SET_IN_POINTER(iov_buf, 1, _pargs_in->iov_buf_size, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_writev_ocall(
+ _pargs_in->fd,
+ (const void*)_pargs_in->iov_buf,
+ _pargs_in->iovcnt,
+ _pargs_in->iov_buf_size);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_lseek_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_lseek_ocall_args_t* _pargs_in = (oe_syscall_lseek_ocall_args_t*)input_buffer;
+ oe_syscall_lseek_ocall_args_t* _pargs_out = (oe_syscall_lseek_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_lseek_ocall(
+ _pargs_in->fd,
+ _pargs_in->offset,
+ _pargs_in->whence);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_pread_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_pread_ocall_args_t* _pargs_in = (oe_syscall_pread_ocall_args_t*)input_buffer;
+ oe_syscall_pread_ocall_args_t* _pargs_out = (oe_syscall_pread_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->buf)
+ OE_SET_OUT_POINTER(buf, 1, _pargs_in->count, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_pread_ocall(
+ _pargs_in->fd,
+ _pargs_in->buf,
+ _pargs_in->count,
+ _pargs_in->offset);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_pwrite_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_pwrite_ocall_args_t* _pargs_in = (oe_syscall_pwrite_ocall_args_t*)input_buffer;
+ oe_syscall_pwrite_ocall_args_t* _pargs_out = (oe_syscall_pwrite_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->buf)
+ OE_SET_IN_POINTER(buf, 1, _pargs_in->count, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_pwrite_ocall(
+ _pargs_in->fd,
+ (const void*)_pargs_in->buf,
+ _pargs_in->count,
+ _pargs_in->offset);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_close_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_close_ocall_args_t* _pargs_in = (oe_syscall_close_ocall_args_t*)input_buffer;
+ oe_syscall_close_ocall_args_t* _pargs_out = (oe_syscall_close_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_close_ocall(
+ _pargs_in->fd);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_flock_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_flock_ocall_args_t* _pargs_in = (oe_syscall_flock_ocall_args_t*)input_buffer;
+ oe_syscall_flock_ocall_args_t* _pargs_out = (oe_syscall_flock_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_flock_ocall(
+ _pargs_in->fd,
+ _pargs_in->operation);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_fsync_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_fsync_ocall_args_t* _pargs_in = (oe_syscall_fsync_ocall_args_t*)input_buffer;
+ oe_syscall_fsync_ocall_args_t* _pargs_out = (oe_syscall_fsync_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_fsync_ocall(
+ _pargs_in->fd);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_fdatasync_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_fdatasync_ocall_args_t* _pargs_in = (oe_syscall_fdatasync_ocall_args_t*)input_buffer;
+ oe_syscall_fdatasync_ocall_args_t* _pargs_out = (oe_syscall_fdatasync_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_fdatasync_ocall(
+ _pargs_in->fd);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_dup_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_dup_ocall_args_t* _pargs_in = (oe_syscall_dup_ocall_args_t*)input_buffer;
+ oe_syscall_dup_ocall_args_t* _pargs_out = (oe_syscall_dup_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_dup_ocall(
+ _pargs_in->oldfd);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_opendir_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_opendir_ocall_args_t* _pargs_in = (oe_syscall_opendir_ocall_args_t*)input_buffer;
+ oe_syscall_opendir_ocall_args_t* _pargs_out = (oe_syscall_opendir_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->name)
+ OE_SET_IN_POINTER(name, _pargs_in->name_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_opendir_ocall(
+ (const char*)_pargs_in->name);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_readdir_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_readdir_ocall_args_t* _pargs_in = (oe_syscall_readdir_ocall_args_t*)input_buffer;
+ oe_syscall_readdir_ocall_args_t* _pargs_out = (oe_syscall_readdir_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->entry)
+ OE_SET_OUT_POINTER(entry, 1, sizeof(struct oe_dirent), struct oe_dirent*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_readdir_ocall(
+ _pargs_in->dirp,
+ _pargs_in->entry);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_rewinddir_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_rewinddir_ocall_args_t* _pargs_in = (oe_syscall_rewinddir_ocall_args_t*)input_buffer;
+ oe_syscall_rewinddir_ocall_args_t* _pargs_out = (oe_syscall_rewinddir_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ oe_syscall_rewinddir_ocall(
+ _pargs_in->dirp);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_closedir_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_closedir_ocall_args_t* _pargs_in = (oe_syscall_closedir_ocall_args_t*)input_buffer;
+ oe_syscall_closedir_ocall_args_t* _pargs_out = (oe_syscall_closedir_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_closedir_ocall(
+ _pargs_in->dirp);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_stat_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_stat_ocall_args_t* _pargs_in = (oe_syscall_stat_ocall_args_t*)input_buffer;
+ oe_syscall_stat_ocall_args_t* _pargs_out = (oe_syscall_stat_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->pathname)
+ OE_SET_IN_POINTER(pathname, _pargs_in->pathname_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->buf)
+ OE_SET_OUT_POINTER(buf, 1, sizeof(struct oe_stat_t), struct oe_stat_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_stat_ocall(
+ (const char*)_pargs_in->pathname,
+ _pargs_in->buf);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_fstat_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_fstat_ocall_args_t* _pargs_in = (oe_syscall_fstat_ocall_args_t*)input_buffer;
+ oe_syscall_fstat_ocall_args_t* _pargs_out = (oe_syscall_fstat_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->buf)
+ OE_SET_OUT_POINTER(buf, 1, sizeof(struct oe_stat_t), struct oe_stat_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_fstat_ocall(
+ _pargs_in->fd,
+ _pargs_in->buf);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_access_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_access_ocall_args_t* _pargs_in = (oe_syscall_access_ocall_args_t*)input_buffer;
+ oe_syscall_access_ocall_args_t* _pargs_out = (oe_syscall_access_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->pathname)
+ OE_SET_IN_POINTER(pathname, _pargs_in->pathname_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_access_ocall(
+ (const char*)_pargs_in->pathname,
+ _pargs_in->mode);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_link_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_link_ocall_args_t* _pargs_in = (oe_syscall_link_ocall_args_t*)input_buffer;
+ oe_syscall_link_ocall_args_t* _pargs_out = (oe_syscall_link_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->oldpath)
+ OE_SET_IN_POINTER(oldpath, _pargs_in->oldpath_len, sizeof(char), char*);
+ if (_pargs_in->newpath)
+ OE_SET_IN_POINTER(newpath, _pargs_in->newpath_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_link_ocall(
+ (const char*)_pargs_in->oldpath,
+ (const char*)_pargs_in->newpath);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_unlink_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_unlink_ocall_args_t* _pargs_in = (oe_syscall_unlink_ocall_args_t*)input_buffer;
+ oe_syscall_unlink_ocall_args_t* _pargs_out = (oe_syscall_unlink_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->pathname)
+ OE_SET_IN_POINTER(pathname, _pargs_in->pathname_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_unlink_ocall(
+ (const char*)_pargs_in->pathname);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_rename_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_rename_ocall_args_t* _pargs_in = (oe_syscall_rename_ocall_args_t*)input_buffer;
+ oe_syscall_rename_ocall_args_t* _pargs_out = (oe_syscall_rename_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->oldpath)
+ OE_SET_IN_POINTER(oldpath, _pargs_in->oldpath_len, sizeof(char), char*);
+ if (_pargs_in->newpath)
+ OE_SET_IN_POINTER(newpath, _pargs_in->newpath_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_rename_ocall(
+ (const char*)_pargs_in->oldpath,
+ (const char*)_pargs_in->newpath);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_truncate_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_truncate_ocall_args_t* _pargs_in = (oe_syscall_truncate_ocall_args_t*)input_buffer;
+ oe_syscall_truncate_ocall_args_t* _pargs_out = (oe_syscall_truncate_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->path)
+ OE_SET_IN_POINTER(path, _pargs_in->path_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_truncate_ocall(
+ (const char*)_pargs_in->path,
+ _pargs_in->length);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_ftruncate_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_ftruncate_ocall_args_t* _pargs_in = (oe_syscall_ftruncate_ocall_args_t*)input_buffer;
+ oe_syscall_ftruncate_ocall_args_t* _pargs_out = (oe_syscall_ftruncate_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_ftruncate_ocall(
+ _pargs_in->fd,
+ _pargs_in->length);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_mkdir_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_mkdir_ocall_args_t* _pargs_in = (oe_syscall_mkdir_ocall_args_t*)input_buffer;
+ oe_syscall_mkdir_ocall_args_t* _pargs_out = (oe_syscall_mkdir_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->pathname)
+ OE_SET_IN_POINTER(pathname, _pargs_in->pathname_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_mkdir_ocall(
+ (const char*)_pargs_in->pathname,
+ _pargs_in->mode);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_rmdir_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_rmdir_ocall_args_t* _pargs_in = (oe_syscall_rmdir_ocall_args_t*)input_buffer;
+ oe_syscall_rmdir_ocall_args_t* _pargs_out = (oe_syscall_rmdir_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->pathname)
+ OE_SET_IN_POINTER(pathname, _pargs_in->pathname_len, sizeof(char), char*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_rmdir_ocall(
+ (const char*)_pargs_in->pathname);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_fcntl_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_fcntl_ocall_args_t* _pargs_in = (oe_syscall_fcntl_ocall_args_t*)input_buffer;
+ oe_syscall_fcntl_ocall_args_t* _pargs_out = (oe_syscall_fcntl_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->argout)
+ OE_SET_IN_OUT_POINTER(argout, 1, _pargs_in->argsize, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->argout)
+ OE_COPY_AND_SET_IN_OUT_POINTER(argout, 1, _pargs_in->argsize, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_fcntl_ocall(
+ _pargs_in->fd,
+ _pargs_in->cmd,
+ _pargs_in->arg,
+ _pargs_in->argsize,
+ _pargs_in->argout);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_ioctl_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_ioctl_ocall_args_t* _pargs_in = (oe_syscall_ioctl_ocall_args_t*)input_buffer;
+ oe_syscall_ioctl_ocall_args_t* _pargs_out = (oe_syscall_ioctl_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->argout)
+ OE_SET_IN_OUT_POINTER(argout, 1, _pargs_in->argsize, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->argout)
+ OE_COPY_AND_SET_IN_OUT_POINTER(argout, 1, _pargs_in->argsize, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_ioctl_ocall(
+ _pargs_in->fd,
+ _pargs_in->request,
+ _pargs_in->arg,
+ _pargs_in->argsize,
+ _pargs_in->argout);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_poll_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_poll_ocall_args_t* _pargs_in = (oe_syscall_poll_ocall_args_t*)input_buffer;
+ oe_syscall_poll_ocall_args_t* _pargs_out = (oe_syscall_poll_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->host_fds)
+ OE_SET_IN_OUT_POINTER(host_fds, _pargs_in->nfds, sizeof(struct oe_host_pollfd), struct oe_host_pollfd*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->host_fds)
+ OE_COPY_AND_SET_IN_OUT_POINTER(host_fds, _pargs_in->nfds, sizeof(struct oe_host_pollfd), struct oe_host_pollfd*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_poll_ocall(
+ _pargs_in->host_fds,
+ _pargs_in->nfds,
+ _pargs_in->timeout);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_kill_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_kill_ocall_args_t* _pargs_in = (oe_syscall_kill_ocall_args_t*)input_buffer;
+ oe_syscall_kill_ocall_args_t* _pargs_out = (oe_syscall_kill_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_kill_ocall(
+ _pargs_in->pid,
+ _pargs_in->signum);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_close_socket_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_close_socket_ocall_args_t* _pargs_in = (oe_syscall_close_socket_ocall_args_t*)input_buffer;
+ oe_syscall_close_socket_ocall_args_t* _pargs_out = (oe_syscall_close_socket_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_close_socket_ocall(
+ _pargs_in->sockfd);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_socket_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_socket_ocall_args_t* _pargs_in = (oe_syscall_socket_ocall_args_t*)input_buffer;
+ oe_syscall_socket_ocall_args_t* _pargs_out = (oe_syscall_socket_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_socket_ocall(
+ _pargs_in->domain,
+ _pargs_in->type,
+ _pargs_in->protocol);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_shutdown_sockets_device_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_shutdown_sockets_device_ocall_args_t* _pargs_in = (oe_syscall_shutdown_sockets_device_ocall_args_t*)input_buffer;
+ oe_syscall_shutdown_sockets_device_ocall_args_t* _pargs_out = (oe_syscall_shutdown_sockets_device_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_shutdown_sockets_device_ocall(
+ _pargs_in->sockfd);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_socketpair_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_socketpair_ocall_args_t* _pargs_in = (oe_syscall_socketpair_ocall_args_t*)input_buffer;
+ oe_syscall_socketpair_ocall_args_t* _pargs_out = (oe_syscall_socketpair_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->sv)
+ OE_SET_OUT_POINTER(sv, 1, sizeof(oe_host_fd_t[2]), oe_host_fd_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_socketpair_ocall(
+ _pargs_in->domain,
+ _pargs_in->type,
+ _pargs_in->protocol,
+ *(oe_host_fd_t(*)[2])_pargs_in->sv);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_connect_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_connect_ocall_args_t* _pargs_in = (oe_syscall_connect_ocall_args_t*)input_buffer;
+ oe_syscall_connect_ocall_args_t* _pargs_out = (oe_syscall_connect_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->addr)
+ OE_SET_IN_POINTER(addr, 1, _pargs_in->addrlen, struct oe_sockaddr*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_connect_ocall(
+ _pargs_in->sockfd,
+ (const struct oe_sockaddr*)_pargs_in->addr,
+ _pargs_in->addrlen);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_accept_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_accept_ocall_args_t* _pargs_in = (oe_syscall_accept_ocall_args_t*)input_buffer;
+ oe_syscall_accept_ocall_args_t* _pargs_out = (oe_syscall_accept_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->addr)
+ OE_SET_OUT_POINTER(addr, 1, _pargs_in->addrlen_in, struct oe_sockaddr*);
+ if (_pargs_in->addrlen_out)
+ OE_SET_OUT_POINTER(addrlen_out, 1, sizeof(oe_socklen_t), oe_socklen_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_accept_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->addr,
+ _pargs_in->addrlen_in,
+ _pargs_in->addrlen_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_bind_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_bind_ocall_args_t* _pargs_in = (oe_syscall_bind_ocall_args_t*)input_buffer;
+ oe_syscall_bind_ocall_args_t* _pargs_out = (oe_syscall_bind_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->addr)
+ OE_SET_IN_POINTER(addr, 1, _pargs_in->addrlen, struct oe_sockaddr*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_bind_ocall(
+ _pargs_in->sockfd,
+ (const struct oe_sockaddr*)_pargs_in->addr,
+ _pargs_in->addrlen);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_listen_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_listen_ocall_args_t* _pargs_in = (oe_syscall_listen_ocall_args_t*)input_buffer;
+ oe_syscall_listen_ocall_args_t* _pargs_out = (oe_syscall_listen_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_listen_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->backlog);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_recvmsg_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_recvmsg_ocall_args_t* _pargs_in = (oe_syscall_recvmsg_ocall_args_t*)input_buffer;
+ oe_syscall_recvmsg_ocall_args_t* _pargs_out = (oe_syscall_recvmsg_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->msg_iov_buf)
+ OE_SET_IN_OUT_POINTER(msg_iov_buf, 1, _pargs_in->msg_iov_buf_size, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->msg_name)
+ OE_SET_OUT_POINTER(msg_name, 1, _pargs_in->msg_namelen, void*);
+ if (_pargs_in->msg_namelen_out)
+ OE_SET_OUT_POINTER(msg_namelen_out, 1, sizeof(oe_socklen_t), oe_socklen_t*);
+ if (_pargs_in->msg_iov_buf)
+ OE_COPY_AND_SET_IN_OUT_POINTER(msg_iov_buf, 1, _pargs_in->msg_iov_buf_size, void*);
+ if (_pargs_in->msg_control)
+ OE_SET_OUT_POINTER(msg_control, 1, _pargs_in->msg_controllen, void*);
+ if (_pargs_in->msg_controllen_out)
+ OE_SET_OUT_POINTER(msg_controllen_out, 1, sizeof(size_t), size_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_recvmsg_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->msg_name,
+ _pargs_in->msg_namelen,
+ _pargs_in->msg_namelen_out,
+ _pargs_in->msg_iov_buf,
+ _pargs_in->msg_iovlen,
+ _pargs_in->msg_iov_buf_size,
+ _pargs_in->msg_control,
+ _pargs_in->msg_controllen,
+ _pargs_in->msg_controllen_out,
+ _pargs_in->flags);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_sendmsg_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_sendmsg_ocall_args_t* _pargs_in = (oe_syscall_sendmsg_ocall_args_t*)input_buffer;
+ oe_syscall_sendmsg_ocall_args_t* _pargs_out = (oe_syscall_sendmsg_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->msg_name)
+ OE_SET_IN_POINTER(msg_name, 1, _pargs_in->msg_namelen, void*);
+ if (_pargs_in->msg_iov_buf)
+ OE_SET_IN_POINTER(msg_iov_buf, 1, _pargs_in->msg_iov_buf_size, void*);
+ if (_pargs_in->msg_control)
+ OE_SET_IN_POINTER(msg_control, 1, _pargs_in->msg_controllen, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_sendmsg_ocall(
+ _pargs_in->sockfd,
+ (const void*)_pargs_in->msg_name,
+ _pargs_in->msg_namelen,
+ _pargs_in->msg_iov_buf,
+ _pargs_in->msg_iovlen,
+ _pargs_in->msg_iov_buf_size,
+ (const void*)_pargs_in->msg_control,
+ _pargs_in->msg_controllen,
+ _pargs_in->flags);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_recv_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_recv_ocall_args_t* _pargs_in = (oe_syscall_recv_ocall_args_t*)input_buffer;
+ oe_syscall_recv_ocall_args_t* _pargs_out = (oe_syscall_recv_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->buf)
+ OE_SET_OUT_POINTER(buf, 1, _pargs_in->len, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_recv_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->buf,
+ _pargs_in->len,
+ _pargs_in->flags);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_recvfrom_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_recvfrom_ocall_args_t* _pargs_in = (oe_syscall_recvfrom_ocall_args_t*)input_buffer;
+ oe_syscall_recvfrom_ocall_args_t* _pargs_out = (oe_syscall_recvfrom_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->buf)
+ OE_SET_OUT_POINTER(buf, 1, _pargs_in->len, void*);
+ if (_pargs_in->src_addr)
+ OE_SET_OUT_POINTER(src_addr, 1, _pargs_in->addrlen_in, struct oe_sockaddr*);
+ if (_pargs_in->addrlen_out)
+ OE_SET_OUT_POINTER(addrlen_out, 1, sizeof(oe_socklen_t), oe_socklen_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_recvfrom_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->buf,
+ _pargs_in->len,
+ _pargs_in->flags,
+ _pargs_in->src_addr,
+ _pargs_in->addrlen_in,
+ _pargs_in->addrlen_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_send_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_send_ocall_args_t* _pargs_in = (oe_syscall_send_ocall_args_t*)input_buffer;
+ oe_syscall_send_ocall_args_t* _pargs_out = (oe_syscall_send_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->buf)
+ OE_SET_IN_POINTER(buf, 1, _pargs_in->len, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_send_ocall(
+ _pargs_in->sockfd,
+ (const void*)_pargs_in->buf,
+ _pargs_in->len,
+ _pargs_in->flags);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_sendto_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_sendto_ocall_args_t* _pargs_in = (oe_syscall_sendto_ocall_args_t*)input_buffer;
+ oe_syscall_sendto_ocall_args_t* _pargs_out = (oe_syscall_sendto_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->buf)
+ OE_SET_IN_POINTER(buf, 1, _pargs_in->len, void*);
+ if (_pargs_in->dest_addr)
+ OE_SET_IN_POINTER(dest_addr, 1, _pargs_in->addrlen, struct oe_sockaddr*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_sendto_ocall(
+ _pargs_in->sockfd,
+ (const void*)_pargs_in->buf,
+ _pargs_in->len,
+ _pargs_in->flags,
+ (const struct oe_sockaddr*)_pargs_in->dest_addr,
+ _pargs_in->addrlen);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_recvv_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_recvv_ocall_args_t* _pargs_in = (oe_syscall_recvv_ocall_args_t*)input_buffer;
+ oe_syscall_recvv_ocall_args_t* _pargs_out = (oe_syscall_recvv_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->iov_buf)
+ OE_SET_IN_OUT_POINTER(iov_buf, 1, _pargs_in->iov_buf_size, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->iov_buf)
+ OE_COPY_AND_SET_IN_OUT_POINTER(iov_buf, 1, _pargs_in->iov_buf_size, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_recvv_ocall(
+ _pargs_in->fd,
+ _pargs_in->iov_buf,
+ _pargs_in->iovcnt,
+ _pargs_in->iov_buf_size);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_sendv_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_sendv_ocall_args_t* _pargs_in = (oe_syscall_sendv_ocall_args_t*)input_buffer;
+ oe_syscall_sendv_ocall_args_t* _pargs_out = (oe_syscall_sendv_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->iov_buf)
+ OE_SET_IN_POINTER(iov_buf, 1, _pargs_in->iov_buf_size, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_sendv_ocall(
+ _pargs_in->fd,
+ (const void*)_pargs_in->iov_buf,
+ _pargs_in->iovcnt,
+ _pargs_in->iov_buf_size);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_shutdown_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_shutdown_ocall_args_t* _pargs_in = (oe_syscall_shutdown_ocall_args_t*)input_buffer;
+ oe_syscall_shutdown_ocall_args_t* _pargs_out = (oe_syscall_shutdown_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_shutdown_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->how);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_setsockopt_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_setsockopt_ocall_args_t* _pargs_in = (oe_syscall_setsockopt_ocall_args_t*)input_buffer;
+ oe_syscall_setsockopt_ocall_args_t* _pargs_out = (oe_syscall_setsockopt_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->optval)
+ OE_SET_IN_POINTER(optval, 1, _pargs_in->optlen, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_setsockopt_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->level,
+ _pargs_in->optname,
+ (const void*)_pargs_in->optval,
+ _pargs_in->optlen);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getsockopt_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getsockopt_ocall_args_t* _pargs_in = (oe_syscall_getsockopt_ocall_args_t*)input_buffer;
+ oe_syscall_getsockopt_ocall_args_t* _pargs_out = (oe_syscall_getsockopt_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->optval)
+ OE_SET_OUT_POINTER(optval, 1, _pargs_in->optlen_in, void*);
+ if (_pargs_in->optlen_out)
+ OE_SET_OUT_POINTER(optlen_out, 1, sizeof(oe_socklen_t), oe_socklen_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getsockopt_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->level,
+ _pargs_in->optname,
+ _pargs_in->optval,
+ _pargs_in->optlen_in,
+ _pargs_in->optlen_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getsockname_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getsockname_ocall_args_t* _pargs_in = (oe_syscall_getsockname_ocall_args_t*)input_buffer;
+ oe_syscall_getsockname_ocall_args_t* _pargs_out = (oe_syscall_getsockname_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->addr)
+ OE_SET_OUT_POINTER(addr, 1, _pargs_in->addrlen_in, struct oe_sockaddr*);
+ if (_pargs_in->addrlen_out)
+ OE_SET_OUT_POINTER(addrlen_out, 1, 1, oe_socklen_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getsockname_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->addr,
+ _pargs_in->addrlen_in,
+ _pargs_in->addrlen_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getpeername_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getpeername_ocall_args_t* _pargs_in = (oe_syscall_getpeername_ocall_args_t*)input_buffer;
+ oe_syscall_getpeername_ocall_args_t* _pargs_out = (oe_syscall_getpeername_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->addr)
+ OE_SET_OUT_POINTER(addr, 1, _pargs_in->addrlen_in, struct oe_sockaddr*);
+ if (_pargs_in->addrlen_out)
+ OE_SET_OUT_POINTER(addrlen_out, 1, 1, oe_socklen_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getpeername_ocall(
+ _pargs_in->sockfd,
+ _pargs_in->addr,
+ _pargs_in->addrlen_in,
+ _pargs_in->addrlen_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getaddrinfo_open_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getaddrinfo_open_ocall_args_t* _pargs_in = (oe_syscall_getaddrinfo_open_ocall_args_t*)input_buffer;
+ oe_syscall_getaddrinfo_open_ocall_args_t* _pargs_out = (oe_syscall_getaddrinfo_open_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->node)
+ OE_SET_IN_POINTER(node, _pargs_in->node_len, sizeof(char), char*);
+ if (_pargs_in->service)
+ OE_SET_IN_POINTER(service, _pargs_in->service_len, sizeof(char), char*);
+ if (_pargs_in->hints)
+ OE_SET_IN_POINTER(hints, 1, sizeof(struct oe_addrinfo), struct oe_addrinfo*);
+ if (_pargs_in->hints && _pargs_in->hints->ai_addr)
+ OE_SET_IN_POINTER(hints->ai_addr, 1, _pargs_in->hints->ai_addrlen, struct oe_sockaddr*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->handle)
+ OE_SET_OUT_POINTER(handle, 1, sizeof(uint64_t), uint64_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getaddrinfo_open_ocall(
+ (const char*)_pargs_in->node,
+ (const char*)_pargs_in->service,
+ (const struct oe_addrinfo*)_pargs_in->hints,
+ _pargs_in->handle);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getaddrinfo_read_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getaddrinfo_read_ocall_args_t* _pargs_in = (oe_syscall_getaddrinfo_read_ocall_args_t*)input_buffer;
+ oe_syscall_getaddrinfo_read_ocall_args_t* _pargs_out = (oe_syscall_getaddrinfo_read_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->ai_flags)
+ OE_SET_OUT_POINTER(ai_flags, 1, sizeof(int), int*);
+ if (_pargs_in->ai_family)
+ OE_SET_OUT_POINTER(ai_family, 1, sizeof(int), int*);
+ if (_pargs_in->ai_socktype)
+ OE_SET_OUT_POINTER(ai_socktype, 1, sizeof(int), int*);
+ if (_pargs_in->ai_protocol)
+ OE_SET_OUT_POINTER(ai_protocol, 1, sizeof(int), int*);
+ if (_pargs_in->ai_addrlen)
+ OE_SET_OUT_POINTER(ai_addrlen, 1, sizeof(oe_socklen_t), oe_socklen_t*);
+ if (_pargs_in->ai_addr)
+ OE_SET_OUT_POINTER(ai_addr, 1, _pargs_in->ai_addrlen_in, struct oe_sockaddr*);
+ if (_pargs_in->ai_canonnamelen)
+ OE_SET_OUT_POINTER(ai_canonnamelen, 1, sizeof(size_t), size_t*);
+ if (_pargs_in->ai_canonname)
+ OE_SET_OUT_POINTER(ai_canonname, 1, _pargs_in->ai_canonnamelen_in, char*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getaddrinfo_read_ocall(
+ _pargs_in->handle,
+ _pargs_in->ai_flags,
+ _pargs_in->ai_family,
+ _pargs_in->ai_socktype,
+ _pargs_in->ai_protocol,
+ _pargs_in->ai_addrlen_in,
+ _pargs_in->ai_addrlen,
+ _pargs_in->ai_addr,
+ _pargs_in->ai_canonnamelen_in,
+ _pargs_in->ai_canonnamelen,
+ _pargs_in->ai_canonname);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getaddrinfo_close_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getaddrinfo_close_ocall_args_t* _pargs_in = (oe_syscall_getaddrinfo_close_ocall_args_t*)input_buffer;
+ oe_syscall_getaddrinfo_close_ocall_args_t* _pargs_out = (oe_syscall_getaddrinfo_close_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getaddrinfo_close_ocall(
+ _pargs_in->handle);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getnameinfo_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getnameinfo_ocall_args_t* _pargs_in = (oe_syscall_getnameinfo_ocall_args_t*)input_buffer;
+ oe_syscall_getnameinfo_ocall_args_t* _pargs_out = (oe_syscall_getnameinfo_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->sa)
+ OE_SET_IN_POINTER(sa, 1, _pargs_in->salen, struct oe_sockaddr*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->host)
+ OE_SET_OUT_POINTER(host, 1, _pargs_in->hostlen, char*);
+ if (_pargs_in->serv)
+ OE_SET_OUT_POINTER(serv, 1, _pargs_in->servlen, char*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getnameinfo_ocall(
+ (const struct oe_sockaddr*)_pargs_in->sa,
+ _pargs_in->salen,
+ _pargs_in->host,
+ _pargs_in->hostlen,
+ _pargs_in->serv,
+ _pargs_in->servlen,
+ _pargs_in->flags);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_nanosleep_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_nanosleep_ocall_args_t* _pargs_in = (oe_syscall_nanosleep_ocall_args_t*)input_buffer;
+ oe_syscall_nanosleep_ocall_args_t* _pargs_out = (oe_syscall_nanosleep_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->req)
+ OE_SET_IN_POINTER(req, 1, sizeof(struct oe_timespec), struct oe_timespec*);
+ if (_pargs_in->rem)
+ OE_SET_IN_OUT_POINTER(rem, 1, sizeof(struct oe_timespec), struct oe_timespec*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->rem)
+ OE_COPY_AND_SET_IN_OUT_POINTER(rem, 1, sizeof(struct oe_timespec), struct oe_timespec*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_nanosleep_ocall(
+ _pargs_in->req,
+ _pargs_in->rem);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_clock_nanosleep_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_clock_nanosleep_ocall_args_t* _pargs_in = (oe_syscall_clock_nanosleep_ocall_args_t*)input_buffer;
+ oe_syscall_clock_nanosleep_ocall_args_t* _pargs_out = (oe_syscall_clock_nanosleep_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->req)
+ OE_SET_IN_POINTER(req, 1, sizeof(struct oe_timespec), struct oe_timespec*);
+ if (_pargs_in->rem)
+ OE_SET_IN_OUT_POINTER(rem, 1, sizeof(struct oe_timespec), struct oe_timespec*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->rem)
+ OE_COPY_AND_SET_IN_OUT_POINTER(rem, 1, sizeof(struct oe_timespec), struct oe_timespec*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_clock_nanosleep_ocall(
+ _pargs_in->clockid,
+ _pargs_in->flag,
+ _pargs_in->req,
+ _pargs_in->rem);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getpid_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getpid_ocall_args_t* _pargs_in = (oe_syscall_getpid_ocall_args_t*)input_buffer;
+ oe_syscall_getpid_ocall_args_t* _pargs_out = (oe_syscall_getpid_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getpid_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getppid_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getppid_ocall_args_t* _pargs_in = (oe_syscall_getppid_ocall_args_t*)input_buffer;
+ oe_syscall_getppid_ocall_args_t* _pargs_out = (oe_syscall_getppid_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getppid_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getpgrp_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getpgrp_ocall_args_t* _pargs_in = (oe_syscall_getpgrp_ocall_args_t*)input_buffer;
+ oe_syscall_getpgrp_ocall_args_t* _pargs_out = (oe_syscall_getpgrp_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getpgrp_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getuid_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getuid_ocall_args_t* _pargs_in = (oe_syscall_getuid_ocall_args_t*)input_buffer;
+ oe_syscall_getuid_ocall_args_t* _pargs_out = (oe_syscall_getuid_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getuid_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_geteuid_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_geteuid_ocall_args_t* _pargs_in = (oe_syscall_geteuid_ocall_args_t*)input_buffer;
+ oe_syscall_geteuid_ocall_args_t* _pargs_out = (oe_syscall_geteuid_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_geteuid_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getgid_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getgid_ocall_args_t* _pargs_in = (oe_syscall_getgid_ocall_args_t*)input_buffer;
+ oe_syscall_getgid_ocall_args_t* _pargs_out = (oe_syscall_getgid_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getgid_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getegid_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getegid_ocall_args_t* _pargs_in = (oe_syscall_getegid_ocall_args_t*)input_buffer;
+ oe_syscall_getegid_ocall_args_t* _pargs_out = (oe_syscall_getegid_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getegid_ocall(
+ );
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getpgid_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getpgid_ocall_args_t* _pargs_in = (oe_syscall_getpgid_ocall_args_t*)input_buffer;
+ oe_syscall_getpgid_ocall_args_t* _pargs_out = (oe_syscall_getpgid_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getpgid_ocall(
+ _pargs_in->pid);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_getgroups_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_getgroups_ocall_args_t* _pargs_in = (oe_syscall_getgroups_ocall_args_t*)input_buffer;
+ oe_syscall_getgroups_ocall_args_t* _pargs_out = (oe_syscall_getgroups_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->list)
+ OE_SET_OUT_POINTER(list, _pargs_in->size, sizeof(unsigned int), unsigned int*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_getgroups_ocall(
+ _pargs_in->size,
+ _pargs_in->list);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_syscall_uname_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_syscall_uname_ocall_args_t* _pargs_in = (oe_syscall_uname_ocall_args_t*)input_buffer;
+ oe_syscall_uname_ocall_args_t* _pargs_out = (oe_syscall_uname_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->buf)
+ OE_SET_OUT_POINTER(buf, 1, sizeof(struct oe_utsname), struct oe_utsname*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_syscall_uname_ocall(
+ _pargs_in->buf);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ _pargs_out->ocall_errno = errno;
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_get_supported_attester_format_ids_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_get_supported_attester_format_ids_ocall_args_t* _pargs_in = (oe_get_supported_attester_format_ids_ocall_args_t*)input_buffer;
+ oe_get_supported_attester_format_ids_ocall_args_t* _pargs_out = (oe_get_supported_attester_format_ids_ocall_args_t*)output_buffer;
+
+ uint8_t* _deepcopy_out_buffer = NULL;
+ size_t _deepcopy_out_buffer_offset = 0;
+ size_t _deepcopy_out_buffer_size = 0;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->format_ids)
+ OE_SET_OUT_POINTER(format_ids, 1, sizeof(format_ids_t), format_ids_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_get_supported_attester_format_ids_ocall(
+ _pargs_in->format_ids);
+
+ /* Compute the size for the deep-copy out buffer. */
+ if (_pargs_in->format_ids && _pargs_in->format_ids->data)
+ OE_ADD_ARG_SIZE(_deepcopy_out_buffer_size, 1, _pargs_in->format_ids->size);
+
+ if (_deepcopy_out_buffer_size)
+ {
+ _deepcopy_out_buffer = (uint8_t*) oe_malloc(_deepcopy_out_buffer_size);
+ if (!_deepcopy_out_buffer)
+ {
+ _result = OE_OUT_OF_MEMORY;
+ goto done;
+ }
+ }
+
+ /* Serialize the deep-copied content into the buffer. */
+ if (_pargs_in->format_ids && _pargs_in->format_ids->data)
+ OE_WRITE_DEEPCOPY_OUT_PARAM(_pargs_in->format_ids->data, 1, _pargs_in->format_ids->size);
+
+ if (_deepcopy_out_buffer_offset != _deepcopy_out_buffer_size)
+ {
+ _result = OE_FAILURE;
+ goto done;
+ }
+
+ /* Set the _deepcopy_out_buffer and _deepcopy_out_buffer as part of _pargs_out. */
+ _pargs_out->deepcopy_out_buffer = _deepcopy_out_buffer;
+ _pargs_out->deepcopy_out_buffer_size = _deepcopy_out_buffer_size;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ /* Free _pargs_out->deepcopy_out_buffer on failure. */
+ if (_result != OE_OK)
+ {
+ oe_free(_pargs_out->deepcopy_out_buffer);
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+ }
+
+ /* Free nested buffers allocated by the user function. */
+ if (_pargs_in->format_ids)
+ {
+ for (size_t _i_1 = 0; _i_1 < 1; _i_1++)
+ {
+ free(_pargs_in->format_ids[_i_1].data);
+ }
+ }
+
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_get_qetarget_info_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_get_qetarget_info_ocall_args_t* _pargs_in = (oe_get_qetarget_info_ocall_args_t*)input_buffer;
+ oe_get_qetarget_info_ocall_args_t* _pargs_out = (oe_get_qetarget_info_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->format_id)
+ OE_SET_IN_POINTER(format_id, 1, sizeof(oe_uuid_t), oe_uuid_t*);
+ if (_pargs_in->opt_params)
+ OE_SET_IN_POINTER(opt_params, 1, _pargs_in->opt_params_size, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->target_info)
+ OE_SET_OUT_POINTER(target_info, 1, sizeof(sgx_target_info_t), sgx_target_info_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_get_qetarget_info_ocall(
+ (const oe_uuid_t*)_pargs_in->format_id,
+ (const void*)_pargs_in->opt_params,
+ _pargs_in->opt_params_size,
+ _pargs_in->target_info);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_get_quote_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_get_quote_ocall_args_t* _pargs_in = (oe_get_quote_ocall_args_t*)input_buffer;
+ oe_get_quote_ocall_args_t* _pargs_out = (oe_get_quote_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->format_id)
+ OE_SET_IN_POINTER(format_id, 1, sizeof(oe_uuid_t), oe_uuid_t*);
+ if (_pargs_in->opt_params)
+ OE_SET_IN_POINTER(opt_params, 1, _pargs_in->opt_params_size, void*);
+ if (_pargs_in->sgx_report)
+ OE_SET_IN_POINTER(sgx_report, 1, sizeof(sgx_report_t), sgx_report_t*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->quote)
+ OE_SET_OUT_POINTER(quote, 1, _pargs_in->quote_size, void*);
+ if (_pargs_in->quote_size_out)
+ OE_SET_OUT_POINTER(quote_size_out, 1, sizeof(size_t), size_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_get_quote_ocall(
+ (const oe_uuid_t*)_pargs_in->format_id,
+ (const void*)_pargs_in->opt_params,
+ _pargs_in->opt_params_size,
+ (const sgx_report_t*)_pargs_in->sgx_report,
+ _pargs_in->quote,
+ _pargs_in->quote_size,
+ _pargs_in->quote_size_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_get_quote_verification_collateral_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_get_quote_verification_collateral_ocall_args_t* _pargs_in = (oe_get_quote_verification_collateral_ocall_args_t*)input_buffer;
+ oe_get_quote_verification_collateral_ocall_args_t* _pargs_out = (oe_get_quote_verification_collateral_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->fmspc)
+ OE_SET_IN_POINTER(fmspc, 1, sizeof(uint8_t[6]), uint8_t*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->tcb_info)
+ OE_SET_OUT_POINTER(tcb_info, 1, _pargs_in->tcb_info_size, void*);
+ if (_pargs_in->tcb_info_size_out)
+ OE_SET_OUT_POINTER(tcb_info_size_out, 1, sizeof(size_t), size_t*);
+ if (_pargs_in->tcb_info_issuer_chain)
+ OE_SET_OUT_POINTER(tcb_info_issuer_chain, 1, _pargs_in->tcb_info_issuer_chain_size, void*);
+ if (_pargs_in->tcb_info_issuer_chain_size_out)
+ OE_SET_OUT_POINTER(tcb_info_issuer_chain_size_out, 1, sizeof(size_t), size_t*);
+ if (_pargs_in->pck_crl)
+ OE_SET_OUT_POINTER(pck_crl, 1, _pargs_in->pck_crl_size, void*);
+ if (_pargs_in->pck_crl_size_out)
+ OE_SET_OUT_POINTER(pck_crl_size_out, 1, sizeof(size_t), size_t*);
+ if (_pargs_in->root_ca_crl)
+ OE_SET_OUT_POINTER(root_ca_crl, 1, _pargs_in->root_ca_crl_size, void*);
+ if (_pargs_in->root_ca_crl_size_out)
+ OE_SET_OUT_POINTER(root_ca_crl_size_out, 1, sizeof(size_t), size_t*);
+ if (_pargs_in->pck_crl_issuer_chain)
+ OE_SET_OUT_POINTER(pck_crl_issuer_chain, 1, _pargs_in->pck_crl_issuer_chain_size, void*);
+ if (_pargs_in->pck_crl_issuer_chain_size_out)
+ OE_SET_OUT_POINTER(pck_crl_issuer_chain_size_out, 1, sizeof(size_t), size_t*);
+ if (_pargs_in->qe_identity)
+ OE_SET_OUT_POINTER(qe_identity, 1, _pargs_in->qe_identity_size, void*);
+ if (_pargs_in->qe_identity_size_out)
+ OE_SET_OUT_POINTER(qe_identity_size_out, 1, sizeof(size_t), size_t*);
+ if (_pargs_in->qe_identity_issuer_chain)
+ OE_SET_OUT_POINTER(qe_identity_issuer_chain, 1, _pargs_in->qe_identity_issuer_chain_size, void*);
+ if (_pargs_in->qe_identity_issuer_chain_size_out)
+ OE_SET_OUT_POINTER(qe_identity_issuer_chain_size_out, 1, sizeof(size_t), size_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_get_quote_verification_collateral_ocall(
+ *(uint8_t(*)[6])_pargs_in->fmspc,
+ _pargs_in->collateral_provider,
+ _pargs_in->tcb_info,
+ _pargs_in->tcb_info_size,
+ _pargs_in->tcb_info_size_out,
+ _pargs_in->tcb_info_issuer_chain,
+ _pargs_in->tcb_info_issuer_chain_size,
+ _pargs_in->tcb_info_issuer_chain_size_out,
+ _pargs_in->pck_crl,
+ _pargs_in->pck_crl_size,
+ _pargs_in->pck_crl_size_out,
+ _pargs_in->root_ca_crl,
+ _pargs_in->root_ca_crl_size,
+ _pargs_in->root_ca_crl_size_out,
+ _pargs_in->pck_crl_issuer_chain,
+ _pargs_in->pck_crl_issuer_chain_size,
+ _pargs_in->pck_crl_issuer_chain_size_out,
+ _pargs_in->qe_identity,
+ _pargs_in->qe_identity_size,
+ _pargs_in->qe_identity_size_out,
+ _pargs_in->qe_identity_issuer_chain,
+ _pargs_in->qe_identity_issuer_chain_size,
+ _pargs_in->qe_identity_issuer_chain_size_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_verify_quote_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_verify_quote_ocall_args_t* _pargs_in = (oe_verify_quote_ocall_args_t*)input_buffer;
+ oe_verify_quote_ocall_args_t* _pargs_out = (oe_verify_quote_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->format_id)
+ OE_SET_IN_POINTER(format_id, 1, sizeof(oe_uuid_t), oe_uuid_t*);
+ if (_pargs_in->opt_params)
+ OE_SET_IN_POINTER(opt_params, 1, _pargs_in->opt_params_size, void*);
+ if (_pargs_in->p_quote)
+ OE_SET_IN_POINTER(p_quote, 1, _pargs_in->quote_size, void*);
+ if (_pargs_in->p_qve_report_info)
+ OE_SET_IN_OUT_POINTER(p_qve_report_info, 1, _pargs_in->qve_report_info_size, void*);
+ if (_pargs_in->p_tcb_info)
+ OE_SET_IN_POINTER(p_tcb_info, 1, _pargs_in->tcb_info_size, void*);
+ if (_pargs_in->p_tcb_info_issuer_chain)
+ OE_SET_IN_POINTER(p_tcb_info_issuer_chain, 1, _pargs_in->tcb_info_issuer_chain_size, void*);
+ if (_pargs_in->p_pck_crl)
+ OE_SET_IN_POINTER(p_pck_crl, 1, _pargs_in->pck_crl_size, void*);
+ if (_pargs_in->p_root_ca_crl)
+ OE_SET_IN_POINTER(p_root_ca_crl, 1, _pargs_in->root_ca_crl_size, void*);
+ if (_pargs_in->p_pck_crl_issuer_chain)
+ OE_SET_IN_POINTER(p_pck_crl_issuer_chain, 1, _pargs_in->pck_crl_issuer_chain_size, void*);
+ if (_pargs_in->p_qe_identity)
+ OE_SET_IN_POINTER(p_qe_identity, 1, _pargs_in->qe_identity_size, void*);
+ if (_pargs_in->p_qe_identity_issuer_chain)
+ OE_SET_IN_POINTER(p_qe_identity_issuer_chain, 1, _pargs_in->qe_identity_issuer_chain_size, void*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->p_collateral_expiration_status)
+ OE_SET_OUT_POINTER(p_collateral_expiration_status, 1, sizeof(uint32_t), uint32_t*);
+ if (_pargs_in->p_quote_verification_result)
+ OE_SET_OUT_POINTER(p_quote_verification_result, 1, sizeof(uint32_t), uint32_t*);
+ if (_pargs_in->p_qve_report_info)
+ OE_COPY_AND_SET_IN_OUT_POINTER(p_qve_report_info, 1, _pargs_in->qve_report_info_size, void*);
+ if (_pargs_in->p_supplemental_data)
+ OE_SET_OUT_POINTER(p_supplemental_data, 1, _pargs_in->supplemental_data_size, void*);
+ if (_pargs_in->p_supplemental_data_size_out)
+ OE_SET_OUT_POINTER(p_supplemental_data_size_out, 1, sizeof(uint32_t), uint32_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_verify_quote_ocall(
+ (const oe_uuid_t*)_pargs_in->format_id,
+ (const void*)_pargs_in->opt_params,
+ _pargs_in->opt_params_size,
+ (const void*)_pargs_in->p_quote,
+ _pargs_in->quote_size,
+ _pargs_in->expiration_check_date,
+ _pargs_in->p_collateral_expiration_status,
+ _pargs_in->p_quote_verification_result,
+ _pargs_in->p_qve_report_info,
+ _pargs_in->qve_report_info_size,
+ _pargs_in->p_supplemental_data,
+ _pargs_in->supplemental_data_size,
+ _pargs_in->p_supplemental_data_size_out,
+ _pargs_in->collateral_version,
+ (const void*)_pargs_in->p_tcb_info,
+ _pargs_in->tcb_info_size,
+ (const void*)_pargs_in->p_tcb_info_issuer_chain,
+ _pargs_in->tcb_info_issuer_chain_size,
+ (const void*)_pargs_in->p_pck_crl,
+ _pargs_in->pck_crl_size,
+ (const void*)_pargs_in->p_root_ca_crl,
+ _pargs_in->root_ca_crl_size,
+ (const void*)_pargs_in->p_pck_crl_issuer_chain,
+ _pargs_in->pck_crl_issuer_chain_size,
+ (const void*)_pargs_in->p_qe_identity,
+ _pargs_in->qe_identity_size,
+ (const void*)_pargs_in->p_qe_identity_issuer_chain,
+ _pargs_in->qe_identity_issuer_chain_size);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_sgx_get_cpuid_table_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_sgx_get_cpuid_table_ocall_args_t* _pargs_in = (oe_sgx_get_cpuid_table_ocall_args_t*)input_buffer;
+ oe_sgx_get_cpuid_table_ocall_args_t* _pargs_out = (oe_sgx_get_cpuid_table_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->cpuid_table_buffer)
+ OE_SET_OUT_POINTER(cpuid_table_buffer, 1, _pargs_in->cpuid_table_buffer_size, void*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_sgx_get_cpuid_table_ocall(
+ _pargs_in->cpuid_table_buffer,
+ _pargs_in->cpuid_table_buffer_size);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_sgx_backtrace_symbols_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_sgx_backtrace_symbols_ocall_args_t* _pargs_in = (oe_sgx_backtrace_symbols_ocall_args_t*)input_buffer;
+ oe_sgx_backtrace_symbols_ocall_args_t* _pargs_out = (oe_sgx_backtrace_symbols_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ if (_pargs_in->buffer)
+ OE_SET_IN_POINTER(buffer, _pargs_in->size, sizeof(uint64_t), uint64_t*);
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ if (_pargs_in->symbols_buffer)
+ OE_SET_OUT_POINTER(symbols_buffer, 1, _pargs_in->symbols_buffer_size, void*);
+ if (_pargs_in->symbols_buffer_size_out)
+ OE_SET_OUT_POINTER(symbols_buffer_size_out, 1, sizeof(size_t), size_t*);
+
+ /* Call user function. */
+ _pargs_out->oe_retval = oe_sgx_backtrace_symbols_ocall(
+ _pargs_in->oe_enclave,
+ (const uint64_t*)_pargs_in->buffer,
+ _pargs_in->size,
+ _pargs_in->symbols_buffer,
+ _pargs_in->symbols_buffer_size,
+ _pargs_in->symbols_buffer_size_out);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_sgx_thread_wake_wait_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_sgx_thread_wake_wait_ocall_args_t* _pargs_in = (oe_sgx_thread_wake_wait_ocall_args_t*)input_buffer;
+ oe_sgx_thread_wake_wait_ocall_args_t* _pargs_out = (oe_sgx_thread_wake_wait_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ oe_sgx_thread_wake_wait_ocall(
+ _pargs_in->oe_enclave,
+ _pargs_in->waiter_tcs,
+ _pargs_in->self_tcs);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_sgx_wake_switchless_worker_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_sgx_wake_switchless_worker_ocall_args_t* _pargs_in = (oe_sgx_wake_switchless_worker_ocall_args_t*)input_buffer;
+ oe_sgx_wake_switchless_worker_ocall_args_t* _pargs_out = (oe_sgx_wake_switchless_worker_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ oe_sgx_wake_switchless_worker_ocall(
+ _pargs_in->context);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+static void ocall_oe_sgx_sleep_switchless_worker_ocall(
+ uint8_t* input_buffer,
+ size_t input_buffer_size,
+ uint8_t* output_buffer,
+ size_t output_buffer_size,
+ size_t* output_bytes_written)
+{
+ oe_result_t _result = OE_FAILURE;
+ OE_UNUSED(input_buffer_size);
+
+ /* Prepare parameters. */
+ oe_sgx_sleep_switchless_worker_ocall_args_t* _pargs_in = (oe_sgx_sleep_switchless_worker_ocall_args_t*)input_buffer;
+ oe_sgx_sleep_switchless_worker_ocall_args_t* _pargs_out = (oe_sgx_sleep_switchless_worker_ocall_args_t*)output_buffer;
+
+ size_t _input_buffer_offset = 0;
+ size_t _output_buffer_offset = 0;
+ OE_ADD_SIZE(_input_buffer_offset, sizeof(*_pargs_in));
+ OE_ADD_SIZE(_output_buffer_offset, sizeof(*_pargs_out));
+
+ if (input_buffer_size < sizeof(*_pargs_in) || output_buffer_size < sizeof(*_pargs_in))
+ goto done;
+
+ /* Make sure input and output buffers are valid. */
+ if (!input_buffer || !output_buffer) {
+ _result = OE_INVALID_PARAMETER;
+ goto done;
+ }
+
+ /* Set in and in-out pointers. */
+ /* There were no in nor in-out parameters. */
+
+ /* Set out and in-out pointers. */
+ /* In-out parameters are copied to output buffer. */
+ /* There were no out nor in-out parameters. */
+
+ /* Call user function. */
+ oe_sgx_sleep_switchless_worker_ocall(
+ _pargs_in->context);
+
+ /* There is no deep-copyable out parameter. */
+ _pargs_out->deepcopy_out_buffer = NULL;
+ _pargs_out->deepcopy_out_buffer_size = 0;
+
+ /* Propagate errno back to enclave. */
+ /* Errno propagation not enabled. */
+
+ /* Success. */
+ _result = OE_OK;
+ *output_bytes_written = _output_buffer_offset;
+
+done:
+ if (_pargs_out && output_buffer_size >= sizeof(*_pargs_out))
+ _pargs_out->oe_result = _result;
+}
+
+/**** OCALL function table. ****/
+
+static oe_ocall_func_t _sgx_cpp_ocall_function_table[] = {
+ (oe_ocall_func_t) ocall_oe_syscall_epoll_create1_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_epoll_wait_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_epoll_wake_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_epoll_ctl_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_epoll_close_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_open_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_read_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_write_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_readv_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_writev_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_lseek_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_pread_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_pwrite_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_close_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_flock_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_fsync_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_fdatasync_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_dup_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_opendir_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_readdir_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_rewinddir_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_closedir_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_stat_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_fstat_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_access_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_link_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_unlink_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_rename_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_truncate_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_ftruncate_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_mkdir_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_rmdir_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_fcntl_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_ioctl_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_poll_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_kill_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_close_socket_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_socket_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_shutdown_sockets_device_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_socketpair_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_connect_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_accept_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_bind_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_listen_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_recvmsg_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_sendmsg_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_recv_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_recvfrom_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_send_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_sendto_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_recvv_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_sendv_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_shutdown_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_setsockopt_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getsockopt_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getsockname_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getpeername_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getaddrinfo_open_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getaddrinfo_read_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getaddrinfo_close_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getnameinfo_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_nanosleep_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_clock_nanosleep_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getpid_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getppid_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getpgrp_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getuid_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_geteuid_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getgid_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getegid_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getpgid_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_getgroups_ocall,
+ (oe_ocall_func_t) ocall_oe_syscall_uname_ocall,
+ (oe_ocall_func_t) ocall_oe_get_supported_attester_format_ids_ocall,
+ (oe_ocall_func_t) ocall_oe_get_qetarget_info_ocall,
+ (oe_ocall_func_t) ocall_oe_get_quote_ocall,
+ (oe_ocall_func_t) ocall_oe_get_quote_verification_collateral_ocall,
+ (oe_ocall_func_t) ocall_oe_verify_quote_ocall,
+ (oe_ocall_func_t) ocall_oe_sgx_get_cpuid_table_ocall,
+ (oe_ocall_func_t) ocall_oe_sgx_backtrace_symbols_ocall,
+ (oe_ocall_func_t) ocall_oe_sgx_thread_wake_wait_ocall,
+ (oe_ocall_func_t) ocall_oe_sgx_wake_switchless_worker_ocall,
+ (oe_ocall_func_t) ocall_oe_sgx_sleep_switchless_worker_ocall,
+ NULL
+};
+
+oe_result_t oe_create_sgx_cpp_enclave(
+ const char* path,
+ oe_enclave_type_t type,
+ uint32_t flags,
+ const oe_enclave_setting_t* settings,
+ uint32_t setting_count,
+ oe_enclave_t** enclave)
+{
+ return oe_create_enclave(
+ path,
+ type,
+ flags,
+ settings,
+ setting_count,
+ _sgx_cpp_ocall_function_table,
+ 83,
+ _sgx_cpp_ecall_info_table,
+ 15,
+ enclave);
+}
+
+OE_EXTERNC_END
diff --git a/enclave/sgx_cpp_u.h b/enclave/sgx_cpp_u.h
new file mode 100644
index 000000000..9f001874e
--- /dev/null
+++ b/enclave/sgx_cpp_u.h
@@ -0,0 +1,559 @@
+/*
+ * This file is auto generated by oeedger8r. DO NOT EDIT.
+ */
+#ifndef EDGER8R_SGX_CPP_U_H
+#define EDGER8R_SGX_CPP_U_H
+
+#include
+
+#include "sgx_cpp_args.h"
+
+OE_EXTERNC_BEGIN
+
+oe_result_t oe_create_sgx_cpp_enclave(
+ const char* path,
+ oe_enclave_type_t type,
+ uint32_t flags,
+ const oe_enclave_setting_t* settings,
+ uint32_t setting_count,
+ oe_enclave_t** enclave);
+
+/**** ECALL prototypes. ****/
+oe_result_t request_counter(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* index);
+
+oe_result_t get_counter(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* index,
+ size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t* buffer_size_array,
+ unsigned char** previous_attestation,
+ uint32_t* counter_value);
+
+oe_result_t reset_prng(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* seed,
+ uint32_t* range);
+
+oe_result_t generate_rdrand(
+ oe_enclave_t* enclave,
+ int* _retval,
+ uint32_t* rdrandNum);
+
+oe_result_t generate_rand(
+ oe_enclave_t* enclave,
+ int* _retval,
+ size_t input_len,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t* buffer_size_array,
+ unsigned char** previous_attestation,
+ uint32_t* randNum);
+
+oe_result_t generate_key(
+ oe_enclave_t* enclave,
+ int* _retval,
+ size_t* key_size);
+
+oe_result_t update_key(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char* priv_key,
+ size_t priv_len,
+ unsigned char* pub_key,
+ size_t pub_len);
+
+oe_result_t get_pubkey(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char** key_buf,
+ size_t* key_len);
+
+oe_result_t encrypt(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len);
+
+oe_result_t decrypt(
+ oe_enclave_t* enclave,
+ int* _retval,
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len);
+
+oe_result_t oe_get_sgx_report_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ const void* opt_params,
+ size_t opt_params_size,
+ sgx_report_t* report);
+
+oe_result_t oe_get_report_v2_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ uint32_t flags,
+ const void* opt_params,
+ size_t opt_params_size,
+ uint8_t** report_buffer,
+ size_t* report_buffer_size);
+
+oe_result_t oe_verify_local_report_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ const uint8_t* report,
+ size_t report_size,
+ oe_report_t* parsed_report);
+
+oe_result_t oe_sgx_init_context_switchless_ecall(
+ oe_enclave_t* enclave,
+ oe_result_t* _retval,
+ oe_host_worker_context_t* host_worker_contexts,
+ uint64_t num_host_workers);
+
+oe_result_t oe_sgx_switchless_enclave_worker_thread_ecall(
+ oe_enclave_t* enclave,
+ oe_enclave_worker_context_t* context);
+
+/**** OCALL prototypes. ****/
+oe_host_fd_t oe_syscall_epoll_create1_ocall(int flags);
+
+int oe_syscall_epoll_wait_ocall(
+ int64_t epfd,
+ struct oe_epoll_event* events,
+ unsigned int maxevents,
+ int timeout);
+
+int oe_syscall_epoll_wake_ocall(void);
+
+int oe_syscall_epoll_ctl_ocall(
+ int64_t epfd,
+ int op,
+ int64_t fd,
+ struct oe_epoll_event* event);
+
+int oe_syscall_epoll_close_ocall(oe_host_fd_t epfd);
+
+oe_host_fd_t oe_syscall_open_ocall(
+ const char* pathname,
+ int flags,
+ oe_mode_t mode);
+
+ssize_t oe_syscall_read_ocall(
+ oe_host_fd_t fd,
+ void* buf,
+ size_t count);
+
+ssize_t oe_syscall_write_ocall(
+ oe_host_fd_t fd,
+ const void* buf,
+ size_t count);
+
+ssize_t oe_syscall_readv_ocall(
+ oe_host_fd_t fd,
+ void* iov_buf,
+ int iovcnt,
+ size_t iov_buf_size);
+
+ssize_t oe_syscall_writev_ocall(
+ oe_host_fd_t fd,
+ const void* iov_buf,
+ int iovcnt,
+ size_t iov_buf_size);
+
+oe_off_t oe_syscall_lseek_ocall(
+ oe_host_fd_t fd,
+ oe_off_t offset,
+ int whence);
+
+ssize_t oe_syscall_pread_ocall(
+ oe_host_fd_t fd,
+ void* buf,
+ size_t count,
+ oe_off_t offset);
+
+ssize_t oe_syscall_pwrite_ocall(
+ oe_host_fd_t fd,
+ const void* buf,
+ size_t count,
+ oe_off_t offset);
+
+int oe_syscall_close_ocall(oe_host_fd_t fd);
+
+int oe_syscall_flock_ocall(
+ oe_host_fd_t fd,
+ int operation);
+
+int oe_syscall_fsync_ocall(oe_host_fd_t fd);
+
+int oe_syscall_fdatasync_ocall(oe_host_fd_t fd);
+
+oe_host_fd_t oe_syscall_dup_ocall(oe_host_fd_t oldfd);
+
+uint64_t oe_syscall_opendir_ocall(const char* name);
+
+int oe_syscall_readdir_ocall(
+ uint64_t dirp,
+ struct oe_dirent* entry);
+
+void oe_syscall_rewinddir_ocall(uint64_t dirp);
+
+int oe_syscall_closedir_ocall(uint64_t dirp);
+
+int oe_syscall_stat_ocall(
+ const char* pathname,
+ struct oe_stat_t* buf);
+
+int oe_syscall_fstat_ocall(
+ oe_host_fd_t fd,
+ struct oe_stat_t* buf);
+
+int oe_syscall_access_ocall(
+ const char* pathname,
+ int mode);
+
+int oe_syscall_link_ocall(
+ const char* oldpath,
+ const char* newpath);
+
+int oe_syscall_unlink_ocall(const char* pathname);
+
+int oe_syscall_rename_ocall(
+ const char* oldpath,
+ const char* newpath);
+
+int oe_syscall_truncate_ocall(
+ const char* path,
+ oe_off_t length);
+
+int oe_syscall_ftruncate_ocall(
+ oe_host_fd_t fd,
+ oe_off_t length);
+
+int oe_syscall_mkdir_ocall(
+ const char* pathname,
+ oe_mode_t mode);
+
+int oe_syscall_rmdir_ocall(const char* pathname);
+
+int oe_syscall_fcntl_ocall(
+ oe_host_fd_t fd,
+ int cmd,
+ uint64_t arg,
+ uint64_t argsize,
+ void* argout);
+
+int oe_syscall_ioctl_ocall(
+ oe_host_fd_t fd,
+ uint64_t request,
+ uint64_t arg,
+ uint64_t argsize,
+ void* argout);
+
+int oe_syscall_poll_ocall(
+ struct oe_host_pollfd* host_fds,
+ oe_nfds_t nfds,
+ int timeout);
+
+int oe_syscall_kill_ocall(
+ int pid,
+ int signum);
+
+int oe_syscall_close_socket_ocall(oe_host_fd_t sockfd);
+
+oe_host_fd_t oe_syscall_socket_ocall(
+ int domain,
+ int type,
+ int protocol);
+
+int oe_syscall_shutdown_sockets_device_ocall(oe_host_fd_t sockfd);
+
+int oe_syscall_socketpair_ocall(
+ int domain,
+ int type,
+ int protocol,
+ oe_host_fd_t sv[2]);
+
+int oe_syscall_connect_ocall(
+ oe_host_fd_t sockfd,
+ const struct oe_sockaddr* addr,
+ oe_socklen_t addrlen);
+
+oe_host_fd_t oe_syscall_accept_ocall(
+ oe_host_fd_t sockfd,
+ struct oe_sockaddr* addr,
+ oe_socklen_t addrlen_in,
+ oe_socklen_t* addrlen_out);
+
+int oe_syscall_bind_ocall(
+ oe_host_fd_t sockfd,
+ const struct oe_sockaddr* addr,
+ oe_socklen_t addrlen);
+
+int oe_syscall_listen_ocall(
+ oe_host_fd_t sockfd,
+ int backlog);
+
+ssize_t oe_syscall_recvmsg_ocall(
+ oe_host_fd_t sockfd,
+ void* msg_name,
+ oe_socklen_t msg_namelen,
+ oe_socklen_t* msg_namelen_out,
+ void* msg_iov_buf,
+ size_t msg_iovlen,
+ size_t msg_iov_buf_size,
+ void* msg_control,
+ size_t msg_controllen,
+ size_t* msg_controllen_out,
+ int flags);
+
+ssize_t oe_syscall_sendmsg_ocall(
+ oe_host_fd_t sockfd,
+ const void* msg_name,
+ oe_socklen_t msg_namelen,
+ void* msg_iov_buf,
+ size_t msg_iovlen,
+ size_t msg_iov_buf_size,
+ const void* msg_control,
+ size_t msg_controllen,
+ int flags);
+
+ssize_t oe_syscall_recv_ocall(
+ oe_host_fd_t sockfd,
+ void* buf,
+ size_t len,
+ int flags);
+
+ssize_t oe_syscall_recvfrom_ocall(
+ oe_host_fd_t sockfd,
+ void* buf,
+ size_t len,
+ int flags,
+ struct oe_sockaddr* src_addr,
+ oe_socklen_t addrlen_in,
+ oe_socklen_t* addrlen_out);
+
+ssize_t oe_syscall_send_ocall(
+ oe_host_fd_t sockfd,
+ const void* buf,
+ size_t len,
+ int flags);
+
+ssize_t oe_syscall_sendto_ocall(
+ oe_host_fd_t sockfd,
+ const void* buf,
+ size_t len,
+ int flags,
+ const struct oe_sockaddr* dest_addr,
+ oe_socklen_t addrlen);
+
+ssize_t oe_syscall_recvv_ocall(
+ oe_host_fd_t fd,
+ void* iov_buf,
+ int iovcnt,
+ size_t iov_buf_size);
+
+ssize_t oe_syscall_sendv_ocall(
+ oe_host_fd_t fd,
+ const void* iov_buf,
+ int iovcnt,
+ size_t iov_buf_size);
+
+int oe_syscall_shutdown_ocall(
+ oe_host_fd_t sockfd,
+ int how);
+
+int oe_syscall_setsockopt_ocall(
+ oe_host_fd_t sockfd,
+ int level,
+ int optname,
+ const void* optval,
+ oe_socklen_t optlen);
+
+int oe_syscall_getsockopt_ocall(
+ oe_host_fd_t sockfd,
+ int level,
+ int optname,
+ void* optval,
+ oe_socklen_t optlen_in,
+ oe_socklen_t* optlen_out);
+
+int oe_syscall_getsockname_ocall(
+ oe_host_fd_t sockfd,
+ struct oe_sockaddr* addr,
+ oe_socklen_t addrlen_in,
+ oe_socklen_t* addrlen_out);
+
+int oe_syscall_getpeername_ocall(
+ oe_host_fd_t sockfd,
+ struct oe_sockaddr* addr,
+ oe_socklen_t addrlen_in,
+ oe_socklen_t* addrlen_out);
+
+int oe_syscall_getaddrinfo_open_ocall(
+ const char* node,
+ const char* service,
+ const struct oe_addrinfo* hints,
+ uint64_t* handle);
+
+int oe_syscall_getaddrinfo_read_ocall(
+ uint64_t handle,
+ int* ai_flags,
+ int* ai_family,
+ int* ai_socktype,
+ int* ai_protocol,
+ oe_socklen_t ai_addrlen_in,
+ oe_socklen_t* ai_addrlen,
+ struct oe_sockaddr* ai_addr,
+ size_t ai_canonnamelen_in,
+ size_t* ai_canonnamelen,
+ char* ai_canonname);
+
+int oe_syscall_getaddrinfo_close_ocall(uint64_t handle);
+
+int oe_syscall_getnameinfo_ocall(
+ const struct oe_sockaddr* sa,
+ oe_socklen_t salen,
+ char* host,
+ oe_socklen_t hostlen,
+ char* serv,
+ oe_socklen_t servlen,
+ int flags);
+
+int oe_syscall_nanosleep_ocall(
+ struct oe_timespec* req,
+ struct oe_timespec* rem);
+
+int oe_syscall_clock_nanosleep_ocall(
+ oe_clockid_t clockid,
+ int flag,
+ struct oe_timespec* req,
+ struct oe_timespec* rem);
+
+int oe_syscall_getpid_ocall(void);
+
+int oe_syscall_getppid_ocall(void);
+
+int oe_syscall_getpgrp_ocall(void);
+
+unsigned int oe_syscall_getuid_ocall(void);
+
+unsigned int oe_syscall_geteuid_ocall(void);
+
+unsigned int oe_syscall_getgid_ocall(void);
+
+unsigned int oe_syscall_getegid_ocall(void);
+
+int oe_syscall_getpgid_ocall(int pid);
+
+int oe_syscall_getgroups_ocall(
+ size_t size,
+ unsigned int* list);
+
+int oe_syscall_uname_ocall(struct oe_utsname* buf);
+
+oe_result_t oe_get_supported_attester_format_ids_ocall(format_ids_t* format_ids);
+
+oe_result_t oe_get_qetarget_info_ocall(
+ const oe_uuid_t* format_id,
+ const void* opt_params,
+ size_t opt_params_size,
+ sgx_target_info_t* target_info);
+
+oe_result_t oe_get_quote_ocall(
+ const oe_uuid_t* format_id,
+ const void* opt_params,
+ size_t opt_params_size,
+ const sgx_report_t* sgx_report,
+ void* quote,
+ size_t quote_size,
+ size_t* quote_size_out);
+
+oe_result_t oe_get_quote_verification_collateral_ocall(
+ uint8_t fmspc[6],
+ uint8_t collateral_provider,
+ void* tcb_info,
+ size_t tcb_info_size,
+ size_t* tcb_info_size_out,
+ void* tcb_info_issuer_chain,
+ size_t tcb_info_issuer_chain_size,
+ size_t* tcb_info_issuer_chain_size_out,
+ void* pck_crl,
+ size_t pck_crl_size,
+ size_t* pck_crl_size_out,
+ void* root_ca_crl,
+ size_t root_ca_crl_size,
+ size_t* root_ca_crl_size_out,
+ void* pck_crl_issuer_chain,
+ size_t pck_crl_issuer_chain_size,
+ size_t* pck_crl_issuer_chain_size_out,
+ void* qe_identity,
+ size_t qe_identity_size,
+ size_t* qe_identity_size_out,
+ void* qe_identity_issuer_chain,
+ size_t qe_identity_issuer_chain_size,
+ size_t* qe_identity_issuer_chain_size_out);
+
+oe_result_t oe_verify_quote_ocall(
+ const oe_uuid_t* format_id,
+ const void* opt_params,
+ size_t opt_params_size,
+ const void* p_quote,
+ uint32_t quote_size,
+ const time_t expiration_check_date,
+ uint32_t* p_collateral_expiration_status,
+ uint32_t* p_quote_verification_result,
+ void* p_qve_report_info,
+ uint32_t qve_report_info_size,
+ void* p_supplemental_data,
+ uint32_t supplemental_data_size,
+ uint32_t* p_supplemental_data_size_out,
+ uint32_t collateral_version,
+ const void* p_tcb_info,
+ uint32_t tcb_info_size,
+ const void* p_tcb_info_issuer_chain,
+ uint32_t tcb_info_issuer_chain_size,
+ const void* p_pck_crl,
+ uint32_t pck_crl_size,
+ const void* p_root_ca_crl,
+ uint32_t root_ca_crl_size,
+ const void* p_pck_crl_issuer_chain,
+ uint32_t pck_crl_issuer_chain_size,
+ const void* p_qe_identity,
+ uint32_t qe_identity_size,
+ const void* p_qe_identity_issuer_chain,
+ uint32_t qe_identity_issuer_chain_size);
+
+oe_result_t oe_sgx_get_cpuid_table_ocall(
+ void* cpuid_table_buffer,
+ size_t cpuid_table_buffer_size);
+
+oe_result_t oe_sgx_backtrace_symbols_ocall(
+ oe_enclave_t* oe_enclave,
+ const uint64_t* buffer,
+ size_t size,
+ void* symbols_buffer,
+ size_t symbols_buffer_size,
+ size_t* symbols_buffer_size_out);
+
+void oe_sgx_thread_wake_wait_ocall(
+ oe_enclave_t* oe_enclave,
+ uint64_t waiter_tcs,
+ uint64_t self_tcs);
+
+void oe_sgx_wake_switchless_worker_ocall(oe_host_worker_context_t* context);
+
+void oe_sgx_sleep_switchless_worker_ocall(oe_enclave_worker_context_t* context);
+
+OE_EXTERNC_END
+
+#endif // EDGER8R_SGX_CPP_U_H
diff --git a/enclave/sgxcode/CMakeLists.txt b/enclave/sgxcode/CMakeLists.txt
new file mode 100644
index 000000000..4e76c9d1b
--- /dev/null
+++ b/enclave/sgxcode/CMakeLists.txt
@@ -0,0 +1,56 @@
+# Copyright (c) Open Enclave SDK contributors.
+# Licensed under the MIT License.
+
+cmake_minimum_required(VERSION 3.11)
+
+# If the CC environment variable has been specified or if the CMAKE_C_COMPILER
+# cmake variable has been passed to cmake, use the C compiler that has been
+# specified. Otherwise, prefer clang. Same for C++ compiler.
+# This must be done before the `project` command.
+if (UNIX)
+ if (NOT DEFINED ENV{CC} AND NOT DEFINED CMAKE_C_COMPILER)
+ find_program(CMAKE_C_COMPILER clang-11 clang-10 clang)
+ endif ()
+ if (NOT DEFINED ENV{CXX} AND NOT DEFINED CMAKE_CXX_COMPILER)
+ find_program(CMAKE_CXX_COMPILER clang++-11 clang++-10 clang++)
+ endif ()
+endif ()
+
+project("sgx code" LANGUAGES C CXX)
+
+find_package(OpenEnclave CONFIG REQUIRED)
+
+set(CMAKE_CXX_STANDARD 11)
+set(OE_CRYPTO_LIB
+ mbedtls
+ CACHE STRING "Crypto library used by enclaves.")
+
+add_subdirectory(enclave)
+add_subdirectory(host)
+
+# Generate key
+add_custom_command(
+ OUTPUT private.pem public.pem
+ COMMAND openssl genrsa -out private.pem -3 3072
+ COMMAND openssl rsa -in private.pem -pubout -out public.pem)
+
+# Sign enclave
+add_custom_command(
+ OUTPUT enclave/enclave.signed
+ DEPENDS enclave enclave/common/file-encryptor.conf private.pem
+ COMMAND openenclave::oesign sign -e $ -c
+ ${CMAKE_SOURCE_DIR}/enclave/common/file-encryptor.conf -k private.pem)
+
+add_custom_target(sign ALL DEPENDS enclave/enclave.signed)
+
+if ((NOT DEFINED ENV{OE_SIMULATION}) OR (NOT $ENV{OE_SIMULATION}))
+ add_custom_target(
+ run
+ DEPENDS sgxhost sign
+ COMMAND sgxhost ${CMAKE_BINARY_DIR}/enclave/enclave.signed)
+endif ()
+
+add_custom_target(
+ simulate
+ DEPENDS sgxhost sign
+ COMMAND sgxhost ${CMAKE_BINARY_DIR}/enclave/enclave.signed --simulate)
diff --git a/enclave/sgxcode/Makefile b/enclave/sgxcode/Makefile
new file mode 100644
index 000000000..d2d10d2b0
--- /dev/null
+++ b/enclave/sgxcode/Makefile
@@ -0,0 +1,24 @@
+# Copyright (c) Open Enclave SDK contributors.
+# Licensed under the MIT License.
+
+.PHONY: all build clean run simulate
+
+OE_CRYPTO_LIB := mbedtls
+export OE_CRYPTO_LIB
+
+all: build
+
+build:
+ $(MAKE) -C enclave
+ $(MAKE) -C host
+
+clean:
+ $(MAKE) -C enclave clean
+ $(MAKE) -C host clean
+
+run:
+ host/file-encryptorhost ./enclave/file-encryptorenc.signed
+
+simulate:
+ host/file-encryptorhost ./enclave/file-encryptorenc.signed --simulate
+
diff --git a/enclave/sgxcode/README.md b/enclave/sgxcode/README.md
new file mode 100644
index 000000000..473d67e05
--- /dev/null
+++ b/enclave/sgxcode/README.md
@@ -0,0 +1,138 @@
+# The File-Encryptor Sample
+
+OE SDK comes with a default crypto support library that supports a [subset of the open sources mbedTLS](https://github.com/openenclave/openenclave/blob/master/docs/MbedtlsSupport.md) library.
+This sample demonstrates how to perform simple file cryptographic operations inside an enclave using mbedTLS library.
+
+It has the following properties:
+
+- Written in C++
+- Show how to encrypt and decrypt data inside an enclave
+- Show how to derive a key from a password string using [PBKDF2](https://en.wikipedia.org/wiki/PBKDF2)
+- Use AES mbedTLS API to perform encryption and decryption
+- Use the following OE APIs
+ - mbedtls_aes_setkey_*
+ - mbedtls_aes_crypt_cbc
+ - mbedtls_pkcs5_pbkdf2_hmac
+ - mbedtls_ctr_drbg_random
+ - mbedtls_entropy_*
+ - mbedtls_ctr_drbg_*
+ - mbedtls_sha256_*
+- Also runs in OE simulation mode
+
+## Host application
+
+This sample is relatively straightforward, It's all about the use of the mbedTLS library.
+
+![Sample components diagram](diagram.png)
+
+The host application drives an enclave to perform the following operations:
+
+1. Create an enclave from the host.
+
+2. Encrypt a `testfile` into `out.encrypted`. It breaks an input file into 16-byte blocks.
+ It then sends each block to the enclave for encryption one block after the other until the
+ very last block is encountered. It makes sure the last block is padded to make it a 16-byte block,
+ which was required AES-CBC encryption algorithm used by the enclave.
+
+3. Decrypt the `out.encrypted` file to the `out.decrypted` file.
+
+ The decryption process is a reverse of the encryption except that it provides a encryption header
+ to the encryptor in the enclave in its `initialize_encryptor` call, which contains a
+ `encryption_header_t` (defined below), that has encryption metadata for the encryptor
+ to validate its password and retrieve the encryption key from it.
+
+ In the end, the host makes sure the contents of `testfile` and `out.decrypted` are identical
+ i.e. that the encryption and the decryption produce the expected result.
+
+4. Terminate the enclave.
+
+## Enclave library
+
+### ECALLs
+
+There are three ECALLs implemented inside the enclave library:
+
+### 1. initialize_encryptor
+
+```c
+int initialize_encryptor(
+ bool encrypt,
+ const char* password,
+ size_t password_len,
+ encryption_header_t* header)
+```
+
+The bulk of the operations done in this enclave call involve allocating resources and setting up mbedTLS for encryption and decryption operations.
+
+#### For encryption operation
+
+It does the following operations to generate `encryption_header_t` information for passing back the host to write into the encrypted file.
+
+```c
+typedef struct _encryption_header
+{
+ size_t fileDataSize;
+ unsigned char digest[HASH_VALUE_SIZE_IN_BYTES];
+ unsigned char encrypted_key[ENCRYPTION_KEY_SIZE_IN_BYTES];
+} encryption_header_t;
+```
+
+- Generate a SHA256 digest for the input password, stored in digest field.
+- Derive a password key from the input password.
+- Produce an encryption key.
+- Encrypt the encryption key with the password key, stored in `encrypted_key` field.
+
+See the following routine for implementation details:
+
+```c
+int ecall_dispatcher::prepare_encryption_header(
+ encryption_header_t* header,
+ string password)
+```
+
+#### For decryption operation
+
+In decryption, instead of generating `encryption_header_t` information, initialize_encryptor uses the host provided `encryption_header_t`
+information to validate the input password and extract encryption key for later decryption operations.
+
+Here what it does:
+
+- Check password by comparing `encryption_header_t.digest` with the calculated hash of the input password.
+- Derive a password key from the input password.
+- Decrypt `encryption_header_t.encrypted_key` with the password key produced above, in preparing for upcoming decryption operations.
+
+See the following routine for details:
+
+```c
+int ecall_dispatcher::parse_encryption_header(
+ encryption_header_t* header,
+ string password)
+```
+
+#### 2. encrypt_block
+
+```c
+int encrypt_block(
+ bool encrypt,
+ unsigned char* input_buf,
+ unsigned char* output_buf,
+ size_t size)
+```
+
+Send a block of data to the enclave for encryption using the configuration setup up by the `initialize_encryptor()` call.
+
+#### 3. close_encryptor()
+
+```c
+void close_encryptor()
+```
+
+Free all the resources allocated for this encryptor instance.
+
+## Build and run
+
+To build and run this sample, please refer to documentation provided in the main [README file](../README.md#building-the-samples)
+
+#### Note
+
+The file-encryptor sample can run under OE simulation mode.
\ No newline at end of file
diff --git a/enclave/sgxcode/enclave/CMakeLists.txt b/enclave/sgxcode/enclave/CMakeLists.txt
new file mode 100644
index 000000000..107491317
--- /dev/null
+++ b/enclave/sgxcode/enclave/CMakeLists.txt
@@ -0,0 +1,42 @@
+# Copyright (c) Open Enclave SDK contributors.
+# Licensed under the MIT License.
+
+# Use the edger8r to generate C bindings from the EDL file.
+add_custom_command(
+ OUTPUT sgx_cpp_t.h sgx_cpp_t.c sgx_cpp_args.h
+ DEPENDS ${CMAKE_SOURCE_DIR}/enclave/sgx_cpp.edl
+ COMMAND
+ openenclave::oeedger8r --trusted ${CMAKE_SOURCE_DIR}/enclave/sgx_cpp.edl
+ --search-path ${OE_INCLUDEDIR} --search-path
+ ${OE_INCLUDEDIR}/openenclave/edl/sgx)
+
+set(COUNTER_SRC simulated_counter_src)
+set(RANDOM_SRC random_src)
+set(DECRYPTOR_SRC decryptor_src)
+
+add_executable(
+ enclave common/ecalls.cpp common/dispatcher.cpp
+ ${COUNTER_SRC}/simulated_counter.cpp
+ ${RANDOM_SRC}/random.cpp
+ ${DECRYPTOR_SRC}/decryptor.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/sgx_cpp_t.c)
+if (WIN32)
+ maybe_build_using_clangw(enclave)
+endif ()
+
+target_compile_definitions(enclave PUBLIC OE_API_VERSION=2)
+
+target_include_directories(
+ enclave
+ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} # Needed for #include "../shared.h"
+ ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
+
+if (OE_CRYPTO_LIB STREQUAL "openssl_3")
+ message(STATUS "openssl_3 enable.")
+else()
+ message(STATUS "openssl_3 not enable. ${OE_CRYPTO_LIB}")
+endif ()
+
+target_link_libraries(
+ enclave openenclave::oeenclave openenclave::oecryptoopenssl
+ openenclave::oelibcxx)
diff --git a/enclave/sgxcode/enclave/Makefile b/enclave/sgxcode/enclave/Makefile
new file mode 100644
index 000000000..218fbd02d
--- /dev/null
+++ b/enclave/sgxcode/enclave/Makefile
@@ -0,0 +1,53 @@
+# Copyright (c) Open Enclave SDK contributors.
+# Licensed under the MIT License.
+
+include ../../config.mk
+
+ifeq ($(OE_CRYPTO_LIB),openssl_3)
+ CFLAGS=$(shell pkg-config oeenclave-$(C_COMPILER) --variable=${OE_CRYPTO_LIB}flags)
+ CXXFLAGS=$(shell pkg-config oeenclave-$(CXX_COMPILER) --variable=${OE_CRYPTO_LIB}flags)
+else
+ CFLAGS=$(shell pkg-config oeenclave-$(C_COMPILER) --cflags)
+ CXXFLAGS=$(shell pkg-config oeenclave-$(CXX_COMPILER) --cflags)
+endif
+LDFLAGS=$(shell pkg-config oeenclave-$(CXX_COMPILER) --libs)
+INCDIR=$(shell pkg-config oeenclave-$(C_COMPILER) --variable=includedir)
+CRYPTO_LDFLAGS=$(shell pkg-config oeenclave-$(COMPILER) --variable=${OE_CRYPTO_LIB}libs)
+
+CRYPTO_SRC = $(OE_CRYPTO_LIB)_src
+CXXINCDIR = -I. -I../ -I../..
+CXXSRCS = common/ecalls.cpp \
+ $(CRYPTO_SRC)/encryptor.cpp \
+ $(CRYPTO_SRC)/keys.cpp
+
+# Cover openssl, openssl_symcrypt_fips, and openssl_3
+ifneq (,$(findstring openssl,$(OE_CRYPTO_LIB)))
+ CRYPTO_SRC = openssl_src
+endif
+
+all:
+ $(MAKE) build
+ $(MAKE) keys
+ $(MAKE) sign
+
+build:
+ @ echo "Compilers used: $(CC), $(CXX)"
+ oeedger8r ../enclave/sgx_cpp.edl --trusted \
+ --search-path $(INCDIR) \
+ --search-path $(INCDIR)/openenclave/edl/sgx
+ $(CXX) -g -c $(CXXFLAGS) -DOE_API_VERSION=2 -std=c++11 $(CXXINCDIR) \
+ $(CXXSRCS)
+ $(CC) -g -c $(CFLAGS) -DOE_API_VERSION=2 sgx_cpp_t.c -o sgx_cpp_t.o
+ $(CXX) -o file-encryptorenc ecalls.o encryptor.o keys.o sgx_cpp_t.o $(LDFLAGS) $(CRYPTO_LDFLAGS)
+
+sign:
+ oesign sign -e file-encryptorenc -c common/file-encryptor.conf -k private.pem
+
+clean:
+ rm -f file-encryptorenc file-encryptorenc.signed *.o sgx_cpp_t.* sgx_cpp_args.h private.pem public.pem
+
+keys:
+ openssl genrsa -out private.pem -3 3072
+ openssl rsa -in private.pem -pubout -out public.pem
+
+
diff --git a/enclave/sgxcode/enclave/common/dispatcher.cpp b/enclave/sgxcode/enclave/common/dispatcher.cpp
new file mode 100644
index 000000000..1d0e0abd6
--- /dev/null
+++ b/enclave/sgxcode/enclave/common/dispatcher.cpp
@@ -0,0 +1,7 @@
+#include "common/dispatcher.h"
+#include "common/trace.h"
+
+
+ecall_dispatcher::ecall_dispatcher() : counterNum(0)
+{
+}
diff --git a/enclave/sgxcode/enclave/common/dispatcher.h b/enclave/sgxcode/enclave/common/dispatcher.h
new file mode 100644
index 000000000..dd25ab2f8
--- /dev/null
+++ b/enclave/sgxcode/enclave/common/dispatcher.h
@@ -0,0 +1,87 @@
+// Copyright (c) Open Enclave SDK contributors.
+// Licensed under the MIT License.
+
+#pragma once
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+
+using namespace std;
+
+class ecall_dispatcher
+{
+ private:
+ // counter
+ uint32_t counterNum;
+ std::vector counters;
+
+ // random generator
+ std::random_device rd; // Obtain a random number from hardware
+ uint32_t seed;
+ uint32_t range;
+ std::mt19937 eng;
+ uint32_t randUseCount;
+
+ // decryptor
+ unsigned char* pubKeyData;
+ unsigned char* privKeyData;
+ int pubLen;
+ int privLen;
+
+ public:
+ ecall_dispatcher();
+
+ // counter
+ int request_counter(uint32_t* index);
+ int get_counter(
+ uint32_t* index,
+ size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t * buffer_size_array,
+ unsigned char ** previous_attestation,
+ uint32_t* counter_value);
+
+ // random generator
+ int reset_prng(
+ uint32_t* seed,
+ uint32_t* range);
+ int generate_rdrand(uint32_t* rdrandNum);
+ int generate_rand(size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t * buffer_size_array,
+ unsigned char ** previous_attestation,
+ uint32_t* randNum);
+
+ // decryptor
+ int generate_key(size_t* key_size);
+ int update_key(
+ unsigned char* priv_key,
+ size_t priv_len,
+ unsigned char* pub_key,
+ size_t pub_len);
+ int get_pubkey(
+ unsigned char **key_buf,
+ size_t *key_len);
+ int encrypt(
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len);
+
+ int decrypt(
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len);
+
+};
diff --git a/enclave/sgxcode/enclave/common/ecalls.cpp b/enclave/sgxcode/enclave/common/ecalls.cpp
new file mode 100644
index 000000000..2a90cfa6f
--- /dev/null
+++ b/enclave/sgxcode/enclave/common/ecalls.cpp
@@ -0,0 +1,93 @@
+// Copyright (c) Open Enclave SDK contributors.
+// Licensed under the MIT License.
+
+#include
+
+#include "dispatcher.h"
+#include "sgx_cpp_t.h"
+
+// Declare a static dispatcher object for enabling for better organization
+// of enclave-wise global variables
+static ecall_dispatcher dispatcher;
+
+int request_counter(
+ uint32_t* index)
+{
+ return dispatcher.request_counter(index);
+}
+
+int get_counter(
+ uint32_t* index,
+ size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t * buffer_size_array,
+ unsigned char ** previous_attestation,
+ uint32_t* counter_value)
+{
+ return dispatcher.get_counter(index,previous_size,limit_count,counter_value_array,buffer_size_array,previous_attestation,counter_value);
+}
+
+int reset_prng(
+ uint32_t* seed,
+ uint32_t* range)
+{
+ return dispatcher.reset_prng(seed, range);
+}
+
+int generate_rdrand(uint32_t* rdrandNum)
+{
+ return dispatcher.generate_rdrand(rdrandNum);
+}
+
+int generate_rand(size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t * buffer_size_array,
+ unsigned char ** previous_attestation,
+ uint32_t* randNum)
+{
+ return dispatcher.generate_rand(previous_size, limit_count, counter_value_array, buffer_size_array,
+ previous_attestation, randNum);
+}
+
+int generate_key(
+ size_t *key_size)
+{
+ return dispatcher.generate_key(key_size);
+}
+
+int update_key(
+ unsigned char* priv_key,
+ size_t priv_len,
+ unsigned char* pub_key,
+ size_t pub_len)
+{
+ return dispatcher.update_key(priv_key, priv_len, pub_key, pub_len);
+}
+
+int get_pubkey(
+ unsigned char **key_buf,
+ size_t *key_len)
+{
+ return dispatcher.get_pubkey(key_buf, key_len);
+}
+
+int encrypt(
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len)
+{
+ return dispatcher.encrypt(input_buf, output_buf, input_len, output_len);
+}
+
+int decrypt(
+ unsigned char* input_buf,
+ unsigned char** output_buf,
+ size_t input_len,
+ size_t* output_len)
+{
+ return dispatcher.decrypt(input_buf, output_buf, input_len, output_len);
+}
+
diff --git a/enclave/sgxcode/enclave/common/file-encryptor.conf b/enclave/sgxcode/enclave/common/file-encryptor.conf
new file mode 100644
index 000000000..10e63351b
--- /dev/null
+++ b/enclave/sgxcode/enclave/common/file-encryptor.conf
@@ -0,0 +1,10 @@
+# Copyright (c) Open Enclave SDK contributors.
+# Licensed under the MIT License.
+
+# Enclave settings:
+Debug=1
+NumHeapPages=2048
+NumStackPages=1024
+NumTCS=2
+ProductID=1
+SecurityVersion=1
diff --git a/enclave/sgxcode/enclave/common/random.h b/enclave/sgxcode/enclave/common/random.h
new file mode 100644
index 000000000..e69de29bb
diff --git a/enclave/sgxcode/enclave/common/trace.h b/enclave/sgxcode/enclave/common/trace.h
new file mode 100644
index 000000000..5d0df7e36
--- /dev/null
+++ b/enclave/sgxcode/enclave/common/trace.h
@@ -0,0 +1,5 @@
+// Copyright (c) Open Enclave SDK contributors.
+// Licensed under the MIT License.
+
+#define TRACE_ENCLAVE(fmt, ...) \
+ printf("Enclave: %s(%d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
diff --git a/enclave/sgxcode/enclave/decryptor_src/decryptor copy.cpp b/enclave/sgxcode/enclave/decryptor_src/decryptor copy.cpp
new file mode 100644
index 000000000..a654ee85c
--- /dev/null
+++ b/enclave/sgxcode/enclave/decryptor_src/decryptor copy.cpp
@@ -0,0 +1,139 @@
+#include "common/dispatcher.h"
+#include "common/trace.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+// Generate an encryption key: this is the key used to encrypt data
+int ecall_dispatcher::generate_key(size_t key_size)
+{
+ TRACE_ENCLAVE("generating encryption key");
+ int ret = 0;
+
+ RSA *keypair = RSA_generate_key(key_size, RSA_F4, NULL, NULL);
+
+ BIO *pubBIO = BIO_new(BIO_s_mem());
+ BIO *privBIO = BIO_new(BIO_s_mem());
+
+ PEM_write_bio_RSAPublicKey(pubBIO, keypair);
+ PEM_write_bio_RSAPrivateKey(privBIO, keypair, NULL, NULL, 0, NULL, NULL);
+
+ pubLen = BIO_pending(pubBIO);
+ privLen = BIO_pending(privBIO);
+
+ pubKeyData = new unsigned char[pubLen + 1];
+ privKeyData = new unsigned char[privLen + 1];
+
+ BIO_read(pubBIO, pubKeyData, pubLen);
+ BIO_read(privBIO, privKeyData, privLen);
+
+ pubKeyData[pubLen] = '\0';
+ privKeyData[privLen] = '\0';
+
+ BIO_free_all(pubBIO);
+ BIO_free_all(privBIO);
+
+exit:
+ return ret;
+}
+
+int ecall_dispatcher::update_key(
+ unsigned char* priv_key,
+ size_t priv_len,
+ unsigned char* pub_key,
+ size_t pub_len)
+{
+ delete[] privKeyData;
+ privKeyData = new unsigned char[priv_len + 1];
+ privLen = priv_len;
+ memcpy(privKeyData, priv_key, priv_len);
+
+ delete[] pubKeyData;
+ pubKeyData = new unsigned char[pub_len + 1];
+ pubLen = pub_len;
+ memcpy(pubKeyData, pub_key, pub_len);
+}
+
+RSA *load_key_from_memory(unsigned char *keydata, bool public_key)
+{
+ BIO *bio = BIO_new_mem_buf(keydata, -1);
+ RSA *key = NULL;
+ if (public_key)
+ {
+ PEM_read_bio_RSAPublicKey(bio, &key, NULL, NULL);
+ }
+ else
+ {
+ PEM_read_bio_RSAPrivateKey(bio, &key, NULL, NULL);
+ }
+
+ BIO_free_all(bio);
+ return key;
+}
+
+
+int ecall_dispatcher::encrypt(
+ unsigned char *input_buf,
+ unsigned char **output_buf,
+ size_t input_len,
+ size_t *output_len)
+{
+ TRACE_ENCLAVE("encrypting data");
+ int ret = 0;
+
+ RSA *pub_key = load_key_from_memory(pubKeyData, true);
+ *output_buf = new unsigned char[RSA_size(pub_key)];
+
+ if (*output_buf == nullptr) {
+ delete[] *output_buf;
+ return -1; // Memory allocation failed
+ }
+
+ int encrypt_length = RSA_public_encrypt(input_len, input_buf, *output_buf, pub_key, RSA_PKCS1_PADDING);
+
+ if (encrypt_length == -1) {
+ TRACE_ENCLAVE("encrypting data failed");
+ delete[] *output_buf;
+ return -1; // Encryption failed
+ }
+
+ *output_len = encrypt_length;
+
+ return ret; // success
+}
+
+
+int ecall_dispatcher::decrypt(
+ unsigned char *input_buf,
+ unsigned char **output_buf,
+ size_t input_len,
+ size_t *output_len)
+{
+ TRACE_ENCLAVE("decrypting data");
+ int ret = 0;
+
+ RSA *priv_key = load_key_from_memory(privKeyData, false);
+ *output_buf = new unsigned char[RSA_size(priv_key)];
+
+ if (*output_buf == nullptr) {
+ delete[] *output_buf;
+ return -1; // Memory allocation failed
+ }
+
+ int decrypt_length = RSA_private_decrypt(input_len, input_buf, *output_buf, priv_key, RSA_PKCS1_PADDING);
+
+ if (decrypt_length == -1) {
+ delete[] *output_buf;
+ return -1; // Encryption failed
+ }
+
+ *output_len = decrypt_length;
+
+ return ret; // success
+}
+
diff --git a/enclave/sgxcode/enclave/decryptor_src/decryptor.cpp b/enclave/sgxcode/enclave/decryptor_src/decryptor.cpp
new file mode 100644
index 000000000..5e239d910
--- /dev/null
+++ b/enclave/sgxcode/enclave/decryptor_src/decryptor.cpp
@@ -0,0 +1,224 @@
+#include "common/dispatcher.h"
+#include "common/trace.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+// Generate an encryption key: this is the key used to encrypt data
+int ecall_dispatcher::generate_key(size_t* key_size)
+{
+ TRACE_ENCLAVE("generating encryption key 1");
+ ERR_load_crypto_strings();
+ int ret = 0;
+
+/*
+ RSA *keypair = RSA_generate_key(*key_size, RSA_F4, NULL, NULL);
+
+ BIO *pubBIO = BIO_new(BIO_s_mem());
+ BIO *privBIO = BIO_new(BIO_s_mem());
+
+ PEM_write_bio_RSAPublicKey(pubBIO, keypair);
+ PEM_write_bio_RSAPrivateKey(privBIO, keypair, NULL, NULL, 0, NULL, NULL);
+
+ pubLen = BIO_pending(pubBIO);
+ privLen = BIO_pending(privBIO);
+
+ pubKeyData = new unsigned char[pubLen + 1];
+ privKeyData = new unsigned char[privLen + 1];
+
+ BIO_read(pubBIO, pubKeyData, pubLen);
+ BIO_read(privBIO, privKeyData, privLen);
+
+ pubKeyData[pubLen] = '\0';
+ privKeyData[privLen] = '\0';
+
+ pubLen = BIO_pending(pubBIO);
+ privLen = BIO_pending(privBIO);
+
+ BIO_free_all(pubBIO);
+ BIO_free_all(privBIO);
+*/
+
+{
+ size_t pubLen_ = 426;
+ size_t privLen_ = 1679;
+ std::string pubKeyDataStr = R"(-----BEGIN RSA PUBLIC KEY-----
+sample public key
+-----END RSA PUBLIC KEY-----)";
+ std::string privKeyDataStr = R"(-----BEGIN RSA PRIVATE KEY-----
+sample private key
+-----END RSA PRIVATE KEY-----)";
+
+ pubKeyData = new unsigned char[pubKeyDataStr.size() + 1];
+ privKeyData = new unsigned char[privKeyDataStr.size() + 1];
+
+ std::memcpy(pubKeyData, pubKeyDataStr.c_str(), pubKeyDataStr.size() + 1); // 包括 null terminator
+ std::memcpy(privKeyData, privKeyDataStr.c_str(), privKeyDataStr.size() + 1);
+
+ pubLen = pubKeyDataStr.size() + 1;
+ privLen = privKeyDataStr.size() + 1;
+}
+
+ TRACE_ENCLAVE("pubKeyData: \n%s",pubKeyData);
+ TRACE_ENCLAVE("privKeyData: \n%s",privKeyData);
+ TRACE_ENCLAVE("pubLen: %d",pubLen);
+ TRACE_ENCLAVE("privLen: %d",privLen);
+
+ return ret;
+}
+
+int ecall_dispatcher::update_key(
+ unsigned char* priv_key,
+ size_t priv_len,
+ unsigned char* pub_key,
+ size_t pub_len)
+{
+ delete[] privKeyData;
+ privKeyData = new unsigned char[priv_len + 1];
+ privLen = priv_len;
+ memcpy(privKeyData, priv_key, priv_len);
+
+ delete[] pubKeyData;
+ pubKeyData = new unsigned char[pub_len + 1];
+ pubLen = pub_len;
+ memcpy(pubKeyData, pub_key, pub_len);
+}
+
+RSA *load_key_from_memory(unsigned char *keydata, bool public_key)
+{
+ BIO *bio = BIO_new_mem_buf(keydata, -1);
+ RSA *key = NULL;
+ if (public_key)
+ {
+ PEM_read_bio_RSAPublicKey(bio, &key, NULL, NULL);
+ }
+ else
+ {
+ PEM_read_bio_RSAPrivateKey(bio, &key, NULL, NULL);
+ }
+
+ BIO_free_all(bio);
+ return key;
+}
+
+int ecall_dispatcher::get_pubkey(
+ unsigned char **key_buf,
+ size_t *key_len)
+{
+ TRACE_ENCLAVE("get_pubkey: \n%s",pubKeyData);
+ int ret = 0;
+ *key_buf = new unsigned char[pubLen + 1];
+ std::memcpy(*key_buf, pubKeyData, pubLen);
+ (*key_buf)[pubLen] = '\0';
+ *key_len = pubLen;
+ return ret;
+}
+
+
+int ecall_dispatcher::encrypt(
+ unsigned char *input_buf,
+ unsigned char **output_buf,
+ size_t input_len,
+ size_t *output_len)
+{
+ TRACE_ENCLAVE("encrypting data");
+ int ret = 0;
+
+ RSA *pub_key = load_key_from_memory(pubKeyData, true);
+ *output_buf = new unsigned char[RSA_size(pub_key)];
+
+ if (*output_buf == nullptr) {
+ delete[] *output_buf;
+ return -1; // Memory allocation failed
+ }
+
+ int encrypt_length = RSA_public_encrypt(input_len, input_buf, *output_buf, pub_key, RSA_PKCS1_PADDING);
+
+ if (encrypt_length == -1) {
+ TRACE_ENCLAVE("encrypting data failed");
+ delete[] *output_buf;
+ return -1; // Encryption failed
+ }
+
+ *output_len = encrypt_length;
+
+ return ret; // success
+}
+
+
+// int ecall_dispatcher::decrypt(
+// unsigned char *input_buf,
+// unsigned char **output_buf,
+// size_t input_len,
+// size_t *output_len)
+// {
+// int ret = 0;
+
+// RSA *priv_key = load_key_from_memory(privKeyData, false);
+// *output_buf = new unsigned char[RSA_size(priv_key)];
+
+// if (*output_buf == nullptr) {
+// delete[] *output_buf;
+// return -1; // Memory allocation failed
+// }
+
+// int decrypt_length = RSA_private_decrypt(input_len, input_buf, *output_buf, priv_key, RSA_PKCS1_PADDING);
+
+// if (decrypt_length == -1) {
+// delete[] *output_buf;
+// return -1; // Encryption failed
+// }
+
+// *output_len = decrypt_length;
+
+// return ret; // succeed
+// }
+
+int ecall_dispatcher::decrypt(
+ unsigned char *input_buf,
+ unsigned char **output_buf,
+ size_t input_len,
+ size_t *output_len)
+{
+ int ret = 0;
+
+ RSA *priv_key = load_key_from_memory(privKeyData, false);
+ if (priv_key == nullptr) {
+ TRACE_ENCLAVE("Failed to load private key.");
+ return -1;
+ }
+
+ int key_size = RSA_size(priv_key);
+ *output_buf = new unsigned char[key_size];
+ if (*output_buf == nullptr) {
+ TRACE_ENCLAVE("Memory allocation failed.");
+ RSA_free(priv_key);
+ return -1;
+ }
+
+ int decrypt_length = RSA_private_decrypt(
+ input_len,
+ input_buf,
+ *output_buf,
+ priv_key,
+ RSA_PKCS1_PADDING);
+
+ if (decrypt_length == -1) {
+ unsigned long err = ERR_get_error();
+ char err_msg[120];
+ ERR_error_string(err, err_msg);
+ TRACE_ENCLAVE("Decryption failed: %s",err_msg);
+ delete[] *output_buf;
+ RSA_free(priv_key);
+ return -1; // Decryption failed
+ }
+
+ *output_len = decrypt_length;
+ RSA_free(priv_key);
+ return ret; // Success
+}
diff --git a/enclave/sgxcode/enclave/random_src/random.cpp b/enclave/sgxcode/enclave/random_src/random.cpp
new file mode 100644
index 000000000..d33020f7b
--- /dev/null
+++ b/enclave/sgxcode/enclave/random_src/random.cpp
@@ -0,0 +1,63 @@
+#include "common/dispatcher.h"
+#include "common/trace.h"
+
+int ecall_dispatcher::reset_prng(uint32_t* seed, uint32_t* range) {
+ int ret = 0;
+ // TRACE_ENCLAVE("ecall_dispatcher::set_seed");
+
+ this->seed = *seed;
+ this->range = *range;
+ eng.seed(*seed);
+ this->randUseCount = 0;
+
+exit:
+ return ret;
+}
+
+int ecall_dispatcher::generate_rdrand(uint32_t* rdrandNum) {
+ int ret = 0;
+ // TRACE_ENCLAVE("ecall_dispatcher::generate_rdrand");
+
+ *rdrandNum = rd();
+
+exit:
+ return ret;
+}
+
+int ecall_dispatcher::generate_rand(size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t * buffer_size_array,
+ unsigned char ** previous_attestation,
+ uint32_t* randNum) {
+ int ret = 0;
+ // TRACE_ENCLAVE("ecall_dispatcher::generate_rdrand");
+
+ // TRACE_ENCLAVE("counter_value:%d, randUseCount:%d, generate_rand",counter_value_array[0],randUseCount);
+
+ if (randUseCount != 0 && previous_size < limit_count) {
+ TRACE_ENCLAVE("%d,%d: Insufficient previous cert number",previous_size,limit_count);
+ goto exit;
+ }
+
+ // Check previous counter info and attestation here
+ for (size_t i = 0; i < previous_size; i++)
+ {
+ if (!std::strncmp((const char*)previous_attestation[i], "Fake Attestation", buffer_size_array[i]) == 0) {
+ TRACE_ENCLAVE("Could not verify the attestation");
+ goto exit;
+ }
+ if (counter_value_array[i]/3 + 1 != randUseCount) {
+ TRACE_ENCLAVE("counter_value:%d, randUseCount:%d, Counter value invalid",counter_value_array[i],randUseCount);
+ goto exit;
+ }
+ // TRACE_ENCLAVE("previous_size: %d, counter: %d, attestation: %.*s", previous_size,
+ // counter_value_array[i], buffer_size_array[i], previous_attestation[i]);
+ }
+
+ *randNum = eng() % range;
+ randUseCount++;
+
+exit:
+ return ret;
+}
diff --git a/enclave/sgxcode/enclave/sgx_cpp.edl b/enclave/sgxcode/enclave/sgx_cpp.edl
new file mode 100644
index 000000000..149327118
--- /dev/null
+++ b/enclave/sgxcode/enclave/sgx_cpp.edl
@@ -0,0 +1,45 @@
+// Copyright (c) Open Enclave SDK contributors.
+// Licensed under the MIT License.
+
+enclave {
+ from "openenclave/edl/syscall.edl" import *;
+ from "platform.edl" import *;
+
+
+ trusted {
+ public int request_counter([out] uint32_t* index);
+ public int get_counter([in] uint32_t* index,
+ size_t previous_size,
+ size_t limit_count,
+ [user_check] uint32_t* counter_value_array,
+ [user_check] size_t* buffer_size_array,
+ [user_check] unsigned char** previous_attestation,
+ [out] uint32_t* counter_value);
+
+ public int reset_prng([in] uint32_t* seed, [in] uint32_t* range);
+ public int generate_rdrand([out] uint32_t* rdrandNum);
+ public int generate_rand(size_t input_len,
+ size_t limit_count,
+ [user_check] uint32_t* counter_value_array,
+ [user_check] size_t* buffer_size_array,
+ [user_check] unsigned char** previous_attestation,
+ [out] uint32_t* randNum);
+
+ public int generate_key([in] size_t *key_size);
+ public int update_key([in] unsigned char* priv_key, size_t priv_len,
+ [in] unsigned char* pub_key, size_t pub_len);
+ public int get_pubkey([user_check] unsigned char** key_buf,
+ [out] size_t* key_len);
+ public int encrypt([user_check] unsigned char* input_buf,
+ [user_check] unsigned char** output_buf,
+ size_t input_len, size_t* output_len);
+ public int decrypt([user_check] unsigned char* input_buf,
+ [user_check] unsigned char** output_buf,
+ size_t input_len, size_t* output_len);
+ };
+
+ //untrusted {
+ // no untrusted functions in this sample
+ //};
+};
+
diff --git a/enclave/sgxcode/enclave/simulated_counter_src/simulated_counter.cpp b/enclave/sgxcode/enclave/simulated_counter_src/simulated_counter.cpp
new file mode 100644
index 000000000..351fba954
--- /dev/null
+++ b/enclave/sgxcode/enclave/simulated_counter_src/simulated_counter.cpp
@@ -0,0 +1,59 @@
+#include "common/dispatcher.h"
+#include "common/trace.h"
+#include
+
+int ecall_dispatcher::request_counter(uint32_t* index) {
+ int ret = 0;
+ // TRACE_ENCLAVE("ecall_dispatcher::request_counter");
+
+ counters.push_back(0);
+ *index = counterNum;
+ counterNum++;
+
+exit:
+ return ret;
+}
+
+int ecall_dispatcher::get_counter(
+ uint32_t* index,
+ size_t previous_size,
+ size_t limit_count,
+ uint32_t* counter_value_array,
+ size_t * buffer_size_array,
+ unsigned char ** previous_attestation,
+ uint32_t* counter_value) {
+
+ int ret = 0;
+
+ if (counters[*index]!=0 && previous_size < limit_count) {
+ TRACE_ENCLAVE("%d,%d: Insufficient previous cert number",previous_size,limit_count);
+ goto exit;
+ }
+
+ // Check previous counter info and attestation here
+ for (size_t i = 0; i < previous_size; i++)
+ {
+ if (!std::strncmp((const char*)previous_attestation[i], "Fake Attestation", buffer_size_array[i]) == 0) {
+ TRACE_ENCLAVE("Could not verify the attestation");
+ goto exit;
+ }
+ if (counter_value_array[i] != counters[*index] - 1) {
+ TRACE_ENCLAVE("Counter value invalid");
+ goto exit;
+ }
+ // TRACE_ENCLAVE("previous_size: %d, counter: %d, attestation: %.*s", previous_size,
+ // counter_value_array[i], buffer_size_array[i], previous_attestation[i]);
+ }
+ // */
+
+ if (*index < 0 || *index >= counterNum) {
+ // TRACE_ENCLAVE("Counter index out of range");
+ goto exit;
+ }
+
+ *counter_value = counters[*index];
+ counters[*index]++;
+
+exit:
+ return ret;
+}
diff --git a/enclave/sgxcode/host/CMakeLists.txt b/enclave/sgxcode/host/CMakeLists.txt
new file mode 100644
index 000000000..b5faeed2c
--- /dev/null
+++ b/enclave/sgxcode/host/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Copyright (c) Open Enclave SDK contributors.
+# Licensed under the MIT License.
+
+add_custom_command(
+ OUTPUT sgx_cpp_u.h sgx_cpp_u.c sgx_cpp_args.h
+ DEPENDS ${CMAKE_SOURCE_DIR}/enclave/sgx_cpp.edl
+ COMMAND
+ openenclave::oeedger8r --untrusted ${CMAKE_SOURCE_DIR}/enclave/sgx_cpp.edl
+ --search-path ${OE_INCLUDEDIR} --search-path
+ ${OE_INCLUDEDIR}/openenclave/edl/sgx)
+
+add_executable(sgxhost
+ host.cpp ${CMAKE_CURRENT_BINARY_DIR}/sgx_cpp_u.c)
+
+if (WIN32)
+ copy_oedebugrt_target(sgxhost_oedebugrt)
+ add_dependencies(sgxhost sgxhost_oedebugrt)
+endif ()
+
+target_include_directories(
+ sgxhost
+ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} # Needed for #include "../shared.h"
+ ${CMAKE_CURRENT_BINARY_DIR})
+
+target_link_libraries(sgxhost openenclave::oehost)
diff --git a/enclave/sgxcode/host/Makefile b/enclave/sgxcode/host/Makefile
new file mode 100644
index 000000000..79719228a
--- /dev/null
+++ b/enclave/sgxcode/host/Makefile
@@ -0,0 +1,24 @@
+# Copyright (c) Open Enclave SDK contributors.
+# Licensed under the MIT License.
+
+include ../../config.mk
+
+CFLAGS=$(shell pkg-config oehost-$(C_COMPILER) --cflags)
+CXXFLAGS=$(shell pkg-config oehost-$(CXX_COMPILER) --cflags)
+LDFLAGS=$(shell pkg-config oehost-$(CXX_COMPILER) --libs)
+INCDIR=$(shell pkg-config oehost-$(C_COMPILER) --variable=includedir)
+
+all: build
+
+build:
+ @ echo "Compilers used: $(CC), $(CXX)"
+ oeedger8r ../enclave/sgx_cpp.edl --untrusted \
+ --search-path $(INCDIR) \
+ --search-path $(INCDIR)/openenclave/edl/sgx
+ $(CXX) -g -c $(CXXFLAGS) host.cpp
+ $(CC) -g -c $(CFLAGS) sgx_cpp_u.c
+ $(CXX) -o file-encryptorhost host.o sgx_cpp_u.o $(LDFLAGS)
+
+clean:
+ rm -f file-encryptorhost sgx_cpp_u.* sgx_cpp_args.h *.o ../out.decrypted ../out.encrypted
+
diff --git a/enclave/sgxcode/host/host.cpp b/enclave/sgxcode/host/host.cpp
new file mode 100644
index 000000000..8ff11d940
--- /dev/null
+++ b/enclave/sgxcode/host/host.cpp
@@ -0,0 +1,278 @@
+// Copyright (c) Open Enclave SDK contributors.
+// Licensed under the MIT License.
+
+// Note: Only for testing enclave !
+
+#include
+#include
+#include
+#include
+#include
+#include "sgx_cpp_u.h"
+
+using namespace std;
+
+#define CIPHER_BLOCK_SIZE 16
+#define DATA_BLOCK_SIZE 256
+#define ENCRYPT_OPERATION true
+#define DECRYPT_OPERATION false
+
+oe_enclave_t *enclave = NULL;
+
+bool check_simulate_opt(int *argc, const char *argv[])
+{
+ for (int i = 0; i < *argc; i++)
+ {
+ if (strcmp(argv[i], "--simulate") == 0)
+ {
+ cout << "Running in simulation mode" << endl;
+ memmove(&argv[i], &argv[i + 1], (*argc - i) * sizeof(char *));
+ (*argc)--;
+ return true;
+ }
+ }
+ return false;
+}
+
+void printHex(unsigned char* data, size_t length) {
+ cout << "{";
+ for (size_t i = 0; i < length; ++i) {
+ printf("0x%02x ", data[i]);
+ }
+ ::cout << "}" << endl;
+}
+
+
+int main(int argc, const char *argv[])
+{
+ oe_result_t result;
+ int ret = 0;
+ uint32_t flags = OE_ENCLAVE_FLAG_DEBUG;
+
+ if (check_simulate_opt(&argc, argv))
+ {
+ flags |= OE_ENCLAVE_FLAG_SIMULATE;
+ }
+
+ cout << "Host: enter main" << endl;
+ if (argc != 2)
+ {
+ cerr << "Usage: " << argv[0]
+ << " enclave_image_path [ --simulate ]" << endl;
+ return 1;
+ }
+
+ cout << "Host: create enclave for image:" << argv[1] << endl;
+ result = oe_create_sgx_cpp_enclave(
+ argv[1], OE_ENCLAVE_TYPE_SGX, flags, NULL, 0, &enclave);
+ if (result != OE_OK)
+ {
+ cerr << "oe_create_sgx_cpp_enclave() failed with " << argv[0]
+ << " " << result << endl;
+ ret = 1;
+ // goto exit;
+ }
+
+ // counter test
+ {
+ // request a counter
+ cout << "Host: requesting a counter:" << endl;
+ uint32_t index = -1;
+ result = request_counter(enclave, &ret, &index);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: request_counter failed with " << ret << endl;
+ // goto exit;
+ }
+
+ // request a counter
+ cout << "Host: requesting a counter:" << endl;
+ uint32_t index2 = -1;
+ result = request_counter(enclave, &ret, &index2);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: request_counter failed with " << ret << endl;
+ // goto exit;
+ }
+
+ // get the counter
+ uint32_t value = -1;
+ result = get_counter(enclave, &ret, &index, 0, 0, nullptr, nullptr, nullptr, &value);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: get_counter failed with " << ret
+ << endl;
+ // goto exit;
+ }
+ cout << "Host: get the " << index << "th counter, value: " << value << endl;
+
+ // get the counter
+ result = get_counter(enclave, &ret, &index2, 0, 0, nullptr, nullptr, nullptr, &value);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: get_counter failed with " << ret
+ << endl;
+ // goto exit;
+ }
+ cout << "Host: get the " << index2 << "th counter, value: " << value << endl;
+
+ // get the counter
+ result = get_counter(enclave, &ret, &index, 0, 0, nullptr, nullptr, nullptr, &value);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: get_counter failed with " << ret
+ << endl;
+ // goto exit;
+ }
+ cout << "Host: get the " << index << "th counter, value: " << value << endl;
+ }
+
+ // random test
+ {
+ // generate random device rand
+ cout << "Host: generate random device rand:" << endl;
+ uint32_t rdrandNum = -1;
+ result = generate_rdrand(enclave, &ret, &rdrandNum);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: reset_prng failed with " << ret << endl;
+ // goto exit;
+ }
+ cout << "Host: get the rdrandNum: " << rdrandNum << endl;
+
+ // reset prng
+ cout << "Host: reset prng:" << endl;
+ uint32_t range = 50;
+ result = reset_prng(enclave, &ret, &rdrandNum, &range);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: reset_prng failed with " << ret << endl;
+ // goto exit;
+ }
+ cout << "Host: reset prng." << endl;
+
+ // generate random device rand
+ cout << "Host: generate random from prng:" << endl;
+ uint32_t randNum = -1;
+ for (size_t i = 0; i < 10; i++)
+ {
+ result = generate_rand(enclave, &ret, 0, 0, nullptr, nullptr, nullptr, &randNum);
+ cout << "Host: get the randNum: " << randNum << endl;
+ }
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: reset_prng failed with " << ret << endl;
+ // goto exit;
+ }
+ }
+
+/*
+ // decryptor test
+ {
+ cout << "Host: generate key" << endl;
+ size_t key_size = 2048;
+ result = generate_key(enclave, &ret, &key_size);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: generate_key failed with " << ret << endl;
+ // goto exit;
+ }
+
+ // Simulating binary data
+ unsigned char binary_data[] = {0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe};
+ int data_len = sizeof(binary_data) / sizeof(binary_data[0]);
+
+ unsigned char* key_buf;
+ size_t key_len = 0;
+ result = get_pubkey(enclave, &ret, &key_buf, &key_len);
+
+ BIO *bio = BIO_new_mem_buf(key_buf, -1);
+ RSA *pub_key = NULL;
+ PEM_read_bio_RSAPublicKey(bio, &pub_key, NULL, NULL);
+
+ size_t encrypted_len = RSA_size(pub_key);
+ unsigned char* encrypted_data = new unsigned char[encrypted_len]; // Initialize buffer
+ std::cout<<"Before RSA_public_encrypt.";
+ size_t result_len = RSA_public_encrypt(data_len, binary_data, encrypted_data,
+ pub_key, RSA_PKCS1_PADDING);
+ std::cout<<"After RSA_public_encrypt.";
+ cout << "Host: encrypt data" << endl;
+ BIO_free_all(bio);
+
+ cout << "Host: decrypt data" << endl;
+ unsigned char * decrypted_data;
+ size_t decrypted_len;
+ result = decrypt(enclave, &ret, encrypted_data, &decrypted_data, encrypted_len, &decrypted_len);
+ if (result != OE_OK)
+ {
+ ret = 1;
+ // goto exit;
+ }
+ if (ret != 0)
+ {
+ cerr << "Host: decrypt failed with " << ret << endl;
+ // goto exit;
+ }
+
+ printHex(binary_data, data_len);
+ printHex(decrypted_data, decrypted_len);
+ std::cout << "Decrypted data matches original: " << (memcmp(binary_data, decrypted_data, decrypted_len) == 0) << std::endl;
+
+ }
+*/
+
+exit:
+ cout << "Host: terminate the enclave" << endl;
+ cout << "Host: Sample completed successfully." << endl;
+ oe_terminate_enclave(enclave);
+ return ret;
+}
+
+
+// Command:
+// g++ host.cpp /root/code_dev/tee-code/sgx_cpp/build/host/sgx_cpp_u.c -I/root/code_dev/tee-code/sgx_cpp/build/host -I/opt/openenclave_0_17_0/include/ -L/opt/openenclave_0_17_0/lib/openenclave/host/ -loehost -lcrypto -ldl -lpthread
diff --git a/entrypoint.sh b/entrypoint.sh
new file mode 100755
index 000000000..a5ef6599c
--- /dev/null
+++ b/entrypoint.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+./service/tools/kv/server_tools/start_kv_service.sh
+tail -f /dev/null
\ No newline at end of file
diff --git a/executor/common/custom_query.h b/executor/common/custom_query.h
index e574a98dd..2c8bf4a7a 100644
--- a/executor/common/custom_query.h
+++ b/executor/common/custom_query.h
@@ -1,26 +1,20 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#pragma once
diff --git a/executor/common/mock_transaction_manager.h b/executor/common/mock_transaction_manager.h
index 86972f662..b4a6ba532 100644
--- a/executor/common/mock_transaction_manager.h
+++ b/executor/common/mock_transaction_manager.h
@@ -1,26 +1,20 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#pragma once
diff --git a/executor/common/transaction_manager.cpp b/executor/common/transaction_manager.cpp
index 854715863..74df05c9c 100644
--- a/executor/common/transaction_manager.cpp
+++ b/executor/common/transaction_manager.cpp
@@ -1,26 +1,20 @@
/*
- * Copyright (c) 2019-2022 ExpoLab, UC Davis
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "executor/common/transaction_manager.h"
@@ -41,6 +35,50 @@ std::unique_ptr TransactionManager::ExecuteData(
return std::make_unique