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