VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/Init.cpp@ 2698

Last change on this file since 2698 was 2698, checked in by vboxsync, 18 years ago

do not swallow errors

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/** @file
2 *
3 * VBoxGuestLib - A support library for VirtualBox guest additions:
4 * Library initialization
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23
24#include <VBox/VBoxGuestLib.h>
25
26#define VBGL_DECL_DATA
27#include "VBGLInternal.h"
28
29#include <iprt/string.h>
30#include <iprt/assert.h>
31
32VBGLDATA g_vbgldata;
33
34#ifndef VBGL_VBOXGUEST
35static int vbglQueryVMMDevPort (void)
36{
37 int rc = VINF_SUCCESS;
38
39 VBGLDRIVER driver;
40
41 rc = vbglDriverOpen (&driver);
42
43 if (VBOX_SUCCESS(rc))
44 {
45 VBoxGuestPortInfo port;
46
47 rc = vbglDriverIOCtl (&driver, IOCTL_VBOXGUEST_GETVMMDEVPORT, &port, sizeof (port));
48
49 if (VBOX_SUCCESS (rc))
50 {
51 dprintf (("port = 0x%04X, mem = %p\n", port.portAddress, port.pVMMDevMemory));
52
53 g_vbgldata.portVMMDev = port.portAddress;
54 g_vbgldata.pVMMDevMemory = port.pVMMDevMemory;
55
56 g_vbgldata.status = VbglStatusReady;
57 }
58
59 vbglDriverClose (&driver);
60 }
61
62 dprintf (("vbglQueryVMMDevPort rc = %d\n", rc));
63
64 return rc;
65}
66#endif
67
68int VbglEnter (void)
69{
70 int rc;
71
72#ifndef VBGL_VBOXGUEST
73 if (g_vbgldata.status == VbglStatusInitializing)
74 {
75 vbglQueryVMMDevPort ();
76 }
77#endif
78
79 rc = g_vbgldata.status != VbglStatusNotInitialized? VINF_SUCCESS: VERR_VBGL_NOT_INITIALIZED;
80
81 // dprintf(("VbglEnter: rc = %d\n", rc));
82
83 return rc;
84}
85
86int vbglInitCommon (void)
87{
88 int rc = VINF_SUCCESS;
89
90 memset(&g_vbgldata, 0, sizeof (VBGLDATA));
91
92 g_vbgldata.status = VbglStatusInitializing;
93
94 rc = VbglPhysHeapInit ();
95
96 if (VBOX_SUCCESS(rc))
97 {
98 /* other subsystems, none yet */
99 ;
100 }
101
102 dprintf(("vbglInitCommon: rc = %d\n", rc));
103
104 return rc;
105}
106
107DECLVBGL(void) vbglTerminateCommon (void)
108{
109 VbglPhysHeapTerminate ();
110
111 memset(&g_vbgldata, 0, sizeof (VBGLDATA));
112
113 return;
114}
115
116#ifdef VBGL_VBOXGUEST
117
118DECLVBGL(int) VbglInit (VBGLIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory)
119{
120 int rc = VINF_SUCCESS;
121
122 dprintf(("vbglInit: starts g_vbgldata.status %d\n", g_vbgldata.status));
123
124 if (g_vbgldata.status == VbglStatusInitializing
125 || g_vbgldata.status == VbglStatusReady)
126 {
127 /* Initialization is already in process. */
128 return rc;
129 }
130
131 rc = vbglInitCommon ();
132
133 if (VBOX_SUCCESS(rc))
134 {
135 g_vbgldata.portVMMDev = portVMMDev;
136 g_vbgldata.pVMMDevMemory = pVMMDevMemory;
137
138 g_vbgldata.status = VbglStatusReady;
139 }
140 else
141 {
142 g_vbgldata.status = VbglStatusNotInitialized;
143 }
144
145 return rc;
146}
147
148DECLVBGL(void) VbglTerminate (void)
149{
150 vbglTerminateCommon ();
151
152 return;
153}
154
155
156#else /* !VBGL_VBOXGUEST */
157
158DECLVBGL(int) VbglInit (void)
159{
160 int rc = VINF_SUCCESS;
161
162 if (g_vbgldata.status == VbglStatusInitializing
163 || g_vbgldata.status == VbglStatusReady)
164 {
165 /* Initialization is already in process. */
166 return rc;
167 }
168
169 rc = vbglInitCommon ();
170
171 if (VBOX_SUCCESS(rc))
172 {
173 /* Obtain VMMDev port via IOCTL to VBoxGuest main driver. */
174 rc = vbglQueryVMMDevPort ();
175
176#ifdef VBOX_HGCM
177 if (VBOX_SUCCESS(rc))
178 {
179 rc = vbglHGCMInit ();
180 }
181#endif
182
183 if (VBOX_FAILURE(rc))
184 {
185 vbglTerminateCommon ();
186 }
187 }
188
189 return rc;
190}
191
192DECLVBGL(void) VbglTerminate (void)
193{
194 vbglTerminateCommon ();
195
196#ifdef VBOX_HGCM
197 vbglHGCMTerminate ();
198#endif
199
200 return;
201}
202
203#endif /* !VBGL_VBOXGUEST */
204
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