VirtualBox

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

Last change on this file since 105381 was 103684, checked in by vboxsync, 10 months ago

Linux kernel modules: Fix UBSAN warnings by switching to flexible arrays where possible, bugref:10585.

  • 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 103684 2024-03-05 15:27:02Z 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 RT_FLEXIBLE_ARRAY_EXTENSION
232 VTGDESCARG aArgs[RT_FLEXIBLE_ARRAY];
233} VTGDESCARGLIST;
234/** Pointer to a VTG argument list descriptor. */
235typedef VTGDESCARGLIST *PVTGDESCARGLIST;
236/** Pointer to a const VTG argument list descriptor. */
237typedef VTGDESCARGLIST const *PCVTGDESCARGLIST;
238
239
240/**
241 * VTG probe descriptor.
242 */
243typedef struct VTGDESCPROBE
244{
245 VTGSTROFF offName;
246 uint32_t offArgList;
247 uint16_t idxEnabled;
248 uint16_t idxProvider;
249 /** The distance from this structure to the VTG object header. */
250 int32_t offObjHdr;
251} VTGDESCPROBE;
252AssertCompileSize(VTGDESCPROBE, 16);
253/** Pointer to a VTG probe descriptor. */
254typedef VTGDESCPROBE *PVTGDESCPROBE;
255/** Pointer to a const VTG probe descriptor. */
256typedef VTGDESCPROBE const *PCVTGDESCPROBE;
257
258
259/**
260 * Code/data stability.
261 */
262typedef enum kVTGStability
263{
264 kVTGStability_Invalid = 0,
265 kVTGStability_Internal,
266 kVTGStability_Private,
267 kVTGStability_Obsolete,
268 kVTGStability_External,
269 kVTGStability_Unstable,
270 kVTGStability_Evolving,
271 kVTGStability_Stable,
272 kVTGStability_Standard,
273 kVTGStability_End
274} kVTGStability;
275
276/**
277 * Data dependency.
278 */
279typedef enum kVTGClass
280{
281 kVTGClass_Invalid = 0,
282 kVTGClass_Unknown,
283 kVTGClass_Cpu,
284 kVTGClass_Platform,
285 kVTGClass_Group,
286 kVTGClass_Isa,
287 kVTGClass_Common,
288 kVTGClass_End
289} kVTGClass;
290
291
292/**
293 * VTG attributes.
294 */
295typedef struct VTGDESCATTR
296{
297 uint8_t u8Code;
298 uint8_t u8Data;
299 uint8_t u8DataDep;
300} VTGDESCATTR;
301AssertCompileSize(VTGDESCATTR, 3);
302/** Pointer to a const VTG attribute. */
303typedef VTGDESCATTR const *PCVTGDESCATTR;
304
305
306/**
307 * VTG provider descriptor.
308 */
309typedef struct VTGDESCPROVIDER
310{
311 VTGSTROFF offName;
312 uint16_t iFirstProbe;
313 uint16_t cProbes;
314 VTGDESCATTR AttrSelf;
315 VTGDESCATTR AttrModules;
316 VTGDESCATTR AttrFunctions;
317 VTGDESCATTR AttrNames;
318 VTGDESCATTR AttrArguments;
319 uint8_t bReserved;
320 uint32_t volatile cProbesEnabled;
321 /** This increases every time a probe is enabled or disabled.
322 * Can be used in non-ring-3 context via PROVIDER_GET_SETTINGS_SEQ_NO() in
323 * order to only configure probes related stuff when actually required. */
324 uint32_t volatile uSettingsSerialNo;
325} VTGDESCPROVIDER;
326AssertCompileSize(VTGDESCPROVIDER, 32);
327/** Pointer to a VTG provider descriptor. */
328typedef VTGDESCPROVIDER *PVTGDESCPROVIDER;
329/** Pointer to a const VTG provider descriptor. */
330typedef VTGDESCPROVIDER const *PCVTGDESCPROVIDER;
331
332
333/**
334 * VTG data object header.
335 */
336typedef struct VTGOBJHDR
337{
338 /** Magic value (VTGOBJHDR_MAGIC). */
339 char szMagic[24];
340 /** The bitness of the structures.
341 * This only affects the probe location pointers and structures. */
342 uint32_t cBits;
343 /** The size of the VTG object. This excludes the probe locations. */
344 uint32_t cbObj;
345
346 /** @name Area Descriptors
347 * @remarks The offsets are relative to the header. The members are
348 * ordered by ascending offset (maybe with the exception of the
349 * probe locations). No overlaps, though there might be zero
350 * filled gaps between them due to alignment.
351 * @{ */
352 /* 32: */
353 /** Offset of the string table (char) relative to this header. */
354 uint32_t offStrTab;
355 /** The size of the string table, in bytes. */
356 uint32_t cbStrTab;
357 /** Offset of the argument lists (VTGDESCARGLIST - variable size) relative
358 * to this header. */
359 uint32_t offArgLists;
360 /** The size of the argument lists, in bytes. */
361 uint32_t cbArgLists;
362 /* 48: */
363 /** Offset of the probe array (VTGDESCPROBE) relative to this header. */
364 uint32_t offProbes;
365 /** The size of the probe array, in bytes. */
366 uint32_t cbProbes;
367 /** Offset of the provider array (VTGDESCPROVIDER) relative to this
368 * header. */
369 uint32_t offProviders;
370 /** The size of the provider array, in bytes. */
371 uint32_t cbProviders;
372 /* 64: */
373 /** Offset of the probe-enabled array (uint32_t) relative to this
374 * header. */
375 uint32_t offProbeEnabled;
376 /** The size of the probe-enabled array, in bytes. */
377 uint32_t cbProbeEnabled;
378 /** Offset of the probe location array (VTGPROBELOC) relative to this
379 * header.
380 * @remarks This is filled in by the first VTG user using uProbeLocs. */
381 int32_t offProbeLocs;
382 /** The size of the probe location array, in bytes.
383 * @remarks This is filled in by the first VTG user using uProbeLocs. */
384 uint32_t cbProbeLocs;
385 /** @} */
386 /* 80: */
387 /**
388 * The probe location array is generated by C code and lives in a
389 * different section/subsection/segment than the rest of the data.
390 *
391 * The assembler cannot generate offsets across sections for most (if not
392 * all) object formats, so we have to store pointers here. The first user
393 * of the data will convert these two members into offset and size and fill
394 * in the offProbeLocs and cbProbeLocs members above.
395 *
396 * @remarks Converting these members to offset+size and reusing the members
397 * to store the converted values isn't possible because of
398 * raw-mode context modules having relocations associated with the
399 * fields.
400 */
401 union
402 {
403 PVTGPROBELOC p;
404 uintptr_t uPtr;
405 uint32_t u32;
406 uint64_t u64;
407 }
408 /** Pointer to the probe location array. */
409 uProbeLocs,
410 /** Pointer to the end of the probe location array. */
411 uProbeLocsEnd;
412 /** UUID for making sharing ring-0 structures for the same ring-3
413 * modules easier. */
414 RTUUID Uuid;
415 /** Mac 10.6.x load workaround.
416 * The linker or/and load messes up the uProbeLocs and uProbeLocsEnd fields
417 * so that they will be link addresses instead of load addresses. To be
418 * able to work around it we store the start address of the __VTGObj section
419 * here and uses it to validate the probe location addresses. */
420 uint64_t u64VtgObjSectionStart;
421 /** Reserved / alignment. */
422 uint32_t au32Reserved1[2];
423} VTGOBJHDR;
424AssertCompileSize(VTGOBJHDR, 128);
425AssertCompileMemberAlignment(VTGOBJHDR, uProbeLocs, 8);
426AssertCompileMemberAlignment(VTGOBJHDR, uProbeLocsEnd, 8);
427/** Pointer to a VTG data object header. */
428typedef VTGOBJHDR *PVTGOBJHDR;
429/** Pointer to a const VTG data object header. */
430typedef VTGOBJHDR const *PCVTGOBJHDR;
431
432/** The current VTGOBJHDR::szMagic value. */
433#define VTGOBJHDR_MAGIC "VTG Object Header v1.7\0"
434
435/** The name of the VTG data object header symbol in the object file. */
436extern VTGOBJHDR g_VTGObjHeader;
437
438
439/** @name Macros for converting typical pointer arguments to ring-0 pointers.
440 * @{ */
441#ifdef IN_RING0
442# define VTG_VM_TO_R0(a_pVM) (a_pVM)
443# define VTG_VMCPU_TO_R0(a_pVCpu) (a_pVCpu)
444# define VTG_CPUMCTX_TO_R0(a_pVCpu, a_pCtx) (a_pCtx)
445#else
446# define VTG_VM_TO_R0(a_pVM) ((a_pVM) ? (a_pVM)->pVMR0ForCall : NIL_RTR0PTR)
447# define VTG_VMCPU_TO_R0(a_pVCpu) ((a_pVCpu) ? (a_pVCpu)->pVCpuR0ForVtg : NIL_RTR0PTR)
448# define VTG_CPUMCTX_TO_R0(a_pVCpu, a_pCtx) ((a_pVCpu) ? (a_pVCpu)->pVCpuR0ForVtg + ((uintptr_t)(a_pCtx) - (uintptr_t)(a_pVCpu)) : NIL_RTR0PTR)
449#endif
450/** @} */
451
452
453RT_C_DECLS_END
454
455#endif /* !VBOX_INCLUDED_VBoxTpG_h */
456
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