VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibInternal.h

Last change on this file was 100360, checked in by vboxsync, 11 months ago

Additions/VBoxGuest/VBoxGuestR0LibPhysHeap: Make use of the RTR0MemObjContAlloc() API and support allocating memory above 4GiB, bugref:10457

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: VBoxGuestR0LibInternal.h 100360 2023-07-04 07:09:24Z vboxsync $ */
2/** @file
3 * VBoxGuestLibR0 - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31#ifndef GA_INCLUDED_SRC_common_VBoxGuest_lib_VBoxGuestR0LibInternal_h
32#define GA_INCLUDED_SRC_common_VBoxGuest_lib_VBoxGuestR0LibInternal_h
33#ifndef RT_WITHOUT_PRAGMA_ONCE
34# pragma once
35#endif
36
37/*
38 * Define the private IDC handle structure before we include the VBoxGuestLib.h header.
39 */
40#include <iprt/types.h>
41#include <iprt/assert.h>
42RT_C_DECLS_BEGIN
43
44# ifndef VBGL_VBOXGUEST
45/**
46 * The hidden part of VBGLIDCHANDLE.
47 */
48struct VBGLIDCHANDLEPRIVATE
49{
50 /** Pointer to the session handle. */
51 void *pvSession;
52# if defined(RT_OS_WINDOWS) && (defined(IPRT_INCLUDED_nt_ntddk_h) || defined(IPRT_INCLUDED_nt_nt_h))
53 /** Pointer to the NT device object. */
54 PDEVICE_OBJECT pDeviceObject;
55 /** Pointer to the NT file object. */
56 PFILE_OBJECT pFileObject;
57# elif defined(RT_OS_SOLARIS) && defined(_SYS_SUNLDI_H)
58 /** LDI device handle to keep the device attached. */
59 ldi_handle_t hDev;
60# endif
61};
62/** Indicate that the VBGLIDCHANDLEPRIVATE structure is present. */
63# define VBGLIDCHANDLEPRIVATE_DECLARED 1
64#endif
65
66#include <VBox/VMMDev.h>
67#include <VBox/VBoxGuest.h>
68#include <VBox/VBoxGuestLib.h>
69
70#ifdef VBGLIDCHANDLEPRIVATE_DECLARED
71AssertCompile(RT_SIZEOFMEMB(VBGLIDCHANDLE, apvPadding) >= sizeof(struct VBGLIDCHANDLEPRIVATE));
72#endif
73
74
75/*
76 * Native IDC functions.
77 */
78int VBOXCALL vbglR0IdcNativeOpen(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCCONNECT pReq);
79int VBOXCALL vbglR0IdcNativeClose(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCDISCONNECT pReq);
80
81
82/*
83 * Deprecated logging macro
84 */
85#include <VBox/log.h>
86#ifdef RT_OS_WINDOWS /** @todo dprintf() -> Log() */
87# if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(LOG_ENABLED)
88# define dprintf(a) RTLogBackdoorPrintf a
89# else
90# define dprintf(a) do {} while (0)
91# endif
92#else
93# define dprintf(a) Log(a)
94#endif
95
96/*
97 * Lazy bird: OS/2 doesn't currently implement the RTSemMutex API in ring-0, so
98 * use a fast mutex instead. Unlike Windows, the OS/2 implementation
99 * doesn't have any nasty side effects on IRQL-like context properties, so the
100 * fast mutexes on OS/2 are identical to normal mutexes except for the missing
101 * timeout aspec. Fortunately we don't need timeouts here.
102 */
103#ifdef RT_OS_OS2
104# define VBGLDATA_USE_FAST_MUTEX
105#endif
106
107struct VBGLPHYSHEAPBLOCK;
108typedef struct VBGLPHYSHEAPBLOCK VBGLPHYSHEAPBLOCK;
109struct VBGLPHYSHEAPFREEBLOCK;
110typedef struct VBGLPHYSHEAPFREEBLOCK VBGLPHYSHEAPFREEBLOCK;
111struct VBGLPHYSHEAPCHUNK;
112typedef struct VBGLPHYSHEAPCHUNK VBGLPHYSHEAPCHUNK;
113
114enum VbglLibStatus
115{
116 VbglStatusNotInitialized = 0,
117 VbglStatusInitializing,
118 VbglStatusReady
119};
120
121/**
122 * Global VBGL ring-0 data.
123 * Lives in VBoxGuestR0LibInit.cpp.
124 */
125typedef struct VBGLDATA
126{
127 /** Init status of the library. */
128 enum VbglLibStatus status;
129 /** I/O port to issue requests to. */
130 RTIOPORT portVMMDev;
131 /** MMIO request region if available. */
132 volatile uintptr_t *pMmioReq;
133 /** VMMDev adapter memory region if available. */
134 VMMDevMemory *pVMMDevMemory;
135
136 /** Physical memory heap data.
137 * @{
138 */
139 RTSEMFASTMUTEX hMtxHeap;
140 /** Head of the block list (both free and allocated blocks).
141 * This runs parallel to the chunk list and is sorted by address within each
142 * chunk. This allows merging with blocks both after and before when
143 * freeing. */
144 VBGLPHYSHEAPBLOCK *pBlockHead;
145 /** Head of the free list.
146 * This is not sorted and more on the most recently freed approach. */
147 VBGLPHYSHEAPFREEBLOCK *pFreeHead;
148 /** Number of block of any kind. */
149 int32_t cBlocks;
150 /** Number of free blocks. */
151 int32_t cFreeBlocks;
152 /** Head of the chunk list. */
153 VBGLPHYSHEAPCHUNK *pChunkHead;
154 /** Maximum physical address allowed for allocations, inclusive. */
155 RTHCPHYS HCPhysMax;
156 /** @} */
157
158 /**
159 * The host version data.
160 */
161 VMMDevReqHostVersion hostVersion;
162
163
164#ifndef VBGL_VBOXGUEST
165 /** The IDC handle. This is used for talking to the main driver. */
166 VBGLIDCHANDLE IdcHandle;
167 /** Mutex used to serialize IDC setup. */
168# ifdef VBGLDATA_USE_FAST_MUTEX
169 RTSEMFASTMUTEX hMtxIdcSetup;
170# else
171 RTSEMMUTEX hMtxIdcSetup;
172# endif
173#endif
174} VBGLDATA;
175
176
177extern VBGLDATA g_vbgldata;
178
179/**
180 * Internal macro for checking whether we can pass physical page lists to the
181 * host.
182 *
183 * ASSUMES that vbglR0Enter has been called already.
184 *
185 * @param a_fLocked For the windows shared folders workarounds.
186 *
187 * @remarks Disabled the PageList feature for locked memory on Windows,
188 * because a new MDL is created by VBGL to get the page addresses
189 * and the pages from the MDL are marked as dirty when they should not.
190 */
191#if defined(RT_OS_WINDOWS)
192# define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
193 ( !(a_fLocked) && (g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
194#else
195# define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
196 ( !!(g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
197#endif
198
199int vbglR0Enter (void);
200
201#ifdef VBOX_WITH_HGCM
202struct VBGLHGCMHANDLEDATA *vbglR0HGCMHandleAlloc(void);
203void vbglR0HGCMHandleFree(struct VBGLHGCMHANDLEDATA *pHandle);
204#endif /* VBOX_WITH_HGCM */
205
206#ifndef VBGL_VBOXGUEST
207/**
208 * Get the IDC handle to the main VBoxGuest driver.
209 * @returns VERR_TRY_AGAIN if the main driver has not yet been loaded.
210 */
211int VBOXCALL vbglR0QueryIdcHandle(PVBGLIDCHANDLE *ppIdcHandle);
212#endif
213
214RT_C_DECLS_END
215
216#endif /* !GA_INCLUDED_SRC_common_VBoxGuest_lib_VBoxGuestR0LibInternal_h */
217
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use