VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use