VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibHostChannel.cpp

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
RevLine 
[43346]1/* $Id: VBoxGuestR3LibHostChannel.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Host Channel.
4 */
5
6/*
[98103]7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
[43346]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
[43346]11 *
[96407]12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
[43346]25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
[96407]27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
[43346]29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
[96407]33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
[43346]35 */
36
[48938]37
[43346]38#include <iprt/mem.h>
39
40#include <VBox/HostServices/VBoxHostChannel.h>
41
[68650]42#include "VBoxGuestR3LibInternal.h"
[43346]43
44
[68550]45VBGLR3DECL(int) VbglR3HostChannelInit(uint32_t *pidClient)
[43346]46{
[68550]47 return VbglR3HGCMConnect("VBoxHostChannel", pidClient);
[43346]48}
49
[68550]50VBGLR3DECL(void) VbglR3HostChannelTerm(uint32_t idClient)
[43346]51{
[68550]52 VbglR3HGCMDisconnect(idClient);
[43346]53}
54
55VBGLR3DECL(int) VbglR3HostChannelAttach(uint32_t *pu32ChannelHandle,
56 uint32_t u32HGCMClientId,
57 const char *pszName,
58 uint32_t u32Flags)
59{
60 /* Make a heap copy of the name, because HGCM can not use some of other memory types. */
61 size_t cbName = strlen(pszName) + 1;
62 char *pszCopy = (char *)RTMemAlloc(cbName);
63 if (pszCopy == NULL)
64 {
65 return VERR_NO_MEMORY;
66 }
67
68 memcpy(pszCopy, pszName, cbName);
69
70 VBoxHostChannelAttach parms;
[68458]71 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_ATTACH, 3);
[43346]72 VbglHGCMParmPtrSet(&parms.name, pszCopy, (uint32_t)cbName);
73 VbglHGCMParmUInt32Set(&parms.flags, u32Flags);
74 VbglHGCMParmUInt32Set(&parms.handle, 0);
75
[68465]76 int rc = VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43346]77
78 if (RT_SUCCESS(rc))
[68465]79 *pu32ChannelHandle = parms.handle.u.value32;
[43346]80
81 RTMemFree(pszCopy);
82
83 return rc;
84}
85
86VBGLR3DECL(void) VbglR3HostChannelDetach(uint32_t u32ChannelHandle,
87 uint32_t u32HGCMClientId)
88{
89 VBoxHostChannelDetach parms;
[68458]90 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_DETACH, 1);
[43346]91 VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
92
[68465]93 VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43346]94}
95
96VBGLR3DECL(int) VbglR3HostChannelSend(uint32_t u32ChannelHandle,
97 uint32_t u32HGCMClientId,
98 void *pvData,
99 uint32_t cbData)
100{
101 VBoxHostChannelSend parms;
[68458]102 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_SEND, 2);
[43346]103 VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
104 VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
105
[68465]106 return VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43346]107}
108
109VBGLR3DECL(int) VbglR3HostChannelRecv(uint32_t u32ChannelHandle,
110 uint32_t u32HGCMClientId,
111 void *pvData,
112 uint32_t cbData,
113 uint32_t *pu32SizeReceived,
114 uint32_t *pu32SizeRemaining)
115{
116 VBoxHostChannelRecv parms;
[68458]117 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_RECV, 4);
[43346]118 VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
119 VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
120 VbglHGCMParmUInt32Set(&parms.sizeReceived, 0);
121 VbglHGCMParmUInt32Set(&parms.sizeRemaining, 0);
122
[68465]123 int rc = VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43346]124
125 if (RT_SUCCESS(rc))
126 {
[68465]127 *pu32SizeReceived = parms.sizeReceived.u.value32;
128 *pu32SizeRemaining = parms.sizeRemaining.u.value32;
[43346]129 }
130
131 return rc;
132}
133
134VBGLR3DECL(int) VbglR3HostChannelControl(uint32_t u32ChannelHandle,
135 uint32_t u32HGCMClientId,
136 uint32_t u32Code,
137 void *pvParm,
138 uint32_t cbParm,
139 void *pvData,
140 uint32_t cbData,
141 uint32_t *pu32SizeDataReturned)
142{
143 VBoxHostChannelControl parms;
[68458]144 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_CONTROL, 5);
[43346]145 VbglHGCMParmUInt32Set(&parms.handle, u32ChannelHandle);
146 VbglHGCMParmUInt32Set(&parms.code, u32Code);
147 VbglHGCMParmPtrSet(&parms.parm, pvParm, cbParm);
148 VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
149 VbglHGCMParmUInt32Set(&parms.sizeDataReturned, 0);
150
[68465]151 int rc = VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43346]152
153 if (RT_SUCCESS(rc))
154 {
[68465]155 *pu32SizeDataReturned = parms.sizeDataReturned.u.value32;
[43346]156 }
157
158 return rc;
159}
160
161VBGLR3DECL(int) VbglR3HostChannelEventWait(uint32_t *pu32ChannelHandle,
162 uint32_t u32HGCMClientId,
163 uint32_t *pu32EventId,
164 void *pvParm,
165 uint32_t cbParm,
166 uint32_t *pu32SizeReturned)
167{
168 VBoxHostChannelEventWait parms;
[68458]169 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_EVENT_WAIT, 4);
[43346]170 VbglHGCMParmUInt32Set(&parms.handle, 0);
171 VbglHGCMParmUInt32Set(&parms.id, 0);
172 VbglHGCMParmPtrSet(&parms.parm, pvParm, cbParm);
173 VbglHGCMParmUInt32Set(&parms.sizeReturned, 0);
174
[68465]175 int rc = VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43346]176
177 if (RT_SUCCESS(rc))
178 {
[68465]179 *pu32ChannelHandle = parms.handle.u.value32;
180 *pu32EventId = parms.id.u.value32;
181 *pu32SizeReturned = parms.sizeReturned.u.value32;
[43346]182 }
183
184 return rc;
185}
186
187VBGLR3DECL(int) VbglR3HostChannelEventCancel(uint32_t u32ChannelHandle,
188 uint32_t u32HGCMClientId)
189{
[62842]190 RT_NOREF1(u32ChannelHandle);
[43346]191
[68458]192 VBoxHostChannelEventCancel parms;
193 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_EVENT_CANCEL, 0);
[43346]194
[68465]195 return VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43346]196}
[43462]197
198VBGLR3DECL(int) VbglR3HostChannelQuery(const char *pszName,
199 uint32_t u32HGCMClientId,
200 uint32_t u32Code,
201 void *pvParm,
202 uint32_t cbParm,
203 void *pvData,
204 uint32_t cbData,
205 uint32_t *pu32SizeDataReturned)
206{
207 /* Make a heap copy of the name, because HGCM can not use some of other memory types. */
208 size_t cbName = strlen(pszName) + 1;
209 char *pszCopy = (char *)RTMemAlloc(cbName);
210 if (pszCopy == NULL)
211 {
212 return VERR_NO_MEMORY;
213 }
214
215 memcpy(pszCopy, pszName, cbName);
216
217 VBoxHostChannelQuery parms;
[68458]218 VBGL_HGCM_HDR_INIT(&parms.hdr, u32HGCMClientId, VBOX_HOST_CHANNEL_FN_QUERY, 5);
[43462]219 VbglHGCMParmPtrSet(&parms.name, pszCopy, (uint32_t)cbName);
220 VbglHGCMParmUInt32Set(&parms.code, u32Code);
221 VbglHGCMParmPtrSet(&parms.parm, pvParm, cbParm);
222 VbglHGCMParmPtrSet(&parms.data, pvData, cbData);
223 VbglHGCMParmUInt32Set(&parms.sizeDataReturned, 0);
224
[68465]225 int rc = VbglR3HGCMCall(&parms.hdr, sizeof(parms));
[43462]226
227 if (RT_SUCCESS(rc))
228 {
[68465]229 *pu32SizeDataReturned = parms.sizeDataReturned.u.value32;
[43462]230 }
231
232 RTMemFree(pszCopy);
233
234 return rc;
235}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use