added project template for easier use
diff --git a/samplecode/project_template/Makefile b/samplecode/project_template/Makefile
new file mode 100644
index 0000000..1955bdd
--- /dev/null
+++ b/samplecode/project_template/Makefile
@@ -0,0 +1,46 @@
+# Dummy makefile, will call the host and enclave makefile when requested.
+
+SRC_U = app/
+SRC_T = enclave/
+
+# Compilation process, will call the appropriate makefiles.
+
+all: host enclave
+
+host:
+	@echo "\033[32mRequest to compile the host part...\033[0m"
+	@make -C $(SRC_U)
+
+enclave:
+	@echo "\033[32mRequest to compile the enclave part...\033[0m"
+	@make -C $(SRC_T)
+
+clean:
+	@make -C $(SRC_U) clean
+	@make -C $(SRC_T) clean
+
+fclean:
+	@make -C $(SRC_U) fclean
+	@make -C $(SRC_T) fclean
+
+clean_host:
+	@make -C $(SRC_U) clean
+
+clean_enclave:
+	@make -C $(SRC_T) clean
+
+fclean_host:
+	@make -C $(SRC_U) fclean
+
+fclean_enclave:
+	@make -C $(SRC_T) fclean
+
+re_host: fclean_host host
+
+re_enclave: fclean_enclave enclave
+
+re: fclean all
+
+# Dummy rules to let make know that those rules are not files.
+
+.PHONY: host enclave clean clean_host clean_enclave fclean_host fclean_enclave fclean re re_host re_enclave
\ No newline at end of file
diff --git a/samplecode/project_template/README.md b/samplecode/project_template/README.md
new file mode 100644
index 0000000..25a8537
--- /dev/null
+++ b/samplecode/project_template/README.md
@@ -0,0 +1,70 @@
+# Rust SGX - Template project
+==================================
+
+### This is a template project to start developing with the Teaenclave Rust SGX SDK (https://github.com/apache/incubator-teaclave-sgx-sdk/) easily.
+
+You will find in its template:
+- Makefiles to build your project easily, and link the ```SGX EDL C``` generated files to your Rust SGX projects
+- The file ```buildenv.mk``` that contains compilation rules when building enclave. No need to specify anymore where this file is located.
+- The file ```build.rs``` already configured to build the app/host part properly.
+- The file rust-toolchain, so we can force the use of one specific toolchain (```nightly-2020-10-25``` in this case)
+- ```Cargo/Xargo.toml``` files to set up your project easily. All the dependencies you might need has been added.
+
+You can find those files in this template: 
+
+```
+|-- app/
+|   |-- src/
+|       |-- main.rs
+|   |-- Cargo.toml
+|   |-- Makefile
+|   |-- build.rs
+|   +-- rust-toolchain
+|-- enclave/
+|   |-- src/
+|       |-- lib.rs
+|   |-- Cargo.toml
+|   |-- Enclave.config.xml
+|   |-- Enclave.edl
+|   |-- Enclave.lds
+|   |-- Makefile
+|   |-- Xargo.toml
+|   +-- rust-toolchain
+|-- Makefile
++-- buildenv.mk
+```
+
+## Setting up your project
+
+You need to follow a few steps to use this template properly:
+- Add your ```.rs``` files to the ```src/``` folders (```lib.rs``` / your enclave source code goes in ```enclave/src```, your host/app source code goes in ```app/src```), or modify the ```.rs``` files already included with the project
+- Add your own ```Enclave.edl``` file, or modify the one joined in the project.
+- Change the ```Cargo.toml (or/and Xargo.toml if you want to use Xargo)``` files depending of your needs (adding/removing dependences). 
+    - Be careful if you want to change the library name on the ```Cargo.toml``` file (enclave part), you will need to reflect this change on the enclave ```Makefile```, more specifically on the ```ENCLAVE_CARGO_LIB``` variable, and on the ```lib.rs``` file.
+    - If you need to change the app/host name, please make sure to edit the host ```Makefile```, and change the variable ```APP_U```.
+
+## Build your project
+
+### Before starting the building process, please make sure you downloaded the Rust SGX SDK repository, we're going to need the EDL and headers files joined in the SDK.
+
+Once you downloaded the Rust SGX SDK, you have multiple ways to start the building process: 
+- Run this command: ```CUSTOM_EDL_PATH=~/teaenclave/edl CUSTOM_COMMON_PATH=~/teaenclave/common make``` (replace ```~/teaenclave``` by the actual SDK location)
+- You can also run the command export (```export CUSTOM_EDL_PATH=~/teaenclave/edl```), and specify the variables before calling make. It is adviced to add this command on your ```.bashrc``` file (if you use bash), or your favorite shell configuration file.
+
+### By default, your project will be compiled in hardware mode. If you wish to compile your project in software/simulation mode, you will need to specify it, either by adding ```SGX_MODE=SW``` before make, or by setting the SGX_MODE variable environment to SW.
+
+### Cargo is used by default when compiling, but you can also use Xargo either by adding ```XARGO_SGX=1``` before make, or by setting the XARGO_SGX variable environment to 1. You will also need to specify Xargo library path with XARGO_PATH.
+
+### The makefile has those commands available: 
+- make (will compile everything)
+- make host (will only compile the host part)
+- make enclave (will only compile the enclave part)
+- make clean (will clean the objects/C edl files generated)
+- make clean_host (will clean the objects/C edl files generated for the host only)
+- make clean_enclave (will clean the objects/C edl files generated for the enclave only)
+- make fclean (will clean objects/C edl files and the binairies, plus calling cargo clean for everything)
+- make fclean_host (will clean objects/C edl files and the binairies, plus calling cargo clean for the host only)
+- make fclean_enclave (will clean objects/C edl files and the binairies, plus calling cargo clean for the enclave only)
+- make re (re as relink, will clean everything then compile everything again)
+- make re_host (re as relink, will clean the host part then compile it again)
+- make re_enclave (re as relink, will clean the enclave part then compile it again)
\ No newline at end of file
diff --git a/samplecode/project_template/app/Cargo.toml b/samplecode/project_template/app/Cargo.toml
new file mode 100644
index 0000000..21f712a
--- /dev/null
+++ b/samplecode/project_template/app/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "app"
+version = "1.0.0"
+authors = ["Teaclave"]
+build = "build.rs"
+
+[dependencies] # You can specify the features you need for urts, such as global_exit and global_init
+sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+sgx_urts = { git = "https://github.com/apache/teaclave-sgx-sdk.git"}
+
+[patch.'https://github.com/apache/teaclave-sgx-sdk.git']
\ No newline at end of file
diff --git a/samplecode/project_template/app/Makefile b/samplecode/project_template/app/Makefile
new file mode 100644
index 0000000..fab6a6c
--- /dev/null
+++ b/samplecode/project_template/app/Makefile
@@ -0,0 +1,124 @@
+# Makefile settings - Host part
+
+LIB = ../lib/
+BIN = ../bin/
+SRC_RST = ./src/
+APP_U = app
+APP_T = enclave.so
+NAME_U = libEnclave_u.a
+SRC_U = ./
+SRC_T = ../enclave/
+OBJ_U = ../obj/
+SGX_SDK = /opt/sgxsdk
+FLAGS = -Wall -Wextra
+GCC_STEP1_U = -I $(SRC_U) -I./include -I$(SGX_SDK)/include -I$(CUSTOM_EDL_PATH) -fPIC -Wno-attributes $(SGX_COMMON_CFLAGS)
+FILES_U = Enclave_u.c 
+FILES_U_H = Enclave_u.h
+BUILD_RS = build.rs
+TOML = Cargo.toml 
+SGX_ARCH = x64
+SGX_SDK = /opt/sgxsdk
+TRTS_LIB = sgx_trts
+SERVICE_LIB = sgx_tservice
+# Addprefix dependant variables, no need to change those
+OUTPUT_U = $(FILES_U:.c=.o)
+BIN_U = $(addprefix $(BIN), $(APP_U))
+NAME_U_D = $(addprefix $(LIB), $(NAME_U))
+FILES_U_F=$(addprefix $(SRC_U), $(FILES_U))
+OUTPUT_W_FU=$(addprefix $(OBJ_U), $(OUTPUT_U))
+FILES_RUST_F= $(wildcard $(SRC_RST)*.rs) # Wildcare function used, no need to specify the rust files. Safe as we don't compile the rust files with the makefile.
+
+# Contains compilation rules for the enclave part
+
+include ../buildenv.mk
+
+# Custom librairies, EDL paths. Needs to be specified with make (CUSTOM_EDL_PATH) (CUSTOM_COMMON_PATH)
+
+# Directly imported from the original Intel SGX samples, helpful to detect the system architecture
+
+ifeq ($(shell getconf LONG_BIT), 32)
+	SGX_ARCH := x86
+else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32)
+	SGX_ARCH := x86
+endif
+
+ifeq ($(SGX_ARCH), x86)
+	SGX_COMMON_CFLAGS := -m32
+	SGX_LIBRARY_PATH := $(SGX_SDK)/lib
+	SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign
+	SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r
+else
+	SGX_COMMON_CFLAGS := -m64
+	SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
+	SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign
+	SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r
+endif
+
+# If specified, software / simulation mode. Otherwise, hardware mode no matter what.
+
+ifeq ($(SGX_MODE), SW)
+	TRTS_LIB := sgx_trts_sim
+	SERVICE_LIB := sgx_tservice_sim
+endif
+
+# If debug mode, we can set up extra options such as the debug flags
+
+ifeq ($(SGX_DEBUG), 1)
+	SGX_COMMON_CFLAGS += -O0 -g
+else
+	SGX_COMMON_CFLAGS += -O2
+endif
+
+# Compilation process, we set up all the dependencies needed to have the correct order of build, and avoid relink
+
+all: $(BIN_U)
+
+$(FILES_U_F): $(SGX_EDGER8R) $(SRC_T)/Enclave.edl
+	@echo "\033[32mGenerating untrusted SGX C edl files...\033[0m"
+	@$(SGX_EDGER8R) --untrusted $(SRC_T)/Enclave.edl --search-path $(SGX_SDK)/include --search-path $(CUSTOM_EDL_PATH) --untrusted-dir $(SRC_U)
+
+$(NAME_U_D): $(FILES_U_F) $(OUTPUT_W_FU)
+	@echo "\033[32mBuilding untrusted C edl static library...\033[0m"
+	@mkdir -p $(LIB)
+	@$(AR) rcsD $@ $(OUTPUT_W_FU)
+
+$(OBJ_U)%.o:$(SRC_U)%.c
+	@mkdir -p $(OBJ_U)
+	@echo "\033[32m$?: Build in progress...\033[0m"
+	@$(CC) $(FLAGS) $(GCC_STEP1_U) -o $@ -c $?
+
+# We print the compilation mode we're in (hardware/software mode), just as a reminder.
+
+$(BIN_U): $(NAME_U_D) $(FILES_RUST_F) $(FILES_U_H) $(BUILD_RS) $(TOML) # We added as a reference the rust files, along with the build.rs file and the cargo.toml file, so Make can detect if any change was made
+ifeq ($(SGX_MODE), SW)
+	@echo "\033[32mSoftware / Simulation mode\033[0m"
+else
+	@echo "\033[32mHardware mode\033[0m"
+endif
+	@echo "\033[32mStarting cargo to build the host...\033[0m"
+	@cd $(SRC_U) && SGX_SDK=$(SGX_SDK) cargo build --release
+	@echo "\033[32mCopying the host to the correct location... ($(BIN_U))\033[0m"
+	@mkdir -p $(BIN)
+	@cp $(SRC_U)/target/release/app $(BIN)
+
+clean: c_clean
+	@rm -rf $(OBJ_U)
+	@echo "\033[32mObject files deleted\033[0m"
+
+fclean: clean fclean_host
+
+fclean_host:
+	@echo "\033[32mBinary file $(BIN_U) deleted\033[0m"
+	@rm -f $(BIN_U)
+	@rm -f $(NAME_U_D)
+	@cargo clean && rm -f Cargo.lock
+
+
+c_clean:
+	@echo "\033[32mC edl generated files deleted\033[0m"
+	@rm -rf $(FILES_U_F)
+	@rm -rf $(FILES_U_H)
+
+re: fclean all
+
+.PHONY: all clean c_clean fclean re fclean_host
\ No newline at end of file
diff --git a/samplecode/project_template/app/build.rs b/samplecode/project_template/app/build.rs
new file mode 100644
index 0000000..65a322e
--- /dev/null
+++ b/samplecode/project_template/app/build.rs
@@ -0,0 +1,36 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License..
+
+use std::env;
+
+fn main () {
+
+    let sdk_dir = env::var("SGX_SDK")
+                    .unwrap_or_else(|_| "/opt/sgxsdk".to_string());
+    let is_sim = env::var("SGX_MODE")
+                    .unwrap_or_else(|_| "HW".to_string());
+
+    println!("cargo:rustc-link-search=native=../lib");
+    println!("cargo:rustc-link-lib=static=Enclave_u");
+
+    println!("cargo:rustc-link-search=native={}/lib64", sdk_dir);
+    match is_sim.as_ref() {
+        "SW" => println!("cargo:rustc-link-lib=dylib=sgx_urts_sim"),
+        "HW" => println!("cargo:rustc-link-lib=dylib=sgx_urts"),
+        _    => println!("cargo:rustc-link-lib=dylib=sgx_urts"), // Treat undefined as HW
+    }
+}
diff --git a/samplecode/project_template/app/rust-toolchain b/samplecode/project_template/app/rust-toolchain
new file mode 100644
index 0000000..e966e30
--- /dev/null
+++ b/samplecode/project_template/app/rust-toolchain
@@ -0,0 +1 @@
+nightly-2020-10-25
\ No newline at end of file
diff --git a/samplecode/project_template/app/src/main.rs b/samplecode/project_template/app/src/main.rs
new file mode 100644
index 0000000..51de899
--- /dev/null
+++ b/samplecode/project_template/app/src/main.rs
@@ -0,0 +1,80 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License..
+
+extern crate sgx_types;
+extern crate sgx_urts;
+use sgx_types::*;
+use sgx_urts::SgxEnclave;
+
+static ENCLAVE_FILE: &'static str = "enclave.signed.so";
+
+extern {
+    fn ecall_test(eid: sgx_enclave_id_t, retval: *mut sgx_status_t,
+                     some_string: *const u8, len: usize) -> sgx_status_t;
+}
+
+fn init_enclave() -> SgxResult<SgxEnclave> {
+
+    let mut launch_token: sgx_launch_token_t = [0; 1024];
+    let mut launch_token_updated: i32 = 0;
+    // call sgx_create_enclave to initialize an enclave instance
+    // Debug Support: set 2nd parameter to 1
+    let debug = 1;
+    let mut misc_attr = sgx_misc_attribute_t {secs_attr: sgx_attributes_t { flags:0, xfrm:0}, misc_select:0};
+    SgxEnclave::create(ENCLAVE_FILE,
+                       debug,
+                       &mut launch_token,
+                       &mut launch_token_updated,
+                       &mut misc_attr)
+}
+
+fn main() {
+
+    let enclave = match init_enclave() {
+        Ok(r) => {
+            println!("[+] Init Enclave Successful {}!", r.geteid());
+            r
+        },
+        Err(x) => {
+            println!("[-] Init Enclave Failed {}!", x.as_str());
+            return;
+        },
+    };
+
+    let input_string = String::from("Sending this string to the enclave then printing it\n");
+
+    let mut retval = sgx_status_t::SGX_SUCCESS;
+
+    let result = unsafe {
+        ecall_test(enclave.geteid(),
+                      &mut retval,
+                      input_string.as_ptr() as * const u8,
+                      input_string.len())
+    };
+
+    match result {
+        sgx_status_t::SGX_SUCCESS => {},
+        _ => {
+            println!("[-] ECALL Enclave Failed {}!", result.as_str());
+            return;
+        }
+    }
+
+    println!("[+] ecall_test success...");
+
+    enclave.destroy();
+}
diff --git a/samplecode/project_template/buildenv.mk b/samplecode/project_template/buildenv.mk
new file mode 100644
index 0000000..a86675e
--- /dev/null
+++ b/samplecode/project_template/buildenv.mk
@@ -0,0 +1,167 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License..
+#
+#
+
+CP    := /bin/cp -f
+MKDIR := mkdir -p
+STRIP := strip
+OBJCOPY := objcopy
+
+# clean the content of 'INCLUDE' - this variable will be set by vcvars32.bat
+# thus it will cause build error when this variable is used by our Makefile,
+# when compiling the code under Cygwin tainted by MSVC environment settings.
+INCLUDE :=
+
+# turn on stack protector for SDK
+COMMON_FLAGS += -fstack-protector
+
+ifdef DEBUG
+    COMMON_FLAGS += -O0 -g -DDEBUG -UNDEBUG
+else
+    COMMON_FLAGS += -O2 -D_FORTIFY_SOURCE=2 -UDEBUG -DNDEBUG
+endif
+
+# turn on compiler warnings as much as possible
+COMMON_FLAGS += -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type \
+		-Waddress -Wsequence-point -Wformat-security \
+		-Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow \
+		-Wcast-align -Wconversion -Wredundant-decls
+
+# additional warnings flags for C
+CFLAGS += -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants
+
+# additional warnings flags for C++
+CXXFLAGS += -Wnon-virtual-dtor
+
+# for static_assert()
+CXXFLAGS += -std=c++0x
+
+.DEFAULT_GOAL := all
+# this turns off the RCS / SCCS implicit rules of GNU Make
+% : RCS/%,v
+% : RCS/%
+% : %,v
+% : s.%
+% : SCCS/s.%
+
+# If a rule fails, delete $@.
+.DELETE_ON_ERROR:
+
+HOST_FILE_PROGRAM := file
+
+UNAME := $(shell uname -m)
+ifneq (,$(findstring 86,$(UNAME)))
+    HOST_ARCH := x86
+    ifneq (,$(shell $(HOST_FILE_PROGRAM) -L $(SHELL) | grep 'x86[_-]64'))
+        HOST_ARCH := x86_64
+    endif
+else
+    $(info Unknown host CPU arhitecture $(UNAME))
+    $(error Aborting)
+endif
+
+
+ifeq "$(findstring __INTEL_COMPILER, $(shell $(CC) -E -dM -xc /dev/null))" "__INTEL_COMPILER"
+  ifeq ($(shell test -f /usr/bin/dpkg; echo $$?), 0)
+    ADDED_INC := -I /usr/include/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)
+  endif
+endif
+
+ARCH := $(HOST_ARCH)
+ifeq "$(findstring -m32, $(CXXFLAGS))" "-m32"
+  ARCH := x86
+endif
+
+ifeq ($(ARCH), x86)
+COMMON_FLAGS += -DITT_ARCH_IA32
+else
+COMMON_FLAGS += -DITT_ARCH_IA64
+endif
+
+CFLAGS   += $(COMMON_FLAGS)
+CXXFLAGS += $(COMMON_FLAGS)
+
+# Enable the security flags
+COMMON_LDFLAGS := -Wl,-z,relro,-z,now,-z,noexecstack
+
+# mitigation options
+MITIGATION_INDIRECT ?= 0
+MITIGATION_RET ?= 0
+MITIGATION_C ?= 0
+MITIGATION_ASM ?= 0
+MITIGATION_AFTERLOAD ?= 0
+MITIGATION_LIB_PATH :=
+
+ifeq ($(MITIGATION-CVE-2020-0551), LOAD)
+    MITIGATION_C := 1
+    MITIGATION_ASM := 1
+    MITIGATION_INDIRECT := 1
+    MITIGATION_RET := 1
+    MITIGATION_AFTERLOAD := 1
+    MITIGATION_LIB_PATH := cve_2020_0551_load
+else ifeq ($(MITIGATION-CVE-2020-0551), CF)
+    MITIGATION_C := 1
+    MITIGATION_ASM := 1
+    MITIGATION_INDIRECT := 1
+    MITIGATION_RET := 1
+    MITIGATION_AFTERLOAD := 0
+    MITIGATION_LIB_PATH := cve_2020_0551_cf
+endif
+
+MITIGATION_CFLAGS :=
+MITIGATION_ASFLAGS :=
+ifeq ($(MITIGATION_C), 1)
+ifeq ($(MITIGATION_INDIRECT), 1)
+    MITIGATION_CFLAGS += -mindirect-branch-register
+endif
+ifeq ($(MITIGATION_RET), 1)
+    MITIGATION_CFLAGS += -mfunction-return=thunk-extern
+endif
+endif
+
+ifeq ($(MITIGATION_ASM), 1)
+    MITIGATION_ASFLAGS += -fno-plt
+ifeq ($(MITIGATION_AFTERLOAD), 1)
+    MITIGATION_ASFLAGS += -Wa,-mlfence-after-load=yes
+else
+    MITIGATION_ASFLAGS += -Wa,-mlfence-before-indirect-branch=register
+endif
+ifeq ($(MITIGATION_RET), 1)
+    MITIGATION_ASFLAGS += -Wa,-mlfence-before-ret=not
+endif
+endif
+
+MITIGATION_CFLAGS += $(MITIGATION_ASFLAGS)
+
+# Compiler and linker options for an Enclave
+#
+# We are using '--export-dynamic' so that `g_global_data_sim' etc.
+# will be exported to dynamic symbol table.
+#
+# When `pie' is enabled, the linker (both BFD and Gold) under Ubuntu 14.04
+# will hide all symbols from dynamic symbol table even if they are marked
+# as `global' in the LD version script.
+ENCLAVE_CFLAGS   = -ffreestanding -nostdinc -fvisibility=hidden -fpie -fno-strict-overflow -fno-delete-null-pointer-checks
+ENCLAVE_CXXFLAGS = $(ENCLAVE_CFLAGS) -nostdinc++
+ENCLAVE_LDFLAGS  = $(COMMON_LDFLAGS) -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
+                   -Wl,-pie,-eenclave_entry -Wl,--export-dynamic  \
+                   -Wl,--gc-sections \
+                   -Wl,--defsym,__ImageBase=0
+
+ENCLAVE_CFLAGS += $(MITIGATION_CFLAGS)
+ENCLAVE_ASFLAGS = $(MITIGATION_ASFLAGS)
\ No newline at end of file
diff --git a/samplecode/project_template/enclave/Cargo.toml b/samplecode/project_template/enclave/Cargo.toml
new file mode 100644
index 0000000..441e90e
--- /dev/null
+++ b/samplecode/project_template/enclave/Cargo.toml
@@ -0,0 +1,23 @@
+[package]
+name = "template"
+version = "1.0.0"
+authors = ["The Teaclave Authors"]
+
+[lib]
+name = "sample" # Library name. If you change this, please reflect those changes in the Makefile on the variable ENCLAVE_CARGO_LIB
+crate-type = ["staticlib"] 
+
+[features]
+default = []
+
+[target.'cfg(not(target_env = "sgx"))'.dependencies] # You can remove what you don't need, except types and tstd
+sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+sgx_tstd = { git = "https://github.com/apache/teaclave-sgx-sdk.git", features = ["backtrace"] }
+sgx_tcrypto = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+sgx_trts = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+sgx_tseal = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+sgx_serialize = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+sgx_alloc = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+sgx_libc = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
+
+[patch.'https://github.com/apache/teaclave-sgx-sdk.git']
\ No newline at end of file
diff --git a/samplecode/project_template/enclave/Enclave.config.xml b/samplecode/project_template/enclave/Enclave.config.xml
new file mode 100644
index 0000000..ee4c3f7
--- /dev/null
+++ b/samplecode/project_template/enclave/Enclave.config.xml
@@ -0,0 +1,12 @@
+<!-- Please refer to User's Guide for the explanation of each field -->
+<EnclaveConfiguration>
+  <ProdID>0</ProdID>
+  <ISVSVN>0</ISVSVN>
+  <StackMaxSize>0x40000</StackMaxSize>
+  <HeapMaxSize>0x100000</HeapMaxSize>
+  <TCSNum>1</TCSNum>
+  <TCSPolicy>1</TCSPolicy>
+  <DisableDebug>0</DisableDebug>
+  <MiscSelect>0</MiscSelect>
+  <MiscMask>0xFFFFFFFF</MiscMask>
+</EnclaveConfiguration>
diff --git a/samplecode/project_template/enclave/Enclave.edl b/samplecode/project_template/enclave/Enclave.edl
new file mode 100644
index 0000000..e476b1e
--- /dev/null
+++ b/samplecode/project_template/enclave/Enclave.edl
@@ -0,0 +1,34 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+/* This is your enclave EDL file, please specify the EDL files you need and ECALLs/OCALLs needed */
+
+enclave {
+    from "sgx_tstd.edl" import *;
+    from "sgx_stdio.edl" import *;
+    from "sgx_backtrace.edl" import *;
+    from "sgx_tstdc.edl" import *;
+    trusted
+    {
+        /* ECALLs */
+        public sgx_status_t ecall_test([in, size=len] const uint8_t* some_string, size_t len);
+    };
+    untrusted
+    {
+        /* OCALLs */
+    };
+};
diff --git a/samplecode/project_template/enclave/Enclave.lds b/samplecode/project_template/enclave/Enclave.lds
new file mode 100644
index 0000000..e3d9d0e
--- /dev/null
+++ b/samplecode/project_template/enclave/Enclave.lds
@@ -0,0 +1,9 @@
+enclave.so
+{
+    global:
+        g_global_data_sim;
+        g_global_data;
+        enclave_entry;
+    local:
+        *;
+};
diff --git a/samplecode/project_template/enclave/Makefile b/samplecode/project_template/enclave/Makefile
new file mode 100644
index 0000000..4ef0ca2
--- /dev/null
+++ b/samplecode/project_template/enclave/Makefile
@@ -0,0 +1,152 @@
+# Makefile settings
+
+APP_T_SIGNED = enclave.signed.so
+LIB = ../lib/
+BIN = ../bin/
+SRC_RST = ./src/
+APP_T = enclave.so
+NAME_T = libenclave.a
+SRC_U = ../app/
+SRC_T = ./
+OBJ_T = ../obj/
+SGX_SDK = /opt/sgxsdk
+FLAGS = -Wall -Wextra
+GCC_STEP1_T = -fstack-protector -I$(CUSTOM_COMMON_PATH)/inc -I$(CUSTOM_EDL_PATH) -I$(SGX_SDK)/include \
+	-I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I$(SGX_SDK)/include/epid -I $(SRC_T) \
+	-L$(LIB) $(ENCLAVE_CFLAGS) $(SGX_COMMON_CFLAGS)
+GCC_STEP2_T = -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
+	-Wl,--whole-archive -l$(TRTS_LIB) -Wl,--no-whole-archive \
+	-Wl,--start-group -lsgx_tstdc -l$(SERVICE_LIB) -lsgx_tcrypto -L$(LIB) -lenclave -Wl,--end-group \
+	-Wl,--version-script=$(SRC_T)Enclave.lds $(ENCLAVE_LDFLAGS)
+FILES_T = Enclave_t.c 
+FILES_T_H = Enclave_t.h
+EDL_FILE = Enclave.edl
+TOML = Cargo.toml
+ENCLAVE_CONFIG = Enclave.config.xml
+SGX_ARCH = x64
+SGX_SDK = /opt/sgxsdk
+TRTS_LIB = sgx_trts
+SERVICE_LIB = sgx_tservice
+ENCLAVE_CARGO_LIB=libsample.a # This is the name of the enclave static library compiled by Cargo/Xargo. You will have to change it, depending of your project.
+# Addprefix dependant variables, no need to change those
+OUTPUT_T = $(FILES_T:.c=.o)
+NAME = $(addprefix $(BIN), $(APP_T_SIGNED))
+BIN_T = $(addprefix $(BIN), $(APP_T))
+NAME_T_D = $(addprefix $(LIB), $(NAME_T))
+OUTPUT_W_FU=$(addprefix $(OBJ_U), $(OUTPUT_U))
+FILES_T_F=$(addprefix $(SRC_T), $(FILES_T))
+FILES_T_F_RUST=$(addprefix $(SRC_T), $(FILES_T_RUST))
+OUTPUT_W_FT=$(addprefix $(OBJ_T), $(OUTPUT_T))
+FILES_RUST_F= $(wildcard $(SRC_RST)*.rs) # Wildcare function used, no need to specify the rust files. Safe as we don't compile the rust files with the makefile.
+
+# Contains compilation rules for the enclave part
+
+include ../buildenv.mk
+
+# Custom header files and EDL paths needs to be specified with make (CUSTOM_EDL_PATH) (CUSTOM_COMMON_PATH) Same goes for Xargo location (XARGO_PATH)
+
+# Directly imported from the original Intel SGX samples, helpful to detect the system architecture
+
+ifeq ($(shell getconf LONG_BIT), 32)
+	SGX_ARCH := x86
+else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32)
+	SGX_ARCH := x86
+endif
+
+ifeq ($(SGX_ARCH), x86)
+	SGX_COMMON_CFLAGS := -m32
+	SGX_LIBRARY_PATH := $(SGX_SDK)/lib
+	SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign
+	SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r
+else
+	SGX_COMMON_CFLAGS := -m64
+	SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
+	SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign
+	SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r
+endif
+
+ifeq ($(MITIGATION-CVE-2020-0551), LOAD)
+export MITIGATION_CVE_2020_0551=LOAD
+else ifeq ($(MITIGATION-CVE-2020-0551), CF)
+export MITIGATION_CVE_2020_0551=CF
+endif
+
+
+# If specified, software / simulation mode. Otherwise, hardware mode no matter what.
+
+ifeq ($(SGX_MODE), SW)
+	TRTS_LIB := sgx_trts_sim
+	SERVICE_LIB := sgx_tservice_sim
+endif
+
+# If debug mode, we can set up extra options such as the debug flags
+
+ifeq ($(SGX_DEBUG), 1)
+	SGX_COMMON_CFLAGS += -O0 -g
+else
+	SGX_COMMON_CFLAGS += -O2
+endif
+
+# Compilation process, we set up all the dependencies needed to have the correct order of build, and avoid relink
+
+all: $(NAME)
+
+# We print the compilation mode we're in (hardware/software mode), just as a reminder.
+
+$(NAME): $(BIN_T)
+ifeq ($(SGX_MODE), SW)
+	@echo "\033[32mSoftware / Simulation mode\033[0m"
+else
+	@echo "\033[32mHardware mode\033[0m"
+endif
+	@echo "\033[32mGenerating keys and signing the enclave...\033[0m"
+	@mkdir -p $(BIN)
+	@openssl genrsa -out Enclave_private.pem -3 3072
+	@openssl rsa -in Enclave_private.pem -pubout -out Enclave_public.pem
+	@$(SGX_ENCLAVE_SIGNER) sign -key $(SRC_T)Enclave_private.pem -enclave $(BIN_T) -out $@ -config $(SRC_T)Enclave.config.xml
+
+$(BIN_T): $(NAME_T_D)
+	@echo "\033[32mBuilding the enclave...\033[0m"
+	@$(CXX) $(OUTPUT_W_FT) -o $@ $(GCC_STEP2_T) 
+
+$(NAME_T_D): $(FILES_T_F) $(OUTPUT_W_FT) $(FILES_RUST_F) $(EDL_FILE) $(ENCLAVE_CONFIG) $(TOML) # We added as a reference the rust files, along with the EDL, the XML config file and the cargo.toml file, so Make can detect if any change was made
+ifeq ($(XARGO_SGX), 1) # Building with Xargo
+	@echo "\033[32mBuilding enclave static library with Xargo...\033[0m"
+	RUST_TARGET_PATH=$(XARGO_PATH) xargo build --target x86_64-unknown-linux-sgx --release
+	@cp ./target/x86_64-unknown-linux-sgx/release/$(ENCLAVE_CARGO_LIB) $(LIB)libenclave.a
+else
+	@echo "\033[32mBuilding enclave static library with Cargo...\033[0m"
+	@cargo build --release
+	@cp ./target/release/$(ENCLAVE_CARGO_LIB) $(LIB)libenclave.a
+endif
+
+$(FILES_T_F): $(SGX_EDGER8R) $(SRC_T)/Enclave.edl
+	@echo "\033[32mGenerating trusted SGX C edl files...\033[0m"
+	@$(SGX_EDGER8R) --trusted $(SRC_T)/Enclave.edl --search-path $(SGX_SDK)/include --search-path $(CUSTOM_EDL_PATH) --trusted-dir $(SRC_T)
+
+$(OBJ_T)%.o:$(SRC_T)%.c
+	@mkdir -p $(OBJ_T)
+	@echo "\033[32m$?: Build in progress...\033[0m"
+	@$(CC) $(FLAGS) $(GCC_STEP1_T) -o $@ -c $?
+
+clean: c_clean
+	@rm -rf $(OBJ_T)
+	@echo "\033[32mObject files deleted\033[0m"
+
+fclean: clean fclean_enclave
+
+fclean_enclave: 
+	@echo "\033[32mBinary file $(NAME) deleted\033[0m"
+	@rm -f $(NAME)
+	@rm -f $(BIN_T)
+	@rm -f $(LIB)libenclave.a
+	@cargo clean && rm -f Cargo.lock
+
+c_clean:
+	@echo "\033[32mC edl generated files deleted\033[0m"
+	@rm -rf $(FILES_T_F)
+	@rm -f $(FILES_T_H)
+
+re: fclean all
+
+.PHONY: all clean c_clean fclean re fclean_enclave
\ No newline at end of file
diff --git a/samplecode/project_template/enclave/Xargo.toml b/samplecode/project_template/enclave/Xargo.toml
new file mode 100644
index 0000000..40db8ee
--- /dev/null
+++ b/samplecode/project_template/enclave/Xargo.toml
@@ -0,0 +1,95 @@
+[dependencies]
+alloc = {}
+
+[dependencies.sgx_types]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 1
+
+[dependencies.sgx_alloc]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 1
+
+[dependencies.sgx_unwind]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 1
+
+[dependencies.sgx_demangle]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 1
+
+[dependencies.panic_abort]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 1
+
+[dependencies.sgx_libc]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 2
+
+[dependencies.sgx_tkey_exchange]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 2
+
+[dependencies.sgx_tse]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 2
+
+[dependencies.sgx_tcrypto]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 2
+
+[dependencies.sgx_trts]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 3
+
+[dependencies.sgx_backtrace_sys]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 3
+
+[dependencies.panic_unwind]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 3
+
+[dependencies.sgx_tdh]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 4
+
+[dependencies.sgx_tseal]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 4
+
+[dependencies.sgx_tprotected_fs]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 4
+
+[dependencies.std]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 5
+features = ["backtrace"]
+
+[dependencies.sgx_no_tstd]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 5
+
+[dependencies.sgx_rand]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 6
+
+[dependencies.sgx_serialize]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 6
+
+[dependencies.sgx_tunittest]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 6
+
+[dependencies.sgx_backtrace]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 7
+
+[dependencies.sgx_cov]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 7
+
+[dependencies.sgx_signal]
+git = "https://github.com/apache/teaclave-sgx-sdk.git"
+stage = 7
diff --git a/samplecode/project_template/enclave/rust-toolchain b/samplecode/project_template/enclave/rust-toolchain
new file mode 100644
index 0000000..e966e30
--- /dev/null
+++ b/samplecode/project_template/enclave/rust-toolchain
@@ -0,0 +1 @@
+nightly-2020-10-25
\ No newline at end of file
diff --git a/samplecode/project_template/enclave/src/lib.rs b/samplecode/project_template/enclave/src/lib.rs
new file mode 100644
index 0000000..4c2c791
--- /dev/null
+++ b/samplecode/project_template/enclave/src/lib.rs
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License..
+
+#![crate_name = "sample"]
+#![crate_type = "staticlib"]
+
+#![cfg_attr(not(target_env = "sgx"), no_std)]
+#![cfg_attr(target_env = "sgx", feature(rustc_private))]
+
+extern crate sgx_types;
+#[cfg(not(target_env = "sgx"))]
+#[macro_use]
+extern crate sgx_tstd as std;
+
+use sgx_types::*;
+use std::io::{self, Write};
+use std::slice;
+
+#[no_mangle]
+pub extern "C" fn ecall_test(some_string: *const u8, some_len: usize) -> sgx_status_t {
+
+    let str_slice = unsafe { slice::from_raw_parts(some_string, some_len) };
+    let _ = io::stdout().write(str_slice);
+
+    println!("Message from the enclave");
+
+    sgx_status_t::SGX_SUCCESS
+}