VirtualBox

Ignore:
Timestamp:
Apr 26, 2023 8:59:07 PM (19 months ago)
Author:
vboxsync
Message:

iprt/runtime-loader.h: Added RT_PROXY_VARIADICT_STUB hack. Cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/runtime-loader.h

    r98103 r99538  
    6565 *  RT_PROXY_STUB(func_name, ret_type, (long_param_list), (short_param_list)) \
    6666 *  RT_PROXY_STUB(func_name2, ret_type2, (long_param_list2), (short_param_list2)) \
     67 *  RT_PROXY_VARIADIC_STUB(func_name3, ret_type3, (long_param_list3, ...)) \
    6768 *  ...
     69 * #define func_name3(...) g_pfn_func_name3(__VA_ARGS__)
    6870 * @endcode
    6971 *
     
    7880 * file.
    7981 *
     82 * @note For functions with a variable number of parameters, this approch is
     83 *       clumsy as it requires an additional \#define for each function that
     84 *       makes use of the g_pfn_XXX function pointer. See func_name3 in the
     85 *       snipped above.  Instead, use the VBoxDef2LazyLoad approach.
     86 *
     87 * @deprecated This is deprecated. Use VBoxDef2LazyLoad instead where possible.
     88 *             See VBOX_DEF_2_LAZY_LOAD in /Config.kmk,
     89 *             src/bldprog/VBoxDef2LazyLoad.cpp and examples in
     90 *             src/VBox/Devices/Makefile.kmk and other places.
     91 *
    8092 * @{
    8193 */
     
    8799 * the EMX/GCC toolchain on OS/2...  It's a wee bit more annoying in x86 PIC/PIE
    88100 * mode, but nothing that cannot be dealt with.
     101 *
     102 * Update: This was done years ago. See src/bldprogs/VBoxDef2LazyLoad.cpp and
     103 *         VBOX_DEF_2_LAZY_LOAD in /Config.kmk.
    89104 */
    90105/** @todo r=bird: The use of RTR3DECL here is an unresolved issue. */
     
    99114/* The following are the symbols which we need from the library. */
    100115# define RT_PROXY_STUB(function, rettype, signature, shortsig) \
    101     void (*function ## _fn)(void); \
     116    rettype (*g_pfn_ ## function) signature; \
    102117    RTR3DECL(rettype) function signature \
    103     { return ( (rettype (*) signature) function ## _fn ) shortsig; }
     118    { return g_pfn_ ## function shortsig; }
     119
     120/* The following are the symbols which correspond to variadic functions
     121 * provided by the library. */
     122# define RT_PROXY_VARIADIC_STUB(function, rettype, signature) \
     123    rettype (*g_pfn_ ## function) signature;
    104124
    105125RT_RUNTIME_LOADER_INSERT_SYMBOLS
    106126
    107127# undef RT_PROXY_STUB
     128# undef RT_PROXY_VARIADIC_STUB
     129
     130/* Function pointer type for easy casting below. */
     131typedef void (*PFNRTLDRSHAREDGENERIC)(void);
    108132
    109133/* Now comes a table of functions to be loaded from the library. */
    110134typedef struct
    111135{
    112     const char *pszName;
    113     void (**ppfn)(void);
     136    const char            *pszName;
     137    PFNRTLDRSHAREDGENERIC *ppfn;
    114138} RTLDRSHAREDFUNC;
    115139
    116 # define RT_PROXY_STUB(s, dummy1, dummy2, dummy3 ) { #s , & s ## _fn } ,
    117 static RTLDRSHAREDFUNC g_aSharedFuncs[] =
     140# define RT_PROXY_STUB(function, rettype, signature, shortsig ) { #function , (PFNRTLDRSHAREDGENERIC *)&g_pfn_ ## function } ,
     141# define RT_PROXY_VARIADIC_STUB(function, rettype, signature)   { #function , (PFNRTLDRSHAREDGENERIC *)&g_pfn_ ## function } ,
     142static RTLDRSHAREDFUNC const g_aSharedFuncs[] =
    118143{
    119144    RT_RUNTIME_LOADER_INSERT_SYMBOLS
    120     { NULL, NULL }
    121145};
     146# undef RT_PROXY_VARIADIC_STUB
    122147# undef RT_PROXY_STUB
    123148
     
    128153static DECLCALLBACK(int) rtldrLoadOnce(void *)
    129154{
    130     RTLDRMOD    hLib;
    131     int         rc;
    132 
    133155    LogFlowFunc(("\n"));
    134     rc = RTLdrLoadEx(RT_RUNTIME_LOADER_LIB_NAME, &hLib, RTLDRLOAD_FLAGS_LOCAL | RTLDRLOAD_FLAGS_NO_UNLOAD, NULL);
    135     for (unsigned i = 0; RT_SUCCESS(rc) && g_aSharedFuncs[i].pszName != NULL; ++i)
    136         rc = RTLdrGetSymbol(hLib, g_aSharedFuncs[i].pszName, (void **)g_aSharedFuncs[i].ppfn);
    137     LogFlowFunc(("rc = %Rrc\n", rc));
    138 
    139     return rc;
     156    RTLDRMOD hLdrMod;
     157    int rcRet = RTLdrLoadEx(RT_RUNTIME_LOADER_LIB_NAME, &hLdrMod, RTLDRLOAD_FLAGS_LOCAL | RTLDRLOAD_FLAGS_NO_UNLOAD, NULL);
     158    if (RT_SUCCESS(rcRet))
     159    {
     160        for (unsigned i = 0; i < RT_ELEMENTS(g_aSharedFuncs); ++i)
     161        {
     162            int rc2 = RTLdrGetSymbol(hLdrMod, g_aSharedFuncs[i].pszName, (void **)g_aSharedFuncs[i].ppfn);
     163            if (RT_FAILURE(rc2))
     164            {
     165                LogFunc(("RTLdrGetSymbol(%s, %s) failed: %Rrc\n", RT_RUNTIME_LOADER_LIB_NAME, g_aSharedFuncs[i].pszName, rc2));
     166                rcRet = rc2;
     167            }
     168        }
     169        LogFlowFunc(("rcRet = %Rrc\n", rcRet));
     170    }
     171    else
     172        LogFunc(("RTLdrLoadEx(%s) failed: %Rrc\n",  RT_RUNTIME_LOADER_LIB_NAME, rcRet));
     173    return rcRet;
    140174}
    141175
     
    151185RTR3DECL(int) RT_RUNTIME_LOADER_FUNCTION(void)
    152186{
    153     static RTONCE   s_Once = RTONCE_INITIALIZER;
    154     int             rc;
    155 
     187    static RTONCE s_Once = RTONCE_INITIALIZER;
    156188    LogFlowFunc(("\n"));
    157     rc = RTOnce(&s_Once, rtldrLoadOnce, NULL);
     189    int rc = RTOnce(&s_Once, rtldrLoadOnce, NULL);
    158190    LogFlowFunc(("rc = %Rrc\n", rc));
    159 
    160191    return rc;
    161192}
     
    167198#  define RT_PROXY_STUB(function, rettype, signature, shortsig) \
    168199    RTR3DECL(rettype)  function  signature ;
     200/* Variadict functions needs custom mappings via \#defines as we cannot forward
     201   the arguments in an inline function, so only make the function pointer available here. */
     202# define RT_PROXY_VARIADIC_STUB(function, rettype, signature) \
     203    rettype (*g_pfn_ ## function) signature; \
    169204
    170205RT_RUNTIME_LOADER_INSERT_SYMBOLS
    171206
     207
    172208#  undef RT_PROXY_STUB
     209#  undef RT_PROXY_VARIADIC_STUB
    173210# endif /* RT_RUNTIME_LOADER_GENERATE_DECLS */
    174211
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