VirtualBox

Ignore:
Timestamp:
Aug 11, 2020 5:05:29 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139838
Message:

IPRT,lnx-kmods: Use new linux kernel version checking macros. Moved them to separate wrapper header.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c

    r85516 r85698  
    5757 * This is a must for 5.8+, but we enable it all the way back to 3.2.x for
    5858 * better W^R compliance (fExecutable flag). */
    59 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0) || defined(DOXYGEN_RUNNING)
     59#if RTLNX_VER_MIN(3,2,0) || defined(DOXYGEN_RUNNING)
    6060# define IPRT_USE_ALLOC_VM_AREA_FOR_EXEC
    6161#endif
     
    6666 * It should be safe to use vm_insert_page() older kernels as well.
    6767 */
    68 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
     68#if RTLNX_VER_MIN(2,6,23)
    6969# define VBOX_USE_INSERT_PAGE
    7070#endif
    7171#if    defined(CONFIG_X86_PAE) \
    7272    && (   defined(HAVE_26_STYLE_REMAP_PAGE_RANGE) \
    73         || (   LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) \
    74             && LINUX_VERSION_CODE <  KERNEL_VERSION(2, 6, 11)))
     73        || RTLNX_VER_RANGE(2,6,0,  2,6,11) )
    7574# define VBOX_USE_PAE_HACK
    7675#endif
    7776
    7877/* gfp_t was introduced in 2.6.14, define it for earlier. */
    79 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14)
     78#if RTLNX_VER_MAX(2,6,14)
    8079# define gfp_t  unsigned
    8180#endif
     
    8483 * Wrappers around mmap_lock/mmap_sem difference.
    8584 */
    86 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0)
     85#if RTLNX_VER_MIN(5,8,0)
    8786# define LNX_MM_DOWN_READ(a_pMm)    down_read(&(a_pMm)->mmap_lock)
    8887# define LNX_MM_UP_READ(a_pMm)        up_read(&(a_pMm)->mmap_lock)
     
    252251    if (R3PtrFixed != (RTR3PTR)-1)
    253252    {
    254 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
     253#if RTLNX_VER_MIN(3,5,0)
    255254        ulAddr = vm_mmap(NULL, R3PtrFixed, cb, fLnxProt, MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, 0);
    256255#else
     
    262261    else
    263262    {
    264 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
     263#if RTLNX_VER_MIN(3,5,0)
    265264        ulAddr = vm_mmap(NULL, 0, cb, fLnxProt, MAP_SHARED | MAP_ANONYMOUS, 0);
    266265#else
     
    298297static void rtR0MemObjLinuxDoMunmap(void *pv, size_t cb, struct task_struct *pTask)
    299298{
    300 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
     299#if RTLNX_VER_MIN(3,5,0)
    301300    Assert(pTask == current); RT_NOREF_PV(pTask);
    302301    vm_munmap((unsigned long)pv, cb);
     
    359358     * For small allocations we'll try contiguous first and then fall back on page by page.
    360359     */
    361 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
     360#if RTLNX_VER_MIN(2,4,22)
    362361    if (    fContiguous
    363362        ||  cb <= PAGE_SIZE * 2)
     
    418417    pMemLnx->fExecutable = fExecutable;
    419418
    420 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
     419#if RTLNX_VER_MAX(4,5,0)
    421420    /*
    422421     * Reserve the pages.
     
    475474        while (iPage-- > 0)
    476475        {
    477 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
     476#if RTLNX_VER_MAX(4,5,0)
    478477            /* See SetPageReserved() in rtR0MemObjLinuxAllocPages() */
    479478            ClearPageReserved(pMemLnx->apPages[iPage]);
    480479#endif
    481 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 22)
     480#if RTLNX_VER_MAX(2,4,22)
    482481            if (pMemLnx->fExecutable)
    483482                MY_SET_PAGES_NOEXEC(pMemLnx->apPages[iPage], 1);
     
    488487         * Free the pages.
    489488         */
    490 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
     489#if RTLNX_VER_MIN(2,4,22)
    491490        if (!pMemLnx->fContiguous)
    492491        {
     
    545544         * Use vmap - 2.4.22 and later.
    546545         */
    547 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
     546#if RTLNX_VER_MIN(2,4,22)
    548547        pgprot_t fPg;
    549548        pgprot_val(fPg) = _PAGE_PRESENT | _PAGE_RW;
     
    620619static void rtR0MemObjLinuxVUnmap(PRTR0MEMOBJLNX pMemLnx)
    621620{
    622 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
     621#if RTLNX_VER_MIN(2,4,22)
    623622# ifdef IPRT_USE_ALLOC_VM_AREA_FOR_EXEC
    624623    if (pMemLnx->pArea)
     
    683682                    if (!PageReserved(pMemLnx->apPages[iPage]))
    684683                        SetPageDirty(pMemLnx->apPages[iPage]);
    685 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
     684#if RTLNX_VER_MIN(4,6,0)
    686685                    put_page(pMemLnx->apPages[iPage]);
    687686#else
     
    746745    int rc;
    747746
    748 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
     747#if RTLNX_VER_MIN(2,4,22)
    749748    rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_PAGE, cb, PAGE_SIZE, GFP_HIGHUSER,
    750749                                   false /* non-contiguous */, fExecutable, VERR_NO_MEMORY);
     
    995994    {
    996995        pgd_t       Global;
    997 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
     996#if RTLNX_VER_MIN(4,12,0)
    998997        p4d_t       Four;
    999998#endif
    1000 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
     999#if RTLNX_VER_MIN(2,6,11)
    10011000        pud_t       Upper;
    10021001#endif
     
    10131012    if (RT_UNLIKELY(pgd_none(u.Global)))
    10141013        return NULL;
    1015 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
    1016 # if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
     1014#if RTLNX_VER_MIN(2,6,11)
     1015# if RTLNX_VER_MIN(4,12,0)
    10171016    u.Four  = *p4d_offset(&u.Global, ulAddr);
    10181017    if (RT_UNLIKELY(p4d_none(u.Four)))
     
    10331032    if (RT_UNLIKELY(pud_none(u.Upper)))
    10341033        return NULL;
    1035 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
     1034# if RTLNX_VER_MIN(2,6,25)
    10361035    if (pud_large(u.Upper))
    10371036    {
     
    10491048    if (RT_UNLIKELY(pmd_none(u.Middle)))
    10501049        return NULL;
    1051 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
     1050#if RTLNX_VER_MIN(2,6,0)
    10521051    if (pmd_large(u.Middle))
    10531052    {
     
    10601059#endif
    10611060
    1062 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 5) || defined(pte_offset_map) /* As usual, RHEL 3 had pte_offset_map earlier. */
     1061#if RTLNX_VER_MIN(2,5,5) || defined(pte_offset_map) /* As usual, RHEL 3 had pte_offset_map earlier. */
    10631062    pEntry = pte_offset_map(&u.Middle, ulAddr);
    10641063#else
     
    10681067        return NULL;
    10691068    u.Entry = *pEntry;
    1070 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 5) || defined(pte_offset_map)
     1069#if RTLNX_VER_MIN(2,5,5) || defined(pte_offset_map)
    10711070    pte_unmap(pEntry);
    10721071#endif
     
    11201119
    11211120/* openSUSE Leap 42.3 detection :-/ */
    1122 #if    LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) \
    1123     && LINUX_VERSION_CODE <  KERNEL_VERSION(4, 6, 0) \
    1124     && defined(FAULT_FLAG_REMOTE)
     1121#if RTLNX_VER_RANGE(4,4,0,  4,6,0) && defined(FAULT_FLAG_REMOTE)
    11251122# define GET_USER_PAGES_API     KERNEL_VERSION(4, 10, 0) /* no typo! */
    11261123#else
     
    11341131    struct task_struct *pTask = rtR0ProcessToLinuxTask(R0Process);
    11351132    struct vm_area_struct **papVMAs;
    1136     PRTR0MEMOBJLNX pMemLnx;
     1133    PRTR0MEMOBJLNX  pMemLnx;
    11371134    int             rc      = VERR_NO_MEMORY;
    11381135    int  const      fWrite  = fAccess & RTMEM_PROT_WRITE ? 1 : 0;
     
    12091206                                cPages,                 /* How many pages. */
    12101207/* The get_user_pages API change was back-ported to 4.4.168. */
    1211 # if    LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 168) \
    1212       && LINUX_VERSION_CODE <  KERNEL_VERSION(4, 5, 0)
     1208# if RTLNX_VER_RANGE(4,4,168,  4,5,0)
    12131209                                fWrite ? FOLL_WRITE |   /* Write to memory. */
    12141210                                         FOLL_FORCE     /* force write access. */
     
    12651261            if (!PageReserved(pMemLnx->apPages[rc]))
    12661262                SetPageDirty(pMemLnx->apPages[rc]);
    1267 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
     1263#if RTLNX_VER_MIN(4,6,0)
    12681264            put_page(pMemLnx->apPages[rc]);
    12691265#else
     
    13751371DECLHIDDEN(int) rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
    13761372{
    1377 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
     1373#if RTLNX_VER_MIN(2,4,22)
    13781374    IPRT_LINUX_SAVE_EFL_AC();
    13791375    const size_t cPages = cb >> PAGE_SHIFT;
     
    15001496        if (pMemLnxToMap->cPages)
    15011497        {
    1502 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
     1498#if RTLNX_VER_MIN(2,4,22)
    15031499            /*
    15041500             * Use vmap - 2.4.22 and later.
     
    15451541             */
    15461542            Assert(pMemLnxToMap->Core.enmType == RTR0MEMOBJTYPE_PHYS && !pMemLnxToMap->Core.u.Phys.fAllocated);
    1547 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
     1543#if RTLNX_VER_MIN(2,6,25)
    15481544            /*
    15491545             * ioremap() defaults to no caching since the 2.6 kernels.
     
    16951691                for (iPage = offSub >> PAGE_SHIFT; iPage < cPages; iPage++, ulAddrCur += PAGE_SIZE)
    16961692                {
    1697 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
     1693#if RTLNX_VER_MAX(2,6,11)
    16981694                    RTHCPHYS Phys = page_to_phys(pMemLnxToMap->apPages[iPage]);
    16991695#endif
    1700 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
     1696#if RTLNX_VER_MIN(2,6,0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
    17011697                    struct vm_area_struct *vma = find_vma(pTask->mm, ulAddrCur); /* this is probably the same for all the pages... */
    17021698                    AssertBreakStmt(vma, rc = VERR_INTERNAL_ERROR);
    17031699#endif
    1704 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) && defined(RT_ARCH_X86)
     1700#if RTLNX_VER_MAX(2,6,0) && defined(RT_ARCH_X86)
    17051701                    /* remap_page_range() limitation on x86 */
    17061702                    AssertBreakStmt(Phys < _4G, rc = VERR_NO_MEMORY);
    17071703#endif
    17081704
    1709 #if   defined(VBOX_USE_INSERT_PAGE) && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
     1705#if   defined(VBOX_USE_INSERT_PAGE) && RTLNX_VER_MIN(2,6,22)
    17101706                    rc = vm_insert_page(vma, ulAddrCur, pMemLnxToMap->apPages[iPage]);
    17111707                    /* Thes flags help making 100% sure some bad stuff wont happen (swap, core, ++).
    17121708                     * See remap_pfn_range() in mm/memory.c */
    1713 #if    LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
     1709#if    RTLNX_VER_MIN(3,7,0)
    17141710                    vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
    17151711#else
    17161712                    vma->vm_flags |= VM_RESERVED;
    17171713#endif
    1718 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
     1714#elif RTLNX_VER_MIN(2,6,11)
    17191715                    rc = remap_pfn_range(vma, ulAddrCur, page_to_pfn(pMemLnxToMap->apPages[iPage]), PAGE_SIZE, fPg);
    17201716#elif defined(VBOX_USE_PAE_HACK)
     
    17221718                    if (!rc)
    17231719                        rc = rtR0MemObjLinuxFixPte(pTask->mm, ulAddrCur, Phys);
    1724 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
     1720#elif RTLNX_VER_MIN(2,6,0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
    17251721                    rc = remap_page_range(vma, ulAddrCur, Phys, PAGE_SIZE, fPg);
    17261722#else /* 2.4 */
     
    17501746                    for (iPage = offSub >> PAGE_SHIFT; iPage < cPages; iPage++, ulAddrCur += PAGE_SIZE, Phys += PAGE_SIZE)
    17511747                    {
    1752 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
     1748#if RTLNX_VER_MIN(2,6,0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
    17531749                        struct vm_area_struct *vma = find_vma(pTask->mm, ulAddrCur); /* this is probably the same for all the pages... */
    17541750                        AssertBreakStmt(vma, rc = VERR_INTERNAL_ERROR);
    17551751#endif
    1756 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) && defined(RT_ARCH_X86)
     1752#if RTLNX_VER_MAX(2,6,0) && defined(RT_ARCH_X86)
    17571753                        /* remap_page_range() limitation on x86 */
    17581754                        AssertBreakStmt(Phys < _4G, rc = VERR_NO_MEMORY);
    17591755#endif
    17601756
    1761 #if   LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
     1757#if   RTLNX_VER_MIN(2,6,11)
    17621758                        rc = remap_pfn_range(vma, ulAddrCur, Phys, PAGE_SIZE, fPg);
    17631759#elif defined(VBOX_USE_PAE_HACK)
     
    17651761                        if (!rc)
    17661762                            rc = rtR0MemObjLinuxFixPte(pTask->mm, ulAddrCur, Phys);
    1767 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
     1763#elif RTLNX_VER_MIN(2,6,0) || defined(HAVE_26_STYLE_REMAP_PAGE_RANGE)
    17681764                        rc = remap_page_range(vma, ulAddrCur, Phys, PAGE_SIZE, fPg);
    17691765#else /* 2.4 */
     
    17801776
    17811777#ifdef CONFIG_NUMA_BALANCING
    1782 # if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
     1778# if RTLNX_VER_MAX(3,13,0)
    17831779#  ifdef RHEL_RELEASE_CODE
    17841780#   if RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7, 0)
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