1 | /* $Id: VBoxGuestR3LibModule.cpp 69500 2017-10-28 15:14:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Shared modules.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2017 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 | */
|
---|
46 | VBGLR3DECL(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_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]));
|
---|
57 | AssertReturn(pReq, VERR_NO_MEMORY);
|
---|
58 |
|
---|
59 | vmmdevInitRequest(&pReq->header, VMMDevReq_RegisterSharedModule);
|
---|
60 | pReq->header.size = RT_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]);
|
---|
61 | pReq->GCBaseAddr = GCBaseAddr;
|
---|
62 | pReq->cbModule = cbModule;
|
---|
63 | pReq->cRegions = cRegions;
|
---|
64 | #ifdef RT_OS_WINDOWS
|
---|
65 | # if ARCH_BITS == 32
|
---|
66 | pReq->enmGuestOS = VBOXOSFAMILY_Windows32;
|
---|
67 | # else
|
---|
68 | pReq->enmGuestOS = VBOXOSFAMILY_Windows64;
|
---|
69 | # endif
|
---|
70 | #else
|
---|
71 | /** @todo */
|
---|
72 | pReq->enmGuestOS = VBOXOSFAMILY_Unknown;
|
---|
73 | #endif
|
---|
74 | for (unsigned i = 0; i < cRegions; i++)
|
---|
75 | pReq->aRegions[i] = pRegions[i];
|
---|
76 |
|
---|
77 | if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
|
---|
78 | || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
|
---|
79 | {
|
---|
80 | rc = VERR_BUFFER_OVERFLOW;
|
---|
81 | goto end;
|
---|
82 | }
|
---|
83 |
|
---|
84 | rc = vbglR3GRPerform(&pReq->header);
|
---|
85 |
|
---|
86 | end:
|
---|
87 | RTMemFree(pReq);
|
---|
88 | return rc;
|
---|
89 |
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Unregisters a shared module for the VM
|
---|
94 | *
|
---|
95 | * @returns IPRT status code.
|
---|
96 | * @param pszModuleName Module name
|
---|
97 | * @param pszVersion Module version
|
---|
98 | * @param GCBaseAddr Module base address
|
---|
99 | * @param cbModule Module size
|
---|
100 | */
|
---|
101 | VBGLR3DECL(int) VbglR3UnregisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule)
|
---|
102 | {
|
---|
103 | VMMDevSharedModuleUnregistrationRequest Req;
|
---|
104 |
|
---|
105 | vmmdevInitRequest(&Req.header, VMMDevReq_UnregisterSharedModule);
|
---|
106 | Req.GCBaseAddr = GCBaseAddr;
|
---|
107 | Req.cbModule = cbModule;
|
---|
108 |
|
---|
109 | if ( RTStrCopy(Req.szName, sizeof(Req.szName), pszModuleName) != VINF_SUCCESS
|
---|
110 | || RTStrCopy(Req.szVersion, sizeof(Req.szVersion), pszVersion) != VINF_SUCCESS)
|
---|
111 | {
|
---|
112 | return VERR_BUFFER_OVERFLOW;
|
---|
113 | }
|
---|
114 | return vbglR3GRPerform(&Req.header);
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Checks registered modules for shared pages
|
---|
119 | *
|
---|
120 | * @returns IPRT status code.
|
---|
121 | */
|
---|
122 | VBGLR3DECL(int) VbglR3CheckSharedModules()
|
---|
123 | {
|
---|
124 | VMMDevSharedModuleCheckRequest Req;
|
---|
125 |
|
---|
126 | vmmdevInitRequest(&Req.header, VMMDevReq_CheckSharedModules);
|
---|
127 | return vbglR3GRPerform(&Req.header);
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Checks if page sharing is enabled.
|
---|
132 | *
|
---|
133 | * @returns true/false enabled/disabled
|
---|
134 | */
|
---|
135 | VBGLR3DECL(bool) VbglR3PageSharingIsEnabled()
|
---|
136 | {
|
---|
137 | VMMDevPageSharingStatusRequest Req;
|
---|
138 |
|
---|
139 | vmmdevInitRequest(&Req.header, VMMDevReq_GetPageSharingStatus);
|
---|
140 | int rc = vbglR3GRPerform(&Req.header);
|
---|
141 | if (RT_SUCCESS(rc))
|
---|
142 | return Req.fEnabled;
|
---|
143 | return false;
|
---|
144 | }
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Checks if page sharing is enabled.
|
---|
148 | *
|
---|
149 | * @returns true/false enabled/disabled
|
---|
150 | */
|
---|
151 | VBGLR3DECL(int) VbglR3PageIsShared(RTGCPTR pPage, bool *pfShared, uint64_t *puPageFlags)
|
---|
152 | {
|
---|
153 | #ifdef DEBUG
|
---|
154 | VMMDevPageIsSharedRequest Req;
|
---|
155 |
|
---|
156 | vmmdevInitRequest(&Req.header, VMMDevReq_DebugIsPageShared);
|
---|
157 | Req.GCPtrPage = pPage;
|
---|
158 | int rc = vbglR3GRPerform(&Req.header);
|
---|
159 | if (RT_SUCCESS(rc))
|
---|
160 | {
|
---|
161 | *pfShared = Req.fShared;
|
---|
162 | *puPageFlags = Req.uPageFlags;
|
---|
163 | }
|
---|
164 | return rc;
|
---|
165 | #else
|
---|
166 | RT_NOREF3(pPage, pfShared, puPageFlags);
|
---|
167 | return VERR_NOT_IMPLEMENTED;
|
---|
168 | #endif
|
---|
169 | }
|
---|