1010#include < errno.h>
1111#include < limits.h>
1212
13+ #if defined (APPLE_OS_X)
1314#include < dlfcn.h>
15+ #endif // def APPLE_OX_X
16+
1417#include < fcntl.h>
1518#include < unistd.h>
1619#include < stdint.h>
8285
8386#include " cpp-util.hh"
8487
88+ #include " java-interop-dlfcn.h"
89+
8590using namespace xamarin ::android;
8691using namespace xamarin ::android::internal;
8792
@@ -151,12 +156,11 @@ MonodroidRuntime::setup_bundled_app (const char *dso_name)
151156 if (!application_config.is_a_bundled_app )
152157 return ;
153158
154- static int dlopen_flags = RTLD_LAZY;
155159 void *libapp = nullptr ;
156160
157161 if (androidSystem.is_embedded_dso_mode_enabled ()) {
158162 log_info (LOG_DEFAULT, " bundle app: embedded DSO mode" );
159- libapp = androidSystem.load_dso_from_any_directories (dso_name, dlopen_flags );
163+ libapp = androidSystem.load_dso_from_any_directories (dso_name, 0 );
160164 } else {
161165 bool needs_free = false ;
162166 log_info (LOG_DEFAULT, " bundle app: normal mode" );
@@ -165,7 +169,7 @@ MonodroidRuntime::setup_bundled_app (const char *dso_name)
165169 if (bundle_path == nullptr )
166170 return ;
167171 log_info (LOG_BUNDLE, " Attempting to load bundled app from %s" , bundle_path);
168- libapp = androidSystem.load_dso (bundle_path, dlopen_flags , true );
172+ libapp = androidSystem.load_dso (bundle_path, 0 , true );
169173 if (needs_free)
170174 delete[] bundle_path;
171175 }
@@ -181,11 +185,11 @@ MonodroidRuntime::setup_bundled_app (const char *dso_name)
181185 }
182186 }
183187
184- mono_mkbundle_initialize_mono_api = reinterpret_cast <mono_mkbundle_initialize_mono_api_ptr> (dlsym (libapp, " initialize_mono_api" ));
188+ mono_mkbundle_initialize_mono_api = reinterpret_cast <mono_mkbundle_initialize_mono_api_ptr> (java_interop_get_symbol_address (libapp, " initialize_mono_api" , nullptr ));
185189 if (!mono_mkbundle_initialize_mono_api)
186190 log_error (LOG_BUNDLE, " Missing initialize_mono_api in the application" );
187191
188- mono_mkbundle_init = reinterpret_cast <mono_mkbundle_init_ptr> (dlsym (libapp, " mono_mkbundle_init" ));
192+ mono_mkbundle_init = reinterpret_cast <mono_mkbundle_init_ptr> (java_interop_get_symbol_address (libapp, " mono_mkbundle_init" , nullptr ));
189193 if (!mono_mkbundle_init)
190194 log_error (LOG_BUNDLE, " Missing mono_mkbundle_init in the application" );
191195 log_info (LOG_BUNDLE, " Bundled app loaded: %s" , dso_name);
@@ -1067,13 +1071,7 @@ setup_gc_logging (void)
10671071force_inline int
10681072MonodroidRuntime::convert_dl_flags (int flags)
10691073{
1070- int lflags = flags & static_cast <int > (MONO_DL_LOCAL) ? 0 : RTLD_GLOBAL;
1071-
1072- if (flags & static_cast <int > (MONO_DL_LAZY))
1073- lflags |= RTLD_LAZY;
1074- else
1075- lflags |= RTLD_NOW;
1076- return lflags;
1074+ return 0 ;
10771075}
10781076
10791077force_inline void
@@ -1099,7 +1097,7 @@ MonodroidRuntime::init_internal_api_dso (void *handle)
10991097
11001098 std::lock_guard<std::mutex> lock (api_init_lock);
11011099 if (api_dso_handle != nullptr ) {
1102- auto api_shutdown = reinterpret_cast <external_api_shutdown_fn> (dlsym (api_dso_handle, MonoAndroidInternalCalls::SHUTDOWN_FUNCTION_NAME));
1100+ auto api_shutdown = reinterpret_cast <external_api_shutdown_fn> (java_interop_get_symbol_address (api_dso_handle, MonoAndroidInternalCalls::SHUTDOWN_FUNCTION_NAME, nullptr ));
11031101 if (api_shutdown == nullptr ) {
11041102 // We COULD ignore this situation, but if the function is missing it means we messed something up and thus
11051103 // it *is* a fatal error.
@@ -1111,7 +1109,7 @@ MonodroidRuntime::init_internal_api_dso (void *handle)
11111109
11121110 api_dso_handle = handle;
11131111 auto api = new MonoAndroidInternalCalls_Impl ();
1114- auto api_init = reinterpret_cast <external_api_init_fn>(dlsym (handle, MonoAndroidInternalCalls::INIT_FUNCTION_NAME));
1112+ auto api_init = reinterpret_cast <external_api_init_fn>(java_interop_get_symbol_address (handle, MonoAndroidInternalCalls::INIT_FUNCTION_NAME, nullptr ));
11151113 if (api_init == nullptr ) {
11161114 log_fatal (LOG_DEFAULT, " Unable to initialize Internal API library, init function '%s' not found in the module" , MonoAndroidInternalCalls::INIT_FUNCTION_NAME);
11171115 exit (FATAL_EXIT_MONO_MISSING_SYMBOLS);
@@ -1190,11 +1188,15 @@ void*
11901188MonodroidRuntime::monodroid_dlsym (void *handle, const char *name, char **err, [[maybe_unused]] void *user_data)
11911189{
11921190 void *s;
1191+ char *e = nullptr ;
11931192
1194- s = dlsym (handle, name);
1193+ s = java_interop_get_symbol_address (handle, name, &e );
11951194
11961195 if (!s && err) {
1197- *err = utils.monodroid_strdup_printf (" Could not find symbol '%s'." , name);
1196+ *err = utils.monodroid_strdup_printf (" Could not find symbol '%s': %s" , name, e);
1197+ }
1198+ if (e) {
1199+ java_interop_free (e);
11981200 }
11991201
12001202 return s;
@@ -1370,9 +1372,9 @@ MonodroidRuntime::disable_external_signal_handlers (void)
13701372 if (!androidSystem.is_mono_llvm_enabled ())
13711373 return ;
13721374
1373- void *llvm = androidSystem.load_dso (" libLLVM.so" , RTLD_LAZY , TRUE );
1375+ void *llvm = androidSystem.load_dso (" libLLVM.so" , 0 , TRUE );
13741376 if (llvm) {
1375- bool *disable_signals = reinterpret_cast <bool *> (dlsym (llvm, " _ZN4llvm23DisablePrettyStackTraceE" ));
1377+ bool *disable_signals = reinterpret_cast <bool *> (java_interop_get_symbol_address (llvm, " _ZN4llvm23DisablePrettyStackTraceE" , nullptr ));
13761378 if (disable_signals) {
13771379 *disable_signals = true ;
13781380 log_info (LOG_DEFAULT, " Disabled LLVM signal trapping" );
@@ -1605,7 +1607,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
16051607 if (my_location != nullptr ) {
16061608 simple_pointer_guard<char , false > dso_path (utils.path_combine (my_location, API_DSO_NAME));
16071609 log_info (LOG_DEFAULT, " Attempting to load %s" , dso_path.get ());
1608- api_dso_handle = dlopen (dso_path.get (), RTLD_NOW );
1610+ api_dso_handle = java_interop_load_library (dso_path.get (), 0 , nullptr );
16091611#if defined (APPLE_OS_X)
16101612 delete[] my_location;
16111613#else // !defined(APPLE_OS_X)
@@ -1615,11 +1617,11 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
16151617
16161618 if (api_dso_handle == nullptr ) {
16171619 log_info (LOG_DEFAULT, " Attempting to load %s with \" bare\" dlopen" , API_DSO_NAME);
1618- api_dso_handle = dlopen (API_DSO_NAME, RTLD_NOW );
1620+ api_dso_handle = java_interop_load_library (API_DSO_NAME, 0 , nullptr );
16191621 }
16201622#endif // defined(WINDOWS) || defined(APPLE_OS_X)
16211623 if (api_dso_handle == nullptr )
1622- api_dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, RTLD_NOW );
1624+ api_dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, 0 );
16231625 init_internal_api_dso (api_dso_handle);
16241626
16251627 mono_dl_fallback_register (monodroid_dlopen, monodroid_dlsym, nullptr , nullptr );
0 commit comments