1 | /* $Id: DrvIfsTrace.cpp 104894 2024-06-12 13:53:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox interface callback tracing driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #define LOG_GROUP LOG_GROUP_MISC
|
---|
33 | #include <VBox/log.h>
|
---|
34 | #include <VBox/version.h>
|
---|
35 |
|
---|
36 | #include <iprt/errcore.h>
|
---|
37 | #include <iprt/buildconfig.h>
|
---|
38 | #include <iprt/tracelog.h>
|
---|
39 | #include <iprt/uuid.h>
|
---|
40 |
|
---|
41 | #include "VBoxDD.h"
|
---|
42 | #include "DrvIfsTraceInternal.h"
|
---|
43 |
|
---|
44 |
|
---|
45 | /*
|
---|
46 | *
|
---|
47 | * IBase Implementation.
|
---|
48 | *
|
---|
49 | */
|
---|
50 |
|
---|
51 |
|
---|
52 | static DECLCALLBACK(void *) drvIfTraceIBase_QueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
53 | {
|
---|
54 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
55 | PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
|
---|
56 |
|
---|
57 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
58 | if (pThis->pISerialConBelow)
|
---|
59 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMISERIALCONNECTOR, &pThis->ISerialConnector);
|
---|
60 | if (pThis->pISerialPortAbove)
|
---|
61 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMISERIALPORT, &pThis->ISerialPort);
|
---|
62 |
|
---|
63 | if (pThis->pITpmConBelow)
|
---|
64 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMITPMCONNECTOR, &pThis->ITpmConnector);
|
---|
65 | if (pThis->pITpmPortAbove)
|
---|
66 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMITPMPORT, &pThis->ITpmPort);
|
---|
67 |
|
---|
68 | return NULL;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | /*
|
---|
73 | *
|
---|
74 | * PDMDRVREG Methods
|
---|
75 | *
|
---|
76 | */
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Destroys a interface filter driver instance.
|
---|
80 | *
|
---|
81 | * @copydoc FNPDMDRVDESTRUCT
|
---|
82 | */
|
---|
83 | static DECLCALLBACK(void) drvIfTrace_Destruct(PPDMDRVINS pDrvIns)
|
---|
84 | {
|
---|
85 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
86 | PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
|
---|
87 | LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
|
---|
88 |
|
---|
89 | if (pThis->hTraceLog != NIL_RTTRACELOGWR)
|
---|
90 | {
|
---|
91 | RTTraceLogWrDestroy(pThis->hTraceLog);
|
---|
92 | pThis->hTraceLog = NIL_RTTRACELOGWR;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (pThis->pszTraceFilePath)
|
---|
96 | {
|
---|
97 | PDMDrvHlpMMHeapFree(pDrvIns, pThis->pszTraceFilePath);
|
---|
98 | pThis->pszTraceFilePath = NULL;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Construct a interface filter driver instance.
|
---|
105 | *
|
---|
106 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
107 | */
|
---|
108 | static DECLCALLBACK(int) drvIfTrace_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
109 | {
|
---|
110 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
111 | PDRVIFTRACE pThis = PDMINS_2_DATA(pDrvIns, PDRVIFTRACE);
|
---|
112 | PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
|
---|
113 |
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Initialize the instance data.
|
---|
117 | */
|
---|
118 | pThis->pDrvIns = pDrvIns;
|
---|
119 | pThis->hTraceLog = NIL_RTTRACELOGWR;
|
---|
120 | pDrvIns->IBase.pfnQueryInterface = drvIfTraceIBase_QueryInterface;
|
---|
121 |
|
---|
122 | drvIfsTrace_SerialIfInit(pThis);
|
---|
123 | drvIfsTrace_TpmIfInit(pThis);
|
---|
124 |
|
---|
125 | /*
|
---|
126 | * Validate and read config.
|
---|
127 | */
|
---|
128 | PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "TraceFilePath|", "");
|
---|
129 |
|
---|
130 | int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "TraceFilePath", &pThis->pszTraceFilePath);
|
---|
131 | AssertLogRelRCReturn(rc, rc);
|
---|
132 |
|
---|
133 | /* Try to create a file based trace log. */
|
---|
134 | rc = RTTraceLogWrCreateFile(&pThis->hTraceLog, RTBldCfgVersion(), pThis->pszTraceFilePath);
|
---|
135 | AssertLogRelRCReturn(rc, rc);
|
---|
136 |
|
---|
137 | /*
|
---|
138 | * Query interfaces from the driver/device above us.
|
---|
139 | */
|
---|
140 | pThis->pISerialPortAbove = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISERIALPORT);
|
---|
141 | pThis->pITpmPortAbove = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMITPMPORT);
|
---|
142 |
|
---|
143 | /*
|
---|
144 | * Attach driver below us.
|
---|
145 | */
|
---|
146 | PPDMIBASE pIBaseBelow;
|
---|
147 | rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pIBaseBelow);
|
---|
148 | AssertLogRelRCReturn(rc, rc);
|
---|
149 |
|
---|
150 | pThis->pISerialConBelow = PDMIBASE_QUERY_INTERFACE(pIBaseBelow, PDMISERIALCONNECTOR);
|
---|
151 | pThis->pITpmConBelow = PDMIBASE_QUERY_INTERFACE(pIBaseBelow, PDMITPMCONNECTOR);
|
---|
152 |
|
---|
153 | return VINF_SUCCESS;
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Storage filter driver registration record.
|
---|
159 | */
|
---|
160 | const PDMDRVREG g_DrvIfTrace =
|
---|
161 | {
|
---|
162 | /* u32Version */
|
---|
163 | PDM_DRVREG_VERSION,
|
---|
164 | /* szName */
|
---|
165 | "IfTrace",
|
---|
166 | /* szRCMod */
|
---|
167 | "",
|
---|
168 | /* szR0Mod */
|
---|
169 | "",
|
---|
170 | /* pszDescription */
|
---|
171 | "Interface callback tracing driver",
|
---|
172 | /* fFlags */
|
---|
173 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
174 | /* fClass. */
|
---|
175 | PDM_DRVREG_CLASS_STATUS,
|
---|
176 | /* cMaxInstances */
|
---|
177 | ~0U,
|
---|
178 | /* cbInstance */
|
---|
179 | sizeof(DRVIFTRACE),
|
---|
180 | /* pfnConstruct */
|
---|
181 | drvIfTrace_Construct,
|
---|
182 | /* pfnDestruct */
|
---|
183 | drvIfTrace_Destruct,
|
---|
184 | /* pfnRelocate */
|
---|
185 | NULL,
|
---|
186 | /* pfnIOCtl */
|
---|
187 | NULL,
|
---|
188 | /* pfnPowerOn */
|
---|
189 | NULL,
|
---|
190 | /* pfnReset */
|
---|
191 | NULL,
|
---|
192 | /* pfnSuspend */
|
---|
193 | NULL,
|
---|
194 | /* pfnResume */
|
---|
195 | NULL,
|
---|
196 | /* pfnAttach */
|
---|
197 | NULL,
|
---|
198 | /* pfnDetach */
|
---|
199 | NULL,
|
---|
200 | /* pfnPowerOff */
|
---|
201 | NULL,
|
---|
202 | /* pfnSoftReset */
|
---|
203 | NULL,
|
---|
204 | /* u32EndVersion */
|
---|
205 | PDM_DRVREG_VERSION
|
---|
206 | };
|
---|
207 |
|
---|