VirtualBox

source: vbox/trunk/include/VBox/ExtPack/ExtPack.h@ 49076

Last change on this file since 49076 was 48313, checked in by vboxsync, 11 years ago

Main/ExtPackManager+Console: add a way to load HGCM modules from an extension pack, contributed by Jeff Westphal (partially rewritten). Thanks!

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