2222#include <stdarg.h>
2323#include <string.h>
2424#include <setjmp.h>
25+ #include <stdatomic.h>
2526
2627#if !defined(__FreeBSD__ ) \
2728 && !defined(__FreeBSD_kernel__ ) \
@@ -483,35 +484,13 @@ static void bound_not_found_warning(const char *file, const char *function,
483484 dprintf (stderr , "%s%s, %s(): Not found %p\n" , exec , file , function , ptr );
484485}
485486
486- static void fetch_and_add (int * variable , int value )
487- {
488- #if defined __i386__ || defined __x86_64__
489- __asm__ volatile ("lock; addl %0, %1"
490- : "+r" (value ), "+m" (* variable ) // input+output
491- : // No input-only
492- : "memory"
493- );
494- #elif defined __arm__
495- extern void fetch_and_add_arm (int * variable , int value );
496- fetch_and_add_arm (variable , value );
497- #elif defined __aarch64__
498- extern void fetch_and_add_arm64 (int * variable , int value );
499- fetch_and_add_arm64 (variable , value );
500- #elif defined __riscv
501- extern void fetch_and_add_riscv64 (int * variable , int value );
502- fetch_and_add_riscv64 (variable , value );
503- #else
504- * variable += value ;
505- #endif
506- }
507-
508487/* enable/disable checking. This can be used in signal handlers. */
509488void __bounds_checking (int no_check )
510489{
511490#if HAVE_TLS_FUNC || HAVE_TLS_VAR
512491 NO_CHECKING_SET (NO_CHECKING_GET () + no_check );
513492#else
514- fetch_and_add (& no_checking , no_check );
493+ atomic_fetch_add (& no_checking , no_check );
515494#endif
516495}
517496
@@ -528,7 +507,7 @@ void __bound_checking_unlock(void)
528507/* enable/disable checking. This can be used in signal handlers. */
529508void __bound_never_fatal (int neverfatal )
530509{
531- fetch_and_add (& never_fatal , neverfatal );
510+ atomic_fetch_add (& never_fatal , neverfatal );
532511}
533512
534513/* return '(p + offset)' for pointer arithmetic (a pointer can reach
0 commit comments