Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
40d6e366 MD |
3 | * wrapper/compiler.h |
4 | * | |
5 | * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
40d6e366 MD |
6 | */ |
7 | ||
9f36eaed MJ |
8 | #ifndef _LTTNG_WRAPPER_COMPILER_H |
9 | #define _LTTNG_WRAPPER_COMPILER_H | |
10 | ||
40d6e366 | 11 | #include <linux/compiler.h> |
57ccbfa6 | 12 | #include <linux/version.h> |
40d6e366 MD |
13 | |
14 | /* | |
15 | * Don't allow compiling with buggy compiler. | |
16 | */ | |
17 | ||
cf262f57 MD |
18 | #ifdef GCC_VERSION |
19 | ||
40d6e366 MD |
20 | /* |
21 | * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58854 | |
22 | */ | |
cf262f57 MD |
23 | # ifdef __ARMEL__ |
24 | # if GCC_VERSION >= 40800 && GCC_VERSION <= 40802 | |
25 | # error Your gcc version produces clobbered frame accesses | |
26 | # endif | |
40d6e366 MD |
27 | # endif |
28 | #endif | |
29 | ||
a8f2d0c7 MJ |
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 | ||
57ccbfa6 MJ |
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 | ||
40d6e366 | 60 | #endif /* _LTTNG_WRAPPER_COMPILER_H */ |