VirtualBox

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

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

SUPDrv: Doxygen fix. bugref:9937

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* $Id: SUPWrapperMod-linux.c 87708 2021-02-11 00:09:46Z 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 /* Locate the module structure before we call SUPDrv to register.
171
172 Before Linux v5.9 this could be done by address (__module_address()
173 or __module_text_address()), but someone (guess who) apparently on
174 a mission to make life miserable for out-of-tree modules or something,
175 decided it was only used by build-in code and unexported both of them.
176
177 I could find no init callouts getting a struct module pointer either,
178 nor any module name hint anywhere I could see. So, we're left with
179 hardcoding the module name via the compiler and call find_module.
180
181 Sigh^2. */
182 /*printk("vboxwrap/" WRAPPED_MODULE_NAME ": VBoxWrapperModInit\n");*/
183 struct module *pLnxMod = find_module(WRAPPER_MODULE_KMOD_NAME);
184 if (pLnxMod)
185 {
186 int rc = SUPDrvLinuxLdrRegisterWrappedModule(&g_WrappedMod, pLnxMod, &g_hWrappedRegistration);
187 if (rc == 0)
188 return 0;
189 printk("vboxwrap/" WRAPPED_MODULE_NAME ": SUPDrvLinuxRegisterWrappedModule failed: %d\n", rc);
190 }
191 else
192 printk("vboxwrap/" WRAPPED_MODULE_NAME ": find_module(" WRAPPER_MODULE_KMOD_NAME ") failed\n");
193 return -EINVAL;
194}
195
196
197/**
198 * Unload the module.
199 */
200static void __exit VBoxWrapperModUnload(void)
201{
202 /*printk("vboxwrap/" WRAPPED_MODULE_NAME ": VBoxWrapperModUnload\n");*/
203 SUPDrvLinuxLdrDeregisterWrappedModule(&g_WrappedMod, &g_hWrappedRegistration);
204}
205
206module_init(VBoxWrapperModInit);
207module_exit(VBoxWrapperModUnload);
208
209MODULE_AUTHOR(VBOX_VENDOR);
210MODULE_DESCRIPTION(VBOX_PRODUCT " - " WRAPPED_MODULE_NAME);
211#ifndef WRAPPED_MODULE_LICENSE_PROPRIETARY
212MODULE_LICENSE("GPL");
213#else
214MODULE_LICENSE("Proprietary");
215#endif
216#ifdef MODULE_VERSION
217MODULE_VERSION(VBOX_VERSION_STRING " r" RT_XSTR(VBOX_SVN_REV));
218#endif
219
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