22
22
#include <stdarg.h>
23
23
#include <string.h>
24
24
#include <setjmp.h>
25
+ #include <stdatomic.h>
25
26
26
27
#if !defined(__FreeBSD__ ) \
27
28
&& !defined(__FreeBSD_kernel__ ) \
@@ -483,35 +484,13 @@ static void bound_not_found_warning(const char *file, const char *function,
483
484
dprintf (stderr , "%s%s, %s(): Not found %p\n" , exec , file , function , ptr );
484
485
}
485
486
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
-
508
487
/* enable/disable checking. This can be used in signal handlers. */
509
488
void __bounds_checking (int no_check )
510
489
{
511
490
#if HAVE_TLS_FUNC || HAVE_TLS_VAR
512
491
NO_CHECKING_SET (NO_CHECKING_GET () + no_check );
513
492
#else
514
- fetch_and_add (& no_checking , no_check );
493
+ atomic_fetch_add (& no_checking , no_check );
515
494
#endif
516
495
}
517
496
@@ -528,7 +507,7 @@ void __bound_checking_unlock(void)
528
507
/* enable/disable checking. This can be used in signal handlers. */
529
508
void __bound_never_fatal (int neverfatal )
530
509
{
531
- fetch_and_add (& never_fatal , neverfatal );
510
+ atomic_fetch_add (& never_fatal , neverfatal );
532
511
}
533
512
534
513
/* return '(p + offset)' for pointer arithmetic (a pointer can reach
0 commit comments