VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPDrv-dtrace.cpp@ 60480

Last change on this file since 60480 was 58976, checked in by vboxsync, 9 years ago

VBoxTpG,SUPDrv: Extended VTGDESCPROVIDER again to facilitate HM in ring-0; major support driver version bump.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.4 KB
Line 
1/* $Id: SUPDrv-dtrace.cpp 58976 2015-12-03 21:42:04Z vboxsync $ */
2/** @file
3 * VBoxDrv - The VirtualBox Support Driver - DTrace Provider.
4 */
5
6/*
7 * Copyright (C) 2012-2015 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/log.h>
36#include <VBox/VBoxTpG.h>
37
38#include <iprt/assert.h>
39#include <iprt/ctype.h>
40#include <iprt/mem.h>
41#include <iprt/errno.h>
42#ifdef RT_OS_DARWIN
43# include <iprt/dbg.h>
44#endif
45
46#ifdef RT_OS_DARWIN
47# include VBOX_PATH_MACOSX_DTRACE_H
48#elif defined(RT_OS_LINUX)
49/* Avoid type and define conflicts. */
50# undef UINT8_MAX
51# undef UINT16_MAX
52# undef UINT32_MAX
53# undef UINT64_MAX
54# undef INT64_MAX
55# undef INT64_MIN
56# define intptr_t dtrace_intptr_t
57
58# if 0
59/* DTrace experiments with the Unbreakable Enterprise Kernel (UEK2)
60 (Oracle Linux).
61 1. The dtrace.h here is from the dtrace module source, not
62 /usr/include/sys/dtrace.h nor /usr/include/dtrace.h.
63 2. To generate the missing entries for the dtrace module in Module.symvers
64 of UEK:
65 nm /lib/modules/....../kernel/drivers/dtrace/dtrace.ko \
66 | grep _crc_ \
67 | sed -e 's/^......../0x/' -e 's/ A __crc_/\t/' \
68 -e 's/$/\tdrivers\/dtrace\/dtrace\tEXPORT_SYMBOL/' \
69 >> Module.symvers
70 Update: Althernative workaround (active), resolve symbols dynamically.
71 3. No tracepoints in vboxdrv, vboxnet* or vboxpci yet. This requires yasm
72 and VBoxTpG and build time. */
73# include "dtrace.h"
74# else
75/* DTrace experiments with the Unbreakable Enterprise Kernel (UEKR3)
76 (Oracle Linux).
77 1. To generate the missing entries for the dtrace module in Module.symvers
78 of UEK:
79 nm /lib/modules/....../kernel/drivers/dtrace/dtrace.ko \
80 | grep _crc_ \
81 | sed -e 's/^......../0x/' -e 's/ A __crc_/\t/' \
82 -e 's/$/\tdrivers\/dtrace\/dtrace\tEXPORT_SYMBOL/' \
83 >> Module.symvers
84 Update: Althernative workaround (active), resolve symbols dynamically.
85 2. No tracepoints in vboxdrv, vboxnet* or vboxpci yet. This requires yasm
86 and VBoxTpG and build time. */
87# include <dtrace/provider.h>
88# include <dtrace/enabling.h> /* Missing from provider.h. */
89# include <dtrace/arg.h> /* Missing from provider.h. */
90# endif
91# include <linux/kallsyms.h>
92/** Status code fixer (UEK uses linux convension unlike the others). */
93# define FIX_UEK_RC(a_rc) (-(a_rc))
94#else
95# include <sys/dtrace.h>
96#endif
97
98
99/**
100 * The UEK DTrace port is trying to be smart and seems to have turned all
101 * errno return codes negative. While this conforms to the linux kernel way of
102 * doing things, it breaks with the way the interfaces work on Solaris and
103 * Mac OS X.
104 */
105#ifndef FIX_UEK_RC
106# define FIX_UEK_RC(a_rc) (a_rc)
107#endif
108
109
110/*********************************************************************************************************************************
111* Structures and Typedefs *
112*********************************************************************************************************************************/
113/* Seems there is some return code difference here. Keep the return code and
114 case it to whatever the host desires. */
115#ifdef RT_OS_DARWIN
116# if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
117typedef void FNPOPS_ENABLE(void *, dtrace_id_t, void *);
118# else
119typedef int FNPOPS_ENABLE(void *, dtrace_id_t, void *);
120# endif
121#else
122typedef int FNPOPS_ENABLE(void *, dtrace_id_t, void *);
123#endif
124
125/** Caller indicator. */
126typedef enum VBOXDTCALLER
127{
128 kVBoxDtCaller_Invalid = 0,
129 kVBoxDtCaller_Generic,
130 kVBoxDtCaller_ProbeFireUser,
131 kVBoxDtCaller_ProbeFireKernel
132} VBOXDTCALLER;
133
134
135/**
136 * Stack data planted before calling dtrace_probe so that we can easily find the
137 * stack argument later.
138 */
139typedef struct VBDTSTACKDATA
140{
141 /** Eyecatcher no. 1 (SUPDRVDT_STACK_DATA_MAGIC2). */
142 uint32_t u32Magic1;
143 /** Eyecatcher no. 2 (SUPDRVDT_STACK_DATA_MAGIC2). */
144 uint32_t u32Magic2;
145 /** The format of the caller specific data. */
146 VBOXDTCALLER enmCaller;
147 /** Caller specific data. */
148 union
149 {
150 /** kVBoxDtCaller_ProbeFireKernel. */
151 struct
152 {
153 /** Pointer to the stack arguments of a probe function call. */
154 uintptr_t *pauStackArgs;
155 } ProbeFireKernel;
156 /** kVBoxDtCaller_ProbeFireUser. */
157 struct
158 {
159 /** The user context. */
160 PCSUPDRVTRACERUSRCTX pCtx;
161 /** The argument displacement caused by 64-bit arguments passed directly to
162 * dtrace_probe. */
163 int offArg;
164 } ProbeFireUser;
165 } u;
166 /** Pointer to this structure.
167 * This is the final bit of integrity checking. */
168 struct VBDTSTACKDATA *pSelf;
169} VBDTSTACKDATA;
170/** Pointer to the on-stack thread specific data. */
171typedef VBDTSTACKDATA *PVBDTSTACKDATA;
172
173
174/*********************************************************************************************************************************
175* Defined Constants And Macros *
176*********************************************************************************************************************************/
177/** The first magic value. */
178#define SUPDRVDT_STACK_DATA_MAGIC1 RT_MAKE_U32_FROM_U8('S', 'U', 'P', 'D')
179/** The second magic value. */
180#define SUPDRVDT_STACK_DATA_MAGIC2 RT_MAKE_U32_FROM_U8('D', 'T', 'r', 'c')
181
182/** The alignment of the stack data.
183 * The data doesn't require more than sizeof(uintptr_t) alignment, but the
184 * greater alignment the quicker lookup. */
185#define SUPDRVDT_STACK_DATA_ALIGN 32
186
187/** Plants the stack data. */
188#define VBDT_SETUP_STACK_DATA(a_enmCaller) \
189 uint8_t abBlob[sizeof(VBDTSTACKDATA) + SUPDRVDT_STACK_DATA_ALIGN - 1]; \
190 PVBDTSTACKDATA pStackData = (PVBDTSTACKDATA)( (uintptr_t)&abBlob[SUPDRVDT_STACK_DATA_ALIGN - 1] \
191 & ~(uintptr_t)(SUPDRVDT_STACK_DATA_ALIGN - 1)); \
192 pStackData->u32Magic1 = SUPDRVDT_STACK_DATA_MAGIC1; \
193 pStackData->u32Magic2 = SUPDRVDT_STACK_DATA_MAGIC2; \
194 pStackData->enmCaller = a_enmCaller; \
195 pStackData->pSelf = pStackData
196
197/** Passifies the stack data and frees up resource held within it. */
198#define VBDT_CLEAR_STACK_DATA() \
199 do \
200 { \
201 pStackData->u32Magic1 = 0; \
202 pStackData->u32Magic2 = 0; \
203 pStackData->pSelf = NULL; \
204 } while (0)
205
206/** Simple SUPR0Printf-style logging. */
207#if 0 /*def DEBUG_bird*/
208# define LOG_DTRACE(a) SUPR0Printf a
209#else
210# define LOG_DTRACE(a) do { } while (0)
211#endif
212
213
214/*********************************************************************************************************************************
215* Global Variables *
216*********************************************************************************************************************************/
217#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX)
218/** @name DTrace kernel interface used on Darwin and Linux.
219 * @{ */
220static void (* g_pfnDTraceProbeFire)(dtrace_id_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
221static dtrace_id_t (* g_pfnDTraceProbeCreate)(dtrace_provider_id_t, const char *, const char *, const char *, int, void *);
222static dtrace_id_t (* g_pfnDTraceProbeLookup)(dtrace_provider_id_t, const char *, const char *, const char *);
223static int (* g_pfnDTraceProviderRegister)(const char *, const dtrace_pattr_t *, uint32_t, /*cred_t*/ void *,
224 const dtrace_pops_t *, void *, dtrace_provider_id_t *);
225static void (* g_pfnDTraceProviderInvalidate)(dtrace_provider_id_t);
226static int (* g_pfnDTraceProviderUnregister)(dtrace_provider_id_t);
227
228#define dtrace_probe g_pfnDTraceProbeFire
229#define dtrace_probe_create g_pfnDTraceProbeCreate
230#define dtrace_probe_lookup g_pfnDTraceProbeLookup
231#define dtrace_register g_pfnDTraceProviderRegister
232#define dtrace_invalidate g_pfnDTraceProviderInvalidate
233#define dtrace_unregister g_pfnDTraceProviderUnregister
234
235/** @} */
236#endif
237
238
239/**
240 * Gets the stack data.
241 *
242 * @returns Pointer to the stack data. Never NULL.
243 */
244static PVBDTSTACKDATA vboxDtGetStackData(void)
245{
246 /*
247 * Locate the caller of probe_dtrace.
248 */
249 int volatile iDummy = 1; /* use this to get the stack address. */
250 PVBDTSTACKDATA pData = (PVBDTSTACKDATA)( ((uintptr_t)&iDummy + SUPDRVDT_STACK_DATA_ALIGN - 1)
251 & ~(uintptr_t)(SUPDRVDT_STACK_DATA_ALIGN - 1));
252 for (;;)
253 {
254 if ( pData->u32Magic1 == SUPDRVDT_STACK_DATA_MAGIC1
255 && pData->u32Magic2 == SUPDRVDT_STACK_DATA_MAGIC2
256 && pData->pSelf == pData)
257 return pData;
258 pData = (PVBDTSTACKDATA)((uintptr_t)pData + SUPDRVDT_STACK_DATA_ALIGN);
259 }
260}
261
262
263/*
264 *
265 * Helpers for handling VTG structures.
266 * Helpers for handling VTG structures.
267 * Helpers for handling VTG structures.
268 *
269 */
270
271
272
273/**
274 * Converts an attribute from VTG description speak to DTrace.
275 *
276 * @param pDtAttr The DTrace attribute (dst).
277 * @param pVtgAttr The VTG attribute descriptor (src).
278 */
279static void vboxDtVtgConvAttr(dtrace_attribute_t *pDtAttr, PCVTGDESCATTR pVtgAttr)
280{
281 pDtAttr->dtat_name = pVtgAttr->u8Code - 1;
282 pDtAttr->dtat_data = pVtgAttr->u8Data - 1;
283 pDtAttr->dtat_class = pVtgAttr->u8DataDep - 1;
284}
285
286/**
287 * Gets a string from the string table.
288 *
289 * @returns Pointer to the string.
290 * @param pVtgHdr The VTG object header.
291 * @param offStrTab The string table offset.
292 */
293static const char *vboxDtVtgGetString(PVTGOBJHDR pVtgHdr, uint32_t offStrTab)
294{
295 Assert(offStrTab < pVtgHdr->cbStrTab);
296 return (const char *)pVtgHdr + pVtgHdr->offStrTab + offStrTab;
297}
298
299
300
301/*
302 *
303 * DTrace Provider Interface.
304 * DTrace Provider Interface.
305 * DTrace Provider Interface.
306 *
307 */
308
309
310/**
311 * @callback_method_impl{dtrace_pops_t,dtps_provide}
312 */
313static void vboxDtPOps_Provide(void *pvProv, const dtrace_probedesc_t *pDtProbeDesc)
314{
315 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv;
316 AssertPtrReturnVoid(pProv);
317 LOG_DTRACE(("%s: %p / %p pDtProbeDesc=%p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, pDtProbeDesc));
318
319 if (pDtProbeDesc)
320 return; /* We don't generate probes, so never mind these requests. */
321
322 if (pProv->TracerData.DTrace.fZombie)
323 return;
324
325 dtrace_provider_id_t const idProvider = pProv->TracerData.DTrace.idProvider;
326 AssertPtrReturnVoid(idProvider);
327
328 AssertPtrReturnVoid(pProv->pHdr);
329 AssertReturnVoid(pProv->pHdr->offProbeLocs != 0);
330 uint32_t const cProbeLocs = pProv->pHdr->cbProbeLocs / sizeof(VTGPROBELOC);
331
332 /* Need a buffer for extracting the function names and mangling them in
333 case of collision. */
334 size_t const cbFnNmBuf = _4K + _1K;
335 char *pszFnNmBuf = (char *)RTMemAlloc(cbFnNmBuf);
336 if (!pszFnNmBuf)
337 return;
338
339 /*
340 * Itereate the probe location list and register all probes related to
341 * this provider.
342 */
343 uint16_t const idxProv = (uint16_t)((PVTGDESCPROVIDER)((uintptr_t)pProv->pHdr + pProv->pHdr->offProviders) - pProv->pDesc);
344 uint32_t idxProbeLoc;
345 for (idxProbeLoc = 0; idxProbeLoc < cProbeLocs; idxProbeLoc++)
346 {
347 /* Skip probe location belonging to other providers or once that
348 we've already reported. */
349 PCVTGPROBELOC pProbeLocRO = &pProv->paProbeLocsRO[idxProbeLoc];
350 PVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe;
351 if (pProbeDesc->idxProvider != idxProv)
352 continue;
353
354 uint32_t *pidProbe;
355 if (!pProv->fUmod)
356 pidProbe = (uint32_t *)&pProbeLocRO->idProbe;
357 else
358 pidProbe = &pProv->paR0ProbeLocs[idxProbeLoc].idProbe;
359 if (*pidProbe != 0)
360 continue;
361
362 /* The function name may need to be stripped since we're using C++
363 compilers for most of the code. ASSUMES nobody are brave/stupid
364 enough to use function pointer returns without typedef'ing
365 properly them (e.g. signal). */
366 const char *pszPrbName = vboxDtVtgGetString(pProv->pHdr, pProbeDesc->offName);
367 const char *pszFunc = pProbeLocRO->pszFunction;
368 const char *psz = strchr(pProbeLocRO->pszFunction, '(');
369 size_t cch;
370 if (psz)
371 {
372 /* skip blanks preceeding the parameter parenthesis. */
373 while ( (uintptr_t)psz > (uintptr_t)pProbeLocRO->pszFunction
374 && RT_C_IS_BLANK(psz[-1]))
375 psz--;
376
377 /* Find the start of the function name. */
378 pszFunc = psz - 1;
379 while ((uintptr_t)pszFunc > (uintptr_t)pProbeLocRO->pszFunction)
380 {
381 char ch = pszFunc[-1];
382 if (!RT_C_IS_ALNUM(ch) && ch != '_' && ch != ':')
383 break;
384 pszFunc--;
385 }
386 cch = psz - pszFunc;
387 }
388 else
389 cch = strlen(pszFunc);
390 RTStrCopyEx(pszFnNmBuf, cbFnNmBuf, pszFunc, cch);
391
392 /* Look up the probe, if we have one in the same function, mangle
393 the function name a little to avoid having to deal with having
394 multiple location entries with the same probe ID. (lazy bird) */
395 Assert(!*pidProbe);
396 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) != DTRACE_IDNONE)
397 {
398 RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u", pProbeLocRO->uLine);
399 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) != DTRACE_IDNONE)
400 {
401 unsigned iOrd = 2;
402 while (iOrd < 128)
403 {
404 RTStrPrintf(pszFnNmBuf+cch, cbFnNmBuf - cch, "-%u-%u", pProbeLocRO->uLine, iOrd);
405 if (dtrace_probe_lookup(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName) == DTRACE_IDNONE)
406 break;
407 iOrd++;
408 }
409 if (iOrd >= 128)
410 {
411 LogRel(("VBoxDrv: More than 128 duplicate probe location instances %s at line %u in function %s [%s], probe %s\n",
412 pProbeLocRO->uLine, pProbeLocRO->pszFunction, pszFnNmBuf, pszPrbName));
413 continue;
414 }
415 }
416 }
417
418 /* Create the probe. */
419 AssertCompile(sizeof(*pidProbe) == sizeof(dtrace_id_t));
420 *pidProbe = dtrace_probe_create(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName,
421 1 /*aframes*/, (void *)(uintptr_t)idxProbeLoc);
422 pProv->TracerData.DTrace.cProvidedProbes++;
423 }
424
425 RTMemFree(pszFnNmBuf);
426 LOG_DTRACE(("%s: returns\n", __FUNCTION__));
427}
428
429
430/**
431 * @callback_method_impl{dtrace_pops_t,dtps_enable}
432 */
433static int vboxDtPOps_Enable(void *pvProv, dtrace_id_t idProbe, void *pvProbe)
434{
435 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv;
436 LOG_DTRACE(("%s: %p / %p - %#x / %p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe));
437 AssertPtrReturn(pProv->TracerData.DTrace.idProvider, EINVAL);
438
439 if (!pProv->TracerData.DTrace.fZombie)
440 {
441 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe;
442 PVTGPROBELOC32 pProbeLocEn = (PVTGPROBELOC32)( (uintptr_t)pProv->pvProbeLocsEn + idxProbeLoc * pProv->cbProbeLocsEn);
443 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc];
444 PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe;
445 uint32_t const idxProbe = pProbeDesc->idxEnabled;
446
447 if (!pProv->fUmod)
448 {
449 if (!pProbeLocEn->fEnabled)
450 {
451 pProbeLocEn->fEnabled = 1;
452 ASMAtomicIncU32(&pProv->pacProbeEnabled[idxProbe]);
453 ASMAtomicIncU32(&pProv->pDesc->cProbesEnabled);
454 ASMAtomicIncU32(&pProv->pDesc->uSettingsSerialNo);
455 }
456 }
457 else
458 {
459 /* Update kernel mode structure */
460 if (!pProv->paR0ProbeLocs[idxProbeLoc].fEnabled)
461 {
462 pProv->paR0ProbeLocs[idxProbeLoc].fEnabled = 1;
463 ASMAtomicIncU32(&pProv->paR0Probes[idxProbe].cEnabled);
464 ASMAtomicIncU32(&pProv->pDesc->cProbesEnabled);
465 ASMAtomicIncU32(&pProv->pDesc->uSettingsSerialNo);
466 }
467
468 /* Update user mode structure. */
469 pProbeLocEn->fEnabled = 1;
470 pProv->pacProbeEnabled[idxProbe] = pProv->paR0Probes[idxProbe].cEnabled;
471 }
472 }
473
474 return 0;
475}
476
477
478/**
479 * @callback_method_impl{dtrace_pops_t,dtps_disable}
480 */
481static void vboxDtPOps_Disable(void *pvProv, dtrace_id_t idProbe, void *pvProbe)
482{
483 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv;
484 AssertPtrReturnVoid(pProv);
485 LOG_DTRACE(("%s: %p / %p - %#x / %p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe));
486 AssertPtrReturnVoid(pProv->TracerData.DTrace.idProvider);
487
488 if (!pProv->TracerData.DTrace.fZombie)
489 {
490 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe;
491 PVTGPROBELOC32 pProbeLocEn = (PVTGPROBELOC32)( (uintptr_t)pProv->pvProbeLocsEn + idxProbeLoc * pProv->cbProbeLocsEn);
492 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc];
493 PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe;
494 uint32_t const idxProbe = pProbeDesc->idxEnabled;
495
496 if (!pProv->fUmod)
497 {
498 if (pProbeLocEn->fEnabled)
499 {
500 pProbeLocEn->fEnabled = 0;
501 ASMAtomicDecU32(&pProv->pacProbeEnabled[idxProbe]);
502 ASMAtomicIncU32(&pProv->pDesc->cProbesEnabled);
503 ASMAtomicIncU32(&pProv->pDesc->uSettingsSerialNo);
504 }
505 }
506 else
507 {
508 /* Update kernel mode structure */
509 if (pProv->paR0ProbeLocs[idxProbeLoc].fEnabled)
510 {
511 pProv->paR0ProbeLocs[idxProbeLoc].fEnabled = 0;
512 ASMAtomicDecU32(&pProv->paR0Probes[idxProbe].cEnabled);
513 ASMAtomicDecU32(&pProv->pDesc->cProbesEnabled);
514 ASMAtomicIncU32(&pProv->pDesc->uSettingsSerialNo);
515 }
516
517 /* Update user mode structure. */
518 pProbeLocEn->fEnabled = 0;
519 pProv->pacProbeEnabled[idxProbe] = pProv->paR0Probes[idxProbe].cEnabled;
520 }
521 }
522}
523
524
525/**
526 * @callback_method_impl{dtrace_pops_t,dtps_getargdesc}
527 */
528static void vboxDtPOps_GetArgDesc(void *pvProv, dtrace_id_t idProbe, void *pvProbe,
529 dtrace_argdesc_t *pArgDesc)
530{
531 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv;
532 unsigned uArg = pArgDesc->dtargd_ndx;
533
534 pArgDesc->dtargd_ndx = DTRACE_ARGNONE;
535 AssertPtrReturnVoid(pProv);
536 LOG_DTRACE(("%s: %p / %p - %#x / %p uArg=%d\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe, uArg));
537 AssertPtrReturnVoid(pProv->TracerData.DTrace.idProvider);
538
539 if (!pProv->TracerData.DTrace.fZombie)
540 {
541 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe;
542 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc];
543 PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe;
544 PCVTGDESCARGLIST pArgList = (PCVTGDESCARGLIST)( (uintptr_t)pProv->pHdr
545 + pProv->pHdr->offArgLists
546 + pProbeDesc->offArgList);
547 AssertReturnVoid(pProbeDesc->offArgList < pProv->pHdr->cbArgLists);
548
549 if (uArg < pArgList->cArgs)
550 {
551 const char *pszType = vboxDtVtgGetString(pProv->pHdr, pArgList->aArgs[uArg].offType);
552 size_t cchType = strlen(pszType);
553 if (cchType < sizeof(pArgDesc->dtargd_native))
554 {
555 memcpy(pArgDesc->dtargd_native, pszType, cchType + 1);
556 /** @todo mapping? */
557 pArgDesc->dtargd_ndx = uArg;
558 LOG_DTRACE(("%s: returns dtargd_native = %s\n", __FUNCTION__, pArgDesc->dtargd_native));
559 return;
560 }
561 }
562 }
563}
564
565
566/**
567 * @callback_method_impl{dtrace_pops_t,dtps_getargval}
568 *
569 *
570 * We just cook our own stuff here, using a stack marker for finding the
571 * required information. That's more reliable than subjecting oneself to the
572 * solaris bugs and 32-bit apple peculiarities.
573 *
574 *
575 * @remarks Solaris Bug
576 *
577 * dtrace_getarg on AMD64 has a different opinion about how to use the cFrames
578 * argument than dtrace_caller() and/or dtrace_getpcstack(), at least when the
579 * probe is fired by dtrace_probe() the way we do.
580 *
581 * Setting aframes to 1 when calling dtrace_probe_create gives me the right
582 * arguments, but the wrong 'caller'. Since I cannot do anything about
583 * 'caller', the only solution is this hack.
584 *
585 * Not sure why the Solaris guys hasn't seen this issue before, but maybe there
586 * isn't anyone using the default argument getter path for ring-0 dtrace_probe()
587 * calls, SDT surely isn't.
588 *
589 * @todo File a solaris bug on dtrace_probe() + dtrace_getarg().
590 *
591 *
592 * @remarks 32-bit XNU (Apple)
593 *
594 * The dtrace_probe arguments are 64-bit unsigned integers instead of uintptr_t,
595 * so we need to make an extra call.
596 *
597 */
598static uint64_t vboxDtPOps_GetArgVal(void *pvProv, dtrace_id_t idProbe, void *pvProbe,
599 int iArg, int cFrames)
600{
601 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv;
602 AssertPtrReturn(pProv, UINT64_MAX);
603 LOG_DTRACE(("%s: %p / %p - %#x / %p iArg=%d cFrames=%u\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe, iArg, cFrames));
604 AssertReturn(iArg >= 5, UINT64_MAX);
605 if (pProv->TracerData.DTrace.fZombie)
606 return UINT64_MAX;
607
608 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe;
609 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc];
610 PCVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe;
611 PCVTGDESCARGLIST pArgList = (PCVTGDESCARGLIST)( (uintptr_t)pProv->pHdr
612 + pProv->pHdr->offArgLists
613 + pProbeDesc->offArgList);
614 AssertReturn(pProbeDesc->offArgList < pProv->pHdr->cbArgLists, UINT64_MAX);
615
616 PVBDTSTACKDATA pData = vboxDtGetStackData();
617
618 /*
619 * Get the stack data. This is a wee bit complicated on 32-bit systems
620 * since we want to support 64-bit integer arguments.
621 */
622 uint64_t u64Ret;
623 if (iArg >= 20)
624 u64Ret = UINT64_MAX;
625 else if (pData->enmCaller == kVBoxDtCaller_ProbeFireKernel)
626 {
627#if ARCH_BITS == 64
628 u64Ret = pData->u.ProbeFireKernel.pauStackArgs[iArg - 5];
629#else
630 if ( !pArgList->fHaveLargeArgs
631 || iArg >= pArgList->cArgs)
632 u64Ret = pData->u.ProbeFireKernel.pauStackArgs[iArg - 5];
633 else
634 {
635 /* Similar to what we did for mac in when calling dtrace_probe(). */
636 uint32_t offArg = 0;
637 for (int i = 5; i < iArg; i++)
638 if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType))
639 offArg++;
640 u64Ret = pData->u.ProbeFireKernel.pauStackArgs[iArg - 5 + offArg];
641 if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType))
642 u64Ret |= (uint64_t)pData->u.ProbeFireKernel.pauStackArgs[iArg - 5 + offArg + 1] << 32;
643 }
644#endif
645 }
646 else if (pData->enmCaller == kVBoxDtCaller_ProbeFireUser)
647 {
648 int offArg = pData->u.ProbeFireUser.offArg;
649 PCSUPDRVTRACERUSRCTX pCtx = pData->u.ProbeFireUser.pCtx;
650 AssertPtrReturn(pCtx, UINT64_MAX);
651
652 if (pCtx->cBits == 32)
653 {
654 if ( !pArgList->fHaveLargeArgs
655 || iArg >= pArgList->cArgs)
656 {
657 if (iArg + offArg < (int)RT_ELEMENTS(pCtx->u.X86.aArgs))
658 u64Ret = pCtx->u.X86.aArgs[iArg + offArg];
659 else
660 u64Ret = UINT64_MAX;
661 }
662 else
663 {
664 int i;
665 for (i = 5; i < iArg; i++)
666 if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType))
667 offArg++;
668 if (offArg + iArg < (int)RT_ELEMENTS(pCtx->u.X86.aArgs))
669 {
670 u64Ret = pCtx->u.X86.aArgs[iArg + offArg];
671 if ( VTG_TYPE_IS_LARGE(pArgList->aArgs[iArg].fType)
672 && offArg + iArg + 1 < (int)RT_ELEMENTS(pCtx->u.X86.aArgs))
673 u64Ret |= (uint64_t)pCtx->u.X86.aArgs[iArg + offArg + 1] << 32;
674 }
675 else
676 u64Ret = UINT64_MAX;
677 }
678 }
679 else
680 {
681 if (iArg + offArg < (int)RT_ELEMENTS(pCtx->u.Amd64.aArgs))
682 u64Ret = pCtx->u.Amd64.aArgs[iArg + offArg];
683 else
684 u64Ret = UINT64_MAX;
685 }
686 }
687 else
688 AssertFailedReturn(UINT64_MAX);
689
690 LOG_DTRACE(("%s: returns %#llx\n", __FUNCTION__, u64Ret));
691 return u64Ret;
692}
693
694
695/**
696 * @callback_method_impl{dtrace_pops_t,dtps_destroy}
697 */
698static void vboxDtPOps_Destroy(void *pvProv, dtrace_id_t idProbe, void *pvProbe)
699{
700 PSUPDRVVDTPROVIDERCORE pProv = (PSUPDRVVDTPROVIDERCORE)pvProv;
701 AssertPtrReturnVoid(pProv);
702 LOG_DTRACE(("%s: %p / %p - %#x / %p\n", __FUNCTION__, pProv, pProv->TracerData.DTrace.idProvider, idProbe, pvProbe));
703 AssertReturnVoid(pProv->TracerData.DTrace.cProvidedProbes > 0);
704 AssertPtrReturnVoid(pProv->TracerData.DTrace.idProvider);
705
706 if (!pProv->TracerData.DTrace.fZombie)
707 {
708 uint32_t idxProbeLoc = (uint32_t)(uintptr_t)pvProbe;
709 PCVTGPROBELOC pProbeLocRO = (PVTGPROBELOC)&pProv->paProbeLocsRO[idxProbeLoc];
710 uint32_t *pidProbe;
711 if (!pProv->fUmod)
712 {
713 pidProbe = (uint32_t *)&pProbeLocRO->idProbe;
714 Assert(!pProbeLocRO->fEnabled);
715 Assert(*pidProbe == idProbe);
716 }
717 else
718 {
719 pidProbe = &pProv->paR0ProbeLocs[idxProbeLoc].idProbe;
720 Assert(!pProv->paR0ProbeLocs[idxProbeLoc].fEnabled);
721 Assert(*pidProbe == idProbe); NOREF(idProbe);
722 }
723 *pidProbe = 0;
724 }
725 pProv->TracerData.DTrace.cProvidedProbes--;
726}
727
728
729
730/**
731 * DTrace provider method table.
732 */
733static const dtrace_pops_t g_vboxDtVtgProvOps =
734{
735 /* .dtps_provide = */ vboxDtPOps_Provide,
736 /* .dtps_provide_module = */ NULL,
737 /* .dtps_enable = */ (FNPOPS_ENABLE *)vboxDtPOps_Enable,
738 /* .dtps_disable = */ vboxDtPOps_Disable,
739 /* .dtps_suspend = */ NULL,
740 /* .dtps_resume = */ NULL,
741 /* .dtps_getargdesc = */ vboxDtPOps_GetArgDesc,
742 /* .dtps_getargval = */ vboxDtPOps_GetArgVal,
743 /* .dtps_usermode = */ NULL,
744 /* .dtps_destroy = */ vboxDtPOps_Destroy
745};
746
747
748
749
750/*
751 *
752 * Support Driver Tracer Interface.
753 * Support Driver Tracer Interface.
754 * Support Driver Tracer Interface.
755 *
756 */
757
758
759
760/**
761 * interface_method_impl{SUPDRVTRACERREG,pfnProbeFireKernel}
762 */
763static DECLCALLBACK(void) vboxDtTOps_ProbeFireKernel(struct VTGPROBELOC *pVtgProbeLoc, uintptr_t uArg0, uintptr_t uArg1, uintptr_t uArg2,
764 uintptr_t uArg3, uintptr_t uArg4)
765{
766 AssertPtrReturnVoid(pVtgProbeLoc);
767 LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pVtgProbeLoc, pVtgProbeLoc->idProbe));
768 AssertPtrReturnVoid(pVtgProbeLoc->pProbe);
769 AssertPtrReturnVoid(pVtgProbeLoc->pszFunction);
770
771 VBDT_SETUP_STACK_DATA(kVBoxDtCaller_ProbeFireKernel);
772
773 pStackData->u.ProbeFireKernel.pauStackArgs = &uArg4 + 1;
774
775#if defined(RT_OS_DARWIN) && ARCH_BITS == 32
776 /*
777 * Convert arguments from uintptr_t to uint64_t.
778 */
779 PVTGDESCPROBE pProbe = (PVTGDESCPROBE)((PVTGPROBELOC)pVtgProbeLoc)->pProbe;
780 AssertPtrReturnVoid(pProbe);
781 PVTGOBJHDR pVtgHdr = (PVTGOBJHDR)((uintptr_t)pProbe + pProbe->offObjHdr);
782 AssertPtrReturnVoid(pVtgHdr);
783 PVTGDESCARGLIST pArgList = (PVTGDESCARGLIST)((uintptr_t)pVtgHdr + pVtgHdr->offArgLists + pProbe->offArgList);
784 AssertPtrReturnVoid(pArgList);
785 if (!pArgList->fHaveLargeArgs)
786 dtrace_probe(pVtgProbeLoc->idProbe, uArg0, uArg1, uArg2, uArg3, uArg4);
787 else
788 {
789 uintptr_t *auSrcArgs = &uArg0;
790 uint32_t iSrcArg = 0;
791 uint32_t iDstArg = 0;
792 uint64_t au64DstArgs[5];
793
794 while ( iDstArg < RT_ELEMENTS(au64DstArgs)
795 && iSrcArg < pArgList->cArgs)
796 {
797 au64DstArgs[iDstArg] = auSrcArgs[iSrcArg];
798 if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iDstArg].fType))
799 au64DstArgs[iDstArg] |= (uint64_t)auSrcArgs[++iSrcArg] << 32;
800 iSrcArg++;
801 iDstArg++;
802 }
803 while (iDstArg < RT_ELEMENTS(au64DstArgs))
804 au64DstArgs[iDstArg++] = auSrcArgs[iSrcArg++];
805
806 pStackData->u.ProbeFireKernel.pauStackArgs = &auSrcArgs[iSrcArg];
807 dtrace_probe(pVtgProbeLoc->idProbe, au64DstArgs[0], au64DstArgs[1], au64DstArgs[2], au64DstArgs[3], au64DstArgs[4]);
808 }
809#else
810 dtrace_probe(pVtgProbeLoc->idProbe, uArg0, uArg1, uArg2, uArg3, uArg4);
811#endif
812
813 VBDT_CLEAR_STACK_DATA();
814 LOG_DTRACE(("%s: returns\n", __FUNCTION__));
815}
816
817
818/**
819 * interface_method_impl{SUPDRVTRACERREG,pfnProbeFireUser}
820 */
821static DECLCALLBACK(void) vboxDtTOps_ProbeFireUser(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, PCSUPDRVTRACERUSRCTX pCtx,
822 PCVTGOBJHDR pVtgHdr, PCVTGPROBELOC pProbeLocRO)
823{
824 LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pCtx, pCtx->idProbe));
825 AssertPtrReturnVoid(pProbeLocRO);
826 AssertPtrReturnVoid(pVtgHdr);
827
828 VBDT_SETUP_STACK_DATA(kVBoxDtCaller_ProbeFireUser);
829
830 if (pCtx->cBits == 32)
831 {
832 pStackData->u.ProbeFireUser.pCtx = pCtx;
833 pStackData->u.ProbeFireUser.offArg = 0;
834
835#if ARCH_BITS == 64 || defined(RT_OS_DARWIN)
836 /*
837 * Combine two 32-bit arguments into one 64-bit argument where needed.
838 */
839 PVTGDESCPROBE pProbeDesc = pProbeLocRO->pProbe;
840 AssertPtrReturnVoid(pProbeDesc);
841 PVTGDESCARGLIST pArgList = (PVTGDESCARGLIST)((uintptr_t)pVtgHdr + pVtgHdr->offArgLists + pProbeDesc->offArgList);
842 AssertPtrReturnVoid(pArgList);
843
844 if (!pArgList->fHaveLargeArgs)
845 dtrace_probe(pCtx->idProbe,
846 pCtx->u.X86.aArgs[0],
847 pCtx->u.X86.aArgs[1],
848 pCtx->u.X86.aArgs[2],
849 pCtx->u.X86.aArgs[3],
850 pCtx->u.X86.aArgs[4]);
851 else
852 {
853 uint32_t const *auSrcArgs = &pCtx->u.X86.aArgs[0];
854 uint32_t iSrcArg = 0;
855 uint32_t iDstArg = 0;
856 uint64_t au64DstArgs[5];
857
858 while ( iDstArg < RT_ELEMENTS(au64DstArgs)
859 && iSrcArg < pArgList->cArgs)
860 {
861 au64DstArgs[iDstArg] = auSrcArgs[iSrcArg];
862 if (VTG_TYPE_IS_LARGE(pArgList->aArgs[iDstArg].fType))
863 au64DstArgs[iDstArg] |= (uint64_t)auSrcArgs[++iSrcArg] << 32;
864 iSrcArg++;
865 iDstArg++;
866 }
867 while (iDstArg < RT_ELEMENTS(au64DstArgs))
868 au64DstArgs[iDstArg++] = auSrcArgs[iSrcArg++];
869
870 pStackData->u.ProbeFireUser.offArg = iSrcArg - RT_ELEMENTS(au64DstArgs);
871 dtrace_probe(pCtx->idProbe, au64DstArgs[0], au64DstArgs[1], au64DstArgs[2], au64DstArgs[3], au64DstArgs[4]);
872 }
873#else
874 dtrace_probe(pCtx->idProbe,
875 pCtx->u.X86.aArgs[0],
876 pCtx->u.X86.aArgs[1],
877 pCtx->u.X86.aArgs[2],
878 pCtx->u.X86.aArgs[3],
879 pCtx->u.X86.aArgs[4]);
880#endif
881 }
882 else if (pCtx->cBits == 64)
883 {
884 pStackData->u.ProbeFireUser.pCtx = pCtx;
885 pStackData->u.ProbeFireUser.offArg = 0;
886 dtrace_probe(pCtx->idProbe,
887 pCtx->u.Amd64.aArgs[0],
888 pCtx->u.Amd64.aArgs[1],
889 pCtx->u.Amd64.aArgs[2],
890 pCtx->u.Amd64.aArgs[3],
891 pCtx->u.Amd64.aArgs[4]);
892 }
893 else
894 AssertFailed();
895
896 VBDT_CLEAR_STACK_DATA();
897 LOG_DTRACE(("%s: returns\n", __FUNCTION__));
898}
899
900
901/**
902 * interface_method_impl{SUPDRVTRACERREG,pfnTracerOpen}
903 */
904static DECLCALLBACK(int) vboxDtTOps_TracerOpen(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uint32_t uCookie,
905 uintptr_t uArg, uintptr_t *puSessionData)
906{
907 NOREF(pThis); NOREF(pSession); NOREF(uCookie); NOREF(uArg);
908 *puSessionData = 0;
909 return VERR_NOT_SUPPORTED;
910}
911
912
913/**
914 * interface_method_impl{SUPDRVTRACERREG,pfnTracerClose}
915 */
916static DECLCALLBACK(int) vboxDtTOps_TracerIoCtl(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData,
917 uintptr_t uCmd, uintptr_t uArg, int32_t *piRetVal)
918{
919 NOREF(pThis); NOREF(pSession); NOREF(uSessionData);
920 NOREF(uCmd); NOREF(uArg); NOREF(piRetVal);
921 return VERR_NOT_SUPPORTED;
922}
923
924
925/**
926 * interface_method_impl{SUPDRVTRACERREG,pfnTracerClose}
927 */
928static DECLCALLBACK(void) vboxDtTOps_TracerClose(PCSUPDRVTRACERREG pThis, PSUPDRVSESSION pSession, uintptr_t uSessionData)
929{
930 NOREF(pThis); NOREF(pSession); NOREF(uSessionData);
931 return;
932}
933
934
935/**
936 * interface_method_impl{SUPDRVTRACERREG,pfnProviderRegister}
937 */
938static DECLCALLBACK(int) vboxDtTOps_ProviderRegister(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore)
939{
940 LOG_DTRACE(("%s: %p %s/%s\n", __FUNCTION__, pThis, pCore->pszModName, pCore->pszName));
941 AssertReturn(pCore->TracerData.DTrace.idProvider == 0, VERR_INTERNAL_ERROR_3);
942
943 PVTGDESCPROVIDER pDesc = pCore->pDesc;
944 dtrace_pattr_t DtAttrs;
945 vboxDtVtgConvAttr(&DtAttrs.dtpa_provider, &pDesc->AttrSelf);
946 vboxDtVtgConvAttr(&DtAttrs.dtpa_mod, &pDesc->AttrModules);
947 vboxDtVtgConvAttr(&DtAttrs.dtpa_func, &pDesc->AttrFunctions);
948 vboxDtVtgConvAttr(&DtAttrs.dtpa_name, &pDesc->AttrNames);
949 vboxDtVtgConvAttr(&DtAttrs.dtpa_args, &pDesc->AttrArguments);
950
951 /* Note! DTrace may call us back before dtrace_register returns, so we
952 have to point it to pCore->TracerData.DTrace.idProvider. */
953 AssertCompile(sizeof(dtrace_provider_id_t) == sizeof(pCore->TracerData.DTrace.idProvider));
954 int rc = dtrace_register(pCore->pszName,
955 &DtAttrs,
956 DTRACE_PRIV_KERNEL,
957 NULL /* cred */,
958 &g_vboxDtVtgProvOps,
959 pCore,
960 &pCore->TracerData.DTrace.idProvider);
961 if (!rc)
962 {
963 LOG_DTRACE(("%s: idProvider=%p\n", __FUNCTION__, pCore->TracerData.DTrace.idProvider));
964 AssertPtr(pCore->TracerData.DTrace.idProvider);
965 rc = VINF_SUCCESS;
966 }
967 else
968 {
969 pCore->TracerData.DTrace.idProvider = 0;
970 rc = RTErrConvertFromErrno(FIX_UEK_RC(rc));
971 }
972
973 LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc));
974 return rc;
975}
976
977
978/**
979 * interface_method_impl{SUPDRVTRACERREG,pfnProviderDeregister}
980 */
981static DECLCALLBACK(int) vboxDtTOps_ProviderDeregister(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore)
982{
983 uintptr_t idProvider = pCore->TracerData.DTrace.idProvider;
984 LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pThis, idProvider));
985 AssertPtrReturn(idProvider, VERR_INTERNAL_ERROR_3);
986
987 dtrace_invalidate(idProvider);
988 int rc = dtrace_unregister(idProvider);
989 if (!rc)
990 {
991 pCore->TracerData.DTrace.idProvider = 0;
992 rc = VINF_SUCCESS;
993 }
994 else
995 {
996 AssertMsg(FIX_UEK_RC(rc) == EBUSY, ("%d\n", rc));
997 pCore->TracerData.DTrace.fZombie = true;
998 rc = VERR_TRY_AGAIN;
999 }
1000
1001 LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc));
1002 return rc;
1003}
1004
1005
1006/**
1007 * interface_method_impl{SUPDRVTRACERREG,pfnProviderDeregisterZombie}
1008 */
1009static DECLCALLBACK(int) vboxDtTOps_ProviderDeregisterZombie(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore)
1010{
1011 uintptr_t idProvider = pCore->TracerData.DTrace.idProvider;
1012 LOG_DTRACE(("%s: %p / %p\n", __FUNCTION__, pThis, idProvider));
1013 AssertPtrReturn(idProvider, VERR_INTERNAL_ERROR_3);
1014 Assert(pCore->TracerData.DTrace.fZombie);
1015
1016 int rc = dtrace_unregister(idProvider);
1017 if (!rc)
1018 {
1019 pCore->TracerData.DTrace.idProvider = 0;
1020 rc = VINF_SUCCESS;
1021 }
1022 else
1023 {
1024 AssertMsg(FIX_UEK_RC(rc) == EBUSY, ("%d\n", rc));
1025 rc = VERR_TRY_AGAIN;
1026 }
1027
1028 LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc));
1029 return rc;
1030}
1031
1032
1033
1034/**
1035 * The tracer registration record of the VBox DTrace implementation
1036 */
1037static SUPDRVTRACERREG g_VBoxDTraceReg =
1038{
1039 SUPDRVTRACERREG_MAGIC,
1040 SUPDRVTRACERREG_VERSION,
1041 vboxDtTOps_ProbeFireKernel,
1042 vboxDtTOps_ProbeFireUser,
1043 vboxDtTOps_TracerOpen,
1044 vboxDtTOps_TracerIoCtl,
1045 vboxDtTOps_TracerClose,
1046 vboxDtTOps_ProviderRegister,
1047 vboxDtTOps_ProviderDeregister,
1048 vboxDtTOps_ProviderDeregisterZombie,
1049 SUPDRVTRACERREG_MAGIC
1050};
1051
1052
1053
1054/**
1055 * Module initialization code.
1056 */
1057const SUPDRVTRACERREG * VBOXCALL supdrvDTraceInit(void)
1058{
1059#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX)
1060 /*
1061 * Resolve the kernel symbols we need.
1062 */
1063# ifndef RT_OS_LINUX
1064 RTDBGKRNLINFO hKrnlInfo;
1065 int rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0);
1066 if (RT_FAILURE(rc))
1067 {
1068 SUPR0Printf("supdrvDTraceInit: RTR0DbgKrnlInfoOpen failed with rc=%d.\n", rc);
1069 return NULL;
1070 }
1071# endif
1072
1073 static const struct
1074 {
1075 const char *pszName;
1076 PFNRT *ppfn;
1077 } s_aDTraceFunctions[] =
1078 {
1079 { "dtrace_probe", (PFNRT*)&dtrace_probe },
1080 { "dtrace_probe_create", (PFNRT*)&dtrace_probe_create },
1081 { "dtrace_probe_lookup", (PFNRT*)&dtrace_probe_lookup },
1082 { "dtrace_register", (PFNRT*)&dtrace_register },
1083 { "dtrace_invalidate", (PFNRT*)&dtrace_invalidate },
1084 { "dtrace_unregister", (PFNRT*)&dtrace_unregister },
1085 };
1086 unsigned i;
1087 for (i = 0; i < RT_ELEMENTS(s_aDTraceFunctions); i++)
1088 {
1089# ifndef RT_OS_LINUX
1090 rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_aDTraceFunctions[i].pszName,
1091 (void **)s_aDTraceFunctions[i].ppfn);
1092 if (RT_FAILURE(rc))
1093 {
1094 SUPR0Printf("supdrvDTraceInit: Failed to resolved '%s' (rc=%Rrc, i=%u).\n", s_aDTraceFunctions[i].pszName, rc, i);
1095 break;
1096 }
1097# else
1098 unsigned long ulAddr = kallsyms_lookup_name(s_aDTraceFunctions[i].pszName);
1099 if (!ulAddr)
1100 {
1101 SUPR0Printf("supdrvDTraceInit: Failed to resolved '%s' (i=%u).\n", s_aDTraceFunctions[i].pszName, i);
1102 return NULL;
1103 }
1104 *s_aDTraceFunctions[i].ppfn = (PFNRT)ulAddr;
1105# endif
1106 }
1107
1108# ifndef RT_OS_LINUX
1109 RTR0DbgKrnlInfoRelease(hKrnlInfo);
1110 if (RT_FAILURE(rc))
1111 return NULL;
1112# else
1113 /** @todo grab a reference to the dtrace module... */
1114# endif
1115#endif
1116
1117 return &g_VBoxDTraceReg;
1118}
1119
1120#ifndef VBOX_WITH_NATIVE_DTRACE
1121# error "VBOX_WITH_NATIVE_DTRACE is not defined as it should"
1122#endif
1123
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette