VirtualBox

Changeset 82148 in vbox for trunk/src


Ignore:
Timestamp:
Nov 24, 2019 4:24:54 PM (5 years ago)
Author:
vboxsync
Message:

VirtualKD: Converted to new style. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Misc/VirtualKD.cpp

    r81591 r82148  
    4141*   Structures and Typedefs                                                                                                      *
    4242*********************************************************************************************************************************/
    43 
    4443typedef struct VKDREQUESTHDR
    4544{
     
    7776
    7877
    79 /*********************************************************************************************************************************
    80 *   Internal Functions                                                                                                           *
    81 *********************************************************************************************************************************/
    82 
    83 static DECLCALLBACK(int) vkdPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
    84 {
    85     RT_NOREF(pvUser, Port, cb);
     78
     79
     80static DECLCALLBACK(VBOXSTRICTRC) vkdPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
     81{
     82    RT_NOREF(pvUser, offPort, cb);
    8683    VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *);
    8784
     
    9895}
    9996
    100 static DECLCALLBACK(int) vkdPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
     97static DECLCALLBACK(VBOXSTRICTRC) vkdPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
    10198{
    10299    RT_NOREF(pvUser, cb);
    103100    VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *);
    104101
    105     if (Port == 0x5659)
    106     {
     102    if (offPort == 1)
     103    {
     104        RTGCPHYS GCPhys = u32;
    107105        VKDREQUESTHDR RequestHeader = {0, };
    108         int rc = PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &RequestHeader, sizeof(RequestHeader));
     106        int rc = PDMDevHlpPhysRead(pDevIns, GCPhys, &RequestHeader, sizeof(RequestHeader));
    109107        if (   !RT_SUCCESS(rc)
    110108            || !RequestHeader.cbData)
     
    112110
    113111        unsigned cbData = RT_MIN(RequestHeader.cbData, sizeof(pThis->abCmdBody));
    114         rc = PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)(u32 + sizeof(RequestHeader)), pThis->abCmdBody, cbData);
     112        rc = PDMDevHlpPhysRead(pDevIns, GCPhys + sizeof(RequestHeader), pThis->abCmdBody, cbData);
    115113        if (!RT_SUCCESS(rc))
    116114            return VINF_SUCCESS;
     
    122120            cbReply = 0;
    123121
     122        /** @todo r=bird: RequestHeader.cbReplyMax is not taking into account here. */
    124123        VKDREPLYHDR ReplyHeader;
    125124        ReplyHeader.cbData = cbReply + 2;
    126125        ReplyHeader.chOne = '1';
    127126        ReplyHeader.chSpace = ' ';
    128         rc = PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &ReplyHeader, sizeof(ReplyHeader));
     127        rc = PDMDevHlpPhysWrite(pDevIns, GCPhys, &ReplyHeader, sizeof(ReplyHeader));
    129128        if (!RT_SUCCESS(rc))
    130129            return VINF_SUCCESS;
    131130        if (cbReply)
    132131        {
    133             rc = PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)(u32 + sizeof(ReplyHeader)), pReply, cbReply);
     132            rc = PDMDevHlpPhysWrite(pDevIns, GCPhys + sizeof(ReplyHeader), pReply, cbReply);
    134133            if (!RT_SUCCESS(rc))
    135134                return VINF_SUCCESS;
    136135        }
    137136    }
    138     else if (Port == 0x5658)
    139     {
     137    else
     138    {
     139        Assert(offPort == 0);
    140140        if (u32 == 0x564D5868)
    141141            pThis->fOpenChannelDetected = true;
     
    156156    VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *);
    157157
    158     delete pThis->pKDClient;
     158    if (pThis->pKDClient)
     159    {
     160        delete pThis->pKDClient;
     161        pThis->pKDClient = NULL;
     162    }
     163
    159164    if (pThis->hLib != NIL_RTLDRMOD)
     165    {
    160166        RTLdrClose(pThis->hLib);
     167        pThis->hLib = NIL_RTLDRMOD;
     168    }
    161169
    162170    return VINF_SUCCESS;
     
    169177static DECLCALLBACK(int) vkdConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    170178{
    171     RT_NOREF(iInstance);
    172179    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    173180    VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *);
     181    RT_NOREF(iInstance);
    174182
    175183    pThis->fOpenChannelDetected = false;
     
    178186    pThis->pKDClient = NULL;
    179187
    180     if (!CFGMR3AreValuesValid(pCfg,
    181                               "Path\0"))
    182         return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
     188
     189    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Path", "");
    183190
    184191    /* This device is a bit unusual, after this point it will not fail to be
    185192     * constructed, but there will be a warning and it will not work. */
    186193
    187     char szPath[RTPATH_MAX] = "";
    188     CFGMR3QueryString(pCfg, "Path", szPath, sizeof(szPath));
    189 
    190     RTPathAppend(szPath, sizeof(szPath), HC_ARCH_BITS == 64 ?  "kdclient64.dll" : "kdclient.dll");
    191     int rc = RTLdrLoad(szPath, &pThis->hLib);
     194    char szPath[RTPATH_MAX];
     195    int rc = CFGMR3QueryStringDef(pCfg, "Path", szPath, sizeof(szPath) - sizeof("kdclient64.dll"), "");
    192196    if (RT_FAILURE(rc))
    193     {
     197        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"Path\" value"));
     198
     199    rc = RTPathAppend(szPath, sizeof(szPath), HC_ARCH_BITS == 64 ?  "kdclient64.dll" : "kdclient.dll");
     200    AssertRCReturn(rc, rc);
     201    rc = RTLdrLoad(szPath, &pThis->hLib);
     202    if (RT_SUCCESS(rc))
     203    {
     204        PFNCreateVBoxKDClientEx pfnInit;
     205        rc = RTLdrGetSymbol(pThis->hLib, "CreateVBoxKDClientEx", (void **)&pfnInit);
     206        if (RT_SUCCESS(rc))
     207        {
     208            pThis->pKDClient = pfnInit(IKDClient_InterfaceVersion);
     209            if (pThis->pKDClient)
     210            {
     211                IOMIOPORTHANDLE hIoPorts;
     212                rc = PDMDevHlpIoPortCreateAndMap(pDevIns, 0x5658 /*uPort*/, 2 /*cPorts*/, vkdPortWrite, vkdPortRead,
     213                                                 "VirtualKD",  NULL /*paExtDescs*/, &hIoPorts);
     214                AssertRCReturn(rc, rc);
     215            }
     216            else
     217                PDMDevHlpVMSetRuntimeError(pDevIns, 0 /* fFlags */, "VirtualKD_INIT",
     218                                           N_("Failed to initialize VirtualKD library '%s'. Fast kernel-mode debugging will not work"), szPath);
     219        }
     220        else
     221            PDMDevHlpVMSetRuntimeError(pDevIns, 0 /* fFlags */, "VirtualKD_SYMBOL",
     222                                       N_("Failed to find entry point for VirtualKD library '%s'. Fast kernel-mode debugging will not work"), szPath);
     223    }
     224    else
    194225        PDMDevHlpVMSetRuntimeError(pDevIns, 0 /* fFlags */, "VirtualKD_LOAD",
    195226                                   N_("Failed to load VirtualKD library '%s'. Fast kernel-mode debugging will not work"), szPath);
    196         return VINF_SUCCESS;
    197     }
    198 
    199     PFNCreateVBoxKDClientEx pfnInit;
    200     rc = RTLdrGetSymbol(pThis->hLib, "CreateVBoxKDClientEx", (void **)&pfnInit);
    201     if (RT_FAILURE(rc))
    202     {
    203         RTLdrClose(pThis->hLib);
    204         pThis->hLib = NIL_RTLDRMOD;
    205         PDMDevHlpVMSetRuntimeError(pDevIns, 0 /* fFlags */, "VirtualKD_SYMBOL",
    206                                    N_("Failed to find entry point for VirtualKD library '%s'. Fast kernel-mode debugging will not work"), szPath);
    207         return VINF_SUCCESS;
    208     }
    209 
    210     pThis->pKDClient = pfnInit(IKDClient_InterfaceVersion);
    211     if (!pThis->pKDClient)
    212     {
    213         RTLdrClose(pThis->hLib);
    214         pThis->hLib = NIL_RTLDRMOD;
    215         PDMDevHlpVMSetRuntimeError(pDevIns, 0 /* fFlags */, "VirtualKD_INIT",
    216                                    N_("Failed to initialize VirtualKD library '%s'. Fast kernel-mode debugging will not work"), szPath);
    217         return VINF_SUCCESS;
    218     }
    219 
    220     return PDMDevHlpIOPortRegister(pDevIns, 0x5658, 2, NULL, vkdPortWrite, vkdPortRead, NULL, NULL, "VirtualKD");
     227    return VINF_SUCCESS;
    221228}
    222229
     
    230237    /* .uReserved0 = */             0,
    231238    /* .szName = */                 "VirtualKD",
    232     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS,
     239    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
    233240    /* .fClass = */                 PDM_DEVREG_CLASS_MISC,
    234241    /* .cMaxInstances = */          1,
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