Commit | Line | Data |
---|---|---|
5fa38800 MD |
1 | #ifndef _LTTNG_KERNEL_VERSION_H |
2 | #define _LTTNG_KERNEL_VERSION_H | |
3 | ||
4 | /* | |
5 | * lttng-kernel-version.h | |
6 | * | |
7 | * Contains helpers to check more complex kernel version conditions. | |
8 | * | |
9 | * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
10 | * | |
11 | * This library is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License as published by the Free Software Foundation; only | |
14 | * version 2.1 of the License. | |
15 | * | |
16 | * This library is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * Lesser General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU Lesser General Public | |
22 | * License along with this library; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
24 | */ | |
25 | ||
26 | #include <linux/version.h> | |
9f61c55f | 27 | |
82151df0 MJ |
28 | /* |
29 | * The following defines are extracted from the toplevel Linux Makefile and | |
30 | * passed on the command line -with '-D'. | |
31 | */ | |
32 | ||
33 | #ifndef LTTNG_LINUX_MAJOR | |
34 | #define LTTNG_LINUX_MAJOR 0 | |
35 | #endif | |
36 | ||
37 | #ifndef LTTNG_LINUX_MINOR | |
38 | #define LTTNG_LINUX_MINOR 0 | |
39 | #endif | |
40 | ||
41 | #ifndef LTTNG_LINUX_PATCH | |
42 | #define LTTNG_LINUX_PATCH 0 | |
43 | #endif | |
44 | ||
45 | /* | |
46 | * Some stable releases have overflowed the 8bits allocated to the sublevel in | |
47 | * the version code. To determine if the current kernel is affected, use the | |
48 | * sublevel version from the Makefile. This is currently true for the 4.4.256 | |
49 | * and 4.9.256 stable releases. | |
50 | * | |
51 | * When the sublevel has overflowed, use the values from the Makefile instead | |
52 | * of LINUX_VERSION_CODE from the kernel headers and allocate 16bits. | |
53 | * Otherwise, keep using the version code from the headers to minimise the | |
54 | * behavior change and avoid regressions. | |
1dc55aa6 MJ |
55 | * |
56 | * Cast the result to uint64_t to prevent overflowing when we append distro | |
57 | * specific version information. | |
82151df0 MJ |
58 | */ |
59 | #if (LTTNG_LINUX_PATCH >= 256) | |
60 | ||
61 | #define LTTNG_KERNEL_VERSION(a, b, c) \ | |
1dc55aa6 | 62 | ((((a) << 24) + ((b) << 16) + (c)) * 1ULL) |
82151df0 MJ |
63 | |
64 | #define LTTNG_LINUX_VERSION_CODE \ | |
65 | LTTNG_KERNEL_VERSION(LTTNG_LINUX_MAJOR, LTTNG_LINUX_MINOR, LTTNG_LINUX_PATCH) | |
66 | ||
67 | #else | |
68 | ||
1dc55aa6 MJ |
69 | #define LTTNG_KERNEL_VERSION(a, b, c) (KERNEL_VERSION(a, b, c) * 1ULL) |
70 | #define LTTNG_LINUX_VERSION_CODE (LINUX_VERSION_CODE * 1ULL) | |
360d3efe | 71 | |
82151df0 MJ |
72 | #endif |
73 | ||
360d3efe | 74 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) |
9f61c55f | 75 | #include <generated/utsrelease.h> |
360d3efe | 76 | #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */ |
7b10d281 | 77 | #include <linux/utsrelease.h> |
360d3efe | 78 | #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */ |
5fa38800 MD |
79 | |
80 | /* | |
81 | * This macro checks if the kernel version is between the two specified | |
144bbfd5 | 82 | * versions (lower limit inclusive, upper limit exclusive). |
5fa38800 MD |
83 | */ |
84 | #define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \ | |
360d3efe MJ |
85 | (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \ |
86 | LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(a_high, b_high, c_high)) | |
5fa38800 | 87 | |
c94ac1ac MJ |
88 | /* Ubuntu */ |
89 | ||
3e5941df | 90 | #define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \ |
07842fef | 91 | (((LTTNG_KERNEL_VERSION(a, b, c)) << 16) + (d)) |
3e5941df | 92 | |
05732a66 | 93 | #ifdef UTS_UBUNTU_RELEASE_ABI |
3e5941df | 94 | #define LTTNG_UBUNTU_VERSION_CODE \ |
07842fef | 95 | ((LTTNG_LINUX_VERSION_CODE << 16) + UTS_UBUNTU_RELEASE_ABI) |
05732a66 MD |
96 | #else |
97 | #define LTTNG_UBUNTU_VERSION_CODE 0 | |
98 | #endif | |
3e5941df JD |
99 | |
100 | #define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ | |
101 | a_high, b_high, c_high, d_high) \ | |
05732a66 | 102 | (LTTNG_UBUNTU_VERSION_CODE >= \ |
3e5941df JD |
103 | LTTNG_UBUNTU_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ |
104 | LTTNG_UBUNTU_VERSION_CODE < \ | |
105 | LTTNG_UBUNTU_KERNEL_VERSION(a_high, b_high, c_high, d_high)) | |
106 | ||
c94ac1ac MJ |
107 | /* Debian */ |
108 | ||
72e6c528 | 109 | #define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \ |
360d3efe | 110 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
72e6c528 | 111 | |
05732a66 | 112 | #ifdef DEBIAN_API_VERSION |
72e6c528 | 113 | #define LTTNG_DEBIAN_VERSION_CODE \ |
360d3efe | 114 | ((LTTNG_LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION) |
05732a66 MD |
115 | #else |
116 | #define LTTNG_DEBIAN_VERSION_CODE 0 | |
117 | #endif | |
72e6c528 MD |
118 | |
119 | #define LTTNG_DEBIAN_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ | |
120 | a_high, b_high, c_high, d_high, e_high, f_high) \ | |
05732a66 | 121 | (LTTNG_DEBIAN_VERSION_CODE >= \ |
72e6c528 MD |
122 | LTTNG_DEBIAN_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ |
123 | LTTNG_DEBIAN_VERSION_CODE < \ | |
124 | LTTNG_DEBIAN_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) | |
125 | ||
c94ac1ac | 126 | #define LTTNG_RHEL_KERNEL_VERSION(a, b, c, d, e, f) \ |
a7781f7b | 127 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 100000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
c94ac1ac MJ |
128 | |
129 | /* RHEL */ | |
f30ae671 | 130 | |
c94ac1ac | 131 | #ifdef RHEL_API_VERSION |
f30ae671 | 132 | #define LTTNG_RHEL_VERSION_CODE \ |
a7781f7b | 133 | ((LTTNG_LINUX_VERSION_CODE * 100000000ULL) + RHEL_API_VERSION) |
f30ae671 MD |
134 | #else |
135 | #define LTTNG_RHEL_VERSION_CODE 0 | |
136 | #endif | |
137 | ||
c94ac1ac MJ |
138 | #define LTTNG_RHEL_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ |
139 | a_high, b_high, c_high, d_high, e_high, f_high) \ | |
f30ae671 | 140 | (LTTNG_RHEL_VERSION_CODE >= \ |
c94ac1ac | 141 | LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ |
f30ae671 | 142 | LTTNG_RHEL_VERSION_CODE < \ |
c94ac1ac MJ |
143 | LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) |
144 | ||
ce66b486 MJ |
145 | /* SUSE Linux enterprise */ |
146 | ||
147 | #define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \ | |
e362ba5e | 148 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 100000000ULL) + ((d) * 100000) + ((e) * 100) + (f)) |
ce66b486 MJ |
149 | |
150 | #ifdef SLE_API_VERSION | |
151 | #define LTTNG_SLE_VERSION_CODE \ | |
e362ba5e | 152 | ((LTTNG_LINUX_VERSION_CODE * 100000000ULL) + SLE_API_VERSION) |
ce66b486 MJ |
153 | #else |
154 | #define LTTNG_SLE_VERSION_CODE 0 | |
155 | #endif | |
156 | ||
157 | #define LTTNG_SLE_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ | |
158 | a_high, b_high, c_high, d_high, e_high, f_high) \ | |
159 | (LTTNG_SLE_VERSION_CODE >= \ | |
160 | LTTNG_SLE_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ | |
161 | LTTNG_SLE_VERSION_CODE < \ | |
162 | LTTNG_SLE_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) | |
163 | ||
26d6737c LG |
164 | /* Fedora */ |
165 | ||
166 | #define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \ | |
360d3efe | 167 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000ULL) + (d)) |
26d6737c LG |
168 | |
169 | #ifdef FEDORA_REVISION_VERSION | |
170 | #define LTTNG_FEDORA_VERSION_CODE \ | |
360d3efe | 171 | ((LTTNG_LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION) |
26d6737c LG |
172 | #else |
173 | #define LTTNG_FEDORA_VERSION_CODE 0 | |
174 | #endif | |
175 | ||
176 | #define LTTNG_FEDORA_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ | |
177 | a_high, b_high, c_high, d_high) \ | |
178 | (LTTNG_FEDORA_VERSION_CODE >= \ | |
179 | LTTNG_FEDORA_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ | |
180 | LTTNG_FEDORA_VERSION_CODE < \ | |
181 | LTTNG_FEDORA_KERNEL_VERSION(a_high, b_high, c_high, d_high)) | |
182 | ||
c94ac1ac | 183 | /* RT patch */ |
f30ae671 | 184 | |
b4c8e4d3 | 185 | #define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \ |
ea14d581 | 186 | (((LTTNG_KERNEL_VERSION(a, b, c)) << 16) + (d)) |
b4c8e4d3 MJ |
187 | |
188 | #ifdef RT_PATCH_VERSION | |
189 | #define LTTNG_RT_VERSION_CODE \ | |
ea14d581 | 190 | ((LTTNG_LINUX_VERSION_CODE << 16) + RT_PATCH_VERSION) |
b4c8e4d3 MJ |
191 | #else |
192 | #define LTTNG_RT_VERSION_CODE 0 | |
193 | #endif | |
194 | ||
195 | #define LTTNG_RT_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ | |
196 | a_high, b_high, c_high, d_high) \ | |
197 | (LTTNG_RT_VERSION_CODE >= \ | |
198 | LTTNG_RT_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ | |
199 | LTTNG_RT_VERSION_CODE < \ | |
200 | LTTNG_RT_KERNEL_VERSION(a_high, b_high, c_high, d_high)) | |
201 | ||
5fa38800 | 202 | #endif /* _LTTNG_KERNEL_VERSION_H */ |