1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/** @file
* VirtualBox - Extension Pack Interface.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___VBox_ExtPack_ExtPack_h
#define ___VBox_ExtPack_ExtPack_h
#include <VBox/types.h>
/** @def VBOXEXTPACK_IF_CS
* Selects 'class' on 'struct' for interface references.
* @param I The interface name
*/
#if defined(__cplusplus) && !defined(RT_OS_WINDOWS)
# define VBOXEXTPACK_IF_CS(I) class I
#else
# define VBOXEXTPACK_IF_CS(I) struct I
#endif
VBOXEXTPACK_IF_CS(IConsole);
VBOXEXTPACK_IF_CS(IMachine);
VBOXEXTPACK_IF_CS(IVirtualBox);
/**
* Module kind for use with VBOXEXTPACKHLP::pfnFindModule.
*/
typedef enum VBOXEXTPACKMODKIND
{
/** Zero is invalid as alwasy. */
VBOXEXTPACKMODKIND_INVALID = 0,
/** Raw-mode context module. */
VBOXEXTPACKMODKIND_RC,
/** Ring-0 context module. */
VBOXEXTPACKMODKIND_R0,
/** Ring-3 context module. */
VBOXEXTPACKMODKIND_R3,
/** End of the valid values (exclusive). */
VBOXEXTPACKMODKIND_END,
/** The usual 32-bit type hack. */
VBOXEXTPACKMODKIND_32BIT_HACK = 0x7fffffff
} VBOXEXTPACKMODKIND;
/**
* Contexts returned by VBOXEXTPACKHLP::pfnGetContext.
*/
typedef enum VBOXEXTPACKCTX
{
/** Zero is invalid as alwasy. */
VBOXEXTPACKCTX_INVALID = 0,
/** The per-user daemon process (VBoxSVC). */
VBOXEXTPACKCTX_PER_USER_DAEMON,
/** A VM process.
* @remarks This will also include the client processes in v4.0. */
VBOXEXTPACKCTX_VM_PROCESS,
/** A API client process.
* @remarks This will not be returned by VirtualBox 4.0. */
VBOXEXTPACKCTX_CLIENT_PROCESS,
/** End of the valid values (exclusive). */
VBOXEXTPACKCTX_END,
/** The usual 32-bit type hack. */
VBOXEXTPACKCTX_32BIT_HACK = 0x7fffffff
} VBOXEXTPACKCTX;
/** Pointer to const helpers passed to the VBoxExtPackRegister() call. */
typedef const struct VBOXEXTPACKHLP *PCVBOXEXTPACKHLP;
/**
* Extension pack helpers passed to VBoxExtPackRegister().
*
* This will be valid until the module is unloaded.
*/
typedef struct VBOXEXTPACKHLP
{
/** Interface version.
* This is set to VBOXEXTPACKHLP_VERSION. */
uint32_t u32Version;
/** The VirtualBox full version (see VBOX_FULL_VERSION). */
uint32_t uVBoxFullVersion;
/** The VirtualBox subversion tree revision. */
uint32_t uVBoxInternalRevision;
/** Explicit alignment padding, must be zero. */
uint32_t u32Padding;
/** Pointer to the version string (read-only). */
const char *pszVBoxVersion;
/**
* Finds a module belonging to this extension pack.
*
* @returns VBox status code.
* @param pHlp Pointer to this helper structure.
* @param pszName The module base name.
* @param pszExt The extension. If NULL the default ring-3
* library extension will be used.
* @param enmKind The kind of module to locate.
* @param pszFound Where to return the path to the module on
* success.
* @param cbFound The size of the buffer @a pszFound points to.
* @param pfNative Where to return the native/agnostic indicator.
*/
DECLR3CALLBACKMEMBER(int, pfnFindModule,(PCVBOXEXTPACKHLP pHlp, const char *pszName, const char *pszExt,
VBOXEXTPACKMODKIND enmKind,
char *pszFound, size_t cbFound, bool *pfNative));
/**
* Gets the path to a file belonging to this extension pack.
*
* @returns VBox status code.
* @retval VERR_INVALID_POINTER if any of the pointers are invalid.
* @retval VERR_BUFFER_OVERFLOW if the buffer is too small. The buffer
* will contain nothing.
*
* @param pHlp Pointer to this helper structure.
* @param pszFilename The filename.
* @param pszPath Where to return the path to the file on
* success.
* @param cbPath The size of the buffer @a pszPath.
*/
DECLR3CALLBACKMEMBER(int, pfnGetFilePath,(PCVBOXEXTPACKHLP pHlp, const char *pszFilename, char *pszPath, size_t cbPath));
/**
* Gets the context the extension pack is operating in.
*
* @returns The context.
* @retval VBOXEXTPACKCTX_INVALID if @a pHlp is invalid.
*
* @param pHlp Pointer to this helper structure.
*/
DECLR3CALLBACKMEMBER(VBOXEXTPACKCTX, pfnGetContext,(PCVBOXEXTPACKHLP pHlp));
DECLR3CALLBACKMEMBER(int, pfnReserved1,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved2,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved3,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved4,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved5,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved6,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved7,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved8,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
DECLR3CALLBACKMEMBER(int, pfnReserved9,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
/** End of structure marker (VBOXEXTPACKHLP_VERSION). */
uint32_t u32EndMarker;
} VBOXEXTPACKHLP;
/** Current version of the VBOXEXTPACKHLP structure. */
#define VBOXEXTPACKHLP_VERSION RT_MAKE_U32(0, 1)
/** Pointer to the extension pack callback table. */
typedef struct VBOXEXTPACKREG const *PCVBOXEXTPACKREG;
/**
* Callback table returned by VBoxExtPackRegister.
*
* This must be valid until the extension pack main module is unloaded.
*/
typedef struct VBOXEXTPACKREG
{
/** Interface version.
* This is set to VBOXEXTPACKREG_VERSION. */
uint32_t u32Version;
/**
* Hook for doing setups after the extension pack was installed.
*
* This is called in the context of the per-user service (VBoxSVC).
*
* @returns VBox status code.
* @retval VERR_EXTPACK_UNSUPPORTED_HOST_UNINSTALL if the extension pack
* requires some different host version or a prerequisite is
* missing from the host. Automatic uninstall will be attempted.
* Must set error info.
*
* @param pThis Pointer to this structure.
* @param pVirtualBox The VirtualBox interface.
* @param pErrInfo Where to return extended error information.
*/
DECLCALLBACKMEMBER(int, pfnInstalled)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox,
PRTERRINFO pErrInfo);
/**
* Hook for cleaning up before the extension pack is uninstalled.
*
* This is called in the context of the per-user service (VBoxSVC).
*
* @returns VBox status code.
* @param pThis Pointer to this structure.
* @param pVirtualBox The VirtualBox interface.
*
* @todo This is currently called holding locks making pVirtualBox
* relatively unusable.
*/
DECLCALLBACKMEMBER(int, pfnUninstall)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox);
/**
* Hook for doing work after the VirtualBox object is ready.
*
* This is called in the context of the per-user service (VBoxSVC). The
* pfnConsoleReady method is the equivalent for the VM/client process.
*
* @param pThis Pointer to this structure.
* @param pVirtualBox The VirtualBox interface.
*/
DECLCALLBACKMEMBER(void, pfnVirtualBoxReady)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox);
/**
* Hook for doing work after the Console object is ready.
*
* This is called in the context of the VM/client process. The
* pfnVirtualBoxReady method is the equivalent for the per-user service
* (VBoxSVC).
*
* @param pThis Pointer to this structure.
* @param pConsole The Console interface.
*/
DECLCALLBACKMEMBER(void, pfnConsoleReady)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole);
/**
* Hook for doing work before unloading.
*
* This is called both in the context of the per-user service (VBoxSVC) and
* in context of the VM process (VBoxC).
*
* @param pThis Pointer to this structure.
*
* @remarks The helpers are not available at this point in time.
* @remarks This is not called on uninstall, then pfnUninstall will be the
* last callback.
*/
DECLCALLBACKMEMBER(void, pfnUnload)(PCVBOXEXTPACKREG pThis);
/**
* Hook for changing the default VM configuration upon creation.
*
* This is called in the context of the per-user service (VBoxSVC).
*
* @returns VBox status code.
* @param pThis Pointer to this structure.
* @param pVirtualBox The VirtualBox interface.
* @param pMachine The machine interface.
*/
DECLCALLBACKMEMBER(int, pfnVMCreated)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox,
VBOXEXTPACK_IF_CS(IMachine) *pMachine);
/**
* Hook for configuring the VMM for a VM.
*
* This is called in the context of the VM process (VBoxC).
*
* @returns VBox status code.
* @param pThis Pointer to this structure.
* @param pConsole The console interface.
* @param pVM The VM handle.
*/
DECLCALLBACKMEMBER(int, pfnVMConfigureVMM)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole, PVM pVM);
/**
* Hook for doing work right before powering on the VM.
*
* This is called in the context of the VM process (VBoxC).
*
* @returns VBox status code.
* @param pThis Pointer to this structure.
* @param pConsole The console interface.
* @param pVM The VM handle.
*/
DECLCALLBACKMEMBER(int, pfnVMPowerOn)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole, PVM pVM);
/**
* Hook for doing work after powering on the VM.
*
* This is called in the context of the VM process (VBoxC).
*
* @param pThis Pointer to this structure.
* @param pConsole The console interface.
* @param pVM The VM handle. Can be NULL.
*/
DECLCALLBACKMEMBER(void, pfnVMPowerOff)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole, PVM pVM);
/**
* Query the IUnknown interface to an object in the main module.
*
* This is can be called in any context.
*
* @returns IUnknown pointer (referenced) on success, NULL on failure.
* @param pThis Pointer to this structure.
* @param pObjectId Pointer to the object ID (UUID).
*/
DECLCALLBACKMEMBER(void *, pfnQueryObject)(PCVBOXEXTPACKREG pThis, PCRTUUID pObjectId);
/** End of structure marker (VBOXEXTPACKREG_VERSION). */
uint32_t u32EndMarker;
} VBOXEXTPACKREG;
/** Current version of the VBOXEXTPACKREG structure. */
#define VBOXEXTPACKREG_VERSION RT_MAKE_U32(0, 1)
/**
* The VBoxExtPackRegister callback function.
*
* PDM will invoke this function after loading a driver module and letting
* the module decide which drivers to register and how to handle conflicts.
*
* @returns VBox status code.
* @param pHlp Pointer to the extension pack helper function
* table. This is valid until the module is unloaded.
* @param ppReg Where to return the pointer to the registration
* structure containing all the hooks. This structure
* be valid and unchanged until the module is unloaded
* (i.e. use some static const data for it).
* @param pErrInfo Where to return extended error information.
*/
typedef DECLCALLBACK(int) FNVBOXEXTPACKREGISTER(PCVBOXEXTPACKHLP pHlp, PCVBOXEXTPACKREG *ppReg, PRTERRINFO pErrInfo);
/** Pointer to a FNVBOXEXTPACKREGISTER. */
typedef FNVBOXEXTPACKREGISTER *PFNVBOXEXTPACKREGISTER;
/** The name of the main module entry point. */
#define VBOX_EXTPACK_MAIN_MOD_ENTRY_POINT "VBoxExtPackRegister"
/**
* Checks if extension pack interface version is compatible.
*
* @returns true if the do, false if they don't.
* @param u32Provider The provider version.
* @param u32User The user version.
*/
#define VBOXEXTPACK_IS_VER_COMPAT(u32Provider, u32User) \
( VBOXEXTPACK_IS_MAJOR_VER_EQUAL(u32Provider, u32User) \
&& (int32_t)RT_LOWORD(u32Provider) >= (int32_t)RT_LOWORD(u32User) ) /* stupid casts to shut up gcc */
/**
* Check if two extension pack interface versions has the same major version.
*
* @returns true if the do, false if they don't.
* @param u32Ver1 The first version number.
* @param u32Ver2 The second version number.
*/
#define VBOXEXTPACK_IS_MAJOR_VER_EQUAL(u32Ver1, u32Ver2) (RT_HIWORD(u32Ver1) == RT_HIWORD(u32Ver2))
#endif
|