Changeset 40819 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Apr 7, 2012 8:53:40 PM (13 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDrv.c
r40806 r40819 695 695 pSession->R0Process = NIL_RTR0PROCESS; 696 696 } 697 /*pSession->uTracerData = 0;*/ 698 pSession->hTracerCaller = NIL_RTNATIVETHREAD; 697 699 698 700 VBOXDRV_SESSION_CREATE(pSession, fUser); … … 1116 1118 { \ 1117 1119 OSDBGPRINT(( #Name ": Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", \ 1118 (long)pReq ->Hdr.cbIn, (long)(cbInExpect), (long)pReq->Hdr.cbOut, (long)(cbOutExpect))); \1120 (long)pReqHdr->cbIn, (long)(cbInExpect), (long)pReqHdr->cbOut, (long)(cbOutExpect))); \ 1119 1121 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \ 1120 return pReq ->Hdr.rc = VERR_INVALID_PARAMETER; \1122 return pReqHdr->rc = VERR_INVALID_PARAMETER; \ 1121 1123 } \ 1122 1124 } while (0) … … 1129 1131 { \ 1130 1132 OSDBGPRINT(( #Name ": Invalid input/output sizes. cbIn=%ld expected %ld.\n", \ 1131 (long)pReq ->Hdr.cbIn, (long)(cbInExpect))); \1133 (long)pReqHdr->cbIn, (long)(cbInExpect))); \ 1132 1134 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \ 1133 return pReq ->Hdr.rc = VERR_INVALID_PARAMETER; \1135 return pReqHdr->rc = VERR_INVALID_PARAMETER; \ 1134 1136 } \ 1135 1137 } while (0) … … 1140 1142 { \ 1141 1143 OSDBGPRINT(( #Name ": Invalid input/output sizes. cbOut=%ld expected %ld.\n", \ 1142 (long)pReq ->Hdr.cbOut, (long)(cbOutExpect))); \1144 (long)pReqHdr->cbOut, (long)(cbOutExpect))); \ 1143 1145 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \ 1144 return pReq ->Hdr.rc = VERR_INVALID_PARAMETER; \1146 return pReqHdr->rc = VERR_INVALID_PARAMETER; \ 1145 1147 } \ 1146 1148 } while (0) … … 1152 1154 OSDBGPRINT(( #Name ": %s\n", #expr)); \ 1153 1155 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \ 1154 return pReq ->Hdr.rc = VERR_INVALID_PARAMETER; \1156 return pReqHdr->rc = VERR_INVALID_PARAMETER; \ 1155 1157 } \ 1156 1158 } while (0) … … 1162 1164 OSDBGPRINT( fmt ); \ 1163 1165 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER); \ 1164 return pReq ->Hdr.rc = VERR_INVALID_PARAMETER; \1166 return pReqHdr->rc = VERR_INVALID_PARAMETER; \ 1165 1167 } \ 1166 1168 } while (0) … … 1825 1827 } 1826 1828 1829 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_TRACER_OPEN): 1830 { 1831 /* validate */ 1832 PSUPTRACEROPEN pReq = (PSUPTRACEROPEN)pReqHdr; 1833 REQ_CHECK_SIZES(SUP_IOCTL_TRACER_OPEN); 1834 1835 /* execute */ 1836 pReq->Hdr.rc = supdrvIOCtl_TracerOpen(pDevExt, pSession, pReq->u.In.uCookie, pReq->u.In.uArg); 1837 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReq->Hdr.rc); 1838 return 0; 1839 } 1840 1841 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_TRACER_CLOSE): 1842 { 1843 /* validate */ 1844 REQ_CHECK_SIZES(SUP_IOCTL_TRACER_CLOSE); 1845 1846 /* execute */ 1847 pReqHdr->rc = supdrvIOCtl_TracerClose(pDevExt, pSession); 1848 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReqHdr->rc); 1849 return 0; 1850 } 1851 1852 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_TRACER_IOCTL): 1853 { 1854 /* validate */ 1855 PSUPTRACERIOCTL pReq = (PSUPTRACERIOCTL)pReqHdr; 1856 REQ_CHECK_SIZES(SUP_IOCTL_TRACER_IOCTL); 1857 1858 /* execute */ 1859 pReqHdr->rc = supdrvIOCtl_TracerIOCtl(pDevExt, pSession, pReq->u.In.uCmd, pReq->u.In.uArg, &pReq->u.Out.iRetVal); 1860 VBOXDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VINF_SUCCESS, pReqHdr->rc); 1861 return 0; 1862 } 1863 1827 1864 default: 1828 1865 Log(("Unknown IOCTL %#lx\n", (long)uIOCtl)); -
trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h
r40806 r40819 193 193 * - Remove RTSpinlockReleaseNoInts. 194 194 */ 195 #define SUPDRV_IOC_VERSION 0x001a000 0195 #define SUPDRV_IOC_VERSION 0x001a0001 196 196 197 197 /** SUP_IOCTL_COOKIE. */ … … 1092 1092 /** @} */ 1093 1093 1094 1094 1095 /** @name SUP_IOCTL_SEM_OP3 1095 1096 * Semaphore operations. … … 1141 1142 /** @} */ 1142 1143 1144 1143 1145 /** @name SUP_IOCTL_VT_CAPS 1144 1146 * Get the VT-x/AMD-V capabilities. … … 1168 1170 /** @} */ 1169 1171 1172 1173 /** @name SUP_IOCTL_TRACER_OPEN 1174 * Open the tracer. 1175 * 1176 * Should be matched by an SUP_IOCTL_TRACER_CLOSE call. 1177 * 1178 * @{ 1179 */ 1180 #define SUP_IOCTL_TRACER_OPEN SUP_CTL_CODE_SIZE(28, SUP_IOCTL_TRACER_OPEN_SIZE) 1181 #define SUP_IOCTL_TRACER_OPEN_SIZE sizeof(SUPTRACEROPEN) 1182 #define SUP_IOCTL_TRACER_OPEN_SIZE_IN sizeof(SUPTRACEROPEN) 1183 #define SUP_IOCTL_TRACER_OPEN_SIZE_OUT sizeof(SUPREQHDR) 1184 typedef struct SUPTRACEROPEN 1185 { 1186 /** The header. */ 1187 SUPREQHDR Hdr; 1188 union 1189 { 1190 struct 1191 { 1192 /** Tracer cookie. Used to make sure we only open a matching tracer. */ 1193 uint32_t uCookie; 1194 /** Tracer specific argument. */ 1195 RTHCUINTPTR uArg; 1196 } In; 1197 } u; 1198 } SUPTRACEROPEN, *PSUPTRACEROPEN; 1199 /** @} */ 1200 1201 1202 /** @name SUP_IOCTL_TRACER_CLOSE 1203 * Close the tracer. 1204 * 1205 * Must match a SUP_IOCTL_TRACER_OPEN call. 1206 * 1207 * @{ 1208 */ 1209 #define SUP_IOCTL_TRACER_CLOSE SUP_CTL_CODE_SIZE(29, SUP_IOCTL_TRACER_CLOSE_SIZE) 1210 #define SUP_IOCTL_TRACER_CLOSE_SIZE sizeof(SUPREQHDR) 1211 #define SUP_IOCTL_TRACER_CLOSE_SIZE_IN sizeof(SUPREQHDR) 1212 #define SUP_IOCTL_TRACER_CLOSE_SIZE_OUT sizeof(SUPREQHDR) 1213 /** @} */ 1214 1215 1216 /** @name SUP_IOCTL_TRACER_IOCTL 1217 * Speak UNIX ioctl() with the tracer. 1218 * 1219 * The session must have opened the tracer prior to issuing this request. 1220 * 1221 * @{ 1222 */ 1223 #define SUP_IOCTL_TRACER_IOCTL SUP_CTL_CODE_SIZE(30, SUP_IOCTL_TRACER_IOCTL_SIZE) 1224 #define SUP_IOCTL_TRACER_IOCTL_SIZE sizeof(SUPTRACERIOCTL) 1225 #define SUP_IOCTL_TRACER_IOCTL_SIZE_IN sizeof(SUPTRACERIOCTL) 1226 #define SUP_IOCTL_TRACER_IOCTL_SIZE_OUT (RT_UOFFSETOF(SUPTRACERIOCTL, u.Out.iRetVal) + sizeof(int32_t)) 1227 typedef struct SUPTRACERIOCTL 1228 { 1229 /** The header. */ 1230 SUPREQHDR Hdr; 1231 union 1232 { 1233 struct 1234 { 1235 /** The command. */ 1236 RTHCUINTPTR uCmd; 1237 /** Argument to the command. */ 1238 RTHCUINTPTR uArg; 1239 } In; 1240 1241 struct 1242 { 1243 /** The return value. */ 1244 int32_t iRetVal; 1245 } Out; 1246 } u; 1247 } SUPTRACERIOCTL, *PSUPTRACERIOCTL; 1248 /** @} */ 1249 1250 1170 1251 #pragma pack() /* paranoia */ 1171 1252 -
trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h
r40806 r40819 438 438 /** Per session tracer specfic data. */ 439 439 uintptr_t uTracerData; 440 /** The thread currently actively talking to the tracer. (One at the time!) */ 441 RTNATIVETHREAD hTracerCaller; 440 442 #ifndef SUPDRV_AGNOSTIC 441 443 # if defined(RT_OS_DARWIN) … … 555 557 /** The tracer helpers. */ 556 558 SUPDRVTRACERHLP TracerHlp; 559 /** The number of session having opened the tracer currently. */ 560 uint32_t cTracerOpens; 557 561 /** Set if the tracer is being unloaded. */ 558 562 bool fTracerUnloading; … … 651 655 void VBOXCALL supdrvTracerModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage); 652 656 void VBOXCALL supdrvTracerCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); 657 int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg); 658 int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); 659 int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal); 653 660 extern PFNRT g_pfnSupdrvProbeFireKernel; 654 661 DECLASM(void) supdrvTracerProbeFireStub(void); -
trunk/src/VBox/HostDrivers/Support/SUPDrvTracer.cpp
r40813 r40819 150 150 uintptr_t offTmp; 151 151 uintptr_t i; 152 uintptr_t cProviders; 152 153 int rc; 153 uint32_t cProviders;154 154 155 155 if (!pbImage || !cbImage) … … 436 436 437 437 /* 438 * Try unregister zombies now, sleep on busy ones .438 * Try unregister zombies now, sleep on busy ones and tracer opens. 439 439 */ 440 440 for (i = 0; ; i++) … … 443 443 444 444 RTSemFastMutexRequest(pDevExt->mtxTracer); 445 446 /* Zombies */ 445 447 RTListForEachSafe(&pDevExt->TracerProviderZombieList, pProv, pProvNext, SUPDRVTPPROVIDER, ListEntry) 446 448 { … … 467 469 468 470 fEmpty = RTListIsEmpty(&pDevExt->TracerProviderZombieList); 471 472 /* Tracer opens. */ 473 if ( pDevExt->cTracerOpens 474 && pDevExt->pTracerOps) 475 { 476 fEmpty = false; 477 if (!(i & 0xf)) 478 SUPR0Printf("supdrvTracerRemoveAllProviders: Waiting on %u opens\n", pDevExt->cTracerOpens); 479 else 480 LOG_TRACER(("supdrvTracerRemoveAllProviders: Waiting on %u opens\n", pDevExt->cTracerOpens)); 481 } 482 469 483 RTSemFastMutexRelease(pDevExt->mtxTracer); 484 470 485 if (fEmpty) 471 486 break; … … 492 507 { 493 508 int rc; 494 u nsignedi;509 uintptr_t i; 495 510 PSUPDRVTPPROVIDER pProv; 496 511 … … 845 860 { 846 861 int rc; 847 LOG_TRACER(("supdrvTracer RemoveAllProviders: Attemting to unregister '%s' / %p...\n",862 LOG_TRACER(("supdrvTracerCommonDeregisterImpl: Attemting to unregister '%s' / %p...\n", 848 863 pProv->szName, pProv->Core.TracerData.DTrace.idProvider)); 849 864 … … 876 891 { 877 892 int rc; 878 LOG_TRACER(("supdrvTracer RemoveAllProviders: Attemting to unregister '%s' / %p (zombie)...\n",893 LOG_TRACER(("supdrvTracerCommonDeregisterImpl: Attemting to unregister '%s' / %p (zombie)...\n", 879 894 pProv->szName, pProv->Core.TracerData.DTrace.idProvider)); 880 895 … … 889 904 cZombies++; 890 905 if (!(i & 0xf)) 891 SUPR0Printf("supdrvTracer RemoveAllProviders: Waiting on busy provider '%s' / %p (rc=%d)\n",906 SUPR0Printf("supdrvTracerCommonDeregisterImpl: Waiting on busy provider '%s' / %p (rc=%d)\n", 892 907 pProv->szName, pProv->Core.TracerData.DTrace.idProvider, rc); 893 908 else 894 LOG_TRACER(("supdrvTracer RemoveAllProviders: Failed to unregister provider '%s' / %p - rc=%d\n",909 LOG_TRACER(("supdrvTracerCommonDeregisterImpl: Failed to unregister provider '%s' / %p - rc=%d\n", 895 910 pProv->szName, pProv->Core.TracerData.DTrace.idProvider, rc)); 896 911 } 897 912 } 898 913 914 /* Tracer opens. */ 915 if (pDevExt->cTracerOpens) 916 { 917 cZombies++; 918 if (!(i & 0xf)) 919 SUPR0Printf("supdrvTracerCommonDeregisterImpl: Waiting on %u opens\n", pDevExt->cTracerOpens); 920 else 921 LOG_TRACER(("supdrvTracerCommonDeregisterImpl: Waiting on %u opens\n", pDevExt->cTracerOpens)); 922 } 923 924 /* Done? */ 899 925 if (cZombies == 0) 900 926 break; … … 1014 1040 .previous \n\ 1015 1041 "); 1042 # if 0 /* Slickedit on windows highlighting fix */ 1043 ) 1044 # endif 1016 1045 #endif 1017 1046 … … 1111 1140 1112 1141 /** 1142 * Open the tracer. 1143 * 1144 * @returns VBox status code 1145 * @param pDevExt The device extension structure. 1146 * @param pSession The current session. 1147 * @param uCookie The tracer cookie. 1148 * @param uArg The tracer open argument. 1149 */ 1150 int VBOXCALL supdrvIOCtl_TracerOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uint32_t uCookie, uintptr_t uArg) 1151 { 1152 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 1153 int rc; 1154 1155 RTSemFastMutexRequest(pDevExt->mtxTracer); 1156 1157 if (!pSession->uTracerData) 1158 { 1159 if (pDevExt->pTracerOps) 1160 { 1161 if (pDevExt->pTracerSession != pSession) 1162 { 1163 if (!pDevExt->fTracerUnloading) 1164 { 1165 if (pSession->hTracerCaller == NIL_RTNATIVETHREAD) 1166 { 1167 pDevExt->cTracerOpens++; 1168 pSession->uTracerData = ~(uintptr_t)0; 1169 pSession->hTracerCaller = hNativeSelf; 1170 RTSemFastMutexRelease(pDevExt->mtxTracer); 1171 1172 rc = pDevExt->pTracerOps->pfnTracerOpen(pDevExt->pTracerOps, pSession, uCookie, uArg, &pSession->uTracerData); 1173 1174 RTSemFastMutexRequest(pDevExt->mtxTracer); 1175 if (RT_FAILURE(rc)) 1176 { 1177 pDevExt->cTracerOpens--; 1178 pSession->uTracerData = 0; 1179 } 1180 pSession->hTracerCaller = NIL_RTNATIVETHREAD; 1181 } 1182 else 1183 rc = VERR_SUPDRV_TRACER_SESSION_BUSY; 1184 } 1185 else 1186 rc = VERR_SUPDRV_TRACER_UNLOADING; 1187 } 1188 else 1189 rc = VERR_SUPDRV_TRACER_CANNOT_OPEN_SELF; 1190 } 1191 else 1192 rc = VERR_SUPDRV_TRACER_NOT_PRESENT; 1193 } 1194 else 1195 rc = VERR_SUPDRV_TRACER_ALREADY_OPENED; 1196 1197 RTSemFastMutexRelease(pDevExt->mtxTracer); 1198 return rc; 1199 } 1200 1201 1202 /** 1203 * Closes the tracer. 1204 * 1205 * @returns VBox status code. 1206 * @param pDevExt The device extension structure. 1207 * @param pSession The current session. 1208 */ 1209 int VBOXCALL supdrvIOCtl_TracerClose(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession) 1210 { 1211 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 1212 int rc; 1213 1214 RTSemFastMutexRequest(pDevExt->mtxTracer); 1215 1216 if (pSession->uTracerData) 1217 { 1218 Assert(pDevExt->cTracerOpens > 0); 1219 1220 if (pDevExt->pTracerOps) 1221 { 1222 if (pSession->hTracerCaller == NIL_RTNATIVETHREAD) 1223 { 1224 uintptr_t uTracerData = pSession->uTracerData; 1225 pSession->uTracerData = 0; 1226 pSession->hTracerCaller = hNativeSelf; 1227 RTSemFastMutexRelease(pDevExt->mtxTracer); 1228 1229 pDevExt->pTracerOps->pfnTracerClose(pDevExt->pTracerOps, pSession, uTracerData); 1230 rc = VINF_SUCCESS; 1231 1232 RTSemFastMutexRequest(pDevExt->mtxTracer); 1233 pSession->hTracerCaller = NIL_RTNATIVETHREAD; 1234 Assert(pDevExt->cTracerOpens > 0); 1235 pDevExt->cTracerOpens--; 1236 } 1237 else 1238 rc = VERR_SUPDRV_TRACER_SESSION_BUSY; 1239 } 1240 else 1241 { 1242 rc = VERR_SUPDRV_TRACER_NOT_PRESENT; 1243 pSession->uTracerData = 0; 1244 Assert(pDevExt->cTracerOpens > 0); 1245 pDevExt->cTracerOpens--; 1246 } 1247 } 1248 else 1249 rc = VERR_SUPDRV_TRACER_NOT_OPENED; 1250 1251 RTSemFastMutexRelease(pDevExt->mtxTracer); 1252 return rc; 1253 } 1254 1255 1256 /** 1257 * Performs a tracer I/O control request. 1258 * 1259 * @returns VBox status code. 1260 * @param pDevExt The device extension structure. 1261 * @param pSession The current session. 1262 * @param uCmd The tracer command. 1263 * @param uArg The tracer argument. 1264 * @param piRetVal Where to store the tracer specific return value. 1265 */ 1266 int VBOXCALL supdrvIOCtl_TracerIOCtl(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal) 1267 { 1268 RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf(); 1269 int rc; 1270 1271 RTSemFastMutexRequest(pDevExt->mtxTracer); 1272 1273 if (pSession->uTracerData) 1274 { 1275 Assert(pDevExt->cTracerOpens > 0); 1276 if (pDevExt->pTracerOps) 1277 { 1278 if (!pDevExt->fTracerUnloading) 1279 { 1280 if (pSession->hTracerCaller == NIL_RTNATIVETHREAD) 1281 { 1282 uintptr_t uTracerData = pSession->uTracerData; 1283 pDevExt->cTracerOpens++; 1284 pSession->hTracerCaller = hNativeSelf; 1285 RTSemFastMutexRelease(pDevExt->mtxTracer); 1286 1287 rc = pDevExt->pTracerOps->pfnTracerIoCtl(pDevExt->pTracerOps, pSession, uTracerData, uCmd, uArg, piRetVal); 1288 1289 RTSemFastMutexRequest(pDevExt->mtxTracer); 1290 pSession->hTracerCaller = NIL_RTNATIVETHREAD; 1291 Assert(pDevExt->cTracerOpens > 0); 1292 pDevExt->cTracerOpens--; 1293 } 1294 else 1295 rc = VERR_SUPDRV_TRACER_SESSION_BUSY; 1296 } 1297 else 1298 rc = VERR_SUPDRV_TRACER_UNLOADING; 1299 } 1300 else 1301 rc = VERR_SUPDRV_TRACER_NOT_PRESENT; 1302 } 1303 else 1304 rc = VERR_SUPDRV_TRACER_NOT_OPENED; 1305 1306 RTSemFastMutexRelease(pDevExt->mtxTracer); 1307 return rc; 1308 } 1309 1310 1311 /** 1113 1312 * Early module initialization hook. 1114 1313 *
Note:
See TracChangeset
for help on using the changeset viewer.