VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/linux/SUPWrapperMod-linux.c@ 90780

Last change on this file since 90780 was 87728, checked in by vboxsync, 4 years ago

SUPDrv,VMMR0,VBoxDDR0,++: More work on wrapper kmods. bugref:9937

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/* $Id: SUPWrapperMod-linux.c 87728 2021-02-12 02:24:07Z vboxsync $ */
2/** @file
3 * Linux .r0 wrapper module template.
4 */
5
6/*
7 * Copyright (C) 2006-2021 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#define IPRT_WITHOUT_EFLAGS_AC_PRESERVING
32#include "the-linux-kernel.h"
33
34#include "version-generated.h"
35#include "product-generated.h"
36#include "revision-generated.h"
37
38#include <VBox/sup.h>
39
40
41/*********************************************************************************************************************************
42* Defined Constants And Macros *
43*********************************************************************************************************************************/
44/** @def WRAPPED_MODULE_FLAGS
45 * SUPLDRWRAPPEDMODULE_F_XXX or 0. Default: 0 */
46#ifndef WRAPPED_MODULE_FLAGS
47# define WRAPPED_MODULE_FLAGS 0
48#endif
49/** @def WRAPPED_MODULE_INIT
50 * The module init function or NULL. Default: ModuleInit */
51#ifndef WRAPPED_MODULE_INIT
52# define WRAPPED_MODULE_INIT ModuleInit
53#endif
54/** @def WRAPPED_MODULE_TERM
55 * The module termination function or NULL. Default: ModuleTerm */
56#ifndef WRAPPED_MODULE_TERM
57# define WRAPPED_MODULE_TERM ModuleTerm
58#endif
59/** @def WRAPPED_MODULE_SRV_REQ_HANDLER
60 * The service request handler function. Default: NULL */
61#ifndef WRAPPED_MODULE_SRV_REQ_HANDLER
62# define WRAPPED_MODULE_SRV_REQ_HANDLER NULL
63#endif
64/** @def WRAPPED_MODULE_VMMR0_ENTRY_FAST
65 * The VMMR0 fast entry point. Default: NULL */
66#ifndef WRAPPED_MODULE_VMMR0_ENTRY_FAST
67# define WRAPPED_MODULE_VMMR0_ENTRY_FAST NULL
68#endif
69/** @def WRAPPED_MODULE_VMMR0_ENTRY_EX
70 * The VMMR0 extended entry point. Default: NULL */
71#ifndef WRAPPED_MODULE_VMMR0_ENTRY_EX
72# define WRAPPED_MODULE_VMMR0_ENTRY_EX NULL
73#endif
74/** @def WRAPPED_MODULE_SRV_REQ_HANDLER
75 * The service request handler function. Default: NULL */
76#ifndef WRAPPED_MODULE_SRV_REQ_HANDLER
77# define WRAPPED_MODULE_SRV_REQ_HANDLER NULL
78#endif
79
80#ifdef DOXYGEN_RUNNING
81/** @def WRAPPED_MODULE_LINUX_EXPORTS
82 * Define to enabled linux exports. (Needed for VMMR0.r0 only at present.) */
83# define WRAPPED_MODULE_LINUX_EXPORTS
84#endif
85#ifdef DOXYGEN_RUNNING
86/** @def WRAPPED_MODULE_LICENSE_PROPRIETARY
87 * Define to select proprietary license instead of GPL. */
88# define WRAPPED_MODULE_LICENSE_PROPRIETARY
89#endif
90#ifdef DOXYGEN_RUNNING
91/** @def WRAPPED_MODULE_SYMBOL_INCLUDE
92 * The include with SYMBOL_ENTRY() invocations for all exported symbols. */
93# define WRAPPED_MODULE_SYMBOL_INCLUDE "iprt/cdefs.h"
94#endif
95
96
97/*********************************************************************************************************************************
98* Internal Functions *
99*********************************************************************************************************************************/
100static int __init VBoxWrapperModInit(void);
101static void __exit VBoxWrapperModUnload(void);
102
103
104/*
105 * Prototype the symbols:
106 */
107#undef RT_MANGLER
108#define RT_MANGLER(a_Name) a_Name /* No mangling */
109#define SYMBOL_ENTRY(a_Name) extern FNRT a_Name;
110#include WRAPPED_MODULE_SYMBOL_INCLUDE
111#undef SYMBOL_ENTRY
112
113/*
114 * Export the symbols linux style:
115 */
116#ifdef WRAPPED_MODULE_LINUX_EXPORTS
117# define SYMBOL_ENTRY(a_Name) EXPORT_SYMBOL(a_Name);
118# include WRAPPED_MODULE_SYMBOL_INCLUDE
119# undef SYMBOL_ENTRY
120#endif
121
122
123/*********************************************************************************************************************************
124* Global Variables *
125*********************************************************************************************************************************/
126extern char vboxr0mod_start[]; /**< start of text in the .r0 module. */
127extern char vboxr0mod_end[]; /**< end of bss in the .r0 module. */
128
129/** The symbol table. */
130static SUPLDRWRAPMODSYMBOL const g_aSymbols[] =
131{
132#define SYMBOL_ENTRY(a_Name) { #a_Name, &a_Name },
133#include WRAPPED_MODULE_SYMBOL_INCLUDE
134#undef SYMBOL_ENTRY
135};
136
137/** Wrapped module registration info. */
138static SUPLDRWRAPPEDMODULE const g_WrappedMod =
139{
140 /* .uMagic = */ SUPLDRWRAPPEDMODULE_MAGIC,
141 /* .uVersion = */ SUPLDRWRAPPEDMODULE_VERSION,
142 /* .fFlags = */ WRAPPED_MODULE_FLAGS,
143 /* .pvImageStart = */ &vboxr0mod_start[0],
144 /* .pvImageEnd = */ &vboxr0mod_end[0],
145
146 /* .pfnModuleInit = */ WRAPPED_MODULE_INIT,
147 /* .pfnModuleTerm = */ WRAPPED_MODULE_TERM,
148 /* .pfnVMMR0EntryFast = */ WRAPPED_MODULE_VMMR0_ENTRY_FAST,
149 /* .pfnVMMR0EntryEx = */ WRAPPED_MODULE_VMMR0_ENTRY_EX,
150 /* .pfnSrvReqHandler = */ (PFNSUPR0SERVICEREQHANDLER)WRAPPED_MODULE_SRV_REQ_HANDLER,
151
152 /* .apSymbols = */ g_aSymbols,
153 /* .cSymbols = */ RT_ELEMENTS(g_aSymbols),
154
155 /* .szName = */ WRAPPED_MODULE_NAME,
156 /* .uEndMagic = */ SUPLDRWRAPPEDMODULE_MAGIC,
157};
158
159/** The wrapped module handle. */
160static void *g_hWrappedRegistration = NULL;
161
162
163/**
164 * Initialize module.
165 *
166 * @returns appropriate status code.
167 */
168static int __init VBoxWrapperModInit(void)
169{
170 /*printk("vboxwrap/" WRAPPED_MODULE_NAME ": VBoxWrapperModInit\n");*/
171 int rc = SUPDrvLinuxLdrRegisterWrappedModule(&g_WrappedMod, KBUILD_MODNAME, &g_hWrappedRegistration);
172 if (rc == 0)
173 return 0;
174 printk("vboxwrap/" WRAPPED_MODULE_NAME ": SUPDrvLinuxRegisterWrappedModule failed: %d\n", rc);
175 return -EINVAL;
176}
177
178
179/**
180 * Unload the module.
181 */
182static void __exit VBoxWrapperModUnload(void)
183{
184 /*printk("vboxwrap/" WRAPPED_MODULE_NAME ": VBoxWrapperModUnload\n");*/
185 SUPDrvLinuxLdrDeregisterWrappedModule(&g_WrappedMod, &g_hWrappedRegistration);
186}
187
188module_init(VBoxWrapperModInit);
189module_exit(VBoxWrapperModUnload);
190
191MODULE_AUTHOR(VBOX_VENDOR);
192MODULE_DESCRIPTION(VBOX_PRODUCT " - " WRAPPED_MODULE_NAME);
193#ifndef WRAPPED_MODULE_LICENSE_PROPRIETARY
194MODULE_LICENSE("GPL");
195#else
196MODULE_LICENSE("Proprietary");
197#endif
198#ifdef MODULE_VERSION
199MODULE_VERSION(VBOX_VERSION_STRING " r" RT_XSTR(VBOX_SVN_REV));
200#endif
201
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