4efe0cfa671fab25b6b283543512b25903668425
[lttng-modules.git] / include / wrapper / compiler.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * wrapper/compiler.h
4 *
5 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8 #ifndef _LTTNG_WRAPPER_COMPILER_H
9 #define _LTTNG_WRAPPER_COMPILER_H
10
11 #include <linux/compiler.h>
12 #include <linux/version.h>
13
14 /*
15 * Don't allow compiling with buggy compiler.
16 */
17
18 #ifdef GCC_VERSION
19
20 /*
21 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58854
22 */
23 # ifdef __ARMEL__
24 # if GCC_VERSION >= 40800 && GCC_VERSION <= 40802
25 # error Your gcc version produces clobbered frame accesses
26 # endif
27 # endif
28 #endif
29
30 /*
31 * READ/WRITE_ONCE were introduced in kernel 3.19 and ACCESS_ONCE
32 * was removed in 4.15. Prefer READ/WRITE but fallback to ACCESS
33 * when they are not available.
34 */
35 #ifndef READ_ONCE
36 # define READ_ONCE(x) ACCESS_ONCE(x)
37 #endif
38
39 #ifndef WRITE_ONCE
40 # define WRITE_ONCE(x, val) ({ ACCESS_ONCE(x) = val; })
41 #endif
42
43 /*
44 * In v4.15 a smp read barrier was added to READ_ONCE to replace
45 * lockless_dereference(), replicate this behavior on prior kernels
46 * and remove calls to smp_read_barrier_depends which was dropped
47 * in v5.9.
48 */
49 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0))
50 #define LTTNG_READ_ONCE(x) READ_ONCE(x)
51 #else
52 #define LTTNG_READ_ONCE(x) \
53 ({ \
54 typeof(x) __val = READ_ONCE(x); \
55 smp_read_barrier_depends(); \
56 __val; \
57 })
58 #endif
59
60 #define __LTTNG_COMPOUND_LITERAL(type, ...) (type[]) { __VA_ARGS__ }
61
62 #endif /* _LTTNG_WRAPPER_COMPILER_H */
This page took 0.042221 seconds and 3 git commands to generate.