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. | |
55 | */ | |
56 | #if (LTTNG_LINUX_PATCH >= 256) | |
57 | ||
58 | #define LTTNG_KERNEL_VERSION(a, b, c) \ | |
59 | (((a) << 24) + ((b) << 16) + (c)) | |
60 | ||
61 | #define LTTNG_LINUX_VERSION_CODE \ | |
62 | LTTNG_KERNEL_VERSION(LTTNG_LINUX_MAJOR, LTTNG_LINUX_MINOR, LTTNG_LINUX_PATCH) | |
63 | ||
64 | #else | |
65 | ||
360d3efe MJ |
66 | #define LTTNG_KERNEL_VERSION(a, b, c) KERNEL_VERSION(a, b, c) |
67 | #define LTTNG_LINUX_VERSION_CODE LINUX_VERSION_CODE | |
68 | ||
82151df0 MJ |
69 | #endif |
70 | ||
360d3efe | 71 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) |
9f61c55f | 72 | #include <generated/utsrelease.h> |
360d3efe | 73 | #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */ |
7b10d281 | 74 | #include <linux/utsrelease.h> |
360d3efe | 75 | #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */ |
5fa38800 MD |
76 | |
77 | /* | |
78 | * This macro checks if the kernel version is between the two specified | |
144bbfd5 | 79 | * versions (lower limit inclusive, upper limit exclusive). |
5fa38800 MD |
80 | */ |
81 | #define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \ | |
360d3efe MJ |
82 | (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \ |
83 | LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(a_high, b_high, c_high)) | |
5fa38800 | 84 | |
c94ac1ac MJ |
85 | /* Ubuntu */ |
86 | ||
3e5941df | 87 | #define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \ |
360d3efe | 88 | (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d)) |
3e5941df | 89 | |
05732a66 | 90 | #ifdef UTS_UBUNTU_RELEASE_ABI |
3e5941df | 91 | #define LTTNG_UBUNTU_VERSION_CODE \ |
360d3efe | 92 | ((LTTNG_LINUX_VERSION_CODE << 8) + UTS_UBUNTU_RELEASE_ABI) |
05732a66 MD |
93 | #else |
94 | #define LTTNG_UBUNTU_VERSION_CODE 0 | |
95 | #endif | |
3e5941df JD |
96 | |
97 | #define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ | |
98 | a_high, b_high, c_high, d_high) \ | |
05732a66 | 99 | (LTTNG_UBUNTU_VERSION_CODE >= \ |
3e5941df JD |
100 | LTTNG_UBUNTU_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ |
101 | LTTNG_UBUNTU_VERSION_CODE < \ | |
102 | LTTNG_UBUNTU_KERNEL_VERSION(a_high, b_high, c_high, d_high)) | |
103 | ||
c94ac1ac MJ |
104 | /* Debian */ |
105 | ||
72e6c528 | 106 | #define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \ |
360d3efe | 107 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
72e6c528 | 108 | |
05732a66 | 109 | #ifdef DEBIAN_API_VERSION |
72e6c528 | 110 | #define LTTNG_DEBIAN_VERSION_CODE \ |
360d3efe | 111 | ((LTTNG_LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION) |
05732a66 MD |
112 | #else |
113 | #define LTTNG_DEBIAN_VERSION_CODE 0 | |
114 | #endif | |
72e6c528 MD |
115 | |
116 | #define LTTNG_DEBIAN_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ | |
117 | a_high, b_high, c_high, d_high, e_high, f_high) \ | |
05732a66 | 118 | (LTTNG_DEBIAN_VERSION_CODE >= \ |
72e6c528 MD |
119 | LTTNG_DEBIAN_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ |
120 | LTTNG_DEBIAN_VERSION_CODE < \ | |
121 | LTTNG_DEBIAN_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) | |
122 | ||
c94ac1ac | 123 | #define LTTNG_RHEL_KERNEL_VERSION(a, b, c, d, e, f) \ |
360d3efe | 124 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
c94ac1ac MJ |
125 | |
126 | /* RHEL */ | |
f30ae671 | 127 | |
c94ac1ac | 128 | #ifdef RHEL_API_VERSION |
f30ae671 | 129 | #define LTTNG_RHEL_VERSION_CODE \ |
360d3efe | 130 | ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + RHEL_API_VERSION) |
f30ae671 MD |
131 | #else |
132 | #define LTTNG_RHEL_VERSION_CODE 0 | |
133 | #endif | |
134 | ||
c94ac1ac MJ |
135 | #define LTTNG_RHEL_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ |
136 | a_high, b_high, c_high, d_high, e_high, f_high) \ | |
f30ae671 | 137 | (LTTNG_RHEL_VERSION_CODE >= \ |
c94ac1ac | 138 | LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ |
f30ae671 | 139 | LTTNG_RHEL_VERSION_CODE < \ |
c94ac1ac MJ |
140 | LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) |
141 | ||
ce66b486 MJ |
142 | /* SUSE Linux enterprise */ |
143 | ||
144 | #define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \ | |
360d3efe | 145 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
ce66b486 MJ |
146 | |
147 | #ifdef SLE_API_VERSION | |
148 | #define LTTNG_SLE_VERSION_CODE \ | |
360d3efe | 149 | ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + SLE_API_VERSION) |
ce66b486 MJ |
150 | #else |
151 | #define LTTNG_SLE_VERSION_CODE 0 | |
152 | #endif | |
153 | ||
154 | #define LTTNG_SLE_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ | |
155 | a_high, b_high, c_high, d_high, e_high, f_high) \ | |
156 | (LTTNG_SLE_VERSION_CODE >= \ | |
157 | LTTNG_SLE_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ | |
158 | LTTNG_SLE_VERSION_CODE < \ | |
159 | LTTNG_SLE_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) | |
160 | ||
26d6737c LG |
161 | /* Fedora */ |
162 | ||
163 | #define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \ | |
360d3efe | 164 | (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000ULL) + (d)) |
26d6737c LG |
165 | |
166 | #ifdef FEDORA_REVISION_VERSION | |
167 | #define LTTNG_FEDORA_VERSION_CODE \ | |
360d3efe | 168 | ((LTTNG_LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION) |
26d6737c LG |
169 | #else |
170 | #define LTTNG_FEDORA_VERSION_CODE 0 | |
171 | #endif | |
172 | ||
173 | #define LTTNG_FEDORA_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ | |
174 | a_high, b_high, c_high, d_high) \ | |
175 | (LTTNG_FEDORA_VERSION_CODE >= \ | |
176 | LTTNG_FEDORA_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ | |
177 | LTTNG_FEDORA_VERSION_CODE < \ | |
178 | LTTNG_FEDORA_KERNEL_VERSION(a_high, b_high, c_high, d_high)) | |
179 | ||
c94ac1ac | 180 | /* RT patch */ |
f30ae671 | 181 | |
b4c8e4d3 | 182 | #define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \ |
360d3efe | 183 | (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d)) |
b4c8e4d3 MJ |
184 | |
185 | #ifdef RT_PATCH_VERSION | |
186 | #define LTTNG_RT_VERSION_CODE \ | |
360d3efe | 187 | ((LTTNG_LINUX_VERSION_CODE << 8) + RT_PATCH_VERSION) |
b4c8e4d3 MJ |
188 | #else |
189 | #define LTTNG_RT_VERSION_CODE 0 | |
190 | #endif | |
191 | ||
192 | #define LTTNG_RT_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ | |
193 | a_high, b_high, c_high, d_high) \ | |
194 | (LTTNG_RT_VERSION_CODE >= \ | |
195 | LTTNG_RT_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ | |
196 | LTTNG_RT_VERSION_CODE < \ | |
197 | LTTNG_RT_KERNEL_VERSION(a_high, b_high, c_high, d_high)) | |
198 | ||
5fa38800 | 199 | #endif /* _LTTNG_KERNEL_VERSION_H */ |