VirtualBox

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

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