VirtualBox

Changeset 22461 in vbox for trunk


Ignore:
Timestamp:
Aug 26, 2009 9:50:17 AM (15 years ago)
Author:
vboxsync
Message:

DevPS2: Protect the internal device state with a PDM critsect.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Input/DevPS2.cpp

    r22277 r22461  
    230230    /** Pointer to the device instance. */
    231231    PPDMDEVINSR0                pDevInsR0;
     232    /** Critical section protecting the state. */
     233    PDMCRITSECT                 CritSect;
    232234    /**
    233235     * Keyboard port - LUN#0.
     
    288290    {
    289291        s->status |= KBD_STAT_OBF;
    290         if ((s->mode & KBD_MODE_KBD_INT) && !(s->mode & KBD_MODE_DISABLE_KBD))
     292        if ((s->mode & KBD_MODE_KBD_INT) /*&& !(s->mode & KBD_MODE_DISABLE_KBD)*/)
    291293            irq1_level = 1;
    292294    }
     
    12981300    if (cb == 1)
    12991301    {
    1300         *pu32 = kbd_read_data(PDMINS_2_DATA(pDevIns, KBDState *), Port);
    1301         Log2(("kbdIOPortDataRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32));
    1302         return VINF_SUCCESS;
     1302        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
     1303        int rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_READ);
     1304        if (RT_LIKELY(rc == VINF_SUCCESS))
     1305        {
     1306            *pu32 = kbd_read_data(pThis, Port);
     1307            PDMCritSectLeave(&pThis->CritSect);
     1308            Log2(("kbdIOPortDataRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32));
     1309        }
     1310        return rc;
    13031311    }
    13041312    AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
     
    13231331    if (cb == 1)
    13241332    {
    1325         rc = kbd_write_data(PDMINS_2_DATA(pDevIns, KBDState *), Port, u32);
    1326         Log2(("kbdIOPortDataWrite: Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
     1333        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
     1334        rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_WRITE);
     1335        if (RT_LIKELY(rc == VINF_SUCCESS))
     1336        {
     1337            rc = kbd_write_data(pThis, Port, u32);
     1338            PDMCritSectLeave(&pThis->CritSect);
     1339            Log2(("kbdIOPortDataWrite: Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
     1340        }
    13271341    }
    13281342    else
     
    13471361    if (cb == 1)
    13481362    {
    1349         *pu32 = kbd_read_status(PDMINS_2_DATA(pDevIns, KBDState *), Port);
    1350         Log2(("kbdIOPortStatusRead: Port=%#x cb=%d -> *pu32=%#x\n", Port, cb, *pu32));
    1351         return VINF_SUCCESS;
     1363        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
     1364        int rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_READ);
     1365        if (RT_LIKELY(rc == VINF_SUCCESS))
     1366        {
     1367            *pu32 = kbd_read_status(pThis, Port);
     1368            PDMCritSectLeave(&pThis->CritSect);
     1369            Log2(("kbdIOPortStatusRead: Port=%#x cb=%d -> *pu32=%#x\n", Port, cb, *pu32));
     1370        }
     1371        return rc;
    13521372    }
    13531373    AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
     
    13681388PDMBOTHCBDECL(int) kbdIOPortCommandWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
    13691389{
     1390    int rc = VINF_SUCCESS;
    13701391    NOREF(pvUser);
    13711392    if (cb == 1)
    13721393    {
    1373         int rc = kbd_write_command(PDMINS_2_DATA(pDevIns, KBDState *), Port, u32);
    1374         Log2(("kbdIOPortCommandWrite: Port=%#x cb=%d u32=%#x rc=%Rrc\n", Port, cb, u32, rc));
    1375         return rc;
    1376     }
    1377     AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
    1378     return VINF_SUCCESS;
     1394        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
     1395        rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_WRITE);
     1396        if (RT_LIKELY(rc == VINF_SUCCESS))
     1397        {
     1398            rc = kbd_write_command(pThis, Port, u32);
     1399            PDMCritSectLeave(&pThis->CritSect);
     1400            Log2(("kbdIOPortCommandWrite: Port=%#x cb=%d u32=%#x rc=%Rrc\n", Port, cb, u32, rc));
     1401        }
     1402    }
     1403    else
     1404        AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
     1405    return rc;
    13791406}
    13801407
     
    14601487{
    14611488    KBDState *pThis = IKEYBOARDPORT_2_KBDSTATE(pInterface);
     1489    int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
     1490    AssertReleaseRC(rc);
    14621491    pc_kbd_put_keycode(pThis, u8KeyCode);
     1492    PDMCritSectLeave(&pThis->CritSect);
    14631493    return VINF_SUCCESS;
    14641494}
     
    15081538{
    15091539    KBDState *pThis = IMOUSEPORT_2_KBDSTATE(pInterface);
     1540    int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
     1541    AssertReleaseRC(rc);
    15101542    pc_kbd_mouse_event(pThis, i32DeltaX, i32DeltaY, i32DeltaZ, fButtonStates);
     1543    PDMCritSectLeave(&pThis->CritSect);
    15111544    return VINF_SUCCESS;
    15121545}
     
    16461679}
    16471680
     1681/**
     1682 * Destruct a device instance for a VM.
     1683 *
     1684 * @returns VBox status.
     1685 * @param   pDevIns     The device instance data.
     1686 */
     1687static DECLCALLBACK(int) kbdDestruct(PPDMDEVINS pDevIns)
     1688{
     1689    KBDState   *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
     1690    PDMR3CritSectDelete(&pThis->CritSect);
     1691
     1692    return VINF_SUCCESS;
     1693}
    16481694
    16491695/**
     
    16931739    pThis->Mouse.Base.pfnQueryInterface     = kbdMouseQueryInterface;
    16941740    pThis->Mouse.Port.pfnPutEvent           = kbdMousePutEvent;
     1741
     1742    /*
     1743     * Initialize the critical section.
     1744     */
     1745    char szName[24];
     1746    RTStrPrintf(szName, sizeof(szName), "PS2KM#%d", iInstance);
     1747    rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, szName);
     1748    if (RT_FAILURE(rc))
     1749        return rc;
    16951750
    16961751    /*
     
    17741829    kbdConstruct,
    17751830    /* pfnDestruct */
    1776     NULL,
     1831    kbdDestruct,
    17771832    /* pfnRelocate */
    17781833    kdbRelocate,
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