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