a41829f0a6160ee33be6f8ea9da258910148c752
[lttng-modules.git] / include / lttng / kernel-version.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng/kernel-version.h
4 *
5 * Contains helpers to check kernel version conditions.
6 *
7 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #ifndef _LTTNG_KERNEL_VERSION_H
11 #define _LTTNG_KERNEL_VERSION_H
12
13 #include <linux/version.h>
14 #include <generated/utsrelease.h>
15
16 /*
17 * The following defines are extracted from the toplevel Linux Makefile and
18 * passed on the command line -with '-D'.
19 */
20
21 #ifndef LTTNG_LINUX_MAJOR
22 #define LTTNG_LINUX_MAJOR 0
23 #endif
24
25 #ifndef LTTNG_LINUX_MINOR
26 #define LTTNG_LINUX_MINOR 0
27 #endif
28
29 #ifndef LTTNG_LINUX_PATCH
30 #define LTTNG_LINUX_PATCH 0
31 #endif
32
33 /*
34 * Some stable releases have overflowed the 8bits allocated to the sublevel in
35 * the version code. To determine if the current kernel is affected, use the
36 * sublevel version from the Makefile. This is currently true for the 4.4.256
37 * and 4.9.256 stable releases.
38 *
39 * When the sublevel has overflowed, use the values from the Makefile instead
40 * of LINUX_VERSION_CODE from the kernel headers and allocate 16bits.
41 * Otherwise, keep using the version code from the headers to minimise the
42 * behavior change and avoid regressions.
43 */
44 #if (LTTNG_LINUX_PATCH >= 256)
45
46 #define LTTNG_KERNEL_VERSION(a, b, c) \
47 (((a) << 24) + ((b) << 16) + (c))
48
49 #define LTTNG_LINUX_VERSION_CODE \
50 LTTNG_KERNEL_VERSION(LTTNG_LINUX_MAJOR, LTTNG_LINUX_MINOR, LTTNG_LINUX_PATCH)
51
52 #else
53
54 #define LTTNG_KERNEL_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
55 #define LTTNG_LINUX_VERSION_CODE LINUX_VERSION_CODE
56
57 #endif
58
59 /*
60 * This macro checks if the kernel version is between the two specified
61 * versions (lower limit inclusive, upper limit exclusive).
62 */
63 #define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \
64 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \
65 LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(a_high, b_high, c_high))
66
67 /* Ubuntu */
68
69 #define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \
70 (((LTTNG_KERNEL_VERSION(a, b, c)) << 16) + (d))
71
72 #ifdef UTS_UBUNTU_RELEASE_ABI
73 #define LTTNG_UBUNTU_VERSION_CODE \
74 ((LTTNG_LINUX_VERSION_CODE << 16) + UTS_UBUNTU_RELEASE_ABI)
75 #else
76 #define LTTNG_UBUNTU_VERSION_CODE 0
77 #endif
78
79 #define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
80 a_high, b_high, c_high, d_high) \
81 (LTTNG_UBUNTU_VERSION_CODE >= \
82 LTTNG_UBUNTU_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
83 LTTNG_UBUNTU_VERSION_CODE < \
84 LTTNG_UBUNTU_KERNEL_VERSION(a_high, b_high, c_high, d_high))
85
86 /* Debian */
87
88 #define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \
89 (((LTTNG_KERNEL_VERSION(a, b, c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
90
91 #ifdef DEBIAN_API_VERSION
92 #define LTTNG_DEBIAN_VERSION_CODE \
93 ((LTTNG_LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION)
94 #else
95 #define LTTNG_DEBIAN_VERSION_CODE 0
96 #endif
97
98 #define LTTNG_DEBIAN_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
99 a_high, b_high, c_high, d_high, e_high, f_high) \
100 (LTTNG_DEBIAN_VERSION_CODE >= \
101 LTTNG_DEBIAN_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
102 LTTNG_DEBIAN_VERSION_CODE < \
103 LTTNG_DEBIAN_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
104
105 /* RHEL */
106
107 #define LTTNG_RHEL_KERNEL_VERSION(a, b, c, d, e, f) \
108 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
109
110 #ifdef RHEL_API_VERSION
111 #define LTTNG_RHEL_VERSION_CODE \
112 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + RHEL_API_VERSION)
113 #else
114 #define LTTNG_RHEL_VERSION_CODE 0
115 #endif
116
117 #define LTTNG_RHEL_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
118 a_high, b_high, c_high, d_high, e_high, f_high) \
119 (LTTNG_RHEL_VERSION_CODE >= \
120 LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
121 LTTNG_RHEL_VERSION_CODE < \
122 LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
123
124 /* SUSE Linux enterprise */
125
126 #define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \
127 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
128
129 #ifdef SLE_API_VERSION
130 #define LTTNG_SLE_VERSION_CODE \
131 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + SLE_API_VERSION)
132 #else
133 #define LTTNG_SLE_VERSION_CODE 0
134 #endif
135
136 #define LTTNG_SLE_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
137 a_high, b_high, c_high, d_high, e_high, f_high) \
138 (LTTNG_SLE_VERSION_CODE >= \
139 LTTNG_SLE_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
140 LTTNG_SLE_VERSION_CODE < \
141 LTTNG_SLE_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
142
143 /* Fedora */
144
145 #define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \
146 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000ULL) + (d))
147
148 #ifdef FEDORA_REVISION_VERSION
149 #define LTTNG_FEDORA_VERSION_CODE \
150 ((LTTNG_LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION)
151 #else
152 #define LTTNG_FEDORA_VERSION_CODE 0
153 #endif
154
155 #define LTTNG_FEDORA_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
156 a_high, b_high, c_high, d_high) \
157 (LTTNG_FEDORA_VERSION_CODE >= \
158 LTTNG_FEDORA_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
159 LTTNG_FEDORA_VERSION_CODE < \
160 LTTNG_FEDORA_KERNEL_VERSION(a_high, b_high, c_high, d_high))
161
162 /* RT patch */
163
164 #define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \
165 (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d))
166
167 #ifdef RT_PATCH_VERSION
168 #define LTTNG_RT_VERSION_CODE \
169 ((LTTNG_LINUX_VERSION_CODE << 8) + RT_PATCH_VERSION)
170 #else
171 #define LTTNG_RT_VERSION_CODE 0
172 #endif
173
174 #define LTTNG_RT_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
175 a_high, b_high, c_high, d_high) \
176 (LTTNG_RT_VERSION_CODE >= \
177 LTTNG_RT_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
178 LTTNG_RT_VERSION_CODE < \
179 LTTNG_RT_KERNEL_VERSION(a_high, b_high, c_high, d_high))
180
181 #endif /* _LTTNG_KERNEL_VERSION_H */
This page took 0.032626 seconds and 3 git commands to generate.