Skip to content

Commit faf2ff2

Browse files
committed
move WC_BARRIER() definition from wolfssl/wolfcrypt/types.h to wolfssl/wolfcrypt/wc_port.h, and strengthen it.
1 parent e671337 commit faf2ff2

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

wolfssl/wolfcrypt/types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,6 @@ enum {
489489
static WC_INLINE WARN_UNUSED_RESULT int WC_WUR_INT(int x) { return x; }
490490
#endif
491491

492-
/* XFENCE() is a no-op on some targets. WC_BARRIER() uses C89 intrinsics as an
493-
* additional portable barrier.
494-
*/
495-
#define WC_BARRIER() do { volatile byte _xfence = 0; (void)_xfence; XFENCE(); \
496-
} while(0)
497-
498492
#ifdef WORD64_AVAILABLE
499493
#define WC_MAX_UINT_OF(x) \
500494
((x)((((word64)1 << ((sizeof(x) * (word64)CHAR_BIT) - \

wolfssl/wolfcrypt/wc_port.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,18 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
18081808
#define XFENCE() WC_DO_NOTHING
18091809
#endif
18101810

1811+
#ifdef WC_BARRIER
1812+
/* use user-supplied WC_BARRIER() definition. */
1813+
#elif defined(__GNUC__) && !defined(WOLFSSL_NO_ASM)
1814+
#define WC_BARRIER() __asm__ __volatile__("" ::: "memory")
1815+
#else
1816+
/* XFENCE() is a no-op on some targets. The fallback construct uses C89
1817+
* intrinsics as an additional (but weak) portable barrier.
1818+
*/
1819+
#define WC_BARRIER() do { volatile byte _xfence = 0; (void)_xfence; XFENCE(); \
1820+
} while(0)
1821+
#endif
1822+
18111823

18121824
/* AFTER user_settings.h is loaded,
18131825
** determine if POSIX multi-threaded: HAVE_PTHREAD */

0 commit comments

Comments
 (0)