VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 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: 4.1 KB
Line 
1/* $Id: VBoxGuestR3LibHGCM.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions,
4 * generic HGCM.
5 */
6
7/*
8 * Copyright (C) 2015-2023 Oracle and/or its affiliates.
9 *
10 * This file is part of VirtualBox base platform packages, as
11 * available from https://www.virtualbox.org.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation, in version 3 of the
16 * License.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <https://www.gnu.org/licenses>.
25 *
26 * The contents of this file may alternatively be used under the terms
27 * of the Common Development and Distribution License Version 1.0
28 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
29 * in the VirtualBox distribution, in which case the provisions of the
30 * CDDL are applicable instead of those of the GPL.
31 *
32 * You may elect to license modified versions of this file under the
33 * terms and conditions of either the GPL or the CDDL or both.
34 *
35 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 */
37
38
39/*********************************************************************************************************************************
40* Header Files *
41*********************************************************************************************************************************/
42#include "VBoxGuestR3LibInternal.h"
43#include <VBox/VBoxGuestLib.h>
44#include <iprt/string.h>
45
46
47/**
48 * Connects to an HGCM service.
49 *
50 * @returns VBox status code
51 * @param pszServiceName Name of the host service.
52 * @param pidClient Where to put the client ID on success. The client ID
53 * must be passed to all the other calls to the service.
54 */
55VBGLR3DECL(int) VbglR3HGCMConnect(const char *pszServiceName, HGCMCLIENTID *pidClient)
56{
57 AssertPtrReturn(pszServiceName, VERR_INVALID_POINTER);
58 AssertPtrReturn(pidClient, VERR_INVALID_POINTER);
59
60 VBGLIOCHGCMCONNECT Info;
61 RT_ZERO(Info);
62 VBGLREQHDR_INIT(&Info.Hdr, HGCM_CONNECT);
63 Info.u.In.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
64 int rc = RTStrCopy(Info.u.In.Loc.u.host.achName, sizeof(Info.u.In.Loc.u.host.achName), pszServiceName);
65 if (RT_FAILURE(rc))
66 return rc;
67 rc = vbglR3DoIOCtl(VBGL_IOCTL_HGCM_CONNECT, &Info.Hdr, sizeof(Info));
68 if (RT_SUCCESS(rc))
69 *pidClient = Info.u.Out.idClient;
70 return rc;
71}
72
73
74/**
75 * Disconnect from an HGCM service.
76 *
77 * @returns VBox status code.
78 * @param idClient The client id returned by VbglR3HGCMConnect().
79 */
80VBGLR3DECL(int) VbglR3HGCMDisconnect(HGCMCLIENTID idClient)
81{
82 VBGLIOCHGCMDISCONNECT Info;
83 VBGLREQHDR_INIT(&Info.Hdr, HGCM_DISCONNECT);
84 Info.u.In.idClient = idClient;
85
86 return vbglR3DoIOCtl(VBGL_IOCTL_HGCM_DISCONNECT, &Info.Hdr, sizeof(Info));
87}
88
89
90/**
91 * Makes a fully prepared HGCM call.
92 *
93 * @returns VBox status code.
94 * @param pInfo Fully prepared HGCM call info.
95 * @param cbInfo Size of the info. This may sometimes be larger than
96 * what the parameter count indicates because of
97 * parameter changes between versions and such.
98 */
99VBGLR3DECL(int) VbglR3HGCMCall(PVBGLIOCHGCMCALL pInfo, size_t cbInfo)
100{
101 /* Expect caller to have filled in pInfo. */
102 AssertMsg(pInfo->Hdr.cbIn == cbInfo, ("cbIn=%#x cbInfo=%#zx\n", pInfo->Hdr.cbIn, cbInfo));
103 AssertMsg(pInfo->Hdr.cbOut == cbInfo, ("cbOut=%#x cbInfo=%#zx\n", pInfo->Hdr.cbOut, cbInfo));
104 Assert(sizeof(*pInfo) + pInfo->cParms * sizeof(HGCMFunctionParameter) <= cbInfo);
105 Assert(pInfo->u32ClientID != 0);
106
107 return vbglR3DoIOCtl(VBGL_IOCTL_HGCM_CALL(cbInfo), &pInfo->Hdr, cbInfo);
108}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use