VirtualBox

source: vbox/trunk/src/VBox/VMM/PGMSharedPage.cpp@ 29561

Last change on this file since 29561 was 29468, checked in by vboxsync, 15 years ago

Split up

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: PGMSharedPage.cpp 29468 2010-05-14 12:16:44Z vboxsync $ */
2/** @file
3 * PGM - Page Manager and Monitor, Shared page handling
4 */
5
6/*
7 * Copyright (C) 2006-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
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_PGM_SHARED
23#include <VBox/pgm.h>
24#include <VBox/stam.h>
25#include "PGMInternal.h"
26#include "PGMInline.h"
27#include <VBox/vm.h>
28#include <VBox/sup.h>
29#include <VBox/param.h>
30#include <VBox/err.h>
31#include <VBox/log.h>
32#include <iprt/assert.h>
33#include <iprt/asm.h>
34#include <iprt/string.h>
35#include <iprt/mem.h>
36
37
38/**
39 * Registers a new shared module for the VM
40 *
41 * @returns VBox status code.
42 * @param pVM VM handle
43 * @param enmGuestOS Guest OS type
44 * @param pszModuleName Module name
45 * @param pszVersion Module version
46 * @param GCBaseAddr Module base address
47 * @param cbModule Module size
48 * @param cRegions Number of shared region descriptors
49 * @param pRegions Shared region(s)
50 */
51VMMR3DECL(int) PGMR3SharedModuleRegister(PVM pVM, VBOXOSFAMILY enmGuestOS, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule,
52 unsigned cRegions, VMMDEVSHAREDREGIONDESC *pRegions)
53{
54#ifdef VBOX_WITH_PAGE_SHARING
55 PGMMREGISTERSHAREDMODULEREQ pReq;
56
57 Log(("PGMR3SharedModuleRegister family=%d name=%s version=%s base=%RGv size=%x cRegions=%d\n", enmGuestOS, pszModuleName, pszVersion, GCBaseAddr, cbModule, cRegions));
58
59 /* Sanity check. */
60 AssertReturn(cRegions < VMMDEVSHAREDREGIONDESC_MAX, VERR_INVALID_PARAMETER);
61
62 pReq = (PGMMREGISTERSHAREDMODULEREQ)RTMemAllocZ(RT_OFFSETOF(GMMREGISTERSHAREDMODULEREQ, aRegions[cRegions]));
63 AssertReturn(pReq, VERR_NO_MEMORY);
64
65 pReq->enmGuestOS = enmGuestOS;
66 pReq->GCBaseAddr = GCBaseAddr;
67 pReq->cbModule = cbModule;
68 pReq->cRegions = cRegions;
69 for (unsigned i = 0; i < cRegions; i++)
70 pReq->aRegions[i] = pRegions[i];
71
72 if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
73 || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
74 {
75 RTMemFree(pReq);
76 return VERR_BUFFER_OVERFLOW;
77 }
78
79 int rc = GMMR3RegisterSharedModule(pVM, pReq);
80 RTMemFree(pReq);
81 Assert(rc == VINF_SUCCESS || rc == VINF_PGM_SHARED_MODULE_COLLISION || rc == VINF_PGM_SHARED_MODULE_ALREADY_REGISTERED);
82 if (RT_FAILURE(rc))
83 return rc;
84 return VINF_SUCCESS;
85#else
86 return VERR_NOT_IMPLEMENTED;
87#endif
88}
89
90/**
91 * Unregisters a shared module for the VM
92 *
93 * @returns VBox status code.
94 * @param pVM VM handle
95 * @param pszModuleName Module name
96 * @param pszVersion Module version
97 * @param GCBaseAddr Module base address
98 * @param cbModule Module size
99 */
100VMMR3DECL(int) PGMR3SharedModuleUnregister(PVM pVM, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule)
101{
102#ifdef VBOX_WITH_PAGE_SHARING
103 PGMMUNREGISTERSHAREDMODULEREQ pReq;
104
105 Log(("PGMR3SharedModuleUnregister name=%s version=%s base=%RGv size=%x\n", pszModuleName, pszVersion, GCBaseAddr, cbModule));
106
107 pReq = (PGMMUNREGISTERSHAREDMODULEREQ)RTMemAllocZ(sizeof(*pReq));
108 AssertReturn(pReq, VERR_NO_MEMORY);
109
110 pReq->GCBaseAddr = GCBaseAddr;
111 pReq->cbModule = cbModule;
112
113 if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
114 || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
115 {
116 RTMemFree(pReq);
117 return VERR_BUFFER_OVERFLOW;
118 }
119 int rc = GMMR3UnregisterSharedModule(pVM, pReq);
120 RTMemFree(pReq);
121 return rc;
122#else
123 return VERR_NOT_IMPLEMENTED;
124#endif
125}
126
127#ifdef VBOX_WITH_PAGE_SHARING
128/**
129 * Rendezvous callback that will be called once.
130 *
131 * @returns VBox strict status code.
132 * @param pVM VM handle.
133 * @param pVCpu The VMCPU handle for the calling EMT.
134 * @param pvUser Not used;
135 */
136static DECLCALLBACK(VBOXSTRICTRC) pgmR3SharedModuleRegRendezvous(PVM pVM, PVMCPU pVCpu, void *pvUser)
137{
138 return GMMR3CheckSharedModules(pVM);
139}
140
141/**
142 * Shared module check helper (called on the way out).
143 *
144 * @param pVM The VM handle.
145 */
146static DECLCALLBACK(void) pgmR3CheckSharedModulesHelper(PVM pVM)
147{
148 /* We must stall other VCPUs as we'd otherwise have to send IPI flush commands for every single change we make. */
149 int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, pgmR3SharedModuleRegRendezvous, NULL);
150 AssertRC(rc);
151}
152#endif
153
154/**
155 * Check all registered modules for changes.
156 *
157 * @returns VBox status code.
158 * @param pVM VM handle
159 */
160VMMR3DECL(int) PGMR3SharedModuleCheckAll(PVM pVM)
161{
162#ifdef VBOX_WITH_PAGE_SHARING
163 /* Queue the actual registration as we are under the IOM lock right now. Perform this operation on the way out. */
164 return VMR3ReqCallNoWait(pVM, VMMGetCpuId(pVM), (PFNRT)pgmR3CheckSharedModulesHelper, 1, pVM);
165#else
166 return VERR_NOT_IMPLEMENTED;
167#endif
168}
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