VirtualBox

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

Last change on this file since 41683 was 38827, checked in by vboxsync, 13 years ago

Additions/solaris: Fix panic while mounting shared folders when no previous userland connections to VBoxGuest is alive.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Rev: 38827 $ */
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-2009 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 * Some lines of code to disable the local APIC on x86_64 machines taken
19 * from a Mandriva patch by Gwenole Beauchesne <[email protected]>.
20 */
21
22
23/** @todo Use some header that we have in common with VBoxGuestLib.h... */
24DECLVBGL(void *) VBoxGuestIDCOpen(uint32_t *pu32Version);
25DECLVBGL(int) VBoxGuestIDCClose(void *pvSession);
26DECLVBGL(int) VBoxGuestIDCCall(void *pvSession, unsigned iCmd, void *pvData, size_t cbData, size_t *pcbDataReturned);
27
28
29/**
30 * Open a new IDC connection.
31 *
32 * @returns Opaque pointer to session object.
33 * @param pu32Version Where to store VMMDev version.
34 */
35DECLVBGL(void *) VBoxGuestIDCOpen(uint32_t *pu32Version)
36{
37 PVBOXGUESTSESSION pSession;
38 int rc;
39 LogFlow(("VBoxGuestIDCOpen: Version=%#x\n", pu32Version ? *pu32Version : 0));
40
41 AssertPtrReturn(pu32Version, NULL);
42
43#ifdef RT_OS_SOLARIS
44 mutex_enter(&g_LdiMtx);
45 if (!g_LdiHandle)
46 {
47 ldi_ident_t DevIdent = ldi_ident_from_anon();
48 rc = ldi_open_by_name(VBOXGUEST_DEVICE_NAME, FREAD, kcred, &g_LdiHandle, DevIdent);
49 ldi_ident_release(DevIdent);
50 if (rc)
51 {
52 LogRel(("VBoxGuestIDCOpen: ldi_open_by_name failed. rc=%d\n", rc));
53 mutex_exit(&g_LdiMtx);
54 return NULL;
55 }
56 }
57 ++g_cLdiOpens;
58 mutex_exit(&g_LdiMtx);
59#endif
60
61 rc = VBoxGuestCreateKernelSession(&g_DevExt, &pSession);
62 if (RT_SUCCESS(rc))
63 {
64 *pu32Version = VMMDEV_VERSION;
65 return pSession;
66 }
67
68#ifdef RT_OS_SOLARIS
69 mutex_enter(&g_LdiMtx);
70 if (g_cLdiOpens > 0)
71 --g_cLdiOpens;
72 if ( g_cLdiOpens == 0
73 && g_LdiHandle)
74 {
75 ldi_close(g_LdiHandle, FREAD, kcred);
76 g_LdiHandle = NULL;
77 }
78 mutex_exit(&g_LdiMtx);
79#endif
80
81 LogRel(("VBoxGuestIDCOpen: VBoxGuestCreateKernelSession failed. rc=%d\n", rc));
82 return NULL;
83}
84
85
86/**
87 * Close an IDC connection.
88 *
89 * @returns VBox error code.
90 * @param pvState Opaque pointer to the session object.
91 */
92DECLVBGL(int) VBoxGuestIDCClose(void *pvSession)
93{
94 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pvSession;
95 LogFlow(("VBoxGuestIDCClose:\n"));
96
97 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
98 VBoxGuestCloseSession(&g_DevExt, pSession);
99
100#ifdef RT_OS_SOLARIS
101 mutex_enter(&g_LdiMtx);
102 if (g_cLdiOpens > 0)
103 --g_cLdiOpens;
104 if ( g_cLdiOpens == 0
105 && g_LdiHandle)
106 {
107 ldi_close(g_LdiHandle, FREAD, kcred);
108 g_LdiHandle = NULL;
109 }
110 mutex_exit(&g_LdiMtx);
111#endif
112
113 return VINF_SUCCESS;
114}
115
116
117/**
118 * Perform an IDC call.
119 *
120 * @returns VBox error code.
121 * @param pvSession Opaque pointer to the session.
122 * @param iCmd Requested function.
123 * @param pvData IO data buffer.
124 * @param cbData Size of the data buffer.
125 * @param pcbDataReturned Where to store the amount of returned data.
126 */
127DECLVBGL(int) VBoxGuestIDCCall(void *pvSession, unsigned iCmd, void *pvData, size_t cbData, size_t *pcbDataReturned)
128{
129 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pvSession;
130 LogFlow(("VBoxGuestIDCCall: %pvSession=%p Cmd=%u pvData=%p cbData=%d\n", pvSession, iCmd, pvData, cbData));
131
132 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
133 AssertMsgReturn(pSession->pDevExt == &g_DevExt,
134 ("SC: %p != %p\n", pSession->pDevExt, &g_DevExt), VERR_INVALID_HANDLE);
135
136 return VBoxGuestCommonIOCtl(iCmd, &g_DevExt, pSession, pvData, cbData, pcbDataReturned);
137}
138
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