Changeset 40600 in vbox
- Timestamp:
- Mar 23, 2012 10:09:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDrv-dtrace.cpp
r40599 r40600 33 33 34 34 #include <VBox/err.h> 35 #include <VBox/VBoxTpG.h> 35 36 #include <iprt/assert.h> 36 37 37 38 #include <sys/dtrace.h> 38 39 40 41 /******************************************************************************* 42 * Structures and Typedefs * 43 *******************************************************************************/ 44 /** 45 * Data for a provider. 46 */ 47 typedef struct SUPDRVDTPROVIDER 48 { 49 /** The entry in the provider list for this image. */ 50 RTLISTNODE ListEntry; 51 52 /** The provider descriptor. */ 53 PVTGDESCPROVIDER pDesc; 54 /** The VTG header. */ 55 PVTGOBJHDR pHdr; 56 57 /** Pointer to the image this provider resides in. NULL if it's a 58 * driver. */ 59 PSUPDRVLDRIMAGE pImage; 60 /** The session this provider is associated with if registered via 61 * SUPR0VtgRegisterDrv. NULL if pImage is set. */ 62 PSUPDRVSESSION pSession; 63 /** The module name. */ 64 const char *pszModName; 65 } SUPDRVDTPROVIDER; 66 /** Pointer to the data for a provider. */ 67 typedef SUPDRVDTPROVIDER *PSUPDRVDTPROVIDER; 39 68 40 69 … … 45 74 static int supdrvDTracePOps_Enable(void *pvProv, dtrace_id_t idProbe, void *pvProbe); 46 75 static void supdrvDTracePOps_Disable(void *pvProv, dtrace_id_t idProbe, void *pvProbe); 47 static void supdrvDTracePOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe, 76 static void supdrvDTracePOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe, 48 77 dtrace_argdesc_t *pArgDesc); 49 78 /*static uint64_t supdrvDTracePOps_GetArgVal(void *pvProv, dtrace_id_t idProbe, void *pvProbe, … … 57 86 *******************************************************************************/ 58 87 /** The default provider attributes. */ 59 static dtrace_pattr_t g_DefProvAttrs = 88 static dtrace_pattr_t g_DefProvAttrs = 60 89 { /* .dtat_name, .dtat_data, .dtat_class */ 61 90 /* .dtpa_provider = */ { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA }, … … 66 95 }; 67 96 68 /** 69 * DTrace provider method table. 70 */ 71 static const dtrace_pops_t g_SupDrvDTraceProvOps = 97 /** 98 * DTrace provider method table. 99 */ 100 static const dtrace_pops_t g_SupDrvDTraceProvOps = 72 101 { 73 102 /* .dtps_provide = */ NULL, … … 84 113 85 114 115 #define VERR_SUPDRV_VTG_MAGIC (-3704) 116 #define VERR_SUPDRV_VTG_BITS (-3705) 117 #define VERR_SUPDRV_VTG_RESERVED (-3705) 118 #define VERR_SUPDRV_VTG_BAD_PTR (-3706) 119 #define VERR_SUPDRV_VTG_TOO_FEW (-3707) 120 #define VERR_SUPDRV_VTG_TOO_MUCH (-3708) 121 #define VERR_SUPDRV_VTG_NOT_MULTIPLE (-3709) 122 123 124 /** 125 * Validates the VTG data. 126 * 127 * @returns VBox status code. 128 * @param pVtgHdr The VTG object header of the data to validate. 129 * @param cbVtgObj The size of the VTG object. 130 * @param pbImage The image base. For validating the probe 131 * locations. 132 * @param cbImage The image size to go with @a pbImage. 133 */ 134 static int supdrvVtgValidate(PVTGOBJHDR pVtgHdr, size_t cbVtgObj, uint8_t *pbImage, size_t cbImage) 135 { 136 /* 137 * The header. 138 */ 139 if (!memcmp(pVtgHdr->szMagic, VTGOBJHDR_MAGIC, sizeof(pVtgHdr->szMagic))) 140 return VERR_SUPDRV_VTG_MAGIC; 141 if (pVtgHdr->cBits != ARCH_BITS) 142 return VERR_SUPDRV_VTG_BITS; 143 if (pVtgHdr->u32Reserved0) 144 return VERR_SUPDRV_VTG_RESERVED; 145 146 #define MY_VALIDATE_PTR(p, cb, cMin, cMax, cbUnit) \ 147 do { \ 148 if ( (cb) >= cbVtgObj \ 149 || (uintptr_t)(p) - (uintptr_t)pVtgHdr < cbVtgObj - (cb) ) \ 150 return VERR_SUPDRV_VTG_BAD_PTR; \ 151 if ((cb) < (cMin) * (cbUnit)) \ 152 return VERR_SUPDRV_VTG_TOO_FEW; \ 153 if ((cb) >= (cMax) * (cbUnit)) \ 154 return VERR_SUPDRV_VTG_TOO_MUCH; \ 155 if ((cb) / (cbUnit) * (cbUnit) != (cb)) \ 156 return VERR_SUPDRV_VTG_NOT_MULTIPLE; \ 157 } while (0) 158 159 MY_VALIDATE_PTR(pVtgHdr->paProviders, pVtgHdr->cbProviders, 1, 16, sizeof(VTGDESCPROVIDER)); 160 MY_VALIDATE_PTR(pVtgHdr->paProbes, pVtgHdr->cbProbes, 1, _32K, sizeof(VTGDESCPROBE)); 161 MY_VALIDATE_PTR(pVtgHdr->pafProbeEnabled, pVtgHdr->cbProbeEnabled, 1, _32K, sizeof(bool)); 162 MY_VALIDATE_PTR(pVtgHdr->pachStrTab, pVtgHdr->cbStrTab, 4, _1M, sizeof(char)); 163 MY_VALIDATE_PTR(pVtgHdr->paArgLists, pVtgHdr->cbArgLists, 0, _32K, sizeof(uint32_t)); 164 #undef MY_VALIDATE_PTR 165 166 if (!RT_VALID_PTR(pVtgHdr->paProbLocs)) 167 return VERR_SUPDRV_VTG_BAD_PTR; 168 if (!RT_VALID_PTR(pVtgHdr->paProbLocsEnd)) 169 return VERR_SUPDRV_VTG_BAD_PTR; 170 if ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs < sizeof(VTGPROBELOC)) 171 return VERR_SUPDRV_VTG_TOO_FEW; 172 if ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs > sizeof(VTGPROBELOC) * _128K) 173 return VERR_SUPDRV_VTG_TOO_MUCH; 174 if ( ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs) 175 / sizeof(VTGPROBELOC) * sizeof(VTGPROBELOC) 176 != (uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs) 177 return VERR_SUPDRV_VTG_NOT_MULTIPLE; 178 if (pbImage && cbImage) 179 { 180 if ((uintptr_t)pVtgHdr->paProbLocs - (uintptr_t)pbImage >= cbImage) 181 return VERR_SUPDRV_VTG_BAD_PTR; 182 if ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pbImage > cbImage) 183 return VERR_SUPDRV_VTG_BAD_PTR; 184 } 185 186 /* 187 * Validate the providers. 188 */ 189 190 191 return VINF_SUCCESS; 192 } 193 194 195 /** 196 * Registers the VTG tracepoint providers of a driver. 197 * 198 * @returns VBox status code. 199 * @param pszName The driver name. 200 * @param pVtgHdr The VTG header. 201 * @param pImage The image if applicable. 202 * @param pSession The session if applicable. 203 * @param pszModName The module name. 204 */ 205 static int supdrvVtgRegister(PSUPDRVDEVEXT pDevExt, PVTGOBJHDR pVtgHdr, PSUPDRVLDRIMAGE pImage, PSUPDRVSESSION pSession, 206 const char *pszModName) 207 { 208 /* 209 * Validate input. 210 */ 211 AssertPtrReturn(pDevExt, VERR_INVALID_POINTER); 212 AssertPtrReturn(pVtgHdr, VERR_INVALID_POINTER); 213 AssertPtrNullReturn(pImage, VERR_INVALID_POINTER); 214 AssertPtrNullReturn(pSession, VERR_INVALID_POINTER); 215 AssertPtrReturn(pszModName, VERR_INVALID_POINTER); 216 AssertReturn((pImage == NULL) != (pSession != NULL), VERR_INVALID_PARAMETER); 217 218 219 220 /* 221 * 222 */ 223 224 } 225 226 227 228 /** 229 * Registers the VTG tracepoint providers of a driver. 230 * 231 * @returns VBox status code. 232 * @param pSession The support driver session handle. 233 * @param pVtgHdr The VTG header. 234 * @param pszName The driver name. 235 */ 236 SUPR0DECL(int) SUPR0VtgRegisterDrv(PSUPDRVSESSION pSession, PVTGOBJHDR pVtgHdr, const char *pszName) 237 { 238 AssertReturn(SUP_IS_SESSION_VALID(pSession), NULL); 239 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 240 AssertPtrReturn(pVtgHdr, VERR_INVALID_POINTER); 241 242 return supdrvVtgRegister(pSession->pDevExt, pVtgHdr, NULL, pSession, pszName); 243 } 244 245 246 247 /** 248 * Deregister the VTG tracepoint providers of a driver. 249 * 250 * @param pSession The support driver session handle. 251 * @param pVtgHdr The VTG header. 252 */ 253 SUPR0DECL(void) SUPR0VtgDeregisterDrv(PSUPDRVSESSION pSession, PVTGOBJHDR pVtgHdr) 254 { 255 } 256 257 86 258 87 259 /** 88 260 * Early module initialization hook. 89 * 261 * 90 262 * @returns VBox status code. 91 263 * @param pDevExt The device extension structure. … … 103 275 /** 104 276 * Late module termination hook. 105 * 277 * 106 278 * @returns VBox status code. 107 279 * @param pDevExt The device extension structure. … … 119 291 /** 120 292 * Module loading hook, called before calling into the module. 121 * 293 * 122 294 * @returns VBox status code. 123 295 * @param pDevExt The device extension structure. … … 126 298 { 127 299 /* 128 * Check for DTrace probes in the module, register a new provider for them 300 * Check for DTrace probes in the module, register a new provider for them 129 301 * if found. 130 302 */ … … 135 307 136 308 /** 137 * Module unloading hook, called after execution in the module 309 * Module unloading hook, called after execution in the module 138 310 * have ceased. 139 * 311 * 140 312 * @returns VBox status code. 141 313 * @param pDevExt The device extension structure. … … 143 315 int supdrvDTraceModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage) 144 316 { 145 /* 317 /* 146 318 * Undo what we did in supdrvDTraceModuleLoading. 147 319 */ … … 182 354 * @callback_method_impl{dtrace_pops_t,dtps_getargdesc} 183 355 */ 184 static void supdrvDTracePOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe, 356 static void supdrvDTracePOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe, 185 357 dtrace_argdesc_t *pArgDesc) 186 358 {
Note:
See TracChangeset
for help on using the changeset viewer.