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