fix: UTS_UBUNTU_RELEASE_ABI is close to overflow
[lttng-modules.git] / lttng-kernel-version.h
... / ...
CommitLineData
1#ifndef _LTTNG_KERNEL_VERSION_H
2#define _LTTNG_KERNEL_VERSION_H
3
4/*
5 * lttng-kernel-version.h
6 *
7 * Contains helpers to check more complex kernel version conditions.
8 *
9 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#include <linux/version.h>
27
28/*
29 * The following defines are extracted from the toplevel Linux Makefile and
30 * passed on the command line -with '-D'.
31 */
32
33#ifndef LTTNG_LINUX_MAJOR
34#define LTTNG_LINUX_MAJOR 0
35#endif
36
37#ifndef LTTNG_LINUX_MINOR
38#define LTTNG_LINUX_MINOR 0
39#endif
40
41#ifndef LTTNG_LINUX_PATCH
42#define LTTNG_LINUX_PATCH 0
43#endif
44
45/*
46 * Some stable releases have overflowed the 8bits allocated to the sublevel in
47 * the version code. To determine if the current kernel is affected, use the
48 * sublevel version from the Makefile. This is currently true for the 4.4.256
49 * and 4.9.256 stable releases.
50 *
51 * When the sublevel has overflowed, use the values from the Makefile instead
52 * of LINUX_VERSION_CODE from the kernel headers and allocate 16bits.
53 * Otherwise, keep using the version code from the headers to minimise the
54 * behavior change and avoid regressions.
55 */
56#if (LTTNG_LINUX_PATCH >= 256)
57
58#define LTTNG_KERNEL_VERSION(a, b, c) \
59 (((a) << 24) + ((b) << 16) + (c))
60
61#define LTTNG_LINUX_VERSION_CODE \
62 LTTNG_KERNEL_VERSION(LTTNG_LINUX_MAJOR, LTTNG_LINUX_MINOR, LTTNG_LINUX_PATCH)
63
64#else
65
66#define LTTNG_KERNEL_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
67#define LTTNG_LINUX_VERSION_CODE LINUX_VERSION_CODE
68
69#endif
70
71#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33))
72#include <generated/utsrelease.h>
73#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */
74#include <linux/utsrelease.h>
75#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(2,6,33)) */
76
77/*
78 * This macro checks if the kernel version is between the two specified
79 * versions (lower limit inclusive, upper limit exclusive).
80 */
81#define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \
82 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \
83 LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(a_high, b_high, c_high))
84
85/* Ubuntu */
86
87#define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \
88 (((LTTNG_KERNEL_VERSION(a, b, c)) << 16) + (d))
89
90#ifdef UTS_UBUNTU_RELEASE_ABI
91#define LTTNG_UBUNTU_VERSION_CODE \
92 ((LTTNG_LINUX_VERSION_CODE << 16) + UTS_UBUNTU_RELEASE_ABI)
93#else
94#define LTTNG_UBUNTU_VERSION_CODE 0
95#endif
96
97#define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
98 a_high, b_high, c_high, d_high) \
99 (LTTNG_UBUNTU_VERSION_CODE >= \
100 LTTNG_UBUNTU_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
101 LTTNG_UBUNTU_VERSION_CODE < \
102 LTTNG_UBUNTU_KERNEL_VERSION(a_high, b_high, c_high, d_high))
103
104/* Debian */
105
106#define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \
107 (((LTTNG_KERNEL_VERSION(a, b, c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
108
109#ifdef DEBIAN_API_VERSION
110#define LTTNG_DEBIAN_VERSION_CODE \
111 ((LTTNG_LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION)
112#else
113#define LTTNG_DEBIAN_VERSION_CODE 0
114#endif
115
116#define LTTNG_DEBIAN_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
117 a_high, b_high, c_high, d_high, e_high, f_high) \
118 (LTTNG_DEBIAN_VERSION_CODE >= \
119 LTTNG_DEBIAN_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
120 LTTNG_DEBIAN_VERSION_CODE < \
121 LTTNG_DEBIAN_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
122
123#define LTTNG_RHEL_KERNEL_VERSION(a, b, c, d, e, f) \
124 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
125
126/* RHEL */
127
128#ifdef RHEL_API_VERSION
129#define LTTNG_RHEL_VERSION_CODE \
130 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + RHEL_API_VERSION)
131#else
132#define LTTNG_RHEL_VERSION_CODE 0
133#endif
134
135#define LTTNG_RHEL_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
136 a_high, b_high, c_high, d_high, e_high, f_high) \
137 (LTTNG_RHEL_VERSION_CODE >= \
138 LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
139 LTTNG_RHEL_VERSION_CODE < \
140 LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
141
142/* SUSE Linux enterprise */
143
144#define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \
145 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
146
147#ifdef SLE_API_VERSION
148#define LTTNG_SLE_VERSION_CODE \
149 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + SLE_API_VERSION)
150#else
151#define LTTNG_SLE_VERSION_CODE 0
152#endif
153
154#define LTTNG_SLE_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
155 a_high, b_high, c_high, d_high, e_high, f_high) \
156 (LTTNG_SLE_VERSION_CODE >= \
157 LTTNG_SLE_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
158 LTTNG_SLE_VERSION_CODE < \
159 LTTNG_SLE_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
160
161/* Fedora */
162
163#define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \
164 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000ULL) + (d))
165
166#ifdef FEDORA_REVISION_VERSION
167#define LTTNG_FEDORA_VERSION_CODE \
168 ((LTTNG_LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION)
169#else
170#define LTTNG_FEDORA_VERSION_CODE 0
171#endif
172
173#define LTTNG_FEDORA_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
174 a_high, b_high, c_high, d_high) \
175 (LTTNG_FEDORA_VERSION_CODE >= \
176 LTTNG_FEDORA_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
177 LTTNG_FEDORA_VERSION_CODE < \
178 LTTNG_FEDORA_KERNEL_VERSION(a_high, b_high, c_high, d_high))
179
180/* RT patch */
181
182#define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \
183 (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d))
184
185#ifdef RT_PATCH_VERSION
186#define LTTNG_RT_VERSION_CODE \
187 ((LTTNG_LINUX_VERSION_CODE << 8) + RT_PATCH_VERSION)
188#else
189#define LTTNG_RT_VERSION_CODE 0
190#endif
191
192#define LTTNG_RT_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
193 a_high, b_high, c_high, d_high) \
194 (LTTNG_RT_VERSION_CODE >= \
195 LTTNG_RT_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
196 LTTNG_RT_VERSION_CODE < \
197 LTTNG_RT_KERNEL_VERSION(a_high, b_high, c_high, d_high))
198
199#endif /* _LTTNG_KERNEL_VERSION_H */
This page took 0.0254450000000001 seconds and 4 git commands to generate.