VirtualBox

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

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

Prevent some warnings as these files are compiled as .c files on Linux now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 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#if defined(__LINUX__) && defined(__KERNEL__)
24#ifndef bool /* Linux 2.6.19 C++ nightmare */
25#define bool bool_type
26#define true true_type
27#define false false_type
28#define _Bool int
29#define bool_Init_cpp
30#endif
31#include <linux/string.h>
32#ifdef bool_Init_cpp
33#undef bool
34#undef true
35#undef false
36#undef _Bool
37#undef bool_Init_cpp
38#endif
39#else
40#include <string.h>
41#endif
42
43#include <VBox/VBoxGuestLib.h>
44
45#define VBGL_DECL_DATA
46#include "VBGLInternal.h"
47
48#include <iprt/assert.h>
49
50VBGLDATA g_vbgldata;
51
52#ifndef VBGL_VBOXGUEST
53static int vbglQueryVMMDevPort (void)
54{
55 int rc = VINF_SUCCESS;
56
57 VBGLDRIVER driver;
58
59 rc = vbglDriverOpen (&driver);
60
61 if (VBOX_SUCCESS(rc))
62 {
63 VBoxGuestPortInfo port;
64
65 rc = vbglDriverIOCtl (&driver, IOCTL_VBOXGUEST_GETVMMDEVPORT, &port, sizeof (port));
66
67 if (VBOX_SUCCESS (rc))
68 {
69 dprintf (("port = 0x%04X, mem = %p\n", port.portAddress, port.pVMMDevMemory));
70
71 g_vbgldata.portVMMDev = port.portAddress;
72 g_vbgldata.pVMMDevMemory = port.pVMMDevMemory;
73
74 g_vbgldata.status = VbglStatusReady;
75 }
76
77 vbglDriverClose (&driver);
78 }
79
80 dprintf (("vbglQueryVMMDevPort rc = %d\n", rc));
81
82 return rc;
83}
84#endif
85
86int VbglEnter (void)
87{
88 int rc;
89
90#ifndef VBGL_VBOXGUEST
91 if (g_vbgldata.status == VbglStatusInitializing)
92 {
93 vbglQueryVMMDevPort ();
94 }
95#endif
96
97 rc = g_vbgldata.status != VbglStatusNotInitialized? VINF_SUCCESS: VERR_VBGL_NOT_INITIALIZED;
98
99 // dprintf(("VbglEnter: rc = %d\n", rc));
100
101 return rc;
102}
103
104int vbglInitCommon (void)
105{
106 int rc = VINF_SUCCESS;
107
108 memset(&g_vbgldata, 0, sizeof (VBGLDATA));
109
110 g_vbgldata.status = VbglStatusInitializing;
111
112 rc = VbglPhysHeapInit ();
113
114 if (VBOX_SUCCESS(rc))
115 {
116 /* other subsystems, none yet */
117 ;
118 }
119
120 dprintf(("vbglInitCommon: rc = %d\n", rc));
121
122 return rc;
123}
124
125DECLVBGL(void) vbglTerminateCommon (void)
126{
127 VbglPhysHeapTerminate ();
128
129 memset(&g_vbgldata, 0, sizeof (VBGLDATA));
130
131 return;
132}
133
134#ifdef VBGL_VBOXGUEST
135
136DECLVBGL(int) VbglInit (VBGLIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory)
137{
138 int rc = VINF_SUCCESS;
139
140 dprintf(("vbglInit: starts g_vbgldata.status %d\n", g_vbgldata.status));
141
142 if (g_vbgldata.status == VbglStatusInitializing
143 || g_vbgldata.status == VbglStatusReady)
144 {
145 /* Initialization is already in process. */
146 return rc;
147 }
148
149 rc = vbglInitCommon ();
150
151 if (VBOX_SUCCESS(rc))
152 {
153 g_vbgldata.portVMMDev = portVMMDev;
154 g_vbgldata.pVMMDevMemory = pVMMDevMemory;
155
156 g_vbgldata.status = VbglStatusReady;
157 }
158 else
159 {
160 g_vbgldata.status = VbglStatusNotInitialized;
161 }
162
163 return rc;
164}
165
166DECLVBGL(void) VbglTerminate (void)
167{
168 vbglTerminateCommon ();
169
170 return;
171}
172
173
174#else /* !VBGL_VBOXGUEST */
175
176DECLVBGL(int) VbglInit (void)
177{
178 int rc = VINF_SUCCESS;
179
180 if (g_vbgldata.status == VbglStatusInitializing
181 || g_vbgldata.status == VbglStatusReady)
182 {
183 /* Initialization is already in process. */
184 return rc;
185 }
186
187 rc = vbglInitCommon ();
188
189 if (VBOX_SUCCESS(rc))
190 {
191 /* Obtain VMMDev port via IOCTL to VBoxGuest main driver. */
192 vbglQueryVMMDevPort ();
193
194#ifdef VBOX_HGCM
195 rc = vbglHGCMInit ();
196#endif
197
198 if (VBOX_FAILURE(rc))
199 {
200 vbglTerminateCommon ();
201 }
202 }
203
204 return rc;
205}
206
207DECLVBGL(void) VbglTerminate (void)
208{
209 vbglTerminateCommon ();
210
211#ifdef VBOX_HGCM
212 vbglHGCMTerminate ();
213#endif
214
215 return;
216}
217
218#endif /* !VBGL_VBOXGUEST */
219
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