VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibModule.cpp

Last change on this file was 98103, checked in by vboxsync, 16 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: 5.9 KB
Line 
1/* $Id: VBoxGuestR3LibModule.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Shared modules.
4 */
5
6/*
7 * Copyright (C) 2007-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "VBoxGuestR3LibInternal.h"
42#include <iprt/mem.h>
43#include <iprt/string.h>
44
45/**
46 * Registers a new shared module for the VM
47 *
48 * @returns IPRT status code.
49 * @param pszModuleName Module name
50 * @param pszVersion Module version
51 * @param GCBaseAddr Module base address
52 * @param cbModule Module size
53 * @param cRegions Number of shared region descriptors
54 * @param pRegions Shared region(s)
55 */
56VBGLR3DECL(int) VbglR3RegisterSharedModule(char *pszModuleName, char *pszVersion,
57 RTGCPTR64 GCBaseAddr, uint32_t cbModule,
58 unsigned cRegions, VMMDEVSHAREDREGIONDESC *pRegions)
59{
60 VMMDevSharedModuleRegistrationRequest *pReq;
61 int rc;
62
63 /* Sanity check. */
64 AssertReturn(cRegions < VMMDEVSHAREDREGIONDESC_MAX, VERR_INVALID_PARAMETER);
65
66 pReq = (VMMDevSharedModuleRegistrationRequest *)RTMemAllocZ(RT_UOFFSETOF_DYN(VMMDevSharedModuleRegistrationRequest,
67 aRegions[cRegions]));
68 AssertReturn(pReq, VERR_NO_MEMORY);
69
70 vmmdevInitRequest(&pReq->header, VMMDevReq_RegisterSharedModule);
71 pReq->header.size = RT_UOFFSETOF_DYN(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]);
72 pReq->GCBaseAddr = GCBaseAddr;
73 pReq->cbModule = cbModule;
74 pReq->cRegions = cRegions;
75#ifdef RT_OS_WINDOWS
76# if ARCH_BITS == 32
77 pReq->enmGuestOS = VBOXOSFAMILY_Windows32;
78# else
79 pReq->enmGuestOS = VBOXOSFAMILY_Windows64;
80# endif
81#else
82 /** @todo */
83 pReq->enmGuestOS = VBOXOSFAMILY_Unknown;
84#endif
85 for (unsigned i = 0; i < cRegions; i++)
86 pReq->aRegions[i] = pRegions[i];
87
88 if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
89 || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
90 {
91 rc = VERR_BUFFER_OVERFLOW;
92 goto end;
93 }
94
95 rc = vbglR3GRPerform(&pReq->header);
96
97end:
98 RTMemFree(pReq);
99 return rc;
100
101}
102
103/**
104 * Unregisters a shared module for the VM
105 *
106 * @returns IPRT status code.
107 * @param pszModuleName Module name
108 * @param pszVersion Module version
109 * @param GCBaseAddr Module base address
110 * @param cbModule Module size
111 */
112VBGLR3DECL(int) VbglR3UnregisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule)
113{
114 VMMDevSharedModuleUnregistrationRequest Req;
115
116 vmmdevInitRequest(&Req.header, VMMDevReq_UnregisterSharedModule);
117 Req.GCBaseAddr = GCBaseAddr;
118 Req.cbModule = cbModule;
119
120 if ( RTStrCopy(Req.szName, sizeof(Req.szName), pszModuleName) != VINF_SUCCESS
121 || RTStrCopy(Req.szVersion, sizeof(Req.szVersion), pszVersion) != VINF_SUCCESS)
122 {
123 return VERR_BUFFER_OVERFLOW;
124 }
125 return vbglR3GRPerform(&Req.header);
126}
127
128/**
129 * Checks registered modules for shared pages
130 *
131 * @returns IPRT status code.
132 */
133VBGLR3DECL(int) VbglR3CheckSharedModules()
134{
135 VMMDevSharedModuleCheckRequest Req;
136
137 vmmdevInitRequest(&Req.header, VMMDevReq_CheckSharedModules);
138 return vbglR3GRPerform(&Req.header);
139}
140
141/**
142 * Checks if page sharing is enabled.
143 *
144 * @returns true/false enabled/disabled
145 */
146VBGLR3DECL(bool) VbglR3PageSharingIsEnabled()
147{
148 VMMDevPageSharingStatusRequest Req;
149
150 vmmdevInitRequest(&Req.header, VMMDevReq_GetPageSharingStatus);
151 int rc = vbglR3GRPerform(&Req.header);
152 if (RT_SUCCESS(rc))
153 return Req.fEnabled;
154 return false;
155}
156
157/**
158 * Checks if page sharing is enabled.
159 *
160 * @returns true/false enabled/disabled
161 */
162VBGLR3DECL(int) VbglR3PageIsShared(RTGCPTR pPage, bool *pfShared, uint64_t *puPageFlags)
163{
164#ifdef DEBUG
165 VMMDevPageIsSharedRequest Req;
166
167 vmmdevInitRequest(&Req.header, VMMDevReq_DebugIsPageShared);
168 Req.GCPtrPage = pPage;
169 int rc = vbglR3GRPerform(&Req.header);
170 if (RT_SUCCESS(rc))
171 {
172 *pfShared = Req.fShared;
173 *puPageFlags = Req.uPageFlags;
174 }
175 return rc;
176#else
177 RT_NOREF3(pPage, pfShared, puPageFlags);
178 return VERR_NOT_IMPLEMENTED;
179#endif
180}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use