[55401] | 1 | /* $Id: VBoxGuestR0LibInternal.h 100360 2023-07-04 07:09:24Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[21211] | 3 | * VBoxGuestLibR0 - Internal header.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[72627] | 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:
|
---|
[8155] | 17 | *
|
---|
[72627] | 18 | * The above copyright notice and this permission notice shall be
|
---|
| 19 | * included in all copies or substantial portions of the Software.
|
---|
[26425] | 20 | *
|
---|
[72627] | 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.
|
---|
[1] | 29 | */
|
---|
| 30 |
|
---|
[76563] | 31 | #ifndef GA_INCLUDED_SRC_common_VBoxGuest_lib_VBoxGuestR0LibInternal_h
|
---|
| 32 | #define GA_INCLUDED_SRC_common_VBoxGuest_lib_VBoxGuestR0LibInternal_h
|
---|
[76533] | 33 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 34 | # pragma once
|
---|
| 35 | #endif
|
---|
[1] | 36 |
|
---|
[68645] | 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>
|
---|
| 42 | RT_C_DECLS_BEGIN
|
---|
| 43 |
|
---|
| 44 | # ifndef VBGL_VBOXGUEST
|
---|
| 45 | /**
|
---|
| 46 | * The hidden part of VBGLIDCHANDLE.
|
---|
| 47 | */
|
---|
| 48 | struct VBGLIDCHANDLEPRIVATE
|
---|
| 49 | {
|
---|
| 50 | /** Pointer to the session handle. */
|
---|
| 51 | void *pvSession;
|
---|
[76557] | 52 | # if defined(RT_OS_WINDOWS) && (defined(IPRT_INCLUDED_nt_ntddk_h) || defined(IPRT_INCLUDED_nt_nt_h))
|
---|
[68645] | 53 | /** Pointer to the NT device object. */
|
---|
| 54 | PDEVICE_OBJECT pDeviceObject;
|
---|
| 55 | /** Pointer to the NT file object. */
|
---|
| 56 | PFILE_OBJECT pFileObject;
|
---|
[68648] | 57 | # elif defined(RT_OS_SOLARIS) && defined(_SYS_SUNLDI_H)
|
---|
[68645] | 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 |
|
---|
[21227] | 66 | #include <VBox/VMMDev.h>
|
---|
| 67 | #include <VBox/VBoxGuest.h>
|
---|
[719] | 68 | #include <VBox/VBoxGuestLib.h>
|
---|
| 69 |
|
---|
[68645] | 70 | #ifdef VBGLIDCHANDLEPRIVATE_DECLARED
|
---|
| 71 | AssertCompile(RT_SIZEOFMEMB(VBGLIDCHANDLE, apvPadding) >= sizeof(struct VBGLIDCHANDLEPRIVATE));
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | /*
|
---|
| 76 | * Native IDC functions.
|
---|
| 77 | */
|
---|
| 78 | int VBOXCALL vbglR0IdcNativeOpen(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCCONNECT pReq);
|
---|
| 79 | int VBOXCALL vbglR0IdcNativeClose(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCDISCONNECT pReq);
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * Deprecated logging macro
|
---|
| 84 | */
|
---|
[14217] | 85 | #include <VBox/log.h>
|
---|
[21461] | 86 | #ifdef RT_OS_WINDOWS /** @todo dprintf() -> Log() */
|
---|
[36318] | 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
|
---|
[1] | 92 | #else
|
---|
[21461] | 93 | # define dprintf(a) Log(a)
|
---|
| 94 | #endif
|
---|
[1] | 95 |
|
---|
[68613] | 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
|
---|
[1] | 106 |
|
---|
[97913] | 107 | struct VBGLPHYSHEAPBLOCK;
|
---|
| 108 | typedef struct VBGLPHYSHEAPBLOCK VBGLPHYSHEAPBLOCK;
|
---|
[97937] | 109 | struct VBGLPHYSHEAPFREEBLOCK;
|
---|
| 110 | typedef struct VBGLPHYSHEAPFREEBLOCK VBGLPHYSHEAPFREEBLOCK;
|
---|
| 111 | struct VBGLPHYSHEAPCHUNK;
|
---|
[97913] | 112 | typedef struct VBGLPHYSHEAPCHUNK VBGLPHYSHEAPCHUNK;
|
---|
[1] | 113 |
|
---|
| 114 | enum VbglLibStatus
|
---|
| 115 | {
|
---|
| 116 | VbglStatusNotInitialized = 0,
|
---|
| 117 | VbglStatusInitializing,
|
---|
| 118 | VbglStatusReady
|
---|
| 119 | };
|
---|
| 120 |
|
---|
[21461] | 121 | /**
|
---|
| 122 | * Global VBGL ring-0 data.
|
---|
[97921] | 123 | * Lives in VBoxGuestR0LibInit.cpp.
|
---|
[21461] | 124 | */
|
---|
[58178] | 125 | typedef struct VBGLDATA
|
---|
[1] | 126 | {
|
---|
[100267] | 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;
|
---|
[1] | 135 |
|
---|
[97913] | 136 | /** Physical memory heap data.
|
---|
[1] | 137 | * @{
|
---|
| 138 | */
|
---|
[97940] | 139 | RTSEMFASTMUTEX hMtxHeap;
|
---|
[97937] | 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;
|
---|
[100360] | 154 | /** Maximum physical address allowed for allocations, inclusive. */
|
---|
| 155 | RTHCPHYS HCPhysMax;
|
---|
[1] | 156 | /** @} */
|
---|
| 157 |
|
---|
[21461] | 158 | /**
|
---|
| 159 | * The host version data.
|
---|
| 160 | */
|
---|
| 161 | VMMDevReqHostVersion hostVersion;
|
---|
| 162 |
|
---|
| 163 |
|
---|
[1] | 164 | #ifndef VBGL_VBOXGUEST
|
---|
[68550] | 165 | /** The IDC handle. This is used for talking to the main driver. */
|
---|
| 166 | VBGLIDCHANDLE IdcHandle;
|
---|
| 167 | /** Mutex used to serialize IDC setup. */
|
---|
[68613] | 168 | # ifdef VBGLDATA_USE_FAST_MUTEX
|
---|
| 169 | RTSEMFASTMUTEX hMtxIdcSetup;
|
---|
| 170 | # else
|
---|
[68550] | 171 | RTSEMMUTEX hMtxIdcSetup;
|
---|
[68613] | 172 | # endif
|
---|
[1] | 173 | #endif
|
---|
| 174 | } VBGLDATA;
|
---|
| 175 |
|
---|
[21461] | 176 |
|
---|
[1] | 177 | extern VBGLDATA g_vbgldata;
|
---|
| 178 |
|
---|
[21461] | 179 | /**
|
---|
[40901] | 180 | * Internal macro for checking whether we can pass physical page lists to the
|
---|
[21461] | 181 | * host.
|
---|
| 182 | *
|
---|
| 183 | * ASSUMES that vbglR0Enter has been called already.
|
---|
[40901] | 184 | *
|
---|
| 185 | * @param a_fLocked For the windows shared folders workarounds.
|
---|
| 186 | *
|
---|
[44558] | 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.
|
---|
[1] | 190 | */
|
---|
[40901] | 191 | #if defined(RT_OS_WINDOWS)
|
---|
[44558] | 192 | # define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
|
---|
| 193 | ( !(a_fLocked) && (g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
|
---|
[38407] | 194 | #else
|
---|
[40901] | 195 | # define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
|
---|
[21461] | 196 | ( !!(g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
|
---|
[38407] | 197 | #endif
|
---|
[1] | 198 |
|
---|
[21461] | 199 | int vbglR0Enter (void);
|
---|
| 200 |
|
---|
[11820] | 201 | #ifdef VBOX_WITH_HGCM
|
---|
[68476] | 202 | struct VBGLHGCMHANDLEDATA *vbglR0HGCMHandleAlloc(void);
|
---|
| 203 | void vbglR0HGCMHandleFree(struct VBGLHGCMHANDLEDATA *pHandle);
|
---|
[21227] | 204 | #endif /* VBOX_WITH_HGCM */
|
---|
[1] | 205 |
|
---|
[41852] | 206 | #ifndef VBGL_VBOXGUEST
|
---|
| 207 | /**
|
---|
[68550] | 208 | * Get the IDC handle to the main VBoxGuest driver.
|
---|
[41852] | 209 | * @returns VERR_TRY_AGAIN if the main driver has not yet been loaded.
|
---|
| 210 | */
|
---|
[68550] | 211 | int VBOXCALL vbglR0QueryIdcHandle(PVBGLIDCHANDLE *ppIdcHandle);
|
---|
[41852] | 212 | #endif
|
---|
| 213 |
|
---|
[68645] | 214 | RT_C_DECLS_END
|
---|
[21211] | 215 |
|
---|
[76563] | 216 | #endif /* !GA_INCLUDED_SRC_common_VBoxGuest_lib_VBoxGuestR0LibInternal_h */
|
---|
[68645] | 217 |
|
---|