VirtualBox

Ignore:
Timestamp:
Jun 9, 2010 12:14:59 PM (14 years ago)
Author:
vboxsync
Message:

iprt/asm.h,*: Revised the ASMAtomic*Ptr functions and macros. The new saves lots of unsafe (void * volatile *) casts as well as adding some type safety when using GCC (typeof rulez).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c

    r30059 r30111  
    171171#ifdef VBOXNETFLT_WITH_QDISC
    172172//#define QDISC_LOG(x) printk x
    173 #define QDISC_LOG(x)
     173#define QDISC_LOG(x) do { } while (0)
    174174
    175175#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
     
    593593#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
    594594        pPriv->ppSaved[0] = pDev->qdisc_sleeping;
    595         ASMAtomicWritePtr((void * volatile *)&pDev->qdisc_sleeping, pNew);
    596         ASMAtomicWritePtr((void * volatile *)&pDev->qdisc, pNew);
     595        ASMAtomicWritePtr(&pDev->qdisc_sleeping, pNew);
     596        ASMAtomicWritePtr(&pDev->qdisc, pNew);
    597597#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) */
    598598        for (i = 0; i < pDev->num_tx_queues; i++)
     
    601601
    602602            pPriv->ppSaved[i] = pQueue->qdisc_sleeping;
    603             ASMAtomicWritePtr((void * volatile *)&pQueue->qdisc_sleeping, pNew);
    604             ASMAtomicWritePtr((void * volatile *)&pQueue->qdisc, pNew);
     603            ASMAtomicWritePtr(&pQueue->qdisc_sleeping, pNew);
     604            ASMAtomicWritePtr(&pQueue->qdisc, pNew);
    605605            if (i)
    606606                atomic_inc(&pNew->refcnt);
     
    609609# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
    610610        pPriv->ppSaved[pDev->num_tx_queues] = pDev->qdisc;
    611         ASMAtomicWritePtr((void * volatile *)&pDev->qdisc, pNew);
     611        ASMAtomicWritePtr(&pDev->qdisc, pNew);
    612612        atomic_inc(&pNew->refcnt);
    613613# endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32) */
     
    619619        pPriv = qdisc_priv(pExisting);
    620620    }
    621     ASMAtomicWritePtr((void * volatile *)&pPriv->pVBoxNetFlt, pThis);
     621    ASMAtomicWritePtr(&pPriv->pVBoxNetFlt, pThis);
    622622    QDISC_LOG(("vboxNetFltLinuxInstallQdisc: pThis=%p\n", pPriv->pVBoxNetFlt));
    623623}
     
    631631    struct Qdisc *pQdisc;
    632632    if (!pDev)
    633         pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     633        pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    634634    if (!VALID_PTR(pDev))
    635635    {
     
    651651    pPriv = qdisc_priv(pQdisc);
    652652    Assert(pPriv->pVBoxNetFlt == pThis);
    653     ASMAtomicWritePtr((void * volatile *)&pPriv->pVBoxNetFlt, NULL);
    654 
    655     QDISC_LOG(("vboxNetFltLinuxQdiscRemove: refcnt=%d num_tx_queues=%d\n", 
     653    ASMAtomicWritePtr(&pPriv->pVBoxNetFlt, NULL);
     654
     655    QDISC_LOG(("vboxNetFltLinuxQdiscRemove: refcnt=%d num_tx_queues=%d\n",
    656656               atomic_read(&pQdisc->refcnt), pDev->num_tx_queues));
    657657#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
     
    659659    if (pPriv->ppSaved[0])
    660660    {
    661         ASMAtomicWritePtr((void * volatile *)&pDev->qdisc_sleeping,
    662                           pPriv->ppSaved[0]);
    663         ASMAtomicWritePtr((void * volatile *)&pDev->qdisc,
    664                           pPriv->ppSaved[0]);
     661        ASMAtomicWritePtr(&pDev->qdisc_sleeping, pPriv->ppSaved[0]);
     662        ASMAtomicWritePtr(&pDev->qdisc, pPriv->ppSaved[0]);
    665663        pPriv->ppSaved[0] = NULL;
    666664        while (QDISC_IS_BUSY(pDev, pQdisc))
     
    675673        {
    676674            Assert(pQueue->qdisc_sleeping == pQdisc);
    677             ASMAtomicWritePtr((void * volatile *)&pQueue->qdisc_sleeping,
    678                               pPriv->ppSaved[i]);
    679             ASMAtomicWritePtr((void * volatile *)&pQueue->qdisc,
    680                               pPriv->ppSaved[i]);
     675            ASMAtomicWritePtr(&pQueue->qdisc_sleeping, pPriv->ppSaved[i]);
     676            ASMAtomicWritePtr(&pQueue->qdisc, pPriv->ppSaved[i]);
    681677            pPriv->ppSaved[i] = NULL;
    682678            while (QDISC_IS_BUSY(pDev, pQdisc))
     
    687683    /* Newer kernels store root qdisc in netdev structure as well. */
    688684#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
    689     ASMAtomicWritePtr((void * volatile *)&pDev->qdisc,
    690                       pPriv->ppSaved[pDev->num_tx_queues]);
     685    ASMAtomicWritePtr(&pDev->qdisc, pPriv->ppSaved[pDev->num_tx_queues]);
    691686    pPriv->ppSaved[pDev->num_tx_queues] = NULL;
    692687    while (QDISC_IS_BUSY(pDev, pQdisc))
     
    912907
    913908    RTSpinlockAcquireNoInts(pThis->hSpinlock, &Tmp); /* (this isn't necessary, but so what) */
    914     ASMAtomicXchgPtr((void * volatile *)&pDev->netdev_ops, pOverride);
     909    ASMAtomicWritePtr((void * volatile *)&pDev->netdev_ops, pOverride);
    915910    RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
    916911}
     
    930925    RTSpinlockAcquireNoInts(pThis->hSpinlock, &Tmp);
    931926    if (!pDev)
    932         pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     927        pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    933928    if (VALID_PTR(pDev))
    934929    {
     
    939934           )
    940935        {
    941             ASMAtomicXchgPtr((void * volatile *)&pDev->netdev_ops, pOverride->pOrgOps);
     936            ASMAtomicWritePtr((void * volatile *)&pDev->netdev_ops, pOverride->pOrgOps);
    942937            ASMAtomicWriteU32(&pOverride->u32Magic, 0);
    943938        }
     
    990985    return pDev;
    991986#else
    992     return (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     987    return ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    993988#endif
    994989}
     
    10601055     * Allocate a packet and copy over the data.
    10611056     */
    1062     pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     1057    pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    10631058    pPkt = dev_alloc_skb(pSG->cbTotal + NET_IP_ALIGN);
    10641059    if (RT_UNLIKELY(!pPkt))
     
    12821277
    12831278    pThis = VBOX_FLT_PT_TO_INST(pPacketType);
    1284     pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     1279    pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    12851280    if (pThis->u.s.pDev != pSkbDev)
    12861281    {
     
    18201815
    18211816        pSwitchPort = pThis->pSwitchPort; /* this doesn't need to be here, but it doesn't harm. */
    1822         pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     1817        pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    18231818        if (pDev)
    18241819            fFeatures = pDev->features;
     
    18871882
    18881883    RTSpinlockAcquireNoInts(pThis->hSpinlock, &Tmp);
    1889     ASMAtomicUoWritePtr((void * volatile *)&pThis->u.s.pDev, pDev);
     1884    ASMAtomicUoWritePtr(&pThis->u.s.pDev, pDev);
    18901885    RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
    18911886
    18921887    Log(("vboxNetFltLinuxAttachToInterface: Device %p(%s) retained. ref=%d\n", pDev, pDev->name, atomic_read(&pDev->refcnt)));
    1893     Log(("vboxNetFltLinuxAttachToInterface: Got pDev=%p pThis=%p pThis->u.s.pDev=%p\n", pDev, pThis, ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev)));
     1888    Log(("vboxNetFltLinuxAttachToInterface: Got pDev=%p pThis=%p pThis->u.s.pDev=%p\n", pDev, pThis, ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *)));
    18941889
    18951890    /* Get the mac address while we still have a valid net_device reference. */
     
    19161911     */
    19171912    RTSpinlockAcquireNoInts(pThis->hSpinlock, &Tmp);
    1918     pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     1913    pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    19191914    if (pDev)
    19201915    {
     
    19511946#endif /* VBOXNETFLT_WITH_QDISC */
    19521947        RTSpinlockAcquireNoInts(pThis->hSpinlock, &Tmp);
    1953         ASMAtomicUoWritePtr((void * volatile *)&pThis->u.s.pDev, NULL);
     1948        ASMAtomicUoWritePtr(&pThis->u.s.pDev, NULL);
    19541949        RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
    19551950        dev_put(pDev);
     
    19781973    ASMAtomicWriteBool(&pThis->u.s.fRegistered, false);
    19791974    ASMAtomicWriteBool(&pThis->fDisconnectedFromHost, true);
    1980     ASMAtomicUoWritePtr((void * volatile *)&pThis->u.s.pDev, NULL);
     1975    ASMAtomicUoWritePtr(&pThis->u.s.pDev, NULL);
    19811976    RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
    19821977
     
    20682063
    20692064    Log(("VBoxNetFlt: got event %s(0x%lx) on %s, pDev=%p pThis=%p pThis->u.s.pDev=%p\n",
    2070          vboxNetFltLinuxGetNetDevEventName(ulEventType), ulEventType, pDev->name, pDev, pThis, ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev)));
     2065         vboxNetFltLinuxGetNetDevEventName(ulEventType), ulEventType, pDev->name, pDev, pThis, ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *)));
    20712066    if (    ulEventType == NETDEV_REGISTER
    20722067        && !strcmp(pDev->name, pThis->szName))
     
    20762071    else
    20772072    {
    2078         pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     2073        pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    20792074        if (pDev == ptr)
    20802075        {
     
    21112106int  vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst)
    21122107{
    2113     NOREF(pvIfData);
    2114 
    21152108    struct net_device * pDev;
    21162109    int err;
    21172110    int rc = VINF_SUCCESS;
     2111    NOREF(pvIfData);
    21182112
    21192113    LogFlow(("vboxNetFltPortOsXmit: pThis=%p (%s)\n", pThis, pThis->szName));
     
    22742268
    22752269    RTSpinlockAcquireNoInts(pThis->hSpinlock, &Tmp);
    2276     pDev = (struct net_device *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.pDev);
     2270    pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    22772271    fRegistered = ASMAtomicUoReadBool(&pThis->u.s.fRegistered);
    22782272    RTSpinlockReleaseNoInts(pThis->hSpinlock, &Tmp);
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