1 | /* $Id: VBoxGuestR3LibModule.cpp 28434 2010-04-17 18:08:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Shared modules.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2010 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #include "VBGLR3Internal.h"
|
---|
36 | #include <iprt/mem.h>
|
---|
37 | #include <iprt/string.h>
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Registers a new shared module for the VM
|
---|
41 | *
|
---|
42 | * @returns IPRT status code.
|
---|
43 | * @param pszModuleName Module name
|
---|
44 | * @param pszVersion Module version
|
---|
45 | * @param GCBaseAddr Module base address
|
---|
46 | * @param cbModule Module size
|
---|
47 | * @param cRegions Number of shared region descriptors
|
---|
48 | * @param pRegions Shared region(s)
|
---|
49 | */
|
---|
50 | VBGLR3DECL(int) VbglR3RegisterSharedModule(char *pszModuleName, char *pszVersion,
|
---|
51 | RTGCPTR64 GCBaseAddr, uint32_t cbModule,
|
---|
52 | unsigned cRegions, VMMDEVSHAREDREGIONDESC *pRegions)
|
---|
53 | {
|
---|
54 | VMMDevSharedModuleRegistrationRequest *pReq;
|
---|
55 | int rc;
|
---|
56 |
|
---|
57 | /* Sanity check. */
|
---|
58 | AssertReturn(cRegions < VMMDEVSHAREDREGIONDESC_MAX, VERR_INVALID_PARAMETER);
|
---|
59 |
|
---|
60 | pReq = (VMMDevSharedModuleRegistrationRequest *)RTMemAllocZ(RT_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]));
|
---|
61 | AssertReturn(pReq, VERR_NO_MEMORY);
|
---|
62 |
|
---|
63 | vmmdevInitRequest(&pReq->header, VMMDevReq_RegisterSharedModule);
|
---|
64 | pReq->GCBaseAddr = GCBaseAddr;
|
---|
65 | pReq->cbModule = cbModule;
|
---|
66 | pReq->cRegions = cRegions;
|
---|
67 | for (unsigned i = 0; i < cRegions; i++)
|
---|
68 | pReq->aRegions[i] = pRegions[i];
|
---|
69 |
|
---|
70 | if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
|
---|
71 | || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
|
---|
72 | {
|
---|
73 | rc = VERR_BUFFER_OVERFLOW;
|
---|
74 | goto end;
|
---|
75 | }
|
---|
76 |
|
---|
77 | rc = vbglR3GRPerform(&pReq->header);
|
---|
78 |
|
---|
79 | end:
|
---|
80 | RTMemFree(pReq);
|
---|
81 | return rc;
|
---|
82 |
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Unregisters a shared module for the VM
|
---|
87 | *
|
---|
88 | * @returns IPRT status code.
|
---|
89 | * @param pszModuleName Module name
|
---|
90 | * @param pszVersion Module version
|
---|
91 | * @param GCBaseAddr Module base address
|
---|
92 | * @param cbModule Module size
|
---|
93 | */
|
---|
94 | VBGLR3DECL(int) VbglR3UnregisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule)
|
---|
95 | {
|
---|
96 | VMMDevSharedModuleUnregistrationRequest Req;
|
---|
97 |
|
---|
98 | vmmdevInitRequest(&Req.header, VMMDevReq_UnregisterSharedModule);
|
---|
99 | Req.GCBaseAddr = GCBaseAddr;
|
---|
100 | Req.cbModule = cbModule;
|
---|
101 |
|
---|
102 | if ( RTStrCopy(Req.szName, sizeof(Req.szName), pszModuleName) != VINF_SUCCESS
|
---|
103 | || RTStrCopy(Req.szVersion, sizeof(Req.szVersion), pszVersion) != VINF_SUCCESS)
|
---|
104 | {
|
---|
105 | return VERR_BUFFER_OVERFLOW;
|
---|
106 | }
|
---|
107 | return vbglR3GRPerform(&Req.header);
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Checks regsitered modules for shared pages
|
---|
112 | *
|
---|
113 | * @returns IPRT status code.
|
---|
114 | */
|
---|
115 | VBGLR3DECL(int) VbglR3CheckSharedModules()
|
---|
116 | {
|
---|
117 | VMMDevSharedModuleCheckRequest Req;
|
---|
118 |
|
---|
119 | vmmdevInitRequest(&Req.header, VMMDevReq_CheckSharedModules);
|
---|
120 | return vbglR3GRPerform(&Req.header);
|
---|
121 | }
|
---|
122 |
|
---|