VirtualBox

source: vbox/trunk/include/iprt/linux/version.h@ 99802

Last change on this file since 99802 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/* $Id: version.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Linux kernel version.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_linux_version_h
38#define IPRT_INCLUDED_linux_version_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <linux/version.h>
44
45/* We need utsrelease.h in order to detect Ubuntu kernel,
46 * i.e. check if UTS_UBUNTU_RELEASE_ABI is defined. Support kernels
47 * starting from Ubuntu 14.04 Trusty which is based on upstream
48 * kernel 3.13.x. */
49#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
50# include <generated/utsrelease.h>
51# include <iprt/cdefs.h>
52#endif
53
54/** @def RTLNX_VER_MIN
55 * Evaluates to true if the linux kernel version is equal or higher to the
56 * one specfied. */
57#define RTLNX_VER_MIN(a_Major, a_Minor, a_Patch) \
58 (LINUX_VERSION_CODE >= KERNEL_VERSION(a_Major, a_Minor, a_Patch))
59
60/** @def RTLNX_VER_MAX
61 * Evaluates to true if the linux kernel version is less to the one specfied
62 * (exclusive). */
63#define RTLNX_VER_MAX(a_Major, a_Minor, a_Patch) \
64 (LINUX_VERSION_CODE < KERNEL_VERSION(a_Major, a_Minor, a_Patch))
65
66/** @def RTLNX_VER_RANGE
67 * Evaluates to true if the linux kernel version is equal or higher to the given
68 * minimum version and less (but not equal) to the maximum version (exclusive). */
69#define RTLNX_VER_RANGE(a_MajorMin, a_MinorMin, a_PatchMin, a_MajorMax, a_MinorMax, a_PatchMax) \
70 ( LINUX_VERSION_CODE >= KERNEL_VERSION(a_MajorMin, a_MinorMin, a_PatchMin) \
71 && LINUX_VERSION_CODE < KERNEL_VERSION(a_MajorMax, a_MinorMax, a_PatchMax) )
72
73
74/** @def RTLNX_RHEL_MIN
75 * Require a minium RedHat release.
76 * @param a_iMajor The major release number (RHEL_MAJOR).
77 * @param a_iMinor The minor release number (RHEL_MINOR).
78 * @sa RTLNX_RHEL_MAX, RTLNX_RHEL_RANGE, RTLNX_RHEL_MAJ_PREREQ
79 */
80#if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
81# define RTLNX_RHEL_MIN(a_iMajor, a_iMinor) \
82 ((RHEL_MAJOR) > (a_iMajor) || ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) >= (a_iMinor)))
83#else
84# define RTLNX_RHEL_MIN(a_iMajor, a_iMinor) (0)
85#endif
86
87/** @def RTLNX_RHEL_MAX
88 * Require a maximum RedHat release, true for all RHEL versions below it.
89 * @param a_iMajor The major release number (RHEL_MAJOR).
90 * @param a_iMinor The minor release number (RHEL_MINOR).
91 * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_RANGE, RTLNX_RHEL_MAJ_PREREQ
92 */
93#if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
94# define RTLNX_RHEL_MAX(a_iMajor, a_iMinor) \
95 ((RHEL_MAJOR) < (a_iMajor) || ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) < (a_iMinor)))
96#else
97# define RTLNX_RHEL_MAX(a_iMajor, a_iMinor) (0)
98#endif
99
100/** @def RTLNX_RHEL_RANGE
101 * Check that it's a RedHat kernel in the given version range.
102 * The max version is exclusive, the minimum inclusive.
103 * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_MAX, RTLNX_RHEL_MAJ_PREREQ
104 */
105#if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
106# define RTLNX_RHEL_RANGE(a_iMajorMin, a_iMinorMin, a_iMajorMax, a_iMinorMax) \
107 (RTLNX_RHEL_MIN(a_iMajorMin, a_iMinorMin) && RTLNX_RHEL_MAX(a_iMajorMax, a_iMinorMax))
108#else
109# define RTLNX_RHEL_RANGE(a_iMajorMin, a_iMinorMin, a_iMajorMax, a_iMinorMax) (0)
110#endif
111
112/** @def RTLNX_RHEL_MAJ_PREREQ
113 * Require a minimum minor release number for the given RedHat release.
114 * @param a_iMajor RHEL_MAJOR must _equal_ this.
115 * @param a_iMinor RHEL_MINOR must be greater or equal to this.
116 * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_MAX
117 */
118#if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
119# define RTLNX_RHEL_MAJ_PREREQ(a_iMajor, a_iMinor) ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) >= (a_iMinor))
120#else
121# define RTLNX_RHEL_MAJ_PREREQ(a_iMajor, a_iMinor) (0)
122#endif
123
124
125/** @def RTLNX_SUSE_MAJ_PREREQ
126 * Require a minimum minor release number for the given SUSE release.
127 * @param a_iMajor CONFIG_SUSE_VERSION must _equal_ this.
128 * @param a_iMinor CONFIG_SUSE_PATCHLEVEL must be greater or equal to this.
129 */
130#if defined(CONFIG_SUSE_VERSION) && defined(CONFIG_SUSE_PATCHLEVEL)
131# define RTLNX_SUSE_MAJ_PREREQ(a_iMajor, a_iMinor) ((CONFIG_SUSE_VERSION) == (a_iMajor) && (CONFIG_SUSE_PATCHLEVEL) >= (a_iMinor))
132#else
133# define RTLNX_SUSE_MAJ_PREREQ(a_iMajor, a_iMinor) (0)
134#endif
135
136
137#if defined(UTS_UBUNTU_RELEASE_ABI) || defined(DOXYGEN_RUNNING)
138
139/** Hack to make the UTS_UBUNTU_RELEASE_ABI palatable by the C preprocesor.
140 *
141 * While the Ubuntu kernel ABI version looks like a decimal number, some
142 * kernels has a leading zero (e.g. 050818) that makes the preprocessor think
143 * it's an octal number. To work around that, we turn it into an hexadecimal
144 * number by prefixing it with '0x'. */
145# define RTLNX_UBUNTU_ABI(a_iAbi) (RT_CONCAT(0x,a_iAbi))
146
147/** @def RTLNX_UBUNTU_ABI_MIN
148 * Require Ubuntu release ABI to be equal or newer than specified version.
149 *
150 * The kernel version should exactly match the specified @a a_iMajor, @a
151 * a_iMinor and @a a_iPatch. The @a a_iAbi number should be equal to or greater
152 * than the current ABI version.
153 *
154 * @param a_iMajor The major kernel version number.
155 * @param a_iMinor The minor kernel version number.
156 * @param a_iPatch The kernel patch level.
157 * @param a_iAbi Ubuntu kernel ABI version number (inclusive).
158 */
159# define RTLNX_UBUNTU_ABI_MIN(a_iMajor, a_iMinor, a_iPatch, a_iAbi) \
160 ( KERNEL_VERSION(a_iMajor, a_iMinor, a_iPatch) == LINUX_VERSION_CODE \
161 && RTLNX_UBUNTU_ABI(UTS_UBUNTU_RELEASE_ABI) >= RTLNX_UBUNTU_ABI(a_iAbi))
162
163/** @def RTLNX_UBUNTU_ABI_MAX
164 * Require Ubuntu release ABI to be older than specified version.
165 *
166 * The kernel version should exactly match the specified @a a_iMajor, @a
167 * a_iMinor and @a a_iPatch. The @a a_iAbi number should be less than the
168 * current ABI version.
169 *
170 * @param a_iMajor The major kernel version number.
171 * @param a_iMinor The minor kernel version number.
172 * @param a_iPatch The kernel patch level.
173 * @param a_iAbi Ubuntu kernel ABI version number (exclusive).
174 */
175# define RTLNX_UBUNTU_ABI_MAX(a_iMajor, a_iMinor, a_iPatch, a_iAbi) \
176 ( KERNEL_VERSION(a_iMajor, a_iMinor, a_iPatch) == LINUX_VERSION_CODE \
177 && RTLNX_UBUNTU_ABI(UTS_UBUNTU_RELEASE_ABI) < RTLNX_UBUNTU_ABI(a_iAbi))
178
179/** @def RTLNX_UBUNTU_ABI_RANGE
180 * Require Ubuntu release ABI to be in specified range.
181 *
182 * The kernel version should exactly match the specified @a a_iMajor, @a
183 * a_iMinor and @a a_iPatch. The numbers @a a_iAbiMin and @a a_iAbiMax specify
184 * ABI versions range. The max ABI version is exclusive, the minimum inclusive.
185 *
186 * @param a_iMajor The major kernel version number.
187 * @param a_iMinor The minor kernel version number.
188 * @param a_iPatch The kernel patch level.
189 * @param a_iAbiMin The minimum Ubuntu kernel ABI version number (inclusive).
190 * @param a_iAbiMax The maximum Ubuntu kernel ABI version number (exclusive).
191 */
192# define RTLNX_UBUNTU_ABI_RANGE(a_iMajor, a_iMinor, a_iPatch, a_iAbiMin, a_iAbiMax) \
193 ( RTLNX_UBUNTU_ABI_MIN(a_iMajor, a_iMinor, a_iPatch, a_iAbiMin) \
194 && RTLNX_UBUNTU_ABI_MAX(a_iMajor, a_iMinor, a_iPatch, a_iAbiMax))
195
196#else /* !UTS_UBUNTU_RELEASE_ABI */
197
198# define RTLNX_UBUNTU_ABI_MIN(a_iMajor, a_iMinor, a_iPatch, a_iAbi) (0)
199# define RTLNX_UBUNTU_ABI_MAX(a_iMajor, a_iMinor, a_iPatch, a_iAbi) (0)
200# define RTLNX_UBUNTU_ABI_RANGE(a_iMajorMin, a_iMinorMin, a_iPatchMin, a_iAbiMin, a_iAbiMax) (0)
201
202#endif /* !UTS_UBUNTU_RELEASE_ABI */
203
204#endif /* !IPRT_INCLUDED_linux_version_h */
205
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette