VirtualBox

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

Last change on this file since 34521 was 34287, checked in by vboxsync, 14 years ago

ExtPack: Don't hold any locks when calling extension pack hooks (except for pfnUnload and pfnUninstall).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.8 KB
Line 
1/** @file
2 * VirtualBox - Extension Pack Interface.
3 */
4
5/*
6 * Copyright (C) 2010 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, pfnReserved1,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
153 DECLR3CALLBACKMEMBER(int, pfnReserved2,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
154 DECLR3CALLBACKMEMBER(int, pfnReserved3,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
155 DECLR3CALLBACKMEMBER(int, pfnReserved4,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
156 DECLR3CALLBACKMEMBER(int, pfnReserved5,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
157 DECLR3CALLBACKMEMBER(int, pfnReserved6,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
158 DECLR3CALLBACKMEMBER(int, pfnReserved7,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
159 DECLR3CALLBACKMEMBER(int, pfnReserved8,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
160 DECLR3CALLBACKMEMBER(int, pfnReserved9,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
161
162 /** End of structure marker (VBOXEXTPACKHLP_VERSION). */
163 uint32_t u32EndMarker;
164} VBOXEXTPACKHLP;
165/** Current version of the VBOXEXTPACKHLP structure. */
166#define VBOXEXTPACKHLP_VERSION RT_MAKE_U32(0, 1)
167
168
169/** Pointer to the extension pack callback table. */
170typedef struct VBOXEXTPACKREG const *PCVBOXEXTPACKREG;
171/**
172 * Callback table returned by VBoxExtPackRegister.
173 *
174 * This must be valid until the extension pack main module is unloaded.
175 */
176typedef struct VBOXEXTPACKREG
177{
178 /** Interface version.
179 * This is set to VBOXEXTPACKREG_VERSION. */
180 uint32_t u32Version;
181
182 /**
183 * Hook for doing setups after the extension pack was installed.
184 *
185 * This is called in the context of the per-user service (VBoxSVC).
186 *
187 * @param pThis Pointer to this structure.
188 * @param pVirtualBox The VirtualBox interface.
189 */
190 DECLCALLBACKMEMBER(void, pfnInstalled)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox);
191
192 /**
193 * Hook for cleaning up before the extension pack is uninstalled.
194 *
195 * This is called in the context of the per-user service (VBoxSVC).
196 *
197 * @returns VBox status code.
198 * @param pThis Pointer to this structure.
199 * @param pVirtualBox The VirtualBox interface.
200 * @todo This is currently called holding locks making pVirtualBox
201 * relatively unusable.
202 */
203 DECLCALLBACKMEMBER(int, pfnUninstall)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox);
204
205 /**
206 * Hook for doing work after the VirtualBox object is ready.
207 *
208 * This is called in the context of the per-user service (VBoxSVC). The
209 * pfnConsoleReady method is the equivalent for the VM/client process.
210 *
211 * @param pThis Pointer to this structure.
212 * @param pVirtualBox The VirtualBox interface.
213 */
214 DECLCALLBACKMEMBER(void, pfnVirtualBoxReady)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox);
215
216 /**
217 * Hook for doing work after the Console object is ready.
218 *
219 * This is called in the context of the VM/client process. The
220 * pfnVirtualBoxReady method is the equivalent for the per-user service
221 * (VBoxSVC).
222 *
223 * @param pThis Pointer to this structure.
224 * @param pConsole The Console interface.
225 */
226 DECLCALLBACKMEMBER(void, pfnConsoleReady)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole);
227
228 /**
229 * Hook for doing work before unloading.
230 *
231 * This is called both in the context of the per-user service (VBoxSVC) and
232 * in context of the VM process (VBoxC).
233 *
234 * @param pThis Pointer to this structure.
235 *
236 * @remarks The helpers are not available at this point in time.
237 * @remarks This is not called on uninstall, then pfnUninstall will be the
238 * last callback.
239 */
240 DECLCALLBACKMEMBER(void, pfnUnload)(PCVBOXEXTPACKREG pThis);
241
242 /**
243 * Hook for changing the default VM configuration upon creation.
244 *
245 * This is called in the context of the per-user service (VBoxSVC).
246 *
247 * @returns VBox status code.
248 * @param pThis Pointer to this structure.
249 * @param pVirtualBox The VirtualBox interface.
250 * @param pMachine The machine interface.
251 */
252 DECLCALLBACKMEMBER(int, pfnVMCreated)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IVirtualBox) *pVirtualBox,
253 VBOXEXTPACK_IF_CS(IMachine) *pMachine);
254
255 /**
256 * Hook for configuring the VMM for a VM.
257 *
258 * This is called in the context of the VM process (VBoxC).
259 *
260 * @returns VBox status code.
261 * @param pThis Pointer to this structure.
262 * @param pConsole The console interface.
263 * @param pVM The VM handle.
264 */
265 DECLCALLBACKMEMBER(int, pfnVMConfigureVMM)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole, PVM pVM);
266
267 /**
268 * Hook for doing work right before powering on the VM.
269 *
270 * This is called in the context of the VM process (VBoxC).
271 *
272 * @returns VBox status code.
273 * @param pThis Pointer to this structure.
274 * @param pConsole The console interface.
275 * @param pVM The VM handle.
276 */
277 DECLCALLBACKMEMBER(int, pfnVMPowerOn)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole, PVM pVM);
278
279 /**
280 * Hook for doing work after powering on the VM.
281 *
282 * This is called in the context of the VM process (VBoxC).
283 *
284 * @param pThis Pointer to this structure.
285 * @param pConsole The console interface.
286 * @param pVM The VM handle. Can be NULL.
287 */
288 DECLCALLBACKMEMBER(void, pfnVMPowerOff)(PCVBOXEXTPACKREG pThis, VBOXEXTPACK_IF_CS(IConsole) *pConsole, PVM pVM);
289
290 /**
291 * Query the IUnknown interface to an object in the main module.
292 *
293 * This is can be called in any context.
294 *
295 * @returns IUnknown pointer (referenced) on success, NULL on failure.
296 * @param pThis Pointer to this structure.
297 * @param pObjectId Pointer to the object ID (UUID).
298 */
299 DECLCALLBACKMEMBER(void *, pfnQueryObject)(PCVBOXEXTPACKREG pThis, PCRTUUID pObjectId);
300
301 /** End of structure marker (VBOXEXTPACKREG_VERSION). */
302 uint32_t u32EndMarker;
303} VBOXEXTPACKREG;
304/** Current version of the VBOXEXTPACKREG structure. */
305#define VBOXEXTPACKREG_VERSION RT_MAKE_U32(0, 1)
306
307
308/**
309 * The VBoxExtPackRegister callback function.
310 *
311 * PDM will invoke this function after loading a driver module and letting
312 * the module decide which drivers to register and how to handle conflicts.
313 *
314 * @returns VBox status code.
315 * @param pHlp Pointer to the extension pack helper function
316 * table. This is valid until the module is unloaded.
317 * @param ppReg Where to return the pointer to the registration
318 * structure containing all the hooks. This structure
319 * be valid and unchanged until the module is unloaded
320 * (i.e. use some static const data for it).
321 * @param pszErr Error message buffer for explaining any failure.
322 * @param cbErr The size of the error message buffer.
323 */
324typedef DECLCALLBACK(int) FNVBOXEXTPACKREGISTER(PCVBOXEXTPACKHLP pHlp, PCVBOXEXTPACKREG *ppReg, char *pszErr, size_t cbErr);
325/** Pointer to a FNVBOXEXTPACKREGISTER. */
326typedef FNVBOXEXTPACKREGISTER *PFNVBOXEXTPACKREGISTER;
327
328/** The name of the main module entry point. */
329#define VBOX_EXTPACK_MAIN_MOD_ENTRY_POINT "VBoxExtPackRegister"
330
331
332/**
333 * Checks if extension pack interface version is compatible.
334 *
335 * @returns true if the do, false if they don't.
336 * @param u32Provider The provider version.
337 * @param u32User The user version.
338 */
339#define VBOXEXTPACK_IS_VER_COMPAT(u32Provider, u32User) \
340 ( VBOXEXTPACK_IS_MAJOR_VER_EQUAL(u32Provider, u32User) \
341 && RT_LOWORD(u32Provider) >= RT_LOWORD(u32User) )
342
343/**
344 * Check if two extension pack interface versions has the same major version.
345 *
346 * @returns true if the do, false if they don't.
347 * @param u32Ver1 The first version number.
348 * @param u32Ver2 The second version number.
349 */
350#define VBOXEXTPACK_IS_MAJOR_VER_EQUAL(u32Ver1, u32Ver2) (RT_HIWORD(u32Ver1) == RT_HIWORD(u32Ver2))
351
352#endif
353
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette