VirtualBox

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

Last change on this file was 106921, checked in by vboxsync, 5 weeks ago

VBoxDTrace,VMM,IPRT: Made the ring-0 component of the DTrace extension pack compile on win.arm64. jiraref:VBP-1447

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.6 KB
Line 
1
2/* $Id: VBoxDTraceTypes.h 106921 2024-11-11 09:51:28Z vboxsync $ */
3/** @file
4 * VBoxDTraceTypes.h - Fake a bunch of Solaris types.
5 *
6 * Contributed by: bird
7 */
8
9/*
10 * Copyright (C) 2012-2024 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#elif defined(RT_ARCH_ARM64)
136# ifndef _LP64
137# define _LP64 1
138# endif
139# if !defined(_LITTLE_ENDIAN)
140# define _LITTLE_ENDIAN 1
141# endif
142
143#else
144# error "unsupported arch!"
145#endif
146
147/** Mark a cast added when porting the code to VBox.
148 * Avoids lots of \#ifdef VBOX otherwise needed to mark up the changes. */
149#define VBDTCAST(a_Type) (a_Type)
150/** Mark a type change made when porting the code to VBox.
151 * This is usually signed -> unsigned type changes that avoids a whole lot of
152 * comparsion warnings. */
153#define VBDTTYPE(a_VBox, a_Org) a_VBox
154/** Mark missing void in a parameter list. */
155#define VBDTVOID void
156/** Mark missing static in a function definition. */
157#define VBDTSTATIC static
158#define VBDTUNASS(a_Value) = a_Value
159#define VBDTGCC(a_Value) = a_Value
160#define VBDTMSC(a_Value) = a_Value
161
162/*
163 * string
164 */
165#ifdef IN_RING0
166# undef bcopy
167# define bcopy(a_pSrc, a_pDst, a_cb) ((void)memmove(a_pDst, a_pSrc, a_cb))
168# undef bzero
169# define bzero(a_pDst, a_cb) ((void)memset(a_pDst, 0, a_cb))
170# undef bcmp
171# define bcmp(a_p1, a_p2, a_cb) (memcmp(a_p1, a_p2, a_cb))
172#endif
173#if defined(_MSC_VER) || defined(IN_RING0)
174# define snprintf (int)RTStrPrintf /** @todo wrong return value */
175# define vsnprintf (int)RTStrPrintfV /** @todo wrong return value */
176#endif
177
178/*
179 * Bitmap stuff.
180 */
181#define BT_SIZEOFMAP(a_cBits) ( (a_cBits + 63) / 8 )
182#define BT_SET(a_aulBitmap, iBit) ASMBitSet(a_aulBitmap, iBit)
183#define BT_CLEAR(a_aulBitmap, iBit) ASMBitClear(a_aulBitmap, iBit)
184#define BT_TEST(a_aulBitmap, iBit) ASMBitTest(a_aulBitmap, iBit)
185#if ARCH_BITS == 32
186# define BT_NBIPUL 32
187# define BT_ULSHIFT 5 /* log2(32) = 5 */
188# define BT_ULMASK 0x1f
189# define BT_BITOUL(a_cBits) ( ((a_cBits) + 31) / 32 )
190#elif ARCH_BITS == 64
191# define BT_NBIPUL 64
192# define BT_ULSHIFT 6 /* log2(32) = 6 */
193# define BT_ULMASK 0x3f
194# define BT_BITOUL(a_cBits) ( ((a_cBits) + 63) / 64 )
195#else
196# error Bad ARCH_BITS...
197#endif
198
199
200#ifdef IN_RING0
201
202/*
203 * Kernel stuff...
204 */
205#define CPU_ON_INTR(a_pCpu) (false)
206
207#define KERNELBASE VBoxDtGetKernelBase()
208uintptr_t VBoxDtGetKernelBase(void);
209
210
211typedef struct VBoxDtCred
212{
213 int32_t cr_refs;
214 RTUID cr_uid;
215 RTUID cr_ruid;
216 RTUID cr_suid;
217 RTGID cr_gid;
218 RTGID cr_rgid;
219 RTGID cr_sgid;
220 zoneid_t cr_zone;
221} cred_t;
222#define PRIV_POLICY_ONLY(a_pCred, a_uPriv, a_fAll) (true)
223#define priv_isequalset(a, b) (true)
224#define crgetuid(a_pCred) ((a_pCred)->cr_uid)
225#define crgetzoneid(a_pCred) ((a_pCred)->cr_zone)
226#define crhold VBoxDtCredHold
227#define crfree VBoxDtCredFree
228void VBoxDtCredHold(struct VBoxDtCred *pCred);
229void VBoxDtCredFree(struct VBoxDtCred *pCred);
230
231
232typedef struct RTTIMER *cyclic_id_t;
233#define CYCLIC_NONE ((struct RTTIMER *)NULL)
234#define cyclic_remove(a_hTimer) RTTimerDestroy(a_hTimer)
235
236typedef struct VBoxDtThread
237{
238 /** The next thread with the same hash table entry.
239 * Or the next free thread. */
240 struct VBoxDtThread *pNext;
241 /** Age list node. */
242 RTLISTNODE AgeEntry;
243 /** The native thread handle. */
244 RTNATIVETHREAD hNative;
245 /** The process ID. */
246 RTPROCESS uPid;
247
248 uint32_t t_predcache;
249 uintptr_t t_dtrace_scrpc;
250 uintptr_t t_dtrace_astpc;
251 hrtime_t t_dtrace_vtime;
252 hrtime_t t_dtrace_start;
253 uint8_t t_dtrace_stop;
254} kthread_t;
255struct VBoxDtThread *VBoxDtGetCurrentThread(void);
256#define curthread (VBoxDtGetCurrentThread())
257
258
259typedef struct VBoxDtProcess proc_t;
260# if 0 /* not needed ? */
261struct VBoxDtProcess proc_t;
262{
263/* uint32_t p_flag; - don't bother with this */
264 RTPROCESS p_pid;
265 struct dtrace_helpers *p_dtrace_helpers;
266}
267proc_t *VBoxDtGetCurrentProc(void);
268# define curproc (VBoxDtGetCurrentProc())
269/*# define SNOCD RT_BIT(0) - don't bother with this */
270# endif
271
272typedef struct VBoxDtTaskQueue taskq_t;
273
274typedef struct VBoxDtMutex
275{
276 RTSEMMUTEX hMtx;
277 RTNATIVETHREAD volatile hOwner;
278} kmutex_t;
279#define mutex_enter VBoxDtMutexEnter
280#define mutex_exit VBoxDtMutexExit
281#define MUTEX_HELD(a_pMtx) VBoxDtMutexIsOwner(a_pMtx)
282#define MUTEX_NOT_HELD(a_pMtx) (!VBoxDtMutexIsOwner(a_pMtx))
283#define mod_lock g_DummyMtx
284#define cpu_lock g_DummyMtx
285int VBoxDtMutexInit(struct VBoxDtMutex *pMtx);
286void VBoxDtMutexDelete(struct VBoxDtMutex *pMtx);
287void VBoxDtMutexEnter(struct VBoxDtMutex *pMtx);
288void VBoxDtMutexExit(struct VBoxDtMutex *pMtx);
289bool VBoxDtMutexIsOwner(struct VBoxDtMutex *pMtx);
290extern struct VBoxDtMutex g_DummyMtx;
291
292
293typedef struct VBoxDtCpuCore
294{
295 RTCPUID cpu_id;
296 uintptr_t cpuc_dtrace_illval;
297 uint16_t volatile cpuc_dtrace_flags;
298
299} cpucore_t;
300
301#define CPU_DTRACE_BADADDR RT_BIT(0)
302#define CPU_DTRACE_BADALIGN RT_BIT(1)
303#define CPU_DTRACE_BADSTACK RT_BIT(2)
304#define CPU_DTRACE_KPRIV RT_BIT(3)
305#define CPU_DTRACE_DIVZERO RT_BIT(4)
306#define CPU_DTRACE_ILLOP RT_BIT(5)
307#define CPU_DTRACE_NOSCRATCH RT_BIT(6)
308#define CPU_DTRACE_UPRIV RT_BIT(7)
309#define CPU_DTRACE_TUPOFLOW RT_BIT(8)
310#define CPU_DTRACE_ENTRY RT_BIT(9)
311#define CPU_DTRACE_FAULT UINT16_C(0x03ff)
312#define CPU_DTRACE_DROP RT_BIT(12)
313#define CPU_DTRACE_ERROR UINT16_C(0x13ff)
314#define CPU_DTRACE_NOFAULT RT_BIT(15)
315
316extern cpucore_t g_aVBoxDtCpuCores[RTCPUSET_MAX_CPUS];
317#define cpu_core (g_aVBoxDtCpuCores)
318
319struct VBoxDtCred *VBoxDtGetCurrentCreds(void);
320#define CRED() VBoxDtGetCurrentCreds()
321
322proc_t *VBoxDtThreadToProc(kthread_t *);
323
324
325#define ASSERT(a_Expr) Assert(a_Expr)
326#define panic VBoxDtPanic
327void VBoxDtPanic(const char *pszFormat, ...);
328#define cmn_err VBoxDtCmnErr
329void VBoxDtCmnErr(int iLevel, const char *pszFormat, ...);
330#define CE_WARN 10
331#define CE_NOTE 11
332#define uprintf VBoxDtUPrintf
333#define vuprintf VBoxDtUPrintfV
334void VBoxDtUPrintf(const char *pszFormat, ...);
335void VBoxDtUPrintfV(const char *pszFormat, va_list va);
336
337/*
338 * Memory allocation wrappers.
339 */
340#define KM_SLEEP RT_BIT(0)
341#define KM_NOSLEEP RT_BIT(1)
342#define kmem_alloc VBoxDtKMemAlloc
343#define kmem_zalloc VBoxDtKMemAllocZ
344#define kmem_free VBoxDtKMemFree
345void *VBoxDtKMemAlloc(size_t cbMem, uint32_t fFlags);
346void *VBoxDtKMemAllocZ(size_t cbMem, uint32_t fFlags);
347void VBoxDtKMemFree(void *pvMem, size_t cbMem);
348
349
350typedef struct VBoxDtMemCache kmem_cache_t;
351#define kmem_cache_create VBoxDtKMemCacheCreate
352#define kmem_cache_destroy VBoxDtKMemCacheDestroy
353#define kmem_cache_alloc VBoxDtKMemCacheAlloc
354#define kmem_cache_free VBoxDtKMemCacheFree
355struct VBoxDtMemCache *VBoxDtKMemCacheCreate(const char *pszName, size_t cbBuf, size_t cbAlign,
356 PFNRT pfnCtor, PFNRT pfnDtor, PFNRT pfnReclaim,
357 void *pvUser, void *pvVM, uint32_t fFlags);
358void VBoxDtKMemCacheDestroy(struct VBoxDtMemCache *pCache);
359void *VBoxDtKMemCacheAlloc(struct VBoxDtMemCache *pCache, uint32_t fFlags);
360void VBoxDtKMemCacheFree(struct VBoxDtMemCache *pCache, void *pvMem);
361
362
363typedef struct VBoxDtVMem vmem_t;
364#define VM_SLEEP RT_BIT(0)
365#define VM_BESTFIT RT_BIT(1)
366#define VMC_IDENTIFIER RT_BIT(16)
367#define vmem_create VBoxDtVMemCreate
368#define vmem_destroy VBoxDtVMemDestroy
369#define vmem_alloc VBoxDtVMemAlloc
370#define vmem_free VBoxDtVMemFree
371struct VBoxDtVMem *VBoxDtVMemCreate(const char *pszName, void *pvBase, size_t cb, size_t cbUnit,
372 PFNRT pfnAlloc, PFNRT pfnFree, struct VBoxDtVMem *pSrc,
373 size_t cbQCacheMax, uint32_t fFlags);
374void VBoxDtVMemDestroy(struct VBoxDtVMem *pVMemArena);
375void *VBoxDtVMemAlloc(struct VBoxDtVMem *pVMemArena, size_t cbMem, uint32_t fFlags);
376void VBoxDtVMemFree(struct VBoxDtVMem *pVMemArena, void *pvMem, size_t cbMem);
377
378/*
379 * Copy In/Out
380 */
381#define copyin VBoxDtCopyIn
382#define copyout VBoxDtCopyOut
383int VBoxDtCopyIn(void const *pvUser, void *pvDst, size_t cb);
384int VBoxDtCopyOut(void const *pvSrc, void *pvUser, size_t cb);
385
386/*
387 * Device numbers.
388 */
389typedef uint64_t dev_t;
390typedef uint32_t major_t;
391typedef uint32_t minor_t;
392#define makedevice(a_Maj, a_Min) RT_MAKE_U64(a_Min, a_Maj)
393#define getemajor(a_Dev) RT_HIDWORD(a_Dev)
394#define geteminor(a_Dev) RT_LODWORD(a_Dev)
395#define getminor(a_Dev) RT_LODWORD(a_Dev)
396
397/*
398 * DDI
399 */
400# define DDI_SUCCESS (0)
401# define DDI_FAILURE (-1)
402# if 0 /* not needed */
403# define ddi_soft_state_init VBoxDtDdiSoftStateInit
404# define ddi_soft_state_fini VBoxDtDdiSoftStateTerm
405# define ddi_soft_state_zalloc VBoxDtDdiSoftStateAllocZ
406# define ddi_get_soft_state VBoxDtDdiSoftStateGet
407# define ddi_soft_state_free VBoxDtDdiSoftStateFree
408int VBoxDtDdiSoftStateInit(void **ppvSoftStates, size_t cbSoftState, uint32_t cMaxItems);
409int VBoxDtDdiSoftStateTerm(void **ppvSoftStates);
410int VBoxDtDdiSoftStateAllocZ(void *pvSoftStates, RTDEV uMinor);
411int VBoxDtDdiSoftStateFree(void *pvSoftStates, RTDEV uMinor);
412void *VBoxDtDdiSoftStateGet(void *pvSoftStates, RTDEV uMinor);
413
414typedef enum { DDI_ATT_CMD_DUMMY } ddi_attach_cmd_t;
415typedef enum { DDI_DETACH, DDI_SUSPEND } ddi_detach_cmd_t;
416typedef struct VBoxDtDevInfo dev_info_t;
417# define ddi_driver_major VBoxDtDdiDriverMajor
418# define ddi_report_dev VBoxDtDdiReportDev
419major_t VBoxDtDdiDriverMajor(struct VBoxDtDevInfo *pDevInfo);
420void VBoxDtDdiReportDev(struct VBoxDtDevInfo *pDevInfo);
421# endif
422
423/*
424 * DTrace bits we've made external.
425 */
426extern int dtrace_attach(void);
427extern int dtrace_detach(void);
428struct dtrace_state;
429extern int dtrace_open(struct dtrace_state **ppState, struct VBoxDtCred *cred_p);
430extern int dtrace_ioctl(struct dtrace_state *state, int cmd, intptr_t arg, int32_t *rv);
431extern int dtrace_close(struct dtrace_state *state);
432
433#endif /* IN_RING0 */
434
435
436#ifdef IN_RING3
437/*
438 * Make life a little easier in ring-3.
439 */
440
441/* Replacement for strndup(), requires editing the code unfortunately. */
442# define MY_STRDUPA(a_pszRes, a_pszSrc) \
443 do { \
444 size_t cb = strlen(a_pszSrc) + 1; \
445 (a_pszRes) = (char *)alloca(cb); \
446 memcpy(a_pszRes, a_pszSrc, cb); \
447 } while (0)
448
449/*
450 * gelf
451 */
452# include <iprt/formats/elf64.h>
453typedef Elf64_Half GElf_Half;
454typedef Elf64_Xword GElf_Xword;
455typedef Elf64_Shdr GElf_Shdr;
456typedef Elf64_Ehdr GElf_Ehdr;
457typedef Elf64_Sym GElf_Sym;
458typedef Elf64_Addr GElf_Addr;
459#define GELF_ST_INFO ELF64_ST_INFO
460#define GELF_ST_TYPE ELF64_ST_TYPE
461#define GELF_ST_BIND ELF64_ST_BIND
462
463/*
464 * MSC stuff.
465 */
466# ifdef _MSC_VER
467# ifndef SIZE_MAX
468# if ARCH_BITS == 32
469# define SIZE_MAX UINT32_MAX
470# else
471# define SIZE_MAX UINT64_MAX
472# endif
473# endif
474# endif /* _MSC_VER */
475
476#endif /* IN_RING3 */
477
478RT_C_DECLS_END
479#endif /* !VBOX_INCLUDED_SRC_VBoxDTrace_include_VBoxDTraceTypes_h */
480
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