rseq-access.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* RSEQ_* accessors. Generic version.
  2. Copyright (C) 2002-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <atomic.h>
  16. /* Read member of the RSEQ area directly. */
  17. #define RSEQ_GETMEM(member) \
  18. RSEQ_SELF()->member
  19. /* Set member of the RSEQ area directly. */
  20. #define RSEQ_SETMEM(member, value) \
  21. RSEQ_SELF()->member = (value)
  22. /* Static assert for types that can't be loaded/stored atomically on the
  23. current architecture. */
  24. #if HAVE_64B_ATOMICS
  25. #define __RSEQ_ASSERT_ATOMIC(member) \
  26. _Static_assert (sizeof (RSEQ_SELF()->member) == 1 \
  27. || sizeof (RSEQ_SELF()->member) == 4 \
  28. || sizeof (RSEQ_SELF()->member) == 8, \
  29. "size of rseq data")
  30. #else
  31. #define __RSEQ_ASSERT_ATOMIC(member) \
  32. _Static_assert (sizeof (RSEQ_SELF()->member) == 1 \
  33. || sizeof (RSEQ_SELF()->member) == 4, \
  34. "size of rseq data")
  35. #endif
  36. /* Read member of the RSEQ area directly, with single-copy atomicity semantics. */
  37. #define RSEQ_GETMEM_ONCE(member) \
  38. ({ \
  39. __RSEQ_ASSERT_ATOMIC(member); \
  40. (*(volatile __typeof (RSEQ_SELF()->member) *)&RSEQ_SELF()->member); \
  41. })
  42. /* Set member of the RSEQ area directly, with single-copy atomicity semantics. */
  43. #define RSEQ_SETMEM_ONCE(member, value) \
  44. ({ \
  45. __RSEQ_ASSERT_ATOMIC(member); \
  46. (*(volatile __typeof (RSEQ_SELF()->member) *)&RSEQ_SELF()->member = (value)); \
  47. })