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