VirtualBox

source: vbox/trunk/include/VBox/VBoxTpG.h@ 103224

Last change on this file since 103224 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.9 KB
Line 
1/* $Id: VBoxTpG.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Tracepoint Generator Structures.
4 */
5
6/*
7 * Copyright (C) 2012-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 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef VBOX_INCLUDED_VBoxTpG_h
38#define VBOX_INCLUDED_VBoxTpG_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/types.h>
44#include <iprt/assert.h>
45
46RT_C_DECLS_BEGIN
47
48/**
49 * 32-bit probe location.
50 */
51typedef struct VTGPROBELOC32
52{
53 uint32_t uLine : 31;
54 uint32_t fEnabled : 1;
55 uint32_t idProbe;
56 uint32_t pszFunction;
57 uint32_t pProbe;
58} VTGPROBELOC32;
59AssertCompileSize(VTGPROBELOC32, 16);
60/** Pointer to a 32-bit probe location. */
61typedef VTGPROBELOC32 *PVTGPROBELOC32;
62/** Pointer to a const 32-bit probe location. */
63typedef VTGPROBELOC32 const *PCVTGPROBELOC32;
64
65/**
66 * 64-bit probe location.
67 */
68typedef struct VTGPROBELOC64
69{
70 uint32_t uLine : 31;
71 uint32_t fEnabled : 1;
72 uint32_t idProbe;
73 uint64_t pszFunction;
74 uint64_t pProbe;
75 uint64_t uAlignment;
76} VTGPROBELOC64;
77AssertCompileSize(VTGPROBELOC64, 32);
78/** Pointer to a 64-bit probe location. */
79typedef VTGPROBELOC64 *PVTGPROBELOC64;
80/** Pointer to a const 64-bit probe location. */
81typedef VTGPROBELOC64 const *PCVTGPROBELOC64;
82
83
84/**
85 * Probe location.
86 */
87typedef struct VTGPROBELOC
88{
89 uint32_t uLine : 31;
90 uint32_t fEnabled : 1;
91 uint32_t idProbe;
92 const char *pszFunction;
93 struct VTGDESCPROBE *pProbe;
94#if ARCH_BITS == 64
95 uintptr_t uAlignment;
96#endif
97} VTGPROBELOC;
98AssertCompileSizeAlignment(VTGPROBELOC, 16);
99/** Pointer to a probe location. */
100typedef VTGPROBELOC *PVTGPROBELOC;
101/** Pointer to a const probe location. */
102typedef VTGPROBELOC const *PCVTGPROBELOC;
103
104/** @def VTG_OBJ_SECT
105 * The name of the section containing the other probe data provided by the
106 * assembly / object generated by VBoxTpG. */
107/** @def VTG_LOC_SECT
108 * The name of the section containing the VTGPROBELOC structures. This is
109 * filled by the probe macros, @see VTG_DECL_VTGPROBELOC. */
110/** @def VTG_DECL_VTGPROBELOC
111 * Declares a static variable, @a a_VarName, of type VTGPROBELOC in the section
112 * indicated by VTG_LOC_SECT. */
113#if defined(RT_OS_WINDOWS)
114# define VTG_OBJ_SECT "VTGObj"
115# define VTG_LOC_SECT "VTGPrLc.Data"
116# ifdef _MSC_VER
117# define VTG_DECL_VTGPROBELOC(a_VarName) \
118 __declspec(allocate(VTG_LOC_SECT)) static VTGPROBELOC a_VarName
119# elif defined(__GNUC__) || defined(DOXYGEN_RUNNING)
120# define VTG_DECL_VTGPROBELOC(a_VarName) \
121 static VTGPROBELOC __attribute__((section(VTG_LOC_SECT))) a_VarName
122# else
123# error "Unsupported Windows compiler!"
124# endif
125
126#elif defined(RT_OS_DARWIN)
127# define VTG_OBJ_SECT "__VTGObj"
128# define VTG_LOC_SECT "__VTGPrLc"
129# define VTG_LOC_SEG "__VTG"
130# if defined(__GNUC__) || defined(DOXYGEN_RUNNING)
131# define VTG_DECL_VTGPROBELOC(a_VarName) \
132 static VTGPROBELOC __attribute__((section(VTG_LOC_SEG "," VTG_LOC_SECT ",regular")/*, aligned(16)*/)) a_VarName
133# else
134# error "Unsupported Darwin compiler!"
135# endif
136
137#elif defined(RT_OS_OS2) /** @todo This doesn't actually work, but it makes the code compile. */
138# define VTG_OBJ_SECT "__DATA"
139# define VTG_LOC_SECT "__VTGPrLc"
140# define VTG_LOC_SET "__VTGPrLcSet"
141# if defined(__GNUC__) || defined(DOXYGEN_RUNNING)
142# define VTG_DECL_VTGPROBELOC(a_VarName) \
143 static VTGPROBELOC a_VarName; \
144 __asm__ (".stabs \"__VTGPrLcSet\", 23, 0, 0, _" #a_VarName );
145
146# else
147# error "Unsupported Darwin compiler!"
148# endif
149
150#else /* Assume the rest uses ELF. */
151# define VTG_OBJ_SECT ".VTGObj"
152# define VTG_LOC_SECT ".VTGPrLc"
153# if defined(__GNUC__) || defined(DOXYGEN_RUNNING)
154# define VTG_DECL_VTGPROBELOC(a_VarName) \
155 static VTGPROBELOC __attribute__((section(VTG_LOC_SECT))) a_VarName
156# else
157# error "Unsupported compiler!"
158# endif
159#endif
160
161/** VTG string table offset. */
162typedef uint32_t VTGSTROFF;
163
164
165/** @name VTG type flags
166 * @{ */
167/** Masking out the fixed size if given. */
168#define VTG_TYPE_SIZE_MASK UINT32_C(0x000000ff)
169/** Indicates that VTG_TYPE_SIZE_MASK can be applied, UNSIGNED or SIGNED is
170 * usually set as well, so may PHYS. */
171#define VTG_TYPE_FIXED_SIZED RT_BIT_32(8)
172/** It's a pointer type, the size is given by the context the probe fired in. */
173#define VTG_TYPE_POINTER RT_BIT_32(9)
174/** A context specfic pointer or address, consult VTG_TYPE_CTX_XXX. */
175#define VTG_TYPE_CTX_POINTER RT_BIT_32(10)
176/** The type has the same size as the host architecture. */
177#define VTG_TYPE_HC_ARCH_SIZED RT_BIT_32(11)
178/** Const char pointer, requires casting in wrapper headers. */
179#define VTG_TYPE_CONST_CHAR_PTR RT_BIT_32(12)
180/** The type applies to ring-3 context. */
181#define VTG_TYPE_CTX_R3 RT_BIT_32(24)
182/** The type applies to ring-0 context. */
183#define VTG_TYPE_CTX_R0 RT_BIT_32(25)
184/** The type applies to raw-mode context. */
185#define VTG_TYPE_CTX_RC RT_BIT_32(26)
186/** The type applies to guest context. */
187#define VTG_TYPE_CTX_GST RT_BIT_32(27)
188/** The type context mask. */
189#define VTG_TYPE_CTX_MASK UINT32_C(0x0f000000)
190/** The type is automatically converted to a ring-0 pointer. */
191#define VTG_TYPE_AUTO_CONV_PTR RT_BIT_32(28)
192/** The type is a physical address. */
193#define VTG_TYPE_PHYS RT_BIT_32(29)
194/** The type is unsigned. */
195#define VTG_TYPE_UNSIGNED RT_BIT_32(30)
196/** The type is signed. */
197#define VTG_TYPE_SIGNED RT_BIT_32(31)
198/** Mask of valid bits (for simple validation). */
199#define VTG_TYPE_VALID_MASK UINT32_C(0xff001fff)
200/** @} */
201
202/**
203 * Checks if the VTG type flags indicates a large fixed size argument.
204 */
205#define VTG_TYPE_IS_LARGE(a_fType) \
206 ( ((a_fType) & VTG_TYPE_SIZE_MASK) > 4 && ((a_fType) & VTG_TYPE_FIXED_SIZED) )
207
208
209/**
210 * VTG argument descriptor.
211 */
212typedef struct VTGDESCARG
213{
214 VTGSTROFF offType;
215 uint32_t fType;
216} VTGDESCARG;
217/** Pointer to an argument descriptor. */
218typedef VTGDESCARG *PVTGDESCARG;
219/** Pointer to a const argument descriptor. */
220typedef VTGDESCARG const *PCVTGDESCARG;
221
222
223/**
224 * VTG argument list descriptor.
225 */
226typedef struct VTGDESCARGLIST
227{
228 uint8_t cArgs;
229 uint8_t fHaveLargeArgs;
230 uint8_t abReserved[2];
231 VTGDESCARG aArgs[1];
232} VTGDESCARGLIST;
233/** Pointer to a VTG argument list descriptor. */
234typedef VTGDESCARGLIST *PVTGDESCARGLIST;
235/** Pointer to a const VTG argument list descriptor. */
236typedef VTGDESCARGLIST const *PCVTGDESCARGLIST;
237
238
239/**
240 * VTG probe descriptor.
241 */
242typedef struct VTGDESCPROBE
243{
244 VTGSTROFF offName;
245 uint32_t offArgList;
246 uint16_t idxEnabled;
247 uint16_t idxProvider;
248 /** The distance from this structure to the VTG object header. */
249 int32_t offObjHdr;
250} VTGDESCPROBE;
251AssertCompileSize(VTGDESCPROBE, 16);
252/** Pointer to a VTG probe descriptor. */
253typedef VTGDESCPROBE *PVTGDESCPROBE;
254/** Pointer to a const VTG probe descriptor. */
255typedef VTGDESCPROBE const *PCVTGDESCPROBE;
256
257
258/**
259 * Code/data stability.
260 */
261typedef enum kVTGStability
262{
263 kVTGStability_Invalid = 0,
264 kVTGStability_Internal,
265 kVTGStability_Private,
266 kVTGStability_Obsolete,
267 kVTGStability_External,
268 kVTGStability_Unstable,
269 kVTGStability_Evolving,
270 kVTGStability_Stable,
271 kVTGStability_Standard,
272 kVTGStability_End
273} kVTGStability;
274
275/**
276 * Data dependency.
277 */
278typedef enum kVTGClass
279{
280 kVTGClass_Invalid = 0,
281 kVTGClass_Unknown,
282 kVTGClass_Cpu,
283 kVTGClass_Platform,
284 kVTGClass_Group,
285 kVTGClass_Isa,
286 kVTGClass_Common,
287 kVTGClass_End
288} kVTGClass;
289
290
291/**
292 * VTG attributes.
293 */
294typedef struct VTGDESCATTR
295{
296 uint8_t u8Code;
297 uint8_t u8Data;
298 uint8_t u8DataDep;
299} VTGDESCATTR;
300AssertCompileSize(VTGDESCATTR, 3);
301/** Pointer to a const VTG attribute. */
302typedef VTGDESCATTR const *PCVTGDESCATTR;
303
304
305/**
306 * VTG provider descriptor.
307 */
308typedef struct VTGDESCPROVIDER
309{
310 VTGSTROFF offName;
311 uint16_t iFirstProbe;
312 uint16_t cProbes;
313 VTGDESCATTR AttrSelf;
314 VTGDESCATTR AttrModules;
315 VTGDESCATTR AttrFunctions;
316 VTGDESCATTR AttrNames;
317 VTGDESCATTR AttrArguments;
318 uint8_t bReserved;
319 uint32_t volatile cProbesEnabled;
320 /** This increases every time a probe is enabled or disabled.
321 * Can be used in non-ring-3 context via PROVIDER_GET_SETTINGS_SEQ_NO() in
322 * order to only configure probes related stuff when actually required. */
323 uint32_t volatile uSettingsSerialNo;
324} VTGDESCPROVIDER;
325AssertCompileSize(VTGDESCPROVIDER, 32);
326/** Pointer to a VTG provider descriptor. */
327typedef VTGDESCPROVIDER *PVTGDESCPROVIDER;
328/** Pointer to a const VTG provider descriptor. */
329typedef VTGDESCPROVIDER const *PCVTGDESCPROVIDER;
330
331
332/**
333 * VTG data object header.
334 */
335typedef struct VTGOBJHDR
336{
337 /** Magic value (VTGOBJHDR_MAGIC). */
338 char szMagic[24];
339 /** The bitness of the structures.
340 * This only affects the probe location pointers and structures. */
341 uint32_t cBits;
342 /** The size of the VTG object. This excludes the probe locations. */
343 uint32_t cbObj;
344
345 /** @name Area Descriptors
346 * @remarks The offsets are relative to the header. The members are
347 * ordered by ascending offset (maybe with the exception of the
348 * probe locations). No overlaps, though there might be zero
349 * filled gaps between them due to alignment.
350 * @{ */
351 /* 32: */
352 /** Offset of the string table (char) relative to this header. */
353 uint32_t offStrTab;
354 /** The size of the string table, in bytes. */
355 uint32_t cbStrTab;
356 /** Offset of the argument lists (VTGDESCARGLIST - variable size) relative
357 * to this header. */
358 uint32_t offArgLists;
359 /** The size of the argument lists, in bytes. */
360 uint32_t cbArgLists;
361 /* 48: */
362 /** Offset of the probe array (VTGDESCPROBE) relative to this header. */
363 uint32_t offProbes;
364 /** The size of the probe array, in bytes. */
365 uint32_t cbProbes;
366 /** Offset of the provider array (VTGDESCPROVIDER) relative to this
367 * header. */
368 uint32_t offProviders;
369 /** The size of the provider array, in bytes. */
370 uint32_t cbProviders;
371 /* 64: */
372 /** Offset of the probe-enabled array (uint32_t) relative to this
373 * header. */
374 uint32_t offProbeEnabled;
375 /** The size of the probe-enabled array, in bytes. */
376 uint32_t cbProbeEnabled;
377 /** Offset of the probe location array (VTGPROBELOC) relative to this
378 * header.
379 * @remarks This is filled in by the first VTG user using uProbeLocs. */
380 int32_t offProbeLocs;
381 /** The size of the probe location array, in bytes.
382 * @remarks This is filled in by the first VTG user using uProbeLocs. */
383 uint32_t cbProbeLocs;
384 /** @} */
385 /* 80: */
386 /**
387 * The probe location array is generated by C code and lives in a
388 * different section/subsection/segment than the rest of the data.
389 *
390 * The assembler cannot generate offsets across sections for most (if not
391 * all) object formats, so we have to store pointers here. The first user
392 * of the data will convert these two members into offset and size and fill
393 * in the offProbeLocs and cbProbeLocs members above.
394 *
395 * @remarks Converting these members to offset+size and reusing the members
396 * to store the converted values isn't possible because of
397 * raw-mode context modules having relocations associated with the
398 * fields.
399 */
400 union
401 {
402 PVTGPROBELOC p;
403 uintptr_t uPtr;
404 uint32_t u32;
405 uint64_t u64;
406 }
407 /** Pointer to the probe location array. */
408 uProbeLocs,
409 /** Pointer to the end of the probe location array. */
410 uProbeLocsEnd;
411 /** UUID for making sharing ring-0 structures for the same ring-3
412 * modules easier. */
413 RTUUID Uuid;
414 /** Mac 10.6.x load workaround.
415 * The linker or/and load messes up the uProbeLocs and uProbeLocsEnd fields
416 * so that they will be link addresses instead of load addresses. To be
417 * able to work around it we store the start address of the __VTGObj section
418 * here and uses it to validate the probe location addresses. */
419 uint64_t u64VtgObjSectionStart;
420 /** Reserved / alignment. */
421 uint32_t au32Reserved1[2];
422} VTGOBJHDR;
423AssertCompileSize(VTGOBJHDR, 128);
424AssertCompileMemberAlignment(VTGOBJHDR, uProbeLocs, 8);
425AssertCompileMemberAlignment(VTGOBJHDR, uProbeLocsEnd, 8);
426/** Pointer to a VTG data object header. */
427typedef VTGOBJHDR *PVTGOBJHDR;
428/** Pointer to a const VTG data object header. */
429typedef VTGOBJHDR const *PCVTGOBJHDR;
430
431/** The current VTGOBJHDR::szMagic value. */
432#define VTGOBJHDR_MAGIC "VTG Object Header v1.7\0"
433
434/** The name of the VTG data object header symbol in the object file. */
435extern VTGOBJHDR g_VTGObjHeader;
436
437
438/** @name Macros for converting typical pointer arguments to ring-0 pointers.
439 * @{ */
440#ifdef IN_RING0
441# define VTG_VM_TO_R0(a_pVM) (a_pVM)
442# define VTG_VMCPU_TO_R0(a_pVCpu) (a_pVCpu)
443# define VTG_CPUMCTX_TO_R0(a_pVCpu, a_pCtx) (a_pCtx)
444#else
445# define VTG_VM_TO_R0(a_pVM) ((a_pVM) ? (a_pVM)->pVMR0ForCall : NIL_RTR0PTR)
446# define VTG_VMCPU_TO_R0(a_pVCpu) ((a_pVCpu) ? (a_pVCpu)->pVCpuR0ForVtg : NIL_RTR0PTR)
447# define VTG_CPUMCTX_TO_R0(a_pVCpu, a_pCtx) ((a_pVCpu) ? (a_pVCpu)->pVCpuR0ForVtg + ((uintptr_t)(a_pCtx) - (uintptr_t)(a_pVCpu)) : NIL_RTR0PTR)
448#endif
449/** @} */
450
451
452RT_C_DECLS_END
453
454#endif /* !VBOX_INCLUDED_VBoxTpG_h */
455
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