fix: sublevel version overflow in LINUX_VERSION_CODE
[lttng-modules.git] / include / lttng / kernel-version.h
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
2df37e95 3 * lttng/kernel-version.h
5fa38800 4 *
7b25fa17 5 * Contains helpers to check kernel version conditions.
5fa38800
MD
6 *
7 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5fa38800
MD
8 */
9
9f36eaed
MJ
10#ifndef _LTTNG_KERNEL_VERSION_H
11#define _LTTNG_KERNEL_VERSION_H
12
5fa38800 13#include <linux/version.h>
9f61c55f 14#include <generated/utsrelease.h>
5fa38800 15
5f4c791e
MJ
16#define LTTNG_KERNEL_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
17#define LTTNG_LINUX_VERSION_CODE LINUX_VERSION_CODE
18
7b25fa17
MJ
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
5fa38800
MD
62/*
63 * This macro checks if the kernel version is between the two specified
144bbfd5 64 * versions (lower limit inclusive, upper limit exclusive).
5fa38800
MD
65 */
66#define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \
5f4c791e
MJ
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))
5fa38800 69
c94ac1ac
MJ
70/* Ubuntu */
71
3e5941df 72#define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \
5f4c791e 73 (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d))
3e5941df 74
05732a66 75#ifdef UTS_UBUNTU_RELEASE_ABI
3e5941df 76#define LTTNG_UBUNTU_VERSION_CODE \
5f4c791e 77 ((LTTNG_LINUX_VERSION_CODE << 8) + UTS_UBUNTU_RELEASE_ABI)
05732a66
MD
78#else
79#define LTTNG_UBUNTU_VERSION_CODE 0
80#endif
3e5941df
JD
81
82#define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
83 a_high, b_high, c_high, d_high) \
05732a66 84 (LTTNG_UBUNTU_VERSION_CODE >= \
3e5941df
JD
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
c94ac1ac
MJ
89/* Debian */
90
72e6c528 91#define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \
5f4c791e 92 (((LTTNG_KERNEL_VERSION(a, b, c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
72e6c528 93
05732a66 94#ifdef DEBIAN_API_VERSION
72e6c528 95#define LTTNG_DEBIAN_VERSION_CODE \
5f4c791e 96 ((LTTNG_LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION)
05732a66
MD
97#else
98#define LTTNG_DEBIAN_VERSION_CODE 0
99#endif
72e6c528
MD
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) \
05732a66 103 (LTTNG_DEBIAN_VERSION_CODE >= \
72e6c528
MD
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
c94ac1ac 108/* RHEL */
f30ae671 109
5f4c791e
MJ
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
c94ac1ac 113#ifdef RHEL_API_VERSION
f30ae671 114#define LTTNG_RHEL_VERSION_CODE \
5f4c791e 115 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + RHEL_API_VERSION)
f30ae671
MD
116#else
117#define LTTNG_RHEL_VERSION_CODE 0
118#endif
119
c94ac1ac
MJ
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) \
f30ae671 122 (LTTNG_RHEL_VERSION_CODE >= \
c94ac1ac 123 LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
f30ae671 124 LTTNG_RHEL_VERSION_CODE < \
c94ac1ac
MJ
125 LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
126
ce66b486
MJ
127/* SUSE Linux enterprise */
128
129#define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \
5f4c791e 130 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
ce66b486
MJ
131
132#ifdef SLE_API_VERSION
133#define LTTNG_SLE_VERSION_CODE \
5f4c791e 134 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + SLE_API_VERSION)
ce66b486
MJ
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
e4838da1
LG
146/* Fedora */
147
148#define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \
5f4c791e 149 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000ULL) + (d))
e4838da1
LG
150
151#ifdef FEDORA_REVISION_VERSION
152#define LTTNG_FEDORA_VERSION_CODE \
5f4c791e 153 ((LTTNG_LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION)
e4838da1
LG
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
c94ac1ac 165/* RT patch */
f30ae671 166
b4c8e4d3 167#define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \
5f4c791e 168 (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d))
b4c8e4d3
MJ
169
170#ifdef RT_PATCH_VERSION
171#define LTTNG_RT_VERSION_CODE \
5f4c791e 172 ((LTTNG_LINUX_VERSION_CODE << 8) + RT_PATCH_VERSION)
b4c8e4d3
MJ
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
5fa38800 184#endif /* _LTTNG_KERNEL_VERSION_H */
This page took 0.047547 seconds and 4 git commands to generate.