VirtualBox

Changeset 108673 in vbox


Ignore:
Timestamp:
Mar 20, 2025 6:18:43 PM (8 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168086
Message:

VMM/VMMR3/GVMMR3.cpp: Make it work for hosts where we don't know the host page size when building, bugref:10391

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/GVMMR3.cpp

    r107900 r108673  
    3939
    4040#include <iprt/mem.h>
     41#include <iprt/system.h>
    4142
    4243
     
    5859    AssertReturn(cCpus >= VMM_MIN_CPU_COUNT && cCpus <= VMM_MAX_CPU_COUNT, VERR_INVALID_PARAMETER);
    5960    AssertReturn(enmTarget == VMTARGET_X86 || enmTarget == VMTARGET_ARMV8, VERR_INVALID_PARAMETER);
    60     AssertCompile((sizeof(VM)    & HOST_PAGE_OFFSET_MASK) == 0);
    61     AssertCompile((sizeof(VMCPU) & HOST_PAGE_OFFSET_MASK) == 0);
     61    AssertReturn((sizeof(VM)    & RTSystemGetPageOffsetMask()) == 0, VERR_UNSUPPORTED_ALIGNMENT);
     62    AssertReturn((sizeof(VMCPU) & RTSystemGetPageOffsetMask()) == 0, VERR_UNSUPPORTED_ALIGNMENT);
    6263
    6364    int rc;
     
    9091         */
    9192        /* Allocate the VM structure: */
     93        size_t const cbPageSize = RTSystemGetPageSize();
    9294        size_t const cbVM = sizeof(VM) + sizeof(VMCPU) * cCpus;
    93         PVM          pVM  = (PVM)RTMemPageAlloc(cbVM + HOST_PAGE_SIZE * (1 + 2 * cCpus));
     95        PVM          pVM  = (PVM)RTMemPageAlloc(cbVM + cbPageSize * (1 + 2 * cCpus));
    9496        if (!pVM)
    9597            return VERR_NO_PAGE_MEMORY;
    9698
    9799        /* Set up guard pages: */
    98         RTMemProtect(pVM, HOST_PAGE_SIZE, RTMEM_PROT_NONE);
    99         pVM = (PVM)((uintptr_t)pVM + HOST_PAGE_SIZE);
    100         RTMemProtect(pVM + 1, HOST_PAGE_SIZE, RTMEM_PROT_NONE);
     100        RTMemProtect(pVM, cbPageSize, RTMEM_PROT_NONE);
     101        pVM = (PVM)((uintptr_t)pVM + cbPageSize);
     102        RTMemProtect(pVM + 1, cbPageSize, RTMEM_PROT_NONE);
    101103
    102104        /* VM: */
     
    113115
    114116        /* CPUs: */
    115         PVMCPU pVCpu = (PVMCPU)((uintptr_t)pVM + sizeof(VM) + HOST_PAGE_SIZE);
     117        PVMCPU pVCpu = (PVMCPU)((uintptr_t)pVM + sizeof(VM) + cbPageSize);
    116118        for (VMCPUID idxCpu = 0; idxCpu < cCpus; idxCpu++)
    117119        {
     
    125127            pVCpu->idCpu           = idxCpu;
    126128
    127             RTMemProtect(pVCpu + 1, HOST_PAGE_SIZE, RTMEM_PROT_NONE);
    128             pVCpu = (PVMCPU)((uintptr_t)pVCpu + sizeof(VMCPU) + HOST_PAGE_SIZE);
     129            RTMemProtect(pVCpu + 1, cbPageSize, RTMEM_PROT_NONE);
     130            pVCpu = (PVMCPU)((uintptr_t)pVCpu + sizeof(VMCPU) + cbPageSize);
    129131        }
    130132
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