@@ -1918,16 +1918,30 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
19181918 #endif
19191919#endif
19201920
1921- #ifdef WOLF_C99
1922- /* use alternate keyword for compatibility with -std=c99 */
1923- #define XASM_VOLATILE (a ) __asm__ volatile(a)
1924- #elif defined(__IAR_SYSTEMS_ICC__ )
1921+ /* XASM_VOLATILE_MB() adds a "memory" clobber. IAR/KEIL checked before
1922+ * WOLF_C99 since both may define __STDC_VERSION__ under --c99.
1923+ * XASM_VOLATILE() has no in-tree callers now; kept for out-of-tree ports. */
1924+ /* NOLINTBEGIN(bugprone-macro-parentheses) */
1925+ #if defined(__IAR_SYSTEMS_ICC__ )
1926+ /* clobber list supported: see sp_cortexm.c's __asm__/asm redefine. */
19251927 #define XASM_VOLATILE (a ) asm volatile(a)
1928+ #define XASM_VOLATILE_MB (a ) asm volatile(a ::: "memory")
19261929#elif defined(__KEIL__ )
1930+ /* clobber list supported: see sp_cortexm.c's __asm__/__asm redefine. */
19271931 #define XASM_VOLATILE (a ) __asm volatile(a)
1932+ #define XASM_VOLATILE_MB (a ) __asm volatile(a ::: "memory")
1933+ #elif defined(WOLF_C99 )
1934+ #define XASM_VOLATILE (a ) __asm__ volatile(a)
1935+ #define XASM_VOLATILE_MB (a ) __asm__ volatile(a ::: "memory")
1936+ #elif defined(__GNUC__ ) || defined(__clang__ )
1937+ #define XASM_VOLATILE (a ) __asm__ __volatile__(a)
1938+ #define XASM_VOLATILE_MB (a ) __asm__ __volatile__(a ::: "memory")
19281939#else
1940+ /* unknown compiler: assume basic asm only, no clobber list. */
19291941 #define XASM_VOLATILE (a ) __asm__ __volatile__(a)
1942+ #define XASM_VOLATILE_MB (a ) XASM_VOLATILE(a)
19301943#endif
1944+ /* NOLINTEND(bugprone-macro-parentheses) */
19311945
19321946#ifndef WOLFSSL_NO_FENCE
19331947 #ifdef XFENCE
@@ -1948,33 +1962,33 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
19481962 #elif defined(WOLFSSL_NO_ASM )
19491963 #define XFENCE () WC_DO_NOTHING
19501964 #elif defined (__i386__ ) || defined(__x86_64__ )
1951- #define XFENCE () XASM_VOLATILE ("lfence")
1965+ #define XFENCE () XASM_VOLATILE_MB ("lfence")
19521966 #elif defined (__arm__ ) && (__ARM_ARCH > 6 )
1953- #define XFENCE () XASM_VOLATILE ("isb")
1967+ #define XFENCE () XASM_VOLATILE_MB ("isb")
19541968 #elif defined(_MSC_VER ) && defined(_M_ARM64 )
19551969 /* MSVC on ARM64 has no __asm__; use the ISB intrinsic barrier. */
19561970 #include <intrin.h>
19571971 #define XFENCE () __isb(_ARM64_BARRIER_SY)
19581972 #elif defined(__aarch64__ )
19591973 /* Change ".inst 0xd50330ff" to "sb" when compilers support it. */
19601974 #ifdef WOLFSSL_ARMASM_BARRIER_SB
1961- #define XFENCE () XASM_VOLATILE (".inst 0xd50330ff")
1975+ #define XFENCE () XASM_VOLATILE_MB (".inst 0xd50330ff")
19621976 #elif defined(WOLFSSL_ARMASM_BARRIER_DETECT )
19631977 extern int aarch64_use_sb ;
1964- #define XFENCE () \
1965- do { \
1966- if (aarch64_use_sb) \
1967- XASM_VOLATILE (".inst 0xd50330ff"); \
1968- else \
1969- XASM_VOLATILE ("isb"); \
1978+ #define XFENCE () \
1979+ do { \
1980+ if (aarch64_use_sb) \
1981+ XASM_VOLATILE_MB (".inst 0xd50330ff"); \
1982+ else \
1983+ XASM_VOLATILE_MB ("isb"); \
19701984 } while (0)
19711985 #else
1972- #define XFENCE () XASM_VOLATILE ("isb")
1986+ #define XFENCE () XASM_VOLATILE_MB ("isb")
19731987 #endif
19741988 #elif defined(__riscv )
1975- #define XFENCE () XASM_VOLATILE ("fence")
1989+ #define XFENCE () XASM_VOLATILE_MB ("fence")
19761990 #elif defined(__PPC__ ) || defined(__POWERPC__ )
1977- #define XFENCE () XASM_VOLATILE ("isync; sync")
1991+ #define XFENCE () XASM_VOLATILE_MB ("isync; sync")
19781992 #else
19791993 #define XFENCE () WC_DO_NOTHING
19801994 #endif
0 commit comments