Changeset 99538 in vbox for trunk/include/iprt/runtime-loader.h
- Timestamp:
- Apr 26, 2023 8:59:07 PM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/runtime-loader.h
r98103 r99538 65 65 * RT_PROXY_STUB(func_name, ret_type, (long_param_list), (short_param_list)) \ 66 66 * 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, ...)) \ 67 68 * ... 69 * #define func_name3(...) g_pfn_func_name3(__VA_ARGS__) 68 70 * @endcode 69 71 * … … 78 80 * file. 79 81 * 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 * 80 92 * @{ 81 93 */ … … 87 99 * the EMX/GCC toolchain on OS/2... It's a wee bit more annoying in x86 PIC/PIE 88 100 * 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. 89 104 */ 90 105 /** @todo r=bird: The use of RTR3DECL here is an unresolved issue. */ … … 99 114 /* The following are the symbols which we need from the library. */ 100 115 # define RT_PROXY_STUB(function, rettype, signature, shortsig) \ 101 void (*function ## _fn)(void); \116 rettype (*g_pfn_ ## function) signature; \ 102 117 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; 104 124 105 125 RT_RUNTIME_LOADER_INSERT_SYMBOLS 106 126 107 127 # undef RT_PROXY_STUB 128 # undef RT_PROXY_VARIADIC_STUB 129 130 /* Function pointer type for easy casting below. */ 131 typedef void (*PFNRTLDRSHAREDGENERIC)(void); 108 132 109 133 /* Now comes a table of functions to be loaded from the library. */ 110 134 typedef struct 111 135 { 112 const char *pszName;113 void (**ppfn)(void);136 const char *pszName; 137 PFNRTLDRSHAREDGENERIC *ppfn; 114 138 } RTLDRSHAREDFUNC; 115 139 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 } , 142 static RTLDRSHAREDFUNC const g_aSharedFuncs[] = 118 143 { 119 144 RT_RUNTIME_LOADER_INSERT_SYMBOLS 120 { NULL, NULL }121 145 }; 146 # undef RT_PROXY_VARIADIC_STUB 122 147 # undef RT_PROXY_STUB 123 148 … … 128 153 static DECLCALLBACK(int) rtldrLoadOnce(void *) 129 154 { 130 RTLDRMOD hLib;131 int rc;132 133 155 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; 140 174 } 141 175 … … 151 185 RTR3DECL(int) RT_RUNTIME_LOADER_FUNCTION(void) 152 186 { 153 static RTONCE s_Once = RTONCE_INITIALIZER; 154 int rc; 155 187 static RTONCE s_Once = RTONCE_INITIALIZER; 156 188 LogFlowFunc(("\n")); 157 rc = RTOnce(&s_Once, rtldrLoadOnce, NULL);189 int rc = RTOnce(&s_Once, rtldrLoadOnce, NULL); 158 190 LogFlowFunc(("rc = %Rrc\n", rc)); 159 160 191 return rc; 161 192 } … … 167 198 # define RT_PROXY_STUB(function, rettype, signature, shortsig) \ 168 199 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; \ 169 204 170 205 RT_RUNTIME_LOADER_INSERT_SYMBOLS 171 206 207 172 208 # undef RT_PROXY_STUB 209 # undef RT_PROXY_VARIADIC_STUB 173 210 # endif /* RT_RUNTIME_LOADER_GENERATE_DECLS */ 174 211
Note:
See TracChangeset
for help on using the changeset viewer.