From e2b03486a9e0627bbc922681863b4661be8a4e3b Mon Sep 17 00:00:00 2001 From: Pi Delport Date: Mon, 4 Oct 2021 16:22:27 +0200 Subject: [PATCH] patchset: port to Rust SGX SDK (1.1.3) --- Cargo.toml | 23 +- rust-toolchain.toml | 5 + sgx-tests/.gitignore | 2 + sgx-tests/Makefile | 50 + sgx-tests/Makefile.toml | 8 + sgx-tests/README.md | 14 + sgx-tests/app/.gitignore | 1 + sgx-tests/app/Cargo.toml | 13 + sgx-tests/app/Makefile | 99 + sgx-tests/app/build.rs | 19 + sgx-tests/app/codegen/Enclave_u.c | 956 ++++++ sgx-tests/app/codegen/Enclave_u.h | 257 ++ sgx-tests/app/codegen/Enclave_u.rs | 7 + sgx-tests/app/src/main.rs | 46 + sgx-tests/app/src/safe_ecalls.rs | 13 + sgx-tests/buildenv.mk | 167 + sgx-tests/buildenv_sgx.mk | 49 + sgx-tests/enclave/.gitignore | 1 + sgx-tests/enclave/Cargo.toml | 30 + sgx-tests/enclave/Enclave.config.xml | 12 + sgx-tests/enclave/Enclave.edl | 10 + sgx-tests/enclave/Enclave.lds | 9 + sgx-tests/enclave/Makefile | 117 + sgx-tests/enclave/codegen/Enclave_t.c | 4477 +++++++++++++++++++++++++ sgx-tests/enclave/codegen/Enclave_t.h | 88 + sgx-tests/enclave/src/lib.rs | 42 + src/error.rs | 2 + src/lib.rs | 6 + tests/api.rs | 92 +- 29 files changed, 6567 insertions(+), 48 deletions(-) create mode 100644 rust-toolchain.toml create mode 100644 sgx-tests/.gitignore create mode 100644 sgx-tests/Makefile create mode 100644 sgx-tests/Makefile.toml create mode 100644 sgx-tests/README.md create mode 100644 sgx-tests/app/.gitignore create mode 100644 sgx-tests/app/Cargo.toml create mode 100644 sgx-tests/app/Makefile create mode 100644 sgx-tests/app/build.rs create mode 100644 sgx-tests/app/codegen/Enclave_u.c create mode 100644 sgx-tests/app/codegen/Enclave_u.h create mode 100644 sgx-tests/app/codegen/Enclave_u.rs create mode 100644 sgx-tests/app/src/main.rs create mode 100644 sgx-tests/app/src/safe_ecalls.rs create mode 100644 sgx-tests/buildenv.mk create mode 100644 sgx-tests/buildenv_sgx.mk create mode 100644 sgx-tests/enclave/.gitignore create mode 100644 sgx-tests/enclave/Cargo.toml create mode 100644 sgx-tests/enclave/Enclave.config.xml create mode 100644 sgx-tests/enclave/Enclave.edl create mode 100644 sgx-tests/enclave/Enclave.lds create mode 100644 sgx-tests/enclave/Makefile create mode 100644 sgx-tests/enclave/codegen/Enclave_t.c create mode 100644 sgx-tests/enclave/codegen/Enclave_t.h create mode 100644 sgx-tests/enclave/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index c6ffa11..5cb3061 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,28 @@ categories = ["cryptography::cryptocurrencies", "encoding"] edition = "2018" +# SGX: No test harness. +autotests = false + +[lib] +test = false +doctest = false +bench = false + + [dependencies] -base-x = "0.2.8" -ring = "0.16.18" +base-x = { version = "0.2.8", default-features = false } +ring = { version = "0.16.19", git = "https://github.com/mesalock-linux/ring-sgx" } + +sgx_tstd = { git = "https://github.com/apache/teaclave-sgx-sdk.git" } [dev-dependencies] -hex = "0.4.2" +hex = { version = "0.4.2", default-features = false, features = ["alloc"] } rand = "0.8.0" + + +[patch.'https://github.com/apache/teaclave-sgx-sdk.git'] +sgx_libc = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } +sgx_trts = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } +sgx_tstd = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..1dbea21 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,5 @@ +# https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file +[toolchain] +# SGX: algonaut 0.3.0+ requires Rust 1.51, for min_const_generics: +# https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1510-2021-03-25 +channel = "nightly-2021-03-25" diff --git a/sgx-tests/.gitignore b/sgx-tests/.gitignore new file mode 100644 index 0000000..438fbf5 --- /dev/null +++ b/sgx-tests/.gitignore @@ -0,0 +1,2 @@ +/build +/keys diff --git a/sgx-tests/Makefile b/sgx-tests/Makefile new file mode 100644 index 0000000..83195a9 --- /dev/null +++ b/sgx-tests/Makefile @@ -0,0 +1,50 @@ +# Dummy makefile, will call the host and enclave makefile when requested. + +SRC_U = app/ +SRC_T = enclave/ + +# Compilation process, will call the appropriate makefiles. + +all: host enclave + +host: + @echo "\033[32mRequest to compile the host part...\033[0m" + @make -C $(SRC_U) + +enclave: + @echo "\033[32mRequest to compile the enclave part...\033[0m" + @make -C $(SRC_T) + +clean: + @make -C $(SRC_U) clean + @make -C $(SRC_T) clean + +fclean: + @make -C $(SRC_U) fclean + @make -C $(SRC_T) fclean + +clean_host: + @make -C $(SRC_U) clean + +clean_enclave: + @make -C $(SRC_T) clean + +fclean_host: + @make -C $(SRC_U) fclean + +fclean_enclave: + @make -C $(SRC_T) fclean + +re_host: fclean_host host + +re_enclave: fclean_enclave enclave + +re: fclean all + +# Dummy rules to let make know that those rules are not files. + +.PHONY: host enclave clean clean_host clean_enclave fclean_host fclean_enclave fclean re re_host re_enclave + +.PHONY: run +run: all + @(cd build/bin && ./sgx-test-app) diff --git a/sgx-tests/Makefile.toml b/sgx-tests/Makefile.toml new file mode 100644 index 0000000..5a7c55d --- /dev/null +++ b/sgx-tests/Makefile.toml @@ -0,0 +1,8 @@ +[env] + +# https://github.com/sagiegurari/cargo-make#workspace-emulation +CARGO_MAKE_WORKSPACE_EMULATION = true +CARGO_MAKE_CRATE_WORKSPACE_MEMBERS = ["app", "enclave"] + +# https://github.com/sagiegurari/cargo-make#automatically-extend-workspace-makefile +CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true diff --git a/sgx-tests/README.md b/sgx-tests/README.md new file mode 100644 index 0000000..a7626a3 --- /dev/null +++ b/sgx-tests/README.md @@ -0,0 +1,14 @@ +# SGX tests for ripple-address-codec + +## Prerequisites + +* [Rust SGX SDK](https://github.com/apache/incubator-teaclave-sgx-sdk) + +## Running the tests + +With the SDK configured, this should work: + +``` +make +make run +``` diff --git a/sgx-tests/app/.gitignore b/sgx-tests/app/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/sgx-tests/app/.gitignore @@ -0,0 +1 @@ +/target diff --git a/sgx-tests/app/Cargo.toml b/sgx-tests/app/Cargo.toml new file mode 100644 index 0000000..1b41817 --- /dev/null +++ b/sgx-tests/app/Cargo.toml @@ -0,0 +1,13 @@ +[package] +# name matches APP_U in Makefile +name = "sgx-test-app" +version = "0.1.0" +edition = "2018" +authors = ["Pi Delport "] +build = "build.rs" + +[dependencies] +sgx_types = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } +sgx_urts = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } + +[patch.'https://github.com/apache/teaclave-sgx-sdk.git'] diff --git a/sgx-tests/app/Makefile b/sgx-tests/app/Makefile new file mode 100644 index 0000000..3e739bc --- /dev/null +++ b/sgx-tests/app/Makefile @@ -0,0 +1,99 @@ +# Makefile settings - Host part + +LIB = ../build/lib/ +BIN = ../build/bin/ +# APP_U matches name in Cargo.toml +APP_U = sgx-test-app +APP_T = enclave.so +NAME_U = libEnclave_u.a +SRC_U = ./ +CODEGEN_U = $(SRC_U)/codegen/ +SRC_T = ../enclave/ +OBJ_U = ../build/obj/ +FLAGS = -Wall -Wextra +GCC_STEP1_U = -I $(CODEGEN_U) -I./include -I$(SGX_SDK)/include -I$(CUSTOM_EDL_PATH) -fPIC -Wno-attributes $(SGX_COMMON_CFLAGS) +FILES_U = Enclave_u.c +FILES_U_H = Enclave_u.h +SGX_ARCH = x64 +TRTS_LIB = sgx_trts +SERVICE_LIB = sgx_tservice +# Addprefix dependant variables, no need to change those +OUTPUT_U = $(FILES_U:.c=.o) +BIN_U = $(addprefix $(BIN), $(APP_U)) +NAME_U_D = $(addprefix $(LIB), $(NAME_U)) +FILES_U_F=$(addprefix $(CODEGEN_U), $(FILES_U)) +FILES_U_H_F=$(addprefix $(CODEGEN_U), $(FILES_U_H)) +OUTPUT_W_FU=$(addprefix $(OBJ_U), $(OUTPUT_U)) + +# All Rust and other source files that the Cargo build depends on. +FILES_RUST_F = Cargo.toml Cargo.lock build.rs $(shell find src -name '*.rs') $(CODEGEN_U)Enclave_u.rs + +# Contains compilation rules for the enclave part + +include ../buildenv.mk +include ../buildenv_sgx.mk + +# Custom libraries, EDL paths. Needs to be specified with make (CUSTOM_EDL_PATH) (CUSTOM_COMMON_PATH) + +# Compilation process, we set up all the dependencies needed to have the correct order of build, and avoid relink + +all: $(BIN_U) + +$(FILES_U_F): $(SGX_EDGER8R) $(SRC_T)/Enclave.edl + @echo "\033[32mGenerating untrusted SGX C edl files...\033[0m" + @$(SGX_EDGER8R) --untrusted $(SRC_T)/Enclave.edl --search-path $(SGX_SDK)/include --search-path $(CUSTOM_EDL_PATH) --untrusted-dir $(CODEGEN_U) + +$(NAME_U_D): $(FILES_U_F) $(OUTPUT_W_FU) + @echo "\033[32mBuilding untrusted C edl static library...\033[0m" + @mkdir -p $(LIB) + @$(AR) rcsD $@ $(OUTPUT_W_FU) + +$(OBJ_U)%.o:$(CODEGEN_U)%.c + @mkdir -p $(OBJ_U) + @echo "\033[32m$?: Build in progress...\033[0m" + @$(CC) $(FLAGS) $(GCC_STEP1_U) -o $@ -c $? + +# We print the compilation mode we're in (hardware/software mode), just as a reminder. + +$(BIN_U): $(NAME_U_D) $(FILES_RUST_F) $(FILES_U_H_F) +ifeq ($(SGX_MODE), SW) + @echo "\033[32mSoftware / Simulation mode\033[0m" +else + @echo "\033[32mHardware mode\033[0m" +endif + @echo "\033[32mStarting cargo to build the host...\033[0m" + @cd $(SRC_U) && SGX_SDK=$(SGX_SDK) cargo build --release + @echo "\033[32mCopying the host to the correct location... ($(BIN_U))\033[0m" + @mkdir -p $(BIN) + @cp $(SRC_U)/target/release/$(APP_U) $(BIN) + +$(CODEGEN_U)Enclave_u.rs: $(CODEGEN_U)Enclave_u.h + @echo "\033[32mGenerating Rust bindings: $@\033[0m" + @bindgen \ + --no-recursive-allowlist \ + --raw-line 'use sgx_types::*;' \ + --allowlist-function run_tests_ecall \ + --output $@ \ + $? \ + -- -I$(SGX_SDK)/include -I$(CUSTOM_EDL_PATH) + +clean: c_clean + @rm -rf $(OBJ_U) + @echo "\033[32mObject files deleted\033[0m" + +fclean: clean fclean_host + +fclean_host: + @echo "\033[32mBinary file $(BIN_U) deleted\033[0m" + @rm -f $(BIN_U) + @rm -f $(NAME_U_D) + @cargo clean + +c_clean: + @echo "\033[32mC edl generated files deleted\033[0m" + @rm -rf $(FILES_U_F) + @rm -rf $(FILES_U_H_F) + +re: fclean all + +.PHONY: all clean c_clean fclean re fclean_host diff --git a/sgx-tests/app/build.rs b/sgx-tests/app/build.rs new file mode 100644 index 0000000..6fce49f --- /dev/null +++ b/sgx-tests/app/build.rs @@ -0,0 +1,19 @@ +use std::env; + +fn main() { + println!("cargo:rerun-if-env-changed=SGX_SDK"); + println!("cargo:rerun-if-env-changed=SGX_MODE"); + + let sdk_dir = env::var("SGX_SDK").unwrap_or_else(|_| "/opt/sgxsdk".to_string()); + let is_sim = env::var("SGX_MODE").unwrap_or_else(|_| "HW".to_string()); + + println!("cargo:rustc-link-search=native=../build/lib"); + println!("cargo:rustc-link-lib=static=Enclave_u"); + + println!("cargo:rustc-link-search=native={}/lib64", sdk_dir); + match is_sim.as_ref() { + "SW" => println!("cargo:rustc-link-lib=dylib=sgx_urts_sim"), + "HW" => println!("cargo:rustc-link-lib=dylib=sgx_urts"), + _ => println!("cargo:rustc-link-lib=dylib=sgx_urts"), // Treat undefined as HW + } +} diff --git a/sgx-tests/app/codegen/Enclave_u.c b/sgx-tests/app/codegen/Enclave_u.c new file mode 100644 index 0000000..2355855 --- /dev/null +++ b/sgx-tests/app/codegen/Enclave_u.c @@ -0,0 +1,956 @@ +#include "Enclave_u.h" +#include + +typedef struct ms_run_tests_ecall_t { + size_t ms_retval; +} ms_run_tests_ecall_t; + +typedef struct ms_t_global_init_ecall_t { + uint64_t ms_id; + const uint8_t* ms_path; + size_t ms_len; +} ms_t_global_init_ecall_t; + +typedef struct ms_u_thread_set_event_ocall_t { + int ms_retval; + int* ms_error; + const void* ms_tcs; +} ms_u_thread_set_event_ocall_t; + +typedef struct ms_u_thread_wait_event_ocall_t { + int ms_retval; + int* ms_error; + const void* ms_tcs; + const struct timespec* ms_timeout; +} ms_u_thread_wait_event_ocall_t; + +typedef struct ms_u_thread_set_multiple_events_ocall_t { + int ms_retval; + int* ms_error; + const void** ms_tcss; + int ms_total; +} ms_u_thread_set_multiple_events_ocall_t; + +typedef struct ms_u_thread_setwait_events_ocall_t { + int ms_retval; + int* ms_error; + const void* ms_waiter_tcs; + const void* ms_self_tcs; + const struct timespec* ms_timeout; +} ms_u_thread_setwait_events_ocall_t; + +typedef struct ms_u_clock_gettime_ocall_t { + int ms_retval; + int* ms_error; + int ms_clk_id; + struct timespec* ms_tp; +} ms_u_clock_gettime_ocall_t; + +typedef struct ms_u_read_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + void* ms_buf; + size_t ms_count; +} ms_u_read_ocall_t; + +typedef struct ms_u_pread64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + void* ms_buf; + size_t ms_count; + int64_t ms_offset; +} ms_u_pread64_ocall_t; + +typedef struct ms_u_readv_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; +} ms_u_readv_ocall_t; + +typedef struct ms_u_preadv64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; + int64_t ms_offset; +} ms_u_preadv64_ocall_t; + +typedef struct ms_u_write_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const void* ms_buf; + size_t ms_count; +} ms_u_write_ocall_t; + +typedef struct ms_u_pwrite64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const void* ms_buf; + size_t ms_count; + int64_t ms_offset; +} ms_u_pwrite64_ocall_t; + +typedef struct ms_u_writev_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; +} ms_u_writev_ocall_t; + +typedef struct ms_u_pwritev64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; + int64_t ms_offset; +} ms_u_pwritev64_ocall_t; + +typedef struct ms_u_fcntl_arg0_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_cmd; +} ms_u_fcntl_arg0_ocall_t; + +typedef struct ms_u_fcntl_arg1_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_cmd; + int ms_arg; +} ms_u_fcntl_arg1_ocall_t; + +typedef struct ms_u_ioctl_arg0_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_request; +} ms_u_ioctl_arg0_ocall_t; + +typedef struct ms_u_ioctl_arg1_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_request; + int* ms_arg; +} ms_u_ioctl_arg1_ocall_t; + +typedef struct ms_u_close_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; +} ms_u_close_ocall_t; + +typedef struct ms_u_malloc_ocall_t { + void* ms_retval; + int* ms_error; + size_t ms_size; +} ms_u_malloc_ocall_t; + +typedef struct ms_u_free_ocall_t { + void* ms_p; +} ms_u_free_ocall_t; + +typedef struct ms_u_mmap_ocall_t { + void* ms_retval; + int* ms_error; + void* ms_start; + size_t ms_length; + int ms_prot; + int ms_flags; + int ms_fd; + int64_t ms_offset; +} ms_u_mmap_ocall_t; + +typedef struct ms_u_munmap_ocall_t { + int ms_retval; + int* ms_error; + void* ms_start; + size_t ms_length; +} ms_u_munmap_ocall_t; + +typedef struct ms_u_msync_ocall_t { + int ms_retval; + int* ms_error; + void* ms_addr; + size_t ms_length; + int ms_flags; +} ms_u_msync_ocall_t; + +typedef struct ms_u_mprotect_ocall_t { + int ms_retval; + int* ms_error; + void* ms_addr; + size_t ms_length; + int ms_prot; +} ms_u_mprotect_ocall_t; + +typedef struct ms_u_open_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; + int ms_flags; +} ms_u_open_ocall_t; + +typedef struct ms_u_open64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + int ms_oflag; + int ms_mode; +} ms_u_open64_ocall_t; + +typedef struct ms_u_fstat_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + struct stat_t* ms_buf; +} ms_u_fstat_ocall_t; + +typedef struct ms_u_fstat64_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + struct stat64_t* ms_buf; +} ms_u_fstat64_ocall_t; + +typedef struct ms_u_stat_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat_t* ms_buf; +} ms_u_stat_ocall_t; + +typedef struct ms_u_stat64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat64_t* ms_buf; +} ms_u_stat64_ocall_t; + +typedef struct ms_u_lstat_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat_t* ms_buf; +} ms_u_lstat_ocall_t; + +typedef struct ms_u_lstat64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat64_t* ms_buf; +} ms_u_lstat64_ocall_t; + +typedef struct ms_u_lseek_ocall_t { + uint64_t ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_offset; + int ms_whence; +} ms_u_lseek_ocall_t; + +typedef struct ms_u_lseek64_ocall_t { + int64_t ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_offset; + int ms_whence; +} ms_u_lseek64_ocall_t; + +typedef struct ms_u_ftruncate_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_length; +} ms_u_ftruncate_ocall_t; + +typedef struct ms_u_ftruncate64_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_length; +} ms_u_ftruncate64_ocall_t; + +typedef struct ms_u_truncate_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + int64_t ms_length; +} ms_u_truncate_ocall_t; + +typedef struct ms_u_truncate64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + int64_t ms_length; +} ms_u_truncate64_ocall_t; + +typedef struct ms_u_fsync_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; +} ms_u_fsync_ocall_t; + +typedef struct ms_u_fdatasync_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; +} ms_u_fdatasync_ocall_t; + +typedef struct ms_u_fchmod_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + uint32_t ms_mode; +} ms_u_fchmod_ocall_t; + +typedef struct ms_u_unlink_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_unlink_ocall_t; + +typedef struct ms_u_link_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_oldpath; + const char* ms_newpath; +} ms_u_link_ocall_t; + +typedef struct ms_u_rename_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_oldpath; + const char* ms_newpath; +} ms_u_rename_ocall_t; + +typedef struct ms_u_chmod_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + uint32_t ms_mode; +} ms_u_chmod_ocall_t; + +typedef struct ms_u_readlink_ocall_t { + size_t ms_retval; + int* ms_error; + const char* ms_path; + char* ms_buf; + size_t ms_bufsz; +} ms_u_readlink_ocall_t; + +typedef struct ms_u_symlink_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path1; + const char* ms_path2; +} ms_u_symlink_ocall_t; + +typedef struct ms_u_realpath_ocall_t { + char* ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_realpath_ocall_t; + +typedef struct ms_u_mkdir_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; + uint32_t ms_mode; +} ms_u_mkdir_ocall_t; + +typedef struct ms_u_rmdir_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_rmdir_ocall_t; + +typedef struct ms_u_opendir_ocall_t { + void* ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_opendir_ocall_t; + +typedef struct ms_u_readdir64_r_ocall_t { + int ms_retval; + void* ms_dirp; + struct dirent64_t* ms_entry; + struct dirent64_t** ms_result; +} ms_u_readdir64_r_ocall_t; + +typedef struct ms_u_closedir_ocall_t { + int ms_retval; + int* ms_error; + void* ms_dirp; +} ms_u_closedir_ocall_t; + +typedef struct ms_u_dirfd_ocall_t { + int ms_retval; + int* ms_error; + void* ms_dirp; +} ms_u_dirfd_ocall_t; + +typedef struct ms_u_fstatat64_ocall_t { + int ms_retval; + int* ms_error; + int ms_dirfd; + const char* ms_pathname; + struct stat64_t* ms_buf; + int ms_flags; +} ms_u_fstatat64_ocall_t; + +typedef struct ms_sgx_oc_cpuidex_t { + int* ms_cpuinfo; + int ms_leaf; + int ms_subleaf; +} ms_sgx_oc_cpuidex_t; + +static sgx_status_t SGX_CDECL Enclave_u_thread_set_event_ocall(void* pms) +{ + ms_u_thread_set_event_ocall_t* ms = SGX_CAST(ms_u_thread_set_event_ocall_t*, pms); + ms->ms_retval = u_thread_set_event_ocall(ms->ms_error, ms->ms_tcs); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_thread_wait_event_ocall(void* pms) +{ + ms_u_thread_wait_event_ocall_t* ms = SGX_CAST(ms_u_thread_wait_event_ocall_t*, pms); + ms->ms_retval = u_thread_wait_event_ocall(ms->ms_error, ms->ms_tcs, ms->ms_timeout); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_thread_set_multiple_events_ocall(void* pms) +{ + ms_u_thread_set_multiple_events_ocall_t* ms = SGX_CAST(ms_u_thread_set_multiple_events_ocall_t*, pms); + ms->ms_retval = u_thread_set_multiple_events_ocall(ms->ms_error, ms->ms_tcss, ms->ms_total); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_thread_setwait_events_ocall(void* pms) +{ + ms_u_thread_setwait_events_ocall_t* ms = SGX_CAST(ms_u_thread_setwait_events_ocall_t*, pms); + ms->ms_retval = u_thread_setwait_events_ocall(ms->ms_error, ms->ms_waiter_tcs, ms->ms_self_tcs, ms->ms_timeout); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_clock_gettime_ocall(void* pms) +{ + ms_u_clock_gettime_ocall_t* ms = SGX_CAST(ms_u_clock_gettime_ocall_t*, pms); + ms->ms_retval = u_clock_gettime_ocall(ms->ms_error, ms->ms_clk_id, ms->ms_tp); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_read_ocall(void* pms) +{ + ms_u_read_ocall_t* ms = SGX_CAST(ms_u_read_ocall_t*, pms); + ms->ms_retval = u_read_ocall(ms->ms_error, ms->ms_fd, ms->ms_buf, ms->ms_count); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_pread64_ocall(void* pms) +{ + ms_u_pread64_ocall_t* ms = SGX_CAST(ms_u_pread64_ocall_t*, pms); + ms->ms_retval = u_pread64_ocall(ms->ms_error, ms->ms_fd, ms->ms_buf, ms->ms_count, ms->ms_offset); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_readv_ocall(void* pms) +{ + ms_u_readv_ocall_t* ms = SGX_CAST(ms_u_readv_ocall_t*, pms); + ms->ms_retval = u_readv_ocall(ms->ms_error, ms->ms_fd, ms->ms_iov, ms->ms_iovcnt); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_preadv64_ocall(void* pms) +{ + ms_u_preadv64_ocall_t* ms = SGX_CAST(ms_u_preadv64_ocall_t*, pms); + ms->ms_retval = u_preadv64_ocall(ms->ms_error, ms->ms_fd, ms->ms_iov, ms->ms_iovcnt, ms->ms_offset); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_write_ocall(void* pms) +{ + ms_u_write_ocall_t* ms = SGX_CAST(ms_u_write_ocall_t*, pms); + ms->ms_retval = u_write_ocall(ms->ms_error, ms->ms_fd, ms->ms_buf, ms->ms_count); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_pwrite64_ocall(void* pms) +{ + ms_u_pwrite64_ocall_t* ms = SGX_CAST(ms_u_pwrite64_ocall_t*, pms); + ms->ms_retval = u_pwrite64_ocall(ms->ms_error, ms->ms_fd, ms->ms_buf, ms->ms_count, ms->ms_offset); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_writev_ocall(void* pms) +{ + ms_u_writev_ocall_t* ms = SGX_CAST(ms_u_writev_ocall_t*, pms); + ms->ms_retval = u_writev_ocall(ms->ms_error, ms->ms_fd, ms->ms_iov, ms->ms_iovcnt); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_pwritev64_ocall(void* pms) +{ + ms_u_pwritev64_ocall_t* ms = SGX_CAST(ms_u_pwritev64_ocall_t*, pms); + ms->ms_retval = u_pwritev64_ocall(ms->ms_error, ms->ms_fd, ms->ms_iov, ms->ms_iovcnt, ms->ms_offset); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fcntl_arg0_ocall(void* pms) +{ + ms_u_fcntl_arg0_ocall_t* ms = SGX_CAST(ms_u_fcntl_arg0_ocall_t*, pms); + ms->ms_retval = u_fcntl_arg0_ocall(ms->ms_error, ms->ms_fd, ms->ms_cmd); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fcntl_arg1_ocall(void* pms) +{ + ms_u_fcntl_arg1_ocall_t* ms = SGX_CAST(ms_u_fcntl_arg1_ocall_t*, pms); + ms->ms_retval = u_fcntl_arg1_ocall(ms->ms_error, ms->ms_fd, ms->ms_cmd, ms->ms_arg); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_ioctl_arg0_ocall(void* pms) +{ + ms_u_ioctl_arg0_ocall_t* ms = SGX_CAST(ms_u_ioctl_arg0_ocall_t*, pms); + ms->ms_retval = u_ioctl_arg0_ocall(ms->ms_error, ms->ms_fd, ms->ms_request); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_ioctl_arg1_ocall(void* pms) +{ + ms_u_ioctl_arg1_ocall_t* ms = SGX_CAST(ms_u_ioctl_arg1_ocall_t*, pms); + ms->ms_retval = u_ioctl_arg1_ocall(ms->ms_error, ms->ms_fd, ms->ms_request, ms->ms_arg); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_close_ocall(void* pms) +{ + ms_u_close_ocall_t* ms = SGX_CAST(ms_u_close_ocall_t*, pms); + ms->ms_retval = u_close_ocall(ms->ms_error, ms->ms_fd); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_malloc_ocall(void* pms) +{ + ms_u_malloc_ocall_t* ms = SGX_CAST(ms_u_malloc_ocall_t*, pms); + ms->ms_retval = u_malloc_ocall(ms->ms_error, ms->ms_size); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_free_ocall(void* pms) +{ + ms_u_free_ocall_t* ms = SGX_CAST(ms_u_free_ocall_t*, pms); + u_free_ocall(ms->ms_p); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_mmap_ocall(void* pms) +{ + ms_u_mmap_ocall_t* ms = SGX_CAST(ms_u_mmap_ocall_t*, pms); + ms->ms_retval = u_mmap_ocall(ms->ms_error, ms->ms_start, ms->ms_length, ms->ms_prot, ms->ms_flags, ms->ms_fd, ms->ms_offset); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_munmap_ocall(void* pms) +{ + ms_u_munmap_ocall_t* ms = SGX_CAST(ms_u_munmap_ocall_t*, pms); + ms->ms_retval = u_munmap_ocall(ms->ms_error, ms->ms_start, ms->ms_length); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_msync_ocall(void* pms) +{ + ms_u_msync_ocall_t* ms = SGX_CAST(ms_u_msync_ocall_t*, pms); + ms->ms_retval = u_msync_ocall(ms->ms_error, ms->ms_addr, ms->ms_length, ms->ms_flags); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_mprotect_ocall(void* pms) +{ + ms_u_mprotect_ocall_t* ms = SGX_CAST(ms_u_mprotect_ocall_t*, pms); + ms->ms_retval = u_mprotect_ocall(ms->ms_error, ms->ms_addr, ms->ms_length, ms->ms_prot); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_open_ocall(void* pms) +{ + ms_u_open_ocall_t* ms = SGX_CAST(ms_u_open_ocall_t*, pms); + ms->ms_retval = u_open_ocall(ms->ms_error, ms->ms_pathname, ms->ms_flags); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_open64_ocall(void* pms) +{ + ms_u_open64_ocall_t* ms = SGX_CAST(ms_u_open64_ocall_t*, pms); + ms->ms_retval = u_open64_ocall(ms->ms_error, ms->ms_path, ms->ms_oflag, ms->ms_mode); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fstat_ocall(void* pms) +{ + ms_u_fstat_ocall_t* ms = SGX_CAST(ms_u_fstat_ocall_t*, pms); + ms->ms_retval = u_fstat_ocall(ms->ms_error, ms->ms_fd, ms->ms_buf); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fstat64_ocall(void* pms) +{ + ms_u_fstat64_ocall_t* ms = SGX_CAST(ms_u_fstat64_ocall_t*, pms); + ms->ms_retval = u_fstat64_ocall(ms->ms_error, ms->ms_fd, ms->ms_buf); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_stat_ocall(void* pms) +{ + ms_u_stat_ocall_t* ms = SGX_CAST(ms_u_stat_ocall_t*, pms); + ms->ms_retval = u_stat_ocall(ms->ms_error, ms->ms_path, ms->ms_buf); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_stat64_ocall(void* pms) +{ + ms_u_stat64_ocall_t* ms = SGX_CAST(ms_u_stat64_ocall_t*, pms); + ms->ms_retval = u_stat64_ocall(ms->ms_error, ms->ms_path, ms->ms_buf); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_lstat_ocall(void* pms) +{ + ms_u_lstat_ocall_t* ms = SGX_CAST(ms_u_lstat_ocall_t*, pms); + ms->ms_retval = u_lstat_ocall(ms->ms_error, ms->ms_path, ms->ms_buf); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_lstat64_ocall(void* pms) +{ + ms_u_lstat64_ocall_t* ms = SGX_CAST(ms_u_lstat64_ocall_t*, pms); + ms->ms_retval = u_lstat64_ocall(ms->ms_error, ms->ms_path, ms->ms_buf); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_lseek_ocall(void* pms) +{ + ms_u_lseek_ocall_t* ms = SGX_CAST(ms_u_lseek_ocall_t*, pms); + ms->ms_retval = u_lseek_ocall(ms->ms_error, ms->ms_fd, ms->ms_offset, ms->ms_whence); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_lseek64_ocall(void* pms) +{ + ms_u_lseek64_ocall_t* ms = SGX_CAST(ms_u_lseek64_ocall_t*, pms); + ms->ms_retval = u_lseek64_ocall(ms->ms_error, ms->ms_fd, ms->ms_offset, ms->ms_whence); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_ftruncate_ocall(void* pms) +{ + ms_u_ftruncate_ocall_t* ms = SGX_CAST(ms_u_ftruncate_ocall_t*, pms); + ms->ms_retval = u_ftruncate_ocall(ms->ms_error, ms->ms_fd, ms->ms_length); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_ftruncate64_ocall(void* pms) +{ + ms_u_ftruncate64_ocall_t* ms = SGX_CAST(ms_u_ftruncate64_ocall_t*, pms); + ms->ms_retval = u_ftruncate64_ocall(ms->ms_error, ms->ms_fd, ms->ms_length); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_truncate_ocall(void* pms) +{ + ms_u_truncate_ocall_t* ms = SGX_CAST(ms_u_truncate_ocall_t*, pms); + ms->ms_retval = u_truncate_ocall(ms->ms_error, ms->ms_path, ms->ms_length); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_truncate64_ocall(void* pms) +{ + ms_u_truncate64_ocall_t* ms = SGX_CAST(ms_u_truncate64_ocall_t*, pms); + ms->ms_retval = u_truncate64_ocall(ms->ms_error, ms->ms_path, ms->ms_length); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fsync_ocall(void* pms) +{ + ms_u_fsync_ocall_t* ms = SGX_CAST(ms_u_fsync_ocall_t*, pms); + ms->ms_retval = u_fsync_ocall(ms->ms_error, ms->ms_fd); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fdatasync_ocall(void* pms) +{ + ms_u_fdatasync_ocall_t* ms = SGX_CAST(ms_u_fdatasync_ocall_t*, pms); + ms->ms_retval = u_fdatasync_ocall(ms->ms_error, ms->ms_fd); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fchmod_ocall(void* pms) +{ + ms_u_fchmod_ocall_t* ms = SGX_CAST(ms_u_fchmod_ocall_t*, pms); + ms->ms_retval = u_fchmod_ocall(ms->ms_error, ms->ms_fd, ms->ms_mode); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_unlink_ocall(void* pms) +{ + ms_u_unlink_ocall_t* ms = SGX_CAST(ms_u_unlink_ocall_t*, pms); + ms->ms_retval = u_unlink_ocall(ms->ms_error, ms->ms_pathname); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_link_ocall(void* pms) +{ + ms_u_link_ocall_t* ms = SGX_CAST(ms_u_link_ocall_t*, pms); + ms->ms_retval = u_link_ocall(ms->ms_error, ms->ms_oldpath, ms->ms_newpath); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_rename_ocall(void* pms) +{ + ms_u_rename_ocall_t* ms = SGX_CAST(ms_u_rename_ocall_t*, pms); + ms->ms_retval = u_rename_ocall(ms->ms_error, ms->ms_oldpath, ms->ms_newpath); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_chmod_ocall(void* pms) +{ + ms_u_chmod_ocall_t* ms = SGX_CAST(ms_u_chmod_ocall_t*, pms); + ms->ms_retval = u_chmod_ocall(ms->ms_error, ms->ms_path, ms->ms_mode); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_readlink_ocall(void* pms) +{ + ms_u_readlink_ocall_t* ms = SGX_CAST(ms_u_readlink_ocall_t*, pms); + ms->ms_retval = u_readlink_ocall(ms->ms_error, ms->ms_path, ms->ms_buf, ms->ms_bufsz); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_symlink_ocall(void* pms) +{ + ms_u_symlink_ocall_t* ms = SGX_CAST(ms_u_symlink_ocall_t*, pms); + ms->ms_retval = u_symlink_ocall(ms->ms_error, ms->ms_path1, ms->ms_path2); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_realpath_ocall(void* pms) +{ + ms_u_realpath_ocall_t* ms = SGX_CAST(ms_u_realpath_ocall_t*, pms); + ms->ms_retval = u_realpath_ocall(ms->ms_error, ms->ms_pathname); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_mkdir_ocall(void* pms) +{ + ms_u_mkdir_ocall_t* ms = SGX_CAST(ms_u_mkdir_ocall_t*, pms); + ms->ms_retval = u_mkdir_ocall(ms->ms_error, ms->ms_pathname, ms->ms_mode); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_rmdir_ocall(void* pms) +{ + ms_u_rmdir_ocall_t* ms = SGX_CAST(ms_u_rmdir_ocall_t*, pms); + ms->ms_retval = u_rmdir_ocall(ms->ms_error, ms->ms_pathname); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_opendir_ocall(void* pms) +{ + ms_u_opendir_ocall_t* ms = SGX_CAST(ms_u_opendir_ocall_t*, pms); + ms->ms_retval = u_opendir_ocall(ms->ms_error, ms->ms_pathname); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_readdir64_r_ocall(void* pms) +{ + ms_u_readdir64_r_ocall_t* ms = SGX_CAST(ms_u_readdir64_r_ocall_t*, pms); + ms->ms_retval = u_readdir64_r_ocall(ms->ms_dirp, ms->ms_entry, ms->ms_result); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_closedir_ocall(void* pms) +{ + ms_u_closedir_ocall_t* ms = SGX_CAST(ms_u_closedir_ocall_t*, pms); + ms->ms_retval = u_closedir_ocall(ms->ms_error, ms->ms_dirp); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_dirfd_ocall(void* pms) +{ + ms_u_dirfd_ocall_t* ms = SGX_CAST(ms_u_dirfd_ocall_t*, pms); + ms->ms_retval = u_dirfd_ocall(ms->ms_error, ms->ms_dirp); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_u_fstatat64_ocall(void* pms) +{ + ms_u_fstatat64_ocall_t* ms = SGX_CAST(ms_u_fstatat64_ocall_t*, pms); + ms->ms_retval = u_fstatat64_ocall(ms->ms_error, ms->ms_dirfd, ms->ms_pathname, ms->ms_buf, ms->ms_flags); + + return SGX_SUCCESS; +} + +static sgx_status_t SGX_CDECL Enclave_sgx_oc_cpuidex(void* pms) +{ + ms_sgx_oc_cpuidex_t* ms = SGX_CAST(ms_sgx_oc_cpuidex_t*, pms); + sgx_oc_cpuidex(ms->ms_cpuinfo, ms->ms_leaf, ms->ms_subleaf); + + return SGX_SUCCESS; +} + +static const struct { + size_t nr_ocall; + void * table[56]; +} ocall_table_Enclave = { + 56, + { + (void*)Enclave_u_thread_set_event_ocall, + (void*)Enclave_u_thread_wait_event_ocall, + (void*)Enclave_u_thread_set_multiple_events_ocall, + (void*)Enclave_u_thread_setwait_events_ocall, + (void*)Enclave_u_clock_gettime_ocall, + (void*)Enclave_u_read_ocall, + (void*)Enclave_u_pread64_ocall, + (void*)Enclave_u_readv_ocall, + (void*)Enclave_u_preadv64_ocall, + (void*)Enclave_u_write_ocall, + (void*)Enclave_u_pwrite64_ocall, + (void*)Enclave_u_writev_ocall, + (void*)Enclave_u_pwritev64_ocall, + (void*)Enclave_u_fcntl_arg0_ocall, + (void*)Enclave_u_fcntl_arg1_ocall, + (void*)Enclave_u_ioctl_arg0_ocall, + (void*)Enclave_u_ioctl_arg1_ocall, + (void*)Enclave_u_close_ocall, + (void*)Enclave_u_malloc_ocall, + (void*)Enclave_u_free_ocall, + (void*)Enclave_u_mmap_ocall, + (void*)Enclave_u_munmap_ocall, + (void*)Enclave_u_msync_ocall, + (void*)Enclave_u_mprotect_ocall, + (void*)Enclave_u_open_ocall, + (void*)Enclave_u_open64_ocall, + (void*)Enclave_u_fstat_ocall, + (void*)Enclave_u_fstat64_ocall, + (void*)Enclave_u_stat_ocall, + (void*)Enclave_u_stat64_ocall, + (void*)Enclave_u_lstat_ocall, + (void*)Enclave_u_lstat64_ocall, + (void*)Enclave_u_lseek_ocall, + (void*)Enclave_u_lseek64_ocall, + (void*)Enclave_u_ftruncate_ocall, + (void*)Enclave_u_ftruncate64_ocall, + (void*)Enclave_u_truncate_ocall, + (void*)Enclave_u_truncate64_ocall, + (void*)Enclave_u_fsync_ocall, + (void*)Enclave_u_fdatasync_ocall, + (void*)Enclave_u_fchmod_ocall, + (void*)Enclave_u_unlink_ocall, + (void*)Enclave_u_link_ocall, + (void*)Enclave_u_rename_ocall, + (void*)Enclave_u_chmod_ocall, + (void*)Enclave_u_readlink_ocall, + (void*)Enclave_u_symlink_ocall, + (void*)Enclave_u_realpath_ocall, + (void*)Enclave_u_mkdir_ocall, + (void*)Enclave_u_rmdir_ocall, + (void*)Enclave_u_opendir_ocall, + (void*)Enclave_u_readdir64_r_ocall, + (void*)Enclave_u_closedir_ocall, + (void*)Enclave_u_dirfd_ocall, + (void*)Enclave_u_fstatat64_ocall, + (void*)Enclave_sgx_oc_cpuidex, + } +}; +sgx_status_t run_tests_ecall(sgx_enclave_id_t eid, size_t* retval) +{ + sgx_status_t status; + ms_run_tests_ecall_t ms; + status = sgx_ecall(eid, 0, &ocall_table_Enclave, &ms); + if (status == SGX_SUCCESS && retval) *retval = ms.ms_retval; + return status; +} + +sgx_status_t t_global_init_ecall(sgx_enclave_id_t eid, uint64_t id, const uint8_t* path, size_t len) +{ + sgx_status_t status; + ms_t_global_init_ecall_t ms; + ms.ms_id = id; + ms.ms_path = path; + ms.ms_len = len; + status = sgx_ecall(eid, 1, &ocall_table_Enclave, &ms); + return status; +} + +sgx_status_t t_global_exit_ecall(sgx_enclave_id_t eid) +{ + sgx_status_t status; + status = sgx_ecall(eid, 2, &ocall_table_Enclave, NULL); + return status; +} + diff --git a/sgx-tests/app/codegen/Enclave_u.h b/sgx-tests/app/codegen/Enclave_u.h new file mode 100644 index 0000000..ec8e4c8 --- /dev/null +++ b/sgx-tests/app/codegen/Enclave_u.h @@ -0,0 +1,257 @@ +#ifndef ENCLAVE_U_H__ +#define ENCLAVE_U_H__ + +#include +#include +#include +#include +#include "sgx_edger8r.h" /* for sgx_status_t etc. */ + +#include "time.h" +#include "inc/stat.h" +#include "sys/uio.h" +#include "inc/stat.h" +#include "inc/dirent.h" + +#include /* for size_t */ + +#define SGX_CAST(type, item) ((type)(item)) + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef U_THREAD_SET_EVENT_OCALL_DEFINED__ +#define U_THREAD_SET_EVENT_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_thread_set_event_ocall, (int* error, const void* tcs)); +#endif +#ifndef U_THREAD_WAIT_EVENT_OCALL_DEFINED__ +#define U_THREAD_WAIT_EVENT_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_thread_wait_event_ocall, (int* error, const void* tcs, const struct timespec* timeout)); +#endif +#ifndef U_THREAD_SET_MULTIPLE_EVENTS_OCALL_DEFINED__ +#define U_THREAD_SET_MULTIPLE_EVENTS_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_thread_set_multiple_events_ocall, (int* error, const void** tcss, int total)); +#endif +#ifndef U_THREAD_SETWAIT_EVENTS_OCALL_DEFINED__ +#define U_THREAD_SETWAIT_EVENTS_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_thread_setwait_events_ocall, (int* error, const void* waiter_tcs, const void* self_tcs, const struct timespec* timeout)); +#endif +#ifndef U_CLOCK_GETTIME_OCALL_DEFINED__ +#define U_CLOCK_GETTIME_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_clock_gettime_ocall, (int* error, int clk_id, struct timespec* tp)); +#endif +#ifndef U_READ_OCALL_DEFINED__ +#define U_READ_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_read_ocall, (int* error, int fd, void* buf, size_t count)); +#endif +#ifndef U_PREAD64_OCALL_DEFINED__ +#define U_PREAD64_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_pread64_ocall, (int* error, int fd, void* buf, size_t count, int64_t offset)); +#endif +#ifndef U_READV_OCALL_DEFINED__ +#define U_READV_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_readv_ocall, (int* error, int fd, const struct iovec* iov, int iovcnt)); +#endif +#ifndef U_PREADV64_OCALL_DEFINED__ +#define U_PREADV64_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_preadv64_ocall, (int* error, int fd, const struct iovec* iov, int iovcnt, int64_t offset)); +#endif +#ifndef U_WRITE_OCALL_DEFINED__ +#define U_WRITE_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_write_ocall, (int* error, int fd, const void* buf, size_t count)); +#endif +#ifndef U_PWRITE64_OCALL_DEFINED__ +#define U_PWRITE64_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_pwrite64_ocall, (int* error, int fd, const void* buf, size_t count, int64_t offset)); +#endif +#ifndef U_WRITEV_OCALL_DEFINED__ +#define U_WRITEV_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_writev_ocall, (int* error, int fd, const struct iovec* iov, int iovcnt)); +#endif +#ifndef U_PWRITEV64_OCALL_DEFINED__ +#define U_PWRITEV64_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_pwritev64_ocall, (int* error, int fd, const struct iovec* iov, int iovcnt, int64_t offset)); +#endif +#ifndef U_FCNTL_ARG0_OCALL_DEFINED__ +#define U_FCNTL_ARG0_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fcntl_arg0_ocall, (int* error, int fd, int cmd)); +#endif +#ifndef U_FCNTL_ARG1_OCALL_DEFINED__ +#define U_FCNTL_ARG1_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fcntl_arg1_ocall, (int* error, int fd, int cmd, int arg)); +#endif +#ifndef U_IOCTL_ARG0_OCALL_DEFINED__ +#define U_IOCTL_ARG0_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_ioctl_arg0_ocall, (int* error, int fd, int request)); +#endif +#ifndef U_IOCTL_ARG1_OCALL_DEFINED__ +#define U_IOCTL_ARG1_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_ioctl_arg1_ocall, (int* error, int fd, int request, int* arg)); +#endif +#ifndef U_CLOSE_OCALL_DEFINED__ +#define U_CLOSE_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_close_ocall, (int* error, int fd)); +#endif +#ifndef U_MALLOC_OCALL_DEFINED__ +#define U_MALLOC_OCALL_DEFINED__ +void* SGX_UBRIDGE(SGX_NOCONVENTION, u_malloc_ocall, (int* error, size_t size)); +#endif +#ifndef U_FREE_OCALL_DEFINED__ +#define U_FREE_OCALL_DEFINED__ +void SGX_UBRIDGE(SGX_NOCONVENTION, u_free_ocall, (void* p)); +#endif +#ifndef U_MMAP_OCALL_DEFINED__ +#define U_MMAP_OCALL_DEFINED__ +void* SGX_UBRIDGE(SGX_NOCONVENTION, u_mmap_ocall, (int* error, void* start, size_t length, int prot, int flags, int fd, int64_t offset)); +#endif +#ifndef U_MUNMAP_OCALL_DEFINED__ +#define U_MUNMAP_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_munmap_ocall, (int* error, void* start, size_t length)); +#endif +#ifndef U_MSYNC_OCALL_DEFINED__ +#define U_MSYNC_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_msync_ocall, (int* error, void* addr, size_t length, int flags)); +#endif +#ifndef U_MPROTECT_OCALL_DEFINED__ +#define U_MPROTECT_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_mprotect_ocall, (int* error, void* addr, size_t length, int prot)); +#endif +#ifndef U_OPEN_OCALL_DEFINED__ +#define U_OPEN_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_open_ocall, (int* error, const char* pathname, int flags)); +#endif +#ifndef U_OPEN64_OCALL_DEFINED__ +#define U_OPEN64_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_open64_ocall, (int* error, const char* path, int oflag, int mode)); +#endif +#ifndef U_FSTAT_OCALL_DEFINED__ +#define U_FSTAT_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fstat_ocall, (int* error, int fd, struct stat_t* buf)); +#endif +#ifndef U_FSTAT64_OCALL_DEFINED__ +#define U_FSTAT64_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fstat64_ocall, (int* error, int fd, struct stat64_t* buf)); +#endif +#ifndef U_STAT_OCALL_DEFINED__ +#define U_STAT_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_stat_ocall, (int* error, const char* path, struct stat_t* buf)); +#endif +#ifndef U_STAT64_OCALL_DEFINED__ +#define U_STAT64_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_stat64_ocall, (int* error, const char* path, struct stat64_t* buf)); +#endif +#ifndef U_LSTAT_OCALL_DEFINED__ +#define U_LSTAT_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_lstat_ocall, (int* error, const char* path, struct stat_t* buf)); +#endif +#ifndef U_LSTAT64_OCALL_DEFINED__ +#define U_LSTAT64_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_lstat64_ocall, (int* error, const char* path, struct stat64_t* buf)); +#endif +#ifndef U_LSEEK_OCALL_DEFINED__ +#define U_LSEEK_OCALL_DEFINED__ +uint64_t SGX_UBRIDGE(SGX_NOCONVENTION, u_lseek_ocall, (int* error, int fd, int64_t offset, int whence)); +#endif +#ifndef U_LSEEK64_OCALL_DEFINED__ +#define U_LSEEK64_OCALL_DEFINED__ +int64_t SGX_UBRIDGE(SGX_NOCONVENTION, u_lseek64_ocall, (int* error, int fd, int64_t offset, int whence)); +#endif +#ifndef U_FTRUNCATE_OCALL_DEFINED__ +#define U_FTRUNCATE_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_ftruncate_ocall, (int* error, int fd, int64_t length)); +#endif +#ifndef U_FTRUNCATE64_OCALL_DEFINED__ +#define U_FTRUNCATE64_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_ftruncate64_ocall, (int* error, int fd, int64_t length)); +#endif +#ifndef U_TRUNCATE_OCALL_DEFINED__ +#define U_TRUNCATE_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_truncate_ocall, (int* error, const char* path, int64_t length)); +#endif +#ifndef U_TRUNCATE64_OCALL_DEFINED__ +#define U_TRUNCATE64_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_truncate64_ocall, (int* error, const char* path, int64_t length)); +#endif +#ifndef U_FSYNC_OCALL_DEFINED__ +#define U_FSYNC_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fsync_ocall, (int* error, int fd)); +#endif +#ifndef U_FDATASYNC_OCALL_DEFINED__ +#define U_FDATASYNC_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fdatasync_ocall, (int* error, int fd)); +#endif +#ifndef U_FCHMOD_OCALL_DEFINED__ +#define U_FCHMOD_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fchmod_ocall, (int* error, int fd, uint32_t mode)); +#endif +#ifndef U_UNLINK_OCALL_DEFINED__ +#define U_UNLINK_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_unlink_ocall, (int* error, const char* pathname)); +#endif +#ifndef U_LINK_OCALL_DEFINED__ +#define U_LINK_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_link_ocall, (int* error, const char* oldpath, const char* newpath)); +#endif +#ifndef U_RENAME_OCALL_DEFINED__ +#define U_RENAME_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_rename_ocall, (int* error, const char* oldpath, const char* newpath)); +#endif +#ifndef U_CHMOD_OCALL_DEFINED__ +#define U_CHMOD_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_chmod_ocall, (int* error, const char* path, uint32_t mode)); +#endif +#ifndef U_READLINK_OCALL_DEFINED__ +#define U_READLINK_OCALL_DEFINED__ +size_t SGX_UBRIDGE(SGX_NOCONVENTION, u_readlink_ocall, (int* error, const char* path, char* buf, size_t bufsz)); +#endif +#ifndef U_SYMLINK_OCALL_DEFINED__ +#define U_SYMLINK_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_symlink_ocall, (int* error, const char* path1, const char* path2)); +#endif +#ifndef U_REALPATH_OCALL_DEFINED__ +#define U_REALPATH_OCALL_DEFINED__ +char* SGX_UBRIDGE(SGX_NOCONVENTION, u_realpath_ocall, (int* error, const char* pathname)); +#endif +#ifndef U_MKDIR_OCALL_DEFINED__ +#define U_MKDIR_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_mkdir_ocall, (int* error, const char* pathname, uint32_t mode)); +#endif +#ifndef U_RMDIR_OCALL_DEFINED__ +#define U_RMDIR_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_rmdir_ocall, (int* error, const char* pathname)); +#endif +#ifndef U_OPENDIR_OCALL_DEFINED__ +#define U_OPENDIR_OCALL_DEFINED__ +void* SGX_UBRIDGE(SGX_NOCONVENTION, u_opendir_ocall, (int* error, const char* pathname)); +#endif +#ifndef U_READDIR64_R_OCALL_DEFINED__ +#define U_READDIR64_R_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_readdir64_r_ocall, (void* dirp, struct dirent64_t* entry, struct dirent64_t** result)); +#endif +#ifndef U_CLOSEDIR_OCALL_DEFINED__ +#define U_CLOSEDIR_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_closedir_ocall, (int* error, void* dirp)); +#endif +#ifndef U_DIRFD_OCALL_DEFINED__ +#define U_DIRFD_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_dirfd_ocall, (int* error, void* dirp)); +#endif +#ifndef U_FSTATAT64_OCALL_DEFINED__ +#define U_FSTATAT64_OCALL_DEFINED__ +int SGX_UBRIDGE(SGX_NOCONVENTION, u_fstatat64_ocall, (int* error, int dirfd, const char* pathname, struct stat64_t* buf, int flags)); +#endif +#ifndef SGX_OC_CPUIDEX_DEFINED__ +#define SGX_OC_CPUIDEX_DEFINED__ +void SGX_UBRIDGE(SGX_CDECL, sgx_oc_cpuidex, (int cpuinfo[4], int leaf, int subleaf)); +#endif + +sgx_status_t run_tests_ecall(sgx_enclave_id_t eid, size_t* retval); +sgx_status_t t_global_init_ecall(sgx_enclave_id_t eid, uint64_t id, const uint8_t* path, size_t len); +sgx_status_t t_global_exit_ecall(sgx_enclave_id_t eid); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/sgx-tests/app/codegen/Enclave_u.rs b/sgx-tests/app/codegen/Enclave_u.rs new file mode 100644 index 0000000..8ec300f --- /dev/null +++ b/sgx-tests/app/codegen/Enclave_u.rs @@ -0,0 +1,7 @@ +/* automatically generated by rust-bindgen 0.59.1 */ + +use sgx_types::*; + +extern "C" { + pub fn run_tests_ecall(eid: sgx_enclave_id_t, retval: *mut size_t) -> sgx_status_t; +} diff --git a/sgx-tests/app/src/main.rs b/sgx-tests/app/src/main.rs new file mode 100644 index 0000000..2aeacc4 --- /dev/null +++ b/sgx-tests/app/src/main.rs @@ -0,0 +1,46 @@ +extern crate sgx_types; +extern crate sgx_urts; + +#[path = "../codegen/Enclave_u.rs"] +mod enclave_u; +mod safe_ecalls; + +use sgx_types::{sgx_attributes_t, sgx_launch_token_t, sgx_misc_attribute_t, SgxResult}; +use sgx_urts::SgxEnclave; + +use crate::safe_ecalls::safe_run_tests_ecall; + +static ENCLAVE_FILE: &str = "enclave.signed.so"; + +fn init_enclave() -> SgxResult { + let mut launch_token: sgx_launch_token_t = [0; 1024]; + let mut launch_token_updated: i32 = 0; + // call sgx_create_enclave to initialize an enclave instance + // Debug Support: set 2nd parameter to 1 + let debug = 1; + let mut misc_attr = sgx_misc_attribute_t { + secs_attr: sgx_attributes_t { flags: 0, xfrm: 0 }, + misc_select: 0, + }; + SgxEnclave::create( + ENCLAVE_FILE, + debug, + &mut launch_token, + &mut launch_token_updated, + &mut misc_attr, + ) +} + +fn main() -> Result<(), String> { + let enclave = init_enclave().map_err(|err| format!("init_enclave failed: {:?}", err))?; + + let failed_tests = safe_run_tests_ecall(enclave.geteid()) + .map_err(|err| format!("run_tests_ecall failed: {:?}", err))?; + + enclave.destroy(); + + match failed_tests { + 0 => Ok(()), + _ => Err(format!("{} tests failed", failed_tests)), + } +} diff --git a/sgx-tests/app/src/safe_ecalls.rs b/sgx-tests/app/src/safe_ecalls.rs new file mode 100644 index 0000000..b4de870 --- /dev/null +++ b/sgx-tests/app/src/safe_ecalls.rs @@ -0,0 +1,13 @@ +//! Safe Rust wrappers around [`enclave_u`]. + +use sgx_types::{sgx_enclave_id_t, sgx_status_t, size_t, SgxResult}; + +use crate::enclave_u; + +pub(crate) fn safe_run_tests_ecall(eid: sgx_enclave_id_t) -> SgxResult { + let mut retval = size_t::MAX; + match unsafe { enclave_u::run_tests_ecall(eid, &mut retval) } { + sgx_status_t::SGX_SUCCESS => Ok(retval), + err => Err(err), + } +} diff --git a/sgx-tests/buildenv.mk b/sgx-tests/buildenv.mk new file mode 100644 index 0000000..a86675e --- /dev/null +++ b/sgx-tests/buildenv.mk @@ -0,0 +1,167 @@ +# 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.. +# +# + +CP := /bin/cp -f +MKDIR := mkdir -p +STRIP := strip +OBJCOPY := objcopy + +# clean the content of 'INCLUDE' - this variable will be set by vcvars32.bat +# thus it will cause build error when this variable is used by our Makefile, +# when compiling the code under Cygwin tainted by MSVC environment settings. +INCLUDE := + +# turn on stack protector for SDK +COMMON_FLAGS += -fstack-protector + +ifdef DEBUG + COMMON_FLAGS += -O0 -g -DDEBUG -UNDEBUG +else + COMMON_FLAGS += -O2 -D_FORTIFY_SOURCE=2 -UDEBUG -DNDEBUG +endif + +# turn on compiler warnings as much as possible +COMMON_FLAGS += -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type \ + -Waddress -Wsequence-point -Wformat-security \ + -Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow \ + -Wcast-align -Wconversion -Wredundant-decls + +# additional warnings flags for C +CFLAGS += -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants + +# additional warnings flags for C++ +CXXFLAGS += -Wnon-virtual-dtor + +# for static_assert() +CXXFLAGS += -std=c++0x + +.DEFAULT_GOAL := all +# this turns off the RCS / SCCS implicit rules of GNU Make +% : RCS/%,v +% : RCS/% +% : %,v +% : s.% +% : SCCS/s.% + +# If a rule fails, delete $@. +.DELETE_ON_ERROR: + +HOST_FILE_PROGRAM := file + +UNAME := $(shell uname -m) +ifneq (,$(findstring 86,$(UNAME))) + HOST_ARCH := x86 + ifneq (,$(shell $(HOST_FILE_PROGRAM) -L $(SHELL) | grep 'x86[_-]64')) + HOST_ARCH := x86_64 + endif +else + $(info Unknown host CPU arhitecture $(UNAME)) + $(error Aborting) +endif + + +ifeq "$(findstring __INTEL_COMPILER, $(shell $(CC) -E -dM -xc /dev/null))" "__INTEL_COMPILER" + ifeq ($(shell test -f /usr/bin/dpkg; echo $$?), 0) + ADDED_INC := -I /usr/include/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH) + endif +endif + +ARCH := $(HOST_ARCH) +ifeq "$(findstring -m32, $(CXXFLAGS))" "-m32" + ARCH := x86 +endif + +ifeq ($(ARCH), x86) +COMMON_FLAGS += -DITT_ARCH_IA32 +else +COMMON_FLAGS += -DITT_ARCH_IA64 +endif + +CFLAGS += $(COMMON_FLAGS) +CXXFLAGS += $(COMMON_FLAGS) + +# Enable the security flags +COMMON_LDFLAGS := -Wl,-z,relro,-z,now,-z,noexecstack + +# mitigation options +MITIGATION_INDIRECT ?= 0 +MITIGATION_RET ?= 0 +MITIGATION_C ?= 0 +MITIGATION_ASM ?= 0 +MITIGATION_AFTERLOAD ?= 0 +MITIGATION_LIB_PATH := + +ifeq ($(MITIGATION-CVE-2020-0551), LOAD) + MITIGATION_C := 1 + MITIGATION_ASM := 1 + MITIGATION_INDIRECT := 1 + MITIGATION_RET := 1 + MITIGATION_AFTERLOAD := 1 + MITIGATION_LIB_PATH := cve_2020_0551_load +else ifeq ($(MITIGATION-CVE-2020-0551), CF) + MITIGATION_C := 1 + MITIGATION_ASM := 1 + MITIGATION_INDIRECT := 1 + MITIGATION_RET := 1 + MITIGATION_AFTERLOAD := 0 + MITIGATION_LIB_PATH := cve_2020_0551_cf +endif + +MITIGATION_CFLAGS := +MITIGATION_ASFLAGS := +ifeq ($(MITIGATION_C), 1) +ifeq ($(MITIGATION_INDIRECT), 1) + MITIGATION_CFLAGS += -mindirect-branch-register +endif +ifeq ($(MITIGATION_RET), 1) + MITIGATION_CFLAGS += -mfunction-return=thunk-extern +endif +endif + +ifeq ($(MITIGATION_ASM), 1) + MITIGATION_ASFLAGS += -fno-plt +ifeq ($(MITIGATION_AFTERLOAD), 1) + MITIGATION_ASFLAGS += -Wa,-mlfence-after-load=yes +else + MITIGATION_ASFLAGS += -Wa,-mlfence-before-indirect-branch=register +endif +ifeq ($(MITIGATION_RET), 1) + MITIGATION_ASFLAGS += -Wa,-mlfence-before-ret=not +endif +endif + +MITIGATION_CFLAGS += $(MITIGATION_ASFLAGS) + +# Compiler and linker options for an Enclave +# +# We are using '--export-dynamic' so that `g_global_data_sim' etc. +# will be exported to dynamic symbol table. +# +# When `pie' is enabled, the linker (both BFD and Gold) under Ubuntu 14.04 +# will hide all symbols from dynamic symbol table even if they are marked +# as `global' in the LD version script. +ENCLAVE_CFLAGS = -ffreestanding -nostdinc -fvisibility=hidden -fpie -fno-strict-overflow -fno-delete-null-pointer-checks +ENCLAVE_CXXFLAGS = $(ENCLAVE_CFLAGS) -nostdinc++ +ENCLAVE_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--gc-sections \ + -Wl,--defsym,__ImageBase=0 + +ENCLAVE_CFLAGS += $(MITIGATION_CFLAGS) +ENCLAVE_ASFLAGS = $(MITIGATION_ASFLAGS) \ No newline at end of file diff --git a/sgx-tests/buildenv_sgx.mk b/sgx-tests/buildenv_sgx.mk new file mode 100644 index 0000000..4ec0119 --- /dev/null +++ b/sgx-tests/buildenv_sgx.mk @@ -0,0 +1,49 @@ +SGX_SDK ?= /opt/sgxsdk + +# Directly imported from the original Intel SGX samples, helpful to detect the system architecture + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +# If specified, software / simulation mode. Otherwise, hardware mode no matter what. + +ifeq ($(SGX_MODE), SW) + TRTS_LIB := sgx_trts_sim + SERVICE_LIB := sgx_tservice_sim +endif + +# If debug mode, we can set up extra options such as the debug flags + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +# Show helpful error messages if main environment variables are not set. + +$(SGX_EDGER8R): + $(error "$@" does not exist. (Is SGX_SDK set correctly?)) + +ifndef CUSTOM_EDL_PATH +$(error CUSTOM_EDL_PATH not set) +endif + +ifndef CUSTOM_COMMON_PATH +$(error CUSTOM_COMMON_PATH not set) +endif diff --git a/sgx-tests/enclave/.gitignore b/sgx-tests/enclave/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/sgx-tests/enclave/.gitignore @@ -0,0 +1 @@ +/target diff --git a/sgx-tests/enclave/Cargo.toml b/sgx-tests/enclave/Cargo.toml new file mode 100644 index 0000000..3b71145 --- /dev/null +++ b/sgx-tests/enclave/Cargo.toml @@ -0,0 +1,30 @@ +[package] +# name matches ENCLAVE_CARGO_LIB in Makefile +name = "sgx-test-enclave" +version = "0.1.0" +edition = "2018" +authors = ["Pi Delport "] + +[lib] +crate-type = ["staticlib"] +test = false +doctest = false +bench = false + +[features] +default = [] + +[dependencies] +hex = { version = "0.4.2", default-features = false, features = ["alloc"] } +rand = { git = "https://github.com/mesalock-linux/rand-sgx" } + +ripple-address-codec = { path = "../.." } + +sgx_types = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } +sgx_tstd = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk", features = ["backtrace"] } +sgx_tunittest = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } + +[patch.'https://github.com/apache/teaclave-sgx-sdk.git'] +sgx_libc = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } +sgx_trts = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } +sgx_tstd = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk" } diff --git a/sgx-tests/enclave/Enclave.config.xml b/sgx-tests/enclave/Enclave.config.xml new file mode 100644 index 0000000..ee4c3f7 --- /dev/null +++ b/sgx-tests/enclave/Enclave.config.xml @@ -0,0 +1,12 @@ + + + 0 + 0 + 0x40000 + 0x100000 + 1 + 1 + 0 + 0 + 0xFFFFFFFF + diff --git a/sgx-tests/enclave/Enclave.edl b/sgx-tests/enclave/Enclave.edl new file mode 100644 index 0000000..5380c02 --- /dev/null +++ b/sgx-tests/enclave/Enclave.edl @@ -0,0 +1,10 @@ +enclave { + from "sgx_tstd.edl" import *; + from "sgx_backtrace.edl" import *; + + from "sgx_tstdc.edl" import sgx_oc_cpuidex; + + trusted { + public size_t run_tests_ecall(); + }; +}; diff --git a/sgx-tests/enclave/Enclave.lds b/sgx-tests/enclave/Enclave.lds new file mode 100644 index 0000000..e3d9d0e --- /dev/null +++ b/sgx-tests/enclave/Enclave.lds @@ -0,0 +1,9 @@ +enclave.so +{ + global: + g_global_data_sim; + g_global_data; + enclave_entry; + local: + *; +}; diff --git a/sgx-tests/enclave/Makefile b/sgx-tests/enclave/Makefile new file mode 100644 index 0000000..461b283 --- /dev/null +++ b/sgx-tests/enclave/Makefile @@ -0,0 +1,117 @@ +# Makefile settings + +APP_T_SIGNED = enclave.signed.so +KEYS = ../keys +LIB = ../build/lib/ +BIN = ../build/bin/ +APP_T = enclave.so +NAME_T = libenclave.a +SRC_U = ../app/ +SRC_T = ./ +CODEGEN_T = $(SRC_T)/codegen/ +OBJ_T = ../build/obj/ +FLAGS = -Wall -Wextra +GCC_STEP1_T = -fstack-protector -I$(CUSTOM_COMMON_PATH)/inc -I$(CUSTOM_EDL_PATH) -I$(SGX_SDK)/include \ + -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I$(SGX_SDK)/include/epid -I $(CODEGEN_T) \ + -L$(LIB) $(ENCLAVE_CFLAGS) $(SGX_COMMON_CFLAGS) +GCC_STEP2_T = -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(TRTS_LIB) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -l$(SERVICE_LIB) -lsgx_tcrypto -L$(LIB) -lenclave -Wl,--end-group \ + -Wl,--version-script=$(SRC_T)Enclave.lds $(ENCLAVE_LDFLAGS) +FILES_T = Enclave_t.c +FILES_T_H = Enclave_t.h +EDL_FILE = Enclave.edl +ENCLAVE_CONFIG = Enclave.config.xml +SGX_ARCH = x64 +TRTS_LIB = sgx_trts +SERVICE_LIB = sgx_tservice +# ENCLAVE_CARGO_LIB matches name in Cargo.toml +ENCLAVE_CARGO_LIB=libsgx_test_enclave.a +# Addprefix dependant variables, no need to change those +OUTPUT_T = $(FILES_T:.c=.o) +NAME = $(addprefix $(BIN), $(APP_T_SIGNED)) +BIN_T = $(addprefix $(BIN), $(APP_T)) +NAME_T_D = $(addprefix $(LIB), $(NAME_T)) +OUTPUT_W_FU=$(addprefix $(OBJ_U), $(OUTPUT_U)) +FILES_T_F=$(addprefix $(CODEGEN_T), $(FILES_T)) +FILES_T_H_F=$(addprefix $(CODEGEN_T), $(FILES_T_H)) +FILES_T_F_RUST=$(addprefix $(SRC_T), $(FILES_T_RUST)) +OUTPUT_W_FT=$(addprefix $(OBJ_T), $(OUTPUT_T)) + +# All Rust and other source files that the Cargo build depends on. +FILES_RUST_F = Cargo.toml Cargo.lock $(shell find src ../../tests -name '*.rs') + +# Contains compilation rules for the enclave part + +include ../buildenv.mk +include ../buildenv_sgx.mk + +# Custom header files and EDL paths needs to be specified with make (CUSTOM_EDL_PATH) (CUSTOM_COMMON_PATH) + +ifeq ($(MITIGATION-CVE-2020-0551), LOAD) +export MITIGATION_CVE_2020_0551=LOAD +else ifeq ($(MITIGATION-CVE-2020-0551), CF) +export MITIGATION_CVE_2020_0551=CF +endif + +# Compilation process, we set up all the dependencies needed to have the correct order of build, and avoid relink + +all: $(NAME) + +# We print the compilation mode we're in (hardware/software mode), just as a reminder. + +$(NAME): $(BIN_T) $(KEYS)/Enclave_private.pem +ifeq ($(SGX_MODE), SW) + @echo "\033[32mSoftware / Simulation mode\033[0m" +else + @echo "\033[32mHardware mode\033[0m" +endif + @echo "\033[32mSigning the enclave...\033[0m" + @mkdir -p $(BIN) + @$(SGX_ENCLAVE_SIGNER) sign -key $(KEYS)/Enclave_private.pem -enclave $(BIN_T) -out $@ -config $(SRC_T)Enclave.config.xml + +$(KEYS)/Enclave_private.pem $(KEYS)/Enclave_public.pem: + @echo "\033[32mGenerating keys...\033[0m" + @mkdir -p $(KEYS) + @openssl genrsa -out $(KEYS)/Enclave_private.pem -3 3072 + @openssl rsa -in $(KEYS)/Enclave_private.pem -pubout -out $(KEYS)/Enclave_public.pem + +$(BIN_T): $(NAME_T_D) + @echo "\033[32mBuilding the enclave...\033[0m" + @$(CXX) $(OUTPUT_W_FT) -o $@ $(GCC_STEP2_T) + +$(NAME_T_D): $(FILES_T_F) $(OUTPUT_W_FT) $(FILES_RUST_F) $(EDL_FILE) $(ENCLAVE_CONFIG) # We added as a reference the rust files, along with the EDL, the XML config file and the cargo.toml file, so Make can detect if any change was made + @echo "\033[32mBuilding enclave static library with Cargo...\033[0m" + @cargo build --release + @cp ./target/release/$(ENCLAVE_CARGO_LIB) $(LIB)libenclave.a + +$(FILES_T_F): $(SGX_EDGER8R) $(SRC_T)/Enclave.edl + @echo "\033[32mGenerating trusted SGX C edl files...\033[0m" + @$(SGX_EDGER8R) --trusted $(SRC_T)/Enclave.edl --search-path $(SGX_SDK)/include --search-path $(CUSTOM_EDL_PATH) --trusted-dir $(CODEGEN_T) + +$(OBJ_T)%.o:$(CODEGEN_T)%.c + @mkdir -p $(OBJ_T) + @echo "\033[32m$?: Build in progress...\033[0m" + @$(CC) $(FLAGS) $(GCC_STEP1_T) -o $@ -c $? + +clean: c_clean + @rm -rf $(OBJ_T) + @echo "\033[32mObject files deleted\033[0m" + +fclean: clean fclean_enclave + +fclean_enclave: + @echo "\033[32mBinary file $(NAME) deleted\033[0m" + @rm -f $(NAME) + @rm -f $(BIN_T) + @rm -f $(LIB)libenclave.a + @cargo clean + +c_clean: + @echo "\033[32mC edl generated files deleted\033[0m" + @rm -rf $(FILES_T_F) + @rm -f $(FILES_T_H_F) + +re: fclean all + +.PHONY: all clean c_clean fclean re fclean_enclave diff --git a/sgx-tests/enclave/codegen/Enclave_t.c b/sgx-tests/enclave/codegen/Enclave_t.c new file mode 100644 index 0000000..231440b --- /dev/null +++ b/sgx-tests/enclave/codegen/Enclave_t.c @@ -0,0 +1,4477 @@ +#include "Enclave_t.h" + +#include "sgx_trts.h" /* for sgx_ocalloc, sgx_is_outside_enclave */ +#include "sgx_lfence.h" /* for sgx_lfence */ + +#include +#include /* for memcpy_s etc */ +#include /* for malloc/free etc */ + +#define CHECK_REF_POINTER(ptr, siz) do { \ + if (!(ptr) || ! sgx_is_outside_enclave((ptr), (siz))) \ + return SGX_ERROR_INVALID_PARAMETER;\ +} while (0) + +#define CHECK_UNIQUE_POINTER(ptr, siz) do { \ + if ((ptr) && ! sgx_is_outside_enclave((ptr), (siz))) \ + return SGX_ERROR_INVALID_PARAMETER;\ +} while (0) + +#define CHECK_ENCLAVE_POINTER(ptr, siz) do { \ + if ((ptr) && ! sgx_is_within_enclave((ptr), (siz))) \ + return SGX_ERROR_INVALID_PARAMETER;\ +} while (0) + +#define ADD_ASSIGN_OVERFLOW(a, b) ( \ + ((a) += (b)) < (b) \ +) + + +typedef struct ms_run_tests_ecall_t { + size_t ms_retval; +} ms_run_tests_ecall_t; + +typedef struct ms_t_global_init_ecall_t { + uint64_t ms_id; + const uint8_t* ms_path; + size_t ms_len; +} ms_t_global_init_ecall_t; + +typedef struct ms_u_thread_set_event_ocall_t { + int ms_retval; + int* ms_error; + const void* ms_tcs; +} ms_u_thread_set_event_ocall_t; + +typedef struct ms_u_thread_wait_event_ocall_t { + int ms_retval; + int* ms_error; + const void* ms_tcs; + const struct timespec* ms_timeout; +} ms_u_thread_wait_event_ocall_t; + +typedef struct ms_u_thread_set_multiple_events_ocall_t { + int ms_retval; + int* ms_error; + const void** ms_tcss; + int ms_total; +} ms_u_thread_set_multiple_events_ocall_t; + +typedef struct ms_u_thread_setwait_events_ocall_t { + int ms_retval; + int* ms_error; + const void* ms_waiter_tcs; + const void* ms_self_tcs; + const struct timespec* ms_timeout; +} ms_u_thread_setwait_events_ocall_t; + +typedef struct ms_u_clock_gettime_ocall_t { + int ms_retval; + int* ms_error; + int ms_clk_id; + struct timespec* ms_tp; +} ms_u_clock_gettime_ocall_t; + +typedef struct ms_u_read_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + void* ms_buf; + size_t ms_count; +} ms_u_read_ocall_t; + +typedef struct ms_u_pread64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + void* ms_buf; + size_t ms_count; + int64_t ms_offset; +} ms_u_pread64_ocall_t; + +typedef struct ms_u_readv_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; +} ms_u_readv_ocall_t; + +typedef struct ms_u_preadv64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; + int64_t ms_offset; +} ms_u_preadv64_ocall_t; + +typedef struct ms_u_write_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const void* ms_buf; + size_t ms_count; +} ms_u_write_ocall_t; + +typedef struct ms_u_pwrite64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const void* ms_buf; + size_t ms_count; + int64_t ms_offset; +} ms_u_pwrite64_ocall_t; + +typedef struct ms_u_writev_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; +} ms_u_writev_ocall_t; + +typedef struct ms_u_pwritev64_ocall_t { + size_t ms_retval; + int* ms_error; + int ms_fd; + const struct iovec* ms_iov; + int ms_iovcnt; + int64_t ms_offset; +} ms_u_pwritev64_ocall_t; + +typedef struct ms_u_fcntl_arg0_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_cmd; +} ms_u_fcntl_arg0_ocall_t; + +typedef struct ms_u_fcntl_arg1_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_cmd; + int ms_arg; +} ms_u_fcntl_arg1_ocall_t; + +typedef struct ms_u_ioctl_arg0_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_request; +} ms_u_ioctl_arg0_ocall_t; + +typedef struct ms_u_ioctl_arg1_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int ms_request; + int* ms_arg; +} ms_u_ioctl_arg1_ocall_t; + +typedef struct ms_u_close_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; +} ms_u_close_ocall_t; + +typedef struct ms_u_malloc_ocall_t { + void* ms_retval; + int* ms_error; + size_t ms_size; +} ms_u_malloc_ocall_t; + +typedef struct ms_u_free_ocall_t { + void* ms_p; +} ms_u_free_ocall_t; + +typedef struct ms_u_mmap_ocall_t { + void* ms_retval; + int* ms_error; + void* ms_start; + size_t ms_length; + int ms_prot; + int ms_flags; + int ms_fd; + int64_t ms_offset; +} ms_u_mmap_ocall_t; + +typedef struct ms_u_munmap_ocall_t { + int ms_retval; + int* ms_error; + void* ms_start; + size_t ms_length; +} ms_u_munmap_ocall_t; + +typedef struct ms_u_msync_ocall_t { + int ms_retval; + int* ms_error; + void* ms_addr; + size_t ms_length; + int ms_flags; +} ms_u_msync_ocall_t; + +typedef struct ms_u_mprotect_ocall_t { + int ms_retval; + int* ms_error; + void* ms_addr; + size_t ms_length; + int ms_prot; +} ms_u_mprotect_ocall_t; + +typedef struct ms_u_open_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; + int ms_flags; +} ms_u_open_ocall_t; + +typedef struct ms_u_open64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + int ms_oflag; + int ms_mode; +} ms_u_open64_ocall_t; + +typedef struct ms_u_fstat_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + struct stat_t* ms_buf; +} ms_u_fstat_ocall_t; + +typedef struct ms_u_fstat64_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + struct stat64_t* ms_buf; +} ms_u_fstat64_ocall_t; + +typedef struct ms_u_stat_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat_t* ms_buf; +} ms_u_stat_ocall_t; + +typedef struct ms_u_stat64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat64_t* ms_buf; +} ms_u_stat64_ocall_t; + +typedef struct ms_u_lstat_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat_t* ms_buf; +} ms_u_lstat_ocall_t; + +typedef struct ms_u_lstat64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + struct stat64_t* ms_buf; +} ms_u_lstat64_ocall_t; + +typedef struct ms_u_lseek_ocall_t { + uint64_t ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_offset; + int ms_whence; +} ms_u_lseek_ocall_t; + +typedef struct ms_u_lseek64_ocall_t { + int64_t ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_offset; + int ms_whence; +} ms_u_lseek64_ocall_t; + +typedef struct ms_u_ftruncate_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_length; +} ms_u_ftruncate_ocall_t; + +typedef struct ms_u_ftruncate64_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + int64_t ms_length; +} ms_u_ftruncate64_ocall_t; + +typedef struct ms_u_truncate_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + int64_t ms_length; +} ms_u_truncate_ocall_t; + +typedef struct ms_u_truncate64_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + int64_t ms_length; +} ms_u_truncate64_ocall_t; + +typedef struct ms_u_fsync_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; +} ms_u_fsync_ocall_t; + +typedef struct ms_u_fdatasync_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; +} ms_u_fdatasync_ocall_t; + +typedef struct ms_u_fchmod_ocall_t { + int ms_retval; + int* ms_error; + int ms_fd; + uint32_t ms_mode; +} ms_u_fchmod_ocall_t; + +typedef struct ms_u_unlink_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_unlink_ocall_t; + +typedef struct ms_u_link_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_oldpath; + const char* ms_newpath; +} ms_u_link_ocall_t; + +typedef struct ms_u_rename_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_oldpath; + const char* ms_newpath; +} ms_u_rename_ocall_t; + +typedef struct ms_u_chmod_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path; + uint32_t ms_mode; +} ms_u_chmod_ocall_t; + +typedef struct ms_u_readlink_ocall_t { + size_t ms_retval; + int* ms_error; + const char* ms_path; + char* ms_buf; + size_t ms_bufsz; +} ms_u_readlink_ocall_t; + +typedef struct ms_u_symlink_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_path1; + const char* ms_path2; +} ms_u_symlink_ocall_t; + +typedef struct ms_u_realpath_ocall_t { + char* ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_realpath_ocall_t; + +typedef struct ms_u_mkdir_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; + uint32_t ms_mode; +} ms_u_mkdir_ocall_t; + +typedef struct ms_u_rmdir_ocall_t { + int ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_rmdir_ocall_t; + +typedef struct ms_u_opendir_ocall_t { + void* ms_retval; + int* ms_error; + const char* ms_pathname; +} ms_u_opendir_ocall_t; + +typedef struct ms_u_readdir64_r_ocall_t { + int ms_retval; + void* ms_dirp; + struct dirent64_t* ms_entry; + struct dirent64_t** ms_result; +} ms_u_readdir64_r_ocall_t; + +typedef struct ms_u_closedir_ocall_t { + int ms_retval; + int* ms_error; + void* ms_dirp; +} ms_u_closedir_ocall_t; + +typedef struct ms_u_dirfd_ocall_t { + int ms_retval; + int* ms_error; + void* ms_dirp; +} ms_u_dirfd_ocall_t; + +typedef struct ms_u_fstatat64_ocall_t { + int ms_retval; + int* ms_error; + int ms_dirfd; + const char* ms_pathname; + struct stat64_t* ms_buf; + int ms_flags; +} ms_u_fstatat64_ocall_t; + +typedef struct ms_sgx_oc_cpuidex_t { + int* ms_cpuinfo; + int ms_leaf; + int ms_subleaf; +} ms_sgx_oc_cpuidex_t; + +static sgx_status_t SGX_CDECL sgx_run_tests_ecall(void* pms) +{ + CHECK_REF_POINTER(pms, sizeof(ms_run_tests_ecall_t)); + // + // fence after pointer checks + // + sgx_lfence(); + ms_run_tests_ecall_t* ms = SGX_CAST(ms_run_tests_ecall_t*, pms); + sgx_status_t status = SGX_SUCCESS; + + + + ms->ms_retval = run_tests_ecall(); + + + return status; +} + +static sgx_status_t SGX_CDECL sgx_t_global_init_ecall(void* pms) +{ + CHECK_REF_POINTER(pms, sizeof(ms_t_global_init_ecall_t)); + // + // fence after pointer checks + // + sgx_lfence(); + ms_t_global_init_ecall_t* ms = SGX_CAST(ms_t_global_init_ecall_t*, pms); + sgx_status_t status = SGX_SUCCESS; + const uint8_t* _tmp_path = ms->ms_path; + size_t _tmp_len = ms->ms_len; + size_t _len_path = _tmp_len; + uint8_t* _in_path = NULL; + + CHECK_UNIQUE_POINTER(_tmp_path, _len_path); + + // + // fence after pointer checks + // + sgx_lfence(); + + if (_tmp_path != NULL && _len_path != 0) { + if ( _len_path % sizeof(*_tmp_path) != 0) + { + status = SGX_ERROR_INVALID_PARAMETER; + goto err; + } + _in_path = (uint8_t*)malloc(_len_path); + if (_in_path == NULL) { + status = SGX_ERROR_OUT_OF_MEMORY; + goto err; + } + + if (memcpy_s(_in_path, _len_path, _tmp_path, _len_path)) { + status = SGX_ERROR_UNEXPECTED; + goto err; + } + + } + + t_global_init_ecall(ms->ms_id, (const uint8_t*)_in_path, _tmp_len); + +err: + if (_in_path) free(_in_path); + return status; +} + +static sgx_status_t SGX_CDECL sgx_t_global_exit_ecall(void* pms) +{ + sgx_status_t status = SGX_SUCCESS; + if (pms != NULL) return SGX_ERROR_INVALID_PARAMETER; + t_global_exit_ecall(); + return status; +} + +SGX_EXTERNC const struct { + size_t nr_ecall; + struct {void* ecall_addr; uint8_t is_priv; uint8_t is_switchless;} ecall_table[3]; +} g_ecall_table = { + 3, + { + {(void*)(uintptr_t)sgx_run_tests_ecall, 0, 0}, + {(void*)(uintptr_t)sgx_t_global_init_ecall, 0, 0}, + {(void*)(uintptr_t)sgx_t_global_exit_ecall, 0, 0}, + } +}; + +SGX_EXTERNC const struct { + size_t nr_ocall; + uint8_t entry_table[56][3]; +} g_dyn_entry_table = { + 56, + { + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + {0, 0, 0, }, + } +}; + + +sgx_status_t SGX_CDECL u_thread_set_event_ocall(int* retval, int* error, const void* tcs) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_thread_set_event_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_thread_set_event_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_thread_set_event_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_thread_set_event_ocall_t)); + ocalloc_size -= sizeof(ms_u_thread_set_event_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_tcs = tcs; + status = sgx_ocall(0, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_thread_wait_event_ocall(int* retval, int* error, const void* tcs, const struct timespec* timeout) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_timeout = sizeof(struct timespec); + + ms_u_thread_wait_event_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_thread_wait_event_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(timeout, _len_timeout); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (timeout != NULL) ? _len_timeout : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_thread_wait_event_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_thread_wait_event_ocall_t)); + ocalloc_size -= sizeof(ms_u_thread_wait_event_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_tcs = tcs; + if (timeout != NULL) { + ms->ms_timeout = (const struct timespec*)__tmp; + if (memcpy_s(__tmp, ocalloc_size, timeout, _len_timeout)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_timeout); + ocalloc_size -= _len_timeout; + } else { + ms->ms_timeout = NULL; + } + + status = sgx_ocall(1, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_thread_set_multiple_events_ocall(int* retval, int* error, const void** tcss, int total) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_tcss = total * sizeof(void*); + + ms_u_thread_set_multiple_events_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_thread_set_multiple_events_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(tcss, _len_tcss); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (tcss != NULL) ? _len_tcss : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_thread_set_multiple_events_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_thread_set_multiple_events_ocall_t)); + ocalloc_size -= sizeof(ms_u_thread_set_multiple_events_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (tcss != NULL) { + ms->ms_tcss = (const void**)__tmp; + if (_len_tcss % sizeof(*tcss) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, tcss, _len_tcss)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_tcss); + ocalloc_size -= _len_tcss; + } else { + ms->ms_tcss = NULL; + } + + ms->ms_total = total; + status = sgx_ocall(2, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_thread_setwait_events_ocall(int* retval, int* error, const void* waiter_tcs, const void* self_tcs, const struct timespec* timeout) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_timeout = sizeof(struct timespec); + + ms_u_thread_setwait_events_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_thread_setwait_events_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(timeout, _len_timeout); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (timeout != NULL) ? _len_timeout : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_thread_setwait_events_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_thread_setwait_events_ocall_t)); + ocalloc_size -= sizeof(ms_u_thread_setwait_events_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_waiter_tcs = waiter_tcs; + ms->ms_self_tcs = self_tcs; + if (timeout != NULL) { + ms->ms_timeout = (const struct timespec*)__tmp; + if (memcpy_s(__tmp, ocalloc_size, timeout, _len_timeout)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_timeout); + ocalloc_size -= _len_timeout; + } else { + ms->ms_timeout = NULL; + } + + status = sgx_ocall(3, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_clock_gettime_ocall(int* retval, int* error, int clk_id, struct timespec* tp) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_tp = sizeof(struct timespec); + + ms_u_clock_gettime_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_clock_gettime_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_tp = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(tp, _len_tp); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (tp != NULL) ? _len_tp : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_clock_gettime_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_clock_gettime_ocall_t)); + ocalloc_size -= sizeof(ms_u_clock_gettime_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_clk_id = clk_id; + if (tp != NULL) { + ms->ms_tp = (struct timespec*)__tmp; + __tmp_tp = __tmp; + memset(__tmp_tp, 0, _len_tp); + __tmp = (void *)((size_t)__tmp + _len_tp); + ocalloc_size -= _len_tp; + } else { + ms->ms_tp = NULL; + } + + status = sgx_ocall(4, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (tp) { + if (memcpy_s((void*)tp, _len_tp, __tmp_tp, _len_tp)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_read_ocall(size_t* retval, int* error, int fd, void* buf, size_t count) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_read_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_read_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_read_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_read_ocall_t)); + ocalloc_size -= sizeof(ms_u_read_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_buf = buf; + ms->ms_count = count; + status = sgx_ocall(5, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_pread64_ocall(size_t* retval, int* error, int fd, void* buf, size_t count, int64_t offset) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_pread64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_pread64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_pread64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_pread64_ocall_t)); + ocalloc_size -= sizeof(ms_u_pread64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_buf = buf; + ms->ms_count = count; + ms->ms_offset = offset; + status = sgx_ocall(6, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_readv_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_iov = iovcnt * sizeof(struct iovec); + + ms_u_readv_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_readv_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(iov, _len_iov); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (iov != NULL) ? _len_iov : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_readv_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_readv_ocall_t)); + ocalloc_size -= sizeof(ms_u_readv_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + if (iov != NULL) { + ms->ms_iov = (const struct iovec*)__tmp; + if (memcpy_s(__tmp, ocalloc_size, iov, _len_iov)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_iov); + ocalloc_size -= _len_iov; + } else { + ms->ms_iov = NULL; + } + + ms->ms_iovcnt = iovcnt; + status = sgx_ocall(7, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_preadv64_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt, int64_t offset) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_iov = iovcnt * sizeof(struct iovec); + + ms_u_preadv64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_preadv64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(iov, _len_iov); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (iov != NULL) ? _len_iov : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_preadv64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_preadv64_ocall_t)); + ocalloc_size -= sizeof(ms_u_preadv64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + if (iov != NULL) { + ms->ms_iov = (const struct iovec*)__tmp; + if (memcpy_s(__tmp, ocalloc_size, iov, _len_iov)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_iov); + ocalloc_size -= _len_iov; + } else { + ms->ms_iov = NULL; + } + + ms->ms_iovcnt = iovcnt; + ms->ms_offset = offset; + status = sgx_ocall(8, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_write_ocall(size_t* retval, int* error, int fd, const void* buf, size_t count) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_write_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_write_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_write_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_write_ocall_t)); + ocalloc_size -= sizeof(ms_u_write_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_buf = buf; + ms->ms_count = count; + status = sgx_ocall(9, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_pwrite64_ocall(size_t* retval, int* error, int fd, const void* buf, size_t count, int64_t offset) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_pwrite64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_pwrite64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_pwrite64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_pwrite64_ocall_t)); + ocalloc_size -= sizeof(ms_u_pwrite64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_buf = buf; + ms->ms_count = count; + ms->ms_offset = offset; + status = sgx_ocall(10, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_writev_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_iov = iovcnt * sizeof(struct iovec); + + ms_u_writev_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_writev_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(iov, _len_iov); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (iov != NULL) ? _len_iov : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_writev_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_writev_ocall_t)); + ocalloc_size -= sizeof(ms_u_writev_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + if (iov != NULL) { + ms->ms_iov = (const struct iovec*)__tmp; + if (memcpy_s(__tmp, ocalloc_size, iov, _len_iov)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_iov); + ocalloc_size -= _len_iov; + } else { + ms->ms_iov = NULL; + } + + ms->ms_iovcnt = iovcnt; + status = sgx_ocall(11, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_pwritev64_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt, int64_t offset) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_iov = iovcnt * sizeof(struct iovec); + + ms_u_pwritev64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_pwritev64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(iov, _len_iov); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (iov != NULL) ? _len_iov : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_pwritev64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_pwritev64_ocall_t)); + ocalloc_size -= sizeof(ms_u_pwritev64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + if (iov != NULL) { + ms->ms_iov = (const struct iovec*)__tmp; + if (memcpy_s(__tmp, ocalloc_size, iov, _len_iov)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_iov); + ocalloc_size -= _len_iov; + } else { + ms->ms_iov = NULL; + } + + ms->ms_iovcnt = iovcnt; + ms->ms_offset = offset; + status = sgx_ocall(12, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fcntl_arg0_ocall(int* retval, int* error, int fd, int cmd) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_fcntl_arg0_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fcntl_arg0_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fcntl_arg0_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fcntl_arg0_ocall_t)); + ocalloc_size -= sizeof(ms_u_fcntl_arg0_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_cmd = cmd; + status = sgx_ocall(13, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fcntl_arg1_ocall(int* retval, int* error, int fd, int cmd, int arg) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_fcntl_arg1_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fcntl_arg1_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fcntl_arg1_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fcntl_arg1_ocall_t)); + ocalloc_size -= sizeof(ms_u_fcntl_arg1_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_cmd = cmd; + ms->ms_arg = arg; + status = sgx_ocall(14, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_ioctl_arg0_ocall(int* retval, int* error, int fd, int request) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_ioctl_arg0_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_ioctl_arg0_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_ioctl_arg0_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_ioctl_arg0_ocall_t)); + ocalloc_size -= sizeof(ms_u_ioctl_arg0_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_request = request; + status = sgx_ocall(15, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_ioctl_arg1_ocall(int* retval, int* error, int fd, int request, int* arg) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_arg = sizeof(int); + + ms_u_ioctl_arg1_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_ioctl_arg1_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_arg = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(arg, _len_arg); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (arg != NULL) ? _len_arg : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_ioctl_arg1_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_ioctl_arg1_ocall_t)); + ocalloc_size -= sizeof(ms_u_ioctl_arg1_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_request = request; + if (arg != NULL) { + ms->ms_arg = (int*)__tmp; + __tmp_arg = __tmp; + if (_len_arg % sizeof(*arg) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, arg, _len_arg)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_arg); + ocalloc_size -= _len_arg; + } else { + ms->ms_arg = NULL; + } + + status = sgx_ocall(16, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (arg) { + if (memcpy_s((void*)arg, _len_arg, __tmp_arg, _len_arg)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_close_ocall(int* retval, int* error, int fd) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_close_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_close_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_close_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_close_ocall_t)); + ocalloc_size -= sizeof(ms_u_close_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + status = sgx_ocall(17, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_malloc_ocall(void** retval, int* error, size_t size) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_malloc_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_malloc_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_malloc_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_malloc_ocall_t)); + ocalloc_size -= sizeof(ms_u_malloc_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_size = size; + status = sgx_ocall(18, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_free_ocall(void* p) +{ + sgx_status_t status = SGX_SUCCESS; + + ms_u_free_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_free_ocall_t); + void *__tmp = NULL; + + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_free_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_free_ocall_t)); + ocalloc_size -= sizeof(ms_u_free_ocall_t); + + ms->ms_p = p; + status = sgx_ocall(19, ms); + + if (status == SGX_SUCCESS) { + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_mmap_ocall(void** retval, int* error, void* start, size_t length, int prot, int flags, int fd, int64_t offset) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_mmap_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_mmap_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_mmap_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_mmap_ocall_t)); + ocalloc_size -= sizeof(ms_u_mmap_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_start = start; + ms->ms_length = length; + ms->ms_prot = prot; + ms->ms_flags = flags; + ms->ms_fd = fd; + ms->ms_offset = offset; + status = sgx_ocall(20, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_munmap_ocall(int* retval, int* error, void* start, size_t length) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_munmap_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_munmap_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_munmap_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_munmap_ocall_t)); + ocalloc_size -= sizeof(ms_u_munmap_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_start = start; + ms->ms_length = length; + status = sgx_ocall(21, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_msync_ocall(int* retval, int* error, void* addr, size_t length, int flags) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_msync_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_msync_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_msync_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_msync_ocall_t)); + ocalloc_size -= sizeof(ms_u_msync_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_addr = addr; + ms->ms_length = length; + ms->ms_flags = flags; + status = sgx_ocall(22, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_mprotect_ocall(int* retval, int* error, void* addr, size_t length, int prot) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_mprotect_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_mprotect_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_mprotect_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_mprotect_ocall_t)); + ocalloc_size -= sizeof(ms_u_mprotect_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_addr = addr; + ms->ms_length = length; + ms->ms_prot = prot; + status = sgx_ocall(23, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_open_ocall(int* retval, int* error, const char* pathname, int flags) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_pathname = pathname ? strlen(pathname) + 1 : 0; + + ms_u_open_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_open_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(pathname, _len_pathname); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (pathname != NULL) ? _len_pathname : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_open_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_open_ocall_t)); + ocalloc_size -= sizeof(ms_u_open_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (pathname != NULL) { + ms->ms_pathname = (const char*)__tmp; + if (_len_pathname % sizeof(*pathname) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, pathname, _len_pathname)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_pathname); + ocalloc_size -= _len_pathname; + } else { + ms->ms_pathname = NULL; + } + + ms->ms_flags = flags; + status = sgx_ocall(24, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_open64_ocall(int* retval, int* error, const char* path, int oflag, int mode) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + + ms_u_open64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_open64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_open64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_open64_ocall_t)); + ocalloc_size -= sizeof(ms_u_open64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + ms->ms_oflag = oflag; + ms->ms_mode = mode; + status = sgx_ocall(25, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fstat_ocall(int* retval, int* error, int fd, struct stat_t* buf) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_buf = sizeof(struct stat_t); + + ms_u_fstat_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fstat_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fstat_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fstat_ocall_t)); + ocalloc_size -= sizeof(ms_u_fstat_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + if (buf != NULL) { + ms->ms_buf = (struct stat_t*)__tmp; + __tmp_buf = __tmp; + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + status = sgx_ocall(26, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fstat64_ocall(int* retval, int* error, int fd, struct stat64_t* buf) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_buf = sizeof(struct stat64_t); + + ms_u_fstat64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fstat64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fstat64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fstat64_ocall_t)); + ocalloc_size -= sizeof(ms_u_fstat64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + if (buf != NULL) { + ms->ms_buf = (struct stat64_t*)__tmp; + __tmp_buf = __tmp; + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + status = sgx_ocall(27, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_stat_ocall(int* retval, int* error, const char* path, struct stat_t* buf) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + size_t _len_buf = sizeof(struct stat_t); + + ms_u_stat_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_stat_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_stat_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_stat_ocall_t)); + ocalloc_size -= sizeof(ms_u_stat_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + if (buf != NULL) { + ms->ms_buf = (struct stat_t*)__tmp; + __tmp_buf = __tmp; + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + status = sgx_ocall(28, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_stat64_ocall(int* retval, int* error, const char* path, struct stat64_t* buf) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + size_t _len_buf = sizeof(struct stat64_t); + + ms_u_stat64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_stat64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_stat64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_stat64_ocall_t)); + ocalloc_size -= sizeof(ms_u_stat64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + if (buf != NULL) { + ms->ms_buf = (struct stat64_t*)__tmp; + __tmp_buf = __tmp; + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + status = sgx_ocall(29, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_lstat_ocall(int* retval, int* error, const char* path, struct stat_t* buf) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + size_t _len_buf = sizeof(struct stat_t); + + ms_u_lstat_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_lstat_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_lstat_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_lstat_ocall_t)); + ocalloc_size -= sizeof(ms_u_lstat_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + if (buf != NULL) { + ms->ms_buf = (struct stat_t*)__tmp; + __tmp_buf = __tmp; + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + status = sgx_ocall(30, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_lstat64_ocall(int* retval, int* error, const char* path, struct stat64_t* buf) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + size_t _len_buf = sizeof(struct stat64_t); + + ms_u_lstat64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_lstat64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_lstat64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_lstat64_ocall_t)); + ocalloc_size -= sizeof(ms_u_lstat64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + if (buf != NULL) { + ms->ms_buf = (struct stat64_t*)__tmp; + __tmp_buf = __tmp; + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + status = sgx_ocall(31, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_lseek_ocall(uint64_t* retval, int* error, int fd, int64_t offset, int whence) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_lseek_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_lseek_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_lseek_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_lseek_ocall_t)); + ocalloc_size -= sizeof(ms_u_lseek_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_offset = offset; + ms->ms_whence = whence; + status = sgx_ocall(32, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_lseek64_ocall(int64_t* retval, int* error, int fd, int64_t offset, int whence) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_lseek64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_lseek64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_lseek64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_lseek64_ocall_t)); + ocalloc_size -= sizeof(ms_u_lseek64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_offset = offset; + ms->ms_whence = whence; + status = sgx_ocall(33, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_ftruncate_ocall(int* retval, int* error, int fd, int64_t length) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_ftruncate_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_ftruncate_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_ftruncate_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_ftruncate_ocall_t)); + ocalloc_size -= sizeof(ms_u_ftruncate_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_length = length; + status = sgx_ocall(34, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_ftruncate64_ocall(int* retval, int* error, int fd, int64_t length) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_ftruncate64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_ftruncate64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_ftruncate64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_ftruncate64_ocall_t)); + ocalloc_size -= sizeof(ms_u_ftruncate64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_length = length; + status = sgx_ocall(35, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_truncate_ocall(int* retval, int* error, const char* path, int64_t length) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + + ms_u_truncate_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_truncate_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_truncate_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_truncate_ocall_t)); + ocalloc_size -= sizeof(ms_u_truncate_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + ms->ms_length = length; + status = sgx_ocall(36, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_truncate64_ocall(int* retval, int* error, const char* path, int64_t length) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + + ms_u_truncate64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_truncate64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_truncate64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_truncate64_ocall_t)); + ocalloc_size -= sizeof(ms_u_truncate64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + ms->ms_length = length; + status = sgx_ocall(37, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fsync_ocall(int* retval, int* error, int fd) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_fsync_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fsync_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fsync_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fsync_ocall_t)); + ocalloc_size -= sizeof(ms_u_fsync_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + status = sgx_ocall(38, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fdatasync_ocall(int* retval, int* error, int fd) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_fdatasync_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fdatasync_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fdatasync_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fdatasync_ocall_t)); + ocalloc_size -= sizeof(ms_u_fdatasync_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + status = sgx_ocall(39, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fchmod_ocall(int* retval, int* error, int fd, uint32_t mode) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_fchmod_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fchmod_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fchmod_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fchmod_ocall_t)); + ocalloc_size -= sizeof(ms_u_fchmod_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_fd = fd; + ms->ms_mode = mode; + status = sgx_ocall(40, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_unlink_ocall(int* retval, int* error, const char* pathname) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_pathname = pathname ? strlen(pathname) + 1 : 0; + + ms_u_unlink_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_unlink_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(pathname, _len_pathname); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (pathname != NULL) ? _len_pathname : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_unlink_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_unlink_ocall_t)); + ocalloc_size -= sizeof(ms_u_unlink_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (pathname != NULL) { + ms->ms_pathname = (const char*)__tmp; + if (_len_pathname % sizeof(*pathname) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, pathname, _len_pathname)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_pathname); + ocalloc_size -= _len_pathname; + } else { + ms->ms_pathname = NULL; + } + + status = sgx_ocall(41, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_link_ocall(int* retval, int* error, const char* oldpath, const char* newpath) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_oldpath = oldpath ? strlen(oldpath) + 1 : 0; + size_t _len_newpath = newpath ? strlen(newpath) + 1 : 0; + + ms_u_link_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_link_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(oldpath, _len_oldpath); + CHECK_ENCLAVE_POINTER(newpath, _len_newpath); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (oldpath != NULL) ? _len_oldpath : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (newpath != NULL) ? _len_newpath : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_link_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_link_ocall_t)); + ocalloc_size -= sizeof(ms_u_link_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (oldpath != NULL) { + ms->ms_oldpath = (const char*)__tmp; + if (_len_oldpath % sizeof(*oldpath) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, oldpath, _len_oldpath)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_oldpath); + ocalloc_size -= _len_oldpath; + } else { + ms->ms_oldpath = NULL; + } + + if (newpath != NULL) { + ms->ms_newpath = (const char*)__tmp; + if (_len_newpath % sizeof(*newpath) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, newpath, _len_newpath)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_newpath); + ocalloc_size -= _len_newpath; + } else { + ms->ms_newpath = NULL; + } + + status = sgx_ocall(42, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_rename_ocall(int* retval, int* error, const char* oldpath, const char* newpath) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_oldpath = oldpath ? strlen(oldpath) + 1 : 0; + size_t _len_newpath = newpath ? strlen(newpath) + 1 : 0; + + ms_u_rename_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_rename_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(oldpath, _len_oldpath); + CHECK_ENCLAVE_POINTER(newpath, _len_newpath); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (oldpath != NULL) ? _len_oldpath : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (newpath != NULL) ? _len_newpath : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_rename_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_rename_ocall_t)); + ocalloc_size -= sizeof(ms_u_rename_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (oldpath != NULL) { + ms->ms_oldpath = (const char*)__tmp; + if (_len_oldpath % sizeof(*oldpath) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, oldpath, _len_oldpath)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_oldpath); + ocalloc_size -= _len_oldpath; + } else { + ms->ms_oldpath = NULL; + } + + if (newpath != NULL) { + ms->ms_newpath = (const char*)__tmp; + if (_len_newpath % sizeof(*newpath) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, newpath, _len_newpath)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_newpath); + ocalloc_size -= _len_newpath; + } else { + ms->ms_newpath = NULL; + } + + status = sgx_ocall(43, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_chmod_ocall(int* retval, int* error, const char* path, uint32_t mode) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + + ms_u_chmod_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_chmod_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_chmod_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_chmod_ocall_t)); + ocalloc_size -= sizeof(ms_u_chmod_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + ms->ms_mode = mode; + status = sgx_ocall(44, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_readlink_ocall(size_t* retval, int* error, const char* path, char* buf, size_t bufsz) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path = path ? strlen(path) + 1 : 0; + size_t _len_buf = bufsz; + + ms_u_readlink_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_readlink_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path, _len_path); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path != NULL) ? _len_path : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_readlink_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_readlink_ocall_t)); + ocalloc_size -= sizeof(ms_u_readlink_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path != NULL) { + ms->ms_path = (const char*)__tmp; + if (_len_path % sizeof(*path) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path, _len_path)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path); + ocalloc_size -= _len_path; + } else { + ms->ms_path = NULL; + } + + if (buf != NULL) { + ms->ms_buf = (char*)__tmp; + __tmp_buf = __tmp; + if (_len_buf % sizeof(*buf) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + ms->ms_bufsz = bufsz; + status = sgx_ocall(45, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_symlink_ocall(int* retval, int* error, const char* path1, const char* path2) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_path1 = path1 ? strlen(path1) + 1 : 0; + size_t _len_path2 = path2 ? strlen(path2) + 1 : 0; + + ms_u_symlink_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_symlink_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(path1, _len_path1); + CHECK_ENCLAVE_POINTER(path2, _len_path2); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path1 != NULL) ? _len_path1 : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (path2 != NULL) ? _len_path2 : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_symlink_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_symlink_ocall_t)); + ocalloc_size -= sizeof(ms_u_symlink_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (path1 != NULL) { + ms->ms_path1 = (const char*)__tmp; + if (_len_path1 % sizeof(*path1) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path1, _len_path1)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path1); + ocalloc_size -= _len_path1; + } else { + ms->ms_path1 = NULL; + } + + if (path2 != NULL) { + ms->ms_path2 = (const char*)__tmp; + if (_len_path2 % sizeof(*path2) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, path2, _len_path2)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_path2); + ocalloc_size -= _len_path2; + } else { + ms->ms_path2 = NULL; + } + + status = sgx_ocall(46, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_realpath_ocall(char** retval, int* error, const char* pathname) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_pathname = pathname ? strlen(pathname) + 1 : 0; + + ms_u_realpath_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_realpath_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(pathname, _len_pathname); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (pathname != NULL) ? _len_pathname : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_realpath_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_realpath_ocall_t)); + ocalloc_size -= sizeof(ms_u_realpath_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (pathname != NULL) { + ms->ms_pathname = (const char*)__tmp; + if (_len_pathname % sizeof(*pathname) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, pathname, _len_pathname)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_pathname); + ocalloc_size -= _len_pathname; + } else { + ms->ms_pathname = NULL; + } + + status = sgx_ocall(47, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_mkdir_ocall(int* retval, int* error, const char* pathname, uint32_t mode) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_pathname = pathname ? strlen(pathname) + 1 : 0; + + ms_u_mkdir_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_mkdir_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(pathname, _len_pathname); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (pathname != NULL) ? _len_pathname : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_mkdir_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_mkdir_ocall_t)); + ocalloc_size -= sizeof(ms_u_mkdir_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (pathname != NULL) { + ms->ms_pathname = (const char*)__tmp; + if (_len_pathname % sizeof(*pathname) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, pathname, _len_pathname)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_pathname); + ocalloc_size -= _len_pathname; + } else { + ms->ms_pathname = NULL; + } + + ms->ms_mode = mode; + status = sgx_ocall(48, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_rmdir_ocall(int* retval, int* error, const char* pathname) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_pathname = pathname ? strlen(pathname) + 1 : 0; + + ms_u_rmdir_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_rmdir_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(pathname, _len_pathname); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (pathname != NULL) ? _len_pathname : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_rmdir_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_rmdir_ocall_t)); + ocalloc_size -= sizeof(ms_u_rmdir_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (pathname != NULL) { + ms->ms_pathname = (const char*)__tmp; + if (_len_pathname % sizeof(*pathname) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, pathname, _len_pathname)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_pathname); + ocalloc_size -= _len_pathname; + } else { + ms->ms_pathname = NULL; + } + + status = sgx_ocall(49, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_opendir_ocall(void** retval, int* error, const char* pathname) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_pathname = pathname ? strlen(pathname) + 1 : 0; + + ms_u_opendir_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_opendir_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(pathname, _len_pathname); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (pathname != NULL) ? _len_pathname : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_opendir_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_opendir_ocall_t)); + ocalloc_size -= sizeof(ms_u_opendir_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + if (pathname != NULL) { + ms->ms_pathname = (const char*)__tmp; + if (_len_pathname % sizeof(*pathname) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, pathname, _len_pathname)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_pathname); + ocalloc_size -= _len_pathname; + } else { + ms->ms_pathname = NULL; + } + + status = sgx_ocall(50, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_readdir64_r_ocall(int* retval, void* dirp, struct dirent64_t* entry, struct dirent64_t** result) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_entry = sizeof(struct dirent64_t); + size_t _len_result = sizeof(struct dirent64_t*); + + ms_u_readdir64_r_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_readdir64_r_ocall_t); + void *__tmp = NULL; + + void *__tmp_entry = NULL; + void *__tmp_result = NULL; + + CHECK_ENCLAVE_POINTER(entry, _len_entry); + CHECK_ENCLAVE_POINTER(result, _len_result); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (entry != NULL) ? _len_entry : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (result != NULL) ? _len_result : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_readdir64_r_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_readdir64_r_ocall_t)); + ocalloc_size -= sizeof(ms_u_readdir64_r_ocall_t); + + ms->ms_dirp = dirp; + if (entry != NULL) { + ms->ms_entry = (struct dirent64_t*)__tmp; + __tmp_entry = __tmp; + if (memcpy_s(__tmp, ocalloc_size, entry, _len_entry)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_entry); + ocalloc_size -= _len_entry; + } else { + ms->ms_entry = NULL; + } + + if (result != NULL) { + ms->ms_result = (struct dirent64_t**)__tmp; + __tmp_result = __tmp; + if (_len_result % sizeof(*result) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_result, 0, _len_result); + __tmp = (void *)((size_t)__tmp + _len_result); + ocalloc_size -= _len_result; + } else { + ms->ms_result = NULL; + } + + status = sgx_ocall(51, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (entry) { + if (memcpy_s((void*)entry, _len_entry, __tmp_entry, _len_entry)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (result) { + if (memcpy_s((void*)result, _len_result, __tmp_result, _len_result)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_closedir_ocall(int* retval, int* error, void* dirp) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_closedir_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_closedir_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_closedir_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_closedir_ocall_t)); + ocalloc_size -= sizeof(ms_u_closedir_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_dirp = dirp; + status = sgx_ocall(52, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_dirfd_ocall(int* retval, int* error, void* dirp) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + + ms_u_dirfd_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_dirfd_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_dirfd_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_dirfd_ocall_t)); + ocalloc_size -= sizeof(ms_u_dirfd_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_dirp = dirp; + status = sgx_ocall(53, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL u_fstatat64_ocall(int* retval, int* error, int dirfd, const char* pathname, struct stat64_t* buf, int flags) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_error = sizeof(int); + size_t _len_pathname = pathname ? strlen(pathname) + 1 : 0; + size_t _len_buf = sizeof(struct stat64_t); + + ms_u_fstatat64_ocall_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_u_fstatat64_ocall_t); + void *__tmp = NULL; + + void *__tmp_error = NULL; + void *__tmp_buf = NULL; + + CHECK_ENCLAVE_POINTER(error, _len_error); + CHECK_ENCLAVE_POINTER(pathname, _len_pathname); + CHECK_ENCLAVE_POINTER(buf, _len_buf); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (error != NULL) ? _len_error : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (pathname != NULL) ? _len_pathname : 0)) + return SGX_ERROR_INVALID_PARAMETER; + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (buf != NULL) ? _len_buf : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_u_fstatat64_ocall_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_u_fstatat64_ocall_t)); + ocalloc_size -= sizeof(ms_u_fstatat64_ocall_t); + + if (error != NULL) { + ms->ms_error = (int*)__tmp; + __tmp_error = __tmp; + if (_len_error % sizeof(*error) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_error, 0, _len_error); + __tmp = (void *)((size_t)__tmp + _len_error); + ocalloc_size -= _len_error; + } else { + ms->ms_error = NULL; + } + + ms->ms_dirfd = dirfd; + if (pathname != NULL) { + ms->ms_pathname = (const char*)__tmp; + if (_len_pathname % sizeof(*pathname) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + if (memcpy_s(__tmp, ocalloc_size, pathname, _len_pathname)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + __tmp = (void *)((size_t)__tmp + _len_pathname); + ocalloc_size -= _len_pathname; + } else { + ms->ms_pathname = NULL; + } + + if (buf != NULL) { + ms->ms_buf = (struct stat64_t*)__tmp; + __tmp_buf = __tmp; + memset(__tmp_buf, 0, _len_buf); + __tmp = (void *)((size_t)__tmp + _len_buf); + ocalloc_size -= _len_buf; + } else { + ms->ms_buf = NULL; + } + + ms->ms_flags = flags; + status = sgx_ocall(54, ms); + + if (status == SGX_SUCCESS) { + if (retval) *retval = ms->ms_retval; + if (error) { + if (memcpy_s((void*)error, _len_error, __tmp_error, _len_error)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + if (buf) { + if (memcpy_s((void*)buf, _len_buf, __tmp_buf, _len_buf)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + +sgx_status_t SGX_CDECL sgx_oc_cpuidex(int cpuinfo[4], int leaf, int subleaf) +{ + sgx_status_t status = SGX_SUCCESS; + size_t _len_cpuinfo = 4 * sizeof(int); + + ms_sgx_oc_cpuidex_t* ms = NULL; + size_t ocalloc_size = sizeof(ms_sgx_oc_cpuidex_t); + void *__tmp = NULL; + + void *__tmp_cpuinfo = NULL; + + CHECK_ENCLAVE_POINTER(cpuinfo, _len_cpuinfo); + + if (ADD_ASSIGN_OVERFLOW(ocalloc_size, (cpuinfo != NULL) ? _len_cpuinfo : 0)) + return SGX_ERROR_INVALID_PARAMETER; + + __tmp = sgx_ocalloc(ocalloc_size); + if (__tmp == NULL) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + ms = (ms_sgx_oc_cpuidex_t*)__tmp; + __tmp = (void *)((size_t)__tmp + sizeof(ms_sgx_oc_cpuidex_t)); + ocalloc_size -= sizeof(ms_sgx_oc_cpuidex_t); + + if (cpuinfo != NULL) { + ms->ms_cpuinfo = (int*)__tmp; + __tmp_cpuinfo = __tmp; + if (_len_cpuinfo % sizeof(*cpuinfo) != 0) { + sgx_ocfree(); + return SGX_ERROR_INVALID_PARAMETER; + } + memset(__tmp_cpuinfo, 0, _len_cpuinfo); + __tmp = (void *)((size_t)__tmp + _len_cpuinfo); + ocalloc_size -= _len_cpuinfo; + } else { + ms->ms_cpuinfo = NULL; + } + + ms->ms_leaf = leaf; + ms->ms_subleaf = subleaf; + status = sgx_ocall(55, ms); + + if (status == SGX_SUCCESS) { + if (cpuinfo) { + if (memcpy_s((void*)cpuinfo, _len_cpuinfo, __tmp_cpuinfo, _len_cpuinfo)) { + sgx_ocfree(); + return SGX_ERROR_UNEXPECTED; + } + } + } + sgx_ocfree(); + return status; +} + diff --git a/sgx-tests/enclave/codegen/Enclave_t.h b/sgx-tests/enclave/codegen/Enclave_t.h new file mode 100644 index 0000000..af527d8 --- /dev/null +++ b/sgx-tests/enclave/codegen/Enclave_t.h @@ -0,0 +1,88 @@ +#ifndef ENCLAVE_T_H__ +#define ENCLAVE_T_H__ + +#include +#include +#include +#include "sgx_edger8r.h" /* for sgx_ocall etc. */ + +#include "time.h" +#include "inc/stat.h" +#include "sys/uio.h" +#include "inc/stat.h" +#include "inc/dirent.h" + +#include /* for size_t */ + +#define SGX_CAST(type, item) ((type)(item)) + +#ifdef __cplusplus +extern "C" { +#endif + +size_t run_tests_ecall(void); +void t_global_init_ecall(uint64_t id, const uint8_t* path, size_t len); +void t_global_exit_ecall(void); + +sgx_status_t SGX_CDECL u_thread_set_event_ocall(int* retval, int* error, const void* tcs); +sgx_status_t SGX_CDECL u_thread_wait_event_ocall(int* retval, int* error, const void* tcs, const struct timespec* timeout); +sgx_status_t SGX_CDECL u_thread_set_multiple_events_ocall(int* retval, int* error, const void** tcss, int total); +sgx_status_t SGX_CDECL u_thread_setwait_events_ocall(int* retval, int* error, const void* waiter_tcs, const void* self_tcs, const struct timespec* timeout); +sgx_status_t SGX_CDECL u_clock_gettime_ocall(int* retval, int* error, int clk_id, struct timespec* tp); +sgx_status_t SGX_CDECL u_read_ocall(size_t* retval, int* error, int fd, void* buf, size_t count); +sgx_status_t SGX_CDECL u_pread64_ocall(size_t* retval, int* error, int fd, void* buf, size_t count, int64_t offset); +sgx_status_t SGX_CDECL u_readv_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt); +sgx_status_t SGX_CDECL u_preadv64_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt, int64_t offset); +sgx_status_t SGX_CDECL u_write_ocall(size_t* retval, int* error, int fd, const void* buf, size_t count); +sgx_status_t SGX_CDECL u_pwrite64_ocall(size_t* retval, int* error, int fd, const void* buf, size_t count, int64_t offset); +sgx_status_t SGX_CDECL u_writev_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt); +sgx_status_t SGX_CDECL u_pwritev64_ocall(size_t* retval, int* error, int fd, const struct iovec* iov, int iovcnt, int64_t offset); +sgx_status_t SGX_CDECL u_fcntl_arg0_ocall(int* retval, int* error, int fd, int cmd); +sgx_status_t SGX_CDECL u_fcntl_arg1_ocall(int* retval, int* error, int fd, int cmd, int arg); +sgx_status_t SGX_CDECL u_ioctl_arg0_ocall(int* retval, int* error, int fd, int request); +sgx_status_t SGX_CDECL u_ioctl_arg1_ocall(int* retval, int* error, int fd, int request, int* arg); +sgx_status_t SGX_CDECL u_close_ocall(int* retval, int* error, int fd); +sgx_status_t SGX_CDECL u_malloc_ocall(void** retval, int* error, size_t size); +sgx_status_t SGX_CDECL u_free_ocall(void* p); +sgx_status_t SGX_CDECL u_mmap_ocall(void** retval, int* error, void* start, size_t length, int prot, int flags, int fd, int64_t offset); +sgx_status_t SGX_CDECL u_munmap_ocall(int* retval, int* error, void* start, size_t length); +sgx_status_t SGX_CDECL u_msync_ocall(int* retval, int* error, void* addr, size_t length, int flags); +sgx_status_t SGX_CDECL u_mprotect_ocall(int* retval, int* error, void* addr, size_t length, int prot); +sgx_status_t SGX_CDECL u_open_ocall(int* retval, int* error, const char* pathname, int flags); +sgx_status_t SGX_CDECL u_open64_ocall(int* retval, int* error, const char* path, int oflag, int mode); +sgx_status_t SGX_CDECL u_fstat_ocall(int* retval, int* error, int fd, struct stat_t* buf); +sgx_status_t SGX_CDECL u_fstat64_ocall(int* retval, int* error, int fd, struct stat64_t* buf); +sgx_status_t SGX_CDECL u_stat_ocall(int* retval, int* error, const char* path, struct stat_t* buf); +sgx_status_t SGX_CDECL u_stat64_ocall(int* retval, int* error, const char* path, struct stat64_t* buf); +sgx_status_t SGX_CDECL u_lstat_ocall(int* retval, int* error, const char* path, struct stat_t* buf); +sgx_status_t SGX_CDECL u_lstat64_ocall(int* retval, int* error, const char* path, struct stat64_t* buf); +sgx_status_t SGX_CDECL u_lseek_ocall(uint64_t* retval, int* error, int fd, int64_t offset, int whence); +sgx_status_t SGX_CDECL u_lseek64_ocall(int64_t* retval, int* error, int fd, int64_t offset, int whence); +sgx_status_t SGX_CDECL u_ftruncate_ocall(int* retval, int* error, int fd, int64_t length); +sgx_status_t SGX_CDECL u_ftruncate64_ocall(int* retval, int* error, int fd, int64_t length); +sgx_status_t SGX_CDECL u_truncate_ocall(int* retval, int* error, const char* path, int64_t length); +sgx_status_t SGX_CDECL u_truncate64_ocall(int* retval, int* error, const char* path, int64_t length); +sgx_status_t SGX_CDECL u_fsync_ocall(int* retval, int* error, int fd); +sgx_status_t SGX_CDECL u_fdatasync_ocall(int* retval, int* error, int fd); +sgx_status_t SGX_CDECL u_fchmod_ocall(int* retval, int* error, int fd, uint32_t mode); +sgx_status_t SGX_CDECL u_unlink_ocall(int* retval, int* error, const char* pathname); +sgx_status_t SGX_CDECL u_link_ocall(int* retval, int* error, const char* oldpath, const char* newpath); +sgx_status_t SGX_CDECL u_rename_ocall(int* retval, int* error, const char* oldpath, const char* newpath); +sgx_status_t SGX_CDECL u_chmod_ocall(int* retval, int* error, const char* path, uint32_t mode); +sgx_status_t SGX_CDECL u_readlink_ocall(size_t* retval, int* error, const char* path, char* buf, size_t bufsz); +sgx_status_t SGX_CDECL u_symlink_ocall(int* retval, int* error, const char* path1, const char* path2); +sgx_status_t SGX_CDECL u_realpath_ocall(char** retval, int* error, const char* pathname); +sgx_status_t SGX_CDECL u_mkdir_ocall(int* retval, int* error, const char* pathname, uint32_t mode); +sgx_status_t SGX_CDECL u_rmdir_ocall(int* retval, int* error, const char* pathname); +sgx_status_t SGX_CDECL u_opendir_ocall(void** retval, int* error, const char* pathname); +sgx_status_t SGX_CDECL u_readdir64_r_ocall(int* retval, void* dirp, struct dirent64_t* entry, struct dirent64_t** result); +sgx_status_t SGX_CDECL u_closedir_ocall(int* retval, int* error, void* dirp); +sgx_status_t SGX_CDECL u_dirfd_ocall(int* retval, int* error, void* dirp); +sgx_status_t SGX_CDECL u_fstatat64_ocall(int* retval, int* error, int dirfd, const char* pathname, struct stat64_t* buf, int flags); +sgx_status_t SGX_CDECL sgx_oc_cpuidex(int cpuinfo[4], int leaf, int subleaf); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/sgx-tests/enclave/src/lib.rs b/sgx-tests/enclave/src/lib.rs new file mode 100644 index 0000000..ae50b5a --- /dev/null +++ b/sgx-tests/enclave/src/lib.rs @@ -0,0 +1,42 @@ +#![no_std] + +#[macro_use] +extern crate sgx_tstd as std; + +use std::backtrace; +use std::string::String; +use std::vec::Vec; + +use sgx_tunittest::*; + +#[path = "../../../tests/api.rs"] +mod api; + +#[no_mangle] +pub extern "C" fn run_tests_ecall() -> usize { + backtrace::enable_backtrace("enclave.signed.so", backtrace::PrintFormat::Short).unwrap(); + + rsgx_unit_tests!( + api::account_id::decode_bad_alphabet, + api::account_id::decode_bad_lenght, + api::account_id::decode_bad_prefix, + api::account_id::decode_bad_checksum, + api::account_id::encode_random, + api::account_id::encode, + api::account_id::decode, + api::secp256k1_seed::decode_bad_alphabet, + api::secp256k1_seed::decode_bad_lenght, + api::secp256k1_seed::decode_bad_prefix, + api::secp256k1_seed::decode_bad_checksum, + api::secp256k1_seed::encode_random, + api::secp256k1_seed::encode, + api::secp256k1_seed::decode, + api::ed25519_seed::decode_bad_alphabet, + api::ed25519_seed::decode_bad_lenght, + api::ed25519_seed::decode_bad_prefix, + api::ed25519_seed::decode_bad_checksum, + api::ed25519_seed::encode_random, + api::ed25519_seed::encode, + api::ed25519_seed::decode, + ) +} diff --git a/src/error.rs b/src/error.rs index 4e1cd5c..febd410 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,5 @@ +use std::prelude::v1::*; + use std::{error, fmt}; use Error::DecodeError; diff --git a/src/lib.rs b/src/lib.rs index 6fd853b..c099c30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,12 @@ #![doc(test(attr(deny(warnings))))] #![doc(html_root_url = "https://docs.rs/ripple-address-codec/0.1.1")] +#![no_std] + +extern crate sgx_tstd as std; + +use std::prelude::v1::*; + use std::{convert::TryInto, result}; use base_x; diff --git a/tests/api.rs b/tests/api.rs index fbd2389..f245a5b 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -3,6 +3,8 @@ use ripple_address_codec as api; use utils::*; mod utils { + use std::prelude::v1::*; + use std::convert::TryInto; use hex; @@ -45,43 +47,43 @@ mod utils { } } -mod account_id { +pub(crate) mod account_id { use super::*; - #[test] - fn decode_bad_alphabet() { + // #[test] + pub(crate) fn decode_bad_alphabet() { assert_eq!( api::decode_account_id("r_000").unwrap_err(), api::DecodeError ); } - #[test] - fn decode_bad_lenght() { + // #[test] + pub(crate) fn decode_bad_lenght() { assert_eq!( api::decode_account_id("rJrRMgWyPbY35ErN").unwrap_err(), api::DecodeError ); } - #[test] - fn decode_bad_prefix() { + // #[test] + pub(crate) fn decode_bad_prefix() { assert_eq!( api::decode_account_id("bJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN").unwrap_err(), api::DecodeError ); } - #[test] - fn decode_bad_checksum() { + // #[test] + pub(crate) fn decode_bad_checksum() { assert_eq!( api::decode_account_id("rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErA").unwrap_err(), api::DecodeError ); } - #[test] - fn encode_random() { + // #[test] + pub(crate) fn encode_random() { let bytes = get_20_random_bytes(); let encoded = api::encode_account_id(&bytes); let decoded_bytes = api::decode_account_id(&encoded).unwrap(); @@ -91,16 +93,16 @@ mod account_id { assert_eq!(bytes, decoded_bytes); } - #[test] - fn encode() { + // #[test] + pub(crate) fn encode() { assert_eq!( api::encode_account_id(&to_20_bytes("BA8E78626EE42C41B46D46C3048DF3A1C3C87072")), "rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN" ); } - #[test] - fn decode() { + // #[test] + pub(crate) fn decode() { assert_eq!( api::decode_account_id("rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN").unwrap(), to_20_bytes("BA8E78626EE42C41B46D46C3048DF3A1C3C87072") @@ -108,40 +110,40 @@ mod account_id { } } -mod secp256k1_seed { +pub(crate) mod secp256k1_seed { use super::*; - #[test] - fn decode_bad_alphabet() { + // #[test] + pub(crate) fn decode_bad_alphabet() { assert_eq!(api::decode_seed("s_000").unwrap_err(), api::DecodeError); } - #[test] - fn decode_bad_lenght() { + // #[test] + pub(crate) fn decode_bad_lenght() { assert_eq!( api::decode_seed("sn259rEFXrQrWcwV6dfL").unwrap_err(), api::DecodeError ); } - #[test] - fn decode_bad_prefix() { + // #[test] + pub(crate) fn decode_bad_prefix() { assert_eq!( api::decode_seed("Sn259rEFXrQrWyx3Q7XneWcwV6dfL").unwrap_err(), api::DecodeError ); } - #[test] - fn decode_bad_checksum() { + // #[test] + pub(crate) fn decode_bad_checksum() { assert_eq!( api::decode_seed("sn259rEFXrQrWyx3Q7XneWcwV6dfA").unwrap_err(), api::DecodeError ); } - #[test] - fn encode_random() { + // #[test] + pub(crate) fn encode_random() { let bytes = get_16_random_bytes(); let encoded = api::encode_seed(&bytes, &api::Secp256k1); let (decoded_bytes, decoded_kind) = api::decode_seed(&encoded).unwrap(); @@ -151,8 +153,8 @@ mod secp256k1_seed { assert_eq!(decoded_kind, &api::Secp256k1); } - #[test] - fn encode() { + // #[test] + pub(crate) fn encode() { assert_eq!( api::encode_seed( &to_16_bytes("CF2DE378FBDD7E2EE87D486DFB5A7BFF"), @@ -162,8 +164,8 @@ mod secp256k1_seed { ); } - #[test] - fn decode() { + // #[test] + pub(crate) fn decode() { let (bytes, kind) = api::decode_seed("sn259rEFXrQrWyx3Q7XneWcwV6dfL").unwrap(); assert_eq!(to_hex(&bytes), "CF2DE378FBDD7E2EE87D486DFB5A7BFF"); @@ -172,37 +174,37 @@ mod secp256k1_seed { } } -mod ed25519_seed { +pub(crate) mod ed25519_seed { use super::*; - #[test] - fn decode_bad_alphabet() { + // #[test] + pub(crate) fn decode_bad_alphabet() { assert_eq!(api::decode_seed("sEd_000").unwrap_err(), api::DecodeError); } - #[test] - fn decode_bad_lenght() { + // #[test] + pub(crate) fn decode_bad_lenght() { assert_eq!(api::decode_seed("sEdTM1uX8").unwrap_err(), api::DecodeError); } - #[test] - fn decode_bad_prefix() { + // #[test] + pub(crate) fn decode_bad_prefix() { assert_eq!( api::decode_seed("SEdTM1uX8pu2do5XvTnutH6HsouMaM2").unwrap_err(), api::DecodeError ); } - #[test] - fn decode_bad_checksum() { + // #[test] + pub(crate) fn decode_bad_checksum() { assert_eq!( api::decode_seed("sEdTM1uX8pu2do5XvTnutH6HsouMaMA").unwrap_err(), api::DecodeError ); } - #[test] - fn encode_random() { + // #[test] + pub(crate) fn encode_random() { let bytes = get_16_random_bytes(); let encoded = api::encode_seed(&bytes, &api::Ed25519); let (decoded_bytes, decoded_kind) = api::decode_seed(&encoded).unwrap(); @@ -212,8 +214,8 @@ mod ed25519_seed { assert_eq!(decoded_kind, &api::Ed25519); } - #[test] - fn encode() { + // #[test] + pub(crate) fn encode() { assert_eq!( api::encode_seed( &to_16_bytes("4C3A1D213FBDFB14C7C28D609469B341"), @@ -223,8 +225,8 @@ mod ed25519_seed { ); } - #[test] - fn decode() { + // #[test] + pub(crate) fn decode() { let (bytes, kind) = api::decode_seed("sEdTM1uX8pu2do5XvTnutH6HsouMaM2").unwrap(); assert_eq!(to_hex(&bytes), "4C3A1D213FBDFB14C7C28D609469B341");