VirtualBox

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

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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