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