From 32b597746c1c9da4656ef34e2930c604f6c13c81 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Tue, 24 Jun 2025 21:38:31 +0200 Subject: [PATCH] Update bcheck for recent atomic change The functions fetch_and_add_arm, fetch_and_add_arm64 and fetch_and_add_riscv64 where removed with atomic change. Replace the code in bcheck.c with call to atomic_fetch_add. --- lib/bcheck.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/lib/bcheck.c b/lib/bcheck.c index e3f70e14..96066d99 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -22,6 +22,7 @@ #include #include #include +#include #if !defined(__FreeBSD__) \ && !defined(__FreeBSD_kernel__) \ @@ -483,35 +484,13 @@ static void bound_not_found_warning(const char *file, const char *function, dprintf(stderr, "%s%s, %s(): Not found %p\n", exec, file, function, ptr); } -static void fetch_and_add(int* variable, int value) -{ -#if defined __i386__ || defined __x86_64__ - __asm__ volatile("lock; addl %0, %1" - : "+r" (value), "+m" (*variable) // input+output - : // No input-only - : "memory" - ); -#elif defined __arm__ - extern void fetch_and_add_arm(int* variable, int value); - fetch_and_add_arm(variable, value); -#elif defined __aarch64__ - extern void fetch_and_add_arm64(int* variable, int value); - fetch_and_add_arm64(variable, value); -#elif defined __riscv - extern void fetch_and_add_riscv64(int* variable, int value); - fetch_and_add_riscv64(variable, value); -#else - *variable += value; -#endif -} - /* enable/disable checking. This can be used in signal handlers. */ void __bounds_checking (int no_check) { #if HAVE_TLS_FUNC || HAVE_TLS_VAR NO_CHECKING_SET(NO_CHECKING_GET() + no_check); #else - fetch_and_add (&no_checking, no_check); + atomic_fetch_add (&no_checking, no_check); #endif } @@ -528,7 +507,7 @@ void __bound_checking_unlock(void) /* enable/disable checking. This can be used in signal handlers. */ void __bound_never_fatal (int neverfatal) { - fetch_and_add (&never_fatal, neverfatal); + atomic_fetch_add (&never_fatal, neverfatal); } /* return '(p + offset)' for pointer arithmetic (a pointer can reach