VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuestIDC-unix.c.h@ 58089

Last change on this file since 58089 was 58089, checked in by vboxsync, 9 years ago

VBoxGuest,VBoxService,Doxyfile.Core: fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Rev: 58089 $ */
2/** @file
3 * VBoxGuest - Inter Driver Communication, unix implementation.
4 *
5 * This file is included by the platform specific source file.
6 */
7
8/*
9 * Copyright (C) 2006-2015 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * The contents of this file may alternatively be used under the terms
20 * of the Common Development and Distribution License Version 1.0
21 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
22 * VirtualBox OSE distribution, in which case the provisions of the
23 * CDDL are applicable instead of those of the GPL.
24 *
25 * You may elect to license modified versions of this file under the
26 * terms and conditions of either the GPL or the CDDL or both.
27 */
28
29
30/** @todo Use some header that we have in common with VBoxGuestLib.h... */
31/** @todo fix DECLVBGL usage. */
32RT_C_DECLS_BEGIN
33DECLEXPORT(void *) VBOXCALL VBoxGuestIDCOpen(uint32_t *pu32Version);
34DECLEXPORT(int) VBOXCALL VBoxGuestIDCClose(void *pvSession);
35DECLEXPORT(int) VBOXCALL VBoxGuestIDCCall(void *pvSession, unsigned iCmd, void *pvData, size_t cbData, size_t *pcbDataReturned);
36RT_C_DECLS_END
37
38
39/**
40 * Open a new IDC connection.
41 *
42 * @returns Opaque pointer to session object.
43 * @param pu32Version Where to store VMMDev version.
44 */
45DECLEXPORT(void *) VBOXCALL VBoxGuestIDCOpen(uint32_t *pu32Version)
46{
47 PVBOXGUESTSESSION pSession;
48 int rc;
49 LogFlow(("VBoxGuestIDCOpen: Version=%#x\n", pu32Version ? *pu32Version : 0));
50
51 AssertPtrReturn(pu32Version, NULL);
52
53#ifdef RT_OS_SOLARIS
54 mutex_enter(&g_LdiMtx);
55 if (!g_LdiHandle)
56 {
57 ldi_ident_t DevIdent = ldi_ident_from_anon();
58 rc = ldi_open_by_name(VBOXGUEST_DEVICE_NAME, FREAD, kcred, &g_LdiHandle, DevIdent);
59 ldi_ident_release(DevIdent);
60 if (rc)
61 {
62 LogRel(("VBoxGuestIDCOpen: ldi_open_by_name failed. rc=%d\n", rc));
63 mutex_exit(&g_LdiMtx);
64 return NULL;
65 }
66 }
67 ++g_cLdiOpens;
68 mutex_exit(&g_LdiMtx);
69#endif
70
71 rc = VGDrvCommonCreateKernelSession(&g_DevExt, &pSession);
72 if (RT_SUCCESS(rc))
73 {
74 *pu32Version = VMMDEV_VERSION;
75 return pSession;
76 }
77
78#ifdef RT_OS_SOLARIS
79 mutex_enter(&g_LdiMtx);
80 if (g_cLdiOpens > 0)
81 --g_cLdiOpens;
82 if ( g_cLdiOpens == 0
83 && g_LdiHandle)
84 {
85 ldi_close(g_LdiHandle, FREAD, kcred);
86 g_LdiHandle = NULL;
87 }
88 mutex_exit(&g_LdiMtx);
89#endif
90
91 LogRel(("VBoxGuestIDCOpen: VbgdCommonCreateKernelSession failed. rc=%d\n", rc));
92 return NULL;
93}
94
95
96/**
97 * Close an IDC connection.
98 *
99 * @returns VBox error code.
100 * @param pvSession Opaque pointer to the session object.
101 */
102DECLEXPORT(int) VBOXCALL VBoxGuestIDCClose(void *pvSession)
103{
104 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pvSession;
105 LogFlow(("VBoxGuestIDCClose:\n"));
106
107 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
108 VGDrvCommonCloseSession(&g_DevExt, pSession);
109
110#ifdef RT_OS_SOLARIS
111 mutex_enter(&g_LdiMtx);
112 if (g_cLdiOpens > 0)
113 --g_cLdiOpens;
114 if ( g_cLdiOpens == 0
115 && g_LdiHandle)
116 {
117 ldi_close(g_LdiHandle, FREAD, kcred);
118 g_LdiHandle = NULL;
119 }
120 mutex_exit(&g_LdiMtx);
121#endif
122
123 return VINF_SUCCESS;
124}
125
126
127/**
128 * Perform an IDC call.
129 *
130 * @returns VBox error code.
131 * @param pvSession Opaque pointer to the session.
132 * @param iCmd Requested function.
133 * @param pvData IO data buffer.
134 * @param cbData Size of the data buffer.
135 * @param pcbDataReturned Where to store the amount of returned data.
136 */
137DECLEXPORT(int) VBOXCALL VBoxGuestIDCCall(void *pvSession, unsigned iCmd, void *pvData, size_t cbData, size_t *pcbDataReturned)
138{
139 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pvSession;
140 LogFlow(("VBoxGuestIDCCall: %pvSession=%p Cmd=%u pvData=%p cbData=%d\n", pvSession, iCmd, pvData, cbData));
141
142 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
143 AssertMsgReturn(pSession->pDevExt == &g_DevExt,
144 ("SC: %p != %p\n", pSession->pDevExt, &g_DevExt), VERR_INVALID_HANDLE);
145
146 return VGDrvCommonIoCtl(iCmd, &g_DevExt, pSession, pvData, cbData, pcbDataReturned);
147}
148
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette