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