1 | /* $Id: SUPDrv-dtrace.cpp 40600 2012-03-23 22:09:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxDrv - The VirtualBox Support Driver - DTrace Provider.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #define LOG_GROUP LOG_GROUP_SUP_DRV
|
---|
32 | #include "SUPDrvInternal.h"
|
---|
33 |
|
---|
34 | #include <VBox/err.h>
|
---|
35 | #include <VBox/VBoxTpG.h>
|
---|
36 | #include <iprt/assert.h>
|
---|
37 |
|
---|
38 | #include <sys/dtrace.h>
|
---|
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;
|
---|
68 |
|
---|
69 |
|
---|
70 | /*******************************************************************************
|
---|
71 | * Internal Functions *
|
---|
72 | *******************************************************************************/
|
---|
73 | static void supdrvDTracePOps_ProvideModule(void *pvProv, struct modctl *pMod);
|
---|
74 | static int supdrvDTracePOps_Enable(void *pvProv, dtrace_id_t idProbe, void *pvProbe);
|
---|
75 | static void supdrvDTracePOps_Disable(void *pvProv, dtrace_id_t idProbe, void *pvProbe);
|
---|
76 | static void supdrvDTracePOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe,
|
---|
77 | dtrace_argdesc_t *pArgDesc);
|
---|
78 | /*static uint64_t supdrvDTracePOps_GetArgVal(void *pvProv, dtrace_id_t idProbe, void *pvProbe,
|
---|
79 | int iArg, int cFrames);*/
|
---|
80 | static void supdrvDTracePOps_Destroy(void *pvProv, dtrace_id_t idProbe, void *pvProbe);
|
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 | /*******************************************************************************
|
---|
85 | * Global Variables *
|
---|
86 | *******************************************************************************/
|
---|
87 | /** The default provider attributes. */
|
---|
88 | static dtrace_pattr_t g_DefProvAttrs =
|
---|
89 | { /* .dtat_name, .dtat_data, .dtat_class */
|
---|
90 | /* .dtpa_provider = */ { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
|
---|
91 | /* .dtpa_mod = */ { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
|
---|
92 | /* .dtpa_func = */ { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
|
---|
93 | /* .dtpa_name = */ { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
|
---|
94 | /* .dtpa_args = */ { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
|
---|
95 | };
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * DTrace provider method table.
|
---|
99 | */
|
---|
100 | static const dtrace_pops_t g_SupDrvDTraceProvOps =
|
---|
101 | {
|
---|
102 | /* .dtps_provide = */ NULL,
|
---|
103 | /* .dtps_provide_module = */ supdrvDTracePOps_ProvideModule,
|
---|
104 | /* .dtps_enable = */ supdrvDTracePOps_Enable,
|
---|
105 | /* .dtps_disable = */ supdrvDTracePOps_Disable,
|
---|
106 | /* .dtps_suspend = */ NULL,
|
---|
107 | /* .dtps_resume = */ NULL,
|
---|
108 | /* .dtps_getargdesc = */ supdrvDTracePOps_GetArgDesc,
|
---|
109 | /* .dtps_getargval = */ NULL/*supdrvDTracePOps_GetArgVal*/,
|
---|
110 | /* .dtps_usermode = */ NULL,
|
---|
111 | /* .dtps_destroy = */ supdrvDTracePOps_Destroy
|
---|
112 | };
|
---|
113 |
|
---|
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 |
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Early module initialization hook.
|
---|
261 | *
|
---|
262 | * @returns VBox status code.
|
---|
263 | * @param pDevExt The device extension structure.
|
---|
264 | */
|
---|
265 | int supdrvDTraceInit(PSUPDRVDEVEXT pDevExt)
|
---|
266 | {
|
---|
267 | /*
|
---|
268 | * Register a provider for this module.
|
---|
269 | */
|
---|
270 |
|
---|
271 | return VINF_SUCCESS;
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Late module termination hook.
|
---|
277 | *
|
---|
278 | * @returns VBox status code.
|
---|
279 | * @param pDevExt The device extension structure.
|
---|
280 | */
|
---|
281 | int supdrvDTraceTerm(PSUPDRVDEVEXT pDevExt)
|
---|
282 | {
|
---|
283 | /*
|
---|
284 | * Undo what we did in supdrvDTraceInit.
|
---|
285 | */
|
---|
286 |
|
---|
287 | return VINF_SUCCESS;
|
---|
288 | }
|
---|
289 |
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * Module loading hook, called before calling into the module.
|
---|
293 | *
|
---|
294 | * @returns VBox status code.
|
---|
295 | * @param pDevExt The device extension structure.
|
---|
296 | */
|
---|
297 | int supdrvDTraceModuleLoading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
|
---|
298 | {
|
---|
299 | /*
|
---|
300 | * Check for DTrace probes in the module, register a new provider for them
|
---|
301 | * if found.
|
---|
302 | */
|
---|
303 |
|
---|
304 | return VINF_SUCCESS;
|
---|
305 | }
|
---|
306 |
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * Module unloading hook, called after execution in the module
|
---|
310 | * have ceased.
|
---|
311 | *
|
---|
312 | * @returns VBox status code.
|
---|
313 | * @param pDevExt The device extension structure.
|
---|
314 | */
|
---|
315 | int supdrvDTraceModuleUnloading(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
|
---|
316 | {
|
---|
317 | /*
|
---|
318 | * Undo what we did in supdrvDTraceModuleLoading.
|
---|
319 | */
|
---|
320 | return VINF_SUCCESS;
|
---|
321 | }
|
---|
322 |
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * @callback_method_impl{dtrace_pops_t,dtps_provide_module}
|
---|
329 | */
|
---|
330 | static void supdrvDTracePOps_ProvideModule(void *pvProv, struct modctl *pMod)
|
---|
331 | {
|
---|
332 | return;
|
---|
333 | }
|
---|
334 |
|
---|
335 |
|
---|
336 | /**
|
---|
337 | * @callback_method_impl{dtrace_pops_t,dtps_enable}
|
---|
338 | */
|
---|
339 | static int supdrvDTracePOps_Enable(void *pvProv, dtrace_id_t idProbe, void *pvProbe)
|
---|
340 | {
|
---|
341 | return -1;
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * @callback_method_impl{dtrace_pops_t,dtps_disable}
|
---|
347 | */
|
---|
348 | static void supdrvDTracePOps_Disable(void *pvProv, dtrace_id_t idProbe, void *pvProbe)
|
---|
349 | {
|
---|
350 | }
|
---|
351 |
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * @callback_method_impl{dtrace_pops_t,dtps_getargdesc}
|
---|
355 | */
|
---|
356 | static void supdrvDTracePOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe,
|
---|
357 | dtrace_argdesc_t *pArgDesc)
|
---|
358 | {
|
---|
359 | pArgDesc->dtargd_ndx = DTRACE_ARGNONE;
|
---|
360 | }
|
---|
361 |
|
---|
362 |
|
---|
363 | #if 0
|
---|
364 | /**
|
---|
365 | * @callback_method_impl{dtrace_pops_t,dtps_getargval}
|
---|
366 | */
|
---|
367 | static uint64_t supdrvDTracePOps_GetArgVal(void *pvProv, dtrace_id_t idProbe, void *pvProbe,
|
---|
368 | int iArg, int cFrames)
|
---|
369 | {
|
---|
370 | return 0xbeef;
|
---|
371 | }
|
---|
372 | #endif
|
---|
373 |
|
---|
374 |
|
---|
375 | /**
|
---|
376 | * @callback_method_impl{dtrace_pops_t,dtps_destroy}
|
---|
377 | */
|
---|
378 | static void supdrvDTracePOps_Destroy(void *pvProv, dtrace_id_t idProbe, void *pvProbe)
|
---|
379 | {
|
---|
380 | }
|
---|
381 |
|
---|
382 |
|
---|