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