diff --git a/src/aal/aal.h b/src/aal/aal.h index 1fb58b79..55b14778 100644 --- a/src/aal/aal.h +++ b/src/aal/aal.h @@ -7,7 +7,12 @@ #if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \ defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \ defined(_M_AMD64) -# define PLATFORM_IS_X86 +# if defined(SNMALLOC_SGX) +# define PLATFORM_IS_X86_SGX +# define SNMALLOC_NO_AAL_BUILTINS +# else +# define PLATFORM_IS_X86 +# endif #endif #if defined(__arm__) || defined(__aarch64__) @@ -93,6 +98,8 @@ namespace snmalloc #if defined(PLATFORM_IS_X86) # include "aal_x86.h" +#elif defined(PLATFORM_IS_X86_SGX) +# include "aal_x86_sgx.h" #elif defined(PLATFORM_IS_ARM) # include "aal_arm.h" #endif diff --git a/src/aal/aal_x86.h b/src/aal/aal_x86.h index d30df33e..2473b5f3 100644 --- a/src/aal/aal_x86.h +++ b/src/aal/aal_x86.h @@ -8,7 +8,7 @@ # include #endif -#if defined(__linux__) && !defined(OPEN_ENCLAVE) +#if defined(__linux__) # include #endif diff --git a/src/aal/aal_x86_sgx.h b/src/aal/aal_x86_sgx.h new file mode 100644 index 00000000..9aa87c36 --- /dev/null +++ b/src/aal/aal_x86_sgx.h @@ -0,0 +1,60 @@ +#pragma once + +#ifdef _MSC_VER +# include +# include +#else +# include +#endif + +#if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \ + defined(_M_AMD64) +# define SNMALLOC_VA_BITS_64 +#else +# define SNMALLOC_VA_BITS_32 +#endif + +namespace snmalloc +{ + /** + * x86-specific architecture abstraction layer minimised for use + * inside SGX enclaves. + */ + class AAL_x86_sgx + { + public: + /** + * Bitmap of AalFeature flags + */ + static constexpr uint64_t aal_features = IntegerPointers; + + /** + * On pipelined processors, notify the core that we are in a spin loop and + * that speculative execution past this point may not be a performance gain. + */ + static inline void pause() + { + _mm_pause(); + } + + /** + * Issue a prefetch hint at the specified address. + */ + static inline void prefetch(void* ptr) + { + _mm_prefetch(reinterpret_cast(ptr), _MM_HINT_T0); + } + + /** + * Return a cycle counter value. + * Not guaranteed inside an enclave, so just always return 0. + * This is only used for benchmarking inside snmalloc. + */ + static inline uint64_t tick() + { + return 0; + } + }; + + using AAL_Arch = AAL_x86_sgx; +} // namespace snmalloc diff --git a/src/test/func/fixed_region/fixed_region.cc b/src/test/func/fixed_region/fixed_region.cc index 00409cb1..94ad3773 100644 --- a/src/test/func/fixed_region/fixed_region.cc +++ b/src/test/func/fixed_region/fixed_region.cc @@ -1,4 +1,4 @@ - +#define SNMALLOC_SGX #define OPEN_ENCLAVE #define OPEN_ENCLAVE_SIMULATION #define USE_RESERVE_MULTIPLE 1