1 | /* $Id: VBoxGuestR0LibCrOgl.cpp 72627 2018-06-20 13:53:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestLib - Ring-3 Support Library for VirtualBox guest additions, Chromium OpenGL Service.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person
|
---|
10 | * obtaining a copy of this software and associated documentation
|
---|
11 | * files (the "Software"), to deal in the Software without
|
---|
12 | * restriction, including without limitation the rights to use,
|
---|
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | * copies of the Software, and to permit persons to whom the
|
---|
15 | * Software is furnished to do so, subject to the following
|
---|
16 | * conditions:
|
---|
17 | *
|
---|
18 | * The above copyright notice and this permission notice shall be
|
---|
19 | * included in all copies or substantial portions of the Software.
|
---|
20 | *
|
---|
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*********************************************************************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *********************************************************************************************************************************/
|
---|
35 | #include <iprt/string.h>
|
---|
36 | #include "VBoxGuestR0LibInternal.h"
|
---|
37 |
|
---|
38 | #ifdef VBGL_VBOXGUEST
|
---|
39 | # error "This file shouldn't be part of the VBoxGuestR0LibBase library that is linked into VBoxGuest. It's client code."
|
---|
40 | #endif
|
---|
41 |
|
---|
42 |
|
---|
43 | DECLR0VBGL(int) VbglR0CrCtlCreate(VBGLCRCTLHANDLE *phCtl)
|
---|
44 | {
|
---|
45 | int rc;
|
---|
46 |
|
---|
47 | if (phCtl)
|
---|
48 | {
|
---|
49 | struct VBGLHGCMHANDLEDATA *pHandleData = vbglR0HGCMHandleAlloc();
|
---|
50 | if (pHandleData)
|
---|
51 | {
|
---|
52 | rc = VbglR0IdcOpen(&pHandleData->IdcHandle,
|
---|
53 | VBGL_IOC_VERSION /*uReqVersion*/,
|
---|
54 | VBGL_IOC_VERSION & UINT32_C(0xffff0000) /*uMinVersion*/,
|
---|
55 | NULL /*puSessionVersion*/, NULL /*puDriverVersion*/, NULL /*uDriverRevision*/);
|
---|
56 | if (RT_SUCCESS(rc))
|
---|
57 | {
|
---|
58 | *phCtl = pHandleData;
|
---|
59 | return VINF_SUCCESS;
|
---|
60 | }
|
---|
61 |
|
---|
62 | vbglR0HGCMHandleFree(pHandleData);
|
---|
63 | }
|
---|
64 | else
|
---|
65 | rc = VERR_NO_MEMORY;
|
---|
66 |
|
---|
67 | *phCtl = NULL;
|
---|
68 | }
|
---|
69 | else
|
---|
70 | rc = VERR_INVALID_PARAMETER;
|
---|
71 |
|
---|
72 | return rc;
|
---|
73 | }
|
---|
74 |
|
---|
75 | DECLR0VBGL(int) VbglR0CrCtlDestroy(VBGLCRCTLHANDLE hCtl)
|
---|
76 | {
|
---|
77 | VbglR0IdcClose(&hCtl->IdcHandle);
|
---|
78 |
|
---|
79 | vbglR0HGCMHandleFree(hCtl);
|
---|
80 |
|
---|
81 | return VINF_SUCCESS;
|
---|
82 | }
|
---|
83 |
|
---|
84 | DECLR0VBGL(int) VbglR0CrCtlConConnect(VBGLCRCTLHANDLE hCtl, HGCMCLIENTID *pidClient)
|
---|
85 | {
|
---|
86 | VBGLIOCHGCMCONNECT info;
|
---|
87 | int rc;
|
---|
88 |
|
---|
89 | if (!hCtl || !pidClient)
|
---|
90 | return VERR_INVALID_PARAMETER;
|
---|
91 |
|
---|
92 | RT_ZERO(info);
|
---|
93 | VBGLREQHDR_INIT(&info.Hdr, HGCM_CONNECT);
|
---|
94 | info.u.In.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
|
---|
95 | RTStrCopy(info.u.In.Loc.u.host.achName, sizeof(info.u.In.Loc.u.host.achName), "VBoxSharedCrOpenGL");
|
---|
96 | rc = VbglR0IdcCall(&hCtl->IdcHandle, VBGL_IOCTL_HGCM_CONNECT, &info.Hdr, sizeof(info));
|
---|
97 | if (RT_SUCCESS(rc))
|
---|
98 | {
|
---|
99 | Assert(info.u.Out.idClient);
|
---|
100 | *pidClient = info.u.Out.idClient;
|
---|
101 | return rc;
|
---|
102 | }
|
---|
103 |
|
---|
104 | AssertRC(rc);
|
---|
105 | *pidClient = 0;
|
---|
106 | return rc;
|
---|
107 | }
|
---|
108 |
|
---|
109 | DECLR0VBGL(int) VbglR0CrCtlConDisconnect(VBGLCRCTLHANDLE hCtl, HGCMCLIENTID idClient)
|
---|
110 | {
|
---|
111 | VBGLIOCHGCMDISCONNECT info;
|
---|
112 | VBGLREQHDR_INIT(&info.Hdr, HGCM_DISCONNECT);
|
---|
113 | info.u.In.idClient = idClient;
|
---|
114 | return VbglR0IdcCall(&hCtl->IdcHandle, VBGL_IOCTL_HGCM_DISCONNECT, &info.Hdr, sizeof(info));
|
---|
115 | }
|
---|
116 |
|
---|
117 | DECLR0VBGL(int) VbglR0CrCtlConCallRaw(VBGLCRCTLHANDLE hCtl, PVBGLIOCHGCMCALL pCallInfo, int cbCallInfo)
|
---|
118 | {
|
---|
119 | return VbglR0IdcCallRaw(&hCtl->IdcHandle, VBGL_IOCTL_HGCM_CALL(cbCallInfo), &pCallInfo->Hdr, cbCallInfo);
|
---|
120 | }
|
---|
121 |
|
---|
122 | DECLR0VBGL(int) VbglR0CrCtlConCall(VBGLCRCTLHANDLE hCtl, PVBGLIOCHGCMCALL pCallInfo, int cbCallInfo)
|
---|
123 | {
|
---|
124 | int rc = VbglR0IdcCallRaw(&hCtl->IdcHandle, VBGL_IOCTL_HGCM_CALL(cbCallInfo), &pCallInfo->Hdr, cbCallInfo);
|
---|
125 | if (RT_SUCCESS(rc))
|
---|
126 | rc = pCallInfo->Hdr.rc;
|
---|
127 | return rc;
|
---|
128 | }
|
---|
129 |
|
---|
130 | DECLR0VBGL(int) VbglR0CrCtlConCallUserDataRaw(VBGLCRCTLHANDLE hCtl, PVBGLIOCHGCMCALL pCallInfo, int cbCallInfo)
|
---|
131 | {
|
---|
132 | return VbglR0IdcCallRaw(&hCtl->IdcHandle, VBGL_IOCTL_HGCM_CALL_WITH_USER_DATA(cbCallInfo), &pCallInfo->Hdr, cbCallInfo);
|
---|
133 | }
|
---|
134 |
|
---|