VirtualBox

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

Last change on this file since 486 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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#ifndef VBGL_VBOXGUEST
89 if (g_vbgldata.status == VbglStatusInitializing)
90 {
91 vbglQueryVMMDevPort ();
92 }
93#endif
94
95 int rc = g_vbgldata.status != VbglStatusNotInitialized? VINF_SUCCESS: VERR_VBGL_NOT_INITIALIZED;
96
97 // dprintf(("VbglEnter: rc = %d\n", rc));
98
99 return rc;
100}
101
102int vbglInitCommon (void)
103{
104 int rc = VINF_SUCCESS;
105
106 memset(&g_vbgldata, 0, sizeof (VBGLDATA));
107
108 g_vbgldata.status = VbglStatusInitializing;
109
110 rc = VbglPhysHeapInit ();
111
112 if (VBOX_SUCCESS(rc))
113 {
114 /* other subsystems, none yet */
115 ;
116 }
117
118 dprintf(("vbglInitCommon: rc = %d\n", rc));
119
120 return rc;
121}
122
123DECLVBGL(void) vbglTerminateCommon (void)
124{
125 VbglPhysHeapTerminate ();
126
127 memset(&g_vbgldata, 0, sizeof (VBGLDATA));
128
129 return;
130}
131
132#ifdef VBGL_VBOXGUEST
133
134DECLVBGL(int) VbglInit (VBGLIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory)
135{
136 int rc = VINF_SUCCESS;
137
138 dprintf(("vbglInit: starts g_vbgldata.status %d\n", g_vbgldata.status));
139
140 if (g_vbgldata.status == VbglStatusInitializing
141 || g_vbgldata.status == VbglStatusReady)
142 {
143 /* Initialization is already in process. */
144 return rc;
145 }
146
147 rc = vbglInitCommon ();
148
149 if (VBOX_SUCCESS(rc))
150 {
151 g_vbgldata.portVMMDev = portVMMDev;
152 g_vbgldata.pVMMDevMemory = pVMMDevMemory;
153
154 g_vbgldata.status = VbglStatusReady;
155 }
156 else
157 {
158 g_vbgldata.status = VbglStatusNotInitialized;
159 }
160
161 return rc;
162}
163
164DECLVBGL(void) VbglTerminate (void)
165{
166 vbglTerminateCommon ();
167
168 return;
169}
170
171
172#else /* !VBGL_VBOXGUEST */
173
174DECLVBGL(int) VbglInit (void)
175{
176 int rc = VINF_SUCCESS;
177
178 if (g_vbgldata.status == VbglStatusInitializing
179 || g_vbgldata.status == VbglStatusReady)
180 {
181 /* Initialization is already in process. */
182 return rc;
183 }
184
185 rc = vbglInitCommon ();
186
187 if (VBOX_SUCCESS(rc))
188 {
189 /* Obtain VMMDev port via IOCTL to VBoxGuest main driver. */
190 vbglQueryVMMDevPort ();
191
192#ifdef VBOX_HGCM
193 rc = vbglHGCMInit ();
194#endif
195
196 if (VBOX_FAILURE(rc))
197 {
198 vbglTerminateCommon ();
199 }
200 }
201
202 return rc;
203}
204
205DECLVBGL(void) VbglTerminate (void)
206{
207 vbglTerminateCommon ();
208
209#ifdef VBOX_HGCM
210 vbglHGCMTerminate ();
211#endif
212
213 return;
214}
215
216#endif /* !VBGL_VBOXGUEST */
217
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