VirtualBox

Changeset 4971 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Sep 21, 2007 10:19:12 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
24737
Message:

GVM.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDRV.h

    r4833 r4971  
    516516    /** Pointer to the next in the global list. */
    517517    struct SUPDRVOBJ * volatile     pNext;
    518     /** Pointer to the object destructor. */
     518    /** Pointer to the object destructor.
     519     * This may be set to NULL if the image containing the destructor get unloaded. */
    519520    PFNSUPDRVDESTRUCTOR             pfnDestructor;
    520521    /** User argument 1. */
     
    612613{
    613614    /** Spinlock to serialize the initialization,
    614      * usage counting and destruction of the IDT entry override. */
     615     * usage counting and destruction of the IDT entry override and objects. */
    615616    RTSPINLOCK              Spinlock;
    616617
     
    622623#endif
    623624
    624     /** List of registered objects. */
     625    /** List of registered objects. Protected by the spinlock. */
    625626    PSUPDRVOBJ volatile     pObjs;
    626627    /** List of free object usage records. */
  • trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c

    r4965 r4971  
    8888    { "SUPR0ContAlloc",                         (void *)SUPR0ContAlloc },
    8989    { "SUPR0ContFree",                          (void *)SUPR0ContFree },
     90    { "SUPR0LowAlloc",                          (void *)SUPR0LowAlloc },
     91    { "SUPR0LowFree",                           (void *)SUPR0LowFree },
    9092    { "SUPR0MemAlloc",                          (void *)SUPR0MemAlloc },
    9193    { "SUPR0MemGetPhys",                        (void *)SUPR0MemGetPhys },
     
    429431                RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
    430432
    431                 pObj->pfnDestructor(pObj, pObj->pvUser1, pObj->pvUser2);
     433                if (pObj->pfnDestructor)
     434                    pObj->pfnDestructor(pObj, pObj->pvUser1, pObj->pvUser2);
    432435                RTMemFree(pObj);
    433436            }
     
    13151318    {
    13161319        pObj->u32Magic++;
    1317         pObj->pfnDestructor(pObj, pObj->pvUser1, pObj->pvUser2);
     1320        if (pObj->pfnDestructor)
     1321            pObj->pfnDestructor(pObj, pObj->pvUser1, pObj->pvUser2);
    13181322        RTMemFree(pObj);
    13191323    }
     
    31273131static int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq)
    31283132{
     3133    int             rc;
    31293134    PSUPDRVLDRUSAGE pUsagePrev;
    31303135    PSUPDRVLDRUSAGE pUsage;
     
    31533158     * Check if we can remove anything.
    31543159     */
     3160    rc = VINF_SUCCESS;
    31553161    pImage = pUsage->pImage;
    31563162    if (pImage->cUsage <= 1 || pUsage->cUsage <= 1)
    31573163    {
    3158         /* unlink it */
    3159         if (pUsagePrev)
    3160             pUsagePrev->pNext = pUsage->pNext;
     3164        /*
     3165         * Check if there are any objects with destructors in the image, if
     3166         * so leave it for the session cleanup routine so we get a chance to
     3167         * clean things up in the right order and not leave them all dangling.
     3168         */
     3169        RTSPINLOCKTMP   SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
     3170        RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
     3171        if (pImage->cUsage <= 1)
     3172        {
     3173            PSUPDRVOBJ pObj;
     3174            for (pObj = pDevExt->pObjs; pObj; pObj = pObj->pNext)
     3175                if (RT_UNLIKELY((uintptr_t)pObj->pfnDestructor - (uintptr_t)pImage->pvImage < pImage->cbImage))
     3176                {
     3177                    rc = VERR_SHARING_VIOLATION; /** @todo VERR_DANGLING_OBJECTS */
     3178                    break;
     3179                }
     3180        }
    31613181        else
    3162             pSession->pLdrUsage = pUsage->pNext;
    3163         /* free it */
    3164         pUsage->pImage = NULL;
    3165         pUsage->pNext = NULL;
    3166         RTMemFree(pUsage);
    3167 
    3168         /*
    3169          * Derefrence the image.
    3170          */
    3171         if (pImage->cUsage <= 1)
    3172             supdrvLdrFree(pDevExt, pImage);
    3173         else
    3174             pImage->cUsage--;
     3182        {
     3183            PSUPDRVUSAGE pGenUsage;
     3184            for (pGenUsage = pSession->pUsage; pGenUsage; pGenUsage = pGenUsage->pNext)
     3185                if (RT_UNLIKELY((uintptr_t)pGenUsage->pObj->pfnDestructor - (uintptr_t)pImage->pvImage < pImage->cbImage))
     3186                {
     3187                    rc = VERR_SHARING_VIOLATION; /** @todo VERR_DANGLING_OBJECTS */
     3188                    break;
     3189                }
     3190        }
     3191        RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
     3192        if (rc == VINF_SUCCESS)
     3193        {
     3194            /* unlink it */
     3195            if (pUsagePrev)
     3196                pUsagePrev->pNext = pUsage->pNext;
     3197            else
     3198                pSession->pLdrUsage = pUsage->pNext;
     3199
     3200            /* free it */
     3201            pUsage->pImage = NULL;
     3202            pUsage->pNext = NULL;
     3203            RTMemFree(pUsage);
     3204
     3205            /*
     3206             * Derefrence the image.
     3207             */
     3208            if (pImage->cUsage <= 1)
     3209                supdrvLdrFree(pDevExt, pImage);
     3210            else
     3211                pImage->cUsage--;
     3212        }
    31753213    }
    31763214    else
     
    34233461    if (pDevExt->pvVMMR0 == pImage->pvImage)
    34243462        supdrvLdrUnsetR0EP(pDevExt);
     3463
     3464    /* check for objects with destructors in this image. (Shouldn't happen.) */
     3465    if (pDevExt->pObjs)
     3466    {
     3467        unsigned        cObjs = 0;
     3468        PSUPDRVOBJ      pObj;
     3469        RTSPINLOCKTMP   SpinlockTmp = RTSPINLOCKTMP_INITIALIZER;
     3470        RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp);
     3471        for (pObj = pDevExt->pObjs; pObj; pObj = pObj->pNext)
     3472            if (RT_UNLIKELY((uintptr_t)pObj->pfnDestructor - (uintptr_t)pImage->pvImage < pImage->cbImage))
     3473            {
     3474                pObj->pfnDestructor = NULL;
     3475                cObjs++;
     3476            }
     3477        RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp);
     3478        if (cObjs)
     3479            OSDBGPRINT(("supdrvLdrFree: Image '%s' has %d dangling objects!\n", pImage->szName, cObjs));
     3480    }
    34253481
    34263482    /* call termination function if fully loaded. */
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