VirtualBox

Ignore:
Timestamp:
Mar 24, 2025 6:53:21 PM (4 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168147
Message:

HostDrivers/Support: Make SUPR3 work on hosts where the page size is not known during compile time, bugref:10391

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/linux/SUPLib-linux.cpp

    r106061 r108724  
    6464#include <VBox/types.h>
    6565#include <iprt/string.h>
    66 #include <iprt/system.h>
    6766#include <VBox/err.h>
    6867#include <VBox/param.h>
     
    10099     * Check if madvise works.
    101100     */
    102     void *pv = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     101    uint32_t const cbPage = SUP_PAGE_SIZE;
     102    void *pv = mmap(NULL, cbPage, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    103103    if (pv == MAP_FAILED)
    104104        return VERR_NO_MEMORY;
    105     pThis->fSysMadviseWorks = (0 == madvise(pv, PAGE_SIZE, MADV_DONTFORK));
    106     munmap(pv, PAGE_SIZE);
     105    pThis->fSysMadviseWorks = (0 == madvise(pv, cbPage, MADV_DONTFORK));
     106    munmap(pv, cbPage);
    107107
    108108    /*
     
    256256#endif
    257257
    258     size_t cbMmap = cPages << PAGE_SHIFT;
     258    uint32_t const cbPage = SUP_PAGE_SIZE;
     259    uint32_t const cPageShift = SUP_PAGE_SHIFT;
     260
     261    size_t cbMmap = cPages << cPageShift;
    259262    if (   !pThis->fSysMadviseWorks
    260263        && (fFlags & (SUP_PAGE_ALLOC_F_FOR_LOCKING | SUP_PAGE_ALLOC_F_LARGE_PAGES)) == SUP_PAGE_ALLOC_F_FOR_LOCKING)
    261         cbMmap += PAGE_SIZE * 2;
     264        cbMmap += cbPage * 2;
    262265
    263266    uint8_t *pbPages = (uint8_t *)mmap(NULL, cbMmap, PROT_READ | PROT_WRITE, fMmap, -1, 0);
     
    268271        fMmap &= ~MAP_HUGETLB;
    269272        if (!pThis->fSysMadviseWorks && (fFlags & SUP_PAGE_ALLOC_F_FOR_LOCKING))
    270             cbMmap = (cPages + 2) << PAGE_SHIFT;
     273            cbMmap = (cPages + 2) << cPageShift;
    271274        pbPages = (uint8_t *)mmap(NULL, cbMmap, PROT_READ | PROT_WRITE, fMmap, -1, 0);
    272275    }
     
    313316             * area struct of the very same size as the mmap area.
    314317             */
    315             mprotect(pbPages,                      PAGE_SIZE, PROT_NONE);
    316             mprotect(pbPages + cbMmap - PAGE_SIZE, PAGE_SIZE, PROT_NONE);
    317             pbPages += PAGE_SHIFT;
     318            mprotect(pbPages,                   cbPage, PROT_NONE);
     319            mprotect(pbPages + cbMmap - cbPage, cbPage, PROT_NONE);
     320            pbPages += cPageShift;
    318321        }
    319322
     
    322325         * so I qualified it with SUP_PAGE_ALLOC_F_FOR_LOCKING (unused) for now... */
    323326        if (fFlags & SUP_PAGE_ALLOC_F_FOR_LOCKING)
    324             memset(pbPages, 0, cPages << PAGE_SHIFT);
     327            memset(pbPages, 0, cPages << cPageShift);
    325328
    326329        *ppvPages = pbPages;
     
    334337{
    335338    NOREF(pThis);
    336     munmap(pvPages, cPages << PAGE_SHIFT);
     339    munmap(pvPages, cPages << SUP_PAGE_SHIFT);
    337340    return VINF_SUCCESS;
    338341}
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