VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibModule.cpp@ 29365

Last change on this file since 29365 was 29307, checked in by vboxsync, 15 years ago

Shared paging interface updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: VBoxGuestR3LibModule.cpp 29307 2010-05-10 15:18:22Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Shared modules.
4 */
5
6/*
7 * Copyright (C) 2007-2010 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 "VBGLR3Internal.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_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]));
57 AssertReturn(pReq, VERR_NO_MEMORY);
58
59 vmmdevInitRequest(&pReq->header, VMMDevReq_RegisterSharedModule);
60 pReq->GCBaseAddr = GCBaseAddr;
61 pReq->cbModule = cbModule;
62 pReq->cRegions = cRegions;
63#ifdef RT_OS_WINDOWS
64# if ARCH_BITS == 32
65 pReq->enmGuestOS = VBOXOSFAMILY_Windows32;
66# else
67 pReq->enmGuestOS = VBOXOSFAMILY_Windows64;
68# endif
69#else
70 /** todo */
71 pReq->enmGuestOS = VBOXOSFAMILY_unknown;
72#endif
73 for (unsigned i = 0; i < cRegions; i++)
74 pReq->aRegions[i] = pRegions[i];
75
76 if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
77 || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
78 {
79 rc = VERR_BUFFER_OVERFLOW;
80 goto end;
81 }
82
83 rc = vbglR3GRPerform(&pReq->header);
84
85end:
86 RTMemFree(pReq);
87 return rc;
88
89}
90
91/**
92 * Unregisters a shared module for the VM
93 *
94 * @returns IPRT status code.
95 * @param pszModuleName Module name
96 * @param pszVersion Module version
97 * @param GCBaseAddr Module base address
98 * @param cbModule Module size
99 */
100VBGLR3DECL(int) VbglR3UnregisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule)
101{
102 VMMDevSharedModuleUnregistrationRequest Req;
103
104 vmmdevInitRequest(&Req.header, VMMDevReq_UnregisterSharedModule);
105 Req.GCBaseAddr = GCBaseAddr;
106 Req.cbModule = cbModule;
107
108 if ( RTStrCopy(Req.szName, sizeof(Req.szName), pszModuleName) != VINF_SUCCESS
109 || RTStrCopy(Req.szVersion, sizeof(Req.szVersion), pszVersion) != VINF_SUCCESS)
110 {
111 return VERR_BUFFER_OVERFLOW;
112 }
113 return vbglR3GRPerform(&Req.header);
114}
115
116/**
117 * Checks registered modules for shared pages
118 *
119 * @returns IPRT status code.
120 */
121VBGLR3DECL(int) VbglR3CheckSharedModules()
122{
123 VMMDevSharedModuleCheckRequest Req;
124
125 vmmdevInitRequest(&Req.header, VMMDevReq_CheckSharedModules);
126 return vbglR3GRPerform(&Req.header);
127}
128
129/**
130 * Checks if page sharing is enabled.
131 *
132 * @returns true/false enabled/disabled
133 */
134VBGLR3DECL(bool) VbglR3PageSharingIsEnabled()
135{
136 VMMDevPageSharingStatusRequest Req;
137
138 vmmdevInitRequest(&Req.header, VMMDevReq_GetPageSharingStatus);
139 int rc = vbglR3GRPerform(&Req.header);
140 if (RT_SUCCESS(rc))
141 return Req.fEnabled;
142 return false;
143}
144
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette