VirtualBox

Changeset 87728 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Feb 12, 2021 2:24:07 AM (4 years ago)
Author:
vboxsync
Message:

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

Location:
trunk/src/VBox/HostDrivers
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r87700 r87728  
    788788  ifdef VBOX_WITH_KMOD_WRAPPED_R0_MODS
    789789#
    790 # The wrapper modules.
    791 #
    792 INSTALLS.linux += vbox_vmmr0-src
    793 vbox_vmmr0-src_INST = bin/src/vbox_vmmr0/
    794 vbox_vmmr0-src_SOURCES = \
     790# Common wrapper module files.
     791#
     792INSTALLS.linux += vboxwrappermod-common-src
     793vboxwrappermod-common-src_INST = bin/src/common/
     794vboxwrappermod-common-src_SOURCES = \
    795795        linux/SUPWrapperMod-linux.c=>SUPWrapperMod-linux.c \
    796         linux/Makefile-vbox_vmmr0.gmk=>Makefile \
    797796        linux/Makefile-wrapper.gmk=>Makefile-wrapper.gmk \
    798        $(PATH_ROOT)/src/VBox/Installer/linux/Makefile-header.gmk=>Makefile-header.gmk \
    799        $(PATH_ROOT)/src/VBox/Installer/linux/Makefile-footer.gmk=>Makefile-footer.gmk \
    800         $(PATH_OBJ)/VMMR0/VMMR0.r0=>VMMR0.r0 \
    801         $(PATH_OBJ)/VMMR0/VMMR0.debug=>VMMR0.debug \
    802 
    803 INSTALLS.linux += vbox_vboxddr0-src
    804 vbox_vboxddr0-src_INST = bin/src/vbox_vboxddr0/
    805 vbox_vboxddr0-src_SOURCES = \
    806         linux/SUPWrapperMod-linux.c=>SUPWrapperMod-linux.c \
    807         linux/Makefile-vbox_vboxddr0.gmk=>Makefile \
    808         linux/Makefile-wrapper.gmk=>Makefile-wrapper.gmk \
    809        $(PATH_ROOT)/src/VBox/Installer/linux/Makefile-header.gmk=>Makefile-header.gmk \
    810        $(PATH_ROOT)/src/VBox/Installer/linux/Makefile-footer.gmk=>Makefile-footer.gmk \
    811         $(PATH_OBJ)/VBoxDDR0/VBoxDDR0.r0=>VBoxDDR0.r0 \
    812         $(PATH_OBJ)/VBoxDDR0/VBoxDDR0.debug=>VBoxDDR0.debug \
    813 
     797        $(PATH_ROOT)/src/VBox/Installer/linux/Makefile-header.gmk=>Makefile-header.gmk \
     798        $(PATH_ROOT)/src/VBox/Installer/linux/Makefile-footer.gmk=>Makefile-footer.gmk
    814799  endif
     800
    815801 endif # supported host arch
    816802endif # linux freebsd
  • trunk/src/VBox/HostDrivers/Support/linux/Makefile-vbox_vboxddr0.gmk

    r87700 r87728  
    3030WRAPPER_NEED_VMMR0   := yes
    3131
    32 include $(dir $(lastword $(MAKEFILE_LIST)))/Makefile-wrapper.gmk
     32include $(dir $(lastword $(MAKEFILE_LIST)))Makefile-wrapper.gmk
    3333
    3434
  • trunk/src/VBox/HostDrivers/Support/linux/Makefile-vbox_vmmr0.gmk

    r87700 r87728  
    3131WRAPPED_MODULE_LINUX_EXPORTS   := yes
    3232
    33 include $(dir $(lastword $(MAKEFILE_LIST)))/Makefile-wrapper.gmk
     33include $(dir $(lastword $(MAKEFILE_LIST)))Makefile-wrapper.gmk
    3434
  • trunk/src/VBox/HostDrivers/Support/linux/Makefile-wrapper.gmk

    r87700 r87728  
    3535
    3636# Linux kbuild sets this to our source directory if we are called from there
    37 obj ?= $(CURDIR)
    38 include $(obj)/Makefile-header.gmk
    39 VBOXDRV_DIR     := $(abspath $(VBOX_MODULE_SRC_DIR)../vboxdrv/)/
    40 VBOX_VMMR0_DIR  := $(abspath $(VBOX_MODULE_SRC_DIR)../vbox_vmmr0/)/
     37ifndef VBOX_MODULE_SRC_DIR
     38 VBOX_MODULE_SRC_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))/
     39endif
     40VBOXDRV_DIR          := $(abspath $(VBOX_MODULE_SRC_DIR)../vboxdrv/)/
     41VBOX_VMMR0_DIR       := $(abspath $(VBOX_MODULE_SRC_DIR)../vbox_vmmr0/)/
     42include $(VBOXDRV_DIR)Makefile-header.gmk
    4143
    4244# All of these wrappers depend on
     
    4749 endif
    4850endif
    49 $(warning KBUILD_EXTRA_SYMBOLS=$(KBUILD_EXTRA_SYMBOLS) WRAPPER_NEED_VMMR0=$(WRAPPER_NEED_VMMR0))
    5051
    5152VBOXMOD_OBJS = \
     
    6667       \
    6768        WRAPPED_MODULE_NAME=\"$(WRAPPED_MODULE_NAME).r0\" \
    68         WRAPPED_MODULE_SYMBOL_INCLUDE=\"$(WRAPPED_MODULE_NAME)-symbols.h\" \
    69         WRAPPER_MODULE_KMOD_NAME=\"$(VBOXMOD_NAME)\"
     69        WRAPPED_MODULE_SYMBOL_INCLUDE=\"$(WRAPPED_MODULE_NAME)-symbols.h\"
    7070ifdef WRAPPED_MODULE_FLAGS
    7171VBOXMOD_DEFS += WRAPPED_MODULE_FLAGS="$(WRAPPED_MODULE_FLAGS)"
     
    8787VBOXMOD_DEFS += WRAPPED_MODULE_TERM=NULL
    8888endif
     89ifdef WRAPPED_MODULE_LICENSE_PROPRIETARY
     90VBOXMOD_DEFS += WRAPPED_MODULE_LICENSE_PROPRIETARY
     91endif
    8992
    9093VBOXMOD_CFLAGS = -include $(VBOXDRV_DIR)include/VBox/SUPDrvMangling.h \
     
    9396## @todo cleanup
    9497
    95 include $(obj)/Makefile-footer.gmk
     98include $(VBOXDRV_DIR)Makefile-footer.gmk
    9699
    97100
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r87700 r87728  
    758758 * with device extension prepended to the argument list.
    759759 */
    760 SUPR0DECL(int)  SUPDrvLinuxLdrRegisterWrappedModule(PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void *pvLnxModule, void **phMod)
    761 {
    762     AssertPtrReturn(pvLnxModule, VERR_INVALID_POINTER);
    763     return supdrvLdrRegisterWrappedModule(&g_DevExt, pWrappedModInfo, pvLnxModule, phMod);
     760SUPR0DECL(int)  SUPDrvLinuxLdrRegisterWrappedModule(PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
     761                                                    const char *pszLnxModName, void **phMod)
     762{
     763    /* Locate the module structure for the caller so can later reference
     764       and dereference it to prevent unloading while it is being used.
     765
     766       Before Linux v5.9 this could be done by address (__module_address()
     767       or __module_text_address()), but someone (guess who) apparently on
     768       a mission to make life miserable for out-of-tree modules or something,
     769       decided it was only used by build-in code and unexported both of them.
     770
     771       I could find no init callouts getting a struct module pointer either,
     772       nor any module name hint anywhere I could see.  So, we're left with
     773       hardcoding the module name via the compiler and pass it along to
     774       SUPDrv so we can call find_module() here.
     775
     776       Sigh^2. */
     777    AssertPtrReturn(pszLnxModName, VERR_INVALID_POINTER);
     778    AssertReturn(*pszLnxModName, VERR_INVALID_NAME);
     779    struct module *pLnxModule = find_module(pszLnxModName);
     780    if (pLnxModule)
     781        return supdrvLdrRegisterWrappedModule(&g_DevExt, pWrappedModInfo, pLnxModule, phMod);
     782    printk("vboxdrv: find_module(%s) failed in SUPDrvLinuxLdrRegisterWrappedModule!\n", pszLnxModName);
     783    return VERR_MODULE_NOT_FOUND;
    764784}
    765785EXPORT_SYMBOL(SUPDrvLinuxLdrRegisterWrappedModule);
  • trunk/src/VBox/HostDrivers/Support/linux/SUPWrapperMod-linux.c

    r87708 r87728  
    168168static int __init VBoxWrapperModInit(void)
    169169{
    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. */
    182170    /*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");
     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);
    193175    return -EINVAL;
    194176}
  • trunk/src/VBox/HostDrivers/linux/Makefile

    r85943 r87728  
    3030
    3131obj-m = vboxdrv/
    32 ifneq ($(wildcard $(CURDIR)/vboxnetflt/Makefile),)
    33  obj-m += vboxnetflt/
    34 endif
    35 ifneq ($(wildcard $(CURDIR)/vboxnetadp/Makefile),)
    36  obj-m += vboxnetadp/
    37 endif
    38 ifneq ($(wildcard $(CURDIR)/vboxpci/Makefile),)
    39  obj-m += vboxpci/
    40 endif
     32 ifneq ($(wildcard $(CURDIR)/vboxnetflt/Makefile),)
     33obj-m += vboxnetflt/
     34 endif
     35 ifneq ($(wildcard $(CURDIR)/vboxnetadp/Makefile),)
     36obj-m += vboxnetadp/
     37 endif
     38 ifneq ($(wildcard $(CURDIR)/vboxpci/Makefile),)
     39obj-m += vboxpci/
     40 endif
    4141
    4242else # ! KERNELRELEASE
     
    4545
    4646KBUILD_VERBOSE ?=
    47 KERN_VER ?= $(shell uname -r)
    4847.PHONY: all install clean check unload load \
    4948    vboxdrv vboxnetflt vboxnetadp vboxpci \
     
    5453
    5554# We want to build on Linux 2.6.18 and later kernels.
    56 ifneq ($(filter-out 1.% 2.0.% 2.1.% 2.2.% 2.3.% 2.4.% 2.5.%,$(KERN_VER)),)
     55KERN_VER ?= $(shell uname -r)
     56 ifneq ($(filter-out 1.% 2.0.% 2.1.% 2.2.% 2.3.% 2.4.% 2.5.%,$(KERN_VER)),)
    5757
    5858vboxdrv:
     
    115115install: install-vboxdrv install-vboxnetflt install-vboxnetadp install-vboxpci
    116116
    117 else
     117# Look for wrapper modules, sorting them so vmmr0 is first.
     118VBOX_WRAPPER_DIRS := $(notdir $(wildcard $(CURDIR)/vbox_*))
     119  ifneq ($(VBOX_WRAPPER_DIRS),)
     120VBOX_WRAPPER_DIRS := $(filter vbox_vmmr0,$(VBOX_WRAPPER_DIRS)) $(sort $(filter-out vbox_vmmr0,$(VBOX_WRAPPER_DIRS)))
     121  endif
     122  define wrapper_template
     123$(wrapper): $(subst $(wrapper),,vbox_vmmr0)
     124        $$(MAKE) KBUILD_VERBOSE=$$(KBUILD_VERBOSE) -C $(wrapper)/
     125
     126load-$(wrapper): $(if $(eq $(wrapper),vbox_vmmr0),,load-vbox_vmmr0)
     127        @if ! grep -q "^$(wrapper) " /proc/modules; then \
     128        echo "Loading $(wrapper)..."; \
     129                /sbin/insmod $(wrapper)/$(wrapper).ko; \
     130        else \
     131        echo "Skipping loading $(wrapper) module (already loaded)."; \
     132        fi
     133
     134unload-$(wrapper):
     135        @if grep -q "^$(wrapper) " /proc/modules; then \
     136        echo "Unloading $(wrapper)..."; \
     137                /sbin/rmmod $(wrapper)/$(wrapper).ko; \
     138        fi
     139  endef
     140$(foreach wrapper,$(VBOX_WRAPPER_DIRS), $(eval $(wrapper_template)))
     141
     142wrappers:       $(VBOX_WRAPPER_DIRS)
     143load-wrappers: $(addprefix load-,$(VBOX_WRAPPER_DIRS))
     144unload-wrappers:
     145        @for module in $(filter-out vbox_vmmr0,$(VBOX_WRAPPER_DIRS)) $(filter vbox_vmmr0,$(VBOX_WRAPPER_DIRS)); \
     146        do \
     147                if grep -q "^$${module} " /proc/modules; then \
     148                        echo "Unloading $${module}..."; \
     149                if \
     150        done
     151
     152buildid:
     153        @for module in $(foreach module,vboxdrv vboxnetflt vboxnetadp $(VBOX_WRAPPER_DIRS),$(module)/$(module).ko); \
     154        do \
     155                buildid=`readelf -n $${module} | sed -ne 's/^.*Build ID: *\([[:xdigit:]][[:xdigit:]]\)\(.*\)$$/\1\/\2/p' `; \
     156                if [ -n "$${buildid}" ]; then \
     157                        mkdir -p ~/.debug/.build-id/`dirname $${buildid}`; \
     158                        ln -sfn -- "$(CURDIR)/$${module}" ~/.debug/.build-id/$${buildid}; \
     159                else \
     160                        echo "warning: No build ID for $${module}}"; \
     161                fi \
     162        done
     163
     164.PHONY: wrappers load-wrappers unload-wrappers buildid $(VBOX_WRAPPER_DIRS) \
     165        $(addprefix load-,$(VBOX_WRAPPER_DIRS)) $(addprefix unload-,$(VBOX_WRAPPER_DIRS))
     166
     167 else # Too old:
     168
     169VBOX_WRAPPER_DIRS :=
    118170
    119171vboxdrv:
     
    122174vboxpci:
    123175install:
    124 
    125 endif
     176wrappers:
     177load-wrappers:
     178unload-wrappers:
     179buildid-wrappers:
     180
     181 endif
    126182
    127183clean-vboxdrv:
     
    169225
    170226endif # ! KERNELRELEASE
     227
Note: See TracChangeset for help on using the changeset viewer.

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