├── .drone.yml ├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── ci ├── build-lcov ├── gbdt-cov-rustc ├── llvm-gcov └── run-cov ├── dataset ├── YearPred │ ├── README.md │ ├── split.py │ └── xg.py ├── agaricus-lepiota │ ├── agaricus-lepiota.data.txt │ ├── agaricus-lepiota.names.txt │ ├── readme │ ├── split.py │ ├── test.txt │ ├── train.txt │ ├── vectorize.py │ └── vectorized.txt └── iris │ ├── bezdekIris.data.txt │ ├── split.py │ ├── test.txt │ └── train.txt ├── examples ├── convert_xgboost.py ├── test-agaricus-lepiota.rs ├── test-batch.rs ├── test-iris.rs ├── test-multithreads.rs ├── test-xgb-binary-logistic.rs ├── test-xgb-binary-logitraw.rs ├── test-xgb-multi-softmax.rs ├── test-xgb-multi-softprob.rs ├── test-xgb-rank-pairwise.rs ├── test-xgb-reg-linear.rs └── test-xgb-reg-logistic.rs ├── gbdt.pdf ├── sgx ├── gbdt-sgx-test │ ├── Makefile │ ├── app │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ │ └── main.rs │ ├── bin │ │ ├── dataset │ │ └── readme.txt │ ├── common │ │ └── inc │ │ │ ├── assert.h │ │ │ ├── complex.h │ │ │ ├── ctype.h │ │ │ ├── dirent.h │ │ │ ├── endian.h │ │ │ ├── errno.h │ │ │ ├── float.h │ │ │ ├── inttypes.h │ │ │ ├── iso646.h │ │ │ ├── limits.h │ │ │ ├── math.h │ │ │ ├── mbusafecrt.h │ │ │ ├── netdb.h │ │ │ ├── poll.h │ │ │ ├── pwd.h │ │ │ ├── sched.h │ │ │ ├── setjmp.h │ │ │ ├── signal.h │ │ │ ├── stdarg.h │ │ │ ├── stdbool.h │ │ │ ├── stddef.h │ │ │ ├── stdint.h │ │ │ ├── stdio.h │ │ │ ├── stdlib.h │ │ │ ├── string.h │ │ │ ├── sys │ │ │ ├── _types.h │ │ │ ├── cdefs.h │ │ │ ├── endian.h │ │ │ ├── epoll.h │ │ │ ├── ieee.h │ │ │ ├── limits.h │ │ │ ├── sockaddr.h │ │ │ ├── socket.h │ │ │ ├── stat.h │ │ │ ├── stdint.h │ │ │ ├── struct_timespec.h │ │ │ ├── types.h │ │ │ └── uio.h │ │ │ ├── time.h │ │ │ ├── unistd.h │ │ │ ├── wchar.h │ │ │ └── wctype.h │ ├── edl │ │ ├── inc │ │ │ ├── dirent.h │ │ │ └── stat.h │ │ ├── intel │ │ │ ├── sgx_dcap_tvl.edl │ │ │ ├── sgx_pthread.edl │ │ │ ├── sgx_tkey_exchange.edl │ │ │ ├── sgx_tprotected_fs.edl │ │ │ ├── sgx_tstdc.edl │ │ │ └── sgx_tswitchless.edl │ │ ├── sgx_asyncio.edl │ │ ├── sgx_backtrace.edl │ │ ├── sgx_env.edl │ │ ├── sgx_fd.edl │ │ ├── sgx_file.edl │ │ ├── sgx_fs.edl │ │ ├── sgx_mem.edl │ │ ├── sgx_net.edl │ │ ├── sgx_net_switchless.edl │ │ ├── sgx_pipe.edl │ │ ├── sgx_process.edl │ │ ├── sgx_signal.edl │ │ ├── sgx_socket.edl │ │ ├── sgx_stdio.edl │ │ ├── sgx_sys.edl │ │ ├── sgx_thread.edl │ │ ├── sgx_time.edl │ │ └── sgx_tstd.edl │ ├── enclave │ │ ├── Cargo.toml │ │ ├── Enclave.config.xml │ │ ├── Enclave.edl │ │ ├── Enclave.lds │ │ ├── Enclave_private.pem │ │ ├── Makefile │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── test_agaricus_lepiota.rs │ │ │ └── test_lib.rs │ │ └── x86_64-unknown-linux-sgx.json │ └── lib │ │ └── readme.txt └── gbdt-sgx │ └── Cargo.toml ├── src ├── binary_tree.rs ├── config.rs ├── decision_tree.rs ├── errors.rs ├── fitness.rs ├── gradient_boost.rs ├── input.rs └── lib.rs └── xgb-data ├── xgb_binary_logistic ├── agaricus.txt.test ├── agaricus.txt.train ├── gbdt.model ├── pred.csv ├── xg.py └── xgb.model ├── xgb_binary_logitraw ├── agaricus.txt.test ├── agaricus.txt.train ├── gbdt.model ├── pred.csv ├── xg.py └── xgb.model ├── xgb_multi_softmax ├── dermatology.data ├── dermatology.data.test ├── dermatology.data.train ├── gbdt.model ├── pred.csv ├── xg.py └── xgb.model ├── xgb_multi_softprob ├── dermatology.data.test ├── dermatology.data.train ├── gbdt.model ├── pred.csv ├── xg.py └── xgb.model ├── xgb_rank_pairwise ├── gbdt.model ├── mq2008.test ├── pred.csv └── xgb.model ├── xgb_reg_linear ├── gbdt.model ├── machine.txt.test ├── machine.txt.train ├── pred.csv ├── xg.py └── xgb.model └── xgb_reg_logistic ├── agaricus.txt.test ├── agaricus.txt.train ├── gbdt.model ├── pred.csv ├── xg.py └── xgb.model /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | # ignore files 13 | .vscode/* 14 | .idea/* 15 | .DS_Store 16 | 17 | # Automatically generated during cargo test 18 | gbdt.model 19 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gbdt" 3 | version = "0.1.3" 4 | authors = ["Tongxin Li ", "Tianyi Li ", "Yu Ding "] 5 | homepage = "https://github.com/mesalock-linux/gbdt-rs" 6 | repository = "https://github.com/mesalock-linux/gbdt-rs" 7 | license = "Apache-2.0" 8 | description = "A implementation of Gradient Boosting Regression Tree in Rust programming language" 9 | edition = "2018" 10 | 11 | include = [ 12 | "LICENSE", 13 | "Readme.md", 14 | "Cargo.toml", 15 | "src/*.rs", 16 | "examples/*.rs", 17 | ] 18 | 19 | [features] 20 | default = ["enable_training", "input"] 21 | enable_training = [] 22 | profiling = [] 23 | input = ["regex"] 24 | 25 | [badges] 26 | 27 | [lib] 28 | name = "gbdt" 29 | crate-type = ["rlib", "staticlib"] 30 | 31 | [dependencies] 32 | rand="0.8" 33 | serde = "1.0" 34 | serde_derive = "1.0" 35 | serde_json = "1.0" 36 | regex = { version = "1", optional = true } 37 | cfg-if = "1.0" 38 | -------------------------------------------------------------------------------- /ci/build-lcov: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | if [ ! -e lcov/ ] ; then 4 | git clone https://github.com/linux-test-project/lcov.git 5 | cd lcov && make install 6 | fi 7 | -------------------------------------------------------------------------------- /ci/gbdt-cov-rustc: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | get_crate_name() 4 | { 5 | while [[ $# -gt 1 ]] ; do 6 | v=$1 7 | case $v in 8 | --crate-name) 9 | echo $2 10 | return 11 | ;; 12 | esac 13 | shift 14 | done 15 | } 16 | 17 | case $(get_crate_name "$@") in 18 | gbdt | convert_xgboost | test-agaricus-lepiota | test-batch | test-iris | test-multithreads | test-xgb-binary-logistic | test-xgb-binary-logitraw | test-xgb-multi-softmax | test-xgb-multi-softprob | test-xgb-rank-pairwise | test-xgb-reg-linear | test-xgb-reg-logistic) 19 | EXTRA=$COVERAGE_OPTIONS 20 | ;; 21 | *) 22 | EXTRA=$OPTIONS 23 | ;; 24 | esac 25 | 26 | exec "$@" $EXTRA 27 | -------------------------------------------------------------------------------- /ci/llvm-gcov: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | llvm-cov gcov $* -------------------------------------------------------------------------------- /ci/run-cov: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | for path in /usr/lib/llvm-3.9/lib/clang/3.9.[0-9]/lib/linux/; do LLVM_PATH=$path; done 4 | export OPTIONS="-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -C panic=abort -Zpanic_abort_tests -L$LLVM_PATH -lclang_rt.profile-x86_64" 5 | export COVERAGE_OPTIONS="-Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Cpasses=insert-gcov-profiling -C panic=abort -Zpanic_abort_tests -L$LLVM_PATH -lclang_rt.profile-x86_64" 6 | export CARGO_INCREMENTAL=0 7 | 8 | LCOVOPT="--gcov-tool ./ci/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert" 9 | LCOV="/usr/local/bin/lcov" 10 | 11 | # cleanup all 12 | rm -rf *.info *.gcda *.gcno 13 | cargo clean 14 | 15 | # unit tests of gbdt 16 | export RUSTC_WRAPPER="./ci/gbdt-cov-rustc" 17 | cargo rustc --package gbdt --all-features --profile test --lib 18 | rm ./target/debug/deps/gbdt-*.d 19 | ./target/debug/deps/gbdt-* 20 | ${LCOV} ${LCOVOPT} --capture --directory . --base-directory . -o unittest.info 21 | 22 | # cleanup target 23 | rm -rf *.gcda *.gcno 24 | cargo clean 25 | 26 | # integration tests 27 | export RUSTC_WRAPPER="./ci/gbdt-cov-rustc" 28 | cargo rustc --all-features --examples 29 | find target/debug/examples -executable -type f -exec ./{} \; > /dev/null 30 | ${LCOV} ${LCOVOPT} --capture --directory . --base-directory . -o examples.info 31 | 32 | # combining and filtering 33 | ${LCOV} ${LCOVOPT} --add unittest.info --add examples.info -o coverage.info 34 | ${LCOV} ${LCOVOPT} --extract coverage.info `find "$(cd src; pwd)" -name "*.rs"` -o final.info 35 | 36 | # generate report if not in CI 37 | if [[ "$CI" != true ]]; then 38 | genhtml --branch-coverage --demangle-cpp --legend final.info -o target/coverage/ --ignore-errors source 39 | fi 40 | -------------------------------------------------------------------------------- /dataset/YearPred/README.md: -------------------------------------------------------------------------------- 1 | Download dataset at and run split.py to split train and test data. -------------------------------------------------------------------------------- /dataset/YearPred/split.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | path = "YearPredictionMSD.txt" 4 | train_out = "train.csv" 5 | train_cnt = 463715 6 | test_out = "test.csv" 7 | 8 | lines = open(path).readlines() 9 | total_cnt = len(lines) 10 | random.shuffle(lines) 11 | ptr = 0 12 | with open(train_out, "w") as f: 13 | while ptr < train_cnt: 14 | f.write(lines[ptr]) 15 | ptr += 1 16 | with open(test_out, "w") as f: 17 | while ptr < total_cnt: 18 | f.write(lines[ptr]) 19 | ptr += 1 20 | -------------------------------------------------------------------------------- /dataset/YearPred/xg.py: -------------------------------------------------------------------------------- 1 | """ 2 | To use this file: 3 | 1. Install xgboost, sklearn, pandas and numpy 4 | 2. Download dataset from and extract it. 5 | 3. Set DATASET_DIR on line 25 to the directory holds the extracted data. 6 | 4. set MODEL_DIR on line 31 to the directory you want to save the model. 7 | 5. Uncomment the function `pre_work()` in main. 8 | 6. Run this scripts. 9 | 10 | ========== 11 | This script runs about 100 mins on iMac Pro. 12 | """ 13 | 14 | 15 | import xgboost as xgb 16 | import numpy as np 17 | from sklearn.metrics import r2_score 18 | from sklearn.preprocessing import LabelEncoder 19 | from sklearn.pipeline import Pipeline 20 | import random 21 | import time 22 | import pickle 23 | 24 | params = { 25 | 'booster': 'gbtree', 26 | 'objective': 'multi:softmax', 27 | 'eta': 0.1, 28 | 'max_depth': 6, 29 | 'num_class': 90, 30 | 'nthread': 1, 31 | } 32 | 33 | def train(): 34 | data = np.loadtxt('./train.csv', delimiter=',', converters={0: lambda(x): int(x.strip())-1922}) 35 | train_X = data[:, 1:] 36 | train_Y = data[:, 0] 37 | 38 | xgb_train = xgb.DMatrix(train_X, label=train_Y) 39 | plst = list(params.items()) 40 | print("Training started.") 41 | t0 = time.time() 42 | model = xgb.train(plst, xgb_train, num_boost_round=5, 43 | ) 44 | print("%.3fs taken for training" % (time.time() - t0)) 45 | print("Saving model...") 46 | model.save_model("xgb.model") 47 | 48 | def predict(): 49 | t0 = time.time() 50 | model = xgb.Booster() 51 | model.load_model("xgb.model") 52 | t1 = time.time() 53 | print("%.3fs taken for load_model" % (t1 - t0)) 54 | 55 | t0 = time.time() 56 | data = np.loadtxt('./test.csv', delimiter=',', converters={0: lambda(x): int(x.strip())-1922}) 57 | test_X = data[:, 1:] 58 | test_Y = data[:, 0] 59 | 60 | xgb_test = xgb.DMatrix(test_X, label=test_Y) 61 | t1 = time.time() 62 | print("%.3fs taken for load_data" % (t1 - t0)) 63 | 64 | t0 = time.time() 65 | preds = model.predict(xgb_test) 66 | t1 = time.time() 67 | print("%.3fs taken for predicting" % (t1 - t0)) 68 | 69 | print("Saving results...") 70 | np.savetxt("./pred.csv", preds, delimiter=",") 71 | 72 | 73 | if __name__ == "__main__": 74 | train() 75 | predict() 76 | -------------------------------------------------------------------------------- /dataset/agaricus-lepiota/agaricus-lepiota.names.txt: -------------------------------------------------------------------------------- 1 | 2 | e,p. 3 | 4 | 5 | cap-shape: b,c,x,f,k,s. 6 | 7 | cap-surface: f,g,y,s. 8 | 9 | cap-color: n,b,c,g,r,p,u,e,w,y. 10 | 11 | bruises?: t,f. 12 | 13 | odor: a,l,c,y,f,m,n,p,s. 14 | 15 | gill-attachment: a,d,f,n. 16 | 17 | gill-spacing: c,w,d. 18 | 19 | gill-size: b,n. 20 | 21 | gill-color: k,n,b,h,g,r,o,p,u,e,w,y. 22 | 23 | stalk-shape: e,t. 24 | 25 | stalk-root: b,c,u,e,z,r. 26 | 27 | stalk-surface-above-ring: f,y,k,s. 28 | 29 | stalk-surface-below-ring: f,y,k,s. 30 | 31 | stalk-color-above-ring: n,b,c,g,o,p,e,w,y. 32 | 33 | stalk-color-below-ring: n,b,c,g,o,p,e,w,y. 34 | 35 | veil-type: p,u. 36 | 37 | veil-color: n,o,w,y. 38 | 39 | ring-number: n,o,t. 40 | 41 | ring-type: c,e,f,l,n,p,s,z. 42 | 43 | spore-print-color: k,n,b,h,r,o,u,w,y. 44 | 45 | population: a,c,n,s,v,y. 46 | 47 | habitat: g,l,m,p,u,w,d. 48 | 49 | -------------------------------------------------------------------------------- /dataset/agaricus-lepiota/readme: -------------------------------------------------------------------------------- 1 | http://www.grappa.univ-lille3.fr/~torre/Recherche/Experiments/Datasets/#agaricus-lepiota 2 | 3 | **vecrorize.py** 4 | 5 | Convert source data to vector. 6 | 7 | **split.py** 8 | 9 | Randomly split data to train set and test set. -------------------------------------------------------------------------------- /dataset/agaricus-lepiota/split.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def x(l): 4 | return l 5 | 6 | ratio = 0.2 7 | fn = "vectorized.txt" 8 | datas = None 9 | with open(fn, "r") as f: 10 | datas = f.readlines() 11 | datas = [l for l in datas if l.strip("\n") != ""] 12 | 13 | random.shuffle(datas) 14 | 15 | test = int(len(datas) * ratio) 16 | 17 | cnt = 0 18 | with open("test.txt", "w") as f: 19 | while cnt < test: 20 | f.write(x(datas[cnt])) 21 | cnt += 1 22 | 23 | with open("train.txt", "w") as f: 24 | while cnt < len(datas): 25 | f.write(x(datas[cnt])) 26 | cnt += 1 -------------------------------------------------------------------------------- /dataset/agaricus-lepiota/vectorize.py: -------------------------------------------------------------------------------- 1 | d = [] 2 | with open("agaricus-lepiota.data.txt") as f: 3 | d = [_.split(",") for _ in f.readlines()] 4 | 5 | l = len(d[0]) 6 | for attr in range(l): 7 | s = set([x[attr] for x in d]) 8 | dic = {} 9 | cnt = 0 10 | for each in s: 11 | dic[each] = cnt 12 | cnt += 1 13 | for _ in range(len(d)): 14 | d[_][attr] = dic[d[_][attr]] 15 | 16 | 17 | for each in d: 18 | if each[-1] == 0: 19 | each[-1] = -1 20 | with open("vectorized.txt", "w") as f: 21 | for each in d: 22 | f.write( 23 | ",".join([str(_) for _ in each]) + "\n" 24 | ) -------------------------------------------------------------------------------- /dataset/iris/split.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def x(l): 4 | ret = l.replace("Iris-versicolor", "1") 5 | ret = ret.replace("Iris-virginica", "2") 6 | ret = ret.replace("Iris-setosa", "3") 7 | return ret 8 | 9 | ratio = 0.2 10 | fn = "bezdekIris.data.txt" 11 | datas = None 12 | with open(fn, "r") as f: 13 | datas = f.readlines() 14 | datas = [l for l in datas if l.strip("\n") != ""] 15 | 16 | random.shuffle(datas) 17 | 18 | test = int(len(datas) * ratio) 19 | 20 | cnt = 0 21 | with open("test.txt", "w") as f: 22 | while cnt < test: 23 | f.write(x(datas[cnt])) 24 | cnt += 1 25 | 26 | with open("train.txt", "w") as f: 27 | while cnt < len(datas): 28 | f.write(x(datas[cnt])) 29 | cnt += 1 -------------------------------------------------------------------------------- /dataset/iris/test.txt: -------------------------------------------------------------------------------- 1 | 7.7,2.6,6.9,2.3,2 2 | 6.1,2.9,4.7,1.4,1 3 | 6.0,2.9,4.5,1.5,1 4 | 5.8,2.6,4.0,1.2,1 5 | 7.6,3.0,6.6,2.1,2 6 | 5.6,2.8,4.9,2.0,2 7 | 5.5,2.5,4.0,1.3,1 8 | 7.1,3.0,5.9,2.1,2 9 | 5.0,3.5,1.6,0.6,3 10 | 6.7,3.0,5.2,2.3,2 11 | 4.6,3.4,1.4,0.3,3 12 | 5.1,3.5,1.4,0.2,3 13 | 5.4,3.7,1.5,0.2,3 14 | 5.0,3.4,1.6,0.4,3 15 | 4.5,2.3,1.3,0.3,3 16 | 4.9,3.6,1.4,0.1,3 17 | 7.0,3.2,4.7,1.4,1 18 | 6.0,2.2,4.0,1.0,1 19 | 6.0,3.0,4.8,1.8,2 20 | 6.7,3.1,5.6,2.4,2 21 | 5.7,2.9,4.2,1.3,1 22 | 6.1,3.0,4.9,1.8,2 23 | 6.7,3.1,4.7,1.5,1 24 | 5.4,3.9,1.3,0.4,3 25 | 4.8,3.4,1.9,0.2,3 26 | 6.4,3.2,5.3,2.3,2 27 | 7.2,3.0,5.8,1.6,2 28 | 5.0,3.5,1.3,0.3,3 29 | 6.3,2.5,4.9,1.5,1 30 | 5.0,3.4,1.5,0.2,3 31 | -------------------------------------------------------------------------------- /dataset/iris/train.txt: -------------------------------------------------------------------------------- 1 | 4.8,3.0,1.4,0.3,3 2 | 5.1,3.7,1.5,0.4,3 3 | 6.7,2.5,5.8,1.8,2 4 | 5.5,2.4,3.7,1.0,1 5 | 4.8,3.4,1.6,0.2,3 6 | 6.9,3.1,5.4,2.1,2 7 | 5.4,3.9,1.7,0.4,3 8 | 6.9,3.1,4.9,1.5,1 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| 6.3,2.7,4.9,1.8,2 103 | 5.7,2.5,5.0,2.0,2 104 | 5.7,2.6,3.5,1.0,1 105 | 6.4,2.7,5.3,1.9,2 106 | 7.7,2.8,6.7,2.0,2 107 | 5.5,2.3,4.0,1.3,1 108 | 5.3,3.7,1.5,0.2,3 109 | 6.7,3.1,4.4,1.4,1 110 | 6.2,3.4,5.4,2.3,2 111 | 5.8,4.0,1.2,0.2,3 112 | 7.3,2.9,6.3,1.8,2 113 | 6.3,2.9,5.6,1.8,2 114 | 5.8,2.8,5.1,2.4,2 115 | 6.8,3.0,5.5,2.1,2 116 | 5.1,3.8,1.6,0.2,3 117 | 6.5,2.8,4.6,1.5,1 118 | 7.4,2.8,6.1,1.9,2 119 | 4.9,3.0,1.4,0.2,3 120 | 5.8,2.7,5.1,1.9,2 121 | -------------------------------------------------------------------------------- /examples/convert_xgboost.py: -------------------------------------------------------------------------------- 1 | """ 2 | Before use this file, install xgboost first 3 | """ 4 | from __future__ import print_function 5 | import sys 6 | import xgboost as xgb 7 | import os 8 | import struct 9 | from ctypes import cdll 10 | from ctypes import c_float, c_uint, c_char_p, c_bool 11 | 12 | LIB_PATH = "./libgbdt.so" 13 | 14 | def convert(input_model, objective, output_file): 15 | model = xgb.Booster() 16 | model.load_model(input_model) 17 | tmp_file = output_file + ".gbdt_rs.mid" 18 | # extract base score 19 | try : 20 | with open(input_model, "rb") as f: 21 | model_format = struct.unpack('cccc',f.read(4)) 22 | model_format = b"".join(model_format) 23 | if model_format == b"bs64": 24 | print("This model type is not supported") 25 | elif model_format != b"binf": 26 | f.seek(0) 27 | base_score = struct.unpack('f',f.read(4))[0] 28 | except Exception as e: 29 | print("error: ", e) 30 | return 1 31 | 32 | if os.path.exists(tmp_file): 33 | print("Intermediate file %s exists. Please remove this file or change your output file path" % tmp_file) 34 | return 1 35 | 36 | # dump json 37 | model.dump_model(tmp_file, dump_format="json") 38 | 39 | # add base score to json file 40 | try: 41 | with open(output_file, "w") as f: 42 | f.write(repr(base_score) + "\n") 43 | with open(tmp_file) as f2: 44 | for line in f2.readlines(): 45 | f.write(line) 46 | except Exception as e: 47 | print("error: ", e) 48 | os.remove(tmp_file) 49 | return 1 50 | 51 | os.remove(tmp_file) 52 | return 0 53 | 54 | 55 | if __name__ == "__main__": 56 | if len(sys.argv) != 4: 57 | print("usage: python script input_model_path objective output_file_path") 58 | print("supported booster: gbtree") 59 | print("supported objective: 'reg:linear', 'binary:logistic', 'reg:logistic'," + \ 60 | "'binary:logitraw', 'multi:softmax', 'multi:softprob', 'rank:pairwise'") 61 | exit(1) 62 | convert(sys.argv[1], sys.argv[2], sys.argv[3]) 63 | 64 | 65 | -------------------------------------------------------------------------------- /examples/test-agaricus-lepiota.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::config::Config; 4 | use gbdt::decision_tree::{DataVec, PredVec}; 5 | use gbdt::fitness::AUC; 6 | use gbdt::gradient_boost::GBDT; 7 | use gbdt::input::{load, InputFormat}; 8 | 9 | fn main() { 10 | let mut cfg = Config::new(); 11 | cfg.set_feature_size(22); 12 | cfg.set_max_depth(3); 13 | cfg.set_iterations(50); 14 | cfg.set_shrinkage(0.1); 15 | cfg.set_loss("LogLikelyhood"); 16 | cfg.set_debug(true); 17 | //cfg.set_data_sample_ratio(0.8); 18 | //cfg.set_feature_sample_ratio(0.5); 19 | cfg.set_training_optimization_level(2); 20 | 21 | // load data 22 | let train_file = "dataset/agaricus-lepiota/train.txt"; 23 | let test_file = "dataset/agaricus-lepiota/test.txt"; 24 | 25 | let mut input_format = InputFormat::csv_format(); 26 | input_format.set_feature_size(22); 27 | input_format.set_label_index(22); 28 | let mut train_dv: DataVec = 29 | load(train_file, input_format).expect("failed to load training data"); 30 | let test_dv: DataVec = load(test_file, input_format).expect("failed to load test data"); 31 | 32 | // train and save model 33 | let mut gbdt = GBDT::new(&cfg); 34 | gbdt.fit(&mut train_dv); 35 | gbdt.save_model("gbdt.model") 36 | .expect("failed to save the model"); 37 | 38 | // load model and do inference 39 | let model = GBDT::load_model("gbdt.model").expect("failed to load the model"); 40 | let predicted: PredVec = model.predict(&test_dv); 41 | 42 | assert_eq!(predicted.len(), test_dv.len()); 43 | let mut correct = 0; 44 | let mut wrong = 0; 45 | for i in 0..predicted.len() { 46 | let label = if predicted[i] > 0.5 { 1.0 } else { -1.0 }; 47 | if (test_dv[i].label - label).abs() < 0.0001 { 48 | correct += 1; 49 | } else { 50 | wrong += 1; 51 | }; 52 | //println!("[{}] {} {}", i, test_dv[i].label, predicted[i]); 53 | } 54 | 55 | println!("correct: {}", correct); 56 | println!("wrong: {}", wrong); 57 | 58 | let auc = AUC(&test_dv, &predicted, test_dv.len()); 59 | println!("AUC: {}", auc); 60 | 61 | use gbdt::fitness::almost_equal; 62 | assert_eq!(wrong, 0); 63 | assert!(almost_equal(auc, 1.0)); 64 | } 65 | -------------------------------------------------------------------------------- /examples/test-batch.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::ValueType; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Use xg.py in xgb-data/xgb_reg_linear to generate a model and get prediction results from xgboost. 11 | // Call this command to convert xgboost model: 12 | // python examples/convert_xgboost.py xgb-data/xgb_reg_linear/xgb.model "reg:linear" xgb-data/xgb_reg_linear/gbdt.model 13 | // load model 14 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_reg_linear/gbdt.model", "reg:linear") 15 | .expect("failed to load model"); 16 | 17 | // load test data 18 | let test_file = "xgb-data/xgb_reg_linear/machine.txt.test"; 19 | let mut input_format = input::InputFormat::txt_format(); 20 | input_format.set_feature_size(36); 21 | input_format.set_delimeter(' '); 22 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 23 | 24 | // inference 25 | println!("start prediction"); 26 | let mut predicted = Vec::with_capacity(test_data.len()); 27 | for (count, data) in test_data.chunks(12).enumerate() { 28 | println!("batch {}: size {}", count, data.len()); 29 | let mut predicted_batch = gbdt.predict(&data.to_vec()); 30 | predicted.append(&mut predicted_batch); 31 | } 32 | assert_eq!(predicted.len(), test_data.len()); 33 | 34 | // compare to xgboost prediction results 35 | let predict_result = "xgb-data/xgb_reg_linear/pred.csv"; 36 | 37 | let mut xgb_results = Vec::new(); 38 | let file = File::open(predict_result).expect("failed to load pred.csv"); 39 | let reader = BufReader::new(file); 40 | for line in reader.lines() { 41 | let text = line.expect("failed to read data from pred.csv"); 42 | let value: ValueType = text.parse().expect("failed to parse data from pred.csv"); 43 | xgb_results.push(value); 44 | } 45 | 46 | let mut max_diff: ValueType = -1.0; 47 | for (value1, value2) in predicted.iter().zip(xgb_results.iter()) { 48 | println!("{} {}", value1, value2); 49 | let diff = (value1 - value2).abs(); 50 | if diff > max_diff { 51 | max_diff = diff; 52 | } 53 | } 54 | 55 | println!( 56 | "Compared to results from xgboost, max error is: {:.10}", 57 | max_diff 58 | ); 59 | assert!(max_diff < 0.01); 60 | } 61 | -------------------------------------------------------------------------------- /examples/test-iris.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::config::Config; 4 | use gbdt::decision_tree::{DataVec, PredVec}; 5 | use gbdt::fitness::almost_equal_thrs; 6 | use gbdt::gradient_boost::GBDT; 7 | use gbdt::input::{load, InputFormat}; 8 | 9 | fn main() { 10 | let mut cfg = Config::new(); 11 | cfg.set_feature_size(4); 12 | cfg.set_max_depth(4); 13 | cfg.set_iterations(100); 14 | cfg.set_shrinkage(0.1); 15 | cfg.set_loss("LAD"); 16 | cfg.set_debug(true); 17 | cfg.set_training_optimization_level(2); 18 | 19 | // load data 20 | let train_file = "dataset/iris/train.txt"; 21 | let test_file = "dataset/iris/test.txt"; 22 | 23 | let mut input_format = InputFormat::csv_format(); 24 | input_format.set_feature_size(4); 25 | input_format.set_label_index(4); 26 | let mut train_dv: DataVec = 27 | load(train_file, input_format).expect("failed to load training data"); 28 | let test_dv: DataVec = load(test_file, input_format).expect("failed to load test data"); 29 | 30 | // train and save the model 31 | let mut gbdt = GBDT::new(&cfg); 32 | gbdt.fit(&mut train_dv); 33 | gbdt.save_model("gbdt.model") 34 | .expect("failed to save the model"); 35 | 36 | // load the model and do inference 37 | let model = GBDT::load_model("gbdt.model").expect("failed to load the model"); 38 | let predicted: PredVec = model.predict(&test_dv); 39 | 40 | assert_eq!(predicted.len(), test_dv.len()); 41 | let mut correct = 0; 42 | let mut wrong = 0; 43 | for i in 0..predicted.len() { 44 | if almost_equal_thrs(test_dv[i].label, predicted[i], 0.0001) { 45 | correct += 1; 46 | } else { 47 | wrong += 1; 48 | }; 49 | println!("[{}] {} {}", i, test_dv[i].label, predicted[i]); 50 | } 51 | 52 | println!("correct: {}", correct); 53 | println!("wrong: {}", wrong); 54 | 55 | assert!(wrong <= 2); 56 | } 57 | -------------------------------------------------------------------------------- /examples/test-multithreads.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::gradient_boost::GBDT; 4 | 5 | use std::time::Instant; 6 | 7 | use gbdt::input; 8 | use std::sync::Arc; 9 | use std::thread; 10 | 11 | fn main() { 12 | let thread_num = 12; 13 | let feature_size = 36; 14 | let model_path = "xgb-data/xgb_reg_linear/gbdt.model"; 15 | let test_file = "xgb-data/xgb_reg_linear/machine.txt.test"; 16 | 17 | // load model 18 | let gbdt = GBDT::from_xgboost_dump(model_path, "reg:linear").expect("faild to load model"); 19 | 20 | // load test data 21 | let mut fmt = input::InputFormat::txt_format(); 22 | fmt.set_feature_size(feature_size); 23 | fmt.set_delimeter(' '); 24 | let mut test_data = input::load(test_file, fmt).unwrap(); 25 | 26 | // split test data to `thread_num` vectors. 27 | let t1 = Instant::now(); 28 | let mut handles = vec![]; 29 | let mut test_data_vec = vec![]; 30 | let data_size = test_data.len(); 31 | let batch_size = (data_size - 1) / thread_num + 1; 32 | for one_batch in test_data.chunks(batch_size) { 33 | test_data_vec.push(one_batch.to_vec()) 34 | } 35 | 36 | test_data.clear(); 37 | test_data.shrink_to_fit(); 38 | let t2 = Instant::now(); 39 | println!("split data: {:?}", t2 - t1); 40 | 41 | // Create `thread_num` threads. Call gbdt::predict in parallel 42 | let t1 = Instant::now(); 43 | let gbdt_arc = Arc::new(gbdt); 44 | for data in test_data_vec.into_iter() { 45 | let gbdt_clone = Arc::clone(&gbdt_arc); 46 | let handle = thread::spawn(move || gbdt_clone.predict(&data)); 47 | handles.push(handle) 48 | } 49 | 50 | // collect results 51 | let mut preds = Vec::with_capacity(data_size); 52 | for handle in handles { 53 | preds.append(&mut handle.join().unwrap()); 54 | } 55 | 56 | let t2 = Instant::now(); 57 | println!("predict data: {:?}", t2 - t1); 58 | assert_eq!(preds.len(), data_size); 59 | } 60 | -------------------------------------------------------------------------------- /examples/test-xgb-binary-logistic.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::{PredVec, ValueType}; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Use xg.py in xgb-data/xgb_binary_logistic to generate a model and get prediction results from xgboost. 11 | // Call this command to convert xgboost model: 12 | // python examples/convert_xgboost.py xgb-data/xgb_binary_logistic/xgb.model "binary:logistic" xgb-data/xgb_binary_logistic/gbdt.model 13 | // load model 14 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_binary_logistic/gbdt.model", "binary:logistic") 15 | .expect("failed to load model"); 16 | 17 | // load test data 18 | let test_file = "xgb-data/xgb_binary_logistic/agaricus.txt.test"; 19 | let mut input_format = input::InputFormat::txt_format(); 20 | input_format.set_feature_size(126); 21 | input_format.set_delimeter(' '); 22 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 23 | 24 | // inference 25 | println!("start prediction"); 26 | let predicted: PredVec = gbdt.predict(&test_data); 27 | assert_eq!(predicted.len(), test_data.len()); 28 | 29 | // compare to xgboost prediction results 30 | let predict_result = "xgb-data/xgb_binary_logistic/pred.csv"; 31 | 32 | let mut xgb_results = Vec::new(); 33 | let file = File::open(predict_result).expect("failed to load pred.csv"); 34 | let reader = BufReader::new(file); 35 | for line in reader.lines() { 36 | let text = line.expect("failed to read data from pred.csv"); 37 | let value: ValueType = text.parse().expect("failed to parse data from pred.csv"); 38 | xgb_results.push(value); 39 | } 40 | 41 | let mut max_diff: ValueType = -1.0; 42 | for (value1, value2) in predicted.iter().zip(xgb_results.iter()) { 43 | println!("{} {}", value1, value2); 44 | let diff = (value1 - value2).abs(); 45 | if diff > max_diff { 46 | max_diff = diff; 47 | } 48 | } 49 | 50 | println!( 51 | "Compared to results from xgboost, max error is: {:.10}", 52 | max_diff 53 | ); 54 | assert!(max_diff < 0.01); 55 | } 56 | -------------------------------------------------------------------------------- /examples/test-xgb-binary-logitraw.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::{PredVec, ValueType}; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Use xg.py in xgb-data/xgb_binary_logitraw to generate a model and get prediction results from xgboost. 11 | // Call this command to convert xgboost model: 12 | // python examples/convert_xgboost.py xgb-data/xgb_binary_logitraw/xgb.model "binary:logitraw" xgb-data/xgb_binary_logitraw/gbdt.model 13 | // load model 14 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_binary_logitraw/gbdt.model", "binary:logitraw") 15 | .expect("failed to load model"); 16 | 17 | // load test data 18 | let test_file = "xgb-data/xgb_binary_logitraw/agaricus.txt.test"; 19 | let mut input_format = input::InputFormat::txt_format(); 20 | input_format.set_feature_size(126); 21 | input_format.set_delimeter(' '); 22 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 23 | 24 | // inference 25 | println!("start prediction"); 26 | let predicted: PredVec = gbdt.predict(&test_data); 27 | assert_eq!(predicted.len(), test_data.len()); 28 | 29 | // compare to xgboost prediction results 30 | let predict_result = "xgb-data/xgb_binary_logitraw/pred.csv"; 31 | 32 | let mut xgb_results = Vec::new(); 33 | let file = File::open(predict_result).expect("failed to load pred.csv"); 34 | let reader = BufReader::new(file); 35 | for line in reader.lines() { 36 | let text = line.expect("failed to read data from pred.csv"); 37 | let value: ValueType = text.parse().expect("failed to parse data from pred.csv"); 38 | xgb_results.push(value); 39 | } 40 | 41 | let mut max_diff: ValueType = -1.0; 42 | for (value1, value2) in predicted.iter().zip(xgb_results.iter()) { 43 | println!("{} {}", value1, value2); 44 | let diff = (value1 - value2).abs(); 45 | if diff > max_diff { 46 | max_diff = diff; 47 | } 48 | } 49 | 50 | println!( 51 | "Compared to results from xgboost, max error is: {:.10}", 52 | max_diff 53 | ); 54 | assert!(max_diff < 0.01); 55 | } 56 | -------------------------------------------------------------------------------- /examples/test-xgb-multi-softmax.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::ValueType; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Use xg.py in xgb-data/xgb_multi_softmax to generate a model and get prediction results from xgboost. 11 | // Call this command to convert xgboost model: 12 | // python examples/convert_xgboost.py xgb-data/xgb_multi_softmax/xgb.model "multi:softmax" xgb-data/xgb_multi_softmax/gbdt.model 13 | // load model 14 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_multi_softmax/gbdt.model", "multi:softmax") 15 | .expect("failed to load model"); 16 | 17 | // load test data 18 | let test_file = "xgb-data/xgb_multi_softmax/dermatology.data.test"; 19 | let mut input_format = input::InputFormat::csv_format(); 20 | input_format.set_label_index(34); 21 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 22 | 23 | // inference 24 | println!("start prediction"); 25 | let (labels, _probs) = gbdt.predict_multiclass(&test_data, 6); 26 | assert_eq!(labels.len(), test_data.len()); 27 | 28 | // compare to xgboost prediction results 29 | let predict_result = "xgb-data/xgb_multi_softmax/pred.csv"; 30 | 31 | let mut xgb_results = Vec::new(); 32 | let file = File::open(predict_result).expect("failed to load pred.csv"); 33 | let reader = BufReader::new(file); 34 | for line in reader.lines() { 35 | let text = line.expect("failed to read data from pred.csv"); 36 | let value: ValueType = text.parse().expect("failed to parse data from pred.csv"); 37 | xgb_results.push(value); 38 | } 39 | 40 | let mut max_diff: ValueType = -1.0; 41 | for (value1, value2) in labels.iter().zip(xgb_results.iter()) { 42 | println!("{} {}", value1, value2); 43 | let diff = (*value1 as ValueType - *value2).abs(); 44 | if diff > max_diff { 45 | max_diff = diff; 46 | } 47 | } 48 | 49 | println!( 50 | "Compared to results from xgboost, max error is: {:.10}", 51 | max_diff 52 | ); 53 | assert!(max_diff < 0.01); 54 | } 55 | -------------------------------------------------------------------------------- /examples/test-xgb-multi-softprob.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::ValueType; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Use xg.py in xgb-data/xgb_multi_softprob to generate a model and get prediction results from xgboost. 11 | // Call this command to convert xgboost model: 12 | // python examples/convert_xgboost.py xgb-data/xgb_multi_softprob/xgb.model "multi:softprob" xgb-data/xgb_multi_softprob/gbdt.model 13 | // load model 14 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_multi_softprob/gbdt.model", "multi:softprob") 15 | .expect("failed to load model"); 16 | 17 | // load test data 18 | let test_file = "xgb-data/xgb_multi_softprob/dermatology.data.test"; 19 | let mut input_format = input::InputFormat::csv_format(); 20 | input_format.set_label_index(34); 21 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 22 | 23 | // inference 24 | println!("start prediction"); 25 | let (labels, probs) = gbdt.predict_multiclass(&test_data, 6); 26 | assert_eq!(labels.len(), test_data.len()); 27 | 28 | // compare to xgboost prediction results 29 | let predict_result = "xgb-data/xgb_multi_softprob/pred.csv"; 30 | 31 | let mut xgb_results = Vec::new(); 32 | let file = File::open(predict_result).expect("failed to load pred.csv"); 33 | let reader = BufReader::new(file); 34 | for line in reader.lines() { 35 | let text = line.expect("failed to read data from pred.csv"); 36 | let split_results: Vec<&str> = text.trim().split(',').collect(); 37 | for item in split_results.iter() { 38 | let value: ValueType = item.parse().expect("failed to parse data from pred.csv"); 39 | xgb_results.push(value); 40 | } 41 | } 42 | 43 | let mut flat_probs = Vec::new(); 44 | for item in probs.iter() { 45 | for value in item.iter() { 46 | flat_probs.push(*value); 47 | } 48 | } 49 | 50 | let mut max_diff: ValueType = -1.0; 51 | for (value1, value2) in flat_probs.iter().zip(xgb_results.iter()) { 52 | println!("{} {}", value1, value2); 53 | let diff = (value1 - value2).abs(); 54 | if diff > max_diff { 55 | max_diff = diff; 56 | } 57 | } 58 | 59 | println!( 60 | "Compared to results from xgboost, max error is: {:.10}", 61 | max_diff 62 | ); 63 | assert!(max_diff < 0.01); 64 | } 65 | -------------------------------------------------------------------------------- /examples/test-xgb-rank-pairwise.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::{PredVec, ValueType}; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Call this command to convert xgboost model: 11 | // python examples/convert_xgboost.py xgb-data/xgb_rank_pairwise/xgb.model "rank:pairwise" xgb-data/xgb_rank_pairwise/gbdt.model 12 | // load model 13 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_rank_pairwise/gbdt.model", "rank:pairwise") 14 | .expect("failed to load model"); 15 | 16 | // load test data 17 | let test_file = "xgb-data/xgb_rank_pairwise/mq2008.test"; 18 | let mut input_format = input::InputFormat::txt_format(); 19 | input_format.set_feature_size(47); 20 | input_format.set_delimeter(' '); 21 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 22 | 23 | // inference 24 | println!("start prediction"); 25 | let predicted: PredVec = gbdt.predict(&test_data); 26 | assert_eq!(predicted.len(), test_data.len()); 27 | 28 | // compare to xgboost prediction results 29 | let predict_result = "xgb-data/xgb_rank_pairwise/pred.csv"; 30 | 31 | let mut xgb_results = Vec::new(); 32 | let file = File::open(predict_result).expect("failed to load pred.csv"); 33 | let reader = BufReader::new(file); 34 | for line in reader.lines() { 35 | let text = line.expect("failed to read data from pred.csv"); 36 | let value: ValueType = text.parse().expect("failed to parse data from pred.csv"); 37 | xgb_results.push(value); 38 | } 39 | 40 | let mut max_diff: ValueType = -1.0; 41 | for (value1, value2) in predicted.iter().zip(xgb_results.iter()) { 42 | println!("{} {}", value1, value2); 43 | let diff = (value1 - value2).abs(); 44 | if diff > max_diff { 45 | max_diff = diff; 46 | } 47 | } 48 | 49 | println!( 50 | "Compared to results from xgboost, max error is: {:.10}", 51 | max_diff 52 | ); 53 | assert!(max_diff < 0.01); 54 | } 55 | -------------------------------------------------------------------------------- /examples/test-xgb-reg-linear.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::{PredVec, ValueType}; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Use xg.py in xgb-data/xgb_reg_linear to generate a model and get prediction results from xgboost. 11 | // Call this command to convert xgboost model: 12 | // python examples/convert_xgboost.py xgb-data/xgb_reg_linear/xgb.model "reg:linear" xgb-data/xgb_reg_linear/gbdt.model 13 | // load model 14 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_reg_linear/gbdt.model", "reg:linear") 15 | .expect("failed to load model"); 16 | 17 | // load test data 18 | let test_file = "xgb-data/xgb_reg_linear/machine.txt.test"; 19 | let mut input_format = input::InputFormat::txt_format(); 20 | input_format.set_feature_size(36); 21 | input_format.set_delimeter(' '); 22 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 23 | 24 | // inference 25 | println!("start prediction"); 26 | let predicted: PredVec = gbdt.predict(&test_data); 27 | assert_eq!(predicted.len(), test_data.len()); 28 | 29 | // compare to xgboost prediction results 30 | let predict_result = "xgb-data/xgb_reg_linear/pred.csv"; 31 | 32 | let mut xgb_results = Vec::new(); 33 | let file = File::open(predict_result).expect("failed to load pred.csv"); 34 | let reader = BufReader::new(file); 35 | for line in reader.lines() { 36 | let text = line.expect("failed to read data from pred.csv"); 37 | let value: ValueType = text.parse().expect("failed to parse data from pred.csv"); 38 | xgb_results.push(value); 39 | } 40 | 41 | let mut max_diff: ValueType = -1.0; 42 | for (value1, value2) in predicted.iter().zip(xgb_results.iter()) { 43 | println!("{} {}", value1, value2); 44 | let diff = (value1 - value2).abs(); 45 | if diff > max_diff { 46 | max_diff = diff; 47 | } 48 | } 49 | 50 | println!( 51 | "Compared to results from xgboost, max error is: {:.10}", 52 | max_diff 53 | ); 54 | assert!(max_diff < 0.01); 55 | } 56 | -------------------------------------------------------------------------------- /examples/test-xgb-reg-logistic.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt; 2 | 3 | use gbdt::decision_tree::{PredVec, ValueType}; 4 | use gbdt::gradient_boost::GBDT; 5 | use gbdt::input; 6 | use std::fs::File; 7 | use std::io::{BufRead, BufReader}; 8 | 9 | fn main() { 10 | // Use xg.py in xgb-data/xgb_reg_logistic to generate a model and get prediction results from xgboost. 11 | // Call this command to convert xgboost model: 12 | // python examples/convert_xgboost.py xgb-data/xgb_reg_logistic/xgb.model "reg:logistic" xgb-data/xgb_reg_logistic/gbdt.model 13 | // load model 14 | let gbdt = GBDT::from_xgboost_dump("xgb-data/xgb_reg_logistic/gbdt.model", "reg:logistic") 15 | .expect("failed to load model"); 16 | 17 | // load test data 18 | let test_file = "xgb-data/xgb_reg_logistic/agaricus.txt.test"; 19 | let mut input_format = input::InputFormat::txt_format(); 20 | input_format.set_feature_size(126); 21 | input_format.set_delimeter(' '); 22 | let test_data = input::load(test_file, input_format).expect("failed to load test data"); 23 | 24 | // inference 25 | println!("start prediction"); 26 | let predicted: PredVec = gbdt.predict(&test_data); 27 | assert_eq!(predicted.len(), test_data.len()); 28 | 29 | // compare to xgboost prediction results 30 | let predict_result = "xgb-data/xgb_reg_logistic/pred.csv"; 31 | 32 | let mut xgb_results = Vec::new(); 33 | let file = File::open(predict_result).expect("failed to load pred.csv"); 34 | let reader = BufReader::new(file); 35 | for line in reader.lines() { 36 | let text = line.expect("failed to read data from pred.csv"); 37 | let value: ValueType = text.parse().expect("failed to parse data from pred.csv"); 38 | xgb_results.push(value); 39 | } 40 | 41 | let mut max_diff: ValueType = -1.0; 42 | for (value1, value2) in predicted.iter().zip(xgb_results.iter()) { 43 | println!("{} {}", value1, value2); 44 | let diff = (value1 - value2).abs(); 45 | if diff > max_diff { 46 | max_diff = diff; 47 | } 48 | } 49 | 50 | println!( 51 | "Compared to results from xgboost, max error is: {:.10}", 52 | max_diff 53 | ); 54 | assert!(max_diff < 0.01); 55 | } 56 | -------------------------------------------------------------------------------- /gbdt.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/gbdt.pdf -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/app/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "app" 3 | version = "1.0.0" 4 | authors = ["Baidu"] 5 | build = "build.rs" 6 | 7 | [dependencies] 8 | sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk.git" } 9 | sgx_urts = { git = "https://github.com/apache/teaclave-sgx-sdk.git" } 10 | dirs = "1.0.2" 11 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/app/build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017-2018 Baidu, Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions 5 | // are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in 11 | // the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Baidu, Inc., nor the names of its 14 | // contributors may be used to endorse or promote products derived 15 | // from this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | use std::env; 30 | 31 | fn main() { 32 | let sdk_dir = env::var("SGX_SDK").unwrap_or_else(|_| "/opt/intel/sgxsdk".to_string()); 33 | let is_sim = env::var("SGX_MODE").unwrap_or_else(|_| "HW".to_string()); 34 | 35 | println!("cargo:rustc-link-search=native=../lib"); 36 | println!("cargo:rustc-link-lib=static=Enclave_u"); 37 | 38 | println!("cargo:rustc-link-search=native={}/lib64", sdk_dir); 39 | match is_sim.as_ref() { 40 | "SW" => println!("cargo:rustc-link-lib=dylib=sgx_urts_sim"), 41 | "HW" => println!("cargo:rustc-link-lib=dylib=sgx_urts"), 42 | _ => println!("cargo:rustc-link-lib=dylib=sgx_urts"), // Treat undefined as HW 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/bin/dataset: -------------------------------------------------------------------------------- 1 | ../../../dataset -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/bin/readme.txt: -------------------------------------------------------------------------------- 1 | lib -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/assert.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: assert.h,v 1.12 2006/01/31 10:53:51 hshoexer Exp $ */ 2 | /* $NetBSD: assert.h,v 1.6 1994/10/26 00:55:44 cgd Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * (c) UNIX System Laboratories, Inc. 8 | * All or some portions of this file are derived from material licensed 9 | * to the University of California by American Telephone and Telegraph 10 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with 11 | * the permission of UNIX System Laboratories, Inc. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 3. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | * 37 | * @(#)assert.h 8.2 (Berkeley) 1/21/94 38 | */ 39 | 40 | /* 41 | * Unlike other ANSI header files, may usefully be included 42 | * multiple times, with and without NDEBUG defined. 43 | */ 44 | 45 | #include 46 | 47 | #undef assert 48 | 49 | #ifdef NDEBUG 50 | # define assert(e) ((void)0) 51 | #else 52 | # define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, __func__, #e)) 53 | #endif 54 | 55 | #ifndef _ASSERT_H_DECLS 56 | #define _ASSERT_H_DECLS 57 | __BEGIN_DECLS 58 | 59 | void _TLIBC_CDECL_ __assert(const char *, int, const char *, const char *); 60 | 61 | __END_DECLS 62 | #endif /* Not _ASSERT_H_DECLS */ 63 | 64 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/complex.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: complex.h,v 1.3 2010/07/24 22:17:03 guenther Exp $ */ 2 | /* 3 | * Copyright (c) 2008 Martynas Venckus 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _COMPLEX_H_ 19 | #define _COMPLEX_H_ 20 | 21 | #include 22 | 23 | /* 24 | * C99 25 | */ 26 | #ifdef __GNUC__ 27 | #if __STDC_VERSION__ < 199901 28 | #define _Complex __complex__ 29 | #endif 30 | #define _Complex_I 1.0fi 31 | #elif defined(lint) 32 | #define _Complex_I 1.0fi 33 | #endif 34 | 35 | #define complex _Complex 36 | 37 | /* XXX switch to _Imaginary_I */ 38 | #undef I 39 | #define I _Complex_I 40 | 41 | __BEGIN_DECLS 42 | /* 43 | * Double versions of C99 functions 44 | */ 45 | double complex cacos(double complex); 46 | double complex casin(double complex); 47 | double complex catan(double complex); 48 | double complex ccos(double complex); 49 | double complex csin(double complex); 50 | double complex ctan(double complex); 51 | double complex cacosh(double complex); 52 | double complex casinh(double complex); 53 | double complex catanh(double complex); 54 | double complex ccosh(double complex); 55 | double complex csinh(double complex); 56 | double complex ctanh(double complex); 57 | double complex cexp(double complex); 58 | double complex clog(double complex); 59 | double cabs(double complex); 60 | double complex cpow(double complex, double complex); 61 | double complex csqrt(double complex); 62 | double carg(double complex); 63 | double cimag(double complex); 64 | double complex conj(double complex); 65 | double complex cproj(double complex); 66 | double creal(double complex); 67 | /* 68 | * C99 reserved 69 | */ 70 | double complex clog10(double complex); 71 | 72 | /* 73 | * Float versions of C99 functions 74 | */ 75 | float complex cacosf(float complex); 76 | float complex casinf(float complex); 77 | float complex catanf(float complex); 78 | float complex ccosf(float complex); 79 | float complex csinf(float complex); 80 | float complex ctanf(float complex); 81 | float complex cacoshf(float complex); 82 | float complex casinhf(float complex); 83 | float complex catanhf(float complex); 84 | float complex ccoshf(float complex); 85 | float complex csinhf(float complex); 86 | float complex ctanhf(float complex); 87 | float complex cexpf(float complex); 88 | float complex clogf(float complex); 89 | float cabsf(float complex); 90 | float complex cpowf(float complex, float complex); 91 | float complex csqrtf(float complex); 92 | float cargf(float complex); 93 | float cimagf(float complex); 94 | float complex conjf(float complex); 95 | float complex cprojf(float complex); 96 | float crealf(float complex); 97 | /* 98 | * C99 reserved 99 | */ 100 | float complex clog10f(float complex); 101 | 102 | /* 103 | * Long double versions of C99 functions 104 | */ 105 | long double complex cacosl(long double complex); 106 | long double complex casinl(long double complex); 107 | long double complex catanl(long double complex); 108 | long double complex ccosl(long double complex); 109 | long double complex csinl(long double complex); 110 | long double complex ctanl(long double complex); 111 | long double complex cacoshl(long double complex); 112 | long double complex casinhl(long double complex); 113 | long double complex catanhl(long double complex); 114 | long double complex ccoshl(long double complex); 115 | long double complex csinhl(long double complex); 116 | long double complex ctanhl(long double complex); 117 | long double complex cexpl(long double complex); 118 | long double complex clogl(long double complex); 119 | long double cabsl(long double complex); 120 | long double complex cpowl(long double complex, long double complex); 121 | long double complex csqrtl(long double complex); 122 | long double cargl(long double complex); 123 | long double cimagl(long double complex); 124 | long double complex conjl(long double complex); 125 | long double complex cprojl(long double complex); 126 | long double creall(long double complex); 127 | /* 128 | * C99 reserved 129 | */ 130 | long double complex clog10l(long double complex); 131 | 132 | __END_DECLS 133 | 134 | #endif /* !_COMPLEX_H_ */ 135 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/ctype.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ctype.h,v 1.22 2010/10/01 20:10:24 guenther Exp $ */ 2 | /* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1989 The Regents of the University of California. 6 | * All rights reserved. 7 | * (c) UNIX System Laboratories, Inc. 8 | * All or some portions of this file are derived from material licensed 9 | * to the University of California by American Telephone and Telegraph 10 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with 11 | * the permission of UNIX System Laboratories, Inc. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 3. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | * 37 | * @(#)ctype.h 5.3 (Berkeley) 4/3/91 38 | */ 39 | 40 | #ifndef _CTYPE_H_ 41 | #define _CTYPE_H_ 42 | 43 | #include 44 | 45 | __BEGIN_DECLS 46 | 47 | int _TLIBC_CDECL_ isalnum(int); 48 | int _TLIBC_CDECL_ isalpha(int); 49 | int _TLIBC_CDECL_ iscntrl(int); 50 | int _TLIBC_CDECL_ isdigit(int); 51 | int _TLIBC_CDECL_ isgraph(int); 52 | int _TLIBC_CDECL_ islower(int); 53 | int _TLIBC_CDECL_ isprint(int); 54 | int _TLIBC_CDECL_ ispunct(int); 55 | int _TLIBC_CDECL_ isspace(int); 56 | int _TLIBC_CDECL_ isupper(int); 57 | int _TLIBC_CDECL_ isxdigit(int); 58 | int _TLIBC_CDECL_ tolower(int); 59 | int _TLIBC_CDECL_ toupper(int); 60 | int _TLIBC_CDECL_ isblank(int); 61 | 62 | __END_DECLS 63 | 64 | #endif /* _CTYPE_H_ */ 65 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/dirent.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1996-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | #ifndef _DIRENT_H 19 | #define _DIRENT_H 20 | 21 | struct dirent 22 | { 23 | #ifndef __USE_FILE_OFFSET64 24 | __ino_t d_ino; 25 | __off_t d_off; 26 | #else 27 | __ino64_t d_ino; 28 | __off64_t d_off; 29 | #endif 30 | unsigned short int d_reclen; 31 | unsigned char d_type; 32 | char d_name[256]; /* We must not include limits.h! */ 33 | }; 34 | 35 | //#ifdef __USE_LARGEFILE64 36 | struct dirent64 37 | { 38 | __ino64_t d_ino; 39 | __off64_t d_off; 40 | unsigned short int d_reclen; 41 | unsigned char d_type; 42 | char d_name[256]; /* We must not include limits.h! */ 43 | }; 44 | //#endif 45 | 46 | #define d_fileno d_ino /* Backwards compatibility. */ 47 | 48 | #undef _DIRENT_HAVE_D_NAMLEN 49 | #define _DIRENT_HAVE_D_RECLEN 50 | #define _DIRENT_HAVE_D_OFF 51 | #define _DIRENT_HAVE_D_TYPE 52 | 53 | #if defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T 54 | /* Inform libc code that these two types are effectively identical. */ 55 | # define _DIRENT_MATCHES_DIRENT64 1 56 | #else 57 | # define _DIRENT_MATCHES_DIRENT64 0 58 | #endif 59 | #endif 60 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/endian.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: endian.h,v 1.18 2006/03/27 07:09:24 otto Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef _ENDIAN_H_ 28 | #define _ENDIAN_H_ 29 | 30 | #include 31 | 32 | #endif /* _ENDIAN_H_ */ 33 | 34 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/float.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: float.h,v 1.3 2008/07/21 20:50:54 martynas Exp $ */ 2 | /* $NetBSD: float.h,v 1.8 1995/06/20 20:45:37 jtc Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1989 Regents of the University of California. 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * @(#)float.h 7.1 (Berkeley) 5/8/90 33 | */ 34 | 35 | #ifndef _FLOAT_H_ 36 | #define _FLOAT_H_ 37 | 38 | #include 39 | 40 | #define FLT_RADIX 2 /* b */ 41 | 42 | // The rounding direction can be specified by fesetround() in 43 | #define FLT_ROUNDS 1 /* addition rounding: near */ 44 | #define DECIMAL_DIG 21 /* max precision in decimal digits */ 45 | 46 | // NOTE: FLT_EVAL_METHOD is -1 under FREEBSD x86. 47 | #ifdef __i386__ 48 | #define FLT_EVAL_METHOD 2 /* long double */ 49 | #else 50 | #define FLT_EVAL_METHOD 0 /* no promotions */ 51 | #endif 52 | 53 | #define DBL_MANT_DIG 53 54 | #define DBL_EPSILON 2.2204460492503131E-16 55 | #define DBL_DIG 15 56 | #define DBL_MIN_EXP (-1021) 57 | #define DBL_MIN 2.2250738585072014E-308 58 | #define DBL_MIN_10_EXP (-307) 59 | #define DBL_MAX_EXP 1024 60 | #define DBL_MAX_10_EXP 308 61 | 62 | #define FLT_MANT_DIG 24 /* p */ 63 | #define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ 64 | #define FLT_MIN_EXP (-125) /* emin */ 65 | #define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ 66 | #define FLT_MAX_EXP 128 /* emax */ 67 | #define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ 68 | 69 | #define DBL_MAX 1.7976931348623157E+308 70 | #define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ 71 | #define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ 72 | #define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ 73 | 74 | #define LDBL_MANT_DIG 64 75 | #define LDBL_EPSILON 1.08420217248550443401e-19L 76 | #define LDBL_DIG 18 77 | #define LDBL_MIN_EXP (-16381) 78 | #define LDBL_MIN 3.36210314311209350626e-4932L 79 | #define LDBL_MIN_10_EXP (-4931) 80 | #define LDBL_MAX_EXP 16384 81 | #define LDBL_MAX 1.18973149535723176502e+4932L 82 | #define LDBL_MAX_10_EXP 4932 83 | 84 | #endif /* _FLOAT_H_ */ 85 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/iso646.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: iso646.h,v 1.3 2001/10/11 00:05:21 espie Exp $ */ 2 | /* $NetBSD: iso646.h,v 1.1 1995/02/17 09:08:10 jtc Exp $ */ 3 | 4 | /* 5 | * Written by J.T. Conklin 02/16/95. 6 | * Public domain. 7 | */ 8 | 9 | #ifndef _ISO646_H_ 10 | #define _ISO646_H_ 11 | 12 | #ifndef __cplusplus 13 | #define and && 14 | #define and_eq &= 15 | #define bitand & 16 | #define bitor | 17 | #define compl ~ 18 | #define not ! 19 | #define not_eq != 20 | #define or || 21 | #define or_eq |= 22 | #define xor ^ 23 | #define xor_eq ^= 24 | #endif 25 | 26 | #endif /* !_ISO646_H_ */ 27 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/limits.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: limits.h,v 1.15 2008/02/10 09:59:54 kettenis Exp $ */ 2 | /* $NetBSD: limits.h,v 1.7 1994/10/26 00:56:00 cgd Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1988 The Regents of the University of California. 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * @(#)limits.h 5.9 (Berkeley) 4/3/91 33 | */ 34 | 35 | 36 | #ifndef _LIMITS_H_ 37 | #define _LIMITS_H_ 38 | 39 | #include 40 | 41 | #endif /* !_LIMITS_H_ */ 42 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/mbusafecrt.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | // 5 | 6 | /*** 7 | * mbusafecrt.h - public declarations for SafeCRT lib 8 | * 9 | 10 | * 11 | * Purpose: 12 | * This file contains the public declarations SafeCRT 13 | * functions ported to MacOS. These are the safe versions of 14 | * functions standard functions banned by SWI 15 | * 16 | 17 | ****/ 18 | 19 | /* shields! */ 20 | 21 | #ifndef MBUSAFECRT_H 22 | #define MBUSAFECRT_H 23 | #include 24 | #include 25 | #include 26 | typedef wchar_t WCHAR; 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | extern errno_t strcat_s( char* ioDest, size_t inDestBufferSize, const char* inSrc ); 33 | extern errno_t wcscat_s( WCHAR* ioDest, size_t inDestBufferSize, const WCHAR* inSrc ); 34 | 35 | extern errno_t strncat_s( char* ioDest, size_t inDestBufferSize, const char* inSrc, size_t inCount ); 36 | extern errno_t wcsncat_s( WCHAR* ioDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount ); 37 | 38 | extern errno_t strcpy_s( char* outDest, size_t inDestBufferSize, const char* inSrc ); 39 | extern errno_t wcscpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc ); 40 | 41 | extern errno_t strncpy_s( char* outDest, size_t inDestBufferSize, const char* inSrc, size_t inCount ); 42 | extern errno_t wcsncpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount ); 43 | 44 | extern char* strtok_s( char* inString, const char* inControl, char** ioContext ); 45 | extern WCHAR* wcstok_s( WCHAR* inString, const WCHAR* inControl, WCHAR** ioContext ); 46 | 47 | extern size_t wcsnlen( const WCHAR* inString, size_t inMaxSize ); 48 | 49 | extern errno_t _itoa_s( int inValue, char* outBuffer, size_t inDestBufferSize, int inRadix ); 50 | extern errno_t _itow_s( int inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix ); 51 | 52 | extern errno_t _ltoa_s( long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix ); 53 | extern errno_t _ltow_s( long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix ); 54 | 55 | extern errno_t _ultoa_s( unsigned long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix ); 56 | extern errno_t _ultow_s( unsigned long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix ); 57 | 58 | extern errno_t _i64toa_s( long long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix ); 59 | extern errno_t _i64tow_s( long long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix ); 60 | 61 | extern errno_t _ui64toa_s( unsigned long long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix ); 62 | extern errno_t _ui64tow_s( unsigned long long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix ); 63 | 64 | extern int sprintf_s( char *string, size_t sizeInBytes, const char *format, ... ); 65 | extern int swprintf_s( WCHAR *string, size_t sizeInWords, const WCHAR *format, ... ); 66 | 67 | extern int _snprintf_s( char *string, size_t sizeInBytes, size_t count, const char *format, ... ); 68 | extern int _snwprintf_s( WCHAR *string, size_t sizeInWords, size_t count, const WCHAR *format, ... ); 69 | 70 | extern int _vsprintf_s( char* string, size_t sizeInBytes, const char* format, va_list arglist ); 71 | extern int _vsnprintf_s( char* string, size_t sizeInBytes, size_t count, const char* format, va_list arglist ); 72 | 73 | extern int _vswprintf_s( WCHAR* string, size_t sizeInWords, const WCHAR* format, va_list arglist ); 74 | extern int _vsnwprintf_s( WCHAR* string, size_t sizeInWords, size_t count, const WCHAR* format, va_list arglist ); 75 | 76 | extern errno_t memcpy_s( void * dst, size_t sizeInBytes, const void * src, size_t count ); 77 | extern errno_t memmove_s( void * dst, size_t sizeInBytes, const void * src, size_t count ); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* MBUSAFECRT_H */ 84 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/netdb.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1996-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | /* All data returned by the network data base library are supplied in 19 | host order and returned in network order (suitable for use in 20 | system calls). */ 21 | 22 | #ifndef _NETDB_H 23 | #define _NETDB_H 24 | 25 | struct addrinfo 26 | { 27 | int ai_flags; /* Input flags. */ 28 | int ai_family; /* Protocol family for socket. */ 29 | int ai_socktype; /* Socket type. */ 30 | int ai_protocol; /* Protocol for socket. */ 31 | socklen_t ai_addrlen; /* Length of socket address. */ 32 | struct sockaddr *ai_addr; /* Socket address for socket. */ 33 | char *ai_canonname; /* Canonical name for service location. */ 34 | struct addrinfo *ai_next; /* Pointer to next in list. */ 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/poll.h: -------------------------------------------------------------------------------- 1 | #ifndef _POLL_H_ 2 | #define _POLL_H_ 3 | 4 | /* Type used for the number of file descriptors. */ 5 | typedef unsigned long int nfds_t; 6 | 7 | /* Data structure describing a polling request. */ 8 | struct pollfd 9 | { 10 | int fd; /* File descriptor to poll. */ 11 | short int events; /* Types of events poller cares about. */ 12 | short int revents; /* Types of events that actually occurred. */ 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/pwd.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1991-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | /* 19 | * POSIX Standard: 9.2.2 User Database Access 20 | */ 21 | 22 | #ifndef _PWD_H 23 | #define _PWD_H 24 | 25 | struct passwd 26 | { 27 | char *pw_name; /* Username. */ 28 | char *pw_passwd; /* Password. */ 29 | __uid_t pw_uid; /* User ID. */ 30 | __gid_t pw_gid; /* Group ID. */ 31 | char *pw_gecos; /* Real name. */ 32 | char *pw_dir; /* Home directory. */ 33 | char *pw_shell; /* Shell program. */ 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sched.h: -------------------------------------------------------------------------------- 1 | /* Definition of the cpu_set_t structure used by the POSIX 1003.1b-1993 2 | scheduling interface. 3 | Copyright (C) 1996-2018 Free Software Foundation, Inc. 4 | This file is part of the GNU C Library. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | #ifndef _SCHED_H 21 | #define _SCHED_H 22 | #include 23 | 24 | /* Size definition for CPU sets. */ 25 | #define __CPU_SETSIZE 1024 26 | #define __NCPUBITS (8 * sizeof (__cpu_mask)) 27 | 28 | /* Basic access functions. */ 29 | #define __CPUELT(cpu) ((cpu) / __NCPUBITS) 30 | #define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS)) 31 | 32 | /* Data structure to describe CPU mask. */ 33 | typedef struct 34 | { 35 | __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS]; 36 | } cpu_set_t; 37 | 38 | typedef __pid_t pid_t; 39 | 40 | #endif -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/setjmp.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: setjmp.h,v 1.26 2011/11/05 09:27:06 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * (c) UNIX System Laboratories, Inc. 7 | * All or some portions of this file are derived from material licensed 8 | * to the University of California by American Telephone and Telegraph 9 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 | * the permission of UNIX System Laboratories, Inc. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. Neither the name of the University nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | * SUCH DAMAGE. 35 | * 36 | * @(#)setjmp.h 8.2 (Berkeley) 1/21/94 37 | */ 38 | 39 | #ifndef _SETJMP_H_ 40 | #define _SETJMP_H_ 41 | 42 | #ifndef _JB_ATTRIBUTES 43 | #define _JB_ATTRIBUTES /**/ 44 | #else 45 | #endif 46 | #ifndef _BSD_JBSLOT_T_ 47 | #define _BSD_JBSLOT_T_ long 48 | #endif 49 | 50 | #define _JBLEN 8 51 | 52 | typedef _BSD_JBSLOT_T_ jmp_buf[_JBLEN] _JB_ATTRIBUTES; 53 | 54 | #include 55 | #define __returns_twice __attribute__((__returns_twice__)) 56 | #define __dead 57 | 58 | 59 | __BEGIN_DECLS 60 | int setjmp(jmp_buf) __returns_twice; 61 | void longjmp(jmp_buf, int) __dead; 62 | __END_DECLS 63 | 64 | #endif /* !_SETJMP_H_ */ 65 | 66 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/signal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1991-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | #ifndef _SIGNAL_H 19 | #define _SIGNAL_H 20 | 21 | #define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) 22 | typedef struct 23 | { 24 | unsigned long int __val[_SIGSET_NWORDS]; 25 | } __sigset_t; 26 | 27 | typedef __sigset_t sigset_t; 28 | 29 | struct sigaction 30 | { 31 | /* Signal handler. */ 32 | #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED 33 | union 34 | { 35 | /* Used if SA_SIGINFO is not set. */ 36 | void (*sa_handler) (int); 37 | /* Used if SA_SIGINFO is set. */ 38 | void (*sa_sigaction) (int, siginfo_t *, void *); 39 | } 40 | __sigaction_handler; 41 | #define sa_handler __sigaction_handler.sa_handler 42 | #define sa_sigaction __sigaction_handler.sa_sigaction 43 | #else 44 | void (*sa_handler) (int); 45 | #endif 46 | 47 | /* Additional set of signals to be blocked. */ 48 | __sigset_t sa_mask; 49 | 50 | /* Special flags. */ 51 | int sa_flags; 52 | 53 | /* Restore handler. */ 54 | void (*sa_restorer) (void); 55 | }; 56 | 57 | #define __SI_MAX_SIZE 128 58 | #define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4) 59 | 60 | typedef struct 61 | { 62 | int si_signo; /* Signal number. */ 63 | 64 | int si_errno; /* If non-zero, an errno value associated with 65 | this signal, as defined in . */ 66 | int si_code; /* Signal code. */ 67 | 68 | int __pad0; 69 | int _pad[__SI_PAD_SIZE]; 70 | } siginfo_t; 71 | 72 | #endif -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/stdarg.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: stdarg.h,v 1.14 2010/12/30 05:01:36 tedu Exp $ */ 2 | /* $NetBSD: stdarg.h,v 1.12 1995/12/25 23:15:31 mycroft Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1991, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 33 | */ 34 | 35 | #ifndef _STDARG_H_ 36 | #define _STDARG_H_ 37 | 38 | #include 39 | #include 40 | 41 | typedef __va_list va_list; 42 | 43 | #define va_start(ap, last) __builtin_va_start((ap), last) 44 | #define va_end __builtin_va_end 45 | #define va_arg __builtin_va_arg 46 | #define va_copy(dst, src) __builtin_va_copy((dst),(src)) 47 | 48 | #endif /* !_STDARG_H_ */ 49 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/stdbool.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: stdbool.h,v 1.5 2010/07/24 22:17:03 guenther Exp $ */ 2 | 3 | /* 4 | * Written by Marc Espie, September 25, 1999 5 | * Public domain. 6 | */ 7 | 8 | #ifndef _STDBOOL_H_ 9 | #define _STDBOOL_H_ 10 | 11 | #ifndef __cplusplus 12 | 13 | #ifndef __GNUC__ 14 | /* Support for _C99: type _Bool is already built-in. */ 15 | /* `_Bool' type must promote to `int' or `unsigned int'. */ 16 | typedef enum { 17 | false = 0, 18 | true = 1 19 | } _Bool; 20 | 21 | /* And those constants must also be available as macros. */ 22 | # define false false 23 | # define true true 24 | #else /* __GNUC__ */ 25 | # define false 0 26 | # define true 1 27 | #endif 28 | 29 | /* User visible type `bool' is provided as a macro which may be redefined */ 30 | #define bool _Bool 31 | 32 | #else /* __cplusplus */ 33 | 34 | # define _Bool bool 35 | # define bool bool 36 | # define false false 37 | # define true true 38 | 39 | #endif 40 | 41 | /* Inform that everything is fine */ 42 | #define __bool_true_false_are_defined 1 43 | 44 | #endif /* _STDBOOL_H_ */ 45 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/stddef.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: stddef.h,v 1.10 2009/09/22 21:40:02 jsg Exp $ */ 2 | /* $NetBSD: stddef.h,v 1.4 1994/10/26 00:56:26 cgd Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1990 The Regents of the University of California. 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * @(#)stddef.h 5.5 (Berkeley) 4/3/91 33 | */ 34 | 35 | #ifndef _STDDEF_H_ 36 | #define _STDDEF_H_ 37 | 38 | #include 39 | #include 40 | 41 | #ifndef _PTRDIFF_T_DEFINED_ 42 | #define _PTRDIFF_T_DEFINED_ 43 | typedef __ptrdiff_t ptrdiff_t; 44 | #endif 45 | 46 | #ifndef _SIZE_T_DEFINED_ 47 | #define _SIZE_T_DEFINED_ 48 | typedef __size_t size_t; 49 | #endif 50 | 51 | #if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) 52 | #define _WCHAR_T_DEFINED_ 53 | #ifndef __WCHAR_TYPE__ 54 | #define __WCHAR_TYPE__ int 55 | #endif 56 | typedef __WCHAR_TYPE__ wchar_t; 57 | #endif 58 | 59 | #ifndef NULL 60 | #ifdef __cplusplus 61 | #define NULL 0 62 | #else 63 | #define NULL ((void *)0) 64 | #endif 65 | #endif 66 | 67 | #define offsetof(type, member) ((size_t)(&((type *)0)->member)) 68 | 69 | #endif /* _STDDEF_H_ */ 70 | 71 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/stdint.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: stdint.h,v 1.4 2006/12/10 22:17:55 deraadt Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1997, 2005 Todd C. Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifndef _STDINT_H_ 20 | #define _STDINT_H_ 21 | 22 | #include 23 | 24 | #endif /* _STDINT_H_ */ 25 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/stdio.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: stdio.h,v 1.38 2009/11/09 00:18:27 kurt Exp $ */ 2 | /* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1990 The Regents of the University of California. 6 | * All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Chris Torek. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)stdio.h 5.17 (Berkeley) 6/3/91 36 | */ 37 | 38 | #ifndef _STDIO_H_ 39 | #define _STDIO_H_ 40 | 41 | #include 42 | #include 43 | 44 | #include 45 | 46 | #ifndef _SIZE_T_DEFINED_ 47 | typedef __size_t size_t; 48 | #define _SIZE_T_DEFINED_ 49 | #endif 50 | 51 | #ifndef NULL 52 | # ifdef __cplusplus 53 | # define NULL 0 54 | # else 55 | # define NULL ((void *)0) 56 | # endif 57 | #endif 58 | 59 | # define BUFSIZ 8192 60 | 61 | #define EOF (-1) 62 | 63 | __BEGIN_DECLS 64 | 65 | int _TLIBC_CDECL_ snprintf(char *, size_t, const char *, ...) _GCC_PRINTF_FORMAT_(3, 4); 66 | int _TLIBC_CDECL_ vsnprintf(char *, size_t, const char *, __va_list) _GCC_PRINTF_FORMAT_(3, 0); 67 | 68 | /* 69 | * Deprecated definitions. 70 | */ 71 | #if 0 /* No FILE */ 72 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fprintf, FILE *, const char *, ...); 73 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, putc, int, FILE *); 74 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fputc, int, FILE *); 75 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fputs, const char *, FILE *); 76 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fscanf, FILE *, const char *, ...); 77 | _TLIBC_DEPRECATED_FUNCTION_(size_t _TLIBC_CDECL_, fwrite, const void *, size_t, size_t, FILE *); 78 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, printf, const char *, ...); 79 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, putchar, int); 80 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, puts, const char *); 81 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, scanf, const char *, ...); 82 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, sprintf, char *, const char *, ...); 83 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, sscanf, const char *, const char *, ...); 84 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vfprintf, FILE *, const char *, __va_list); 85 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vfscanf, FILE *, const char *, __va_list); 86 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vprintf, const char *, __va_list); 87 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vscanf, const char *, __va_list); 88 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vsprintf, char *, const char *, __va_list); 89 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vsscanf, const char *, const char *, __va_list); 90 | #endif 91 | 92 | __END_DECLS 93 | 94 | 95 | #endif /* !_STDIO_H_ */ 96 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/endian.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: endian.h,v 1.18 2006/03/27 07:09:24 otto Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* 28 | * Generic definitions for little- and big-endian systems. Other endianesses 29 | * has to be dealt with in the specific machine/endian.h file for that port. 30 | * 31 | * This file is meant to be included from a little- or big-endian port's 32 | * machine/endian.h after setting _BYTE_ORDER to either 1234 for little endian 33 | * or 4321 for big.. 34 | */ 35 | 36 | #ifndef _SYS_ENDIAN_H_ 37 | #define _SYS_ENDIAN_H_ 38 | 39 | #define _LITTLE_ENDIAN 1234 40 | #define _BIG_ENDIAN 4321 41 | #define _PDP_ENDIAN 3412 42 | #define _BYTE_ORDER _LITTLE_ENDIAN 43 | 44 | #define LITTLE_ENDIAN _LITTLE_ENDIAN 45 | #define BIG_ENDIAN _BIG_ENDIAN 46 | #define PDP_ENDIAN _PDP_ENDIAN 47 | #define BYTE_ORDER _BYTE_ORDER 48 | 49 | #define __BYTE_ORDER _BYTE_ORDER 50 | #define __BIG_ENDIAN _BIG_ENDIAN 51 | #define __LITTLE_ENDIAN _LITTLE_ENDIAN 52 | 53 | #endif /* _SYS_ENDIAN_H_ */ 54 | 55 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/epoll.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | #ifndef _SYS_EPOLL_H 19 | #define _SYS_EPOLL_H 20 | 21 | #define __EPOLL_PACKED __attribute__ ((__packed__)) 22 | 23 | typedef union epoll_data 24 | { 25 | void *ptr; 26 | int fd; 27 | uint32_t u32; 28 | uint64_t u64; 29 | } epoll_data_t; 30 | 31 | struct epoll_event 32 | { 33 | uint32_t events; /* Epoll events */ 34 | epoll_data_t data; /* User data variable */ 35 | } __EPOLL_PACKED; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/limits.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: limits.h,v 1.8 2009/11/27 19:54:35 guenther Exp $ */ 2 | /* 3 | * Copyright (c) 2002 Marc Espie. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS 15 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD 18 | * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef _SYS_LIMITS_H_ 27 | #define _SYS_LIMITS_H_ 28 | 29 | #include 30 | 31 | /* Common definitions for limits.h. */ 32 | 33 | #define CHAR_BIT 8 /* number of bits in a char */ 34 | 35 | #define SCHAR_MAX 0x7f /* max value for a signed char */ 36 | #define SCHAR_MIN (-0x7f - 1) /* min value for a signed char */ 37 | 38 | #define UCHAR_MAX 0xff /* max value for an unsigned char */ 39 | #ifdef __CHAR_UNSIGNED__ 40 | # define CHAR_MIN 0 /* min value for a char */ 41 | # define CHAR_MAX 0xff /* max value for a char */ 42 | #else 43 | # define CHAR_MAX 0x7f 44 | # define CHAR_MIN (-0x7f-1) 45 | #endif 46 | 47 | #define MB_LEN_MAX 1 /* Allow UTF-8 (RFC 3629) */ 48 | 49 | #define USHRT_MAX 0xffff /* max value for an unsigned short */ 50 | #define SHRT_MAX 0x7fff /* max value for a short */ 51 | #define SHRT_MIN (-0x7fff-1) /* min value for a short */ 52 | 53 | #define UINT_MAX 0xffffffffU /* max value for an unsigned int */ 54 | #define INT_MAX 0x7fffffff /* max value for an int */ 55 | #define INT_MIN (-0x7fffffff-1) /* min value for an int */ 56 | 57 | #ifdef __x86_64__ 58 | # define ULONG_MAX 0xffffffffffffffffUL /* max value for unsigned long */ 59 | # define LONG_MAX 0x7fffffffffffffffL /* max value for a signed long */ 60 | # define LONG_MIN (-0x7fffffffffffffffL-1) /* min value for a signed long */ 61 | #else 62 | # define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */ 63 | # define LONG_MAX 0x7fffffffL /* max value for a long */ 64 | # define LONG_MIN (-0x7fffffffL-1) /* min value for a long */ 65 | #endif 66 | 67 | #define ULLONG_MAX 0xffffffffffffffffULL /* max value for unsigned long long */ 68 | #define LLONG_MAX 0x7fffffffffffffffLL /* max value for a signed long long */ 69 | #define LLONG_MIN (-0x7fffffffffffffffLL-1) /* min value for a signed long long */ 70 | 71 | #ifdef __x86_64__ 72 | # define LONG_BIT 64 73 | #else 74 | # define LONG_BIT 32 75 | #endif 76 | 77 | #endif /* !_SYS_LIMITS_H_ */ 78 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/sockaddr.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1996-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | #ifndef _SYS_SOCKADDR_H_ 19 | #define _SYS_SOCKADDR_H_ 20 | 21 | /* POSIX.1g specifies this type name for the `sa_family' member. */ 22 | typedef unsigned short int sa_family_t; 23 | 24 | /* This macro is used to declare the initial common members 25 | of the data types used for socket addresses, `struct sockaddr', 26 | `struct sockaddr_in', `struct sockaddr_un', etc. */ 27 | 28 | #define __SOCKADDR_COMMON(sa_prefix) \ 29 | sa_family_t sa_prefix##family 30 | 31 | #define __SOCKADDR_COMMON_SIZE (sizeof (unsigned short int)) 32 | 33 | /* Size of struct sockaddr_storage. */ 34 | #define _SS_SIZE 128 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/socket.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1996-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | #ifndef _SYS_SOCKET_H_ 19 | #define _SYS_SOCKET_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | /* Type for length arguments in socket calls. */ 26 | #ifndef __socklen_t_defined 27 | typedef __socklen_t socklen_t; 28 | # define __socklen_t_defined 29 | #endif 30 | 31 | /* Structure describing a generic socket address. */ 32 | struct sockaddr 33 | { 34 | __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */ 35 | char sa_data[14]; /* Address data. */ 36 | }; 37 | 38 | struct msghdr 39 | { 40 | void *msg_name; /* Address to send to/receive from. */ 41 | socklen_t msg_namelen; /* Length of address data. */ 42 | 43 | struct iovec *msg_iov; /* Vector of data to send/receive into. */ 44 | size_t msg_iovlen; /* Number of elements in the vector. */ 45 | 46 | void *msg_control; /* Ancillary data (eg BSD filedesc passing). */ 47 | size_t msg_controllen; /* Ancillary data buffer length. 48 | !! The type should be socklen_t but the 49 | definition of the kernel is incompatible 50 | with this. */ 51 | int msg_flags; /* Flags on received message. */ 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/struct_timespec.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1996-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | #ifndef _SYS_TIMESPEC_H_ 19 | #define _SYS_TIMESPEC_H_ 20 | 21 | #include 22 | 23 | /* POSIX.1b structure for a time value. This is like a `struct timeval' but 24 | has nanoseconds instead of microseconds. */ 25 | struct timespec 26 | { 27 | __time_t tv_sec; /* Seconds. */ 28 | long tv_nsec; /* Nanoseconds. */ 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/types.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: types.h,v 1.31 2008/03/16 19:42:57 otto Exp $ */ 2 | /* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1982, 1986, 1991, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * (c) UNIX System Laboratories, Inc. 8 | * All or some portions of this file are derived from material licensed 9 | * to the University of California by American Telephone and Telegraph 10 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with 11 | * the permission of UNIX System Laboratories, Inc. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 3. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | * 37 | * @(#)types.h 8.4 (Berkeley) 1/21/94 38 | */ 39 | 40 | #ifndef _SYS_TYPES_H_ 41 | #define _SYS_TYPES_H_ 42 | 43 | #include 44 | #include 45 | 46 | typedef unsigned char u_char; 47 | typedef unsigned short u_short; 48 | typedef unsigned int u_int; 49 | typedef unsigned long u_long; 50 | 51 | typedef unsigned char unchar; /* Sys V compatibility */ 52 | typedef unsigned short ushort; /* Sys V compatibility */ 53 | typedef unsigned int uint; /* Sys V compatibility */ 54 | typedef unsigned long ulong; /* Sys V compatibility */ 55 | 56 | #ifndef _INT8_T_DEFINED_ 57 | #define _INT8_T_DEFINED_ 58 | typedef __int8_t int8_t; 59 | #endif 60 | 61 | #ifndef _UINT8_T_DEFINED_ 62 | #define _UINT8_T_DEFINED_ 63 | typedef __uint8_t uint8_t; 64 | #endif 65 | 66 | #ifndef _INT16_T_DEFINED_ 67 | #define _INT16_T_DEFINED_ 68 | typedef __int16_t int16_t; 69 | #endif 70 | 71 | #ifndef _UINT16_T_DEFINED_ 72 | #define _UINT16_T_DEFINED_ 73 | typedef __uint16_t uint16_t; 74 | #endif 75 | 76 | #ifndef _INT32_T_DEFINED_ 77 | #define _INT32_T_DEFINED_ 78 | typedef __int32_t int32_t; 79 | #endif 80 | 81 | #ifndef _UINT32_T_DEFINED_ 82 | #define _UINT32_T_DEFINED_ 83 | typedef __uint32_t uint32_t; 84 | #endif 85 | 86 | #ifndef _INT64_T_DEFINED_ 87 | #define _INT64_T_DEFINED_ 88 | typedef __int64_t int64_t; 89 | #endif 90 | 91 | #ifndef _UINT64_T_DEFINED_ 92 | #define _UINT64_T_DEFINED_ 93 | typedef __uint64_t uint64_t; 94 | #endif 95 | 96 | #ifndef _INTPTR_T_DEFINED_ 97 | #define _INTPTR_T_DEFINED_ 98 | typedef __intptr_t intptr_t; 99 | #endif 100 | 101 | #ifndef _UINTPTR_T_DEFINED_ 102 | #define _UINTPTR_T_DEFINED_ 103 | typedef __uintptr_t uintptr_t; 104 | #endif 105 | 106 | /* BSD-style unsigned bits types */ 107 | typedef __uint8_t u_int8_t; 108 | typedef __uint16_t u_int16_t; 109 | typedef __uint32_t u_int32_t; 110 | typedef __uint64_t u_int64_t; 111 | 112 | 113 | #ifndef _SIZE_T_DEFINED_ 114 | #define _SIZE_T_DEFINED_ 115 | typedef __size_t size_t; 116 | #endif 117 | 118 | #ifndef _SSIZE_T_DEFINED_ 119 | #define _SSIZE_T_DEFINED_ 120 | typedef __ssize_t ssize_t; 121 | #endif 122 | 123 | #ifndef _OFF_T_DEFINED_ 124 | #define _OFF_T_DEFINED_ 125 | typedef __off_t off_t; 126 | typedef __off64_t off64_t; 127 | #endif 128 | 129 | #endif /* !_SYS_TYPES_H_ */ 130 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/sys/uio.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1996-2018 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with the GNU C Library; if not, see 16 | . */ 17 | 18 | #ifndef _SYS_UIO_H_ 19 | #define _SYS_UIO_H_ 20 | 21 | /* Structure for scatter/gather I/O. */ 22 | struct iovec 23 | { 24 | void *iov_base; /* Pointer to data. */ 25 | size_t iov_len; /* Length of data. */ 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/time.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: time.h,v 1.18 2006/01/06 18:53:04 millert Exp $ */ 2 | /* $NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1989 The Regents of the University of California. 6 | * All rights reserved. 7 | * 8 | * (c) UNIX System Laboratories, Inc. 9 | * All or some portions of this file are derived from material licensed 10 | * to the University of California by American Telephone and Telegraph 11 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with 12 | * the permission of UNIX System Laboratories, Inc. 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * 1. Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 3. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | * 38 | * @(#)time.h 5.12 (Berkeley) 3/9/91 39 | */ 40 | 41 | #ifndef _TIME_H_ 42 | #define _TIME_H_ 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #ifndef NULL 49 | #ifdef __cplusplus 50 | #define NULL 0 51 | #else 52 | #define NULL ((void *)0) 53 | #endif 54 | #endif 55 | 56 | #if !defined (_CLOCK_T_DEFINED_) && !defined (_CLOCK_T_DEFINED) 57 | #define _CLOCK_T_DEFINED_ 58 | #define _CLOCK_T_DEFINED 59 | typedef __clock_t clock_t; 60 | #endif 61 | 62 | #if !defined (_TIME_T_DEFINED_) && !defined (_TIME_T_DEFINED) 63 | #define _TIME_T_DEFINED_ 64 | #define _TIME_T_DEFINED 65 | typedef __time_t time_t; 66 | #endif 67 | 68 | #if !defined (_SIZE_T_DEFINED_) && !defined (_SIZE_T_DEFINED) 69 | #define _SIZE_T_DEFINED_ 70 | #define _SIZE_T_DEFINED 71 | typedef __size_t size_t; 72 | #endif 73 | 74 | #if !defined (_TM_DEFINED) 75 | #define _TM_DEFINED 76 | struct tm { 77 | int tm_sec; /* seconds after the minute [0-60] */ 78 | int tm_min; /* minutes after the hour [0-59] */ 79 | int tm_hour; /* hours since midnight [0-23] */ 80 | int tm_mday; /* day of the month [1-31] */ 81 | int tm_mon; /* months since January [0-11] */ 82 | int tm_year; /* years since 1900 */ 83 | int tm_wday; /* days since Sunday [0-6] */ 84 | int tm_yday; /* days since January 1 [0-365] */ 85 | int tm_isdst; /* Daylight Saving Time flag */ 86 | /* FIXME: naming issue exists on Fedora/Ubuntu */ 87 | long tm_gmtoff; /* offset from UTC in seconds */ 88 | char *tm_zone; /* timezone abbreviation */ 89 | }; 90 | #endif 91 | 92 | __BEGIN_DECLS 93 | 94 | double _TLIBC_CDECL_ difftime(time_t, time_t); 95 | char * _TLIBC_CDECL_ asctime(const struct tm *); 96 | size_t _TLIBC_CDECL_ strftime(char *, size_t, const char *, const struct tm *); 97 | 98 | /* 99 | * Non-C99 100 | */ 101 | char * _TLIBC_CDECL_ asctime_r(const struct tm *, char *); 102 | 103 | __END_DECLS 104 | 105 | #endif /* !_TIME_H_ */ 106 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/unistd.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: unistd.h,v 1.62 2008/06/25 14:58:54 millert Exp $ */ 2 | /* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1991 The Regents of the University of California. 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * @(#)unistd.h 5.13 (Berkeley) 6/17/91 33 | */ 34 | 35 | #ifndef _UNISTD_H_ 36 | #define _UNISTD_H_ 37 | 38 | #include 39 | #include 40 | 41 | __BEGIN_DECLS 42 | 43 | void * _TLIBC_CDECL_ sbrk(intptr_t); 44 | 45 | /* 46 | * Deprecated Non-C99. 47 | */ 48 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execl, const char *, const char *, ...); 49 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execlp, const char *, const char *, ...); 50 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execle, const char *, const char *, ...); 51 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execv, const char *, char * const *); 52 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execve, const char *, char * const *, char * const *); 53 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execvp, const char *, char * const *); 54 | 55 | //_TLIBC_DEPRECATED_FUNCTION_(pid_t _TLIBC_CDECL_, fork, void); /* no pid_t */ 56 | 57 | __END_DECLS 58 | 59 | #endif /* !_UNISTD_H_ */ 60 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/common/inc/wctype.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: wctype.h,v 1.5 2006/01/06 18:53:04 millert Exp $ */ 2 | /* $NetBSD: wctype.h,v 1.5 2003/03/02 22:18:11 tshiozak Exp $ */ 3 | 4 | /*- 5 | * Copyright (c)1999 Citrus Project, 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp 30 | */ 31 | 32 | #ifndef _WCTYPE_H_ 33 | #define _WCTYPE_H_ 34 | 35 | #include 36 | #include 37 | 38 | #ifndef _WINT_T_DEFINED_ 39 | #define _WINT_T_DEFINED_ 40 | typedef __wint_t wint_t; 41 | #endif 42 | 43 | #ifndef _WCTRANS_T_DEFINED_ 44 | #define _WCTRANS_T_DEFINED_ 45 | typedef __wctrans_t wctrans_t; 46 | #endif 47 | 48 | #ifndef _WCTYPE_T_DEFINED_ 49 | #define _WCTYPE_T_DEFINED_ 50 | typedef __wctype_t wctype_t; 51 | #endif 52 | 53 | #ifndef WEOF 54 | #define WEOF ((wint_t)-1) 55 | #endif 56 | 57 | __BEGIN_DECLS 58 | 59 | /* 60 | * Deprecated definitions. 61 | */ 62 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswalnum, wint_t); 63 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswalpha, wint_t); 64 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswblank, wint_t); 65 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswcntrl, wint_t); 66 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswdigit, wint_t); 67 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswgraph, wint_t); 68 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswlower, wint_t); 69 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswprint, wint_t); 70 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswpunct, wint_t); 71 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswspace, wint_t); 72 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswupper, wint_t); 73 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswxdigit, wint_t); 74 | _TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswctype, wint_t, wctype_t); 75 | _TLIBC_DEPRECATED_FUNCTION_(wint_t _TLIBC_CDECL_, towctrans, wint_t, wctrans_t); 76 | _TLIBC_DEPRECATED_FUNCTION_(wint_t _TLIBC_CDECL_, towlower, wint_t); 77 | _TLIBC_DEPRECATED_FUNCTION_(wint_t _TLIBC_CDECL_, towupper, wint_t); 78 | _TLIBC_DEPRECATED_FUNCTION_(wctrans_t _TLIBC_CDECL_, wctrans, const char *); 79 | _TLIBC_DEPRECATED_FUNCTION_(wctype_t _TLIBC_CDECL_, wctype, const char *); 80 | 81 | __END_DECLS 82 | 83 | #endif /* _WCTYPE_H_ */ 84 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/inc/dirent.h: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License.. 17 | 18 | #ifndef _EDL_DIRENT_H 19 | #define _EDL_DIRENT_H 20 | 21 | struct dirent_t 22 | { 23 | uint64_t d_ino; 24 | int64_t d_off; 25 | unsigned short int d_reclen; 26 | unsigned char d_type; 27 | char d_name[256]; 28 | }; 29 | 30 | struct dirent64_t 31 | { 32 | uint64_t d_ino; 33 | int64_t d_off; 34 | unsigned short int d_reclen; 35 | unsigned char d_type; 36 | char d_name[256]; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/inc/stat.h: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License.. 17 | 18 | #ifndef _EDL_STAT_H 19 | #define _EDL_STAT_H 20 | 21 | struct stat_t 22 | { 23 | uint64_t st_dev; 24 | uint64_t st_ino; 25 | uint64_t st_nlink; 26 | uint32_t st_mode; 27 | uint32_t st_uid; 28 | uint32_t st_gid; 29 | int __pad0; 30 | uint64_t st_rdev; 31 | uint64_t st_size; 32 | int64_t st_blksize; 33 | int64_t st_blocks; 34 | int64_t st_atime; 35 | int64_t st_atime_nsec; 36 | int64_t st_mtime; 37 | int64_t st_mtime_nsec; 38 | int64_t st_ctime; 39 | int64_t st_ctime_nsec; 40 | int64_t __reserved[3]; 41 | }; 42 | 43 | struct stat64_t 44 | { 45 | uint64_t st_dev; 46 | uint64_t st_ino; 47 | uint64_t st_nlink; 48 | uint32_t st_mode; 49 | uint32_t st_uid; 50 | uint32_t st_gid; 51 | int __pad0; 52 | uint64_t st_rdev; 53 | uint64_t st_size; 54 | int64_t st_blksize; 55 | int64_t st_blocks; 56 | int64_t st_atime; 57 | int64_t st_atime_nsec; 58 | int64_t st_mtime; 59 | int64_t st_mtime_nsec; 60 | int64_t st_ctime; 61 | int64_t st_ctime_nsec; 62 | int64_t __reserved[3]; 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/intel/sgx_dcap_tvl.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2020 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | enclave { 33 | 34 | include "sgx_qve_header.h" 35 | include "sgx_ql_quote.h" 36 | 37 | 38 | trusted { 39 | 40 | /** 41 | * Verify QvE Report and Identity 42 | * 43 | * @param p_quote[IN] - Pointer to SGX Quote. 44 | * @param quote_size[IN] - Size of the buffer pointed to by p_quote (in bytes). 45 | * @param p_qve_report_info[IN] - The output of API "sgx_qv_verify_quote", it should contain QvE report and nonce 46 | * @param expiration_check_date[IN] - This is the date to verify QvE report data, you should use same value for this API and "sgx_qv_verify_quote" 47 | * @param collateral_expiration_status[IN] - The output of API "sgx_qv_verify_quote" about quote verification collateral's expiration status 48 | * @param quote_verification_result[IN] - The output of API "sgx_qv_verify_quote" about quote verification result 49 | * @param p_supplemental_data[IN] - The output of API "sgx_qv_verify_quote", the pointer to supplemental data 50 | * @param supplemental_data_size[IN] - Size of the buffer pointed to by p_quote (in bytes) 51 | * @param qve_isvsvn_threshold [IN] - The threshold of QvE ISVSVN, the ISVSVN of QvE used to verify quote must be greater or equal to this threshold. You can get latest QvE ISVSVN in QvE Identity (JSON) from Intel PCS. 52 | * 53 | * @return Status code of the operation, one of: 54 | * - SGX_QL_SUCCESS 55 | * - SGX_QL_ERROR_INVALID_PARAMETER 56 | * - SGX_QL_ERROR_REPORT // Error when verifying QvE report 57 | * - SGX_QL_ERROR_UNEXPECTED // Error when comparing QvE report data 58 | * - SGX_QL_QVEIDENTITY_MISMATCH // Error when comparing QvE identity 59 | * - SGX_QL_QVE_OUT_OF_DATE // QvE ISVSVN is smaller than input QvE ISV SVN threshold 60 | **/ 61 | 62 | public quote3_error_t sgx_tvl_verify_qve_report_and_identity( 63 | [in, size=quote_size] const uint8_t *p_quote, 64 | uint32_t quote_size, 65 | [in, count=1] const sgx_ql_qe_report_info_t *p_qve_report_info, 66 | time_t expiration_check_date, 67 | uint32_t collateral_expiration_status, 68 | sgx_ql_qv_result_t quote_verification_result, 69 | [in, size=supplemental_data_size] const uint8_t *p_supplemental_data, 70 | uint32_t supplemental_data_size, 71 | sgx_isv_svn_t qve_isvsvn_threshold); 72 | }; 73 | }; 74 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/intel/sgx_pthread.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2019 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | enclave { 33 | untrusted { 34 | [cdecl] int pthread_wait_timeout_ocall (unsigned long long waiter, unsigned long long timeout); 35 | [cdecl] int pthread_create_ocall(unsigned long long self); 36 | [cdecl] int pthread_wakeup_ocall(unsigned long long waiter); 37 | }; 38 | }; 39 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/intel/sgx_tkey_exchange.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2019 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | enclave { 33 | trusted { 34 | public sgx_status_t sgx_ra_get_ga(sgx_ra_context_t context, 35 | [out] sgx_ec256_public_t *g_a); 36 | 37 | public sgx_status_t sgx_ra_proc_msg2_trusted(sgx_ra_context_t context, 38 | [in]const sgx_ra_msg2_t *p_msg2, /*copy msg2 except quote into enclave */ 39 | [in] const sgx_target_info_t *p_qe_target, 40 | [out] sgx_report_t *p_report, 41 | [out] sgx_quote_nonce_t *p_nonce); 42 | 43 | public sgx_status_t sgx_ra_get_msg3_trusted(sgx_ra_context_t context, 44 | uint32_t quote_size, 45 | [in]sgx_report_t* qe_report, 46 | [user_check]sgx_ra_msg3_t *p_msg3, 47 | uint32_t msg3_size); 48 | }; 49 | }; 50 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/intel/sgx_tprotected_fs.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2019 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | enclave { 33 | from "sgx_tstdc.edl" import *; 34 | untrusted { 35 | void* u_sgxprotectedfs_exclusive_file_open([in, string] const char* filename, uint8_t read_only, [out] int64_t* file_size, [out] int32_t* error_code); 36 | uint8_t u_sgxprotectedfs_check_if_file_exists([in, string] const char* filename); 37 | int32_t u_sgxprotectedfs_fread_node([user_check] void* f, uint64_t node_number, [out, size=node_size] uint8_t* buffer, uint32_t node_size); 38 | int32_t u_sgxprotectedfs_fwrite_node([user_check] void* f, uint64_t node_number, [in, size=node_size] uint8_t* buffer, uint32_t node_size); 39 | int32_t u_sgxprotectedfs_fclose([user_check] void* f); 40 | uint8_t u_sgxprotectedfs_fflush([user_check] void* f); 41 | int32_t u_sgxprotectedfs_remove([in, string] const char* filename); 42 | 43 | void* u_sgxprotectedfs_recovery_file_open([in, string] const char* filename); 44 | uint8_t u_sgxprotectedfs_fwrite_recovery_node([user_check] void* f, [in, count=data_length] uint8_t* data, uint32_t data_length); 45 | int32_t u_sgxprotectedfs_do_file_recovery([in, string] const char* filename, [in, string] const char* recovery_filename, uint32_t node_size); 46 | }; 47 | }; 48 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/intel/sgx_tstdc.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2019 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | enclave { 33 | untrusted { 34 | [cdecl] void sgx_oc_cpuidex([out] int cpuinfo[4], int leaf, int subleaf); 35 | 36 | /* Go outside and wait on my untrusted event */ 37 | [cdecl] int sgx_thread_wait_untrusted_event_ocall([user_check] const void *self); 38 | 39 | /* Wake a thread waiting on its untrusted event */ 40 | [cdecl] int sgx_thread_set_untrusted_event_ocall([user_check] const void *waiter); 41 | 42 | /* Wake a thread waiting on its untrusted event, and wait on my untrusted event */ 43 | [cdecl] int sgx_thread_setwait_untrusted_events_ocall([user_check] const void *waiter, [user_check] const void *self); 44 | 45 | /* Wake multiple threads waiting on their untrusted events */ 46 | [cdecl] int sgx_thread_set_multiple_untrusted_events_ocall([in, count = total] const void **waiters, size_t total); 47 | }; 48 | }; 49 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/intel/sgx_tswitchless.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011-2019 Intel Corporation. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Intel Corporation nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | enclave { 33 | 34 | trusted { 35 | public sgx_status_t sl_init_switchless([user_check]void* sl_data); 36 | public sgx_status_t sl_run_switchless_tworker(); 37 | }; 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_asyncio.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "sys/epoll.h" 21 | include "poll.h" 22 | 23 | trusted { 24 | /* define ECALLs here. */ 25 | }; 26 | 27 | untrusted { 28 | int u_poll_ocall([out] int *error, [in, out, count=nfds] struct pollfd *fds, nfds_t nfds, int timeout); 29 | int u_epoll_create1_ocall([out] int *error, int flags); 30 | int u_epoll_ctl_ocall([out] int *error, int epfd, int op, int fd, [in] struct epoll_event *event); 31 | int u_epoll_wait_ocall([out] int *error, int epfd, [out, count=maxevents] struct epoll_event *events, int maxevents, int timeout); 32 | }; 33 | }; 34 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_backtrace.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | from "sgx_fd.edl" import *; 21 | from "sgx_file.edl" import *; 22 | from "sgx_mem.edl" import *; 23 | 24 | trusted { 25 | /* define ECALLs here. */ 26 | }; 27 | 28 | untrusted { 29 | /* define OCALLs here. */ 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_env.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "pwd.h" 21 | 22 | trusted { 23 | /* define ECALLs here. */ 24 | }; 25 | 26 | untrusted { 27 | char **u_environ_ocall(); 28 | char *u_getenv_ocall([in, string] const char *name); 29 | int u_setenv_ocall([out] int *error, [in, string] const char *name, [in, string] const char *value, int overwrite); 30 | int u_unsetenv_ocall([out] int *error, [in, string] const char *name); 31 | int u_chdir_ocall([out] int *error, [in, string] const char *dir); 32 | char *u_getcwd_ocall([out] int *error, [out, size=buflen] char *buf, size_t buflen); 33 | int u_getpwuid_r_ocall(unsigned int uid, 34 | [out] struct passwd *pwd, 35 | [out, size=buflen] char *buf, 36 | size_t buflen, 37 | [out] struct passwd **passwd_result); 38 | unsigned int u_getuid_ocall(); 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_fd.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "inc/stat.h" 21 | include "sys/uio.h" 22 | 23 | from "sgx_mem.edl" import *; 24 | 25 | trusted { 26 | /* define ECALLs here. */ 27 | }; 28 | 29 | untrusted { 30 | size_t u_read_ocall([out] int *error, int fd, [user_check] void *buf, size_t count); 31 | size_t u_pread64_ocall([out] int *error, int fd, [user_check] void *buf, size_t count, int64_t offset); 32 | size_t u_readv_ocall([out] int *error, int fd, [in, count=iovcnt] const struct iovec *iov, int iovcnt); 33 | size_t u_preadv64_ocall([out] int *error, int fd, [in, count=iovcnt] const struct iovec *iov, int iovcnt, int64_t offset); 34 | 35 | size_t u_write_ocall([out] int *error, int fd, [user_check] const void *buf, size_t count); 36 | size_t u_pwrite64_ocall([out] int *error, int fd, [user_check] const void *buf, size_t count, int64_t offset); 37 | size_t u_writev_ocall([out] int *error, int fd, [in, count=iovcnt] const struct iovec *iov, int iovcnt); 38 | size_t u_pwritev64_ocall([out] int *error, int fd, [in, count=iovcnt] const struct iovec *iov, int iovcnt, int64_t offset); 39 | 40 | int u_fcntl_arg0_ocall([out] int *error, int fd, int cmd); 41 | int u_fcntl_arg1_ocall([out] int *error, int fd, int cmd, int arg); 42 | int u_ioctl_arg0_ocall([out] int *error, int fd, int request); 43 | int u_ioctl_arg1_ocall([out] int *error, int fd, int request, [in, out] int *arg); 44 | 45 | int u_close_ocall([out] int *error, int fd); 46 | }; 47 | }; 48 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_file.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "inc/stat.h" 21 | include "inc/dirent.h" 22 | 23 | trusted { 24 | /* define ECALLs here. */ 25 | }; 26 | 27 | untrusted { 28 | int u_open_ocall([out] int *error, [in, string] const char *pathname, int flags); 29 | int u_open64_ocall([out] int *error, [in, string] const char *path, int oflag, int mode); 30 | 31 | int u_fstat_ocall([out] int *error, int fd, [out] struct stat_t *buf); 32 | int u_fstat64_ocall([out] int *error, int fd, [out] struct stat64_t *buf); 33 | int u_stat_ocall([out] int *error, [in, string] const char *path, [out] struct stat_t *buf); 34 | int u_stat64_ocall([out] int *error, [in, string] const char *path, [out] struct stat64_t *buf); 35 | int u_lstat_ocall([out] int *error, [in, string] const char *path, [out] struct stat_t *buf); 36 | int u_lstat64_ocall([out] int *error, [in, string] const char *path, [out] struct stat64_t *buf); 37 | uint64_t u_lseek_ocall([out] int *error, int fd, int64_t offset, int whence); 38 | int64_t u_lseek64_ocall([out] int *error, int fd, int64_t offset, int whence); 39 | int u_ftruncate_ocall([out] int *error, int fd, int64_t length); 40 | int u_ftruncate64_ocall([out] int *error, int fd, int64_t length); 41 | int u_truncate_ocall([out] int *error, [in, string] const char *path, int64_t length); 42 | int u_truncate64_ocall([out] int *error, [in, string] const char *path, int64_t length); 43 | 44 | int u_fsync_ocall([out] int *error, int fd); 45 | int u_fdatasync_ocall([out] int *error, int fd); 46 | int u_fchmod_ocall([out] int *error, int fd, uint32_t mode); 47 | int u_unlink_ocall([out] int *error, [in, string] const char *pathname); 48 | int u_link_ocall([out] int *error, [in, string] const char *oldpath, [in, string] const char *newpath); 49 | int u_rename_ocall([out] int *error, [in, string] const char *oldpath, [in, string] const char *newpath); 50 | int u_chmod_ocall([out] int *error, [in, string] const char *path, uint32_t mode); 51 | size_t u_readlink_ocall([out] int *error, [in, string] const char *path, [out, size=bufsz] char *buf, size_t bufsz); 52 | int u_symlink_ocall([out] int *error, [in, string] const char *path1, [in, string] const char *path2); 53 | char *u_realpath_ocall([out] int *error, [in, string] const char *pathname); 54 | int u_mkdir_ocall([out] int *error, [in, string] const char *pathname, uint32_t mode); 55 | int u_rmdir_ocall([out] int *error, [in, string] const char *pathname); 56 | void *u_opendir_ocall([out] int *error, [in, string] const char *pathname); 57 | int u_readdir64_r_ocall([user_check] void *dirp, [in, out] struct dirent64_t *entry, [out] struct dirent64_t **result); 58 | int u_closedir_ocall([out] int *error, [user_check] void *dirp); 59 | int u_dirfd_ocall([out] int *error, [user_check] void *dirp); 60 | int u_fstatat64_ocall([out] int *error, int dirfd, [in, string] const char *pathname, [out] struct stat64_t *buf, int flags); 61 | }; 62 | }; 63 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_fs.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | from "sgx_mem.edl" import *; 21 | from "sgx_fd.edl" import *; 22 | from "sgx_file.edl" import *; 23 | 24 | trusted { 25 | /* define ECALLs here. */ 26 | }; 27 | 28 | untrusted { 29 | /* define OCALLs here. */ 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_mem.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | trusted { 21 | /* define ECALLs here. */ 22 | }; 23 | 24 | untrusted { 25 | void *u_malloc_ocall([out] int *error, size_t size); 26 | void u_free_ocall([user_check] void *p); 27 | 28 | void *u_mmap_ocall([out] int *error, 29 | [user_check] void *start, 30 | size_t length, 31 | int prot, 32 | int flags, 33 | int fd, 34 | int64_t offset); 35 | int u_munmap_ocall([out] int *error, [user_check] void *start, size_t length); 36 | 37 | int u_msync_ocall([out] int *error, [user_check] void *addr, size_t length, int flags); 38 | int u_mprotect_ocall([out] int *error, [user_check] void *addr, size_t length, int prot); 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_net.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "sys/socket.h" 21 | include "netdb.h" 22 | 23 | from "sgx_socket.edl" import *; 24 | from "sgx_asyncio.edl" import *; 25 | from "sgx_fd.edl" import *; 26 | from "sgx_time.edl" import *; 27 | 28 | trusted { 29 | /* define ECALLs here. */ 30 | }; 31 | 32 | untrusted { 33 | int u_getaddrinfo_ocall([out] int *error, 34 | [in, string] const char *node, 35 | [in, string] const char *service, 36 | [in] const struct addrinfo *hints, 37 | [out] struct addrinfo **res); 38 | void u_freeaddrinfo_ocall([user_check] struct addrinfo *res); 39 | char *u_gai_strerror_ocall(int errcode); 40 | }; 41 | }; 42 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_pipe.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | from "sgx_fd.edl" import *; 21 | from "sgx_asyncio.edl" import *; 22 | 23 | trusted { 24 | /* define ECALLs here. */ 25 | }; 26 | 27 | untrusted { 28 | int u_pipe_ocall([out] int *error, [out, count=2] int *pipefd); 29 | int u_pipe2_ocall([out] int *error, [out, count=2] int *pipefd, int flags); 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_process.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | trusted { 21 | /* define ECALLs here. */ 22 | 23 | }; 24 | 25 | untrusted { 26 | int u_getpid_ocall(); 27 | }; 28 | }; 29 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_signal.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | include "signal.h" 20 | 21 | trusted { 22 | /* define ECALLs here. */ 23 | public int t_signal_handler_ecall([in]const siginfo_t *info); 24 | }; 25 | 26 | untrusted { 27 | int u_sigaction_ocall([out]int *error, 28 | int signum, 29 | [in] const struct sigaction *act, 30 | [out] struct sigaction *oldact, 31 | uint64_t enclave_id); 32 | 33 | int u_sigprocmask_ocall([out]int *error, 34 | int signum, 35 | [in] const sigset_t *set, 36 | [out] sigset_t *oldset); 37 | 38 | int u_raise_ocall(int signum) allow(t_signal_handler_ecall); 39 | 40 | void u_signal_clear_ocall(uint64_t enclave_id); 41 | }; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_socket.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "sys/socket.h" 21 | 22 | from "sgx_mem.edl" import *; 23 | 24 | trusted { 25 | /* define ECALLs here. */ 26 | }; 27 | 28 | untrusted { 29 | int u_socket_ocall([out] int *error, int domain, int ty, int protocol); 30 | int u_socketpair_ocall([out] int *error, int domain, int ty, int protocol, [out] int sv[2]); 31 | int u_bind_ocall([out] int *error, int sockfd, [in, size=addrlen] const struct sockaddr *addr, socklen_t addrlen); 32 | int u_listen_ocall([out] int *error, int sockfd, int backlog); 33 | int u_accept_ocall([out] int *error, 34 | int sockfd, 35 | [in, out, size=addrlen_in] struct sockaddr *addr, 36 | socklen_t addrlen_in, 37 | [out] socklen_t *addrlen_out); 38 | int u_accept4_ocall([out] int *error, 39 | int sockfd, 40 | [in, out, size=addrlen_in] struct sockaddr *addr, 41 | socklen_t addrlen_in, 42 | [out] socklen_t *addrlen_out, 43 | int flags); 44 | int u_connect_ocall([out] int *error, 45 | int sockfd, 46 | [in, size=addrlen] const struct sockaddr *addr, 47 | socklen_t addrlen); 48 | size_t u_recv_ocall([out] int *error, int sockfd,[user_check] void *buf, size_t len, int flags); 49 | size_t u_recvfrom_ocall([out] int *error, 50 | int sockfd, 51 | [user_check] void *buf, 52 | size_t len, 53 | int flags, 54 | [out, size=addrlen_in] struct sockaddr *src_addr, 55 | socklen_t addrlen_in, 56 | [out] socklen_t *addrlen_out); 57 | size_t u_recvmsg_ocall([out] int *error, int sockfd, [in, out] struct msghdr *msg, int flags); 58 | size_t u_send_ocall([out] int *error, int sockfd, [user_check] const void *buf, size_t len, int flags); 59 | size_t u_sendto_ocall([out] int *error, 60 | int sockfd, 61 | [user_check] const void *buf, 62 | size_t len, 63 | int flags, 64 | [in, size=addrlen] const struct sockaddr *dest_addr, 65 | socklen_t addrlen); 66 | size_t u_sendmsg_ocall([out] int *error, int sockfd, [in] const struct msghdr *msg, int flags); 67 | int u_getsockopt_ocall([out] int *error, 68 | int sockfd, 69 | int level, 70 | int optname, 71 | [out, size=optlen_in] void *optval, 72 | socklen_t optlen_in, 73 | [out] socklen_t *optlen_out); 74 | int u_setsockopt_ocall([out] int *error, 75 | int sockfd, 76 | int level, 77 | int optname, 78 | [in, size=optlen] const void *optval, 79 | socklen_t optlen); 80 | int u_getsockname_ocall([out] int *error, 81 | int sockfd, 82 | [out, size=addrlen_in] struct sockaddr *addr, 83 | socklen_t addrlen_in, 84 | [out] socklen_t *addrlen_out); 85 | int u_getpeername_ocall([out] int *error, 86 | int sockfd, 87 | [out, size=addrlen_in] struct sockaddr *addr, 88 | socklen_t addrlen_in, 89 | [out] socklen_t *addrlen_out); 90 | int u_shutdown_ocall([out] int *error, int sockfd, int how); 91 | }; 92 | }; 93 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_stdio.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | from "sgx_fd.edl" import *; 21 | 22 | trusted { 23 | /* define ECALLs here. */ 24 | }; 25 | 26 | untrusted { 27 | /* define OCALLs here. */ 28 | }; 29 | }; 30 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_sys.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "sched.h" 21 | 22 | trusted { 23 | /* define ECALLs here. */ 24 | }; 25 | 26 | untrusted { 27 | long u_sysconf_ocall([out] int *error, int name); 28 | int u_prctl_ocall([out] int *error, int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); 29 | int u_sched_setaffinity_ocall([out] int *error, pid_t pid, size_t cpusetsize, [in]cpu_set_t *mask); 30 | int u_sched_getaffinity_ocall([out] int *error, pid_t pid, size_t cpusetsize, [out]cpu_set_t *mask); 31 | }; 32 | }; 33 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_thread.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | enclave { 18 | 19 | include "time.h" 20 | 21 | from "intel/sgx_pthread.edl" import *; 22 | from "sgx_sys.edl" import *; 23 | 24 | trusted { 25 | /* define ECALLs here. */ 26 | }; 27 | 28 | untrusted { 29 | int u_sched_yield_ocall([out]int *error); 30 | int u_nanosleep_ocall([out]int *error, [in]const struct timespec *req, [out]struct timespec *rem); 31 | }; 32 | }; 33 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_time.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | include "time.h" 21 | 22 | trusted { 23 | /* define ECALLs here. */ 24 | }; 25 | 26 | untrusted { 27 | int u_clock_gettime_ocall([out] int *error, int clk_id, [out] struct timespec *tp); 28 | }; 29 | }; 30 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/edl/sgx_tstd.edl: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | enclave { 19 | 20 | from "sgx_time.edl" import *; 21 | 22 | trusted { 23 | /* define ECALLs here. */ 24 | public void t_global_init_ecall(uint64_t id, [in, size=len] const uint8_t *path, size_t len); 25 | public void t_global_exit_ecall(); 26 | }; 27 | 28 | untrusted { 29 | /* define OCALLs here. */ 30 | int u_thread_set_event_ocall([out] int *error, [user_check] const void *tcs); 31 | int u_thread_wait_event_ocall([out] int *error, [user_check] const void *tcs, [in] const struct timespec *timeout); 32 | int u_thread_set_multiple_events_ocall([out] int *error, [in, count=total] const void **tcss, int total); 33 | int u_thread_setwait_events_ocall([out] int *error, 34 | [user_check] const void *waiter_tcs, 35 | [user_check] const void *self_tcs, 36 | [in] const struct timespec *timeout); 37 | }; 38 | }; 39 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "Helloworldsampleenclave" 3 | version = "1.0.0" 4 | authors = ["Baidu"] 5 | 6 | [lib] 7 | name = "gbdtenclave" 8 | crate-type = ["staticlib"] 9 | 10 | [features] 11 | default = [] 12 | 13 | [dependencies] 14 | gbdt_sgx = { path = "../../gbdt-sgx", default-features = false, features = ["mesalock_sgx", "input", "enable_training"] } 15 | 16 | [target.'cfg(not(target_env = "sgx"))'.dependencies] 17 | sgx_types = { rev = "v1.1.3", git = "https://github.com/apache/teaclave-sgx-sdk.git" } 18 | sgx_tstd = { rev = "v1.1.3", git = "https://github.com/apache/teaclave-sgx-sdk.git" } 19 | sgx_tunittest = { rev = "v1.1.3", git = "https://github.com/apache/teaclave-sgx-sdk.git" } 20 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/Enclave.config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 0 5 | 0x40000 6 | 0x1000000 7 | 1 8 | 0 9 | 0 10 | 0 11 | 0xFFFFFFFF 12 | 13 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/Enclave.edl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 Baidu, Inc. All Rights Reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Baidu, Inc., nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | enclave { 33 | from "sgx_tstd.edl" import *; 34 | from "sgx_stdio.edl" import *; 35 | from "sgx_backtrace.edl" import *; 36 | from "sgx_tstdc.edl" import *; 37 | trusted { 38 | /* define ECALLs here. */ 39 | 40 | public sgx_status_t say_something([in, size=len] const uint8_t* some_string, size_t len); 41 | }; 42 | }; 43 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/Enclave.lds: -------------------------------------------------------------------------------- 1 | enclave.so 2 | { 3 | global: 4 | g_global_data_sim; 5 | g_global_data; 6 | enclave_entry; 7 | local: 8 | *; 9 | }; 10 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/Enclave_private.pem: -------------------------------------------------------------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dMbkKyI4mHOuXvGv 33 | fg95si9oO7EBT+Oqvhccd2J+F1IVXncccYnF4u5ZGWt5lLewN/pVr7MjjykeaHqN 34 | t+rfnQam2psA6fL4zS2zTmZPzR2tnY8Y1GBTi0Ko1OKd1HMCgcAb5cB/7/AQlhP9 35 | yQa04PLH9ygQkKKptZp7dy5WcWRx0K/hAHRoi2aw1wZqfm7VBNu2SLcs90kCCCxp 36 | 6C5sfJi6b8NpNbIPC+sc9wsFr7pGo9SFzQ78UlcWYK2Gu2FxlMjonhka5hvo4zvg 37 | WxlpXKEkaFt3gLd92m/dMqBrHfafH7VwOJY2zT3WIpjwuk0ZzmRg5p0pG/svVQEH 38 | NZmwRwlopysbR69B/n1nefJ84UO50fLh5s5Zr3gBRwbWNZyzhXk= 39 | -----END RSA PRIVATE KEY----- 40 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017-2018 Baidu, Inc. All Rights Reserved. 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # * Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in 11 | # the documentation and/or other materials provided with the 12 | # distribution. 13 | # * Neither the name of Baidu, Inc., nor the names of its 14 | # contributors may be used to endorse or promote products derived 15 | # from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | # 29 | Rust_Enclave_Name := libenclave.a 30 | Rust_Enclave_Files := $(wildcard src/*.rs) 31 | Rust_Target_Path := $(CURDIR) 32 | 33 | .PHONY: all 34 | 35 | all: $(Rust_Enclave_Name) 36 | 37 | $(Rust_Enclave_Name): $(Rust_Enclave_Files) 38 | ifeq ($(XARGO_SGX), 1) 39 | RUST_TARGET_PATH=$(Rust_Target_Path) xargo build --target x86_64-unknown-linux-sgx --release 40 | cp ./target/x86_64-unknown-linux-sgx/release/libgbdtenclave.a ../lib/libenclave.a 41 | else 42 | cargo build --release 43 | cp ./target/release/libgbdtenclave.a ../lib/libenclave.a 44 | endif 45 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/Xargo.toml: -------------------------------------------------------------------------------- 1 | [dependencies] 2 | alloc = {} 3 | 4 | [dependencies.sgx_types] 5 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 6 | stage = 1 7 | 8 | [dependencies.sgx_alloc] 9 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 10 | stage = 1 11 | 12 | [dependencies.sgx_unwind] 13 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 14 | stage = 1 15 | 16 | [dependencies.sgx_demangle] 17 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 18 | stage = 1 19 | 20 | [dependencies.panic_abort] 21 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 22 | stage = 1 23 | 24 | [dependencies.sgx_libc] 25 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 26 | stage = 2 27 | 28 | [dependencies.sgx_tkey_exchange] 29 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 30 | stage = 2 31 | 32 | [dependencies.sgx_tse] 33 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 34 | stage = 2 35 | 36 | [dependencies.sgx_tcrypto] 37 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 38 | stage = 2 39 | 40 | [dependencies.sgx_trts] 41 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 42 | stage = 3 43 | 44 | [dependencies.sgx_backtrace_sys] 45 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 46 | stage = 3 47 | 48 | [dependencies.panic_unwind] 49 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 50 | stage = 3 51 | 52 | [dependencies.sgx_tdh] 53 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 54 | stage = 4 55 | 56 | [dependencies.sgx_tseal] 57 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 58 | stage = 4 59 | 60 | [dependencies.sgx_tprotected_fs] 61 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 62 | stage = 4 63 | 64 | [dependencies.std] 65 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 66 | features = ["untrusted_fs", "backtrace", "net"] 67 | stage = 5 68 | 69 | [dependencies.sgx_no_tstd] 70 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 71 | stage = 5 72 | 73 | [dependencies.sgx_rand] 74 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 75 | stage = 6 76 | 77 | [dependencies.sgx_serialize] 78 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 79 | stage = 6 80 | 81 | [dependencies.sgx_tunittest] 82 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 83 | stage = 6 84 | 85 | [dependencies.sgx_backtrace] 86 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 87 | stage = 7 88 | 89 | [dependencies.sgx_cov] 90 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 91 | stage = 7 92 | 93 | [dependencies.sgx_signal] 94 | git = "https://github.com/apache/teaclave-sgx-sdk.git" 95 | stage = 7 96 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017-2018 Baidu, Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions 5 | // are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in 11 | // the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Baidu, Inc., nor the names of its 14 | // contributors may be used to endorse or promote products derived 15 | // from this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #![crate_name = "gbdtenclave"] 30 | #![crate_type = "staticlib"] 31 | #![cfg_attr(not(target_env = "sgx"), no_std)] 32 | #![cfg_attr(target_env = "sgx", feature(rustc_private))] 33 | 34 | extern crate sgx_types; 35 | #[cfg(not(target_env = "sgx"))] 36 | #[macro_use] 37 | extern crate sgx_tstd as std; 38 | extern crate sgx_tunittest; 39 | 40 | use sgx_tunittest::*; 41 | use sgx_types::*; 42 | use std::io::{self, Write}; 43 | use std::slice; 44 | use std::string::String; 45 | use std::vec::Vec; 46 | 47 | extern crate gbdt_sgx; 48 | 49 | mod test_agaricus_lepiota; 50 | mod test_lib; 51 | 52 | #[no_mangle] 53 | pub extern "C" fn say_something(some_string: *const u8, some_len: usize) -> sgx_status_t { 54 | let str_slice = unsafe { slice::from_raw_parts(some_string, some_len) }; 55 | let _ = io::stdout().write(str_slice); 56 | 57 | // A sample &'static string 58 | let rust_raw_string = "This is a in-Enclave "; 59 | // An array 60 | let word: [u8; 4] = [82, 117, 115, 116]; 61 | // An vector 62 | let word_vec: Vec = vec![32, 115, 116, 114, 105, 110, 103, 33]; 63 | 64 | // Construct a string from &'static string 65 | let mut hello_string = String::from(rust_raw_string); 66 | 67 | // Iterate on word array 68 | for c in word.iter() { 69 | hello_string.push(*c as char); 70 | } 71 | 72 | // Rust style convertion 73 | hello_string += String::from_utf8(word_vec).expect("Invalid UTF-8").as_str(); 74 | 75 | // Ocall to normal world for output 76 | println!("{}", &hello_string); 77 | 78 | test_agaricus_lepiota::test_main(); 79 | 80 | rsgx_unit_tests!( 81 | test_lib::walk_tree, 82 | test_lib::decision_tree, 83 | test_lib::build_decision_tree, 84 | test_lib::config_express, 85 | test_lib::loss_type, 86 | test_lib::fitness 87 | ); 88 | 89 | sgx_status_t::SGX_SUCCESS 90 | } 91 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/src/test_agaricus_lepiota.rs: -------------------------------------------------------------------------------- 1 | extern crate gbdt_sgx; 2 | use gbdt_sgx::config::Config; 3 | use gbdt_sgx::decision_tree::{DataVec, PredVec}; 4 | use gbdt_sgx::fitness::AUC; 5 | use gbdt_sgx::gradient_boost::GBDT; 6 | use gbdt_sgx::input::{load, InputFormat}; 7 | 8 | pub fn test_main() { 9 | let mut cfg = Config::new(); 10 | cfg.set_feature_size(22); 11 | cfg.set_max_depth(3); 12 | cfg.set_iterations(50); 13 | cfg.set_shrinkage(0.1); 14 | cfg.set_loss("LogLikelyhood"); 15 | cfg.set_debug(true); 16 | //cfg.set_data_sample_ratio(0.8); 17 | //cfg.set_feature_sample_ratio(0.5); 18 | cfg.set_training_optimization_level(2); 19 | 20 | // load data 21 | let train_file = "dataset/agaricus-lepiota/train.txt"; 22 | let test_file = "dataset/agaricus-lepiota/test.txt"; 23 | 24 | let mut input_format = InputFormat::csv_format(); 25 | input_format.set_feature_size(22); 26 | input_format.set_label_index(22); 27 | let mut train_dv: DataVec = 28 | load(train_file, input_format).expect("failed to load training data"); 29 | let test_dv: DataVec = load(test_file, input_format).expect("failed to load test data"); 30 | 31 | // train and save model 32 | let mut gbdt = GBDT::new(&cfg); 33 | gbdt.fit(&mut train_dv); 34 | gbdt.save_model("gbdt.model") 35 | .expect("failed to save the model"); 36 | 37 | // load model and do inference 38 | let model = GBDT::load_model("gbdt.model").expect("failed to load the model"); 39 | let predicted: PredVec = model.predict(&test_dv); 40 | 41 | assert_eq!(predicted.len(), test_dv.len()); 42 | let mut correct = 0; 43 | let mut wrong = 0; 44 | for i in 0..predicted.len() { 45 | let label = if predicted[i] > 0.5 { 1.0 } else { -1.0 }; 46 | if (test_dv[i].label - label).abs() < 0.0001 { 47 | correct += 1; 48 | } else { 49 | wrong += 1; 50 | }; 51 | //println!("[{}] {} {}", i, test_dv[i].label, predicted[i]); 52 | } 53 | 54 | println!("correct: {}", correct); 55 | println!("wrong: {}", wrong); 56 | 57 | let auc = AUC(&test_dv, &predicted, test_dv.len()); 58 | println!("AUC: {}", auc); 59 | 60 | use gbdt_sgx::fitness::almost_equal; 61 | assert_eq!(wrong, 0); 62 | assert!(almost_equal(auc, 1.0)); 63 | } 64 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/enclave/x86_64-unknown-linux-sgx.json: -------------------------------------------------------------------------------- 1 | { 2 | "arch": "x86_64", 3 | "cpu": "x86-64", 4 | "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", 5 | "dynamic-linking": true, 6 | "env": "sgx", 7 | "exe-allocation-crate": "alloc_system", 8 | "executables": true, 9 | "has-elf-tls": true, 10 | "has-rpath": true, 11 | "linker-flavor": "gcc", 12 | "linker-is-gnu": true, 13 | "llvm-target": "x86_64-unknown-linux-gnu", 14 | "max-atomic-width": 64, 15 | "os": "linux", 16 | "position-independent-executables": true, 17 | "pre-link-args": { 18 | "gcc": [ 19 | "-Wl,--as-needed", 20 | "-Wl,-z,noexecstack", 21 | "-m64" 22 | ] 23 | }, 24 | "relro-level": "full", 25 | "stack-probes": true, 26 | "target-c-int-width": "32", 27 | "target-endian": "little", 28 | "target-family": "unix", 29 | "target-pointer-width": "64", 30 | "vendor": "mesalock" 31 | } 32 | -------------------------------------------------------------------------------- /sgx/gbdt-sgx-test/lib/readme.txt: -------------------------------------------------------------------------------- 1 | lib -------------------------------------------------------------------------------- /sgx/gbdt-sgx/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gbdt_sgx" 3 | version = "0.1.0" 4 | authors = ["Tongxin Li ", "Tianyi Li ", "Yu Ding "] 5 | homepage = "https://github.com/mesalock-linux/gbdt-rs" 6 | repository = "https://github.com/mesalock-linux/gbdt-rs" 7 | license = "Apache-2.0" 8 | description = "A implementation of Gradient Boosting Regression Tree in Rust programming language" 9 | edition = "2018" 10 | 11 | [features] 12 | default = ["mesalock_sgx"] 13 | enable_training = ["rand"] 14 | profiling = ["time"] 15 | input = ["regex"] 16 | mesalock_sgx = ["sgx_tstd"] 17 | 18 | [badges] 19 | 20 | [lib] 21 | name = "gbdt_sgx" 22 | path = "../../src/lib.rs" 23 | crate-type = ["rlib", "staticlib"] 24 | 25 | [dependencies] 26 | serde = { git = "https://github.com/mesalock-linux/serde-sgx" } 27 | serde_derive = { git = "https://github.com/mesalock-linux/serde-sgx" } 28 | serde_json = { git = "https://github.com/mesalock-linux/serde-json-sgx" } 29 | rand = { version = "0.7", optional = true, git = "https://github.com/mesalock-linux/rand-sgx", tag = "v0.7.3_sgx1.1.3" } 30 | regex = { version = "1", git = "https://github.com/mesalock-linux/regex-sgx", optional = true } 31 | time = { version = "0.1", optional = true } 32 | sgx_tstd = { rev = "v1.1.3", git = "https://github.com/apache/teaclave-sgx-sdk", optional = true } 33 | cfg-if = "0.1" 34 | 35 | [dev-dependencies] 36 | time = "0.1" 37 | -------------------------------------------------------------------------------- /src/errors.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | use std::fmt::{Display, Formatter}; 3 | use std::io; 4 | use std::num; 5 | 6 | pub type Result = std::result::Result; 7 | 8 | #[derive(Debug)] 9 | pub enum GbdtError { 10 | NotSupportExtraMissingNode, 11 | ChildrenNotFound, 12 | IO(io::Error), 13 | ParseInt(num::ParseIntError), 14 | ParseFloat(num::ParseFloatError), 15 | SerdeJson(serde_json::Error), 16 | } 17 | 18 | impl From<&str> for GbdtError { 19 | fn from(err: &str) -> GbdtError { 20 | GbdtError::IO(io::Error::new(io::ErrorKind::Other, err)) 21 | } 22 | } 23 | 24 | impl From for GbdtError { 25 | fn from(err: serde_json::Error) -> GbdtError { 26 | GbdtError::SerdeJson(err) 27 | } 28 | } 29 | 30 | impl From for GbdtError { 31 | fn from(err: num::ParseFloatError) -> GbdtError { 32 | GbdtError::ParseFloat(err) 33 | } 34 | } 35 | 36 | impl From for GbdtError { 37 | fn from(err: num::ParseIntError) -> GbdtError { 38 | GbdtError::ParseInt(err) 39 | } 40 | } 41 | 42 | impl From for GbdtError { 43 | fn from(err: io::Error) -> GbdtError { 44 | GbdtError::IO(err) 45 | } 46 | } 47 | 48 | impl Display for GbdtError { 49 | fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { 50 | match *self { 51 | GbdtError::NotSupportExtraMissingNode => write!(f, "Not support extra missing node"), 52 | GbdtError::ChildrenNotFound => write!(f, "Children not found"), 53 | GbdtError::IO(ref e) => write!(f, "IO error: {}", e), 54 | GbdtError::ParseInt(ref e) => write!(f, "ParseInt error: {}", e), 55 | GbdtError::ParseFloat(ref e) => write!(f, "ParseFloat error: {}", e), 56 | GbdtError::SerdeJson(ref e) => write!(f, "SerdeJson error: {}", e), 57 | } 58 | } 59 | } 60 | 61 | impl Error for GbdtError { 62 | fn source(&self) -> Option<&(dyn Error + 'static)> { 63 | match *self { 64 | GbdtError::NotSupportExtraMissingNode => None, 65 | GbdtError::ChildrenNotFound => None, 66 | GbdtError::IO(ref e) => Some(e), 67 | GbdtError::ParseInt(ref e) => Some(e), 68 | GbdtError::ParseFloat(ref e) => Some(e), 69 | GbdtError::SerdeJson(ref e) => Some(e), 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /xgb-data/xgb_binary_logistic/xg.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import xgboost as xgb 3 | import numpy as np 4 | import time 5 | 6 | params = { 7 | 'booster': 'gbtree', 8 | 'objective': 'binary:logistic', 9 | 'eta': 0.1, 10 | 'gamma': 1.0, 11 | 'max_depth': 4, 12 | 'min_child_weight': 1, 13 | 'seed': 1000, 14 | 'nthread': 1, 15 | } 16 | 17 | def train(): 18 | xgb_train = xgb.DMatrix("./agaricus.txt.train") 19 | plst = list(params.items()) 20 | print("Training started.") 21 | t0 = time.time() 22 | model = xgb.train(plst, xgb_train, num_boost_round=50, 23 | ) 24 | print("%.3fs taken for training" % (time.time() - t0)) 25 | print("Saving model...") 26 | model.save_model("xgb.model") 27 | 28 | def predict(): 29 | t0 = time.time() 30 | model = xgb.Booster(params=params) 31 | model.load_model("xgb.model") 32 | t1 = time.time() 33 | print("%.3fs taken for load_model" % (t1 - t0)) 34 | 35 | t0 = time.time() 36 | xgb_test = xgb.DMatrix("./agaricus.txt.test") 37 | t1 = time.time() 38 | print("%.3fs taken for load_data" % (t1 - t0)) 39 | 40 | preds = model.predict(xgb_test) 41 | t1 = time.time() 42 | print("%.3fs taken for predicting" % (t1 - t0)) 43 | 44 | print("Saving results...") 45 | np.savetxt("./pred.csv", preds, delimiter=",") 46 | 47 | if __name__ == "__main__": 48 | train() 49 | predict() 50 | -------------------------------------------------------------------------------- /xgb-data/xgb_binary_logistic/xgb.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/xgb-data/xgb_binary_logistic/xgb.model -------------------------------------------------------------------------------- /xgb-data/xgb_binary_logitraw/xg.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import xgboost as xgb 3 | import numpy as np 4 | import time 5 | 6 | params = { 7 | 'booster': 'gbtree', 8 | 'objective': 'binary:logitraw', 9 | 'eta': 0.1, 10 | 'gamma': 1.0, 11 | 'max_depth': 3, 12 | 'min_child_weight': 1, 13 | 'seed': 1000, 14 | 'nthread': 1, 15 | } 16 | 17 | def train(): 18 | xgb_train = xgb.DMatrix("./agaricus.txt.train") 19 | plst = list(params.items()) 20 | print("Training started.") 21 | t0 = time.time() 22 | model = xgb.train(plst, xgb_train, num_boost_round=50, 23 | ) 24 | print("%.3fs taken for training" % (time.time() - t0)) 25 | print("Saving model...") 26 | model.save_model("xgb.model") 27 | 28 | def predict(): 29 | t0 = time.time() 30 | model = xgb.Booster() 31 | model.load_model("xgb.model") 32 | t1 = time.time() 33 | print("%.3fs taken for load_model" % (t1 - t0)) 34 | 35 | t0 = time.time() 36 | xgb_test = xgb.DMatrix("./agaricus.txt.test") 37 | t1 = time.time() 38 | print("%.3fs taken for load_data" % (t1 - t0)) 39 | 40 | t0 = time.time() 41 | preds = model.predict(xgb_test) 42 | t1 = time.time() 43 | print("%.3fs taken for predicting" % (t1 - t0)) 44 | 45 | print("Saving results...") 46 | np.savetxt("./pred.csv", preds, delimiter=",") 47 | 48 | 49 | if __name__ == "__main__": 50 | train() 51 | predict() 52 | -------------------------------------------------------------------------------- /xgb-data/xgb_binary_logitraw/xgb.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/xgb-data/xgb_binary_logitraw/xgb.model -------------------------------------------------------------------------------- /xgb-data/xgb_multi_softmax/dermatology.data.test: -------------------------------------------------------------------------------- 1 | 2,2,1,3,0,0,0,0,0,0,0,0,0,0,3,0,2,1,0,0,3,0,0,0,0,0,0,0,0,0,0,2,0,52,5 2 | 2,2,3,3,1,2,0,1,0,0,0,2,0,0,0,2,2,0,1,0,0,0,0,0,1,0,2,0,2,0,0,2,3,25,3 3 | 3,2,2,2,0,2,0,2,0,0,0,3,0,0,0,3,2,0,1,0,0,0,0,0,1,0,2,0,3,0,0,3,3,36,3 4 | 2,2,2,3,1,2,0,1,0,0,0,2,0,0,0,2,2,0,1,0,0,0,0,0,1,0,2,0,3,0,0,1,2,50,3 5 | 2,1,2,0,1,0,0,0,0,0,0,0,0,0,0,2,2,0,1,0,0,0,0,0,0,0,0,2,0,0,0,2,0,34,4 6 | 3,1,2,1,0,0,0,0,2,3,0,0,0,0,0,0,2,0,2,3,2,2,0,3,0,2,0,0,0,0,0,2,0,17,1 7 | 2,2,2,0,1,0,0,0,2,1,0,0,0,0,0,0,3,1,1,3,2,2,0,2,0,0,0,0,0,0,0,2,0,24,1 8 | 2,1,1,0,1,0,0,0,0,0,0,0,0,0,0,3,1,0,0,0,0,0,0,0,0,1,0,3,0,0,0,2,0,22,4 9 | 2,1,2,1,1,0,0,0,0,0,0,0,0,0,0,2,2,0,1,0,0,0,0,0,0,1,0,3,0,0,0,2,0,55,4 10 | 2,1,1,0,1,0,0,0,0,0,0,0,0,0,0,3,2,0,0,0,0,0,0,0,0,0,0,2,0,0,0,2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,0,0,0,2,0,0,0,3,2,0,0,0,0,0,0,0,3,0,2,0,1,0,0,2,3,50,3 67 | 3,2,2,0,0,0,0,0,3,3,0,0,0,1,0,0,2,0,2,3,2,3,0,2,0,2,0,0,0,0,0,3,0,35,1 68 | -------------------------------------------------------------------------------- /xgb-data/xgb_multi_softmax/pred.csv: -------------------------------------------------------------------------------- 1 | 4.000000000000000000e+00 2 | 2.000000000000000000e+00 3 | 2.000000000000000000e+00 4 | 2.000000000000000000e+00 5 | 3.000000000000000000e+00 6 | 0.000000000000000000e+00 7 | 0.000000000000000000e+00 8 | 3.000000000000000000e+00 9 | 3.000000000000000000e+00 10 | 3.000000000000000000e+00 11 | 0.000000000000000000e+00 12 | 0.000000000000000000e+00 13 | 0.000000000000000000e+00 14 | 2.000000000000000000e+00 15 | 2.000000000000000000e+00 16 | 2.000000000000000000e+00 17 | 2.000000000000000000e+00 18 | 2.000000000000000000e+00 19 | 0.000000000000000000e+00 20 | 0.000000000000000000e+00 21 | 0.000000000000000000e+00 22 | 0.000000000000000000e+00 23 | 3.000000000000000000e+00 24 | 3.000000000000000000e+00 25 | 0.000000000000000000e+00 26 | 0.000000000000000000e+00 27 | 3.000000000000000000e+00 28 | 2.000000000000000000e+00 29 | 2.000000000000000000e+00 30 | 1.000000000000000000e+00 31 | 0.000000000000000000e+00 32 | 0.000000000000000000e+00 33 | 3.000000000000000000e+00 34 | 3.000000000000000000e+00 35 | 4.000000000000000000e+00 36 | 4.000000000000000000e+00 37 | 0.000000000000000000e+00 38 | 0.000000000000000000e+00 39 | 4.000000000000000000e+00 40 | 4.000000000000000000e+00 41 | 2.000000000000000000e+00 42 | 0.000000000000000000e+00 43 | 4.000000000000000000e+00 44 | 4.000000000000000000e+00 45 | 5.000000000000000000e+00 46 | 5.000000000000000000e+00 47 | 3.000000000000000000e+00 48 | 1.000000000000000000e+00 49 | 5.000000000000000000e+00 50 | 5.000000000000000000e+00 51 | 5.000000000000000000e+00 52 | 0.000000000000000000e+00 53 | 0.000000000000000000e+00 54 | 0.000000000000000000e+00 55 | 4.000000000000000000e+00 56 | 4.000000000000000000e+00 57 | 0.000000000000000000e+00 58 | 0.000000000000000000e+00 59 | 0.000000000000000000e+00 60 | 0.000000000000000000e+00 61 | 1.000000000000000000e+00 62 | 1.000000000000000000e+00 63 | 3.000000000000000000e+00 64 | 3.000000000000000000e+00 65 | 2.000000000000000000e+00 66 | 2.000000000000000000e+00 67 | 0.000000000000000000e+00 68 | -------------------------------------------------------------------------------- /xgb-data/xgb_multi_softmax/xg.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import xgboost as xgb 3 | import numpy as np 4 | import time 5 | 6 | params = { 7 | 'booster': 'gbtree', 8 | 'objective': 'multi:softmax', 9 | 'eta': 0.1, 10 | 'max_depth': 6, 11 | 'num_class': 6, 12 | 'nthread': 1, 13 | } 14 | 15 | def train(): 16 | data = np.loadtxt('./dermatology.data.train', delimiter=',', 17 | converters={33: lambda x:int(x == '?'), 34: lambda x:int(x) - 1}) 18 | train_X = data[:, :33] 19 | train_Y = data[:, 34] 20 | 21 | xgb_train = xgb.DMatrix(train_X, label=train_Y) 22 | plst = list(params.items()) 23 | print("Training started.") 24 | t0 = time.time() 25 | model = xgb.train(plst, xgb_train, num_boost_round=50, 26 | ) 27 | print("%.3fs taken for training" % (time.time() - t0)) 28 | print("Saving model...") 29 | model.save_model("xgb.model") 30 | 31 | def predict(): 32 | t0 = time.time() 33 | model = xgb.Booster() 34 | model.load_model("xgb.model") 35 | t1 = time.time() 36 | print("%.3fs taken for load_model" % (t1 - t0)) 37 | 38 | t0 = time.time() 39 | data = np.loadtxt('./dermatology.data.test', delimiter=',', 40 | converters={33: lambda x:int(x == '?'), 34: lambda x:int(x) - 1}) 41 | test_X = data[:, :33] 42 | test_Y = data[:, 34] 43 | 44 | xgb_test = xgb.DMatrix(test_X, label=test_Y) 45 | t1 = time.time() 46 | print("%.3fs taken for load_data" % (t1 - t0)) 47 | 48 | t0 = time.time() 49 | preds = model.predict(xgb_test) 50 | t1 = time.time() 51 | print("%.3fs taken for predicting" % (t1 - t0)) 52 | 53 | print("Saving results...") 54 | np.savetxt("./pred.csv", preds, delimiter=",") 55 | 56 | 57 | if __name__ == "__main__": 58 | train() 59 | predict() 60 | -------------------------------------------------------------------------------- /xgb-data/xgb_multi_softmax/xgb.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/xgb-data/xgb_multi_softmax/xgb.model -------------------------------------------------------------------------------- /xgb-data/xgb_multi_softprob/dermatology.data.test: -------------------------------------------------------------------------------- 1 | 2,2,1,3,0,0,0,0,0,0,0,0,0,0,3,0,2,1,0,0,3,0,0,0,0,0,0,0,0,0,0,2,0,52,5 2 | 2,2,3,3,1,2,0,1,0,0,0,2,0,0,0,2,2,0,1,0,0,0,0,0,1,0,2,0,2,0,0,2,3,25,3 3 | 3,2,2,2,0,2,0,2,0,0,0,3,0,0,0,3,2,0,1,0,0,0,0,0,1,0,2,0,3,0,0,3,3,36,3 4 | 2,2,2,3,1,2,0,1,0,0,0,2,0,0,0,2,2,0,1,0,0,0,0,0,1,0,2,0,3,0,0,1,2,50,3 5 | 2,1,2,0,1,0,0,0,0,0,0,0,0,0,0,2,2,0,1,0,0,0,0,0,0,0,0,2,0,0,0,2,0,34,4 6 | 3,1,2,1,0,0,0,0,2,3,0,0,0,0,0,0,2,0,2,3,2,2,0,3,0,2,0,0,0,0,0,2,0,17,1 7 | 2,2,2,0,1,0,0,0,2,1,0,0,0,0,0,0,3,1,1,3,2,2,0,2,0,0,0,0,0,0,0,2,0,24,1 8 | 2,1,1,0,1,0,0,0,0,0,0,0,0,0,0,3,1,0,0,0,0,0,0,0,0,1,0,3,0,0,0,2,0,22,4 9 | 2,1,2,1,1,0,0,0,0,0,0,0,0,0,0,2,2,0,1,0,0,0,0,0,0,1,0,3,0,0,0,2,0,55,4 10 | 2,1,1,0,1,0,0,0,0,0,0,0,0,0,0,3,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0,0,2,3,28,3 66 | 2,1,3,1,2,3,0,2,0,0,0,2,0,0,0,3,2,0,0,0,0,0,0,0,3,0,2,0,1,0,0,2,3,50,3 67 | 3,2,2,0,0,0,0,0,3,3,0,0,0,1,0,0,2,0,2,3,2,3,0,2,0,2,0,0,0,0,0,3,0,35,1 68 | -------------------------------------------------------------------------------- /xgb-data/xgb_multi_softprob/xg.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import xgboost as xgb 3 | import numpy as np 4 | import time 5 | 6 | params = { 7 | 'booster': 'gbtree', 8 | 'objective': 'multi:softprob', 9 | 'eta': 0.1, 10 | 'max_depth': 6, 11 | 'num_class': 6, 12 | 'nthread': 1, 13 | } 14 | 15 | def train(): 16 | data = np.loadtxt('./dermatology.data.train', delimiter=',', 17 | converters={33: lambda x:int(x == '?'), 34: lambda x:int(x) - 1}) 18 | train_X = data[:, :33] 19 | train_Y = data[:, 34] 20 | 21 | xgb_train = xgb.DMatrix(train_X, label=train_Y) 22 | plst = list(params.items()) 23 | print("Training started.") 24 | t0 = time.time() 25 | model = xgb.train(plst, xgb_train, num_boost_round=5, 26 | ) 27 | print("%.3fs taken for training" % (time.time() - t0)) 28 | print("Saving model...") 29 | model.save_model("xgb.model") 30 | 31 | def predict(): 32 | t0 = time.time() 33 | model = xgb.Booster() 34 | model.load_model("xgb.model") 35 | t1 = time.time() 36 | print("%.3fs taken for load_model" % (t1 - t0)) 37 | 38 | t0 = time.time() 39 | data = np.loadtxt('./dermatology.data.test', delimiter=',', 40 | converters={33: lambda x:int(x == '?'), 34: lambda x:int(x) - 1}) 41 | test_X = data[:, :33] 42 | test_Y = data[:, 34] 43 | 44 | xgb_test = xgb.DMatrix(test_X, label=test_Y) 45 | t1 = time.time() 46 | print("%.3fs taken for load_data" % (t1 - t0)) 47 | 48 | t0 = time.time() 49 | preds = model.predict(xgb_test) 50 | t1 = time.time() 51 | print("%.3fs taken for predicting" % (t1 - t0)) 52 | 53 | print("Saving results...") 54 | np.savetxt("./pred.csv", preds, delimiter=",") 55 | 56 | 57 | if __name__ == "__main__": 58 | train() 59 | predict() 60 | -------------------------------------------------------------------------------- /xgb-data/xgb_multi_softprob/xgb.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/xgb-data/xgb_multi_softprob/xgb.model -------------------------------------------------------------------------------- /xgb-data/xgb_rank_pairwise/xgb.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/xgb-data/xgb_rank_pairwise/xgb.model -------------------------------------------------------------------------------- /xgb-data/xgb_reg_linear/machine.txt.test: -------------------------------------------------------------------------------- 1 | 489 0:23 1:16000 2:32000 3:64 4:16 5:32 7:1 2 | 138 0:50 1:4000 2:16000 3:65 4:1 5:8 9:1 3 | 61 0:143 1:2300 2:6200 3:0 4:6 5:64 11:1 4 | 27 0:320 1:256 2:3000 3:4 4:1 5:3 12:1 5 | 77 0:320 1:512 2:5000 3:4 4:1 5:5 12:1 6 | 27 0:320 1:256 2:5000 3:4 4:1 5:6 12:1 7 | 29 0:50 1:1000 2:4000 3:8 4:1 5:5 13:1 8 | 36 0:50 1:1000 2:8000 3:8 4:3 5:5 14:1 9 | 60 0:50 1:2000 2:16000 3:8 4:3 5:6 14:1 10 | 62 0:200 1:512 2:8000 3:8 4:1 5:8 15:1 11 | 36 0:200 1:1000 2:8000 3:0 4:1 5:2 16:1 12 | 60 0:110 1:1000 2:12000 3:16 4:1 5:2 16:1 13 | 71 0:220 1:1000 2:8000 3:16 4:1 5:2 16:1 14 | 144 0:75 1:2000 2:16000 3:64 4:1 5:38 19:1 15 | 259 0:75 1:2000 2:16000 3:128 4:1 5:38 19:1 16 | 26 0:105 1:256 2:2000 3:0 4:3 5:10 20:1 17 | 44 0:300 1:768 2:3000 3:6 4:6 5:24 21:1 18 | 36 0:300 1:192 2:768 3:6 4:6 5:24 21:1 19 | 66 0:140 1:2000 2:8000 3:32 4:1 5:54 22:1 20 | 277 0:26 1:8000 2:32000 3:0 4:8 5:24 23:1 21 | 45 0:115 1:512 2:6000 3:16 4:1 5:6 23:1 22 | 7 0:1100 1:512 2:1500 3:0 4:1 5:1 23:1 23 | 16 0:600 1:768 2:2000 3:0 4:1 5:1 23:1 24 | 32 0:400 1:2000 2:4000 3:0 4:1 5:1 23:1 25 | 32 0:400 1:4000 2:8000 3:0 4:1 5:1 23:1 26 | 100 0:17 1:4000 2:16000 3:8 4:6 5:12 23:1 27 | 45 0:50 1:2000 2:16000 3:12 4:3 5:16 25:1 28 | 60 0:92 1:2000 2:8000 3:32 4:1 5:6 27:1 29 | 86 0:60 1:4000 2:16000 3:32 4:1 5:6 27:1 30 | 93 0:60 1:4000 2:16000 3:64 4:5 5:8 27:1 31 | 111 0:50 1:4000 2:16000 3:64 4:5 5:10 27:1 32 | 105 0:72 1:2000 2:8000 3:16 4:6 5:8 27:1 33 | 140 0:38 1:8000 2:24000 3:160 4:4 5:8 28:1 34 | 25 0:200 1:1000 2:2000 3:0 4:1 5:2 29:1 35 | 30 0:200 1:1000 2:4000 3:0 4:1 5:4 29:1 36 | 307 0:50 1:2000 2:32000 3:112 4:52 5:104 33:1 37 | 1150 0:30 1:8000 2:64000 3:128 4:12 5:176 33:1 38 | 46 0:98 1:1000 2:8000 3:32 4:2 5:8 33:1 39 | 52 0:125 1:2000 2:8000 3:0 4:2 5:14 34:1 40 | 67 0:480 1:512 2:8000 3:32 4:0 5:0 35:1 41 | -------------------------------------------------------------------------------- /xgb-data/xgb_reg_linear/pred.csv: -------------------------------------------------------------------------------- 1 | 3.694624328613281250e+02 2 | 1.152264785766601562e+02 3 | 4.366616058349609375e+01 4 | 3.263910675048828125e+01 5 | 4.125198745727539062e+01 6 | 3.676187896728515625e+01 7 | 3.120022964477539062e+01 8 | 3.972547149658203125e+01 9 | 6.033256912231445312e+01 10 | 3.879360580444335938e+01 11 | 3.388624954223632812e+01 12 | 7.326078796386718750e+01 13 | 4.947885894775390625e+01 14 | 1.417399444580078125e+02 15 | 1.828303985595703125e+02 16 | 2.296177291870117188e+01 17 | 3.691416549682617188e+01 18 | 2.940616035461425781e+01 19 | 9.157737731933593750e+01 20 | 1.997601013183593750e+02 21 | 3.819830703735351562e+01 22 | 1.926759910583496094e+01 23 | 2.085104942321777344e+01 24 | 2.459629058837890625e+01 25 | 4.389839553833007812e+01 26 | 1.012913589477539062e+02 27 | 6.531851196289062500e+01 28 | 6.361949157714843750e+01 29 | 9.856855773925781250e+01 30 | 9.109255218505859375e+01 31 | 1.356136322021484375e+02 32 | 4.785631561279296875e+01 33 | 1.741499633789062500e+02 34 | 2.085104942321777344e+01 35 | 2.190690612792968750e+01 36 | 3.877758789062500000e+02 37 | 8.914226074218750000e+02 38 | 1.104216079711914062e+02 39 | 3.881540679931640625e+01 40 | 1.009904861450195312e+02 41 | -------------------------------------------------------------------------------- /xgb-data/xgb_reg_linear/xg.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import xgboost as xgb 3 | import numpy as np 4 | import time 5 | 6 | params = { 7 | 'booster': 'gbtree', 8 | 'objective': 'reg:linear', 9 | 'eta': 0.1, 10 | 'gamma': 1.0, 11 | 'max_depth': 4, 12 | 'min_child_weight': 1, 13 | 'seed': 1000, 14 | 'nthread': 1, 15 | } 16 | 17 | def train(): 18 | xgb_train = xgb.DMatrix("./machine.txt.train") 19 | plst = list(params.items()) 20 | print("Training started.") 21 | t0 = time.time() 22 | model = xgb.train(plst, xgb_train, num_boost_round=50, 23 | ) 24 | print("%.3fs taken for training" % (time.time() - t0)) 25 | print("Saving model...") 26 | model.save_model("xgb.model") 27 | 28 | def predict(): 29 | t0 = time.time() 30 | model = xgb.Booster() 31 | model.load_model("xgb.model") 32 | t1 = time.time() 33 | print("%.3fs taken for load_model" % (t1 - t0)) 34 | 35 | t0 = time.time() 36 | xgb_test = xgb.DMatrix("./machine.txt.test") 37 | t1 = time.time() 38 | print("%.3fs taken for load_data" % (t1 - t0)) 39 | 40 | t0 = time.time() 41 | preds = model.predict(xgb_test) 42 | t1 = time.time() 43 | print("%.3fs taken for predicting" % (t1 - t0)) 44 | 45 | print("Saving results...") 46 | np.savetxt("./pred.csv", preds, delimiter=",") 47 | 48 | 49 | if __name__ == "__main__": 50 | train() 51 | predict() 52 | -------------------------------------------------------------------------------- /xgb-data/xgb_reg_linear/xgb.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/xgb-data/xgb_reg_linear/xgb.model -------------------------------------------------------------------------------- /xgb-data/xgb_reg_logistic/xg.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import xgboost as xgb 3 | import numpy as np 4 | import time 5 | 6 | params = { 7 | 'booster': 'gbtree', 8 | 'objective': 'reg:logistic', 9 | 'eta': 0.1, 10 | 'gamma': 1.0, 11 | 'max_depth': 3, 12 | 'min_child_weight': 1, 13 | 'seed': 1000, 14 | 'nthread': 1, 15 | } 16 | 17 | def train(): 18 | xgb_train = xgb.DMatrix("./agaricus.txt.train") 19 | plst = list(params.items()) 20 | print("Training started.") 21 | t0 = time.time() 22 | model = xgb.train(plst, xgb_train, num_boost_round=50, 23 | ) 24 | print("%.3fs taken for training" % (time.time() - t0)) 25 | print("Saving model...") 26 | model.save_model("xgb.model") 27 | 28 | def predict(): 29 | t0 = time.time() 30 | model = xgb.Booster() 31 | model.load_model("xgb.model") 32 | t1 = time.time() 33 | print("%.3fs taken for load_model" % (t1 - t0)) 34 | 35 | t0 = time.time() 36 | xgb_test = xgb.DMatrix("./agaricus.txt.test") 37 | t1 = time.time() 38 | print("%.3fs taken for load_data" % (t1 - t0)) 39 | 40 | t0 = time.time() 41 | preds = model.predict(xgb_test) 42 | t1 = time.time() 43 | print("%.3fs taken for predicting" % (t1 - t0)) 44 | 45 | print("Saving results...") 46 | np.savetxt("./pred.csv", preds, delimiter=",") 47 | 48 | 49 | if __name__ == "__main__": 50 | train() 51 | predict() 52 | -------------------------------------------------------------------------------- /xgb-data/xgb_reg_logistic/xgb.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mesalock-linux/gbdt-rs/594194af697ca10b6f83cf514536bc992d476b9b/xgb-data/xgb_reg_logistic/xgb.model --------------------------------------------------------------------------------