VirtualBox

Changeset 88973 in vbox


Ignore:
Timestamp:
May 11, 2021 10:44:27 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144310
Message:

iprt: introduce Ubuntu kernel version checkers, bugref:10007.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/linux/version.h

    r85709 r88973  
    3232
    3333#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.11. */
     39#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,11))
     40# include <generated/utsrelease.h>
     41# include <iprt/cdefs.h>
     42#endif
    3443
    3544/** @def RTLNX_VER_MIN
     
    116125
    117126
     127#if defined(UTS_UBUNTU_RELEASE_ABI)
     128/** @def RTLNX_UBUNTU_VERSION
     129 * Ubuntu kernels are based on upstream kernels and provide
     130 * version information with regular KERNEL_VERSION() macro. However,
     131 * Ubuntu kernel additionally provides UTS_UBUNTU_RELEASE_ABI macro
     132 * which increases with the kernel update while KERNEL_VERSION() info
     133 * stays the same.
     134 *
     135 * UTS_UBUNTU_RELEASE_ABI does not increase constantly, but rather reset
     136 * when the next kernel update is based on a newer upstream version (i.e.
     137 * KERNEL_VERSION() value has changed). Therefore, in order to compare
     138 * Ubuntu kernels, UTS_UBUNTU_RELEASE_ABI macro is treated as a KERNEL_VERSION()
     139 * extension and appended to the end of it. So, regular 24-bit-value
     140 * of KERNEL_VERSION() becomes 32-bit-value, as can be seen below.
     141 *
     142 * NOTE: @a_iVer is expected to be in range of [0x000000..0xFFFFFF],
     143 * @a_iAbi is expected to be in range of [0x00..0xFF].
     144 *
     145 * @param a_iVer        The 24-bit-value of kernel version number, result
     146 *                      of KERNEL_VERSION() macro.
     147 * @param a_iAbi        8-bit Ubuntu kernel ABI version number.
     148 */
     149# define RTLNX_UBUNTU_VERSION(a_iVer, a_iAbi) \
     150    (((a_iVer) << 8) | (RT_MIN((a_iAbi), 0xFF)))
     151
     152/** @def RTLNX_UBUNTU_MIN
     153 * Require Ubuntu release to be equal or newer than specified version.
     154 * @param a_iMajor      The major kernel version number.
     155 * @param a_iMinor      The minor kernel version number.
     156 * @param a_iPatch      The micro kernel version number.
     157 * @param a_iAbi        Ubuntu kernel ABI version number.
     158 */
     159# define RTLNX_UBUNTU_MIN(a_iMajor, a_iMinor, a_iPatch, a_iAbi) \
     160    (   RTLNX_UBUNTU_VERSION(LINUX_VERSION_CODE, UTS_UBUNTU_RELEASE_ABI) \
     161     >= RTLNX_UBUNTU_VERSION(KERNEL_VERSION(a_iMajor, a_iMinor, a_iPatch), a_iAbi) )
     162
     163/** @def RTLNX_UBUNTU_MAX
     164 * Require Ubuntu release to be older than specified version.
     165 * @param a_iMajor      The major kernel version number.
     166 * @param a_iMinor      The minor kernel version number.
     167 * @param a_iPatch      The micro kernel version number.
     168 * @param a_iAbi        Ubuntu kernel ABI version number.
     169 */
     170# define RTLNX_UBUNTU_MAX(a_iMajor, a_iMinor, a_iPatch, a_iAbi) \
     171    (   RTLNX_UBUNTU_VERSION(LINUX_VERSION_CODE, UTS_UBUNTU_RELEASE_ABI) \
     172     <  RTLNX_UBUNTU_VERSION(KERNEL_VERSION(a_iMajor, a_iMinor, a_iPatch), a_iAbi) )
     173#else /* !UTS_UBUNTU_RELEASE_ABI */
     174# define RTLNX_UBUNTU_MIN(a_iMajor, a_iMinor, a_iPatch, a_iAbi)  (0)
     175# define RTLNX_UBUNTU_MAX(a_iMajor, a_iMinor, a_iPatch, a_iAbi)  (0)
     176#endif /* !UTS_UBUNTU_RELEASE_ABI */
     177
    118178#endif /* !IPRT_INCLUDED_linux_version_h */
    119179
Note: See TracChangeset for help on using the changeset viewer.

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