- Timestamp:
- Nov 24, 2019 4:24:54 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Misc/VirtualKD.cpp
r81591 r82148 41 41 * Structures and Typedefs * 42 42 *********************************************************************************************************************************/ 43 44 43 typedef struct VKDREQUESTHDR 45 44 { … … 77 76 78 77 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 80 static DECLCALLBACK(VBOXSTRICTRC) vkdPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb) 81 { 82 RT_NOREF(pvUser, offPort, cb); 86 83 VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *); 87 84 … … 98 95 } 99 96 100 static DECLCALLBACK( int) vkdPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORTPort, uint32_t u32, unsigned cb)97 static DECLCALLBACK(VBOXSTRICTRC) vkdPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb) 101 98 { 102 99 RT_NOREF(pvUser, cb); 103 100 VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *); 104 101 105 if (Port == 0x5659) 106 { 102 if (offPort == 1) 103 { 104 RTGCPHYS GCPhys = u32; 107 105 VKDREQUESTHDR RequestHeader = {0, }; 108 int rc = PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &RequestHeader, sizeof(RequestHeader));106 int rc = PDMDevHlpPhysRead(pDevIns, GCPhys, &RequestHeader, sizeof(RequestHeader)); 109 107 if ( !RT_SUCCESS(rc) 110 108 || !RequestHeader.cbData) … … 112 110 113 111 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); 115 113 if (!RT_SUCCESS(rc)) 116 114 return VINF_SUCCESS; … … 122 120 cbReply = 0; 123 121 122 /** @todo r=bird: RequestHeader.cbReplyMax is not taking into account here. */ 124 123 VKDREPLYHDR ReplyHeader; 125 124 ReplyHeader.cbData = cbReply + 2; 126 125 ReplyHeader.chOne = '1'; 127 126 ReplyHeader.chSpace = ' '; 128 rc = PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &ReplyHeader, sizeof(ReplyHeader));127 rc = PDMDevHlpPhysWrite(pDevIns, GCPhys, &ReplyHeader, sizeof(ReplyHeader)); 129 128 if (!RT_SUCCESS(rc)) 130 129 return VINF_SUCCESS; 131 130 if (cbReply) 132 131 { 133 rc = PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)(u32 + sizeof(ReplyHeader)), pReply, cbReply);132 rc = PDMDevHlpPhysWrite(pDevIns, GCPhys + sizeof(ReplyHeader), pReply, cbReply); 134 133 if (!RT_SUCCESS(rc)) 135 134 return VINF_SUCCESS; 136 135 } 137 136 } 138 else if (Port == 0x5658) 139 { 137 else 138 { 139 Assert(offPort == 0); 140 140 if (u32 == 0x564D5868) 141 141 pThis->fOpenChannelDetected = true; … … 156 156 VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *); 157 157 158 delete pThis->pKDClient; 158 if (pThis->pKDClient) 159 { 160 delete pThis->pKDClient; 161 pThis->pKDClient = NULL; 162 } 163 159 164 if (pThis->hLib != NIL_RTLDRMOD) 165 { 160 166 RTLdrClose(pThis->hLib); 167 pThis->hLib = NIL_RTLDRMOD; 168 } 161 169 162 170 return VINF_SUCCESS; … … 169 177 static DECLCALLBACK(int) vkdConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 170 178 { 171 RT_NOREF(iInstance);172 179 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 173 180 VIRTUALKD *pThis = PDMDEVINS_2_DATA(pDevIns, VIRTUALKD *); 181 RT_NOREF(iInstance); 174 182 175 183 pThis->fOpenChannelDetected = false; … … 178 186 pThis->pKDClient = NULL; 179 187 180 if (!CFGMR3AreValuesValid(pCfg, 181 "Path\0")) 182 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES; 188 189 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Path", ""); 183 190 184 191 /* This device is a bit unusual, after this point it will not fail to be 185 192 * constructed, but there will be a warning and it will not work. */ 186 193 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"), ""); 192 196 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 194 225 PDMDevHlpVMSetRuntimeError(pDevIns, 0 /* fFlags */, "VirtualKD_LOAD", 195 226 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; 221 228 } 222 229 … … 230 237 /* .uReserved0 = */ 0, 231 238 /* .szName = */ "VirtualKD", 232 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS ,239 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE, 233 240 /* .fClass = */ PDM_DEVREG_CLASS_MISC, 234 241 /* .cMaxInstances = */ 1,
Note:
See TracChangeset
for help on using the changeset viewer.