fix: sublevel version overflow in LINUX_VERSION_CODE
[lttng-modules.git] / lttng-kernel-version.h
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
5fa38800
MD
3 * lttng-kernel-version.h
4 *
b78104db 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
2a51de8b
MJ
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
b78104db
MJ
53#define LTTNG_KERNEL_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
54#define LTTNG_LINUX_VERSION_CODE LINUX_VERSION_CODE
55
2a51de8b
MJ
56#endif
57
b78104db 58#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33))
9f61c55f 59#include <generated/utsrelease.h>
b78104db 60#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */
7b10d281 61#include <linux/utsrelease.h>
b78104db 62#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */
5fa38800
MD
63
64/*
65 * This macro checks if the kernel version is between the two specified
144bbfd5 66 * versions (lower limit inclusive, upper limit exclusive).
5fa38800
MD
67 */
68#define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \
b78104db
MJ
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))
5fa38800 71
c94ac1ac
MJ
72/* Ubuntu */
73
3e5941df 74#define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \
b78104db 75 (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d))
3e5941df 76
05732a66 77#ifdef UTS_UBUNTU_RELEASE_ABI
3e5941df 78#define LTTNG_UBUNTU_VERSION_CODE \
b78104db 79 ((LTTNG_LINUX_VERSION_CODE << 8) + UTS_UBUNTU_RELEASE_ABI)
05732a66
MD
80#else
81#define LTTNG_UBUNTU_VERSION_CODE 0
82#endif
3e5941df
JD
83
84#define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
85 a_high, b_high, c_high, d_high) \
05732a66 86 (LTTNG_UBUNTU_VERSION_CODE >= \
3e5941df
JD
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
c94ac1ac
MJ
91/* Debian */
92
72e6c528 93#define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \
b78104db 94 (((LTTNG_KERNEL_VERSION(a, b, c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
72e6c528 95
05732a66 96#ifdef DEBIAN_API_VERSION
72e6c528 97#define LTTNG_DEBIAN_VERSION_CODE \
b78104db 98 ((LTTNG_LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION)
05732a66
MD
99#else
100#define LTTNG_DEBIAN_VERSION_CODE 0
101#endif
72e6c528
MD
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) \
05732a66 105 (LTTNG_DEBIAN_VERSION_CODE >= \
72e6c528
MD
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
c94ac1ac 110#define LTTNG_RHEL_KERNEL_VERSION(a, b, c, d, e, f) \
b78104db 111 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
c94ac1ac
MJ
112
113/* RHEL */
f30ae671 114
c94ac1ac 115#ifdef RHEL_API_VERSION
f30ae671 116#define LTTNG_RHEL_VERSION_CODE \
b78104db 117 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + RHEL_API_VERSION)
f30ae671
MD
118#else
119#define LTTNG_RHEL_VERSION_CODE 0
120#endif
121
c94ac1ac
MJ
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) \
f30ae671 124 (LTTNG_RHEL_VERSION_CODE >= \
c94ac1ac 125 LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
f30ae671 126 LTTNG_RHEL_VERSION_CODE < \
c94ac1ac
MJ
127 LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
128
ce66b486
MJ
129/* SUSE Linux enterprise */
130
131#define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \
b78104db 132 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
ce66b486
MJ
133
134#ifdef SLE_API_VERSION
135#define LTTNG_SLE_VERSION_CODE \
b78104db 136 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + SLE_API_VERSION)
ce66b486
MJ
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
e4838da1
LG
148/* Fedora */
149
150#define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \
b78104db 151 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000ULL) + (d))
e4838da1
LG
152
153#ifdef FEDORA_REVISION_VERSION
154#define LTTNG_FEDORA_VERSION_CODE \
b78104db 155 ((LTTNG_LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION)
e4838da1
LG
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
c94ac1ac 167/* RT patch */
f30ae671 168
b4c8e4d3 169#define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \
b78104db 170 (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d))
b4c8e4d3
MJ
171
172#ifdef RT_PATCH_VERSION
173#define LTTNG_RT_VERSION_CODE \
b78104db 174 ((LTTNG_LINUX_VERSION_CODE << 8) + RT_PATCH_VERSION)
b4c8e4d3
MJ
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
5fa38800 186#endif /* _LTTNG_KERNEL_VERSION_H */
This page took 0.044476 seconds and 4 git commands to generate.