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