1 | /* $Id: VBoxGuestR3LibModule.cpp 28800 2010-04-27 08:22:32Z 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 | */
|
---|
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->GCBaseAddr = GCBaseAddr;
|
---|
61 | pReq->cbModule = cbModule;
|
---|
62 | pReq->cRegions = cRegions;
|
---|
63 | for (unsigned i = 0; i < cRegions; i++)
|
---|
64 | pReq->aRegions[i] = pRegions[i];
|
---|
65 |
|
---|
66 | if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
|
---|
67 | || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
|
---|
68 | {
|
---|
69 | rc = VERR_BUFFER_OVERFLOW;
|
---|
70 | goto end;
|
---|
71 | }
|
---|
72 |
|
---|
73 | rc = vbglR3GRPerform(&pReq->header);
|
---|
74 |
|
---|
75 | end:
|
---|
76 | RTMemFree(pReq);
|
---|
77 | return rc;
|
---|
78 |
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Unregisters a shared module for the VM
|
---|
83 | *
|
---|
84 | * @returns IPRT status code.
|
---|
85 | * @param pszModuleName Module name
|
---|
86 | * @param pszVersion Module version
|
---|
87 | * @param GCBaseAddr Module base address
|
---|
88 | * @param cbModule Module size
|
---|
89 | */
|
---|
90 | VBGLR3DECL(int) VbglR3UnregisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule)
|
---|
91 | {
|
---|
92 | VMMDevSharedModuleUnregistrationRequest Req;
|
---|
93 |
|
---|
94 | vmmdevInitRequest(&Req.header, VMMDevReq_UnregisterSharedModule);
|
---|
95 | Req.GCBaseAddr = GCBaseAddr;
|
---|
96 | Req.cbModule = cbModule;
|
---|
97 |
|
---|
98 | if ( RTStrCopy(Req.szName, sizeof(Req.szName), pszModuleName) != VINF_SUCCESS
|
---|
99 | || RTStrCopy(Req.szVersion, sizeof(Req.szVersion), pszVersion) != VINF_SUCCESS)
|
---|
100 | {
|
---|
101 | return VERR_BUFFER_OVERFLOW;
|
---|
102 | }
|
---|
103 | return vbglR3GRPerform(&Req.header);
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Checks regsitered modules for shared pages
|
---|
108 | *
|
---|
109 | * @returns IPRT status code.
|
---|
110 | */
|
---|
111 | VBGLR3DECL(int) VbglR3CheckSharedModules()
|
---|
112 | {
|
---|
113 | VMMDevSharedModuleCheckRequest Req;
|
---|
114 |
|
---|
115 | vmmdevInitRequest(&Req.header, VMMDevReq_CheckSharedModules);
|
---|
116 | return vbglR3GRPerform(&Req.header);
|
---|
117 | }
|
---|
118 |
|
---|