VirtualBox

Changeset 20531 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 13, 2009 8:54:43 PM (16 years ago)
Author:
vboxsync
Message:

MM: Added MMR3HyperSetGuard for creating guard pages in the hyper heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/MMHyper.cpp

    r19793 r20531  
    7474    /** @todo @bugref{1865}, @bugref{3202}: Change the cbHyperHeap default
    7575     *        depending on whether VT-x/AMD-V is enabled or not! Don't waste
    76      *        precious kernel space on heap for the PATM. 
     76     *        precious kernel space on heap for the PATM.
    7777     */
    7878    uint32_t cbHyperHeap;
     
    868868 * @remark  This is assumed not to be used at times when serialization is required.
    869869 */
    870 VMMDECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
     870VMMR3DECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
    871871{
    872872    AssertMsg(cb >= 8, ("Hey! Do you really mean to allocate less than 8 bytes?! cb=%d\n", cb));
     
    983983
    984984/**
     985 * Lookus up a ring-3 pointer to HMA.
     986 *
     987 * @returns The lookup record on success, NULL on failure.
     988 * @param   pVM                 The VM handle.
     989 * @param   pvR3                The ring-3 address to look up.
     990 */
     991DECLINLINE(PMMLOOKUPHYPER) mmR3HyperLookupR3(PVM pVM, void *pvR3)
     992{
     993    PMMLOOKUPHYPER  pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.pHyperHeapR3 + pVM->mm.s.offLookupHyper);
     994    for (;;)
     995    {
     996        switch (pLookup->enmType)
     997        {
     998            case MMLOOKUPHYPERTYPE_LOCKED:
     999            {
     1000                unsigned off = (uint8_t *)pvR3 - (uint8_t *)pLookup->u.Locked.pvR3;
     1001                if (off < pLookup->cb)
     1002                    return pLookup;
     1003                break;
     1004            }
     1005
     1006            case MMLOOKUPHYPERTYPE_HCPHYS:
     1007            {
     1008                unsigned off = (uint8_t *)pvR3 - (uint8_t *)pLookup->u.HCPhys.pvR3;
     1009                if (off < pLookup->cb)
     1010                    return pLookup;
     1011                break;
     1012            }
     1013
     1014            case MMLOOKUPHYPERTYPE_GCPHYS:
     1015            case MMLOOKUPHYPERTYPE_MMIO2:
     1016            case MMLOOKUPHYPERTYPE_DYNAMIC:
     1017                /** @todo ?    */
     1018                break;
     1019
     1020            default:
     1021                AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
     1022                return NULL;
     1023        }
     1024
     1025        /* next */
     1026        if ((unsigned)pLookup->offNext == NIL_OFFSET)
     1027            return NULL;
     1028        pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
     1029    }
     1030}
     1031
     1032
     1033/**
     1034 * Set / unset guard status on one or more hyper heap pages.
     1035 *
     1036 * @returns VBox status code (first failure).
     1037 * @param   pVM                 The VM handle.
     1038 * @param   pvStart             The hyper heap page address. Must be page
     1039 *                              aligned.
     1040 * @param   cb                  The number of bytes. Must be page aligned.
     1041 * @param   fSet                Wheter to set or unset guard page status.
     1042 */
     1043VMMR3DECL(int) MMR3HyperSetGuard(PVM pVM, void *pvStart, size_t cb, bool fSet)
     1044{
     1045    /*
     1046     * Validate input.
     1047     */
     1048    AssertReturn(!((uintptr_t)pvStart & PAGE_OFFSET_MASK), VERR_INVALID_POINTER);
     1049    AssertReturn(!(cb & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER);
     1050    PMMLOOKUPHYPER pLookup = mmR3HyperLookupR3(pVM, pvStart);
     1051    AssertReturn(pLookup, VERR_INVALID_PARAMETER);
     1052    AssertReturn(pLookup->enmType == MMLOOKUPHYPERTYPE_LOCKED, VERR_INVALID_PARAMETER);
     1053
     1054    /*
     1055     * Get down to business.
     1056     * Note! We quietly ignore errors from the support library since the
     1057     *       protection stuff isn't possible to implement on all platforms.
     1058     */
     1059    uint8_t    *pbR3  = (uint8_t *)pLookup->u.Locked.pvR3;
     1060#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
     1061    RTR0PTR     R0Ptr = VMMIsHwVirtExtForced(pVM) ? pLookup->u.Locked.pvR0 : NIL_RTR0PTR;
     1062#else
     1063    RTR0PTR     R0Ptr = NIL_RTR0PTR; /* ring-0 and ring-3 uses the same mapping. */
     1064#endif
     1065    uint32_t    off   = (uint32_t)((uint8_t *)pvStart - pbR3);
     1066    int         rc;
     1067    if (fSet)
     1068    {
     1069        rc = PGMMapSetPage(pVM, MMHyperR3ToRC(pVM, pvStart), cb, 0);
     1070        SUPR3PageProtect(pbR3, R0Ptr, off, cb, RTMEM_PROT_NONE);
     1071    }
     1072    else
     1073    {
     1074        rc = PGMMapSetPage(pVM, MMHyperR3ToRC(pVM, pvStart), cb, X86_PTE_P | X86_PTE_A | X86_PTE_D | X86_PTE_RW);
     1075        SUPR3PageProtect(pbR3, R0Ptr, off, cb, RTMEM_PROT_READ | RTMEM_PROT_WRITE);
     1076    }
     1077    return rc;
     1078}
     1079
     1080
     1081/**
    9851082 * Convert hypervisor HC virtual address to HC physical address.
    9861083 *
Note: See TracChangeset for help on using the changeset viewer.

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