VirtualBox

source: vbox/trunk/src/VBox/ExtPacks/VBoxDTrace/include/VBoxDTraceTypes.h

Last change on this file was 98103, checked in by vboxsync, 17 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: 15.4 KB
Line 
1
2/* $Id: VBoxDTraceTypes.h 98103 2023-01-17 14:15:46Z vboxsync $ */
3/** @file
4 * VBoxDTraceTypes.h - Fake a bunch of Solaris types.
5 *
6 * Contributed by: bird
7 */
8
9/*
10 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
11 *
12 * This file is part of VirtualBox base platform packages, as
13 * available from http://www.virtualbox.org.
14 *
15 * The contents of this file are subject to the terms of the Common
16 * Development and Distribution License Version 1.0 (CDDL) only, as it
17 * comes in the "COPYING.CDDL" file of the VirtualBox distribution.
18 *
19 * SPDX-License-Identifier: CDDL-1.0
20 */
21
22#ifndef VBOX_INCLUDED_SRC_VBoxDTrace_include_VBoxDTraceTypes_h
23#define VBOX_INCLUDED_SRC_VBoxDTrace_include_VBoxDTraceTypes_h
24#ifndef RT_WITHOUT_PRAGMA_ONCE
25# pragma once
26#endif
27
28#include <iprt/types.h>
29#include <iprt/stdarg.h>
30#include <iprt/assert.h>
31#include <iprt/param.h>
32#include <iprt/errno.h>
33#ifdef IN_RING0
34# include <iprt/list.h>
35#endif
36#ifdef IN_RING3
37# include <sys/types.h>
38# include <limits.h>
39# ifdef RT_OS_LINUX
40# include <sys/ucontext.h> /* avoid greg_t trouble */
41# endif
42# if defined(_MSC_VER)
43# include <stdio.h>
44# endif
45#endif
46
47RT_C_DECLS_BEGIN
48
49struct modctl;
50
51typedef unsigned char uchar_t;
52typedef unsigned short ushort_t;
53typedef unsigned int uint_t;
54typedef uintptr_t ulong_t;
55#ifndef RT_OS_SOLARIS
56typedef int64_t longlong_t;
57typedef uint64_t u_longlong_t;
58typedef uint64_t hrtime_t;
59# ifndef RT_OS_FREEBSD
60typedef uint32_t id_t;
61# endif
62typedef uint32_t zoneid_t;
63#endif
64#if (!defined(__NGREG) && !defined(NGREG)) || !defined(RT_OS_LINUX)
65typedef RTCCINTREG greg_t;
66#else
67AssertCompileSize(greg_t, sizeof(RTCCINTREG));
68#endif
69typedef uintptr_t pc_t;
70typedef unsigned int model_t;
71typedef RTCPUID processorid_t;
72#if defined(_MSC_VER) || defined(IN_RING0)
73typedef RTUID uid_t;
74typedef RTPROCESS pid_t;
75#endif
76#if defined(_MSC_VER) || defined(IN_RING0) || defined(RT_OS_LINUX)
77typedef char *caddr_t;
78#endif
79
80#if !defined(NANOSEC) || !defined(RT_OS_SOLARIS)
81# define NANOSEC RT_NS_1SEC
82#endif
83#if !defined(MICROSEC) || !defined(RT_OS_SOLARIS)
84# define MICROSEC RT_US_1SEC
85#endif
86#if !defined(MILLISEC) || !defined(RT_OS_SOLARIS)
87# define MILLISEC RT_MS_1SEC
88#endif
89#if !defined(SEC) || !defined(RT_OS_SOLARIS)
90# define SEC (1)
91#endif
92#define MAXPATHLEN RTPATH_MAX
93#undef PATH_MAX
94#define PATH_MAX RTPATH_MAX
95#undef NBBY
96#define NBBY (8)
97#define NCPU RTCPUSET_MAX_CPUS
98#define B_FALSE (0)
99#define B_TRUE (1)
100#define MIN(a1, a2) RT_MIN(a1, a2)
101#define MAX(a1, a2) RT_MAX(a1, a2)
102#define ABS(a_iValue) RT_ABS(a_iValue)
103#define IS_P2ALIGNED(uWhat, uAlign) ( !((uWhat) & ((uAlign) - 1)) )
104#define P2ROUNDUP(uWhat, uAlign) ( ((uWhat) + (uAlign) - 1) & ~(uAlign - 1) )
105#define roundup(uWhat, uUnit) ( ( (uWhat) + ((uUnit) - 1)) / (uUnit) * (uUnit) )
106
107#if defined(RT_ARCH_X86)
108# ifndef __i386
109# define __i386 1
110# endif
111# ifndef __x86
112# define __x86 1
113# endif
114# ifndef _IPL32
115# define _IPL32 1
116# endif
117# if !defined(_LITTLE_ENDIAN) || (!defined(RT_OS_SOLARIS) && !defined(RT_OS_FREEBSD))
118# define _LITTLE_ENDIAN 1
119# endif
120
121#elif defined(RT_ARCH_AMD64)
122# ifndef __x86_64
123# define __x86_64 1
124# endif
125# ifndef __x86
126# define __x86 1
127# endif
128# ifndef _LP64
129# define _LP64 1
130# endif
131# if !defined(_LITTLE_ENDIAN) || (!defined(RT_OS_SOLARIS) && !defined(RT_OS_FREEBSD))
132# define _LITTLE_ENDIAN 1
133# endif
134
135#else
136# error "unsupported arch!"
137#endif
138
139/** Mark a cast added when porting the code to VBox.
140 * Avoids lots of \#ifdef VBOX otherwise needed to mark up the changes. */
141#define VBDTCAST(a_Type) (a_Type)
142/** Mark a type change made when porting the code to VBox.
143 * This is usually signed -> unsigned type changes that avoids a whole lot of
144 * comparsion warnings. */
145#define VBDTTYPE(a_VBox, a_Org) a_VBox
146/** Mark missing void in a parameter list. */
147#define VBDTVOID void
148/** Mark missing static in a function definition. */
149#define VBDTSTATIC static
150#define VBDTUNASS(a_Value) = a_Value
151#define VBDTGCC(a_Value) = a_Value
152#define VBDTMSC(a_Value) = a_Value
153
154/*
155 * string
156 */
157#ifdef IN_RING0
158# undef bcopy
159# define bcopy(a_pSrc, a_pDst, a_cb) ((void)memmove(a_pDst, a_pSrc, a_cb))
160# undef bzero
161# define bzero(a_pDst, a_cb) ((void)memset(a_pDst, 0, a_cb))
162# undef bcmp
163# define bcmp(a_p1, a_p2, a_cb) (memcmp(a_p1, a_p2, a_cb))
164#endif
165#if defined(_MSC_VER) || defined(IN_RING0)
166# define snprintf (int)RTStrPrintf /** @todo wrong return value */
167# define vsnprintf (int)RTStrPrintfV /** @todo wrong return value */
168#endif
169
170/*
171 * Bitmap stuff.
172 */
173#define BT_SIZEOFMAP(a_cBits) ( (a_cBits + 63) / 8 )
174#define BT_SET(a_aulBitmap, iBit) ASMBitSet(a_aulBitmap, iBit)
175#define BT_CLEAR(a_aulBitmap, iBit) ASMBitClear(a_aulBitmap, iBit)
176#define BT_TEST(a_aulBitmap, iBit) ASMBitTest(a_aulBitmap, iBit)
177#if ARCH_BITS == 32
178# define BT_NBIPUL 32
179# define BT_ULSHIFT 5 /* log2(32) = 5 */
180# define BT_ULMASK 0x1f
181# define BT_BITOUL(a_cBits) ( ((a_cBits) + 31) / 32 )
182#elif ARCH_BITS == 64
183# define BT_NBIPUL 64
184# define BT_ULSHIFT 6 /* log2(32) = 6 */
185# define BT_ULMASK 0x3f
186# define BT_BITOUL(a_cBits) ( ((a_cBits) + 63) / 64 )
187#else
188# error Bad ARCH_BITS...
189#endif
190
191
192#ifdef IN_RING0
193
194/*
195 * Kernel stuff...
196 */
197#define CPU_ON_INTR(a_pCpu) (false)
198
199#define KERNELBASE VBoxDtGetKernelBase()
200uintptr_t VBoxDtGetKernelBase(void);
201
202
203typedef struct VBoxDtCred
204{
205 int32_t cr_refs;
206 RTUID cr_uid;
207 RTUID cr_ruid;
208 RTUID cr_suid;
209 RTGID cr_gid;
210 RTGID cr_rgid;
211 RTGID cr_sgid;
212 zoneid_t cr_zone;
213} cred_t;
214#define PRIV_POLICY_ONLY(a_pCred, a_uPriv, a_fAll) (true)
215#define priv_isequalset(a, b) (true)
216#define crgetuid(a_pCred) ((a_pCred)->cr_uid)
217#define crgetzoneid(a_pCred) ((a_pCred)->cr_zone)
218#define crhold VBoxDtCredHold
219#define crfree VBoxDtCredFree
220void VBoxDtCredHold(struct VBoxDtCred *pCred);
221void VBoxDtCredFree(struct VBoxDtCred *pCred);
222
223
224typedef struct RTTIMER *cyclic_id_t;
225#define CYCLIC_NONE ((struct RTTIMER *)NULL)
226#define cyclic_remove(a_hTimer) RTTimerDestroy(a_hTimer)
227
228typedef struct VBoxDtThread
229{
230 /** The next thread with the same hash table entry.
231 * Or the next free thread. */
232 struct VBoxDtThread *pNext;
233 /** Age list node. */
234 RTLISTNODE AgeEntry;
235 /** The native thread handle. */
236 RTNATIVETHREAD hNative;
237 /** The process ID. */
238 RTPROCESS uPid;
239
240 uint32_t t_predcache;
241 uintptr_t t_dtrace_scrpc;
242 uintptr_t t_dtrace_astpc;
243 hrtime_t t_dtrace_vtime;
244 hrtime_t t_dtrace_start;
245 uint8_t t_dtrace_stop;
246} kthread_t;
247struct VBoxDtThread *VBoxDtGetCurrentThread(void);
248#define curthread (VBoxDtGetCurrentThread())
249
250
251typedef struct VBoxDtProcess proc_t;
252# if 0 /* not needed ? */
253struct VBoxDtProcess proc_t;
254{
255/* uint32_t p_flag; - don't bother with this */
256 RTPROCESS p_pid;
257 struct dtrace_helpers *p_dtrace_helpers;
258}
259proc_t *VBoxDtGetCurrentProc(void);
260# define curproc (VBoxDtGetCurrentProc())
261/*# define SNOCD RT_BIT(0) - don't bother with this */
262# endif
263
264typedef struct VBoxDtTaskQueue taskq_t;
265
266typedef struct VBoxDtMutex
267{
268 RTSEMMUTEX hMtx;
269 RTNATIVETHREAD volatile hOwner;
270} kmutex_t;
271#define mutex_enter VBoxDtMutexEnter
272#define mutex_exit VBoxDtMutexExit
273#define MUTEX_HELD(a_pMtx) VBoxDtMutexIsOwner(a_pMtx)
274#define MUTEX_NOT_HELD(a_pMtx) (!VBoxDtMutexIsOwner(a_pMtx))
275#define mod_lock g_DummyMtx
276#define cpu_lock g_DummyMtx
277int VBoxDtMutexInit(struct VBoxDtMutex *pMtx);
278void VBoxDtMutexDelete(struct VBoxDtMutex *pMtx);
279void VBoxDtMutexEnter(struct VBoxDtMutex *pMtx);
280void VBoxDtMutexExit(struct VBoxDtMutex *pMtx);
281bool VBoxDtMutexIsOwner(struct VBoxDtMutex *pMtx);
282extern struct VBoxDtMutex g_DummyMtx;
283
284
285typedef struct VBoxDtCpuCore
286{
287 RTCPUID cpu_id;
288 uintptr_t cpuc_dtrace_illval;
289 uint16_t volatile cpuc_dtrace_flags;
290
291} cpucore_t;
292
293#define CPU_DTRACE_BADADDR RT_BIT(0)
294#define CPU_DTRACE_BADALIGN RT_BIT(1)
295#define CPU_DTRACE_BADSTACK RT_BIT(2)
296#define CPU_DTRACE_KPRIV RT_BIT(3)
297#define CPU_DTRACE_DIVZERO RT_BIT(4)
298#define CPU_DTRACE_ILLOP RT_BIT(5)
299#define CPU_DTRACE_NOSCRATCH RT_BIT(6)
300#define CPU_DTRACE_UPRIV RT_BIT(7)
301#define CPU_DTRACE_TUPOFLOW RT_BIT(8)
302#define CPU_DTRACE_ENTRY RT_BIT(9)
303#define CPU_DTRACE_FAULT UINT16_C(0x03ff)
304#define CPU_DTRACE_DROP RT_BIT(12)
305#define CPU_DTRACE_ERROR UINT16_C(0x13ff)
306#define CPU_DTRACE_NOFAULT RT_BIT(15)
307
308extern cpucore_t g_aVBoxDtCpuCores[RTCPUSET_MAX_CPUS];
309#define cpu_core (g_aVBoxDtCpuCores)
310
311struct VBoxDtCred *VBoxDtGetCurrentCreds(void);
312#define CRED() VBoxDtGetCurrentCreds()
313
314proc_t *VBoxDtThreadToProc(kthread_t *);
315
316
317#define ASSERT(a_Expr) Assert(a_Expr)
318#define panic VBoxDtPanic
319void VBoxDtPanic(const char *pszFormat, ...);
320#define cmn_err VBoxDtCmnErr
321void VBoxDtCmnErr(int iLevel, const char *pszFormat, ...);
322#define CE_WARN 10
323#define CE_NOTE 11
324#define uprintf VBoxDtUPrintf
325#define vuprintf VBoxDtUPrintfV
326void VBoxDtUPrintf(const char *pszFormat, ...);
327void VBoxDtUPrintfV(const char *pszFormat, va_list va);
328
329/*
330 * Memory allocation wrappers.
331 */
332#define KM_SLEEP RT_BIT(0)
333#define KM_NOSLEEP RT_BIT(1)
334#define kmem_alloc VBoxDtKMemAlloc
335#define kmem_zalloc VBoxDtKMemAllocZ
336#define kmem_free VBoxDtKMemFree
337void *VBoxDtKMemAlloc(size_t cbMem, uint32_t fFlags);
338void *VBoxDtKMemAllocZ(size_t cbMem, uint32_t fFlags);
339void VBoxDtKMemFree(void *pvMem, size_t cbMem);
340
341
342typedef struct VBoxDtMemCache kmem_cache_t;
343#define kmem_cache_create VBoxDtKMemCacheCreate
344#define kmem_cache_destroy VBoxDtKMemCacheDestroy
345#define kmem_cache_alloc VBoxDtKMemCacheAlloc
346#define kmem_cache_free VBoxDtKMemCacheFree
347struct VBoxDtMemCache *VBoxDtKMemCacheCreate(const char *pszName, size_t cbBuf, size_t cbAlign,
348 PFNRT pfnCtor, PFNRT pfnDtor, PFNRT pfnReclaim,
349 void *pvUser, void *pvVM, uint32_t fFlags);
350void VBoxDtKMemCacheDestroy(struct VBoxDtMemCache *pCache);
351void *VBoxDtKMemCacheAlloc(struct VBoxDtMemCache *pCache, uint32_t fFlags);
352void VBoxDtKMemCacheFree(struct VBoxDtMemCache *pCache, void *pvMem);
353
354
355typedef struct VBoxDtVMem vmem_t;
356#define VM_SLEEP RT_BIT(0)
357#define VM_BESTFIT RT_BIT(1)
358#define VMC_IDENTIFIER RT_BIT(16)
359#define vmem_create VBoxDtVMemCreate
360#define vmem_destroy VBoxDtVMemDestroy
361#define vmem_alloc VBoxDtVMemAlloc
362#define vmem_free VBoxDtVMemFree
363struct VBoxDtVMem *VBoxDtVMemCreate(const char *pszName, void *pvBase, size_t cb, size_t cbUnit,
364 PFNRT pfnAlloc, PFNRT pfnFree, struct VBoxDtVMem *pSrc,
365 size_t cbQCacheMax, uint32_t fFlags);
366void VBoxDtVMemDestroy(struct VBoxDtVMem *pVMemArena);
367void *VBoxDtVMemAlloc(struct VBoxDtVMem *pVMemArena, size_t cbMem, uint32_t fFlags);
368void VBoxDtVMemFree(struct VBoxDtVMem *pVMemArena, void *pvMem, size_t cbMem);
369
370/*
371 * Copy In/Out
372 */
373#define copyin VBoxDtCopyIn
374#define copyout VBoxDtCopyOut
375int VBoxDtCopyIn(void const *pvUser, void *pvDst, size_t cb);
376int VBoxDtCopyOut(void const *pvSrc, void *pvUser, size_t cb);
377
378/*
379 * Device numbers.
380 */
381typedef uint64_t dev_t;
382typedef uint32_t major_t;
383typedef uint32_t minor_t;
384#define makedevice(a_Maj, a_Min) RT_MAKE_U64(a_Min, a_Maj)
385#define getemajor(a_Dev) RT_HIDWORD(a_Dev)
386#define geteminor(a_Dev) RT_LODWORD(a_Dev)
387#define getminor(a_Dev) RT_LODWORD(a_Dev)
388
389/*
390 * DDI
391 */
392# define DDI_SUCCESS (0)
393# define DDI_FAILURE (-1)
394# if 0 /* not needed */
395# define ddi_soft_state_init VBoxDtDdiSoftStateInit
396# define ddi_soft_state_fini VBoxDtDdiSoftStateTerm
397# define ddi_soft_state_zalloc VBoxDtDdiSoftStateAllocZ
398# define ddi_get_soft_state VBoxDtDdiSoftStateGet
399# define ddi_soft_state_free VBoxDtDdiSoftStateFree
400int VBoxDtDdiSoftStateInit(void **ppvSoftStates, size_t cbSoftState, uint32_t cMaxItems);
401int VBoxDtDdiSoftStateTerm(void **ppvSoftStates);
402int VBoxDtDdiSoftStateAllocZ(void *pvSoftStates, RTDEV uMinor);
403int VBoxDtDdiSoftStateFree(void *pvSoftStates, RTDEV uMinor);
404void *VBoxDtDdiSoftStateGet(void *pvSoftStates, RTDEV uMinor);
405
406typedef enum { DDI_ATT_CMD_DUMMY } ddi_attach_cmd_t;
407typedef enum { DDI_DETACH, DDI_SUSPEND } ddi_detach_cmd_t;
408typedef struct VBoxDtDevInfo dev_info_t;
409# define ddi_driver_major VBoxDtDdiDriverMajor
410# define ddi_report_dev VBoxDtDdiReportDev
411major_t VBoxDtDdiDriverMajor(struct VBoxDtDevInfo *pDevInfo);
412void VBoxDtDdiReportDev(struct VBoxDtDevInfo *pDevInfo);
413# endif
414
415/*
416 * DTrace bits we've made external.
417 */
418extern int dtrace_attach(void);
419extern int dtrace_detach(void);
420struct dtrace_state;
421extern int dtrace_open(struct dtrace_state **ppState, struct VBoxDtCred *cred_p);
422extern int dtrace_ioctl(struct dtrace_state *state, int cmd, intptr_t arg, int32_t *rv);
423extern int dtrace_close(struct dtrace_state *state);
424
425#endif /* IN_RING0 */
426
427
428#ifdef IN_RING3
429/*
430 * Make life a little easier in ring-3.
431 */
432
433/* Replacement for strndup(), requires editing the code unfortunately. */
434# define MY_STRDUPA(a_pszRes, a_pszSrc) \
435 do { \
436 size_t cb = strlen(a_pszSrc) + 1; \
437 (a_pszRes) = (char *)alloca(cb); \
438 memcpy(a_pszRes, a_pszSrc, cb); \
439 } while (0)
440
441/*
442 * gelf
443 */
444# include <iprt/formats/elf64.h>
445typedef Elf64_Half GElf_Half;
446typedef Elf64_Xword GElf_Xword;
447typedef Elf64_Shdr GElf_Shdr;
448typedef Elf64_Ehdr GElf_Ehdr;
449typedef Elf64_Sym GElf_Sym;
450typedef Elf64_Addr GElf_Addr;
451#define GELF_ST_INFO ELF64_ST_INFO
452#define GELF_ST_TYPE ELF64_ST_TYPE
453#define GELF_ST_BIND ELF64_ST_BIND
454
455/*
456 * MSC stuff.
457 */
458# ifdef _MSC_VER
459# ifndef SIZE_MAX
460# if ARCH_BITS == 32
461# define SIZE_MAX UINT32_MAX
462# else
463# define SIZE_MAX UINT64_MAX
464# endif
465# endif
466# endif /* _MSC_VER */
467
468#endif /* IN_RING3 */
469
470RT_C_DECLS_END
471#endif /* !VBOX_INCLUDED_SRC_VBoxDTrace_include_VBoxDTraceTypes_h */
472
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use