compiler.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef LINUX_COMPILER_H
  3. #define LINUX_COMPILER_H
  4. /* Avoid redefinition warnings */
  5. #undef __user
  6. #include "../../../include/linux/compiler_types.h"
  7. #undef __user
  8. #define __user
  9. #define WRITE_ONCE(var, val) \
  10. (*((volatile typeof(val) *)(&(var))) = (val))
  11. #define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
  12. #define __aligned(x) __attribute((__aligned__(x)))
  13. /**
  14. * data_race - mark an expression as containing intentional data races
  15. *
  16. * This data_race() macro is useful for situations in which data races
  17. * should be forgiven. One example is diagnostic code that accesses
  18. * shared variables but is not a part of the core synchronization design.
  19. * For example, if accesses to a given variable are protected by a lock,
  20. * except for diagnostic code, then the accesses under the lock should
  21. * be plain C-language accesses and those in the diagnostic code should
  22. * use data_race(). This way, KCSAN will complain if buggy lockless
  23. * accesses to that variable are introduced, even if the buggy accesses
  24. * are protected by READ_ONCE() or WRITE_ONCE().
  25. *
  26. * This macro *does not* affect normal code generation, but is a hint
  27. * to tooling that data races here are to be ignored. If the access must
  28. * be atomic *and* KCSAN should ignore the access, use both data_race()
  29. * and READ_ONCE(), for example, data_race(READ_ONCE(x)).
  30. */
  31. #define data_race(expr) \
  32. ({ \
  33. auto __v = (expr); \
  34. __v; \
  35. })
  36. #define __must_check
  37. #endif