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