diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index e1a8a964f5..6fd7f8198d 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -489,12 +489,6 @@ enum { static WC_INLINE WARN_UNUSED_RESULT int WC_WUR_INT(int x) { return x; } #endif -/* XFENCE() is a no-op on some targets. WC_BARRIER() uses C89 intrinsics as an - * additional portable barrier. - */ -#define WC_BARRIER() do { volatile byte _xfence = 0; (void)_xfence; XFENCE(); \ - } while(0) - #ifdef WORD64_AVAILABLE #define WC_MAX_UINT_OF(x) \ ((x)((((word64)1 << ((sizeof(x) * (word64)CHAR_BIT) - \ diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index f2ac50ddcd..b13ac51bd0 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -1808,6 +1808,18 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); #define XFENCE() WC_DO_NOTHING #endif +#ifdef WC_BARRIER + /* use user-supplied WC_BARRIER() definition. */ +#elif defined(__GNUC__) && !defined(WOLFSSL_NO_ASM) + #define WC_BARRIER() __asm__ __volatile__("" ::: "memory") +#else + /* XFENCE() is a no-op on some targets. The fallback construct uses C89 + * intrinsics as an additional (but weak) portable barrier. + */ + #define WC_BARRIER() do { volatile byte _xfence = 0; (void)_xfence; XFENCE(); \ + } while(0) +#endif + /* AFTER user_settings.h is loaded, ** determine if POSIX multi-threaded: HAVE_PTHREAD */