VirtualBox

Changeset 87700 in vbox


Ignore:
Timestamp:
Feb 10, 2021 8:21:04 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142743
Message:

SUPDrv,++: Experimental support for wrapping .r0 modules in native kernel modules on linux, so that perf and similar tools work better. Minor IOC version increase as SUP_IOCTL_LDR_OPEN now support just opening a module w/o preparing the loading. SUPDrv must export all the symbols in g_aFunctions the linux way now, or linux won't see them, so introduced a SUPR0_EXPORT_SYMBOL macro similar to RT_EXPORT_SYMBOL. bugref:9937

Location:
trunk
Files:
5 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Config.kmk

    r87668 r87700  
    47334733 TEMPLATE_VBoxR0_LD_DEBUG           = split
    47344734 endif
    4735  if1of ($(KBUILD_TARGET), linux)
     4735 if "$(KBUILD_TARGET)" == "linux" && !defined(VBOX_WITH_KMOD_WRAPPED_R0_MODS)
    47364736VBOX_WITH_VBOXR0_AS_DLL = 1
    47374737TEMPLATE_VBoxR0_DLLSUFF             = .r0
     
    47444744TEMPLATE_VBoxR0_CFLAGS.amd64       += -mcmodel=kernel
    47454745TEMPLATE_VBoxR0_CXXFLAGS.amd64     += -mcmodel=kernel
     4746 endif
     4747 ifdef VBOX_WITH_KMOD_WRAPPED_R0_MODS
     4748TEMPLATE_VBoxR0_DEFS               += VBOX_WITH_KMOD_WRAPPED_R0_MODS
     4749TEMPLATE_VBoxR0_LDFLAGS.linux      += $(PATH_ROOT)/src/VBox/HostDrivers/Support/linux/VBoxR0-wrapped.lds
     4750TEMPLATE_VBoxR0_LNK_DEPS.linux     += $(PATH_ROOT)/src/VBox/HostDrivers/Support/linux/VBoxR0-wrapped.lds
    47464751 endif
    47474752 ifn1of ($(KBUILD_TARGET),solaris freebsd)
  • trunk/include/VBox/sup.h

    r87542 r87700  
    606606extern DECLEXPORT(PSUPGLOBALINFOPAGE)   g_pSUPGlobalInfoPage;
    607607
    608 #elif !defined(IN_RING0) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS)
     608#elif !defined(IN_RING0) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(VBOX_WITH_KMOD_WRAPPED_R0_MODS)
    609609extern DECLIMPORT(PSUPGLOBALINFOPAGE)   g_pSUPGlobalInfoPage;
    610610
     
    20062006typedef FNSUPDRVDESTRUCTOR *PFNSUPDRVDESTRUCTOR;
    20072007
     2008/**
     2009 * Service request callback function.
     2010 *
     2011 * @returns VBox status code.
     2012 * @param   pSession    The caller's session.
     2013 * @param   uOperation  The operation identifier.
     2014 * @param   u64Arg      64-bit integer argument.
     2015 * @param   pReqHdr     The request header. Input / Output. Optional.
     2016 */
     2017typedef DECLCALLBACKTYPE(int, FNSUPR0SERVICEREQHANDLER,(PSUPDRVSESSION pSession, uint32_t uOperation,
     2018                                                        uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr));
     2019/** Pointer to a FNR0SERVICEREQHANDLER(). */
     2020typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
     2021
     2022/**
     2023 * Symbol entry for a wrapped module (SUPLDRWRAPPEDMODULE).
     2024 */
     2025typedef struct SUPLDRWRAPMODSYMBOL
     2026{
     2027    /** The symbol namel. */
     2028    const char *pszSymbol;
     2029    /** The symbol address/value. */
     2030    PFNRT       pfnValue;
     2031} SUPLDRWRAPMODSYMBOL;
     2032/** Pointer to a symbol entry for a wrapped module. */
     2033typedef SUPLDRWRAPMODSYMBOL const *PCSUPLDRWRAPMODSYMBOL;
     2034
     2035/**
     2036 * Registration structure for SUPR0LdrRegisterWrapperModule.
     2037 *
     2038 * This is used to register a .r0 module when loaded manually as a native kernel
     2039 * module/extension/driver/whatever.
     2040 */
     2041typedef struct SUPLDRWRAPPEDMODULE
     2042{
     2043    /** Magic value (SUPLDRWRAPPEDMODULE_MAGIC). */
     2044    uint32_t                    uMagic;
     2045    /** The structure version. */
     2046    uint16_t                    uVersion;
     2047    /** SUPLDRWRAPPEDMODULE_F_XXX.   */
     2048    uint16_t                    fFlags;
     2049
     2050    /** As close as possible to the start of the image. */
     2051    void                       *pvImageStart;
     2052    /** As close as possible to the end of the image. */
     2053    void                       *pvImageEnd;
     2054
     2055    /** @name Standar entry points
     2056     * @{ */
     2057    /** Pointer to the module initialization function (optional). */
     2058    DECLCALLBACKMEMBER(int,     pfnModuleInit,(void *hMod));
     2059    /** Pointer to the module termination function (optional). */
     2060    DECLCALLBACKMEMBER(void,    pfnModuleTerm,(void *hMod));
     2061    /** The VMMR0EntryFast entry point for VMMR0. */
     2062    PFNRT                       pfnVMMR0EntryFast;
     2063    /** The VMMR0EntryEx entry point for VMMR0. */
     2064    PFNRT                       pfnVMMR0EntryEx;
     2065    /** The service request handler entry point. */
     2066    PFNSUPR0SERVICEREQHANDLER   pfnServiceReqHandler;
     2067    /** @} */
     2068
     2069    /** The symbol table. */
     2070    PCSUPLDRWRAPMODSYMBOL       paSymbols;
     2071    /** Number of symbols. */
     2072    uint32_t                    cSymbols;
     2073
     2074    /** The normal VBox module name. */
     2075    char                        szName[32];
     2076    /** Repeating the magic value here (SUPLDRWRAPPEDMODULE_MAGIC). */
     2077    uint32_t                    uEndMagic;
     2078} SUPLDRWRAPPEDMODULE;
     2079/** Pointer to the wrapped module registration structure. */
     2080typedef SUPLDRWRAPPEDMODULE const *PCSUPLDRWRAPPEDMODULE;
     2081
     2082/** Magic value for the wrapped module structure (Doris lessing). */
     2083#define SUPLDRWRAPPEDMODULE_MAGIC       UINT32_C(0x19191117)
     2084/** Current SUPLDRWRAPPEDMODULE structure version. */
     2085#define SUPLDRWRAPPEDMODULE_VERSION     UINT16_C(0x0001)
     2086
     2087/** Set if this is the VMMR0 module.   */
     2088#define SUPLDRWRAPPEDMODULE_F_VMMR0     UINT16_C(0x0001)
     2089
     2090
    20082091SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2);
    20092092SUPR0DECL(int) SUPR0ObjAddRef(void *pvObj, PSUPDRVSESSION pSession);
     
    20362119SUPR0DECL(int) SUPR0LdrModRetain(PSUPDRVSESSION pSession, void *hMod);
    20372120SUPR0DECL(int) SUPR0LdrModRelease(PSUPDRVSESSION pSession, void *hMod);
     2121#ifdef RT_OS_LINUX
     2122SUPR0DECL(int) SUPDrvLinuxLdrRegisterWrappedModule(PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void *pvLnxModule, void **phMod);
     2123SUPR0DECL(int) SUPDrvLinuxLdrDeregisterWrappedModule(PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod);
     2124#endif
    20382125SUPR0DECL(int) SUPR0GetVTSupport(uint32_t *pfCaps);
    20392126SUPR0DECL(int) SUPR0GetHwvirtMsrs(PSUPHWVIRTMSRS pMsrs, uint32_t fCaps, bool fForce);
     
    24582545
    24592546
    2460 /**
    2461  * Service request callback function.
    2462  *
    2463  * @returns VBox status code.
    2464  * @param   pSession    The caller's session.
    2465  * @param   uOperation  The operation identifier.
    2466  * @param   u64Arg      64-bit integer argument.
    2467  * @param   pReqHdr     The request header. Input / Output. Optional.
    2468  */
    2469 typedef DECLCALLBACKTYPE(int, FNSUPR0SERVICEREQHANDLER,(PSUPDRVSESSION pSession, uint32_t uOperation,
    2470                                                         uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr));
    2471 /** Pointer to a FNR0SERVICEREQHANDLER(). */
    2472 typedef R0PTRTYPE(FNSUPR0SERVICEREQHANDLER *) PFNSUPR0SERVICEREQHANDLER;
    2473 
    2474 
    24752547/** @defgroup   grp_sup_r0_idc  The IDC Interface
    24762548 * @{
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r87646 r87700  
    749749if1of ($(KBUILD_TARGET), linux freebsd)
    750750 if1of ($(KBUILD_TARGET_ARCH), $(VBOX_SUPPORTED_HOST_ARCHS))
    751  #
    752  # Targets for installing the linux sources.
    753  #
    754  vboxdrv-src_INST    = bin/src/vboxdrv/
    755  vboxdrv-src_SOURCES = \
    756         $(subst $(DQUOTE),,$(FILES_VBOXDRV_NOBIN)) \
    757         $(vboxdrv-src_0_OUTDIR)/Makefile
    758  vboxdrv-src_EXEC_SOURCES  = \
    759         $(subst $(DQUOTE),,$(FILES_VBOXDRV_BIN))
    760  vboxdrv-src_CLEAN   = \
    761         $(vboxdrv-src_0_OUTDIR)/Makefile \
    762         $(PATH_TARGET)/vboxdrv-src-1.dep \
    763 
    764  # Scripts needed for building the kernel modules
    765  includedep $(PATH_TARGET)/vboxdrv-src-1.dep
    766  $$(vboxdrv-src_0_OUTDIR)/Makefile: \
     751#
     752# Targets for installing the linux sources.
     753#
     754vboxdrv-src_INST    = bin/src/vboxdrv/
     755vboxdrv-src_SOURCES = \
     756        $(subst $(DQUOTE),,$(FILES_VBOXDRV_NOBIN)) \
     757        $(vboxdrv-src_0_OUTDIR)/Makefile
     758vboxdrv-src_EXEC_SOURCES  = \
     759        $(subst $(DQUOTE),,$(FILES_VBOXDRV_BIN))
     760vboxdrv-src_CLEAN   = \
     761        $(vboxdrv-src_0_OUTDIR)/Makefile \
     762        $(PATH_TARGET)/vboxdrv-src-1.dep \
     763
     764# Scripts needed for building the kernel modules
     765includedep $(PATH_TARGET)/vboxdrv-src-1.dep
     766$$(vboxdrv-src_0_OUTDIR)/Makefile: \
    767767                $(PATH_SUB_CURRENT)/$(KBUILD_TARGET)/Makefile \
    768768                $$(if $$(eq $$(Support/$(KBUILD_TARGET)/Makefile_VBOX_HARDENED),$$(VBOX_WITH_HARDENING)),,FORCE) \
     
    781781                'Support/$(KBUILD_TARGET)/Makefile_VBOX_RAM_IN_KERNEL=$(VBOX_WITH_RAM_IN_KERNEL)'
    782782
    783  #
    784  # Build test for the linux host kernel modules.
    785  #
    786  $(evalcall2 VBOX_LINUX_KMOD_TEST_BUILD_RULE_FN,vboxdrv-src,,save_symvers)
     783#
     784# Build test for the linux host kernel modules.
     785#
     786$(evalcall2 VBOX_LINUX_KMOD_TEST_BUILD_RULE_FN,vboxdrv-src,,save_symvers)
     787
     788  ifdef VBOX_WITH_KMOD_WRAPPED_R0_MODS
     789#
     790# The wrapper modules.
     791#
     792INSTALLS.linux += vbox_vmmr0-src
     793vbox_vmmr0-src_INST = bin/src/vbox_vmmr0/
     794vbox_vmmr0-src_SOURCES = \
     795        linux/SUPWrapperMod-linux.c=>SUPWrapperMod-linux.c \
     796        linux/Makefile-vbox_vmmr0.gmk=>Makefile \
     797        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
     803INSTALLS.linux += vbox_vboxddr0-src
     804vbox_vboxddr0-src_INST = bin/src/vbox_vboxddr0/
     805vbox_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
     814  endif
    787815 endif # supported host arch
    788816endif # linux freebsd
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.cpp

    r87542 r87700  
    140140static int                  supdrvIOCtl_LdrQuerySymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq);
    141141static int                  supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq);
    142 static int                  supdrvLdrSetVMMR0EPs(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx);
    143 static void                 supdrvLdrUnsetVMMR0EPs(PSUPDRVDEVEXT pDevExt);
    144 static int                  supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage, bool fRing3Usage);
     142static int                  supdrvLdrAddUsage(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage, bool fRing3Usage);
     143DECLINLINE(void)            supdrvLdrSubtractUsage(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, uint32_t cReference);
    145144static void                 supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
    146145DECLINLINE(int)             supdrvLdrLock(PSUPDRVDEVEXT pDevExt);
     
    10791078            PSUPDRVLDRIMAGE pImage = pUsage->pImage;
    10801079            uint32_t        cUsage = pUsage->cRing0Usage + pUsage->cRing3Usage;
    1081             if (pImage->cUsage > cUsage)
    1082                 pImage->cUsage -= cUsage;
     1080            if (pImage->cImgUsage > cUsage)
     1081                supdrvLdrSubtractUsage(pDevExt, pImage, cUsage);
    10831082            else
    10841083                supdrvLdrFree(pDevExt, pImage);
     
    17331732            PSUPLDROPEN pReq = (PSUPLDROPEN)pReqHdr;
    17341733            REQ_CHECK_SIZES(SUP_IOCTL_LDR_OPEN);
    1735             REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageWithEverything > 0);
    1736             REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageWithEverything < 16*_1M);
    1737             REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageBits > 0);
    1738             REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageBits < pReq->u.In.cbImageWithEverything);
     1734            if (   pReq->u.In.cbImageWithEverything != 0
     1735                || pReq->u.In.cbImageBits != 0)
     1736            {
     1737                REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageWithEverything > 0);
     1738                REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageWithEverything < 16*_1M);
     1739                REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageBits > 0);
     1740                REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImageBits < pReq->u.In.cbImageWithEverything);
     1741            }
    17391742            REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.szName[0]);
    17401743            REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, RTStrEnd(pReq->u.In.szName, sizeof(pReq->u.In.szName)));
     
    28012804SUPR0DECL(void *) SUPR0ObjRegister(PSUPDRVSESSION pSession, SUPDRVOBJTYPE enmType, PFNSUPDRVDESTRUCTOR pfnDestructor, void *pvUser1, void *pvUser2)
    28022805{
    2803     PSUPDRVDEVEXT   pDevExt     = pSession->pDevExt;
     2806    PSUPDRVDEVEXT   pDevExt = pSession->pDevExt;
    28042807    PSUPDRVOBJ      pObj;
    28052808    PSUPDRVUSAGE    pUsage;
     
    28702873    return pObj;
    28712874}
     2875SUPR0_EXPORT_SYMBOL(SUPR0ObjRegister);
    28722876
    28732877
     
    28882892    return SUPR0ObjAddRefEx(pvObj, pSession, false /* fNoBlocking */);
    28892893}
     2894SUPR0_EXPORT_SYMBOL(SUPR0ObjAddRef);
    28902895
    28912896
     
    30073012    return rc;
    30083013}
     3014SUPR0_EXPORT_SYMBOL(SUPR0ObjAddRefEx);
    30093015
    30103016
     
    31163122    return rc;
    31173123}
     3124SUPR0_EXPORT_SYMBOL(SUPR0ObjRelease);
    31183125
    31193126
     
    31613168    return VERR_PERMISSION_DENIED;
    31623169}
     3170SUPR0_EXPORT_SYMBOL(SUPR0ObjVerifyAccess);
    31633171
    31643172
     
    31743182    return pSession->pSessionVM;
    31753183}
     3184SUPR0_EXPORT_SYMBOL(SUPR0GetSessionVM);
    31763185
    31773186
     
    31873196    return pSession->pSessionGVM;
    31883197}
     3198SUPR0_EXPORT_SYMBOL(SUPR0GetSessionGVM);
    31893199
    31903200
     
    32383248    return VINF_SUCCESS;
    32393249}
     3250SUPR0_EXPORT_SYMBOL(SUPR0SetSessionVM);
    32403251
    32413252
     
    32463257    return RTLogGetDefaultInstanceEx(fFlagsAndGroup);
    32473258}
     3259SUPR0_EXPORT_SYMBOL(SUPR0GetDefaultLogInstanceEx);
    32483260
    32493261
     
    32543266    return RTLogRelGetDefaultInstanceEx(fFlagsAndGroup);
    32553267}
     3268SUPR0_EXPORT_SYMBOL(SUPR0GetDefaultLogRelInstanceEx);
    32563269
    32573270
     
    33173330    return rc;
    33183331}
     3332SUPR0_EXPORT_SYMBOL(SUPR0LockMem);
    33193333
    33203334
     
    33323346    return supdrvMemRelease(pSession, (RTHCUINTPTR)pvR3, MEMREF_TYPE_LOCKED);
    33333347}
     3348SUPR0_EXPORT_SYMBOL(SUPR0UnlockMem);
    33343349
    33353350
     
    33983413    return rc;
    33993414}
     3415SUPR0_EXPORT_SYMBOL(SUPR0ContAlloc);
    34003416
    34013417
     
    34133429    return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_CONT);
    34143430}
     3431SUPR0_EXPORT_SYMBOL(SUPR0ContFree);
    34153432
    34163433
     
    34863503    return rc;
    34873504}
     3505SUPR0_EXPORT_SYMBOL(SUPR0LowAlloc);
    34883506
    34893507
     
    35013519    return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_LOW);
    35023520}
     3521SUPR0_EXPORT_SYMBOL(SUPR0LowFree);
    35033522
    35043523
     
    35623581    return rc;
    35633582}
     3583SUPR0_EXPORT_SYMBOL(SUPR0MemAlloc);
    35643584
    35653585
     
    36203640    return VERR_INVALID_PARAMETER;
    36213641}
     3642SUPR0_EXPORT_SYMBOL(SUPR0MemGetPhys);
    36223643
    36233644
     
    36353656    return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_MEM);
    36363657}
     3658SUPR0_EXPORT_SYMBOL(SUPR0MemFree);
    36373659
    36383660
     
    37183740    return rc;
    37193741}
     3742SUPR0_EXPORT_SYMBOL(SUPR0PageAllocEx);
    37203743
    37213744
     
    38033826    return rc;
    38043827}
     3828SUPR0_EXPORT_SYMBOL(SUPR0PageMapKernel);
    38053829
    38063830
     
    38923916
    38933917}
     3918SUPR0_EXPORT_SYMBOL(SUPR0PageProtect);
    38943919
    38953920
     
    39083933    return supdrvMemRelease(pSession, (RTHCUINTPTR)pvR3, MEMREF_TYPE_PAGE);
    39093934}
     3935SUPR0_EXPORT_SYMBOL(SUPR0PageFree);
    39103936
    39113937
     
    39683994    supdrvBadContext(pDevExt, pszFile, uLine, pszExtra);
    39693995}
     3996SUPR0_EXPORT_SYMBOL(SUPR0BadContext);
    39703997
    39713998
     
    40494076    return enmMode;
    40504077}
     4078SUPR0_EXPORT_SYMBOL(SUPR0GetPagingMode);
    40514079
    40524080
     
    40774105#endif
    40784106}
     4107SUPR0_EXPORT_SYMBOL(SUPR0ChangeCR4);
    40794108
    40804109
     
    40974126#endif
    40984127}
     4128SUPR0_EXPORT_SYMBOL(SUPR0EnableVTx);
    40994129
    41004130
     
    41144144#endif
    41154145}
     4146SUPR0_EXPORT_SYMBOL(SUPR0SuspendVTxOnCpu);
    41164147
    41174148
     
    41324163#endif
    41334164}
     4165SUPR0_EXPORT_SYMBOL(SUPR0ResumeVTxOnCpu);
    41344166
    41354167
     
    41434175#endif
    41444176}
     4177SUPR0_EXPORT_SYMBOL(SUPR0GetCurrentGdtRw);
    41454178
    41464179
     
    42094242    return VERR_UNSUPPORTED_CPU;
    42104243}
     4244SUPR0_EXPORT_SYMBOL(SUPR0GetVTSupport);
    42114245
    42124246
     
    43354369    return rc;
    43364370}
     4371SUPR0_EXPORT_SYMBOL(SUPR0GetVmxUsability);
    43374372
    43384373
     
    43824417    return rc;
    43834418}
     4419SUPR0_EXPORT_SYMBOL(SUPR0GetSvmUsability);
    43844420
    43854421
     
    45024538    return supdrvQueryVTCapsInternal(pfCaps);
    45034539}
     4540SUPR0_EXPORT_SYMBOL(SUPR0QueryVTCaps);
    45044541
    45054542
     
    45714608}
    45724609
     4610
    45734611/**
    45744612 * Queries the CPU microcode revision.
     
    45944632    return supdrvQueryUcodeRev(puRevision);
    45954633}
     4634SUPR0_EXPORT_SYMBOL(SUPR0QueryUcodeRev);
    45964635
    45974636
     
    46944733    return rc;
    46954734}
     4735SUPR0_EXPORT_SYMBOL(SUPR0GetHwvirtMsrs);
    46964736
    46974737
     
    47754815    return rc;
    47764816}
     4817SUPR0_EXPORT_SYMBOL(SUPR0ComponentRegisterFactory);
    47774818
    47784819
     
    48384879    return rc;
    48394880}
     4881SUPR0_EXPORT_SYMBOL(SUPR0ComponentDeregisterFactory);
    48404882
    48414883
     
    49084950    return rc;
    49094951}
     4952SUPR0_EXPORT_SYMBOL(SUPR0ComponentQueryFactory);
    49104953
    49114954
     
    50665109            &&  !memcmp(pImage->szName, pReq->u.In.szName, cchName))
    50675110        {
    5068             if (RT_LIKELY(pImage->cUsage < UINT32_MAX / 2U))
     5111            if (RT_LIKELY(pImage->cImgUsage < UINT32_MAX / 2U))
    50695112            {
    50705113                /** @todo check cbImageBits and cbImageWithEverything here, if they differs
    50715114                 *        that indicates that the images are different. */
    5072                 pImage->cUsage++;
    50735115                pReq->u.Out.pvImageBase   = pImage->pvImage;
    50745116                pReq->u.Out.fNeedsLoading = pImage->uState == SUP_IOCTL_LDR_OPEN;
    50755117                pReq->u.Out.fNativeLoader = pImage->fNative;
    5076                 supdrvLdrAddUsage(pSession, pImage, true /*fRing3Usage*/);
     5118                supdrvLdrAddUsage(pDevExt, pSession, pImage, true /*fRing3Usage*/);
    50775119                supdrvLdrUnlock(pDevExt);
    50785120                SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     
    50945136    }
    50955137
     5138    /* Stop if caller doesn't wish to prepare loading things. */
     5139    if (!pReq->u.In.cbImageBits)
     5140    {
     5141        supdrvLdrUnlock(pDevExt);
     5142        Log(("supdrvIOCtl_LdrOpen: Returning VERR_MODULE_NOT_FOUND for '%s'!\n", pReq->u.In.szName));
     5143        return VERR_MODULE_NOT_FOUND;
     5144    }
     5145
    50965146    /*
    50975147     * Allocate memory.
    50985148     */
    50995149    Assert(cchName < sizeof(pImage->szName));
    5100     pv = RTMemAlloc(sizeof(SUPDRVLDRIMAGE));
     5150    pv = RTMemAllocZ(sizeof(SUPDRVLDRIMAGE));
    51015151    if (!pv)
    51025152    {
    51035153        supdrvLdrUnlock(pDevExt);
    5104         Log(("supdrvIOCtl_LdrOpen: RTMemAlloc() failed\n"));
    5105         return /*VERR_NO_MEMORY*/ VERR_INTERNAL_ERROR_2;
     5154        Log(("supdrvIOCtl_LdrOpen: RTMemAllocZ() failed\n"));
     5155        return VERR_NO_MEMORY;
    51065156    }
    51075157    SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     
    51295179    pImage->pfnServiceReqHandler = NULL;
    51305180    pImage->uState          = SUP_IOCTL_LDR_OPEN;
    5131     pImage->cUsage          = 1;
     5181    pImage->cImgUsage       = 0; /* Increased by supdrvLdrAddUsage later */
    51325182    pImage->pDevExt         = pDevExt;
    51335183    pImage->pImageImport    = NULL;
    51345184    pImage->uMagic          = SUPDRVLDRIMAGE_MAGIC;
     5185    pImage->pWrappedModInfo = NULL;
    51355186    memcpy(pImage->szName, pReq->u.In.szName, cchName + 1);
    51365187
     
    51585209        SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
    51595210    }
     5211    if (RT_SUCCESS(rc))
     5212        rc = supdrvLdrAddUsage(pDevExt, pSession, pImage, true /*fRing3Usage*/);
    51605213    if (RT_FAILURE(rc))
    51615214    {
     
    51735226    pImage->pNext           = pDevExt->pLdrImages;
    51745227    pDevExt->pLdrImages     = pImage;
    5175 
    5176     supdrvLdrAddUsage(pSession, pImage, true /*fRing3Usage*/);
    51775228
    51785229    pReq->u.Out.pvImageBase   = pImage->pvImage;
     
    54035454            if (RT_FAILURE(rc))
    54045455                return rc;
     5456
     5457            /* Fail here if there is already a VMMR0 module. */
     5458            if (pDevExt->pvVMMR0 != NULL)
     5459            {
     5460                supdrvLdrUnlock(pDevExt);
     5461                return supdrvLdrLoadError(VERR_INVALID_PARAMETER, pReq, "There is already a VMMR0 module loaded (%p)", pDevExt->pvVMMR0);
     5462            }
    54055463            break;
    54065464
     
    54985556
    54995557    /*
    5500      * Update any entry points.
    5501      */
    5502     if (RT_SUCCESS(rc))
    5503     {
    5504         switch (pReq->u.In.eEPType)
    5505         {
    5506             default:
    5507             case SUPLDRLOADEP_NOTHING:
    5508                 rc = VINF_SUCCESS;
    5509                 break;
    5510             case SUPLDRLOADEP_VMMR0:
    5511                 rc = supdrvLdrSetVMMR0EPs(pDevExt, pReq->u.In.EP.VMMR0.pvVMMR0,
    5512                                           pReq->u.In.EP.VMMR0.pvVMMR0EntryFast, pReq->u.In.EP.VMMR0.pvVMMR0EntryEx);
    5513                 break;
    5514             case SUPLDRLOADEP_SERVICE:
    5515                 pImage->pfnServiceReqHandler = (PFNSUPR0SERVICEREQHANDLER)(uintptr_t)pReq->u.In.EP.Service.pfnServiceReq;
    5516                 rc = VINF_SUCCESS;
    5517                 break;
    5518         }
    5519     }
    5520 
    5521     /*
    55225558     * On success call the module initialization.
    55235559     */
     
    55345570        pDevExt->hLdrInitThread = NIL_RTNATIVETHREAD;
    55355571        if (RT_FAILURE(rc))
    5536         {
    5537             if (pDevExt->pvVMMR0 == pImage->pvImage)
    5538                 supdrvLdrUnsetVMMR0EPs(pDevExt);
    55395572            supdrvLdrLoadError(rc, pReq, "ModuleInit failed: %Rrc", rc);
    5540         }
    55415573    }
    55425574    if (RT_SUCCESS(rc))
    55435575    {
    5544         /* Increase the usage counter of any import image. */
     5576        /*
     5577         * Publish any standard entry points.
     5578         */
     5579        switch (pReq->u.In.eEPType)
     5580        {
     5581            case SUPLDRLOADEP_VMMR0:
     5582                Assert(!pDevExt->pvVMMR0);
     5583                Assert(!pDevExt->pfnVMMR0EntryFast);
     5584                Assert(!pDevExt->pfnVMMR0EntryEx);
     5585                ASMAtomicWritePtrVoid(&pDevExt->pvVMMR0, pImage->pvImage);
     5586                ASMAtomicWritePtrVoid((void * volatile *)(uintptr_t)&pDevExt->pfnVMMR0EntryFast,
     5587                                      (void *)(uintptr_t)  pReq->u.In.EP.VMMR0.pvVMMR0EntryFast);
     5588                ASMAtomicWritePtrVoid((void * volatile *)(uintptr_t)&pDevExt->pfnVMMR0EntryEx,
     5589                                      (void *)(uintptr_t)  pReq->u.In.EP.VMMR0.pvVMMR0EntryEx);
     5590                break;
     5591            case SUPLDRLOADEP_SERVICE:
     5592                pImage->pfnServiceReqHandler = (PFNSUPR0SERVICEREQHANDLER)(uintptr_t)pReq->u.In.EP.Service.pfnServiceReq;
     5593                break;
     5594            default:
     5595                break;
     5596        }
     5597
     5598        /*
     5599         * Increase the usage counter of any imported image.
     5600         */
    55455601        if (pImageImport)
    55465602        {
    5547             pImageImport->cUsage++;
     5603            pImageImport->cImgUsage++;
     5604            if (pImageImport->cImgUsage == 2 && pImageImport->pWrappedModInfo)
     5605                supdrvOSLdrRetainWrapperModule(pDevExt, pImageImport);
    55485606            pImage->pImageImport = pImageImport;
    55495607        }
    55505608
    5551         /* Done! */
     5609        /*
     5610         * Done!
     5611         */
    55525612        SUPR0Printf("vboxdrv: %RKv %s\n", pImage->pvImage, pImage->szName);
    55535613        pReq->u.Out.uErrorMagic = 0;
     
    55785638
    55795639/**
     5640 * Registers a .r0 module wrapped in a native one and manually loaded.
     5641 *
     5642 * @returns VINF_SUCCESS or error code (no info statuses).
     5643 * @param   pWrappedModInfo     The wrapped module info.
     5644 * @param   pvNative            OS specific information.
     5645 * @param   phMod               Where to store the module handle.
     5646 */
     5647int VBOXCALL supdrvLdrRegisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
     5648                                            void *pvNative, void **phMod)
     5649{
     5650    size_t                  cchName;
     5651    PSUPDRVLDRIMAGE         pImage;
     5652    PCSUPLDRWRAPMODSYMBOL   paSymbols;
     5653    uint16_t                idx;
     5654    const char             *pszPrevSymbol;
     5655    int                     rc;
     5656    SUPDRV_CHECK_SMAP_SETUP();
     5657    SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     5658
     5659    /*
     5660     * Validate input.
     5661     */
     5662    AssertPtrReturn(phMod, VERR_INVALID_POINTER);
     5663    *phMod = NULL;
     5664    AssertPtrReturn(pDevExt, VERR_INTERNAL_ERROR_2);
     5665
     5666    AssertPtrReturn(pWrappedModInfo, VERR_INVALID_POINTER);
     5667    AssertMsgReturn(pWrappedModInfo->uMagic == SUPLDRWRAPPEDMODULE_MAGIC,
     5668                    ("uMagic=%#x, expected %#x\n", pWrappedModInfo->uMagic, SUPLDRWRAPPEDMODULE_MAGIC),
     5669                    VERR_INVALID_MAGIC);
     5670    AssertMsgReturn(pWrappedModInfo->uVersion == SUPLDRWRAPPEDMODULE_VERSION,
     5671                    ("Unsupported uVersion=%#x, current version %#x\n", pWrappedModInfo->uVersion, SUPLDRWRAPPEDMODULE_VERSION),
     5672                    VERR_VERSION_MISMATCH);
     5673    AssertMsgReturn(pWrappedModInfo->uEndMagic == SUPLDRWRAPPEDMODULE_MAGIC,
     5674                    ("uEndMagic=%#x, expected %#x\n", pWrappedModInfo->uEndMagic, SUPLDRWRAPPEDMODULE_MAGIC),
     5675                    VERR_INVALID_MAGIC);
     5676    AssertMsgReturn(pWrappedModInfo->fFlags <= SUPLDRWRAPPEDMODULE_F_VMMR0, ("Unknown flags in: %#x\n", pWrappedModInfo->fFlags),
     5677                    VERR_INVALID_FLAGS);
     5678
     5679    /* szName: */
     5680    AssertReturn(RTStrEnd(pWrappedModInfo->szName, sizeof(pWrappedModInfo->szName)) != NULL, VERR_INVALID_NAME);
     5681    AssertReturn(supdrvIsLdrModuleNameValid(pWrappedModInfo->szName), VERR_INVALID_NAME);
     5682    AssertCompile(sizeof(pImage->szName) == sizeof(pWrappedModInfo->szName));
     5683    cchName = strlen(pWrappedModInfo->szName);
     5684
     5685    /* Image range: */
     5686    AssertPtrReturn(pWrappedModInfo->pvImageStart, VERR_INVALID_POINTER);
     5687    AssertPtrReturn(pWrappedModInfo->pvImageEnd, VERR_INVALID_POINTER);
     5688    AssertReturn((uintptr_t)pWrappedModInfo->pvImageEnd > (uintptr_t)pWrappedModInfo->pvImageStart, VERR_INVALID_PARAMETER);
     5689
     5690    /* Symbol table: */
     5691    AssertMsgReturn(pWrappedModInfo->cSymbols <= _8K, ("Too many symbols: %u, max 8192\n", pWrappedModInfo->cSymbols),
     5692                    VERR_TOO_MANY_SYMLINKS);
     5693    pszPrevSymbol = "\x7f";
     5694    paSymbols = pWrappedModInfo->paSymbols;
     5695    idx = pWrappedModInfo->cSymbols;
     5696    while (idx-- > 0)
     5697    {
     5698        const char *pszSymbol = paSymbols[idx].pszSymbol;
     5699        AssertMsgReturn(RT_VALID_PTR(pszSymbol) && RT_VALID_PTR(paSymbols[idx].pfnValue),
     5700                        ("paSymbols[%u]: %p/%p\n", idx, pszSymbol, paSymbols[idx].pfnValue),
     5701                        VERR_INVALID_POINTER);
     5702        AssertReturn(*pszSymbol != '\0', VERR_EMPTY_STRING);
     5703        AssertMsgReturn(strcmp(pszSymbol, pszPrevSymbol) < 0,
     5704                        ("symbol table out of order at index %u: '%s' vs '%s'\n", idx, pszSymbol, pszPrevSymbol),
     5705                        VERR_WRONG_ORDER);
     5706        pszPrevSymbol = pszSymbol;
     5707    }
     5708
     5709    /* Standard entry points: */
     5710    AssertPtrNullReturn(pWrappedModInfo->pfnModuleInit, VERR_INVALID_POINTER);
     5711    AssertPtrNullReturn(pWrappedModInfo->pfnModuleTerm, VERR_INVALID_POINTER);
     5712    AssertReturn((uintptr_t)pWrappedModInfo->pfnModuleInit != (uintptr_t)pWrappedModInfo->pfnModuleTerm || pWrappedModInfo->pfnModuleInit == NULL,
     5713                 VERR_INVALID_PARAMETER);
     5714    if (pWrappedModInfo->fFlags & SUPLDRWRAPPEDMODULE_F_VMMR0)
     5715    {
     5716        AssertReturn(pWrappedModInfo->pfnServiceReqHandler == NULL, VERR_INVALID_PARAMETER);
     5717        AssertPtrReturn(pWrappedModInfo->pfnVMMR0EntryFast, VERR_INVALID_POINTER);
     5718        AssertPtrReturn(pWrappedModInfo->pfnVMMR0EntryEx, VERR_INVALID_POINTER);
     5719        AssertReturn(pWrappedModInfo->pfnVMMR0EntryFast != pWrappedModInfo->pfnVMMR0EntryEx, VERR_INVALID_PARAMETER);
     5720    }
     5721    else
     5722    {
     5723        AssertPtrNullReturn(pWrappedModInfo->pfnServiceReqHandler, VERR_INVALID_POINTER);
     5724        AssertReturn(pWrappedModInfo->pfnVMMR0EntryFast == NULL, VERR_INVALID_PARAMETER);
     5725        AssertReturn(pWrappedModInfo->pfnVMMR0EntryEx   == NULL, VERR_INVALID_PARAMETER);
     5726    }
     5727
     5728    /*
     5729     * Check if we got an instance of the image already.
     5730     */
     5731    supdrvLdrLock(pDevExt);
     5732    SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     5733    for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext)
     5734    {
     5735        if (   pImage->szName[cchName] == '\0'
     5736            && !memcmp(pImage->szName, pWrappedModInfo->szName, cchName))
     5737        {
     5738            supdrvLdrUnlock(pDevExt);
     5739            Log(("supdrvLdrRegisterWrappedModule: '%s' already loaded!\n", pWrappedModInfo->szName));
     5740            return VERR_ALREADY_LOADED;
     5741        }
     5742    }
     5743    /* (not found - add it!) */
     5744
     5745    /* If the loader interface is locked down, make userland fail early */
     5746    if (pDevExt->fLdrLockedDown)
     5747    {
     5748        supdrvLdrUnlock(pDevExt);
     5749        Log(("supdrvLdrRegisterWrappedModule: Not adding '%s' to image list, loader interface is locked down!\n", pWrappedModInfo->szName));
     5750        return VERR_PERMISSION_DENIED;
     5751    }
     5752
     5753    /* Only one VMMR0: */
     5754    if (   pDevExt->pvVMMR0 != NULL
     5755        && (pWrappedModInfo->fFlags & SUPLDRWRAPPEDMODULE_F_VMMR0))
     5756    {
     5757        supdrvLdrUnlock(pDevExt);
     5758        Log(("supdrvLdrRegisterWrappedModule: Rejecting '%s' as we already got a VMMR0 module!\n",  pWrappedModInfo->szName));
     5759        return VERR_ALREADY_EXISTS;
     5760    }
     5761
     5762    /*
     5763     * Allocate memory.
     5764     */
     5765    Assert(cchName < sizeof(pImage->szName));
     5766    pImage = (PSUPDRVLDRIMAGE)RTMemAllocZ(sizeof(SUPDRVLDRIMAGE));
     5767    if (!pImage)
     5768    {
     5769        supdrvLdrUnlock(pDevExt);
     5770        Log(("supdrvLdrRegisterWrappedModule: RTMemAllocZ() failed\n"));
     5771        return VERR_NO_MEMORY;
     5772    }
     5773    SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     5774
     5775    /*
     5776     * Setup and link in the LDR stuff.
     5777     */
     5778    pImage->pvImage         = (void *)pWrappedModInfo->pvImageStart;
     5779#ifdef SUPDRV_USE_MEMOBJ_FOR_LDR_IMAGE
     5780    pImage->hMemObjImage    = NIL_RTR0MEMOBJ;
     5781#else
     5782    pImage->pvImageAlloc    = NULL;
     5783#endif
     5784    pImage->cbImageWithEverything
     5785        = pImage->cbImageBits = (uintptr_t)pWrappedModInfo->pvImageEnd - (uintptr_t)pWrappedModInfo->pvImageStart;
     5786    pImage->cSymbols        = 0;
     5787    pImage->paSymbols       = NULL;
     5788    pImage->pachStrTab      = NULL;
     5789    pImage->cbStrTab        = 0;
     5790    pImage->cSegments       = 0;
     5791    pImage->paSegments      = NULL;
     5792    pImage->pfnModuleInit   = pWrappedModInfo->pfnModuleInit;
     5793    pImage->pfnModuleTerm   = pWrappedModInfo->pfnModuleTerm;
     5794    pImage->pfnServiceReqHandler = NULL;    /* Only setting this after module init  */
     5795    pImage->uState          = SUP_IOCTL_LDR_LOAD;
     5796    pImage->cImgUsage       = 1;            /* Held by the wrapper module till unload. */
     5797    pImage->pDevExt         = pDevExt;
     5798    pImage->pImageImport    = NULL;
     5799    pImage->uMagic          = SUPDRVLDRIMAGE_MAGIC;
     5800    pImage->pWrappedModInfo = pWrappedModInfo;
     5801    pImage->pvWrappedNative = pvNative;
     5802    pImage->fNative         = true;
     5803    memcpy(pImage->szName, pWrappedModInfo->szName, cchName + 1);
     5804
     5805    /*
     5806     * Link it.
     5807     */
     5808    pImage->pNext           = pDevExt->pLdrImages;
     5809    pDevExt->pLdrImages     = pImage;
     5810
     5811    /*
     5812     * Call module init function if found.
     5813     */
     5814    if (pImage->pfnModuleInit)
     5815    {
     5816        Log(("supdrvIOCtl_LdrLoad: calling pfnModuleInit=%p\n", pImage->pfnModuleInit));
     5817        pDevExt->pLdrInitImage  = pImage;
     5818        pDevExt->hLdrInitThread = RTThreadNativeSelf();
     5819        SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     5820        rc = pImage->pfnModuleInit(pImage);
     5821        SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     5822        pDevExt->pLdrInitImage  = NULL;
     5823        pDevExt->hLdrInitThread = NIL_RTNATIVETHREAD;
     5824    }
     5825    if (RT_SUCCESS(rc))
     5826    {
     5827        /*
     5828         * Update entry points.
     5829         */
     5830        if (pWrappedModInfo->fFlags & SUPLDRWRAPPEDMODULE_F_VMMR0)
     5831        {
     5832            Assert(!pDevExt->pvVMMR0);
     5833            Assert(!pDevExt->pfnVMMR0EntryFast);
     5834            Assert(!pDevExt->pfnVMMR0EntryEx);
     5835            ASMAtomicWritePtrVoid(&pDevExt->pvVMMR0, pImage->pvImage);
     5836            ASMAtomicWritePtrVoid((void * volatile *)(uintptr_t)&pDevExt->pfnVMMR0EntryFast,
     5837                                  (void *)(uintptr_t)    pWrappedModInfo->pfnVMMR0EntryFast);
     5838            ASMAtomicWritePtrVoid((void * volatile *)(uintptr_t)&pDevExt->pfnVMMR0EntryEx,
     5839                                  (void *)(uintptr_t)    pWrappedModInfo->pfnVMMR0EntryEx);
     5840        }
     5841        else
     5842            pImage->pfnServiceReqHandler = pWrappedModInfo->pfnServiceReqHandler;
     5843#ifdef IN_RING3
     5844# error "WTF?"
     5845#endif
     5846        *phMod = pImage;
     5847    }
     5848    else
     5849    {
     5850        /*
     5851         * Module init failed - bail, no module term callout.
     5852         */
     5853        SUPR0Printf("ModuleInit failed for '%s': %Rrc\n", pImage->szName, rc);
     5854
     5855        pImage->pfnModuleTerm = NULL;
     5856        pImage->uState        = SUP_IOCTL_LDR_OPEN;
     5857        supdrvLdrFree(pDevExt, pImage);
     5858    }
     5859
     5860    supdrvLdrUnlock(pDevExt);
     5861    SUPDRV_CHECK_SMAP_CHECK(pDevExt, RT_NOTHING);
     5862    return VINF_SUCCESS;
     5863}
     5864
     5865
     5866/**
     5867 * Decrements SUPDRVLDRIMAGE::cImgUsage when two or greater.
     5868 *
     5869 * @param   pDevExt     Device globals.
     5870 * @param   pImage      The image.
     5871 * @param   cReference  Number of references being removed.
     5872 */
     5873DECLINLINE(void) supdrvLdrSubtractUsage(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, uint32_t cReference)
     5874{
     5875    Assert(cReference > 0);
     5876    Assert(pImage->cImgUsage > cReference);
     5877    pImage->cImgUsage -= cReference;
     5878    if (pImage->cImgUsage == 1 && pImage->pWrappedModInfo)
     5879        supdrvOSLdrReleaseWrapperModule(pDevExt, pImage);
     5880}
     5881
     5882
     5883/**
    55805884 * Frees a previously loaded (prep'ed) image.
    55815885 *
     
    56225926    rc = VINF_SUCCESS;
    56235927    pImage = pUsage->pImage;
    5624     Log(("SUP_IOCTL_LDR_FREE: pImage=%p %s cUsage=%d r3=%d r0=%u\n",
    5625          pImage, pImage->szName, pImage->cUsage, pUsage->cRing3Usage, pUsage->cRing0Usage));
    5626     if (pImage->cUsage <= 1 || pUsage->cRing3Usage + pUsage->cRing0Usage <= 1)
     5928    Log(("SUP_IOCTL_LDR_FREE: pImage=%p %s cImgUsage=%d r3=%d r0=%u\n",
     5929         pImage, pImage->szName, pImage->cImgUsage, pUsage->cRing3Usage, pUsage->cRing0Usage));
     5930    if (pImage->cImgUsage <= 1 || pUsage->cRing3Usage + pUsage->cRing0Usage <= 1)
    56275931    {
    56285932        /*
     
    56325936         */
    56335937        RTSpinlockAcquire(pDevExt->Spinlock);
    5634         if (pImage->cUsage <= 1)
     5938        if (pImage->cImgUsage <= 1)
    56355939        {
    56365940            PSUPDRVOBJ pObj;
     
    56695973             * Dereference the image.
    56705974             */
    5671             if (pImage->cUsage <= 1)
     5975            if (pImage->cImgUsage <= 1)
    56725976                supdrvLdrFree(pDevExt, pImage);
    56735977            else
    5674                 pImage->cUsage--;
     5978                supdrvLdrSubtractUsage(pDevExt, pImage, 1);
    56755979        }
    56765980        else
     
    56825986         * Dereference both image and usage.
    56835987         */
    5684         pImage->cUsage--;
    56855988        pUsage->cRing3Usage--;
     5989        supdrvLdrSubtractUsage(pDevExt, pImage, 1);
    56865990    }
    56875991
     
    56925996
    56935997/**
     5998 * Deregisters a wrapped .r0 module.
     5999 *
     6000 * @param   pWrappedModInfo     The wrapped module info.
     6001 * @param   phMod               Where to store the module is stored (NIL'ed on
     6002 *                              success).
     6003 */
     6004int VBOXCALL supdrvLdrDeregisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod)
     6005{
     6006    PSUPDRVLDRIMAGE pImage;
     6007    uint32_t        cSleeps;
     6008
     6009    /*
     6010     * Validate input.
     6011     */
     6012    AssertPtrReturn(pWrappedModInfo, VERR_INVALID_POINTER);
     6013    AssertMsgReturn(pWrappedModInfo->uMagic == SUPLDRWRAPPEDMODULE_MAGIC,
     6014                    ("uMagic=%#x, expected %#x\n", pWrappedModInfo->uMagic, SUPLDRWRAPPEDMODULE_MAGIC),
     6015                    VERR_INVALID_MAGIC);
     6016    AssertMsgReturn(pWrappedModInfo->uEndMagic == SUPLDRWRAPPEDMODULE_MAGIC,
     6017                    ("uEndMagic=%#x, expected %#x\n", pWrappedModInfo->uEndMagic, SUPLDRWRAPPEDMODULE_MAGIC),
     6018                    VERR_INVALID_MAGIC);
     6019
     6020    AssertPtrReturn(phMod, VERR_INVALID_POINTER);
     6021    pImage = *(PSUPDRVLDRIMAGE *)phMod;
     6022    if (!pImage)
     6023        return VINF_SUCCESS;
     6024    AssertPtrReturn(pImage, VERR_INVALID_POINTER);
     6025    AssertMsgReturn(pImage->uMagic == SUPDRVLDRIMAGE_MAGIC, ("pImage=%p uMagic=%#x\n", pImage, pImage->uMagic),
     6026                    VERR_INVALID_MAGIC);
     6027    AssertMsgReturn(pImage->pvImage == pWrappedModInfo->pvImageStart,
     6028                    ("pWrappedModInfo(%p)->pvImageStart=%p vs. pImage(=%p)->pvImage=%p\n",
     6029                     pWrappedModInfo, pWrappedModInfo->pvImageStart, pImage, pImage->pvImage),
     6030                    VERR_MISMATCH);
     6031
     6032    AssertPtrReturn(pDevExt, VERR_INVALID_POINTER);
     6033
     6034    /*
     6035     * Try free it, but first we have to wait for its usage count to reach 1 (our).
     6036     */
     6037    supdrvLdrLock(pDevExt);
     6038    for (cSleeps = 0; ; cSleeps++)
     6039    {
     6040        PSUPDRVLDRIMAGE pCur;
     6041
     6042        /* Check that the image is in the list. */
     6043        for (pCur = pDevExt->pLdrImages; pCur; pCur = pCur->pNext)
     6044            if (pCur == pImage)
     6045                break;
     6046        AssertBreak(pCur == pImage);
     6047
     6048        /* Anyone still using it? */
     6049        if (pImage->cImgUsage <= 1)
     6050            break;
     6051
     6052        /* Someone is using it, wait and check again. */
     6053        if (!(cSleeps % 60))
     6054            SUPR0Printf("supdrvLdrUnregisterWrappedModule: Still %u users of wrapped image '%s' ...\n",
     6055                        pImage->cImgUsage, pImage->szName);
     6056        supdrvLdrUnlock(pDevExt);
     6057        RTThreadSleep(1000);
     6058        supdrvLdrLock(pDevExt);
     6059    }
     6060
     6061    /* We're the last 'user', free it. */
     6062    supdrvLdrFree(pDevExt, pImage);
     6063
     6064    supdrvLdrUnlock(pDevExt);
     6065
     6066    *phMod = NULL;
     6067    return VINF_SUCCESS;
     6068}
     6069
     6070
     6071/**
    56946072 * Lock down the image loader interface.
    56956073 *
     
    57106088
    57116089    return VINF_SUCCESS;
     6090}
     6091
     6092
     6093/**
     6094 * Worker for getting the address of a symbol in an image.
     6095 *
     6096 * @returns IPRT status code.
     6097 * @param   pDevExt     Device globals.
     6098 * @param   pImage      The image to search.
     6099 * @param   pszSymbol   The symbol name.
     6100 * @param   cchSymbol   The length of the symbol name.
     6101 * @param   ppvValue    Where to return the symbol
     6102 * @note    Caller owns the loader lock.
     6103 */
     6104static int supdrvLdrQuerySymbolWorker(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage,
     6105                                      const char *pszSymbol, size_t cchSymbol, void **ppvValue)
     6106{
     6107    int rc = VERR_SYMBOL_NOT_FOUND;
     6108    if (pImage->fNative && !pImage->pWrappedModInfo)
     6109        rc = supdrvOSLdrQuerySymbol(pDevExt, pImage, pszSymbol, cchSymbol, ppvValue);
     6110    else if (pImage->fNative && pImage->pWrappedModInfo)
     6111    {
     6112        PCSUPLDRWRAPMODSYMBOL   paSymbols = pImage->pWrappedModInfo->paSymbols;
     6113        uint32_t                iEnd      = pImage->pWrappedModInfo->cSymbols;
     6114        uint32_t                iStart    = 0;
     6115        while (iStart < iEnd)
     6116        {
     6117            uint32_t const i     = iStart + (iEnd - iStart) / 2;
     6118            int      const iDiff = strcmp(paSymbols[i].pszSymbol, pszSymbol);
     6119            if (iDiff < 0)
     6120                iStart = i + 1;
     6121            else if (iDiff > 0)
     6122                iEnd = i;
     6123            else
     6124            {
     6125                *ppvValue = (void *)(uintptr_t)paSymbols[i].pfnValue;
     6126                rc = VINF_SUCCESS;
     6127                break;
     6128            }
     6129        }
     6130#ifdef VBOX_STRICT
     6131        if (rc != VINF_SUCCESS)
     6132            for (iStart = 0, iEnd = pImage->pWrappedModInfo->cSymbols; iStart < iEnd; iStart++)
     6133                Assert(strcmp(paSymbols[iStart].pszSymbol, pszSymbol));
     6134#endif
     6135    }
     6136    else
     6137    {
     6138        const char *pchStrings = pImage->pachStrTab;
     6139        PSUPLDRSYM  paSyms     = pImage->paSymbols;
     6140        uint32_t    i;
     6141        Assert(!pImage->pWrappedModInfo);
     6142        for (i = 0; i < pImage->cSymbols; i++)
     6143        {
     6144            if (    paSyms[i].offName + cchSymbol + 1 <= pImage->cbStrTab
     6145                &&  !memcmp(pchStrings + paSyms[i].offName, pszSymbol, cchSymbol + 1))
     6146            {
     6147                /*
     6148                 * Note! The int32_t is for native loading on solaris where the data
     6149                 *       and text segments are in very different places.
     6150                 */
     6151                *ppvValue = (uint8_t *)pImage->pvImage + (int32_t)paSyms[i].offSymbol;
     6152                rc = VINF_SUCCESS;
     6153                break;
     6154            }
     6155        }
     6156    }
     6157    return rc;
    57126158}
    57136159
     
    57256171    PSUPDRVLDRIMAGE pImage;
    57266172    PSUPDRVLDRUSAGE pUsage;
    5727     uint32_t        i;
    5728     PSUPLDRSYM      paSyms;
    5729     const char     *pchStrings;
    5730     const size_t    cbSymbol = strlen(pReq->u.In.szSymbol) + 1;
    5731     void           *pvSymbol = NULL;
    5732     int             rc = VERR_SYMBOL_NOT_FOUND;
     6173    const size_t    cchSymbol = strlen(pReq->u.In.szSymbol);
     6174    void           *pvSymbol  = NULL;
     6175    int             rc;
    57336176    Log3(("supdrvIOCtl_LdrQuerySymbol: pvImageBase=%p szSymbol=\"%s\"\n", pReq->u.In.pvImageBase, pReq->u.In.szSymbol));
    57346177
     
    57376180     */
    57386181    supdrvLdrLock(pDevExt);
     6182
    57396183    pUsage = pSession->pLdrUsage;
    57406184    while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase)
    57416185        pUsage = pUsage->pNext;
    5742     if (!pUsage)
    5743     {
    5744         supdrvLdrUnlock(pDevExt);
     6186    if (pUsage)
     6187    {
     6188        pImage = pUsage->pImage;
     6189        if (pImage->uState == SUP_IOCTL_LDR_LOAD)
     6190        {
     6191            /*
     6192             * Search the image exports / symbol strings.
     6193             */
     6194            rc = supdrvLdrQuerySymbolWorker(pDevExt, pImage, pReq->u.In.szSymbol, cchSymbol, &pvSymbol);
     6195        }
     6196        else
     6197        {
     6198            Log(("SUP_IOCTL_LDR_GET_SYMBOL: invalid image state %d (%#x)!\n", pImage->uState, pImage->uState));
     6199            rc = VERR_WRONG_ORDER;
     6200        }
     6201    }
     6202    else
     6203    {
    57456204        Log(("SUP_IOCTL_LDR_GET_SYMBOL: couldn't find image!\n"));
    5746         return VERR_INVALID_HANDLE;
    5747     }
    5748     pImage = pUsage->pImage;
    5749     if (pImage->uState != SUP_IOCTL_LDR_LOAD)
    5750     {
    5751         unsigned uState = pImage->uState;
    5752         supdrvLdrUnlock(pDevExt);
    5753         Log(("SUP_IOCTL_LDR_GET_SYMBOL: invalid image state %d (%#x)!\n", uState, uState)); NOREF(uState);
    5754         return VERR_ALREADY_LOADED;
    5755     }
    5756 
    5757     /*
    5758      * Search the image exports / symbol strings.
    5759      *
    5760      * Note! The int32_t is for native loading on solaris where the data
    5761      *       and text segments are in very different places.
    5762      */
    5763     if (pImage->fNative)
    5764         rc = supdrvOSLdrQuerySymbol(pDevExt, pImage, pReq->u.In.szSymbol, cbSymbol - 1, &pvSymbol);
    5765     else
    5766     {
    5767         pchStrings = pImage->pachStrTab;
    5768         paSyms     = pImage->paSymbols;
    5769         for (i = 0; i < pImage->cSymbols; i++)
    5770         {
    5771             if (    paSyms[i].offName + cbSymbol <= pImage->cbStrTab
    5772                 &&  !memcmp(pchStrings + paSyms[i].offName, pReq->u.In.szSymbol, cbSymbol))
    5773             {
    5774                 pvSymbol = (uint8_t *)pImage->pvImage + (int32_t)paSyms[i].offSymbol;
    5775                 rc = VINF_SUCCESS;
    5776                 break;
    5777             }
    5778         }
    5779     }
     6205        rc = VERR_INVALID_HANDLE;
     6206    }
     6207
    57806208    supdrvLdrUnlock(pDevExt);
     6209
    57816210    pReq->u.Out.pvSymbol = pvSymbol;
    57826211    return rc;
     
    57876216 * Gets the address of a symbol in an open image or the support driver.
    57886217 *
    5789  * @returns VINF_SUCCESS on success.
    5790  * @returns
     6218 * @returns VBox status code.
    57916219 * @param   pDevExt     Device globals.
    57926220 * @param   pSession    Session data.
     
    57956223static int supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq)
    57966224{
    5797     int             rc = VINF_SUCCESS;
    57986225    const char     *pszSymbol = pReq->u.In.pszSymbol;
    57996226    const char     *pszModule = pReq->u.In.pszModule;
    5800     size_t          cbSymbol;
     6227    size_t          cchSymbol;
    58016228    char const     *pszEnd;
    58026229    uint32_t        i;
     6230    int             rc;
    58036231
    58046232    /*
     
    58086236    pszEnd = RTStrEnd(pszSymbol, 512);
    58096237    AssertReturn(pszEnd, VERR_INVALID_PARAMETER);
    5810     cbSymbol = pszEnd - pszSymbol + 1;
     6238    cchSymbol = pszEnd - pszSymbol;
    58116239
    58126240    if (pszModule)
     
    58186246    Log3(("supdrvIDC_LdrGetSymbol: pszModule=%p:{%s} pszSymbol=%p:{%s}\n", pszModule, pszModule, pszSymbol, pszSymbol));
    58196247
    5820 
    58216248    if (    !pszModule
    58226249        ||  !strcmp(pszModule, "SupDrv"))
     
    58256252         * Search the support driver export table.
    58266253         */
     6254        rc = VERR_SYMBOL_NOT_FOUND;
    58276255        for (i = 0; i < RT_ELEMENTS(g_aFunctions); i++)
    58286256            if (!strcmp(g_aFunctions[i].szName, pszSymbol))
    58296257            {
    58306258                pReq->u.Out.pfnSymbol = (PFNRT)(uintptr_t)g_aFunctions[i].pfn;
     6259                rc = VINF_SUCCESS;
    58316260                break;
    58326261            }
     
    58476276        {
    58486277            /*
    5849              * Search the image exports / symbol strings.
     6278             * Search the image exports / symbol strings.  Do usage counting on the session.
    58506279             */
    5851             if (pImage->fNative)
    5852             {
    5853                 rc = supdrvOSLdrQuerySymbol(pDevExt, pImage, pszSymbol, cbSymbol - 1, (void **)&pReq->u.Out.pfnSymbol);
    5854                 if (RT_SUCCESS(rc))
    5855                     rc = supdrvLdrAddUsage(pSession, pImage, true /*fRing3Usage*/);
    5856             }
    5857             else
    5858             {
    5859                 const char *pchStrings = pImage->pachStrTab;
    5860                 PCSUPLDRSYM paSyms     = pImage->paSymbols;
    5861                 rc = VERR_SYMBOL_NOT_FOUND;
    5862                 for (i = 0; i < pImage->cSymbols; i++)
    5863                 {
    5864                     if (    paSyms[i].offName + cbSymbol <= pImage->cbStrTab
    5865                         &&  !memcmp(pchStrings + paSyms[i].offName, pszSymbol, cbSymbol))
    5866                     {
    5867                         /*
    5868                          * Found it! Calc the symbol address and add a reference to the module.
    5869                          */
    5870                         pReq->u.Out.pfnSymbol = (PFNRT)((uintptr_t)pImage->pvImage + (int32_t)paSyms[i].offSymbol);
    5871                         rc = supdrvLdrAddUsage(pSession, pImage, true /*fRing3Usage*/);
    5872                         break;
    5873                     }
    5874                 }
    5875             }
     6280            rc = supdrvLdrQuerySymbolWorker(pDevExt, pImage, pszSymbol, cchSymbol, (void **)&pReq->u.Out.pfnSymbol);
     6281            if (RT_SUCCESS(rc))
     6282                rc = supdrvLdrAddUsage(pDevExt, pSession, pImage, true /*fRing3Usage*/);
    58766283        }
    58776284        else
     
    59126319
    59136320/**
    5914  * Updates the VMMR0 entry point pointers.
    5915  *
    5916  * @returns IPRT status code.
    5917  * @param   pDevExt             Device globals.
    5918  * @param   pvVMMR0             VMMR0 image handle.
    5919  * @param   pvVMMR0EntryFast    VMMR0EntryFast address.
    5920  * @param   pvVMMR0EntryEx      VMMR0EntryEx address.
    5921  * @remark  Caller must own the loader mutex.
    5922  */
    5923 static int supdrvLdrSetVMMR0EPs(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx)
    5924 {
    5925     int rc = VINF_SUCCESS;
    5926     LogFlow(("supdrvLdrSetR0EP pvVMMR0=%p pvVMMR0EntryFast=%p\n", pvVMMR0, pvVMMR0EntryFast));
    5927 
    5928 
    5929     /*
    5930      * Check if not yet set.
    5931      */
    5932     if (!pDevExt->pvVMMR0)
    5933     {
    5934         pDevExt->pvVMMR0 = pvVMMR0;
    5935         *(void **)&pDevExt->pfnVMMR0EntryFast = pvVMMR0EntryFast;
    5936         *(void **)&pDevExt->pfnVMMR0EntryEx   = pvVMMR0EntryEx;
    5937         ASMCompilerBarrier(); /* the above isn't nice, so be careful... */
    5938     }
    5939     else
    5940     {
    5941         /*
    5942          * Return failure or success depending on whether the values match or not.
    5943          */
    5944         if (    pDevExt->pvVMMR0 != pvVMMR0
    5945             ||  (uintptr_t)pDevExt->pfnVMMR0EntryFast  != (uintptr_t)pvVMMR0EntryFast
    5946             ||  (uintptr_t)pDevExt->pfnVMMR0EntryEx    != (uintptr_t)pvVMMR0EntryEx)
    5947         {
    5948             AssertMsgFailed(("SUP_IOCTL_LDR_SETR0EP: Already set pointing to a different module!\n"));
    5949             rc = VERR_INVALID_PARAMETER;
    5950         }
    5951     }
    5952     return rc;
    5953 }
    5954 
    5955 
    5956 /**
    5957  * Unsets the VMMR0 entry point installed by supdrvLdrSetR0EP.
    5958  *
    5959  * @param   pDevExt     Device globals.
    5960  */
    5961 static void supdrvLdrUnsetVMMR0EPs(PSUPDRVDEVEXT pDevExt)
    5962 {
    5963     pDevExt->pvVMMR0            = NULL;
    5964     pDevExt->pfnVMMR0EntryFast  = NULL;
    5965     pDevExt->pfnVMMR0EntryEx    = NULL;
    5966 }
    5967 
    5968 
    5969 /**
    59706321 * Adds a usage reference in the specified session of an image.
    59716322 *
     
    59736324 *
    59746325 * @returns VINF_SUCCESS on success and VERR_NO_MEMORY on failure.
     6326 * @param   pDevExt     Pointer to device extension.
    59756327 * @param   pSession    Session in question.
    59766328 * @param   pImage      Image which the session is using.
    59776329 * @param   fRing3Usage Set if it's ring-3 usage, clear if ring-0.
    59786330 */
    5979 static int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage, bool fRing3Usage)
     6331static int supdrvLdrAddUsage(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage, bool fRing3Usage)
    59806332{
    59816333    PSUPDRVLDRUSAGE pUsage;
     
    59946346            else
    59956347                pUsage->cRing0Usage++;
     6348            Assert(pImage->cImgUsage > 1 || !pImage->pWrappedModInfo);
     6349            pImage->cImgUsage++;
    59966350            return VINF_SUCCESS;
    59976351        }
     
    60036357     */
    60046358    pUsage = (PSUPDRVLDRUSAGE)RTMemAlloc(sizeof(*pUsage));
    6005     AssertReturn(pUsage, /*VERR_NO_MEMORY*/ VERR_INTERNAL_ERROR_5);
     6359    AssertReturn(pUsage, VERR_NO_MEMORY);
    60066360    pUsage->cRing3Usage = fRing3Usage ? 1 : 0;
    60076361    pUsage->cRing0Usage = fRing3Usage ? 0 : 1;
     
    60096363    pUsage->pNext       = pSession->pLdrUsage;
    60106364    pSession->pLdrUsage = pUsage;
     6365
     6366    /*
     6367     * Wrapped modules needs to retain a native module reference.
     6368     */
     6369    pImage->cImgUsage++;
     6370    if (pImage->cImgUsage == 2 && pImage->pWrappedModInfo)
     6371        supdrvOSLdrRetainWrapperModule(pDevExt, pImage);
     6372
    60116373    return VINF_SUCCESS;
    60126374}
     
    60576419        /* check if this is VMMR0.r0 unset its entry point pointers. */
    60586420        if (pDevExt->pvVMMR0 == pImage->pvImage)
    6059             supdrvLdrUnsetVMMR0EPs(pDevExt);
     6421        {
     6422            pDevExt->pvVMMR0            = NULL;
     6423            pDevExt->pfnVMMR0EntryFast  = NULL;
     6424            pDevExt->pfnVMMR0EntryEx    = NULL;
     6425        }
    60606426
    60616427        /* check for objects with destructors in this image. (Shouldn't happen.) */
     
    60966462
    60976463        /* free the image */
    6098         pImage->uMagic  = SUPDRVLDRIMAGE_MAGIC_DEAD;
    6099         pImage->cUsage  = 0;
    6100         pImage->pDevExt = NULL;
    6101         pImage->pNext   = NULL;
    6102         pImage->uState  = SUP_IOCTL_LDR_FREE;
     6464        pImage->uMagic       = SUPDRVLDRIMAGE_MAGIC_DEAD;
     6465        pImage->cImgUsage    = 0;
     6466        pImage->pDevExt      = NULL;
     6467        pImage->pNext        = NULL;
     6468        pImage->uState       = SUP_IOCTL_LDR_FREE;
    61036469#ifdef SUPDRV_USE_MEMOBJ_FOR_LDR_IMAGE
    61046470        RTR0MemObjFree(pImage->hMemObjImage, true /*fMappings*/);
     
    61086474        pImage->pvImageAlloc = NULL;
    61096475#endif
    6110         pImage->pvImage = NULL;
     6476        pImage->pvImage      = NULL;
    61116477        RTMemFree(pImage->pachStrTab);
    6112         pImage->pachStrTab = NULL;
     6478        pImage->pachStrTab   = NULL;
    61136479        RTMemFree(pImage->paSymbols);
    6114         pImage->paSymbols = NULL;
     6480        pImage->paSymbols    = NULL;
    61156481        RTMemFree(pImage->paSegments);
    6116         pImage->paSegments = NULL;
     6482        pImage->paSegments   = NULL;
    61176483
    61186484        pImageImport = pImage->pImageImport;
     
    61266492        if (!pImageImport)
    61276493            break;
    6128         if (pImageImport->cUsage > 1)
    6129         {
    6130             pImageImport->cUsage--;
     6494        if (pImageImport->cImgUsage > 1)
     6495        {
     6496            supdrvLdrSubtractUsage(pDevExt, pImageImport, 1);
    61316497            break;
    61326498        }
     
    61876553    return supdrvLdrLock(pSession->pDevExt);
    61886554}
     6555SUPR0_EXPORT_SYMBOL(SUPR0LdrLock);
    61896556
    61906557
     
    62046571    return supdrvLdrUnlock(pSession->pDevExt);
    62056572}
     6573SUPR0_EXPORT_SYMBOL(SUPR0LdrUnlock);
    62066574
    62076575
     
    62466614#endif
    62476615}
     6616SUPR0_EXPORT_SYMBOL(SUPR0LdrIsLockOwnerByMod);
    62486617
    62496618
     
    62946663                if (uState == SUP_IOCTL_LDR_LOAD)
    62956664                {
    6296                     if (RT_LIKELY(pImage->cUsage < UINT32_MAX / 2U))
     6665                    if (RT_LIKELY(pImage->cImgUsage < UINT32_MAX / 2U))
    62976666                    {
    6298                         pImage->cUsage++;
    6299                         supdrvLdrAddUsage(pSession, pImage, false /*fRing3Usage*/);
     6667                        supdrvLdrAddUsage(pDevExt, pSession, pImage, false /*fRing3Usage*/);
    63006668                        *phMod = pImage;
    63016669                        supdrvLdrUnlock(pDevExt);
     
    63176685    return rc;
    63186686}
     6687SUPR0_EXPORT_SYMBOL(SUPR0LdrModByName);
    63196688
    63206689
     
    63486717        if (pImage->uMagic == SUPDRVLDRIMAGE_MAGIC)
    63496718        {
    6350             if (RT_LIKELY(pImage->cUsage < UINT32_MAX / 2U))
    6351             {
    6352                 rc = supdrvLdrAddUsage(pSession, pImage, false /*fRing3Usage*/);
    6353                 if (RT_SUCCESS(rc))
    6354                 {
    6355                     pImage->cUsage++;
    6356                     rc = VINF_SUCCESS;
    6357                 }
    6358             }
     6719            if (RT_LIKELY(pImage->cImgUsage < UINT32_MAX / 2U))
     6720                rc = supdrvLdrAddUsage(pDevExt, pSession, pImage, false /*fRing3Usage*/);
    63596721            else
    63606722                AssertFailedStmt(rc = VERR_TOO_MANY_REFERENCES);
     
    63666728    return rc;
    63676729}
     6730SUPR0_EXPORT_SYMBOL(SUPR0LdrModRetain);
    63686731
    63696732
     
    64156778                     * Drop a ring-0 reference:
    64166779                     */
    6417                     Assert(pImage->cUsage >= pUsage->cRing0Usage + pUsage->cRing3Usage);
     6780                    Assert(pImage->cImgUsage >= pUsage->cRing0Usage + pUsage->cRing3Usage);
    64186781                    if (pUsage->cRing0Usage > 0)
    64196782                    {
    6420                         if (pImage->cUsage > 1)
     6783                        if (pImage->cImgUsage > 1)
    64216784                        {
    6422                             pImage->cUsage      -= 1;
    64236785                            pUsage->cRing0Usage -= 1;
     6786                            supdrvLdrSubtractUsage(pDevExt, pImage, 1);
    64246787                            rc = VINF_SUCCESS;
    64256788                        }
    64266789                        else
    64276790                        {
     6791                            Assert(!pImage->pWrappedModInfo /* (The wrapper kmod has the last reference.) */);
    64286792                            supdrvLdrFree(pDevExt, pImage);
    64296793
     
    64556819
    64566820}
     6821SUPR0_EXPORT_SYMBOL(SUPR0LdrModRelease);
    64576822
    64586823
  • trunk/src/VBox/HostDrivers/Support/SUPDrvGip.cpp

    r82968 r87700  
    143143*********************************************************************************************************************************/
    144144DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage = NULL;
     145SUPR0_EXPORT_SYMBOL(g_pSUPGlobalInfoPage);
    145146
    146147
     
    751752    return rc;
    752753}
     754SUPR0_EXPORT_SYMBOL(SUPR0GipMap);
    753755
    754756
     
    826828    return rc;
    827829}
     830SUPR0_EXPORT_SYMBOL(SUPR0GipUnmap);
    828831
    829832
     
    48284831    return rc;
    48294832}
     4833SUPR0_EXPORT_SYMBOL(SUPR0TscDeltaMeasureBySetIndex);
    48304834
    48314835
  • trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h

    r87233 r87700  
    221221 *
    222222 * @todo Pending work on next major version change:
    223  *          - Nothing.
    224  */
    225 #define SUPDRV_IOC_VERSION                              0x00300000
     223 *          - Remove pvVMMR0 from SUPLDRLOAD.
     224 */
     225#define SUPDRV_IOC_VERSION                              0x00300001
    226226
    227227/** SUP_IOCTL_COOKIE. */
     
    315315        struct
    316316        {
    317             /** Size of the image we'll be loading (including all tables). */
     317            /** Size of the image we'll be loading (including all tables).
     318             * Zero if the caller does not wish to prepare loading anything, then
     319             * cbImageBits must be zero too ofc. */
    318320            uint32_t        cbImageWithEverything;
    319             /** The size of the image bits. (Less or equal to cbImageWithTabs.) */
     321            /** The size of the image bits. (Less or equal to cbImageWithTabs.)
     322             * Zero if the caller does not wish to prepare loading anything. */
    320323            uint32_t        cbImageBits;
    321324            /** Image name.
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r86512 r87700  
    4747#include <iprt/err.h>
    4848
    49 #ifdef SUPDRV_AGNOSTIC
     49#if defined(SUPDRV_AGNOSTIC) && !defined(RT_OS_LINUX)
    5050/* do nothing */
    5151
     
    7676#       endif
    7777#   endif
    78 #   include <linux/string.h>
    79 #   include <linux/spinlock.h>
    80 #   include <linux/slab.h>
    81 #   if RTLNX_VER_MIN(2,6,27)
    82 #       include <linux/semaphore.h>
    83 #   else /* older kernels */
    84 #       include <asm/semaphore.h>
    85 #   endif /* older kernels */
    86 #   include <linux/timer.h>
     78#   ifndef SUPDRV_AGNOSTIC
     79#       include <linux/string.h>
     80#       include <linux/spinlock.h>
     81#       include <linux/slab.h>
     82#       if RTLNX_VER_MIN(2,6,27)
     83#           include <linux/semaphore.h>
     84#       else /* older kernels */
     85#           include <asm/semaphore.h>
     86#       endif /* older kernels */
     87#       include <linux/timer.h>
     88#   endif
     89#   if RTLNX_VER_MIN(3,2,0)
     90#       include <linux/export.h>
     91#   else
     92#       include <linux/module.h>
     93#   endif
     94#   define SUPR0_EXPORT_SYMBOL(a_Name) EXPORT_SYMBOL(a_Name)
    8795
    8896#elif defined(RT_OS_DARWIN)
     
    152160#endif
    153161
     162#ifndef SUPR0_EXPORT_SYMBOL
     163# define SUPR0_EXPORT_SYMBOL(a_Name) extern int g_supDrvExportSymbolDummyVariable
     164#endif
    154165
    155166/**
     
    370381    uint32_t                        uState;
    371382    /** Usage count. */
    372     uint32_t volatile               cUsage;
     383    uint32_t volatile               cImgUsage;
    373384    /** Pointer to the device extension. */
    374385    struct SUPDRVDEVEXT            *pDevExt;
     
    390401    /** Hack for seeing the module in perf, dtrace and other stack crawlers. */
    391402    struct module                  *pLnxModHack;
     403    /** The wrapper module.  */
     404    struct module                  *pLnxWrapperModule;
     405    /** Set if we're holding a reference to the wrapper module. */
     406    bool                            fLnxWrapperRef;
    392407#endif
    393408#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_DARWIN_R0_DARWIN_IMAGE_VERIFICATION)
     
    397412    RTR0MEMOBJ                      hMemAlloc;
    398413#endif
     414    /** This points to the module info if the image is a wrapped up in a native one. */
     415    PCSUPLDRWRAPPEDMODULE           pWrappedModInfo;
     416    /** OS specific information for wrapped modules. */
     417    void                           *pvWrappedNative;
    399418    /** Whether it's loaded by the native loader or not. */
    400419    bool                            fNative;
     
    10081027                                       const char *pszSymbol, size_t cchSymbol, void **ppvSymbol);
    10091028
     1029/**
     1030 * Retains a native wrapper module when it is first being used.
     1031 *
     1032 * This will be call when pImage->cImgUsage is incremented to 2.
     1033 *
     1034 * @param   pDevExt             The device globals.
     1035 * @param   pImage              The wrapped image.
     1036 */
     1037void VBOXCALL   supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
     1038
     1039/**
     1040 * Release a native wrapper module when it is no longer being used.
     1041 *
     1042 * This will be call when pImage->cImgUsage is decremented to 1.
     1043 *
     1044 * @param   pDevExt             The device globals.
     1045 * @param   pImage              The wrapped image.
     1046 */
     1047void VBOXCALL   supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
    10101048
    10111049#ifdef SUPDRV_WITH_MSR_PROBER
     
    10821120int VBOXCALL    supdrvLdrLoadError(int rc, PSUPLDRLOAD pReq, const char *pszFormat, ...);
    10831121int VBOXCALL    supdrvLdrGetExportedSymbol(const char *pszSymbol, uintptr_t *puValue);
     1122int VBOXCALL    supdrvLdrRegisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo,
     1123                                               void *pvNative, void **phMod);
     1124int VBOXCALL    supdrvLdrDeregisterWrappedModule(PSUPDRVDEVEXT pDevExt, PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod);
     1125
    10841126
    10851127/* SUPDrvGip.cpp */
  • trunk/src/VBox/HostDrivers/Support/SUPDrvSem.cpp

    r82968 r87700  
    100100    return rc;
    101101}
     102SUPR0_EXPORT_SYMBOL(SUPSemEventCreate);
    102103
    103104
     
    128129    return SUPR0ObjRelease(pObj, pSession); /* The handle table reference. */
    129130}
     131SUPR0_EXPORT_SYMBOL(SUPSemEventClose);
    130132
    131133
     
    155157    return rc;
    156158}
     159SUPR0_EXPORT_SYMBOL(SUPSemEventSignal);
    157160
    158161
     
    191194    return supR0SemEventWaitEx(pSession, hEvent, fFlags, cMillies);
    192195}
     196SUPR0_EXPORT_SYMBOL(SUPSemEventWait);
    193197
    194198
     
    200204    return supR0SemEventWaitEx(pSession, hEvent, fFlags, cMillies);
    201205}
     206SUPR0_EXPORT_SYMBOL(SUPSemEventWaitNoResume);
    202207
    203208
     
    207212    return supR0SemEventWaitEx(pSession, hEvent, fFlags, uNsTimeout);
    208213}
     214SUPR0_EXPORT_SYMBOL(SUPSemEventWaitNsAbsIntr);
    209215
    210216
     
    214220    return supR0SemEventWaitEx(pSession, hEvent, fFlags, cNsTimeout);
    215221}
     222SUPR0_EXPORT_SYMBOL(SUPSemEventWaitNsRelIntr);
    216223
    217224
     
    222229    return RTSemEventGetResolution();
    223230}
     231SUPR0_EXPORT_SYMBOL(SUPSemEventGetResolution);
    224232
    225233
     
    273281    return rc;
    274282}
     283SUPR0_EXPORT_SYMBOL(SUPSemEventMultiCreate);
    275284
    276285
     
    301310    return SUPR0ObjRelease(pObj, pSession); /* The handle table reference. */
    302311}
     312SUPR0_EXPORT_SYMBOL(SUPSemEventMultiClose);
    303313
    304314
     
    328338    return rc;
    329339}
     340SUPR0_EXPORT_SYMBOL(SUPSemEventMultiSignal);
    330341
    331342
     
    355366    return rc;
    356367}
     368SUPR0_EXPORT_SYMBOL(SUPSemEventMultiReset);
    357369
    358370
     
    382394    return rc;
    383395}
     396
    384397
    385398SUPDECL(int) SUPSemEventMultiWait(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies)
     
    390403    return supR0SemEventMultiWaitEx(pSession, hEventMulti, fFlags, cMillies);
    391404}
     405SUPR0_EXPORT_SYMBOL(SUPSemEventMultiWait);
    392406
    393407
     
    400414    return supR0SemEventMultiWaitEx(pSession, hEventMulti, fFlags, cMillies);
    401415}
     416SUPR0_EXPORT_SYMBOL(SUPSemEventMultiWaitNoResume);
    402417
    403418
     
    407422    return supR0SemEventMultiWaitEx(pSession, hEventMulti, fFlags, uNsTimeout);
    408423}
     424SUPR0_EXPORT_SYMBOL(SUPSemEventMultiWaitNsAbsIntr);
    409425
    410426
     
    414430    return supR0SemEventMultiWaitEx(pSession, hEventMulti, fFlags, cNsTimeout);
    415431}
     432SUPR0_EXPORT_SYMBOL(SUPSemEventMultiWaitNsRelIntr);
    416433
    417434
     
    422439    return RTSemEventMultiGetResolution();
    423440}
    424 
     441SUPR0_EXPORT_SYMBOL(SUPSemEventMultiGetResolution);
  • trunk/src/VBox/HostDrivers/Support/SUPDrvTracer.cpp

    r85766 r87700  
    10981098    return rc;
    10991099}
     1100SUPR0_EXPORT_SYMBOL(SUPR0TracerRegisterDrv);
    11001101
    11011102
     
    11301131    supdrvTracerProcessZombies(pDevExt);
    11311132}
     1133SUPR0_EXPORT_SYMBOL(SUPR0TracerDeregisterDrv);
    11321134
    11331135
     
    11761178    return rc;
    11771179}
     1180SUPR0_EXPORT_SYMBOL(SUPR0TracerRegisterModule);
    11781181
    11791182
     
    12751278
    12761279}
     1280SUPR0_EXPORT_SYMBOL(SUPR0TracerRegisterImpl);
    12771281
    12781282
     
    14601464    return rc;
    14611465}
     1466SUPR0_EXPORT_SYMBOL(SUPR0TracerDeregisterImpl);
    14621467
    14631468
     
    15061511# endif
    15071512#endif
     1513SUPR0_EXPORT_SYMBOL(SUPR0TracerFireProbe);
    15081514
    15091515
     
    22302236    supdrvTracerUmodProbeFire(pSession->pDevExt, pSession, pCtx);
    22312237}
     2238SUPR0_EXPORT_SYMBOL(SUPR0TracerUmodProbeFire);
    22322239
    22332240
  • trunk/src/VBox/HostDrivers/Support/SUPLib.cpp

    r85507 r87700  
    126126/** The negotiated session cookie. */
    127127DECL_HIDDEN_DATA(uint32_t)          g_u32SessionCookie;
     128/** The session version. */
     129DECL_HIDDEN_DATA(uint32_t)          g_uSupSessionVersion = 0;
    128130/** Session handle. */
    129131DECL_HIDDEN_DATA(PSUPDRVSESSION)    g_pSession;
     
    284286            &&  RT_SUCCESS(CookieReq.Hdr.rc))
    285287        {
     288            g_uSupSessionVersion = CookieReq.u.Out.u32SessionVersion;
    286289            if (    (CookieReq.u.Out.u32SessionVersion & 0xffff0000) == (SUPDRV_IOC_VERSION & 0xffff0000)
    287290                &&  CookieReq.u.Out.u32SessionVersion >= uMinVersion)
  • trunk/src/VBox/HostDrivers/Support/SUPLibAll.cpp

    r87235 r87700  
    4141#endif
    4242#include <iprt/errcore.h>
     43#if defined(IN_RING0) && defined(RT_OS_LINUX)
     44# include "SUPDrvInternal.h"
     45#endif
     46
    4347
    4448
     
    217221    return uTsc;
    218222}
     223# ifdef IN_RING0
     224SUPR0_EXPORT_SYMBOL(SUPReadTscWithDelta);
     225# endif
    219226#endif /* RT_ARCH_AMD64 || RT_ARCH_X86 */
    220227
  • trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h

    r87030 r87700  
    341341extern DECL_HIDDEN_DATA(uint32_t)               g_u32Cookie;
    342342extern DECL_HIDDEN_DATA(uint32_t)               g_u32SessionCookie;
     343extern DECL_HIDDEN_DATA(uint32_t)               g_uSupSessionVersion;
    343344extern DECL_HIDDEN_DATA(SUPLIBDATA)             g_supLibData;
    344345extern DECL_HIDDEN_DATA(uint32_t)               g_uSupFakeMode;
  • trunk/src/VBox/HostDrivers/Support/SUPLibLdr.cpp

    r86512 r87700  
    716716                         PRTERRINFO pErrInfo, void **ppvImageBase)
    717717{
    718     int rc;
     718    SUPLDROPEN OpenReq;
    719719
    720720    /*
     
    724724    AssertPtrReturn(pszModule, VERR_INVALID_PARAMETER);
    725725    AssertPtrReturn(ppvImageBase, VERR_INVALID_PARAMETER);
    726     /** @todo abspath it right into SUPLDROPEN */
    727     AssertReturn(strlen(pszModule) < RT_SIZEOFMEMB(SUPLDROPEN, u.In.szName), VERR_FILENAME_TOO_LONG);
    728     char szAbsFilename[RT_SIZEOFMEMB(SUPLDROPEN, u.In.szFilename)];
    729     rc = RTPathAbs(pszFilename, szAbsFilename, sizeof(szAbsFilename));
    730     if (RT_FAILURE(rc))
    731         return rc;
    732     pszFilename = szAbsFilename;
     726    AssertReturn(strlen(pszModule) < sizeof(OpenReq.u.In.szName), VERR_FILENAME_TOO_LONG);
    733727
    734728    const bool fIsVMMR0 = !strcmp(pszModule, "VMMR0.r0");
     
    737731
    738732    /*
     733     * First try open it w/o preparing a binary for loading.
     734     *
     735     * This will be a lot faster if it's already loaded, and it will
     736     * avoid fixup issues when using wrapped binaries.  With wrapped
     737     * ring-0 binaries not all binaries need to be wrapped, so trying
     738     * to load it ourselves is not a bug, but intentional behaviour
     739     * (even it it asserts in the loader code).
     740     */
     741    OpenReq.Hdr.u32Cookie              = g_u32Cookie;
     742    OpenReq.Hdr.u32SessionCookie       = g_u32SessionCookie;
     743    OpenReq.Hdr.cbIn                   = SUP_IOCTL_LDR_OPEN_SIZE_IN;
     744    OpenReq.Hdr.cbOut                  = SUP_IOCTL_LDR_OPEN_SIZE_OUT;
     745    OpenReq.Hdr.fFlags                 = SUPREQHDR_FLAGS_DEFAULT;
     746    OpenReq.Hdr.rc                     = VERR_INTERNAL_ERROR;
     747    OpenReq.u.In.cbImageWithEverything = 0;
     748    OpenReq.u.In.cbImageBits           = 0;
     749    strcpy(OpenReq.u.In.szName, pszModule);
     750    int rc = RTPathAbs(pszFilename, OpenReq.u.In.szFilename, sizeof(OpenReq.u.In.szFilename));
     751    if (RT_FAILURE(rc))
     752        return rc;
     753    if (   (SUPDRV_IOC_VERSION & 0xffff0000) != 0x00300000
     754        || g_uSupSessionVersion >= 0x00300001)
     755    {
     756        if (!g_uSupFakeMode)
     757        {
     758            rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LDR_OPEN, &OpenReq, SUP_IOCTL_LDR_OPEN_SIZE);
     759            if (RT_SUCCESS(rc))
     760                rc = OpenReq.Hdr.rc;
     761        }
     762        else
     763        {
     764            OpenReq.u.Out.fNeedsLoading = true;
     765            OpenReq.u.Out.pvImageBase = 0xef423420;
     766        }
     767        *ppvImageBase = (void *)OpenReq.u.Out.pvImageBase;
     768        if (rc != VERR_MODULE_NOT_FOUND)
     769            return rc;
     770    }
     771
     772    /*
    739773     * Open image file and figure its size.
    740774     */
    741775    RTLDRMOD hLdrMod;
    742     rc = RTLdrOpenEx(pszFilename, 0 /*fFlags*/, RTLDRARCH_HOST, &hLdrMod, pErrInfo);
     776    rc = RTLdrOpenEx(OpenReq.u.In.szFilename, 0 /*fFlags*/, RTLDRARCH_HOST, &hLdrMod, pErrInfo);
    743777    if (RT_FAILURE(rc))
    744778    {
    745         LogRel(("SUP: RTLdrOpen failed for %s (%s) %Rrc\n", pszModule, pszFilename, rc));
     779        LogRel(("SUP: RTLdrOpen failed for %s (%s) %Rrc\n", pszModule, OpenReq.u.In.szFilename, rc));
    746780        return rc;
    747781    }
     
    785819             * Open the R0 image.
    786820             */
    787             SUPLDROPEN OpenReq;
    788821            OpenReq.Hdr.u32Cookie              = g_u32Cookie;
    789822            OpenReq.Hdr.u32SessionCookie       = g_u32SessionCookie;
     
    795828            OpenReq.u.In.cbImageBits           = (uint32_t)CalcArgs.cbImage;
    796829            strcpy(OpenReq.u.In.szName, pszModule);
    797             strcpy(OpenReq.u.In.szFilename, pszFilename);
    798             if (!g_uSupFakeMode)
     830            rc = RTPathAbs(pszFilename, OpenReq.u.In.szFilename, sizeof(OpenReq.u.In.szFilename));
     831            AssertRC(rc);
     832            if (RT_SUCCESS(rc))
    799833            {
    800                 rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LDR_OPEN, &OpenReq, SUP_IOCTL_LDR_OPEN_SIZE);
    801                 if (RT_SUCCESS(rc))
    802                     rc = OpenReq.Hdr.rc;
    803             }
    804             else
    805             {
    806                 OpenReq.u.Out.fNeedsLoading = true;
    807                 OpenReq.u.Out.pvImageBase = 0xef423420;
     834                if (!g_uSupFakeMode)
     835                {
     836                    rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_LDR_OPEN, &OpenReq, SUP_IOCTL_LDR_OPEN_SIZE);
     837                    if (RT_SUCCESS(rc))
     838                        rc = OpenReq.Hdr.rc;
     839                }
     840                else
     841                {
     842                    OpenReq.u.Out.fNeedsLoading = true;
     843                    OpenReq.u.Out.pvImageBase = 0xef423420;
     844                }
    808845            }
    809846            *ppvImageBase = (void *)OpenReq.u.Out.pvImageBase;
    810             if (    RT_SUCCESS(rc)
    811                 &&  OpenReq.u.Out.fNeedsLoading)
     847            if (   RT_SUCCESS(rc)
     848                && OpenReq.u.Out.fNeedsLoading)
    812849            {
    813850                /*
  • trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp

    r86549 r87700  
    16821682
    16831683
     1684void VBOXCALL   supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     1685{
     1686    RT_NOREF(pDevExt, pImage);
     1687    AssertFailed();
     1688}
     1689
     1690
     1691void VBOXCALL   supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     1692{
     1693    RT_NOREF(pDevExt, pImage);
     1694    AssertFailed();
     1695}
     1696
     1697
    16841698#ifdef SUPDRV_WITH_MSR_PROBER
    16851699
  • trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c

    r77107 r87700  
    600600
    601601
     602void VBOXCALL   supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     603{
     604    RT_NOREF(pDevExt, pImage);
     605    AssertFailed();
     606}
     607
     608
     609void VBOXCALL   supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     610{
     611    RT_NOREF(pDevExt, pImage);
     612    AssertFailed();
     613}
     614
    602615#ifdef SUPDRV_WITH_MSR_PROBER
    603616
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r85776 r87700  
    751751    return supdrvIDC(uReq, &g_DevExt, pSession, pReq);
    752752}
    753 
    754753EXPORT_SYMBOL(SUPDrvLinuxIDC);
     754
     755
     756/**
     757 * Used by native wrapper modules, forwarding to supdrvLdrRegisterWrappedModule
     758 * with device extension prepended to the argument list.
     759 */
     760SUPR0DECL(int)  SUPDrvLinuxLdrRegisterWrappedModule(PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void *pvLnxModule, void **phMod)
     761{
     762    AssertPtrReturn(pvLnxModule, VERR_INVALID_POINTER);
     763    return supdrvLdrRegisterWrappedModule(&g_DevExt, pWrappedModInfo, pvLnxModule, phMod);
     764}
     765EXPORT_SYMBOL(SUPDrvLinuxLdrRegisterWrappedModule);
     766
     767
     768/**
     769 * Used by native wrapper modules, forwarding to supdrvLdrDeregisterWrappedModule
     770 * with device extension prepended to the argument list.
     771 */
     772SUPR0DECL(int) SUPDrvLinuxLdrDeregisterWrappedModule(PCSUPLDRWRAPPEDMODULE pWrappedModInfo, void **phMod)
     773{
     774    return supdrvLdrDeregisterWrappedModule(&g_DevExt, pWrappedModInfo, phMod);
     775}
     776EXPORT_SYMBOL(SUPDrvLinuxLdrDeregisterWrappedModule);
    755777
    756778
     
    12441266
    12451267
     1268void VBOXCALL   supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     1269{
     1270    struct module *pLnxMod = (struct module *)pImage->pvWrappedNative;
     1271    Assert(!pImage->fLnxWrapperRef);
     1272    AssertReturnVoid(pLnxMod);
     1273    pImage->fLnxWrapperRef = try_module_get(pLnxMod);
     1274    RT_NOREF(pDevExt);
     1275}
     1276
     1277
     1278void VBOXCALL   supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     1279{
     1280    if (pImage->fLnxWrapperRef)
     1281    {
     1282        struct module *pLnxMod = (struct module *)pImage->pvWrappedNative;
     1283        pImage->fLnxWrapperRef = false;
     1284        module_put(pLnxMod);
     1285    }
     1286    RT_NOREF(pDevExt);
     1287}
     1288
     1289
    12461290#ifdef SUPDRV_WITH_MSR_PROBER
    12471291
     
    14121456    return VINF_SUCCESS;
    14131457}
     1458SUPR0_EXPORT_SYMBOL(SUPR0HCPhysToVirt);
    14141459
    14151460
     
    14301475    return 0;
    14311476}
     1477SUPR0_EXPORT_SYMBOL(SUPR0Printf);
    14321478
    14331479
     
    14491495    return fFlags;
    14501496}
     1497SUPR0_EXPORT_SYMBOL(SUPR0GetKernelFeatures);
    14511498
    14521499
  • trunk/src/VBox/HostDrivers/Support/os2/SUPDrv-os2.cpp

    r82972 r87700  
    473473
    474474
     475void VBOXCALL   supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     476{
     477    RT_NOREF(pDevExt, pImage);
     478    AssertFailed();
     479}
     480
     481
     482void VBOXCALL   supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     483{
     484    RT_NOREF(pDevExt, pImage);
     485    AssertFailed();
     486}
     487
    475488#ifdef SUPDRV_WITH_MSR_PROBER
    476489
  • trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c

    r82968 r87700  
    12531253
    12541254
     1255void VBOXCALL   supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     1256{
     1257    RT_NOREF(pDevExt, pImage);
     1258    AssertFailed();
     1259}
     1260
     1261
     1262void VBOXCALL   supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     1263{
     1264    RT_NOREF(pDevExt, pImage);
     1265    AssertFailed();
     1266}
     1267
    12551268#ifdef SUPDRV_WITH_MSR_PROBER
    12561269
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp

    r84497 r87700  
    24342434
    24352435
     2436void VBOXCALL   supdrvOSLdrRetainWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     2437{
     2438    RT_NOREF(pDevExt, pImage);
     2439    AssertFailed();
     2440}
     2441
     2442
     2443void VBOXCALL   supdrvOSLdrReleaseWrapperModule(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
     2444{
     2445    RT_NOREF(pDevExt, pImage);
     2446    AssertFailed();
     2447}
     2448
     2449
    24362450#ifdef SUPDRV_WITH_MSR_PROBER
    24372451
Note: See TracChangeset for help on using the changeset viewer.

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